X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fcdrom.c;h=17d65ab8f3621f45a51e9c9d48581a41f22cdfeb;hb=HEAD;hp=b980be0613e56a269051fedaf81669a0abf44cbf;hpb=1237304d5560b492b8601a04e5cfa30b56f1537a;p=pcsx_rearmed.git diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index b980be06..d4d14742 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -68,7 +68,7 @@ static struct { } subq; unsigned char TrackChanged; unsigned char ReportDelay; - unsigned char unused3; + unsigned char PhysCdPropagations; unsigned short sectorsRead; unsigned int freeze_ver; @@ -583,19 +583,15 @@ static int cdrSeekTime(unsigned char *target) int cyclesSinceRS = psxRegs.cycle - cdr.LastReadSeekCycles; seekTime = MAX_VALUE(seekTime, 20000); - // need this stupidly long penalty or else Spyro2 intro desyncs - // note: if misapplied this breaks MGS cutscenes among other things - if (cdr.DriveState == DRIVESTATE_PAUSED && cyclesSinceRS > cdReadTime * 50) - seekTime += cdReadTime * 25; // Transformers Beast Wars Transmetals does Setloc(x),SeekL,Setloc(x),ReadN // and then wants some slack time - else if (cdr.DriveState == DRIVESTATE_PAUSED || cyclesSinceRS < cdReadTime *3/2) + if (cdr.DriveState == DRIVESTATE_PAUSED || cyclesSinceRS < cdReadTime *3/2) seekTime += cdReadTime; seekTime = MIN_VALUE(seekTime, PSXCLK * 2 / 3); - CDR_LOG("seek: %.2f %.2f (%.2f) st %d\n", (float)seekTime / PSXCLK, + CDR_LOG("seek: %.2f %.2f (%.2f) st %d di %d\n", (float)seekTime / PSXCLK, (float)seekTime / cdReadTime, (float)cyclesSinceRS / cdReadTime, - cdr.DriveState); + cdr.DriveState, diff); return seekTime; } @@ -660,6 +656,14 @@ static void msfiSub(u8 *msfi, u32 count) void cdrPlayReadInterrupt(void) { + int hit = CDR_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2]); + if (!hit && cdr.PhysCdPropagations++ < 222) { + // this propagates real cdrom delays to the emulated game + CDRPLAYREAD_INT(cdReadTime / 2, 0); + return; + } + cdr.PhysCdPropagations = 0; + cdr.LastReadSeekCycles = psxRegs.cycle; if (cdr.Reading) { @@ -694,6 +698,7 @@ void cdrPlayReadInterrupt(void) } msfiAdd(cdr.SetSectorPlay, 1); + CDR_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2]); // update for CdlGetlocP/autopause generate_subq(cdr.SetSectorPlay); @@ -701,6 +706,30 @@ void cdrPlayReadInterrupt(void) CDRPLAYREAD_INT(cdReadTime, 0); } +static void softReset(void) +{ + 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; + } + else { + cdr.DriveState = DRIVESTATE_STANDBY; + cdr.StatP = STATUS_ROTATING; + } + + cdr.FifoOffset = DATA_SIZE; // fifo empty + cdr.LocL[0] = LOCL_INVALID; + cdr.Mode = MODE_SIZE_2340; + cdr.Muted = FALSE; + SPU_setCDvol(cdr.AttenuatorLeftToLeft, cdr.AttenuatorLeftToRight, + cdr.AttenuatorRightToLeft, cdr.AttenuatorRightToRight, psxRegs.cycle); +} + #define CMD_PART2 0x100 #define CMD_WHILE_NOT_READY 0x200 @@ -942,27 +971,19 @@ void cdrInterrupt(void) { cdr.sectorsRead = 0; /* - Gundam Battle Assault 2: much slower (*) - - Fixes boot, gameplay - - Hokuto no Ken 2: slower - - Fixes intro + subtitles - - InuYasha - Feudal Fairy Tale: slower - - Fixes battles + Gundam Battle Assault 2 + Hokuto no Ken 2 + InuYasha - Feudal Fairy Tale + Dance Dance Revolution Konamix + ... */ - /* Gameblabla - Tightening the timings (as taken from Duckstation). - * The timings from Duckstation are based upon hardware tests. - * Mednafen's timing don't work for Gundam Battle Assault 2 in PAL/50hz mode, - * seems to be timing sensitive as it can depend on the CPU's clock speed. - * */ if (!(cdr.StatP & (STATUS_PLAY | STATUS_READ))) { second_resp_time = 7000; } else { - second_resp_time = (((cdr.Mode & MODE_SPEED) ? 1 : 2) * 1097107); + second_resp_time = 2 * 1097107; } SetPlaySeekRead(cdr.StatP, 0); DriveStateOld = cdr.DriveState; @@ -983,15 +1004,11 @@ void cdrInterrupt(void) { case CdlReset: case CdlReset + CMD_WHILE_NOT_READY: + // note: nocash and Duckstation calls this 'Init', but + // the official SDK calls it 'Reset', and so do we StopCdda(); StopReading(); - SetPlaySeekRead(cdr.StatP, 0); - cdr.LocL[0] = LOCL_INVALID; - cdr.Mode = MODE_SIZE_2340; /* This fixes This is Football 2, Pooh's Party lockups */ - cdr.DriveState = DRIVESTATE_PAUSED; - cdr.Muted = FALSE; - SPU_setCDvol(cdr.AttenuatorLeftToLeft, cdr.AttenuatorLeftToRight, - cdr.AttenuatorRightToLeft, cdr.AttenuatorRightToRight, psxRegs.cycle); + softReset(); second_resp_time = not_ready ? 70000 : 4100000; start_rotating = 1; break; @@ -1089,6 +1106,8 @@ void cdrInterrupt(void) { seekTime = cdrSeekTime(cdr.SetSector); memcpy(cdr.SetSectorPlay, cdr.SetSector, 4); cdr.DriveState = DRIVESTATE_SEEK; + CDR_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], + cdr.SetSectorPlay[2]); /* Crusaders of Might and Magic = 0.5x-4x - fix cutscene speech start @@ -1226,6 +1245,8 @@ void cdrInterrupt(void) { cdr.SubqForwardSectors = 1; cdr.sectorsRead = 0; cdr.DriveState = DRIVESTATE_SEEK; + CDR_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], + cdr.SetSectorPlay[2]); cycles = (cdr.Mode & MODE_SPEED) ? cdReadTime : cdReadTime * 2; cycles += seekTime; @@ -1366,7 +1387,7 @@ static void cdrReadInterrupt(void) subhdr->file, subhdr->chan, cdr.CurFile, cdr.CurChannel, cdr.FilterFile, cdr.FilterChannel); if ((cdr.Mode & MODE_SF) && (subhdr->file != cdr.FilterFile || subhdr->chan != cdr.FilterChannel)) break; - if (subhdr->chan & 0xe0) { // ? + if (subhdr->chan & 0x80) { // ? if (subhdr->chan != 0xff) log_unhandled("adpcm %d:%d\n", subhdr->file, subhdr->chan); break; @@ -1403,6 +1424,7 @@ static void cdrReadInterrupt(void) cdrReadInterruptSetResult(cdr.StatP); msfiAdd(cdr.SetSectorPlay, 1); + CDR_prefetch(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2]); CDRPLAYREAD_INT((cdr.Mode & MODE_SPEED) ? (cdReadTime / 2) : cdReadTime, 0); } @@ -1715,30 +1737,14 @@ void cdrReset() { cdr.FilterChannel = 0; cdr.IrqMask = 0x1f; cdr.IrqStat = NoIntr; - cdr.FifoOffset = DATA_SIZE; // fifo empty - 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; - } - else { - cdr.DriveState = DRIVESTATE_STANDBY; - cdr.StatP = STATUS_ROTATING; - } - // BIOS player - default values cdr.AttenuatorLeftToLeft = 0x80; cdr.AttenuatorLeftToRight = 0x00; cdr.AttenuatorRightToLeft = 0x00; cdr.AttenuatorRightToRight = 0x80; - SPU_setCDvol(cdr.AttenuatorLeftToLeft, cdr.AttenuatorLeftToRight, - cdr.AttenuatorRightToLeft, cdr.AttenuatorRightToRight, psxRegs.cycle); + softReset(); getCdInfo(); }