Source file: /~heha/basteln/8bit/KC85/kcemu/kcemusrc.zip/DISASM.ASM

;Disassembler nach %REAS
	IDEAL
	MODEL	small,pascal
	P286
	warn pro	;Protected-Mode-Fehler anmeckern

public LCode,Reas
extrn MemKCSel:Word, PutHexW:near, PutHexB:near

CODESEG
;Maske - Mnemonik - Terminator (-1)
	db	6ah,3ah,39h,06h,66h,35h
MMT_Ohne:
	db	-1,0
	db	10h,22h,32h,27h,37h,08h,18h,2ah
	db	3ah,2fh,3fh,76h,0c3h,0d3h,0e3h,0f3h,0c9h
	db	0d9h,0e9h,0f9h,0dbh,0ebh,0fbh,0cdh,-1
	db	0cfh,1h,2h,3h,9h,0ah,0bh,0c1h,0c5h,-1
	db	0c7h,0h,4h,5h,6h,0c0h,0c2h,0c4h,0c6h,-1
MMT_CB:
	db	0c0h,0h,40h,80h,0c0h
MMT_ED:
	db	-1,70h,71h,47h,57h,67h,4dh,4fh,5fh,6fh,-1
	db	0cfh,42h,43h,4ah,4bh,-1
	db	0c7h,40h,41h,44h,45h,-1
	db	0e7h,0a0h,0a1h,0a2h,-1
	db	0f7h,0b3h,0a3h,-1
	db	0d7h,46h,-1
	db	0dfh,56h,5eh,-1
	db	0,0

addy=0		;Zeichen-Addierwert
last=-1000	;Ungültiger Startwert
counter=-1	;Laufender DEFS-Zähler

macro POKE value
 if last NE -1000
	db	last
 endif
last=value
endm

macro DEFS str:rest
 addy=128		;;Erstes Zeichen mit gesetztem Bit 7
 irp arg,<str>		;;Mit jedem Argument der Liste tue...
  irpc c,<arg>  	;;Mit jedem Zeichen des Arguments tue...
   if addy AND 127	;;Mitten in Zeichenersetzung?
    ifidn <c>,< >	;;Leerzeichen (nie zuerst!)?
     last=last+26	;;LAST korrigieren
    elseifidn <c>,<'>	;;Abschließendes Hochkomma?
     exitm		;;Zeichen-Schleife verlassen
    else
     POKE %('&c'+addy)
    endif
    addy=11		;;Bit7 löschen nach erstem Zeichen
   elseifidn <c>,<'>	;;Stringanfang?
    addy=addy+11	;;InString setzen
   else
    POKE %(arg+addy)
    exitm		;;Zeichen-Schleife verlassen
   endif
  endm
addy=0			;;Nächstes Argument ohne Bit7
 endm
 POKE -1000		;;Letztes Byte schreiben
 counter=counter+1	;;Aufrufe mitzählen
endm

BMNE:	DEFS	'LD '		;0
	DEFS	'RET'		;1
	DEFS	'NOP'		;2
	DEFS	'OUT '		;3
	DEFS	'INC '		;4
	DEFS	'DEC '		;5
	DEFS	'(',26h,')'	;6 (nn)
	DEFS	'(',1fh,')'	;7 (dd)
	DEFS	31,','		;8 nn,
	DEFS	',',31		;9 ,nn
	DEFS	'A,'		;10
	DEFS	',A'		;11
	DEFS	28h,',',29h	;12 b,r
	DEFS	'ADD '		;13 ari_
	DEFS	'ADC '
	DEFS	'SUB '
	DEFS	'SBC '
	DEFS	'AND '
	DEFS	'X',19
	DEFS	'OR '
	DEFS	'CP '
	DEFS	22		;21 BC
	DEFS	'BC'		;22
	DEFS	24		;23 DE
	DEFS	'DE'		;24
	DEFS	26		;25 HL
	DEFS	'HL'		;26
	DEFS	'AF'		;27
	DEFS	'SP'		;28

	DEFS	'RLC'		;29 rot
	DEFS	'RRC'
	DEFS	'RL'
	DEFS	'RR'
	DEFS	'SLA'
	DEFS	'SRA
	DEFS	'SLS'
	DEFS	'SRL'
	DEFS	'B'		;37 r
	DEFS	'C'
	DEFS	'D'
	DEFS	'E'
	DEFS	'H'
	DEFS	'L'
