changeset 2232:0c42982dd4d8

Make sure 68K interrupt is executed immediately when resuming core if it has a target cycle <= current. Fixes IRQ tests in mcd-verificator
author Michael Pavone <pavone@retrodev.com>
date Thu, 08 Sep 2022 20:50:18 -0700
parents 8e6fb2c06024
children 54cd40fc0da5
files m68k_core_x86.c
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/m68k_core_x86.c	Thu Sep 08 18:56:34 2022 -0700
+++ b/m68k_core_x86.c	Thu Sep 08 20:50:18 2022 -0700
@@ -2991,10 +2991,13 @@
 	*code = tmp_code;
 
 	opts->gen.handle_cycle_limit_int = code->cur;
-	//calculate stack adjust size
-	add_ir(code, 16-sizeof(void*), RSP, SZ_PTR);
+	//calculate address adjust for sync return
+	check_cycles_int(&opts->gen, 0);
 	uint32_t adjust_size = code->cur - opts->gen.handle_cycle_limit_int;
 	code->cur = opts->gen.handle_cycle_limit_int;
+	add_ir(code, 16-sizeof(void *), RSP, SZ_PTR);
+	adjust_size -= code->cur - opts->gen.handle_cycle_limit_int;
+	code->cur = opts->gen.handle_cycle_limit_int;
 	//handle trace mode
 	cmp_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B);
 	code_ptr do_trace = code->cur + 1;
@@ -3026,7 +3029,7 @@
 	//fetch return address and adjust RSP
 	pop_r(code, opts->gen.scratch1);
 	add_ir(code, 16-sizeof(void *), RSP, SZ_PTR);
-	add_ir(code, adjust_size, opts->gen.scratch1, SZ_PTR);
+	sub_ir(code, adjust_size, opts->gen.scratch1, SZ_PTR);
 	//save return address for restoring later
 	mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, resume_pc), SZ_PTR);
 	retn(code);