From 50eb890a382d7026696f43ab0e02b1cda4908828 Mon Sep 17 00:00:00 2001 From: AKuHAK <621640+AKuHAK@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:42:36 +0300 Subject: [PATCH 1/3] Reduced structure size Sync EE sector_read with IOP Used predefined values --- modules/iopcore/cdvdfsv/ncmd.c | 13 +++++++------ modules/iopcore/cdvdman/internal.h | 4 ++-- modules/iopcore/cdvdman/ncmd.c | 10 +++++----- modules/iopcore/cdvdman/scmd.c | 8 ++++---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/modules/iopcore/cdvdfsv/ncmd.c b/modules/iopcore/cdvdfsv/ncmd.c index a32b505b1..4387a936f 100644 --- a/modules/iopcore/cdvdfsv/ncmd.c +++ b/modules/iopcore/cdvdfsv/ncmd.c @@ -103,7 +103,8 @@ static inline void cdvd_readee(void *buf) { // Read Disc data to EE mem buffer u8 curlsn_buf[16]; u32 nbytes, nsectors, sectors_to_read, size_64b, size_64bb, bytesent, temp; - int sector_size, flag_64b, fsverror; + u16 sector_size; + int flag_64b, fsverror; void *fsvRbuf = (void *)cdvdfsv_buf; void *eeaddr_64b, *eeaddr2_64b; cdvdfsv_readee_t readee; @@ -114,13 +115,13 @@ static inline void cdvd_readee(void *buf) return; } - sector_size = 2328; + sector_size = 2048; - if ((r->mode.datapattern & 0xff) != 1) { + if (r->mode.datapattern == SCECdSecS2328) + sector_size = 2328; + if (r->mode.datapattern == SCECdSecS2340) sector_size = 2340; - if ((r->mode.datapattern & 0xff) != 2) - sector_size = 2048; - } + r->eeaddr1 = (void *)((u32)r->eeaddr1 & 0x1fffffff); r->eeaddr2 = (void *)((u32)r->eeaddr2 & 0x1fffffff); diff --git a/modules/iopcore/cdvdman/internal.h b/modules/iopcore/cdvdman/internal.h index aed7ee984..f64292a0d 100644 --- a/modules/iopcore/cdvdman/internal.h +++ b/modules/iopcore/cdvdman/internal.h @@ -71,10 +71,10 @@ struct SteamingData typedef struct { int err; - int status; + u8 status; // SCECdvdDriveState struct SteamingData StreamingData; int intr_ef; - int disc_type_reg; + int disc_type_reg; // SCECdvdMediaType u32 cdread_lba; u32 cdread_sectors; u16 sector_size; diff --git a/modules/iopcore/cdvdman/ncmd.c b/modules/iopcore/cdvdman/ncmd.c index e43697e0a..f5b4d6c83 100644 --- a/modules/iopcore/cdvdman/ncmd.c +++ b/modules/iopcore/cdvdman/ncmd.c @@ -78,8 +78,8 @@ int cdvdman_fill_toc(u8 *tocBuff) } switch (discType) { - case 0x12: // SCECdPS2CD - case 0x13: // SCECdPS2CDDA + case SCECdPS2CD: + case SCECdPS2CDDA: u8 min; u8 sec; u8 frm; @@ -109,8 +109,8 @@ int cdvdman_fill_toc(u8 *tocBuff) // Later if PS2CCDA is added the tracks need to get filled in toc too. break; - case 0x14: // SCECdPS2DVD - case 0xFE: // SCECdDVDV + case SCECdPS2DVD: + case SCECdDVDV: // Toc for single layer DVD. memset(tocBuff, 0, 2048); @@ -168,7 +168,7 @@ int cdvdman_fill_toc(u8 *tocBuff) } // Not known type. - DPRINTF("cdvdman_fill_toc unimplemented for discType=%02X\n", discType); + DPRINTF("cdvdman_fill_toc unimplemented for discType=%02X\n", discType); return 0; } diff --git a/modules/iopcore/cdvdman/scmd.c b/modules/iopcore/cdvdman/scmd.c index 83f31b590..1fd5e9040 100644 --- a/modules/iopcore/cdvdman/scmd.c +++ b/modules/iopcore/cdvdman/scmd.c @@ -66,7 +66,7 @@ int sceCdTrayReq(int mode, u32 *traycnt) } cdvdman_stat.status = SCECdStatShellOpen; - cdvdman_stat.disc_type_reg = 0; + cdvdman_stat.disc_type_reg = SCECdNODISC; DelayThread(11000); @@ -93,7 +93,7 @@ int sceCdTrayReq(int mode, u32 *traycnt) 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_stat.disc_type_reg = cdvdman_settings.common.media; cdvdman_media_changed = 1; @@ -114,9 +114,9 @@ int sceCdApplySCmd(u8 cmd, const void *in, u16 in_size, void *out) //------------------------------------------------------------------------- int sceCdStatus(void) { - DPRINTF("sceCdStatus %d\n", cdvdman_stat.status); + DPRINTF("sceCdStatus %d\n", (int)cdvdman_stat.status); - return cdvdman_stat.status; + return (int)cdvdman_stat.status; } //------------------------------------------------------------------------- From 8252c64db49c4bd3c343eedf41d76f299b214f15 Mon Sep 17 00:00:00 2001 From: AKuHAK <621640+AKuHAK@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:42:53 +0300 Subject: [PATCH 2/3] Fix semaphore pr that broke same games --- modules/iopcore/cdvdman/ioops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/iopcore/cdvdman/ioops.c b/modules/iopcore/cdvdman/ioops.c index e85cda83b..a61480553 100644 --- a/modules/iopcore/cdvdman/ioops.c +++ b/modules/iopcore/cdvdman/ioops.c @@ -398,7 +398,7 @@ static int cdrom_dread(iop_file_t *f, iox_dirent_t *dirent) DPRINTF("cdrom_dread fh->lsn=%lu\n", fh->lsn); if ((r = sceCdRead(fh->lsn, 1, cdvdman_fs_buf, NULL)) == 1) { - // sceCdSync(0); // TODO: need to verify + sceCdSync(0); do { r = 0; From a7519fb16cafa00578c1a01e0db375e71a137a53 Mon Sep 17 00:00:00 2001 From: AKuHAK <621640+AKuHAK@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:05:52 +0300 Subject: [PATCH 3/3] krat0s: fix semaphores, add more debgging --- modules/iopcore/cdvdman/cdvdman.c | 1 + modules/iopcore/cdvdman/ioops.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/modules/iopcore/cdvdman/cdvdman.c b/modules/iopcore/cdvdman/cdvdman.c index 14d73c6cc..e5b79e399 100644 --- a/modules/iopcore/cdvdman/cdvdman.c +++ b/modules/iopcore/cdvdman/cdvdman.c @@ -600,6 +600,7 @@ int sceCdSC(int code, int *param) result = 1; break; default: + DPRINTF("sceCdSC unknown, code=0x%X param=0x%X \n", code, *param); result = 1; // dummy result } diff --git a/modules/iopcore/cdvdman/ioops.c b/modules/iopcore/cdvdman/ioops.c index a61480553..c3e1f7f57 100644 --- a/modules/iopcore/cdvdman/ioops.c +++ b/modules/iopcore/cdvdman/ioops.c @@ -433,6 +433,8 @@ static int cdrom_ioctl(iop_file_t *f, u32 cmd, void *args) { register int r = 0; + DPRINTF("cdrom_ioctl 0x%X\n", cmd); + WaitSema(cdrom_io_sema); if (cmd != 0x10000) // Spin Ctrl op @@ -449,6 +451,7 @@ static int cdrom_devctl(iop_file_t *f, const char *name, int cmd, void *args, u3 int result; WaitSema(cdrom_io_sema); + WaitEventFlag(cdvdman_stat.intr_ef, 1, WEF_AND, NULL); result = 0; switch (cmd) { @@ -536,6 +539,7 @@ static int cdrom_devctl(iop_file_t *f, const char *name, int cmd, void *args, u3 result = cdvdman_stat.intr_ef; break; default: + DPRINTF("cdrom_devctl unknown, cmd=0x%X\n", cmd); result = -EIO; break; } @@ -553,6 +557,7 @@ static int cdrom_ioctl2(iop_file_t *f, int cmd, void *args, unsigned int arglen, // There was a check here on whether the file was opened with mode 8. WaitSema(cdrom_io_sema); + WaitEventFlag(cdvdman_stat.intr_ef, 1, WEF_AND, NULL); switch (cmd) { case CIOCSTREAMPAUSE: @@ -565,6 +570,7 @@ static int cdrom_ioctl2(iop_file_t *f, int cmd, void *args, unsigned int arglen, r = sceCdStStat(); break; default: + DPRINTF("cdrom_ioctl2 unknown, cmd=0x%X\n", cmd); r = -EINVAL; }