summaryrefslogtreecommitdiff
path: root/z80.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-08-21 00:01:01 +0000
committerIan C <ianc@noddybox.co.uk>2006-08-21 00:01:01 +0000
commit65c818acf64915aa6b1de12774abab855cb6437b (patch)
treec4d2ab06375f3591fe84958c0789959c86d388fa /z80.c
parentf295f65db435ab7cb384e44e1dd74dc6d7a34853 (diff)
Added disassembler
Diffstat (limited to 'z80.c')
-rw-r--r--z80.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/z80.c b/z80.c
index 11e466b..0b74bf5 100644
--- a/z80.c
+++ b/z80.c
@@ -29,6 +29,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include "z80.h"
#include "z80_private.h"
@@ -310,13 +311,32 @@ Z80Val Z80Cycles(Z80 *cpu)
}
-const char *Z80Disassemble(Z80 *cpu, Z80Word *addr)
+const char *Z80Disassemble(Z80 *cpu, Z80Word *pc)
{
-#ifdef Z80_DISASSEMBLER_ENABLED
- (*addr)+=4;
- return "NO DISASSEMBLER";
+#ifdef ENABLE_DISASSEM
+ static char s[80];
+ Z80Word opc,npc;
+ Z80Byte op;
+ int f;
+
+ opc=*pc;
+ op=Z80_Dis_FetchByte(cpu,pc);
+ dis_opcode_z80[op](cpu,op,pc);
+ npc=*pc;
+
+ strcpy(s,Z80_Dis_Printf("%-5s",Z80_Dis_GetOp()));
+ strcat(s,Z80_Dis_Printf("%-40s ;",Z80_Dis_GetArg()));
+
+ for(f=0;f<5 && opc!=npc;f++)
+ strcat(s,Z80_Dis_Printf(" %.2x",(int)cpu->memory[opc++]));
+
+ if (opc!=npc)
+ for(f=1;f<3;f++)
+ s[strlen(s)-f]='.';
+
+ return s;
#else
- (*addr)+=4;
+ (*pc)+=4;
return "NO DISASSEMBLER";
#endif
}