changeset 150:3e68e517cc01

Do a sync when interrupt mask changes so we can recompute the next interrupt cycle. Also fix a bug in which the SR part of ORI to SR was not being performed.
author Mike Pavone <pavone@retrodev.com>
date Tue, 01 Jan 2013 09:40:17 -0800
parents 139e5dcd6aa3
children 6b593ea0ed90
files m68k_to_x86.c runtime.S
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/m68k_to_x86.c	Tue Jan 01 07:06:57 2013 -0800
+++ b/m68k_to_x86.c	Tue Jan 01 09:40:17 2013 -0800
@@ -42,6 +42,7 @@
 void set_sr();
 void set_ccr();
 void get_sr();
+void do_sync();
 void m68k_start_context(uint8_t * addr, m68k_context * context);
 
 uint8_t * cycles(uint8_t * dst, uint32_t num)
@@ -2247,6 +2248,9 @@
 				dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, opts->aregs[7], SZ_B);
 				dst = mov_rrdisp8(dst, SCRATCH1, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, SZ_B);
 			}
+			if (inst->src.params.immed & 0x700) {
+				dst = call(dst, (uint8_t *)do_sync);
+			}
 		}
 		break;
 	case M68K_ASL:
@@ -2447,6 +2451,7 @@
 					dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, opts->aregs[7], SZ_D);
 					dst = mov_rrdisp8(dst, SCRATCH1, CONTEXT, offsetof(m68k_context, aregs) + sizeof(uint32_t) * 8, SZ_D);
 				}
+				dst = call(dst, (uint8_t *)do_sync);
 			}
 			dst = cycles(dst, 12);
 		} else {
@@ -2557,8 +2562,11 @@
 		if (inst->src.params.immed & 0x10) {
 			dst = mov_irind(dst, 1, CONTEXT, SZ_B);
 		}
-		if (inst->op == M68K_ANDI_SR) {
+		if (inst->op == M68K_ORI_SR) {
 			dst = or_irdisp8(dst, inst->src.params.immed >> 8, CONTEXT, offsetof(m68k_context, status), SZ_B);
+			if (inst->src.params.immed & 0x700) {
+				dst = call(dst, (uint8_t *)do_sync);
+			}
 		}
 		break;
 	/*case M68K_RESET:*/
@@ -2921,8 +2929,8 @@
 			next = m68k_decode(encoded, &instbuf, address);
 			address += (next-encoded)*2;
 			encoded = next;
-			m68k_disasm(&instbuf, disbuf);
-			printf("%X: %s\n", instbuf.address, disbuf);
+			//m68k_disasm(&instbuf, disbuf);
+			//printf("%X: %s\n", instbuf.address, disbuf);
 			dst = translate_m68k(dst, &instbuf, opts);
 		} while(instbuf.op != M68K_ILLEGAL && instbuf.op != M68K_RTS && instbuf.op != M68K_RTE && !(instbuf.op == M68K_BCC && instbuf.extra.cond == COND_TRUE) && instbuf.op != M68K_JMP);
 		process_deferred(opts);
--- a/runtime.S	Tue Jan 01 07:06:57 2013 -0800
+++ b/runtime.S	Tue Jan 01 09:40:17 2013 -0800
@@ -1,8 +1,10 @@
 
 	.global handle_cycle_limit
+	.global do_sync
 handle_cycle_limit:
 	cmp 84(%rsi), %eax
 	jb skip_sync
+do_sync:
 	call m68k_save_context
 	mov %rsi, %rdi
 	call sync_components
@@ -49,9 +51,14 @@
 	/* discard function return address */
 	pop %rdi
 	jmp *%rcx
+	ret
 skip_int:
+	cmp 84(%rsi), %eax
+	jnb do_sync
 	ret
 	
+	.global do_sync
+	
 int_dbg_msg:
 	.asciz "Executing Interrupt!"
 print_int_dbg: