Chapter 25: The system variables
The bytes in memory from 23552 to 23733 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 the BASIC. The computer will not recognize the names as referring to system variables, and they are given solely as mnemonics for we humans.
Poking system variables in the BASin editor will not always have the desired effect, because there is a layer of abstraction between BASin and the emulated ZX Spectrum memory.
The abbreviations in column 1 have the following meanings:
X |
The variables should not be poked because the system might crash. |
N |
Poking the variable will have no lasting effect. |
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)
and to peek its value, use the expression
PEEK n+256*PEEK (n+1)
Notes |
Address |
Name |
Contents |
N8 |
23552 |
KSTATE |
Used in reading the keyboard. |
N1 |
23560 |
LAST K |
Stores newly pressed key. |
1 |
23561 |
REPDEL |
Time (in 50ths of a second, in 60ths of a second in N. America) that a key must be held down before it repeats. This starts off at 35, but you can POKE in other values. |
1 |
23562 |
REPPER |
Delay (in 50ths of a second, in 60ths of a second in N. America) between successive repeats of a key held down: initially 5. |
N2 |
23563 |
DEFADD |
Address of arguments of user defined function if one is being evaluated; otherwise 0. |
Nl |
23565 |
K DATA |
Stores 2nd byte of colour controls entered from keyboard. |
N2 |
23566 |
TVDATA |
Stores bytes of coiour, AT and TAB controls going to television. |
X38 |
23568 |
STRMS |
Addresses of channels attached to streams. |
2 |
23606 |
CHARS |
256 less than address of character set (which starts with space and carries on to the copyright symbol). Normally in ROM, but you can set up your own in RAM and make CHARS point to it. |
1 |
23608 |
RASP |
Length of warning buzz. |
1 |
23609 |
PIP |
Length of keyboard click. |
1 |
23610 |
ERR NR |
1 less than the report code. Starts off at 255 (for 1) so PEEK 23610 gives 255. |
X1 |
23611 |
FLAGS |
Various flags to control the BASIC system. |
X1 |
23612 |
TV FLAG |
Flags associated with the television. |
X2 |
23613 |
ERR SP |
Address of item on machine stack to be used as error return. |
N2 |
23615 |
LIST SP |
Address of return address from automatic listing. |
N1 |
23617 |
MODE |
Specifies K, L, C, E or G cursor. |
2 |
23618 |
NEWPPC |
Line to be jumped to. |
|
23620 |
NSPPC |
Statement number in line to be jumped to. Poking first NEWPPC and then NSPPC forces a jump to a specified statement in a line. |
2 |
23621 |
PPC |
Line number of statement currently being executed. |
1 |
23623 |
SUBPPC |
Number within line of statement being executed. |
1 |
23624 |
BORDCR |
Border colour * 8; also contains the attributes normally used for the lower half of the screen. |
2 |
23625 |
E PPC |
Number of current line (with program cursor). |
X2 |
23627 |
VARS |
Address of variables. |
N2 |
23629 |
DEST |
Address of variable in assignment. |
X2 |
23631 |
CHANS |
Address of channel data. |
X2 |
23633 |
CURCHL |
Address of information currently being used for input and output. |
X2 |
23635 |
PROG |
Address of BASIC program. |
X2 |
23637 |
NXTLIN |
Address of next line in program. |
X2 |
23639 |
DATADD |
Address of terminator of last DATA item. |
X2 |
23641 |
E LINE |
Address of command being typed in. |
2 |
23643 |
K CUR |
Address of cursor. |
X2 |
23645 |
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. |
2 |
23647 |
X PTR |
Address of the character after the ? syntax error marker in traditional 48K BASIC. |
X2 |
23649 |
WORKSP |
Address of temporary work space. |
X2 |
23651 |
STKBOT |
Address of bottom of calculator stack. |
X2 |
23653 |
STKEND |
Address of start of spare space. |
N1 |
23655 |
BREG |
Calculator's b register. |
N2 |
23656 |
MEM |
Address of area used for calculator's memory. (Usually MEMBOT, but not always.) |
|
23658 |
FLAGS2 |
More flags. |
X1 |
23659 |
DF SZ |
The number of lines (including one blank line) in the lower part of the screen. |
2 |
23660 |
S TOP |
The number of the top program line in automatic listings. |
2 |
23662 |
OLDPPC |
Line number to which CONTINUE jumps. |
|
23664 |
OSPCC |
Number within line of statement to which CONTINUE jumps. |
N1 |
23665 |
FLAGX |
Various flags. |
N2 |
23666 |
STRLEN |
Length of string type destination in assignment. |
N2 |
23668 |
T ADDR |
Address of next item in syntax table (very unlikely to be useful). |
2 |
23670 |
SEED |
The seed for RND. This is the variable that is set by RANDOMIZE. |
3 |
23672 |
FRAMES |
3 byte (least significant first), frame counter. Incremented every 20ms. See Chapter 18. |
2 |
23675 |
UDG |
Address of 1st user defined graphic. You can change this for instance to save space by having fewer user defined graphics. |
1 |
23677 |
COORDS |
x-coordinate of last point plotted. |
1 |
23678 |
|
y-coordinate of last point plotted. |
1 |
23679 |
P POSN |
33 column number of printer position. |
X2 |
23680 |
PR CC |
Full address of next position for LPRINT to print at (in printer buffer). |
2 |
23682 |
ECHO E |
33 column number and 24 line number (in lower half) of end of input buffer. |
2 |
23684 |
DF CC |
Address in display file of PRINT position. |
2 |
23686 |
DFCCL |
Like DF CC for lower part of screen. |
X1 |
23688 |
S POSN |
33 column number for PRINT position. |
X1 |
23689 |
|
24 line number for PRINT position. |
X2 |
23690 |
SPOSNL |
Like S POSN for lower part. |
|
23692 |
SCR CT |
Counts scrolls: it is always 1 more than the number of scrolls that will be done before stopping with scroll? If you keep poking this with a number bigger than 1 (say 255), the screen will scroll on and on without asking you. |
1 |
23693 |
ATTR P |
Permanent current colours, etc (as set up by colour statements). |
1 |
23694 |
MASK P |
Used for transparent colours, etc. Any bit that is 1 shows that the corresponding attribute bit is taken not from ATTR P, but from what is already on the screen. |
N1 |
23695 |
ATTR T |
Temporary current colours, etc (as set up by colour items). |
N1 |
23696 |
MASK T |
Like MASK P, but temporary. |
|
23697 |
P FLAG |
More flags. |
N30 |
23698 |
MEMBOT |
Calculator's memory area; used to store numbers that cannot conveniently be put on the calculator stack. |
2 |
23728 |
|
Used for the NMI in the +3 and +2A, and by the Interface 1. |
2 |
23730 |
RAMTOP |
Address of last byte of BASIC system area. |
2 |
23732 |
P RAMT |
Address of last byte of physical RAM. |
This program tells you the first 22 bytes of the variables area:
10 FOR n=0 TO 21 20 PRINT PEEK (PEEK 23627+256*PEEK 23628+n) 30 NEXT n
Try to match up the control variable n with the descriptions above. Now change line 20 to
20 PRINT PEEK (23755+n)
This tells you the first 22 bytes of the program area. Match these up with the program itself.