CDVD: Replace cdvd.Ready handling

This commit is contained in:
refractionpcsx2 2021-12-26 09:59:07 +00:00
parent 7d9c8c9172
commit 5546b102eb
2 changed files with 34 additions and 18 deletions

View File

@ -634,7 +634,7 @@ s32 cdvdCtrlTrayOpen()
DiscSwapTimerSeconds = cdvd.RTC.second; // remember the PS2 time when this happened
cdvd.Status = CDVD_STATUS_TRAY_OPEN;
cdvd.Ready &= ~CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.mediaChanged = true;
@ -655,7 +655,7 @@ s32 cdvdCtrlTrayClose()
if (!g_GameStarted && g_SkipBiosHack)
{
DevCon.WriteLn(Color_Green, L"Media already loaded (fast boot)");
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_PAUSE;
cdvd.Tray.trayState = CDVD_DISC_ENGAGED;
cdvd.Tray.cdvdActionSeconds = 0;
@ -663,7 +663,7 @@ s32 cdvdCtrlTrayClose()
else
{
DevCon.WriteLn(Color_Green, L"Detecting media");
cdvd.Ready &= ~CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_SEEK;
cdvd.Tray.trayState = CDVD_DISC_DETECTING;
cdvd.Tray.cdvdActionSeconds = 3;
@ -811,7 +811,7 @@ void cdvdReset()
cdvd.Spinning = false;
cdvd.sDataIn = 0x40;
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_PAUSE;
cdvd.Speed = 4;
cdvd.BlockSize = 2064;
@ -905,7 +905,7 @@ void cdvdNewDiskCB()
{
DevCon.WriteLn(Color_Green, L"Ejecting media");
cdvd.Status = CDVD_STATUS_TRAY_OPEN;
cdvd.Ready &= ~CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.Tray.trayState = CDVD_DISC_EJECT;
cdvd.mediaChanged = true;
@ -916,7 +916,7 @@ void cdvdNewDiskCB()
else if (cdvd.Type > 0)
{
DevCon.WriteLn(Color_Green, L"Seeking new media");
cdvd.Ready &= ~CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_SEEK;
cdvd.Tray.trayState = CDVD_DISC_DETECTING;
cdvd.Tray.cdvdActionSeconds = 3;
@ -1059,7 +1059,7 @@ __fi void cdvdActionInterrupt()
{
case cdvdAction_Seek:
cdvd.Spinning = true;
cdvd.Ready |= CDVD_DRIVE_READY; //check (rama)
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Sector = cdvd.SeekToSector;
cdvd.Status = CDVD_STATUS_PAUSE;
cdvd.nextSectorsBuffered = 0;
@ -1069,7 +1069,7 @@ __fi void cdvdActionInterrupt()
case cdvdAction_Standby:
DevCon.Warning("CDVD Standby Call");
cdvd.Spinning = true; //check (rama)
cdvd.Ready |= CDVD_DRIVE_READY; //check (rama)
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Sector = cdvd.SeekToSector;
cdvd.Status = CDVD_STATUS_PAUSE;
cdvd.nextSectorsBuffered = 0;
@ -1078,7 +1078,7 @@ __fi void cdvdActionInterrupt()
case cdvdAction_Stop:
cdvd.Spinning = false;
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Sector = 0;
cdvd.Status = CDVD_STATUS_STOP;
break;
@ -1086,12 +1086,12 @@ __fi void cdvdActionInterrupt()
case cdvdAction_Break:
// Make sure the cdvd action state is pretty well cleared:
DevCon.WriteLn("CDVD Break Call");
if (!(cdvd.Ready & 0x40))
if ((cdvd.Ready & 0x80))
cdvd.Error = 1; // Abort
cdvd.Reading = 0;
cdvd.Readed = 0;
cdvd.Ready |= CDVD_DRIVE_READY; // should be CDVD_READY1 or something else?
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON | CDVD_DRIVE_ERROR; // should be CDVD_READY1 or something else?
cdvd.Status = CDVD_STATUS_PAUSE; //Break stops the command in progress it doesn't stop the drive. Formula 2001
cdvd.RErr = 0;
break;
@ -1118,7 +1118,7 @@ __fi void cdvdReadInterrupt()
{
//Console.WriteLn("cdvdReadInterrupt %x %x %x %x %x", cpuRegs.interrupt, cdvd.Readed, cdvd.Reading, cdvd.nSectors, (HW_DMA3_BCR_H16 * HW_DMA3_BCR_L16) *4);
cdvd.Ready &= ~CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_READ;
cdvd.WaitingDMA = false;
@ -1205,7 +1205,7 @@ __fi void cdvdReadInterrupt()
// Setting the data ready flag fixes a black screen loading issue in
// Street Fighter Ex3 (NTSC-J version).
cdvdSetIrq();
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_PAUSE;
//DevCon.Warning("Scheduling interrupt in %d cycles", cdvd.ReadTime - ((cdvd.BlockSize / 4) * 12));
@ -1224,7 +1224,7 @@ __fi void cdvdReadInterrupt()
cdvdSetIrq();
//psxHu32(0x1070) |= 0x4;
iopIntcIrq(2);
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvd.Status = CDVD_STATUS_PAUSE;
return;
@ -1251,7 +1251,7 @@ static uint cdvdStartSeek(uint newsector, CDVD_MODE_TYPE mode)
uint seektime;
bool isSeeking = cdvd.nCommand == N_CD_SEEK;
cdvd.Ready &= ~(CDVD_DRIVE_READY | CDVD_DRIVE_DATARDY);
cdvd.Ready = CDVD_DRIVE_BUSY | CDVD_DRIVE_DEV9CON;
cdvd.Reading = 1;
cdvd.Readed = 0;
// Okay so let's explain this, since people keep messing with it in the past and just poking it.
@ -1368,7 +1368,7 @@ void cdvdUpdateTrayState()
case CDVD_DISC_SEEKING:
case CDVD_DISC_ENGAGED:
cdvd.Tray.trayState = CDVD_DISC_ENGAGED;
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
if (CDVDsys_GetSourceType() != CDVD_SourceType::NoDisc)
{
DevCon.WriteLn(Color_Green, L"Media ready to read");
@ -1586,6 +1586,7 @@ static bool cdvdReadErrorHandler()
{
DevCon.Warning("Bad Sector Count Error");
cdvd.Error = 0x21; // Number of read sectors abnormal
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON | CDVD_DRIVE_ERROR;
cdvdSetIrq();
return false;
}
@ -1594,6 +1595,7 @@ static bool cdvdReadErrorHandler()
{
DevCon.Warning("Invalid Sector Error");
cdvd.Error = 0x20; // Sector position is abnormal
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON | CDVD_DRIVE_ERROR;
cdvdSetIrq();
return false;
}
@ -1641,7 +1643,7 @@ static void cdvdWrite04(u8 rt)
// A few games rely on PAUSE setting the Status correctly.
// However we should probably stop any read in progress too, just to be safe
psxRegs.interrupt &= ~(1 << IopEvt_Cdvd);
cdvd.Ready |= CDVD_DRIVE_READY;
cdvd.Ready = CDVD_DRIVE_READY | CDVD_DRIVE_DEV9CON;
cdvdSetIrq();
//After Pausing needs to buffer the next sector
cdvd.Status = CDVD_STATUS_PAUSE;

View File

@ -82,11 +82,25 @@ enum cdvdStatus
CDVD_STATUS_EMERGENCY = 0x20,
};
/* from PS2Tek https://psi-rockin.github.io/ps2tek/#cdvdioports
1F402005h N command status (R)
0 Error (1=error occurred)
1 Unknown/unused
2 DEV9 device connected (1=HDD/network adapter connected)
3 Unknown/unused
4 Test mode
5 Power off ready
6 Drive status (1=ready)
7 Busy executing NCMD
*/
enum cdvdready
{
CDVD_DRIVE_DATARDY = 0x2,
CDVD_DRIVE_ERROR = 0x01,
CDVD_DRIVE_DEV9CON = 0x04,
CDVD_DRIVE_PWOFF = 0x20,
CDVD_DRIVE_READY = 0x40,
CDVD_DRIVE_BUSY = 0x80,
};
// Cdvd actions tell the emulator how and when to respond to certain requests.