Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b207ddb

Browse files
authoredDec 12, 2022
[PS2] Use ps2_drivers library for simplify frontend (#14724)
* Use ps2_drivers * improvements in frontend driver * Resetting IOP drivers before load elf
1 parent b2d73c9 commit b207ddb

File tree

6 files changed

+108
-534
lines changed

6 files changed

+108
-534
lines changed
 

‎Makefile.ps2

+2-21
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,15 @@ $(error "Please set PS2SDK in your environment. export PS2SDK=<path to>ps2sdk")
8484
endif
8585

8686
INCDIR = -I$(PS2DEV)/gsKit/include -I$(PS2SDK)/ports/include
87-
INCDIR += -Ips2/include -Ilibretro-common/include -Ideps -Ideps/stb -Ideps/7zip
87+
INCDIR += -Ilibretro-common/include -Ideps -Ideps/stb -Ideps/7zip
8888

8989
LDFLAGS += -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ports/lib -L.
9090
# Lib cdvd is needed to get proper time
91-
LIBS += -lpatches -lgskit -ldmakit -laudsrv -lmtap -lpadx -lz -lcdvd -lelf-loader -lfileXio -lpoweroff
92-
91+
LIBS += -lpatches -lgskit -ldmakit -lps2_drivers -lz -lelf-loader
9392

9493
CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) $(DEFINES) -DPS2 -ffast-math -fsingle-precision-constant
9594
ASFLAGS = $(CFLAGS)
9695

97-
# IRX libs
98-
IRX_FILES += sio2man.irx iomanX.irx fileXio.irx
99-
IRX_FILES += mcman.irx mcserv.irx
100-
IRX_FILES += usbd.irx bdm.irx bdmfs_vfat.irx usbmass_bd.irx
101-
IRX_FILES += libsd.irx audsrv.irx
102-
IRX_FILES += cdfs.irx
103-
IRX_FILES += ps2dev9.irx ps2atad.irx ps2hdd.irx ps2fs.irx poweroff.irx
104-
IRX_FILES += mtapman.irx padman.irx
105-
EE_OBJS += $(IRX_FILES:.irx=_irx.o)
106-
107-
# Missing objecst on the PS2SDK
108-
EE_OBJS += ps2/compat_files/ps2_devices.o
109-
11096
EE_OBJS += $(OBJ)
11197

11298
EE_CFLAGS = $(CFLAGS)
@@ -118,7 +104,6 @@ EE_INCS = $(INCDIR)
118104
EE_BIN = $(TARGET).elf
119105
EE_GPVAL = $(GPVAL)
120106

121-
122107
all: $(EE_BIN)
123108

124109
clean:
@@ -139,10 +124,6 @@ debug: clean all run
139124
release: all
140125
ps2-packer $(EE_BIN) $(TARGET_RELEASE)
141126

142-
# IRX files
143-
%_irx.c:
144-
$(PS2SDK)/bin/bin2c $(PS2SDK)/iop/irx/$*.irx $@ $*_irx
145-
146127
#Include preferences
147128
include $(PS2SDK)/samples/Makefile.pref
148129
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

‎Makefile.ps2.salamander

+4-17
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ ifeq ($(MUTE_WARNINGS), 1)
2020
endif
2121

2222
INCDIR = -Ilibretro-common/include
23-
INCDIR += -Ips2/include
23+
INCDIR += -I$(PS2SDK)/ports/include
2424
CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant
2525
ASFLAGS = $(CFLAGS)
2626

2727
RARCH_DEFINES += -DPS2 -DIS_SALAMANDER -DRARCH_CONSOLE
2828

2929
LIBDIR =
30-
LDFLAGS =
31-
LIBS = -lelf-loader -lpatches -lfileXio -lpoweroff
30+
LDFLAGS += -L$(PS2SDK)/ports/lib
31+
LIBS = -lelf-loader -lps2_drivers -lpatches
3232

