Skip to content

Commit

Permalink
Pass DISC_INTERFACE to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Nov 8, 2024
1 parent 70db9ee commit fdff5b7
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion gc/di/di.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ typedef int(*read_func)(void*,uint32_t,uint32_t);
typedef int(*read_func_async)(void*,uint32_t,uint32_t,ipccallback);

extern int di_fd;
extern const DISC_INTERFACE __io_wiidvd;
extern DISC_INTERFACE __io_wiidvd;

int DI_Init(void);
void DI_LoadDVDX(bool load);
Expand Down
4 changes: 2 additions & 2 deletions gc/iso9660.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
extern "C" {
#endif

bool ISO9660_Mount(const char* name, const DISC_INTERFACE* disc_interface);
bool ISO9660_Unmount(const char* name);
bool ISO9660_Mount(const char *name, DISC_INTERFACE *disc_interface);
bool ISO9660_Unmount(const char *name);
const char *ISO9660_GetVolumeLabel(const char *name);

#ifdef __cplusplus
Expand Down
16 changes: 8 additions & 8 deletions gc/ogc/disc_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@

typedef uint64_t sec_t;

typedef bool (* FN_MEDIUM_STARTUP)(void) ;
typedef bool (* FN_MEDIUM_ISINSERTED)(void) ;
typedef bool (* FN_MEDIUM_READSECTORS)(sec_t sector, sec_t numSectors, void* buffer) ;
typedef bool (* FN_MEDIUM_WRITESECTORS)(sec_t sector, sec_t numSectors, const void* buffer) ;
typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ;
typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ;
typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ;

typedef bool (* FN_MEDIUM_STARTUP)(DISC_INTERFACE* disc) ;
typedef bool (* FN_MEDIUM_ISINSERTED)(DISC_INTERFACE* disc) ;
typedef bool (* FN_MEDIUM_READSECTORS)(DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, void* buffer) ;
typedef bool (* FN_MEDIUM_WRITESECTORS)(DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, const void* buffer) ;
typedef bool (* FN_MEDIUM_CLEARSTATUS)(DISC_INTERFACE* disc) ;
typedef bool (* FN_MEDIUM_SHUTDOWN)(DISC_INTERFACE* disc) ;

struct DISC_INTERFACE_STRUCT {
unsigned long ioType ;
Expand All @@ -64,6 +66,4 @@ struct DISC_INTERFACE_STRUCT {
FN_MEDIUM_SHUTDOWN shutdown ;
} ;

typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ;

#endif // define OGC_DISC_IO_INCLUDE
14 changes: 7 additions & 7 deletions libdi/di.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ int DI_ReadDiscID(uint64_t *id)
return(ret == 1)? 0 : -ret;
}

static bool diio_Startup(void)
static bool diio_Startup(DISC_INTERFACE *disc)
{
u64 t1,t2;

Expand All @@ -939,7 +939,7 @@ static bool diio_Startup(void)
return false;
}

static bool diio_IsInserted(void)
static bool diio_IsInserted(DISC_INTERFACE *disc)
{
u32 val;

Expand All @@ -953,7 +953,7 @@ static bool diio_IsInserted(void)
return false;
}

static bool diio_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
static bool diio_ReadSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, void *buffer)
{
if((uint32_t)sector != sector)
return false;
Expand All @@ -966,23 +966,23 @@ static bool diio_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
return false;
}

static bool diio_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer)
static bool diio_WriteSectors(DISC_INTERFACE *disc, sec_t sector, sec_t numSectors, const void *buffer)
{
return false;
}

static bool diio_ClearStatus(void)
static bool diio_ClearStatus(DISC_INTERFACE *disc)
{
return true;
}

static bool diio_Shutdown(void)
static bool diio_Shutdown(DISC_INTERFACE *disc)
{
DI_StopMotor();
return true;
}

