summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2014-12-29 23:08:39 -0800
committerMichael Pavone <pavone@retrodev.com>2014-12-29 23:08:39 -0800
commitc61ca95add7b82aadef09aea8b4c48774e079069 (patch)
tree7710ffc0c0f1a5d86949af8171558dbc434ddc91
parentc6beba019312aaaf7bd8718bb239b7c632477852 (diff)
Fix handling of code writes for Z80 core. This seems to get things close to being back to where they were before the big refactor that broke the Z80 core. Some problems remain. Notably the sound driver in Sonic 2 is still quite broken.
-rw-r--r--backend.h1
-rw-r--r--backend_x86.c7
-rw-r--r--m68k_core_x86.c1
-rw-r--r--z80_to_x86.c1
4 files changed, 8 insertions, 2 deletions
diff --git a/backend.h b/backend.h
index 58f8a47..18c3752 100644
--- a/backend.h
+++ b/backend.h
@@ -62,6 +62,7 @@ typedef struct {
uint32_t bus_cycles;
int32_t mem_ptr_off;
int32_t ram_flags_off;
+ uint8_t ram_flags_shift;
uint8_t address_size;
uint8_t byte_swap;
uint8_t context_reg;
diff --git a/backend_x86.c b/backend_x86.c
index 631c6c7..71eaf28 100644
--- a/backend_x86.c
+++ b/backend_x86.c
@@ -200,9 +200,8 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n
}
}
if (is_write && (memmap[chunk].flags & MMAP_CODE)) {
- //TODO: Fixme for Z80
mov_rr(code, opts->scratch2, opts->scratch1, opts->address_size);
- shr_ir(code, 11, opts->scratch1, opts->address_size);
+ shr_ir(code, opts->ram_flags_shift, opts->scratch1, opts->address_size);
bt_rrdisp(code, opts->scratch1, opts->context_reg, opts->ram_flags_off, opts->address_size);
code_ptr not_code = code->cur + 1;
jcc(code, CC_NC, code->cur + 2);
@@ -210,6 +209,10 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n
#ifdef X86_32
push_r(code, opts->context_reg);
push_r(code, opts->scratch2);
+#else
+ if (opts->scratch2 != RDI) {
+ mov_rr(code, opts->scratch2, RDI, opts->address_size);
+ }
#endif
call(code, opts->handle_code_write);
#ifdef X86_32
diff --git a/m68k_core_x86.c b/m68k_core_x86.c
index d4e0a1c..7e97886 100644
--- a/m68k_core_x86.c
+++ b/m68k_core_x86.c
@@ -2237,6 +2237,7 @@ void init_m68k_opts(m68k_options * opts, memmap_chunk * memmap, uint32_t num_chu
opts->gen.bus_cycles = BUS;
opts->gen.mem_ptr_off = offsetof(m68k_context, mem_pointers);
opts->gen.ram_flags_off = offsetof(m68k_context, ram_code_flags);
+ opts->gen.ram_flags_shift = 11;
for (int i = 0; i < 8; i++)
{
opts->dregs[i] = opts->aregs[i] = -1;
diff --git a/z80_to_x86.c b/z80_to_x86.c
index c785e8a..bb701a6 100644
--- a/z80_to_x86.c
+++ b/z80_to_x86.c
@@ -1907,6 +1907,7 @@ void init_x86_z80_opts(z80_options * options, memmap_chunk const * chunks, uint3
options->gen.bus_cycles = 3;
options->gen.mem_ptr_off = offsetof(z80_context, mem_pointers);
options->gen.ram_flags_off = offsetof(z80_context, ram_code_flags);
+ options->gen.ram_flags_shift = 7;
options->flags = 0;
options->regs[Z80_B] = BH;