
 1000  *---------------------------------
 1010  *      STEP-TRACE UTILITY
 1020  *---------------------------------
 1030  MON.WNDBTM .EQ $23
 1040  MON.CH     .EQ $24
 1050  MON.CV     .EQ $25
 1060  LMNEM      .EQ $2C
 1070  RMNEM      .EQ $2D
 1080  MON.FORMAT .EQ $2E
 1090  MON.LENGTH .EQ $2F
 1100  MON.PC     .EQ $3A,3B
 1110  MON.A1     .EQ $3C,3D
 1120  MON.A2     .EQ $3E,3F
 1130  *---------------------------------
 1140  DOS.REENTRY .EQ $3D0
 1150  Y.VECTOR    .EQ $3F8
 1160  BASE.LINE24 .EQ $7D0
 1170  MON.INSDS2  .EQ $F88E
 1180  MON.INSTDSP .EQ $F8D0
 1190  MON.PRADDR  .EQ $F90C
 1200  MON.PRBLNK  .EQ $F948
 1210  MON.PRBL2   .EQ $F94A
 1220  MNEML       .EQ $F9C0
 1230  MNEMH       .EQ $FA00
 1240  MON.VTAB    .EQ $FC22
 1250  MON.CLREOP  .EQ $FC42
 1260  MON.SCROLL  .EQ $FC70
 1270  MON.CLREOL  .EQ $FC9C
 1280  MON.RDKEY   .EQ $FD0C
 1290  MON.CROUT   .EQ $FD8E
 1300  MON.PRYX3   .EQ $FD99
 1310  MON.PRBYTE  .EQ $FDDA
 1320  MON.COUT    .EQ $FDED
 1330  MON.SETINV  .EQ $FE80
 1340  MON.SETNORM .EQ $FE84
 1350  *---------------------------------
 1360  KEYBOARD   .EQ $C000
 1370  STROBE     .EQ $C010
 1380  *---------------------------------
 1390  STEP.TRACE.SETUP
 1400         LDA #$4C     'JMP' OPCODE
 1410         STA Y.VECTOR
 1420         LDA #STEP.TRACE
 1430         STA Y.VECTOR+1
 1440         LDA /STEP.TRACE
 1450         STA Y.VECTOR+2
 1451         LDA #0       CLEAR USER STATUS REGISTER
 1452         STA SAVE.P
 1460         RTS
 1470  *---------------------------------
 1480  *      (Y)          SINGLE STEP AT CURRENT PC
 1490  *      ADR(Y)       SINGLE STEP AT ADR
 1500  *---------------------------------
 1510  STEP.TRACE
 1520         TXA          X=0 IF NO ADDRESSES
 1530         BEQ .1       NO ADDRESSES
 1540         LDA MON.A1   ONE OR TWO ADDRESSES
 1550         STA MON.PC
 1560         LDA MON.A1+1
 1570         STA MON.PC+1
 1580  .1     LDX #$FF     USER GETS WHOLE STACK
 1590         TXS
 1600         STX SAVE.S
 1610         LDA #23
 1620         STA MON.CV
 1630         JSR MON.CROUT
 1640  *---------------------------------
 1650  TRACE.LOOP
 1660         JSR DISPLAY.REGISTERS
 1670         JSR DISASSEMBLE ONE INSTRUCTION
 1680         JSR WAIT.ON.KEYBOARD
 1690         LDA #$EA     'NOP' OPCODE
 1700         STA XQT.AREA+1
 1710         STA XQT.AREA+2
 1720         LDX SAVE.S
 1730         TXS
 1740         LDY #0
 1750         LDA (MON.PC),Y  GET USER OPCODE
 1760         BEQ X.BRK    'BRK' OPCODE
 1770         CMP #$20     'JSR' OPCODE
 1780         BEQ X.JSR
 1790         CMP #$40     'RTI' OPCODE
 1800         BEQ X.RTI
 1810         CMP #$4C     'JMP' OPCODE
 1820         BEQ X.JMP
 1830         CMP #$60     'RTS' OPCODE
 1840         BEQ X.RTS
 1850         CMP #$6C     'JMP ()' OPCODE
 1860         BEQ X.JMPI
 1870         LDY MON.LENGTH  # BYTES IN INSTRUCTION
 1880         AND #$1F     IF RELATIVE BRANCH, CHANGE
 1890         EOR #$14     DISPLACEMENT TO $04
 1900         CMP #$04     FOR XQT AREA
 1910         BEQ .2
 1920  .1     LDA (MON.PC),Y  COPY INSTRUCTION INTO XQT AREA
 1930  .2     STA XQT.AREA,Y
 1940         DEY
 1950         BPL .1
 1960         LDA SAVE.P   RESTORE ALL REGISTERS
 1970         PHA
 1980         LDA SAVE.A
 1990         LDX SAVE.X
 2000         LDY SAVE.Y
 2010         PLP
 2020  *---------------------------------
 2030  XQT.AREA
 2040         NOP          USER'S OPCODE GOES HERE
 2050         NOP
 2060         NOP
 2070         JMP DID.NOT.BRANCH
 2080  *---------------------------------
 2090  *   RELATIVE BRANCHES THAT DO BRANCH COME HERE
 2091         CLD
 2100         CLC
 2110         LDY #1       GET ORIGINAL DISPLACEMENT
 2120         LDA (MON.PC),Y
 2130         BPL .1       POSITIVE DISPLACEMENT
 2140         DEC MON.PC+1 DECREMENT HI-BYTE IF NEGATIVE
 2150  .1     JSR ADD.A.TO.PC
 2160         JMP UPDATE.PC
 2170  *---------------------------------
 2180  X.BRK  JSR DISPLAY.REGISTERS
 2190  RTRN.JMP  JMP RETURN
 2200  *---------------------------------
 2210  X.RTI  TSX
 2220         CPX #$FD
 2230         BCS RTRN.JMP
 2240         PLA          SIMULATE RTI BY GETTING
 2250         STA SAVE.P   STATUS FROM STACK
 2260  X.RTS  TSX
 2270         CPX #$FE
 2280         BCS RTRN.JMP
 2290         PLA          SIMULATE RTS BY GETTING
 2300         STA MON.PC   PC FROM STACK
 2310         PLA
 2320         STA MON.PC+1
 2330         TSX
 2340         STX SAVE.S
 2350         JMP UPDATE.PC
 2360  *---------------------------------
 2370  X.JSR  CLC          UPDATE PC AND PUSH ON STACK
 2380         LDA MON.PC
 2390         ADC #2
 2400         TAY          SAVE LO-BYTE FOR NOW
 2410         LDA MON.PC+1
 2420         ADC #0
 2430         PHA          PUSH HI-BYTE
 2440         TYA
 2450         PHA          PUSH LO-BYTE
 2460         TSX
 2470         STX SAVE.S
 2480  X.JMP  JSR GET.NEW.PC
 2490         JMP TRACE.LOOP
 2500  X.JMPI JSR GET.NEW.PC
 2510         LDY #0
 2520         JSR GET.NEW.PC.0
 2530         JMP TRACE.LOOP
 2540  *---------------------------------
 2550  DID.NOT.BRANCH
 2560         STA SAVE.A   SAVE ALL REGISTERS
 2570         STX SAVE.X
 2580         STY SAVE.Y
 2590         PHP
 2600         PLA
 2610         STA SAVE.P
 2620         TSX
 2630         STX SAVE.S
 2640         CLD
 2650  UPDATE.PC
 2660         SEC          0=1, 1=2, 2=3
 2670         LDA MON.LENGTH
 2680         JSR ADD.A.TO.PC
 2690         JMP TRACE.LOOP
 2700  *---------------------------------
 2710  GET.NEW.PC
 2720         LDY #1       GET NEW PC FROM INSTRUCTION
 2730  GET.NEW.PC.0
 2740         LDA (MON.PC),Y
 2750         TAX          SAVE LO-BYTE FOR NOW
 2760         INY
 2770         LDA (MON.PC),Y
 2780         STA MON.PC+1 NEW HI-BYTE
 2790         STX MON.PC   NEW LO-BYTE
 2800         RTS
 2810  *---------------------------------
 2820  WAIT.ON.KEYBOARD
 2830         LDA #22      LINE 23
 2840         STA MON.CV
 2850         LDA #26      COLUMN 27
 2860         STA MON.CH
 2870         JSR MON.VTAB
 2880         JSR MON.RDKEY
 2890         CMP #$8D
 2900         BEQ RETURN
 2910         CMP #$A0
 2920         BNE .1       REGISTER NAME
 2930         RTS
 2940  .1     LDY #4
 2950  .2     CMP REG.NAMES,Y
 2960         BEQ .3
 2970         DEY
 2980         BPL .2
 2990         BMI WAIT.ON.KEYBOARD
 3000  .3     STY REG.INDEX
 3010  .4     JSR MON.SETINV
 3020         LDA #22
 3030         STA MON.CV
 3040         JSR MON.VTAB
 3050         LDY REG.INDEX
 3060         LDA REG.CH,Y
 3070         STA MON.CH
 3080         LDA SAVE.AREA,Y
 3090         JSR MON.PRBYTE
 3100         JSR MON.SETNORM
 3110  .5     LDA KEYBOARD
 3120         BPL .5
 3130         STA STROBE
 3140         CMP #$A0     BLANK?
 3150         BEQ .8       YES
 3160         CMP #$8D     RETURN?
 3170         BEQ .9       YES
 3180         EOR #$B0
 3190         CMP #10
 3200         BCC .6       DIGIT
 3210         ADC #$88
 3220         CMP #$FA
 3230         BCC .5       NOT DIGIT, SO IGNORE
 3240  .6     LDY #3
 3250         ASL
 3260         ASL 
 3270         ASL
 3280         ASL
 3290         LDX REG.INDEX
 3300  .7     ASL
 3310         ROL SAVE.AREA,X
 3320         DEY
 3330         BPL .7
 3340         BMI .4       ...ALWAYS
 3350  .8     LDY REG.INDEX 
 3360         DEY
 3370         BPL .3
 3380         LDY #4
 3390         BNE .3       ...ALWAYS
 3400  .9     LDA #23
 3410         STA MON.WNDBTM
 3420         JSR MON.SCROLL
 3430         INC MON.WNDBTM
 3440         JMP WAIT.ON.KEYBOARD
 3450  REG.NAMES .AS -/SPYXA/
 3460  REG.INDEX .BS 1
 3470  REG.CH    .DA #38,#35,#32,#29,#26
 3480  *---------------------------------
 3490  RETURN JSR MON.CLREOP
 3500         JMP DOS.REENTRY
 3510  *---------------------------------
 3520  *      ADD (A) TO MON.PC
 3530  *---------------------------------
 3540  ADD.A.TO.PC
 3550         ADC MON.PC
 3560         STA MON.PC
 3570         BCC .1
 3580         INC MON.PC+1
 3590  .1     RTS
 3600  *---------------------------------
 3610  *      DISPLAY REGISTERS
 3620  *---------------------------------
 3630  DISPLAY.REGISTERS
 3640         LDA #26
 3650         STA MON.CH
 3660         LDX #4
 3670         BNE .2
 3680  .1     LDA #$A0
 3690         JSR MON.COUT
 3700  .2     LDA SAVE.AREA,X
 3710         JSR MON.PRBYTE
 3720         DEX
 3730         BPL .1
 3740         RTS
 3750  *---------------------------------
 3760  BOTTOM.LINE .AS / <SPC>=NEXT  <RET>=QUIT   A  X  Y  P  S /
 3770         .HS 00
 3780  *---------------------------------
 3790  *      PRINT PC AND DASH
 3800  *---------------------------------
 3810  PRINT.PC
 3820         LDX MON.PC
 3830         LDY MON.PC+1
 3840         JMP MON.PRYX3
 3850  *---------------------------------
 3860  *      DISASSEMBLE NEXT OPCODE
 3870  *---------------------------------
 3880  DISASSEMBLE
 3890         JSR PRINT.PC
 3900         LDY #0
 3910         LDA (MON.PC),Y GET OPCODE
 3920         JSR MON.INSDS2
 3930         PHA          SAVE MNEMONIC TABLE INDEX
 3940  .1     LDA (MON.PC),Y
 3950         JSR MON.PRBYTE
 3960         LDX #1       PRINT ONE BLANK
 3970  .2     JSR MON.PRBL2
 3980         CPY MON.LENGTH
 3990         INY
 4000         BCC .1
 4010         LDX #3
 4020         CPY #3
 4030         BCC .2
 4040         PLA          GET MNEMONIC TABLE INDEX
 4050         TAY
 4060         LDA MNEML,Y
 4070         STA LMNEM
 4080         LDA MNEMH,Y
 4090         STA RMNEM
 4100  .3     LDA #0
 4110         LDY #5
 4120  .4     ASL RMNEM    SHIFT 5 BITS OF CHARACTER INTO A
 4130         ROL LMNEM
 4140         ROL
 4150         DEY
 4160         BNE .4
 4170         ADC #$BF
 4180         JSR MON.COUT
 4190         DEX
 4200         BNE .3
 4210         LDA #$A0     PRINT BLANK
 4220         JSR MON.COUT
 4230         JSR MON.PRADDR
 4240         JSR MON.CLREOL
 4250         JSR MON.CROUT
 4260         LDY #39
 4270  .5     LDA BOTTOM.LINE,Y
 4280         AND #$3F
 4290         STA BASE.LINE24,Y
 4300         DEY
 4310         BPL .5
 4320         DEC MON.CV
 4330         RTS
 4340  *---------------------------------
 4350  SAVE.AREA
 4360  SAVE.S .BS 1
 4370  SAVE.P .BS 1
 4380  SAVE.Y .BS 1
 4390  SAVE.X .BS 1
 4400  SAVE.A .BS 1
 4410  *---------------------------------
 4420  *      TEST PROGRAM
 4430  *---------------------------------
 4440  TEST   JSR TEST1
 4450         BRK
 4460  TEST1  JSR TEST2
 4470  TEST2  JSR TEST3
 4480  TEST3  RTS

