-
Notifications
You must be signed in to change notification settings - Fork 84
/
numsyms
338 lines (293 loc) · 5.6 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
.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.
; TOPS POINTS TO INSERT ADR FOR NEW SYMBOL.
NFIND LDA STSAVE ;COPY START SYMS' ADR
STA BOTS
LDA STSAVE+1
STA BOTS+1
LDA NOSYM ;CALC TOP FROM SYMS' #
STA TOPS+1
LDA NOSYM+1
ASL A ;TIMES 8
ROL TOPS+1
ASL A
ROL TOPS+1
ASL A
ROL TOPS+1
CLC ;ADD DELTA TO BEGINNING
ADC BOTS
STA TOPS
STA ITOPS
LDA TOPS+1
ADC BOTS+1
STA TOPS+1
STA ITOPS+1
G10 SEC ;CALC DELTA = TOPS-BOTS
LDA TOPS
SBC BOTS
STA DELS
LDA TOPS+1
SBC BOTS+1
BCS GGG10 ;ALWAYS I HOPE !
BRK ;<<<<<<<<<< ERROR <<<<<<<<<<
GGG10 LSR A ;DIVIDE BY 2
STA DELS+1
LDA DELS
ROR A
AND #$F8 ;MOD 8
STA DELS
CLC ;CALC MIDS=BOTS+DELS/2
LDA BOTS
ADC DELS
STA MIDS
LDA BOTS+1
ADC DELS+1
STA MIDS+1
LDY #$FF ;SO WE START AT ZERO
G30 INY
CPY #6 ;A MATCH ON SYM
BEQ SMTCH ;YES
LDA (MIDS),Y ;CMP ANOTHER CHAR
CMP ISYM,Y
BEQ G30 ;EQUAL CHECK NEXT COLUMN
LDA DELS ;NO MORE IN TOP & BOT ?
ORA DELS+1
BEQ NOMTCH ;YES - NO MATCH
LDA MIDS
LDY MIDS+1
BCC SGREAT ;SYM GREATER THAN
SLESS STA TOPS ;SYM LESS THAN
STY TOPS+1
BNE G10 ;ALWAYS
SGREAT STA BOTS ;SYM GREATER THAN
STY BOTS+1
BNE G10 ;ALWAYS
NOMTCH BCC FNRTS ;EXIT
LDA BOTS ;LOWEST LABEL
LDY BOTS+1 ;MOVE TOPS TO BOTS
STA TOPS
STY TOPS+1
CLC
FNRTS RTS
SMTCH LDA (MIDS),Y ;COPY VALUE
STA KNVAL
INY
LDA (MIDS),Y
STA KNVAL+1
LDA PASS ;ON PASS TWO ?
BEQ XRF300 ;NO
LDA XREF ;DOING A CROSS REF ?
BEQ XRF300 ;NO
SEC ;GET SYM #
LDA MIDS ;ACTUAL ADR
SBC STSAVE ;SUBTRACT BASE
STA DELS
LDA MIDS+1
SBC STSAVE+1
LSR A ;DIVIDE BY 8
ROR DELS
LSR A
ROR DELS
LSR A
ROR DELS
STA DELS+1
LDX #9 ;IS OUR CHANNEL OPEN ?
CPX CHAN
BEQ XRF120 ;YES
JSR CLRCH ;CLEAR LAST
LDX #9
STX CHAN
JSR CKOUT ;OPEN IT
XRF120 LDA DELS ;SEND LABEL #
JSR BSOUT
LDA DELS+1
JSR BSOUT
LDA ICRDNO+1 ;SEND CARD #
JSR BSOUT
LDA ICRDNO
JSR BSOUT
XRF300 SEC ;FLAG A FIND
RTS
; **********************************
; * ENTER NEW SYMBOL INTO SYM TAB
; * (SYMTBL)-NEXT AVAILABLE LOCATION
; * IN THE SYMBOL TABLE.
; * .X CONTAINS OFFSET
; * FOR SYMBOL INFORMATION STORAGE.
; **********************************
NSERT CLC ;CALC NEW TOP FROM SYMS
LDA ITOPS ;TOPS FROM NFIND
ADC #8 ;MOVE UP BY 8
STA DELS
LDA ITOPS+1
ADC #0
STA DELS+1
LDY #7 ;FOR INDIRECTS
SEC
LDA DELS ;OUT OF ROOM ?
SBC ISYEND
LDA DELS+1
SBC ISYEND+1
BCS G110 ;YES
XXXD5 LDA TOPS+1
CMP DELS+1
BNE XXXD1
LDA TOPS
CMP DELS
BEQ XXXD2
XXXD1 LDA (ITOPS),Y ;MOVE A SYMBOL
STA (DELS),Y
LDA ITOPS
BNE XXXD3
DEC ITOPS+1
XXXD3 DEC ITOPS
LDA DELS
BNE XXXD4
DEC DELS+1
XXXD4 DEC DELS
JMP XXXD5
XXXD2 LDY #5 ;PUT SYM INTO TABLE
G100 LDA ISYM,Y ;SOURCE
STA (TOPS),Y ;DESTINATION
DEY
BPL G100 ;NOT DONE
;
; SYMBOL IS IN TABLE- DEFINE
;
LDY #6
LDA KNVAL
STA (TOPS),Y
INY
LDA KNVAL+1
STA (TOPS),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