#include <assert.h>
#include "cdrom.h"
+#include "misc.h"
#include "ppf.h"
#include "psxdma.h"
#include "arm_features.h"
unsigned char Absolute[3];
} subq;
unsigned char TrackChanged;
- unsigned char unused3[3];
+ unsigned char ReportDelay;
+ unsigned char unused3[2];
unsigned int freeze_ver;
unsigned char Prev[4];
u16 CmdInProgress;
u8 Irq1Pending;
u8 unused5;
- u32 unused6;
+ u32 LastReadCycles;
u8 unused7;
u8 DriveState;
u8 FastForward;
u8 FastBackward;
- u8 unused8;
+ u8 errorRetryhack;
u8 AttenuatorLeftToLeft, AttenuatorLeftToRight;
u8 AttenuatorRightToRight, AttenuatorRightToLeft;
StopCdda();
SetPlaySeekRead(cdr.StatP, 0);
}
- else if (((cdr.Mode & MODE_REPORT) || cdr.FastForward || cdr.FastBackward)) {
+ else if ((cdr.Mode & MODE_REPORT) && !cdr.ReportDelay &&
+ ((cdr.subq.Absolute[2] & 0x0f) == 0 || cdr.FastForward || cdr.FastBackward))
+ {
cdr.Result[0] = cdr.StatP;
cdr.Result[1] = cdr.subq.Track;
cdr.Result[2] = cdr.subq.Index;
SetResultSize(8);
setIrq(0x1001);
}
+
+ if (cdr.ReportDelay)
+ cdr.ReportDelay--;
}
+// LastReadCycles
static int cdrSeekTime(unsigned char *target)
{
int diff = msf2sec(cdr.SetSectorPlay) - msf2sec(target);
- int seekTime = abs(diff) * (cdReadTime / 200);
- /*
- * Gameblabla :
- * It was originally set to 1000000 for Driver, however it is not high enough for Worms Pinball
- * and was unreliable for that game.
- * I also tested it against Mednafen and Driver's titlescreen music starts 25 frames later, not immediatly.
- *
- * Obviously, this isn't perfect but right now, it should be a bit better.
- * Games to test this against if you change that setting :
- * - Driver (titlescreen music delay and retry mission)
- * - Worms Pinball (Will either not boot or crash in the memory card screen)
- * - Viewpoint (short pauses if the delay in the ingame music is too long)
- *
- * It seems that 3386880 * 5 is too much for Driver's titlescreen and it starts skipping.
- * However, 1000000 is not enough for Worms Pinball to reliably boot.
- */
- if(seekTime > 3386880 * 2) seekTime = 3386880 * 2;
+ int pausePenalty, seekTime = abs(diff) * (cdReadTime / 2000);
+ seekTime = MAX_VALUE(seekTime, 20000);
+
+ // need this stupidly long penalty or else Spyro2 intro desyncs
+ pausePenalty = (s32)(psxRegs.cycle - cdr.LastReadCycles) > cdReadTime * 4 ? cdReadTime * 25 : 0;
+ seekTime += pausePenalty;
+
+ seekTime = MIN_VALUE(seekTime, PSXCLK * 2 / 3);
CDR_LOG("seek: %.2f %.2f\n", (float)seekTime / PSXCLK, (float)seekTime / cdReadTime);
return seekTime;
}
void cdrPlayReadInterrupt(void)
{
+ cdr.LastReadCycles = psxRegs.cycle;
+
if (cdr.Reading) {
cdrReadInterrupt();
return;
if (((cdr.Param[0] & 0x0F) > 0x09) || (cdr.Param[0] > 0x99) || ((cdr.Param[1] & 0x0F) > 0x09) || (cdr.Param[1] >= 0x60) || ((cdr.Param[2] & 0x0F) > 0x09) || (cdr.Param[2] >= 0x75))
{
CDR_LOG_I("Invalid/out of range seek to %02X:%02X:%02X\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]);
+ if (++cdr.errorRetryhack > 100)
+ break;
error = ERROR_INVALIDARG;
goto set_error;
}
memcpy(cdr.SetSector, set_loc, 3);
cdr.SetSector[3] = 0;
cdr.SetlocPending = 1;
+ cdr.errorRetryhack = 0;
}
break;
cdr.SubqForwardSectors = 1;
cdr.TrackChanged = FALSE;
cdr.FirstSector = 1;
+ cdr.ReportDelay = 60;
if (!Config.Cdda)
CDR_play(cdr.SetSectorPlay);
}
else
{
- second_resp_time = (((cdr.Mode & MODE_SPEED) ? 2 : 1) * 1000000);
+ second_resp_time = (((cdr.Mode & MODE_SPEED) ? 1 : 2) * 1097107);
}
SetPlaySeekRead(cdr.StatP, 0);
break;
}
void psxDma3(u32 madr, u32 bcr, u32 chcr) {
- u32 cdsize;
+ u32 cdsize, max_words;
int size;
u8 *ptr;
switch (chcr & 0x71000000) {
case 0x11000000:
- ptr = (u8 *)PSXM(madr);
+ ptr = getDmaRam(madr, &max_words);
if (ptr == INVALID_PTR) {
CDR_LOG_I("psxDma3() Log: *** DMA 3 *** NULL Pointer!\n");
break;
size = DATA_SIZE - cdr.FifoOffset;
if (size > cdsize)
size = cdsize;
+ if (size > max_words * 4)
+ size = max_words * 4;
if (size > 0)
{
memcpy(ptr, cdr.Transfer + cdr.FifoOffset, size);
Find_CurTrack(cdr.SetSectorPlay);
if (!Config.Cdda)
CDR_play(cdr.SetSectorPlay);
- if (psxRegs.interrupt & (1 << PSXINT_CDRPLAY_OLD))
- CDRPLAYREAD_INT((cdr.Mode & MODE_SPEED) ? (cdReadTime / 2) : cdReadTime, 1);
}
if ((cdr.freeze_ver & 0xffffff00) != 0x63647200) {