From 508a9aedf03d887dcc00a8c53caf8cef1ada2937 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 24 Apr 2016 02:19:48 -0700 Subject: Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing --- 68kinst.c | 2 ++ 68kinst.h | 1 + blastem.c | 11 +++++++---- blastem.h | 1 + m68k_core.c | 7 +++++++ m68k_core.h | 1 + m68k_core_x86.c | 5 +++++ m68k_internal.h | 1 + vdp.c | 3 +-- 9 files changed, 26 insertions(+), 6 deletions(-) diff --git a/68kinst.c b/68kinst.c index 64aa5df..b1a2f37 100644 --- a/68kinst.c +++ b/68kinst.c @@ -1546,8 +1546,10 @@ uint16_t * m68k_decode(uint16_t * istream, m68kinst * decoded, uint32_t address) } if (decoded->op == M68K_INVALID) { decoded->src.params.immed = *start; + decoded->bytes = 2; return start + 1; } + decoded->bytes = 2 * (istream + 1 - start); return istream+1; } diff --git a/68kinst.h b/68kinst.h index 0d5072f..cab2574 100644 --- a/68kinst.h +++ b/68kinst.h @@ -282,6 +282,7 @@ typedef struct m68kinst { uint8_t size; uint8_t cond; } extra; + uint8_t bytes; uint32_t address; m68k_op_info src; m68k_op_info dst; diff --git a/blastem.c b/blastem.c index 2601c0e..354fb04 100644 --- a/blastem.c +++ b/blastem.c @@ -144,6 +144,11 @@ uint16_t read_dma_value(uint32_t address) return 0; } +uint16_t get_open_bus_value() +{ + return read_dma_value(genesis->m68k->last_prefetch_address/2); +} + void adjust_int_cycle(m68k_context * context, vdp_context * v_context) { //static int old_int_cycle = CYCLE_NEVER; @@ -705,8 +710,7 @@ uint8_t io_read(uint32_t location, m68k_context * context) } else { if (location == 0x1100) { value = z80_enabled ? !z80_get_busack(gen->z80, context->current_cycle) : !gen->z80->busack; - //TODO: actual pre-fetch emulation - value |= 0x4E; + value |= (get_open_bus_value() >> 8) & 0xFE; dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->current_cycle, gen->z80->reset); } else if (location == 0x1200) { value = !gen->z80->reset; @@ -726,8 +730,7 @@ uint16_t io_read_w(uint32_t location, m68k_context * context) value = value | (value << 8); } else { value <<= 8; - //TODO: actual pre-fetch emulation - value |= 0x73; + value |= get_open_bus_value() & 0xFF; } return value; } diff --git a/blastem.h b/blastem.h index 70c5134..eb1cc74 100644 --- a/blastem.h +++ b/blastem.h @@ -68,6 +68,7 @@ extern uint16_t *ram; extern uint8_t z80_ram[Z80_RAM_BYTES]; uint16_t read_dma_value(uint32_t address); +uint16_t get_open_bus_value(); m68k_context * sync_components(m68k_context *context, uint32_t address); m68k_context * debugger(m68k_context * context, uint32_t address); void set_speed_percent(genesis_context * context, uint32_t percent); diff --git a/m68k_core.c b/m68k_core.c index a39830b..c920768 100644 --- a/m68k_core.c +++ b/m68k_core.c @@ -796,6 +796,13 @@ void translate_m68k(m68k_options * opts, m68kinst * inst) { check_cycles_int(&opts->gen, inst->address); //log_address(&opts->gen, inst->address, "M68K: %X @ %d\n"); + if ( + (inst->src.addr_mode > MODE_AREG && inst->src.addr_mode < MODE_IMMEDIATE) + || (inst->dst.addr_mode > MODE_AREG && inst->dst.addr_mode < MODE_IMMEDIATE) + ) { + //Not accurate for all cases, but probably good enough for now + m68k_set_last_prefetch(opts, inst->address + inst->bytes); + } impl_info * info = m68k_impls + inst->op; if (info->itype == RAW_FUNC) { info->impl.raw(opts, inst); diff --git a/m68k_core.h b/m68k_core.h index 8c8deb6..7aeb3f3 100644 --- a/m68k_core.h +++ b/m68k_core.h @@ -57,6 +57,7 @@ typedef struct { uint32_t sync_cycle; uint32_t int_cycle; uint32_t int_num; + uint32_t last_prefetch_address; uint16_t *mem_pointers[NUM_MEM_AREAS]; code_ptr resume_pc; native_map_slot *native_code_map; diff --git a/m68k_core_x86.c b/m68k_core_x86.c index 9882b35..149e84d 100644 --- a/m68k_core_x86.c +++ b/m68k_core_x86.c @@ -2167,6 +2167,11 @@ void translate_out_of_bounds(code_info *code) call_args(code, (code_ptr)exit, 1, RDI); } +void m68k_set_last_prefetch(m68k_options *opts, uint32_t address) +{ + mov_irdisp(&opts->gen.code, address, opts->gen.context_reg, offsetof(m68k_context, last_prefetch_address), SZ_D); +} + void nop_fill_or_jmp_next(code_info *code, code_ptr old_end, code_ptr next_inst) { if (next_inst == old_end && next_inst - code->cur < 2) { diff --git a/m68k_internal.h b/m68k_internal.h index b74f06b..8b891bd 100644 --- a/m68k_internal.h +++ b/m68k_internal.h @@ -32,6 +32,7 @@ void calc_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg); void calc_areg_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg); void nop_fill_or_jmp_next(code_info *code, code_ptr old_end, code_ptr next_inst); void check_user_mode_swap_ssp_usp(m68k_options *opts); +void m68k_set_last_prefetch(m68k_options *opts, uint32_t address); //functions implemented in m68k_core.c int8_t native_reg(m68k_op_info * op, m68k_options * opts); diff --git a/vdp.c b/vdp.c index 8b1ed22..5e1fab8 100644 --- a/vdp.c +++ b/vdp.c @@ -1694,9 +1694,8 @@ void vdp_test_port_write(vdp_context * context, uint16_t value) uint16_t vdp_control_port_read(vdp_context * context) { context->flags &= ~FLAG_PENDING; - //TODO: Open bus emulation //Bits 15-10 are not fixed like Charles MacDonald's doc suggests, but instead open bus values that reflect 68K prefetch - uint16_t value = 0; + uint16_t value = get_open_bus_value() & 0xFC00; if (context->fifo_read < 0) { value |= 0x200; } -- cgit v1.2.3