const DISC_INTERFACE __io_wiidvd = {
DISC_INTERFACE __io_wiidvd = {
DEVICE_TYPE_WII_DVD,
FEATURE_MEDIUM_CANREAD | FEATURE_WII_DVD,
diio_Startup,
Expand Down
20 changes: 10 additions & 10 deletions libiso9660/iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct dentry_s

typedef struct iso9660mount_s
{
const DISC_INTERFACE *disc_interface;
DISC_INTERFACE *disc_interface;
u8 read_buffer[BUFFER_SIZE] __attribute__((aligned(32)));
u8 cluster_buffer[BUFFER_SIZE] __attribute__((aligned(32)));
u32 cache_start;
Expand Down Expand Up @@ -118,7 +118,7 @@ static int __read(MOUNT_DESCR *mdescr, void *ptr, u64 offset, size_t len)
u32 end_sector = (offset + len - 1) / SECTOR_SIZE;
u32 sectors = MIN(BUFFER_SIZE / SECTOR_SIZE, end_sector - sector + 1);
u32 sector_offset = offset % SECTOR_SIZE;
const DISC_INTERFACE *disc = mdescr->disc_interface;
DISC_INTERFACE *disc = mdescr->disc_interface;

len = MIN(BUFFER_SIZE - sector_offset, len);
if (mdescr->cache_sectors && sector >= mdescr->cache_start && (sector + sectors) <= (mdescr->cache_start + mdescr->cache_sectors))
Expand All @@ -127,7 +127,7 @@ static int __read(MOUNT_DESCR *mdescr, void *ptr, u64 offset, size_t len)
return len;
}

if (!disc->readSectors(sector, BUFFER_SIZE / SECTOR_SIZE, mdescr->read_buffer))
if (!disc->readSectors(disc, sector, BUFFER_SIZE / SECTOR_SIZE, mdescr->read_buffer))
{
mdescr->cache_sectors = 0;
return -1;
Expand Down Expand Up @@ -847,11 +847,11 @@ static void cleanup_recursive(PATH_ENTRY *entry)
static struct pvd_s* read_volume_descriptor(MOUNT_DESCR *mdescr, u8 descriptor)
{
u8 sector;
const DISC_INTERFACE *disc = mdescr->disc_interface;
DISC_INTERFACE *disc = mdescr->disc_interface;

for (sector = 16; sector < 32; sector++)
{
if (!disc->readSectors(sector, 1, mdescr->read_buffer))
if (!disc->readSectors(disc, sector, 1, mdescr->read_buffer))
return NULL;
if (!memcmp(mdescr->read_buffer + 1, "CD001\1", 6))
{
Expand Down Expand Up @@ -928,7 +928,7 @@ static bool read_directories(MOUNT_DESCR *mdescr)
return true;
}

static MOUNT_DESCR *_ISO9660_mdescr_constructor(const DISC_INTERFACE *disc_interface)
static MOUNT_DESCR *_ISO9660_mdescr_constructor(DISC_INTERFACE *disc_interface)
{
MOUNT_DESCR *mdescr = NULL;

Expand All @@ -951,7 +951,7 @@ static MOUNT_DESCR *_ISO9660_mdescr_constructor(const DISC_INTERFACE *disc_inter
return mdescr;
}

bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface)
bool ISO9660_Mount(const char *name, DISC_INTERFACE *disc_interface)
{
char *nameCopy;
devoptab_t *devops = NULL;
Expand All @@ -961,10 +961,10 @@ bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface)
if (!name || strlen(name) > 8 || !disc_interface)
return false;

if (!disc_interface->startup())
if (!disc_interface->startup(disc_interface))
return false;

if (!disc_interface->isInserted())
if (!disc_interface->isInserted(disc_interface))
return false;

sprintf(devname, "%s:", name);
Expand Down Expand Up @@ -1002,7 +1002,7 @@ bool ISO9660_Mount(const char* name, const DISC_INTERFACE *disc_interface)
}


bool ISO9660_Unmount(const char* name)
bool ISO9660_Unmount(const char *name)
{
devoptab_t *devops;
MOUNT_DESCR *mdescr;
Expand Down
30 changes: 15 additions & 15 deletions libogc/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3558,7 +3558,7 @@ u32 DVD_SetAutoInvalidation(u32 auto_inv)
return ret;
}

static bool __gcdvd_Startup(void)
static bool __gcdvd_Startup(DISC_INTERFACE *disc)
{
DVD_Init();

Expand All @@ -3574,7 +3574,7 @@ static bool __gcdvd_Startup(void)
return true;
}

static bool __gcdvd_IsInserted(void)
static bool __gcdvd_IsInserted(DISC_INTERFACE *disc)
{
u32 status = 0;
DVD_LowGetStatus(&status, NULL);
Expand All @@ -3585,7 +3585,7 @@ static bool __gcdvd_IsInserted(void)
return false;
}

static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
static bool __gcdvd_ReadSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,void *buffer)
{
dvdcmdblk blk;

Expand All @@ -3599,24 +3599,24 @@ static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
return true;
}

static bool __gcdvd_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer)
static bool __gcdvd_WriteSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,const void *buffer)
{
return false;
}

static bool __gcdvd_ClearStatus(void)
static bool __gcdvd_ClearStatus(DISC_INTERFACE *disc)
{
return true;
}

static bool __gcdvd_Shutdown(void)
static bool __gcdvd_Shutdown(DISC_INTERFACE *disc)
{
dvdcmdblk blk;
DVD_StopMotor(&blk);
return true;
}

static bool __gcode_Startup(void)
static bool __gcode_Startup(DISC_INTERFACE *disc)
{
dvdcmdblk blk;

Expand All @@ -3629,24 +3629,24 @@ static bool __gcode_Startup(void)
return false;

if(__dvd_driveinfo.pad[1] == 'w')
__io_gcode.features |= FEATURE_MEDIUM_CANWRITE;
disc->features |= FEATURE_MEDIUM_CANWRITE;
else
__io_gcode.features &= ~FEATURE_MEDIUM_CANWRITE;
disc->features &= ~FEATURE_MEDIUM_CANWRITE;

__dvd_gcode_writebufsize = __dvd_driveinfo.pad[3] + 1;

return true;
}

static bool __gcode_IsInserted(void)
static bool __gcode_IsInserted(DISC_INTERFACE *disc)
{
if(DVD_LowGetCoverStatus() == 1)
return false;

return true;
}

static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
static bool __gcode_ReadSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,void *buffer)
{
dvdcmdblk blk;

Expand All @@ -3660,11 +3660,11 @@ static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer)
return true;
}

static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffer)
static bool __gcode_WriteSectors(DISC_INTERFACE *disc,sec_t sector,sec_t numSectors,const void *buffer)
{
dvdcmdblk blk;

if(!(__io_gcode.features & FEATURE_MEDIUM_CANWRITE)) return false;
if(!(disc->features & FEATURE_MEDIUM_CANWRITE)) return false;
if((u32)sector != sector) return false;
if((u32)numSectors != numSectors) return false;
if(!SYS_IsDMAAddress(buffer)) return false;
Expand All @@ -3675,12 +3675,12 @@ static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffe
return true;
}

static bool __gcode_ClearStatus(void)
static bool __gcode_ClearStatus(DISC_INTERFACE *disc)
{
return true;
}

static bool __gcode_Shutdown(void)
static bool __gcode_Shutdown(DISC_INTERFACE *disc)
{
return true;
}
Expand Down
Loading

0 comments on commit fdff5b7

Please sign in to comment.