SPECTRUM SYSTEM VARIABLES ========================= SPECTRUM 128 SYSTEM VARIABLES ----------------------------- ADDRESS NOTES HEX DECIMAL NAME CONTENTS -------------------------------------------------------------------- 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. N2 5B58 23384 TARGET Subroutine address in ROM 3. X2 5B5A 23386 RETADDR Return address in ROM 1. X1 5B5C 23388 BANKM Copy of last byte output to I/O port 7FFD (32765). This port is used to control the RAM paging (bits 0...2), the 'horizontal' ROM switch 0<->1 and 2<->3 - bit 4), screen selection (bit 3 and added I/O disabling (bit 5). 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. 2 5B5F 23391 BAUD RS232 bit period in T states/26. Set by FORMAT LINE. N2 5B61 23393 SERFL Second-character-received-flag, and data. N1 5B63 23395 COL Current column from 1 to width. 1 5B64 23396 WIDTH Paper column width. Defaults to 80. 1 5B65 23397 TVPARS Number of inline parameters expected by RS232. 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 1FFD (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 0<->2 and 1<->3), 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. N1 5B68 23400 XLOC Holds X location when using the unexpanded COPY command. N1 5B69 23401 YLOC Holds Y location when using the unexpanded COPY command. 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. 2 5B73 23411 RCLINE Current line being renumbered. 2 5B75 23413 RCSTART Starting line number for renumbering. The default value is 10. 2 5B77 23415 RCSTEP Incremental value for renumbering. The default is 10. 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'. 1 5B7B 23419 DUMPLF Holds the number of 1/216ths user for line feeds in 'COPY EXP'. This is normally set to 9. If problems are experienced fitting a dump onto a sheet of A4 paper, POKE this location with 8. This will reduce the size of the dump and improve the aspect ratio slightly. (The quality of the dump will be marginally degraded, however.) N8 5B7C 23420 STRIP1 Stripe one bitmap. N8 5B84 23428 STRIP2 Stripe two bitmap. This extends to 5B8B (23436). X115 5BFF 23551 TSTACK Temporary stack grows down from here. Used when RAM page 7 is switched in at top of memory (while executing the editor or calling +3DOS). It may safely go down to 5B8C and across STRIP1 and STRIP2 if necessary). This guarantees at least 115 bytes of stack when BASIC calls +3DOS. STANDARD 48K SPECTRUM SYSTEM VARIABLES -------------------------------------- ADDRESS NOTES HEX DECIMAL IY NAME CONTENTS -------------------------------------------------------------------- N8 5C00 23552 IY-58 KSTATE Used in reading the keyboard. N1 5C08 23560 IY-50 LASTK Stores newly pressed key. 1 5C09 23561 IY-49 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 IY-48 REPPER Delay (in 50ths of a second) between successive repeats of a key held down - initially 5. N2 5C0B 23563 IY-47 DEFADD Address of arguments of user defined function (if one is being evaluated), otherwise 0. N1 5C0D 23565 IY-45 K_DATA Stores 2nd byte of colour controls entered from keyboard. N2 5C0E 23566 IY-44 TVDATA Stores bytes of colour, AT and TAB controls going to TV. X38 5C10 23568 IY-42 STRMS Addresses of channels attached to streams &FD to &0F. 2 5C36 23606 IY-4 CHARS 256 less than address of character set (which starts with space and carries on to (C)). Normally in ROM, but you can set up your own in RAM and make CHARS point to it. 1 5C38 23608 IY-2 RASP Length of warning buzz. 1 5C39 23609 IY-1 PIP Length of keyboard click. 1 5C3A 23610 IY+0 ERRNR 1 less than the report code. Starts off at 255 (for -1) so 'PEEK 23610' gives 255. X1 5C3B 23611 IY+1 FLAGS Various flags to control the BASIC system. b7 b6 String/numeric variable b5 New key in LASTK b4 Set if in 128K Basic b3 Input in K mode/L mode b2 Print in K mode/L mode b1 Output to printer [text/raw centronics] b0 Leading spaces/no leading spaces X1 5C3C 23612 IY+2 TVFLAG Flags associated with the TV. b7 b6 b5 Clear lower screen on keypress b4 Automatic listing b3 Mode changed b2 b1 b0 X2 5C3D 23613 IY+3 ERRSP Address of item on machine stack to be used as error return. N2 5C3F 23615 IY+5 LISTSP Address of return address from automatic listing. N1 5C41 23617 IY+7 MODE Specifies 'K', 'L', 'C', 'E' or 'G' cursor. 2 5C42 23618 IY+8 NEWPPC Line to be jumped to. 1 5C44 23620 IY+10 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 5C45 23621 IY+11 PPC Line number of statement currently being executed. 1 5C47 23623 IY+13 SUBPPC Number within line of statement currently being executed. 1 5C48 23624 IY+14 BORDCR Border colour multiplied by 8; also contains the attributes normally used for the lower half of the screen. 2 5C49 23625 IY+15 E_PPC Number of current line (with program cursor). X2 5C4B 23627 IY+17 VARS Address of variables. N2 5C4D 23629 IY+19 DEST Address of variable in assignment. X2 5C4F 23631 IY+21 CHANS Address of channel data. X2 5C51 23633 IY+23 CURCHL Address of channel currently being used for input and output. X2 5C53 23635 IY+25 PROG Address of BASIC program. X2 5C57 23637 IY+27 NXTLIN Address of next line in program. X2 5C57 23639 IY+29 DATADD Address of terminator of last DATA item. X2 5C59 23641 IY+31 E_LINE Address of command being typed in. 2 5C5B 23643 IY+33 K_CUR Address of cursor. X2 5C5D 23645 IY+35 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 IY+37 X_PTR Address of the character after the [?] error marker. X2 5C61 23649 IY+39 WORKSP Address of temporary work space. X2 5C63 23651 IY+41 STKBOT Address of bottom of calculator stack. X2 5C65 23653 IY+43 STKEND Address of start of spare space. N1 5C67 23655 IY+45 BREG Calculator's B register. N2 5C68 23656 IY+46 MEM Address of area used for calculator's memory (usually MEMBOT, but not always). 1 5C6A 23658 IY+48 FLAGS2 More flags. b7 [Default tokeniser ignore case] b6 [Default tokeniser no abbreviations] b5 [Default tokeniser enforce separators] b4 Output using channel 'K' b3 CAPS LOCK on b2 Parsing within quotes b1 Printer buffer not empty b0 Screen is clear X1 5C6B 23659 IY+49 DFSZ The number of lines (including one blank line in the lower part of the screen. 2 5C6C 23660 IY+50 S_TOP The number of the top program line in automatic listings. 2 5C6E 23662 IY+52 OLDPPC Line number to which CONTINUE jumps. 1 5C70 23664 IY+54 OSPPC Number within line of statement to which CONTINUE jumps. N1 5C71 23665 IY+55 FLAGX Various flags. b7 INPUT LINE b6 String result b5 INPUT b4 b3 b2 b1 New variable b0 Sliced string/simple string N2 5C72 23666 IY+56 STRLEN Length of string type destination in assignment. N2 5C74 23668 IY+58 T_ADDR Address of next item in syntax table, with file operations set to 0=SAVE, 1=LOAD, 2=VERIFY, 3=MERGE 2 5C76 23670 IY+60 SEED The seed for RND. This is the variable that is set by RANDOMIZE. 3 5C78 23672 IY+62 FRAMES 3-byte (least significant byte first), frame counter incremented every 20ms. 2 5C7B 23675 IY+65 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 IY+67 COORDS X-coordinate of last point plotted. 1 5C7E 23678 IY+68 Y-coordinate of last point plotted. 1 5C7F 23679 IY+69 P_POSN 33-column number of printer position. [Current default device, 'T' or '1'-'8'] X2 5C80 23680 IY+70 PRCC Full address of next position for LPRINT to print at (in ZX printer buffer). Legal values 5B00 - 5B1F. [Not used in 128K mode or when certain peripherals are attached] [NMIADD on some systems] 2 5C82 23682 IY+72 ECHO_E 33-column number and 24-line number (in lower half of end of input buffer). 2 5C84 23684 IY+74 DFCC Address in display file of PRINT position. 2 5C86 23686 IY+76 DFCCL Like DFCC for lower part of screen. X1 5C88 23688 IY+78 S_POSN 33-column number for PRINT position. X1 5C89 23689 IY+79 24-line number for PRINT position. X2 5C8A 23690 IY+80 SPOSNL Like S_POSN but for lower part. 1 5C8C 23692 IY+82 SCRCT 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, or with SET 7,(IY+82), the screen will scroll on and on without asking you. 1 5C8D 23692 IY+83 ATTRP Permanent current colours, etc., (as set up by colour statements). 1 5C8E 23693 IY+84 MASKP Used for transparent colours, etc. Any bit that is 1 shows that the corresponding attribute bit is taken not from ATTRP, but from what is already on the screen. N1 5C8F 23694 IY+85 ATTRT Temporary current colours, etc., (as set up by PRINT colour items). N1 5C90 23696 IY+86 MASKT Like MASKP, but temporary. 1 5C91 23697 IY+87 PFLAG Print flags. b7 PAPER 9 permanent setting b6 PAPER 9 current setting b5 INK 9 permanent setting b4 INK 9 current setting b3 INVERSE permanent setting b2 INVERSE current setting b1 OVER permanent setting b0 OVER current setting N30 5C92 23698 IY+88 MEMBOT Calculator's memory area - used to store numbers that cannot conveniently be put on the calculator stack, and as miscellaneous workspace. 2 5CB0 23728 IY+118 NMIADD Holds the address of the user's NMI service routine. NOTE - On previous machines, this did not work correctly and these two bytes were documented as 'Not used.' Programs that use these two bytes for passing values may need to be modified. With the Interface 1 this has been reused as: 1 5CB0 23728 IY+118 PRCOL RS232 text output column 1 5CB1 23729 IY+119 WIDTH RS232 text output width 2 5CB2 23730 IY+120 RAMTOP Address of last byte of BASIC system area. 2 5CB4 23732 IY+122 PRAMT Address of last byte of physical RAM. 5CB6 23734 Start of CHANS when no Interface 1 active. INTERFACE 1 SYSTEM VARIABLES ---------------------------- X1 5CB6 23734 IY+124 FLAGS3 Various flags b7 VERIFY command b6 MERGE command b5 SAVE command b4 LOAD or MOVE command b3 using the network b2 set if main ROM error handler to be used b1 set during CLEAR# or first entry to shadow ROM b0 set during new command When no Interface 1 is present, this is the first byte of CHANS and will be set to F4 as the output address for 'K'. With the Interface 1 present and enabled it will be some value other than F4, usually 00, so can be tested for with: CLOSE#0:LET int1=(PEEK 23734<>244) X2 5CB7 23735 IY+125 VECTOR Normally points to 01F0 (ERR_6). You may modify this address to point to a RAM routine to extend commands. X10 5CB9 23737 IY+127 SBRT ROM paging routine. 5CBA 23738 H_L Used to save the value of HL when calling main ROM routines. 2 5CC3 23747 BAUD Timing constant used during RS232 I/O. Calculated with (3500000/(26*baudrate))-2 1 5CC5 23749 NTSTAT Network station 1 5CC6 23750 IOBORD Border colour during I/O, normally 0 (black) N1 5CC7 23751 SER_FL Number of buffered serial characters, 0 or 1 N1 5CC8 23752 SER_BF One-byte serial input buffer N2 5CC9 23753 SECTOR Counter of sectors examined during Microdrive operations N2 5CCB 23755 CHADD_ Temporary store for CH_ADD. 1 5CCD 23757 NTRESP Store for network response code +1. Network buffer: 1 5CCE 23758 NTDEST Destination station for current packet 1 5CCF 23759 NTSRCE Station number of sending machine in current packet X2 5CD0 23760 NTNUMB Current packet block number N1 5CD2 23762 NTTYPE Packet type, 0=normal, 1=EOF X1 5CD3 23763 NTLEN Length of data block, 1-255 N1 5CD4 23764 NTDCS Current data block checksum N1 5CD5 23765 NTCHS Current header block checksum First 8-byte file specifier: N2 5CD6 23766 D_STR1 Drive number 1-8, station number 0-64, or baud rate 75-19200 N1 5CD8 23768 S_STR1 Stream number 0-15 N1 5CD9 23769 L_STR1 Device specifier 'M', 'N', 'T' or 'B' N2 5CDA 23770 N_STR1 Filename length N2 5CDC 23772 Filename start Second 8-byte file specifier, used by LOAD and MOVE: N2 5CDE 23774 D_STR2 Drive number 1-8, station number 0-64, or baud rate 75-19200 N1 5CE0 23776 S_STR2 Stream number 0-15 N1 5CE1 23777 L_STR2 Device specifier 'M', 'N', 'T' or 'B' N2 5CE2 23778 N_STR2 Filename length N2 5CE4 23780 Filename start File header workspace: N1 5CE6 23782 HD_00 File type N2 5CE7 23783 HD_0B Data block length N2 5CE9 23785 HD_0D Data block start address N2 5CEB 23787 HD_0F Program length without variables, or array name N2 5CED 23789 HD_11 Autostart line number, execute address, address called by hook code &32. N1 5CEF 23791 COPIES Number of copies made by SAVE, Reset to 1 after SAVE. 5CF0 23792 Start of CHANS when Interface 1 active. INTERFACE 1 SYSTEM VARIABLES WHEN INTERFACE 1 INACTIVE ------------------------------------------------------ 5CB6 23734 FLAGS3 CHANS => F4 Channel block for 'K' 5CB7 23735 VECTOR 09 5CB8 23736 VECTOR+1 A8 5CB9 23737 SBRT 10 5CBA 23738 H_L 'K' 5CBB 23739 F4 Channel block for 'S' 5CBC 23740 09 5CBD 23741 C4 5CBE 23742 15 5CBF 23743 'S' 5CC0 23744 81 Channel block for 'R' 5CC1 23745 0F 5CC2 23746 C4 5CC3 23747 BAUD 15 5CC4 23748 BAUD+1 'R' 5CC5 23749 NTSTAT F4 Channel block for 'P' 5CC6 23750 IOBORD 09 5CC7 23751 SER_FL C4 5CC8 23752 SER_BF 15 5CC9 23753 SECTOR 'P' 5CCA 23754 SECTOR+1 80 End of CHANS area 5CCB 23755 CHADD_ PROG => 80 1st byte of program 5CCC 23756 CHADD_+1 0D 2nd byte of program 5CCD 23757 NTRESP 80 3rd byte of program 5CCE 23758 NTDEST xx etc... 5CCF 23759 NTSRCE xx 5CD0 23760 NTNUMB xx 5CD1 23761 NTNUMB+1 xx 5CD2 23762 NTTYPE xx 5CD3 23763 NTLEN xx 5CD4 23764 NTDCS xx 5CD5 23765 NTCHS xx 5CD6 23766 D_STR1 xx 5CD7 23767 D_STR1+1 xx 5CD8 23768 S_STR1 xx 5CD9 23769 L_STR1 xx 5CDA 23770 N_STR1 xx 5CDB 23771 N_STR1+1 xx 5CDC 23772 N_NAM1 xx Of particular interest: FLAGS3 the Interface 1 flags holds &F4 as the low byte of the 'K' output channel. With the Interface 1 active, it will normally be &00. D_STR1 the last drive used, points into the start of the program. With careful contruction of the start of the program you can avoid this byte being &01-&08 indicating a microdrive drive. L_STR1 the last device used, also points into the start of the program. With careful construction you can avoid this byte being 'B', 'M' or 'N' indicating devices loaded from. Note that loading/saving to tape does not change these locations, they are only changed by using the Interface 1. If you load from tape and the Interface 1 is active and you want to prevent your code thinking it has loaded from the Interface 1, you must modify these locations yourself, for example: IF int1 AND drive=CODE"T" THEN POKE 23769,CODE"T" LOAD "filename"