1 ; This code is been found in a ZX Spectrum tool called UTILITY3 v1.3
5 ;; emit routine should preserve all registers except AF and HL
18 DISASM_USE_HEX_PREFIX equ 1
19 ; Einar Saukas' optimisation, cut 2 bytes
20 DISASM_EINAR_OPTIMISATION equ 1
22 ; ====================
23 ; DIS-Z80 was published in the SUBSET column of Personal Computer World 1987.
24 ; The routine disassembles a single Z80 instruction at address DE.
25 ; It is required to be followed by a routine called CHROP that outputs a
26 ; single ASCII character.
27 ; It was originally developed for CP/M on an Amstrad CPC128.
29 ; The original ORG was $0100. I have added $5000 to all addresses.
30 ; The stated aim was to write a Z80 disassembly routine in as short a space
31 ; as possible and, at just over 1K (1090 bytes), it is a rather incredible
34 ; The SUBSET editor David Barrow was able to trim only one byte from John
35 ; Kerr's compact code. I've forgotten where so there's a challenge.
37 ; k8: sadly, i had to add some mode code, so it is 1101 bytes now
38 ; (including `EMIT_CB` variable)
39 ; or 1099 bytes with Einar's optimisation ;-)
42 ; DE: address to disasm from
44 ; DE: addres of the next instruction
46 ; ====================
234 ;***********************
238 defb $04,$80,$2D,$C0,$BE
239 defb $FF,$F8,$06,$00,$33
240 defb $08,$38,$10,$35,$18
241 defb $3A,$20,$3F,$28,$40
247 defb $24,$07,$32,$0F,$37
248 defb $17,$31,$1F,$36,$27
249 defb $0D,$2F,$0B,$37,$3D
250 defb $3F,$06,$76,$14,$C9
251 defb $30,$D9,$12,$F3,$0F
252 defb $FB,$91,$72,$C6,$02
253 defb $CE,$01,$de,$bc,$02
254 defb $D6,$42,$E6,$03,$EE
255 defb $43,$F6,$25,$FE,$8C
256 defb $04,$08,$93,$01,$10
257 defb $10,$18,$9D,$af,$22
258 defb $A2,$FA,$2A,$A2,$A7
259 defb $32,$A2,$7A,$3A,$A2
260 defb $03,$C3,$1C,$CD,$85
261 defb $97,$D3,$AA,$79,$db
262 defb $9B,$5F,$E3,$93,$0E
263 defb $E9,$9C,$05,$EB,$93
264 defb $DF,$F9,$A2,$FF,$C0
265 defb $B6,$40,$A2,$FF,$F8
266 defb $76,$80,$02,$88,$01
267 defb $98,$bc,$06,$90,$42
268 defb $A0,$03,$A8,$43,$B0
269 defb $25,$B8,$8C,$FF,$C7
270 defb $0B,$04,$16,$05,$8E
271 defb $B2,$06,$A2,$20,$C0
272 defb $B0,$23,$C2,$1C,$C4
273 defb $85,$10,$C7,$BB,$FF
274 defb $CF,$D3,$01,$A2,$0D
275 defb $03,$16,$0B,$8E,$FD
276 defb $09,$82,$60,$C1,$2B
277 defb $C5,$AC,$FF,$E7,$21
278 defb $20,$9D,$FF,$EF,$E7
279 defb $02,$A2,$7E,$0A,$A2
284 defb $23,$45,$2F,$4D,$2E
285 defb $4E,$00,$67,$39,$6F
286 defb $34,$70,$00,$71,$00
287 defb $A0,$21,$A1,$0A,$A2
288 defb $1A,$A3,$29,$A8,$1F
289 defb $A9,$08,$AA,$18,$AB
290 defb $28,$B0,$20,$B1,$09
291 defb $B2,$19,$B3,$27,$B8
292 defb $1E,$B9,$07,$BA,$17
293 defb $BB,$A6,$FF,$C7,$B8
294 defb $40,$9B,$8B,$41,$AA
295 defb $FF,$CF,$FD,$42,$3C
296 defb $4A,$81,$AD,$43,$A2
297 defb $DA,$4B,$A2,$FF,$E7
298 defb $40,$46,$95,$FF,$F7
299 defb $C7,$47,$A2,$7C,$57
306 defb 'A','D','C'+$80 ; ADC
307 defb 'A','D','D'+$80 ; ADD
308 defb 'A','N','D'+$80 ; AND
309 defb 'B','I','T'+$80 ; BIT
310 defb 'C','A','L','L'+$80 ; CALL
311 defb 'C','C','F'+$80 ; CCF
312 defb 'C','P','D','R'+$80 ; CPDR
313 defb 'C','P','D'+$80 ; CPD
314 defb 'C','P','I','R'+$80 ; CPIR
315 defb 'C','P','I'+$80 ; CPI
316 defb 'C','P','L'+$80 ; CPL
317 defb 'C','P'+$80 ; CP
318 defb 'D','A','A'+$80 ; DAA
319 defb 'D','E','C'+$80 ; DEC
320 defb 'D','I'+$80 ; DI
321 defb 'D','J','N','Z'+$80 ; DJNZ
322 defb 'E','I'+$80 ; EI
323 defb 'E','X','X'+$80 ; EXX
324 defb 'E','X'+$80 ; EX
325 defb 'H','A','L','T'+$80 ; HALT
326 defb 'I','M'+$80 ; IM
327 defb 'I','N','C'+$80 ; INC
328 defb 'I','N','D','R'+$80 ; INDR
329 defb 'I','N','D'+$80 ; IND
330 defb 'I','N','I','R'+$80 ; INIR
331 defb 'I','N','I'+$80 ; INI
332 defb 'I','N'+$80 ; IN
333 defb 'J','P'+$80 ; JP
334 defb 'J','R'+$80 ; JR
335 defb 'L','D','D','R'+$80 ; LDDR
336 defb 'L','D','D'+$80 ; LDD
337 defb 'L','D','I','R'+$80 ; LDIR
338 defb 'L','D','I'+$80 ; LDI
339 defb 'L','D'+$80 ; LD
340 defb 'N','E','G'+$80 ; NEG
341 defb 'N','O','P'+$80 ; NOP
342 defb 'O','R'+$80 ; OR
343 defb 'O','T','D','R'+$80 ; OTDR
344 defb 'O','T','I','R'+$80 ; OTIR
345 defb 'O','U','T','D'+$80 ; OUTD
346 defb 'O','U','T','I'+$80 ; OUTI
347 defb 'O','U','T'+$80 ; OUT
348 defb 'P','O','P'+$80 ; POP
349 defb 'P','U','S','H'+$80 ; PUSH
350 defb 'R','E','S'+$80 ; RES
351 defb 'R','E','T','I'+$80 ; RETI
352 defb 'R','E','T','N'+$80 ; RETN
353 defb 'R','E','T'+$80 ; RET
354 defb 'R','L','A'+$80 ; RLA
355 defb 'R','L','C','A'+$80 ; RLCA
356 defb 'R','L','C'+$80 ; RLC
357 defb 'R','L','D'+$80 ; RLD
358 defb 'R','L'+$80 ; RL
359 defb 'R','R','A'+$80 ; RRA
360 defb 'R','R','C','A'+$80 ; RA
361 defb 'R','R','C'+$80 ; RRC
362 defb 'R','R','D'+$80 ; RRD
363 defb 'R','R'+$80 ; RR
364 defb 'R','S','T'+$80 ; RST
365 defb 'S','B','C'+$80 ; SBC
366 defb 'S','C','F'+$80 ; SCF
367 defb 'S','E','T'+$80 ; SET
368 defb 'S','L','A'+$80 ; SLA
369 defb 'S','R','A'+$80 ; SRA
370 defb 'S','R','L'+$80 ; SRL
371 defb 'S','U','B'+$80 ; SUB
372 defb 'X','O','R'+$80 ; XOR
447 $IF !DISASM_USE_HEX_PREFIX
459 $IF !DISASM_USE_HEX_PREFIX
530 $IF DISASM_USE_HEX_PREFIX
629 defb '(','C',')' +$80
633 defb 'A','F',',','A','F','\'' +$80
634 defb 'D','E',',','H','L' +$80
642 defb '(','S','P',')' +$80
656 ;********************
659 $IF !DISASM_USE_HEX_PREFIX
714 ; convert nibble (low 4 bits of A) to hexadecimal digit
716 ; OUT: A: digit ready to print
728 $IF DISASM_EINAR_OPTIMISATION
799 ; -----------------------------------
800 ; End of John Kerr's DIS-Z80 routine.
801 ; -------------------------------------
802 dissizest = $-dissizest
803 $printf "disasm size: %d bytes", dissizest
804 dissizest = -1 ; so it won't clutter symbol table