# HG changeset patch # User Michael Pavone # Date 1438153416 25200 # Node ID ab017fb09e77b344a4077ce8e32ce103255fe550 # Parent a634ed0a92cfab2744d3357c6c7e1b7f5e8054a6 Added support for an IO memory map in Z80 core diff -r a634ed0a92cf -r ab017fb09e77 blastem.c --- a/blastem.c Wed Jul 29 00:03:09 2015 -0700 +++ b/blastem.c Wed Jul 29 00:03:36 2015 -0700 @@ -1037,7 +1037,7 @@ z80_context z_context; #ifndef NO_Z80 z80_options z_opts; - init_z80_opts(&z_opts, z80_map, 5, MCLKS_PER_Z80); + init_z80_opts(&z_opts, z80_map, 5, NULL, 0, MCLKS_PER_Z80); init_z80_context(&z_context, &z_opts); z80_assert_reset(&z_context, 0); #endif diff -r a634ed0a92cf -r ab017fb09e77 z80_to_x86.c --- a/z80_to_x86.c Wed Jul 29 00:03:09 2015 -0700 +++ b/z80_to_x86.c Wed Jul 29 00:03:36 2015 -0700 @@ -339,7 +339,7 @@ code_info *code = &opts->gen.code; if (!interp) { check_cycles_int(&opts->gen, address); - if (context->breakpoint_flags[address / sizeof(uint8_t)] & (1 << (address % sizeof(uint8_t)))) { + if (context->breakpoint_flags[address / 8] & (1 << (address % 8))) { zbreakpoint_patch(context, address, start); } #ifdef Z80_LOG_ADDRESS @@ -2244,7 +2244,7 @@ } while (opts->gen.deferred); } -void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, uint32_t clock_divider) +void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, memmap_chunk const * io_chunks, uint32_t num_io_chunks, uint32_t clock_divider) { memset(options, 0, sizeof(*options)); @@ -2451,18 +2451,13 @@ *skip_sync = code->cur - (skip_sync+1); retn(code); - options->read_io = code->cur; - check_cycles(&options->gen); - cycles(&options->gen, 4); - //Genesis has no IO hardware and always returns FF - //eventually this should use a second memory map array - mov_ir(code, 0xFF, options->gen.scratch1, SZ_B); - retn(code); - - options->write_io = code->cur; - check_cycles(&options->gen); - cycles(&options->gen, 4); - retn(code); + //HACK + options->gen.address_size = SZ_D; + options->gen.address_mask = 0xFF; + options->read_io = gen_mem_fun(&options->gen, io_chunks, num_io_chunks, READ_8, NULL); + options->write_io = gen_mem_fun(&options->gen, io_chunks, num_io_chunks, WRITE_8, NULL); + options->gen.address_size = SZ_W; + options->gen.address_mask = 0xFFFF; options->read_16 = code->cur; cycles(&options->gen, 3); @@ -2722,9 +2717,9 @@ void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler) { context->bp_handler = bp_handler; - uint8_t bit = 1 << (address % sizeof(uint8_t)); - if (!(bit & context->breakpoint_flags[address / sizeof(uint8_t)])) { - context->breakpoint_flags[address / sizeof(uint8_t)] |= bit; + uint8_t bit = 1 << (address % 8); + if (!(bit & context->breakpoint_flags[address / 8])) { + context->breakpoint_flags[address / 8] |= bit; if (!context->bp_stub) { zcreate_stub(context); } @@ -2737,7 +2732,7 @@ void zremove_breakpoint(z80_context * context, uint16_t address) { - context->breakpoint_flags[address / sizeof(uint8_t)] &= ~(1 << (address % sizeof(uint8_t))); + context->breakpoint_flags[address / 8] &= ~(1 << (address % 8)); uint8_t * native = z80_get_native_address(context, address); if (native) { z80_options * opts = context->options; diff -r a634ed0a92cf -r ab017fb09e77 z80_to_x86.h --- a/z80_to_x86.h Wed Jul 29 00:03:09 2015 -0700 +++ b/z80_to_x86.h Wed Jul 29 00:03:36 2015 -0700 @@ -87,7 +87,7 @@ } z80_context; void translate_z80_stream(z80_context * context, uint32_t address); -void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, uint32_t clock_divider); +void init_z80_opts(z80_options * options, memmap_chunk const * chunks, uint32_t num_chunks, memmap_chunk const * io_chunks, uint32_t num_io_chunks, uint32_t clock_divider); void init_z80_context(z80_context * context, z80_options * options); code_ptr z80_get_native_address(z80_context * context, uint32_t address); code_ptr z80_get_native_address_trans(z80_context * context, uint32_t address); diff -r a634ed0a92cf -r ab017fb09e77 ztestrun.c --- a/ztestrun.c Wed Jul 29 00:03:09 2015 -0700 +++ b/ztestrun.c Wed Jul 29 00:03:36 2015 -0700 @@ -75,7 +75,7 @@ exit(1); } fclose(f); - init_z80_opts(&opts, z80_map, 2, 1); + init_z80_opts(&opts, z80_map, 2, NULL, 0, 1); init_z80_context(&context, &opts); //Z80 RAM context.mem_pointers[0] = z80_ram;