AppXY:	DEFS	'M'
	DEFS	'A'
	DEFS	'NZ '		;45 cc
	DEFS	'Z '
	DEFS	'NC '
	DEFS	'C '
	DEFS	'PO '
	DEFS	'PE '
	DEFS	'P '
	DEFS	'M '
	DEFS	'I'		;53 blo
	DEFS	'D'
	DEFS	'IR'
	DEFS	'DR'
	DEFS	'(',26,'+',37,')'	;(IX+d)
HashBasis_Ohne=counter
	DEFS	2		;NOP
	DEFS	'DJNZ ',27h
	DEFS	0,6,9		;LD (nn),HL
	DEFS	0,6,11		;LD (nn),A
	DEFS	'DAA'
	DEFS	'SCF'
	DEFS	'EXAF'
	DEFS	'JR ',27h
	DEFS	0,8,6		;LD HL,(nn)
	DEFS	0,0ah,6		;LD A,(nn)
	DEFS	'CPL'
	DEFS	'CCF'
	DEFS	'HALT'
	DEFS	'JMP ',26h
	DEFS	3,25h		;OUT n
	DEFS	'EX (',1ch,')',9	;EX (SP),HL
	DEFS	'DI'
	DEFS	1		;RET
	DEFS	'EXX'
	DEFS	'JMP ',7	;JMP (HL)
	DEFS	0,8,1ah		;LD SP,HL
	DEFS	'IN ',25h
	DEFS	'EX ',18h,',HL'	;EX DE,HL; Umstand wegen IX/IY
	DEFS	'EI'
	DEFS	'CALL ',26h
	DEFS	0,8,26h		;LD dd,nn
	DEFS	0,7,0bh		;LD (dd),A
	DEFS	4,1fh		;INC dd
	DEFS	0dh,1ah,9	;ADD HL,dd
	DEFS	0,0ah,7		;LD A,(dd)
	DEFS	5,1fh		;DEC dd
	DEFS	'POP ',1eh	;POP qq
	DEFS	'PUSH ',1eh	;PUSH qq
	DEFS	'J',23h,27h	;Jcc e
	DEFS	4,21h		;INC r
	DEFS	5,21h		;DEC r
	DEFS	0,21h,',',25h	;LD r,n
	DEFS	'R',22h		;Rcc
	DEFS	'JP',22h,26h	;JPcc nn
	DEFS	'CA',22h,26h	;CAcc nn
	DEFS	1dh,25h		;ADD..CP n
	DEFS	20h,'A'		;RLCA..RRA
	DEFS	0,21h,',',29h	;LD r,r
	DEFS	1dh,29h		;ADD..CP r
	DEFS	'RST',28h	;RSTp
HashBasis_CB=counter
	DEFS	20h,2bh,29h,2ah	;RLC...SRL r
	DEFS	'BIT ',0ch
	DEFS	'RES ',0ch,2ah
	DEFS	'SET ',0ch,2ah
HashBasis_ED=counter
	DEFS	'INF'
	DEFS	'OTCL'
	DEFS	0,'I',0bh	;LD I,A
	DEFS	0,0ah,'I'	;LD A,I
	DEFS	'RRD'
	DEFS	1,'I'		;RETI
	DEFS	0,'R',0bh	;LD R,A
	DEFS	0,0ah,'R'	;LD A,R
	DEFS	'R',0		;RLD
	DEFS	10h,1ah,9	;SBC HL,dd
	DEFS	0,6,9		;LD (nn),dd
	DEFS	0eh,1ah,9	;ADC AL,dd
	DEFS	0,8,6		;LD dd,(nn)
	DEFS	'IN ',21h
	DEFS	3,21h		;OUT r
	DEFS	'NEG'
	DEFS	1,'N'		;RETN
	DEFS	'LD',24h	;LDI...LDDR
	DEFS	'CP',24h	;CPI...CPDR
	DEFS	'IN',24h	;INI
	DEFS	'OT',24h	;OTIR/OTDR
	DEFS	'OUT',24h	;OUTI/OUTD
	DEFS	'IM0'
	DEFS	'IM1'
	DEFS	'IM2'
	DEFS	2		;NOP
HashBasis_Asm=counter
	DEFS	'DB ',25h	;für den Assembler
	DEFS	'DW ',26h	;für den Assembler
	db	80h		;Abschluß

proc Reas
arg mc:far ptr byte, asm:far ptr byte
;Register: DS:BX=Source-Zeiger, CS:SI=Tabellen-Zeiger
;AL oder AH: Opcode, ES:DI=Ausgabe-Stringzeiger
;CH=Z80:LY, DH=Z80:B, DL=Z80:C
;DL Bit7: DD+CB, Bit6: (IX+d), Bit2: Ausgaberoutine für (IX+d),
;Bit 1: DD/FD-Präfix, Bit0: FD-Präfix
	push	ds
	cld
	mov	dx,HashBasis_Ohne*256	;DH=Hashindex-1
	lds	bx,[mc]
	les	di,[asm]
	mov	si,offset MMT_Ohne
