From 4f6bd43fb07238183fba973080eb555114436f4f Mon Sep 17 00:00:00 2001 From: SP193 Date: Sun, 17 Feb 2019 11:11:02 +0800 Subject: [PATCH] GENVMC: removed ioman_add.h, moved custom imports to imports.lst, use PS2SDK's libmc and libcdvd definitions, fixed returned time for mc_getmcrtime() when the clock battery is flat, fixed vmc_mcformat() not using BLOCKKB to determine the buffer length. --- modules/vmc/genvmc/genvmc.c | 168 +++++++++---------------------- modules/vmc/genvmc/imports.lst | 10 ++ modules/vmc/genvmc/ioman_add.h | 48 --------- modules/vmc/genvmc/irx_imports.h | 3 +- 4 files changed, 58 insertions(+), 171 deletions(-) delete mode 100644 modules/vmc/genvmc/ioman_add.h diff --git a/modules/vmc/genvmc/genvmc.c b/modules/vmc/genvmc/genvmc.c index 3e5352012..ee019112a 100644 --- a/modules/vmc/genvmc/genvmc.c +++ b/modules/vmc/genvmc/genvmc.c @@ -6,12 +6,12 @@ Review Open PS2 Loader README & LICENSE files for further details. */ +#include #include #include -#include -#include "ioman_add.h" -#include +#include #include +#include #include #include #include @@ -32,15 +32,15 @@ IRX_ID(MODNAME, 1, 1); // driver ops protypes -int genvmc_dummy(void); -int genvmc_init(iop_device_t *dev); -int genvmc_deinit(iop_device_t *dev); -int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, u32 arglen, void *buf, u32 buflen); +static int genvmc_dummy(void); +static int genvmc_init(iop_device_t *dev); +static int genvmc_deinit(iop_device_t *dev); +static int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen); // driver ops func tab -void *genvmc_ops[27] = { - (void *)genvmc_init, - (void *)genvmc_deinit, +static iop_device_ops_t genvmc_ops = { + &genvmc_init, + &genvmc_deinit, (void *)genvmc_dummy, (void *)genvmc_dummy, (void *)genvmc_dummy, @@ -62,64 +62,26 @@ void *genvmc_ops[27] = { (void *)genvmc_dummy, (void *)genvmc_dummy, (void *)genvmc_dummy, - (void *)genvmc_devctl, + &genvmc_devctl, (void *)genvmc_dummy, (void *)genvmc_dummy, (void *)genvmc_dummy}; // driver descriptor -static iop_ext_device_t genvmc_dev = { +static iop_device_t genvmc_dev = { "genvmc", IOP_DT_FS | IOP_DT_FSEXT, 1, "genvmc", - (struct _iop_ext_device_ops *)&genvmc_ops}; + &genvmc_ops}; -// from cdvdman -typedef struct -{ - u8 stat; - u8 second; - u8 minute; - u8 hour; - u8 week; - u8 day; - u8 month; - u8 year; -} cd_clock_t; - -int sceCdRC(cd_clock_t *rtc); // #51 - -int sceMcDetectCard(int port, int slot); // #05 -int sceMcReadPage(int port, int slot, int page, char *mcbuffer); // #18 -int sceMcGetCardType(int port, int slot); // #39 - - -// mc file attributes -#define SCE_STM_R 0x01 -#define SCE_STM_W 0x02 -#define SCE_STM_X 0x04 -#define SCE_STM_C 0x08 -#define SCE_STM_F 0x10 -#define SCE_STM_D 0x20 -#define sceMcFileAttrReadable SCE_STM_R -#define sceMcFileAttrWriteable SCE_STM_W -#define sceMcFileAttrExecutable SCE_STM_X -#define sceMcFileAttrDupProhibit SCE_STM_C -#define sceMcFileAttrFile SCE_STM_F -#define sceMcFileAttrSubdir SCE_STM_D -#define sceMcFileCreateDir 0x0040 -#define sceMcFileAttrClosed 0x0080 -#define sceMcFileCreateFile 0x0200 -#define sceMcFile0400 0x0400 -#define sceMcFileAttrPDAExec 0x0800 -#define sceMcFileAttrPS1 0x1000 -#define sceMcFileAttrHidden 0x2000 -#define sceMcFileAttrExists 0x8000 +#define sceMcDetectCard McDetectCard +#define sceMcReadPage McReadPage +#define sceMcGetCardType McGetMcType // SONY superblock magic & version -static char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format "; -static char SUPERBLOCK_VERSION[] = "1.2.0.0"; +static const char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format "; +static const char SUPERBLOCK_VERSION[] = "1.2.0.0"; // superblock struct typedef struct @@ -155,32 +117,6 @@ typedef struct int unknown5; } MCDevInfo; -typedef struct _sceMcStDateTime -{ - u8 Resv2; - u8 Sec; - u8 Min; - u8 Hour; - u8 Day; - u8 Month; - u16 Year; -} sceMcStDateTime; - -typedef struct -{ // size = 512 - u16 mode; // 0 - u16 unused; // 2 - u32 length; // 4 - sceMcStDateTime created; // 8 - u32 cluster; // 16 - u32 dir_entry; // 20 - sceMcStDateTime modified; // 24 - u32 attr; // 32 - u32 unused2[7]; // 36 - char name[32]; // 64 - u8 unused3[416]; // 96 -} McFsEntry; - #define BLOCKKB 16 static MCDevInfo devinfo __attribute__((aligned(64))); @@ -220,7 +156,7 @@ static void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO) static int mc_getmcrtime(sceMcStDateTime *time) { register int retries; - cd_clock_t cdtime; + sceCdCLOCK cdtime; retries = 64; @@ -229,28 +165,28 @@ static int mc_getmcrtime(sceMcStDateTime *time) break; } while (--retries > 0); - if (cdtime.stat & 128) { - *((u16 *)&cdtime.month) = 0x7d0; - cdtime.day = 3; - cdtime.week = 4; - cdtime.hour = 0; - cdtime.minute = 0; - cdtime.second = 0; - cdtime.stat = 0; - } - - time->Resv2 = 0; - time->Sec = ((((cdtime.second >> 4) << 2) + (cdtime.second >> 4)) << 1) + (cdtime.second & 0xf); - time->Min = ((((cdtime.minute >> 4) << 2) + (cdtime.minute >> 4)) << 1) + (cdtime.minute & 0xf); - time->Hour = ((((cdtime.hour >> 4) << 2) + (cdtime.hour >> 4)) << 1) + (cdtime.hour & 0xf); - time->Day = ((((cdtime.day >> 4) << 2) + (cdtime.day >> 4)) << 1) + (cdtime.day & 0xf); - - if ((cdtime.month & 0x10) != 0) - time->Month = (cdtime.month & 0xf) + 0xa; - else - time->Month = cdtime.month & 0xf; + if (cdtime.stat & 0x80) { + time->Year = 2000; + time->Month = 3; + time->Day = 4; + time->Hour = 5; + time->Min = 6; + time->Sec = 7; + time->Resv2 = 0; + } else { + time->Resv2 = 0; + time->Sec = btoi(cdtime.second); + time->Min = btoi(cdtime.minute); + time->Hour = btoi(cdtime.hour); + time->Day = btoi(cdtime.day); + + if ((cdtime.month & 0x10) != 0) //Keep only valid bits: 0x1f (for month values 1-12 in BCD) + time->Month = (cdtime.month & 0xf) + 0xa; + else + time->Month = cdtime.month & 0xf; - time->Year = ((((cdtime.year >> 4) << 2) + (cdtime.year >> 4)) << 1) + ((cdtime.year & 0xf) | 0x7d0); + time->Year = btoi(cdtime.year) + 2000; + } return 0; } @@ -387,9 +323,9 @@ static int vmc_mcformat(char *filename, int size_kb, int blocksize, int *progres // erase all clusters strcpy(msg, "Erasing VMC clusters..."); memset(cluster_buf, 0xff, sizeof(cluster_buf)); - for (i = 0; i < mcdi->clusters_per_card; i += 16) { + for (i = 0; i < mcdi->clusters_per_card; i += BLOCKKB) { *progress = i / (mcdi->clusters_per_card / 99); - r = mc_writecluster(genvmc_fh, i, cluster_buf, 16); + r = mc_writecluster(genvmc_fh, i, cluster_buf, BLOCKKB); if (r < 0) { if (r == -2) // it's user abort r = -1000; @@ -588,13 +524,13 @@ static int vmc_mcformat(char *filename, int size_kb, int blocksize, int *progres } //-------------------------------------------------------------- -int genvmc_dummy(void) +static int genvmc_dummy(void) { return -EPERM; } //-------------------------------------------------------------- -int genvmc_init(iop_device_t *dev) +static int genvmc_init(iop_device_t *dev) { genvmc_io_sema = CreateMutex(IOP_MUTEX_UNLOCKED); genvmc_thread_sema = CreateMutex(IOP_MUTEX_UNLOCKED); @@ -604,7 +540,7 @@ int genvmc_init(iop_device_t *dev) } //-------------------------------------------------------------- -int genvmc_deinit(iop_device_t *dev) +static int genvmc_deinit(iop_device_t *dev) { DeleteSema(genvmc_io_sema); DeleteSema(genvmc_thread_sema); @@ -714,7 +650,7 @@ static int vmc_status(statusVMCparam_t *param) } //-------------------------------------------------------------- -int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, u32 arglen, void *buf, u32 buflen) +static int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen) { register int r = 0; @@ -768,15 +704,3 @@ int _start(int argc, char **argv) return MODULE_RESIDENT_END; } -//-------------------------------------------------------------- -// Extra import tables - -DECLARE_IMPORT_TABLE(cdvdman, 1, 1) -DECLARE_IMPORT(51, sceCdRC) -END_IMPORT_TABLE - -DECLARE_IMPORT_TABLE(mcman, 1, 1) -DECLARE_IMPORT(5, sceMcDetectCard) -DECLARE_IMPORT(18, sceMcReadPage) -DECLARE_IMPORT(39, sceMcGetCardType) -END_IMPORT_TABLE diff --git a/modules/vmc/genvmc/imports.lst b/modules/vmc/genvmc/imports.lst index 8b8b83711..14617cf9c 100644 --- a/modules/vmc/genvmc/imports.lst +++ b/modules/vmc/genvmc/imports.lst @@ -1,3 +1,7 @@ +cdvdman_IMPORTS_start +I_sceCdRC +cdvdman_IMPORTS_end + ioman_IMPORTS_start I_DelDrv I_AddDrv @@ -13,6 +17,12 @@ I_CpuSuspendIntr I_CpuResumeIntr intrman_IMPORTS_end +mcman_IMPORTS_start +I_McDetectCard +I_McReadPage +I_McGetMcType +mcman_IMPORTS_end + sysmem_IMPORTS_start I_AllocSysMemory I_FreeSysMemory diff --git a/modules/vmc/genvmc/ioman_add.h b/modules/vmc/genvmc/ioman_add.h deleted file mode 100644 index d3506e537..000000000 --- a/modules/vmc/genvmc/ioman_add.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _IOMAN_ADD_H_ -#define _IOMAN_ADD_H_ - -#define IOP_DT_FSEXT 0x10000000 - -typedef struct _iop_ext_device -{ - const char *name; - unsigned int type; - unsigned int version; /* Not so sure about this one. */ - const char *desc; - struct _iop_ext_device_ops *ops; -} iop_ext_device_t; - -typedef struct _iop_ext_device_ops -{ - int (*init)(iop_device_t *); - int (*deinit)(iop_device_t *); - int (*format)(iop_file_t *); - int (*open)(iop_file_t *, const char *, int); - int (*close)(iop_file_t *); - int (*read)(iop_file_t *, void *, int); - int (*write)(iop_file_t *, void *, int); - int (*lseek)(iop_file_t *, unsigned long, int); - int (*ioctl)(iop_file_t *, unsigned long, void *); - int (*remove)(iop_file_t *, const char *); - int (*mkdir)(iop_file_t *, const char *); - int (*rmdir)(iop_file_t *, const char *); - int (*dopen)(iop_file_t *, const char *); - int (*dclose)(iop_file_t *); - int (*dread)(iop_file_t *, iox_dirent_t *); - int (*getstat)(iop_file_t *, const char *, iox_stat_t *); - int (*chstat)(iop_file_t *, const char *, iox_stat_t *, unsigned int); - /* Extended ops start here. */ - int (*rename)(iop_file_t *, const char *, const char *); - int (*chdir)(iop_file_t *, const char *); - int (*sync)(iop_file_t *, const char *, int); - int (*mount)(iop_file_t *, const char *, const char *, int, void *, unsigned int); - int (*umount)(iop_file_t *, const char *); - long long (*lseek64)(iop_file_t *, long long, int); - int (*devctl)(iop_file_t *, const char *, int, void *, unsigned int, void *, unsigned int); - int (*symlink)(iop_file_t *, const char *, const char *); - int (*readlink)(iop_file_t *, const char *, char *, unsigned int); - int (*ioctl2)(iop_file_t *, int, void *, unsigned int, void *, unsigned int); - -} iop_ext_device_ops_t; - -#endif diff --git a/modules/vmc/genvmc/irx_imports.h b/modules/vmc/genvmc/irx_imports.h index baa97e4cf..12dcbddb5 100644 --- a/modules/vmc/genvmc/irx_imports.h +++ b/modules/vmc/genvmc/irx_imports.h @@ -3,9 +3,10 @@ #include +#include #include #include -#include "ioman_add.h" +#include #ifdef DEBUG #include #endif