Pages 271–274 · Markdown

Chapter 24 – The System Variables

Overview

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.

System Variables

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)
NotesAddressNameDescription
HexDec
R165B0023296SWAPPaging subroutine
R175B1023312STOOPaging subroutine. Entered with interrupts already disabled and AF, BC on the stack.
R95B2123329YOUNGERPaging subroutine
R165B2A23338REGNUOYPaging subroutine
R245B3A23354ONERRPaging subroutine
X25B5223378OLDHLTemporary register store while switching ROMs
X25B5423380OLDBCTemporary register store while switching ROMs
X25B5623382OLDAFTemporary register store while switching ROMs
X15B5823384CACHEBNK8K Bank ID holding cached program data
N1585923385Reserved for system use
NotesAddressNameDescription
HexDec
X25B5A23386RETADDRReturn address in ROM 1
X15B5C23388BANKMCopy 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
X15B5D23389RAMRSTRST 8 instruction. Used by ROM 1 to report old errors to ROM 3
N15B5E23390RAMERRError number passed from ROM 1 to ROM 3. Also used by SAVE/LOAD as temporary drive store
15B5F23391INKLINK colour for LoRes
15B6023392INK2INK colour for Layer 2
15B6123393ATTRULAAttributes for standard mode
15B6223394ATTRHRAttributes for HiRes (only paper colour in bits 5:3 is used)
15B6323395ATTRHCAttributes for HiColour
15B6423396INKMASKSoftcopy of EnhancedULA InkMask (or 0)
N15B6523397LSBANKTemporary bank number in LOAD/SAVE and other operations
15B6623398FLAGS3Various 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
X15B6723399BANK678Copy 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
X15B6823400FLAGNFlags for the NextZXOS system
15B6923401MAXBNKMaximum available RAM bank
X25B6A23402OLDSPOld SP (stack pointer) when TSTACK is in use
X25B6C23404SYNRETReturn address for ONERR
55B6E23406LASTVLast value printed by calculator
15B7323411TILEBNKLTiles bank for LoRes
15B7423412TILEMLTilemap bank for LoRes
15B7523413TILEBNK2Tiles bank for Layer2
15B7623414TILEM2Tilemap bank for Layer2
X15B7723415NXTBNKBank containing NXTLIN
X15B7823416DATABNKBank containing DATADD
15B7923417LODDRVHolds 'T' if LOAD, VERIFY, MERGE are from tape, otherwise holds 'A', 'B' or 'M'
15B7A23418SAVDRVHolds 'T' if SAVE is to tape, otherwise holds 'A', 'B' or 'M'
N15B7B23419L2SOFTSoftcopy of Layer 2 port
25B7C23420TILEWLWidth of LoRes tilemap
25B7E23422TILEW2Width of Layer 2 tilemap
25B8023424TILEOFFLOffset in bank for LoRes tilemap
25B8223426TILEOFF2Offset in bank for Layer 2 tilemap
25B8423428COORDSXX Coordinate of last point plotted (Layer 1/2)
25B8623430COORDSYY Coordinate of last point plotted (Layer 1/2)
15B8823432PAPERLPAPER colour for LoRes mode
15B8923433PAPER2PAPER colour for Layer 2 mode
Nx5B8A23434TMPVARSBase of temporary system variables (space shared with bottom of TSTACK)
NotesAddressNameDescription
HexDec
X1175BFF23551TSTACKTemporary 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
N85C0023552KSTATEUsed in reading the keyboard
N15C0823560LASTKStores newly pressed key
15C0923561REPDELTime (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
15C0A23562REPPERDelay (in 50ths of a second) between successive repeats of a key held down – initially 5)
X25C0B23563RETVARSAddress of local variables on return stack
N15C0D23565K_DATAStores 2nd byte of colour controls entered from keyboard
N25C0E23566TVDATAStores bytes of colour, AT and TAB controls going to TV
X385C1023568STRMSAddresses of channels attached to streams
25C3623606CHARS256 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
15C3823608RASPLength of warning buzz
15C3923609PIPLength of keyboard click
15C3A23610ERRNR1 less than the report code. Starts off at 255 (for -1) so PEEK 23610 gives 255
X15C3B23611FLAGSVarious flags to control the NextBASIC system
X15C3C23612TVFLAGFlags associated with the TV
X25C3D23613ERRSPAddress of item on machine stack to be used as error return
N25C3F23615Reserved for system use
N15C4123617MODESpecifies K, L, C, E or G cursor.
25C4223618NEWPPCLine to be jumped to
N15C4423620Reserved for system use
25C4523621PPCLine number of statement currently being executed
15C4723623SUBPPCNumber within line of statement currently being executed
15C4823624BORDCRBorder colour multiplied by 8; also contains the attributes normally used for the lower half of the screen
25C4923625E_PPCNumber of current line (with program cursor)
X25C4B23627VARSAddress of variables
N25C4D23629DESTAddress of variable in assignment
X25C4F23631CHANSAddress of channel data
X25C5123633CURCHLAddress of information currently being used for input and output
X25C5323635PROGAddress of NextBASIC program
X25C5523637NXTLINAddress of next line in program
X25C5723639DATADDAddress of terminator of last DATA item
X25C5923641E_LINEAddress of command being typed in
25C5B23643K_CURAddress of cursor
X25C5D23645CH_ADDAddress of the next character to be interpreted – the character after the argument of PEEK, or the NEWLINE at the end of a POKE statement
25C5F23647X_PTRAddress of the character after the ? marker
X25C6123649WORKSPAddress of temporary work space
X25C6323651STKBOTAddress of bottom of calculator stack
X25C6523653STKENDAddress of start of spare space
N15C6723655BREGCalculator's B register
NotesAddressNameDescription
HexDec
N25C6823656MEMAddress of area used for calculator's memory (usually MEMBOT, but not always)
15C6A23658FLAGS2More flags. (Bit 3 set when CAPS SHIFT or CAPS LOCK is on)
X15C6B23659DF_SZThe number of lines (including one blank line) in the lower part of the screen
N25C6C23660Reserved for system use
25C6E23662OLDPPCLine number to which CONTINUE jumps
15C7023664OSPPCNumber within line of statement to which CONTINUE jumps
N15C7123665FLAGXVarious flags
N25C7223666STRLENLength of string type destination in assignment
N25C7423668T_ADDRAddress of next item in syntax table (very unlikely to be useful)
25C7623670SEEDThe seed for RND. This is the variable that is set by RANDOMIZE
35C7823672FRAMES3 byte (least significant byte first), frame counter incremented every 20ms
25C7B23675UDGAddress of first user-defined graphic. You can change this, for instance, to save space by having fewer user-defined characters
15C7D23677COORDSX-coordinate of last point plotted
15C7E23678Y-coordinate of last point plotted
X15C7F23679GMODEGraphical layer/mode flags
X15C8023680PRCCFull address of next position for LPRINT to print at (in ZX Printer buffer). Legal values 5B00 – 5B1F1
15C8123681STIMEOUTScreensaver control
25C8223682ECHO_E33-column number and 24 line number (in lower half) of end of input buffer
25C8423684DF_CCAddress in display file of PRINT position
25C8623686DF_CCLLike DF_CC for lower part of screen
X15C8823688S_POSN33-column number for PRINT position
X15C892368924-line number for PRINT position
X25C8A23690SPOSNLLike S_POSN for lower part
15C8C23692SCR_CTCounts 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
15C8D23693ATTR_PPermanent current colours, etc., (as set up by colour statements)
15C8E23694MASK_PUsed 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
N15C8F23695ATTR_TTemporary current colours, etc., (as set up by colour items)
N15C9023696MASK_TLike MASK_P, but temporary
15C9123697P_FLAGMore flags
N305C9223698MEMBOTCalculator's memory area – used to store numbers that cannot conveniently be put on the calculator stack
25CB023728Not used
25CB223730RAMTOPAddress of last byte of NextBASIC system area.
25CB423732P_RAMTAddress 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.