@@l:	mov	al,[bx]
	cmp	al,0ddh
	jnz	@@ndd
	mov	dl,2
	inc	bx
	jmp	@@l
@@ndd:
	cmp	al,0fdh
	jnz	@@nfd
	mov	dl,3
	inc	bx
	jmp	@@l
@@nfd:
	cmp	al,0cbh
	jnz	@@ncb
	mov	si,offset MMT_CB
	mov	dh,HashBasis_CB	;Anderer Hashindex-1
	test	dl,2		;IX/IY?
	jz	@@zbyte
	or	dl,80h		;für Sonderbehandlung
	inc	bx		;d übergehen
	jmp	@@zbyte
@@ncb:
	cmp	al,0edh
	jnz	@@such
	mov	si,offset MMT_ED
	mov	dx,HashBasis_ED*256 ;Anderer Hashindex-1, kein IX/IY!
@@zbyte:inc	bx
@@such:	mov	ch,[bx]		;Eigentlichen Opcode laden
	segcs	lodsb		;Maske laden
	and	ch,al		;Maskiertes Byte
@@cmp:	segcs	lodsb		;Vergleichsbyte
	cmp	al,-1		;Ende?
	jz	@@such		;ja-Opcode neu maskieren
	inc	dh		;Nächster Hash
	cmp	al,ch		;Gefunden?
	jnz	@@cmp		;nein, weitersuchen
	mov	al,[bx]		;Opcode laden
	inc	bx
	mov	ch,al
	ror	al,3
	and	al,7
	xchg	al,dh
;Aufruf mit BX=Codezeiger, DH=Registernummer (Bits 5,4,3) in (2,1,0),
;CH=Opcode, AL=Hashindex, DL=Flags
	call	pla
	pop	ds
	ret
endp

proc pria
;PE: ES:DI=Ausgabezeiger, CL=Druckzeichen bis Tab
	cmp	al,2bh
	jc	macro_exp
	sub	al,11
	cmp	al,' '
	jz	@@tabu
	cmp	al,')'
	jnz	@@prih
	and	ch,not 4	;IX+d abschließen
@@prih:	cmp	al,5bh
	jc	@@pra
	sub	al,1ah
	stosb
@@tabu:	mov	di,[bp+4]
	add	di,5
	ret
@@pra:	stosb
	ret
endp

proc macro_exp
	cmp	al,1dh		;Festes Makro?
	jc	pla		;ja
	cmp	al,25h		;Ziffernmakros?
	jnc	@@ma		;ja
	cmp	al,1fh		;2-bit variable Textmakros? (??)
	jc	@@m2		;ja
	jnz	@@m1		;nein
	or	dh,1		;auch, aber dd statt qq
@@m1:	dec	al
	cmp	al,22h		;c (Relativsprünge) oder blo (Block-Suffix)
	jc	@@m2		;nein, 3 gültige Bits
	and	dh,3		;2 Bits bleiben gültig
	dec	al
@@m2:	shl	al,3
	add	al,13-(1dh*8)	;Variable Textmakros beginnen ab Hash 13
@@m21:	add	al,dh
;Unterprogramm-Einsprung
pla:	test	dl,3		;IX/IY?
	jz	@@nm		;nein
	cmp	al,1ah		;Hash 1A (HL)?
	jnz	@@nhl		;nein
	mov	al,'I'
	stosb
@@xy:	mov	al,dl
	and	al,1
	add	al,'X'
	stosb
	ret
@@ma:	;Ziffernmakro (n,nn,e,b,r',r'cb) expandieren
	sub	al,25h		;nullbasiert
	cbw
	add	ax,ax		;*2
	xchg	si,ax
	mov	al,dh		;Ziffer des Interesses
	test	dl,80h		;DD+CB-Flag? NZ!
	jmp	[cs:@@mac+si]
@@mac	dw	@@n,@@nn,@@e,@@b,@@re,@@r1

@@re:	;r' (Quell-Register)
	jnz	@@me		;wenn DD+CB
@@ra:	mov	al,ch		;Opcode laden
	and	al,7		;Quell-Register
	mov	dh,al
	mov	al,25h
	jmp	@@m21
@@r1:	;r1
	jz	@@ret		;wenn kein DD+CB: nichts ausgeben! (??)
	and	al,7		;Opcode (Kopie von CH)
	cmp	al,6		;M als Registerkodierung?
	jnz	@@hm
	test	dl,40h		;(IX+d) (??)
	jnz	@@ret
