-
Notifications
You must be signed in to change notification settings - Fork 85
/
numsyms
221 lines (192 loc) · 3.31 KB
/
numsyms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
.PAGE 'NUMSYMS'
; CONVERT BASE 8,10,16 TO BINARY
; CARRY SET IF SUCCESSFUL CONVERSION, CARRY CLEAR IF ERROR.
; X MUST POINT TO CHARACTER
NUMBER LDA #0
STA KNVAL ;VALUE OF NUMBER IS 0
STA KNVAL+1
E10 LDA ICRD,X ;CHARACTER
JSR NUMRC ;SEE IF NUMERIC
BCC E20 ;NOT NUMERIC
SBC #48 ;REMOVE ZONE
JMP E30 ;CHECK FOR VALID BASE
E20 JSR NALPH ;CHAR ALPHABETIC
BCC E40 ;NO...MEANS ERROR
SBC #55 ;ALPHA--REMOVE ZONE
E30 CMP KBASE ;BASE VALID
BCC E50 ;YES...VALID
E40 CLC ;INVALID BASE
RTS
E50 STA COLCNT
TXA
PHA ;PUT POINTER ON STACK
LDY KBASE ;BASE
CPY #2 ;BINARY?
BNE E60 ;NO...
LDX #1 ;BINARY...1 SHIFT
BNE E90
E60 CPY #8 ;OCTAL
BNE E70 ;NO...
LDX #3 ;OCTAL--3 SHIFTS.
BNE E90
E70 CPY #16 ;HEX
BNE E80 ;NO...
LDX #4 ;HEX--4 SHIFTS
BNE E90
E80 CPY #10 ;DECIMAL
BNE E40 ;NO... BASE IS INVALID
LDA KNVAL
STA TEMP
LDA KNVAL+1
STA TEMP+1
LDX #3 ;DECIMAL--3 + 1 SHIFTS
E90 ASL KNVAL+1 ;LOW ORDER BITS
ROL KNVAL ;HIGH ORDER BITS
BCC E100 ;NOT OVERFLOW
LDA IFLAGS+1 ;OVERFLOW BIT
ORA #8
STA IFLAGS+1
E100 DEX ;SHIFT COUNTER
BNE E90 ;CONTINUE
CPY #10 ;DECIMAL
BNE E120 ;NO...
ASL TEMP+1 ;DECIMAL DOES ANOTHER
ROL TEMP
BCC E115 ;DID NOT OVERFLOW
LDA IFLAGS+1 ;SET OVERFLOW
ORA #8
STA IFLAGS+1
E115 LDA KNVAL+1 ;ADD TO FINISH
CLC
ADC TEMP+1
STA KNVAL+1
LDA KNVAL
ADC TEMP
STA KNVAL
BCC E120 ;OVERFLOW?
LDA IFLAGS+1
ORA #8
STA IFLAGS+1
E120 LDA COLCNT
CLC
ADC KNVAL+1
STA KNVAL+1
BCC E130
INC KNVAL
BNE E130 ;NO OVERFLOW
LDA IFLAGS+1
ORA #8
STA IFLAGS+1
E130 PLA
TAX
INX
DEC KLEN ;LENGTH OF NUMBER
BEQ E140 ;DONE
JMP E10
E140 SEC ;SUCCESS
RTS
; SEARCH SYM TAB FOR CURRENT SYM. SEARCH IS LINEAR.
; CARRY SET IF FOUND. CARRY CLEAR IF NOT FOUND.
NFIND
L13C7 LDA STSAVE
STA SYMTBL
LDA STSAVE+1
STA SYMTBL+1
LDA #0
STA TOPPNT+1
STA TOPPNT
L13D5 SEC
LDA TOPPNT+1
SBC NOSYM+1
LDA TOPPNT
SBC NOSYM
BCS L13FC
LDY #5
L13E4 LDA ISYM,Y
CMP (SYMTBL),Y
BNE L13FE
DEY
BPL L13E4
LDY #6
LDA (SYMTBL),Y
STA KNVAL
INY
LDA (SYMTBL),Y
STA KNVAL+1
RTS
L13FC CLC
RTS
L13FE LDA SYMTBL
CLC
ADC #8
STA SYMTBL
BCC L1409
INC SYMTBL+1
L1409 INC TOPPNT+1
BNE L13D5
INC TOPPNT
JMP L13D5
NSERT SEC
LDA SYMTBL
SBC ISYEND
LDA SYMTBL+1
SBC ISYEND+1
BCS G110
XXXD2 LDY #5 ;PUT SYM INTO TABLE
G100 LDA ISYM,Y ;SOURCE
STA (SYMTBL),Y ;DESTINATION
DEY
BPL G100 ;NOT DONE
;
; SYMBOL IS IN TABLE- DEFINE
;
LDY #6
LDA KNVAL
STA (SYMTBL),Y
INY
LDA KNVAL+1
STA (SYMTBL),Y
INC NOSYM+1
BNE G101
INC NOSYM
G101 RTS
;
; OVERFLOWED SYMBOL TABLE
;
G110 LDA #>STOERR
LDY #<STOERR
JSR WSCRN
JMP DONE
; SEARCH OPCODE TAB FOR OPCODE
; CARRY SET IF OPCODE FOUND, CARRY CLEAR IF OPCODE NOT FOUND.
NOPFND LDA #<OPRNDS
STA PNT1
LDA #>OPRNDS
STA PNT1+1
LDX #0
XXXE3 LDY #2
XXXE2 LDA ISYM,Y
CMP (PNT1),Y
BNE XXXE1
DEY
BPL XXXE2
LDA KTMPL,X ;TEMPLATE
STA JOPTEM
LDA KCODE,X ;BASE OPCODE
STA JOPBAS
RTS
;
; NO MATCH
;
XXXE1 LDA PNT1
CLC
ADC #3
STA PNT1
BCC XXXE4
INC PNT1+1
XXXE4 INX
CPX #57
BMI XXXE3
SBNO CLC ;OPCODE NOT FOUND
RTS
.END