Appendix D

Note: The ^ means "to the power of" as in 2 ^ 2=4.

Program D-1. Disassembler (VIC, PET, Apple, 64 Version).

1 HE$="0123456789ABCDEF"
2 L$="------------------------------------
  ---"
4 J$="    --->"
13 PRINT"  DISASSEMBLER
14 PRINT
16 DIMM$(15,15)
17 FORI=0TO15:FORB=0TO14:READM$(I,B):NEXTB:
    NEXTI
25 REM START MAIN LOOP
30 PRINT"STARTING ADDRESS (DECIMAL)";:INPUT
    SA:TA=SA
31 PRINT"START ADDRESS HEX  ";:DE=SA:ZX=3:G
    OSUB1200:PRINTH$"  "
35 IFSA<0THENEND
41 I=SA
45 REM PRINT ADDRESS
46 PRINTI" ";
50 X=PEEK(I)
55 GOSUB5000
56 IFL%=15ORM$(H%,L%)="0"THENPRINT" ?    "
    X:CK=0:LN=LN+1:GOTO70
58 PRINTM$(H%,L%);
60 GOSUB6000:IFEQTHENEQ=0
70 I=I+1
72 IFLN=20THENLN=0:GOTO2000
80 GOTO45
600 IFCK=12THEN603
601 B=PEEK(I+1):IFB>127THENB=((NOTB)AND255)+
    1:B=-B
602 BAD=I+2+B:PRINT"        "BAD:I=I+1:RETUR
    N
603 IFH%>8THEN800
604 IFH%=2THENJ=1:GOTO850
605 IFH%=6THENPRINT:PRINTL$:EQ=1:RETURN
606 IFH%=6THENRETURN
607 PRINT
608 RETURN
610 IFCK=12THEN615
611 PRINT" ("PEEK(I+1)"),Y"
612 I=I+1:RETURN
615 PRINT" ("PEEK(I+1)",X)"
616 I=I+1:RETURN
630 IFCK=12THEN635
631 PRINT" "PEEK(I+1)",X"
632 I=I+1:RETURN
635 PRINT" "PEEK(I+1)
636 I=I+1:RETURN
640 IFCK=12THEN645
641 PRINT" "PEEK(I+1)",X"
642 I=I+1:RETURN
645 PRINT"  "PEEK(I+l)
646 I=I+1:RETURN
660 IFCK=12THEN645
661 IFH%=9ORH%=11THENPRINT" "PEEK(I+1)",Y"
662 IFH%=7ORH%=15ORH%=5ORH%=3THEN640
663 IFH%=13THEN631
664 PRINT:GOTO642
680 PRINT: RETURN
690 IFCK=12THEN800
691 I$="Y":GOTO850
720 IFCK=12THEN725
722 I$="X":GOTO850
725 IFH%=6THENPRINT" (IND.  ";:I=I+l
726 IFH%=2THEN850
727 IFH%=4THENPRINTJ$;:GOTO850
728 IFH%=8ORH%=10ORH%=12ORH%=14THEN850
729 GOTO610
730 IFCK=12THEN850
731 I$="X":GOTO850
740 IFCK=12THEN850
741 IFH%=11THENI$="Y":GOTO850
742 I$="X":GOTO850
800 PRINT"   #"PEEK(I+1)
801 I=I+1:RETURN
850 N=PEEK(I+1)+PEEK(I+2)*256
860 IFI$=""THEN900
870 IFI$="X"THENPRINT"  "N",X"
880 IFI$="Y"THENPRINT"  "N",Y"
890 I$="":I=I+2:RETURN
900 PRINT"  "N:I=I+2
906 RETURN
1000 DATABRK,ORA,0,0,0,ORA,ASL,0,PHP,ORA,ASL,
    0,0,ORA,ASL,BPL,ORA,0,0,0,ORA,ASL
1010 DATA0,CLC,ORA,0,0,0,ORA,ASL,JSR,AND,0,0,
    BIT,AND,ROL,0,PLP,AND,ROL,0,BIT
1020 DATAAND,ROL,BMI,AND,0,0,0,AND,ROL,0,SEC,
    AND,0,0,0,AND,ROL,RTI,EOR,0,0,0
1030 DATAEOR,LSR,0,PHA,EOR,LSR,0,JMP,EOR,LSR,
    BVC,EOR,0,0,0,EOR,LSR,0,CLI,EOR,0
1040 DATA0,0,EOR,LSR,RTS,ADC,0,0,0,ADC,ROR,0,
    PLA,ADC
