changeset 597:8d6ae5b3b87b

Update code->cur before calling z80_get_address_trans in z80_retranslate_inst to avoid any newly translated instructions from being placed in the "buffer zone". Save the current value of the code_info struct for placing the final jmp instruction in the correct place
author Michael Pavone <pavone@retrodev.com>
date Fri, 26 Dec 2014 12:52:13 -0800
parents 9853bcce4729
children faad1927d836
files z80_to_x86.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/z80_to_x86.c	Fri Dec 26 12:37:27 2014 -0800
+++ b/z80_to_x86.c	Fri Dec 26 12:52:13 2014 -0800
@@ -1779,6 +1779,7 @@
 	}
 	#endif
 	if (orig_size != ZMAX_NATIVE_SIZE) {
+		check_alloc_code(code, ZMAX_NATIVE_SIZE);
 		code_ptr start = code->cur;
 		deferred_addr * orig_deferred = opts->gen.deferred;
 		translate_z80inst(&instbuf, context, address);
@@ -1802,10 +1803,11 @@
 		z80_map_native_address(context, address, start, after-inst, ZMAX_NATIVE_SIZE);
 		code_info tmp_code = {orig_start, orig_start + 16};
 		jmp(&tmp_code, start);
+		tmp_code = *code;
+		code->cur = start + ZMAX_NATIVE_SIZE;
 		if (!z80_is_terminal(&instbuf)) {
-			jmp(code, z80_get_native_address_trans(context, address + after-inst));
+			jmp(&tmp_code, z80_get_native_address_trans(context, address + after-inst));
 		}
-		code->cur = start + ZMAX_NATIVE_SIZE;
 		z80_handle_deferred(context);
 		return start;
 	} else {