Skip to content

Commit

Permalink
krat0s: CDVDMAN: fix sceCdTrayReq
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuHAK committed May 23, 2023
1 parent 9a299bf commit 6b991f0
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions modules/iopcore/cdvdman/scmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,52 @@ int sceCdTrayReq(int mode, u32 *traycnt)

DPRINTF("sceCdTrayReq TrayCheck result=%d\n", cdvdman_media_changed);

if (cdvdman_media_changed) {
DelayThread(4000);
}

cdvdman_media_changed = 0;

return 1;
}

// Bit 0 of cdvd status reg is Tray Open.
// Use it to determine if we are already closed or opened.
if (mode == SCECdTrayOpen) {
// Tray is already opened, do nothing.
if (cdvdman_stat.status & 1) {
return 0;
}

cdvdman_stat.status = SCECdStatShellOpen;
cdvdman_stat.disc_type_reg = 0;

DelayThread(11000);

cdvdman_stat.err = SCECdErOPENS; /* not sure about this error code */
// So that it reports disc change status.
cdvdman_media_changed = 1;

return 1;
} else if (mode == SCECdTrayClose) {
// Tray is closed, do nothing.
if (!(cdvdman_stat.status & 1)) {
return 0;
}

// First state is paused after close.
cdvdman_stat.status = SCECdStatPause;

DelayThread(25000);

cdvdman_stat.status = SCECdStatPause; /* not sure if the status is right, may be - SCECdStatSpin */
cdvdman_stat.err = SCECdErNO; /* not sure if this error code is suitable here */
cdvdman_stat.disc_type_reg = (int)cdvdman_settings.common.media;
// If there is a disc(which for OPL always is) then it will start spinning after a while and detect disc type.

cdvdman_stat.status = SCECdStatSpin;

/*
If the day comes that OPL implements disc swapping, this will be place to reupdate all disc type, LBA start offsets, mediaLsn count and everything else.
Until then it will the same disc.
*/
cdvdman_stat.disc_type_reg = cdvdman_settings.common.media & 0xFF;

cdvdman_media_changed = 1;

Expand Down

0 comments on commit 6b991f0

Please sign in to comment.