1045 DATAROR,0,JMP,ADC,ROR,BVS,ADC,0,0,0
1050 DATAADC,ROR,0,SEI,ADC,0,0,0,ADC,ROR,0,ST
    A
1055 DATA0,0,STY,STA,STX,0,DEY,0,TXA,0,STY,ST
    A
1060 DATASTX,BCC,STA,0,0,STY,STA,STX,0,TYA,ST
    A,TXS,0,0,STA,0,LDY,LDA,LDX,0
1070 DATALDY,LDA,LDX,0,TAY,LDA,TAX,0,LDY,LDA,
    LDX,BCS,LDA,0,0,LDY,LDA,LDX,0
1080 DATACLV,LDA,TSX,0
1090 DATALDY,LDA,LDX,CPY,CMP,0,0,CPY,CMP,DEC,
    0,INY,CMP,DEX,0,CPY,CMP,DEC
1095 DATABNE,CMP,0,0,0,CMP,DEC,0,CLD,CMP,0,0,
    0,CMP,DEC,CPX,SBC,0,0,CPX,SBC,INC
1098 DATA0,INX,SBC,NOP,0,CPX,SBC,INC,BEQ,SBC,
    0,0,0,SBC,INC,0,SED,SBC,0,0,0,SBC
1099 DATAINC
1200 REM MAKE DECIMAL INTO HEX
1201 H$="":FORM=ZXTO0STEP-1:N%=DE/(16^M):DE=D
    E-N%*16^M:H$=H$+MID$(HE$,N%+1,1)
1202 NEXT:RETURN
2000 PRINT"TYPE C TO CONTINUE FROM" I
2001 GETK$:IFK$=""THEN2001
2002 IFK$="C"THENSA=I:TA=SA:GOTO35
2003 INPUTSA:TA=SA:GOTO35
5000 REM ANALYZE H & L OF OPCODE
5010 H%=X/16:L%=X-H%*16
5020 :RETURN
6000 REM FIND ADDRESS TYPE & GOSUB
6020 CK=H%/2:IFCK=INT(CK)THENCK=12
6025 L%=L%+1
6030 ONL%GOSUB600,610,800,6050,640,640,660,60
    50,680,690,680,6050,720,730,740
6040 CK=0
6045 LN=LN+l
6050 RETURN


Program D-2. Atari Disassembler.

100 REM   DISASSEMBLER 
105 GRAPHICS 0:POSITION 11,0:? " FAST
     DISASSEMBLER ":? :? "Loading opc
    odes..."
110 DIM OPCODE$(256*10),LN(255),NB(25
    5),T$(10),D$(5)
120 FOR I=0 TO 255
125 READ T$,NB
130 LN(I)=LEN(T$)
140 OPCODE$(I*10+1,I*10+LN(I))=T$
150 NB(I)=NB
160 NEXT I
170 GRAPHICS 0:POSITION 11,0:? " FAST
     DISASSEMBLER "
180 ? :?
190 TRAP 190:? "{UP}{DEL LINE}Startin
    g Address (Decimal)";:INPUT ADDR:
    TRAP 40000
200 IF ADDR<0 OR ADDR>65535 THEN 190
210 OP=PEEK(ADDR):NB=NB(OP)
220 T$=OPCODE$(OP*10+1,OP*10+LN(OP))
230 PRINT ADDR;:POKE 85,10:PRINT OP;:
    POKE 85,15
240 ON NB+2 GOTO 242,244,250,260,270
242 NB=2:T=PEEK(ADDR+1):IF T>128 THEN
    T=T-256
243 PRINT T;:POKE 85,20:PRINT T$;"  "
    ;ADDR+2+T:GOTO 300
244 ? "Unimplemented":NB=1:GOTO 300
246 PRINT T$;" ";ADDR+2+T:GOTO 300
250 POKE 85,20:PRINT T$:GOTO 300
260 PRINT PEEK(ADDR+1);:POKE 85,20:D$
    =STR$(PEEK(ADDR+1)):GOSUB 400:GOT
    0 300
270 PRINT PEEK(ADDR+1);:POKE 85,15:PR
    INT PEEK(ADDR+2);:POKE 85,20
280 D$=STR$((PEEK(ADDR+1)+256*PEEK(AD
    DR+2))):GOSUB 400
300 ADDR=ADDR+NB:IF ADDR<0 THEN ADDR=
    65536-T
310 IF ADDR>65535 THEN ADDR=T
320 IF PEEK(53279)=7 THEN 210
330 GOTO 190
400 ? T$(1,4+(LN(OP)>4));D$;T$(4+2*(L
    N(OP)>5)):RETURN
