# HG changeset patch # User Michael Pavone # Date 1420179512 28800 # Node ID e7cae6d9aaa6c0adb1b8d88c69f71af8abf30778 # Parent 759c38bf97f89362f7b846ed7867cfa18b046e0c Add the 3 cycle delay back in to Z80 bank area access diff -r 759c38bf97f8 -r e7cae6d9aaa6 blastem.c --- a/blastem.c Thu Jan 01 20:26:22 2015 -0800 +++ b/blastem.c Thu Jan 01 22:18:32 2015 -0800 @@ -419,6 +419,7 @@ { z80_context * context = vcontext; genesis_context * gen = context->system; + vdp_port &= 0xFF; if (vdp_port & 0xE0) { printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port); exit(1); @@ -761,11 +762,20 @@ uint8_t z80_read_bank(uint32_t location, void * vcontext) { z80_context * context = vcontext; + //typical delay from bus arbitration + context->current_cycle += 3; + + location &= 0x7FFF; + //TODO: add cycle for an access right after a previous one + //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access + if (context->mem_pointers[1]) { + return context->mem_pointers[1][location ^ 1]; + } uint32_t address = context->bank_reg << 15 | location; if (address >= 0xC00000 && address < 0xE00000) { return z80_vdp_port_read(location & 0xFF, context); } else { - fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area\n", address); + fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area (%X)\n", address, context->bank_reg << 15); } return 0; } @@ -773,6 +783,11 @@ void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) { z80_context * context = vcontext; + //typical delay from bus arbitration + context->current_cycle += 3; + location &= 0x7FFF; + //TODO: add cycle for an access right after a previous one + //TODO: block Z80 if VDP has the bus or the 68K is blocked on a VDP access uint32_t address = context->bank_reg << 15 | location; if (address >= 0xE00000) { address &= 0xFFFF; @@ -791,7 +806,8 @@ context->bank_reg = (context->bank_reg >> 1 | value << 8) & 0x1FF; if (context->bank_reg < 0x80) { - context->mem_pointers[1] = context->mem_pointers[2] + (context->bank_reg << 15); + genesis_context *gen = context->system; + context->mem_pointers[1] = get_native_pointer(context->bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen); } else { context->mem_pointers[1] = NULL; } @@ -1178,11 +1194,11 @@ } #ifndef NO_Z80 const memmap_chunk z80_map[] = { - { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, - { 0x8000, 0x10000, 0x7FFF, 1, MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL | MMAP_BYTESWAP, NULL, NULL, NULL, z80_read_bank, z80_write_bank}, - { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym}, - { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg}, - { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write} + { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL }, + { 0x8000, 0x10000, 0x7FFF, 0, 0, NULL, NULL, NULL, z80_read_bank, z80_write_bank}, + { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym}, + { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg}, + { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write} }; #endif diff -r 759c38bf97f8 -r e7cae6d9aaa6 z80_to_x86.c --- a/z80_to_x86.c Thu Jan 01 20:26:22 2015 -0800 +++ b/z80_to_x86.c Thu Jan 01 22:18:32 2015 -0800 @@ -2223,13 +2223,6 @@ jmp_rind(code, options->gen.context_reg); } -void * z80_gen_bank_write(uint32_t start_address, void * voptions) -{ - z80_options * options = voptions; - //TODO: Handle writes to bank register - return options; -} - void init_z80_context(z80_context * context, z80_options * options) { memset(context, 0, sizeof(*context)); diff -r 759c38bf97f8 -r e7cae6d9aaa6 z80_to_x86.h --- a/z80_to_x86.h Thu Jan 01 20:26:22 2015 -0800 +++ b/z80_to_x86.h Thu Jan 01 22:18:32 2015 -0800 @@ -93,7 +93,6 @@ void z80_reset(z80_context * context); void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler); void zremove_breakpoint(z80_context * context, uint16_t address); -void * z80_gen_bank_write(uint32_t start_address, void * voptions); #endif //Z80_TO_X86_H_