Skip to content

Commit 4f6bd43

Browse files
committed
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.
1 parent ea01c62 commit 4f6bd43

File tree

4 files changed

+58
-171
lines changed

4 files changed

+58
-171
lines changed

modules/vmc/genvmc/genvmc.c

+46-122
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
Review Open PS2 Loader README & LICENSE files for further details.
77
*/
88

9+
#include <cdvdman.h>
910
#include <stdio.h>
1011
#include <loadcore.h>
11-
#include <ioman.h>
12-
#include "ioman_add.h"
13-
#include <io_common.h>
12+
#include <iomanX.h>
1413
#include <intrman.h>
14+
#include <mcman.h>
1515
#include <thsemap.h>
1616
#include <sysclib.h>
1717
#include <sysmem.h>
@@ -32,15 +32,15 @@
3232
IRX_ID(MODNAME, 1, 1);
3333

3434
// driver ops protypes
35-
int genvmc_dummy(void);
36-
int genvmc_init(iop_device_t *dev);
37-
int genvmc_deinit(iop_device_t *dev);
38-
int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, u32 arglen, void *buf, u32 buflen);
35+
static int genvmc_dummy(void);
36+
static int genvmc_init(iop_device_t *dev);
37+
static int genvmc_deinit(iop_device_t *dev);
38+
static int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen);
3939

