annotate src/lwbasic.s @ 66:02080e77386f

Make negative integers parse correctly
author William Astle <lost@l-w.ca>
date Sun, 23 Apr 2023 10:12:14 -0600
parents bb9fe2bd4894
children 8ac1aafb9ecb
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
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
44 valtype_none equ 0 ; unknown value type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
45 valtype_int equ 1 ; integer (32 bit) value (signed)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
46 valtype_float equ 2 ; float type (40 bit) value
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
47 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
48 ; GIME INIT0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
49 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
50 GIME_MMUEN equ 0x40 ; Set to enable MMU
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
51 GIME_IEN equ 0x20 ; GIME IRQ enable
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
52 GIME_FEN equ 0x10 ; GIME FIRQ enable
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
53 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
54 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
55 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
56 GIME_ROME32 equ 0x03 ; 32K external ROM
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
57 GIME_ROMI32 equ 0x02 ; 32K internal ROM
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
58 ; GIME INIT1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
59 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
60 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
61 GIME_TASK0 equ 0x00 ; MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
62 GIME_TASK1 equ 0x01 ; MMU task 1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
63 ; GIME interrupt enable/status bits
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
64 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
65 GIME_IHBORD equ 0x10 ; HSYNC interrupt (falling edge)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
66 GIME_IVBORD equ 0x08 ; VSYNC interrupt (falling edge)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
67 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
68 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
69 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
70 ; GIME VMODE
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
71 GIME_BP equ 0x80 ; enable bit plane mode
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
72 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
73 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
74 GIME_H50 equ 0x08 ; set to 50Hz operation
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
75 GIME_LPR1 equ 0x00 ; one line per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
76 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
77 GIME_LPR8 equ 0x03 ; 8 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
78 GIME_LPR9 equ 0x04 ; 9 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
79 GIME_LPR10 equ 0x05 ; 10 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
80 GIME_LPR11 equ 0x06 ; 11 lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
81 GIME_LPRINF equ 0x07 ; "infinite" lines per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
82 ; GIME VRES
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
83 GIME_LPF192 equ 0x00 ; 192 lines on screen
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
84 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
85 GIME_LPF225 equ 0x60 ; 225 lines on screen
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
86 GIME_BPR16 equ 0x00 ; 16 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
87 GIME_BPR20 equ 0x04 ; 20 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
88 GIME_BPR32 equ 0x08 ; 32 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
89 GIME_BPR40 equ 0x0c ; 40 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
90 GIME_BPR64 equ 0x10 ; 64 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
91 GIME_BPR80 equ 0x14 ; 80 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
92 GIME_BPR128 equ 0x18 ; 128 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
93 GIME_BPR160 equ 0x1c ; 160 bytes per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
94 GIME_TXT32 equ 0x00 ; 32 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
95 GIME_TXT40 equ 0x04 ; 40 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
96 GIME_TXT64 equ 0x10 ; 64 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
97 GIME_TXT80 equ 0x14 ; 80 characters per row
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
98 GIME_BPP1 equ 0x00 ; 1 bit per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
99 GIME_BPP2 equ 0x01 ; 2 bits per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
100 GIME_BPP4 equ 0x02 ; 4 bits per pixel
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
101 GIME_TXTATTR equ 0x01 ; text attributes enabled
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
102 endc
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
103 ifdef COCO3
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
105 ; Stuff on the fixed memory page
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
106 org 0xfe00
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
107 rmb 0xed ; unused
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
108 INT.FLAG rmb 1 ; validity flag
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
109 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
110 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
111 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
112 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
113 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
114 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
115 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
117 ; 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
118 org 0xff00
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 rmb 32 ; miscelaneous hardware
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
134 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
135 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
136 GIME.INIT0 rmb 1 ; basic GIME system config
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
137 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
138 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
139 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
140 GIME.TIMER rmb 2 ; GIME programmable timer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
141 rmb 2 ; *reserved*
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
142 GIME.VMODE rmb 1 ; GIME video mode setting
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
143 GIME.VRES rmb 1 ; GIME video resolution setting
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
144 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
145 GIME.BORDER rmb 1 ; GIME border colour
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
146 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
147 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
148 GIME.HOFFSET rmb 1 ; horizontal scroll offset
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
149 GIME.MMU equ * ; MMU registers (two tasks)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
150 GIME.MMU0 rmb 8 ; MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
151 GIME.MMU1 rmb 8 ; MMU task 1
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
152 GIME.PALETTE rmb 16 ; Palette registers
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
153 else
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
154 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
155 endc
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 SAM.P1SET rmb 1
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
179 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
180 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
181 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
182 SAM.R1SET rmb 1
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
198 ; 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
199 org 0
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
200 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
201 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
202 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
203 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
204 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
205 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
206 stringtab rmb 2 ; bottom of used string space
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 console_blnkdel rmb 1 ; cursor blink delay
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
215 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
216 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
217 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
218 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
219 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
220 keyb_repdel rmb 1 ; repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 tok_kwmatch rmb 2 ; the current best matched token number
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
236 val0.type rmb 1 ; type of value in val0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
237 val0 rmb 0 ; bucket of bytes for val0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
238 val0.int rmb 0 ; 32 bit signed integer value (val0)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
239 val0.exp rmb 1 ; floating point exponent (val0)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
240 val0.mant rmb 4 ; floating point mantissa (val0)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
241 val0.sign rmb 1 ; floating point sign (val0)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
242 val1.type rmb 1 ; type of value in val1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
243 val1 rmb 0 ; bucket of bytes for val1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
244 val1.int rmb 0 ; 32 bit signed integer value (val1)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
245 val1.exp rmb 1 ; floating point exponent (val1)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
246 val1.mant rmb 4 ; floating point mantissa (val1)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
247 val1.sign rmb 1 ; floating point sign (val1)
25
9593401d23cf Rearrange some direct page stuff
William Astle <lost@l-w.ca>
parents: 24
diff changeset
248 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
249 RSTFLG rmb 1 ; 0x55 if RSTVEC is valid
9593401d23cf Rearrange some direct page stuff
William Astle <lost@l-w.ca>
parents: 24
diff changeset
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 ifne *&0x1ff
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
266 rmb 0x200-(*&0x1ff)
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
267 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
268 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
269 heapstart equ * ; start of dynamically allocated stuff
52
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
270 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
271 ; The heap has the following items in order:
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
272 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
273 ; 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
274 ; 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
275 ; 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
276 ; 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
277 ; 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
278 ; 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
279 ; 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
280 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
281 ; 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
282 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
283 ; Pointer Size of entry Variable types
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
284 ; vartabint 4 Integer scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
285 ; vartablong 6 Long integer scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
286 ; vartabfloat 7 Floating point scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
287 ; vartabstring 6 String scalars
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
288 ;
05c754390b1c Add description of heap area
William Astle <lost@l-w.ca>
parents: 51
diff changeset
289 ; 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
290 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
291 ROMSTART equ *
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
292 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
293 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
294 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
295 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
296 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
297 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
298 sta ,-x
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
299 decb ; done?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
300 bne initc0 ; brif not
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
301 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
302 ldd #0xff34 ; initizer for below
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 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
325 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
326 ; 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
327 ; 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
328 ifne (textscreen)&0x200
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
329 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
330 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
331 ifne (textscreen)&0x400
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
332 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
333 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
334 ifne (textscreen)&0x800
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
335 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
336 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
337 ifne (textscreen)&0x1000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
338 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
339 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
340 ifne (textscreen)&0x2000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
341 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
342 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
343 ifne (textscreen)&0x4000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
344 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
345 endc
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
346 ifne (textscreen)&0x8000
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
347 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
348 endc
3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
349 ifdef COCO2B
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
350 ; 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
351 ; 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
352 ; 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
353 ; 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
354 ; 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
355 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
356 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
357 bitb PIA1.DB
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
358 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
359 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
360 sta SAM.P1SET
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
361 skip2
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
362 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
363 else
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
364 ifndef COCO3
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
365 ; 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
366 ; 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
367 ; 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
368 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
369 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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378 endc
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
379 endc
05ef3a3b6d65 Add conditionals for assembly of different variants of the ROM
William Astle <lost@l-w.ca>
parents: 2
diff changeset
380 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
381 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
382 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
383 ifdef COCO3
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
384 ; 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
385 ; 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
386 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
387 cmpb #0x55
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
388 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
389 ldb RSTFLG ; is reset vector valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
390 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
391 ldx RSTVEC ; get reset vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
392 ldb ,x ; is it valid?\
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
393 cmpb #0x12
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
394 bne initc2 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
395 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
396 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
397 ldb RSTFLG ; get new RSTFLG
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
398 cmpb #0x55 ; valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
399 bne initc3 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
400 ldx RSTVEC ; get new RSTVEC
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
401 ldb ,x ; is it valid?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
402 cmpb #0x12
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
403 beq initc1 ; brif so - transfer control
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
404 initc3 ldb #0x38 ; restore MMU
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
405 stb GIME.MMU0
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
406 initc4 ldx #initc6 ; point to helper
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
407 ldu #textscreen ; point to text screen
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
408 ldb #initc7-initc6 ; bytes to copy
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
409 initc5 lda ,x+ ; copy byte
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
410 sta ,u+
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
411 decb ; done?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
412 bne initc5 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 blo initc6 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
422 jmp initc7 ; go back to mainline
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
423 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
424 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
425 sta warmstart
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
426 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
427 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
428 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
429 initc8 lda ,u+ ; copy byte
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
430 sta ,x+
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
431 decb ; done?
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
432 bne initc8 ; brif not
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
433 ; 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
434 endc
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
435 ldb RSTFLG ; is the reset vector valid?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
436 cmpb #0x55
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
437 bne coldstart ; brif not - do cold start
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
438 ldx RSTVEC ; get warm start routine pointer
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
439 ldb ,x ; does it start with NOP?
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
440 cmpb #0x12
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
441 bne coldstart ; brif not - do cold start
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
442 jmp ,x ; transfer control to warm start routine
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
443 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
444 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
445 ; GIME register initializer
10
8d4c0ffa2308 Fix GIME initializer so the text screen shows properly
William Astle <lost@l-w.ca>
parents: 8
diff changeset
446 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
447 fcb GIME_TASK0 ; use MMU task 0
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
448 fcb 0 ; do not enable IRQ sources
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
449 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
450 fdb 0xfff ; set timer to max value
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
451 fdb 0 ; *reserved placeholder*
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
452 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
453 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
454 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
455 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
456 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
457 fcb 0x3c,0x3d,0x3e,0x3f
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
458 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
459 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
460 gime_inite equ *
5
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
461 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
462 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
463 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
464 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
465 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
466 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
467 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
468 int_inite equ *
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
469 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
471 ; Cold start handling
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
472 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
473 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
474 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
475 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
476 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
477 ifndef COCO3
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
478 ; 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
479 ; 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
480 ; 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
481 ; 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
482 ; 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
483 ; 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
484 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
485 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
486 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
487 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
488 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
489 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
490 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
491 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
492 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
493 else
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
494 ; 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
495 ; 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
496 ; 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
497 ; 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
498 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
499 endc
06417341c50e Add memory size detection (coco1/2) and rearrange variables some
William Astle <lost@l-w.ca>
parents: 21
diff changeset
500 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
501 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
502 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
503 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
504 stx freetop ; save top of free memory
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
505 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
506 stx stackptr ; save the new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
507 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
508 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
509 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
510 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
511 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
512 clr ,x+
40
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
513 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
514 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
515 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
516 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
517 sta keyb_flags
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
518 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
519 stx RSTVEC
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
520 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
521 sta RSTFLG
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
522 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
523 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
524 sta IRQVEC
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
525 stx IRQVEC+1
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
526 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
527 ldx #firqhandler
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
528 stx FRQVEC+1
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
529 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
530 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
531 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
532 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
533 ldx #greeting ; display greeting
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
534 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
535 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
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
537 ; Warm start handling
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
538 ifdef COCO3
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
539 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
540 else
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
541 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
542 endc
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
543 jsr console_clear ; clear screen
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
544 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
545 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
546 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
547 sta PIA0.CB
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
548 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
549 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
550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
551 ; System startup message
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
552 ; (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
553 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
554 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
555 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
556 fcn '\n'
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
558 ; 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
559 ; 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
560 ; 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
561 breakcheck lda #0xfb ; strobe column for BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
562 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
563 clra ; clear carry for no BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
564 lda PIA0.DA ; read rows
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
565 bita #0x40 ; is BREAK down?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
566 bne breakcheck0 ; brif not - check for SHIFT-@
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
567 sync ; wait for interrupt to scan keyboard
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
568 bsr keyb_clearbuff ; reset keyboard buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
569 coma ; flag BREAK
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
570 breakcheck1 rts
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
571 breakcheck0 lda #0x7f ; check for SHIFT
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
572 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
573 lda PIA0.DA
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
574 bita #0x40 ; shift?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
575 bne breakcheck1 ; brif not
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
576 lda #0xfe ; check for @
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
577 sta PIA0.DB
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
578 lda PIA0.DA
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
579 bita #1 ; @?
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
580 bne breakcheck1 ; brif not
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
581 bsr keyb_clearbuff ; clear buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
582 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
583 bsr keyb_getkey
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
584 bcs breakcheck2 ; brif no key down
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
585 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
586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
587 ; Empty the keyboard buffer
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
588 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
589 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
590 stx keyb_buffw
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
591 rts
a0f7c8768867 Add SHIFT-@ handling for BREAK check
William Astle <lost@l-w.ca>
parents: 60
diff changeset
592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
593 ; IRQ handler
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
594 ;
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
595 ; 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
596 ; 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
597 ; 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
598 ; 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
599 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
600 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
601 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
602 ifdef COCO3
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
603 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
604 endc
12
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
605 rti
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
606 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
607 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
608 tfr a,dp
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
609 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
610 beq irqhandler1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
611 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
612 bne irqhandler1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
613 lda #console_curdel ; reset blink counter
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
614 sta console_blnkdel
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
615 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
616 adda #0x10 ; move to next colour
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
617 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
618 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
619 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
620 rti
981a5ed51a4d Enable interrupts during startup and add handler to process keyboard
William Astle <lost@l-w.ca>
parents: 11
diff changeset
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
622 ; FIRQ handler
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
623 ;
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
624 ; 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
625 ; 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
626 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
627 ifdef COCO3
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
628 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
629 endc
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
630 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
631 lda PIA1.DB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
632 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
633 anda #0xfe
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
634 sta PIA1.CA
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
635 lda PIA1.CB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
636 anda #0xfe
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
637 sta PIA1.CB
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
638 puls a ; restore register
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
639 rti
686b600a62ee Add safety FIRQ handler and initialize other interrupt vectors
William Astle <lost@l-w.ca>
parents: 14
diff changeset
640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
641 ; Console keyboard input driver
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
642 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
643 ; 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
644 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
645 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
646 anda #keyb_caps
ac52753bacfc Enable capslock by default and keep it on reset
William Astle <lost@l-w.ca>
parents: 36
diff changeset
647 sta keyb_flags
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
648 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
649 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
650 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
651 stx keyb_state
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
652 stx keyb_state+2
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
653 stx keyb_state+4
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
654 stx keyb_state+6
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
655 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
656 ; 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
657 ; 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
658 ; 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
659 ; next.
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
660 keyb_getkey pshs x ; save register
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
661 ldx keyb_buffr ; get read pointer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
662 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
663 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
664 coma ; set carry for empty buffer
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
665 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
666 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
667 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
668 blo keyb_getkey1 ; brif not
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
669 ldx #keyb_buff ; reset to start
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
670 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
671 andcc #0xfe ; flag key retrieved
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
672 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
673 ; 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
674 ; 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
675 ; 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
676 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
677 ; 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
678 ; 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
679 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
680 ; 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
681 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
682 ; * 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
683 ; * 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
684 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
685 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
686 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
687 bne keyb_read0d ; brif so
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
688 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
689 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
690 stb a,y
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
691 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
692 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
693 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
694 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
695 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
696 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
697 comb ; invert bit flag
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
698 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
699 bra keyb_read0c ; finish up
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
700 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
701 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
702 rts
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
703 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
704 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
705 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
706 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
707 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
708 sta PIA0.DB ; strobe no columns
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
709 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
710 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
711 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
712 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
713 rola ; set up for first column
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
714 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
715 ldb PIA0.DA ; read row data
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
716 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
717 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
718 stb ,y+ ; save state change information
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
719 rola ; shift to next column
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
720 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
721 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
722 ldd #0xff00|keyb_shift
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
723 bsr keyb_read0a
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
724 ldd #0xfc00|keyb_ctrl
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
725 bsr keyb_read0a
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
726 ldd #0xfb00|keyb_alt
20fa3242c6a5 Fix modifier key state detection in keyboard driver
William Astle <lost@l-w.ca>
parents: 18
diff changeset
727 bsr keyb_read0a
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
728 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
729 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
730 leau -1,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
731 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
732 bne keyb_read7 ; brif so
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
733 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
734 lslb ; shift bit probe
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
735 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
736 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
737 eorb ,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
738 stb ,u
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
739 ldb #1 ; reset bit probe
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
740 anda #0x07 ; reset scan code
11
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
741 deca ; adjust for next column
13
6b3609304712 Fix keyboard make/break and buffer handling
William Astle <lost@l-w.ca>
parents: 12
diff changeset
742 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
743 leas 9,s ; clean up stack
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
744 ldb keyb_curscan ; is key repeating?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
745 bne keyb_read9 ; brif so
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
746 keyb_reada rts
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
747 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
748 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
749 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
750 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
751 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
752 bra keyb_read6
21
2264569d7aca Fix and speed up key repeat
William Astle <lost@l-w.ca>
parents: 20
diff changeset
753 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
754 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
755 ldb #keyb_repdeli ; intialize repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
756 stb keyb_repdel
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
757 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
758 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
759 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
760 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
761 bne keyb_reada ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
762 ldb #keyb_repdelr ; reset repeat delay
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
763 stb keyb_repdel
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
764 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
765 keyb_tobuff tsta ; @?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
766 beq keyb_tobuff7 ; brif so
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
767 cmpa #26 ; is it alpha or @?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
768 bhi keyb_tobuff6 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
769 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
770 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
771 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
772 ora #0x60 ; make lower case
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
773 bitb #keyb_caps ; capslock enabled?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
774 beq keyb_tobuff0 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
775 eora #0x20 ; flip to upper case
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
776 keyb_tobuff0 bitb #keyb_shift ; shifted?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
777 beq keyb_tobuff1 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
778 eora #0x20 ; flip case if shifted
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
779 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
780 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
781 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
782 blo keyb_tobuff2 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
783 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
784 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
785 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
786 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
787 keyb_tobuff3 rts
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
788 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
789 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
790 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
791 bitb #keyb_shift ; shifted?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
792 beq keyb_tobuff5 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
793 ora #0x20 ; set bit 5
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
794 keyb_tobuff5 bitb #keyb_ctrl ; ctrl?
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
795 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
796 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
797 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
798 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
799 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
800 bne keyb_tobuff8 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
801 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
802 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
803 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
804 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
805 stb keyb_flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
806 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
807 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
808 blo keyb_tobuff9 ; brif not
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
809 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
810 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
811 mul ;*
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
812 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
813 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
814 ldb keyb_flags ; get shift flags
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
815 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
816 lda b,x ; fetch key code
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
817 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
818 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
819 ; 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
820 ; 0: unmodified
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
821 ; 1: shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
822 ; 2: ctrl
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
823 ; 3: ctrl-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
824 ; 4: alt
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
825 ; 5: alt-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
826 ; 6: alt-ctrl
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
827 ; 7: alt-ctrl-shift
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
828 ;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
829 ; 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
830 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
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840 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
841 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
842 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
843 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
844 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
845 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
846 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
847 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
848 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
849 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
850 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
851 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
852 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
853 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
854 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
855 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
856 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
857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b2212c9de7b7 Initial implementation of keyboard scan and setup
William Astle <lost@l-w.ca>
parents: 10
diff changeset
858 ; Console screen output driver
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
859 ;
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
860 ; Clear screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
861 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
862 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
863 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
864 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
865 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
866 blo console_clear0 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
867 rts
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
868 ; Output NUL terminated string
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
869 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
870 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
871 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
872 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
873 ; 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
874 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
875 ; fallthrough intentional
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
876 ; Output a newline (CR LF)
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
877 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
878 bsr console_outchr
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
879 lda #0x0a ; do the LF
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
880 ; fallthrough intentional
7
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
881 ; 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
882 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
883 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
884 cmpa #0x20 ; printable character?
8
6e8bb5223e6a Fix several bugs related to console operations
William Astle <lost@l-w.ca>
parents: 7
diff changeset
885 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
886 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
887 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
888 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
889 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
890 cmpa #0x60 ; upper case?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
891 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
892 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
893 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
894 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
895 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
896 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
897 blo console_outchr4 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
898 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
899 stx console_curptr
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
900 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
901 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
902 std ,x++ ; stick them here
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
903 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
904 blo console_outchr3 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
905 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
906 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
907 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
908 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
909 bne console_outchr6 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
910 bsr console_clear ; clear screen
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
911 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
912 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
913 bne console_outchr7 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
914 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
915 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
916 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
917 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
918 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
919 bne console_outchr8 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
920 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
921 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
922 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
923 console_outchr8 cmpa #0x08 ; backspace?
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
924 bne console_outchr9 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
925 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
926 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
927 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
928 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
929 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
930 bne console_outchr4 ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
931 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
932 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
933 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
934 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
935 incb ; bump counter
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
936 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
937 blo console_outchra ; brif not
b898c74f745c Add console output driver and a greeting message
William Astle <lost@l-w.ca>
parents: 6
diff changeset
938 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
939 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
940 ; General I/O handling package
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
941 ;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
942 ; 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
943 ;
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
944 ; 0: keyboard/screen console
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
945 ;
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
946 ; 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
947 ; 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
948 ; 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
949 readline ldx #linebuff ; point to line input buffer
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
950 clr ,x ; make sure buffer is NUL terminated
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
951 readline0 bsr readchr ; read an input character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
952 bcs readline1 ; brif not EOF
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
953 cmpa #0x0d ; CR (carriage return)
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
954 beq readline1 ; brif so - return
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
955 cmpa #0x03 ; BREAK?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
956 bne readline3 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
957 coma ; set carry for irregular exit
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
958 skip1
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
959 readline1 clra ; clear carry for regular exit
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
960 pshs cc ; save carry state
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
961 lda readlinenoecho ; are we echoing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
962 bne readline2 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
963 lda #0x0d ; echo carriage return + line feed
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
964 bsr writechr
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
965 readline2 tfr x,d ; get end address after input
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
966 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
967 clr ,x ; make sure line is NUL terminated
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
968 puls cc,pc ; restore BREAK flag (C) and return
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
969 readline3 cmpa #0x08 ; backspace?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
970 bne readline4 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
971 cmpx #linebuff ; at start of buffer?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
972 beq readline0 ; brif so - do nothing
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
973 leax -1,x ; move back buffer pointer
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
974 bsr readlinee ; write a BS
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
975 lda #0x20 ; write a space
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
976 bsr readlinee
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
977 lda #0x08 ; and finally a BS
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
978 bsr readlinee
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
979 bra readline0 ; go process more characters
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
980 readline4 cmpa #0x0c ; form feed?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
981 bne readline5 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
982 bsr readlinee ; go echo character if needed
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
983 bra readline ; go restart line entry
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
984 readline5 cmpa #0x20 ; is it non-printing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
985 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
986 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
987 bra readline0 ; go get another character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
988 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
989 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
990 sta ,x+ ; stash character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
991 readlinee ldb readlinenoecho ; are we echoing?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
992 bne readlinee0 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
993 bsr writechr ; echo the character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
994 readlinee0 rts
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
996 ; 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
997 ; position is not knowable.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
998 writecondnl lda filenum ; get file number
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
999 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
1000 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
1001 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
1002 beq writecondnl0 ; brif no newline is needed
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1003 ; fallthrough intended
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1005 ; Write a newline to the chosen device.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1006 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
1007 ; fallthrough intended
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1008 ; 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
1009 ; an output character (doesn't exist, etc.)
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1010 writechr tst filenum ; is it screen?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1011 beq writechr_scr ; brif writing to screen
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1012 orcc #1 ; unknown device flag
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1013 writecondnl0 rts
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1014 ; 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
1015 writechr_scr jsr console_outchr ; output the character
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1016 cmpa #0x0d ; was it CR?
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1017 bne writechr_scr0 ; brif not
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1018 lda #0x0a ; ouptut an LF
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1019 jsr console_outchr
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1020 lda #0x0d ; restore original value
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1021 writechr_scr0 andcc #0xfe ; clear error flag
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1022 rts
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1023 ; 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
1024 ; 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
1025 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
1026 lda filenum ; get input file number
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1027 beq readchr_kb ; brif keyboard input
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1028 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
1029 rts
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1030 ; 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
1031 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
1032 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
1033 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
1034 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
1035 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
1036 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
1037 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
1038 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
1039 stb [console_curptr] ; restore screen character
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1040 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
1041 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
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1043 ; 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
1044 ; 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
1045 ; 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
1046 writechrconduc tst filenum ; is it screen?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1047 bne writechr ; brif not - just output it
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1048 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
1049 bne writechr ; brif so - just output character
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1050 cmpa #'a ; is it lower case?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1051 blo writechr ; brif not
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1052 cmpa #'z ; is it still lower case?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1053 bhi writechr ; brif not
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1054 suba #0x20 ; shift to upper case
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1055 bra writechr ; go output it
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1057 ; 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
1058 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
1059 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
1060 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
1061 rts
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1063 ; 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
1064 ; 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
1065 ; 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
1066 ; 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
1067 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1068 ; 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
1069 ; 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
1070 ; 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
1071 ; 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
1072 ; 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
1073 ; 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
1074 ; 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
1075 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1076 ; 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
1077 ; sequence.
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1078 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1079 ; 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
1080 ; 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
1081 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
1082 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
1083 inc inputptr ; bump MSB
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1084 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
1085 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
1086 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
1087 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
1088 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
1089 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
1090 suba #-'0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1091 curchar0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1093 ; 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
1094 ; 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 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
1101 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
1102 suba #-'0
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1103 curcharraw0 rts
e956d8b6e806 Add raw version of nextchar/curchar that does not skip spaces
William Astle <lost@l-w.ca>
parents: 38
diff changeset
1104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1105 ; The error handler
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1106 ;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1107 ; 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
1108 ; may be active.
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1109 ;
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1110 ; 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
1111 ; 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
1112 ; 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
1113 ERROR clr filenum ; reset display device to console
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1114 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
1115 ldx #errormsg ; point to error message list
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1116 incb ; account for decb below
36
c786c1dd4632 Fix ERROR routine to actually work
William Astle <lost@l-w.ca>
parents: 35
diff changeset
1117 bra ERROR1 ; go search for correct message
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1118 ERROR0 lda ,x+ ; end of message?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1119 bne ERROR0 ; brif not end of message
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1120 ERROR1 decb ; at the correct one?
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1121 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
1122 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
1123 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
1124 beq ERROR3 ; brif so
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1125 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
1126 jsr writestrconduc ; output " in "
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1127 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
1128 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
1129 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
1130 clr ,-s ; reset the call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1131 sts stackptr
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1132 ; fall through to immediate mode intentional
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
1134 ; Immediate mode handler
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1135 immediate jsr writecondnl ; do newline if required
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1136 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
1137 jsr console_outstrn
18
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1138 immediate0 jsr readline ; read input line
6a046bd8107f Add line input routine
William Astle <lost@l-w.ca>
parents: 17
diff changeset
1139 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
1140 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
1141 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
1142 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
1143 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
1144 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
1145 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
1146 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
1147 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
1148 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
1149 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
1150 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
1151 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
1152 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
1153 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
1154 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
1155 immediate2 lda ,u+ ; get source byte
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1156 sta ,y+ ; stash it
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1157 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
1158 blo immediate2 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1159 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
1160 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
1161 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
1162 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
1163 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
1164 ldx inputptr ; point to line text
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1165 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
1166 leay ,x ; save tokenized line pointer
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1167 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
1168 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
1169 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
1170 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
1171 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
1172 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
1173 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
1174 bne immediate4 ; brif not - keep going
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1175 leas 2,s ; clear insertion location
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1176 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
1177 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
1178 std ,x++
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1179 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
1180 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
1181 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
1182 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
1183 ldx vartab ; clear out variables
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1184 stx objecttab
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1185 stx freestart
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1186 bra immediate0 ; go handle more input
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1188 ; 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
1189 ; 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
1190 ;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1191 ; 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
1192 ; 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
1193 ;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1194 ; 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
1195 ; 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
1196 prog_fixlineptrs
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1197 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
1198 prog_fixlineptrsx
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1199 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
1200 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
1201 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
1202 prog_fixlineptrs1
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1203 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
1204 bne prog_fixlineptrs1 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1205 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
1206 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
1207 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
1208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1209 ; 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
1210 ; 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
1211 ; 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
1212 ; 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
1213 ; 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
1214 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
1215 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
1216 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
1217 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
1218 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
1219 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
1220 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
1221 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
1222 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
1223 beq prog_findline1 ; brif not
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1224 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
1225 bls prog_findline2
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1226 ldx ,x ; move to next line
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1227 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
1228 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
1229 prog_findline2 rts
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1231 ; 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
1232 ; 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
1233 ; 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
1234 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
1235 std binval
43
b27b34d0afff Fix line number parsing to actually handle first character
William Astle <lost@l-w.ca>
parents: 42
diff changeset
1236 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
1237 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
1238 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
1239 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
1240 ldd binval ; get accumulated number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1241 lslb ; multiply accumulator by 10
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1242 rola ; times 2
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1243 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1244 lslb
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1245 rola ; times 4
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1246 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1247 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
1248 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1249 lslb
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1250 rola ; times 10
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1251 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1252 addb ,s+ ; add in accumulated digit
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1253 adca #0
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1254 bcs SNERROR ; brif overflow
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1255 std binval ; save accumulated number
68253ccbb9dc Immediate mode line insertion, removal, and replacement
William Astle <lost@l-w.ca>
parents: 39
diff changeset
1256 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
1257 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
1258 parse_lineno1 rts
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1259 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1260 ; The NEW command.
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1261 ;
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1262 ; This also includes several useful entry points:
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1263 ;
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1264 ; 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
1265 ; cmd_newinptr: skips clearing the program text
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1266 ; 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
1267 ; 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
1268 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
1269 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
1270 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
1271 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
1272 clr ,x+
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1273 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
1274 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
1275 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
1276 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
1277 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
1278 stx stringtab ; clear out string space
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1279 ldx vartab ; get start of variables
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1280 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
1281 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
1282 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
1283 stx stringstackptr
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1284 ldx ,s ; get return address
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1285 lds freetop ; reset stack to top of memory
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1286 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
1287 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
1288 clr contstmt ; clear "CONT" destination
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1289 clr contstmt+1
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1290 jmp ,x ; return to caller
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
1291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1292 ; Main interpretation loop
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1293 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1294 ; 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
1295 ; 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
1296 ; 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
1297 ; 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
1298 ; 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
1299 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
1300 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
1301 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
1302 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
1303 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
1304 beq interpret0 ; brif so
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1305 cmpa #': ; end of statement?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1306 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
1307 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
1308 jmp ERROR
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1309 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
1310 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
1311 bne interpret1 ; brif not
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1312 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
1313 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
1314 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
1315 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
1316 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
1317 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
1318 interpret2 stx inputptr
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1319 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
1320 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
1321 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
1322 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
1323 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
1324 anda #0x7f ; lose bit 7
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1325 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
1326 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
1327 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
1328 jsr ,x ; call the routine
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1329 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
1330 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
1331 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
1332 clr curline+1
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1333 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
1334 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
1335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47
b98c01cd3377 Add routine to throw syntax error if input character doesn't match
William Astle <lost@l-w.ca>
parents: 46
diff changeset
1336 ; 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
1337 ; 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
1338 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
1339 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
1340 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
1341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1342 ; The END command.
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1343 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
1344 ;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
1345 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
1346 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
1347 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
1348 coma ; flag STOP - set carry
6a4c342ac12b Add BREAK check to main interpretation loop.
William Astle <lost@l-w.ca>
parents: 56
diff changeset
1349 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
1350 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
1351 ldx curline ; in immediate mode?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1352 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
1353 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
1354 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
1355 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
1356 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
1357 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
1358 ldx #breakmsg ; do "BREAK IN"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1359 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
1360 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
1361 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1362 ; 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
1363 cmd_else
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1364 cmd_apos
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1365 cmd_rem clra ; clear carry
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1366 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
1367 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
1368 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
1369 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
1370 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
1371 rts
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1373 ; DATA command
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1374 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1375 ; 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
1376 ; a quoted string
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1377 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
1378 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
1379 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
1380 cmpa #': ; end of statement?
58
24b123b3e69b Fix flow error in DATA command skipping
William Astle <lost@l-w.ca>
parents: 57
diff changeset
1381 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
1382 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
1383 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
1384 rts
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1385 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
1386 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
1387 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
1388 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
1389 cmpa #'" ; string delimiter?
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1390 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
1391 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
1392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1393 ; RUN command
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1394 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
1395 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
1396 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
1397 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
1398 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
1399 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
1400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1401 ; GOTO command
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1402 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
1403 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
1404 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
1405 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
1406 jmp ERROR
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1407 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
1408 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
1409 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
1410 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
1411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1412 ; GOSUB command
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1413 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
1414 ldd #tok_gosub*256+4 ; stack frame details
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1415 bsr callstack_alloc ; make a stack frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1416 ldx curline ; save current line pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1417 stx ,u
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1418 ldx inputptr ; save current input pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1419 stx 2,u
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1420 bra cmd_gosub0 ; go finish up as a GOTO
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1422 ; RETURN command
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1423 ; POP command
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1424 ;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1425 ; 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
1426 ; of 0 will cause it to stop.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1427 cmd_pop skip1lda ; set nonzero for POP
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1428 cmd_return clra ; set zero for RETURN
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1429 pshs a ; save operation type
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1430 bsr callstack_first ; get first entry on call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1431 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
1432 RG_ERROR ldb #err_rg ; raise RETURN without GOSUB
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1433 jmp ERROR
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1434 cmd_return0 bsr callstack_next ; move to next entry
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1435 beq RG_ERROR ; brif end of stack - raise error
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1436 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
1437 bne cmd_return0 ; brif not - try again
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1438 lda ,s+ ; is it "POP"?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1439 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
1440 ldx ,u ; get back saved line pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1441 stx curline
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1442 ldx 2,u ; get back saved input pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1443 stx inputptr
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1444 cmd_return2 bsr callstack_pop ; clean up call stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1445 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
1446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1447 ; 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
1448 ; sets Z if there is nothing on the stack.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1449 callstack_first ldu stackptr ; get stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1450 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
1451 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1453 ; 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
1454 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
1455 leau b,u ; move to the next frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1456 ldb -2,u ; set flags on frame type code
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1457 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1459 ; 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
1460 ;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1461 ; 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
1462 ; 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
1463 ; 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
1464 ; the call.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1465 callstack_alloc addb #2 ; account for the header bytes
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1466 pshs a,b ; save the type and length
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1467 negb ; need a negative offset
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1468 leax ,s ; point to current bottom of stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1469 leas b,s ; make a hole below the stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1470 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
1471 callstack_alloc0
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1472 lda ,x+ ; copy a byte down
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1473 sta ,u+
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1474 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
1475 blo callstack_alloc0 ; brif not
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1476 stu stackptr ; save the new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1477 puls d ; get back the type and length values
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1478 std ,u++ ; save type and length
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1479 rts
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1481 ; 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
1482 ; newly made gap in memory.
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1483 callstack_pop leau -2,u ; move back to header
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1484 ldb 1,u ; get length of frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1485 leax b,u ; point to element after this frame
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1486 sts ,--s ; save the current bottom of the stack
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1487 stx stackptr ; save new call stack pointer
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1488 callstack_pop0 lda ,-u ; copy a byte up
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1489 sta ,-x
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1490 cmpu ,s ; at the bottom of the call stack?
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1491 bhi callstack_pop0 ; brif not
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1492 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
1493 rts
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1495 ; Miscelaneous strings
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1496 prompt fcn 'OK' ; general prompt
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1497 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
1498 inmsg fcn ' in ' ; " in " message
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1499 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1500 ; 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
1501 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
1502 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
1503 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
1504 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
1505 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
1506 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
1507 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
1508 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
1509 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
1510 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
1511 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
1512 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
1513 stb ,y ; stash it
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1514 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
1515 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
1516 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
1517 cmpa #0x30 ; zero digit?
e0c0ed649269 Make print_uint16d slightly smaller when removing leading zeroes
William Astle <lost@l-w.ca>
parents: 50
diff changeset
1518 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
1519 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
1520 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
1521 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
1522 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
1523 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
1524 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
1525 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
1526 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
1527 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
1528 rts
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1529 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
1530 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
1531 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
1532 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
1533 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
1534 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
1535 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
1536 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
1537 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
1538 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
1539 rts
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1540
39275fdc7c0b Add routine to print unsigned integer in D to current output
William Astle <lost@l-w.ca>
parents: 47
diff changeset
1541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
1542 ; PRINT command
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1543 cmd_print beq cmd_printeol ; brif no argument - do a newline
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1544 cmd_print0 cmpa #'; ; semicolon?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1545 bne cmd_print1 ; brif not
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1546 jsr nextchar ; skip the semicolon
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1547 bne cmd_print0 ; brif not end of the statement
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1548 rts
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1549 cmd_print1 jsr eval_expr ; evaluate the expression
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1550 ldb val0.type ; get value type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1551 cmpb #valtype_int ; integer?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1552 beq cmd_printint ; brif so - print integer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1553 lda #'! ; flag unknown expression type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1554 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1555 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1556 jsr console_outchr
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1557 cmd_printnext jsr curchar ; see what we have here
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1558 bra cmd_print ; and go process
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1559 cmd_printeol jmp console_outnl ; do a newline and return
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1560 cmd_printint leas -12,s ; make a buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1561 leay ,s ; point to buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1562 lda #0x20 ; default sign (positive)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1563 ldb val0.int ; is it negative?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1564 bpl cmd_printint0 ; brif not
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1565 ldd zero ;
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1566 subd val0.int+2
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1567 std val0.int+2
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1568 ldd zero
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1569 sbcb val0.int+1
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1570 sbca val0.int
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1571 std val0.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1572 lda #'- ; negative sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1573 cmd_printint0 sta ,y+ ; save sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1574 ldu #cmd_printintpc ; point to positive constant table
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1575 ldx #10 ; there are 10 constants to process
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1576 ; subtraction loop - positive residue
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1577 cmd_printint1 lda #'0-1 ; initialize digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1578 sta ,y
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1579 cmd_printint2 inc ,y ; bump digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1580 ldd val0.int+2 ; subtract constant
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1581 subd 2,u
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1582 std val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1583 ldd val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1584 sbcb 1,u
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1585 sbca ,u
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1586 std val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1587 bcc cmd_printint2 ; brif we didn't go negative
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1588 ldd val0.int+2 ; undo last subtract
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1589 addd 2,u
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1590 std val0.int+2
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1591 ldd val0.int
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1592 adcb 1,u
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1593 adca ,u
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1594 std val0.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1595 leay 1,y ; move to next digit in buffer
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1596 leau 4,u ; move to next constant
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1597 leax -1,x ; done all constants?
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1598 bne cmd_printint1 ; brif not - done all
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1599 cmd_printint5 clr ,y ; NUL terminate the string
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1600 leax 1,s ; point past the sign
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1601 cmd_printint6 lda ,x+ ; get digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1602 beq cmd_printint8 ; brif end of number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1603 cmpa #'0 ; is it a zero?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1604 beq cmd_printint6 ; brif so - skip it
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1605 cmd_printint7 lda ,s ; get the sign
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1606 sta ,--x ; put it at the start of the number
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1607 jsr console_outstr ; display the number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1608 leas 12,s ; clean up stack
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1609 bra cmd_printnext ; go print the next thing
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1610 cmd_printint8 leax -1,x ; restore one of the zeros
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1611 bra cmd_printint7 ; go finish up
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1612 cmd_printintpc fqb 1000000000 ; 10^9
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1613 fqb 100000000 ; 10^8
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1614 fqb 10000000 ; 10^7
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1615 fqb 1000000 ; 10^6
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1616 fqb 100000 ; 10^5
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1617 fqb 10000 ; 10^4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1618 fqb 1000 ; 10^3
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1619 fqb 100 ; 10^2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1620 fqb 10 ; 10^1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1621 fqb 1 ; 10^0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1622
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1623
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
1624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23
4b4806a32701 Add some error handling framework
William Astle <lost@l-w.ca>
parents: 22
diff changeset
1625 ; Error messages
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1626 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1627 ; 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
1628 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1629 ; deferr slug
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1630 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1631 ; 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
1632 ;
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1633 ; 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
1634 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1635 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1636 __errnum set 0
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1637 deferr macro noexpand
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1638 err_{1} equ __errnum
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1639 __errnum set __errnum+1
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1640 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1641 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1642 errormsg deferr none
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1643 fcn 'No error'
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1644 deferr nf
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1645 fcn 'NEXT without FOR'
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1646 deferr sn
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
1647 fcn 'Syntax error'
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1648 deferr ul
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
1649 fcn 'Undefined line number'
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1650 deferr rg
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
1651 fcn 'RETURN without GOSUB'
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1652 deferr ov
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1653 fcn 'Overflow'
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1654 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
1655 ; 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
1656 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
1657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1658 ; Expression Evaluation Package
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1659 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1660 ; 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
1661 ; 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
1662 ; 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
1663 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1664 ; 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
1665 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
1666 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
1667 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
1668 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
1669 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
1670 bhi eval_expr1 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1671 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
1672 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
1673 eval_expr1 rts
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1674 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
1675 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
1676 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
1677 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
1678 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
1679 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
1680 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
1681 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
1682 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
1683 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
1684 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
1685 ldx 1,x ; get handler address of this operator
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1686 pshs x ; save handler address for later
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1687 lda val0.type ; get current value type
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1688 ldx val0 ; get value accumlator contents (6 bytes)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1689 ldy val0+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1690 ldu val0+4
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1691 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
1692 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
1693 puls a,x,y,u ; get back saved value
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1694 stx val1 ; save it to the second value accumulator
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1695 sty val1+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1696 stu val1+4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1697 sta val1.type ; save previous value type
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1698 jsr [,s++] ; go handle the operator
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1699 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
1700 bra eval_expr0 ; go process another operator or end of expression
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1701 eval_term jsr curchar ; get current input character
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1702 beq eval_term0 ; brif end of input - this is an error
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1703 bcs eval_number ; brif digit - we have a number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1704 ; bmi eval_func ; brif we have a token - handle function call
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1705 cmpa #'. ; decimal point?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1706 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1707 cmpa #'- ; negative sign?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1708 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1709 cmpa #'+ ; positive sign?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1710 beq eval_number ; brif so - evaluate number
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1711 eval_term0 jmp SNERROR ; we have something unrecognized - raise error
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1712 ; Evaluate a number constant. Currently this only handles 32 bit integers.
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1713 eval_number ldb #valtype_int ; start with integer value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1714 stb val0.type ; set return value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1715 ldx zero ; blank out the value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1716 stx val0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1717 stx val0+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1718 stx val0+4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1719 bra eval_number1 ; go do the parsing
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1720 eval_number0 jsr nextchar ; fetch next input
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1721 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
1722 eval_number1 cmpa #'- ; negative (ascii sign)?
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1723 beq eval_number3 ; brif so
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1724 cmpa #tok_minus ; negative (operator negative)?
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1725 bne eval_number2 ; brif not
66
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1726 eval_number3 com val0.sign ; invert sign
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1727 bra eval_number0 ; deal with next input
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1728 eval_number2 cmpa #'+ ; unary +?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1729 beq eval_number0 ; brif so - skip it
65
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1730 eval_number5 cmpa #'. ; decimal point?
bb9fe2bd4894 Fix display of integer values
William Astle <lost@l-w.ca>
parents: 64
diff changeset
1731 beq eval_float ; brif decimal - force float
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1732 cmpa #'0 ; is it a number?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1733 blo eval_numberr ; brif below digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1734 cmpa #'9 ; is it still a number?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1735 bhi eval_numberr ; brif above digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1736 suba #'0 ; offset to binary digit value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1737 pshs a ; save digit value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1738 ldx val0.int ; get current value for later (for quick multiply by 10)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1739 ldd val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1740 pshs d,x ; stored with words swapped on stack for efficiency for later
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1741 lsl val0.int+3 ; times 2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1742 rol val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1743 rol val0.int+1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1744 rol val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1745 bcs OVERROR ; brif overflowed
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1746 lsl val0.int+3 ; times 4
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1747 rol val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1748 rol val0.int+1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1749 rol val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1750 bcs OVERROR ; brif overflowed
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1751 ldd val0.int+2 ; times 5 (add original value)
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1752 addd ,s++
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1753 std val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1754 ldd val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1755 adcb 1,s
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1756 adca ,s++
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1757 std val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1758 bcs OVERROR
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1759 lsl val0.int+3 ; times 10
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1760 rol val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1761 rol val0.int+1
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1762 rol val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1763 bcs OVERROR ; brif overflowed
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1764 ldd val0.int+2 ; get low word
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1765 addb ,s+ ; add in current digit
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1766 adca #0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1767 std val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1768 ldd val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1769 adcb #0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1770 adca #0
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1771 std val0.int
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1772 bcs OVERROR ; brif overflowed
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1773 bpl eval_number4 ; brif we haven't wrapped negative
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1774 cmpd #0x8000 ; is it valid negative two's complement?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1775 bhi OVERROR ; brif not
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1776 ldd val0.int+2 ; is it still valid two's complement (max negative)?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1777 bne OVERROR ; brif so
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1778 eval_number4 jsr nextchar ; fetch next input character
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1779 bra eval_number5 ; go handle it
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1780 OVERROR ldb #err_ov ; flag overflow
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1781 jmp ERROR
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1782 eval_numberr ldb val0.sign ; is the number we want negative?
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1783 beq eval_numberr0 ; brif not
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1784 ldd zero ; negate the value
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1785 subd val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1786 std val0.int+2
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1787 ldd zero
66
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1788 sbcb val0.int+1
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1789 sbca val0.int
02080e77386f Make negative integers parse correctly
William Astle <lost@l-w.ca>
parents: 65
diff changeset
1790 std val0.int
64
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1791 eval_numberr0 rts
2205c3c59a33 Checkpoint
William Astle <lost@l-w.ca>
parents: 63
diff changeset
1792 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
1793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1794 ; Operator table
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1795 ;
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1796 ; 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
1797 ; 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
1798 oper_tab fcb 0x79 ; addition
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1799 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1800 fcb 0x79 ; subtraction
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1801 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1802 fcb 0x7b ; multiplication
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1803 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1804 fcb 0x7b ; division
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1805 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1806 fcb 0x7f ; exponentiation
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1807 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1808 fcb 0x64 ; less than
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1809 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1810 fcb 0x64 ; equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1811 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1812 fcb 0x64 ; greater than
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1813 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1814 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
1815 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1816 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
1817 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1818 fcb 0x64 ; not equal to
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1819 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1820 fcb 0x50 ; boolean AND
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1821 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1822 fcb 0x46 ; boolean OR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1823 fdb SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1824 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1825 ; 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
1826 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
1827 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
1828 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
1829 suba #-'a
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1830 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
1831 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
1832 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
1833 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
1834 suba #-'A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1835 setcifalpha0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1836 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1837 ; Set carry if digit
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1838 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
1839 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
1840 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
1841 suba #-'0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1842 setcifdigit0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1844 ; The LIST command.
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1845 ;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1846 ; Syntax:
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1847 ; LIST
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1848 ; LIST <line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1849 ; LIST <line>-
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1850 ; LIST -<line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1851 ; LIST <start>-<end>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1852 cmd_list bne cmd_list1 ; brif we have arguments
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1853 ldx progtext ; point to start of program
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1854 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
1855 std binval
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1856 bra cmd_list2 ; go do the listing
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1857 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
1858 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
1859 jsr curchar ; are we at the end of the command?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1860 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
1861 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
1862 jsr syncheckb
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1863 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
1864 jsr parse_lineno ; parse ending of range
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1865 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
1866 bne cmd_list4 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1867 cmd_list3 rts
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1868 cmd_list4 ldd 2,x ; get line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1869 cmpd binval ; have we reached the end of the range?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1870 bhi cmd_list3 ; brif so - we're done
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1871 jsr print_uint16d ; print out line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1872 lda #0x20 ; and a space
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1873 jsr writechr
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1874 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
1875 leax 4,x ; move past line header
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1876 bsr detokenize ; detokenize line to current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1877 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
1878 ; need to add a break check here
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1879 bra cmd_list2 ; go handle another line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1881 ; Detokenize a line to the current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1882 detokenize lda ,x+ ; get character from tokenized line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1883 bmi detokenize1 ; brif it's a keyword token
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1884 lbeq writecondnl ; do a newline if needed and return
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1885 cmpa #': ; is it a colon?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1886 bne detokenize0 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1887 ldb ,x ; fetch subsequent character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1888 cmpb #tok_apos ; apostrophe version of REM?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1889 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1890 cmpb #tok_else ; ELSE?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1891 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1892 detokenize0 jsr writechr ; output it unmolested
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1893 bra detokenize ; go handle another character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1894 detokenize1 ldu #primarydict ; point to primary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1895 cmpa #0xff ; is it a secondary token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1896 bne detokenize3 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1897 ldu #secondarydict ; point to secondary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1898 lda ,x+ ; get secondary token value
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1899 bne detokenize3 ; brif not end of line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1900 leax -1,x ; don't consume the NUL
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1901 detokenize2 lda #'! ; invalid token flag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1902 bra detokenize0 ; output it and continue
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1903 detokenize3 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1904 beq detokenize6 ; brif already at the right place
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1905 detokenize4 ldb ,u ; end of dictionary table?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1906 beq detokenize2 ; brif so - show invalid tokenf lag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1907 detokenize5 ldb ,u+ ; fetch character in this keyboard
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1908 bpl detokenize5 ; brif not end of keyword (high bit set)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1909 deca ; at the right token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1910 bne detokenize4 ; brif not - skip another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1911 detokenize6 lda ,u+ ; get keyword character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1912 bmi detokenize7 ; brif end of keyword
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1913 jsr writechr ; output it
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1914 bra detokenize6 ; go fetch another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1915 detokenize7 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1916 bra detokenize0 ; write it and move on with the input
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1918 ; 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
1919 makecanontab fcb tok_less,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1920 fcb tok_greater,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1921 fcb tok_equal,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1922 fcb tok_greater,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1923 fcb tok_less,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1924 fcb tok_equal,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1925 fcb tok_equal,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1926 fcb tok_greater,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1927 fcb tok_less,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1928 fcb 0
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1929 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
1930 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
1931 sta ,y+ ; save in output
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1932 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
1933 rts
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1934 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
1935 cmpa #0xff ; is it secondary?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1936 bne makecanon2 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1937 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
1938 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
1939 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
1940 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
1941 beq makecanon4 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1942 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
1943 lslb ; 2 bytes per
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1944 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
1945 ldb ,u ; end of table?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1946 bne makecanon3 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1947 bra makecanon0 ; no substitutions found
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1948 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
1949 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
1950 cmpa #0x20 ; is it space?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1951 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
1952 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
1953 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
1954 beq makecanon7 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1955 decb ; seen all of them?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1956 bne makecanon6 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1957 puls x ; restore input pointer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1958 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
1959 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
1960 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
1961 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
1962 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
1963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1964 ; Tokenize line to tokebuff
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
1965 ;
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
1966 ; 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
1967 ; 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
1968 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
1969 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
1970 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
1971 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
1972 tokenize0 lda ,x+ ; get input character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1973 bne tokenize3 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1974 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
1975 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
1976 bsr makecanon ; canonicalize certain sequences
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
1977 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
1978 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
1979 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
1980 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
1981 beq tokenize6 ; brif not
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1982 jsr setcifalpha ; is it alpha
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1983 bcs tokenize4 ; brif so - store it and continue
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
1984 jsr setcifdigit ; is it numeric?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1985 bcc tokenize5 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1986 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
1987 bra tokenize0 ; check for another
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1988 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
1989 tokenize6 cmpa #'" ; is it a string?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1990 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
1991 sta ,y+ ; save string delimiter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1992 tokenize7 lda ,x+ ; get input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1993 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
1994 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
1995 cmpa #'" ; end of string?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1996 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
1997 bra tokenize0 ; brif
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1998 tokenize8 cmpa #': ; end of statement?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
1999 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
2000 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
2001 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2002 tokenize9 cmpa #0x20 ; is it a space?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2003 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
2004 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
2005 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
2006 cmpa #'? ; PRINT shortcut?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2007 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
2008 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
2009 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
2010 tokenize10 cmpa #'' ; ' shortcut for remark?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2011 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
2012 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
2013 std ,y++ ; stash it
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2014 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
2015 sta ,y+ ; stash in output
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2016 bne tokenize11 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2017 bra tokenize2 ; go finish up
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2018 tokenize12 jsr setcifdigit ; is it a digit?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2019 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
2020 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
2021 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
2022 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
2023 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
2024 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
2025 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
2026 clr tok_kwmatch+1
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
2027 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
2028 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
2029 tokenize13 clr tok_kwnum ; clear keyword number
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2030 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
2031 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
2032 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
2033 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
2034 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
2035 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
2036 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
2037 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
2038 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
2039 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
2040 tsta ; is it a primary?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2041 beq tokenize24 ; brif so
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2042 bra tokenize23 ; go stash two byte token
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2043 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
2044 lda ,x+ ; get character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2045 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2046 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
2047 clra ; initalize match length counter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2048 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
2049 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
2050 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
2051 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
2052 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
2053 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
2054 subb #0x20 ; convert to upper case
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2055 tokenize18 subb ,u+ ; does it match?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2056 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
2057 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
2058 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
2059 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
2060 tokenize19 ldb ,u+ ; end of token?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2061 bpl tokenize19 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2062 tokenize20 inc tok_kwnum ; bump token counter
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2063 bra tokenize14 ; go check another one
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2064 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
2065 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
2066 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
2067 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
2068 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
2069 std tok_kwmatch ; save matched token
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2070 bra tokenize20 ; keep looking through the tables
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2071 tokenize22 lda #': ; for putting implied colons in
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2072 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
2073 jmp tokenize0 ; go handle more input
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2074 tokenize24 cmpb #tok_else ; is it ELSE?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2075 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
2076 cmpb #tok_data ; is it DATA?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2077 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
2078 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
2079 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
2080 jmp tokenize0 ; go handle more
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2081 tokenize26 cmpb #tok_rem ; is it REM?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2082 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
2083 cmpb #tok_apos ; apostrophe REM?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2084 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
2085 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
2086 sta ,y+
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2087 bra tokenize28
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2088 tokenize27 ldb ,x+ ; fetch next input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2089 tokenize28 stb ,y+ ; stash the character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
2090 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
2091 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
2092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2093 ; Special tokenization handling
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2094 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2095 ; 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
2096 ; 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
2097 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2098 ; defcmd string,symbase
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2099 ; deffunc string,symbase,flags
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2100 ; cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2101 ; functab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2102 ; cmdjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2103 ; funcjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2104 ; 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
2105 ; 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
2106 *pragmapush list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2107 *pragma nolist
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2108 __cmdnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2109 __funcnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2110 defcmd macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2111 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
2112 ifstr ne,"{3}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2113 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
2114 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2115 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
2116 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2117 tok_{2} equ __cmdnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2118 __cmdnum set __cmdnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2119 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2120 deffunc macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2121 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
2122 ifstr ne,"{4}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
2123 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
2124 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2125 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
2126 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2127 tok_{2} equ __funcnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2128 __funcnum set __funcnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2129 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2130 cmdtab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2131 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2132 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2133 includestr "%(__cmdtab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2134 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2135 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
2136 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2137 functab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2138 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2139 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2140 includestr "%(__functab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2141 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2142 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
2143 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2144 cmdjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2145 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2146 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2147 includestr "%(__cmdjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2148 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2149 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2150 funcjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2151 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2152 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2153 includestr "%(__funcjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2154 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2155 endm
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2156 *pragmapop list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2157 defcmd 'REM',rem
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2158 defcmd /'/,apos
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2159 defcmd 'DATA',data
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2160 defcmd 'ELSE',else
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2161 defcmd 'END',end
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2162 defcmd 'STOP',stop
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
2163 defcmd 'LET',let
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
2164 defcmd 'NEW',new
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
2165 defcmd 'PRINT',print
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
2166 defcmd 'LIST',list
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2167 defcmd 'RUN',run
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2168 defcmd 'GOTO',goto
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
2169 defcmd 'GOSUB',gosub
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
2170 defcmd 'RETURN',return
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
2171 defcmd 'POP',pop
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2172 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
2173 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
2174 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
2175 defcmd '/',divide,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2176 defcmd '^',power,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2177 defcmd '<',less,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2178 defcmd '>',greater,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2179 defcmd '=',equal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2180 defcmd '<=',lessequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2181 defcmd '>=',greaterequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2182 defcmd '<>',notequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2183 defcmd 'AND',and,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2184 defcmd 'OR',or,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
2185 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
2186 primarydict cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2187 secondarydict functab
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2188 primaryjump cmdjump
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
2189 secondaryjump funcjump
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
2191 ; 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
2192 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
2193 fdb SW3VEC ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2194 fdb SW2VEC ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2195 fdb FRQVEC ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2196 fdb IRQVEC ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2197 fdb SWIVEC ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2198 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
2199 fdb START ; RESET vector (ROM entry point)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2200 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2201 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2202 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
2203 fdb INT.SWI3 ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2204 fdb INT.SWI2 ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2205 fdb INT.FIRQ ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2206 fdb INT.IRQ ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2207 fdb INT.SWI ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
2208 fdb INT.NMI ; NMI vector
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2209 fdb START ; RESET vector (ROM entry point)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2210 else
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2211 zmb 0x10000-* ; pad ROM to full size
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
2212 endc