From 21ecaf237fe6abc22272ab2cbe2724a69bc3bc8b Mon Sep 17 00:00:00 2001
From: notaz <notasas@gmail.com>
Date: Sun, 2 Aug 2009 21:10:35 +0000
Subject: [PATCH] frame limiter opt, menu btn on cfg load fix

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@727 be3aeb3a-fb24-0410-a615-afba39da0efa
---
 platform/common/config.c | 13 ++-----------
 platform/common/emu.c    | 12 ++++++++----
 platform/common/menu.c   |  1 +
 platform/gp2x/in_gp2x.c  |  6 +++++-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/platform/common/config.c b/platform/common/config.c
index e47a4013..9d973fe0 100644
--- a/platform/common/config.c
+++ b/platform/common/config.c
@@ -490,6 +490,8 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
 			PsndRate = strtoul(val, &tmp, 10);
 			if (PsndRate < 8000 || PsndRate > 44100)
 				PsndRate = 22050;
+			if (*tmp == 'H' || *tmp == 'h') tmp++;
+			if (*tmp == 'Z' || *tmp == 'z') tmp++;
 			while (*tmp == ' ') tmp++;
 			if        (strcasecmp(tmp, "stereo") == 0) {
 				PicoOpt |=  POPT_EN_STEREO;
@@ -551,17 +553,6 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
 				return 0;
 			return 1;
 
-#if 0 // TODO rm?
-		case MA_OPT_CPU_CLOCKS:
-#ifdef __GP2X__
-			if (strcasecmp(var, "GP2X CPU clocks") != 0) return 0;
-#elif defined(PSP)
-			if (strcasecmp(var, "PSP CPU clock") != 0) return 0;
-#endif
-			currentConfig.CPUclock = atoi(val);
-			return 1;
-#endif
-
 		case MA_OPT2_GAMMA:
 			if (strcasecmp(var, "Gamma correction") != 0) return 0;
 			currentConfig.gamma = (int) (atof(val) * 100.0);
diff --git a/platform/common/emu.c b/platform/common/emu.c
index 5bd34e87..7c406b53 100644
--- a/platform/common/emu.c
+++ b/platform/common/emu.c
@@ -1325,10 +1325,14 @@ void emu_loop(void)
 
 		if (timestamp - timestamp_base >= ms_to_ticks(1000))
 		{
-			if (PsndOut == 0 && currentConfig.Frameskip >= 0)
+			if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && currentConfig.Frameskip >= 0)
 				pframes_done = 0;
-			else
+			else {
 				pframes_done -= target_fps;
+				/* don't allow it to drift during heavy slowdowns */
+				if (pframes_done < -2)
+					pframes_done = -2;
+			}
 			timestamp_base += ms_to_ticks(1000);
 		}
 
@@ -1343,7 +1347,7 @@ void emu_loop(void)
 				pframes_done++; frames_done++;
 				diff_lim += target_frametime;
 
-				if (PsndOut && !reset_timing) { // do framelimitting if sound is enabled
+				if (!(currentConfig.EmuOpt & EOPT_NO_FRMLIMIT)) {
 					timestamp = get_ticks();
 					diff = timestamp - timestamp_base;
 					if (diff < diff_lim) // we are too fast
@@ -1369,7 +1373,7 @@ void emu_loop(void)
 		PicoFrame();
 
 		/* frame limiter */
-		if (!reset_timing && (PsndOut != NULL || currentConfig.Frameskip < 0))
+		if (!reset_timing && !(currentConfig.EmuOpt & EOPT_NO_FRMLIMIT))
 		{
 			timestamp = get_ticks();
 			diff = timestamp - timestamp_base;
diff --git a/platform/common/menu.c b/platform/common/menu.c
index 97c22e3d..4a01896e 100644
--- a/platform/common/menu.c
+++ b/platform/common/menu.c
@@ -1450,6 +1450,7 @@ static menu_entry e_menu_adv_options[] =
 	mee_onoff     ("gzip savestates",          MA_OPT2_GZIP_STATES,   currentConfig.EmuOpt, EOPT_GZIP_SAVES),
 	mee_onoff     ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM,   currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
 	mee_onoff     ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),
+	mee_onoff     ("Disable frame limiter",    MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
 	MENU_GP2X_OPTIONS_ADV
 	mee_end,
 };
diff --git a/platform/gp2x/in_gp2x.c b/platform/gp2x/in_gp2x.c
index ec50a360..818aead9 100644
--- a/platform/gp2x/in_gp2x.c
+++ b/platform/gp2x/in_gp2x.c
@@ -104,7 +104,6 @@ static void in_gp2x_probe(void)
 			return;
 		}
 		in_gp2x_get_bits = in_gp2x_get_wiz_bits;
-		in_gp2x_keys[BTN_START] = "MENU";
 		break;
 	default:
 #ifdef FAKE_IN_GP2X
@@ -318,7 +317,12 @@ static int in_gp2x_clean_binds(void *drv_data, int *binds, int *def_binds)
 void in_gp2x_init(void *vdrv)
 {
 	in_drv_t *drv = vdrv;
+	gp2x_soc_t soc;
 
+	soc = soc_detect();
+	if (soc == SOCID_POLLUX)
+		in_gp2x_keys[BTN_START] = "MENU";
+	
 	in_gp2x_combo_keys = in_gp2x_combo_acts = 0;
 
 	drv->prefix = in_gp2x_prefix;
-- 
2.39.5