The bytes in memory from 16384 to 16508 are set aside for specific uses by the system. You can peek them to find out various things about the system, and some of them can be usefully poked. They are listed here with their uses.
These are called system variables, and have names, but do not confuse them with the variables used by BASIC. The computer will not recognize the names as referring to system variables, and they are given solely as mnemonics for you humans.
The abbreviations in column 1 have the following meanings:
X The variable should not be poked because the system might
crash.
N Poking the variable will have no lasting effect.
S The variable is saved by SAVE.
The number in column 1 is the number of bytes in the variable. For two bytes, the first one is the less significant byte - the reverse of what you might expect. So to poke a value v to a two-byte variable at address n, use
POKE n,v-256*INT (v/256)
POKE n+1,INT (v/256)
& to peek its value, use the expression
PEEK n + 256*PEEK (n+1)
| Notes | Address | Name | Contents | |
| Decimal | Hex | |||
| 1 | 16384 | 4000 | ERR_NR | 1 less than the report code. Starts off
at 255 (for - 1), so PEEK 16384, if it works at
all, gives 255. POKE 16384,n can be used to force
an error halt: 0 15 <= n <= 34 or 99 <= n <= 127 gives a non-standard report, and 35 <= n <= 98 is liable to mess up the display file. |
| X1 | 16385 | 4001 | FLAGS | Various flags to control the BASIC
system. Bit 0: Suppression of leading space. Bit 1: Control Flag for the printer. Bit 2: Selects K or F mode; or, F or G Bit 6: FP no. or string parameters. Bit 7: Reset during syntax checking. |
| X2 | 16386 | 4002 | ERR_SP | Address of first item on machine stack (after GOSUB returns). |
| 2 | 16388 | 4004 | RAMTOP | Address of first byte above BASIC system area. You can poke this to make NEW reserve space above that area (see chapter 26) or to fool CLS into setting up a minimal display file (chapter 27). Poking RAMTOP has no effect until one of these two is executed. |
| N1 | 16390 | 4006 | MODE | Specified K, L, F or G cursor. |
| N2 | 16391 | 4007 | PPC | Line number of statement currently being
executed. Poking this has no lasting effect except in the last line of the program. |
| S1 | 16393 | 4009 | VERSN | 0 Identifies ZX81 BASIC in saved programs. |
| S2 | 16394 | 400A | E_PPC | Number of current line (with program cursor). |
| SX2 | 16396 | 400C | D_FILE | See chapter 27. |
| S2 | 16398 | 400E | DF_CC | Address of PRINT position in
display file. Can be poked so that PRINT output is sent elsewhere. |
| SX2 | 16400 | 4010 | VARS | See chapter 27. Ptr. to variable area. |
| SN2 | 16402 | 4012 | DEST | Address of variable in assignment. |
| SX2 | 16404 | 4014 | E_LINE | See chapter 27. Ptr. to workspace. |
| SX2 | 16406 | 4016 | CH_ADD | Address of the next character to be interpreted: the character after the argument of PEEK, or the NEWLINE at the end of a POKE statement. |
| S2 | 16408 | 4018 | X_PTR | Address of the character preceding
the |
| SX2 | 16410 | 401A | STKBOT | See chapter 27. Ptr. to calculator stack bottom. |
| SX2 | 16412 | 401C | STKEND | See chapter 27. Ptr. to calculator stack end. |
| SN1 | 16414 | 401E | BERG | Calculator's b register. Used for many different counting purposes |
| SN2 | 16415 | 401F | MEM | Address of area used for calculator's
memory. (Usually MEMBOT, but not always.) |
| S1 | 16417 | 4021 | not used | Unused by ZX BASIC. Or FLAG Y for G007 |
| SX1 | 16418 | 4022 | DF_SZ | The number of lines (including one blank line) in the lower part of the screen. |
| S2 | 16419 | 4023 | S_TOP | The number of the top program line in automatic listings. |
| SN2 | 16421 | 4025 | LAST_K | Shows which keys pressed. |
| SN1 | 16423 | 4027 | DEBOUNCE | Debounce status of keyboard. |
| SN1 | 16424 | 4028 | MARGIN | Number of blank lines above or below picture: 55 in Britain, 31 in America. |
| SX2 | 16425 | 4029 | NXTLIN | Address of next program line to be executed. |
| S2 | 16427 | 402B | OLDPPC | Line number of which CONT jumps. |
| SN1 | 16429 | 402D | FLAGX | Various flags. Bit 0: Reset indicates an arrayed variable Bit 1: Reset indicates a given variable exists Bit 5: Set during INPUT mode Bit 7: Set when INPUT is to be numeric |
| SN2 | 16430 | 402E | STRLEN | Length of string type destination in
assignment. Length of a string, or a BASIC line |
| SN2 | 16432 | 4030 | T_ADDR | Address of next item in syntax table
(very unlikely to be useful). Ptr. to 'parameter table. & distinguishes between PLOT & UNPLOT |
| S2 | 16434 | 4032 | SEED | The seed for RND. This is the variable that is set by RAND. |
| S2 | 16436 | 4034 | FRAMES | Counts the frames displayed on the television. Bit 15 is 1. Bits 0 to 14 are decremented for each frame set to the television. This can be used for timing, but PAUSE also uses it. PAUSE resets to 0 bit 15, & puts in bits 0 to 14 the length of the pause. When these have been counted down to zero, the pause stops. If the pause stops because of a key depression, bit 15 is set to 1 again. |
| S1 | 16438 | 4036 | COORDS | x-coordinate of last point PLOTted. |
| S1 | 16439 | 4037 | y-coordinate of last point PLOTted. | |
| S1 | 16440 | 4038 | PR_CC | Less significant byte of address of next position for LPRINT to print as (in PRBUFF). |
| SX1 | 16441 | 4039 | S_POSN | Column number for PRINT position. |
| SX1 | 16442 | 403A | Line number for PRINT position. | |
| S1 | 16443 | 403B | CDFLAG | Various flags. Bit 7 is on (1) during
compute & display mode. Bit 6 - the true fast/slow flag Bit 7 - copy of the fast/slow flag. RESET when FAST needed |
| S33 | 16444 | 403C | PRBUFF | Printer buffer (33rd character is NEWLINE). |
| SN30 | 16477 | 405D | MEMBOT | Calculator's memory area; used to store
numbers that cannot conveniently be put on the calculator
stack. |
| S2 | 16507 | 407B | not used | Or RESTART to G007 |
| 16509 | 407D | PROGRAM | The BASIC program starts here | |
1. Try this program
10 FOR N=0 TO 21
20 PRINT PEEK (PEEK 16400+256*PEEK 16401+N)
30 NEXT N
This tells you the first 22 bytes of the variables area: try to match up the control variable N with the description in chapter 27.
2. In the program above, change line 20 to
20 PRINT PEEK (16509+N)
This tells you the fist 22 bytes of the program area. Match these up with the program itself.