# HG changeset patch # User Mike Pavone # Date 1367308810 25200 # Node ID f0c53a4bbfa3c86118201ce1565c6b5628f0795a # Parent 625f8e4d5fd2f88f250cdcdefa0a770addc81f2c Implement LDIR and fix a bug in which context was not restored after a call to z80_handle_code_write diff -r 625f8e4d5fd2 -r f0c53a4bbfa3 z80_to_x86.c --- 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: diff -r 625f8e4d5fd2 -r f0c53a4bbfa3 zruntime.S --- 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: