Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdvdman: allow BDM devices to be ejected and inserted #479

Merged
merged 1 commit into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions modules/iopcore/cdvdman/cdvdman.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ static int cdvdman_read_sectors(u32 lsn, unsigned int sectors, void *buf)
DPRINTF("cdvdman_read lsn=%lu sectors=%u buf=%p\n", lsn, sectors, buf);

cdvdman_stat.err = SCECdErNO;

for (ptr = buf, remaining = sectors; remaining > 0;) {
if (cdvdman_stat.err != SCECdErNO)
break;

SectorsToRead = remaining;

if (cdvdman_settings.common.flags & IOPCORE_COMPAT_ACCU_READS) {
Expand All @@ -167,8 +163,8 @@ static int cdvdman_read_sectors(u32 lsn, unsigned int sectors, void *buf)
SetAlarm(&TargetTime, &cdvdemu_read_end_cb, NULL);
}

if (DeviceReadSectors(lsn, ptr, SectorsToRead) != 0) {
cdvdman_stat.err = SCECdErREAD;
cdvdman_stat.err = DeviceReadSectors(lsn, ptr, SectorsToRead);
if (cdvdman_stat.err != SCECdErNO) {
if (cdvdman_settings.common.flags & IOPCORE_COMPAT_ACCU_READS)
CancelAlarm(&cdvdemu_read_end_cb, NULL);
break;
Expand Down
18 changes: 16 additions & 2 deletions modules/iopcore/cdvdman/device-bdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ void DeviceDeinit(void)
DPRINTF("%s\n", __func__);
}

int DeviceReady(void)
{
//DPRINTF("%s\n", __func__);

return (g_bd == NULL) ? SCECdNotReady : SCECdComplete;
}

void DeviceStop(void)
{
DPRINTF("%s\n", __func__);
Expand Down Expand Up @@ -108,9 +115,13 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
register u32 r, sectors_to_read, lbound, ubound, nlsn, offslsn;
register int i, esc_flag = 0;
u8 *p = (u8 *)buffer;
int rv = SCECdErNO;

//DPRINTF("%s(%u, 0x%p, %u)\n", __func__, (unsigned int)lsn, buffer, sectors);

if (g_bd == NULL)
return SCECdErTRMOPN;

lbound = 0;
ubound = (cdvdman_settings.common.NumParts > 1) ? 0x80000 : 0xFFFFFFFF;
offslsn = lsn;
Expand All @@ -130,7 +141,10 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)

sector = cdvdman_settings.LBAs[i] + (offslsn * g_bd_sectors_per_sector);
count = sectors_to_read * g_bd_sectors_per_sector;
g_bd->read(g_bd, sector, &p[r], count);
if (g_bd->read(g_bd, sector, &p[r], count) != count) {
rv = SCECdErREAD;
break;
}

r += sectors_to_read * 2048;
offslsn += sectors_to_read;
Expand All @@ -143,7 +157,7 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
}
SignalSema(usb_io_sema);

return 0;
return rv;
}

//
Expand Down
11 changes: 8 additions & 3 deletions modules/iopcore/cdvdman/device-hdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ void DeviceDeinit(void)
{
}

int DeviceReady(void)
{
return SCECdComplete;
}

void DeviceFSInit(void)
{
}
Expand All @@ -106,20 +111,20 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
while (sectors) {
if (!((lsn >= cdvdman_partspecs[CurrentPart].part_offset) && (lsn < (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size / 2048)))))
if (cdvdman_get_part_specs(lsn) != 0)
return -ENXIO;
return SCECdErTRMOPN;

u32 nsectors = (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size / 2048)) - lsn;
if (sectors < nsectors)
nsectors = sectors;

u32 lba = cdvdman_partspecs[CurrentPart].data_start + ((lsn - cdvdman_partspecs[CurrentPart].part_offset) << 2);
if (ata_device_sector_io(0, (void *)(buffer + offset), lba, nsectors << 2, ATA_DIR_READ) != 0) {
return -EIO;
return SCECdErREAD;
}
offset += nsectors * 2048;
sectors -= nsectors;
lsn += nsectors;
}

return 0;
return SCECdErNO;
}
13 changes: 11 additions & 2 deletions modules/iopcore/cdvdman/device-smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void DeviceDeinit(void)
DeviceUnmount();
}

int DeviceReady(void)
{
return SCECdComplete;
}

void DeviceFSInit(void)
{
int i = 0;
Expand Down Expand Up @@ -115,6 +120,7 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
register u32 r, sectors_to_read, lbound, ubound, nlsn, offslsn;
register int i, esc_flag = 0;
u8 *p = (u8 *)buffer;
int rv = SCECdErNO;

lbound = 0;
ubound = (cdvdman_settings.common.NumParts > 1) ? 0x80000 : 0xFFFFFFFF;
Expand All @@ -132,7 +138,10 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
} else
esc_flag = 1;

smb_ReadCD(offslsn, sectors_to_read, &p[r], i);
if (smb_ReadCD(offslsn, sectors_to_read, &p[r], i) <= 0) {
rv = SCECdErREAD;
break;
}

r += sectors_to_read * 2048;
offslsn += sectors_to_read;
Expand All @@ -144,5 +153,5 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
break;
}

return 0;
return rv;
}
1 change: 1 addition & 0 deletions modules/iopcore/cdvdman/device.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
void DeviceInit(void); //Called in _start()
void DeviceDeinit(void); //Called in _exit(). Interrupts are disabled.
int DeviceReady(void); //Check if device is ready

void DeviceFSInit(void); //Called when the filesystem layer is initialized
void DeviceLock(void); //Prevents further accesses to the device.
Expand Down
2 changes: 1 addition & 1 deletion modules/iopcore/cdvdman/ncmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int sceCdDiskReady(int mode)
}

if (!sync_flag)
return SCECdComplete;
return DeviceReady();
}

return SCECdNotReady;
Expand Down