From 688bdb9526d42181368e64ceaa6828727a10188c Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 12 Nov 2022 23:05:52 +0200 Subject: [PATCH] cdrom: make the timing hack conditional libretro/pcsx_rearmed#707 --- libpcsxcore/cdrom.c | 11 +++++++-- libpcsxcore/database.c | 53 ++++++++++++++++++++++++++++++++--------- libpcsxcore/psxcommon.h | 3 +++ 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 0f1479e2..18d6bf9e 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -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); diff --git a/libpcsxcore/database.c b/libpcsxcore/database.c index 1ea8d43b..f947b068 100644 --- a/libpcsxcore/database.c +++ b/libpcsxcore/database.c @@ -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