Skip to content

Commit

Permalink
Change sector size '11' bitshifts to '2048' multiply/divide
Browse files Browse the repository at this point in the history
This should make it more clear that it is an operation related to the sector size.
The compiler should optimize it to bitshifts anyway
  • Loading branch information
uyjulian committed Jun 27, 2021
1 parent b73847d commit ab0c973
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions modules/iopcore/cdvdfsv/ncmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static inline void cdvdSt_read(void *buf)
int r, rpos, remaining;
void *ee_addr;

for (rpos = 0, ee_addr = St->buf, remaining = St->sectors; remaining > 0; ee_addr += r << 11, rpos += r, remaining -= r) {
for (rpos = 0, ee_addr = St->buf, remaining = St->sectors; remaining > 0; ee_addr += r * 2048, rpos += r, remaining -= r) {
if ((r = sceCdStRead(remaining, (void *)((u32)ee_addr | 0x80000000), 0, &err)) < 1)
break;
}
Expand Down Expand Up @@ -348,12 +348,12 @@ static inline void cdvd_readchain(void *buf)
return;
}
sceCdSync(0);
sysmemSendEE(cdvdfsv_buf, (void *)addr, nsectors << 11);
sysmemSendEE(cdvdfsv_buf, (void *)addr, nsectors * 2048);

lsn += nsectors;
tsectors -= nsectors;
addr += nsectors << 11;
readpos += nsectors << 11;
addr += nsectors * 2048;
readpos += nsectors * 2048;
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/iopcore/cdvdman/cdvdman.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ static int cdvdman_read_sectors(u32 lsn, unsigned int sectors, void *buf)
}
}

ptr += SectorsToRead << 11;
ptr += SectorsToRead * 2048;
remaining -= SectorsToRead;
lsn += SectorsToRead;
ReadPos += SectorsToRead << 11;
ReadPos += SectorsToRead * 2048;

if (cdvdman_settings.common.flags & IOPCORE_COMPAT_ACCU_READS) {
//Sleep until the required amount of time has been spent.
Expand Down Expand Up @@ -229,7 +229,7 @@ static int cdvdman_read(u32 lsn, u32 sectors, void *buf)

rpos += nsectors;
sectors -= nsectors;
nbytes = nsectors << 11;
nbytes = nsectors * 2048;

memcpy(buf, cdvdman_buf, nbytes);

Expand Down
2 changes: 1 addition & 1 deletion modules/iopcore/cdvdman/device-bdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
count = sectors_to_read * g_bd_sectors_per_sector;
g_bd->read(g_bd, sector, &p[r], count);

r += sectors_to_read << 11;
r += sectors_to_read * 2048;
offslsn += sectors_to_read;
sectors_to_read = sectors;
lsn = nlsn;
Expand Down
8 changes: 4 additions & 4 deletions modules/iopcore/cdvdman/device-hdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static int cdvdman_get_part_specs(u32 lsn)
hdl_partspecs_t *ps;

for (ps = cdvdman_partspecs, i = 0; i < NumParts; i++, ps++) {
if ((lsn >= ps->part_offset) && (lsn < (ps->part_offset + (ps->part_size >> 11)))) {
if ((lsn >= ps->part_offset) && (lsn < (ps->part_offset + (ps->part_size / 2048)))) {
CurrentPart = i;
break;
}
Expand Down Expand Up @@ -104,19 +104,19 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)
{
u32 offset = 0;
while (sectors) {
if (!((lsn >= cdvdman_partspecs[CurrentPart].part_offset) && (lsn < (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size >> 11)))))
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;

u32 nsectors = (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size >> 11)) - lsn;
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;
}
offset += nsectors << 11;
offset += nsectors * 2048;
sectors -= nsectors;
lsn += nsectors;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/iopcore/cdvdman/device-smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors)

smb_ReadCD(offslsn, sectors_to_read, &p[r], i);

r += sectors_to_read << 11;
r += sectors_to_read * 2048;
offslsn += sectors_to_read;
sectors_to_read = sectors;
lsn = nlsn;
Expand Down
2 changes: 1 addition & 1 deletion modules/iopcore/cdvdman/smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ int smb_WriteFile(u16 FID, u32 offsetlow, u32 offsethigh, void *writebuf, int nb
//-------------------------------------------------------------------------
int smb_ReadCD(unsigned int lsn, unsigned int nsectors, void *buf, int part_num)
{
return smb_ReadFile(cdvdman_settings.FIDs[part_num], lsn << 11, lsn >> 21, buf, (int)(nsectors << 11));
return smb_ReadFile(cdvdman_settings.FIDs[part_num], lsn * 2048, lsn >> 21, buf, (int)(nsectors * 2048));
}

void smb_CloseAll(void)
Expand Down

0 comments on commit ab0c973

Please sign in to comment.