changeset 1440:7d4483944d4d

Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
author Michael Pavone <pavone@retrodev.com>
date Thu, 24 Aug 2017 19:28:56 -0700
parents 7da675d0c512
children 8a3d3bb2cd08
files genesis.c z80_to_x86.c
diffstat 2 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/genesis.c	Thu Aug 24 00:02:16 2017 -0700
+++ b/genesis.c	Thu Aug 24 19:28:56 2017 -0700
@@ -54,7 +54,10 @@
 	psg_serialize(gen->psg, buf);
 	end_section(buf);
 	
-	//TODO: bus arbiter state
+	start_section(buf, SECTION_GEN_BUS_ARBITER);
+	save_int8(buf, gen->z80->reset);
+	save_int8(buf, gen->z80->busreq);
+	end_section(buf);
 	
 	start_section(buf, SECTION_SEGA_IO_1);
 	io_serialize(gen->io.ports, buf);
@@ -101,6 +104,13 @@
 	load_buffer8(buf, gen->zram, ram_size);
 }
 
+static void bus_arbiter_deserialize(deserialize_buffer *buf, void *vgen)
+{
+	genesis_context *gen = vgen;
+	gen->z80->reset = load_int8(buf);
+	gen->z80->busreq = load_int8(buf);
+}
+
 void genesis_deserialize(deserialize_buffer *buf, genesis_context *gen)
 {
 	register_section_handler(buf, (section_handler){.fun = m68k_deserialize, .data = gen->m68k}, SECTION_68000);
@@ -108,10 +118,7 @@
 	register_section_handler(buf, (section_handler){.fun = vdp_deserialize, .data = gen->vdp}, SECTION_VDP);
 	register_section_handler(buf, (section_handler){.fun = ym_deserialize, .data = gen->ym}, SECTION_YM2612);
 	register_section_handler(buf, (section_handler){.fun = psg_deserialize, .data = gen->psg}, SECTION_PSG);
-	//TODO: bus arbiter
-	//HACK
-	gen->z80->reset = 0;
-	gen->z80->busreq = 0;
+	register_section_handler(buf, (section_handler){.fun = bus_arbiter_deserialize, .data = gen}, SECTION_GEN_BUS_ARBITER);
 	register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports}, SECTION_SEGA_IO_1);
 	register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 1}, SECTION_SEGA_IO_2);
 	register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 2}, SECTION_SEGA_IO_EXT);
@@ -327,13 +334,15 @@
 			gen->header.enter_debugger = 0;
 			debugger(context, address);
 		}
-		if (gen->header.save_state && (z_context->pc || (!z_context->reset && !z_context->busreq))) {
+		if (gen->header.save_state && (z_context->pc || !z_context->native_pc || z_context->reset || !z_context->busreq)) {
 			uint8_t slot = gen->header.save_state - 1;
 			gen->header.save_state = 0;
-			//advance Z80 core to the start of an instruction
-			while (!z_context->pc)
-			{
-				sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80);
+			if (z_context->native_pc && !z_context->reset) {
+				//advance Z80 core to the start of an instruction
+				while (!z_context->pc)
+				{
+					sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80);
+				}
 			}
 			char *save_path;
 			if (slot == QUICK_SAVE_SLOT) {
--- a/z80_to_x86.c	Thu Aug 24 00:02:16 2017 -0700
+++ b/z80_to_x86.c	Thu Aug 24 19:28:56 2017 -0700
@@ -3872,6 +3872,7 @@
 	save_int8(buf, context->iff1);
 	save_int8(buf, context->iff2);
 	save_int8(buf, context->int_is_nmi);
+	save_int8(buf, context->busack);
 	save_int32(buf, context->current_cycle);
 	save_int32(buf, context->int_cycle);
 	save_int32(buf, context->int_enable_cycle);
@@ -3923,6 +3924,7 @@
 	context->iff1 = load_int8(buf);
 	context->iff2 = load_int8(buf);
 	context->int_is_nmi = load_int8(buf);
+	context->busack = load_int8(buf);
 	context->current_cycle = load_int32(buf);
 	context->int_cycle = load_int32(buf);
 	context->int_enable_cycle = load_int32(buf);