-
Notifications
You must be signed in to change notification settings - Fork 84
/
asmprint
685 lines (599 loc) · 9.58 KB
/
asmprint
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
.PAGE 'ASMPRINT'
; MAKE AN ENTRY IN LENGTH TABLE
; X CONTAINS COL. FOR ERROR
; Y CONTAINS LENGTH
; A CONTAINS ERROR CODE
LTINS PHA
TYA
PHA
STA LTAB
TXA
STA LTAB+1
PLA
TAX
LDA IPC
STA LTAB+2
LDA IPC+1
STA LTAB+3
PLA
STA LTAB+4
LDA ICRDNO+1
STA LTAB+5
; ADJUST RELATIVE BRANCH
CPX #$FF ;-1?
BNE L20 ;NO...
INX ;MAKE X=0
L20 CPX #4
BNE L30
LDA LTAB+4 ;GET ERROR CODE
CMP #201
BNE L30
LDX #2
L30 CPX #3 ;CHECK FOR DBYTE
BNE L31 ;ONLY INCREMENT
LDA LTAB+4
CMP #202
BNE L31
LDX #2
L31 TXA
CLC
ADC IPC ;IPC + KINC
STA IPC
BCC L31A
INC IPC+1
L31A LDA PASS ;WHICH PASS?
BNE P2PRI ;PASS2--LIST...
; LIST LINES WITH THE FOLLOWING ERRORS IN PASS1:
;
; 02--DUPICATE SYMBOL
; 11--FORWARD REFERENCE
LDA LTAB+4 ;GET ERROR NUMBER
CMP #$02 ;DUPLICATE SYMBOL?
BEQ P2PRI ;YES...LIST LINE
CMP #$11 ;FORWARD REFERENCE?
BEQ P2PRI ;YES...LIST LINE
RTS ;DON'T LIST IN PASS1
P2PRI LDA LTAB+4 ;ERROR FLAG
BNE P204
JMP PRTLN
P204 CMP #203 ;.PAGE?
BNE P201
LDA LTAB+1 ;COLUMN FOR TITLE
JMP SKPG ;DO A PAGE...CARRY SET
P201 CMP #204 ;.SKIP ?
BNE P202
LDA LTAB+1 ;GET COL PTR
BNE M121
ADC #0 ;ADD 1--CARRY SET
BNE M124
M121 TAX
JSR EVAL
LDA RETURN ;GOOD EVAL?
BNE M122 ;NO...
LDA IEXP+1
M124 CLC
JMP SKPG
M122 CMP #1 ;CORRECT ERROR CODE
BEQ P202
LDA #$13
P202 CMP #205 ;.END ?
BEQ P205
STA LEROR
LDA PASS
BEQ P202A ;PASS1 PRINTS ERROR
LDA LTAB+4 ;GET ERROR CODE
CMP #$02 ;PASS2--DUP LAB?
BNE P202A ;NO...NORMAL ERROR
LDA #0
STA LTAB+4 ;CLEAR ERRORS
STA IERR
JMP PRTLN
P202A JMP ERRHND
P205 LDA #0 ;PRINT .LIB, .FIL, .END
STA IERR
JMP PRXX
.PAGE
; ************************
; * *
; * SYMBOL TABLE LISTING *
; * FOR HAL-ASMB *
; * *
; ************************
NSTAT ;PRINT SYM TABLE
LDA STSAVE ;SET PTR TO SYM TABLE
STA SYMTBL
LDA STSAVE+1
STA SYMTBL+1
LDA LNCT
CMP #LINES-6
BCS XXXH
JSR PAGEHD
JMP XXXJ
XXXH JSR PAGE ;NEXT PAGE
XXXJ LDA #0
STA KLEN ;CLEAR PRINT COUNTER
R20 LDA LNCT
CMP #LINES
BMI R42
JSR PAGE
R42 JSR OUTCL1
LDY #0
R41 LDA (SYMTBL),Y
JSR OUTPUT ;PRINT SYMBOL
INY
CPY #6
BNE R41
JSR OUTCL3
LDA (SYMTBL),Y
JSR NUMA ;PRINT SYMBOL VALUE
INY
LDA (SYMTBL),Y
JSR NUMA
INC KLEN
LDA KLEN
CMP #4
BEQ R44
JSR OUTCL3
JMP R43
R44 LDA #0
STA KLEN
JSR CRLF
JSR CHKBRK ;ALLOW DURING LIST
INC LNCT
R43 CLC ;MOVE POINTER TO NEXT SYM
LDA SYMTBL
ADC #8
STA SYMTBL
BCC R434
INC SYMTBL+1
R434 SEC
LDA NOSYM+1
SBC #1
STA NOSYM+1
LDA NOSYM
SBC #0
STA NOSYM
ORA NOSYM+1
BEQ R50
BCC R50
JMP R20
R50 RTS
;
; SYMBOL TABLE PAGE ROUTINE
;
PAGE JSR TOPPAG
LDA #256-3
STA LNCT
PAGEHD LDX #STTTL-MSGS
JSR MSG
LDA LNCT
CLC
ADC #6
STA LNCT
RTS
;
; HOME FEED ROUTINE
;
TOPPAG LDY LNCT
R5B CPY #LINES
BCS R5A
JSR CRLF
INY
BNE R5B
R5A JSR CR2
CR4 JSR CRLF
CR3 JSR CRLF
CR2 JSR CRLF
JMP CRLF
.PAGE
; SKIP AND PAGE ROUTINE
;
; CARRY SET TO PAGE, CLEAR TO SKIP.
; ACC IS NUMBER OF LINES TO SKIP OR PNTR TO ICRD WHERE TITLE IS
;
; IF POINTER=0 OLD HEADING USED
; 0 LINES TO SKIP-1 LINE SKIPPED
SKPG PHP
PHA
LDA #4
AND IFLAGS ;NO LIST RUN ??
BNE N11
PLA
PLP
RTS
N11 PLA
PLP
BCC N90 ;IS SKIP
; IS PAGE - DO WE HAVE A TITLE?
SKPG1 TAX
BEQ PTTTL ;NO-USE OLD ONE
LDY #0 ;Y IS TITLE LENGTH
N10 LDA ICRD+1,X
CPY #20 ;MAXIMUM TITLE LENGTH
BEQ N15
CMP #$27 ;APPOSTROPHE
BEQ N15
STA LTLBUF,Y
INY
INX
CPX IMAXCL
BMI N10
BEQ N10
N15 STY LTLLEN ;LENGTH OF TITLE
; INCREMENT PAGE NUMBER & PRINT TITLE & PAGE NUMBER
PTTTL SED ;INC. PAGNUM
CLC
LDA LPGCT
ADC #1
STA LPGCT
LDA #0
ADC LPGCT+1
STA LPGCT+1
CLD
JSR TOPPAG
PTTTL0 LDY #0 ;PRINT TITLE
N40 CPY LTLLEN ;ANY TITLE ??
BEQ NCV
N50 LDA LTLBUF,Y
JSR OUTPUT
INY
CPY LTLLEN
BMI N50
NCV LDX #6 ;PRINT 6 PERIODS
N60 LDA #'.'
JSR OUTPUT
DEX
BNE N60
LDX #PG-MSGS
JSR MSG
LDA LPGCT+1
JSR NUMA
LDA LPGCT
JSR NUMA
LDX #8
JSR MSG
LDA #3
STA LNCT
RTS
N90 TAY
ADC LNCT
CMP #LINES
BPL PTTTL
STA LNCT
XXXI JSR CRLF
DEY
BMI XXXK
BNE XXXI
XXXK RTS
; ========================
; = END OF ASSEMBLY CODE =
; ========================
PASS3 LDA #2
CLC ;FOR SKIP DIRECTIVE
JSR SKPG ;SKIP PAGE
LDX #LINES
DEX
CPX LNCT
BCS M8811
LDA #0
SEC ;FOR A PAGE
JSR SKPG ;SKIP PAGE
M8811 INC LBOTH
; LDX P1ERR ;ANY PASS 1 ERRORS ?
; BEQ M8810 ;NO
;
; LDX #PSERR-MSGS
; JSR MSG
M8810 LDX #NUMERR-MSGS
JSR MSG
LDX LERCT ;ERROR COUNT LO
LDA LERCT+1 ;ERROR COUNT HI
JSR HEXDEC ;MAKE IT DECIMAL
DEC LBOTH
JSR CRLF
INC LNCT
LDA #$40
AND IFLAGS ;SYMBOLS NEEDED?
BEQ M8813 ;NO...
LDA NOPRIN
BEQ M8813
LDA NOSYM
ORA NOSYM+1 ;ANY SYMBOL TO SORT?
BEQ M8813 ;NO...
JSR NSTAT ;PRINT SYMBOL TABLE
JSR CRLF
M8813 INC LBOTH
LDX #DNMSG-MSGS
JSR MSG
DEC LBOTH
JMP DONE
.PAGE
; *************************
; *
; * PRTLN - PRINT ROUTINE
; * PRINTS ONE OUTPUT LINE
; *
; *************************
PRTLN LDA LTAB+4
STA IERR
LDA IERR ;N0 ...ERROR IN CARD ?
BNE PRXXA ;YES...TRY ERROR LIST
LDA #4
AND IFLAGS ;LIST OPTION?
BEQ PRX1
LDA SFILE ;MACRO LINE ?
AND #FRMMAC
BEQ PRXX
LDA IFLAGS
BPL PRXX
PRX1 RTS ;DO NOT LIST THIS CARD
PRXXA LDA IFLAGS
AND #16 ;ERRORS PRINT?
BEQ PRX1 ;NO...
LDA #0
STA OBJMAP
STA OBJMAP+1
STA OBJMAP+2
PRXX LDA LTAB+2
STA IPC
LDA LTAB+3
STA IPC+1
LDA LTAB
Q5 PHA
LDA LTAB+5
PHA ;SAVE ON STACK
LDA #0
STA COLCNT
LDA LNCT ;LINE COUNT
BEQ Q10 ;IF ZERO - PAGE
CMP #LINES ;OVER THE LIMIT?
BCC Q20 ;NO
Q10 LDA #0 ;NEED TO PAGE
SEC
JSR SKPG ;PAGE ROUTINE
Q20 PLA ;RECOVER CARD # LO
TAX
LDA ICRDNO ;A=CARD # HI
JSR HEXDEC
INC COLCNT
INC COLCNT
JSR OUTCL1 ;PRINT ONE BLANKS
LDA SFILE ;ARE WE PRINTING A MACRO EXPANSION ?
AND #FRMMAC
BEQ PRX2 ;NO
LDA #'+'
JSR OUTPUT
INC COLCNT
JMP XXXL
PRX2 JSR OUTCL1
XXXL LDY #$00
PLA
TAX
LDA IPC+1
JSR NUMC2
LDA IPC
JSR NUMC2
JSR OUTCL2
TXA
BMI Q44
CMP #4
BMI Q44
LDX #2
SEC
SBC #2
.BYTE $2C
Q44 LDA #0
Q45 PHA
Q50 DEX ;DEC BYTES LEFT
BMI Q60 ;0 OR MORE-PRINT NEXT
LDA OBJMAP,Y ;GET THE BYTE
JSR NUMC2
JSR OUTCL1
INY
INC IPC
BNE Q55
INC IPC+1
Q55 JMP Q50
; PRINT CARD IF SUPPOSED TO
Q60 LDA LCDPT ;PRINT FLAG
BEQ *+5
JMP Q80A
; NEED TO PRINT THE CARD
LDY COLCNT
Q65 JSR BLANK
INY ;INCR FOR BLANK
CPY #22 ;RIGHT COLUMN FOR CARD
BMI Q65 ;NO, PRINT MORE
INC IMAXCL
LDX #0 ;X POINTS TO CARD
LDA IERR
BNE Q70 ;DON'T TAB ERRORS
LDA ICRD
CMP #';' ;DON'T TAB COMMENT
BEQ Q70
LDY #0
LDA ICRD,Y
CMP #' '
BEQ Q74 ;NO LABEL
Q73 LDA ICRD,X
INX
CMP #' '
BNE Q72 ;NOT BLANK
CPX IMAXCL
BCS Q80 ;RAN OUT OF CARD
BCC Q73
Q72 JSR OUTPUT ;OUTPUT LABEL
INY
CPX IMAXCL
BCS Q80 ;RAN OUT OF CARD
LDA ICRD,X
INX
CMP #$20
BNE Q72 ;STILL LABEL
JSR OUTPUT
INY
Q74 CPY #7
BCS Q75
JSR BLANK
INY
BNE Q74
Q75 LDA ICRD,X ;DO NOT PRINT OP
CMP #$20 ;UNTIL NONBLANK
BNE Q70
INX
CPX IMAXCL
BCS Q80
BCC Q75
Q70 CPX IMAXCL
BCS Q80 ;OUT OF CARD
LDA ICRD,X ;GET OPCODE
; TAB COMMENT FIELD
CMP #';'
BNE Q70AA
PHA
LDA ICRD-1,X ;GET PREVIOUS
CMP #' '
BNE Q70A
Q70B CPY #23
BCS Q70A
JSR BLANK
INY
BNE Q70B
Q70A PLA
Q70AA INX
JSR OUTPUT
INY
BNE Q70
Q80 DEC IMAXCL
Q80A JSR CRLF
INC LNCT ;LINE COUNT
INC LCDPT ;FLAG A 2ND LINE
PLA ;BYTES LEFT OFF STACK
BEQ Q90 ;NONE LEFT-DONE
TAX
LDA IFLAGS ;NOGEN OPTION?
BMI Q90A ;YES...
TXA
JMP Q5 ;GET NEXT LINE
; NOGEN OPTION, UPDATE PC
Q90A TXA
CLC
ADC IPC
STA IPC
BCC Q90
INC IPC+1
Q90 RTS
NUMC2 INC COLCNT
INC COLCNT
JMP NUMA
OUTCL3 JSR OUTCL1
OUTCL2 JSR OUTCL1
OUTCL1 INC COLCNT
BLANK LDA #' '
JMP OUTPUT
; ERROR HANDLER
ERRHND INC LBOTH
LDA IFLAGS
AND #16
BEQ P60
LDA LNCT
CMP #LINES ;END OF PAGE?
BMI P10 ;NO, SO PRINT ERROR
LDA #0 ;YES, SKIP A PAGE
SEC
JSR SKPG
P10 JSR PRTLN ;PRINT THE LINE
LDX #0 ;GET READY FOR ERROR
JSR MSG
JSR OUTCL2
LDX LEROR
TXA
AND #$F
CPX #$20
BCC P15
ADC #9
P15 CPX #$10
BCC P17
ADC #9
P17 TAX
DEX
TXA
ASL A
TAX
LDA ERRTAB,X
STA INPMIN
LDA ERRTAB+1,X
STA INPMIN+1
LDY #0
P40 LDA (INPMIN),Y
JSR OUTPUT
INY
CPY #21
BNE P40
P45 DEC LTAB+1 ;ERROR COLUMN #
BMI P50
BEQ P50
LDA #'*'
JSR OUTPUT
JMP P45
P50 LDA #$5E ;UP ARROW AT ERROR
JSR OUTPUT
JSR CRLF
INC LNCT
P60
; LDA PASS ;IS IT PASS 1 ?
; BNE P61 ;NO
;
; LDA #$FF ;SET PASS 1 ERROR FLAG
; STA P1ERR
P61 INC LERCT
BNE P65 ;NO CARRY
INC LERCT+1
P65 DEC LBOTH
RTS
; PRINT A 5 DIGIT DEC NUMBER
;
HEXDEC STX TEMB ;# LO
STA TEMB+1 ;# HI
LDX #4 ;5 DIGITS
STX MIDS
HX200 LDX MIDS
LDY #$30 ;AN ASCII 0
BNE HX500 ;ALWAYS
HX400 INY
HX500 SEC ;SUBTRACT POWER OF TEN
LDA TEMB
SBC DECL,X
STA TEMB
LDA TEMB+1
SBC DECH,X
STA TEMB+1
BCS HX400 ;GOT ANOTHER ONE
LDA TEMB ;WENT TOO FAR
ADC DECL,X
STA TEMB
LDA TEMB+1
ADC DECH,X
STA TEMB+1
TYA
JSR OUTPUT
DEC MIDS ;DONE 4 DIGITS ?
BPL HX200 ;NO
RTS
; PRINT HEX NUMBER IN A
NUMA PHA
LSR A
LSR A
LSR A
LSR A
JSR NOUT
PLA
AND #$0F
NOUT CLC
ADC #$30
CMP #$3A
BMI LT10
CLC
ADC #7
LT10 JMP OUTPUT
.END