diff m68k_core.c @ 1507:2455662378ed mame_interp

Added MAME Z80 core, re-enabled 68K tracing in Musashi core, disabled a bunch of code gen stuff when using interpreters from MAME
author Michael Pavone <pavone@retrodev.com>
date Sat, 30 Dec 2017 18:27:06 -0800
parents ded16f3d7eb4
children b7ecd0d6a77b
line wrap: on
line diff
--- a/m68k_core.c	Wed Dec 27 13:46:52 2017 -0800
+++ b/m68k_core.c	Sat Dec 30 18:27:06 2017 -0800
@@ -4,20 +4,26 @@
  BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
 */
 #include "m68k_core.h"
+#ifdef USE_NATIVE
 #include "m68k_internal.h"
+#endif
 #include "68kinst.h"
 #include "backend.h"
+#ifdef USE_NATIVE
 #include "gen.h"
+#endif
 #include "util.h"
 #include "serialize.h"
+#ifndef USE_NATIVE
 #include "musashi/m68kcpu.h"
+#endif
 #include <stdio.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
 char disasm_buf[1024];
-
+#ifdef USE_NATIVE
 int8_t native_reg(m68k_op_info * op, m68k_options * opts)
 {
 	if (op->addr_mode == MODE_REG) {
@@ -44,7 +50,7 @@
 {
 	return op->addr_mode == MODE_REG ? dreg_offset(op->params.regs.pri) : areg_offset(op->params.regs.pri);
 }
-
+#endif
 void m68k_print_regs(m68k_context * context)
 {
 	printf("XNZVC\n%d%d%d%d%d\n", context->flags[0], context->flags[1], context->flags[2], context->flags[3], context->flags[4]);
@@ -55,7 +61,7 @@
 		printf("a%d: %X\n", i, context->aregs[i]);
 	}
 }
-
+#ifdef USE_NATIVE
 void m68k_read_size(m68k_options *opts, uint8_t size)
 {
 	switch (size)
@@ -760,6 +766,7 @@
 	uint32_t slot = meta_off/1024;
 	return opts->gen.ram_inst_sizes[slot][(meta_off/2)%512];
 }
+#endif
 
 uint8_t m68k_is_terminal(m68kinst * inst)
 {
@@ -768,6 +775,7 @@
 		|| (inst->op == M68K_BCC && inst->extra.cond == COND_TRUE);
 }
 
+#ifdef USE_NATIVE
 static void m68k_handle_deferred(m68k_context * context)
 {
 	m68k_options * opts = context->options;
@@ -776,9 +784,11 @@
 		translate_m68k_stream(opts->gen.deferred->address, context);
 	}
 }
+#endif
 
 uint16_t m68k_get_ir(m68k_context *context)
 {
+#ifdef USE_NATIVE
 	uint32_t inst_addr = get_instruction_start(context->options, context->last_prefetch_address-2);
 	uint16_t *native_addr = get_native_pointer(inst_addr, (void **)context->mem_pointers, &context->options->gen);
 	if (native_addr) {
@@ -786,6 +796,9 @@
 	}
 	fprintf(stderr, "M68K: Failed to calculate value of IR. Last prefetch address: %X\n", context->last_prefetch_address);
 	return 0xFFFF;
+#else
+	return ((m68000_base_device *)context)->ir;
+#endif
 }
 
 static m68k_debug_handler find_breakpoint(m68k_context *context, uint32_t address)
@@ -813,7 +826,9 @@
 			.handler = bp_handler,
 			.address = address
 		};
+#ifdef USE_NATIVE
 		m68k_breakpoint_patch(context, address, bp_handler, NULL);
+#endif
 	}
 }
 
@@ -831,6 +846,7 @@
 	return context;
 }
 
+#ifdef USE_NATIVE
 typedef enum {
 	RAW_FUNC = 1,
 	BINARY_ARITH,
@@ -1141,6 +1157,7 @@
 	}
 	return ret;
 }
+#endif
 
 void remove_breakpoint(m68k_context * context, uint32_t address)
 {
@@ -1154,6 +1171,7 @@
 			break;
 		}
 	}
+#ifdef USE_NATIVE
 	code_ptr native = get_native_address(context->options, address);
 	if (!native) {
 		return;
@@ -1163,14 +1181,16 @@
 	context->options->gen.code.last = native + MAX_NATIVE_SIZE;
 	check_cycles_int(&context->options->gen, address);
 	context->options->gen.code = tmp;
+#endif
 }
 
+m68k_context * sync_components(m68k_context * context, uint32_t address);
 void start_68k_context(m68k_context * context, uint32_t address)
 {
-	code_ptr addr = get_native_address_trans(context, address);
 	m68k_options * options = context->options;
 	context->should_return = 0;
 #ifdef USE_NATIVE
+	code_ptr addr = get_native_address_trans(context, address);
 	options->start_context(addr, context);
 #else
 	while (!context->should_return) {
@@ -1214,11 +1234,26 @@
 
 void m68k_options_free(m68k_options *opts)
 {
+#ifdef USE_NATIVE
 	free(opts->gen.native_code_map);
 	free(opts->gen.ram_inst_sizes);
+#endif
 	free(opts);
 }
 
+#ifndef USE_NATIVE
+void init_m68k_opts(m68k_options * opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider)
+{
+	memset(opts, 0, sizeof(*opts));
+	opts->gen.memmap = memmap;
+	opts->gen.memmap_chunks = num_chunks;
+	opts->gen.address_mask = 0xFFFFFF;
+	opts->gen.byte_swap = 1;
+	opts->gen.max_address = 0x1000000;
+	opts->gen.bus_cycles = 4;
+	opts->gen.clock_divider = clock_divider;
+}
+#endif
 
 m68k_context * init_68k_context(m68k_options * opts, m68k_reset_handler reset_handler)
 {