ZX 81 - BASIC Programming

Sinclair ZX Spectrum
Appendix C.1 - The ZX81 for those that understand BASIC

General

If you already know BASIC then you should not have much trouble using the ZX81; but it has one or two idiosyncrasies.

    (i) Words are not spelled out, but have keys of their own - this is dealt with in chapter 2 (for keywords & shifted keys) & chapter 5 (for function names). In the text, these words are printed in BOLD TYPE.

    (ii) ZX81 BASIC lacks READ, DATA & RESTORE (but see exercise 3 of chapter 22 concerning this), user-defined functions (FN & DEF; but VAL can sometimes be used), & multi-statement lines.

    (iii) The string handling facilities are comprehensive but non-standard - see chapter 21, & also chapter 22 (for string arrays).

    (iv) The ZX81 character set is completely its own.

    (v) The television display is not in general memory-mapped.

    (vi) If you are accustomed to using PEEK & POKE on a different machine, remember that all the addresses will be different on the ZX81.

Speed

The machine works at two speeds, called compute & display mode, & fast mode.

In compute & display, the television picture is generated continuously & computing is done during the blank parts at the top & bottom.

In fast mode, the television picture is turned off during computing, & is only displayed at the end of the program, while waiting for INPUT data, or during a pause (see PAUSE).

Fast mode runs about four times as fast, & should be used for programs with a lot of computing as opposed to output, or when typing in long programs.

Switching between speeds is done with the FAST & SLOW statements (q.v.).

The keyboard

ZX81 characters comprise not only the single symbols (letters, digits, etc.), but also the compound tokens (keywords, function names, etc.; these are printed here in BOLD TYPE) & all these are entered from the keyboard rather than being spelled out. To fit this in, some keys have up to five distinct meanings, given partly by shifting the keys (i.e. pressing the SHIFT key at the same time as the required one) & partly by having the machine in different modes.

The mode is indicated by the cursor, an inverse video letter that shows where the next character from the keyboard will be inserted.

mode (for keywords) occurs automatically when the machine is expecting a command or program line (rather than INPUT data), & from its position on the line it knows it should expect a line number or a keyword. This is at the beginning of the line, or just after some digits at the beginning of the line, or just after THEN. If unshifted, the next key will be interpreted as either a keyword (these are mostly written above the keys), or a digit.

mode (for letters) normally occurs at all other times. If unshifted, the next key will be interpreted as the main symbol on that key.

In both & modes, shifted keys will be interpreted as the subsidiary red character in the top right-hand corner of the key.

mode (for functions) occurs after FUNCTION (shifted NEWLINE) is pressed, & lasts for one key depression only. That key will be interpreted as a function name, these appearing under the keys.

mode for graphics occurs after GRAPHICS (shifted 9) is pressed, and lasts until it is pressed again. An unshifted key will give the inverse video of its mode interpretation; a shifted key will as well, provided that it is a symbol, but if the shifted key would normally give a token, in graphics mode it gives the graphics symbol that appears in the bottom right hand corner of the key.

The screen

This has 24 lines, each 32 characters long, and is divided into two parts. The top part is at most 22 lines, and displays either a listing or program output. The bottom part, at least two lines, is used for inputting commands, program lines and INPUT data, and also for displaying reports.

Keyboard input: this appears in the bottom half of the screen as it is typed, each character (single symbol or compound token) being inserted just before the cursor. The cursor can be moved left with (shifted 5) or right with (shifted 8). The character before the cursor can be deleted with RUBOUT (shifted 0). (Note:- the whole line can be deleted by typing EDIT (shifted 1) followed by NEWLINE; or, if it is INPUT data, just by typing EDIT.)

When NEWLINE is pressed, the line is executed, entered into the program, or used as INPUT data as appropriate, unless it contains a syntax error. In this case the symbol appears just before the error.

As program lines are entered, a listing is displayed in the top half of the screen. The manner in which the listing is produced is rather complicated, and explained more fully in chapter 9, exercise 6. The last line to be entered is called the current line and indicated by the symbol , but this can be changed using the keys (shifted 6) and (shifted 7). If EDIT (shifted 1) is pressed, the current line is brought down to the bottom part of the screen and can be edited.

When a command is executed or a program run, the screen is first of all cleared, & then output is displayed in the top half of the screen and remains until a program line is entered, or NEWLINE is pressed with an empty line, or or is pressed. In the bottom part appears a report of the form m/n where m is a code showing what happened (see appendix B), & n is the number of the last line executed - or 0 for a command. The report remains until a key is pressed (and indicates mode).

In certain circumstances, the SPACE key acts as a BREAK, stopping the computer with report D. This is recognized

    (i) at the end of a statement while a program is running,

    (ii) while the computer is looking for a program on tape,

or

    (iii) while the computer is using the printer (or by accident trying to use it when it is not there).

Sinclair ZX Spectrum

  Previous Page Back Next Page