changeset 313:a13329645ea3

Fix terminal instruction detection in disassembler
author Mike Pavone <pavone@retrodev.com>
date Thu, 09 May 2013 19:24:18 -0700
parents cf7ecda060c7
children 54c0e5f22198
files z80_to_x86.c z80inst.c z80inst.h zdis.c
diffstat 4 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/z80_to_x86.c	Thu May 09 18:36:21 2013 -0700
+++ b/z80_to_x86.c	Thu May 09 19:24:18 2013 -0700
@@ -15,7 +15,7 @@
 #define SCRATCH2 R14
 #define CONTEXT RSI
 
-//#define DO_DEBUG_PRINT
+#define DO_DEBUG_PRINT
 
 #ifdef DO_DEBUG_PRINT
 #define dprintf printf
@@ -1633,12 +1633,6 @@
 	return dst;
 }
 
-uint8_t z80_is_terminal(z80inst * inst)
-{
-	return inst->op == Z80_RET || inst->op == Z80_RETI || inst->op == Z80_RETN || inst->op == Z80_JP
-		|| inst->op == Z80_JR || inst->op == Z80_HALT || (inst->op == Z80_NOP && inst->immed == 42);
-}
-
 uint8_t * z80_get_native_address(z80_context * context, uint32_t address)
 {
 	native_map_slot *map;
@@ -1649,14 +1643,14 @@
 		address &= 0x7FFF;
 		map = context->banked_code_map + context->bank_reg;
 	} else {
-		dprintf("z80_get_native_address: %X NULL\n", address);
+		//dprintf("z80_get_native_address: %X NULL\n", address);
 		return NULL;
 	}
 	if (!map->base || !map->offsets || map->offsets[address] == INVALID_OFFSET || map->offsets[address] == EXTENSION_WORD) {
-		dprintf("z80_get_native_address: %X NULL\n", address);
+		//dprintf("z80_get_native_address: %X NULL\n", address);
 		return NULL;
 	}
-	dprintf("z80_get_native_address: %X %p\n", address, map->base + map->offsets[address]);
+	//dprintf("z80_get_native_address: %X %p\n", address, map->base + map->offsets[address]);
 	return map->base + map->offsets[address];
 }
 
--- a/z80inst.c	Thu May 09 18:36:21 2013 -0700
+++ b/z80inst.c	Thu May 09 19:24:18 2013 -0700
@@ -1531,4 +1531,11 @@
 	}
 }
 
+uint8_t z80_is_terminal(z80inst * inst)
+{
+	return inst->op == Z80_RET || inst->op == Z80_RETI || inst->op == Z80_RETN || inst->op == Z80_JP
+		|| inst->op == Z80_JR || inst->op == Z80_HALT || (inst->op == Z80_NOP && inst->immed == 42);
+}
 
+
+
--- a/z80inst.h	Thu May 09 18:36:21 2013 -0700
+++ b/z80inst.h	Thu May 09 19:24:18 2013 -0700
@@ -135,6 +135,7 @@
 uint8_t z80_high_reg(uint8_t reg);
 uint8_t z80_low_reg(uint8_t reg);
 uint8_t z80_word_reg(uint8_t reg);
+uint8_t z80_is_terminal(z80inst * inst);
 
 #endif //Z80INST_H_
 
--- a/zdis.c	Thu May 09 18:36:21 2013 -0700
+++ b/zdis.c	Thu May 09 19:24:18 2013 -0700
@@ -135,9 +135,6 @@
 			
 			//z80_disasm(&instbuf, disbuf);
 			//printf("%X: %s\n", address, disbuf);
-			if (instbuf.op == Z80_HALT || instbuf.op == Z80_RET || instbuf.op == Z80_RETI || instbuf.op == Z80_RETN || instbuf.op == Z80_RST) {
-				break;
-			}
 			switch (instbuf.op)
 			{
 			case Z80_JR:
@@ -155,9 +152,14 @@
 			case Z80_JPCC:
 			case Z80_CALL:
 			case Z80_CALLCC:
+			case Z80_RST:
 				reference(instbuf.immed);
 				def = defer(instbuf.immed, def);
 				break;
+			default:
+				if (z80_is_terminal(&instbuf)) {
+					address = filesize + 1;
+				}
 			}
 		}
 	}