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