changeset 981:902c53d9c16f

Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
author Michael Pavone <pavone@retrodev.com>
date Sun, 24 Apr 2016 02:19:48 -0700
parents 928442068afe
children f7bbbf49db4e
files 68kinst.c 68kinst.h blastem.c blastem.h m68k_core.c m68k_core.h m68k_core_x86.c m68k_internal.h vdp.c
diffstat 9 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- 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;
--- 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;
 }
--- 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);
--- 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);
--- 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;
--- 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) {
--- 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);
--- 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;
 	}