Skip to content

Commit

Permalink
cdrom: try more states
Browse files Browse the repository at this point in the history
let's see what else breaks now

libretro#796
  • Loading branch information
notaz committed Nov 13, 2023
1 parent c2a25f6 commit cc1e8bd
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions libpcsxcore/cdrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static struct {

u8 unused7;

u8 DriveState;
u8 DriveState; // enum drive_state
u8 FastForward;
u8 FastBackward;
u8 errorRetryhack;
Expand Down Expand Up @@ -222,11 +222,14 @@ unsigned char Test23[] = { 0x43, 0x58, 0x44, 0x32, 0x39 ,0x34, 0x30, 0x51 };
#define SUBQ_FORWARD_SECTORS 2u

enum drive_state {
DRIVESTATE_STANDBY = 0, // pause, play, read
DRIVESTATE_STANDBY = 0, // different from paused
DRIVESTATE_LID_OPEN,
DRIVESTATE_RESCAN_CD,
DRIVESTATE_PREPARE_CD,
DRIVESTATE_STOPPED,
DRIVESTATE_PAUSED,
DRIVESTATE_PLAY_READ,
DRIVESTATE_SEEK,
};

static struct CdrStat stat;
Expand Down Expand Up @@ -537,6 +540,7 @@ static void cdrPlayInterrupt_Autopause()

StopCdda();
SetPlaySeekRead(cdr.StatP, 0);
cdr.DriveState = DRIVESTATE_PAUSED;
}
else if ((cdr.Mode & MODE_REPORT) && !cdr.ReportDelay &&
((cdr.subq.Absolute[2] & 0x0f) == 0 || cdr.FastForward || cdr.FastBackward))
Expand Down Expand Up @@ -585,16 +589,17 @@ static int cdrSeekTime(unsigned char *target)

// need this stupidly long penalty or else Spyro2 intro desyncs
// note: if misapplied this breaks MGS cutscenes among other things
if (cyclesSinceRS > cdReadTime * 50)
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 (cyclesSinceRS < cdReadTime *3/2)
else if (cdr.DriveState == DRIVESTATE_PAUSED || cyclesSinceRS < cdReadTime *3/2)
seekTime += cdReadTime;

seekTime = MIN_VALUE(seekTime, PSXCLK * 2 / 3);
CDR_LOG("seek: %.2f %.2f (%.2f)\n", (float)seekTime / PSXCLK,
(float)seekTime / cdReadTime, (float)cyclesSinceRS / cdReadTime);
CDR_LOG("seek: %.2f %.2f (%.2f) st %d\n", (float)seekTime / PSXCLK,
(float)seekTime / cdReadTime, (float)cyclesSinceRS / cdReadTime,
cdr.DriveState);
return seekTime;
}

Expand Down Expand Up @@ -672,12 +677,14 @@ void cdrPlayReadInterrupt(void)
CDR_LOG("CDDA - %02d:%02d:%02d m %02x\n",
cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2], cdr.Mode);

cdr.DriveState = DRIVESTATE_PLAY_READ;
SetPlaySeekRead(cdr.StatP, STATUS_PLAY);
if (memcmp(cdr.SetSectorPlay, cdr.SetSectorEnd, 3) == 0) {
CDR_LOG_I("end stop\n");
StopCdda();
SetPlaySeekRead(cdr.StatP, 0);
cdr.TrackChanged = TRUE;
cdr.DriveState = DRIVESTATE_PAUSED;
}
else {
CDR_readCDDA(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2], (u8 *)read_buf);
Expand Down Expand Up @@ -861,6 +868,7 @@ void cdrInterrupt(void) {

// BIOS player - set flag again
cdr.Play = TRUE;
cdr.DriveState = DRIVESTATE_PLAY_READ;

CDRPLAYREAD_INT(cdReadTime + seekTime, 1);
start_rotating = 1;
Expand Down Expand Up @@ -888,6 +896,7 @@ void cdrInterrupt(void) {
error = ERROR_BAD_ARGNUM;
goto set_error;
}
cdr.DriveState = DRIVESTATE_STANDBY;
second_resp_time = cdReadTime * 125 / 2;
start_rotating = 1;
break;
Expand All @@ -913,7 +922,7 @@ void cdrInterrupt(void) {
cdr.LocL[0] = LOCL_INVALID;

second_resp_time = 0x800;
if (cdr.DriveState == DRIVESTATE_STANDBY)
if (cdr.DriveState != DRIVESTATE_STOPPED)
second_resp_time = cdReadTime * 30 / 2;

cdr.DriveState = DRIVESTATE_STOPPED;
Expand Down Expand Up @@ -956,6 +965,7 @@ void cdrInterrupt(void) {
second_resp_time = (((cdr.Mode & MODE_SPEED) ? 1 : 2) * 1097107);
}
SetPlaySeekRead(cdr.StatP, 0);
cdr.DriveState = DRIVESTATE_PAUSED;
break;

case CdlPause + CMD_PART2:
Expand All @@ -970,6 +980,7 @@ void cdrInterrupt(void) {
cdr.LocL[0] = LOCL_INVALID;
cdr.Muted = FALSE;
cdr.Mode = MODE_SIZE_2340; /* This fixes This is Football 2, Pooh's Party lockups */
cdr.DriveState = DRIVESTATE_PAUSED;
second_resp_time = not_ready ? 70000 : 4100000;
start_rotating = 1;
break;
Expand Down Expand Up @@ -1063,6 +1074,7 @@ void cdrInterrupt(void) {

seekTime = cdrSeekTime(cdr.SetSector);
memcpy(cdr.SetSectorPlay, cdr.SetSector, 4);
cdr.DriveState = DRIVESTATE_SEEK;
/*
Crusaders of Might and Magic = 0.5x-4x
- fix cutscene speech start
Expand Down Expand Up @@ -1091,6 +1103,7 @@ void cdrInterrupt(void) {
if (read_ok && (buf = CDR_getBuffer()))
memcpy(cdr.LocL, buf, 8);
UpdateSubq(cdr.SetSectorPlay);
cdr.DriveState = DRIVESTATE_STANDBY;
cdr.TrackChanged = FALSE;
cdr.LastReadSeekCycles = psxRegs.cycle;
break;
Expand Down Expand Up @@ -1198,6 +1211,7 @@ void cdrInterrupt(void) {
cdr.LocL[0] = LOCL_INVALID;
cdr.SubqForwardSectors = 1;
cdr.sectorsRead = 0;
cdr.DriveState = DRIVESTATE_SEEK;

cycles = (cdr.Mode & MODE_SPEED) ? cdReadTime : cdReadTime * 2;
cycles += seekTime;
Expand Down Expand Up @@ -1344,6 +1358,7 @@ static void cdrReadInterrupt(void)

// note: CdlGetlocL should work as soon as STATUS_READ is indicated
SetPlaySeekRead(cdr.StatP, STATUS_READ | STATUS_ROTATING);
cdr.DriveState = DRIVESTATE_PLAY_READ;
cdr.sectorsRead++;

read_ok = ReadTrack(cdr.SetSectorPlay);
Expand All @@ -1355,6 +1370,7 @@ static void cdrReadInterrupt(void)
if (!read_ok) {
CDR_LOG_I("cdrReadInterrupt() Log: err\n");
cdrReadInterruptSetResult(cdr.StatP | STATUS_ERROR);
cdr.DriveState = DRIVESTATE_PAUSED; // ?
return;
}
memcpy(cdr.LocL, buf, 8);
Expand Down

0 comments on commit cc1e8bd

Please sign in to comment.