From 4e917c88a873e38b0eef91112f511219421c5eca Mon Sep 17 00:00:00 2001 From: KrahJohlito Date: Mon, 11 Nov 2024 10:09:26 +1030 Subject: [PATCH] u64 datatype for vmc --- include/bdmsupport.h | 2 +- modules/iopcore/cdvdman/cdvdman.c | 18 +++++++++--------- modules/iopcore/cdvdman/device-bdm.c | 6 +++--- modules/iopcore/cdvdman/device-hdd.c | 10 +++++----- modules/iopcore/cdvdman/device-smb.c | 10 +++++----- modules/iopcore/cdvdman/device.h | 2 +- modules/mcemu/device-bdm.c | 12 ++++-------- modules/mcemu/mcemu.h | 2 +- modules/mcemu/mcemu_utils.h | 4 ++-- 9 files changed, 31 insertions(+), 35 deletions(-) diff --git a/include/bdmsupport.h b/include/bdmsupport.h index 37aedf3b9..5c85b1384 100644 --- a/include/bdmsupport.h +++ b/include/bdmsupport.h @@ -10,7 +10,7 @@ typedef struct { int active; /* Activation flag */ - u32 start_sector; /* Start sector of vmc file */ + u64 start_sector; /* Start sector of vmc file */ int flags; /* Card flag */ vmc_spec_t specs; /* Card specifications */ } bdm_vmc_infos_t; diff --git a/modules/iopcore/cdvdman/cdvdman.c b/modules/iopcore/cdvdman/cdvdman.c index 59be1bcdf..524ff3bbb 100644 --- a/modules/iopcore/cdvdman/cdvdman.c +++ b/modules/iopcore/cdvdman/cdvdman.c @@ -25,8 +25,8 @@ extern struct irx_export_table _exp_dev9; #endif // reader function interface, raw reader impementation by default -int DeviceReadSectorsCached(u32 sector, void *buffer, unsigned int count); -int (*DeviceReadSectorsPtr)(u32 sector, void *buffer, unsigned int count) = &DeviceReadSectors; +int DeviceReadSectorsCached(u64 sector, void *buffer, unsigned int count); +int (*DeviceReadSectorsPtr)(u64 sector, void *buffer, unsigned int count) = &DeviceReadSectors; // internal functions prototypes static void oplShutdown(int poff); @@ -41,7 +41,7 @@ static int cdvdman_read(u32 lsn, u32 sectors, u16 sector_size, void *buf); // Sector cache to improve IO static u8 MAX_SECTOR_CACHE = 0; static u8 *sector_cache = NULL; -static int cur_sector = -1; +static u64 cur_sector = 0xffffffffffffffff; struct cdvdman_cb_data { @@ -170,10 +170,10 @@ void *ziso_alloc(u32 size) If we do a consecutive read of many ISO sectors we will have a huge amount of ZSO sectors ready. Therefore reducing IO access for ZSO files. */ -int DeviceReadSectorsCached(u32 lsn, void *buffer, unsigned int sectors) +int DeviceReadSectorsCached(u64 lsn, void *buffer, unsigned int sectors) { if (sectors < MAX_SECTOR_CACHE) { // if MAX_SECTOR_CACHE is 0 then it will act as disabled and passthrough - if (cur_sector < 0 || lsn < cur_sector || (lsn + sectors) - cur_sector > MAX_SECTOR_CACHE) { + if (cur_sector == 0xffffffffffff || lsn < cur_sector || (lsn + sectors) - cur_sector > MAX_SECTOR_CACHE) { DeviceReadSectors(lsn, sector_cache, MAX_SECTOR_CACHE); cur_sector = lsn; } @@ -193,11 +193,11 @@ int DeviceReadSectorsCached(u32 lsn, void *buffer, unsigned int sectors) int read_raw_data(u8 *addr, u32 size, u32 offset, u32 shift) { u32 o_size = size; - u32 lba = offset / (2048 >> shift); // avoid overflow by shifting sector size instead of offset + u64 lba = offset / (2048 >> shift); // avoid overflow by shifting sector size instead of offset u32 pos = (offset << shift) & 2047; // doesn't matter if it overflows since we only care about the 11 LSB anyways // prevent caching if already reading into ZSO index cache - int (*ReadSectors)(u32 lsn, void *buffer, unsigned int sectors) = (addr == (u8 *)ziso_idx_cache) ? &DeviceReadSectors : &DeviceReadSectorsCached; + int (*ReadSectors)(u64 lsn, void *buffer, unsigned int sectors) = (addr == (u8 *)ziso_idx_cache) ? &DeviceReadSectors : &DeviceReadSectorsCached; // read first block if not aligned to sector size if (pos) { @@ -232,9 +232,9 @@ int read_raw_data(u8 *addr, u32 size, u32 offset, u32 shift) return o_size - size; } -int DeviceReadSectorsCompressed(u32 lsn, void *addr, unsigned int count) +int DeviceReadSectorsCompressed(u64 lsn, void *addr, unsigned int count) { - return (ziso_read_sector(addr, lsn, count) == count) ? SCECdErNO : SCECdErEOM; + return (ziso_read_sector(addr, (u32)lsn, count) == count) ? SCECdErNO : SCECdErEOM; } static int probed = 0; diff --git a/modules/iopcore/cdvdman/device-bdm.c b/modules/iopcore/cdvdman/device-bdm.c index 740fccbc3..8ed837978 100644 --- a/modules/iopcore/cdvdman/device-bdm.c +++ b/modules/iopcore/cdvdman/device-bdm.c @@ -131,7 +131,7 @@ void DeviceUnmount(void) DPRINTF("%s\n", __func__); } -int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors) +int DeviceReadSectors(u64 lsn, void *buffer, unsigned int sectors) { int rv = SCECdErNO; @@ -152,7 +152,7 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors) // oplutils exported function, used by MCEMU // -void bdm_readSector(unsigned int lba, unsigned short int nsectors, unsigned char *buffer) +void bdm_readSector(u64 lba, unsigned short int nsectors, unsigned char *buffer) { DPRINTF("%s\n", __func__); @@ -161,7 +161,7 @@ void bdm_readSector(unsigned int lba, unsigned short int nsectors, unsigned char SignalSema(bdm_io_sema); } -void bdm_writeSector(unsigned int lba, unsigned short int nsectors, const unsigned char *buffer) +void bdm_writeSector(u64 lba, unsigned short int nsectors, const unsigned char *buffer) { DPRINTF("%s\n", __func__); diff --git a/modules/iopcore/cdvdman/device-hdd.c b/modules/iopcore/cdvdman/device-hdd.c index 330b3fcba..0bf370552 100644 --- a/modules/iopcore/cdvdman/device-hdd.c +++ b/modules/iopcore/cdvdman/device-hdd.c @@ -108,19 +108,19 @@ void DeviceStop(void) // This will be handled by ATAD. } -int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors) +int DeviceReadSectors(u64 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 / 2048))))) - if (cdvdman_get_part_specs(lsn) != 0) + if (!(((u32)lsn >= cdvdman_partspecs[CurrentPart].part_offset) && ((u32)lsn < (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size / 2048))))) + if (cdvdman_get_part_specs((u32)lsn) != 0) return SCECdErTRMOPN; - u32 nsectors = (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size / 2048)) - lsn; + u32 nsectors = (cdvdman_partspecs[CurrentPart].part_offset + (cdvdman_partspecs[CurrentPart].part_size / 2048)) - (u32)lsn; if (sectors < nsectors) nsectors = sectors; - u32 lba = cdvdman_partspecs[CurrentPart].data_start + ((lsn - cdvdman_partspecs[CurrentPart].part_offset) << 2); + u32 lba = cdvdman_partspecs[CurrentPart].data_start + (((u32)lsn - cdvdman_partspecs[CurrentPart].part_offset) << 2); if (sceAtaDmaTransfer(0, (void *)((u8 *)buffer + offset), lba, nsectors << 2, ATA_DIR_READ) != 0) { return SCECdErREAD; } diff --git a/modules/iopcore/cdvdman/device-smb.c b/modules/iopcore/cdvdman/device-smb.c index 243c37cc5..0017c131e 100644 --- a/modules/iopcore/cdvdman/device-smb.c +++ b/modules/iopcore/cdvdman/device-smb.c @@ -115,7 +115,7 @@ void DeviceStop(void) { } -int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors) +int DeviceReadSectors(u64 lsn, void *buffer, unsigned int sectors) { register u32 r, sectors_to_read, lbound, ubound, nlsn, offslsn; register int i, esc_flag = 0; @@ -124,15 +124,15 @@ int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors) lbound = 0; ubound = (cdvdman_settings.common.NumParts > 1) ? 0x80000 : 0xFFFFFFFF; - offslsn = lsn; + offslsn = (u32)lsn; r = nlsn = 0; sectors_to_read = sectors; for (i = 0; i < cdvdman_settings.common.NumParts; i++, lbound = ubound, ubound += 0x80000, offslsn -= 0x80000) { - if (lsn >= lbound && lsn < ubound) { - if ((lsn + sectors) > (ubound - 1)) { - sectors_to_read = ubound - lsn; + if ((u32)lsn >= lbound && (u32)lsn < ubound) { + if (((u32)lsn + sectors) > (ubound - 1)) { + sectors_to_read = ubound - (u32)lsn; sectors -= sectors_to_read; nlsn = ubound; } else diff --git a/modules/iopcore/cdvdman/device.h b/modules/iopcore/cdvdman/device.h index e921d67c0..73ff19a6b 100644 --- a/modules/iopcore/cdvdman/device.h +++ b/modules/iopcore/cdvdman/device.h @@ -7,4 +7,4 @@ void DeviceLock(void); // Prevents further accesses to the device. void DeviceUnmount(void); // Called when OPL is shutting down. void DeviceStop(void); // Called before the PS2 is to be shut down. -int DeviceReadSectors(u32 lsn, void *buffer, unsigned int sectors); +int DeviceReadSectors(u64 lsn, void *buffer, unsigned int sectors); diff --git a/modules/mcemu/device-bdm.c b/modules/mcemu/device-bdm.c index fab667e69..e0d3befb7 100644 --- a/modules/mcemu/device-bdm.c +++ b/modules/mcemu/device-bdm.c @@ -9,10 +9,8 @@ int DeviceWritePage(int mc_num, void *buf, u32 page_num) { - u32 lba; - - lba = vmcSpec[mc_num].stsec + page_num; - DPRINTF("writing page 0x%lx at lba 0x%lx\n", page_num, lba); + u64 lba = vmcSpec[mc_num].stsec + page_num; + DPRINTF("writing page 0x%lx at lba 0x%08x%08x\n", page_num, ((u32 *)&lba)[1], ((u32 *)&lba)[0]); bdm_writeSector(lba, 1, buf); @@ -21,10 +19,8 @@ int DeviceWritePage(int mc_num, void *buf, u32 page_num) int DeviceReadPage(int mc_num, void *buf, u32 page_num) { - u32 lba; - - lba = vmcSpec[mc_num].stsec + page_num; - DPRINTF("reading page 0x%lx at lba 0x%lx\n", page_num, lba); + u64 lba = vmcSpec[mc_num].stsec + page_num; + DPRINTF("reading page 0x%lx at lba 0x%08x%08x\n", page_num, ((u32 *)&lba)[1], ((u32 *)&lba)[0]); bdm_readSector(lba, 1, buf); diff --git a/modules/mcemu/mcemu.h b/modules/mcemu/mcemu.h index 18746eca9..5db0ccba6 100644 --- a/modules/mcemu/mcemu.h +++ b/modules/mcemu/mcemu.h @@ -105,7 +105,7 @@ typedef struct _McImageSpec int active; /* Activation flag */ #ifdef BDM_DRIVER - u32 stsec; /* Vmc file start sector */ + u64 stsec; /* Vmc file start sector */ #endif #ifdef HDD_DRIVER diff --git a/modules/mcemu/mcemu_utils.h b/modules/mcemu/mcemu_utils.h index 3b946fe40..f60f3302e 100644 --- a/modules/mcemu/mcemu_utils.h +++ b/modules/mcemu/mcemu_utils.h @@ -41,10 +41,10 @@ int oplRegisterShutdownCallback(oplShutdownCb_t cb); /* BDM Transfer Imports */ #ifdef BDM_DRIVER -void bdm_readSector(unsigned int lba, unsigned short int nsectors, unsigned char *buffer); +void bdm_readSector(u64 lba, unsigned short int nsectors, unsigned char *buffer); #define I_bdm_readSector DECLARE_IMPORT(6, bdm_readSector) -void bdm_writeSector(unsigned int lba, unsigned short int nsectors, const unsigned char *buffer); +void bdm_writeSector(u64 lba, unsigned short int nsectors, const unsigned char *buffer); #define I_bdm_writeSector DECLARE_IMPORT(7, bdm_writeSector) #endif