2 Copyright 2009, jimmikaelkael
3 Licenced under Academic Free License version 3.0
4 Review OpenUsbLd README & LICENSE files for further details.
13 #include <io_common.h>
17 #define MODNAME "discID"
18 IRX_ID(MODNAME
, 1, 1);
20 #define CDVDreg_30 (*(volatile unsigned char *)0xBF402030)
21 #define CDVDreg_31 (*(volatile unsigned char *)0xBF402031)
22 #define CDVDreg_32 (*(volatile unsigned char *)0xBF402032)
23 #define CDVDreg_33 (*(volatile unsigned char *)0xBF402033)
24 #define CDVDreg_34 (*(volatile unsigned char *)0xBF402034)
25 #define CDVDreg_KEYSTATE (*(volatile unsigned char *)0xBF402038)
26 #define CDVDreg_KEYXOR (*(volatile unsigned char *)0xBF402039)
36 int sceCdInit(int init_mode
); // #4
37 int sceCdStandby(void); // #5
38 int sceCdSync(int mode
); // #11
39 int sceCdGetDiskType(void); // #12
40 int sceCdDiskReady(int mode
); // #13
41 int sceCdStop(void); // #15
42 int sceCdReadKey(int arg1
, int arg2
, u32 lsn
, char *key
); // #35
44 // driver ops protypes
45 int discID_dummy(void);
46 int discID_init(iop_device_t
*dev
);
47 int discID_deinit(iop_device_t
*dev
);
48 int discID_open(iop_file_t
*f
, char *filename
, int mode
);
49 int discID_read(iop_file_t
*f
, void *buf
, u32 size
);
50 int discID_close(iop_file_t
*f
);
52 // driver ops func tab
53 void *discID_ops
[17] = {
73 static iop_device_t discID_dev
= {
78 (struct _iop_device_ops
*)&discID_ops
81 iop_file_t discID_fhandle
;
82 static int discID_io_sema
= -1;
84 //--------------------------------------------------------------
85 int discID_dummy(void)
90 //--------------------------------------------------------------
91 int discID_init(iop_device_t
*dev
)
100 discID_io_sema
= CreateSema(&smp
);
105 //--------------------------------------------------------------
106 int discID_deinit(iop_device_t
*dev
)
108 DeleteSema(discID_io_sema
);
113 //--------------------------------------------------------------
114 int discID_open(iop_file_t
*f
, char *filename
, int mode
)
117 iop_file_t
*fh
= &discID_fhandle
;
122 WaitSema(discID_io_sema
);
126 memcpy(fh
, f
, sizeof(iop_file_t
));
138 SignalSema(discID_io_sema
);
143 //--------------------------------------------------------------
144 int discID_close(iop_file_t
*f
)
146 iop_file_t
*fh
= (iop_file_t
*)f
->privdata
;
148 WaitSema(discID_io_sema
);
151 memset(fh
, 0, sizeof(iop_file_t
));
156 SignalSema(discID_io_sema
);
161 //--------------------------------------------------------------
162 int discID_read(iop_file_t
*f
, void *buf
, u32 size
)
168 WaitSema(discID_io_sema
);
171 memset(discID
, 0, 16);
173 r
= sceCdGetDiskType();
174 if ((r
>= 0x12) && (r
< 0x15)) { // check it's PS2 Disc
176 sceCdReadKey(0, 0, 0x4b, key
);
179 if (CDVDreg_KEYSTATE
& 4) {
180 discID
[0] = CDVDreg_30
;
181 discID
[0] ^= CDVDreg_KEYXOR
;
182 discID
[1] = CDVDreg_31
;
183 discID
[1] ^= CDVDreg_KEYXOR
;
184 discID
[2] = CDVDreg_32
;
185 discID
[2] ^= CDVDreg_KEYXOR
;
186 discID
[3] = CDVDreg_33
;
187 discID
[3] ^= CDVDreg_KEYXOR
;
188 discID
[4] = CDVDreg_34
;
189 discID
[4] ^= CDVDreg_KEYXOR
;
191 memcpy(buf
, discID
, 5);
201 SignalSema(discID_io_sema
);
206 //-------------------------------------------------------------------------
207 int _start(int argc
, char** argv
)
210 AddDrv((iop_device_t
*)&discID_dev
);
212 return MODULE_RESIDENT_END
;
215 //-------------------------------------------------------------------------
216 DECLARE_IMPORT_TABLE(cdvdman
, 1, 1)
217 DECLARE_IMPORT(4, sceCdInit
)
218 DECLARE_IMPORT(5, sceCdStandby
)
219 DECLARE_IMPORT(11, sceCdSync
)
220 DECLARE_IMPORT(12, sceCdGetDiskType
)
221 DECLARE_IMPORT(13, sceCdDiskReady
)
222 DECLARE_IMPORT(15, sceCdStop
)
223 DECLARE_IMPORT(35, sceCdReadKey
)