3333
ifeq ($(SCREEN_DEBUG), 1)
3434
LIBS += -ldebug
@@ -60,16 +60,7 @@ EE_OBJS = frontend/frontend_salamander.o \
6060
libretro-common/vfs/vfs_implementation.o \
6161
libretro-common/hash/lrc_hash.o \
6262
libretro-common/time/rtime.o \
63-
verbosity.o \
64-
ps2/compat_files/ps2_devices.o
65-
66-
# IRX libs
67-
IRX_FILES += sio2man.irx iomanX.irx fileXio.irx
68-
IRX_FILES += mcman.irx mcserv.irx
69-
IRX_FILES += usbd.irx bdm.irx bdmfs_vfat.irx usbmass_bd.irx
70-
IRX_FILES += cdfs.irx
71-
IRX_FILES += ps2dev9.irx ps2atad.irx ps2hdd.irx ps2fs.irx poweroff.irx
72-
EE_OBJS += $(IRX_FILES:.irx=_irx.o)
63+
verbosity.o
7364

7465
EE_CFLAGS = $(CFLAGS)
7566
EE_CXXFLAGS = $(CFLAGS)
@@ -93,10 +84,6 @@ run:
9384
release: all
9485
ps2-packer $(EE_BIN) $(TARGET_RELEASE)
9586

96-
# IRX files
97-
%_irx.c:
98-
$(PS2SDK)/bin/bin2c $(PS2SDK)/iop/irx/$*.irx $@ $*_irx
99-
10087
#Include preferences
10188
include $(PS2SDK)/samples/Makefile.pref
10289
include $(PS2SDK)/samples/Makefile.eeglobal_cpp

‎frontend/drivers/platform_ps2.c

+102-153
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,14 @@
1616
#include <stdio.h>
1717
#include <string.h>
1818
#include <unistd.h>
19-
#include <kernel.h>
2019

2120
#include <sbv_patches.h>
2221
#include <sifrpc.h>
2322
#include <iopcontrol.h>
24-
#include <ps2_devices.h>
25-
#include <ps2_irx_variables.h>
26-
#include <loadfile.h>
2723
#include <elf-loader.h>
24+
#include <ps2_all_drivers.h>
2825
#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>
3727

3828
#if defined(SCREEN_DEBUG)
3929
#include <debug.h>
@@ -60,12 +50,15 @@
6050
#define DEFAULT_PARTITION "hdd0:__common:pfs"
6151
#endif
6252

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;
6962

7063
static void create_path_names(void)
7164
{
@@ -141,101 +134,63 @@ static void reset_IOP()
141134
sbv_patch_disable_prefix_check();
142135
}
143136

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)
154147
{
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 )
170150
{
171-
RARCH_WARN("HDD: No HardDisk Drive detected.\n");
172-
return;
151+
return false;
173152
}
174153

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 : "");
188157

189-
RARCH_LOG("HDDSUPPORT modules loaded\n");
190-
pfsModuleLoaded = 1;
158+
return true;
191159
}
192160

193-
static void load_modules()
161+
static void init_drivers(bool extra_drivers)
194162
{
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();
219172
#endif
173+
hddStatus = init_hdd_driver(false, only_if_booted_from_hdd);
220174

221175
#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+
}
229181
#endif
230182
}
231183

232-
static int mount_hdd_partition(void)
184+
static void mount_partition(void)
233185
{
234186
char mount_path[FILENAME_MAX];
235187
char new_cwd[FILENAME_MAX];
236188
int should_mount = 0;
237189
int bootDeviceID = getBootDeviceID(cwd);
238190

191+
if (hddStatus != HDD_INIT_STATUS_IRX_OK)
192+
return;
193+
239194
/* Try to mount HDD partition, either from cwd or default one */
240195
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0)
241196
{
@@ -252,18 +207,19 @@ static int mount_hdd_partition(void)
252207
#endif
253208

254209
if (!should_mount)
255-
return 0;
210+
return;
256211

257212
if (getMountInfo(mount_path, mountString, mountPoint, new_cwd) != 1)
258213
{
259214
RARCH_WARN("Partition info not readed\n");
260-
return 0;
215+
return;
261216
}
262217

263-
if (fileXioMount(mountString, mountPoint, FIO_MT_RDWR) < 0)
218+
hddMountStatus = mount_hdd_partition(mountString, mountPoint);
219+
if (hddMountStatus != HDD_MOUNT_STATUS_OK)
264220
{
265221
RARCH_WARN("Error mount mounting partition %s, %s\n", mountString, mountPoint);
266-
return 0;
222+
return;
267223
}
268224

269225
if (bootDeviceID == BOOT_DEVICE_HDD || bootDeviceID == BOOT_DEVICE_HDD0)
@@ -278,26 +234,34 @@ static int mount_hdd_partition(void)
278234
with LoadELFFromFileWithPartition */
279235
strlcpy(mountPoint, "", sizeof(mountPoint));
280236
}
281-
282-
return 1;
283237
}
284238

