From: notaz <notasas@gmail.com>
Date: Thu, 13 Jul 2023 23:05:30 +0000 (+0300)
Subject: adjust bios handling again
X-Git-Tag: r24~248
X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da65071fd7ceac663bb951b13da2563d7b16431d;p=pcsx_rearmed.git

adjust bios handling again

changed my mind about BiosBooted
---

diff --git a/frontend/libretro.c b/frontend/libretro.c
index 5acaba8b..4477183a 100644
--- a/frontend/libretro.c
+++ b/frontend/libretro.c
@@ -501,7 +501,7 @@ struct rearmed_cbs pl_rearmed_cbs = {
 void pl_frame_limit(void)
 {
    /* called once per frame, make psxCpu->Execute() above return */
-   stop = 1;
+   stop++;
 }
 
 void pl_timing_prepare(int is_pal)
diff --git a/frontend/main.c b/frontend/main.c
index 7d140f82..11bc4ed4 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -487,7 +487,7 @@ int emu_core_init(void)
 
 void emu_core_ask_exit(void)
 {
-	stop = 1;
+	stop++;
 	g_emu_want_quit = 1;
 }
 
diff --git a/frontend/main.h b/frontend/main.h
index 7ce9e5d6..22053bbc 100644
--- a/frontend/main.h
+++ b/frontend/main.h
@@ -91,7 +91,7 @@ static inline void emu_set_action(enum sched_action action_)
 	if (action_ == SACTION_NONE)
 		emu_action_old = 0;
 	else if (action_ != emu_action_old)
-		stop = 1;
+		stop++;
 	emu_action = action_;
 }
 
diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c
index 678f2dbf..223266ba 100644
--- a/libpcsxcore/misc.c
+++ b/libpcsxcore/misc.c
@@ -196,9 +196,10 @@ int LoadCdrom() {
 	char exename[256];
 
 	if (!Config.HLE) {
-		if (!BiosBooted) return 0;              // custom BIOS
-		if (psxRegs.pc != 0x80030000) return 0; // BiosBootBypass'ed
-		if (Config.SlowBoot) return 0;
+		if (psxRegs.pc != 0x80030000) // BiosBootBypass'ed or custom BIOS?
+			return 0;
+		if (Config.SlowBoot)
+			return 0;
 	}
 
 	time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10);
diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c
index f7135872..e89b635f 100644
--- a/libpcsxcore/new_dynarec/emu_if.c
+++ b/libpcsxcore/new_dynarec/emu_if.c
@@ -265,6 +265,17 @@ static void ari64_execute()
 	}
 }
 
