annotate src/lwbasic.s @ 75:5f8f0b0781e8

Split some code into separate files for easier management (3) Because the source for lwbasic is so large, split it into several different files to make it easier to navigate and modify. This is part three of the split. Includes a file missing from part one.
author William Astle <lost@l-w.ca>
date Sun, 06 Aug 2023 00:41:26 -0600
parents e74d00ac6b79
children eb2681108660
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
73
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
32 ; Include the various sub source files
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
33 include defs.s
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
34 include vars.s
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
35 *pragmapop list
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
36 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
37 ROMSTART equ *
73
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
38 *pragmapush list
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
39 *pragma nolist
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
40 include init.s
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
41 include keyb.s
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
42 include irq.s
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
43 include consscr.s
74
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents: 73
diff changeset
44 include genio.s
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents: 73
diff changeset
45 include interp.s
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents: 73
diff changeset
46 include progctrl.s
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents: 73
diff changeset
47 include print.s
75
5f8f0b0781e8 Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents: 74
diff changeset
48 include error.s
5f8f0b0781e8 Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents: 74
diff changeset
49 include expr.s
5f8f0b0781e8 Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents: 74
diff changeset
50
74
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents: 73
diff changeset
51 include miscdata.s
73
2d52cd154ed1 Split some code into separate files for easier management
William Astle <lost@l-w.ca>
parents: 72
diff changeset
52 *pragmapop list
17
f86967c0bc73 Add general keyboard input (blinking cursor) handler
William Astle <lost@l-w.ca>
parents: 16
diff changeset
53 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
54 ; 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
55 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
56 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
57 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
58 suba #-'a
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
59 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
60 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
61 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
62 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
63 suba #-'A
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
64 setcifalpha0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
66 ; Set carry if digit
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
67 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
68 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
69 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
70 suba #-'0
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
71 setcifdigit0 rts
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
73 ; Operator handling routines
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
74 ;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
75 ; binary plus: addition and concatenation
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
76 oper_plus ldb val.type,x ; get type of the left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
77 cmpb valtype_string ; is it string?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
78 bne oper_plus0 ; brif not
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
79 cmpb val.type,u ; is right operand also string?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
80 lbeq SNERROR ; brif so - do string concatenation
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
81 oper_plus0 bsr val_matchtypes ; go match data types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
82 jmp val_add ; go add the values
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
83 ; binary minus: subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
84 oper_minus bsr val_matchtypes ; go match data types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
85 jmp val_sub ; do subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
87 ; Arithmetic package
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
88 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
89 ; This section contains routines that handle floating point and integer arithmetic.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
90 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
91 ; Most routines take a pointer to a value accumulator in X. Some take two pointers with the second in U.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
92 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
93 ; Match operands for a numeric calculation. This works as follows:
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
94 ;
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
95 ; * If both operands are the same, ensure the type is numeric and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
96 ; * If one operand is floating point, convert the other to floating point, as long as it is numeric
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
97 ; * If one or both oeprands are not numeric, raise a type mismatch
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
98 ; The operands are in (X) and (U)
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
99 val_matchtypes ldb val.type,x ; get the type of first argument
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
100 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
101 beq val_matchtypes0 ; brif so
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
102 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
103 beq val_matchtypes1 ; brif so
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
104 TMERROR ldb #err_tm ; raise a type mismatch
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
105 jmp ERROR
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
106 val_matchtypes0 ldb val.type,u ; get type of second operand
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
107 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
108 bne val_matchtypes2 ; brif not
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
109 val_matchtypes3 rts
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
110 val_matchtypes2 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
111 bne TMERROR ; brif not - raise error
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
112 pshs u ; save pointer to second operand
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
113 bsr val_int32tofp ; convert first argument to floating point
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
114 puls u,pc ; restore second operand pointer and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
115 val_matchtypes1 ldb val.type,u ; get second argument type
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
116 cmpb #valtype_float ; is it floating point?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
117 beq val_matchtypes3 ; brif so - we're good
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
118 cmpb #valtype_int ; is it integer?
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
119 bne TMERROR ; brif not - invalid type combination
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
120 pshs x,u ; save value pointers
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
121 leax ,u ; convert (U) to floating point
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
122 bsr val_int32tofp
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
123 puls x,u,pc ; restore argument pointers and return
f4b2406d7352 Add numeric argument matching routine
William Astle <lost@l-w.ca>
parents: 70
diff changeset
124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
125 ; Negate the 32 bit integer (for fp mantissa) at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
126 val_negint32 ldd zero ; subtract integer value from zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
127 subd val.int+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
128 std val.int+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
129 ldd zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
130 sbcb val.int+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
131 sbca val.int,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
132 std val.int,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
133 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
135 ; Convert integer value at (X) to floating point value at (X). Enter at val_uint32tofp to treat the 32 bit value as
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
136 ; unsigned. Otherwise enter at val_int32tofp to treat it as signed.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
137 val_uint32tofp clr val.fpsign,x ; for positive sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
138 bra val_int32tofpp ; go process as positive
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
139 val_int32tofp ldb val.int,x ; get sign to A
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
140 sex
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
141 sta val.fpsign,x ; set sign of result
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
142 bpl val_int32tofpp ; brif positive - don't need to do a two's complement adjustment
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
143 bsr val_negint32 ; negate the integer value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
144 val_int32tofpp ldb valtype_float ; set result to floating point
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
145 stb val.type,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
146 ldb #0xa0 ; exponent to have binary point to the right of the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
147 stb val.fpexp,x ; set the exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
148 clrb ; clear out extra precision bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
149 ; fall through to normalize the value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
151 ; Normalize floating point value at (X); this will shift the mantissa until there is a one in the leftmost
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
152 ; bit of the mantissa. The algorithm is as follows:
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
153 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
154 ; 1. Shift the mantissa left until a 1 bit is found in the high bit of the mantissa.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
155 ; 1a. If more than 40 bits of left shifts occur, determine that the value is zero and return
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
156 ; 2. Adjust exponent based on number of shifts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
157 ; 2a. If new exponent went below -127, then underflow occurred and zero out value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
158 ; 2b. If new exponent went above +127, raise an overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
159 ; 3. If bit 7 of the extra precision byte is clear, return the resulting value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
160 ; 4. Add one to the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
161 ; 5. If a carry in (4) occurred, then set high bit of mantissa and bump exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
162 ; 6. If new exponent carries, then raise overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
163 ; 7. Return result.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
164 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
165 ; Note that if we carried in (4), the only possible result is that the mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
166 ; rolled over to all zeroes so there is no need to shift the entire mantissa right
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
167 ; nor is there any reason to check for additional rounding.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
168 ;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
169 ; The above algorithm has some optimizations in the code sequence below.
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
170 fp_normalize pshs b ; save extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
171 clrb ; set shift counter/exponent adjustment
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
172 fp_normalize0 lda val.fpmant,x ; set flags on high word of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
173 bne fp_normalize2 ; brif we don't have a full byte to shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
174 addb #8 ; account for a while byte of shifts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
175 ldu val.fpmant+1,x ; shift mantissa left 8 bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
176 stu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
177 lda val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
178 sta val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
179 lda ,s ; and include extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
180 sta val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
181 clr ,s ; and blank extra bits
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
182 cmpb #40 ; have we shifted 40 bits?
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
183 blo fp_normalize0 ; brif not - keep shifting
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
184 bra fp_normalize7 ; go zero out the value
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
185 fp_normalize1 incb ; account for one bit of shifting
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
186 lsl ,s ; shift mantissa and extra bits left (will not be more than 7 shifts)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
187 rol val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
188 rol val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
189 rol val.fpmant+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
190 rol val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
191 fp_normalize2 bpl fp_normalize1 ; brif we have to do a bit shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
192 pshs b ; apply exponent counter to exponent
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
193 lda val.fpexp,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
194 suba ,s+
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
195 bls fp_normalize6 ; brif we underflowed to zero
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
196 bcc fp_normalize3 ; brif we did not overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
197 OVERROR2 jmp OVERROR ; raise overflow
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
198 fp_normalize3 lsl ,s+ ; set C if the high bit of extra precision is set
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
199 bcs fp_normalize5 ; brif bit set - we have to do rounding
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
200 fp_normalize4 rts ; return if no rounding
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
201 fp_normalize5 ldu val.fpmant+2,x ; add one to mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
202 leau 1,u
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
203 stu val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
204 bne fp_normalize4 ; brif low word doesn't carry
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
205 ldu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
206 leau 1,u
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
207 stu val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
208 bne fp_normalize4 ; brif high word doesn't carry
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
209 ror val.fpmant,x ; shift right C in to high bit of mantissa (already set to get here)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
210 inc val.fpexp,x ; bump exponent for a right shift
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
211 beq OVERROR2 ; brif it overflows (> +127)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
212 rts ; return result (only possible result was mantissa wrapped to zero)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
213 fp_normalize6 clr val.fpmant,x ; clear mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
214 clr val.fpmant+1,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
215 clr val.fpmant+2,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
216 clr val.fpmant+3,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
217 fp_normalize7 clr val.fpexp,x ; clear exponent and sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
218 clr val.fpsign,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
219 puls b,pc ; clean up stack and return
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
221 ; Addition and subtraction of values; must enter with values of matching types
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
222 ;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
223 ; Calculates (X) + (U) -> (Y) (addition)
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
224 ; Calculates (X) - (U) -> (Y) (subtraction)
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
225 val_add ldb val.type,x ; get type of left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
226 stb val.type,y ; set result type
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
227 cmpb #valtype_float ; is it float?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
228 beq fp_add ; brif so
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
229 ldd val.int+2,x ; do the addition
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
230 addd val.int+2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
231 std val.int+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
232 ldd val.int,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
233 adcb val.int+1,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
234 adca val.int,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
235 std val.int,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
236 lbvs OVERROR ; brif calculation overflowed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
237 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
238 val_sub ldb val.type,x ; get type of left operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
239 stb val.type,y ; set result type
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
240 cmpb #valtype_float ; floating point?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
241 beq fp_sub ; brif so
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
242 ldd val.int+2,x ; do the subtraction
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
243 subd val.int+2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
244 std val.int+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
245 ldd val.int,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
246 sbcb val.int+1,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
247 sbca val.int,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
248 std val.int,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
249 lbvs OVERROR ; brif overflow
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
250 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
252 ; FP subtraction: just invert the sign of the second operand and add; operands must be writable and they should be
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
253 ; considered to be clobbered
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
254 fp_sub com val.fpsign,u ; negate right operand
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
255 ; fall through to addition
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
256 ; FP addition: this requires that *both operands* are writable and they may be clobbered
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
257 fp_add ldb val.fpexp,u ; is the second operand zero?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
258 beq fp_add0 ; brif so - it's a no-op - copy the left operand to the output
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
259 lda val.fpexp,x ; is left operand zero?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
260 bne fp_add1 ; brif not - we have to do the add
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
261 leau ,x ; copy the right operand to the output
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
262 fp_add0 ldd ,u ; copy the value across
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
263 std ,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
264 ldd 2,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
265 std 2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
266 ldd 4,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
267 std 4,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
268 rts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
269 fp_add1 subb val.fpexp,x ; get difference in exponents
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
270 beq fp_add6 ; brif they're the same - no denormalizing is needed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
271 bhi fp_add2 ; brif second one is bigger, need to right-shift the mantissa of first
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
272 exg x,u ; swap the operands (we can do that for addition)l second is now biggest
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
273 negb ; invert the shift count
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
274 fp_add2 cmpb #32 ; are we shifting more than 32 bits?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
275 blo fp_add0 ; brif so - we're effectively adding zero so bail out
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
276 fp_add3 cmpb #8 ; have 8 bits to move?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
277 bhs fp_add5 ; brif not
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
278 lda val.fpmant+2,x ; shift 8 bits right
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
279 sta val.fpmant+3,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
280 lda val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
281 sta val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
282 lda val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
283 sta val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
284 clr val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
285 subb #8 ; account for 8 shifts
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
286 bra fp_add3 ; see if we have a whole byte to shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
287 fp_add4 lsr val.fpmant,x ; shift right one bit
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
288 ror val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
289 ror val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
290 ror val.fpmant+3,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
291 fp_add5 decb ; done all shifts?
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
292 bmi fp_add4 ; brif not - do a shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
293 fp_add6 ldb val.fpexp,u ; set exponent of result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
294 stb val.fpexp,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
295 ldb val.fpsign,u ; fetch sign of larger value
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
296 stb val.fpsign,y ; set result sign
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
297 cmpb val.fpsign,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
298 bne fp_add8 ; brif not - need to subtract the operands
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
299 ldd val.fpmant+2,u ; add the mantissas
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
300 addd val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
301 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
302 ldd val.fpmant,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
303 adcb val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
304 adca val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
305 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
306 clrb ; clear extra precision bits
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
307 bcc fp_add7 ; brif no carry
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
308 ror val.fpmant,y ; shift carry into mantissa
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
309 ror val.fpmant+1,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
310 ror val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
311 ror val.fpmant+3,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
312 rorb ; keep bits for founding
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
313 inc val.fpexp,y ; bump exponent to account for shift
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
314 lbeq OVERROR ; brif it overflowed
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
315 fp_add7 leax ,y ; point to result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
316 jmp fp_normalize ; go normalize the result
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
317 fp_add8 ldd val.fpmant+2,u ; subtract operands
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
318 subd val.fpmant+2,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
319 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
320 ldd val.fpmant,u
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
321 sbcb val.fpmant+1,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
322 sbca val.fpmant,x
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
323 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
324 bcc fp_add7 ; brif we didn't carry - no need to fix up
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
325 ldd zero ; negate the mantissa bits since we use sign+magnitude
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
326 subd val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
327 std val.fpmant+2,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
328 ldd zero
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
329 sbcb val.fpmant+1,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
330 sbca val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
331 std val.fpmant,y
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
332 neg val.fpsign,y ; invert sign of result since we went past zero
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
333 clrb ; clear extra precision bits
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
334 bra fp_add7 ; go normalize the result and return
f492fa6f6dc8 First pass implementation of addition and subtraction
William Astle <lost@l-w.ca>
parents: 71
diff changeset
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
336 ; Pack a floating point value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
337 fp_packval ldb val.fpsign,x ; get sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
338 bmi fp_packval ; brif negative - the default 1 bit will do
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
339 ldb val.fpmant,x ; clear high bit of mantissa for positive
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
340 andb #0x7f
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
341 stb val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
342 fp_packval0 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
344 ; Unpack a floating point value at (X)
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
345 fp_unpackval0 ldb val.fpmant,x ; get high byte of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
346 sex ; now A is value for sign byte
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
347 sta val.fpsign,x ; set sign
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
348 orb #0x80 ; set high bit of mantissa
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
349 stb val.fpmant,x
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
350 rts
eb7c96671f5b Add some infrastructure for value handling
William Astle <lost@l-w.ca>
parents: 69
diff changeset
351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
352 ; The LIST command.
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
353 ;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
354 ; Syntax:
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
355 ; LIST
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
356 ; LIST <line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
357 ; LIST <line>-
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
358 ; LIST -<line>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
359 ; LIST <start>-<end>
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
360 cmd_list bne cmd_list1 ; brif we have arguments
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
361 ldx progtext ; point to start of program
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
362 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
363 std binval
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
364 bra cmd_list2 ; go do the listing
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
365 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
366 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
367 jsr curchar ; are we at the end of the command?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
368 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
369 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
370 jsr syncheckb
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
371 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
372 jsr parse_lineno ; parse ending of range
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
373 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
374 bne cmd_list4 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
375 cmd_list3 rts
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
376 cmd_list4 ldd 2,x ; get line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
377 cmpd binval ; have we reached the end of the range?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
378 bhi cmd_list3 ; brif so - we're done
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
379 jsr print_uint16d ; print out line number
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
380 lda #0x20 ; and a space
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
381 jsr writechr
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
382 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
383 leax 4,x ; move past line header
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
384 bsr detokenize ; detokenize line to current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
385 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
386 ; need to add a break check here
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
387 bra cmd_list2 ; go handle another line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
389 ; Detokenize a line to the current output stream
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
390 detokenize lda ,x+ ; get character from tokenized line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
391 bmi detokenize1 ; brif it's a keyword token
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
392 lbeq writecondnl ; do a newline if needed and return
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
393 cmpa #': ; is it a colon?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
394 bne detokenize0 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
395 ldb ,x ; fetch subsequent character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
396 cmpb #tok_apos ; apostrophe version of REM?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
397 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
398 cmpb #tok_else ; ELSE?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
399 beq detokenize ; brif so - skip the colon
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
400 detokenize0 jsr writechr ; output it unmolested
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
401 bra detokenize ; go handle another character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
402 detokenize1 ldu #primarydict ; point to primary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
403 cmpa #0xff ; is it a secondary token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
404 bne detokenize3 ; brif not
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
405 ldu #secondarydict ; point to secondary dictionary table
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
406 lda ,x+ ; get secondary token value
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
407 bne detokenize3 ; brif not end of line
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
408 leax -1,x ; don't consume the NUL
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
409 detokenize2 lda #'! ; invalid token flag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
410 bra detokenize0 ; output it and continue
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
411 detokenize3 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
412 beq detokenize6 ; brif already at the right place
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
413 detokenize4 ldb ,u ; end of dictionary table?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
414 beq detokenize2 ; brif so - show invalid tokenf lag
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
415 detokenize5 ldb ,u+ ; fetch character in this keyboard
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
416 bpl detokenize5 ; brif not end of keyword (high bit set)
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
417 deca ; at the right token?
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
418 bne detokenize4 ; brif not - skip another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
419 detokenize6 lda ,u+ ; get keyword character
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
420 bmi detokenize7 ; brif end of keyword
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
421 jsr writechr ; output it
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
422 bra detokenize6 ; go fetch another
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
423 detokenize7 anda #0x7f ; lose the high bit
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
424 bra detokenize0 ; write it and move on with the input
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
426 ; 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
427 makecanontab fcb tok_less,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
428 fcb tok_greater,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
429 fcb tok_equal,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
430 fcb tok_greater,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
431 fcb tok_less,tok_notequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
432 fcb tok_equal,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
433 fcb tok_equal,2
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
434 fcb tok_greater,tok_greaterequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
435 fcb tok_less,tok_lessequal
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
436 fcb 0
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
437 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
438 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
439 sta ,y+ ; save in output
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
440 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
441 rts
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
442 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
443 cmpa #0xff ; is it secondary?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
444 bne makecanon2 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
445 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
446 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
447 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
448 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
449 beq makecanon4 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
450 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
451 lslb ; 2 bytes per
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
452 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
453 ldb ,u ; end of table?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
454 bne makecanon3 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
455 bra makecanon0 ; no substitutions found
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
456 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
457 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
458 cmpa #0x20 ; is it space?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
459 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
460 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
461 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
462 beq makecanon7 ; brif so
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
463 decb ; seen all of them?
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
464 bne makecanon6 ; brif not
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
465 puls x ; restore input pointer
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
466 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
467 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
468 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
469 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
470 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
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
472 ; Tokenize line to tokebuff
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
473 ;
27
5db76d113c37 Change register usage for tokenization and use input ptr in immediate loop
William Astle <lost@l-w.ca>
parents: 26
diff changeset
474 ; 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
475 ; 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
476 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
477 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
478 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
479 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
480 tokenize0 lda ,x+ ; get input character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
481 bne tokenize3 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
482 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
483 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
484 bsr makecanon ; canonicalize certain sequences
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
485 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
486 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
487 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
488 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
489 beq tokenize6 ; brif not
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
490 jsr setcifalpha ; is it alpha
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
491 bcs tokenize4 ; brif so - store it and continue
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
492 jsr setcifdigit ; is it numeric?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
493 bcc tokenize5 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
494 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
495 bra tokenize0 ; check for another
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
496 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
497 tokenize6 cmpa #'" ; is it a string?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
498 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
499 sta ,y+ ; save string delimiter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
500 tokenize7 lda ,x+ ; get input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
501 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
502 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
503 cmpa #'" ; end of string?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
504 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
505 bra tokenize0 ; brif
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
506 tokenize8 cmpa #': ; end of statement?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
507 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
508 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
509 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
510 tokenize9 cmpa #0x20 ; is it a space?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
511 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
512 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
513 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
514 cmpa #'? ; PRINT shortcut?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
515 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
516 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
517 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
518 tokenize10 cmpa #'' ; ' shortcut for remark?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
519 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
520 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
521 std ,y++ ; stash it
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
522 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
523 sta ,y+ ; stash in output
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
524 bne tokenize11 ; brif not end of input
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
525 bra tokenize2 ; go finish up
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
526 tokenize12 jsr setcifdigit ; is it a digit?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
527 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
528 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
529 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
530 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
531 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
532 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
533 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
534 clr tok_kwmatch+1
bdd4b9f30916 Convert tokenize routine to do a first longest match
William Astle <lost@l-w.ca>
parents: 52
diff changeset
535 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
536 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
537 tokenize13 clr tok_kwnum ; clear keyword number
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
538 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
539 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
540 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
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 tsta ; is it a primary?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
549 beq tokenize24 ; brif so
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
550 bra tokenize23 ; go stash two byte token
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
551 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
552 lda ,x+ ; get character
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
553 bra tokenize4 ; stash it and continue
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
554 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
555 clra ; initalize match length counter
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
556 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
557 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
558 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
559 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
560 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
561 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
562 subb #0x20 ; convert to upper case
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
563 tokenize18 subb ,u+ ; does it match?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
564 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
565 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
566 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
567 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
568 tokenize19 ldb ,u+ ; end of token?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
569 bpl tokenize19 ; brif not
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
570 tokenize20 inc tok_kwnum ; bump token counter
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
571 bra tokenize14 ; go check another one
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
572 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
573 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
574 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
575 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
576 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
577 std tok_kwmatch ; save matched token
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
578 bra tokenize20 ; keep looking through the tables
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
579 tokenize22 lda #': ; for putting implied colons in
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
580 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
581 jmp tokenize0 ; go handle more input
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
582 tokenize24 cmpb #tok_else ; is it ELSE?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
583 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
584 cmpb #tok_data ; is it DATA?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
585 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
586 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
587 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
588 jmp tokenize0 ; go handle more
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
589 tokenize26 cmpb #tok_rem ; is it REM?
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
590 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
591 cmpb #tok_apos ; apostrophe REM?
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
592 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
593 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
594 sta ,y+
56
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
595 bra tokenize28
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
596 tokenize27 ldb ,x+ ; fetch next input character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
597 tokenize28 stb ,y+ ; stash the character
f741bb544a04 Clean up labels in tokenization routine
William Astle <lost@l-w.ca>
parents: 55
diff changeset
598 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
599 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
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
601 ; Special tokenization handling
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
603 ; 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
604 ; 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
605 ;
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
606 ; defcmd string,symbase
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
607 ; deffunc string,symbase,flags
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
608 ; cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
609 ; functab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
610 ; cmdjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
611 ; funcjump
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
612 ; 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
613 ; 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
614 *pragmapush list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
615 *pragma nolist
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
616 __cmdnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
617 __funcnum set 0x80
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
618 defcmd macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
619 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
620 ifstr ne,"{3}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
621 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
622 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
623 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
624 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
625 tok_{2} equ __cmdnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
626 __cmdnum set __cmdnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
627 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
628 deffunc macro noexpand
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
629 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
630 ifstr ne,"{4}",""
f5966048a796 Modify defcmd and deffunc to allow specifying explicit entry point
William Astle <lost@l-w.ca>
parents: 48
diff changeset
631 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
632 else
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
633 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
634 endc
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
635 tok_{2} equ __funcnum
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
636 __funcnum set __funcnum+1
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
637 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
638 cmdtab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
639 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
640 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
641 includestr "%(__cmdtab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
642 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
643 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
644 endm
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
645 functab macro
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
646 *pragmapush list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
647 *pragma nolist
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
648 includestr "%(__functab)"
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
649 *pragmapop list
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
650 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
651 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
652 cmdjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
653 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
654 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
655 includestr "%(__cmdjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
656 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
657 endm
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
658 funcjump macro
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
659 *pragmapush nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
660 *pragma nolist
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
661 includestr "%(__funcjump)"
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
662 *pragmapop list
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
663 endm
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
664 *pragmapop list
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
665 defcmd 'REM',rem
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
666 defcmd /'/,apos
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
667 defcmd 'DATA',data
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
668 defcmd 'ELSE',else
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
669 defcmd 'END',end
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
670 defcmd 'STOP',stop
34
7111bc587420 Enable default LET command with stub handler
William Astle <lost@l-w.ca>
parents: 33
diff changeset
671 defcmd 'LET',let
41
090db8c5d509 Add NEW command and string stack
William Astle <lost@l-w.ca>
parents: 40
diff changeset
672 defcmd 'NEW',new
45
952bfb5c76fb Add PRINT stub routine and make tokenization handle ? shortcut
William Astle <lost@l-w.ca>
parents: 44
diff changeset
673 defcmd 'PRINT',print
50
aecea4c62324 Add LIST command
William Astle <lost@l-w.ca>
parents: 49
diff changeset
674 defcmd 'LIST',list
59
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
675 defcmd 'RUN',run
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
676 defcmd 'GOTO',goto
9bed204d99b9 Add RUN and GOTO; also IN XXXX for errors
William Astle <lost@l-w.ca>
parents: 58
diff changeset
677 defcmd 'GOSUB',gosub
62
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
678 defcmd 'RETURN',return
eba95ed43423 Add GOSUB/RETURN/POP
William Astle <lost@l-w.ca>
parents: 61
diff changeset
679 defcmd 'POP',pop
63
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
680 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
681 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
682 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
683 defcmd '/',divide,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
684 defcmd '^',power,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
685 defcmd '<',less,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
686 defcmd '>',greater,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
687 defcmd '=',equal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
688 defcmd '<=',lessequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
689 defcmd '>=',greaterequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
690 defcmd '<>',notequal,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
691 defcmd 'AND',and,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
692 defcmd 'OR',or,SNERROR
a3122251b5fe Add initial expression evaluator and some supporting details
William Astle <lost@l-w.ca>
parents: 62
diff changeset
693 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
694 primarydict cmdtab
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
695 secondarydict functab
29
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
696 primaryjump cmdjump
455cdf81b33a Command interpreation loop, END, STOP, DATA, ', REM, ELSE
William Astle <lost@l-w.ca>
parents: 27
diff changeset
697 secondaryjump funcjump
26
001b9ab63731 Add tokenization, keyword lists, and some interpretation loop bits
William Astle <lost@l-w.ca>
parents: 25
diff changeset
698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
19eac734a518 Makefile to actually build something with initial start to ROM init code
William Astle <lost@l-w.ca>
parents:
diff changeset
699 ; 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
700 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
701 fdb SW3VEC ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
702 fdb SW2VEC ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
703 fdb FRQVEC ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
704 fdb IRQVEC ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
705 fdb SWIVEC ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
706 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
707 fdb START ; RESET vector (ROM entry point)
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
708 endc
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
709 ifdef COCO3
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
710 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
711 fdb INT.SWI3 ; SWI3 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
712 fdb INT.SWI2 ; SWI2 vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
713 fdb INT.FIRQ ; FIRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
714 fdb INT.IRQ ; IRQ vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
715 fdb INT.SWI ; SWI vector
80c18925436d More Coco3 specific initialization and interrupt vectors
William Astle <lost@l-w.ca>
parents: 4
diff changeset
716 fdb INT.NMI ; NMI vector
4
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
717 fdb START ; RESET vector (ROM entry point)
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
718 else
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
719 zmb 0x10000-* ; pad ROM to full size
2b6e6b827bd7 Additional Coco 3 build adjustments
William Astle <lost@l-w.ca>
parents: 3
diff changeset
720 endc