S-C DisAssembler
1000 *SAVE D.GENERATE
1010 *--------------------------------
1020 DISASM.CMNT
1030 LDA PASS
1040 BEQ .2 ...DO NOTHING IN PASS 1
1050 JSR GEN.LINE.HEADER
1060 LDY #0
1070 LDA #'*'
1080 .1 JSR STUFF.CHAR
1090 INY
1100 LDA CMDBUF,Y
1110 BNE .1
1120 JSR GEN.EOL
1130 .2 RTS
1140 *--------------------------------
1150 DEFINE.LABEL.CHARS
1160 LDA PASS
1170 BEQ .2 ...DO NOTHING IN PASS 1
1180 JSR GNNB
1190 STA LBLCHR.Z
1200 JSR GNNB
1210 STA LBLCHR.I
1220 JSR GNNB
1230 STA LBLCHR.X
1240 JSR GET.HEX.RANGE
1250 LDX #3
1260 .1 LDA A1,X
1270 STA I.RANGE,X
1280 DEX
1290 BPL .1
1300 .2 RTS
1310 *--------------------------------
1320 GEN.SYMBOLS.UP.TO.PC.MINUS.ONE
1330 LDA PC
1340 BNE .1
1350 DEC PC+1
1360 .1 DEC PC
1370 JSR GEN.SYMBOLS.UP.TO.PC
1380 INCREMENT.PC
1390 INC PC
1400 BNE .1
1410 INC PC+1
1420 .1 RTS
1430 *--------------------------------
1440 GEN.SYMBOLS.UP.TO.PC
1450 JSR GEN.STAR.DASH
1460 .1 JSR CHECK.LPTR
1470 BCS .2 ...NO SYMBOLS LEFT
1480 LDY #2
1490 LDA PC
1500 CMP (LPTR),Y
1510 INY
1520 LDA PC+1
1530 SBC (LPTR),Y
1540 BCC .2 ...THAT IS ENUF FOR NOW
1550 JSR GEN.XREF.LINE
1560 JSR GEN.EQ.LINE
1570 JSR INCREMENT.LOWER.PNTR
1580 JMP .1 ...MORE IN SYMBOL TABLE
1590 .2 RTS
1600 *--------------------------------
1610 CHECK.LPTR
1620 LDA LPTR
1630 CMP SPTR
1640 LDA LPTR+1
1650 SBC SPTR+1
1660 RTS
1670 *--------------------------------
1680 DISASM.CODE
1690 JSR GET.HEX.RANGE
1700 LDA PASS
1710 BNE .4 PASS 2
1720 *---PASS 1-----------------------
1730 JSR COPY.A1.INTO.PC
1740 .1 JSR CALL.INSDS2
1750 LDY LENGTH
1760 BEQ .3 =0, 1 BYTE
1770 DEY
1780 BNE .2 OPERAND HAS 2 BYTES
1790 *---OPERAND HAS 1 BYTE-----------
1800 LDA FORMAT
1810 CMP FORMAT.IMMEDIATE
1820 BEQ .3 ...YES
1830 *---NOW HAVE 2-BYTE VALUE--------
1840 .2 JSR ADD.ENTRY.TO.SYMBOL.TABLE
1850 *---UPDATE PC--------------------
1860 .3 JSR UPDATE.PC.AND.TEST
1870 BCC .1
1880 RTS
1890 *---PASS 2-----------------------
1900 .4 JSR START.PASS.TWO
1910 *** JMP PASS.TWO.CODE
1920 *--------------------------------
1930 PASS.TWO.CODE
1940 .1 JSR CHECK.LPTR
1950 BCS .3 ...NO SYMBOLS LEFT
1960 LDY #2
1970 LDA PC
1980 CMP (LPTR),Y
1990 INY
2000 LDA PC+1
2010 SBC (LPTR),Y
2020 BCC .3 ...PC < NEXT SYMBOL'S VALUE
2030 JSR GEN.XREF.LINE
2040 LDY #2
2050 SEC
2060 LDA PC
2070 SBC (LPTR),Y
2080 STA DELTA
2090 INY
2100 LDA PC+1
2110 SBC (LPTR),Y
2120 BNE .2 ...USE "LABEL .EQ VALUE"
2130 LDA DELTA
2140 BEQ .5 ...USE EXACT LABEL
2150 CMP #10
2160 BCS .2 ...USE "LABEL .EQ VALUE"
2170 JSR GEN.DELTA.LINE ...USE "LABEL .EQ *-#"
2180 JSR INCREMENT.LOWER.PNTR
2190 JMP .1
2200 *--------------------------------
2210 .2 JSR GEN.EQ.LINE
2220 JSR INCREMENT.LOWER.PNTR
2230 JMP .1
2240 *--------------------------------
2250 .3 JSR DO.WE.NEED.TO.FORCE.A.LABEL
2260 BCS .6 ...YES, FORCE A LABEL
2270 JSR GEN.LINE.HEADER
2280 LDA TAB.TO.OPCODE
2290 BNE .7 ...ALWAYS
2300 *--------------------------------
2310 .5 JSR INCREMENT.LOWER.PNTR
2320 .6 JSR GEN.PC.LABEL
2330 .7 JSR GEN.INSTRUCTION.LINE
2340 JSR GEN.STAR.DASH.IF.NEEDED
2350 JSR UPDATE.PC.AND.TEST
2360 BCC .1
2370 RTS
2380 *--------------------------------
2390 ADD.ENTRY.TO.SYMBOL.TABLE
2400 JSR CHECK.IF.NEED.AN.XREF.ENTRY
2410 BCS .3 ...NO
2420 CLC BE SURE ROOM FOR ANOTHER SYMBOL
2430 LDA SPTR
2440 ADC #4
2450 LDX SPTR+1
2460 BCC .1
2470 INX
2480 .1 PHA
2490 CMP LABELS
2500 TXA
2510 SBC LABELS+1
2520 BCC .2
2530 LDY #Q.MEMFUL
2540 JMP ERROR
2550 .2 LDY #0 BUILD ENTRY IN SYMBOL TABLE
2560 LDA PC PCL..PCH....OPL..OPH
2570 STA (SPTR),Y REFERENCE....VALUE
2580 INY
2590 LDA PC+1
2600 STA (SPTR),Y
2610 INY
2620 LDA OPERAND.LO
2630 STA (SPTR),Y
2640 INY
2650 LDA OPERAND.HI
2660 STA (SPTR),Y
2670 STX SPTR+1
2680 PLA
2690 STA SPTR
2700 .3 LDX #H.XREF
2710 JMP SHOW.HEX.INFO
2720 *--------------------------------
2730 CHECK.IF.NEED.AN.XREF.ENTRY
2740 BIT XREF.FLAG
2750 BPL .4 WE DO NEED ONE
2760 >SET UPTR,SYMBOL.TABLE
2770 .1 LDA UPTR
2780 CMP SPTR
2790 LDA UPTR+1
2800 SBC SPTR+1
2810 BCS .4 NOT IN TABLE YET
2820 LDY #2
2830 LDA (UPTR),Y
2840 CMP OPERAND.LO
2850 BNE .2 NOT SAME, TRY NEXT ONE
2860 INY
2870 LDA (UPTR),Y
2880 CMP OPERAND.HI
2890 BEQ .3 SAME, WE DON'T NEED ANOTHER ONE
2900 .2 CLC
2910 LDA UPTR
2920 ADC #4
2930 STA UPTR
2940 BCC .1
2950 INC UPTR+1
2960 BNE .1 ...ALWAYS
2970 .3 SEC SIGNAL WE DO NOT NEED ONE NOW
2980 RTS
2990 .4 CLC SIGNAL WE DO NEED ONE
3000 RTS
3010 *--------------------------------
3020 UPDATE.PC.AND.TEST
3030 SEC ADD LENGTH+1
3040 LDA PC
3050 ADC LENGTH
3060 STA PC
3070 BCC .1
3080 INC PC+1
3090 .1 CMP A2
3100 LDA PC+1
3110 SBC A2+1
3120 RTS
3130 *--------------------------------
3140 DISASM.HEX
3150 JSR GET.HEX.RANGE
3160 LDA PASS
3170 BNE .2 PASS 2
3180 SEC FIGURE HOW MANY BYTES IN HEX BLOCK
3190 LDA A2
3200 SBC A1
3210 STA MARK
3220 LDA A2+1
3230 SBC A1+1
3240 STA MARK+1
3250 JSR MLI READ MARK INTO "OFFSET"
3260 .DA #$CF,P.MARK
3270 CLC FIGURE NEW FILE POSITION
3280 LDA OFFSET
3290 ADC MARK
3300 STA OFFSET
3310 LDA OFFSET+1
3320 ADC MARK+1
3330 STA OFFSET+1
3340 JSR MLI JUMP TO NEW FILE POSITION
3350 .DA #$CE,P.MARK
3360 RTS
3370 *---PASS 2-----------------------
3380 .2 JSR START.PASS.TWO
3390 *** JMP PASS.TWO.DATA
3400 *--------------------------------
3410 PASS.TWO.DATA
3420 LDA #0
3430 STA LENGTH SET LENGTH OF 1 BYTE
3440 STA XCNT SIGNAL NO CURRENT LINE
3450 .1 JSR CHECK.LPTR
3460 BCS .3 ...NO SYMBOLS LEFT
3470 LDY #2
3480 LDA PC
3490 CMP (LPTR),Y
3500 INY
3510 LDA PC+1
3520 SBC (LPTR),Y
3530 BCC .3 PC < NEXT SYMBOL'S VALUE
3540 JSR GEN.EOL.IF.CURRENT.LINE
3550 JSR GEN.XREF.LINE
3560 JSR INCREMENT.LOWER.PNTR
3570 JMP .6
3580 *--------------------------------
3590 .3 JSR DO.WE.NEED.TO.FORCE.A.LABEL
3600 BCS .4 ...YES, FORCE A LABEL
3610 LDA XCNT ANY ROOM LEFT ON CURRENT LINE?
3620 BEQ .5 ...NO
3630 LDA #'.'
3640 JSR STUFF.CHAR
3650 JMP .8
3660 .5 JSR GEN.LINE.HEADER
3670 LDA TAB.TO.OPCODE
3680 BNE .7 ...ALWAYS
3690 *--------------------------------
3700 .4 JSR GEN.EOL.IF.CURRENT.LINE
3710 .6 JSR GEN.PC.LABEL
3720 .7 JSR STUFF.CHAR
3730 LDA #8 ROOM FOR 8 BYTES ON A LINE
3740 STA XCNT
3750 LDY #ST.HS
3760 JSR STUFF.STRING
3770 .8 JSR GET.NEXT.OBJ.BYTE
3780 JSR STUFF.BYTE
3790 JSR DISPLAY.PC
3800 DEC XCNT
3810 BNE .9
3820 JSR GEN.EOL
3830 .9 JSR UPDATE.PC.AND.TEST
3840 BCC .1
3850 GEN.EOL.IF.CURRENT.LINE
3860 LDA XCNT
3870 BEQ .1
3880 JSR GEN.EOL
3890 LDA #0
3900 STA XCNT
3910 .1 RTS
3920 *--------------------------------
3930 SETUP.PC
3940 LDA PC
3950 CMP A1
3960 BNE .1 NEW ORIGIN
3970 LDA PC+1
3980 CMP A1+1
3990 BEQ COPY.A1.INTO.PC
4000 .1 JSR GEN.LINE.HEADER
4010 LDA TAB.TO.OPCODE
4020 JSR STUFF.CHAR
4030 LDY #ST.OR
4040 JSR STUFF.STRING
4050 JSR COPY.A1.INTO.PC
4060 LDA A1+1
4070 JSR STUFF.BYTE
4080 LDA A1
4090 JSR STUFF.BYTE
4100 JSR GEN.EOL
4110 JSR GEN.STAR.DASH
4120 *--------------------------------
4130 COPY.A1.INTO.PC
4140 >MOV A1,PC
4150 RTS
4160 *--------------------------------
4170 GEN.STAR.DASH.IF.NEEDED
4180 LDA OPCODE
4190 ORA #$20 MAKE RTI INTO RTS, JMP INTO JMP()
4200 CMP #$60 RTS OR RTI?
4210 BEQ GEN.STAR.DASH ...YES
4220 CMP #$6C JMP?
4230 BEQ GEN.STAR.DASH ...YES
4240 RTS
4250 GEN.STAR.DASH
4260 BIT STAR.DASH.FLAG
4270 BMI .1 NOT TWO IN A ROW!
4280 JSR GEN.LINE.HEADER
4290 LDY #ST.SD
4300 JSR STUFF.STRING
4310 JSR GEN.EOL
4320 SEC SIGNAL WE JUST WROTE ONE
4330 ROR STAR.DASH.FLAG
4340 .1 RTS
4350 *--------------------------------
4360 * LIST A CROSS REFERENCE
4370 *--------------------------------
4380 GEN.XREF.LINE
4390 BIT XREF.FLAG
4400 BMI .4
4410 .1 JSR GEN.LINE.HEADER
4420 LDY #ST.XR
4430 JSR STUFF.STRING
4440 JSR GEN.ADDRESS.VALUE
4450 LDA #')'
4460 JSR STUFF.CHAR
4470 LDA #10
4480 STA XCNT
4490 .3 LDA #$81 ONE BLANK
4500 JSR STUFF.CHAR
4510 LDY #1
4520 JSR GEN.ADDRESS.VIA.LPTR
4530 LDY #3 SEE IF NEXT ONE IS SAME #
4540 LDA (LPTR),Y
4550 LDY #7
4560 CMP (LPTR),Y
4570 BNE .7 ...NOT SAME
4580 DEY
4590 LDA (LPTR),Y
4600 LDY #2
4610 CMP (LPTR),Y
4620 BNE .7 ...NOT SAME
4630 JSR INCREMENT.LOWER.PNTR
4640 JSR CHECK.LPTR
4650 BCS .7
4660 DEC XCNT
4670 BNE .3 ...STILL ROOM ON SAME LINE
4680 JSR GEN.EOL
4690 JMP .1
4700 .7 JMP GEN.EOL
4710 .4 RTS
4720 *--------------------------------
4730 GEN.LINE.HEADER
4740 LDY #3
4750 STY STUFF.INDEX
4760 INC LINNUM
4770 BNE .1
4780 INC LINNUM+1
4790 .1 RTS
4800 *--------------------------------
4810 GEN.INSTRUCTION.LINE
4820 JSR STUFF.CHAR
4830 JSR CALL.INSDS2
4840 LDX #3
4850 LDA FORMAT
4860 CMP #2 Check for 2nd line of MLI call
4870 BNE .1 ...NO
4880 *--------------------------------
4890 LDY #ST.DA ".DA #$"
4900 JSR STUFF.STRING
4910 LDA OPCODE
4920 JSR STUFF.BYTE
4930 LDA #','
4940 JSR STUFF.CHAR
4950 JMP .9
4960 *--------------------------------
4970 .1 LDA MNEMONIC
4980 ORA MNEMONIC+1
4990 BNE .2
5000 LDY #ST.HS
5010 JSR STUFF.STRING
5020 LDA OPCODE
5030 JSR STUFF.BYTE
5040 JMP GEN.EOL
5050 *--------------------------------
5060 .2 LDA #0 UNPACK AND STUFF OPCODE
5070 LDY #5
5080 .3 ASL MNEMONIC+1
5090 ROL MNEMONIC
5100 ROL
5110 DEY
5120 BNE .3
5130 ADC #'?'
5140 JSR STUFF.CHAR
5150 DEX
5160 BNE .2
5170 *--------------------------------
5180 LDY LENGTH
5190 BEQ .7
5200 LDA #$81 ONE BLANK
5210 JSR STUFF.CHAR
5220 *--------------------------------
5230 LDA FORMAT IS IT RELATIVE FORMAT?
5240 CMP FORMAT.RELATIVE
5250 BEQ .9 ...YES
5260 CMP FORMAT.IMMEDIATE
5270 BEQ .10
5280 *--------------------------------
5290 LDX #4
5300 .4 ASL FORMAT
5310 BPL .6 ...NOTHING IN THIS COLUMN
5320 LDA CHAR1,X
5330 BNE .5
5340 JSR GEN.LABEL.FROM.OPERAND
5350 JMP .6
5360 .5 JSR STUFF.CHAR
5370 LDA CHAR2,X
5380 BEQ .6
5390 JSR STUFF.CHAR
5400 .6 DEX
5410 BPL .4
5420 .7 JMP GEN.EOL
5430 *--------------------------------
5440 .9 JSR GEN.LABEL.FROM.OPERAND
5450 JMP GEN.EOL
5460 *---IMMEDIATE MODE---------------
5470 .10 LDA #'#'
5480 JSR STUFF.CHAR
5490 LDA #'$'
5500 JSR STUFF.CHAR
5510 LDA OPERAND.LO
5520 JSR STUFF.BYTE
5530 JMP GEN.EOL
5540 *--------------------------------
5550 GEN.LABEL.FROM.OPERAND
5560 LDA OPERAND.HI
5570 STA LABEL.HI
5580 LDA OPERAND.LO
5590 JMP GEN.LABEL
5600 *--------------------------------
5610 GEN.ADDRESS.VALUE
5620 LDY #3
5630 GEN.ADDRESS.VIA.LPTR
5640 LDA (LPTR),Y
5650 BEQ .1
5660 JSR STUFF.BYTE
5670 .1 DEY
5680 LDA (LPTR),Y
5690 JMP STUFF.BYTE
5700 *--------------------------------
5710 GEN.DELTA.LINE
5720 JSR GEN.EQ.HEADER
5730 LDY #ST.STAR.MINUS
5740 JSR STUFF.STRING
5750 LDA DELTA
5760 ORA #'0'
5770 JSR STUFF.CHAR
5780 JMP GEN.EOL
5790 *--------------------------------
5800 GEN.EQ.HEADER
5810 JSR GEN.LINE.HEADER
5820 LDY #3
5830 LDA (LPTR),Y
5840 STA LABEL.HI
5850 DEY
5860 LDA (LPTR),Y
5870 JSR GEN.LABEL
5880 JMP STUFF.CHAR
5890 *--------------------------------
5900 GEN.EQ.LINE
5910 JSR GEN.EQ.HEADER
5920 LDY #3 -----------code inserted 3-19-87----vvvv--
5930 .1 INY -----to suppress .EQ lines with "+" in |
5940 LDA LINE,Y -----the label name |
5950 BMI .3 |
5960 CMP #'+' |
5970 BNE .1 |
5980 LDA LINNUM |
5990 BNE .2 |
6000 DEC LINNUM+1 |
6010 .2 DEC LINNUM |
6020 RTS -----------------------------------^^^^---
6030 .3 LDY #ST.EQ
6040 JSR STUFF.STRING
6050 JSR GEN.ADDRESS.VALUE
6060 **** JMP GEN.EOL
6070 *--------------------------------
6080 GEN.EOL
6090 LDA #$00 STORE 00 ON END OF LINE
6100 STA STAR.DASH.FLAG
6110 JSR STUFF.CHAR
6120 LDA STUFF.INDEX
6130 STA LINLEN
6140 STA WR.LEN
6150 JSR MLI
6160 .DA #$CB,P.WRITE
6170 BCC .1
6180 LDY #Q.WRITE
6190 JMP MLI.ERROR
6200 .1 RTS
6210 *--------------------------------
6220 GEN.PC.LABEL
6230 LDA #0
6240 STA STAR.DASH.FLAG
6250 JSR GEN.LINE.HEADER
6260 LDA PC+1
6270 STA LABEL.HI
6280 LDA PC
6290 JSR GEN.LABEL
6300 BCS .1 ...LABEL FITS ON SAME LINE
6310 JSR GEN.EOL ...NEED A SEPARATE LINE
6320 JSR GEN.LINE.HEADER
6330 LDA TAB.TO.OPCODE 7 BLANKS
6340 .1 RTS
6350 *--------------------------------
6360 GEN.LABEL
6370 STA LABEL.LO
6380 JSR SEARCH.LABEL.TABLE
6390 BCS .4
6400 JSR GEN.LABEL.CHAR
6410 LDA #'.'
6420 JSR STUFF.CHAR
6430 LDA LABEL.HI
6440 BEQ .1
6450 JSR STUFF.BYTE
6460 .1 LDA LABEL.LO
6470 JSR STUFF.BYTE
6480 LDA LABEL.HI
6490 BNE .2 ...LONG LABEL
6500 LDA #4 SHORT LABEL
6510 BNE .3 ...ALWAYS
6520 .2 LDA #6 LONG LABEL
6530 .3 STA LABEL.LEN
6540 BNE .5 ...ALWAYS
6550 .4 JSR GEN.NAMED.LABEL
6560 .5 SEC
6570 LDA TAB.TO.OPCODE
6580 SBC LABEL.LEN
6590 CMP #$81
6600 BCS .6
6610 LDA #$81
6620 .6 RTS
6630 *--------------------------------
6640 DO.WE.NEED.TO.FORCE.A.LABEL
6650 LDA STAR.DASH.FLAG
6660 ASL
6670 BCS .1
6680 LDA PC+1
6690 STA LABEL.HI
6700 LDA PC
6710 STA LABEL.LO
6720 JSR SEARCH.LABEL.TABLE
6730 .1 RTS
6740 *--------------------------------
6750 GEN.LABEL.CHAR
6760 JSR GET.LABEL.CHAR
6770 JMP STUFF.CHAR
6780 *--------------------------------
6790 GET.LABEL.CHAR
6800 LDA LABEL.HI
6810 BEQ .1 ...IN Z-RANGE
6820 LDA LABEL.LO
6830 CMP I.RANGE
6840 LDA LABEL.HI
6850 SBC I.RANGE+1
6860 BCC .2 ...BELOW I-RANGE, IN X-RANGE
6870 LDA LABEL.LO
6880 CMP I.RANGE+2
6890 LDA LABEL.HI
6900 SBC I.RANGE+3
6910 BCS .2 ...ABOVE I-RANGE, IN X-RANGE
6920 LDA LBLCHR.I
6930 BNE .3 ...ALWAYS
6940 .1 LDA LBLCHR.Z
6950 BNE .3 ...ALWAYS
6960 .2 LDA LBLCHR.X
6970 .3 RTS
6980 *--------------------------------
6990 STUFF.BYTE
7000 PHA
7010 LSR
7020 LSR
7030 LSR
7040 LSR
7050 JSR .1
7060 PLA
7070 .1 PHA
7080 AND #$0F
7090 ORA #$30
7100 CMP #$3A
7110 BCC .2
7120 ADC #6
7130 .2 JSR STUFF.CHAR
7140 PLA
7150 RTS
7160 *--------------------------------
7170 STUFF.CHAR
7180 STX SAVEX
7190 LDX STUFF.INDEX
7200 STA LINE,X
7210 INC STUFF.INDEX
7220 LDX SAVEX
7230 RTS
7240 *--------------------------------
7250 STST JSR STUFF.CHAR
7260 INY
7270 STUFF.STRING
7280 LDA STRINGS,Y
7290 BNE STST
7300 RTS
7310 *--------------------------------
7320 STRINGS
7330 ST.OR .EQ *-STRINGS
7340 .HS 2E.4F.52.81.24.00
7350 ST.HS .EQ *-STRINGS
7360 .AS /.HS/
7370 .HS 81.00
7380 ST.EQ .EQ *-STRINGS
7390 .AS /.EQ/
7400 .HS 81
7410 .AS /$/
7420 .HS 00
7430 ST.XR .EQ *-STRINGS
7440 .AS /*/
7450 .HS 81
7460 .AS /(/
7470 .HS 00
7480 ST.STAR.MINUS .EQ *-STRINGS
7490 .HS 2E.45.51.81.2A.2D.00
7500 ST.SD .EQ *-STRINGS
7510 .HS 2A.C0.20.2D.00
7520 ST.DA .EQ *-STRINGS
7530 .HS 2E.44.41.81.23.24.00
7540 *--------------------------------