Computer operating system
The Machine Operating System (MOS) or OS is a discontinued computer operating system (OS) used in Acorn Computers' BBC computer range. It included support for four-channel sound, graphics, file system abstraction, and digital and analogue input/output (I/O) including a daisy-chained expansion bus. The system was single-tasking, monolithic and non-reentrant.
Versions 0.10 to 1.20 were used on the BBC Micro, version 1.00 on the Electron, version 2 was used on the B+, and versions 3 to 5 were used in the BBC Master series.
The final BBC computer, the BBC A3000, was 32-bit and ran RISC OS, which kept on portions of the Acorn MOS architecture and shared a number of characteristics (e.g. "star commands" CLI, "VDU" video control codes and screen modes) with the earlier 8-bit MOS.
Versions 0 to 2 of the MOS were 16 KiB in size, written in 6502 machine code, and held in read-only memory (ROM) on the motherboard. The upper quarter of the 16-bit address space (0xC000 to 0xFFFF) is reserved for its ROM code and I/O space.
Versions 3 to 5 were still restricted to a 16 KiB address space, but managed to hold more code and hence more complex routines, partly because of the alternative 65C102 central processing unit (CPU) with its denser instruction set plus the careful use of paging.
User interface.
The original MOS versions, from 0 to 2, did not have a user interface per se: applications were expected to forward operating system command lines to the OS on its behalf, and the programming language BBC BASIC ROM, with 6502 assembler built in, supplied with the BBC Micro is the default application used for this purpose. The BBC Micro would halt with a codice_1 error if no ROM is present that advertises to the OS an ability to provide a user interface (called "language ROMs"). MOS version 3 onwards did feature a simple command-line interface, normally only seen when the CMOS memory did not contain a setting for the default language ROM.
Application programs on ROM, and some cassette and disc-based software also, typically provide a command line, useful for working with file storage such as browsing the currently inserted disc. The OS provides the line entry facility and obeys the commands entered, but the application oversees running the command prompt.
Cassette and disc based software typically relies on BBC BASIC's own user interface in order to be loaded, although it is possible to configure a floppy disk to boot up without needing to have BASIC commands executed, this was rarely used in practice.
In BBC BASIC, OS commands may be preceded with an asterisk to instruct BASIC to forward that command directly to the OS. This led to the asterisk being the prompt symbol for any software providing an OS command line; MOS version 3 onwards officially uses the asterisk as the command prompt symbol. When referring to an OS command, they generally include the asterisk as part of the name, for example , , etc., although only the part after the asterisk is the command. The asterisk was called a "star" and the commands were called "star commands".
From BBC BASIC 2 onwards, commands can also be issued using the keyword in conjunction with a command string. Alternatively, the OSCLI routine may be invoked directly using the keyword after initialising the relevant BASIC variables.
Unrecognised commands are offered to any "service" (extension) ROMs; filing system ROMs will often check to see if a file on disc matches that name, the same most other command-line interfaces do. The operating system call OSWORD with accumulator = 0 does however offer programs single line input (with ctrl-U for clear line and the cursor copying keys enabled) with basic character filtering and line length limit.
The MOS command line interpreter features a rather unusual idea: abbreviation of commands. To save typing a dot could be used after the first few characters, such as for and for . was abbreviated to alone. , the command to catalogue (list) a cassette or disc, can be abbreviated down to .
Service ROMs.
3rd party ROMs generally also support command abbreviation, leading to ambiguity where two service ROMs provide commands which are very similar in name but possibly different in function. In this case, the MOS would prioritise the command from the ROM in the higher numbered ROM slot, e.g., 7 has precedence over 6.
Some 3rd party suppliers would get around this by prefixing their star commands with other letters. For example, Watford Electronics ROMS would have their star commands prefixed with codice_2 thus making them unique.
Extension.
The lower 16 KiB of the ROM map (0x8000 to 0xBFFF) is reserved for the active Sideways address space paged bank. The Sideways system on the BBC Micro allows for one ROM at a time from sockets on the motherboard (or expansion boards) to be switched into the main memory map. Software can be run from ROM this way (leaving the RAM free of user program code, for more workspace) and the OS can be extended by way of such ROMs. The most prevalent sideways ROM after BASIC is the Acorn Disc Filing System used to provide floppy disc support to the machine.
During a reset, every paged ROM is switched in and asked how much public and private workspace it needs. Each ROM is allocated a chunk of private workspace that remains allocated at all times, and a single block of public workspace, equal to the size of the largest request, is made available to the active ROM. During operation, the paged area is rapidly switched between ROMs when file system commands are issued and unrecognised commands are put to the OS.
MOS allocates a 3.5 KiB block of memory (0x0000 to 0x0DFF) from the bottom of the memory map for operating system and language ROM workspace:
On a cassette-only machine, 0x0E00 is the start of user program memory. With OS extension ROMs fitted such as the a filing system ROM, more memory is allocated above this point; DFS ROMs generally use another 2.75 KiB to cache the disc catalogue and manage random access buffers. A network filing system ROM (for Econet) allocates another 0.5 KiB on top of this. This is a serious problem because MOS does not support relocation of machine code, which must be run from the address at which it was assembled, so some programs which assumed a fixed start of user program memory could overwrite MOS workspace. The problem was alleviated in versions 3 to 5 by allowing ROMs to allocate workspace in an alternative RAM bank at 0xC000 to 0xDFFF which was present in Master series computers, though old ROMs could continue to allocate blocks of main memory.
The OS also maintains a vector table of all its calls which can be updated to hook any OS calls for user extension. By altering or 'hooking' these vectors, developers could substitute their own routines for those provided as defaults by the MOS.
Text, graphics, printing.
The MOS permits textual output intended for the screen to be directed instead to the printer, or both at once, allowing for very trivial printing support for plain text. Graphics printing is not supported and has to be written separately.
Graphics and in general all screen output is handled in a very unusual way. The ASCII control characters are almost entirely given new significance under MOS: known as the "VDU drivers", because the documentation described them in relation to the VDU statement in BBC BASIC, they are interpreted as video control characters. (i.e. ASCII 30) moves the cursor to (0, 0), VDU 4 and 5 select whether text should be drawn at the graphics or text cursor, VDU 12 clears the screen and VDU 14 and 15 turn scroll lock on and off. Thus, pressing ctrl-L will clear the screen and ctrl-N will enable scroll lock. VDU 2 and 3 toggle whether screen output is echoed to the printer. The BBC BASIC VDU statement is equivalent to the conventional BASIC and many of the control codes (such as 12 for "clear screen" and 7 for "beep") have the same functions as on other contemporary machines.
Many more control characters take parameters: one or more characters that follow are used solely for their bit value as a parameter and not as a control code. VDU 19 handles palette remap; the following five bytes represent the palette entry, the desired colour and three reserve bytes. VDU 31 locates the text cursor to the location held in the following two bytes. VDU 17 sets the text colour and 18 the graphics colour. VDU 25 uses the succeeding five bytes to move the graphics cursor and plot solid and dashed lines, dots and filled triangles, the documented extent of graphics in MOS 0 and 1. The first byte is the command code, followed by the x and y co-ordinates as two byte pairs. Other graphic functions – such as horizontal line fill bounded by a given colour – were available by use of undocumented or poorly documented command codes. 
BBC BASIC contained aliases for the commonly used VDU codes (such as GCOL for VDU 18 or PLOT for VDU 25). Some statements were direct equivalents to VDU codes, such as CLS for VDU 12. Some statements were less exact equivalents as they incorporated functionality specific to BASIC as well as calling the OS routines; for example the statement would set screen mode and adjust the BASIC system variable HIMEM according to the amount of memory the new mode left available for BASIC, while would set the screen mode only, without altering HIMEM. This allowed a programmer to allocate a block of memory from BASIC – for example to load machine code routines into – by lowering the value of HIMEM at the start of a program, and still be free to switch screen modes without deallocating it as a side effect.
There is one operating system command to write a character, OSWRCH, which is responsible for all text and graphics. For example, to move the cursor to (10, 15), needed, in 6502 assembler:
 LDA #31: JSR OSWRCH \ move text cursor
 LDA #10: JSR OSWRCH \ x-coordinate
 LDA #15: JSR OSWRCH \ y-coordinate
