Skip to content

Commit

Permalink
u64 datatype for vmc
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Nov 18, 2024
1 parent 68885af commit 3db13e8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/bdmsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions modules/iopcore/cdvdman/cdvdman.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions modules/iopcore/cdvdman/device-bdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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__);

Expand All @@ -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__);

Expand Down
10 changes: 5 additions & 5 deletions modules/iopcore/cdvdman/device-hdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions modules/iopcore/cdvdman/device-smb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/iopcore/cdvdman/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
14 changes: 6 additions & 8 deletions modules/mcemu/device-bdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include "mcemu.h"

#define U64_2U32(val) ((u32 *)val)[1], ((u32 *)val)[0]

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, U64_2U32(&lba));

Check failure on line 15 in modules/mcemu/device-bdm.c

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/mcemu/device-bdm.c#L15

printf format string requires 3 parameters but only 2 are given.

bdm_writeSector(lba, 1, buf);

Expand All @@ -21,10 +21,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, U64_2U32(&lba));

Check failure on line 25 in modules/mcemu/device-bdm.c

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/mcemu/device-bdm.c#L25

printf format string requires 3 parameters but only 2 are given.

bdm_readSector(lba, 1, buf);

Expand Down
2 changes: 1 addition & 1 deletion modules/mcemu/mcemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/mcemu/mcemu_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3db13e8

Please sign in to comment.