500 DATA BRK,1,ORA (X),2,?,0,?,0,?,0,
    ORA  ,2,ASL  ,2,?,0,PHP,1,ORA # ,
    2
510 DATA ASL A,1,?,0,?,0,ORA  ,3,ASL
     ,3,?,0,BPL,-1,ORA ()Y,2,?,0,?,0
520 DATA ?,0,ORA  X,2,ASL  X,2,?,0,CL
    C,1,ORA  Y,3,?,0,?,0,?,0,ORA  X,3
530 DATA ASL ,2,?,0,JSR  ,3,AND (X),2
    ,?,0,?,0,BIT ,2,AND ,2,ROL ,2,?,0
540 DATA PLP,1,AND # ,2,ROL A,1,?,0,B
    IT ,3,AND ,3,ROL ,3,?,0,BMI,-1,AN
    D ()Y,2
550 DATA ?,0,?,0,?,0,AND  X,2,ROL  X,
    2,?,0,SEC,1,AND  Y,3,CLI,1,?,0
560 DATA ?,0,AND  X,3,ROL  X,3,?,0,RT
    I,1,EOR (X),2,?,0,?,0,?,0,EOR  ,2
570 DATA LSR  ,2,?,0,PHA,1,EOR # ,2,L
    SR  ,3,?,0,JMP  ,3,EOR  ,3,LSR  ,
    3,?,0
580 DATA BVC,-1,EOR ()Y,2,?,0,?,0,?,0
    ,EOR  X,2,LSR  X,2,?,0,CLI,1,EOR
     Y,2
590 DATA ?,0,?,0,?,0,EOR  X,3,LSR  X,
    3,?,0,RTS,1,ADC (X),2,?,0,?,0
600 DATA ?,0,ADC  ,2,ROR  ,2,?,0,PLA,
    1,ADC # ,2,ROR A,1,?,0,JMP (),108
    ,ADC  ,3
610 DATA ROR  ,3,?,0,BVS,-l,ADC ()Y,2
    ,?,0.?.0.?,0,ADC  X,2,ROR  X,2,?,
    0
620 DATA SEI,1,ADC  Y,3,?,0,?,0,?,0,A
    DC  X,3,ROR  X,3,?,0,?,0,STA (X),
    2
630 DATA ?,0,?,0,STY  ,2,STA  ,2,STX
     ,2,?,0,DEY,1,?,0,TXA,1,?,0
640 DATA STY  ,3,STA  ,3,STX  ,3,?,0,
    BCC,-1,STA ()Y,2,?,0,?,0,STY  X,2
    ,STA  X,2
650 DATA STX  Y,2,?,0,TYA,1,STA  Y,3,
    TXS,1,?,0,?,0,STA  X,3,?,0,?,0
660 DATA LDY # ,2,LDA (X),2,LDX # ,2,
    ?,0,LDY  ,2,LDA  ,2,LDX  ,2,?,0,T
    AY,1,LDA # ,2
670 DATA TAX,1,?,0,LDY  ,3,LDA  ,3,LD
    X  ,3,?,0,BCS,-1,LDA ()Y,2,?,0,?,
    0
680 DATA LDY  X,2,LDA  X,2,LDX  Y,2,?
    ,0,CLV,1,LDA  Y,3,TSX,1,?,0,LDY
    X,3,LDA  X,3
690 DATA LDX  Y,3,?,0,CPY # ,2,CMP (X
    ),2,?,0,?,0,CPY  ,2,CMP  ,2,DEC
    ,2,?,0
700 DATA INY,1,CMP # ,2,DEX,1,?,0,CPY
      ,3,CMP  ,3,DEC  ,3,?,0,BNE,-1,C
    MP ()Y,2
710 DATA ?,0,?,0,?,0,CMP  X,2,DEC  X,
    2,?,0,CLD,1,CMP  Y,3,?,0,?,0
720 DATA ?,0,CMP  X,3,DEC  X,3,?,0,CP
    X # ,2,SBC (X),2,?,0,?,0,CPX  ,2,
    SBC  ,2
730 DATA INC  ,2,?,0,INX,1,SBC # ,2,N
    OP,1,?,0,CPX  ,3,SBC  ,3,INC  , 3,
    ?,0
740 DATA BEQ,-1,SBC (Y),2,?,0,?,0,?,0
    ,SBC  X,2,INC  X,2,?,0,SED,1,SBC
     Y,3
750 DATA ?,0,?,0,?,0,SBC  X,3,INC  X,
    3,?,0


Return to Table of Contents | Previous Chapter | Next Chapter