Remove useless stuff (was thing for RTL transposition only, which will not be impleme...
[open-ps2-loader.git] / src / opl.c
blob7af0a82873e1ad97afd52ed3c72cd7714a6d30a9
1 /*
2 Copyright 2009, Volca
3 Licenced under Academic Free License version 3.0
4 Review OpenUsbLd README & LICENSE files for further details.
5 */
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"
28 // for sleep()
29 #include <unistd.h>
31 #ifdef __EESIO_DEBUG
32 #include <sio.h>
33 #define LOG_INIT() sio_init(38400, 0, 0, 0, 0)
34 #define LOG_ENABLE() do { } while(0)
35 #else
36 #ifdef __DEBUG
37 #define LOG_INIT() do { } while(0)
38 #define LOG_ENABLE() ioPutRequest(IO_CUSTOM_SIMPLEACTION, &debugSetActive)
39 #else
40 #define LOG_INIT() do { } while(0)
41 #define LOG_ENABLE() do { } while(0)
42 #endif
43 #endif
45 #define UPDATE_FRAME_COUNT 250
47 #define IO_MENU_UPDATE_DEFFERED 2
49 extern void *usbd_irx;
50 extern int size_usbd_irx;
52 typedef struct {
53 item_list_t *support;
55 /// menu item used with this list support
56 menu_item_t menuItem;
58 /// submenu list
59 submenu_list_t *subMenu;
60 } opl_io_module_t;
62 static void clearIOModuleT(opl_io_module_t *mod) {
63 mod->subMenu = NULL;
64 mod->support = NULL;
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;
81 // forward decl
82 static void moduleCleanup(opl_io_module_t* mod, int exception);
84 // frame counter
85 static int gFrameCounter;
87 static opl_io_module_t list_support[4];
89 void moduleUpdateMenu(int mode, int themeChanged) {
90 if (mode == -1)
91 return;
93 opl_io_module_t* mod = &list_support[mode];
95 if (!mod->support)
96 return;
98 // refresh Hints
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);
104 else {
105 if (gUseInfoScreen && gTheme->infoElems.first)
106 menuAddHint(&mod->menuItem, _STR_INFO, CROSS_ICON);
107 else
108 menuAddHint(&mod->menuItem, _STR_RUN, CROSS_ICON);
109 if (mod->support->haveCompatibilityMode)
110 menuAddHint(&mod->menuItem, _STR_COMPAT_SETTINGS, TRIANGLE_ICON);
111 if (gEnableDandR) {
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);
119 // refresh Cache
120 if (themeChanged)
121 submenuRebuildCache(mod->subMenu);
124 static void itemExecCross(struct menu_item *curMenu) {
125 item_list_t *support = curMenu->userdata;
127 if (support) {
128 if (support->enabled) {
129 if (curMenu->current) {
130 config_set_t* configSet = menuLoadConfig();
131 support->itemLaunch(curMenu->current->item.id, configSet);
134 else {
135 support->itemInit();
136 moduleUpdateMenu(support->mode, 0);
137 if (!gAutoRefresh)
138 ioPutRequest(IO_MENU_UPDATE_DEFFERED, &list_support[support->mode]);
141 else
142 guiMsgBox("NULL Support object. Please report", 0, NULL);
145 static void itemExecTriangle(struct menu_item *curMenu) {
146 if (!curMenu->current)
147 return;
149 item_list_t *support = curMenu->userdata;
151 if (support) {
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);
158 else
159 guiMsgBox("NULL Support object. Please report", 0, NULL);
162 static void itemExecSquare(struct menu_item *curMenu) {
163 if (!curMenu->current)
164 return;
166 if (!gEnableDandR)
167 return;
169 item_list_t *support = curMenu->userdata;
171 if (support) {
172 if (support->itemDelete) {
173 if (guiMsgBox(_l(_STR_DELETE_WARNING), 1, NULL)) {
174 support->itemDelete(curMenu->current->item.id);
175 if (gAutoRefresh)
176 gFrameCounter = UPDATE_FRAME_COUNT;
177 else
178 ioPutRequest(IO_MENU_UPDATE_DEFFERED, &list_support[support->mode]);
182 else
183 guiMsgBox("NULL Support object. Please report", 0, NULL);
186 static void itemExecCircle(struct menu_item *curMenu) {
187 if (!curMenu->current)
188 return;
190 if (!gEnableDandR)
191 return;
193 item_list_t *support = curMenu->userdata;
195 if (support) {
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);
202 if (gAutoRefresh)
203 gFrameCounter = UPDATE_FRAME_COUNT;
204 else
205 ioPutRequest(IO_MENU_UPDATE_DEFFERED, &list_support[support->mode]);
209 else
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;
248 guiDeferUpdate(mc);
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);
256 itemList->uip = 0;
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;
267 if (gAutoRefresh)
268 gFrameCounter = UPDATE_FRAME_COUNT;
269 else
270 ioPutRequest(IO_MENU_UPDATE_DEFFERED, &list_support[mode]);
274 static void initAllSupport(int force_reinit) {
275 if (gUSBStartMode)
276 initSupport(usbGetObject(0), gUSBStartMode, USB_MODE, force_reinit);
278 if (gETHStartMode)
279 initSupport(ethGetObject(0), gETHStartMode, ETH_MODE, force_reinit);
281 if (gHDDStartMode)
282 initSupport(hddGetObject(0), gHDDStartMode, HDD_MODE, force_reinit);
284 if (gAPPStartMode)
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
300 guiLock();
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
309 guiUnlock();
311 char* temp = NULL;
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();
318 if (count) {
319 int i;
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;
329 gup->submenu.id = i;
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;
337 guiDeferUpdate(gup);
341 if (gAutosort) {
342 gup = guiOpCreate(GUI_OP_SORT);
343 gup->menu.menu = &mdl->menuItem;
344 gup->menu.subMenu = &mdl->subMenu;
345 guiDeferUpdate(gup);
349 static void menuDeferredUpdate(void* data) {
350 opl_io_module_t* mdl = data;
352 if (!mdl->support)
353 return;
355 if (mdl->support->uip)
356 return;
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
370 gFrameCounter++;
372 if (gFrameCounter > UPDATE_FRAME_COUNT) {
373 gFrameCounter = 0;
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) {
395 char path[64];
396 int value;
397 config_set_t *configOPL = configGetByType(CONFIG_OPL);
399 // check USB
400 usbLoadModules();
401 if (usbFindPartition(path, "conf_opl.cfg")) {
402 configEnd();
403 configInit(path);
404 value = configReadMulti(types);
405 configSetInt(configOPL, "usb_mode", 2);
406 return value;
409 // check HDD
410 hddLoadModules();
411 sprintf(path, "pfs0:conf_opl.cfg");
412 value = fioOpen(path, O_RDONLY);
413 if(value >= 0) {
414 fioClose(value);
415 configEnd();
416 configInit("pfs0:");
417 value = configReadMulti(types);
418 configSetInt(configOPL, "hdd_mode", 2);
419 return value;
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:");
425 if (value >= 0) {
426 fioDclose(value);
427 configEnd();
428 configInit("mass0:");
430 else {
431 configEnd();
432 configInit("pfs0:");
436 return 0;
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);
451 char *temp;
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);
502 lscret = result;
503 lscstatus = 0;
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);
520 char temp[255];
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);
545 lscstatus = 0;
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);
559 if (changed) {
560 // reinit the graphics...
561 gVMode = newVMode;
562 gVSync = newVSync;
563 rmSetMode(gVSync, gVMode);
565 thmReloadScreenExtents();
566 guiReloadScreenExtents();
568 // also propagate to vmode cfg
569 config_set_t* configVMode = configGetByType(CONFIG_VMODE);
570 if (configVMode) {
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);
578 if (langID != -1)
579 lngSetGuiValue(langID);
581 // has to be non-empty
582 if (strlen(gPCShareName) == 0)
583 strncpy(gPCShareName, "PS2SMB", 32);
585 if (gPCPort < 0)
586 gPCPort = 445;
588 initAllSupport(0);
590 moduleUpdateMenu(USB_MODE, changed);
591 moduleUpdateMenu(ETH_MODE, changed);
592 moduleUpdateMenu(HDD_MODE, changed);
593 moduleUpdateMenu(APP_MODE, changed);
595 if (gAutoRefresh)
596 guiSetFrameHook(&menuUpdateHook);
597 else
598 guiSetFrameHook(NULL);
601 int loadConfig(int types) {
602 lscstatus = types;
603 lscret = 0;
605 guiHandleDefferedIO(&lscstatus, _l(_STR_LOADING_SETTINGS), IO_CUSTOM_SIMPLEACTION, &_loadConfig);
607 return lscret;
610 int saveConfig(int types, int showUI) {
611 lscstatus = types;
612 lscret = 0;
614 guiHandleDefferedIO(&lscstatus, _l(_STR_SAVING_SETTINGS), IO_CUSTOM_SIMPLEACTION, &_saveConfig);
616 if (showUI) {
617 if (lscret)
618 guiMsgBox(_l(_STR_SETTINGS_SAVED), 0, NULL);
619 else
620 guiMsgBox(_l(_STR_ERROR_SAVING_SETTINGS), 0, NULL);
623 return lscret;
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) {
651 int ret;
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
656 ioBlockOps(1);
658 deinitAllSupport(NO_EXCEPTION);
660 unloadPads();
662 sysReset(SYS_LOAD_PAD_MODULES);
664 int iplen = sysSetIPConfig(ipconfig);
666 ret = sysLoadModuleBuffer(&ps2dev9_irx, size_ps2dev9_irx, 0, NULL);
667 if (ret < 0)
668 return;
670 ret = sysLoadModuleBuffer(&smsutils_irx, size_smsutils_irx, 0, NULL);
671 if (ret < 0)
672 return;
674 ret = sysLoadModuleBuffer(&smstcpip_irx, size_smstcpip_irx, 0, NULL);
675 if (ret < 0)
676 return;
678 ret = sysLoadModuleBuffer(&smsmap_irx, size_smsmap_irx, iplen, ipconfig);
679 if (ret < 0)
680 return;
682 ret = sysLoadModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL);
683 if (ret < 0)
684 return;
686 ret = sysLoadModuleBuffer(&ps2hdd_irx, size_ps2hdd_irx, sizeof(hddarg), hddarg);
687 if (ret < 0)
688 return;
690 ret = sysLoadModuleBuffer(&hdldsvr_irx, size_hdldsvr_irx, 0, NULL);
691 if (ret < 0)
692 return;
694 padInit(0);
696 // init all pads
697 ret = 0;
698 while (!ret)
699 ret = startPads();
701 // now ready to display some status
704 void unloadHdldSvr(void) {
705 unloadPads();
707 sysReset(SYS_LOAD_MC_MODULES | SYS_LOAD_PAD_MODULES);
709 LOG_INIT();
710 LOG_ENABLE();
712 mcInit(MC_TYPE_MC);
714 // reinit the input pads
715 padInit(0);
717 int ret = 0;
718 while (!ret)
719 ret = startPads();
721 // now start io again
722 ioBlockOps(0);
724 // init all supports again
725 initAllSupport(1);
728 void handleHdlSrv() {
729 guiRenderTextScreen(_l(_STR_STARTINGHDL));
731 // prepare for hdl, display screen with info
732 loadHdldSvr();
734 int terminate = 0;
736 while (1) {
737 if (terminate != 0)
738 guiRenderTextScreen(_l(_STR_STOPHDL));
739 else
740 guiRenderTextScreen(_l(_STR_RUNNINGHDL));
742 sleep(2);
744 readPads();
746 if(getKeyOn(KEY_CIRCLE) && terminate == 0) {
747 terminate++;
748 } else if(getKeyOn(KEY_CROSS) && terminate == 1) {
749 terminate++;
750 } else if (terminate > 0)
751 terminate--;
753 if (terminate >= 2)
754 break;
757 guiRenderTextScreen(_l(_STR_UNLOADHDL));
759 // restore normal functionality again
760 unloadHdldSvr();
763 // ----------------------------------------------------------
764 // --------------------- Init/Deinit ------------------------
765 // ----------------------------------------------------------
766 static void reset(void) {
767 sysReset(SYS_LOAD_MC_MODULES | SYS_LOAD_PAD_MODULES);
769 SifInitRpc(0);
771 mcInit(MC_TYPE_MC);
774 static void moduleCleanup(opl_io_module_t* mod, int exception) {
775 if (!mod->support)
776 return;
778 if (mod->support->itemCleanUp)
779 mod->support->itemCleanUp(exception);
782 void shutdown(int exception) {
783 unloadPads();
784 ioEnd();
785 guiEnd();
786 menuEnd();
787 lngEnd();
788 thmEnd();
789 rmEnd();
790 configEnd();
792 deinitAllSupport(exception);
796 static void setDefaults(void) {
797 usbd_irx = NULL;
798 size_usbd_irx = 0;
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;
812 // SMB port on pc
813 gPCPort = 445;
815 // default values
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...
821 gNetworkStartup = 6;
822 gHddStartup = 6;
824 gHDDSpindown = 20;
825 // no change to the ipconfig was done
826 gIPConfigChanged = 0;
827 gScrollSpeed = 1;
828 //Default exit path
829 strncpy(gExitPath, "", 32);
830 // default menu
831 gDefaultDevice = APP_MODE;
832 gAutosort = 1;
833 gAutoRefresh = 1;
834 //Default disable debug colors
835 gDisableDebug = 0;
836 gEnableDandR = 0;
837 gRememberLastPlayed = 0;
838 gCheckUSBFragmentation = 1;
839 gUSBDelay = 3;
840 strncpy(gUSBPrefix, "", 32);
841 gUseInfoScreen = 0;
842 gEnableArt = 0;
843 gWideScreen = 0;
845 gUSBStartMode = 0;
846 gHDDStartMode = 0;
847 gETHStartMode = 0;
848 gAPPStartMode = 0;
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;
869 gVSync = 1;
872 void vmodeInit() {
873 config_set_t* configVMode = configGetByType(CONFIG_VMODE);
875 if (configVMode) {
876 if (configRead(configVMode) == CONFIG_VMODE) {
877 if (!configGetInt(configVMode, "vsync", &gVSync))
878 gVSync = 1;
880 if (!configGetInt(configVMode, "vmode", &gVMode))
881 gVMode = RM_VMODE_AUTO;
885 rmInit(gVSync, gVMode);
888 static void init(void) {
889 // default variable values
890 setDefaults();
892 padInit(0);
893 configInit(NULL);
895 // Loads the vmode config from MCs, then sets the vmode
896 vmodeInit();
898 lngInit();
899 thmInit();
900 guiInit();
901 ioInit();
902 menuInit();
904 startPads();
906 // handler for deffered menu updates
907 ioRegisterHandler(IO_MENU_UPDATE_DEFFERED, &menuDeferredUpdate);
909 // try to restore config
910 _loadConfig();
912 cacheInit();
915 static void deferredInit(void) {
917 // inform GUI main init part is over
918 struct gui_update_t *id = guiOpCreate(GUI_INIT_DONE);
919 guiDeferUpdate(id);
921 if (list_support[gDefaultDevice].support) {
922 id = guiOpCreate(GUI_OP_SELECT_MENU);
923 id->menu.menu = &list_support[gDefaultDevice].menuItem;
924 guiDeferUpdate(id);
928 // --------------------- Main --------------------
929 int main(int argc, char* argv[])
931 LOG_INIT();
932 PREINIT_LOG("OPL GUI start!\n");
934 #ifdef __DEBUG
935 int use_early_debug = 0, exception_test = 0;
936 int i;
937 for (i=1; i<argc; i++) {
938 if (!(strcmp(argv[i], "-use-early-debug"))) {
939 use_early_debug = 1;
940 PREINIT_LOG("Using early debug.\n");
942 if (!(strcmp(argv[i], "-test-exception"))) {
943 exception_test = 1;
944 PREINIT_LOG("Exception test requested.\n");
947 #endif
949 // apply kernel patches
950 sysApplyKernelPatches();
952 // reset, load modules
953 reset();
955 #ifdef __DEBUG
956 if (use_early_debug) {
957 configReadIP();
958 debugSetActive();
961 if (exception_test) {
962 // EXCEPTION test !
963 u32 *p = (u32 *)0xDEADC0DE;
964 *p = 0xDEFACED;
966 #endif
968 init();
970 // until this point in the code is reached, only PREINIT_LOG macro should be used
971 LOG_ENABLE();
973 // queue deffered init which shuts down the intro screen later
974 ioPutRequest(IO_CUSTOM_SIMPLEACTION, &deferredInit);
976 guiMainLoop();
978 return 0;