annotate src/lwbasic.s @ 72:f492fa6f6dc8

First pass implementation of addition and subtraction
author William Astle <lost@l-w.ca>
date Sun, 02 Jul 2023 17:21:11 -0600
parents f4b2406d7352
children 2d52cd154ed1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
2 ; LWBasic Version 0.1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
3 ; Copyright © 2022 Lost Wizard Enterprises Incorporated
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
4 ;
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
5 ; This is LWBasic, a replacement Basic ROM system for the TRS-80 Color Computer which
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
6 ; is most definitely not binary compatible with the stock ROMs.
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
8 *pragmapush list
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
9 *pragma nolist
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
10 *pragma noexpandcond
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
11 *pragma cescapes
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
13 ; Utility macros
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
14 ;
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
15 ; skip next byte; flags preserved
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
16 skip1 macro noexpand
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
17 fcb 0x21 ; opcode for BRN
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
18 endm
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
19 ; skip next byte and load nonzero to A
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
20 skip1lda macro noexpand
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
21 fcb 0x86 ; opcode for LDA immediate
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
22 endm
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
23 ; skip next byte and load nonzero to B
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
24 skip1ldb macro noexpand
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
25 fcb 0xc6 ; opcoe for LDB immediate
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
26 endm
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
27 ; skip next 2 bytes; clobbers flags
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
28 skip2 macro noexpand
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
29 fcb 0x8c ; opcode for CMPX immediate
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
30 endm
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
31 *pragmapop list
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
33 ; Various constants
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
34 console_curdel equ 10 ; delay between cursor blink cycles
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
35 keyb_bufflen equ 64 ; keyboard ring buffer length
14
2ec8c5ea5ed2 Adjust timing on key repeat to be a bit saner
William Astle <lost@l-w.ca>
parents: 13
diff changeset
36 keyb_repdeli equ 40 ; ticks before initial repeat (2/3 s)
21
2264569d7aca Fix and speed up key repeat
William Astle <lost@l-w.ca>
parents: 20
diff changeset
37 keyb_repdelr equ 6 ; 10 repeats per second
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
38 keyb_caps equ 0x80 ; capslock enabled
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
39 keyb_alt equ 0x04 ; alt pressed
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
40 keyb_ctrl equ 0x02 ; ctrl pressed
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
41 keyb_shift equ 0x01 ; shift pressed
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
42 linebuffsize equ 0x100 ; the line input buffer (256 bytes)
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
43 stringstacknum equ 20 ; number of entries on the anonymous string descriptor stack
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
45 ; Data structure used for calculations. Calculations are handled via structurs called value accumulators. A value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
46 ; accumulator consists of a data type flag (at the end of the structure) and a data area whose layout varies based
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
47 ; on the actual data type. The layouts for each value type are described below.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
48 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
49 ; A value type that is NULL (not set to anything) has type 0 (valtype_none) and the rest should be zero.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
50 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
51 ; A value accumulator has the following structure for floating point:
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
52 ; Offset Length Contents
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
53 ; 0 1 fp exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
54 ; 1 4 fp mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
55 ; 5 1 fp sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
56 ; 6 1 value type
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
57 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
58 ; A value accumulator has the following structure for integers:
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
59 ; Offset Length Contents
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
60 ; 0 1 *unsued*
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
61 ; 1 4 integer value (two's complement)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
62 ; 5 1 *unused*
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
63 ; 6 1 value type
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
64 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
65 ; A value accumulator has the following structure for a string:
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
66 ; Offset Length Contents
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
67 ; 0 2 string length
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
68 ; 2 2 *reserved for string data pointer expansion, must be zero*
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
69 ; 4 2 string data pointer
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
70 ; 6 1 value type
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
71 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
72 ; Value type constants
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
73 valtype_none equ 0 ; unknown value type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
74 valtype_int equ 1 ; integer (32 bit) value (signed)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
75 valtype_float equ 2 ; float type (40 bit) value
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
76 valtype_string equ 3 ; string type (16 bit length, 16(32) bit data pointer
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
77 ; Value accumulator structure definitions
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
78 val.type equ 6 ; value type offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
79 val.fpexp equ 0 ; fp exponent offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
80 val.fpmant equ 1 ; fp mantissa offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
81 val.fpsign equ 5 ; fp sign offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
82 val.int equ 1 ; integer offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
83 val.strlen equ 0 ; string length offset
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
84 val.strptr equ 4 ; string data pointer (low word)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
85 val.size equ 7 ; size of a value accumulator
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
87 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
88 ; GIME INIT0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
89 GIME_COCO equ 0x80 ; Set for coco2 compatible mode (video display)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
90 GIME_MMUEN equ 0x40 ; Set to enable MMU
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
91 GIME_IEN equ 0x20 ; GIME IRQ enable
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
92 GIME_FEN equ 0x10 ; GIME FIRQ enable
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
93 GIME_FExx equ 0x08 ; Enable constant RAM at 0xFExx (comes from block 0x3f)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
94 GIME_SCS equ 0x04 ; Set to enable standard SCS (switches 0xFF5x)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
95 GIME_ROME16 equ 0x00 ; 16K internal, 16K external ROM mode
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
96 GIME_ROME32 equ 0x03 ; 32K external ROM
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
97 GIME_ROMI32 equ 0x02 ; 32K internal ROM
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
98 ; GIME INIT1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
99 GIME_TMRFAT equ 0x20 ; TIMER ticks approx every 279.365 ns
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
100 GIME_TMRSLOW equ 0x00 ; TIMER ticks approx every 63.695 µs
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
101 GIME_TASK0 equ 0x00 ; MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
102 GIME_TASK1 equ 0x01 ; MMU task 1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
103 ; GIME interrupt enable/status bits
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
104 GIME_ITIMER equ 0x20 ; TIMER interrupt (timer reaches 0)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
105 GIME_IHBORD equ 0x10 ; HSYNC interrupt (falling edge)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
106 GIME_IVBORD equ 0x08 ; VSYNC interrupt (falling edge)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
107 GIME_ISERIAL equ 0x04 ; Falling edge of signal on pin 4 of serial port
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
108 GIME_IKEYBOARD equ 0x02 ; Interrupt if a 0 bit appears on bits 6-0 of PIA0.DA
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
109 GIME_ICART equ 0x01 ; Interrupt on falling edge of pin 8 of cartridge port
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
110 ; GIME VMODE
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
111 GIME_BP equ 0x80 ; enable bit plane mode
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
112 GIME_BPI equ 0x20 ; colour burst phase inversion (composite output only)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
113 GIME_MONO equ 0x10 ; disable colour burst (composite output only)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
114 GIME_H50 equ 0x08 ; set to 50Hz operation
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
115 GIME_LPR1 equ 0x00 ; one line per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
116 GIME_LPR2 equ 0x02 ; two lines per row (also works on graphics)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
117 GIME_LPR8 equ 0x03 ; 8 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
118 GIME_LPR9 equ 0x04 ; 9 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
119 GIME_LPR10 equ 0x05 ; 10 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
120 GIME_LPR11 equ 0x06 ; 11 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
121 GIME_LPRINF equ 0x07 ; "infinite" lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
122 ; GIME VRES
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
123 GIME_LPF192 equ 0x00 ; 192 lines on screen
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
124 GIME_LPF200 equ 0x40 ; 200 lines on screen (actually 199 due to hardware bug)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
125 GIME_LPF225 equ 0x60 ; 225 lines on screen
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
126 GIME_BPR16 equ 0x00 ; 16 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
127 GIME_BPR20 equ 0x04 ; 20 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
128 GIME_BPR32 equ 0x08 ; 32 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
129 GIME_BPR40 equ 0x0c ; 40 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
130 GIME_BPR64 equ 0x10 ; 64 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
131 GIME_BPR80 equ 0x14 ; 80 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
132 GIME_BPR128 equ 0x18 ; 128 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
133 GIME_BPR160 equ 0x1c ; 160 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
134 GIME_TXT32 equ 0x00 ; 32 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
135 GIME_TXT40 equ 0x04 ; 40 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
136 GIME_TXT64 equ 0x10 ; 64 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
137 GIME_TXT80 equ 0x14 ; 80 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
138 GIME_BPP1 equ 0x00 ; 1 bit per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
139 GIME_BPP2 equ 0x01 ; 2 bits per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
140 GIME_BPP4 equ 0x02 ; 4 bits per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
141 GIME_TXTATTR equ 0x01 ; text attributes enabled
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
142 endc
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
143 ifdef COCO3
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
145 ; Stuff on the fixed memory page
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
146 org 0xfe00
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
147 rmb 0xed ; unused
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
148 INT.FLAG rmb 1 ; validity flag
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
149 INT.SWI3 rmb 3 ; SWI3 bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
150 INT.SWI2 rmb 3 ; SWI2 bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
151 INT.FIRQ rmb 3 ; FIRQ bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
152 INT.IRQ rmb 3 ; IRQ bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
153 INT.SWI rmb 3 ; SWI bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
154 INT.NMI rmb 3 ; NMI bounce vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
155 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
157 ; Hardware definitions for the I/O page
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
158 org 0xff00
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
159 PIA0 equ * ; Keyboard PIA
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
160 PIA0.DA rmb 1 ; PIA0 data/direction A
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
161 PIA0.CA rmb 1 ; PIA0 control A
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
162 PIA0.DB rmb 1 ; PIA0 data/direction B
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
163 PIA0.CB rmb 1 ; PIA0 control B
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
164 rmb 28 ; mirror images of PIA0
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
165 PIA1 equ * ; DA/misc stuff
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
166 PIA1.DA rmb 1 ; PIA1 data/direction A
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
167 PIA1.CA rmb 1 ; PIA1 control A
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
168 PIA1.DB rmb 1 ; PIA1 data/direction B
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
169 PIA1.CB rmb 1 ; PIA1 control B
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
170 rmb 28 ; mirror images of PIA1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
171 rmb 16 ; SCS/Disk controller
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
172 rmb 16 ; second half of SCS area
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
173 rmb 32 ; miscelaneous hardware
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
174 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
175 rmb 16 ; *reserved* (unused but the GIME drives them)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
176 GIME.INIT0 rmb 1 ; basic GIME system config
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
177 GIME.INIT1 rmb 1 ; MMU task and timer rate
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
178 GIME.IRQ rmb 1 ; GIME IRQ enable/status register
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
179 GIME.FIRQ rmb 1 ; GIME FIRQ enable/status register
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
180 GIME.TIMER rmb 2 ; GIME programmable timer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
181 rmb 2 ; *reserved*
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
182 GIME.VMODE rmb 1 ; GIME video mode setting
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
183 GIME.VRES rmb 1 ; GIME video resolution setting
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
184 rmb 1 ; *reserved* (used for MMU expansion on some memory boards)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
185 GIME.BORDER rmb 1 ; GIME border colour
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
186 GIME.VSCROLL rmb 1 ; vertical scroll offset register/VDG screen mode variation
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
187 GIME.VOFFSET rmb 2 ; address of video memory (8 byte increments)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
188 GIME.HOFFSET rmb 1 ; horizontal scroll offset
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
189 GIME.MMU equ * ; MMU registers (two tasks)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
190 GIME.MMU0 rmb 8 ; MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
191 GIME.MMU1 rmb 8 ; MMU task 1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
192 GIME.PALETTE rmb 16 ; Palette registers
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
193 else
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
194 rmb 64 ; unused on Coco 1/2 (GIME on Coco 3)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
195 endc
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
196 SAMREG equ * ; the SAM configuration register
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
197 SAM.V0CLR rmb 1 ; SAM video mode bits
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
198 SAM.V0SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
199 SAM.V1CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
200 SAM.V1SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
201 SAM.V2CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
202 SAM.V2SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
203 SAM.F0CLR rmb 1 ; SAM screen address bits
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
204 SAM.F0SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
205 SAM.F1CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
206 SAM.F1SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
207 SAM.F2CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
208 SAM.F2SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
209 SAM.F3CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
210 SAM.F3SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
211 SAM.F4CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
212 SAM.F4SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
213 SAM.F5CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
214 SAM.F5SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
215 SAM.F6CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
216 SAM.F6SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
217 SAM.P1CLR rmb 1 ; SAM "page 1" selection (or extra memory type flag)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
218 SAM.P1SET rmb 1
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
219 SAM.R0CLR rmb 1 ; SAM R0 bit (address dependent speedup, not used on Coco3)
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
220 SAM.R0SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
221 SAM.R1CLR rmb 1 ; SAM R1 bit (full speedup/coco 3 speedup)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
222 SAM.R1SET rmb 1
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
223 SAM.M0CLR rmb 1 ; SAM M0/M1 bits (memory type, not used on Coco3)
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
224 SAM.M0SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
225 SAM.M1CLR rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
226 SAM.M1SET rmb 1
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
227 SAM.TYCLR rmb 1 ; force ROM mode (map type 0)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
228 SAM.TYSET rmb 1 ; set RAM mode (map type 1)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
229 rmb 18 ; *MPU reserved*
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
230 CPU.SWI3 rmb 2 ; CPU SWI3 vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
231 CPU.SWI2 rmb 2 ; CPU SWI2 vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
232 CPU.FIRQ rmb 2 ; CPU FIRQ vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
233 CPU.IRQ rmb 2 ; CPU IRQ vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
234 CPU.SWI rmb 2 ; CPU SWI vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
235 CPU.NMI rmb 2 ; CPU NMI vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
236 CPU.RESET rmb 2 ; CPU RESET/startup vector
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
238 ; Start of memory which has the direct page and other data.
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
239 org 0
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
240 dpstart equ * ; start of direct page
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
241 zero rmb 2 ; constant zero word used for faster zeroing of 16 bit registers
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
242 binval rmb 2 ; arbitary binary value, usually a line number or integer
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
243 memtop rmb 2 ; absolute top of memory in 64K memory map
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
244 memsize rmb 2 ; top of memory not reserved
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
245 freetop rmb 2 ; top of free memory (bottom of string space)
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
246 stringtab rmb 2 ; bottom of used string space
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
247 stackptr rmb 2 ; bottom of the "stack frame" stack (the actual stack is below here)
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
248 progtext rmb 2 ; pointer to start of program text
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
249 vartab rmb 2 ; pointer to start of integer scalars
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
250 objecttab rmb 2 ; pointer to start of arrays and other variable sized objects
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
251 freestart rmb 2 ; pointer to start of unallocated memory
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
252 readlinenoecho rmb 1 ; if nonzero, the readline routine won't echo its input
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
253 console_curptr rmb 2 ; current cursor pointer for console driver
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
254 console_blnkdel rmb 1 ; cursor blink delay
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
255 console_truelc rmb 1 ; set to nonzero if the console supports true lower case (gfx, etc.)
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
256 filenum rmb 1 ; current input/output channel
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
257 fileeof rmb 1 ; flag for whether last read detected EOF
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
258 keyb_flags rmb 1 ; shift flags for the keyboard
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
259 keyb_joystate rmb 1 ; joystick button state
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
260 keyb_repdel rmb 1 ; repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
261 keyb_curscan rmb 1 ; current repeating scan code
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
262 keyb_buffw rmb 2 ; keyboard ring buffer write pointer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
263 keyb_buffr rmb 2 ; keyboard ring buffer read pointer
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
264 curline rmb 2 ; pointer to current line
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
265 contline rmb 2 ; pointer to line for CONT
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
266 contstmt rmb 2 ; interpretation pointer for CONT
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
267 curstmt rmb 2 ; start of statement currently being interpreted
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
268 endflag rmb 1 ; 00 = END, FF = STOP
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
269 stringstackptr rmb 2 ; anonymous string descriptor stack pointer
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
270 tok_skipkw rmb 1 ; flag for when skipping an unrecognized keyword
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
271 tok_skipdt rmb 1 ; flag for when processing DATA
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
272 tok_kwtype rmb 1 ; primary/secondary type flag for tokens
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
273 tok_kwnum rmb 1 ; the actual token number
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
274 tok_kwmatchl rmb 1 ; the length of the best match during lookup
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
275 tok_kwmatch rmb 2 ; the current best matched token number
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
276 val0 rmb val.size ; value accumulator 0
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
277 val1 rmb val.size ; value accumulator 1
25
9593401d23cf Rearrange some direct page stuff
William Astle <lost@l-w.ca>
parents: 24
diff changeset
278 rmb 0x71-* ; align RSTFLG/RSTVEC for stock ROM compatibility
9593401d23cf Rearrange some direct page stuff
William Astle <lost@l-w.ca>
parents: 24
diff changeset
279 RSTFLG rmb 1 ; 0x55 if RSTVEC is valid
9593401d23cf Rearrange some direct page stuff
William Astle <lost@l-w.ca>
parents: 24
diff changeset
280 RSTVEC rmb 2 ; points to warm start routine (must start with NOP)
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
281 inputptr rmb 2 ; pointer to current program execution location
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
282 rmb 0x100-* ; make sure the stuff that isn't direct page is outside of it
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
283 SW3VEC rmb 3 ; SWI3 vector (for compatibility)
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
284 SW2VEC rmb 3 ; SWI2 vector (for compatibility)
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
285 SWIVEC rmb 3 ; SWI vector (for compatibility)
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
286 NMIVEC rmb 3 ; NMI vector (for compatibility)
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
287 IRQVEC rmb 3 ; IRQ vector (for compatibility)
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
288 FRQVEC rmb 3 ; FIRQ vector (for compatibility)
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
289 keyb_state rmb 8 ; rollover table state
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
290 keyb_buff rmb keyb_bufflen ; the keyboard ring buffer
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
291 linebuff rmb linebuffsize ; the line input buffer
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
292 tokebuff rmb linebuffsize+50 ; make it as long as line buffer plus a margin
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
293 stringstack rmb 5*stringstacknum ; reserve space for the anonymous string descriptor stack
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
294 stringstackend equ * ; end of string stack buffer
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
295 ifne *&0x1ff
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
296 rmb 0x200-(*&0x1ff)
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
297 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
298 textscreen rmb 0x200 ; the actual text screen (must be on 512 byte alignment)
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
299 heapstart equ * ; start of dynamically allocated stuff
52
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
301 ; The heap has the following items in order:
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
302 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
303 ; Program text: preceded by a NUL and pointed to by progtext
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
304 ; Variable table: pointed to by vartab; contains records for all scalar and array variables
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
305 ; Free space: unused memory between the object table and the stack; pointed to by freestart
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
306 ; The stack: grows downward from the bottom of string space, pointed to by the stack pointer, obviously
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
307 ; String space: garbage collected non-constant string data pointed to by freetop
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
308 ; Reserved memory: immediately above string space; pointed to by memsize
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
309 ; Actual top of RAM: top of reserved memory; pointed to by memtop
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
310 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
311 ; The variable table consists of several symbol tables defined as follows:
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
312 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
313 ; Pointer Size of entry Variable types
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
314 ; vartabint 4 Integer scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
315 ; vartablong 6 Long integer scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
316 ; vartabfloat 7 Floating point scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
317 ; vartabstring 6 String scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
318 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
319 ; Each entry starts with 2 bytes for the variable name followed by the data payload.
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
320 org 0x8000 ; the hardware puts the ROMs here; it's not negotiable
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
321 ROMSTART equ *
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
322 START orcc #0x50 ; make sure interrupts are disabled if we come here in an unusual way
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
323 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
324 ldu #gime_inite ; point to end of GIME initializer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
325 ldx #GIME.INIT0+(gime_inite-gime_init) ; point to end of GIME registers
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
326 ldb #gime_inite-gime_init ; number of bytes to transfer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
327 initc0 lda ,-u ; copy byte to GIME (count down so we init MMU before turning it on)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
328 sta ,-x
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
329 decb ; done?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
330 bne initc0 ; brif not
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
331 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
332 ldd #0xff34 ; initizer for below
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
333 tfr a,dp ; set DP to I/O page
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
334 setdp 0xff ; tell assembler about DP value
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
335 clr PIA0.CA ; set PIA0 A to direction mode
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
336 clr PIA0.CB ; set PIA0 B to direction mode
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
337 clr PIA0.DA ; set PIA0 A to all inputs (comparator, keyboard rows)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
338 sta PIA0.DB ; set PIA0 B to all outputs (keyboard columns)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
339 stb PIA0.CA ; set PIA0 A to data mode, interrupt disabled, MUX to source 0
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
340 stb PIA0.CB ; set PIA0 B to data mode, interrupt disabled, MUX to source 0
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
341 clr PIA1.CA ; set PIA1 A to direction mode
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
342 clr PIA1.CB ; set PIA1 B to direction mode
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
343 deca ; set PIA1 A bits 7-1 output (DAC, RS232), 0 input (cassette)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
344 sta PIA1.DA
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
345 lda #0xf8 ;* set PIA1 B bits 7-3 output (VDG stuff), 2-0 input (single bit sound,
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
346 sta PIA1.DB ;* RS232 input, ram size input)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
347 stb PIA1.CA ; set PIA1 A to data mode, interrupt disabled, cassette motor off
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
348 stb PIA1.CB ; set PIA1 B to data mode, interrupt disabled, sound off
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
349 lda #2 ; set RS232 output to "marking" (stop bit)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
350 sta PIA1.DA
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
351 lda #16 ; clear 16 SAM register bits
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
352 ldu #SAMREG ; point to SAM register bits
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
353 init0 sta ,u++ ; clear SAM bit
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
354 deca ; done all?
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
355 bne init0 ; brif not
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
356 ; set the SAM to point to the text screen, which the code will handle at any
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
357 ; arbitrary 512 byte aligned address in memory
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
358 ifne (textscreen)&0x200
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
359 sta SAM.F0SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
360 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
361 ifne (textscreen)&0x400
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
362 sta SAM.F1SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
363 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
364 ifne (textscreen)&0x800
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
365 sta SAM.F2SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
366 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
367 ifne (textscreen)&0x1000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
368 sta SAM.F3SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
369 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
370 ifne (textscreen)&0x2000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
371 sta SAM.F4SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
372 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
373 ifne (textscreen)&0x4000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
374 sta SAM.F5SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
375 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
376 ifne (textscreen)&0x8000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
377 sta SAM.F6SET
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
378 endc
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
379 ifdef COCO2B
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
380 ; The following SAM configuration sequence is different from the one in the usual
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
381 ; one used by the earlier models of the Coco because the Coco2B has the '785 variant
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
382 ; of the SAM instead of the '783 variant. The '785 variant supports 16Kx4 RAMs which
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
383 ; are used in Coco2B systems. Hence why there is a different version of this ROM
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
384 ; just for the Coco2B.
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
385 clr PIA0.DB ; strobe RAM size low
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
386 ldb #4 ; is input low?
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
387 bitb PIA1.DB
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
388 beq init1 ; brif not
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
389 sta SAM.M0SET ; program SAM for 16Kx4 RAMs
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
390 sta SAM.P1SET
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
391 skip2
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
392 init1 sta SAM.M1SET ; program SAM for 64Kx1 RAMs
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
393 else
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
394 ifndef COCO3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
395 ; Detect the installed memory size so the SAM ('783 variant) can be correctly
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
396 ; programmed for the installed memory. Note that this sequence is replaced with
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
397 ; a different one for the Coco2B which has the '785 variant of the SAM.
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
398 ldb #0xff ; strobe RAM size high
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
399 stb PIA0.DB
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
400 ldb #4 ; mask for ram size check
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
401 bitb PIA1.DB ; is the bit set on ram size input?
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
402 beq init2 ; brif not - 4Kx1 RAMs
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
403 sta PIA0.DB ; clear RAM size output to see what happens (A is 0 from above)
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
404 bitb PIA1.DB ; is it set now?
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
405 beq init1 ; brif not - 64Kx1 RAMs
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
406 leau -2,u ; adjust pointer so we set the other RAM size bit for the SAM (16Kx1)
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
407 init1 sta -3,u ; set M0 (16Kx1) or M1 (64Kx1)
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
408 endc
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
409 endc
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
410 init2 tfr a,dp ; set DP to bottom of memory (A is 0 from above)
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
411 setdp 0 ; tell assembler about it
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
412 lds #textscreen ; put the stack just below the text screen
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
413 ifdef COCO3
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
414 ; Check if we need to do a ROM/RAM copy, which will happen if the interrupt vectors are
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
415 ; not flagged valid OR the reset vector isn't valid
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
416 ldb INT.FLAG ; are the bounce vectors valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
417 cmpb #0x55
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
418 bne initc4 ; brif not - do ROM/RAM copy
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
419 ldb RSTFLG ; is reset vector valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
420 bne initc2 ; brif not - check secondary location
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
421 ldx RSTVEC ; get reset vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
422 ldb ,x ; is it valid?\
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
423 cmpb #0x12
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
424 bne initc2 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
425 initc1 jmp ,x ; transfer control to warm start routine
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
426 initc2 clr GIME.MMU0 ; check again with block 0 in the direct page
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
427 ldb RSTFLG ; get new RSTFLG
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
428 cmpb #0x55 ; valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
429 bne initc3 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
430 ldx RSTVEC ; get new RSTVEC
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
431 ldb ,x ; is it valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
432 cmpb #0x12
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
433 beq initc1 ; brif so - transfer control
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
434 initc3 ldb #0x38 ; restore MMU
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
435 stb GIME.MMU0
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
436 initc4 ldx #initc6 ; point to helper
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
437 ldu #textscreen ; point to text screen
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
438 ldb #initc7-initc6 ; bytes to copy
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
439 initc5 lda ,x+ ; copy byte
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
440 sta ,u+
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
441 decb ; done?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
442 bne initc5 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
443 ldu #0x8000 ; point to start of ROM
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
444 jmp textscreen ; transfer control to helper in RAM
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
445 initc6 sta SAM.TYCLR ; drop to ROM mode
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
446 pulu d,x,y,s ; grab 8 bytes
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
447 sta SAM.TYSET ; go to RAM mode
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
448 pshu d,x,y,s ; stick the bytes in RAM
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
449 leau 8,u ; move to next 8 bytes
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
450 cmpu #0xfe00 ; end of stuff to copy?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
451 blo initc6 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
452 jmp initc7 ; go back to mainline
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
453 initc7 lds #textscreen ; reset stack to somewhere safe
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
454 lda #0x12 ; activate ROM warm start handler
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
455 sta warmstart
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
456 ldx #INT.FLAG ; point to bounce vector destination
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
457 ldu #int_init ; point to initializer for bounce vectors
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
458 ldb #int_inite-int_init ; number of bytes to copy
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
459 initc8 lda ,u+ ; copy byte
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
460 sta ,x+
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
461 decb ; done?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
462 bne initc8 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
463 ; now recheck for warm start in case ROM/RAM copy made things valid
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
464 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
465 ldb RSTFLG ; is the reset vector valid?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
466 cmpb #0x55
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
467 bne coldstart ; brif not - do cold start
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
468 ldx RSTVEC ; get warm start routine pointer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
469 ldb ,x ; does it start with NOP?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
470 cmpb #0x12
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
471 bne coldstart ; brif not - do cold start
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
472 jmp ,x ; transfer control to warm start routine
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
473 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
474 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
475 ; GIME register initializer
10
8d4c0ffa2308 Fix GIME initializer so the text screen shows properly
William Astle <lost@l-w.ca>
parents: 8
diff changeset
476 gime_init fcb GIME_COCO|GIME_MMUEN|GIME_FExx|GIME_SCS|GIME_ROMI32 ; enable MMU, SCS, constant page, internal ROM
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
477 fcb GIME_TASK0 ; use MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
478 fcb 0 ; do not enable IRQ sources
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
479 fcb 0 ; do not enable FIRQ sources
10
8d4c0ffa2308 Fix GIME initializer so the text screen shows properly
William Astle <lost@l-w.ca>
parents: 8
diff changeset
480 fdb 0xfff ; set timer to max value
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
481 fdb 0 ; *reserved placeholder*
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
482 fcb 0,0,0,0 ; SG4 screen settings with black border
10
8d4c0ffa2308 Fix GIME initializer so the text screen shows properly
William Astle <lost@l-w.ca>
parents: 8
diff changeset
483 fcb 0x0f,0xe0,0x00,0x00 ; (puts screen in bottom 64K of memory)
6
80b9b4503bb4 Adjust Coco 3 default MMU map for stock ROM compatibility
William Astle <lost@l-w.ca>
parents: 5
diff changeset
484 fcb 0x38,0x39,0x3a,0x3b ; MMU task 0 (bottom of top 64K of RAM)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
485 fcb 0x3c,0x3d,0x3e,0x3f ; (ROM shadow must be in 3c...3f)
6
80b9b4503bb4 Adjust Coco 3 default MMU map for stock ROM compatibility
William Astle <lost@l-w.ca>
parents: 5
diff changeset
486 fcb 0x38,0x39,0x3a,0x3b ; MMU task 1 (copy of task 0)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
487 fcb 0x3c,0x3d,0x3e,0x3f
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
488 fcb 18,54,9,36,63,27,45,38 ; palette values (RGB)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
489 fcb 0,18,0,63,0,18,0,38
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
490 gime_inite equ *
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
491 int_init fcb 0x55 ; vectors valid flag
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
492 jmp SW3VEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
493 jmp SW2VEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
494 jmp FRQVEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
495 jmp IRQVEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
496 jmp SWIVEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
497 jmp NMIVEC ; bounce to stock ROM compatibility vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
498 int_inite equ *
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
499 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
501 ; Cold start handling
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
502 coldstart ldx #dpstart ; point to start of direct page
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
503 ldd #0 ; set up for blanking
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
504 coldstart0 std ,x++ ; blank a couple of bytes
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
505 cmpx #textscreen ; end of low memory?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
506 blo coldstart0 ; brif not
22
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
507 ifndef COCO3
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
508 ; This is the memory size detection sequence. This runs through memory starting at the bottom of memory
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
509 ; and stops when it reaches something that can't be modified successfully. This is basically the same
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
510 ; algorithm used by the stock ROM. It takes less space than doing a more pointed set of probes. The end
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
511 ; result will be X pointing to the byte one below the top of RAM. This is intentional to ensure there
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
512 ; is one writeable byte at the top of string space. Note that X will point to the byte after the end
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
513 ; of the text screen when we get here.
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
514 ldx #heapstart ; point to start of heap
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
515 coldstart1 lda 2,x ; get original value at test location
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
516 coma ; invert all bits
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
517 sta 2,x ; write it to the memory location
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
518 cmpa 2,x ; did it take?
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
519 bne coldstart2 ; brif not
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
520 com 2,x ; restore memory byte
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
521 leax 1,x ; move pointer forward
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
522 bra coldstart1 ; go check next byte
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
523 else
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
524 ; For the Coco3, we do not need to concern ourselves about where the top actual memory is so we don't
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
525 ; bother doing a memory scan in the default 64K memory map. Because we always run from RAM, we can actually
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
526 ; set the top of memory to the actual top of the 32K space without having to ensure there is an extra byte
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
527 ; available above the string space.
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
528 ldx #ROMSTART-1 ; point to top of memory
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
529 endc
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
530 coldstart2 stx memtop ; save absolute top of memory
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
531 stx memsize ; save top of unreserved memory
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
532 stx stringtab ; mark string space as empty
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
533 leax -200,x ; allocate 200 bytes of string space
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
534 stx freetop ; save top of free memory
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
535 clr ,-x ; make a hole for the "end of call stack" flag
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
536 stx stackptr ; save the new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
537 leas ,x ; put the actual stack below the above
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
538 ldx #heapstart ; point to start of free memory
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
539 clr ,x+ ; put a NUL before the start of the program
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
540 stx progtext ; put the start of the program there
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
541 clr ,x+ ; put a NULL pointer to mark end of program
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
542 clr ,x+
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
543 stx vartab ; put start of integer variables at end of program
24
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
544 stx objecttab ; also put the start of large objects there
9586c547fcfa Initialize the memory bookkeeping stuff at startup
William Astle <lost@l-w.ca>
parents: 23
diff changeset
545 stx freestart ; mark the start of free memory
37
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
546 lda #keyb_caps ; enable caps lock but disable all other shift states
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
547 sta keyb_flags
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
548 ldx #warmstart ; set up warm start handler
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
549 stx RSTVEC
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
550 lda #0x55 ; activate warm start handler
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
551 sta RSTFLG
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
552 ldd #0x7e3b ; opcodes for JMP extended and RTI
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
553 ldx #irqhandler ; enable IRQ handler with a JMP at the vector
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
554 sta IRQVEC
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
555 stx IRQVEC+1
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
556 sta FRQVEC ; initialize FIRQ handler with JMP
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
557 ldx #firqhandler
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
558 stx FRQVEC+1
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
559 stb NMIVEC ; initialize NMI to RTI
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
560 stb SW3VEC ; initialize SWI3 to RTI
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
561 stb SW2VEC ; initialize SWI2 to RTI
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
562 stb SWIVEC ; initialize SWI to RTI
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
563 ldx #greeting ; display greeting
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
564 jsr console_outstr
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
565 bra warmstartb ; finish up initialization
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
567 ; Warm start handling
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
568 ifdef COCO3
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
569 warmstart fcb 0xff ; set to 0xff to force ROM/RAM copy on reset
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
570 else
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
571 warmstart nop ; flag warm start routine as valid
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
572 endc
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
573 jsr console_clear ; clear screen
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
574 clr filenum ; reset I/O channel to the screen
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
575 warmstartb jsr keyb_reset ; reset the keyboard
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
576 lda #0x35 ; enable VSYNC interrupt in PIA
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
577 sta PIA0.CB
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
578 andcc #0xaf ; enable interrupts at the cpu
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
579 jmp immediate ; go start immediate mode
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
581 ; System startup message
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
582 ; (start with form feed to clear screen; saves 2 bytes over 'jsr console_clear' in cold start)
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
583 greeting fcc '\fLWBASIC VERSION 2022.0\r\n'
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
584 fcc 'COPYRIGHT (C) 2022 BY LOST\r\n'
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
585 fcc 'WIZARD ENTERPRISES INC.\r\n'
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
586 fcn '\n'
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
588 ; Check for BREAK; this needs to check the keyboard directly instead of just using the usual key fetching routine so
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
589 ; we don't interfere with keyboard buffering if BREAK isn't pressed. We also need to scan the keyboard directly for this
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
590 ; so we react even if the keyboard buffer is full. If BREAK is pressed, the keyboard buffer is emptied.
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
591 breakcheck lda #0xfb ; strobe column for BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
592 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
593 clra ; clear carry for no BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
594 lda PIA0.DA ; read rows
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
595 bita #0x40 ; is BREAK down?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
596 bne breakcheck0 ; brif not - check for SHIFT-@
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
597 sync ; wait for interrupt to scan keyboard
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
598 bsr keyb_clearbuff ; reset keyboard buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
599 coma ; flag BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
600 breakcheck1 rts
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
601 breakcheck0 lda #0x7f ; check for SHIFT
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
602 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
603 lda PIA0.DA
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
604 bita #0x40 ; shift?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
605 bne breakcheck1 ; brif not
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
606 lda #0xfe ; check for @
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
607 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
608 lda PIA0.DA
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
609 bita #1 ; @?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
610 bne breakcheck1 ; brif not
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
611 bsr keyb_clearbuff ; clear buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
612 breakcheck2 sync ; wait for keyboard to actually be scanned
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
613 bsr keyb_getkey
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
614 bcs breakcheck2 ; brif no key down
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
615 bra breakcheck ; go do the break/pause check dance again
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
617 ; Empty the keyboard buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
618 keyb_clearbuff ldx #keyb_buff ; point to start of buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
619 stx keyb_buffr ; set both pointers to the start
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
620 stx keyb_buffw
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
621 rts
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
622 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
623 ; IRQ handler
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
624 ;
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
625 ; Note that the interrupt flag in the PIA is cleared at the start of the interrupt handler. That means that if it takes
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
626 ; a long time to process this interrupt, or processing this interrupt was delayed somewhat, it is far less likely that
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
627 ; an interrupt gets missed. In that case, we may end up re-interrupting immediately on RTI, but it should reduce the
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
628 ; number of missed interrupts.
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
629 irqhandler lda PIA0.CB ; was it VSYNC?
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
630 bmi irqhandler0 ; brif so
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
631 lda PIA0.DA ; clear HSYNC flag so we don't get stuck if it gets enabled
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
632 ifdef COCO3
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
633 lda GIME.IRQ ; clear GIME IRQ state flags
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
634 endc
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
635 rti
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
636 irqhandler0 lda PIA0.DB ; clear VSYNC flag
16
d5ae140d19d4 Make sure DP is set correcting during IRQ handling
William Astle <lost@l-w.ca>
parents: 15
diff changeset
637 clra ; make sure DP is pointing to the right place
d5ae140d19d4 Make sure DP is set correcting during IRQ handling
William Astle <lost@l-w.ca>
parents: 15
diff changeset
638 tfr a,dp
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
639 lda console_blnkdel ; is the cursor blinking?
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
640 beq irqhandler1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
641 dec console_blnkdel ; time to cycle cursor?
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
642 bne irqhandler1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
643 lda #console_curdel ; reset blink counter
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
644 sta console_blnkdel
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
645 lda [console_curptr] ; get character at cursor
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
646 adda #0x10 ; move to next colour
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
647 ora #0x8f ; force it to be a full 4x4 colour block
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
648 sta [console_curptr] ; update cursor on screen
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
649 irqhandler1 bsr keyb_read ; go handle the keyboard
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
650 rti
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
652 ; FIRQ handler
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
653 ;
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
654 ; This handler is present to prevent accidentally enabling the interrupt and thus hanging to system. It may seem to be
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
655 ; a waste of code space, but consider it a self defense situation.
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
656 firqhandler pshs a ; need a scratch register
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
657 ifdef COCO3
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
658 lda GIME.FIRQ ; clear GIME FIRQ state flags
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
659 endc
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
660 lda PIA1.DA ; clear interrupt flags
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
661 lda PIA1.DB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
662 lda PIA1.CA ; disable interrupts to prevent system hang
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
663 anda #0xfe
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
664 sta PIA1.CA
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
665 lda PIA1.CB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
666 anda #0xfe
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
667 sta PIA1.CB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
668 puls a ; restore register
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
669 rti
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
671 ; Console keyboard input driver
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
672 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
673 ; Reset the keyboard state, which means clearing the buffer and state flags
61
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
674 keyb_reset bsr keyb_clearbuff ; clear keyboard buffer
37
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
675 lda keyb_flags ; reset keyboard state flags but keep capslock
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
676 anda #keyb_caps
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
677 sta keyb_flags
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
678 clr keyb_joystate ; clear joystick button state
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
679 clr keyb_curscan ; stop any keyboard repeating
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
680 ldx #0xffff ; mark all key state as "unpressed"
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
681 stx keyb_state
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
682 stx keyb_state+2
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
683 stx keyb_state+4
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
684 stx keyb_state+6
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
685 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
686 ; Read character from keyboard ring buffer; return with C set if buffer empty; this doesn't actually need to have
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
687 ; interrupts disabled because the interrupt only ever updates the write pointer and then only to increase it. As a
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
688 ; result, worst case is that we don't detect the contents added to the buffer on this call and have to wait for the
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
689 ; next.
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
690 keyb_getkey pshs x ; save register
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
691 ldx keyb_buffr ; get read pointer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
692 cmpx keyb_buffw ; same as write pointer?
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
693 bne keyb_getkey0 ; brif not - we have a result
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
694 coma ; set carry for empty buffer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
695 puls x,pc ; restore register and return
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
696 keyb_getkey0 lda ,x+ ; get character from buffer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
697 cmpx #keyb_buff+keyb_bufflen ; did we run off end of buffer?
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
698 blo keyb_getkey1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
699 ldx #keyb_buff ; reset to start
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
700 keyb_getkey1 stx keyb_buffr ; save new read pointer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
701 andcc #0xfe ; flag key retrieved
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
702 puls x,pc ; restore register and return
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
703 ; The PIA reading loop is specifically set up to NOT read PIA0.DB to avoid prematurely clearing the VSYNC interrupt flag
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
704 ; since that could lead to missing interrupts. Reading PIA0.DA will clear the HSYNC interrupt flag but that's less of a
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
705 ; problem because that interrupt is basically useless.
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
706 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
707 ; As a note, doing the PIA read in a loop ends up using an extra 27 CPU cycles for the BCS instruction. However, it
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
708 ; saves 70 code bytes. The trade off seems worth it in this case.
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
709 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
710 ; Once keyboard state is read, we do the following:
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
711 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
712 ; * update the state of SHIFT, CTRL, ALT
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
713 ; * decode all other keys in a loop
19
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
714 keyb_read0a pshs b ; save flag bit
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
715 ldb a,y ; get state flag
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
716 bitb #0x40 ; did it change state?
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
717 bne keyb_read0d ; brif so
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
718 puls b,pc ; clean up and return
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
719 keyb_read0d andb #0xbf ; flag it as not changed
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
720 stb a,y
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
721 ldb a,u ; get current modifier state
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
722 eorb #0x40 ; flip the state bit
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
723 stb a,u ; save new state flags
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
724 bitb #0x40 ; Z set if not down
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
725 puls b ; get back flag bit
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
726 beq keyb_read0b ; brif key is pressed
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
727 comb ; invert bit flag
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
728 andb keyb_flags ; clear bit in flags
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
729 bra keyb_read0c ; finish up
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
730 keyb_read0b orb keyb_flags ; set the flag
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
731 keyb_read0c stb keyb_flags ; update flags
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
732 rts
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
733 keyb_read leas -9,s ; make temporary buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
734 leay 1,s ; point to temporary state buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
735 clra ;* set to 0xff with C clear; start by strobing no columns for joystick
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
736 deca ;* then rotate the 0 bit through to do the actual keyboard columns
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
737 ldu #keyb_state ; point to end of keyboard state buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
738 sta PIA0.DB ; strobe no columns
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
739 ldb PIA0.DA ; get joystick button state
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
740 stb keyb_joystate ; save it for later when needed
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
741 andb #0x7f ; mask off comparator (pretend "button" down)
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
742 stb ,s ; save button/comparator state mask
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
743 rola ; set up for first column
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
744 keyb_read0 sta PIA0.DB ; set column strobe
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
745 ldb PIA0.DA ; read row data
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
746 eorb ,u+ ; set bits if state changed
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
747 andb ,s ; mask off comparator and active buttons
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
748 stb ,y+ ; save state change information
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
749 rola ; shift to next column
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
750 bcs keyb_read0 ; brif we haven't done the last column
19
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
751 sta PIA0.DB ; reset column strobe to none
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
752 ldd #0xff00|keyb_shift
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
753 bsr keyb_read0a
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
754 ldd #0xfc00|keyb_ctrl
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
755 bsr keyb_read0a
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
756 ldd #0xfb00|keyb_alt
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
757 bsr keyb_read0a
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
758 keyb_read3 ldd #0x0701 ; initialize bit probe and counter
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
759 keyb_read4 leay -1,y ; move pointers to next byte
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
760 leau -1,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
761 keyb_read5 bitb ,y ; did this key change state?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
762 bne keyb_read7 ; brif so
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
763 keyb_read6 adda #8 ; adjust scan code
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
764 lslb ; shift bit probe
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
765 bpl keyb_read5 ; brif we haven't done all bits
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
766 ldb ,y ; update state flags for this byte
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
767 eorb ,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
768 stb ,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
769 ldb #1 ; reset bit probe
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
770 anda #0x07 ; reset scan code
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
771 deca ; adjust for next column
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
772 bpl keyb_read4 ; brif not - do another
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
773 leas 9,s ; clean up stack
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
774 ldb keyb_curscan ; is key repeating?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
775 bne keyb_read9 ; brif so
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
776 keyb_reada rts
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
777 keyb_read7 bitb ,u ; get current state
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
778 bne keyb_read8 ; brif key pressed (make)
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
779 cmpa keyb_curscan ; is it the currently repeating key?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
780 bne keyb_read6 ; brif not - don't need to do anything
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
781 clr keyb_curscan ; clear the current repeat
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
782 bra keyb_read6
21
2264569d7aca Fix and speed up key repeat
William Astle <lost@l-w.ca>
parents: 20
diff changeset
783 keyb_read8 sta keyb_curscan ; set the current scan code that is repeating
2264569d7aca Fix and speed up key repeat
William Astle <lost@l-w.ca>
parents: 20
diff changeset
784 pshs d ; save current bit probe and scan code
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
785 ldb #keyb_repdeli ; intialize repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
786 stb keyb_repdel
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
787 bsr keyb_tobuff ; decode key to buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
788 puls d ; restore scan code and bit probe
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
789 bra keyb_read6 ; go handle the next bit
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
790 keyb_read9 dec keyb_repdel ; is it time to repeat it?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
791 bne keyb_reada ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
792 ldb #keyb_repdelr ; reset repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
793 stb keyb_repdel
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
794 lda keyb_curscan ; get current scan code
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
795 keyb_tobuff tsta ; @?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
796 beq keyb_tobuff7 ; brif so
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
797 cmpa #26 ; is it alpha or @?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
798 bhi keyb_tobuff6 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
799 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
800 bitb #keyb_ctrl|keyb_alt ; ALT or CTRL?
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
801 bne keyb_tobuff4 ; brif one or both
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
802 ora #0x60 ; make lower case
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
803 bitb #keyb_caps ; capslock enabled?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
804 beq keyb_tobuff0 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
805 eora #0x20 ; flip to upper case
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
806 keyb_tobuff0 bitb #keyb_shift ; shifted?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
807 beq keyb_tobuff1 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
808 eora #0x20 ; flip case if shifted
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
809 keyb_tobuff1 ldx keyb_buffw ; get write pointer for keyboard buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
810 sta ,x+ ; put it in the buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
811 cmpx #keyb_buff+keyb_bufflen ; end of buffer?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
812 blo keyb_tobuff2 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
813 ldx #keyb_buff ; reset pointer to start
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
814 keyb_tobuff2 cmpx keyb_buffr ; did we run into the read pointer?
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
815 beq keyb_tobuff3 ; brif so - there wasn't room so don't save pointer
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
816 stx keyb_buffw ; update the write pointer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
817 keyb_tobuff3 rts
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
818 keyb_tobuff4 bitb #keyb_alt ; is ALT?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
819 beq keyb_tobuff1 ; brif not - scan code is CTRL-<letter> code
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
820 ora #0x80 ; set bit 7 for "ALT" codes
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
821 bitb #keyb_shift ; shifted?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
822 beq keyb_tobuff5 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
823 ora #0x20 ; set bit 5
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
824 keyb_tobuff5 bitb #keyb_ctrl ; ctrl?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
825 beq keyb_tobuff1 ; brif not - stash it in the buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
826 ora #0x40 ; set bit 6 for "ctrl
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
827 bra keyb_tobuff1 ; stash it the buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
828 keyb_tobuff6 suba #26 ; codes above 26 down to 1; @ will be 0
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
829 keyb_tobuff7 cmpa #6 ; is it "0"?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
830 bne keyb_tobuff8 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
831 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
832 bitb #keyb_shift|keyb_ctrl ; CTRL-0 or SHIFT-0?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
833 beq keyb_tobuff8 ; brif not - not "capslock"
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
834 eorb #keyb_caps ; flip the capslock state
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
835 stb keyb_flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
836 keyb_tobuffa rts ; and don't put it in the buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
837 keyb_tobuff8 cmpa #25 ; is it at or above ALT?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
838 blo keyb_tobuff9 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
839 suba #2 ; close gap for ALT/CTRL
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
840 keyb_tobuff9 ldb #8 ;* 8 codes; multiply by 8 and move to B
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
841 mul ;*
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
842 ldx #keyb_codetab ; point to special code table
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
843 abx ; now X points to the base entry in the table
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
844 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
845 andb #keyb_shift|keyb_ctrl|keyb_alt ; keep only shift/ctrl/alt
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
846 lda b,x ; fetch key code
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
847 beq keyb_tobuffa ; brif no code to return
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
848 bra keyb_tobuff1 ; go stash it in the buffer
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
849 ; This is the keyboard code table; there are 8 bytes per entry in the following order:
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
850 ; 0: unmodified
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
851 ; 1: shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
852 ; 2: ctrl
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
853 ; 3: ctrl-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
854 ; 4: alt
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
855 ; 5: alt-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
856 ; 6: alt-ctrl
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
857 ; 7: alt-ctrl-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
858 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
859 ; No entries for ALT, CTRL, SHIFT, or letters
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
860 keyb_codetab fcb 0x40,0x13,0x40,0x40,0x80,0xa0,0xc0,0xe0 ; @
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
861 fcb 0x5e,0x5f,0x00,0x00,0x00,0x00,0x00,0x00 ; <UP>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
862 fcb 0x0a,0x5b,0x00,0x00,0x00,0x00,0x00,0x00 ; <DOWN>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
863 fcb 0x08,0x15,0x00,0x00,0x00,0x00,0x00,0x00 ; <LEFT>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
864 fcb 0x09,0x5d,0x00,0x00,0x00,0x00,0x00,0x00 ; <RIGHT>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
865 fcb 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20 ; <SPACE>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
866 fcb 0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 0 (shift/ctrl variants shadowed above)
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
867 fcb 0x31,0x21,0x00,0x00,0x00,0x00,0x00,0x00 ; 1 !
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
868 fcb 0x32,0x22,0x00,0x00,0x00,0x00,0x00,0x00 ; 2 "
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
869 fcb 0x33,0x23,0x00,0x00,0x00,0x00,0x00,0x00 ; 3 #
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
870 fcb 0x34,0x24,0x00,0x00,0x00,0x00,0x00,0x00 ; 4 $
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
871 fcb 0x35,0x25,0x00,0x00,0x00,0x00,0x00,0x00 ; 5 %
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
872 fcb 0x36,0x26,0x00,0x00,0x00,0x00,0x00,0x00 ; 6 &
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
873 fcb 0x37,0x27,0x00,0x00,0x00,0x00,0x00,0x00 ; 7 '
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
874 fcb 0x38,0x28,0x00,0x00,0x00,0x00,0x00,0x00 ; 8 (
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
875 fcb 0x39,0x29,0x00,0x00,0x00,0x00,0x00,0x00 ; 9 )
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
876 fcb 0x3a,0x2a,0x00,0x00,0x00,0x00,0x00,0x00 ; : *
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
877 fcb 0x3b,0x2b,0x00,0x00,0x00,0x00,0x00,0x00 ; ; +
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
878 fcb 0x2c,0x3c,0x00,0x00,0x00,0x00,0x00,0x00 ; , <
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
879 fcb 0x2d,0x3d,0x00,0x00,0x00,0x00,0x00,0x00 ; - =
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
880 fcb 0x2e,0x3e,0x00,0x00,0x00,0x00,0x00,0x00 ; . >
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
881 fcb 0x2f,0x3f,0x00,0x00,0x00,0x00,0x00,0x00 ; / ?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
882 fcb 0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d ; <ENTER>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
883 fcb 0x0c,0x5c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c ; <CLEAR>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
884 fcb 0x03,0x03,0x1b,0x1b,0x9b,0xbb,0xdb,0xfb ; <BREAK>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
885 fcb 0x1c,0x1d,0x1c,0x1d,0x00,0x00,0x00,0x00 ; <F1>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
886 fcb 0x1e,0x1f,0x1e,0x1f,0x00,0x00,0x00,0x00 ; <F2>
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
888 ; Console screen output driver
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
889 ;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
890 ; Clear screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
891 console_clear ldb #0x60 ; VDG space character
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
892 ldx #textscreen ; point to text screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
893 stx console_curptr ; set cursor pointer to start of screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
894 console_clear0 stb ,x+ ; blank a character
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
895 cmpx #textscreen+0x200 ; end of screen?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
896 blo console_clear0 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
897 rts
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
898 ; Output NUL terminated string
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
899 console_outstr0 bsr console_outchr ; output the character
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
900 console_outstr lda ,x+ ; get byte from string
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
901 bne console_outstr0 ; brif not end of string
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
902 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
903 ; Output NUL terminated string followed by a newline
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
904 console_outstrn bsr console_outstr ; output the string
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
905 ; fallthrough intentional
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
906 ; Output a newline (CR LF)
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
907 console_outnl lda #0x0d ; do the CR
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
908 bsr console_outchr
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
909 lda #0x0a ; do the LF
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
910 ; fallthrough intentional
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
911 ; Output a single character to the screen; enter with character in A
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
912 console_outchr pshs d,x ; save registers
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
913 ldx console_curptr ; get current cursor pointer
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
914 cmpa #0x20 ; printable character?
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
915 blo console_outchr5 ; brif not
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
916 tsta ; is it a graphics block?
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
917 bmi console_outchr1 ; brif so - don't do anything to it
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
918 cmpa #0x40 ; number or most non-alpha characters?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
919 blo console_outchr0 ; brif so - will need to flip bit 6
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
920 cmpa #0x60 ; upper case?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
921 blo console_outchr1 ; brif so - don't need to do anything to it
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
922 anda #0xdf ; clear bit 5 of lower case; moves it to bottom of character set
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
923 console_outchr0 eora #0x40 ; flip bit 6 - the "inversion" bit
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
924 console_outchr1 sta ,x+ ; stick it on screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
925 console_outchr2 stx console_curptr ; save new cursor pointer
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
926 cmpx #textscreen+0x200 ; end of screen?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
927 blo console_outchr4 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
928 leax -32,x ; move pointer back one line
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
929 stx console_curptr
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
930 ldx #textscreen ; point to start of screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
931 console_outchr3 ldd 32,x ; get bytes from next line
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
932 std ,x++ ; stick them here
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
933 cmpx #textscreen+0x1e0 ; at last row?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
934 blo console_outchr3 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
935 ldb #0x60 ; space character for VDG screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
936 bsr console_clear0 ; blank out last row (borrowing screen clear loop)
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
937 console_outchr4 puls d,x,pc ; restore registers and return
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
938 console_outchr5 cmpa #0x0c ; form feed?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
939 bne console_outchr6 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
940 bsr console_clear ; clear screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
941 puls d,x,pc ; restore registers and return
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
942 console_outchr6 cmpa #0x0d ; carriage return?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
943 bne console_outchr7 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
944 ldb console_curptr+1 ; get current screen pointer LSB
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
945 andb #0xe0 ; reset offset to start of line
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
946 stb console_curptr+1 ; save new pointer LSB
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
947 puls d,x,pc ; restore registers and return
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
948 console_outchr7 cmpa #0x0a ; line feed?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
949 bne console_outchr8 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
950 ldx console_curptr ; get cursor pointer
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
951 leax 32,x ; move it forward exactly one line
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
952 bra console_outchr2 ; go update stuff check for scroll
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
953 console_outchr8 cmpa #0x08 ; backspace?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
954 bne console_outchr9 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
955 cmpx #textscreen ; at start of screen?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
956 beq console_outchr4 ; brif so - backspace does nothing
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
957 leax -1,x ; back up pointer (backspace is non-destructive)
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
958 bra console_outchr2 ; go update pointers, etc.
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
959 console_outchr9 cmpa #0x09 ; TAB character?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
960 bne console_outchr4 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
961 ldb console_curptr ; get LSB of pointer
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
962 andb #7 ; 8 space tabs - only keep low 3 bits
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
963 lda #0x60 ; space character (tab is destructive)
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
964 console_outchra sta ,x+ ; put a space out
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
965 incb ; bump counter
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
966 cmpb #8 ; at next tab stop?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
967 blo console_outchra ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
968 bra console_outchr2 ; go update details and check for scroll
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
970 ; General I/O handling package
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
971 ;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
972 ; These routines operate on the I/O channel specified by filenum. The defined values of filenum are:
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
973 ;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
974 ; 0: keyboard/screen console
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
975 ;
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
976 ; Read a line from the active file into linebuff. The resulting line will be NUL terminated leading to at most
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
977 ; linbuffsize-1 character input. The trailing CR/LF will not be included. The input will be echoed if linebuffecho is
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
978 ; enabled. Exit with the length of the input line in B.
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
979 readline ldx #linebuff ; point to line input buffer
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
980 clr ,x ; make sure buffer is NUL terminated
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
981 readline0 bsr readchr ; read an input character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
982 bcs readline1 ; brif not EOF
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
983 cmpa #0x0d ; CR (carriage return)
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
984 beq readline1 ; brif so - return
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
985 cmpa #0x03 ; BREAK?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
986 bne readline3 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
987 coma ; set carry for irregular exit
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
988 skip1
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
989 readline1 clra ; clear carry for regular exit
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
990 pshs cc ; save carry state
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
991 lda readlinenoecho ; are we echoing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
992 bne readline2 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
993 lda #0x0d ; echo carriage return + line feed
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
994 bsr writechr
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
995 readline2 tfr x,d ; get end address after input
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
996 subd #linebuff ; subtract start of buffer; D is now length and C is clear
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
997 clr ,x ; make sure line is NUL terminated
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
998 puls cc,pc ; restore BREAK flag (C) and return
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
999 readline3 cmpa #0x08 ; backspace?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1000 bne readline4 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1001 cmpx #linebuff ; at start of buffer?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1002 beq readline0 ; brif so - do nothing
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1003 leax -1,x ; move back buffer pointer
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1004 bsr readlinee ; write a BS
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1005 lda #0x20 ; write a space
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1006 bsr readlinee
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1007 lda #0x08 ; and finally a BS
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1008 bsr readlinee
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1009 bra readline0 ; go process more characters
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1010 readline4 cmpa #0x0c ; form feed?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1011 bne readline5 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1012 bsr readlinee ; go echo character if needed
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1013 bra readline ; go restart line entry
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1014 readline5 cmpa #0x20 ; is it non-printing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1015 blo readline0 ; brif so - don't store it and continue
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1016 bsr readlines ; stash character in buffer and echo if necessary
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1017 bra readline0 ; go get another character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1018 readlines cmpx #linebuff+linebuffsize-1 ; is the line buffer full?
20
0b3b4daa0d92 Fix off by one when detecting if line input buffer full
William Astle <lost@l-w.ca>
parents: 19
diff changeset
1019 bhs readlinee0 ; brif so - don't store character OR echo it
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1020 sta ,x+ ; stash character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1021 readlinee ldb readlinenoecho ; are we echoing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1022 bne readlinee0 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1023 bsr writechr ; echo the character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1024 readlinee0 rts
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1026 ; Write a newline if not at left margin. This will unconditinally output a newline for devices where the horizontal
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1027 ; position is not knowable.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1028 writecondnl lda filenum ; get file number
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1029 bne writenl ; brif not screen - we'll do it unconditionally
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1030 lda console_curptr+1 ; get LSB of cursor pointer
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1031 anda #0x1f ; keep only the low 5 bits (32 characters per line)
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1032 beq writecondnl0 ; brif no newline is needed
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1033 ; fallthrough intended
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1035 ; Write a newline to the chosen device.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1036 writenl lda #0x0d ; code for carriage return - will serve as newline
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1037 ; fallthrough intended
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1038 ; Write a character to the active file; all registers preserved but C will be set if the output file cannot handle
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1039 ; an output character (doesn't exist, etc.)
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1040 writechr tst filenum ; is it screen?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1041 beq writechr_scr ; brif writing to screen
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1042 orcc #1 ; unknown device flag
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1043 writecondnl0 rts
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1044 ; Handle output to the screen. This is where we convert CR to CRLF
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1045 writechr_scr jsr console_outchr ; output the character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1046 cmpa #0x0d ; was it CR?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1047 bne writechr_scr0 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1048 lda #0x0a ; ouptut an LF
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1049 jsr console_outchr
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1050 lda #0x0d ; restore original value
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1051 writechr_scr0 andcc #0xfe ; clear error flag
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1052 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1053 ; Read a character from the active file and return it in A; in the event that EOF is detected, readeof will be nonzero
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1054 ; and the call will return with carry set.
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1055 readchr clr fileeof ; flag not end of file (and clear carry)
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1056 lda filenum ; get input file number
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1057 beq readchr_kb ; brif keyboard input
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1058 com fileeof ; flag end of file (C set and fileeof nonzero)
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1059 rts
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1060 ; Read character from keyboard; blink cursor while doing so
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1061 readchr_kb pshs b ; preserve B as temp storage
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1062 ldb [console_curptr] ; get character at cursor
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1063 inc console_blnkdel ; activate cursor blinking (first interrupt will cycle it)
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1064 readchr_kb0 jsr keyb_getkey ; read keyboard
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1065 bcc readchr_kb1 ; brif we got a result
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1066 cwai #0xaf ; wait for interrupt to scan keyboard
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1067 bra readchr_kb0 ; see if we have something yet
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1068 readchr_kb1 clr console_blnkdel ; disable cursor blinking
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1069 stb [console_curptr] ; restore screen character
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1070 clrb ; clear carry to indicate not eof
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1071 puls b,pc ; restore temp and return
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1073 ; Write a character to the selected output device. If the device is one that does not support actual lower case, then
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1074 ; conver the character to upper case. Otherwise, pass it through as is. Currently, only the console screen falls into
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1075 ; this category. This *will* modify the character in A if a change is made.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1076 writechrconduc tst filenum ; is it screen?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1077 bne writechr ; brif not - just output it
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1078 tst console_truelc ; does the current text screen support actual lower case?
35
336be9cef342 Fix test in writechrconduc to test true lower case flag correctly
William Astle <lost@l-w.ca>
parents: 34
diff changeset
1079 bne writechr ; brif so - just output character
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1080 cmpa #'a ; is it lower case?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1081 blo writechr ; brif not
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1082 cmpa #'z ; is it still lower case?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1083 bhi writechr ; brif not
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1084 suba #0x20 ; shift to upper case
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1085 bra writechr ; go output it
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1087 ; Write a NUL terminated string at X to the screen. Conditionally convert to upper case based on the screen type.
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1088 writestrconduc0 bsr writechrconduc ; output the character
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1089 writestrconduc lda ,x+ ; fetch character from string
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1090 bne writestrconduc0 ; brif not end of string
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1091 rts
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1093 ; Fetch next input character, skip spaces. This is structured the way it is to avoid burning any register except A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1094 ; which is used for the returned value. Z will be set if the input character is NUL or a colon. C will be set if the
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1095 ; input character is an ASCII digit. This allows testing Z to identify the end of a command due to either a colon or
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1096 ; the end of a line.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1097 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1098 ; Compared to Color Basic, the instruction sequence only varies in the handling of the LDA. In Color Basic, the sequence
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1099 ; is an LDA extended followed by a JMP extended. This totals to 9 cycles (5 for LDA, 4 for JMP). In LWBasic, an LDA
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1100 ; with extended indirect addressing is used. This also totals 9 cycles. The only other difference is when a space is
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1101 ; detected where the branch can be direct to the nextchar code instead of having to branch around a direct page JUMP
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1102 ; which saves 3 cycles for the case where a space is detected. In other words, this is only slower by virtue of the
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1103 ; fact that it is called with an extended JSR instead of a direct JSR which causes one extra cycle to be used there
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1104 ; and one extra byte for each call to nextchar or curchar.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1105 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1106 ; On 6309, native move saves an extra cycle in the LDA sequence using the LDA extended followed by JMP extended
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1107 ; sequence.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1108 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1109 ; This whole thing could be sped up by keeping the input pointer in a register. However, retaining the ability to
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1110 ; use Y without having to save it first is likely more beneficial.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1111 nextchar inc inputptr+1 ; bump LSB of input pointer
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1112 bne curchar ; brif no carry
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1113 inc inputptr ; bump MSB
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1114 curchar lda [inputptr] ; read the byte
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1115 cmpa #'9+1 ; clear C if above ASCII digits, Z if colon
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1116 bhs curchar0 ; brif above the ASCII digits
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1117 cmpa #0x20 ; is it a space?
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1118 beq nextchar ; brif so - skip over it
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1119 suba #'0 ; clever way to set C if >= ASCII 0, Z if zero
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1120 suba #-'0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1121 curchar0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1123 ; This is exactly the same as nextchar except it doesn't skip spaces. Unfortunately, for efficiency purposes, we need
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1124 ; to actually duplicate code here.
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1125 nextcharraw inc inputptr+1 ; bump LSB of input pointer
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1126 bne curchar ; brif no carry
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1127 inc inputptr ; bump MSB
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1128 curcharraw lda [inputptr] ; fetch the byte
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1129 cmpa #'9+1 ; clear C if above digits, set Z if colon
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1130 bhs curcharraw0 ; brif above digits
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1131 suba #'0 ; clever way to set C if >= ASCII 0, Z if zero
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1132 suba #-'0
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1133 curcharraw0 rts
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1135 ; The error handler
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1136 ;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1137 ; Enter with the error number in B. This routine will do some cleanup and handle any ON ERROR GOTO handler that
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1138 ; may be active.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1139 ;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1140 ; Note the error message lookup does not need to be efficient which is why the lookup just runs through the list
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1141 ; of error messages in sequence looking for NUL terminators. The specific handling of B (error number) below avoids
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1142 ; issues if there happen to be error codes above 128.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1143 ERROR clr filenum ; reset display device to console
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1144 jsr writecondnl ; do a newline if needed (will preserve B)
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1145 ldx #errormsg ; point to error message list
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1146 incb ; account for decb below
36
c786c1dd4632 Fix ERROR routine to actually work
William Astle <lost@l-w.ca>
parents: 35
diff changeset
1147 bra ERROR1 ; go search for correct message
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1148 ERROR0 lda ,x+ ; end of message?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1149 bne ERROR0 ; brif not end of message
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1150 ERROR1 decb ; at the correct one?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1151 bne ERROR0 ; brif not - skip to next one
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1152 ERROR2 jsr writestrconduc ; output error message
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1153 ldu curline ; are we in immediate mode?
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1154 beq ERROR3 ; brif so
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1155 ldx #inmsg ; point to " in "
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1156 jsr writestrconduc ; output " in "
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1157 ldd 2,u ; get line number
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1158 jsr print_uint16d ; display the line number
36
c786c1dd4632 Fix ERROR routine to actually work
William Astle <lost@l-w.ca>
parents: 35
diff changeset
1159 ERROR3 lds freetop ; reset the stack pointer (error routine could be called anywhere)
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1160 clr ,-s ; reset the call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1161 sts stackptr
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1162 ; fall through to immediate mode intentional
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1164 ; Immediate mode handler
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1165 immediate jsr writecondnl ; do newline if required
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1166 ldx #prompt ; point to prompt string
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1167 jsr console_outstrn
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1168 immediate0 jsr readline ; read input line
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1169 bcs immediate0 ; brif ended with BREAK
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1170 ldx #linebuff ; point to start of line input buffer
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1171 stx inputptr ; set input pointer
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1172 jsr curchar ; skip spaces and set flags
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1173 bcs immediate1 ; brif there's a line number
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1174 tsta ; is there anything there at all (end of line)?
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1175 beq immediate0 ; brif not - read another line
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1176 ldx inputptr ; get the modified input pointer processing above
46
8d9345b6d3a9 Fix parsing empty DATA statements
William Astle <lost@l-w.ca>
parents: 45
diff changeset
1177 jsr tokenize ; tokenize the line at inputptr, return with result at tokebuff and X
31
e74a975b38d9 Enable and correct logic error in immediate mode line interpretation
William Astle <lost@l-w.ca>
parents: 30
diff changeset
1178 jsr interpretline ; go interpret the tokenized line
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1179 bra immediate ; go handle another line
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1180 immediate1 bsr parse_lineno ; parse the line number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1181 bsr prog_findline ; go see if the line is in the program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1182 bne immediate3 ; brif not - no need to delete it
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1183 ldu ,x ; get next line pointer which is where we start the copy from
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1184 leay ,x ; use temp pointer for copying
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1185 immediate2 lda ,u+ ; get source byte
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1186 sta ,y+ ; stash it
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1187 cmpu vartab ; did we reach the end of the program text?
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1188 blo immediate2 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1189 sty vartab ; save new end of program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1190 immediate3 jsr curchar ; skip any spaces after line number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1191 tsta ; is it the end of input (don't test for colon)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1192 beq immediate6 ; brif so - we don't need to insert a line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1193 pshs x ; save program insert location and line number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1194 ldx inputptr ; point to line text
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1195 jsr tokenize ; tokenize line, get length to D
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1196 leay ,x ; save tokenized line pointer
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1197 addd #4 ; account for next line pointer and line number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1198 ldx vartab ; get start of copy location
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1199 leau d,x ; set destination copy location D bytes further up
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1200 stu vartab ; save new end of program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1201 immediate4 lda ,-x ; get byte from program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1202 sta ,-u ; stash it above the empty space
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1203 cmpx ,s ; did we reach the insertion point?
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1204 bne immediate4 ; brif not - keep going
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1205 leas 2,s ; clear insertion location
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1206 stu ,x++ ; set next line pointer to not null
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1207 ldd binval ; set the line number for the program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1208 std ,x++
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1209 immediate5 lda ,y+ ; get byte from tokenized line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1210 sta ,x+ ; stash it in the program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1211 bne immediate5 ; brif not at end of tokenized line (see note for fixlineptrs)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1212 immediate6 bsr prog_fixlineptrs ; fix up line pointers (all of them)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1213 ldx vartab ; clear out variables
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1214 stx objecttab
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1215 stx freestart
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1216 bra immediate0 ; go handle more input
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1218 ; Fix up next line pointers. Enter at prog_fixlineptrs to do the entire program. Enter at prog_fixlineptrsx to start
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1219 ; at the line pointered to by X, which MUST NOT point to the end of the program.
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1220 ;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1221 ; Works by simply scanning for a NUL in the program text after a line header (pointer to next line and line number)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1222 ; and uses that as the new next line pointer. A NULL next line pointer flags the end of the program.
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1223 ;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1224 ; Observation: if the program text format is changed such that it can include NULs embedded within a line, this routine
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1225 ; will need to be updated to grok that.
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1226 prog_fixlineptrs
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1227 ldx progtext ; point to start of program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1228 prog_fixlineptrsx
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1229 ldu ,x ; are we at the end of the program?
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1230 beq prog_findline2 ; brif not (borrow RTS from findline)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1231 leau 4,x ; point to line text (past pointer and line number)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1232 prog_fixlineptrs1
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1233 lda ,u+ ; are we at the end of this line?
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1234 bne prog_fixlineptrs1 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1235 stu ,x ; set the next pointer for the previous line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1236 leax ,u ; move to the next line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1237 bra prog_fixlineptrsx ; go handle the next line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1239 ; Find a line in the program. Returns with C set and Z clear if no match and C clear and Z set if a match is found. X
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1240 ; will point to either the exact matched line *or* the line that would be immediately after the desired line number if
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1241 ; the line had been present, which could be the end of the program. D and U are clobbered. Enter at prog_findlinex to
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1242 ; start searching at the line pointed to by X. Enter at prog_findline to start at the beginning of the program. Enter
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1243 ; with the desired line number in binval.
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1244 prog_findlinecl ldx curline ; get current line pointer
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1245 beq prog_findline ; brif immediate mode
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1246 ldd binval ; get desired line number
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1247 cmpd 2,x ; is the desired line number >= current line?
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1248 beq prog_findline2 ; brif this is the right line (optimizes goto self)
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1249 bhi prog_findlinex ; brif desired line higher: start here instead of program start
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1250 prog_findline ldx progtext ; point to start of program
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1251 prog_findlinex ldu binval ; get line number to search for
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1252 prog_findline0 ldd ,x ; end of program?
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1253 beq prog_findline1 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1254 cmpu 2,x ; does line number match? Z set if so, clear if not; C set not found
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1255 bls prog_findline2
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1256 ldx ,x ; move to next line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1257 bra prog_findline0 ; see if we found the line yet
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1258 prog_findline1 coma ; set carry for not found; also clears Z because D is zero from above
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1259 prog_findline2 rts
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1261 ; Parse a line number and return it in binval; raise syntax error if the line number overflows 16 bits unsigned.
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1262 ; Preserves; registers except D. This will accept the entire 16 bit unsigned number range which is why there is
43
b27b34d0afff Fix line number parsing to actually handle first character
William Astle <lost@l-w.ca>
parents: 42
diff changeset
1263 ; a BCS after every shift or add. Enter with the input pointer pointing to the number to parse.
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1264 parse_lineno ldd zero ; clear out accumlator but preserve carry flag
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1265 std binval
43
b27b34d0afff Fix line number parsing to actually handle first character
William Astle <lost@l-w.ca>
parents: 42
diff changeset
1266 jsr curchar ; set flags on current character; skip spaces
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1267 bcc parse_lineno1 ; brif first character wasn't a digit - default to zero
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1268 parse_lineno0 suba #0x30 ; adjust to binary digit
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1269 pshs a ; save digit so we can add it later
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1270 ldd binval ; get accumulated number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1271 lslb ; multiply accumulator by 10
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1272 rola ; times 2
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1273 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1274 lslb
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1275 rola ; times 4
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1276 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1277 addd binval ; times 5 (add orignal value to times 4)
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1278 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1279 lslb
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1280 rola ; times 10
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1281 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1282 addb ,s+ ; add in accumulated digit
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1283 adca #0
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1284 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1285 std binval ; save accumulated number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1286 jsr nextcharraw ; get next input character; DO NOT skip spaces
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1287 bcs parse_lineno0 ; brif it's also a digit
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1288 parse_lineno1 rts
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1290 ; The NEW command.
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1291 ;
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1292 ; This also includes several useful entry points:
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1293 ;
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1294 ; cmd_newraw: does the whole NEW but without any syntax checks
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1295 ; cmd_newinptr: skips clearing the program text
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1296 ; cmd_newvars: clears variables and resets the stack and other misc state
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1297 ; cmd_newstack: just reset the stack and other misc state
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1298 cmd_new bne parse_lineno1 ; brif there was an argument - don't wipe things out on syntax error
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1299 cmd_newraw ldx progtext ; point to start of program
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1300 clr -1,x ; make sure there's a NUL before the start of the program
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1301 clr ,x+ ; put a NULL pointer at the start of the program
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1302 clr ,x+
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1303 stx vartab ; set start of variables after that
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1304 cmd_newinptr ldx progtext ;* set input pointer to the NUL before the program; this will cause the
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1305 leax -1,x ;* the interpreter to drop to immediate mode no matter what it was
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1306 stx inputptr ;* executing before this call if called from the main loop
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1307 cmd_newvars ldx memsize ; get top of memory
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1308 stx stringtab ; clear out string space
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1309 ldx vartab ; get start of variables
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1310 stx objecttab ; set start of large objects (arrays) there too (clear vars)
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1311 stx freestart ; set start of free memory (end of large objects) (clear arrays)
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1312 cmd_newstack ldx #stringstackend ; reset string stack (string stack counts down)
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1313 stx stringstackptr
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1314 ldx ,s ; get return address
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1315 lds freetop ; reset stack to top of memory
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1316 clr ,-s ; put a flag to stop stack searches (NEXT, RETURN)
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1317 sts stackptr ; reset pointer for call stack
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1318 clr contstmt ; clear "CONT" destination
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1319 clr contstmt+1
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1320 jmp ,x ; return to caller
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1322 ; Main interpretation loop
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1323 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1324 ; Enter at interpret with inputptr pointing to the code stream to interpret.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1325 ; Enter at interpretline with X pointing to the command stream to interpret which will return to the caller one the
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1326 ; command stream has completed. STOP or BREAK will return with carry set while END or falling off the end of the
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1327 ; code will return with carry clear. In the event of an error, the usual error processing will be done and control
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1328 ; will return to immediate mode with the stack reset.
61
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
1329 interpret jsr breakcheck ; check for BREAK
57
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1330 bcs cmd_stop0 ; brif BREAK detected - go stop the program
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1331 ldx inputptr ; get interpration address
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1332 stx curstmt ; save address of the current statement (needed for some stuff)
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1333 lda ,x+ ; are we at the end of the line?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1334 beq interpret0 ; brif so
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1335 cmpa #': ; end of statement?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1336 beq interpret3 ; brif so - do a statement
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1337 SNERROR ldb #err_sn ; raise a syntax error
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1338 jmp ERROR
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1339 interpret0 sta endflag ; flag the program exit state as "END" (will be zero)
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1340 ldd curline ; were we in immediate mode?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1341 bne interpret1 ; brif not
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1342 clra ; clear carry to indicate normal exit
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1343 rts ; return to caller
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1344 interpret1 ldd ,x ; are we at the end of the program?
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1345 beq interpret4 ; brif so - bail out
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1346 stx curline ; save pointer to current line
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1347 leax 3,x ; set input pointer one before the start of the line text
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1348 interpret2 stx inputptr
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1349 interpret3 jsr nextchar ; fetch first character of next statement
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1350 beq interpret ; brif end of statement - do the next statement dance
38
ef961e1c30cb Detect tokens in interpretation loop correctly
William Astle <lost@l-w.ca>
parents: 37
diff changeset
1351 tsta ; set flags properly for token
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
1352 lbpl cmd_let ; brif no command - do assignment (LET command is optional)
31
e74a975b38d9 Enable and correct logic error in immediate mode line interpretation
William Astle <lost@l-w.ca>
parents: 30
diff changeset
1353 ldx #primaryjump ; point to jump table
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1354 anda #0x7f ; lose bit 7
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1355 leax a,x ; get half way to the correct offset
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1356 ldx a,x ; get the address the other half of the way from here
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1357 jsr nextchar ; skip past token and set flags
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1358 jsr ,x ; call the routine
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1359 bra interpret ; go handle the next statement dance
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1360 interpret4 bsr cmd_stop1 ; make sure stack is aligned correctly (will not return)
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1361 interpretline clr curline ; blank out current line pointer (for immediate mode)
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1362 clr curline+1
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1363 leax -1,x ; move back before start of code stream
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1364 bra interpret2 ; go interpret this statement and then continue with stuff
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1366 ; Check for character in B and raise a syntax error if not found at current input pointer. If it is found, fetch the
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1367 ; next input character.
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1368 syncheckb cmpb [inputptr] ; do we have a syntax match?
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1369 bne SNERROR ; brif not
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1370 jmp nextchar ; return next input character
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1372 ; The END command.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1373 cmd_end bne SNERROR ; error out if there is an argument
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1374 ;jsr closeall ; close all files for END
57
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1375 clra ; flag END (clear carry)
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1376 bra cmd_stop0 ; go do the stop/end
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1377 cmd_stop bne SNERROR ; raise error if there was an argument
57
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1378 coma ; flag STOP - set carry
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1379 cmd_stop0 ror endflag ; set stop/end flag
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1380 cmd_stop1 clr filenum ; reset I/O to console
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1381 ldx curline ; in immediate mode?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1382 beq cmd_stop2 ; brif so - don't save the continue pointers
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1383 stx contline ; save pointer to current line for CONT
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1384 ldx curstmt ; get current statement address
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1385 stx contstmt ; save it for CONT
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1386 cmd_stop2 rol endflag ; get STOP/END to C (1=STOP)
32
0a476b3e0ec4 Fix STOP to show BREAK message in immediate mode
William Astle <lost@l-w.ca>
parents: 31
diff changeset
1387 bcc cmd_stop3 ; brif END - don't do message
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1388 ldx #breakmsg ; do "BREAK IN"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1389 jmp ERROR2 ; the bottom half of the error handler can deal with the details
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1390 cmd_stop3 puls x,pc ; lose return address and return to caller of interpretation loop
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1392 ; REM and ' commands; also ELSE comes here since it needs to skip the rest of the line in that case.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1393 cmd_else
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1394 cmd_apos
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1395 cmd_rem clra ; clear carry
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1396 ldx curline ; get start of current line
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1397 beq cmd_stop3 ; brif immediate mode - fall back to caller
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1398 ldx ,x ; get address of next line
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1399 leax -1,x ; move back one
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1400 stx inputptr ; put input pointer there
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1401 rts
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1403 ; DATA command
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1404 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1405 ; need to skip to the end of the current statement, which is either the end of the line OR a colon not included inside
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1406 ; a quoted string
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1407 cmd_data ldx inputptr ; get input pointer
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1408 cmd_data0 lda ,x+ ; get character at pointer
46
8d9345b6d3a9 Fix parsing empty DATA statements
William Astle <lost@l-w.ca>
parents: 45
diff changeset
1409 beq cmd_data1 ; brif end of line
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1410 cmpa #': ; end of statement?
58
24b123b3e69b Fix flow error in DATA command skipping
William Astle <lost@l-w.ca>
parents: 57
diff changeset
1411 bne cmd_data2 ; brif not
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1412 cmd_data1 leax -1,x ; move back to the NUL or colon
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1413 stx inputptr ; reset input pointer for interpreter
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1414 rts
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1415 cmd_data2 cmpa #'" ; start of constant string?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1416 bne cmd_data0 ; brif not - process more characters
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1417 cmd_data3 lda ,x+ ; get next string character
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1418 beq cmd_data1 ; brif end of line
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1419 cmpa #'" ; string delimiter?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1420 bne cmd_data3 ; brif not - keep going
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1421 bra cmd_data0 ; process stuff outside string
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1423 ; RUN command
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1424 cmd_run ;jsr closeall ; close all files
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1425 jsr curchar ; what do we have as an argument?
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1426 bcs cmd_goto ; brif a digit - it's a line number (RUN ###); do GOTO
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1427 lbne SNERROR ; brif anything else on the line - not legit command
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1428 ldx progtext ; point to start of program
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1429 bra cmd_goto0 ; go transfer control to the start of the program
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1431 ; GOTO command
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1432 cmd_goto jsr parse_lineno ; parse the line number
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1433 cmd_gosub0 jsr prog_findlinecl ; go look up line number
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1434 bcc cmd_goto0 ; brif line found
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1435 ULERROR ldb #err_ul ; raise undefined line error
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1436 jmp ERROR
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1437 cmd_goto0 stx curline ; make sure we aren't flagging immediate mode
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1438 leax -1,x ; move input pointer to NUL before destination line
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1439 stx inputptr ; put input pointer there
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1440 rts ; resume interpretation at the new location
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1442 ; GOSUB command
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1443 cmd_gosub jsr parse_lineno ; parse the destination line so return location is after the line number
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1444 ldd #tok_gosub*256+4 ; stack frame details
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1445 bsr callstack_alloc ; make a stack frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1446 ldx curline ; save current line pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1447 stx ,u
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1448 ldx inputptr ; save current input pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1449 stx 2,u
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1450 bra cmd_gosub0 ; go finish up as a GOTO
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1452 ; RETURN command
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1453 ; POP command
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1454 ;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1455 ; RETURN will search the call stack for the first GOSUB frame and remove all other placeholders it finds. A frame type
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1456 ; of 0 will cause it to stop.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1457 cmd_pop skip1lda ; set nonzero for POP
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1458 cmd_return clra ; set zero for RETURN
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1459 pshs a ; save operation type
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1460 bsr callstack_first ; get first entry on call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1461 bne cmd_return1 ; brif there's a frame - don't error
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1462 RG_ERROR ldb #err_rg ; raise RETURN without GOSUB
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1463 jmp ERROR
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1464 cmd_return0 bsr callstack_next ; move to next entry
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1465 beq RG_ERROR ; brif end of stack - raise error
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1466 cmd_return1 cmpb #tok_gosub ; do we have a GOSUB frame?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1467 bne cmd_return0 ; brif not - try again
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1468 lda ,s+ ; is it "POP"?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1469 bne cmd_return2 ; brif so - don't change flow control but clear stack frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1470 ldx ,u ; get back saved line pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1471 stx curline
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1472 ldx 2,u ; get back saved input pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1473 stx inputptr
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1474 cmd_return2 bsr callstack_pop ; clean up call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1475 bra cmd_data ; move to end of statement (move past any "ON GOSUB" entries
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1477 ; Point to the first entry on the call stack; yes this is trivial but it points to the payload, not the header. Also
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1478 ; sets Z if there is nothing on the stack.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1479 callstack_first ldu stackptr ; get stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1480 ldb ,u++ ; set flags on frame type and adjust pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1481 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1482 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1483 ; Move to the next frame on the call stack; enter with U pointing to a stack frame payload area
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1484 callstack_next ldb -1,u ; get length of this frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1485 leau b,u ; move to the next frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1486 ldb -2,u ; set flags on frame type code
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1487 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1488 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1489 ; Create a stack frame. Enter with the frame type flag in A and the size in B.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1490 ;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1491 ; The stack frame of size B bytes plus 2 bytes for the length and type flag will be allocated between the actual
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1492 ; hardware stack and the current call stack pointer. Return with the pointer to the allocated frame in U. As long as
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1493 ; there are no pointers to anything on the hardware stack, this will allow the stack to be entirely intact after
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1494 ; the call.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1495 callstack_alloc addb #2 ; account for the header bytes
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1496 pshs a,b ; save the type and length
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1497 negb ; need a negative offset
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1498 leax ,s ; point to current bottom of stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1499 leas b,s ; make a hole below the stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1500 leau ,s ; get a pointer to the destination for copying
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1501 callstack_alloc0
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1502 lda ,x+ ; copy a byte down
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1503 sta ,u+
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1504 cmpx stackptr ; have we reached the top of the stack?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1505 blo callstack_alloc0 ; brif not
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1506 stu stackptr ; save the new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1507 puls d ; get back the type and length values
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1508 std ,u++ ; save type and length
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1509 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1511 ; Pop the call stack to the end of the frame pointed to by U; this will relocate the hardware stack to close the
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1512 ; newly made gap in memory.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1513 callstack_pop leau -2,u ; move back to header
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1514 ldb 1,u ; get length of frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1515 leax b,u ; point to element after this frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1516 sts ,--s ; save the current bottom of the stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1517 stx stackptr ; save new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1518 callstack_pop0 lda ,-u ; copy a byte up
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1519 sta ,-x
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1520 cmpu ,s ; at the bottom of the call stack?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1521 bhi callstack_pop0 ; brif not
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1522 leas 2,x ; reset the stack pointer (and lose the saved stack pointer value)
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1523 rts
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1524 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1525 ; Miscelaneous strings
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1526 prompt fcn 'OK' ; general prompt
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1527 breakmsg fcn 'BREAK' ; "BREAK" message
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1528 inmsg fcn ' in ' ; " in " message
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1530 ; Print out an unsigned 16 bit value in D to the selected output stream
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1531 print_uint16d pshs d,x,y,u ; save number and make some temporaries on the stack
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1532 leay 2,s ; point to start of buffer
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1533 ldu #10000 ; do the 10000s digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1534 bsr print_uint16d4
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1535 ldu #1000 ; do the 1000s digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1536 bsr print_uint16d4
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1537 ldu #100 ; do the 100s digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1538 bsr print_uint16d4
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1539 ldu #10 ; do the 10s digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1540 bsr print_uint16d4
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1541 puls d ; get back number residue and clean up stack
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1542 addb #0x30 ; convert 1s digit to number
51
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1543 stb ,y ; stash it
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1544 clr 1,y ; NUL terminate it
48
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1545 leay ,s ; point to start of converted number
51
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1546 print_uint16d0 lda ,y ; get digit at start
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1547 cmpa #0x30 ; zero digit?
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1548 bne print_uint16d1 ; brif not - we can just show the number from here
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1549 ldb 1,y ; end of number?
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1550 beq print_uint16d1 ; brif so - show the zero anyway
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1551 leay 1,y ; move past the zero
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1552 bra print_uint16d0 ; see if we have more zeroes to skip
48
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1553 print_uint16d1 lda ,y+ ; get number digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1554 beq print_uint16d2 ; brif end of number
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1555 jsr writechr ; output the digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1556 bra print_uint16d1 ; handle next digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1557 print_uint16d2 leas 6,s ; clean up the stack
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1558 rts
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1559 print_uint16d4 lda #0x30-1 ; init digit value
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1560 pshs a,u ; save the digit position and digit value
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1561 ldd 5,s ; get back residue
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1562 print_uint16d5 inc ,s ; bump digit
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1563 subd 1,s ; subtract out place value
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1564 bcc print_uint16d5 ; brif we haven't got the right digit yet
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1565 addd 1,s ; restore residue
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1566 std 5,s ; save new residue
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1567 puls a,u ; get back digit and place value off stack
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1568 sta ,y+ ; save digit in buffer
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1569 rts
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1570
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1571 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
1572 ; PRINT command
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1573 cmd_print beq cmd_printeol ; brif no argument - do a newline
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1574 cmd_print0 cmpa #'; ; semicolon?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1575 bne cmd_print1 ; brif not
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1576 jsr nextchar ; skip the semicolon
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1577 bne cmd_print0 ; brif not end of the statement
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1578 rts
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1579 cmd_print1 jsr eval_expr ; evaluate the expression
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1580 ldb val0+val.type ; get value type
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1581 cmpb #valtype_int ; integer?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1582 beq cmd_printint ; brif so - print integer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1583 lda #'! ; flag unknown expression type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1584 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1585 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1586 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1587 cmd_printnext jsr curchar ; see what we have here
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1588 bra cmd_print ; and go process
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1589 cmd_printeol jmp console_outnl ; do a newline and return
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1590 cmd_printint leas -12,s ; make a buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1591 leay ,s ; point to buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1592 lda #0x20 ; default sign (positive)
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1593 ldb val0+val.int ; is it negative?
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1594 bpl cmd_printint0 ; brif not
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1595 jsr val_negint32 ; negate the integer
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1596 lda #'- ; negative sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1597 cmd_printint0 sta ,y+ ; save sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1598 ldu #cmd_printintpc ; point to positive constant table
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1599 ldx #10 ; there are 10 constants to process
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1600 ; subtraction loop - positive residue
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1601 cmd_printint1 lda #'0-1 ; initialize digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1602 sta ,y
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1603 cmd_printint2 inc ,y ; bump digit
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1604 ldd val0+val.int+2 ; subtract constant
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1605 subd 2,u
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1606 std val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1607 ldd val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1608 sbcb 1,u
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1609 sbca ,u
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1610 std val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1611 bcc cmd_printint2 ; brif we didn't go negative
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1612 ldd val0+val.int+2 ; undo last subtract
68
8ac1aafb9ecb Fix some formatting glitches
William Astle <lost@l-w.ca>
parents: 66
diff changeset
1613 addd 2,u
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1614 std val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1615 ldd val0+val.int
68
8ac1aafb9ecb Fix some formatting glitches
William Astle <lost@l-w.ca>
parents: 66
diff changeset
1616 adcb 1,u
8ac1aafb9ecb Fix some formatting glitches
William Astle <lost@l-w.ca>
parents: 66
diff changeset
1617 adca ,u
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1618 std val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1619 leay 1,y ; move to next digit in buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1620 leau 4,u ; move to next constant
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1621 leax -1,x ; done all constants?
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1622 bne cmd_printint1 ; brif not - done all
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1623 cmd_printint5 clr ,y ; NUL terminate the string
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1624 leax 1,s ; point past the sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1625 cmd_printint6 lda ,x+ ; get digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1626 beq cmd_printint8 ; brif end of number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1627 cmpa #'0 ; is it a zero?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1628 beq cmd_printint6 ; brif so - skip it
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1629 cmd_printint7 lda ,s ; get the sign
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1630 sta ,--x ; put it at the start of the number
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1631 jsr console_outstr ; display the number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1632 leas 12,s ; clean up stack
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1633 bra cmd_printnext ; go print the next thing
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1634 cmd_printint8 leax -1,x ; restore one of the zeros
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1635 bra cmd_printint7 ; go finish up
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1636 cmd_printintpc fqb 1000000000 ; 10^9
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1637 fqb 100000000 ; 10^8
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1638 fqb 10000000 ; 10^7
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1639 fqb 1000000 ; 10^6
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1640 fqb 100000 ; 10^5
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1641 fqb 10000 ; 10^4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1642 fqb 1000 ; 10^3
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1643 fqb 100 ; 10^2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1644 fqb 10 ; 10^1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1645 fqb 1 ; 10^0
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
1646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1647 ; Error messages
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1648 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1649 ; Each error begins with a deferr macro invocation which will define a symbol err_slug with the next error number
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1650 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1651 ; deferr slug
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1652 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1653 ; This is then followed by the error message defined with fcn.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1654 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1655 ; Real error numbers start at 1; 0 is used to indicate no error.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1656 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1657 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1658 __errnum set 0
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1659 deferr macro noexpand
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1660 err_{1} equ __errnum
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1661 __errnum set __errnum+1
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1662 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1663 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1664 errormsg deferr none
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1665 fcn 'No error'
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1666 deferr nf
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1667 fcn 'NEXT without FOR'
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1668 deferr sn
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1669 fcn 'Syntax error'
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1670 deferr ul
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1671 fcn 'Undefined line number'
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1672 deferr rg
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1673 fcn 'RETURN without GOSUB'
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1674 deferr ov
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1675 fcn 'Overflow'
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1676 deferr tm
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1677 fcn 'Type mismatch'
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
1679 ; The LET command which is the default if no token begins a statement
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
1680 cmd_let jmp SNERROR ; not yet implemented
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
1681 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1682 ; Expression Evaluation Package
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1683 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1684 ; This is the expression evaluator. It handles everything from parsing numbers to dispatching function calls. The main
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1685 ; entry point is eval_expr which will evaluate an arbitrary expression. It returns as soon as it reaches something it
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1686 ; doesn't understand as part of an expression.
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1687 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1688 ; The special handling for relational operators is required because Basic allows them in all
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1689 eval_expr clrb ; flag previous operator as minimum precdence (end of expression)
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1690 eval_expraux jsr eval_term ; evaluate the first term of the expression
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1691 eval_expr0 jsr curchar ; fetch current input
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1692 beq eval_expr1 ; brif end of expression - we're done
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1693 cmpa #tok_or ; is it above operators?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1694 bhi eval_expr1 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1695 suba #tok_plus ; offset to zero for first operator token
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1696 bcc eval_expr2 ; brif it is an operator
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1697 eval_expr1 rts
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1698 eval_expr2 pshs b ; save previous operator precedence
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1699 ldx #oper_tab ; point to operator table
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1700 tfr a,b ; shift to B for "ABX"
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1701 abx ; add three times (3 bytes per entry)
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1702 abx ; OBS: TFR + ABX + ABX + ABX is faster than LDB + MUL + ABX
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1703 abx ; now X points to the operator entry in the table
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1704 ldb ,x ; get precedence of current operation
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1705 cmpb ,s ; is it higher than the current operation?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1706 bhi eval_expr3 ; brif so - process this operator
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1707 puls b,pc ; return current value to complete previous operation
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1708 eval_expr3 jsr nextchar ; eat the operator token
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1709 ldx 1,x ; get handler address of this operator
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1710 leas -val.size,s ; make room for the result accumulator
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1711 pshs x ; save handler address for later
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1712 lda val0+val.type ; get current value type
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1713 ldx val0 ; get value accumlator contents (6 bytes)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1714 ldy val0+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1715 ldu val0+4
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1716 pshs a,x,y,u ; save it on the stack
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1717 jsr eval_expraux ; evaluate the following term and higher precedence expressions
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1718 puls a,x,y,u ; get back saved value
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1719 stx val1 ; save it to the second value accumulator
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1720 sty val1+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1721 stu val1+4
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1722 sta val1+val.type ; save previous value type
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1723 ldx #val1 ; point to left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1724 ldu #val0 ; point to right operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1725 leay 2,s ; point to return value location
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1726 jsr [,s++] ; go handle the operator
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1727 puls a,x,y,u ; get return value
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1728 sta val0
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1729 stx val0+1
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1730 sty val0+3
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1731 stu val0+5
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1732 puls b ; get back the previous operator precedence
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1733 bra eval_expr0 ; go process another operator or end of expression
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1734 eval_term jsr curchar ; get current input character
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1735 beq eval_term0 ; brif end of input - this is an error
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1736 bcs eval_number ; brif digit - we have a number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1737 ; bmi eval_func ; brif we have a token - handle function call
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1738 cmpa #'. ; decimal point?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1739 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1740 cmpa #'- ; negative sign?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1741 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1742 cmpa #'+ ; positive sign?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1743 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1744 eval_term0 jmp SNERROR ; we have something unrecognized - raise error
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1745 ; Evaluate a number constant. Currently this only handles 32 bit integers.
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1746 eval_number ldb #valtype_int ; start with integer value
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1747 stb val0+val.type ; set return value
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1748 ldx zero ; blank out the value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1749 stx val0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1750 stx val0+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1751 stx val0+4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1752 bra eval_number1 ; go do the parsing
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1753 eval_number0 jsr nextchar ; fetch next input
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1754 beq eval_numberr ; brif end of expression - bail
66
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1755 eval_number1 cmpa #'- ; negative (ascii sign)?
69
a3c4183f28e0 Clean up some more formatting
William Astle <lost@l-w.ca>
parents: 68
diff changeset
1756 beq eval_number3 ; brif so
a3c4183f28e0 Clean up some more formatting
William Astle <lost@l-w.ca>
parents: 68
diff changeset
1757 cmpa #tok_minus ; negative (operator negative)?
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1758 bne eval_number2 ; brif not
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1759 eval_number3 com val0+val.fpsign ; invert sign
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1760 bra eval_number0 ; deal with next input
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1761 eval_number2 cmpa #'+ ; unary +?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1762 beq eval_number0 ; brif so - skip it
69
a3c4183f28e0 Clean up some more formatting
William Astle <lost@l-w.ca>
parents: 68
diff changeset
1763 eval_number5 cmpa #'. ; decimal point?
a3c4183f28e0 Clean up some more formatting
William Astle <lost@l-w.ca>
parents: 68
diff changeset
1764 beq eval_float ; brif decimal - force float
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1765 cmpa #'0 ; is it a number?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1766 blo eval_numberr ; brif below digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1767 cmpa #'9 ; is it still a number?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1768 bhi eval_numberr ; brif above digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1769 suba #'0 ; offset to binary digit value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1770 pshs a ; save digit value
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1771 ldx val0+val.int ; get current value for later (for quick multiply by 10)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1772 ldd val0+val.int+2
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1773 pshs d,x ; stored with words swapped on stack for efficiency for later
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1774 lsl val0+val.int+3 ; times 2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1775 rol val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1776 rol val0+val.int+1
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1777 rol val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1778 bcs OVERROR ; brif overflowed
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1779 lsl val0+val.int+3 ; times 4
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1780 rol val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1781 rol val0+val.int+1
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1782 rol val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1783 bcs OVERROR ; brif overflowed
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1784 ldd val0+val.int+2 ; times 5 (add original value)
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1785 addd ,s++
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1786 std val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1787 ldd val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1788 adcb 1,s
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1789 adca ,s++
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1790 std val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1791 bcs OVERROR
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1792 lsl val0+val.int+3 ; times 10
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1793 rol val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1794 rol val0+val.int+1
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1795 rol val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1796 bcs OVERROR ; brif overflowed
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1797 ldd val0+val.int+2 ; get low word
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1798 addb ,s+ ; add in current digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1799 adca #0
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1800 std val0+val.int+2
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1801 ldd val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1802 adcb #0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1803 adca #0
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1804 std val0+val.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1805 bcs OVERROR ; brif overflowed
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1806 bpl eval_number4 ; brif we haven't wrapped negative
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1807 cmpd #0x8000 ; is it valid negative two's complement?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1808 bhi OVERROR ; brif not
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1809 ldd val0+val.int+2 ; is it still valid two's complement (max negative)?
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1810 bne OVERROR ; brif so
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1811 eval_number4 jsr nextchar ; fetch next input character
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1812 bra eval_number5 ; go handle it
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1813 OVERROR ldb #err_ov ; flag overflow
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1814 jmp ERROR
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1815 eval_numberr ldb val0+val.fpsign ; is the number we want negative?
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1816 beq eval_numberr0 ; brif not
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1817 jsr val_negint32 ; negate the integer
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1818 eval_numberr0 rts
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1819 eval_float jmp SNERROR ; we don't handle floating point yet
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1821 ; Operator table
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1822 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1823 ; Each entry starts with the precedence value followed by the handler routine. Each handler will receive its left
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1824 ; operand in val1 and its right operand in val0 and should return its result in val0.
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1825 oper_tab fcb 0x79 ; addition
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1826 fdb oper_plus
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1827 fcb 0x79 ; subtraction
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1828 fdb oper_minus
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1829 fcb 0x7b ; multiplication
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1830 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1831 fcb 0x7b ; division
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1832 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1833 fcb 0x7f ; exponentiation
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1834 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1835 fcb 0x64 ; less than
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1836 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1837 fcb 0x64 ; equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1838 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1839 fcb 0x64 ; greater than
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1840 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1841 fcb 0x64 ; less than or equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1842 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1843 fcb 0x64 ; greater than or equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1844 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1845 fcb 0x64 ; not equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1846 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1847 fcb 0x50 ; boolean AND
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1848 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1849 fcb 0x46 ; boolean OR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1850 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1852 ; Set carry if upper/lower case alpha
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1853 setcifalpha cmpa #'z+1 ; is it above lower case Z?
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1854 bhs setcifalpha0 ; brif so, C clear
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1855 suba #'a ; set C if >= lower case A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1856 suba #-'a
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1857 bcs setcifalpha0 ; brif lower case alpha
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1858 setcifualpha cmpa #'Z+1 ; is it above upper case Z?
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1859 bhs setcifalpha0 ; brif so, C clear
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1860 suba #'A ; set C if >= upper case A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1861 suba #-'A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1862 setcifalpha0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1864 ; Set carry if digit
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1865 setcifdigit cmpa #'9+1 ; is it above digit 9?
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1866 bhs setcifdigit0 ; brif so, C clear
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1867 suba #'0 ; set C if >= digit 0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1868 suba #-'0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1869 setcifdigit0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1871 ; Operator handling routines
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1872 ;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1873 ; binary plus: addition and concatenation
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1874 oper_plus ldb val.type,x ; get type of the left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1875 cmpb valtype_string ; is it string?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1876 bne oper_plus0 ; brif not
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1877 cmpb val.type,u ; is right operand also string?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1878 lbeq SNERROR ; brif so - do string concatenation
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1879 oper_plus0 bsr val_matchtypes ; go match data types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1880 jmp val_add ; go add the values
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1881 ; binary minus: subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1882 oper_minus bsr val_matchtypes ; go match data types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1883 jmp val_sub ; do subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
1884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1885 ; Arithmetic package
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1886 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1887 ; This section contains routines that handle floating point and integer arithmetic.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1888 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1889 ; Most routines take a pointer to a value accumulator in X. Some take two pointers with the second in U.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1891 ; Match operands for a numeric calculation. This works as follows:
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1892 ;
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1893 ; * If both operands are the same, ensure the type is numeric and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1894 ; * If one operand is floating point, convert the other to floating point, as long as it is numeric
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1895 ; * If one or both oeprands are not numeric, raise a type mismatch
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1896 ; The operands are in (X) and (U)
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1897 val_matchtypes ldb val.type,x ; get the type of first argument
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1898 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1899 beq val_matchtypes0 ; brif so
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1900 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1901 beq val_matchtypes1 ; brif so
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1902 TMERROR ldb #err_tm ; raise a type mismatch
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1903 jmp ERROR
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1904 val_matchtypes0 ldb val.type,u ; get type of second operand
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1905 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1906 bne val_matchtypes2 ; brif not
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1907 val_matchtypes3 rts
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1908 val_matchtypes2 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1909 bne TMERROR ; brif not - raise error
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1910 pshs u ; save pointer to second operand
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1911 bsr val_int32tofp ; convert first argument to floating point
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1912 puls u,pc ; restore second operand pointer and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1913 val_matchtypes1 ldb val.type,u ; get second argument type
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1914 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1915 beq val_matchtypes3 ; brif so - we're good
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1916 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1917 bne TMERROR ; brif not - invalid type combination
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1918 pshs x,u ; save value pointers
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1919 leax ,u ; convert (U) to floating point
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1920 bsr val_int32tofp
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1921 puls x,u,pc ; restore argument pointers and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
1922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1923 ; Negate the 32 bit integer (for fp mantissa) at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1924 val_negint32 ldd zero ; subtract integer value from zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1925 subd val.int+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1926 std val.int+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1927 ldd zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1928 sbcb val.int+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1929 sbca val.int,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1930 std val.int,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1931 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1933 ; Convert integer value at (X) to floating point value at (X). Enter at val_uint32tofp to treat the 32 bit value as
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1934 ; unsigned. Otherwise enter at val_int32tofp to treat it as signed.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1935 val_uint32tofp clr val.fpsign,x ; for positive sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1936 bra val_int32tofpp ; go process as positive
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1937 val_int32tofp ldb val.int,x ; get sign to A
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1938 sex
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1939 sta val.fpsign,x ; set sign of result
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1940 bpl val_int32tofpp ; brif positive - don't need to do a two's complement adjustment
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1941 bsr val_negint32 ; negate the integer value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1942 val_int32tofpp ldb valtype_float ; set result to floating point
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1943 stb val.type,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1944 ldb #0xa0 ; exponent to have binary point to the right of the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1945 stb val.fpexp,x ; set the exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1946 clrb ; clear out extra precision bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1947 ; fall through to normalize the value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1948 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1949 ; Normalize floating point value at (X); this will shift the mantissa until there is a one in the leftmost
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1950 ; bit of the mantissa. The algorithm is as follows:
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1951 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1952 ; 1. Shift the mantissa left until a 1 bit is found in the high bit of the mantissa.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1953 ; 1a. If more than 40 bits of left shifts occur, determine that the value is zero and return
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1954 ; 2. Adjust exponent based on number of shifts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1955 ; 2a. If new exponent went below -127, then underflow occurred and zero out value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1956 ; 2b. If new exponent went above +127, raise an overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1957 ; 3. If bit 7 of the extra precision byte is clear, return the resulting value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1958 ; 4. Add one to the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1959 ; 5. If a carry in (4) occurred, then set high bit of mantissa and bump exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1960 ; 6. If new exponent carries, then raise overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1961 ; 7. Return result.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1962 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1963 ; Note that if we carried in (4), the only possible result is that the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1964 ; rolled over to all zeroes so there is no need to shift the entire mantissa right
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1965 ; nor is there any reason to check for additional rounding.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1966 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1967 ; The above algorithm has some optimizations in the code sequence below.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1968 fp_normalize pshs b ; save extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1969 clrb ; set shift counter/exponent adjustment
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1970 fp_normalize0 lda val.fpmant,x ; set flags on high word of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1971 bne fp_normalize2 ; brif we don't have a full byte to shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1972 addb #8 ; account for a while byte of shifts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1973 ldu val.fpmant+1,x ; shift mantissa left 8 bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1974 stu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1975 lda val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1976 sta val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1977 lda ,s ; and include extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1978 sta val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1979 clr ,s ; and blank extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1980 cmpb #40 ; have we shifted 40 bits?
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1981 blo fp_normalize0 ; brif not - keep shifting
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1982 bra fp_normalize7 ; go zero out the value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1983 fp_normalize1 incb ; account for one bit of shifting
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1984 lsl ,s ; shift mantissa and extra bits left (will not be more than 7 shifts)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1985 rol val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1986 rol val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1987 rol val.fpmant+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1988 rol val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1989 fp_normalize2 bpl fp_normalize1 ; brif we have to do a bit shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1990 pshs b ; apply exponent counter to exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1991 lda val.fpexp,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1992 suba ,s+
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1993 bls fp_normalize6 ; brif we underflowed to zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1994 bcc fp_normalize3 ; brif we did not overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1995 OVERROR2 jmp OVERROR ; raise overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1996 fp_normalize3 lsl ,s+ ; set C if the high bit of extra precision is set
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1997 bcs fp_normalize5 ; brif bit set - we have to do rounding
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1998 fp_normalize4 rts ; return if no rounding
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
1999 fp_normalize5 ldu val.fpmant+2,x ; add one to mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2000 leau 1,u
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2001 stu val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2002 bne fp_normalize4 ; brif low word doesn't carry
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2003 ldu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2004 leau 1,u
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2005 stu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2006 bne fp_normalize4 ; brif high word doesn't carry
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2007 ror val.fpmant,x ; shift right C in to high bit of mantissa (already set to get here)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2008 inc val.fpexp,x ; bump exponent for a right shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2009 beq OVERROR2 ; brif it overflows (> +127)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2010 rts ; return result (only possible result was mantissa wrapped to zero)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2011 fp_normalize6 clr val.fpmant,x ; clear mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2012 clr val.fpmant+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2013 clr val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2014 clr val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2015 fp_normalize7 clr val.fpexp,x ; clear exponent and sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2016 clr val.fpsign,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2017 puls b,pc ; clean up stack and return
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2019 ; Addition and subtraction of values; must enter with values of matching types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2020 ;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2021 ; Calculates (X) + (U) -> (Y) (addition)
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2022 ; Calculates (X) - (U) -> (Y) (subtraction)
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2023 val_add ldb val.type,x ; get type of left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2024 stb val.type,y ; set result type
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2025 cmpb #valtype_float ; is it float?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2026 beq fp_add ; brif so
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2027 ldd val.int+2,x ; do the addition
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2028 addd val.int+2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2029 std val.int+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2030 ldd val.int,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2031 adcb val.int+1,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2032 adca val.int,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2033 std val.int,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2034 lbvs OVERROR ; brif calculation overflowed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2035 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2036 val_sub ldb val.type,x ; get type of left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2037 stb val.type,y ; set result type
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2038 cmpb #valtype_float ; floating point?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2039 beq fp_sub ; brif so
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2040 ldd val.int+2,x ; do the subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2041 subd val.int+2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2042 std val.int+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2043 ldd val.int,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2044 sbcb val.int+1,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2045 sbca val.int,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2046 std val.int,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2047 lbvs OVERROR ; brif overflow
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2048 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2050 ; FP subtraction: just invert the sign of the second operand and add; operands must be writable and they should be
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2051 ; considered to be clobbered
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2052 fp_sub com val.fpsign,u ; negate right operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2053 ; fall through to addition
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2054 ; FP addition: this requires that *both operands* are writable and they may be clobbered
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2055 fp_add ldb val.fpexp,u ; is the second operand zero?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2056 beq fp_add0 ; brif so - it's a no-op - copy the left operand to the output
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2057 lda val.fpexp,x ; is left operand zero?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2058 bne fp_add1 ; brif not - we have to do the add
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2059 leau ,x ; copy the right operand to the output
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2060 fp_add0 ldd ,u ; copy the value across
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2061 std ,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2062 ldd 2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2063 std 2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2064 ldd 4,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2065 std 4,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2066 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2067 fp_add1 subb val.fpexp,x ; get difference in exponents
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2068 beq fp_add6 ; brif they're the same - no denormalizing is needed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2069 bhi fp_add2 ; brif second one is bigger, need to right-shift the mantissa of first
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2070 exg x,u ; swap the operands (we can do that for addition)l second is now biggest
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2071 negb ; invert the shift count
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2072 fp_add2 cmpb #32 ; are we shifting more than 32 bits?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2073 blo fp_add0 ; brif so - we're effectively adding zero so bail out
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2074 fp_add3 cmpb #8 ; have 8 bits to move?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2075 bhs fp_add5 ; brif not
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2076 lda val.fpmant+2,x ; shift 8 bits right
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2077 sta val.fpmant+3,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2078 lda val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2079 sta val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2080 lda val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2081 sta val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2082 clr val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2083 subb #8 ; account for 8 shifts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2084 bra fp_add3 ; see if we have a whole byte to shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2085 fp_add4 lsr val.fpmant,x ; shift right one bit
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2086 ror val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2087 ror val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2088 ror val.fpmant+3,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2089 fp_add5 decb ; done all shifts?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2090 bmi fp_add4 ; brif not - do a shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2091 fp_add6 ldb val.fpexp,u ; set exponent of result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2092 stb val.fpexp,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2093 ldb val.fpsign,u ; fetch sign of larger value
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2094 stb val.fpsign,y ; set result sign
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2095 cmpb val.fpsign,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2096 bne fp_add8 ; brif not - need to subtract the operands
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2097 ldd val.fpmant+2,u ; add the mantissas
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2098 addd val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2099 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2100 ldd val.fpmant,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2101 adcb val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2102 adca val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2103 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2104 clrb ; clear extra precision bits
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2105 bcc fp_add7 ; brif no carry
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2106 ror val.fpmant,y ; shift carry into mantissa
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2107 ror val.fpmant+1,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2108 ror val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2109 ror val.fpmant+3,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2110 rorb ; keep bits for founding
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2111 inc val.fpexp,y ; bump exponent to account for shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2112 lbeq OVERROR ; brif it overflowed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2113 fp_add7 leax ,y ; point to result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2114 jmp fp_normalize ; go normalize the result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2115 fp_add8 ldd val.fpmant+2,u ; subtract operands
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2116 subd val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2117 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2118 ldd val.fpmant,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2119 sbcb val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2120 sbca val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2121 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2122 bcc fp_add7 ; brif we didn't carry - no need to fix up
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2123 ldd zero ; negate the mantissa bits since we use sign+magnitude
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2124 subd val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2125 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2126 ldd zero
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2127 sbcb val.fpmant+1,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2128 sbca val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2129 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2130 neg val.fpsign,y ; invert sign of result since we went past zero
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2131 clrb ; clear extra precision bits
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2132 bra fp_add7 ; go normalize the result and return
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
2133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2134 ; Pack a floating point value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2135 fp_packval ldb val.fpsign,x ; get sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2136 bmi fp_packval ; brif negative - the default 1 bit will do
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2137 ldb val.fpmant,x ; clear high bit of mantissa for positive
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2138 andb #0x7f
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2139 stb val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2140 fp_packval0 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2142 ; Unpack a floating point value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2143 fp_unpackval0 ldb val.fpmant,x ; get high byte of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2144 sex ; now A is value for sign byte
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2145 sta val.fpsign,x ; set sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2146 orb #0x80 ; set high bit of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2147 stb val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2148 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
2149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2150 ; The LIST command.
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2151 ;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2152 ; Syntax:
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2153 ; LIST
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2154 ; LIST <line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2155 ; LIST <line>-
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2156 ; LIST -<line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2157 ; LIST <start>-<end>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2158 cmd_list bne cmd_list1 ; brif we have arguments
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2159 ldx progtext ; point to start of program
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2160 cmd_list0 ldd #65535 ; set last line to list to max line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2161 std binval
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2162 bra cmd_list2 ; go do the listing
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2163 cmd_list1 jsr parse_lineno ; parse starting line number (will default to 0)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2164 jsr prog_findline ; find the line or the one after where it would be
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2165 jsr curchar ; are we at the end of the command?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2166 beq cmd_list2 ; brif so - we have a single line (binval will have the start line #)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2167 ldb #tok_minus ; insist on a - for a range if more than one line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2168 jsr syncheckb
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2169 beq cmd_list0 ; brif open ended ending - set to max line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2170 jsr parse_lineno ; parse ending of range
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2171 cmd_list2 ldd ,x ; are we at the end of the program?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2172 bne cmd_list4 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2173 cmd_list3 rts
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2174 cmd_list4 ldd 2,x ; get line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2175 cmpd binval ; have we reached the end of the range?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2176 bhi cmd_list3 ; brif so - we're done
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2177 jsr print_uint16d ; print out line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2178 lda #0x20 ; and a space
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2179 jsr writechr
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2180 pshs x ; save start of this line (in case detokenizing exits early)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2181 leax 4,x ; move past line header
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2182 bsr detokenize ; detokenize line to current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2183 ldx [,s++] ; point to next line using saved pointer and clear it from the stack
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2184 ; need to add a break check here
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2185 bra cmd_list2 ; go handle another line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2187 ; Detokenize a line to the current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2188 detokenize lda ,x+ ; get character from tokenized line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2189 bmi detokenize1 ; brif it's a keyword token
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2190 lbeq writecondnl ; do a newline if needed and return
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2191 cmpa #': ; is it a colon?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2192 bne detokenize0 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2193 ldb ,x ; fetch subsequent character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2194 cmpb #tok_apos ; apostrophe version of REM?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2195 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2196 cmpb #tok_else ; ELSE?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2197 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2198 detokenize0 jsr writechr ; output it unmolested
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2199 bra detokenize ; go handle another character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2200 detokenize1 ldu #primarydict ; point to primary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2201 cmpa #0xff ; is it a secondary token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2202 bne detokenize3 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2203 ldu #secondarydict ; point to secondary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2204 lda ,x+ ; get secondary token value
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2205 bne detokenize3 ; brif not end of line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2206 leax -1,x ; don't consume the NUL
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2207 detokenize2 lda #'! ; invalid token flag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2208 bra detokenize0 ; output it and continue
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2209 detokenize3 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2210 beq detokenize6 ; brif already at the right place
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2211 detokenize4 ldb ,u ; end of dictionary table?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2212 beq detokenize2 ; brif so - show invalid tokenf lag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2213 detokenize5 ldb ,u+ ; fetch character in this keyboard
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2214 bpl detokenize5 ; brif not end of keyword (high bit set)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2215 deca ; at the right token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2216 bne detokenize4 ; brif not - skip another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2217 detokenize6 lda ,u+ ; get keyword character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2218 bmi detokenize7 ; brif end of keyword
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2219 jsr writechr ; output it
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2220 bra detokenize6 ; go fetch another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2221 detokenize7 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2222 bra detokenize0 ; write it and move on with the input
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2224 ; Canonicalize certain sequences; ALL the rewrite sequences must make the result shorter or keep it the same size
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2225 makecanontab fcb tok_less,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2226 fcb tok_greater,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2227 fcb tok_equal,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2228 fcb tok_greater,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2229 fcb tok_less,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2230 fcb tok_equal,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2231 fcb tok_equal,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2232 fcb tok_greater,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2233 fcb tok_less,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2234 fcb 0
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2235 makecanon leay ,x ; point output to start of the buffer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2236 makecanon0 lda ,x+ ; get current byte
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2237 sta ,y+ ; save in output
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2238 bne makecanon1 ; brif not end of line
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2239 rts
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2240 makecanon1 bpl makecanon0 ; brif not a token
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2241 cmpa #0xff ; is it secondary?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2242 bne makecanon2 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2243 leax 1,x ; move past second half
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2244 bra makecanon0 ; go handle next byte
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2245 makecanon2 ldu #makecanontab ; point to replacement table
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2246 makecanon3 cmpa ,u+ ; is it this entry?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2247 beq makecanon4 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2248 ldb ,u+ ; get number of entries
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2249 lslb ; 2 bytes per
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2250 leau b,u ; move past entry
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2251 ldb ,u ; end of table?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2252 bne makecanon3 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2253 bra makecanon0 ; no substitutions found
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2254 makecanon4 pshs x ; save original source pointer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2255 makecanon5 lda ,x+ ; get next character
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2256 cmpa #0x20 ; is it space?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2257 beq makecanon5 ; brif so - skip it
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2258 ldb ,u+ ; get number of replacement candidates
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2259 makecanon6 cmpa ,u++ ; does it match?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2260 beq makecanon7 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2261 decb ; seen all of them?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2262 bne makecanon6 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2263 puls x ; restore input pointer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2264 bra makecanon0 ; go handle next input
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2265 makecanon7 leas 2,s ; clear saved input pointer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2266 lda -1,u ; get replacement token
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2267 sta -1,y ; put it in the output
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2268 bra makecanon0 ; go handle more input
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2270 ; Tokenize line to tokebuff
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2271 ;
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2272 ; Enter with X pointing to the text to tokenize.
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2273 ; Exit with X pointing to the start of the tokenized line and D holding the length of the tokenized line.
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2274 tokenize clr tok_skipkw ; clear "not token" flag
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2275 clr tok_skipdt ; clear the "in data" flag
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2276 ldy #tokebuff ; point to destination buffer
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2277 pshs y ; set return value
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2278 tokenize0 lda ,x+ ; get input character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2279 bne tokenize3 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2280 tokenize1 sta ,y+ ; blank out final byte in result
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2281 tokenize2 ldx #tokebuff ; point to start of tokenized line
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2282 bsr makecanon ; canonicalize certain sequences
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2283 tfr y,d ; get end address to accumulator
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2284 subd #tokebuff ; subtract out start; gives length of result
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2285 puls x,pc ; set return pointer and return
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2286 tokenize3 tst tok_skipkw ; are we in the middle of a "not token"?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2287 beq tokenize6 ; brif not
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2288 jsr setcifalpha ; is it alpha
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2289 bcs tokenize4 ; brif so - store it and continue
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2290 jsr setcifdigit ; is it numeric?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2291 bcc tokenize5 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2292 tokenize4 sta ,y+ ; save output character
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2293 bra tokenize0 ; check for another
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2294 tokenize5 clr tok_skipkw ; clear the "not token" flag
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2295 tokenize6 cmpa #'" ; is it a string?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2296 bne tokenize8 ; brif not
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2297 sta ,y+ ; save string delimiter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2298 tokenize7 lda ,x+ ; get input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2299 beq tokenize1 ; brif end of input
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2300 sta ,y+ ; save it in output
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2301 cmpa #'" ; end of string?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2302 bne tokenize7 ; brif not
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2303 bra tokenize0 ; brif
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2304 tokenize8 cmpa #': ; end of statement?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2305 bne tokenize9 ; brif not
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2306 clr tok_skipdt ; reset "in data" flag
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2307 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2308 tokenize9 cmpa #0x20 ; is it a space?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2309 beq tokenize4 ; brif so - stash it unmodified
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2310 tst tok_skipdt ; are we "in data"?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2311 bne tokenize4 ; brif so - don't tokenize it
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
2312 cmpa #'? ; PRINT shortcut?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2313 bne tokenize10 ; brif not
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
2314 lda #tok_print ; load token for PRINT
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2315 bra tokenize4 ; move stash it and move on
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2316 tokenize10 cmpa #'' ; ' shortcut for remark?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2317 bne tokenize12 ; brif not
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2318 ldd #':*256+tok_apos ; put token for ' and an implied colon
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2319 std ,y++ ; stash it
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2320 tokenize11 lda ,x+ ; fetch byte from input
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2321 sta ,y+ ; stash in output
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2322 bne tokenize11 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2323 bra tokenize2 ; go finish up
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2324 tokenize12 jsr setcifdigit ; is it a digit?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2325 bcs tokenize4 ; brif so - pass it through
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2326 tsta ; is the high bit set?
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2327 bmi tokenize0 ; ignore it if so
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2328 ldu #primarydict ; point to keyword table
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2329 leax -1,x ; back up input to start of potential token
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2330 clr tok_kwtype ; set secondary table flag to primary table
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2331 clr tok_kwmatch ; clear the matched token
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2332 clr tok_kwmatch+1
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2333 clr tok_kwmatchl ; set length matched
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2334 pshs x ; save start of input token
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2335 tokenize13 clr tok_kwnum ; clear keyword number
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2336 tokenize14 ldb ,u ; are we at the end of the table?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2337 bne tokenize16 ; brif not
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2338 ldu #secondarydict ; point to secondary token dictionary
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2339 com tok_kwtype ; flip to secondary token flag
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2340 bne tokenize13 ; brif we haven't already done the secondaries
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2341 puls x ; get back input pointer
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2342 ldb tok_kwmatchl ; get length of best match
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2343 beq tokenize15 ; brif we don't have a match
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2344 abx ; move input pointer past matched token
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2345 ldd tok_kwmatch ; get matched token number
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2346 tsta ; is it a primary?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2347 beq tokenize24 ; brif so
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2348 bra tokenize23 ; go stash two byte token
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2349 tokenize15 com tok_skipkw ; set "not token flag"
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2350 lda ,x+ ; get character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2351 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2352 tokenize16 ldx ,s ; get back start of input token
55
1568fa902257 Fix error in calculating match length during tokenization
William Astle <lost@l-w.ca>
parents: 53
diff changeset
2353 clra ; initalize match length counter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2354 tokenize17 inca ; bump length counter
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2355 ldb ,x+ ; get input character
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2356 cmpb #'z ; is it above lower case Z?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2357 bhi tokenize18 ; brif so
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2358 cmpb #'a ; is it below lower case A?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2359 blo tokenize18 ; brif so
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2360 subb #0x20 ; convert to upper case
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2361 tokenize18 subb ,u+ ; does it match?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2362 beq tokenize17 ; brif so - check another
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2363 cmpb #0x80 ; did it match with high bit set?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2364 beq tokenize21 ; brif so - exact match
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2365 leau -1,u ; back up to current test character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2366 tokenize19 ldb ,u+ ; end of token?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2367 bpl tokenize19 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2368 tokenize20 inc tok_kwnum ; bump token counter
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2369 bra tokenize14 ; go check another one
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2370 tokenize21 cmpa tok_kwmatchl ; is it a longer match?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2371 bls tokenize20 ; brif not, ignore it
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2372 sta tok_kwmatchl ; save new match length
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2373 ldd tok_kwtype ; get the matched token count
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2374 orb #0x80 ; set token flag
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2375 std tok_kwmatch ; save matched token
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2376 bra tokenize20 ; keep looking through the tables
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2377 tokenize22 lda #': ; for putting implied colons in
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2378 tokenize23 std ,y++ ; put output into buffer
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2379 jmp tokenize0 ; go handle more input
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2380 tokenize24 cmpb #tok_else ; is it ELSE?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2381 beq tokenize22 ; brif so - stash it with colon
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2382 cmpb #tok_data ; is it DATA?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2383 bne tokenize26 ; brif not
53
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2384 stb tok_skipdt ; set "in data" flag
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2385 tokenize25 stb ,y+ ; stash token
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2386 jmp tokenize0 ; go handle more
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2387 tokenize26 cmpb #tok_rem ; is it REM?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2388 beq tokenize28 ; brif so
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2389 cmpb #tok_apos ; apostrophe REM?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2390 bne tokenize25 ; brif not - stash token and continue
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2391 lda #': ; stash the implied colon
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
2392 sta ,y+
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2393 bra tokenize28
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2394 tokenize27 ldb ,x+ ; fetch next input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2395 tokenize28 stb ,y+ ; stash the character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2396 bne tokenize27 ; brif not end of input - do another
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2397 jmp tokenize2 ; stash end of buffer and handle cleanup
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2399 ; Special tokenization handling
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2401 ; Keyword dictionaries and jump tables. These are defined by several macros which ensure that each command or function
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2402 ; entry has an associated jump table entry. These macros are:
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2403 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2404 ; defcmd string,symbase
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2405 ; deffunc string,symbase,flags
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2406 ; cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2407 ; functab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2408 ; cmdjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2409 ; funcjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2410 ; defcmd and deffunc will add an entry into the relevant dictionary table as well as adding one to the relevant jump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2411 ; tables. The cmdtab, functab, cmdjump, and funcjump will output the table definitions.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2412 *pragmapush list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2413 *pragma nolist
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2414 __cmdnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2415 __funcnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2416 defcmd macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2417 setstr __cmdtab="%(__cmdtab)\tfcs {1}\n"
49
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2418 ifstr ne,"{3}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2419 setstr __cmdjump="%(__cmdjump)\tfdb {3}\n"
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2420 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2421 setstr __cmdjump="%(__cmdjump)\tfdb cmd_{2}\n"
49
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2422 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2423 tok_{2} equ __cmdnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2424 __cmdnum set __cmdnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2425 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2426 deffunc macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2427 setstr __functab="%(__functab)\tfcs {1}\n"
49
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2428 ifstr ne,"{4}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2429 setstr __funcjump="%(__funcjump)\tfcb {3}\n\tfdb {4}\n"
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2430 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2431 setstr __funcjump="%(__funcjump)\tfcb {3}\n\tfdb func_{2}\n"
49
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2432 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2433 tok_{2} equ __funcnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2434 __funcnum set __funcnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2435 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2436 cmdtab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2437 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2438 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2439 includestr "%(__cmdtab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2440 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2441 fcb 0 ; flag end of table
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2442 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2443 functab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2444 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2445 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2446 includestr "%(__functab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2447 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2448 fcb 0 ; flag end of table
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2449 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2450 cmdjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2451 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2452 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2453 includestr "%(__cmdjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2454 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2455 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2456 funcjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2457 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2458 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2459 includestr "%(__funcjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2460 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2461 endm
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2462 *pragmapop list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2463 defcmd 'REM',rem
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2464 defcmd /'/,apos
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2465 defcmd 'DATA',data
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2466 defcmd 'ELSE',else
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2467 defcmd 'END',end
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2468 defcmd 'STOP',stop
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
2469 defcmd 'LET',let
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
2470 defcmd 'NEW',new
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
2471 defcmd 'PRINT',print
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2472 defcmd 'LIST',list
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2473 defcmd 'RUN',run
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2474 defcmd 'GOTO',goto
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2475 defcmd 'GOSUB',gosub
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
2476 defcmd 'RETURN',return
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
2477 defcmd 'POP',pop
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2478 defcmd '+',plus,SNERROR ; IMPORTANT: the operators from + to OR MUST stay in this exact sequence
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2479 defcmd '-',minus,SNERROR ; with no gaps because a secondary lookup table is used for operator
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2480 defcmd '*',times,SNERROR ; handling during binary operator handling.
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2481 defcmd '/',divide,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2482 defcmd '^',power,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2483 defcmd '<',less,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2484 defcmd '>',greater,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2485 defcmd '=',equal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2486 defcmd '<=',lessequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2487 defcmd '>=',greaterequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2488 defcmd '<>',notequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2489 defcmd 'AND',and,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2490 defcmd 'OR',or,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2491 defcmd 'NOT',not,SNERROR
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2492 primarydict cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2493 secondarydict functab
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2494 primaryjump cmdjump
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2495 secondaryjump funcjump
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
2497 ; Need to ensure the vectors are at 0xbff2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
2498 zmb 0xbff2-* ; pad ROM up to the vector point
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2499 fdb SW3VEC ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2500 fdb SW2VEC ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2501 fdb FRQVEC ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2502 fdb IRQVEC ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2503 fdb SWIVEC ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2504 fdb NMIVEC ; NMI vector
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
2505 fdb START ; RESET vector (ROM entry point)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2506 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2507 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2508 zmb 0xfff2-* ; pad ROM to bottom of vectors
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2509 fdb INT.SWI3 ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2510 fdb INT.SWI2 ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2511 fdb INT.FIRQ ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2512 fdb INT.IRQ ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2513 fdb INT.SWI ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2514 fdb INT.NMI ; NMI vector
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2515 fdb START ; RESET vector (ROM entry point)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2516 else
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2517 zmb 0x10000-* ; pad ROM to full size
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2518 endc