changeset 261:f0c53a4bbfa3

Implement LDIR and fix a bug in which context was not restored after a call to z80_handle_code_write
author Mike Pavone <pavone@retrodev.com>
date Tue, 30 Apr 2013 01:00:10 -0700
parents 625f8e4d5fd2
children d97c9eca49f4
files z80_to_x86.c zruntime.S
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/z80_to_x86.c	Tue Apr 30 00:39:31 2013 -0700
+++ b/z80_to_x86.c	Tue Apr 30 01:00:10 2013 -0700
@@ -263,6 +263,7 @@
 	x86_ea src_op, dst_op;
 	uint8_t size;
 	x86_z80_options *opts = context->options;
+	uint8_t * start = dst;
 	dst = z80_check_cycles_int(dst, address);
 	switch(inst->op)
 	{
@@ -424,9 +425,31 @@
 		dst = mov_rdisp8r(dst, CONTEXT, zar_off(Z80_E), opts->regs[Z80_DE], SZ_W);
 		dst = mov_rrdisp8(dst, SCRATCH1, CONTEXT, zar_off(Z80_E), SZ_W);
 		break;
-	/*case Z80_LDI:
-	case Z80_LDIR:
-	case Z80_LDD:
+	//case Z80_LDI:
+	case Z80_LDIR: {
+		dst = zcycles(dst, 8);
+		dst = mov_rr(dst, opts->regs[Z80_HL], SCRATCH1, SZ_W);
+		dst = call(dst, (uint8_t *)z80_read_byte);
+		dst = mov_rr(dst, opts->regs[Z80_DE], SCRATCH2, SZ_W);
+		dst = call(dst, (uint8_t *)z80_read_byte);
+		dst = add_ir(dst, 1, opts->regs[Z80_DE], SZ_W);
+		dst = add_ir(dst, 1, opts->regs[Z80_HL], SZ_W);
+		
+		dst = sub_ir(dst, 1, opts->regs[Z80_BC], SZ_W);
+		uint8_t * cont = dst+1;
+		dst = jcc(dst, CC_Z, dst+2);
+		dst = zcycles(dst, 7);
+		//TODO: Figure out what the flag state should be here
+		//TODO: Figure out whether an interrupt can interrupt this
+		dst = jmp(dst, start);
+		*cont = dst - (cont + 1);
+		dst = zcycles(dst, 2);
+		//TODO: Implement half-carry
+		dst = mov_irdisp8(dst, 0, CONTEXT, zf_off(ZF_N), SZ_B);
+		dst = mov_irdisp8(dst, 0, CONTEXT, zf_off(ZF_PV), SZ_B);
+		break;
+	}
+	/*case Z80_LDD:
 	case Z80_LDDR:
 	case Z80_CPI:
 	case Z80_CPIR:
--- a/zruntime.S	Tue Apr 30 00:39:31 2013 -0700
+++ b/zruntime.S	Tue Apr 30 01:00:10 2013 -0700
@@ -107,6 +107,7 @@
 	mov %r14d, %edi
 	call z80_handle_code_write
 	mov %rax, %rsi
+	call z80_load_context
 not_code:
 	ret
 z80_write_bank: