Pages 271–274 · Markdown
Certain locations in memory are set aside for specific uses by the system. There are a few routines (used to keep the paging in order), and some locations called system variables (or SYSVARS). You can use PEEK and DPEEK to read them, in order to find out various things about the system, and on some of them you can usefully change with POKE and DPOKE. They are listed here with their uses.
The area occupied by SYSVARS spans the addresses 23296 (5B00h) to 23733 (5CB5h) (inclusive) and a subset of them are used in 48K BASIC – addresses 23552 (5C00h) to 23733 (5CB5h).
Note that in 48K mode, there is a buffer area between 23296 (5B00h) and 23552 (5C00h) which was used for controlling the printer. This was quite a popular location for small machine code programs on the old 48K Spectrum and if any of these routines are tried in NextBASIC, the computer will invariably crash. It's advisable that any 48K BASIC program that uses PEEK, POKE and USR to either be run in 48K BASIC mode (although it can be entered in NextBASIC mode and transferred using the SPECTRUM command) or examined thoroughly and converted so it won't use any of these commands. Alternatively, any machine code routine embedded within it should be moved to a safer area.
The system variables listed below, all have unique names, but do not confuse them with NextBASIC variables. The computer will not recognize the names as referring to system variables, and they are given solely as mnemonics to be human-readable.
The abbreviations in column 1 of the table that follows 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
R Routine entry point. Not a variable.
The number in column 1 is the number of bytes in the variable. For two bytes, the first one is the least significant byte; the reverse of what you might expect. So to POKE a value v to a two byte variable at address n, use DPOKE instead, as it does the conversion for you. Otherwise you'll need to enter the following for SYSVAR n value v:
POKE n,v-256*INT (v/256)
POKE n+1,INT (v/256)
and to peek its value, either use DPEEK or the expression:
PEEK n+256*PEEK (n+1)
| Notes | Address | Name | Description | |
|---|---|---|---|---|
| Hex | Dec | |||
| R16 | 5B00 | 23296 | SWAP | Paging subroutine |
| R17 | 5B10 | 23312 | STOO | Paging subroutine. Entered with interrupts already disabled and AF, BC on the stack. |
| R9 | 5B21 | 23329 | YOUNGER | Paging subroutine |
| R16 | 5B2A | 23338 | REGNUOY | Paging subroutine |
| R24 | 5B3A | 23354 | ONERR | Paging subroutine |
| X2 | 5B52 | 23378 | OLDHL | Temporary register store while switching ROMs |
| X2 | 5B54 | 23380 | OLDBC | Temporary register store while switching ROMs |
| X2 | 5B56 | 23382 | OLDAF | Temporary register store while switching ROMs |
| X1 | 5B58 | 23384 | CACHEBNK | 8K Bank ID holding cached program data |
| N1 | 5859 | 23385 | Reserved for system use | |
| Notes | Address | Name | Description | |
|---|---|---|---|---|
| Hex | Dec | |||
| X2 | 5B5A | 23386 | RETADDR | Return address in ROM 1 |
| X1 | 5B5C | 23388 | BANKM | Copy of last byte output to I/O port 7FFDh (32765). See Chapter 23 – The Memory. This byte must be kept up to date with the last value output to the port if interrupts are enabled |
| X1 | 5B5D | 23389 | RAMRST | RST 8 instruction. Used by ROM 1 to report old errors to ROM 3 |
| N1 | 5B5E | 23390 | RAMERR | Error number passed from ROM 1 to ROM 3. Also used by SAVE/LOAD as temporary drive store |
| 1 | 5B5F | 23391 | INKL | INK colour for LoRes |
| 1 | 5B60 | 23392 | INK2 | INK colour for Layer 2 |
| 1 | 5B61 | 23393 | ATTRULA | Attributes for standard mode |
| 1 | 5B62 | 23394 | ATTRHR | Attributes for HiRes (only paper colour in bits 5:3 is used) |
| 1 | 5B63 | 23395 | ATTRHC | Attributes for HiColour |
| 1 | 5B64 | 23396 | INKMASK | Softcopy of EnhancedULA InkMask (or 0) |
| N1 | 5B65 | 23397 | LSBANK | Temporary bank number in LOAD/SAVE and other operations |
| 1 | 5B66 | 23398 | FLAGS3 | Various flags. Bits 0, 1, 6 and 7 unlikely to be useful. Bit 2 is set when tokens are to be expanded on printing. Bit 3 is set if print output is RS232. The default (at reset) is Centronics. Bit 4 is set if a disk interface is present. Bit 5 is set if drive B: is present |
| X1 | 5B67 | 23399 | BANK678 | Copy of last byte output to I/O port 1FFDh (8189). This port is used to control the +3 extended RAM and ROM switching (bits 0..2 – if bit 0 is 0 then bit 2 controls the 'vertical' ROM switch 02 and 13), the disk motor (bit 3) and Centronics strobe (bit 4). This byte must be kept up to date with the last value output to the port if interrupts are enabled |
| X1 | 5B68 | 23400 | FLAGN | Flags for the NextZXOS system |
| 1 | 5B69 | 23401 | MAXBNK | Maximum available RAM bank |
| X2 | 5B6A | 23402 | OLDSP | Old SP (stack pointer) when TSTACK is in use |
| X2 | 5B6C | 23404 | SYNRET | Return address for ONERR |
| 5 | 5B6E | 23406 | LASTV | Last value printed by calculator |
| 1 | 5B73 | 23411 | TILEBNKL | Tiles bank for LoRes |
| 1 | 5B74 | 23412 | TILEML | Tilemap bank for LoRes |
| 1 | 5B75 | 23413 | TILEBNK2 | Tiles bank for Layer2 |
| 1 | 5B76 | 23414 | TILEM2 | Tilemap bank for Layer2 |
| X1 | 5B77 | 23415 | NXTBNK | Bank containing NXTLIN |
| X1 | 5B78 | 23416 | DATABNK | Bank containing DATADD |
| 1 | 5B79 | 23417 | LODDRV | Holds 'T' if LOAD, VERIFY, MERGE are from tape, otherwise holds 'A', 'B' or 'M' |
| 1 | 5B7A | 23418 | SAVDRV | Holds 'T' if SAVE is to tape, otherwise holds 'A', 'B' or 'M' |
| N1 | 5B7B | 23419 | L2SOFT | Softcopy of Layer 2 port |
| 2 | 5B7C | 23420 | TILEWL | Width of LoRes tilemap |
| 2 | 5B7E | 23422 | TILEW2 | Width of Layer 2 tilemap |
| 2 | 5B80 | 23424 | TILEOFFL | Offset in bank for LoRes tilemap |
| 2 | 5B82 | 23426 | TILEOFF2 | Offset in bank for Layer 2 tilemap |
| 2 | 5B84 | 23428 | COORDSX | X Coordinate of last point plotted (Layer 1/2) |
| 2 | 5B86 | 23430 | COORDSY | Y Coordinate of last point plotted (Layer 1/2) |
| 1 | 5B88 | 23432 | PAPERL | PAPER colour for LoRes mode |
| 1 | 5B89 | 23433 | PAPER2 | PAPER colour for Layer 2 mode |
| Nx | 5B8A | 23434 | TMPVARS | Base of temporary system variables (space shared with bottom of TSTACK) |
| Notes | Address | Name | Description | |
|---|---|---|---|---|
| Hex | Dec | |||
| X117 | 5BFF | 23551 | TSTACK | Temporary stack grows down from here. Used when RAM bank 7 is switched in at top of memory while executing the editor or calling NextZXOS. It may safely go down to 5B8Ah if necessary. This guarantees at least 117 bytes of stack when NextBASIC calls NextZXOS |
| N8 | 5C00 | 23552 | KSTATE | Used in reading the keyboard |
| N1 | 5C08 | 23560 | LASTK | Stores newly pressed key |
| 1 | 5C09 | 23561 | REPDEL | Time (in 50ths of a second) that a key must be held down before it repeats. This starts off at 35, but you can POKE in other values |
| 1 | 5C0A | 23562 | REPPER | Delay (in 50ths of a second) between successive repeats of a key held down – initially 5) |
| X2 | 5C0B | 23563 | RETVARS | Address of local variables on return stack |
| N1 | 5C0D | 23565 | K_DATA | Stores 2nd byte of colour controls entered from keyboard |
| N2 | 5C0E | 23566 | TVDATA | Stores bytes of colour, AT and TAB controls going to TV |
| X38 | 5C10 | 23568 | STRMS | Addresses of channels attached to streams |
| 2 | 5C36 | 23606 | CHARS | 256 less than address of character set (which starts with space and carries on until ©). Normally in ROM, but you can set up your own in RAM and make CHARS point to it |
| 1 | 5C38 | 23608 | RASP | Length of warning buzz |
| 1 | 5C39 | 23609 | PIP | Length of keyboard click |
| 1 | 5C3A | 23610 | ERRNR | 1 less than the report code. Starts off at 255 (for -1) so PEEK 23610 gives 255 |
| X1 | 5C3B | 23611 | FLAGS | Various flags to control the NextBASIC system |
| X1 | 5C3C | 23612 | TVFLAG | Flags associated with the TV |
| X2 | 5C3D | 23613 | ERRSP | Address of item on machine stack to be used as error return |
| N2 | 5C3F | 23615 | Reserved for system use | |
| N1 | 5C41 | 23617 | MODE | Specifies K, L, C, E or G cursor. |
| 2 | 5C42 | 23618 | NEWPPC | Line to be jumped to |
| N1 | 5C44 | 23620 | Reserved for system use | |
| 2 | 5C45 | 23621 | PPC | Line number of statement currently being executed |
| 1 | 5C47 | 23623 | SUBPPC | Number within line of statement currently being executed |
| 1 | 5C48 | 23624 | BORDCR | Border colour multiplied by 8; also contains the attributes normally used for the lower half of the screen |
| 2 | 5C49 | 23625 | E_PPC | Number of current line (with program cursor) |
| X2 | 5C4B | 23627 | VARS | Address of variables |
| N2 | 5C4D | 23629 | DEST | Address of variable in assignment |
| X2 | 5C4F | 23631 | CHANS | Address of channel data |
| X2 | 5C51 | 23633 | CURCHL | Address of information currently being used for input and output |
| X2 | 5C53 | 23635 | PROG | Address of NextBASIC program |
| X2 | 5C55 | 23637 | NXTLIN | Address of next line in program |
| X2 | 5C57 | 23639 | DATADD | Address of terminator of last DATA item |
| X2 | 5C59 | 23641 | E_LINE | Address of command being typed in |
| 2 | 5C5B | 23643 | K_CUR | Address of cursor |
| X2 | 5C5D | 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 | 5C5F | 23647 | X_PTR | Address of the character after the ? marker |
| X2 | 5C61 | 23649 | WORKSP | Address of temporary work space |
| X2 | 5C63 | 23651 | STKBOT | Address of bottom of calculator stack |
| X2 | 5C65 | 23653 | STKEND | Address of start of spare space |
| N1 | 5C67 | 23655 | BREG | Calculator's B register |
| Notes | Address | Name | Description | |
|---|---|---|---|---|
| Hex | Dec | |||
| N2 | 5C68 | 23656 | MEM | Address of area used for calculator's memory (usually MEMBOT, but not always) |
| 1 | 5C6A | 23658 | FLAGS2 | More flags. (Bit 3 set when CAPS SHIFT or CAPS LOCK is on) |
| X1 | 5C6B | 23659 | DF_SZ | The number of lines (including one blank line) in the lower part of the screen |
| N2 | 5C6C | 23660 | Reserved for system use | |
| 2 | 5C6E | 23662 | OLDPPC | Line number to which CONTINUE jumps |
| 1 | 5C70 | 23664 | OSPPC | Number within line of statement to which CONTINUE jumps |
| N1 | 5C71 | 23665 | FLAGX | Various flags |
| N2 | 5C72 | 23666 | STRLEN | Length of string type destination in assignment |
| N2 | 5C74 | 23668 | T_ADDR | Address of next item in syntax table (very unlikely to be useful) |
| 2 | 5C76 | 23670 | SEED | The seed for RND. This is the variable that is set by RANDOMIZE |
| 3 | 5C78 | 23672 | FRAMES | 3 byte (least significant byte first), frame counter incremented every 20ms |
| 2 | 5C7B | 23675 | UDG | Address of first user-defined graphic. You can change this, for instance, to save space by having fewer user-defined characters |
| 1 | 5C7D | 23677 | COORDS | X-coordinate of last point plotted |
| 1 | 5C7E | 23678 | Y-coordinate of last point plotted | |
| X1 | 5C7F | 23679 | GMODE | Graphical layer/mode flags |
| X1 | 5C80 | 23680 | PRCC | Full address of next position for LPRINT to print at (in ZX Printer buffer). Legal values 5B00 – 5B1F1 |
| 1 | 5C81 | 23681 | STIMEOUT | Screensaver control |
| 2 | 5C82 | 23682 | ECHO_E | 33-column number and 24 line number (in lower half) of end of input buffer |
| 2 | 5C84 | 23684 | DF_CC | Address in display file of PRINT position |
| 2 | 5C86 | 23686 | DF_CCL | Like DF_CC for lower part of screen |
| X1 | 5C88 | 23688 | S_POSN | 33-column number for PRINT position |
| X1 | 5C89 | 23689 | 24-line number for PRINT position | |
| X2 | 5C8A | 23690 | SPOSNL | Like S_POSN for lower part |
| 1 | 5C8C | 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 | 5C8D | 23693 | ATTR_P | Permanent current colours, etc., (as set up by colour statements) |
| 1 | 5C8E | 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 | 5C8F | 23695 | ATTR_T | Temporary current colours, etc., (as set up by colour items) |
| N1 | 5C90 | 23696 | MASK_T | Like MASK_P, but temporary |
| 1 | 5C91 | 23697 | P_FLAG | More flags |
| N30 | 5C92 | 23698 | MEMBOT | Calculator's memory area – used to store numbers that cannot conveniently be put on the calculator stack |
| 2 | 5CB0 | 23728 | Not used | |
| 2 | 5CB2 | 23730 | RAMTOP | Address of last byte of NextBASIC system area. |
| 2 | 5CB4 | 23732 | P_RAMT | Address of last byte of physical RAM. |
1 Not used in 128K mode or when certain peripherals are attached
ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.