summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2013-05-06 00:54:58 -0700
committerMike Pavone <pavone@retrodev.com>2013-05-06 00:54:58 -0700
commit3eb77ade74ef4fe9f8a7e1eb59e56010a3de778e (patch)
treedb3afb7611ddbb45cd099bd867b826200a3631fb
parent8fa8eb29bee9153853949f7d9193b47911247f39 (diff)
Implement writes from Z80 to YM-2612
-rw-r--r--blastem.c27
-rw-r--r--z80_to_x86.h2
-rw-r--r--zruntime.S24
3 files changed, 49 insertions, 4 deletions
diff --git a/blastem.c b/blastem.c
index b9a1b6a..f1fc062 100644
--- a/blastem.c
+++ b/blastem.c
@@ -701,6 +701,27 @@ m68k_context * io_read_w(uint32_t location, m68k_context * context)
return context;
}
+z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value)
+{
+ genesis_context * gen = context->system;
+ ym_run(gen->ym, (context->current_cycle * MCLKS_PER_Z80) / MCLKS_PER_68K);
+ if (location & 1) {
+ ym_data_write(gen->ym, value);
+ } else if (location & 2) {
+ ym_address_write_part2(gen->ym, value);
+ } else {
+ ym_address_write_part1(gen->ym, value);
+ }
+ return context;
+}
+
+uint8_t z80_read_ym(uint16_t location, z80_context * context)
+{
+ genesis_context * gen = context->system;
+ ym_run(gen->ym, (context->current_cycle * MCLKS_PER_Z80) / MCLKS_PER_68K);
+ return ym_read_status(gen->ym);
+}
+
typedef struct bp_def {
struct bp_def * next;
uint32_t address;
@@ -1015,13 +1036,15 @@ int main(int argc, char ** argv)
x86_z80_options z_opts;
init_x86_z80_opts(&z_opts);
init_z80_context(&z_context, &z_opts);
- z_context.next_context = &v_context;
+
+ genesis_context gen;
+
+ z_context.system = &gen;
z_context.mem_pointers[0] = z80_ram;
z_context.sync_cycle = z_context.target_cycle = MCLKS_PER_FRAME/MCLKS_PER_Z80;
z_context.int_cycle = CYCLE_NEVER;
z_context.mem_pointers[1] = z_context.mem_pointers[2] = (uint8_t *)cart;
- genesis_context gen;
gen.z80 = &z_context;
gen.vdp = &v_context;
gen.ym = &y_context;
diff --git a/z80_to_x86.h b/z80_to_x86.h
index f5e5a39..93af9cc 100644
--- a/z80_to_x86.h
+++ b/z80_to_x86.h
@@ -47,7 +47,7 @@ typedef struct {
native_map_slot * static_code_map;
native_map_slot * banked_code_map;
void * options;
- void * next_context;
+ void * system;
uint8_t ram_code_flags[(8 * 1024)/128/8];
} z80_context;
diff --git a/zruntime.S b/zruntime.S
index c2ffe19..b0c492b 100644
--- a/zruntime.S
+++ b/zruntime.S
@@ -90,6 +90,8 @@ z80_read_byte_noinc:
jb z80_read_ram
cmp $0x8000, %r13w
jae z80_read_bank
+ cmp $0x6000, %r13w
+ jb z80_read_ym2612
/* TODO: Bank reg, YM-2612, PSG/VDP */
mov $0xFF, %r13b
ret
@@ -108,6 +110,15 @@ z80_read_bank:
slow_bank_read:
/* TODO: Call into C to implement this */
ret
+z80_read_ym2612:
+ call z80_save_context
+ mov %r13w, %di
+ push %rsi
+ call z80_read_ym
+ pop %rsi
+ mov %al, %r13b
+ call z80_load_context
+ ret
.global z80_write_byte
z80_write_byte:
@@ -118,7 +129,9 @@ z80_write_byte_noinc:
cmp $0x8000, %r14w
jae z80_write_bank
cmp $0x6000, %r14w
- je z80_write_bank_reg
+ jb z80_write_ym2612
+ cmp $0x6100, %r14w
+ jb z80_write_bank_reg
/* TODO: YM-2612, PSG/VDP */
ret
z80_write_ram:
@@ -146,6 +159,15 @@ z80_write_bank:
slow_bank_write:
/* TODO: Call into C to implement this */
ret
+z80_write_ym2612:
+ and $0x3, %r14w
+ call z80_save_context
+ mov %r14w, %di
+ mov %r13b, %dl
+ call z80_write_ym
+ mov %rax, %rsi
+ call z80_load_context
+ ret
z80_write_bank_reg:
and $1, %r13w
shr %r15w