3 Licenced under Academic Free License version 3.0
4 Review OpenUsbLd README & LICENSE files for further details.
7 #include "include/usbld.h"
8 #include "include/ioman.h"
9 #include "include/gui.h"
10 #include "include/renderman.h"
11 #include "include/lang.h"
12 #include "include/themes.h"
13 #include "include/textures.h"
14 #include "include/pad.h"
15 #include "include/texcache.h"
16 #include "include/dia.h"
17 #include "include/dialogs.h"
18 #include "include/menusys.h"
19 #include "include/system.h"
20 #include "include/debug.h"
21 #include "include/config.h"
23 #include "include/usbsupport.h"
24 #include "include/ethsupport.h"
25 #include "include/hddsupport.h"
26 #include "include/appsupport.h"
33 #define LOG_INIT() sio_init(38400, 0, 0, 0, 0)
34 #define LOG_ENABLE() do { } while(0)
37 #define LOG_INIT() do { } while(0)
38 #define LOG_ENABLE() ioPutRequest(IO_CUSTOM_SIMPLEACTION, &debugSetActive)
40 #define LOG_INIT() do { } while(0)
41 #define LOG_ENABLE() do { } while(0)
45 #define UPDATE_FRAME_COUNT 250
47 #define IO_MENU_UPDATE_DEFFERED 2
49 extern void *usbd_irx
;
50 extern int size_usbd_irx
;
55 /// menu item used with this list support
59 submenu_list_t
*subMenu
;
62 static void clearIOModuleT(opl_io_module_t
*mod
) {
65 mod
->menuItem
.execCross
= NULL
;
66 mod
->menuItem
.execCircle
= NULL
;
67 mod
->menuItem
.execSquare
= NULL
;
68 mod
->menuItem
.execTriangle
= NULL
;
69 mod
->menuItem
.hints
= NULL
;
70 mod
->menuItem
.icon_id
= -1;
71 mod
->menuItem
.current
= NULL
;
72 mod
->menuItem
.submenu
= NULL
;
73 mod
->menuItem
.pagestart
= NULL
;
74 mod
->menuItem
.remindLast
= 0;
75 mod
->menuItem
.refresh
= NULL
;
76 mod
->menuItem
.text
= NULL
;
77 mod
->menuItem
.text_id
= -1;
78 mod
->menuItem
.userdata
= NULL
;
82 static void moduleCleanup(opl_io_module_t
* mod
, int exception
);
85 static int gFrameCounter
;
87 static opl_io_module_t list_support
[4];
89 void moduleUpdateMenu(int mode
, int themeChanged
) {
93 opl_io_module_t
* mod
= &list_support
[mode
];
99 menuRemoveHints(&mod
->menuItem
);
101 menuAddHint(&mod
->menuItem
, _STR_SETTINGS
, START_ICON
);
102 if (!mod
->support
->enabled
)
103 menuAddHint(&mod
->menuItem
, _STR_START_DEVICE
, CROSS_ICON
);
105 if (gUseInfoScreen
&& gTheme
->infoElems
.first
)
106 menuAddHint(&mod
->menuItem
, _STR_INFO
, CROSS_ICON
);
108 menuAddHint(&mod
->menuItem
, _STR_RUN
, CROSS_ICON
);
109 if (mod
->support
->haveCompatibilityMode
)
110 menuAddHint(&mod
->menuItem
, _STR_COMPAT_SETTINGS
, TRIANGLE_ICON
);
112 if (mod
->support
->itemRename
)
113 menuAddHint(&mod
->menuItem
, _STR_RENAME
, CIRCLE_ICON
);
114 if (mod
->support
->itemDelete
)
115 menuAddHint(&mod
->menuItem
, _STR_DELETE
, SQUARE_ICON
);
121 submenuRebuildCache(mod
->subMenu
);
124 static void itemExecCross(struct menu_item
*curMenu
) {
125 item_list_t
*support
= curMenu
->userdata
;
128 if (support
->enabled
) {
129 if (curMenu
->current
) {
130 config_set_t
* configSet
= menuLoadConfig();
131 support
->itemLaunch(curMenu
->current
->item
.id
, configSet
);
136 moduleUpdateMenu(support
->mode
, 0);
138 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[support
->mode
]);
142 guiMsgBox("NULL Support object. Please report", 0, NULL
);
145 static void itemExecTriangle(struct menu_item
*curMenu
) {
146 if (!curMenu
->current
)
149 item_list_t
*support
= curMenu
->userdata
;
152 if (support
->haveCompatibilityMode
) {
153 config_set_t
* configSet
= menuLoadConfig();
154 if (guiShowCompatConfig(curMenu
->current
->item
.id
, support
, configSet
) == COMPAT_TEST
)
155 support
->itemLaunch(curMenu
->current
->item
.id
, configSet
);
159 guiMsgBox("NULL Support object. Please report", 0, NULL
);
162 static void itemExecSquare(struct menu_item
*curMenu
) {
163 if (!curMenu
->current
)
169 item_list_t
*support
= curMenu
->userdata
;
172 if (support
->itemDelete
) {
173 if (guiMsgBox(_l(_STR_DELETE_WARNING
), 1, NULL
)) {
174 support
->itemDelete(curMenu
->current
->item
.id
);
176 gFrameCounter
= UPDATE_FRAME_COUNT
;
178 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[support
->mode
]);
183 guiMsgBox("NULL Support object. Please report", 0, NULL
);
186 static void itemExecCircle(struct menu_item
*curMenu
) {
187 if (!curMenu
->current
)
193 item_list_t
*support
= curMenu
->userdata
;
196 if (support
->itemRename
) {
197 int nameLength
= support
->itemGetNameLength(curMenu
->current
->item
.id
);
198 char newName
[nameLength
];
199 strncpy(newName
, curMenu
->current
->item
.text
, nameLength
);
200 if (guiShowKeyboard(newName
, nameLength
)) {
201 support
->itemRename(curMenu
->current
->item
.id
, newName
);
203 gFrameCounter
= UPDATE_FRAME_COUNT
;
205 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[support
->mode
]);
210 guiMsgBox("NULL Support object. Please report", 0, NULL
);
213 static void itemExecRefresh(struct menu_item
*curMenu
) {
214 item_list_t
*support
= curMenu
->userdata
;
216 if (support
&& support
->enabled
)
217 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[support
->mode
]);
220 static void initMenuForListSupport(int mode
) {
221 opl_io_module_t
* item
= &list_support
[mode
];
222 item
->menuItem
.icon_id
= item
->support
->iconId
;
223 item
->menuItem
.text
= NULL
;
224 item
->menuItem
.text_id
= item
->support
->textId
;
226 item
->menuItem
.userdata
= item
->support
;
228 item
->subMenu
= NULL
;
230 item
->menuItem
.submenu
= NULL
;
231 item
->menuItem
.current
= NULL
;
232 item
->menuItem
.pagestart
= NULL
;
233 item
->menuItem
.remindLast
= 0;
235 item
->menuItem
.refresh
= &itemExecRefresh
;
236 item
->menuItem
.execCross
= &itemExecCross
;
237 item
->menuItem
.execTriangle
= &itemExecTriangle
;
238 item
->menuItem
.execSquare
= &itemExecSquare
;
239 item
->menuItem
.execCircle
= &itemExecCircle
;
241 item
->menuItem
.hints
= NULL
;
243 moduleUpdateMenu(mode
, 0);
245 struct gui_update_t
*mc
= guiOpCreate(GUI_OP_ADD_MENU
);
246 mc
->menu
.menu
= &item
->menuItem
;
247 mc
->menu
.subMenu
= &item
->subMenu
;
251 static void initSupport(item_list_t
* itemList
, int startMode
, int mode
, int force_reinit
) {
252 if (!list_support
[mode
].support
) {
253 itemList
->uip
= 1; // stop updates until we're done with init
254 list_support
[mode
].support
= itemList
;
255 initMenuForListSupport(mode
);
259 if (((force_reinit
) && (startMode
&& list_support
[mode
].support
->enabled
)) \
260 || (startMode
== 2 && !list_support
[mode
].support
->enabled
)) {
261 // stop updates until we're done with init of the device
262 list_support
[mode
].support
->uip
= 1;
263 list_support
[mode
].support
->itemInit();
264 moduleUpdateMenu(mode
, 0);
265 list_support
[mode
].support
->uip
= 0;
268 gFrameCounter
= UPDATE_FRAME_COUNT
;
270 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[mode
]);
274 static void initAllSupport(int force_reinit
) {
276 initSupport(usbGetObject(0), gUSBStartMode
, USB_MODE
, force_reinit
);
279 initSupport(ethGetObject(0), gETHStartMode
, ETH_MODE
, force_reinit
);
282 initSupport(hddGetObject(0), gHDDStartMode
, HDD_MODE
, force_reinit
);
285 initSupport(appGetObject(0), gAPPStartMode
, APP_MODE
, force_reinit
);
288 static void deinitAllSupport(int exception
) {
289 moduleCleanup(&list_support
[USB_MODE
], exception
);
290 moduleCleanup(&list_support
[ETH_MODE
], exception
);
291 moduleCleanup(&list_support
[HDD_MODE
], exception
);
292 moduleCleanup(&list_support
[APP_MODE
], exception
);
295 // ----------------------------------------------------------
296 // ----------------------- Updaters -------------------------
297 // ----------------------------------------------------------
298 static void updateMenuFromGameList(opl_io_module_t
* mdl
) {
299 // lock - gui has to be unused here
302 submenuDestroy(&mdl
->subMenu
);
303 mdl
->menuItem
.submenu
= NULL
;
304 mdl
->menuItem
.current
= NULL
;
305 mdl
->menuItem
.pagestart
= NULL
;
306 mdl
->menuItem
.remindLast
= 0;
308 // unlock, the rest is deferred
312 if (gRememberLastPlayed
)
313 configGetStr(configGetByType(CONFIG_LAST
), "last_played", &temp
);
315 // read the new game list
316 struct gui_update_t
*gup
= NULL
;
317 int count
= mdl
->support
->itemUpdate();
321 for (i
= 0; i
< count
; ++i
) {
323 gup
= guiOpCreate(GUI_OP_APPEND_MENU
);
325 gup
->menu
.menu
= &mdl
->menuItem
;
326 gup
->menu
.subMenu
= &mdl
->subMenu
;
328 gup
->submenu
.icon_id
= -1;
330 gup
->submenu
.text
= mdl
->support
->itemGetName(i
);
331 gup
->submenu
.text_id
= -1;
332 gup
->submenu
.selected
= 0;
334 if (gRememberLastPlayed
&& temp
&& strcmp(temp
, mdl
->support
->itemGetStartup(i
)) == 0)
335 gup
->submenu
.selected
= 1;
342 gup
= guiOpCreate(GUI_OP_SORT
);
343 gup
->menu
.menu
= &mdl
->menuItem
;
344 gup
->menu
.subMenu
= &mdl
->subMenu
;
349 static void menuDeferredUpdate(void* data
) {
350 opl_io_module_t
* mdl
= data
;
355 if (mdl
->support
->uip
)
358 // see if we have to update
359 if (mdl
->support
->itemNeedsUpdate()) {
360 mdl
->support
->uip
= 1;
362 updateMenuFromGameList(mdl
);
364 mdl
->support
->uip
= 0;
368 static void menuUpdateHook() {
369 // if timer exceeds some threshold, schedule updates of the available input sources
372 if (gFrameCounter
> UPDATE_FRAME_COUNT
) {
375 // schedule updates of all the list handlers
376 if (list_support
[USB_MODE
].support
&& list_support
[USB_MODE
].support
->enabled
)
377 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[USB_MODE
]);
378 if (list_support
[ETH_MODE
].support
&& list_support
[ETH_MODE
].support
->enabled
)
379 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[ETH_MODE
]);
380 if (list_support
[HDD_MODE
].support
&& list_support
[HDD_MODE
].support
->enabled
)
381 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[HDD_MODE
]);
382 if (list_support
[APP_MODE
].support
&& list_support
[APP_MODE
].support
->enabled
)
383 ioPutRequest(IO_MENU_UPDATE_DEFFERED
, &list_support
[APP_MODE
]);
387 // ----------------------------------------------------------
388 // ------------------ Configuration handling ----------------
389 // ----------------------------------------------------------
391 static int lscstatus
= CONFIG_ALL
;
392 static int lscret
= 0;
394 static int tryAlternateDevice(int types
) {
397 config_set_t
*configOPL
= configGetByType(CONFIG_OPL
);
401 if (usbFindPartition(path
, "conf_opl.cfg")) {
404 value
= configReadMulti(types
);
405 configSetInt(configOPL
, "usb_mode", 2);
411 sprintf(path
, "pfs0:conf_opl.cfg");
412 value
= fioOpen(path
, O_RDONLY
);
417 value
= configReadMulti(types
);
418 configSetInt(configOPL
, "hdd_mode", 2);
422 if (sysCheckMC() < 0) { // We don't want to get users into alternate mode for their very first of OPL (i.e no config file at all, but still want to save on MC)
423 // set config path to either mass or hdd, to prepare the saving of a new config
424 value
= fioDopen("mass0:");
428 configInit("mass0:");
439 static void _loadConfig() {
440 int result
= configReadMulti(lscstatus
);
442 if (lscstatus
& CONFIG_OPL
) {
443 int themeID
= -1, langID
= -1;
445 if (!(result
& CONFIG_OPL
)) {
446 result
= tryAlternateDevice(lscstatus
);
449 if (result
& CONFIG_OPL
) {
450 config_set_t
*configOPL
= configGetByType(CONFIG_OPL
);
453 configGetInt(configOPL
, "scrolling", &gScrollSpeed
);
454 configGetColor(configOPL
, "bg_color", gDefaultBgColor
);
455 configGetColor(configOPL
, "text_color", gDefaultTextColor
);
456 configGetColor(configOPL
, "ui_text_color", gDefaultUITextColor
);
457 configGetColor(configOPL
, "sel_text_color", gDefaultSelTextColor
);
458 configGetInt(configOPL
, "use_info_screen", &gUseInfoScreen
);
459 configGetInt(configOPL
, "enable_coverart", &gEnableArt
);
460 configGetInt(configOPL
, "wide_screen", &gWideScreen
);
462 if (configGetStr(configOPL
, "theme", &temp
))
463 themeID
= thmFindGuiID(temp
);
465 if (configGetStr(configOPL
, "language_text", &temp
))
466 langID
= lngFindGuiID(temp
);
468 if (configGetStr(configOPL
, "pc_ip", &temp
))
469 sscanf(temp
, "%d.%d.%d.%d", &pc_ip
[0], &pc_ip
[1], &pc_ip
[2], &pc_ip
[3]);
471 configGetInt(configOPL
, "pc_port", &gPCPort
);
473 if (configGetStr(configOPL
, "pc_share", &temp
))
474 strncpy(gPCShareName
, temp
, 32);
475 if (configGetStr(configOPL
, "pc_user", &temp
))
476 strncpy(gPCUserName
, temp
, 32);
477 if (configGetStr(configOPL
, "pc_pass", &temp
))
478 strncpy(gPCPassword
, temp
, 32);
479 if (configGetStr(configOPL
, "exit_path", &temp
))
480 strncpy(gExitPath
, temp
, 32);
482 configGetInt(configOPL
, "autosort", &gAutosort
);
483 configGetInt(configOPL
, "autorefresh", &gAutoRefresh
);
484 configGetInt(configOPL
, "default_device", &gDefaultDevice
);
485 configGetInt(configOPL
, "disable_debug", &gDisableDebug
);
486 configGetInt(configOPL
, "enable_delete_rename", &gEnableDandR
);
487 configGetInt(configOPL
, "hdd_spindown", &gHDDSpindown
);
488 configGetInt(configOPL
, "check_usb_frag", &gCheckUSBFragmentation
);
489 configGetInt(configOPL
, "usb_delay", &gUSBDelay
);
490 if (configGetStr(configOPL
, "usb_prefix", &temp
))
491 strncpy(gUSBPrefix
, temp
, 32);
492 configGetInt(configOPL
, "remember_last", &gRememberLastPlayed
);
493 configGetInt(configOPL
, "usb_mode", &gUSBStartMode
);
494 configGetInt(configOPL
, "hdd_mode", &gHDDStartMode
);
495 configGetInt(configOPL
, "eth_mode", &gETHStartMode
);
496 configGetInt(configOPL
, "app_mode", &gAPPStartMode
);
499 applyConfig(themeID
, langID
, gVMode
, gVSync
);
506 static void _saveConfig() {
507 if (lscstatus
& CONFIG_OPL
) {
508 config_set_t
*configOPL
= configGetByType(CONFIG_OPL
);
509 configSetInt(configOPL
, "scrolling", gScrollSpeed
);
510 configSetStr(configOPL
, "theme", thmGetValue());
511 configSetStr(configOPL
, "language_text", lngGetValue());
512 configSetColor(configOPL
, "bg_color", gDefaultBgColor
);
513 configSetColor(configOPL
, "text_color", gDefaultTextColor
);
514 configSetColor(configOPL
, "ui_text_color", gDefaultUITextColor
);
515 configSetColor(configOPL
, "sel_text_color", gDefaultSelTextColor
);
516 configSetInt(configOPL
, "use_info_screen", gUseInfoScreen
);
517 configSetInt(configOPL
, "enable_coverart", gEnableArt
);
518 configSetInt(configOPL
, "wide_screen", gWideScreen
);
521 sprintf(temp
, "%d.%d.%d.%d", pc_ip
[0], pc_ip
[1], pc_ip
[2], pc_ip
[3]);
522 configSetStr(configOPL
, "pc_ip", temp
);
523 configSetInt(configOPL
, "pc_port", gPCPort
);
524 configSetStr(configOPL
, "pc_share", gPCShareName
);
525 configSetStr(configOPL
, "pc_user", gPCUserName
);
526 configSetStr(configOPL
, "pc_pass", gPCPassword
);
527 configSetStr(configOPL
, "exit_path", gExitPath
);
528 configSetInt(configOPL
, "autosort", gAutosort
);
529 configSetInt(configOPL
, "autorefresh", gAutoRefresh
);
530 configSetInt(configOPL
, "default_device", gDefaultDevice
);
531 configSetInt(configOPL
, "disable_debug", gDisableDebug
);
532 configSetInt(configOPL
, "enable_delete_rename", gEnableDandR
);
533 configSetInt(configOPL
, "hdd_spindown", gHDDSpindown
);
534 configSetInt(configOPL
, "check_usb_frag", gCheckUSBFragmentation
);
535 configSetInt(configOPL
, "usb_delay", gUSBDelay
);
536 configSetStr(configOPL
, "usb_prefix", gUSBPrefix
);
537 configSetInt(configOPL
, "remember_last", gRememberLastPlayed
);
538 configSetInt(configOPL
, "usb_mode", gUSBStartMode
);
539 configSetInt(configOPL
, "hdd_mode", gHDDStartMode
);
540 configSetInt(configOPL
, "eth_mode", gETHStartMode
);
541 configSetInt(configOPL
, "app_mode", gAPPStartMode
);
544 lscret
= configWriteMulti(lscstatus
);
548 void applyConfig(int themeID
, int langID
, int newVMode
, int newVSync
) {
549 infotxt
= _l(_STR_WELCOME
);
551 if (gDefaultDevice
< 0 || gDefaultDevice
> APP_MODE
)
552 gDefaultDevice
= APP_MODE
;
554 guiUpdateScrollSpeed();
555 guiUpdateScreenScale();
557 // we don't want to set the vmode without a reason...
558 int changed
= (gVMode
!= newVMode
|| gVSync
!= newVSync
);
560 // reinit the graphics...
563 rmSetMode(gVSync
, gVMode
);
565 thmReloadScreenExtents();
566 guiReloadScreenExtents();
568 // also propagate to vmode cfg
569 config_set_t
* configVMode
= configGetByType(CONFIG_VMODE
);
571 configSetInt(configVMode
, "vmode", newVMode
);
572 configSetInt(configVMode
, "vsync", newVSync
);
576 // theme must be set after color, and lng after theme
577 changed
= thmSetGuiValue(themeID
, changed
);
579 lngSetGuiValue(langID
);
581 // has to be non-empty
582 if (strlen(gPCShareName
) == 0)
583 strncpy(gPCShareName
, "PS2SMB", 32);
590 moduleUpdateMenu(USB_MODE
, changed
);
591 moduleUpdateMenu(ETH_MODE
, changed
);
592 moduleUpdateMenu(HDD_MODE
, changed
);
593 moduleUpdateMenu(APP_MODE
, changed
);
596 guiSetFrameHook(&menuUpdateHook
);
598 guiSetFrameHook(NULL
);
601 int loadConfig(int types
) {
605 guiHandleDefferedIO(&lscstatus
, _l(_STR_LOADING_SETTINGS
), IO_CUSTOM_SIMPLEACTION
, &_loadConfig
);
610 int saveConfig(int types
, int showUI
) {
614 guiHandleDefferedIO(&lscstatus
, _l(_STR_SAVING_SETTINGS
), IO_CUSTOM_SIMPLEACTION
, &_saveConfig
);
618 guiMsgBox(_l(_STR_SETTINGS_SAVED
), 0, NULL
);
620 guiMsgBox(_l(_STR_ERROR_SAVING_SETTINGS
), 0, NULL
);
626 // ----------------------------------------------------------
627 // -------------------- HD SRV Support ----------------------
628 // ----------------------------------------------------------
629 extern void *ps2dev9_irx
;
630 extern int size_ps2dev9_irx
;
632 extern void *smsutils_irx
;
633 extern int size_smsutils_irx
;
635 extern void *smstcpip_irx
;
636 extern int size_smstcpip_irx
;
638 extern void *smsmap_irx
;
639 extern int size_smsmap_irx
;
641 extern void *ps2atad_irx
;
642 extern int size_ps2atad_irx
;
644 extern void *ps2hdd_irx
;
645 extern int size_ps2hdd_irx
;
647 extern void *hdldsvr_irx
;
648 extern int size_hdldsvr_irx
;
650 void loadHdldSvr(void) {
652 static char hddarg
[] = "-o" "\0" "4" "\0" "-n" "\0" "20";
653 char ipconfig
[IPCONFIG_MAX_LEN
] __attribute__((aligned(64)));
655 // block all io ops, wait for the ones still running to finish
658 deinitAllSupport(NO_EXCEPTION
);
662 sysReset(SYS_LOAD_PAD_MODULES
);
664 int iplen
= sysSetIPConfig(ipconfig
);
666 ret
= sysLoadModuleBuffer(&ps2dev9_irx
, size_ps2dev9_irx
, 0, NULL
);
670 ret
= sysLoadModuleBuffer(&smsutils_irx
, size_smsutils_irx
, 0, NULL
);
674 ret
= sysLoadModuleBuffer(&smstcpip_irx
, size_smstcpip_irx
, 0, NULL
);
678 ret
= sysLoadModuleBuffer(&smsmap_irx
, size_smsmap_irx
, iplen
, ipconfig
);
682 ret
= sysLoadModuleBuffer(&ps2atad_irx
, size_ps2atad_irx
, 0, NULL
);
686 ret
= sysLoadModuleBuffer(&ps2hdd_irx
, size_ps2hdd_irx
, sizeof(hddarg
), hddarg
);
690 ret
= sysLoadModuleBuffer(&hdldsvr_irx
, size_hdldsvr_irx
, 0, NULL
);
701 // now ready to display some status
704 void unloadHdldSvr(void) {
707 sysReset(SYS_LOAD_MC_MODULES
| SYS_LOAD_PAD_MODULES
);
714 // reinit the input pads
721 // now start io again
724 // init all supports again
728 void handleHdlSrv() {
729 guiRenderTextScreen(_l(_STR_STARTINGHDL
));
731 // prepare for hdl, display screen with info
738 guiRenderTextScreen(_l(_STR_STOPHDL
));
740 guiRenderTextScreen(_l(_STR_RUNNINGHDL
));
746 if(getKeyOn(KEY_CIRCLE
) && terminate
== 0) {
748 } else if(getKeyOn(KEY_CROSS
) && terminate
== 1) {
750 } else if (terminate
> 0)
757 guiRenderTextScreen(_l(_STR_UNLOADHDL
));
759 // restore normal functionality again
763 // ----------------------------------------------------------
764 // --------------------- Init/Deinit ------------------------
765 // ----------------------------------------------------------
766 static void reset(void) {
767 sysReset(SYS_LOAD_MC_MODULES
| SYS_LOAD_PAD_MODULES
);
774 static void moduleCleanup(opl_io_module_t
* mod
, int exception
) {
778 if (mod
->support
->itemCleanUp
)
779 mod
->support
->itemCleanUp(exception
);
782 void shutdown(int exception
) {
792 deinitAllSupport(exception
);
796 static void setDefaults(void) {
800 clearIOModuleT(&list_support
[USB_MODE
]);
801 clearIOModuleT(&list_support
[ETH_MODE
]);
802 clearIOModuleT(&list_support
[HDD_MODE
]);
803 clearIOModuleT(&list_support
[APP_MODE
]);
805 gBaseMCDir
= "mc?:OPL";
807 ps2_ip
[0] = 192; ps2_ip
[1] = 168; ps2_ip
[2] = 0; ps2_ip
[3] = 10;
808 ps2_netmask
[0] = 255; ps2_netmask
[1] = 255; ps2_netmask
[2] = 255; ps2_netmask
[3] = 0;
809 ps2_gateway
[0] = 192; ps2_gateway
[1] = 168; ps2_gateway
[2] = 0; ps2_gateway
[3] = 1;
810 pc_ip
[0] = 192;pc_ip
[1] = 168; pc_ip
[2] = 0; pc_ip
[3] = 2;
816 strncpy(gPCShareName
, "PS2SMB", 32);
817 strncpy(gPCUserName
, "GUEST", 32);
818 strncpy(gPCPassword
, "", 32);
820 // loading progress of the network and hdd. Value "6" should mean not started yet...
825 // no change to the ipconfig was done
826 gIPConfigChanged
= 0;
829 strncpy(gExitPath
, "", 32);
831 gDefaultDevice
= APP_MODE
;
834 //Default disable debug colors
837 gRememberLastPlayed
= 0;
838 gCheckUSBFragmentation
= 1;
840 strncpy(gUSBPrefix
, "", 32);
850 gDefaultBgColor
[0] = 0x028;
851 gDefaultBgColor
[1] = 0x0c5;
852 gDefaultBgColor
[2] = 0x0f9;
854 gDefaultTextColor
[0] = 0x0ff;
855 gDefaultTextColor
[1] = 0x0ff;
856 gDefaultTextColor
[2] = 0x0ff;
858 gDefaultSelTextColor
[0] = 0x0ff;
859 gDefaultSelTextColor
[1] = 0x080;
860 gDefaultSelTextColor
[2] = 0x000;
862 gDefaultUITextColor
[0] = 0x040;
863 gDefaultUITextColor
[1] = 0x080;
864 gDefaultUITextColor
[2] = 0x040;
866 gFrameCounter
= UPDATE_FRAME_COUNT
;
868 gVMode
= RM_VMODE_AUTO
;
873 config_set_t
* configVMode
= configGetByType(CONFIG_VMODE
);
876 if (configRead(configVMode
) == CONFIG_VMODE
) {
877 if (!configGetInt(configVMode
, "vsync", &gVSync
))
880 if (!configGetInt(configVMode
, "vmode", &gVMode
))
881 gVMode
= RM_VMODE_AUTO
;
885 rmInit(gVSync
, gVMode
);
888 static void init(void) {
889 // default variable values
895 // Loads the vmode config from MCs, then sets the vmode
906 // handler for deffered menu updates
907 ioRegisterHandler(IO_MENU_UPDATE_DEFFERED
, &menuDeferredUpdate
);
909 // try to restore config
915 static void deferredInit(void) {
917 // inform GUI main init part is over
918 struct gui_update_t
*id
= guiOpCreate(GUI_INIT_DONE
);
921 if (list_support
[gDefaultDevice
].support
) {
922 id
= guiOpCreate(GUI_OP_SELECT_MENU
);
923 id
->menu
.menu
= &list_support
[gDefaultDevice
].menuItem
;
928 // --------------------- Main --------------------
929 int main(int argc
, char* argv
[])
932 PREINIT_LOG("OPL GUI start!\n");
935 int use_early_debug
= 0, exception_test
= 0;
937 for (i
=1; i
<argc
; i
++) {
938 if (!(strcmp(argv
[i
], "-use-early-debug"))) {
940 PREINIT_LOG("Using early debug.\n");
942 if (!(strcmp(argv
[i
], "-test-exception"))) {
944 PREINIT_LOG("Exception test requested.\n");
949 // apply kernel patches
950 sysApplyKernelPatches();
952 // reset, load modules
956 if (use_early_debug
) {
961 if (exception_test
) {
963 u32
*p
= (u32
*)0xDEADC0DE;
970 // until this point in the code is reached, only PREINIT_LOG macro should be used
973 // queue deffered init which shuts down the intro screen later
974 ioPutRequest(IO_CUSTOM_SIMPLEACTION
, &deferredInit
);