diff options
author | Mike Pavone <pavone@retrodev.com> | 2013-05-04 15:58:15 -0700 |
---|---|---|
committer | Mike Pavone <pavone@retrodev.com> | 2013-05-04 15:58:15 -0700 |
commit | 703129f573b4e3b84df96612bb26db672617a8bc (patch) | |
tree | cf1042cf399ac182bd3df92867fd61513b32955e | |
parent | d511cd2c0b128f0e5e3b55ba2d6cda1e75e49f8f (diff) |
Implement IN and OUT (untested)
-rw-r--r-- | z80_to_x86.c | 32 | ||||
-rw-r--r-- | zruntime.S | 25 |
2 files changed, 53 insertions, 4 deletions
diff --git a/z80_to_x86.c b/z80_to_x86.c index 8fc0b57..c30ac8f 100644 --- a/z80_to_x86.c +++ b/z80_to_x86.c @@ -33,6 +33,8 @@ void z80_native_addr(); void z80_do_sync(); void z80_handle_cycle_limit_int(); void z80_retrans_stub(); +void z80_io_read(); +void z80_io_write(); uint8_t z80_size(z80inst * inst) { @@ -1407,13 +1409,35 @@ uint8_t * translate_z80inst(z80inst * inst, uint8_t * dst, z80_context * context dst = jmp(dst, call_dst); break; } - /*case Z80_IN: - case Z80_INI: + case Z80_IN: + dst = zcycles(dst, inst->reg == Z80_A ? 7 : 8);//T States: 4 3/4 + if (inst->addr_mode == Z80_IMMED_INDIRECT) { + dst = mov_ir(dst, inst->immed, SCRATCH1, SZ_B); + } else { + dst = mov_rr(dst, opts->regs[Z80_C], SCRATCH1, SZ_B); + } + dst = call(dst, (uint8_t *)z80_io_read); + translate_z80_reg(inst, &dst_op, dst, opts); + dst = mov_rr(dst, SCRATCH1, dst_op.base, SZ_B); + dst = z80_save_reg(dst, inst, opts); + break; + /*case Z80_INI: case Z80_INIR: case Z80_IND: - case Z80_INDR: + case Z80_INDR:*/ case Z80_OUT: - case Z80_OUTI: + dst = zcycles(dst, inst->reg == Z80_A ? 7 : 8);//T States: 4 3/4 + if ((inst->addr_mode & 0x1F) == Z80_IMMED_INDIRECT) { + dst = mov_ir(dst, inst->immed, SCRATCH2, SZ_B); + } else { + dst = mov_rr(dst, opts->regs[Z80_C], SCRATCH2, SZ_B); + } + translate_z80_reg(inst, &src_op, dst, opts); + dst = mov_rr(dst, dst_op.base, SCRATCH1, SZ_B); + dst = call(dst, (uint8_t *)z80_io_write); + dst = z80_save_reg(dst, inst, opts); + break; + /*case Z80_OUTI: case Z80_OTIR: case Z80_OUTD: case Z80_OTDR:*/ @@ -1,3 +1,14 @@ +z_inccycles_io: + cmp %edi, %ebp + jnb do_limit +no_sync_io: + add $4, %ebp + ret +do_limit_io: + cmp 112(%rsi), %ebp + jb no_sync_io + jmp sync_io + z_inccycles: cmp %edi, %ebp jnb do_limit @@ -7,6 +18,7 @@ no_sync: do_limit: cmp 112(%rsi), %ebp jb no_sync +sync_io: call z80_save_context_scratch pop %rax /*return address in read/write func*/ pop 104(%rsi) /*return address in native code*/ @@ -180,6 +192,19 @@ z80_write_word_lowfirst: call z_inccycles call z80_write_byte_noinc ret + + .global z80_io_read +z80_io_read: + call z_inccycles_io + /* genesis Z80 has no IO port hardware and always returns FF */ + mov $0xFF, %r13 + ret + + .global z80_io_write +z80_io_write: + call z_inccycles_io + /* genesis Z80 has no IO port hardware and writes have no effect */ + ret .global z80_retrans_stub z80_retrans_stub: |