@@hm:	mov	al,','
	stosb
	jmp	@@ra
@@nhl:	;(Doppel)Registerausgabe (mit Vorbyte DD/FD)
	cmp	al,2bh		;M?
	jnz	@@nm		;Keine Ersetzung
@@me:	or	dl,44h		;Ausgabe von (IX+d) erfolgt nun
	mov	al,39h		;Hash dafür
	test	dl,80h		;DD+CB?
	jz	@@nm		;nein
	sub	bx,2		;damit d richtig geholt wird
	call	@@nm
	inc	bx
@@ret:	ret
@@nm:	;Hash suchen (PE: AL=Hash-Index (0=erster))
	mov	cl,al
	inc	cl
	mov	si,offset bmne	;Tabellen-Start
@@sch:	segcs	lodsb		;Byte holen
	or	al,al		;Bit7 (Anfangskennung) gesetzt?
	jns	@@sch		;nein, nicht mitzählen
	dec	cl		;ja, mitzählen
	jnz	@@sch		;bis 0
@@prst:	and	al,7fh
@@prsl:	push	si		;Tabellenzeiger behalten
	 call	pria		;Ausgeben, ggf. Rekursion
	pop	si
	segcs	lodsb		;Nächstes Byte
	or	al,al		;Bit7 gesetzt? (wäre Anfang nächster Eintrag)
	jns	@@prsl		;nein, weiter ausgeben
	test	dl,3		;IX/IY?
	jz	@@ret		;nein
	test	dl,40h		;(IX+d) bereits aufgetreten?
	jnz	@@ret		;ja
	sub	si,offset AppXY	;Untersuchung auf Ausgaben von L und H
	and	si,not 1
	jnz	@@ret		;nein
	mov	al,ch		;Opcode laden
	and	al,0C7h
	cmp	al,46h
	jz	@@ret
	jmp	@@xy
@@n:	;Hexzahl n
	mov	al,[bx]
	inc	bx
	test	dl,4		;Ausgabe (IX+d) läuft?
	jz	@@n1		;nein, immer positives Byte
	or	al,al		;Negativ?
	jns	@@n1		;bleibt so
	neg	al
	mov	[byte es:di-1],'-'	;Minus patchen
@@n1:	jmp	puthexb		;Byte ausgeben

@@nn:	;Hexzahl nn oder Absolutsprung
	mov	ax,[bx]
	add	bx,2
@@ph:	jmp	puthexw
@@e:	;Relativsprung
	mov	al,[bx]
	inc	bx
	cbw
	add	ax,bx
	jmp	@@ph
@@b:	;Bit-Nummer
	add	al,'0'
	stosb
	ret
endp

;**************************************************
proc LCode
arg adr: far ptr byte
	les	si,[adr]
	xor	cx,cx
	jmp	@@w
@@ed:
	seges	lodsb
	inc	cl
	and	al,0c7h
	cmp	al,43h
	jnz	@@ex
	jmp	@@exi2
@@cb:
	test	ch,80h		;mit IX/IY?
	jz	@@exi
	jmp	@@exi2

@@ix:	or	ch,80h		;merken: IX/IY (statt M: noch ein Byte)
@@w:
	seges	lodsb
	inc	cl
	mov	ah,al
	cmp	al,0edh
	jz	@@ed
	cmp	al,0ddh
	jz	@@ix
	cmp	al,0fdh
	jz	@@ix
	cmp	al,0cbh
	jz	@@cb
;normaler Opcode:
	cmp	al,0cdh
	jz	@@exi2
	cmp	al,0c3h
	jz	@@exi2
	and	al,0e7h
	cmp	al,22h
	mov	al,ah
	jz	@@exi2
	and	al,0cfh
	cmp	al,1
	jz	@@exi2
	and	al,0c7h
	jz	@@ew
	cmp	al,0c2h
	jz	@@exi
	cmp	al,0c4h
	jz	@@exi
	cmp	al,6
	jz	@@exi
	cmp	al,0c6h
	jz	@@exi
	mov	al,ah
	and	al,0f7h
	cmp	al,0d3h
	jz	@@exi
	jmp	@@ex
@@ew:	;Extrawurst?
	mov	al,ah
	cmp	al,9
	jc	@@ex
	jmp	@@exi

@@exi2:	inc	cl
@@exi:	inc	cl
@@ex:	mov	al,cl
	cbw
	ret
endp

	END
Detected encoding: OEM (CP437)1
Wrong umlauts? - Assume file is ANSI (CP1252) encoded