psxbios: implement yet more memcard details
[pcsx_rearmed.git] / libpcsxcore / misc.c
index 526ebd4..0848c26 100644 (file)
@@ -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)
@@ -294,7 +301,7 @@ int LoadCdrom() {
        return 0;
 }
 
-int LoadCdromFile(const char *filename, EXE_HEADER *head) {
+int LoadCdromFile(const char *filename, EXE_HEADER *head, u8 *time_bcd_out) {
        struct iso_directory_record *dir;
        u8 time[4],*buf;
        u8 mdir[4096];
@@ -327,6 +334,7 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) {
        if (GetCdromFile(mdir, time, exename) == -1) return -1;
 
        READTRACK();
+       incTime();
 
        memcpy(head, buf + 12, sizeof(EXE_HEADER));
        size = SWAP32(head->t_size);
@@ -336,8 +344,8 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) {
        //psxCpu->Reset();
 
        while (size & ~2047) {
-               incTime();
                READTRACK();
+               incTime();
 
                mem = PSXM(addr);
                if (mem != INVALID_PTR)
@@ -346,6 +354,8 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) {
                size -= 2048;
                addr += 2048;
        }
+       if (time_bcd_out)
+               memcpy(time_bcd_out, time, 3);
 
        return 0;
 }
@@ -667,6 +677,10 @@ int SaveState(const char *file) {
        assert(!psxRegs.branching);
        assert(!psxRegs.cpuInRecursion);
        assert(!misc->magic);
+
+       f = SaveFuncs.open(file, "wb");
+       if (f == NULL) return -1;
+
        misc->magic = MISC_MAGIC;
        misc->gteBusyCycle = psxRegs.gteBusyCycle;
        misc->muldivBusyCycle = psxRegs.muldivBusyCycle;
@@ -677,9 +691,6 @@ int SaveState(const char *file) {
        misc->frame_counter = frame_counter;
        misc->CdromFrontendId = CdromFrontendId;
 
-       f = SaveFuncs.open(file, "wb");
-       if (f == NULL) return -1;
-
        psxCpu->Notify(R3000ACPU_NOTIFY_BEFORE_SAVE, NULL);
 
        SaveFuncs.write(f, (void *)PcsxHeader, 32);