4040
// driver ops func tab
41-
void *genvmc_ops[27] = {
42-
(void *)genvmc_init,
43-
(void *)genvmc_deinit,
41+
static iop_device_ops_t genvmc_ops = {
42+
&genvmc_init,
43+
&genvmc_deinit,
4444
(void *)genvmc_dummy,
4545
(void *)genvmc_dummy,
4646
(void *)genvmc_dummy,
@@ -62,64 +62,26 @@ void *genvmc_ops[27] = {
6262
(void *)genvmc_dummy,
6363
(void *)genvmc_dummy,
6464
(void *)genvmc_dummy,
65-
(void *)genvmc_devctl,
65+
&genvmc_devctl,
6666
(void *)genvmc_dummy,
6767
(void *)genvmc_dummy,
6868
(void *)genvmc_dummy};
6969

7070
// driver descriptor
71-
static iop_ext_device_t genvmc_dev = {
71+
static iop_device_t genvmc_dev = {
7272
"genvmc",
7373
IOP_DT_FS | IOP_DT_FSEXT,
7474
1,
7575
"genvmc",
76-
(struct _iop_ext_device_ops *)&genvmc_ops};
76+
&genvmc_ops};
7777

78-
// from cdvdman
79-
typedef struct
80-
{
81-
u8 stat;
82-
u8 second;
83-
u8 minute;
84-
u8 hour;
85-
u8 week;
86-
u8 day;
87-
u8 month;
88-
u8 year;
89-
} cd_clock_t;
90-
91-
int sceCdRC(cd_clock_t *rtc); // #51
92-
93-
int sceMcDetectCard(int port, int slot); // #05
94-
int sceMcReadPage(int port, int slot, int page, char *mcbuffer); // #18
95-
int sceMcGetCardType(int port, int slot); // #39
96-
97-
98-
// mc file attributes
99-
#define SCE_STM_R 0x01
100-
#define SCE_STM_W 0x02
101-
#define SCE_STM_X 0x04
102-
#define SCE_STM_C 0x08
103-
#define SCE_STM_F 0x10
104-
#define SCE_STM_D 0x20
105-
#define sceMcFileAttrReadable SCE_STM_R
106-
#define sceMcFileAttrWriteable SCE_STM_W
107-
#define sceMcFileAttrExecutable SCE_STM_X
108-
#define sceMcFileAttrDupProhibit SCE_STM_C
109-
#define sceMcFileAttrFile SCE_STM_F
110-
#define sceMcFileAttrSubdir SCE_STM_D
111-
#define sceMcFileCreateDir 0x0040
112-
#define sceMcFileAttrClosed 0x0080
113-
#define sceMcFileCreateFile 0x0200
114-
#define sceMcFile0400 0x0400
115-
#define sceMcFileAttrPDAExec 0x0800
116-
#define sceMcFileAttrPS1 0x1000
117-
#define sceMcFileAttrHidden 0x2000
118-
#define sceMcFileAttrExists 0x8000
78+
#define sceMcDetectCard McDetectCard
79+
#define sceMcReadPage McReadPage
80+
#define sceMcGetCardType McGetMcType
11981

12082
// SONY superblock magic & version
121-
static char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format ";
122-
static char SUPERBLOCK_VERSION[] = "1.2.0.0";
83+
static const char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format ";
84+
static const char SUPERBLOCK_VERSION[] = "1.2.0.0";
12385

12486
// superblock struct
12587
typedef struct
@@ -155,32 +117,6 @@ typedef struct
155117
int unknown5;
156118
} MCDevInfo;
157119

158-
typedef struct _sceMcStDateTime
159-
{
160-
u8 Resv2;
161-
u8 Sec;
162-
u8 Min;
163-
u8 Hour;
164-
u8 Day;
165-
u8 Month;
166-
u16 Year;
167-
} sceMcStDateTime;
168-
169-
typedef struct
170-
{ // size = 512
171-
u16 mode; // 0
172-
u16 unused; // 2
173-
u32 length; // 4
174-
sceMcStDateTime created; // 8
175-
u32 cluster; // 16
176-
u32 dir_entry; // 20
177-
sceMcStDateTime modified; // 24
178-
u32 attr; // 32
179-
u32 unused2[7]; // 36
180-
char name[32]; // 64
181-
u8 unused3[416]; // 96
182-
} McFsEntry;
183-
184120
#define BLOCKKB 16
185121

186122
static MCDevInfo devinfo __attribute__((aligned(64)));
@@ -220,7 +156,7 @@ static void long_multiply(u32 v1, u32 v2, u32 *HI, u32 *LO)
220156
static int mc_getmcrtime(sceMcStDateTime *time)
221157
{
222158
register int retries;
223-
cd_clock_t cdtime;
159+
sceCdCLOCK cdtime;
224160

225161
retries = 64;
226162

@@ -229,28 +165,28 @@ static int mc_getmcrtime(sceMcStDateTime *time)
229165
break;
230166
} while (--retries > 0);
231167

232-
if (cdtime.stat & 128) {
233-
*((u16 *)&cdtime.month) = 0x7d0;
234-
cdtime.day = 3;
235-
cdtime.week = 4;
236-
cdtime.hour = 0;
237-
cdtime.minute = 0;
238-
cdtime.second = 0;
239-
cdtime.stat = 0;
240-
}
241-
242-
time->Resv2 = 0;
243-
time->Sec = ((((cdtime.second >> 4) << 2) + (cdtime.second >> 4)) << 1) + (cdtime.second & 0xf);
244-
time->Min = ((((cdtime.minute >> 4) << 2) + (cdtime.minute >> 4)) << 1) + (cdtime.minute & 0xf);
245-
time->Hour = ((((cdtime.hour >> 4) << 2) + (cdtime.hour >> 4)) << 1) + (cdtime.hour & 0xf);
246-
time->Day = ((((cdtime.day >> 4) << 2) + (cdtime.day >> 4)) << 1) + (cdtime.day & 0xf);
247-
248-
if ((cdtime.month & 0x10) != 0)
249-
time->Month = (cdtime.month & 0xf) + 0xa;
250-
else
251-
time->Month = cdtime.month & 0xf;
168+
if (cdtime.stat & 0x80) {
169+
time->Year = 2000;
170+
time->Month = 3;
171+
time->Day = 4;
172+
time->Hour = 5;
173+
time->Min = 6;
174+
time->Sec = 7;
175+
time->Resv2 = 0;
176+
} else {
177+
time->Resv2 = 0;
178+
time->Sec = btoi(cdtime.second);
179+
time->Min = btoi(cdtime.minute);
180+
time->Hour = btoi(cdtime.hour);
181+
time->Day = btoi(cdtime.day);
182+
183+
if ((cdtime.month & 0x10) != 0) //Keep only valid bits: 0x1f (for month values 1-12 in BCD)
184+
time->Month = (cdtime.month & 0xf) + 0xa;
185+
else
186+
time->Month = cdtime.month & 0xf;
252187

253-
time->Year = ((((cdtime.year >> 4) << 2) + (cdtime.year >> 4)) << 1) + ((cdtime.year & 0xf) | 0x7d0);
188+
time->Year = btoi(cdtime.year) + 2000;
189+
}
254190

255191
return 0;
256192
}
@@ -387,9 +323,9 @@ static int vmc_mcformat(char *filename, int size_kb, int blocksize, int *progres
387323
// erase all clusters
388324
strcpy(msg, "Erasing VMC clusters...");
389325
memset(cluster_buf, 0xff, sizeof(cluster_buf));
390-
for (i = 0; i < mcdi->clusters_per_card; i += 16) {
326+
for (i = 0; i < mcdi->clusters_per_card; i += BLOCKKB) {
391327
*progress = i / (mcdi->clusters_per_card / 99);
392-
r = mc_writecluster(genvmc_fh, i, cluster_buf, 16);
328+
r = mc_writecluster(genvmc_fh, i, cluster_buf, BLOCKKB);
393329
if (r < 0) {
394330
if (r == -2) // it's user abort
395331
r = -1000;
@@ -588,13 +524,13 @@ static int vmc_mcformat(char *filename, int size_kb, int blocksize, int *progres
588524
}
589525

590526
//--------------------------------------------------------------
591-
int genvmc_dummy(void)
527+
static int genvmc_dummy(void)
592528
{
593529
return -EPERM;
594530
}
595531

596532
//--------------------------------------------------------------
597-
int genvmc_init(iop_device_t *dev)
533+
static int genvmc_init(iop_device_t *dev)
598534
{
599535
genvmc_io_sema = CreateMutex(IOP_MUTEX_UNLOCKED);
600536
genvmc_thread_sema = CreateMutex(IOP_MUTEX_UNLOCKED);
@@ -604,7 +540,7 @@ int genvmc_init(iop_device_t *dev)
604540
}
605541

606542
//--------------------------------------------------------------
607-
int genvmc_deinit(iop_device_t *dev)
543+
static int genvmc_deinit(iop_device_t *dev)
608544
{
609545
DeleteSema(genvmc_io_sema);
610546
DeleteSema(genvmc_thread_sema);
@@ -714,7 +650,7 @@ static int vmc_status(statusVMCparam_t *param)
714650
}
715651

716652
//--------------------------------------------------------------
717-
int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, u32 arglen, void *buf, u32 buflen)
653+
static int genvmc_devctl(iop_file_t *f, const char *name, int cmd, void *args, unsigned int arglen, void *buf, unsigned int buflen)
718654
{
719655
register int r = 0;
720656

@@ -768,15 +704,3 @@ int _start(int argc, char **argv)
768704
return MODULE_RESIDENT_END;
769705
}
770706

771-
//--------------------------------------------------------------
772-
// Extra import tables
773-
774-
DECLARE_IMPORT_TABLE(cdvdman, 1, 1)
775-
DECLARE_IMPORT(51, sceCdRC)
776-
END_IMPORT_TABLE
777-
778-
DECLARE_IMPORT_TABLE(mcman, 1, 1)
779-
DECLARE_IMPORT(5, sceMcDetectCard)
780-
DECLARE_IMPORT(18, sceMcReadPage)
781-
DECLARE_IMPORT(39, sceMcGetCardType)
782-
END_IMPORT_TABLE

modules/vmc/genvmc/imports.lst

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
cdvdman_IMPORTS_start
2+
I_sceCdRC
3+
cdvdman_IMPORTS_end
4+
15
ioman_IMPORTS_start
26
I_DelDrv
37
I_AddDrv
@@ -13,6 +17,12 @@ I_CpuSuspendIntr
1317
I_CpuResumeIntr
1418
intrman_IMPORTS_end
1519

20+
mcman_IMPORTS_start
21+
I_McDetectCard
22+
I_McReadPage
23+
I_McGetMcType
24+
mcman_IMPORTS_end
25+
1626
sysmem_IMPORTS_start
1727
I_AllocSysMemory
1828
I_FreeSysMemory

modules/vmc/genvmc/ioman_add.h

-48
This file was deleted.

modules/vmc/genvmc/irx_imports.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#include <irx.h>
55

6+
#include <cdvdman.h>
67
#include <intrman.h>
78
#include <ioman.h>
8-
#include "ioman_add.h"
9+
#include <mcman.h>
910
#ifdef DEBUG
1011
#include <stdio.h>
1112
#endif

0 commit comments

Comments
 (0)