18 ATOM Operating System

18.1 Keyboard

18.1.1 Teletype/Typewriter Nodes

After switching on, or typing BREAK, the ATOM is in teletype mode. In this mode all the alphabetic keys produce upper case letters, and the SHIFT key is used to obtain the lower-case letters. This mode is most convenient for normal operation of the ATOM because all commands are typed in upper case.

When entering documents which contain mixed lower and upper case it is convenient to have the ATOM keyboard behave like a standard typewriter; i.e. for the alphabetic keys to produce lower case, and upper case when shifted. This state may be obtained by typing the LOCK key. The mode is cancelled by typing LOCK a second time. Note that the LOCK key only affects the alphabetic keys, A -- Z.

18.1.2 SHIFT Key

All but one of the 128 ASCII codes are available from the ATOM keyboard. The code which cannot be obtained appears as a back-arrow on the display.

The codes which can be obtained, but which are not marked on the keyboard, are as follows:

        SHIFT +    Displayed as    ASCII character   Code in hex
          @        Inverted @           \              #60
          A        Inverted A           a              #61
          .             .               .               .
          .             .               .               .
          Z        Inverted Z           z              #7A
          [        Inverted [           {              #7B
          \        Inverted \           |              #7C
          ]        Inverted ]           }              #7D
          ^        Inverted ^           ~              #7E

18.1.3 Control Codes

The following list gives all the control codes that perform special functions on the ATOM. They are all available from the keyboard, by typing CTRL with the specified key, or from programs.

STX  (CTRL-B, 2)  Start printer

This code, which is not sent to the printer, starts the printer output stream. All further output is sent to the printer as well as the VDU until receipt of an ETX code.

ETX (CTRL-C, 3) End printer

Ends the printer output stream.

ACK  (CTRL-F, 6)  Start screen

Starts the output stream to the VDU screen, and resets the VDU to character mode. This code is sent to the VDU on BREAK.

BELL (CTRL-G, 7)  Bleep

Causes the output stream to make a 1/2 second bleep on the internal speaker.

BS   (CTRL-H, 8)  Backspace

Moves the cursor back one position.

HT (CTRL-I, 9) Horizontal tab

Moves the cursor forward one position.

LF (CTRL-J, 10) Linefeed

Moves the cursor down one line.

VT (CTRL-K, 11) Vertical tab

Moves the cursor up one line.

FF (CTRL-L, 12) Formfeed

Clears the screen, moves the cursor to the top left-hand corner, and sets the VDU to character mode.

CR (CTRL-M, 13) Return

Moves tle cursor to the start of the current line.

SO (CTRL-N, 14) Page mode on

Turns on paged mode, and resets the line count to zero. Every time the screen in scrolled the line count is incremented. In paged mode the UDU will wait for a key to be typed every time the line count reaches 16.

SI (CTRL-O, 15) Page mode off

Turns off paged mode. This is the mode set on BREAK and on power-up.

NAK (CTRL-U, 21) End screen

Ends the output stream to the VDU; the only code recognised when in this condition is ACK.

CAN (CTRL-X, 24) Cancel

Deletes the line currently being typed, and returns the cursor to the start of the following line. Only happens in BASIC's input modes.

ESC (CTRL-[, 27) Escape

Causes an escape from an executing BASIC program. If typed twice, resets the VDU to character mode.

RS (CTRL-^, 30) Home cursor

Moves the cursor to the top left-hand corner of the screen.

18.4 Screen Editing

Three keys on the ATOM keyboard have special functions, and are used in conjunction with the SHIFT key for screen editing. Their functions are:

Cursor up
SHIFT Cursor down
Cursor right
SHIFT Cursor left
COPY Read character under cursor

Pressing the first four key combinations move the cursor around the screen but do not send any new characters down the input channel. They may be typed at any time and will have no effect on the ATOM, or on programs; they just determine where the cursor is positioned.

The COPY key will read the character under the cursor, and transmit that character to the input stream; the effect is the same as if that character had been typed at the keyboard. After reading a character the cursor is automatically moved one place to the right.

For example, suppose we wanted to edit a piece of stored text. First the text is listed as shown:

>LIST
    10 PIECE OF TEXTUAL MATERIAL

After listing the program the cursor is positioned after the prompt, as shown. First move the cursor vertically upwards, using the ) key, until it is opposite the line we wish to edit:

