# HG changeset patch # User Michael Pavone # Date 1461489588 25200 # Node ID 902c53d9c16fc3e0a46b85493421cbf845c38337 # Parent 928442068afe9c6657b5519cd0269b4c5a94ffa2 Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing diff -r 928442068afe -r 902c53d9c16f 68kinst.c --- a/68kinst.c Sun Apr 24 01:24:38 2016 -0700 +++ b/68kinst.c Sun Apr 24 02:19:48 2016 -0700 @@ -1546,8 +1546,10 @@ } 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 -r 928442068afe -r 902c53d9c16f 68kinst.h --- a/68kinst.h Sun Apr 24 01:24:38 2016 -0700 +++ b/68kinst.h Sun Apr 24 02:19:48 2016 -0700 @@ -282,6 +282,7 @@ uint8_t size; uint8_t cond; } extra; + uint8_t bytes; uint32_t address; m68k_op_info src; m68k_op_info dst; diff -r 928442068afe -r 902c53d9c16f blastem.c --- a/blastem.c Sun Apr 24 01:24:38 2016 -0700 +++ b/blastem.c Sun Apr 24 02:19:48 2016 -0700 @@ -144,6 +144,11 @@ 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 @@ } 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 @@ value = value | (value << 8); } else { value <<= 8; - //TODO: actual pre-fetch emulation - value |= 0x73; + value |= get_open_bus_value() & 0xFF; } return value; } diff -r 928442068afe -r 902c53d9c16f blastem.h --- a/blastem.h Sun Apr 24 01:24:38 2016 -0700 +++ b/blastem.h Sun Apr 24 02:19:48 2016 -0700 @@ -68,6 +68,7 @@ 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 -r 928442068afe -r 902c53d9c16f m68k_core.c --- a/m68k_core.c Sun Apr 24 01:24:38 2016 -0700 +++ b/m68k_core.c Sun Apr 24 02:19:48 2016 -0700 @@ -796,6 +796,13 @@ { 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 -r 928442068afe -r 902c53d9c16f m68k_core.h --- a/m68k_core.h Sun Apr 24 01:24:38 2016 -0700 +++ b/m68k_core.h Sun Apr 24 02:19:48 2016 -0700 @@ -57,6 +57,7 @@ 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 -r 928442068afe -r 902c53d9c16f m68k_core_x86.c --- a/m68k_core_x86.c Sun Apr 24 01:24:38 2016 -0700 +++ b/m68k_core_x86.c Sun Apr 24 02:19:48 2016 -0700 @@ -2167,6 +2167,11 @@ 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 -r 928442068afe -r 902c53d9c16f m68k_internal.h --- a/m68k_internal.h Sun Apr 24 01:24:38 2016 -0700 +++ b/m68k_internal.h Sun Apr 24 02:19:48 2016 -0700 @@ -32,6 +32,7 @@ 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 -r 928442068afe -r 902c53d9c16f vdp.c --- a/vdp.c Sun Apr 24 01:24:38 2016 -0700 +++ b/vdp.c Sun Apr 24 02:19:48 2016 -0700 @@ -1694,9 +1694,8 @@ 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; }