-
Notifications
You must be signed in to change notification settings - Fork 84
/
directive
699 lines (572 loc) · 11.2 KB
/
directive
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
.PAGE 'DIRECTIVE'
; EQUATE AND ORG PROCESSING ****
H102 LDA #$FF ;-1
STA JORG
INC ICOLP
STX ILSST ;SAVE START OF STRING
JSR NFNDNB ;IF REST FIELD BLANK
BCS H103 ;NONBLANK FOUND
H103A JMP H99
H103 LDA ICRD,X ;EQUATE OR ORG
CMP #'='
BNE H103A
H121 INC ICOLP
LDA ICOLP
CMP IMAXCL
BEQ H8804
BCC H8804
JMP H99 ;G.T. IMAXCL
H8804 JSR NFNDNB
BCS H104 ;NON-BLANK FOUND
LDX ICSE
LDA #7
LDY #0
JMP LTS1
H104 JSR EVAL ;EVAL OPERAND FIELD
DEC RETURN
BMI H105
BNE H8806
LDA #$11
LDY #3
JMP LTS1
H8806 LDA #$13
LDY #3
JMP LTS1
H105 LDA JORG ;EQU OR ORG
BEQ H9
LDA #1 ;ORG,EXPRESSION OK
AND IFLAGS+1
BEQ H150 ;EXPRESSION IS GE 0
LDX #0
STX IPC
STX IPC+1
LDX ICSB ;BAD EXPR - FLAG
LDA #$21
LDY #$FF
JSR LTINS
JMP ENDLN
H150 LDX #0
TXA
TAY
JSR LTINS
LDA IEXP ;IPC = IEXP
STA IPC+1
LDA IEXP+1
STA IPC
JMP ENDLN
; IS EQUATE****
H9 PLA ;RESTORE LABEL PORTION
STA ICSL ;RESTORE LENGTH
LDX #5
H8846 PLA
STA ISYM,X
DEX
BPL H8846
JSR NFIND
BCC H106
LDA KNVAL ;SEE IF VALUE IS THE SAME
CMP IEXP
BNE MR01
LDA KNVAL+1
CMP IEXP+1
BEQ H106A ;OK
MR01 LDX ILSST ;ALREADY DEFINED
LDA #2
LDY #0
JMP LTS1
H106 LDA IEXP
STA KNVAL
LDA IEXP+1
STA KNVAL+1
JSR NSERT
H106A JMP H990
; ASSEMBLER DIRECTIVES *****
; FIND WHAT DIRECTIVE TO PROCESS
H5 LDA #$14 ;ASM ERROR CODE
STA IERR
LDX ICSB ;START OF DIRECTIVE
INX ;SKIP PERIOD
LDA #<ASMDIR
STA TBLPTR
LDA #>ASMDIR
STA TBLPTR+1
LDA #3 ;GET LENGTH
STA KLEN
JSR CONSYM ;BUILD DIRECTIVE
H8847 CPX IMAXCL
BEQ H8848
BCS H8849
H8848 LDA ICRD,X
CMP #$20
BEQ H8849
INX
JMP H8847
H8849 STX ICOLP ;PNTR TO CHAR AFTER DIRECT
LDA #0 ;INIT COLUMN TO ZERO
STA J
BCS H8835
JMP H900 ;ERROR--BAD SYMBOL
.PAGE
; SEARCH TABLE FOR MATCH
;
; COMPARE DONE BACK-FRONT
; MATCH-IND JMP MADE TO PROCESS
; MISMATCH-POINTER POINTS TO NEXT
; VALID DIRECTIVE IN TABLE.
; NUMASM IS # DIRECT TO SEARCH.
; (TBLPTR) IS CURR DIRECTIVE
H8835 LDX #NUMASM
H9938 LDY #2 ;OFFSET TO CHARS
H9939 LDA ISYM,Y ;CHR FROM SYMBOL
CMP (TBLPTR),Y ;CHAR IN TABLE
BNE H9940
DEY
BPL H9939 ;NOT DONE YET
; A MATCH-X USED TO LOC ADDR
TXA
ASL A ;*2 FOR ADDR TABLE INDEX
TAX
LDA ASMJMP,X ;LOW BYTE ADDR
STA TBLPTR
LDA ASMJMP+1,X ;HIGH BYTE ADDR
STA TBLPTR+1
LDA IFLAGS ;.OPT FLGS
JMP (TBLPTR) ;=>DIRECTIVE PROVESS
; POINT NEXT DIR & START AGAIN
; QUIT IF DONE (ERROR).
H9940 LDA TBLPTR ;LOW ADDR
CLC
ADC #3 ;OFFSET TO NEXT DIRECTIVE
STA TBLPTR
BCC H9938A
INC TBLPTR+1
H9938A DEX
BPL H9938 ;MORE DIRECTIVES
; INVALID DIRECTIVE - ERROR
JMP H900 ;PUT IN LENGTH TABLE
; BYTE, WORD, DBYTE PROCESSING ***
H111 LDA #1 ;*** .BYTE ***
.BYTE $2C
H506 LDA #3 ;*** DOUBLE BYTE ***
.BYTE $2C
H113 LDA #2 ;*** .WORD ***
STA JBYWOR
LDY #0
STY J ;MEMMAP INDEX FOR BYTE GEN
TAY
CPY #3 ;DBYTE ?
BNE H8809 ;NO
DEY
H8809 STY CHAR ;LENGTH OF EACH PARAM.
JSR NFNDNB ;NEXT NON-BLANK
BCS H18X ;NON-BLANK FOUND
LDX ICSE ;RAN OFF EOL
LDA #7
JMP LTS1
H18X STY CHAR
H18 LDX ICSB
JSR EVAL
DEC RETURN
BMI H14 ;RETURN =0
BEQ H8836 ;RETURN =1
JMP H29 ;RETURN =2
H8836 LDA #1 ;UNDEF'D SYM
STA IERR
XXXO CMP #1
BNE XXXM
LDY JBYWOR
STY CHAR
JMP XXXN
XXXM LDY CHAR
XXXN LDA IERR
LDX ICSB
JSR LTINS
LDY #0
STY J
LDY CHAR
CPY #3
BNE H15
DEC CHAR
JMP H15
H14 LDA #4 ;GOOD RETURN
STA IERR
LDX JBYWOR
CPX #3
BNE H8812
LDA IEXP
LDY J
JSR OBJOUT
INC J
H8812 LDA IEXP+1
LDY J
JSR OBJOUT
INC J
LDX JBYWOR
CPX #2
BNE H8820
LDA IEXP
LDY J
JSR OBJOUT ;IEXP IN MEMORY MAP
INC J
H8820 LDA IFLAGS+1
AND #$09
BNE XXXO
CPX #1
BNE XXXP
LDA IEXP
BNE XXXO
XXXP LDA #0
TAX
LDY CHAR
STA J
JSR LTINS
H15 JSR NFNCMP
BCS H8843
JMP ENDLN
H8843 LDA ICRD,X
; FOUND COMMA OR PARENTHESIS
INX ;SKIP TO NEXT COLUMN
STX ICOLP
CPX IMAXCL ;PASSED END
BEQ H8814
BCC H8814
JMP H99 ;RAN OFF END OF CARD
H8814 CMP #','
BNE H15 ;MIGHT BE A PAREN
JSR NFNDNB
BCS H8844 ;NON BLANK FOUND
JMP H99 ;ONLY BLANKS FOUND
H8844 JMP H18
; EXPRESSION HANDLER BOMBED
H29 LDA ICRD,X
CMP #$27 ;MIGHT BE ASCII (APPOSTROPHI)
BEQ H31 ;YES
H30 LDA #$13 ;BAD EXPRESSION
LDY TEMP
JSR LTINS
LDY #0
STY J
JMP H15
; LOOKS LIKE ASCII
H31 CPX ICSB ;FIRST IN STRING
BNE H30
LDY JBYWOR ;AFTER A .BYT
CPY #2
BCS H30
STX ICOLP ;COUNT BYTES GENERATED
LDY #0
H33 INC ICOLP
LDX ICOLP
CPX IMAXCL ;OFF END OF CARD?
BEQ H8815
BCS H473 ;OFF CARD
H8815 LDA ICRD,X
CMP #$27 ;A QUOTE?
BNE H32 ;NO
INC ICOLP ;IMBEDDED QUOTE
LDX ICOLP
CPX IMAXCL
BEQ H8821
BCS H34 ;RAN OFF END OF CARD
H8821 LDA ICRD,X
CMP #$27 ;A QUOTE?
BNE H34 ;NO
H32 PHA
AND #$7F
CMP #$20
BCC XXXQ
CMP #$60
BCC XXXR
XXXQ PLA
LDA #0
PHA
XXXR PLA
LDY J ;CONVERT TO ASCII
JSR OBJOUT
INC J ;COUNT OF ASCII CHARS
BNE H33 ; ** BRA
H34 LDY J
BCAL05 LDA #0
STA J
TAX
JSR LTINS
JMP H15
H473 LDY J ;*** RAN OFF END OF CARD ***
LDA #7
JMP LTS1
.PAGE
; .OPT ASSEMBLER DIRECTIVE
; LOOK FOR PARMS UNTIL NONE LEFT
; WHEN DONE TREAT AS A COMMENT
; USE SEARCH FROM ASMB DIRECTIVES
H301 JSR NFNDNB ;FIND STT OF PARM
BCS H8837 ;A NONBLANK FOUND
JMP H990 ;NO-TREAT LIKE COMMENT
H8837 LDX ICSB ;GET START OF PARM
LDA #3 ;3 IS LENGTH OF PARM
STA KLEN ;STORE FOR CONSYM
JSR CONSYM ;CONSTRUCT THE PARM
BCS H8838 ;O.K. SO CONTINUE
JMP H900 ;BAD PARM - ERROR
; ARE READY FOR SEARCH
; NEED TO RESTORE X AND THE ADRS
; WHERE THE SEARCH LEFT OFF
H8838 LDA #<OPTDIR
STA TBLPTR
LDA #>OPTDIR
STA TBLPTR+1
LDX #NUMSAV
JMP H9938 ;GO DO THE SEARCH
; GENERATE ASCII STRINGS
H323 AND #127 ;CLEAR NOGEN BIT
.BYTE $2C
; DON'T GENERATE ASCII STRINGS
H302 ORA #128 ;SET NOGEN BIT
.BYTE $2C
; SYMBOLS ************
H303 ORA #64 ;SET SYM BIT
.BYTE $2C
; DON'T PRINT SYMBOL TABLE
H304 AND #191 ;CLEAR SYM BIT
.BYTE $2C
; DON'T COUNT OP CODE USAGE
H305 AND #223 ;CLEAR OPCODE CNT
.BYTE $2C
; COUNT OP CODE USAGE
H306 ORA #32 ;SET OPCODE COUNT
.BYTE $2C
; GENERATE ERROR FILE
H307 ORA #16 ;SET ERROR GEN BIT
.BYTE $2C
; DON'T GENERATE ERROR FILE
H308 AND #239 ;CLEAR ERROR GEN
.BYTE $2C
; GENERATE INTERFACE FILE
H309 ORA #8 ;SET INTERFACE FILE
.BYTE $2C
; DON'T GEN INTERFACE FILE
H310 AND #247 ;NO GEN INT FILE
.BYTE $2C
; DON'T SUPPRESS PRINT FILE
H311 ORA #4 ;SET LIST
.BYTE $2C
; SUPPRESS PRINT FILE
H312 AND #251 ;TURN OFF PRT FILE
H390 STA IFLAGS ;ALL DONE WITH THIS PARM
H391 JSR NFNCMP ;LOOK FOR COMMA & START AGAIN
BCS H8840 ;COMMA OR RIGHT PAREN
JMP ENDLN ;NONE FOUND
H8840 LDA ICRD,X ;ICRD(ICOLP)
CMP #',' ;A COMMA?
BEQ H8839 ;YES,
JMP ENDLN ;NO,
H8839 INX
STX ICOLP
JMP H301
; SKIP ***
H26 JSR NFNDNB ;NEXT NON-BLANK
BCS H8808 ;NON-BLANK FOUND
LDX J
H8808 LDA #204
LDY #0
JMP LTS1
; PAGE ***
; HAS A TITLE WITH IT?
H12 JSR NFNDNB ;NEXT NONBLANK
BCC H8807 ;ONLY BLANKS FOUND
LDA ICRD,X ;NEXT TITLE CHAR
CMP #$27 ;A QUOTE?
BEQ H600 ;YES
H8807 LDX #0
H600 LDA #203
LDY #0
JMP LTS1
; END ***
H10 BIT SFILE ;WHAT IS DONE?
BVS ENLIB ;A LIBRARY ROUTINE...
LDX #$FF ;A SOURCE FILE...
TXS
LDX PASS ;WHICH PASS ON SOURCE?
BEQ DEND2 ;PASS1...
;
; ***** COMPLETION OF PASS 2 *****
;
DEND0 LDA #2 ;LOGICAL FILE #2
JSR FCLOSE ;IS SOURCE TO CLOSE
DEND1 LDX #0
TXA
TAY
; INC LBOTH
JSR LTINS ;PRINT THE .END
; DEC LBOTH
JMP PASS3 ;THEN SORT & PRT SYMS
;
; ***** END OF PASS 1 *****
;
DEND2 INC PASS
LDA #2
JSR FCLOSE
DEND2A JMP PASS2
ENLIB LDA #3 ;CLOSE LIBRARY FILE
JSR FCLOSE
LDA SFILE
AND #$BF ;SWITCH CONTROL
STA SFILE
ENDR LDX #0
STX CHAN
LDY #0
LDA #205
INC LBOTH
JSR LTINS
DEC LBOTH
LDA #$0D
STA LCHAR
JMP ENDLN
; FILE ***
HFIL BIT SFILE
BVC HFIL2 ;NOT IN .LIB
LDA #3 ;CLOSE .LIB FILE
JSR FCLOSE
JMP DLIB1 ;REOPEN .LIB AS .FIL
HFIL2 LDA #2 ;CLOSE OLD FILE
JSR FCLOSE
JSR NFILE ;PARSE NEW FILE
LDA #2 ;LOGICAL ADDRESS
TAY ;SECONDARY ADDRESS
LDX #8 ;DEVICE NUMBER
JSR FILPAR
JSR FOPEN
JSR FDTEST
JMP ENDR
; COMMON PARSE ROUTINE
NFILE JSR NFNDNB ;FIND STT OF NAM
BCC NFIL1 ;NO NAME
LDY #0
NFIL3 LDA ICRD,X
CMP #$20
BEQ NFIL4
STA ISYM,Y
CPX IMAXCL
BEQ NFIL4
INY
INX
CPY #18
BNE NFIL3
BEQ NFIL1
NFIL4 LDA #$0D
INY
STY XFNLEN
STA LCHAR
BNE NFIL2
NFIL1 LDA #>FNERR
LDY #<FNERR
JSR WSCRN
JMP DONE
NFIL2 LDX XFNLEN ;ADD FILE TYPE
LDA #','
STA ISYM,X
INX
LDA #'S'
STA ISYM,X
INX
TXA
LDY #>ISYM ;SET UP NAME CALL
LDX #<ISYM
JMP SETNAM
; LIB ***
HLIB BIT SFILE
BVC DLIB1 ;NOT ALREADY IN .LIB
LDA #>LIBERR
LDY #<LIBERR
JSR WSCRN
JMP DONE
DLIB1 JSR NFILE ;PARSE PARMS
LDA #3
TAY
LDX #8
JSR FILPAR
JSR FOPEN
JSR FDTEST
LDA #$40
ORA SFILE
STA SFILE ;FLAG IN .LIB
JMP ENDR
.PAGE
; .IFN AND .IFE ***
;
; SYNTAX FOR CONDTIONAL ASSEMBLEY
; IS AS FOLLOWS:
;
; .IFE EXPR <
;
; WHERE .IFE(.IFN)IS THE DIRECTIVE
; MEANING IF EQU AND IF NOT EQU.
; EXPR IS A VALID EXPRESSION
; (NO FORWARD REFERENCES).
; & < IS THE START OF AN IF RANGE
; (ON SAME CARD).
;
; & RANGE IS TERMINATED BY > CHR
; IN THE FIRST COL. OF A CARD.
; THE TERMINATOR CARD MUST BE IN
; THE SAME FILE AS THE IF STTMNT.
HIFN LDA #$FF ;NOT EQUAL FLAG
.BYTE $2C
HIFE LDA #$00 ;EQUAL FLAG
STA IFFLAG
JSR NFNDNB ;FIND NEXT NON BLANK
BCC RANOFF ;RAN OFF END OF CARD.
STY CHAR
LDX ICSB ;INDEX INTO CARD
JSR EVAL ;EVAL. THE EXPRESSION
DEC RETURN ;SIMPLER TESTING
BMI HSET ;GOOD RETURN
BEQ HUNDEF ;UNDEFINED SOMETHING
JMP NOEVAL ;COULD NOT EVAL...
; LOOK FOR '< , TEST EXPR AND EXECUTE RESULT
HSET STX ICOLP ;NEW PNTR IN LINE
JSR NFNDNB ;SKIP BLANKS
BCC RANOFF ;NOT THERE
CMP #'<' ;CHECK FOR RIGHT CHAR.
BEQ HOK ;FOUND IT
JMP RANOFF ;BAD DIRECTIVE
HOK LDY #$FF ;SET Y TO INVERSE
LDA IEXP ;GET VALUE OF EXPR
ORA IEXP+1
BEQ TSTFLG
LDY #$00
TSTFLG TYA
EOR IFFLAG ;TACK IN THE FLAG
BNE HDONE ;FALSE CONDITION ASMB
; EAT SOURCE UNTIL '> IS FOUND.
GETMOR JSR NEWCHR ;GET A CHAR.
CMP #$0D ;RETURN CHAR?
BNE GETMOR
JSR NEWCHR ;IF NEXT CARD STARTS WITH > THEN STOP
CMP #'>'
BNE GETMOR
XXXS JSR NEWCHR
CMP #$0D
BNE XXXS
HDONE JMP ENDLN ;FINISHED...
;
; ERRORS AND SUBROUTINES FOR IF'S
;
HUNDEF LDA PASS ;PASS 1 OR 2 ?
BNE NOTDEF
LDA #11 ;FOWARD REF ERROR
.BYTE $2C
NOTDEF LDA #01 ;NOT DEFINED
.BYTE $2C
RANOFF LDA #07 ;RAN OFF CARD
.BYTE $2C
NOEVAL LDA #13 ;CAN'T EVAL EXPR..
LDX ICSE ;POINTER INTO CARD
LDY #$00 ;NUM OF BYTES GENERATED
JMP LTS1
NEWCHR JSR GETCHR ;GET A CHAR.
CMP #$00 ;EOF ?
BEQ NOEND ;END MISSING
RTS
NOEND JMP H10
.END