UrForth: fixed some bugs, added simple benchmark
[urasm.git] / libs / sysvars.zas
blob7ed3ee12077db8d581d6f2866c23a5f1ee99f614
1 ;; system variables
3 ;128K/+2A/+3
4 ;R16     5B00h (23296)   SWAP......Paging subroutine.
5 ;R17     5B10h (23312)   STOO......Paging subroutine. Entered with
6 ;                                  interrupts already disabled and AF, BC
7 ;                                  on the stack.
8 ;R9      5B21h (23329)   YOUNGER...Paging subroutine.
9 ;R16     5B2Ah (23338)   REGNUOY...Paging subroutine.
10 ;R24     5B3Ah (23354)   ONERR.....Paging subroutine.
11 ;X2      5B52h (23378)   OLDHL.....Temporary register store while
12 ;                                  switching ROMs.
13 ;X2      5B54h (23380)   OLDBC.....Temporary register store while
14 ;                                  switching ROMs.
15 ;X2      5B56h (23382)   OLDAF.....Temporary register store while
16 ;                                  switching ROMs.
17 ;N2      5B58h (23384)   TARGET....Subroutine address in ROM 3.
18 ;X2      5B5Ah (23386)   RETADDR...Return address in ROM 1.
19 ;X1      5B5Ch (23388)   BANKM.....Copy of last byte output to I/O port
20 ;                                  7FFDh (32765). This port is used to
21 ;                                  control the RAM paging (bits 0...2),
22 ;                                  the 'horizontal' ROM switch (0<->1 and
23 ;                                  2<->3 - bit 4), screen selection (bit
24 ;                                  3) and added I/O disabling (bit 5).
25 ;                                  This byte must be kept up to date with
26 ;                                  the last value output to the port if
27 ;                                  interrupts are enabled.
28 ;X1      5B5Dh (23389)   RAMRST....RST 8 instruction. Used by ROM 1 to
29 ;                                  report old errors to ROM 3.
30 ;N1      5B5Eh (23390)   RAMERR....Error number passed from ROM 1 to ROM
31 ;                                  3. Also used by SAVE/LOAD as temporary
32 ;                                  drive store.
33 ;2       5B5Fh (23391)   BAUD......RS232 bit period in T states/26. Set
34 ;                                  by FORMAT LINE.
35 ;N2      5B61h (23393)   SERFL.....Second-character-received-flag, and
36 ;                                  data.
37 ;N1      5B63h (23395)   COL.......Current column from 1 to width.
38 ;1       5B64h (23396)   WIDTH.....Paper column width. Defaults to 80.
39 ;1       5B65h (23397)   TVPARS....Number of inline parameters expected
40 ;                                  by RS232.
41 ;1       5B66h (23398)   FLAGS3....Various flags. Bits 0, 1, 6 and 7
42 ;                                  unlikely to be useful. Bit 2 is set
43 ;                                  when tokens are to be expanded on
44 ;                                  printing. Bit 3 is set if print output
45 ;                                  is RS232. The default (at reset) is
46 ;                                  Centronics. Bit 4 is set if a disk
47 ;                                  interface is present. Bit 5 is set if
48 ;                                  drive B: is present.
49 ;X1      5B67h (23399) BANK678.....Copy of last byte output to I/O port
50 ;                                  1FFDh (8189). This port is used to
51 ;                                  control the +3 extended RAM and ROM
52 ;                                  switching (bits 0..2 - if bit 0 is 0
53 ;                                  then bit 2 controls the 'vertical' ROM
54 ;                                  switch 0<->2 and 1<->3), the disk
55 ;                                  motor (bit 3) and Centronics strobe
56 ;                                  (bit 4). This byte must be kept up to
57 ;                                  date with the last value output to the
58 ;                                  port if interrupts are enabled.
59 ;N1      5B68h (23400) XLOC........Holds X location when using the
60 ;                                  unexpanded COPY command.
61 ;N1      5B69h (23401) YLOC........Holds Y location when using the
62 ;                                  unexpanded COPY command.
63 ;X2      5B6Ah (23402) OLDSP.......Old SP (stack pointer) when TSTACK is
64 ;                                  in use.
65 ;X2      5B6Ch (23404) SYNRET......Return address for ONERR.
66 ;5       5B6Eh (23406) LASTV.......Last value printed by calculator.
67 ;2       5B73h (23411) RCLINE......Current line being renumbered.
68 ;2       5B75h (23413) RCSTART.....Starting line number for
69 ;                                  renumbering. The default value is 10.
70 ;2       5B77h (23415) RCSTEP......Incremental value for renumbering. The
71 ;                                  default is 10.
72 ;1       5B79h (23417) LODDRV......Holds 'T' if LOAD, VERIFY, MERGE are
73 ;                                  from tape, otherwise holds 'A', 'B'
74 ;                                  or 'M'.
75 ;1       5B7Ah (23418) SAVDRV......Holds 'T' if SAVE is to tape,
76 ;                                  otherwise holds 'A', 'B' or 'M'.
77 ;1       5B7Bh (23419) DUMPLF......Holds the number of 1/216ths user for
78 ;                                  line feeds in 'COPY EXP'. This is
79 ;                                  normally set to 9. If problems are
80 ;                                  experienced fitting a dump onto a
81 ;                                  sheet of A4 paper, POKE this
82 ;                                  location with 8. This will reduce the
83 ;                                  size of the dump and improve the
84 ;                                  aspect ratio slightly. (The quality of
85 ;                                  the dump will be marginally degraded,
86 ;                                  however.)
87 ;N8      5B7Ch (23420) STRIP1......Stripe one bitmap.
88 ;N8      5B84h (23428) STRIP2......Stripe two bitmap. This extends to
89 ;                                  5B8Bh (23436).
90 ;X115    5BFFh (23551) TSTACK......Temporary stack grows down from
91 ;                                  here. Used when RAM page 7 is switched
92 ;                                  in at top of memory (while executing
93 ;                                  the editor or calling +3DOS). it may
94 ;                                  safely go down to 5B8Ch (and across
95 ;                                  STRIP1 and STRIP2 if necessary). This
96 ;                                  guarantees at least 115 bytes of stack
97 ;                                  when BASIC calls +3DOS.
100 ;; 128k vars
101 ROM1_TARGET   EQU  #5B58  ; 2
102 ROM0_RETADDR  EQU  #5B5A  ; 2
103 PAGE_BANK     EQU  #5B5C  ; 1
104 RAM_RST       EQU  #5B5D  ; 1
105 RAM_ERR       EQU  #5B5E  ; 1
106 RS232_BOUD    EQU  #5B5F  ; 2
107 RS232_SERF    EQU  #5B61  ; 2
108 PR_COL        EQU  #5B63  ; 1
109 PR_WIDTH      EQU  #5B64  ; 1
110 TV_PARS       EQU  #5B65  ; 1
111 FLAGS_3       EQU  #5B66  ; 1
112 N_STR1        EQU  #5B67  ; 10
113 HD_00         EQU  #5B71  ; 1
114 HD_0B         EQU  #5B72  ; 2
115 HD_0D         EQU  #5B74  ; 2
116 HD_0F         EQU  #5B76  ; 2
117 HD_11         EQU  #5B78  ; 2
118 SC_00         EQU  #5B7A  ; 1
119 SC_08         EQU  #5B7B  ; 2
120 SC_0A         EQU  #5B7D  ; 2
121 SC_0F         EQU  #5B7F  ; 2
122 OLD_SP        EQU  #5B81  ; 2
123 SF_NEXT       EQU  #5B83  ; 2
124 SF_SPACE      EQU  #5B85  ; 3
125 ROW_01        EQU  #5B88  ; 1
126 ROW_23        EQU  #5B89  ; 1
127 ROW_45        EQU  #5B8A  ; 1
128 SYN_RET       EQU  #5B8B  ; 2
129 LAST_V        EQU  #5B8D  ; 5
130 RN_LINE       EQU  #5B92  ; 2
131 RN_FIRST      EQU  #5B94  ; 2
132 RN_STEP       EQU  #5B96  ; 2
133 STRIP_1       EQU  #5B98  ; 8
134 STRIP_2       EQU  #5BA0  ; 95
135 T_STACK       EQU  #5BFF  ; 1
137 ; 48_12
138 K_STATE       EQU  #5C00  ; 8
139   ; first block
140   ;  +0 / -58: key code (shifts ignored) or 255 if the block is free
141   ;  +1 / -57: first delay counter
142   ;  +2 / -56: repeat counter
143   ;  +3 / -55: key code (real)
144   ; second block
145   ;  +4 / -54: key code (shifts ignored) or 255 if the block is free
146   ;  +5 / -53: first delay counter
147   ;  +6 / -52: repeat counter
148   ;  +7 / -51: key code (real)
149 LAST_K        EQU  #5C08  ; 1
150   ; -50: last pressed key
151 REP_DEL       EQU  #5C09  ; 1
152   ; -49: first repeat delay
153 K_REPPER      EQU  #5C0A  ; 1
154   ; -48: repeat delay
155 DEF_ADD       EQU  #5C0B  ; 2
156   ; -47: deffn address (points to deffn arg -- the one after the paren)
157 K_DATA        EQU  #5C0D  ; 1
158   ; -45: E mode color data (???)
159 TV_DATA       EQU  #5C0E  ; 2
160   ; +0 / -44: cc code in E mode
161   ; +1 / -43: at/tab first arg
162 SYS_STRMS     EQU  #5C10  ; 38
163   ; -42: streams
164 CHAR_SET      EQU  #5C36  ; 2
165   ; -4: font address (first 32 chars / 256 bytes are not used)
166 SYS_RASP      EQU  #5C38  ; 1
167   ; -2: editor buffer full length
168 SYS_PIP       EQU  #5C39  ; 1
169   ; -1: keypress beep length
170 ERR_NR        EQU  #5C3A  ; 2  ; IY points here!
171   ; +0: error_number-1
172 SYS_FLAGS     EQU  #5C3B  ; 1
173   ; +1: flags
174   ;   bit0: set if RST #10 should omit space before printing a basic token
175   ;   bit1: set if stream #3 is used for printing
176   ;   bit2: set for L mode, reset for K mode
177   ;   bit3: set for L mode, reset for K mode (input wait)
178   ;   bit4: set when +3DOS should be active (motor off on IM1, using page 7 variables block)
179   ;   bit5: set if any key was pressed (LAST_K contains key code)
180   ;   bit6: set when parsing number expression, reset for string expression
181   ;   bit7: set when executing a basic, reset when syntax checking
182 TV_FLAG       EQU  #5C3C  ; 1
183   ; +1: tv flags
184   ;   bit0: set when RST #10 is printing to the main area, reset when in the lower area
185   ;   bit3: set if output mode check required (wtf?)
186   ;   bit4: set when in LIST
187   ;   bit5: set if the lower area should be cleared
188 ERR_SP        EQU  #5C3D  ; 2
189   ; +3: basic error SP
190 LIST_SP       EQU  #5C3F  ; 2
191   ; +5: basic LIST SP
192 CUR_MODE      EQU  #5C41  ; 1
193   ; +7: keyboard input mode
194   ;      0: K/L/C
195   ;      1: E
196   ;      2: G
197 NEW_PPC       EQU  #5C42  ; 2
198 CUR_PPC       EQU  #5C45  ; 2
199 SUB_PPC       EQU  #5C47  ; 2
200 BORDER        EQU  #5C48  ; 1
201   ; +14: lower area color (paper is for border)
202 E_PPC         EQU  #5C49  ; 2
203   ; +15: line number for editor (marked one)
204 SYS_VARS      EQU  #5C4B  ; 2
205   ; +17: start of basic variables
206 SYS_DEST      EQU  #5C4D  ; 2
207 SYS_CHANS     EQU  #5C4F  ; 2
208   ; +21: addess of channel table
209 CUR_CHL       EQU  #5C51  ; 2
210   ; +23: current channel address
211 PROG_BAS      EQU  #5C53  ; 2
212   ; +25: address of the first byte of a BASIC program
213 NXT_LIN       EQU  #5C55  ; 2
214 DAT_ADD       EQU  #5C57  ; 2
215 E_LINE        EQU  #5C59  ; 2
216 K_CUR         EQU  #5C5B  ; 2
217 CH_ADD        EQU  #5C5D  ; 2
218 X_PRT         EQU  #5C5F  ; 2
219 WORK_SP       EQU  #5C61  ; 2
220   ; +39: basic workspace address
221 STK_BOT       EQU  #5C63  ; 2
222   ; +41: calculator stack bottom
223 STK_END       EQU  #5C65  ; 2
224   ; +43: calculator stack top
225 B_REG         EQU  #5C67  ; 1
226   ; +45: calculator "B" reg
227 MEM_CALC      EQU  #5C68  ; 2
228   ; +45: calculator working memory address (usually points to MEM_BOT)
229 FLAGS_2       EQU  #5C6A  ; 1
230   ; +48: more flags
231   ;   bit0: CLS before line input
232   ;   bit1: set if printer buffer was used
233   ;   bit2: set if main screen was cleared
234   ;   bit3: set for C mode, reset for L mode
235   ;   bit4: set for K mode, reset for non-K mode
236   ;   bit5-7: ZX LPRINT III
237 DF_SZ         EQU  #5C6B  ; 1
238   ; +49: number of lines in the lower area
239 S_TOP         EQU  #5C6C  ; 2
240   ; +50: line index to start autolist from
241 OLD_PPC       EQU  #5C6E  ; 2
242 OS_PPC        EQU  #5C70  ; 1
243 FLAG_X        EQU  #5C71  ; 1
244   ; +55: input editor flags
245   ;   bit1: set if input into new variable
246   ;   bit5: set if user input, reset if basic edit
247   ;   bit7: set for INPUT LINE
248 STR_LEN       EQU  #5C72  ; 2
249 T_ADDR        EQU  #5C74  ; 2
250 SEED_RND      EQU  #5C76  ; 2
251   ; +60: basic RND seed
252 FRAMES_CNTR   EQU  #5C78  ; 3
253   ; +62: frame counter
254 UDG_SET       EQU  #5C7B  ; 2
255   ; +65: address of UDG set
256 GR_COORDS     EQU  #5C7D  ; 2
257   ; +66: last "PLOT" position (x, y)
258 P_POSN        EQU  #5C7F  ; 1
259   ; +69: printer buffer position -- 33-n
260 PR_CC         EQU  #5C80  ; 1
261   ; +70: printer buffer address
262 ECHO_E        EQU  #5C82  ; 2
263 DF_CC         EQU  #5C84  ; 2
264 DF_CCL        EQU  #5C86  ; 2
265 S_POSN        EQU  #5C88  ; 2
266   ; +78: current printing position
267   ;      24-y, 33-x
268 S_POSNL       EQU  #5C8A  ; 2
269   ; +80: the same for the lower area
270 SCR_CT        EQU  #5C8C  ; 1
271   ; +82: number of lines left before "scroll?"
272 ATTR_P        EQU  #5C8D  ; 1
273   ; +83: current printing attributes
274 MASK_P        EQU  #5C8E  ; 1
275   ; +84: current printing attributes mask
276 ATTR_T        EQU  #5C8F  ; 1
277   ; +85: temporarily printing attributes
278 MASK_T        EQU  #5C90  ; 1
279   ; +86: temporarily printing attributes mask
280 P_FLAG        EQU  #5C91  ; 1
281   ; +87: printing mode flags
282   ;   bit0,1: pesistent/temp OVER
283   ;   bit2,3: pesistent/temp INVERSE
284   ;   bit4,5: pesistent/temp INK 9
285   ;   bit6,6: pesistent/temp PAPER 9
286 MEM_BOT       EQU  #5C92  ; 30
287   ; +88: default calculator working area (MEM_CALC usually points here)
288 RAM_TOP       EQU  #5CB2  ; 2
289   ; +120: last address that basic is allowed to use (CLEAR)
290 P_RAMT        EQU  #5CB4  ; 2
291   ; +122: last address of the physical ROM
293 ; if1
294 INTF1_USE     EQU  #5CB6  ; 12
295   ; +124
297 ; tr_dos
298 TRD_RET       EQU  #5CC2  ; 6
299 DISK_MODE     EQU  #5CC8  ; 4
300 CUR_SEC_CAT   EQU  #5CCC  ; 1
301 DISK_READY    EQU  #5CCD  ; 1
302 DISK_R_W_OP   EQU  #5CCE  ; 1
303 DISK_ACC      EQU  #5CD6  ; 1
304 START_TRACKS  EQU  #5CD7  ; 2
305 TRD_CH_ADD    EQU  #5CD9  ; 2
306 TRD_LENGTH    EQU  #5CDB  ; 2
307 H_FILENAME    EQU  #5CDD  ; 8
308 H_TYPE        EQU  #5CE5  ; 1
309 H_START       EQU  #5CE6  ; 2
310 H_LENGTH      EQU  #5CE8  ; 2
311 H_SIZE        EQU  #5CEA  ; 1
312 H_SECTOR      EQU  #5CEB  ; 1
313 H_TRACK       EQU  #5CEC  ; 1
314 INTRF1_IS     EQU  #5CEF  ; 5
315 CUR_SECTOR    EQU  #5CF4  ; 1
316 CUR_TRACK     EQU  #5CF5  ; 1
317 TEMP_DISK     EQU  #5CF6  ; 1
318 TRD_ZERO      EQU  #5CF7  ; 1
319 SECOND_DISK   EQU  #5CF8  ; 1
320 DISK_R_V_OP   EQU  #5CF9  ; 1
321 DISK_TIME     EQU  #5CFA  ; 4
322 VG93_CMD      EQU  #5CFE  ; 1
323 SEC_NUMBER    EQU  #5CFF  ; 1
324 BUF_5_6       EQU  #5D00  ; 2
325 SAVE_HL       EQU  #5D02  ; 2
326 SAVE_DE       EQU  #5D04  ; 2
327 SEARCH_N      EQU  #5D06  ; 1
328 DEL_COUNT     EQU  #5D07  ; 1
329 FIRST_CHAR    EQU  #5D08  ; 4
330 BUF_STAT      EQU  #5D0C  ; 2
331 BAS_TRD       EQU  #5D0E  ; 1
332 TRD_ERR       EQU  #5D0F  ; 1
333 TRD_ERR_HIGH  EQU  #5D10  ; 1
334 TRD_LINE_AD   EQU  #5D11  ; 2
335 ERR_SP_COPY   EQU  #5D13  ; 2
336 TRD_MESOUT    EQU  #5D15  ; 1
337 SYSREG_COPY   EQU  #5D16  ; 1
338 TRD_TITLE     EQU  #5D17  ; 1
339 CHANGE_BLKS   EQU  #5D18  ; 1
340 DFLT_DISK     EQU  #5D19  ; 1
341 INTRNL_RET    EQU  #5D1A  ; 2
342 SAVE_SP       EQU  #5D1C  ; 2
343 FOUND_FILE    EQU  #5D1E  ; 2
344 INP_3CHARS    EQU  #5D20  ; 3
347 ; streams:
348 ;  0: keyboard input
349 ;  1: lower area output
350 ;  2: main screen output
351 ;  3: printer output
353 ; some ROM calls
354 ROM_CHECK_BREAK  EQU #1F54  ; 8020
355   ; sets carry flag to inverse of "break was pressed"
356   ; i.e. reset carry means "was pressed"
358 ROM_CLEAR_SCREEN EQU #0D6B  ; 3435
359   ; clear screen (with the current attrs)
360   ; sets stream #1 as default
362 ROM_CLEAR_LOWER EQU #0D6E  ; 3438
363   ; clear the lower area
364   ; sets stream #1 as default
366 ROM_CLEAR_LOWER_PART EQU #0E44  ; 3652
367   ; clear the B lines of the lower area
369 ROM_SCROLL_SCREEN EQU #0DFE  ; 3582
370   ; scroll the whole screen
372 ROM_SCROLL_LOWER_PART EQU #0E00  ; 3584
373   ; scroll B bottom lines
375 ROM_BEEP EQU #03B5  ; 949
376   ; HL: tone   -- (437500/hz)-30.125
377   ; DE: length -- hz*seconds
379 ROM_DRAW_POINT EQU #22E5  ; 8933
380   ; draw point, set COORDS
381   ; B: y -- [0..175]
382   ; C: x -- [0..255]
384 ROM_DRAW_CIRCLE EQU #232D  ; 9005
385   ; push `x`, `y`, `radus` to calculator stack
387 ROM_DRAW_LINE_FP EQU #24B7  ; 9399
388   ; push `x`, `y` to calculator stack
389   ; starting point is in COORDS
391 ROM_DRAW_LINE EQU #24BA  ; 9402
392   ; B: y -- [0..175]
393   ; C: x -- [0..255]
394   ; D: y offset sign (-1/1)
395   ; E: x offset sign (-1/1)
396   ; starting point is in COORDS
398 ROM_CALC_PUSH_A EQU #2D28  ; 11560
399   ; push A to calculator stack
402 ; tape routines
403 LD_BYTES EQU #0556  ; 1366
404   ; load bytes from tape
405   ; in:
406   ;   IX: destination address
407   ;   DE: length
408   ;   A: block type (0: header; 255: data)
409   ;   CARRY: set for LOAD, reset for VERIFY
410   ; out:
411   ;   CARRY: set on success, reset on error
413 SAVE_BYTES EQU #04C2  ; 1218
414   ; save bytes to tabe; quits to basic on BREAK
415   ; in:
416   ;   IX: destination address
417   ;   DE: length
418   ;   A: block type (0: header; 255: data)
420 SAVE_BYTES_X EQU #04C6  ; 1222
421   ; save bytes to tabe; break just stops
422   ; doesn't restore BORDER, doesn't do EI
423   ; in:
424   ;   IX: destination address
425   ;   DE: length
426   ;   A: block type (0: header; 255: data)