cdrom: make the timing hack conditional
authornotaz <notasas@gmail.com>
Sat, 12 Nov 2022 21:05:52 +0000 (23:05 +0200)
committernotaz <notasas@gmail.com>
Sat, 12 Nov 2022 21:05:52 +0000 (23:05 +0200)
libretro/pcsx_rearmed#707

libpcsxcore/cdrom.c
libpcsxcore/database.c
libpcsxcore/psxcommon.h

index 0f1479e..18d6bf9 100644 (file)
@@ -597,8 +597,14 @@ static u32 cdrAlignTimingHack(u32 cycles)
         * active), but before the game's handler loop reads I_STAT. The time
         * window for this is quite small (~1k cycles of so). Apparently this
         * somehow happens naturally on the real hardware.
+        *
+        * Note: always enforcing this breaks other games like Crash PAL version
+        * (inputs get dropped because bios handler doesn't see interrupts).
         */
-       u32 vint_rel = rcnts[3].cycleStart + 63000 - psxRegs.cycle;
+       u32 vint_rel;
+       if (psxRegs.cycle - rcnts[3].cycleStart > 250000)
+               return cycles;
+       vint_rel = rcnts[3].cycleStart + 63000 - psxRegs.cycle;
        vint_rel += PSXCLK / 60;
        while ((s32)(vint_rel - cycles) < 0)
                vint_rel += PSXCLK / 60;
@@ -1154,7 +1160,8 @@ void cdrInterrupt(void) {
 
                        cycles = (cdr.Mode & 0x80) ? cdReadTime : cdReadTime * 2;
                        cycles += seekTime;
-                       cycles = cdrAlignTimingHack(cycles);
+                       if (Config.hacks.cdr_read_timing)
+                               cycles = cdrAlignTimingHack(cycles);
                        CDRPLAYREAD_INT(cycles, 1);
 
                        SetPlaySeekRead(cdr.StatP, STATUS_SEEK);
index 1ea8d43..f947b06 100644 (file)
@@ -5,16 +5,32 @@
 /* It's duplicated from emu_if.c */
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 
-static const char MemorycardHack_db[8][10] =
+static const char * const MemorycardHack_db[] =
 {
        /* Lifeforce Tenka, also known as Codename Tenka */
-       {"SLES00613"},
-       {"SLED00690"},
-       {"SLES00614"},
-       {"SLES00615"},
-       {"SLES00616"},
-       {"SLES00617"},
-       {"SCUS94409"}
+       "SLES00613", "SLED00690", "SLES00614", "SLES00615",
+       "SLES00616", "SLES00617", "SCUS94409"
+};
+
+static const char * const cdr_read_hack_db[] =
+{
+       /* T'ai Fu - Wrath of the Tiger */
+       "SLUS00787",
+};
+
+#define HACK_ENTRY(var, list) \
+       { #var, &Config.hacks.var, list, ARRAY_SIZE(list) }
+
+static const struct
+{
+       const char *name;
+       boolean *var;
+       const char * const * id_list;
+       size_t id_list_len;
+}
+hack_db[] =
+{
+       HACK_ENTRY(cdr_read_timing, cdr_read_hack_db),
 };
 
 static const struct
@@ -42,10 +58,24 @@ cycle_multiplier_overrides[] =
 /* Function for automatic patching according to GameID. */
 void Apply_Hacks_Cdrom()
 {
-       uint32_t i;
-       
+       size_t i, j;
+
+       memset(&Config.hacks, 0, sizeof(Config.hacks));
+
+       for (i = 0; i < ARRAY_SIZE(hack_db); i++)
+       {
+               for (j = 0; j < hack_db[i].id_list_len; j++)
+               {
+                       if (strncmp(CdromId, hack_db[i].id_list[j], 9))
+                               continue;
+                       *hack_db[i].var = 1;
+                       SysPrintf("using hack: %s\n", hack_db[i].name);
+                       break;
+               }
+       }
+
        /* Apply Memory card hack for Codename Tenka. (The game needs one of the memory card slots to be empty) */
-       for(i=0;i<ARRAY_SIZE(MemorycardHack_db);i++)
+       for (i = 0; i < ARRAY_SIZE(MemorycardHack_db); i++)
        {
                if (strncmp(CdromId, MemorycardHack_db[i], 9) == 0)
                {
@@ -53,6 +83,7 @@ void Apply_Hacks_Cdrom()
                        Config.Mcd2[0] = 0;
                        /* This also needs to be done because in sio.c, they don't use Config.Mcd2 for that purpose */
                        McdDisable[1] = 1;
+                       break;
                }
        }
 
index 522abbc..e0876cf 100644 (file)
@@ -145,6 +145,9 @@ typedef struct {
        int cycle_multiplier_override;
        u8 Cpu; // CPU_DYNAREC or CPU_INTERPRETER
        u8 PsxType; // PSX_TYPE_NTSC or PSX_TYPE_PAL
+       struct {
+               boolean cdr_read_timing;
+       } hacks;
 #ifdef _WIN32
        char Lang[256];
 #endif