-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathoperand
616 lines (478 loc) · 12 KB
/
operand
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
.PAGE 'OPERAND'
; OPERAND PROCESSING *****
; PROCESSES NORMAL OPERANDS & DETERMINES IF THEY ARE VALID.
H201 LDY #0
STY JOPTYP ;OPERAND TYPE
STY JOPLEN ;BYTES TO GENERATE
STY JNOPV ;OPERAND VALUE FLAG
; CHECK FOR IMPLIED OPERAND
LDA JOPTEM ;OPCODE TEMPLATE
CMP #20 ;IMPLIED OPERAND
BNE H17 ;SKIP TO NEXT SECT
; GENERATE OPCODE FOR IMPLIED AND ACCUMULATOR MODES
H459 LDY #0 ;INSERT IN OP POSIT
LDA JOPBAS ;OP IS BASE OPCODE
JSR OBJOUT ;PUT IN MEMORY MAP
LDX #0 ;GET ERROR COL
LDY #1 ;NUM OF BYTES
TXA
JMP LTS1
; NEED OPERAND - CHECK BRANCH FIRST
H17 CMP #21 ;BRANCH TEMPLATE
BNE H9960 ;NO
LDA #14
STA JOPTEM
LDA #7 ;ERROR CODE
STA IERR
H9960 LDA ICSE ;PNTR TO LAST CHAR
STA ICOLP
INC ICOLP ;NEXT CHAR
JSR NFNDNB ;FIND START OF OPERND
BCS H9917
LDA #$18
STA IERR
JMP H99 ;ERROR--NO OPERAND
; PROCESS OPERAND FIELD
H9917 LDA ICRD,X ;FIRST CHAR
CMP #';' ;SEE IF COMMENT FIELD
BNE H9934
JMP H900 ;ERROR-NO OPERAND
; AN OPERAND-CHECK .A MODE FIRST
H9934 CMP #'A'
BNE H39 ;NOT ACCUMULATOR MODE
CPX IMAXCL ;SEE IF OFF END
BEQ H9965
LDY ICRD+1,X ;AFTER THE 'A'
CPY #' ' ;MUST BE BLANK
BNE H39 ;NOT .A MODE
H9965 LDY JOPTEM ;.A MODE - PROCESS
LDA KLTBL-1,Y
BMI H458 ;.A MODE NOT VALID
CLC
ADC JOPBAS ;COMPUTE REAL OPCODE
STA JOPBAS
JMP H459 ;DONE WITH THIS OPCODE
; .A MODE NOT ALLOWED- ERROR
H458 LDX ICSB ;ERROR COLUMN
LDY #3 ;NUMBER OF BYTES TO SAVE
LDA #5 ;ERROR CODE
JMP LTS1
H39 CMP #'#' ;CHECK FOR IMMEDIATE MODE
BNE H24 ;NOT IMMEDIATE
LDA #10 ;OPCODE TYPE
JMP H831
H24 CMP #'(' ;CHECK FOR INDIRECT MODE
BNE H23 ;NOT INDIRECT
LDA #5 ;SET OPTYPE
; DONE CHECKING OBVIOUS ADDR MODES. GET READY TO EVALUATE OPERAND.
H831 STA JOPTYP
INX
INC ICSB
CPX IMAXCL ;RAN OFF END CARD?
BEQ H23 ;NO
BCC H23
JMP H99 ;RAN OFF END
H23 JSR EVAL ;EVAL THE OPERAND
STX JERCOL ;ERROR COL FROM EVAL
LDA #$13 ;BAD EXPRESSION
STA IERR ;PRELOAD FOR LATER
DEC RETURN ;0,1 OR 2 FROM EVAL
BMI H20 ;GOOD RETURN (0)
BEQ H202 ;UNDEFINED SYMBOL (1)
;UNINTERP EXPR (2)
LDA JOPTYP ;MIGHT BE SINGLE ASCII IN #
CMP #10 ;SEE IF # MODE
BEQ H9935 ;YES
JMP H995 ;NO--(BAD EXPRESSION)
; IMMIDIATE ASCII OPERATION
H9935 LDA ICRD,X
CMP #$27 ;APPOSTROPHE
BEQ H9936
JMP H980 ;ERROR
H9936 TXA
TAY
INX
CPX IMAXCL ;OFF END OF CARD?
BEQ H457 ;NO
BCC H457
JMP H99 ;YES--ERROR
H457 LDA ICRD,X
CMP #$20
BCC XXXF1
CMP #$60
BCC XXXF2
XXXF1 LDA #0
XXXF2 STA IEXP+1
INX
CPX IMAXCL ;OFF END OF CARD?
BEQ H9923 ;NO
BCS H20 ;YES-FINISH PROCESS
H9923 LDA ICRD,X
CMP #$20 ;MUST BE BLANK
BEQ H20 ;OK
CMP #$27 ;APPOSTROPHE
BEQ H20 ;YES--VALID OPERAND
TYA ;ASCII STRING INVALID
TAX
LDY #3 ;NUMBER OF BYTES
LDA IERR ;ERROR CODE
JMP LTS1
.PAGE
; 1 - OPERAND HAS NO VALUE
H202 INC JNOPV ;NO OPERAND VAL
LDA #2 ;ASSUMED LENGTH
STA JOPLEN ;OPERAND LENGTH
; 0 - GOOD RETURN. INDEX REGISTER CHECK.
H20 JSR NFNCMP ;COMMA OR PAREN
BCC H500 ;NO INDEXING
LDA ICRD,X ;GET CHARACTER
CMP #')'
BNE H51 ;NO
INC JOPTYP ;RIGHT PAREN - ADD TO OPTYPE
INC JOPTYP
LDA JOPBAS ;JUMP INSTR. TEST
CMP #$4C ;JUMP INSTR
BEQ H140 ;YES
; DONE WITH PAREN - NEXT CHAR
INX ;POINT TO NEXT
CPX IMAXCL ;RAN OFF END
BEQ H51 ;NO
BCC H51
JMP H99 ;YES - FLAG AS ERROR
H51 LDA ICRD,X ;CHECK FOR COMMA - INDEXING
CMP #','
BNE H203 ;NO - COULD BE Y
; HAS A COMMA. CHECK FOR JUMP AGAIN.
LDA JOPBAS ;BASE OPCODE
CMP #$4C ;A JUMP
BEQ H142 ;YES-ERROR-NOT ALLOWED
; DONE WITH COMMA - LOOK FOR INDEX.
INX ;POINT TO NEXT CHARACTER
CPX IMAXCL ;OFF END OF CARD?
BEQ H203 ;NO
BCC H203
JMP H99 ;YES - FLAG AS ERROR
H203 LDA ICRD,X ;CHECK FOR INDEX REGISTER X
CMP #'X'
BNE H25 ;NO
INC JOPTYP ;AN X-ADD 1 TO OPTYPE
JMP H40
H25 CMP #'Y' ;CHECK FOR INDEX REG Y
BEQ H27 ;YES
LDY #3 ;INVALID INDEX REG - FLAG
LDA #$12 ;ERROR CODE
JMP LTS1
H27 INC JOPTYP ;INDEX REG Y-ADD 2 TO OPTYPE
INC JOPTYP
BNE H40
H500 LDA JOPBAS ;IF A JUMP INSTRUCTION CHECK
CMP #$4C
BNE H40 ;NOT A JUMP
; A JUMP-SEE IF OPTYPE IS VALID
; ONLY 2 TYPE OPERANDS ALLOWED: TYPE 0 IS ABS, 7 IS IND
H140 LDA JOPTYP
BEQ H145 ;TYPE 0...O.K.
CMP #7
BEQ H501 ;TYPE 7...O.K.
; INVALID OPER FOR JMP - FLAG
H142 LDA #$18 ;ERROR CODE
STA IERR
JMP H980 ;PUT IN LENGTH TAB
H501 INX ;GOOD OPTYPE- MAKE SURE NO MORE
CPX IMAXCL ;OFF END OF CARD?
BMI H9924 ;NO
BCS H145 ;YES
H9924 LDA ICRD,X
CMP #' '
BNE H142 ;NO-BAD JUMP
H145 LDA JOPTYP ;GOOD JUMP-INCR TO BASE OPCODE
BNE H9925 ;OPTYPE IS A 7
JMP H9926 ;FINISH JUMP
H9925 LDA #32 ;TYPE 7-ADD TO BASE
; END OF JUMP PROCESSING
H9926 LDY #2 ;LENGTH OF OPERAND
STY JOPLEN
JMP H46 ;FINISH LINE PROCESS
; OPERAND PROCESSED. SEE IF OPERAND VALID FOR OPCODE.
H40 LDA JNOPV ;OPERAND VALUE?
BEQ *+5
JMP H41 ;NO-ASSUME EXTENDED
; HAVE OPERAND VALUE - CHECK REL
LDA JOPTEM ;OPCODE TEMPLATE
CMP #14 ;RELATIVE ADDRESS
BNE H22 ;NOT RELATIVE
CLC ;RELATIVE ADR- CHK VALIDITY. ADJUST EXPR TO GET REL ADR
LDA IPC
ADC #2
STA TEMP+1
LDA IPC+1
ADC #0
STA TEMP
LDA IEXP+1 ;LOW BYTE OF EXPR
SEC
SBC TEMP+1
STA IEXP+1
TAY ;FOR LATER
LDA IEXP ;HIGH BYTE OF EXPR
SBC TEMP
STA IEXP
; TEST EXPR FOR BRANCH TOO FAR
; IF SIGN BITS SAME THEN O.K.
; LOW BYTE IEXP TESTED.
; BRANCH ATTEMPTED TO GO TOO FAR
BPL H9927 ;HIGH BYTE +
TYA ;HIGH BYTE NEG CHECK LO BYT
BMI H28 ;BOTH NEG-EXPR OK
BPL H9929 ;DIFFER SIGNS-BAD
H9927 TYA ;HI BYTE POS-CHECK LO
BPL H28 ;BOTH POS-EXPR OK
; BAD REL-FLAG AS ERROR
H9929 LDA #$17 ;BRANCH ERROR
STA IERR ;SAVE IN IERR
H28 LDA IEXP ;GOOD RELATIVE-OPLENGTH AT 2
BEQ H400
CMP #255
BEQ H285
LDA #$17
STA IERR
H285 LDA #0
STA IEXP
BEQ H400
; CHECK INDIRECT ADDRESS ERROR
; ERROR INDICATED BY EXPR OVER 254
; OR OPTYPE >= 6 AND <= 9
H22 LDA JOPTYP
CMP #6
BCC H400 ;NO
CMP #9
BEQ H9928 ;YES
BCS H400 ;NOT INDIRECT
H9928 LDA IEXP ;CHECK VAL OF EXPR
BNE H9930 ;ERROR-OVER 255
LDA IEXP+1
CMP #255
BNE H400 ;NO-OK
; ERROR ON INDIRECT
H9930 LDA #$19 ;ERROR CODE
STA IERR
LDA #0
STA IEXP
H400 LDA #2 ;ONE OR TWO BYTE OPERAND
STA JOPLEN
LDA IEXP
BNE H41 ;WE NEED 2 BYTES
; 1 BYTE OPERAND - CHECK IF VALID
LDA #1
STA JOPLEN
LDA JOPTYP
CLC
ADC #2
STA JOPTYP
H50 CMP #13 ;MAX ADDR MODE
BCC H45 ;YES...OPER VALID OPCODE
LDA #$15 ;BAD OPERAND-FLAG
STA IERR ;PAGE ZERO INVALID
JMP H900
H41 LDA JOPTYP ;PROCESS 2 BYTE OPERANDS
CLC
ADC #13
STA JOPTYP
H47 CMP #15 ;OVER 15 COULD BE BAD
BEQ H45 ;GOOD EXTENDED OPERAND
BCS H49 ;BAD-MIGHT BE A PAGE 0
; SEE IF OPERAND IS VALID FOR OPCODE.
H45 TAY ;FIRST SUBSCRIPT
DEY
LDA KLUDG,Y
CLC
ADC JOPTEM ;SECOND SUBSCRIPT
TAY ;OPCODE BASE INCREMENT
LDA KLTBL,Y
BPL H46 ;POS OPERAND TYPE VALID
; OPERAND NOT VALID FIRST TRY. TRY 2 BYTE OPERAND.
H49 LDA JNOPV ;AN OPERAND VALUE
BEQ H48 ;YES
LDA JOPLEN ;NO OPERAND VAL-TRY 1 BYTE INSTR
CMP #2
BEQ H206 ;WAS 2 - TRY AS 1
LDA #$18 ;1 BYTE NOVALUE OPERAND-FLG ERROR
STA IERR ;INVALID OPERAND
JMP H900
H206 LDA #1 ;ABS MODE AS PAGE ZERO MODE
STA JOPLEN
LDA JOPTYP
SEC
SBC #11
STA JOPTYP ;NEW OP TYPE
JMP H50
H48 LDA JOPLEN ;HAD AN OPERAND VALUE
CMP #1 ;1 BYTE LONG
BEQ H207 ;YES...TRY 2 BYTES
LDA #$18 ;OPERAND 2 BYTES - FLAG AS ERROR
STA IERR ;INVALID OPERAND
JMP H900
; PAGE 0 MODE AS ABS
H207 INC JOPLEN ;OP LENGTH TO 2
LDA JOPTYP
CLC
ADC #11
STA JOPTYP
JMP H47
; VALID OPERAND - COMPUTE OPCODE AND PUT IN MEMORY MAP
H46 CLC
ADC JOPBAS ;KLUDGE+BASE OPCODE
LDY #0
JSR OBJOUT
; OPERAND VALUE - ENTER INTO MEMORY MAP
LDA JNOPV ;OPERAND VALUE FLAG
BNE H313 ;NO VALUE
LDY #1 ;AN OPERAND VALUE
LDA IEXP+1 ;LOW BYTE OF EXPR
JSR OBJOUT
LDY #2
LDA JOPLEN
CMP #1 ;IF 1 BYTE THEN DONE
BEQ H9931 ;YES...DONE
LDA IEXP ;2BYT=HI-BYTE TO MEMORY
JSR OBJOUT
; ANY OPERAND ERRORS
H9931 LDA IERR ;ERROR CODE
CMP #$17 ;REL ADDRESS ERROR?
BEQ H900R
CMP #$19 ;IND ADDRESS ERROR?
BEQ H980 ;YES
; OVERFLOW OR NEGATIVE EXPR
;
LDA #9 ;MASK OVERFLOW AND SIGN
AND IFLAGS+1
BNE H960 ;ERROR EXISTS
LDA JOPLEN
CMP #1
BNE H9937 ;2 BYTES OK
LDA IEXP ;SEE IF OVER 1 BYT
BNE H960 ;YES...ERROR
;END OF PROCESSING
H9937 LDX #0 ;ERROR COLUMN
LDY JOPLEN
INY ;COUNT OPCODE
TXA ;ERROR CODE
JMP LTS1
H313 LDY JOPLEN ;FORWARD REFERENCES FOUND
LDA JOPTEM ;OPERAND TEMPLATE
CMP #14 ;BRANCH--3 BYTES
BNE H9932 ;NOT BRANCH
LDY #1 ;BRANCH OPERAND LENGTH
H9932 LDX ICSB ;ERR COL FROM EVAL
INY ;ADJUST COUNT FOR OPCODE
LDA #1
JMP LTS1
; COMMON LENGTH TABLE ENTRIES
;
; RELATIVE BRANCH ERROR #$17
H900R LDA ICSB ;COLUMN OF TARGET
LDY #2 ;TWO BYTE LENGTH
JMP LTS1
H99 LDA #7 ;RAN OFF END OF CARD ERROR
STA IERR
H900 LDX ICSB ;ERROR AT START OF FIELD
JMP H9933
H980 LDX ICOLP ;ERROR AT CURRENT COLUMN
JMP H9933
H995 LDX JERCOL ;ERR AT COL RETURNED BY EVAL
; ENTER IN LENGTH TABLE
H9933 LDY #3 ;SAVE 3 BYTES
LDA IERR ;ERROR CODE
JMP LTS1
H960 LDX ICSB ;INVALID ADDRESS ERR - START OF FIELD
LDY JOPLEN
INY ;COUNT OPCODE
LDA #4 ;GET ERROR MESSAGE
JMP LTS1
; NO ERROR - COMMENT OR BLANK CARD
H990 LDX #0 ;NO ERROR COLUMN
TXA ;NO ERROR CODE
TAY ;NO BYTES GENERATED
LTS1 JSR LTINS
ENDLN LDX #$FF
TXS
JMP SNEWLN
; FIND NEXT NON-BLANK. CARRY SET IF NON-BLANK FOUND.
NFNDNB LDA IMAXCL
CMP #$FF
BEQ J30
LDX ICOLP ;COLUMN POINTER
J10 CPX IMAXCL ;END OF CARD
BEQ J15 ;COL. POINTER GOOD
BCS J30 ;OUT OF RANGE
J15 LDA ICRD,X ;NEXT CHARACTER
CMP #$20
BEQ J20 ;YES...A BLANK
STX ICSB ;RESTORE COL. POINTER
BNE J40
J20 INX
STX ICOLP
JMP J10
; FIND END OF CURRENT STRING.
; CARRY SET WHEN END IS FOUND, CARRY CLEAR IF RAN OFF CARD.
NFNDEN LDY #0
STY ICSL
LDX ICOLP ;CURRENT COLUMN POINTER
I10 CPX IMAXCL ;IN RANGE
BEQ I15 ;POINTER GOOD
BCS I30 ;BAD POINTER
I15 LDA ICRD,X ;NEXT CHARACTER
CMP #$20 ;A BLANK
BEQ I20 ;YES, A BLANK
CMP #'='
BEQ I20 ;YES, EQUALS SIGN
CMP #';'
BNE I40
I20 CPY #0
BNE I60
I25 DEX
STX ICSE ;END OF STRING PNTR
J40 SEC
RTS
I30 CPY #0
BEQ I25
J30 CLC
RTS
I40 CMP #$27 ;APPOSTROPHE
BNE I60 ;NO
INY
CPY #2
BNE I60
LDY #0 ;RESET TEMP
I60 INX ;COL. POINTER
INC ICSL
JMP I10
; FIND NON-EMBEDDED "'" OR ")". CARRY SET IF ABOVE ARE FOUND.
NFNCMP LDX ICOLP ;COL. POINTER
K40 CPX IMAXCL ;OUT OF RANGE?
BEQ K45 ;YES
BCS J30 ;END OF CARD
K45 LDA ICRD,X ;NEXT CHARACTER
CMP #$27 ;BEGINNING OF A STRING? (APPOSTROPHE)
BNE K20
K30 INX ;SKIP OVER THE STRING
STX ICOLP ;NEW COL. POINTER
CPX IMAXCL ;OFF END OF CARD
BEQ K35
BCS J30
K35 LDA ICRD,X ;NEW CHARACTER
CMP #$27 ;CLOSING QUOTE (APPOSTROPHE)
BNE K30
INX ;COL. POINTER
STX ICOLP
JMP K40
K20 LDA ICRD,X ;ANOTHER CHAR
CMP #$20
BEQ J30
CMP #')'
BEQ J40
CMP #','
BEQ J40
INX
STX ICOLP
JMP K40
.END