>LIST
   10 PIECE OF TEXTUAL MATERIAL

Now use the COPY key to read the correct part of the line:

>LIST
   10 PIECE OFTEXTUAL MATERIAL>

Note that the cursor inverts every character it passes over. If any inverted characters are present in the text, these will be un-inverted by the cursor.

Now type in the corrected part of the line:

>LIST
   10 PIECE OF CAKEAL MATERIAL
>

As no more of the old line is required the return key is pressed, and the program may be listed again to verify that the editing gave the correct result.

The key may be used to omit parts of the old line that are no longer required and SHIFT may be used to backspace the cursor in order to make room for inserting extra characters in the line. If you change your mind while editing a line, type CTRL-X (cancel) and the old line will be unchanged.

18.5 The VDU

The character display shows the contents of memory from #8000 to #81FF, mapped one character cell per byte. The address of the top left-hand cell is #8000, and the address of the Cth column in the Lth line is simply:

       #8000+32*L+C

where 0<=C<=31 and 0<=L<=15, and L=0, C=0 corresponds to the top left-hand character position.

The value stored in the memory cell determines the character displayed. All 256 different possible codes produce different displayed characters (with two exceptions), and the codes are assigned as follows:

       Hex Code:               Characters:
       #00 -- #1F              0 to <- (including alphabet)
       #20 -- #3F              space to ? (including digits)
       #40 -- #7F              white graphics symbols
       #80 -- #9F              inverted 0 to <-
       #A0 -- #BF              inverted space to ?
       #C0 -- #FF              grey graphics symbols

The complete character set is displayed by executing:

       FOR N=0 TO 255; N?#8000=N; NEXT N

which will generate the display shown below:

           

The graphics symbols consist of a block divided into 6 pixels, the state of each pixel being determined by the lower 6 bits of the byte, as follows:

5 4
3 2
1 0

If the bit is set, the corresponding pixel is grey or white; if the bit. is clear the pixel is black. Note that #20 and #40, and #7F and #A0 give the same graphics patterns.

Note that in all cases except #20 to #3F the code stored in the cell differs from the ASCII code for the character displayed. If C is the ASCII code for the character to be displayed, the code to be stored in the cell is obtained by:

       C=C+#20; IF C<#80 THEN C=C:#60

Similarly, to obtain the ASCII code for a character from the value V stored in the screen memory, execute:

       IF V<#80 THEN V=V:#60
       V=V-#20

18.6 Changing Text Spaces

The 'text space' is the region of memory used by the ATOM for storing the text of programs. On switching on, or pressing BREAK, the ATOM is initialised with a fixed text space at address #8200 in the unexpanded ATOM, or at #2900 in the ATOM with extra memory in the lower text space. However, it is possible to change the value of the text-space pointer so that text can be entered and stored in different areas of memory. It is even possible to have several different programs resident concurrently in memory, in different text spaces.

The memory location 18 (decimal) contains a pointer to the first page of the BASIC text. This value is refered to by the system in the following cases:--

1. During line editing in direct mode
2. During a SAVE statement; the save parameters are ?18*256 and TOP
3. During a LOAD command; a new program is loaded to ?18*256
4. During the execution of a GOTO or GOSUB statement or a RUN statement, labels with known values being the exception.

Changing ?18 in programs permits a BASIC program in one text area to call subroutines in a BASIC program in another text area. The value of TOP will not change with use like this, so its use as a memory space allocator and pointer to the end of text in the line editor must be watched carefully.

18.6.1 Calling Subroutines in Different Text Spaces

The following example shows the entering of a subprograrn and main program in different text spaces. First enter a subroutine in the first text space:

      ?18=#82
      NEW
   10 PRINT"TEXT AREA ONE"'
   20 RETURN

Now change the value of the text-space pointer and enter a program; to call this subroutine into the second text space:

      ?18=#83
      NEW
   10 REM CALL SUBROUTINE IN #82
   20 ?18=#82
   30 GOSUB 10
   40 REM PROVE YOU'RE BACK
   50 PRINT"TEXT AREA TWO"'
   60 GOSUB 10
   70 ?18=#83;REM BACK FOREVER
   80 END

