From 02b1a085fcb5bbabc4a9148daba91c3dc0a798f8 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 29 Oct 2023 01:19:32 +0300 Subject: [PATCH] cdrom: allow resetting with lid open libretro/pcsx_rearmed#679 --- libpcsxcore/cdriso.c | 1 - libpcsxcore/cdrom.c | 8 +++++++- libpcsxcore/misc.c | 9 ++++++++- libpcsxcore/misc.h | 2 +- libpcsxcore/plugins.h | 2 ++ libpcsxcore/r3000a.c | 3 +-- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 660d109c..ecf42409 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -103,7 +103,6 @@ long CALLBACK CDR__configure(void); long CALLBACK CDR__test(void); void CALLBACK CDR__about(void); long CALLBACK CDR__setfilename(char *filename); -long CALLBACK CDR__getStatus(struct CdrStat *stat); static void DecodeRawSubData(void); diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 99e8dcd6..6f4e3eb4 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -1694,7 +1694,13 @@ void cdrReset() { cdr.Reg2 = 0x1f; cdr.Stat = NoIntr; cdr.FifoOffset = DATA_SIZE; // fifo empty - if (CdromId[0] == '\0') { + + CDR_getStatus(&stat); + if (stat.Status & STATUS_SHELLOPEN) { + cdr.DriveState = DRIVESTATE_LID_OPEN; + cdr.StatP = STATUS_SHELLOPEN; + } + else if (CdromId[0] == '\0') { cdr.DriveState = DRIVESTATE_STOPPED; cdr.StatP = 0; } diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 526ebd43..f175e2a3 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -163,12 +163,19 @@ static void SetBootRegs(u32 pc, u32 gp, u32 sp) psxCpu->Notify(R3000ACPU_NOTIFY_AFTER_LOAD, NULL); } -void BiosBootBypass() { +int BiosBootBypass() { + struct CdrStat stat = { 0, 0, }; assert(psxRegs.pc == 0x80030000); + // no bypass if the lid is open + CDR__getStatus(&stat); + if (stat.Status & 0x10) + return 0; + // skip BIOS logos and region check psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL); psxRegs.pc = psxRegs.GPR.n.ra; + return 1; } static void getFromCnf(char *buf, const char *key, u32 *val) diff --git a/libpcsxcore/misc.h b/libpcsxcore/misc.h index a1c36bb9..539acc7b 100644 --- a/libpcsxcore/misc.h +++ b/libpcsxcore/misc.h @@ -57,7 +57,7 @@ extern char CdromId[10]; extern char CdromLabel[33]; extern int CdromFrontendId; // for frontend use -void BiosBootBypass(); +int BiosBootBypass(); int LoadCdrom(); int LoadCdromFile(const char *filename, EXE_HEADER *head); diff --git a/libpcsxcore/plugins.h b/libpcsxcore/plugins.h index d2086656..b106028c 100644 --- a/libpcsxcore/plugins.h +++ b/libpcsxcore/plugins.h @@ -161,6 +161,8 @@ extern CDRsetfilename CDR_setfilename; extern CDRreadCDDA CDR_readCDDA; extern CDRgetTE CDR_getTE; +long CALLBACK CDR__getStatus(struct CdrStat *stat); + // SPU Functions typedef long (CALLBACK* SPUinit)(void); typedef long (CALLBACK* SPUshutdown)(void); diff --git a/libpcsxcore/r3000a.c b/libpcsxcore/r3000a.c index fb043ae0..0c29dba7 100644 --- a/libpcsxcore/r3000a.c +++ b/libpcsxcore/r3000a.c @@ -76,8 +76,7 @@ void psxReset() { if (!Config.HLE) { psxExecuteBios(); if (psxRegs.pc == 0x80030000 && !Config.SlowBoot) { - BiosBootBypass(); - introBypassed = TRUE; + introBypassed = BiosBootBypass(); } } if (Config.HLE || introBypassed) -- 2.39.2