home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ENTERPRS
/
CPM
/
UTILS
/
A
/
6502DASM.LZH
/
DASM6502.MAC
< prev
Wrap
Text File
|
1991-01-16
|
12KB
|
670 lines
;
;DASM6502.MAC from DASM.6502 (ver. >= 3.0)
;This routine is the 6502 mnemonic disassembler module for DASM.MAC.
;It is included into DASM during assembly under M80.
;
; Hacked by: William F. Dudley Jr. (dudley@nadc)
; uploaded to mit-mc Feb 22 1983
;
IF1
.PRINTX /DASM with 6502-Standard Mnemonics/
ENDIF
;
; This is the Header to be printed for this module
;
HEADER:
DEFB 'DASM for 6502-Standard Mnemonics',0dh,0ah
DEFB ' Derived from ZZSOURCE/RESOURCE',0dh,0ah
DEFB '$',0
;
; This is the Disassembler Module -- Instruction to be disassembled
; is pted to by PC
;
DASM:
CALL HSYM ;WRITE A SYMBOL IF IT EXISTS
;.. AND PUT PC ON THE CRT
LD HL,(RPLPTR) ;SEE IF THIS LINE IS REPLACED
LD A,H
OR L
JR Z,DASM1
LD B,(HL)
INC HL ;SKIP THE '*'
DEC B
CALL NWLN0 ;PRINT THE REPLACING LINE AS A COMMENT
DASM1:
LD HL,(PC)
EX DE,HL
LD HL,(OFFSET)
ADD HL,DE ;HL IS NOW THE BIASED PC
LD (BIASED),HL
EX DE,HL ;DE IS NOW THE BIASED PC
INC HL
LD (PC),HL ;THE NEW PC (NEXT BYTE)
EX DE,HL ;DE IS THE BYTE AFTER THE INSTRUCTION
LD B,(HL)
LD HL,OPC-4
CALL GTCD
CALL TYPEOC
CP 02H ;TYPES 0 and 1 ARE 1 BYTE
JR C,OLDPC ; .. SO DON'T CHANGE THE PC
LD HL,(PC)
INC HL
CP 09H ;TYPES 02 THRU 08H ARE 2-BYTERS
JR C,NEWPC
INC HL ;else must be 3 bytes
NEWPC:
LD (PC),HL
OLDPC:
PUSH DE ;SAVE THE 'E' REGISTER (MAY BE 'X' OR 'Y')
LD E,A
LD D,0
LD HL,JMPTBL
ADD HL,DE ;ADD 2*OPCODE TYPE TO JMPTBL TO GET
ADD HL,DE ;.. ROUTINE ADDRESS
LD E,(HL)
INC HL
LD D,(HL)
EX DE,HL ;HL NOW CONTAINS THE ROUTINE ADDRESS
POP DE
PUSH HL
LD HL,(BIASED)
RET ;'RETURN' TO THE ROUTINE
;
GTCD:
LD DE,4
NXTCD:
ADD HL,DE
NXTCD1:
LD A,(HL)
OR A ;SEE IF WE'RE AT THE NEXT MASK YET
INC HL
JP P,NXTCD1 ;JUMP IF NOT
AND B ;MASK OUT VARIABLES IN THE INSTRUCTION
CP (HL) ;CHECK THE GENERIC INSTRUCTION TYPE
JR NZ,NXTCD
INC HL
LD A,(HL) ;AFTER A MATCH, GET THE OPCODE TYPE
LD (OPCTP),A
RET
;
TOC2:
CP 20H ;CONVERT SPACES IN THE TABLE TO TABS
JR NZ,TOC1
LD A,9
TOC1:
CALL COUT
TYPEOC:
INC HL ;TYPE THE OPCODE THAT HL IS POINTING TO
LD A,(HL)
OR A
JR Z,TYPEOC
JP P,TOC2
LD HL,(PC)
LD A,(OPCTP)
RET
;
JMPTBL:
DEFW T0 ;SIMPLE 1 BYTE INSTRUCTIONS
DEFW T2A ;UNDEFINED OPCODES
DEFW TB ;8 BIT IMMEDIATE ARITH. & LOGICAL
DEFW TF ;RELATIVE JUMPS
defw tdzx ;zero, x
defw tdx ;ind, x
defw tdy ;ind, y
defw tdzy ;zero, y
defw tdzp ;zero page
DEFW T11 ;JUMPS & CALLS
defw twx ;abs, x
defw twy ;abs, y
defw jpind ;jump indirect
;
;ONE BYTE INSTRUCTIONS, SIMPLE
;
T0:
JP DCRLF
;
;ARITHMETIC & LOGICAL IMMEDIATES
TB:
INC HL
DTABYT:
LD A,(HL)
CP ' '
JR C,NOTASC
CP 5BH
JR NC,NOTASC
CALL PASCII
LD A,''''
CALL COUT
LD A,(XCSW) ;WANT SYMBOL COMMENTS?
OR A
JP Z,DCRLF
CALL TAB
CALL SEMI
NOTASC:
LD A,(HL)
CP 0AH
JR C,NTSC0
CALL PASHEX
LD A,'H'
CALL COUT
JP DCRLF
NTSC0:
ADD A,'0'
CALL COUT
JP DCRLF
;
TDX:
CALL LPAR
inc hl
ld e,(hl)
ld d,0
call prntde
call c,pdertn
; LD A,(HL)
; CALL PASHEX
; LD A,'H'
; CALL COUT
CALL COMMA
LD A,'X'
CALL COUT
CALL RPAR
JP DCRLF
;
TDY:
CALL LPAR
inc hl
ld e,(hl)
ld d,0
call prntde
call c,pdertn
; LD A,(HL)
; CALL PASHEX
; LD A,'H'
; CALL COUT
CALL RPAR
CALL COMMA
LD A,'Y'
CALL COUT
JP DCRLF
;
TDZX:
INC HL
LD A,(HL)
CALL PASHEX
LD A,'H'
CALL COUT
CALL COMMA
LD A,'X'
CALL COUT
JP DCRLF
;
TDZY:
INC HL
LD A,(HL)
CALL PASHEX
LD A,'H'
CALL COUT
CALL COMMA
LD A,'Y'
CALL COUT
JP DCRLF
;
twy: call prnn
push af
call comma
ld a,'Y'
call cout
pop af
call c,pdertn
jp dcrlf
;
twx: call prnn
push af
call comma
ld a,'X'
call cout
pop af
call c,pdertn
jp dcrlf
;
; zero page addresses
;
tdzp: inc hl
ld e,(hl)
ld d,0
call prntde
call c,pdertn
jp dcrlf
;
;OTHER RELATIVE INSTRUCTIONS
TF:
INC HL
LD A,(HL)
LD E,A
LD D,0
LD HL,(PC)
OR A
JP P,PSTV
DEC D
PSTV:
ADD HL,DE
EX DE,HL
CALL PRNTDE
CALL C,PDERTN
JP DCRLF
;
;JUMPS AND CALLS
T11:
CALL PRNN
CALL C,PDERTN
JP DCRLF
;
jpind: call dradr
call c,pdertn
jp dcrlf
;
DRADR:
CALL LPAR ;PRINT THE VALUE FOR DE IN PARENTHESIS
CALL PRNN
PUSH AF
CALL RPAR
POP AF
RET
;
;ALL UNDEFINED OPCODES COME HERE FOR A 'DB VALUE' TREATMENT
;
T2A:
LD HL,(BIASED)
CALL PSTG
DEFB 'DB',9,0
JP DTABYT
;
; VARIOUS CHARACTERS TO PRINT
;
COMMA:
LD A,','
JP COUT
TAB:
LD A,9
JP COUT
SEMI:
LD A,';'
JP COUT
LPAR:
LD A,'('
JP COUT
RPAR:
LD A,')'
JP COUT
PCMAA:
CALL COMMA
LD A,'A'
JP COUT
;
; PRINT THE CONDITION CODE LETTERS FOR THIS INSTRUCTION.
;
PRCND:
LD A,(HL)
AND 38H ;FOR A FULL SET OF CONDITION CODES
PRC:
RRCA
RRCA
LD HL,CNDTAB
CALL SKIP
LD A,(HL)
CALL COUT
INC HL
LD A,(HL)
CP '.'
CALL NZ,COUT
RET
PRCND1:
LD A,(HL)
AND 18H
JR PRC
CNDTAB:
DEFB 'NZZ.NCC.POPEP.M.'
;
; PRINT THE SOURCE REGISTER FOR A BYTE
;
PSREG:
LD A,(HL)
PREG:
LD HL,REGTAB
AND 7
CP 6 ;MUST CATCH THE (HL) REFERENCES
JP Z,PHLREG
CALL SKIP
LD A,(HL)
JP COUT
PHLREG:
CALL LPAR
LD A,'H'
CALL COUT
LD A,'L'
CALL COUT
JP RPAR
PDREG:
LD A,(HL) ;PRINT THE DESTINATION REGISTER FOR A BYTE
RRA
RRA
RRA
JP PREG
;
; ADVANCE H&L BY (A)
;
SKIP:
ADD A,L
LD L,A
RET NC
INC H
RET
REGTAB:
DEFB 'BCDEHLMA' ;'M' IS NEVER PRINTED - '(HL)' IS INSTEAD
;
; PRINT A DOUBLE REGISTER PAIR
;
PXSREG:
LD A,(HL)
LD HL,DREGS
JR PXREG
PXQREG:
LD A,(HL)
LD HL,DREGQ
PXREG:
RRA
RRA
RRA
AND 6
CALL SKIP
LD A,(HL)
CALL COUT
INC HL
LD A,(HL)
JP COUT
DREGS:
DEFB 'BCDEHLSP'
DREGQ:
DEFB 'BCDEHLAF'
IXREGS:
DEFB 'BCDEIXSP'
IYREGS:
DEFB 'BCDEIYSP'
;
PBIT:
LD A,(HL)
RRA
RRA
RRA
AND 7
ADD A,'0'
JP COUT
PRXX:
LD A,'I'
CALL COUT
LD A,E
JP COUT
;
;PRINT A LEADING QUOTE AND THEN THE ASCII
;.. (PRINT '' FOR ').
;
PASCII:
PUSH AF
LD A,''''
CALL COUT
POP AF
CP ''''
JP NZ,COUT
PUSH AF
CALL COUT
POP AF
JP COUT
;PRINT THE VALUE IN A AS HEX
; WITH A LEADING ZERO IF NECESSARY
PASHEX:
CP 0A0H
JP C,PHEX
PUSH AF
LD A,'0'
CALL COUT
POP AF
JP PHEX
;PRINT THE STRING AT (HL) FOR (B) CHARACTERS.
PRNT:
LD A,(HL)
CALL COUT
INC HL
DEC B
JP NZ,PRNT
RET
;
;PRINT A DISPLACEMENT IN THE FORM '(IX+d)'
PDISP:
CALL LPAR
CALL PRXX
LD A,'+'
CALL COUT
LD A,(HL)
CALL PASHEX
LD A,'H'
CALL COUT
JP RPAR
;
;PRINT THE NEXT 2 BYTES AS A SYMBOL (AND RETURN Cy=1) IF POSSIBLE
;
PRNN:
INC HL
LD E,(HL)
INC HL
LD D,(HL)
PRNTDE:
PUSH DE
CALL SYMSCH
JP C,NOMTCH
CALL PRNT ;GOT ONE, SO PRINT IT
POP DE
SCF ;INDICATE THAT A SYMBOL WAS PRINTED
RET
NOMTCH:
LD A,(BUILD) ;DO WE BUILD A SYMBOL?
OR A
POP DE
JR Z,NOBLD ;JUST PRINT THE HEX VALUE
PUSH DE
CALL BLDSYM
POP DE
JR NOBLD
PDERTN:
LD A,(XCSW)
OR A
RET Z ;DON'T PRINT THE SYMBOL AS A COMMENT
CALL TAB ;WE'LL PRINT A VALUE AS A COMMENT
CALL SEMI
NOBLD:
LD A,D
OR E
LD A,'0'
JR Z,NOBLD1
LD A,D
OR A
JR Z,NOBLD2
CALL PASHEX ;PRINT THE HIGH ORDER BYTE
LD A,E
CALL PHEX
NOBLD0:
LD A,'H'
NOBLD1:
CALL COUT
OR A ;CLEAR THE CARRY
RET
NOBLD2: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0B0h,03h,'BCS '
DEFB 0ffH,0F0h,03h,'BEQ '
DEFB 0ffH,030h,03h,'BMI '
DEFB 0ffH,0D0h,03h,'BNE '
DEFB 0ffH,010h,03h,'BPL '
DEFB 0ffH,050h,03h,'BVC '
DEFB 0ffH,070h,03h,'BVS '
DEFB 0ffH,06Dh,09h,'ADC '
DEFB 0ffH,02Dh,09h,'AND '
DEFB 0ffH,00Eh,09h,'ASL '
DEFB 0ffH,02Ch,09h,'BIT '
DEFB 0ffH,0CDh,09h,'CMP '
DEFB 0ffH,0ECh,09h,'CPX '
DEFB 0ffH,0CCh,09h,'CPY '
DEFB 0ffH,0CEh,09h,'DEC '
DEFB 0ffH,04Dh,09h,'EOR '
DEFB 0ffH,0EEh,09h,'INC '
DEFB 0ffH,04Ch,09h,'JMP '
DEFB 0ffH,020h,09h,'JSR '
DEFB 0ffH,0ADh,09h,'LDA '
DEFB 0ffH,0AEh,09h,'LDX '
DEFB 0ffH,0ACh,09h,'LDY '
DEFB 0ffH,04Eh,09h,'LSR '
DEFB 0ffH,00Dh,09h,'ORA '
DEFB 0ffH,02Eh,09h,'ROL '
DEFB 0ffH,06Eh,09h,'ROR '
DEFB 0ffH,0EDh,09h,'SBC '
DEFB 0ffH,08Dh,09h,'STA '
DEFB 0ffH,08Eh,09h,'STX '
DEFB 0ffH,08Ch,09h,'STY '
DEFB 0ffH,065h,08h,'ADC '
DEFB 0ffH,025h,08h,'AND '
DEFB 0ffH,006h,08h,'ASL '
DEFB 0ffH,024h,08h,'BIT '
DEFB 0ffH,0C5h,08h,'CMP '
DEFB 0ffH,0E4h,08h,'CPX '
DEFB 0ffH,0C4h,08h,'CPY '
DEFB 0ffH,0C6h,08h,'DEC '
DEFB 0ffH,045h,08h,'EOR '
DEFB 0ffH,0E6h,08h,'INC '
DEFB 0ffH,0A5h,08h,'LDA '
DEFB 0ffH,0A6h,08h,'LDX '
DEFB 0ffH,0A4h,08h,'LDY '
DEFB 0ffH,046h,08h,'LSR '
DEFB 0ffH,005h,08h,'ORA '
DEFB 0ffH,026h,08h,'ROL '
DEFB 0ffH,066h,08h,'ROR '
DEFB 0ffH,0E5h,08h,'SBC '
DEFB 0ffH,085h,08h,'STA '
DEFB 0ffH,086h,08h,'STX '
DEFB 0ffH,084h,08h,'STY '
DEFB 0ffH,075h,04h,'ADC '
DEFB 0ffH,07dh,0ah,'ADC '
DEFB 0ffH,079h,0bh,'ADC '
DEFB 0ffH,061h,05h,'ADC '
DEFB 0ffH,071h,06h,'ADC '
DEFB 0ffH,035h,04h,'AND '
DEFB 0ffH,03dh,0ah,'AND '
DEFB 0ffH,039h,0bh,'AND '
DEFB 0ffH,021h,05h,'AND '
DEFB 0ffH,031h,06h,'AND '
DEFB 0ffH,0d5h,04h,'CMP '
DEFB 0ffH,0ddh,0ah,'CMP '
DEFB 0ffH,0d9h,0bh,'CMP '
DEFB 0ffH,0c1h,05h,'CMP '
DEFB 0ffH,0d1h,06h,'CMP '
DEFB 0ffH,055h,04h,'EOR '
DEFB 0ffH,05dh,0ah,'EOR '
DEFB 0ffH,059h,0bh,'EOR '
DEFB 0ffH,041h,05h,'EOR '
DEFB 0ffH,051h,06h,'EOR '
DEFB 0ffH,0b5h,04h,'LDA '
DEFB 0ffH,0bdh,0ah,'LDA '
DEFB 0ffH,0b9h,0bh,'LDA '
DEFB 0ffH,0a1h,05h,'LDA '
DEFB 0ffH,0b1h,06h,'LDA '
DEFB 0ffH,015h,04h,'ORA '
DEFB 0ffH,01dh,0ah,'ORA '
DEFB 0ffH,019h,0bh,'ORA '
DEFB 0ffH,001h,05h,'ORA '
DEFB 0ffH,011h,06h,'ORA '
DEFB 0ffH,0f5h,04h,'SBC '
DEFB 0ffH,0fdh,0ah,'SBC '
DEFB 0ffH,0f9h,0bh,'SBC '
DEFB 0ffH,0e1h,05h,'SBC '
DEFB 0ffH,0f1h,06h,'SBC '
DEFB 0ffH,095h,04h,'STA '
DEFB 0ffH,09dh,0ah,'STA '
DEFB 0ffH,099h,0bh,'STA '
DEFB 0ffH,081h,05h,'STA '
DEFB 0ffH,091h,06h,'STA '
DEFB 0ffH,016h,04h,'ASL '
DEFB 0ffH,01eh,0ah,'ASL '
DEFB 0ffH,0d6h,04h,'DEC '
DEFB 0ffH,0deh,0ah,'DEC '
DEFB 0ffH,0f6h,04h,'INC '
DEFB 0ffH,0feh,0ah,'INC '
DEFB 0ffH,0b6h,04h,'LDX '
DEFB 0ffH,0beh,0ah,'LDX '
DEFB 0ffH,0b4h,04h,'LDY '
DEFB 0ffH,0bch,0ah,'LDY '
DEFB 0ffH,056h,04h,'LSR '
DEFB 0ffH,05eh,0ah,'LSR '
DEFB 0ffH,036h,04h,'ROL '
DEFB 0ffH,03eh,0ah,'ROL '
DEFB 0ffH,076h,04h,'ROR '
DEFB 0ffH,07eh,0ah,'ROR '
DEFB 0ffH,096h,07h,'STX '
DEFB 0ffH,094h,04h,'STY '
DEFB 0FFH,06CH,0cH,'JMP '
DEFB 080H,000h,01h,0,0
DEFB 080H,080h,01H,0,0
;
; END OF OPCODE TABLE
;