16
16
#include <stdio.h>
17
17
#include <string.h>
18
18
#include <unistd.h>
19
- #include <kernel.h>
20
19
21
20
#include <sbv_patches.h>
22
21
#include <sifrpc.h>
23
22
#include <iopcontrol.h>
24
- #include <ps2_devices.h>
25
- #include <ps2_irx_variables.h>
26
- #include <loadfile.h>
27
23
#include <elf-loader.h>
24
+ #include <ps2_all_drivers.h>
28
25
#include <libpwroff.h>
29
- #include <audsrv.h>
30
- #include <libmtap.h>
31
- #include <libpad.h>
32
-
33
- #define NEWLIB_PORT_AWARE
34
- #include <fileXio_rpc.h>
35
- #include <fileio.h>
36
- #include <hdd-ioctl.h>
26
+ #include <ps2sdkapi.h>
37
27
38
28
#if defined(SCREEN_DEBUG )
39
29
#include <debug.h>
60
50
#define DEFAULT_PARTITION "hdd0:__common:pfs"
61
51
#endif
62
52
63
- static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE ;
64
- static char cwd [FILENAME_MAX ] = {0 };
65
- static char mountString [10 ] = {0 };
66
- static char mountPoint [50 ] = {0 };
67
- static int hdd_mounted = 0 ;
68
- static int pfsModuleLoaded = 0 ;
53
+ // Disable pthread functionality
54
+ PS2_DISABLE_AUTOSTART_PTHREAD ();
55
+
56
+ static enum frontend_fork ps2_fork_mode = FRONTEND_FORK_NONE ;
57
+ static char cwd [FILENAME_MAX ] = {0 };
58
+ static char mountString [10 ] = {0 };
59
+ static char mountPoint [50 ] = {0 };
60
+ static enum HDD_MOUNT_STATUS hddMountStatus = HDD_MOUNT_INIT_STATUS_NOT_READY ;
61
+ static enum HDD_INIT_STATUS hddStatus = HDD_INIT_STATUS_UNKNOWN ;
69
62
70
63
static void create_path_names (void )
71
64
{
@@ -141,101 +134,63 @@ static void reset_IOP()
141
134
sbv_patch_disable_prefix_check ();
142
135
}
143
136
144
- static int hddCheck ( void )
145
- {
146
- int ret = fileXioDevctl ( "hdd0 :" , HDIOC_STATUS , NULL , 0 , NULL , 0 );
147
- /* 0 = HDD connected and formatted, 1 = not formatted, 2 = HDD not usable, 3 = HDD not connected. */
148
- if (( ret >= 3 ) || ( ret < 0 ))
149
- return -1 ;
150
- return ret ;
151
- }
152
-
153
- static void load_hdd_modules ( )
137
+ /* This method returns true if it can extract needed info from path, otherwise false.
138
+ * In case of true, it also updates mountString, mountPoint and newCWD parameters
139
+ * It splits path by " :", and requires a minimum of 3 elements
140
+ * Example: if path = hdd0:__common:pfs:/retroarch/ then
141
+ * mountString = "pfs:"
142
+ * mountPoint = "hdd0:__common"
143
+ * newCWD = pfs:/retroarch/
144
+ * return true
145
+ */
146
+ bool getMountInfo ( char * path , char * mountString , char * mountPoint , char * newCWD )
154
147
{
155
- pfsModuleLoaded = 0 ;
156
- int ret ;
157
- char hddarg [] = "-o" "\0" "4" "\0" "-n" "\0" "20" ;
158
-
159
- ret = SifExecModuleBuffer (& ps2dev9_irx , size_ps2dev9_irx , 0 , NULL , NULL );
160
-
161
- ret = SifExecModuleBuffer (& ps2atad_irx , size_ps2atad_irx , 0 , NULL , NULL );
162
- if (ret < 0 )
163
- {
164
- RARCH_WARN ("HDD: No HardDisk Drive detected.\n" );
165
- return ;
166
- }
167
-
168
- ret = SifExecModuleBuffer (& ps2hdd_irx , size_ps2hdd_irx , sizeof (hddarg ), hddarg , NULL );
169
- if (ret < 0 )
148
+ struct string_list * str_list = string_split (path , ":" );
149
+ if (str_list -> size < 3 )
170
150
{
171
- RARCH_WARN ("HDD: No HardDisk Drive detected.\n" );
172
- return ;
151
+ return false;
173
152
}
174
153
175
- /* Check if a HDD unit is connected */
176
- if (hddCheck () < 0 )
177
- {
178
- RARCH_WARN ("HDD: No HardDisk Drive detected.\n" );
179
- return ;
180
- }
181
-
182
- ret = SifExecModuleBuffer (& ps2fs_irx , size_ps2fs_irx , 0 , NULL , NULL );
183
- if (ret < 0 )
184
- {
185
- RARCH_WARN ("HDD: HardDisk Drive not formatted (PFS).\n" );
186
- return ;
187
- }
154
+ sprintf (mountPoint , "%s:%s" , str_list -> elems [0 ].data , str_list -> elems [1 ].data );
155
+ sprintf (mountString , "%s:" , str_list -> elems [2 ].data );
156
+ sprintf (newCWD , "%s%s" , mountString , str_list -> size == 4 ? str_list -> elems [3 ].data : "" );
188
157
189
- RARCH_LOG ("HDDSUPPORT modules loaded\n" );
190
- pfsModuleLoaded = 1 ;
158
+ return true;
191
159
}
192
160
193
- static void load_modules ( )
161
+ static void init_drivers ( bool extra_drivers )
194
162
{
195
- /* I/O Files */
196
- SifExecModuleBuffer (& iomanX_irx , size_iomanX_irx , 0 , NULL , NULL );
197
- SifExecModuleBuffer (& fileXio_irx , size_fileXio_irx , 0 , NULL , NULL );
198
- SifExecModuleBuffer (& sio2man_irx , size_sio2man_irx , 0 , NULL , NULL );
199
- fileXioInitSkipOverride ();
200
-
201
- /* Memory Card */
202
- SifExecModuleBuffer (& mcman_irx , size_mcman_irx , 0 , NULL , NULL );
203
- SifExecModuleBuffer (& mcserv_irx , size_mcserv_irx , 0 , NULL , NULL );
204
-
205
- /* USB */
206
- SifExecModuleBuffer (& usbd_irx , size_usbd_irx , 0 , NULL , NULL );
207
- SifExecModuleBuffer (& bdm_irx , size_bdm_irx , 0 , NULL , NULL );
208
- SifExecModuleBuffer (& bdmfs_vfat_irx , size_bdmfs_vfat_irx , 0 , NULL , NULL );
209
- SifExecModuleBuffer (& usbmass_bd_irx , size_usbmass_bd_irx , 0 , NULL , NULL );
210
-
211
- /* Power off */
212
- SifExecModuleBuffer (& poweroff_irx , size_poweroff_irx , 0 , NULL , NULL );
213
-
214
- /* HDD */
215
- load_hdd_modules ();
216
- #if !defined(DEBUG )
217
- /* CDFS */
218
- SifExecModuleBuffer (& cdfs_irx , size_cdfs_irx , 0 , NULL , NULL );
163
+ init_fileXio_driver ();
164
+ init_memcard_driver (true);
165
+ init_usb_driver ();
166
+ init_cdfs_driver ();
167
+ bool only_if_booted_from_hdd = true;
168
+ #if defined(DEBUG ) && !defined(BUILD_FOR_PCSX2 )
169
+ only_if_booted_from_hdd = false;
170
+ #else
171
+ init_poweroff_driver ();
219
172
#endif
173
+ hddStatus = init_hdd_driver (false, only_if_booted_from_hdd );
220
174
221
175
#ifndef IS_SALAMANDER
222
- /* Controllers */
223
- SifExecModuleBuffer (& mtapman_irx , size_mtapman_irx , 0 , NULL , NULL );
224
- SifExecModuleBuffer (& padman_irx , size_padman_irx , 0 , NULL , NULL );
225
-
226
- /* Audio */
227
- SifExecModuleBuffer (& libsd_irx , size_libsd_irx , 0 , NULL , NULL );
228
- SifExecModuleBuffer (& audsrv_irx , size_audsrv_irx , 0 , NULL , NULL );
176
+ if (extra_drivers )
177
+ {
178
+ init_audio_driver ();
179
+ init_joystick_driver (true);
180
+ }
229
181
#endif
230
182
}
231
183
232
- static int mount_hdd_partition (void )
184
+ static void mount_partition (void )
233
185
{
234
186
char mount_path [FILENAME_MAX ];
235
187
char new_cwd [FILENAME_MAX ];
236
188
int should_mount = 0 ;
237
189
int bootDeviceID = getBootDeviceID (cwd );
238
190
191
+ if (hddStatus != HDD_INIT_STATUS_IRX_OK )
192
+ return ;
193
+
239
194
/* Try to mount HDD partition, either from cwd or default one */
240
195
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0 )
241
196
{
@@ -252,18 +207,19 @@ static int mount_hdd_partition(void)
252
207
#endif
253
208
254
209
if (!should_mount )
255
- return 0 ;
210
+ return ;
256
211
257
212
if (getMountInfo (mount_path , mountString , mountPoint , new_cwd ) != 1 )
258
213
{
259
214
RARCH_WARN ("Partition info not readed\n" );
260
- return 0 ;
215
+ return ;
261
216
}
262
217
263
- if (fileXioMount (mountString , mountPoint , FIO_MT_RDWR ) < 0 )
218
+ hddMountStatus = mount_hdd_partition (mountString , mountPoint );
219
+ if (hddMountStatus != HDD_MOUNT_STATUS_OK )
264
220
{
265
221
RARCH_WARN ("Error mount mounting partition %s, %s\n" , mountString , mountPoint );
266
- return 0 ;
222
+ return ;
267
223
}
268
224
269
225
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0 )
@@ -278,26 +234,34 @@ static int mount_hdd_partition(void)
278
234
with LoadELFFromFileWithPartition */
279
235
strlcpy (mountPoint , "" , sizeof (mountPoint ));
280
236
}
281
-
282
- return 1 ;
283
237
}
284
238
285
- static void prepare_for_exit ( void )
239
+ static void deinit_drivers ( bool deinit_filesystem , bool deinit_powerOff )
286
240
{
287
- if (hdd_mounted )
288
- {
289
- fileXioUmount (mountString );
290
- fileXioDevctl (mountString , PDIOC_CLOSEALL , NULL , 0 , NULL , 0 );
291
- fileXioDevctl ("hdd0:" , HDIOC_IDLEIMM , NULL , 0 , NULL , 0 );
241
+ #ifndef IS_SALAMANDER
242
+ deinit_audio_driver ();
243
+ deinit_joystick_driver (false);
244
+ #endif
245
+
246
+ if (deinit_filesystem ) {
247
+ umount_hdd_partition (mountString );
248
+
249
+ deinit_hdd_driver (false);
250
+ deinit_usb_driver ();
251
+ deinit_memcard_driver (true);
252
+ deinit_fileXio_driver ();
253
+
254
+ hddMountStatus = HDD_MOUNT_INIT_STATUS_NOT_READY ;
255
+ hddStatus = HDD_INIT_STATUS_UNKNOWN ;
292
256
}
293
257
294
- if (pfsModuleLoaded )
295
- fileXioDevctl ( "dev9x:" , DDIOC_OFF , NULL , 0 , NULL , 0 );
258
+ if (deinit_powerOff )
259
+ deinit_poweroff_driver ( );
296
260
}
297
261
298
262
static void poweroffHandler (void * arg )
299
263
{
300
- prepare_for_exit ( );
264
+ deinit_drivers (true, false );
301
265
poweroffShutdown ();
302
266
}
303
267
@@ -339,79 +303,64 @@ static void frontend_ps2_get_env(int *argc, char *argv[],
339
303
#endif
340
304
}
341
305
342
- static void frontend_ps2_init ( void * data )
306
+ static void common_init_drivers ( bool extra_drivers )
343
307
{
344
- reset_IOP ();
345
- #if defined(SCREEN_DEBUG )
346
- init_scr ();
347
- scr_printf ("\n\nStarting RetroArch...\n" );
348
- #endif
349
- load_modules ();
308
+ init_drivers (true);
350
309
351
- poweroffInit ();
352
310
poweroffSetCallback (& poweroffHandler , NULL );
353
311
354
-
355
- #ifndef IS_SALAMANDER
356
- /* Initializes audsrv library */
357
- if (audsrv_init ())
358
- {
359
- RARCH_ERR ("audsrv library not initalizated\n" );
360
- }
361
-
362
- /* Initializes pad un multitap libraries */
363
- if (mtapInit () != 1 )
364
- {
365
- RARCH_ERR ("mtapInit library not initalizated\n" );
366
- }
367
- if (padInit (0 ) != 1 )
368
- {
369
- RARCH_ERR ("padInit library not initalizated\n" );
370
- }
371
- #endif
372
-
373
312
getcwd (cwd , sizeof (cwd ));
374
313
#if !defined(IS_SALAMANDER ) && !defined(DEBUG )
375
314
/* If it is not Salamander, we need to go one level
376
315
* up for setting the CWD. */
377
316
path_parent_dir (cwd , strlen (cwd ));
378
317
#endif
379
- if ( pfsModuleLoaded )
380
- hdd_mounted = mount_hdd_partition ();
318
+
319
+ mount_partition ();
381
320
382
- #if !defined(DEBUG )
383
321
waitUntilDeviceIsReady (cwd );
322
+ }
323
+
324
+ static void frontend_ps2_init (void * data )
325
+ {
326
+ reset_IOP ();
327
+ #if defined(SCREEN_DEBUG )
328
+ init_scr ();
329
+ scr_printf ("\n\nStarting RetroArch...\n" );
384
330
#endif
331
+ common_init_drivers (true);
385
332
}
386
333
387
334
static void frontend_ps2_deinit (void * data )
388
335
{
336
+ bool deinit_filesystem = false;
389
337
#ifndef IS_SALAMANDER
390
338
if (ps2_fork_mode == FRONTEND_FORK_NONE )
391
- prepare_for_exit ();
392
-
393
- if (audsrv_quit ())
394
- {
395
- RARCH_ERR ("audsrv library not deinitalizated\n" );
396
- }
397
-
398
- if (padEnd () != 1 )
399
- {
400
- RARCH_ERR ("padEnd library not deinitalizated\n" );
401
- }
339
+ deinit_filesystem = true;
402
340
#endif
341
+ deinit_drivers (deinit_filesystem , true);
403
342
}
404
343
405
344
static void frontend_ps2_exec (const char * path , bool should_load_game )
406
345
{
407
346
int args = 0 ;
408
- static char * argv [1 ];
347
+ char * argv [1 ];
409
348
RARCH_LOG ("Attempt to load executable: [%s], partition [%s].\n" , path , mountPoint );
349
+
350
+ /* Reload IOP drivers for saving IOP ram */
351
+ reset_IOP ();
352
+ common_init_drivers (false);
353
+ waitUntilDeviceIsReady (path );
354
+
410
355
#ifndef IS_SALAMANDER
356
+ char game_path [FILENAME_MAX ];
411
357
if (should_load_game && !path_is_empty (RARCH_PATH_CONTENT ))
412
358
{
413
359
args ++ ;
414
- argv [0 ] = (char * )path_get (RARCH_PATH_CONTENT );
360
+ const char * content = path_get (RARCH_PATH_CONTENT );
361
+ strlcpy (game_path , content , sizeof (game_path ));
362
+ argv [0 ] = game_path ;
363
+ RARCH_LOG ("Attempt to load executable: [%s], partition [%s] with game [%s]\n" , path , mountPoint , game_path );
415
364
}
416
365
#endif
417
366
LoadELFFromFileWithPartition (path , mountPoint , args , argv );
@@ -469,7 +418,7 @@ static int frontend_ps2_get_rating(void) { return 10; }
469
418
470
419
enum frontend_architecture frontend_ps2_get_arch (void )
471
420
{
472
- return FRONTEND_ARCH_MIPS ;
421
+ return FRONTEND_ARCH_MIPS ;
473
422
}
474
423
475
424
static int frontend_ps2_parse_drive_list (void * data , bool load_content )
@@ -501,7 +450,7 @@ static int frontend_ps2_parse_drive_list(void *data, bool load_content)
501
450
msg_hash_to_str (MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR ),
502
451
enum_idx ,
503
452
FILE_TYPE_DIRECTORY , 0 , 0 , NULL );
504
- if (hdd_mounted )
453
+ if (hddMountStatus == HDD_MOUNT_STATUS_OK )
505
454
{
506
455
size_t _len = strlcpy (hdd , mountString , sizeof (hdd ));
507
456
hdd [_len ] = '/' ;
0 commit comments