; ***************************************************************************
; Headers for Sinclair ZX Spectrum OS
; Notes about the Sinclair ZX Spectrum operating system & memory
; Author: Peter Mount, Area51.dev & Contributors
;
; URL: https://area51.dev/sinclair/spectrum/
;
; Modified: Sun, 23 Jan 2022 17:05:58 UTC
;
; Current version: https://area51.dev/sinclair/spectrum/reference/include/beebasm/headers.asm
; ***************************************************************************
; Tokens used to store BASIC programs in memory
BAS_CODE = &AF ; CODE
BAS_CLEAR = &FD ; CLEAR statement
BAS_LOAD = &EF ; LOAD statement
BAS_PRINT = &F5 ; PRINT statement
BAS_RANDOMIZE = &F9 ; RANDOMIZE statement
BAS_USR = &C0 ; USR function
; The display attributes specifying colour information
DISPLAYATTR = &5800 ; The display attributes holding colour information
; The display pixel format
DISPLAYFILE = &4000 ; The start of the standard Spectrum's standard screen
; System variables
OLDHL = &5B52 ; Temp store while switching roms
OLDBC = &5B54 ; Temp store while switching roms
OLDAF = &5B56 ; Temp store while switching roms
TARGET = &5B58 ; Subroutine address in ROM 3
RETADDR = &5B5A ; Return address in ROM1
BANKM = &5B5C ; Copy last byte output to Port 7FFD
RAMERR = &5B5E ; Error passed from ROM 1 to 3 via RAMRST. Also used by SAVE/LOAD as temp drive store
BAUD = &5B5F ; RS232 bit period in T states/26. Set by FORMAT LINE
SERFL = &5B61 ; Second-character-received flag & data
COL = &5B63 ; Current column from 1 to width
WIDTH = &5B64 ; Paper column width
TVPARS = &5B65 ; Number of inline parameters expected by RS232
FLAGS3 = &5B66 ; Various Flags
BANK678 = &5B67 ; Copy of last byte output to port 1FFD
XLOC = &5B68 ; Hold X location when using the unexpanded COPY command
YLOC = &5B69 ; Hold Y location when using the unexpanded COPY command
OLDSP = &5B6A ; Old SP (stack pointer) when TSTACK is in use.
SYNRET = &5B6C ; Return address for ONERR
LASTTV = &5B6E ; Last value printed by calculator
RCLINE = &5B73 ; Current line being renumbered
RCSTART = &5B75 ; Starting line number for renumbering
RCSTEP = &5B77 ; Incremental value for renumbering
LODDRV = &5B79 ; Drive for LOAD VERIFY or MERGE
SAVDRV = &5B7A ; Drive for SAVE
DUMPLF = &5B7B ; Holds the number of 1/216ths user for line feeds in 'COPY EXP'. If a dump cannot fit A4 set to 8 to reduce size of dump.
STRIP1 = &5B7C ; Stripe 1 bitmap
STRIP2 = &5B84 ; Strip2 2 bitmap. Extends to 5B8B
TSTACK = &5BFF ; Temp stack (Grows DOWN from here). Used when Page 7 is switched in at top of memory while editing or using +3DOS. It can grow down to STRIP1 safely giving 115 bytes
KSTATE = &5C00 ; Used for reading keyboard
LASTK = &5C08 ; Stores newly pressed key
REPDEL = &5C09 ; Time in 1/50s before key repeats
REPPER = &5C0A ; Delay in 1/50s between key repeats
KDATA = &5C0D ; Stores 2nd byte of colour controls entered from keyboard
TVDATA = &5C0E ; Stores bytes of colour, AT and TAB controls going to TV
STRMS = &5C10 ; Addresses of channels attached to streams
CHARS = &5C36 ; 256 less than address of character set starting with space and up to (C).
RASP = &5C38 ; Length of warning buzz
PIP = &5C39 ; Length of keyboard click
ERRNR = &5C3A ; 1 less than report code. Starts at 255 for -1
FLAGS = &5C3B ; Various flags for BASIC
TVFLAG = &5C3C ; Flags associated with the TV
ERRSP = &5C3D ; Address of item on machine stack to be used as error return
LISTSP = &5C3F ; Address of return address from automatic listing
MODE = &5C41 ; Specifies K, L, C, E or G cursor
NEWPPC = &5C42 ; Line to be jumped to
NSPPC = &5C44 ; Statement number in line to be jumped to. Poking first NEWPPC then NSPPC forces a jump to a specific statement in a line.
PPC = &5C45 ; Line number of statement currently being executed
SUBPPC = &5C47 ; Number within line of statement currently being executed
BORDCR = &5C48 ; Border colour multiplied by 8; also contains attributes normally used for lower half of the screen
EPPC = &5C49 ; Number of current line (with program cursor)
VARS = &5C4B ; Address of variables
DEST = &5C4D ; Address of variable in assignment
CHANS = &5C4F ; Address of channel data
CHURCHL = &5C51 ; Address of information currently being used for IO
PROG = &5C53 ; Address of BASIC program
NXTLIN = &5C55 ; Address of next line in program
DATADD = &5C57 ; Address of terminator of last DATA item
ELINE = &5C59 ; Address of command being typed in
KCUR = &5C5B ; Address of cursor
CHADD = &5C5D ; Address of next character after the argument of PEEK or the NEWLINE at the end of a POKE statement.
XPTR = &5C5F ; Address of character after the [] marker
WORKSP = &5C61 ; Address of temporary workspace
STKBOT = &5C63 ; Address of bottom of calculator stack
STKEND = &5C65 ; Address of start of space space
BREG = &5C67 ; Calculators B register
MEM = &5C68 ; Address of area used for calculators memory, usually MEMBOT
FLAGS2 = &5C6A ; More flags
DFSZ = &5C6B ; Number of lines (including one blank) in lower part of the screen
STOP = &5C6C ; Number of the top program line in automatic listings
OLDPPC = &5C6E ; Line number to which CONTINUE jumps
OSPPC = &5C70 ; Number within line of statement to which CONTINUE jumps
FLAGX = &5C71 ; Various flags
STRLEN = &5C72 ; Length of string type destination in assignment
TADDR = &5C74 ; Address of next item in syntax table
SEED = &5C76 ; The seed for the RNG. Variable set using RANDOMIZE
FRAMES = &5C78 ; 3 byte (least significant first) frame counter incremented every 20ms
UDG = &5C7B ; Address of first user defined graphic
COORDX = &5C7D ; X coordinate of last point plotted
COORDY = &5C7E ; Y coordinate of last point plotted
PPOSN = &5C7F ; 33 column number of printer position
PRCC = &5C80 ; Full address of next position for LPRINT. Only used for ZX printer, not in 128K mode.
ECHOE = &5C82 ; 33 column number & 24 line number of end of input buffer
DFCC = &5C84 ; Address in display file of PRINT position
DFCCL = &5C86 ; Like DFCC but for lower part of screen
SPOSN = &5C88 ; 33 col & 24 line number for PRINT position
SPOSNL = &5C8A ; Like SPOSN but for lower part of screen
SCRCT = &5C8C ; Counts scrolls, always 1 more than number of scrolls to perform before scroll.
ATTRP = &5C8D ; Permanent current colours
MASKP = &5C8E ; Used for transparent colour. Any bit that is 1 shows bit taken from screen and not ATTRP
ATTRT = &5C8F ; Like ATTRP but for temporary colours
MASKT = &5C90 ; Like MASKP but for temporary colours
PFLAG = &5C91 ; More flags
MEMBOT = &5C92 ; Calculators memory area used to store numbers not convenient to store on the calculator stack
NMIADD = &5CB0 ; Address of users NMI routine. Older machines NMI didn't work well so was marked as UNUSED so can cause issues on +3 if user code uses this
RAMTOP = &5CB2 ; Address of last byte of BASIC system area
PRAMT = &5CB4 ; Address of last byte of physical RAM
SYSVAREND = &5CB6 ; Start of Channel information, usually value in (CHANS)
RESERVED_MMAP = &5CC0 ; Marked reserved in 48k memory map
BASE_AVAIL_MEM = &5CCB ; Base of available memory