+static void ari64_execute_block(enum blockExecCaller caller)
+{
+	if (caller == EXEC_CALLER_BOOT)
+		stop++;
+
+	ari64_execute_until();
+
+	if (caller == EXEC_CALLER_BOOT)
+		stop--;
+}
+
 static void ari64_clear(u32 addr, u32 size)
 {
 	size *= 4; /* PCSX uses DMA units (words) */
@@ -315,7 +326,7 @@ R3000Acpu psxRec = {
 	ari64_init,
 	ari64_reset,
 	ari64_execute,
-	ari64_execute_until,
+	ari64_execute_block,
 	ari64_clear,
 	ari64_notify,
 	ari64_apply_config,
diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c
index f57f5129..d31465cf 100644
--- a/libpcsxcore/psxbios.c
+++ b/libpcsxcore/psxbios.c
@@ -285,7 +285,7 @@ static inline void softCall(u32 pc) {
 
 	hleSoftCall = TRUE;
 
-	while (pc0 != 0x80001000) psxCpu->ExecuteBlock();
+	while (pc0 != 0x80001000) psxCpu->ExecuteBlock(EXEC_CALLER_HLE);
 
 	hleSoftCall = FALSE;
 }
@@ -297,7 +297,7 @@ static inline void softCall2(u32 pc) {
 
 	hleSoftCall = TRUE;
 
-	while (pc0 != 0x80001000) psxCpu->ExecuteBlock();
+	while (pc0 != 0x80001000) psxCpu->ExecuteBlock(EXEC_CALLER_HLE);
 	ra = sra;
 
 	hleSoftCall = FALSE;
diff --git a/libpcsxcore/psxcommon.c b/libpcsxcore/psxcommon.c
index fcc3debf..8313304c 100644
--- a/libpcsxcore/psxcommon.c
+++ b/libpcsxcore/psxcommon.c
@@ -26,7 +26,6 @@
 
 PcsxConfig Config;
 boolean NetOpened = FALSE;
-boolean BiosBooted = FALSE;
 
 int Log = 0;
 FILE *emuLog = NULL;
diff --git a/libpcsxcore/psxcommon.h b/libpcsxcore/psxcommon.h
index 67a0ae08..92e69eee 100644
--- a/libpcsxcore/psxcommon.h
+++ b/libpcsxcore/psxcommon.h
@@ -154,7 +154,6 @@ typedef struct {
 
 extern PcsxConfig Config;
 extern boolean NetOpened;
-extern boolean BiosBooted;
 
 struct PcsxSaveFuncs {
 	void *(*open)(const char *name, const char *mode);
diff --git a/libpcsxcore/psxinterpreter.c b/libpcsxcore/psxinterpreter.c
index f59934ae..8e0aafed 100644
--- a/libpcsxcore/psxinterpreter.c
+++ b/libpcsxcore/psxinterpreter.c
@@ -1102,7 +1102,7 @@ static void intExecute() {
 		execI_(memRLUT, regs_);
 }
 
-void intExecuteBlock() {
+void intExecuteBlock(enum blockExecCaller caller) {
 	psxRegisters *regs_ = &psxRegs;
 	u8 **memRLUT = psxMemRLUT;
 
diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c
index 53a5ebac..fbccdea4 100644
--- a/libpcsxcore/r3000a.c
+++ b/libpcsxcore/r3000a.c
@@ -69,7 +69,6 @@ void psxReset() {
 
 	BiosLikeGPUSetup(); // a bit of a hack but whatever
 
-	BiosBooted = FALSE;
 	if (!Config.HLE) {
 		psxExecuteBios();
 		if (psxRegs.pc == 0x80030000 && !Config.SlowBoot)
@@ -244,11 +243,12 @@ void psxJumpTest() {
 
 void psxExecuteBios() {
 	int i;
-	for (i = 0; psxRegs.pc != 0x80030000 && i < 5000000; i++)
-		psxCpu->ExecuteBlock();
-	if (psxRegs.pc == 0x80030000)
-		BiosBooted = TRUE;
-	else
-		SysPrintf("BIOS boot timeout - custom BIOS?\n");
+	for (i = 0; i < 5000000; i++) {
+		psxCpu->ExecuteBlock(EXEC_CALLER_BOOT);
+		if ((psxRegs.pc & 0xff800000) == 0x80000000)
+			break;
+	}
+	if (psxRegs.pc != 0x80030000)
+		SysPrintf("non-standard BIOS detected (%d, %08x)\n", i, psxRegs.pc);
 }
 
diff --git a/libpcsxcore/r3000a.h b/libpcsxcore/r3000a.h
index 229b14a1..8d53a181 100644
--- a/libpcsxcore/r3000a.h
+++ b/libpcsxcore/r3000a.h
@@ -36,11 +36,16 @@ enum R3000Anote {
 	R3000ACPU_NOTIFY_AFTER_LOAD,
 };
 
+enum blockExecCaller {
+	EXEC_CALLER_BOOT,
+	EXEC_CALLER_HLE,
+};
+
 typedef struct {
 	int  (*Init)();
 	void (*Reset)();
-	void (*Execute)();		/* executes up to a break */
-	void (*ExecuteBlock)();	/* executes up to a jump */
+	void (*Execute)();
+	void (*ExecuteBlock)(enum blockExecCaller caller); /* executes up to a jump */
 	void (*Clear)(u32 Addr, u32 Size);
 	void (*Notify)(enum R3000Anote note, void *data);
 	void (*ApplyConfig)();