Now run the program:

      RUN
TEXT AREA ONE
TEXT AREA TWO
TEXT AREA ONE

Note that switching back to the first text space by typing:

?18=#82

will not change the value of TOP:

    PRINT & TOP'
    8398

To reset TOP, type:

    END
    PRINT & TOP'
    8225

18.7 Renumbering Programs

The following routine can be used to renumber the line-numbers of a program or piece of text. The program and renumber routine must both be in memory at the same time, in different text spaces. Note that the renumber program only renumbers the line numbers; it does not renumber numbers in GOTO or GOSUB statements.

18.7.1 Renumbering in the Expanded ATOM

In an expanded ATOM, with the default text space at #2900, the renumber routine can conveniently be entered at #8200 by typing:

      ?18=#82
      NEW

before loading it from tape, or entering it from the keyboard.

    1 REM Renumber
   10 INPUT"TEXT SPACE TO RENUMBER"Z
   15 Z=Z*256
   20 INPUT"START AT"A,"STEP"B
   30 ?18=Z/256
   40 IFZ?1=255 END
   50 DOZ?1=A/256;Z?2=A;A=A+B
   55 Z=Z+3+LEN(Z+3)
   60 UNTILZ?1=255;END

The program to be renumbered should be in the default text space, #29.
Then RUN the program, and reply to the prompts as follows:

TEXT SPACE TO RENUMBER ?029
START AT?10
STEP?10

The program will switch back to the usual text space, and the renumbered program can be listed.

18.7.2 Renumbering Using the Screen Memory

In an unexpanded ATOM there may be no space in the upper text space to load the renumber program. However, with care, it can be loaded from tape, or typed in, and executed in the area of memory that is displayed on the VDU. The size of the program is about #A0 bytes, which will occupy memory corresponding to about 6 lines of the display. Provided that the cursor is kept below the sixth line of the display, and is not allowed to reach the bottom line of the display when it will cause scrolling, the VDU memory can be safely used as a temporary text space in this way.
First type:

?18=#80

to set the text space to the screen area of memory. Move the cursor to the 6th. line of the display using the edit key, and type:

LOAD "RENUMBER"

Alternatively, enter the program from the keyboard in the usual way. The top few lines of the display will be filled with strange characters, corresponding to the text of the program stored directly in the screen memory. Now type:

RUN

and reply to the prompts of the renumber program as follows (or, as desired):

TEXT SPACE TO RENUMBER?082 START AT?10 STEP?10

When the program has run the screen can be allowed to scroll, corrupting the renumber program, and you can list the renumbered program.

18.8 Trapping Errors

The memory locations 16 and 17 contain a pointer, low byte in 16, high byte in 17, to the start of a BASIC program which is entered whenever an error occurs. In direct mode they are set to point at a program in the interpreter which reads:

@=1;P.$6$7'"ERROR "?0;@=8;IF?1\?2P." LINE"!1& #FFFF 0 P.';E. 

Location 0 contains the error number and locations 1 and 2 contain the line number where the interpreter thinks it occurred. Programs intended to handle errors should store the value of !1 since it is changed whenever a return is executed. The first character in a text space that can be pointed to by ?16 and ?17 is at the start of the text space plus three, and this is the first character of the listed program. All interpreter stacks are cleared after an error but the values of labels are not forgotten.

18.8.1 On Error Goto

To provide a GOTO on an error it is necessary to provide a string containing the GOTO statement, and write the address of this string in locations 16 and 17. For example, to provide a jump to line 170 on an error:

10 DIM A(8) 20 $A="GOTO 170" 30 ?16=A; ?17=A&#FFFF/256

18.8.2 Calculator Program

The following program simulates a desk-top calculator; it will evaluate any expression which is typed in, and any error will cause the message "BAD SYNTAX" to be printed out. The program uses integer BASIC statements, but could easily be modified to use the floating-point extension:

 10 E=TOP; $E="P.""BAD SYNTAX""';G.30"
 20 ?16=E; ?17=E/256
 30 @=0; DO IN.A; P.$320"="A; U.0

Next chapter