changeset 1377:e587f16e7d3d

Implemented SMS pause button
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 May 2017 21:03:55 -0700
parents 70d88d9bfe13
children 71c8b97eb962
files default.cfg genesis.c io.c sms.c vdp.c vdp.h
diffstat 6 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/default.cfg	Sun May 28 21:02:47 2017 -0700
+++ b/default.cfg	Sun May 28 21:03:55 2017 -0700
@@ -33,6 +33,7 @@
 		- ui.prev_speed
 		f11 ui.toggle_fullscreen
 		tab ui.soft_reset
+		z ui.sms_pause
 		rctrl ui.toggle_keyboard_captured
 	}
 	pads {
--- a/genesis.c	Sun May 28 21:02:47 2017 -0700
+++ b/genesis.c	Sun May 28 21:03:55 2017 -0700
@@ -1035,6 +1035,7 @@
 	gen->header.request_exit = request_exit;
 	gen->header.inc_debug_mode = inc_debug_mode;
 	gen->header.inc_debug_pal = inc_debug_pal;
+	gen->header.type = SYSTEM_GENESIS;
 	set_region(gen, rom, force_region);
 
 	gen->vdp = malloc(sizeof(vdp_context));
--- a/io.c	Sun May 28 21:02:47 2017 -0700
+++ b/io.c	Sun May 28 21:03:55 2017 -0700
@@ -18,6 +18,7 @@
 #include "io.h"
 #include "blastem.h"
 #include "genesis.h"
+#include "sms.h"
 #include "render.h"
 #include "util.h"
 
@@ -74,6 +75,7 @@
 	UI_TOGGLE_KEYBOARD_CAPTURE,
 	UI_TOGGLE_FULLSCREEN,
 	UI_SOFT_RESET,
+	UI_SMS_PAUSE,
 	UI_SCREENSHOT,
 	UI_EXIT
 } ui_action;
@@ -493,6 +495,12 @@
 		case UI_SOFT_RESET:
 			current_system->soft_reset(current_system);
 			break;
+		case UI_SMS_PAUSE:
+			if (current_system->type == SYSTEM_SMS) {
+				sms_context *sms = (sms_context *)current_system;
+				vdp_pbc_pause(sms->vdp);
+			}
+			break;
 		case UI_SCREENSHOT: {
 			char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval;
 			if (!screenshot_base) {
@@ -690,6 +698,8 @@
 			*ui_out = UI_TOGGLE_FULLSCREEN;
 		} else if (!strcmp(target + 3, "soft_reset")) {
 			*ui_out = UI_SOFT_RESET;
+		} else if (!strcmp(target + 3, "sms_pause")) {
+			*ui_out = UI_SMS_PAUSE;
 		} else if (!strcmp(target + 3, "screenshot")) {
 			*ui_out = UI_SCREENSHOT;
 		} else if(!strcmp(target + 3, "exit")) {
--- a/sms.c	Sun May 28 21:02:47 2017 -0700
+++ b/sms.c	Sun May 28 21:03:55 2017 -0700
@@ -193,7 +193,7 @@
 {
 	render_disable_ym();
 	sms_context *sms = (sms_context *)system;
-	uint32_t target_cycle = sms->z80->current_cycle + 3420*262;
+	uint32_t target_cycle = sms->z80->current_cycle + 3420*16;
 	//TODO: PAL support
 	render_set_video_standard(VID_NTSC);
 	while (!sms->should_return)
@@ -202,6 +202,12 @@
 			system->enter_debugger = 0;
 			zdebugger(sms->z80, sms->z80->pc);
 		}
+		if (sms->z80->nmi_start == CYCLE_NEVER) {
+			uint32_t nmi = vdp_next_nmi(sms->vdp);
+			if (nmi != CYCLE_NEVER) {
+				z80_assert_nmi(sms->z80, nmi);
+			}
+		}
 		z80_run(sms->z80, target_cycle);
 		if (sms->z80->reset) {
 			z80_clear_reset(sms->z80, sms->z80->current_cycle + 128*15);
@@ -209,7 +215,7 @@
 		target_cycle = sms->z80->current_cycle;
 		vdp_run_context(sms->vdp, target_cycle);
 		psg_run(sms->psg, target_cycle);
-		target_cycle += 3420*262;
+		target_cycle += 3420*16;
 		if (target_cycle > 0x10000000) {
 			uint32_t adjust = sms->z80->current_cycle - 3420*262*2;
 			io_adjust_cycles(sms->io.ports, sms->z80->current_cycle, adjust);
@@ -355,6 +361,7 @@
 	sms->header.soft_reset = soft_reset;
 	sms->header.inc_debug_mode = inc_debug_mode;
 	sms->header.inc_debug_pal = inc_debug_pal;
+	sms->header.type = SYSTEM_SMS;
 	
 	return sms;
 }
\ No newline at end of file
--- a/vdp.c	Sun May 28 21:02:47 2017 -0700
+++ b/vdp.c	Sun May 28 21:03:55 2017 -0700
@@ -1685,6 +1685,9 @@
 	if (context->state == PREPARING) {
 		context->state = ACTIVE;
 	}
+	if (context->vcounter == 0x1FF) {
+		context->flags2 &= ~FLAG2_PAUSE;
+	}
 
 	if (context->state != ACTIVE) {
 		context->hint_counter = context->regs[REG_HINT];
@@ -3383,6 +3386,19 @@
 	return context->cycles + cycles_to_vint;
 }
 
+uint32_t vdp_next_nmi(vdp_context *context)
+{
+	if (!(context->flags2 & FLAG2_PAUSE)) {
+		return 0xFFFFFFFF;
+	}
+	return context->cycles + vdp_cycles_to_line(context, 0x1FF);
+}
+
+void vdp_pbc_pause(vdp_context *context)
+{
+	context->flags2 |= FLAG2_PAUSE;
+}
+
 void vdp_int_ack(vdp_context * context)
 {
 	//CPU interrupt acknowledge is only used in Mode 5
--- a/vdp.h	Sun May 28 21:02:47 2017 -0700
+++ b/vdp.h	Sun May 28 21:03:55 2017 -0700
@@ -59,6 +59,7 @@
 #define FLAG2_REGION_PAL     0x10
 #define FLAG2_EVEN_FIELD     0x20
 #define FLAG2_BYTE_PENDING   0x40
+#define FLAG2_PAUSE          0x80
 
 #define DISPLAY_ENABLE 0x40
 
@@ -238,6 +239,7 @@
 uint32_t vdp_next_hint(vdp_context * context);
 uint32_t vdp_next_vint(vdp_context * context);
 uint32_t vdp_next_vint_z80(vdp_context * context);
+uint32_t vdp_next_nmi(vdp_context *context);
 void vdp_int_ack(vdp_context * context);
 void vdp_print_sprite_table(vdp_context * context);
 void vdp_print_reg_explain(vdp_context * context);
@@ -245,5 +247,6 @@
 uint32_t vdp_cycles_to_frame_end(vdp_context * context);
 void write_cram(vdp_context * context, uint16_t address, uint16_t value);
 void vdp_check_update_sat_byte(vdp_context *context, uint32_t address, uint8_t value);
+void vdp_pbc_pause(vdp_context *context);
 
 #endif //VDP_H_