285-
static void prepare_for_exit(void)
239+
static void deinit_drivers(bool deinit_filesystem, bool deinit_powerOff)
286240
{
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;
292256
}
293257

294-
if (pfsModuleLoaded)
295-
fileXioDevctl("dev9x:", DDIOC_OFF, NULL, 0, NULL, 0);
258+
if (deinit_powerOff)
259+
deinit_poweroff_driver();
296260
}
297261

298262
static void poweroffHandler(void *arg)
299263
{
300-
prepare_for_exit();
264+
deinit_drivers(true, false);
301265
poweroffShutdown();
302266
}
303267

@@ -339,79 +303,64 @@ static void frontend_ps2_get_env(int *argc, char *argv[],
339303
#endif
340304
}
341305

342-
static void frontend_ps2_init(void *data)
306+
static void common_init_drivers(bool extra_drivers)
343307
{
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);
350309

351-
poweroffInit();
352310
poweroffSetCallback(&poweroffHandler, NULL);
353311

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-
373312
getcwd(cwd, sizeof(cwd));
374313
#if !defined(IS_SALAMANDER) && !defined(DEBUG)
375314
/* If it is not Salamander, we need to go one level
376315
* up for setting the CWD. */
377316
path_parent_dir(cwd, strlen(cwd));
378317
#endif
379-
if (pfsModuleLoaded)
380-
hdd_mounted = mount_hdd_partition();
318+
319+
mount_partition();
381320

382-
#if !defined(DEBUG)
383321
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");
384330
#endif
331+
common_init_drivers(true);
385332
}
386333

387334
static void frontend_ps2_deinit(void *data)
388335
{
336+
bool deinit_filesystem = false;
389337
#ifndef IS_SALAMANDER
390338
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;
402340
#endif
341+
deinit_drivers(deinit_filesystem, true);
403342
}
404343

405344
static void frontend_ps2_exec(const char *path, bool should_load_game)
406345
{
407346
int args = 0;
408-
static char *argv[1];
347+
char *argv[1];
409348
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+
410355
#ifndef IS_SALAMANDER
356+
char game_path[FILENAME_MAX];
411357
if (should_load_game && !path_is_empty(RARCH_PATH_CONTENT))
412358
{
413359
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);
415364
}
416365
#endif
417366
LoadELFFromFileWithPartition(path, mountPoint, args, argv);
@@ -469,7 +418,7 @@ static int frontend_ps2_get_rating(void) { return 10; }
469418

470419
enum frontend_architecture frontend_ps2_get_arch(void)
471420
{
472-
return FRONTEND_ARCH_MIPS;
421+
return FRONTEND_ARCH_MIPS;
473422
}
474423

475424
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)
501450
msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR),
502451
enum_idx,
503452
FILE_TYPE_DIRECTORY, 0, 0, NULL);
504-
if (hdd_mounted)
453+
if (hddMountStatus == HDD_MOUNT_STATUS_OK)
505454
{
506455
size_t _len = strlcpy(hdd, mountString, sizeof(hdd));
507456
hdd[_len ] = '/';

‎ps2/compat_files/ps2_devices.c

-204
This file was deleted.

‎ps2/include/ps2_devices.h

-52
This file was deleted.

‎ps2/include/ps2_irx_variables.h

-87
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.