Sinclair ZX81 Basic

Basic

All but one of the ZX80's Basic functions, plus a substantial number of additions, have been incorporated into the 8k ROM which drives the ZX81. The following commands and statements are provided over and above the, old ZX80 repertoire: ASN, ACS, ATN, COS, EXP, INKEY$, PI, SGN, SIN, SQR, INT, LEN, LN, TAN, VAL, <=, >=, < >, COPY, DIM A$, FAST, FOR... TO... STEP, LLIST, LLIST n, LPRINT, PAUSE, PLOT, PRINT AT, PRINT TAB, SCROLL, SLOW, UNPLOT. The missing function is TL$, which was used to return a string minus its first character. This ROM plus an appropriate keypad overlay is available to existing ZX80 users who wish to upgrade their machine. They should note, however, that even with the new ROM they will continue to get the screen flicker which, I'm sure, they've grown to know and love by now.

Binary Operations

+ - * I ** ~ > <- <~ > <>


Statements (all except INPUT may be used as commands)

CLEAR CLS CONT COPY DIM FAST FOR. .TO. .(STEP) GOSUB GOTO IF. .THEN INPUT LET LIST LLIST LOAD LPRINT NEW NEXT PAUSE PLOT POKE PRINT (TAB) (AT) RAND REM RETURN RUN SAVE SCROLL SLOW STOP UNPLOT


Functions

ABS ACS AND ASN ATN CHR$ CODE COS EXP INKEY$ INT LEN LN NOT OR PEEK PI RND SGN SIN SQR STR$ TAN USR VAL

The machine can be operated in two modes - SLOW (sometimes called 'compute and display'), and FAST. FAST mode offers the world famous screen flicker every time you hit a key, while SLOW mode keeps the screen refreshed at all times, resulting in a nicer display, moving graphics and a lot of irritating delays: see the Benchmarks for comparisons. If you need to see the screen continuously then SLOW mode is a boon. If you don't, say if you were doing lots of calculations, then it's better to use the FAST mode. The two can be called from within a program, thus offering the best of both worlds. The SCROLL feature removes the top line from the screen and moves each line up, leaving a blank bottom line. Without SCROLL, the display freezes when the bottom line is reached. A PAUSE instruction is provided which suspends a program's operation for a user-defined period or until a key is depressed. The screen is visible when in PAUSE mode, regardless of whether the program is running FAST or SLOW. In SLOW mode the screen flickers siightly when the PAUSE takes effect but in FAST mode it has to come on altogether. This means that you'll have to be careful not to have your PAUSEs too close together, unless you actually enjoy watching the screen going absolutely bananas. The INKEY$ function is welcome since it can be tested to see if a key is being depressed and, if so, which key it is. This feature is great for fast-moving games since you need only hit the key you're interested in - there's 'no need to hit NEWLINE.

There are no DATA or READ instructions but this can be circumvented by saving a program with all its associated variables and then using a GOTO to kick the program off when it's reloaded. (RUN automatically clears any variables.) Pressing CONT, not surprisingly, allows you to continue the program. PLOT and UNPLOT functions (0,0 is in the bottom left.hand corner) are provided, giving a graphics capability of 44 by 64 points. Each point, or pixel (picture element), is a quarter the size of a normal character. Hardly high resolution but better 1han a poke in the eye with a sharp stick!

The cassette needs either 35mm sockets or an appropriate adaptor. SA VE is offered but no VERIFY, so saving a long program can be a bit worrying. I suggest you first save a few short programs, just to make sure the controls are set properly. When loading a program, the pattern on the screen shows you when data is being recognised. The theory of cassette adjustment is that you playa data tape, gradually turning the volume up until the pattern appears. Then you turn it up a little more and it should be ready for use.

The printer, when it arrives, will allow you to LPRINT and LLIST data and programs respectively. Even better, it will allow you to dump the screen contents to the printer using the COPY command either within the program or as an immediate instruction. Such a screen copy takes about 12 seconds to produce.

The only function to disappear is the TL$ command mentioned earlier. The same thing can be accomplished using the LEN and TO instructions. All trigonometric stuff is in radians and PI is provided to help you unravel the results. SGN = signum which can possess one of three values: -1, 0 and +1. At one stage the new ROM (for the ZX80 and, subsequently, for the ZX81) was expected to offer DRAW, UNDRAW, DATA, READ and RESTORE features. Instead I think the idea of adding printing facilities became more important. After all, these features can be realised using the existing range of commands.

A character string of any length may be used as a numeric variable name, providing it starts with a letter. String variable names are restricted to A$ to Z$. String and numeric arrays may be any number of dimensions - the limit is dictated by the amount of free memory available. String arrays are character arrays really, with the last entry in a DIM statement being the number of characters per array element. With a full 16k RAM and a small program (it fitted on the screen) I set up a string array 100 x 6 x 25 characters long. I used this since each element would be about the size of a name and address record, allowing extra information like telephone number and birthday, for example. Substrings are handled using the TO function. LET A$=B$ (3 TO 5) would make A$ a three character string comprising the third to fifth characters of string B$. This open up possibilities for giant strings and the use of string slicing to extract variable length fields.

<< Software : Previous

Next : Documentation >>

apj home > technology > Sinclair ZX81 > Basic © 2007 Seamus Waldron