# HG changeset patch # User Mike Pavone # Date 1367826898 25200 # Node ID 171f97e70d85896cd9424152ec00a899fd9f3a82 # Parent 1cc0850ab6bcfddbf34218a875948a5cebfee780 Implement writes from Z80 to YM-2612 diff -r 1cc0850ab6bc -r 171f97e70d85 blastem.c --- a/blastem.c Mon May 06 00:22:24 2013 -0700 +++ b/blastem.c Mon May 06 00:54:58 2013 -0700 @@ -701,6 +701,27 @@ 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 @@ 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 -r 1cc0850ab6bc -r 171f97e70d85 z80_to_x86.h --- a/z80_to_x86.h Mon May 06 00:22:24 2013 -0700 +++ b/z80_to_x86.h Mon May 06 00:54:58 2013 -0700 @@ -47,7 +47,7 @@ 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 -r 1cc0850ab6bc -r 171f97e70d85 zruntime.S --- a/zruntime.S Mon May 06 00:22:24 2013 -0700 +++ b/zruntime.S Mon May 06 00:54:58 2013 -0700 @@ -90,6 +90,8 @@ 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 @@ 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 @@ 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 @@ 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