(LDA loads a value into the accumulator; JSR is "jump to subroutine".) On the third OS call, the cursor will move. The following code would draw a line from (0, 0) to (0, +100):
 LDA #25: JSR OSWRCH \ begin "PLOT" (ASCII 25) command
 LDA #4: JSR OSWRCH \ command k=4, or move absolute
 LDA #0: JSR OSWRCH: JSR OSWRCH: JSR OSWRCH: JSR OSWRCH
 \ send (0, 0) as low, high byte pairs
 LDA #25: JSR OSWRCH \ begin PLOT
 LDA #1: JSR OSWRCH \ k=1 - draw relative
 LDA #0: JSR OSWRCH: JSR OSWRCH \ x = 0
 LDA #100: JSR OSWRCH \ y = 100 (low byte)
 LDA #0: JSR OSWRCH \ high byte
BBC BASIC allows performing the above as any of the following:
 VDU 25, 4, 0; 0; 25, 4, 100; 0;
 PRINT CHR$(25); CHR$(4); CHR$(0); ... etc.
 PLOT 4, 0, 0: PLOT 1, 0, 100
 MOVE 0, 0: DRAW 0, 100: REM absolute co-ords only!
 OSWRCH=&amp;FFEE: A%=25: CALL OSWRCH: A%=4: CALL OSWRCH: A%=0: CALL OSWRCH ... etc.
Graphics in the Acorn MOS use a virtual graphics resolution of 1280×1024, with pixel positions mapped to the nearest equivalent pixel in the current graphics mode. Switching video resolution will not affect the shape, size or position of graphics drawn even with completely different pixel metrics in the new mode, because this is all accounted for by the OS.
MOS does provide two other OS calls that handle text output: codice_3 and codice_4. OSNEWL writes a line feed and carriage return to the current output stream. OSASCI forwards all characters directly to OSWRCH except for carriage return, which triggers a call to OSNEWL instead. The precise code for OSASCI and OSNEWL – five lines of 6502 assembler – is documented in the BBC Micro User Guide.
MOS implements character recognition so that text printed on screen in the system font can be selected with the arrow keys and input with the key as though it was being typed. To activate "screen editing" the user moves the hardware cursor to the text to be read and the OS displays a second cursor in software at the original position. Pressing copies one character from the hardware cursor to the software cursor and advances both, so that holding the key down copies a section of the text,