summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2013-05-04 16:23:28 -0700
committerMike Pavone <pavone@retrodev.com>2013-05-04 16:23:28 -0700
commit3f1e17f9803faeab79f6dbf000b4855ba7bc894f (patch)
treed8554c519b335be3fac67ae02d7eccc9fb55f210
parent703129f573b4e3b84df96612bb26db672617a8bc (diff)
Implement HALT (sort of tested)
-rw-r--r--z80_to_x86.c9
-rw-r--r--zruntime.S11
2 files changed, 19 insertions, 1 deletions
diff --git a/z80_to_x86.c b/z80_to_x86.c
index c30ac8f..7314afc 100644
--- a/z80_to_x86.c
+++ b/z80_to_x86.c
@@ -35,6 +35,7 @@ void z80_handle_cycle_limit_int();
void z80_retrans_stub();
void z80_io_read();
void z80_io_write();
+void z80_halt();
uint8_t z80_size(z80inst * inst)
{
@@ -898,7 +899,13 @@ uint8_t * translate_z80inst(z80inst * inst, uint8_t * dst, z80_context * context
dst = zcycles(dst, 4 * inst->immed);
}
break;
- //case Z80_HALT:
+ case Z80_HALT:
+ dst = zcycles(dst, 4);
+ dst = mov_ir(dst, address, SCRATCH1, SZ_W);
+ uint8_t * call_inst = dst;
+ dst = call(dst, (uint8_t *)z80_halt);
+ dst = jmp(dst, call_inst);
+ break;
case Z80_DI:
dst = zcycles(dst, 4);
dst = mov_irdisp8(dst, 0, CONTEXT, offsetof(z80_context, iff1), SZ_B);
diff --git a/zruntime.S b/zruntime.S
index 8b74b1b..c2ffe19 100644
--- a/zruntime.S
+++ b/zruntime.S
@@ -71,6 +71,17 @@ z80_do_sync:
zskip_sync:
ret
+ .global z80_halt
+z80_halt:
+ mov %edi, %r14d
+ sub %ebp, %r14d
+ and $0xFFFFFFFC, %r14d
+ add %r14d, %ebp
+ cmp %edi, %ebp
+ jnb z80_handle_cycle_limit_int
+ add $4, %ebp
+ jmp z80_handle_cycle_limit_int
+
.global z80_read_byte
z80_read_byte:
call z_inccycles