changeset 819:ab017fb09e77

Added support for an IO memory map in Z80 core
author Michael Pavone <pavone@retrodev.com>
date Wed, 29 Jul 2015 00:03:36 -0700
parents a634ed0a92cf
children cf6149b7c6e5
files blastem.c z80_to_x86.c z80_to_x86.h ztestrun.c
diffstat 4 files changed, 16 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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;
--- 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);
--- 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;