Some changes in the way the network is "reloaded".
[open-ps2-loader.git] / src / gui.c
blob78817ee17dd38ec96e48cac260701114901c1ce8
1 /*
2 Copyright 2010, 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/gui.h"
9 #include "include/renderman.h"
10 #include "include/menusys.h"
11 #include "include/fntsys.h"
12 #include "include/ioman.h"
13 #include "include/lang.h"
14 #include "include/themes.h"
15 #include "include/pad.h"
16 #include "include/util.h"
17 #include "include/config.h"
18 #include "include/system.h"
19 #include "include/ethsupport.h"
21 #include <stdlib.h>
22 #include <libvux.h>
24 static int gScheduledOps;
25 static int gCompletedOps;
26 static int gTerminate;
27 static int gInitComplete;
29 static gui_callback_t gFrameHook;
31 static s32 gSemaId;
32 static s32 gGUILockSemaId;
33 static ee_sema_t gQueueSema;
35 static int screenWidth;
36 static float wideScreenScale;
37 static int screenHeight;
39 // forward decl.
40 static void guiShow();
42 #ifdef __DEBUG
44 #include <timer.h>
46 #define CLOCKS_PER_MILISEC 147456
48 // debug version displays an FPS meter
49 static u32 curtime = 0;
50 static u32 time_since_last = 0;
51 static u32 time_render = 0;
53 #endif
55 struct gui_update_list_t {
56 struct gui_update_t* item;
57 struct gui_update_list_t* next;
60 struct gui_update_list_t *gUpdateList;
61 struct gui_update_list_t *gUpdateEnd;
63 typedef struct {
64 void (*handleInput)(void);
65 void (*renderScreen)(void);
66 short inMenu;
67 } gui_screen_handler_t;
69 static gui_screen_handler_t screenHandlers[] = {{ &menuHandleInputMain, &menuRenderMain, 0 },
70 { &menuHandleInputMenu, &menuRenderMenu, 1 },
71 { &menuHandleInputInfo, &menuRenderInfo, 1 } };
73 // default screen handler (menu screen)
74 static gui_screen_handler_t *screenHandler = &screenHandlers[GUI_SCREEN_MENU];
76 // screen transition handling
77 static gui_screen_handler_t *screenHandlerTarget = NULL;
78 static int transIndex, transMax, transitionX, transitionY;
80 // Helper perlin noise data
81 #define PLASMA_H 32
82 #define PLASMA_W 32
83 #define PLASMA_ROWS_PER_FRAME 6
84 #define FADE_SIZE 256
86 static GSTEXTURE gBackgroundTex;
87 static int pperm[512];
88 static float fadetbl[FADE_SIZE + 1];
90 static VU_VECTOR pgrad3[12] = {{ 1, 1, 0, 1 }, { -1, 1, 0, 1 }, { 1, -1, 0, 1 }, { -1, -1, 0, 1 },
91 { 1, 0, 1, 1 }, { -1, 0, 1, 1 }, { 1, 0, -1, 1 }, { -1, 0, -1, 1 },
92 { 0, 1, 1, 1 }, { 0, -1, 1, 1 }, { 0, 1, -1, 1 }, { 0, -1, -1, 1 } };
94 void guiReloadScreenExtents() {
95 rmGetScreenExtents(&screenWidth, &screenHeight);
98 void guiInit(void) {
99 guiFrameId = 0;
100 guiInactiveFrames = 0;
102 gFrameHook = NULL;
103 gTerminate = 0;
104 gInitComplete = 0;
105 gScheduledOps = 0;
106 gCompletedOps = 0;
108 gUpdateList = NULL;
109 gUpdateEnd = NULL;
111 gQueueSema.init_count = 1;
112 gQueueSema.max_count = 1;
113 gQueueSema.option = 0;
115 gSemaId = CreateSema(&gQueueSema);
116 gGUILockSemaId = CreateSema(&gQueueSema);
118 guiReloadScreenExtents();
120 // background texture - for perlin
121 gBackgroundTex.Width = PLASMA_W;
122 gBackgroundTex.Height = PLASMA_H;
123 gBackgroundTex.Mem = memalign(128, PLASMA_W * PLASMA_H * 4);
124 gBackgroundTex.PSM = GS_PSM_CT32;
125 gBackgroundTex.Filter = GS_FILTER_LINEAR;
126 gBackgroundTex.Vram = 0;
127 gBackgroundTex.VramClut = 0;
128 gBackgroundTex.Clut = NULL;
130 wideScreenScale = 1.0f;
132 // Precalculate the values for the perlin noise plasma
133 int i;
134 for (i = 0; i < 256; ++i) {
135 pperm[i] = rand() % 256;
136 pperm[i + 256] = pperm[i];
139 for (i = 0; i <= FADE_SIZE; ++i) {
140 float t = (float) (i) / FADE_SIZE;
142 fadetbl[i] = t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
146 void guiEnd() {
147 if (gBackgroundTex.Mem)
148 free(gBackgroundTex.Mem);
150 DeleteSema(gSemaId);
151 DeleteSema(gGUILockSemaId);
154 void guiLock(void) {
155 WaitSema(gGUILockSemaId);
158 void guiUnlock(void) {
159 SignalSema(gGUILockSemaId);
162 void guiStartFrame(void) {
163 #ifdef __DEBUG
164 u32 newtime = cpu_ticks() / CLOCKS_PER_MILISEC;
165 time_since_last = newtime - curtime;
166 curtime = newtime;
167 #endif
169 guiLock();
170 rmStartFrame();
171 guiFrameId++;
174 void guiEndFrame(void) {
175 guiUnlock();
176 rmFlush();
178 #ifdef __DEBUG
179 u32 newtime = cpu_ticks() / CLOCKS_PER_MILISEC;
180 time_render = newtime - curtime;
181 #endif
183 rmEndFrame();
186 void guiShowAbout() {
187 char OPLVersion[64];
188 snprintf(OPLVersion, 64, _l(_STR_OUL_VER), USBLD_VERSION);
190 #ifdef VMC
191 strcat(OPLVersion, " VMC");
192 #endif
193 #ifdef __RTL
194 strcat(OPLVersion, " RTL");
195 #endif
196 #ifdef __CHILDPROOF
197 strcat(OPLVersion, " CHILDPROOF");
198 #endif
200 diaSetLabel(diaAbout, 1, OPLVersion);
202 diaExecuteDialog(diaAbout, -1, 1, NULL);
205 void guiShowConfig() {
206 // configure the enumerations
207 const char* deviceNames[] = { _l(_STR_USB_GAMES), _l(_STR_NET_GAMES), _l(_STR_HDD_GAMES), NULL };
208 const char* deviceModes[] = { _l(_STR_OFF), _l(_STR_MANUAL), _l(_STR_AUTO), NULL };
210 diaSetEnum(diaConfig, CFG_DEFDEVICE, deviceNames);
211 diaSetEnum(diaConfig, CFG_USBMODE, deviceModes);
212 diaSetEnum(diaConfig, CFG_HDDMODE, deviceModes);
213 diaSetEnum(diaConfig, CFG_ETHMODE, deviceModes);
214 diaSetEnum(diaConfig, CFG_APPMODE, deviceModes);
216 diaSetInt(diaConfig, CFG_DEBUG, gDisableDebug);
217 diaSetString(diaConfig, CFG_EXITTO, gExitPath);
218 diaSetInt(diaConfig, CFG_DANDROP, gEnableDandR);
219 diaSetInt(diaConfig, CFG_HDDSPINDOWN, gHDDSpindown);
220 diaSetInt(diaConfig, CFG_CHECKUSBFRAG, gCheckUSBFragmentation);
221 diaSetInt(diaConfig, CFG_USBDELAY, gUSBDelay);
222 diaSetString(diaConfig, CFG_USBPREFIX, gUSBPrefix);
223 diaSetInt(diaConfig, CFG_LASTPLAYED, gRememberLastPlayed);
224 diaSetInt(diaConfig, CFG_DEFDEVICE, gDefaultDevice);
225 diaSetInt(diaConfig, CFG_USBMODE, gUSBStartMode);
226 diaSetInt(diaConfig, CFG_HDDMODE, gHDDStartMode);
227 diaSetInt(diaConfig, CFG_ETHMODE, gETHStartMode);
228 diaSetInt(diaConfig, CFG_APPMODE, gAPPStartMode);
230 int ret = diaExecuteDialog(diaConfig, -1, 1, NULL);
231 if (ret) {
232 diaGetString(diaConfig, CFG_EXITTO, gExitPath);
233 diaGetInt(diaConfig, CFG_DEBUG, &gDisableDebug);
234 diaGetInt(diaConfig, CFG_DANDROP, &gEnableDandR);
235 diaGetInt(diaConfig, CFG_HDDSPINDOWN, &gHDDSpindown);
236 diaGetInt(diaConfig, CFG_CHECKUSBFRAG, &gCheckUSBFragmentation);
237 diaGetInt(diaConfig, CFG_USBDELAY, &gUSBDelay);
238 diaGetString(diaConfig, CFG_USBPREFIX, gUSBPrefix);
239 diaGetInt(diaConfig, CFG_LASTPLAYED, &gRememberLastPlayed);
240 diaGetInt(diaConfig, CFG_DEFDEVICE, &gDefaultDevice);
241 diaGetInt(diaConfig, CFG_USBMODE, &gUSBStartMode);
242 diaGetInt(diaConfig, CFG_HDDMODE, &gHDDStartMode);
243 diaGetInt(diaConfig, CFG_ETHMODE, &gETHStartMode);
244 diaGetInt(diaConfig, CFG_APPMODE, &gAPPStartMode);
246 applyConfig(-1, -1, gVMode, gVSync);
250 static int curTheme = -1;
252 static int guiUIUpdater(int modified) {
253 if (modified) {
254 int temp;
255 diaGetInt(diaUIConfig, UICFG_THEME, &temp);
256 if (temp != curTheme) {
257 curTheme = temp;
258 if (temp == 0) {
259 diaUIConfig[32].type = UI_COLOUR; // Must be correctly set before doing the diaS/GetColor !!
260 diaUIConfig[36].type = UI_COLOUR;
261 diaUIConfig[40].type = UI_COLOUR;
262 diaUIConfig[44].type = UI_COLOUR;
263 diaSetColor(diaUIConfig, UICFG_BGCOL, gDefaultBgColor);
264 diaSetColor(diaUIConfig, UICFG_UICOL, gDefaultUITextColor);
265 diaSetColor(diaUIConfig, UICFG_TXTCOL, gDefaultTextColor);
266 diaSetColor(diaUIConfig, UICFG_SELCOL, gDefaultSelTextColor);
267 } else if (temp == thmGetGuiValue()) {
268 diaUIConfig[32].type = UI_COLOUR;
269 diaUIConfig[36].type = UI_COLOUR;
270 diaUIConfig[40].type = UI_COLOUR;
271 diaUIConfig[44].type = UI_COLOUR;
272 diaSetColor(diaUIConfig, UICFG_BGCOL, gTheme->bgColor);
273 diaSetU64Color(diaUIConfig, UICFG_UICOL, gTheme->uiTextColor);
274 diaSetU64Color(diaUIConfig, UICFG_TXTCOL, gTheme->textColor);
275 diaSetU64Color(diaUIConfig, UICFG_SELCOL, gTheme->selTextColor);
276 } else {
277 diaUIConfig[32].type = UI_SPACER;
278 diaUIConfig[36].type = UI_SPACER;
279 diaUIConfig[40].type = UI_SPACER;
280 diaUIConfig[44].type = UI_SPACER;
283 temp = !temp;
284 diaSetEnabled(diaUIConfig, UICFG_BGCOL, temp);
285 diaSetEnabled(diaUIConfig, UICFG_UICOL, temp);
286 diaSetEnabled(diaUIConfig, UICFG_TXTCOL, temp);
287 diaSetEnabled(diaUIConfig, UICFG_SELCOL, temp);
291 return 0;
294 void guiShowUIConfig() {
295 curTheme = -1;
297 // configure the enumerations
298 const char* scrollSpeeds[] = { _l(_STR_SLOW), _l(_STR_MEDIUM), _l(_STR_FAST), NULL };
299 const char* vmodeNames[] = { "AUTO", "PAL", "NTSC", NULL };
300 diaSetEnum(diaUIConfig, UICFG_SCROLL, scrollSpeeds);
301 diaSetEnum(diaUIConfig, UICFG_THEME, (const char **) thmGetGuiList());
302 diaSetEnum(diaUIConfig, UICFG_LANG, (const char **) lngGetGuiList());
303 diaSetEnum(diaUIConfig, UICFG_VMODE, vmodeNames);
305 diaSetInt(diaUIConfig, UICFG_SCROLL, gScrollSpeed);
306 diaSetInt(diaUIConfig, UICFG_THEME, thmGetGuiValue());
307 diaSetInt(diaUIConfig, UICFG_LANG, lngGetGuiValue());
308 guiUIUpdater(1);
309 diaSetInt(diaUIConfig, UICFG_AUTOSORT, gAutosort);
310 diaSetInt(diaUIConfig, UICFG_AUTOREFRESH, gAutoRefresh);
311 diaSetInt(diaUIConfig, UICFG_INFOPAGE, gUseInfoScreen);
312 diaSetInt(diaUIConfig, UICFG_COVERART, gEnableArt);
313 diaSetInt(diaUIConfig, UICFG_WIDESCREEN, gWideScreen);
314 diaSetInt(diaUIConfig, UICFG_VMODE, gVMode);
315 diaSetInt(diaUIConfig, UICFG_VSYNC, gVSync);
317 int ret = diaExecuteDialog(diaUIConfig, -1, 1, guiUIUpdater);
318 if (ret) {
319 int themeID = -1, langID = -1, newVMode = gVMode, newVSync = gVSync;
320 diaGetInt(diaUIConfig, UICFG_SCROLL, &gScrollSpeed);
321 diaGetInt(diaUIConfig, UICFG_LANG, &langID);
322 diaGetInt(diaUIConfig, UICFG_THEME, &themeID);
323 if (themeID == 0) {
324 diaGetColor(diaUIConfig, UICFG_BGCOL, gDefaultBgColor);
325 diaGetColor(diaUIConfig, UICFG_UICOL, gDefaultUITextColor);
326 diaGetColor(diaUIConfig, UICFG_TXTCOL, gDefaultTextColor);
327 diaGetColor(diaUIConfig, UICFG_SELCOL, gDefaultSelTextColor);
329 diaGetInt(diaUIConfig, UICFG_AUTOSORT, &gAutosort);
330 diaGetInt(diaUIConfig, UICFG_AUTOREFRESH, &gAutoRefresh);
331 diaGetInt(diaUIConfig, UICFG_INFOPAGE, &gUseInfoScreen);
332 diaGetInt(diaUIConfig, UICFG_COVERART, &gEnableArt);
333 diaGetInt(diaUIConfig, UICFG_WIDESCREEN, &gWideScreen);
334 diaGetInt(diaUIConfig, UICFG_VMODE, &newVMode);
335 diaGetInt(diaUIConfig, UICFG_VSYNC, &newVSync);
337 applyConfig(themeID, langID, newVMode, newVSync);
341 void guiShowIPConfig() {
342 size_t i;
343 // upload current values
344 // TODO disable elems
345 for (i = 0; i < 4; ++i) {
346 diaSetInt(diaIPConfig, 2 + i, ps2_ip[i]);
347 diaSetInt(diaIPConfig, 6 + i, ps2_netmask[i]);
348 diaSetInt(diaIPConfig, 10 + i, ps2_gateway[i]);
349 diaSetInt(diaIPConfig, 14 + i, pc_ip[i]);
352 diaSetInt(diaIPConfig, 18, gPCPort);
353 diaSetString(diaIPConfig, 19, gPCShareName);
354 diaSetString(diaIPConfig, 20, gPCUserName);
355 diaSetString(diaIPConfig, 21, gPCPassword);
357 if (gNetworkStartup == 0)
358 diaIPConfig[64].type = UI_SPACER;
359 else
360 diaIPConfig[64].type = UI_TERMINATOR;
362 int result = diaExecuteDialog(diaIPConfig, -1, 1, NULL);
363 if (result) {
364 // Store values
365 for (i = 0; i < 4; ++i) {
366 diaGetInt(diaIPConfig, 2 + i, &ps2_ip[i]);
367 diaGetInt(diaIPConfig, 6 + i, &ps2_netmask[i]);
368 diaGetInt(diaIPConfig, 10 + i, &ps2_gateway[i]);
369 diaGetInt(diaIPConfig, 14 + i, &pc_ip[i]);
372 diaGetInt(diaIPConfig, 18, &gPCPort);
373 diaGetString(diaIPConfig, 19, gPCShareName);
374 // has to be non-empty
375 if (strlen(gPCShareName) == 0)
376 strncpy(gPCShareName, "PS2SMB", 32);
377 diaGetString(diaIPConfig, 20, gPCUserName);
378 diaGetString(diaIPConfig, 21, gPCPassword);
379 gIPConfigChanged = 1;
381 if (result == NETCFG_RECONNECT)
382 gNetworkStartup = ERROR_ETH_SMB_LOGON;
384 applyConfig(-1, -1, gVMode, gVSync);
388 int guiShowKeyboard(char* value, int maxLength) {
389 char tmp[maxLength];
390 strncpy(tmp, value, maxLength);
392 int result = diaShowKeyb(tmp, maxLength);
393 if (result) {
394 strncpy(value, tmp, maxLength);
395 value[maxLength - 1] = '\0';
398 return result;
401 #ifdef VMC
402 typedef struct { // size = 76
403 int VMC_status; // 0=available, 1=busy
404 int VMC_error;
405 int VMC_progress;
406 char VMC_msg[64];
407 }statusVMCparam_t;
409 #define OPERATION_CREATE 0
410 #define OPERATION_CREATING 1
411 #define OPERATION_ABORTING 2
412 #define OPERATION_ENDING 3
413 #define OPERATION_END 4
415 static short vmc_refresh;
416 static int vmc_operation;
417 static statusVMCparam_t vmc_status;
419 int guiVmcNameHandler(char* text, int maxLen) {
420 int result = diaShowKeyb(text, maxLen);
422 if (result)
423 vmc_refresh = 1;
425 return result;
428 static int guiRefreshVMCConfig(item_list_t *support, char* name) {
429 int size = support->itemCheckVMC(name, 0);
431 if (size != -1) {
432 diaSetLabel(diaVMC, VMC_BUTTON_CREATE, _l(_STR_MODIFY));
433 diaSetLabel(diaVMC, VMC_STATUS, _l(_STR_VMC_FILE_EXISTS));
435 if (size == 8)
436 diaSetInt(diaVMC, VMC_SIZE, 0);
437 else if (size == 16)
438 diaSetInt(diaVMC, VMC_SIZE, 1);
439 else if (size == 32)
440 diaSetInt(diaVMC, VMC_SIZE, 2);
441 else if (size == 64)
442 diaSetInt(diaVMC, VMC_SIZE, 3);
443 else {
444 diaSetInt(diaVMC, VMC_SIZE, 0);
445 diaSetLabel(diaVMC, VMC_STATUS, _l(_STR_VMC_FILE_ERROR));
448 if (gEnableDandR) {
449 diaSetEnabled(diaVMC, VMC_SIZE, 1);
450 diaVMC[20].type = UI_SPLITTER;
452 else {
453 diaSetEnabled(diaVMC, VMC_SIZE, 0);
454 diaVMC[20].type = UI_TERMINATOR;
457 else {
458 diaSetLabel(diaVMC, VMC_BUTTON_CREATE, _l(_STR_CREATE));
459 diaSetLabel(diaVMC, VMC_STATUS, _l(_STR_VMC_FILE_NEW));
461 diaSetInt(diaVMC, VMC_SIZE, 0);
462 diaSetEnabled(diaVMC, VMC_SIZE, 1);
463 diaVMC[20].type = UI_TERMINATOR;
466 return size;
469 static int guiVMCUpdater(int modified) {
470 if (vmc_refresh) {
471 vmc_refresh = 0;
472 return VMC_REFRESH;
475 if ((vmc_operation == OPERATION_CREATING) || (vmc_operation == OPERATION_ABORTING)) {
476 int result = fileXioDevctl("genvmc:", 0xC0DE0003, NULL, 0, (void*) &vmc_status, sizeof(vmc_status));
477 if (result == 0) {
478 diaSetLabel(diaVMC, VMC_STATUS, vmc_status.VMC_msg);
479 diaSetInt(diaVMC, VMC_PROGRESS, vmc_status.VMC_progress);
481 if (vmc_status.VMC_error != 0)
482 LOG("genvmc updater: %d\n", vmc_status.VMC_error);
484 if (vmc_status.VMC_status == 0x00) {
485 diaSetLabel(diaVMC, VMC_BUTTON_CREATE, _l(_STR_OK));
486 vmc_operation = OPERATION_ENDING;
487 return VMC_BUTTON_CREATE;
490 else
491 LOG("status result: %d\n", result);
494 return 0;
497 static int guiShowVMCConfig(int id, item_list_t *support, char *VMCName, int slot, int validate) {
498 int result = validate ? VMC_BUTTON_CREATE : 0;
499 char vmc[32];
501 if (strlen(VMCName))
502 strncpy(vmc, VMCName, 32);
503 else {
504 if (validate)
505 return 1; // nothing to validate if no user input
507 char* startup = support->itemGetStartup(id);
508 snprintf(vmc, 32, "%s_%d", startup, slot);
511 vmc_refresh = 0;
512 vmc_operation = OPERATION_CREATE;
513 diaSetEnabled(diaVMC, VMC_NAME, 1);
514 diaSetEnabled(diaVMC, VMC_SIZE, 1);
515 diaSetInt(diaVMC, VMC_PROGRESS, 0);
517 const char* VMCSizes[] = {"8 Mb", "16 Mb", "32 Mb", "64 Mb", NULL};
518 diaSetEnum(diaVMC, VMC_SIZE, VMCSizes);
519 int size = guiRefreshVMCConfig(support, vmc);
520 diaSetString(diaVMC, VMC_NAME, vmc);
522 do {
523 if (result == VMC_BUTTON_CREATE) {
524 if (vmc_operation == OPERATION_CREATE) { // User start creation of VMC
525 int sizeUI;
526 diaGetInt(diaVMC, VMC_SIZE, &sizeUI);
527 if (sizeUI == 1)
528 sizeUI = 16;
529 else if (sizeUI == 2)
530 sizeUI = 32;
531 else if (sizeUI == 3)
532 sizeUI = 64;
533 else
534 sizeUI = 8;
536 if (sizeUI != size) {
537 support->itemCheckVMC(vmc, sizeUI);
539 diaSetEnabled(diaVMC, VMC_NAME, 0);
540 diaSetEnabled(diaVMC, VMC_SIZE, 0);
541 diaSetLabel(diaVMC, VMC_BUTTON_CREATE, _l(_STR_ABORT));
542 vmc_operation = OPERATION_CREATING;
544 else
545 break;
547 else if (vmc_operation == OPERATION_ENDING) {
548 if (validate)
549 break; // directly close VMC config dialog
551 vmc_operation = OPERATION_END;
553 else if (vmc_operation == OPERATION_END) { // User closed creation dialog of VMC
554 break;
556 else if (vmc_operation == OPERATION_CREATING) { // User canceled creation of VMC
557 fileXioDevctl("genvmc:", 0xC0DE0002, NULL, 0, NULL, 0);
558 vmc_operation = OPERATION_ABORTING;
561 else if (result == VMC_BUTTON_DELETE) {
562 if (guiMsgBox(_l(_STR_DELETE_WARNING), 1, diaVMC)) {
563 support->itemCheckVMC(vmc, -1);
564 diaSetString(diaVMC, VMC_NAME, "");
565 break;
568 else if (result == VMC_REFRESH) { // User changed the VMC name
569 diaGetString(diaVMC, VMC_NAME, vmc);
570 size = guiRefreshVMCConfig(support, vmc);
573 result = diaExecuteDialog(diaVMC, result, 1, &guiVMCUpdater);
575 if ((result == 0) && (vmc_operation == OPERATION_CREATE))
576 break;
577 } while (1);
579 return result;
582 #endif
584 int guiAltStartupNameHandler(char* text, int maxLen) {
585 int i;
587 int result = diaShowKeyb(text, maxLen);
588 if (result) {
589 for (i = 0; text[i]; i++) {
590 if (text[i] > 96 && text[i] < 123)
591 text[i] -= 32;
595 return result;
598 int guiShowCompatConfig(int id, item_list_t *support, config_set_t* configSet) {
599 int dmaMode = 7; // defaulting to UDMA 4
600 if (support->haveCompatibilityMode == COMPAT_FULL) {
601 configGetInt(configSet, CONFIG_ITEM_DMA, &dmaMode);
602 const char* dmaModes[] = { "MDMA 0", "MDMA 1", "MDMA 2", "UDMA 0", "UDMA 1", "UDMA 2", "UDMA 3", "UDMA 4", "UDMA 5", "UDMA 6", NULL };
603 diaSetEnum(diaCompatConfig, COMPAT_MODE_BASE + COMPAT_MODE_COUNT, dmaModes);
604 diaSetInt(diaCompatConfig, COMPAT_MODE_BASE + COMPAT_MODE_COUNT, dmaMode);
605 } else {
606 const char* dmaModes[] = { NULL };
607 diaSetEnum(diaCompatConfig, COMPAT_MODE_BASE + COMPAT_MODE_COUNT, dmaModes);
608 diaSetInt(diaCompatConfig, COMPAT_MODE_BASE + COMPAT_MODE_COUNT, 0);
611 diaSetLabel(diaCompatConfig, COMPAT_GAME, support->itemGetName(id));
613 int compatMode = 0;
614 configGetInt(configSet, CONFIG_ITEM_COMPAT, &compatMode);
615 int i, result = -1;
616 for (i = 0; i < COMPAT_MODE_COUNT; ++i)
617 diaSetInt(diaCompatConfig, COMPAT_MODE_BASE + i, (compatMode & (1 << i)) > 0 ? 1 : 0);
619 // Find out the current game ID
620 char hexid[32];
621 configGetStrCopy(configSet, CONFIG_ITEM_DNAS, hexid);
622 diaSetString(diaCompatConfig, COMPAT_GAMEID, hexid);
624 char altStartup[32];
625 configGetStrCopy(configSet, CONFIG_ITEM_ALTSTARTUP, altStartup);
626 diaSetString(diaCompatConfig, COMPAT_ALTSTARTUP, altStartup);
628 #ifdef VMC
629 char vmc1[32];
630 configGetVMC(configSet, vmc1, 0);
631 diaSetLabel(diaCompatConfig, COMPAT_VMC1_DEFINE, vmc1);
633 char vmc2[32]; // required as diaSetLabel use pointer to value
634 configGetVMC(configSet, vmc2, 1);
635 diaSetLabel(diaCompatConfig, COMPAT_VMC2_DEFINE, vmc2);
636 #endif
638 // show dialog
639 do {
640 #ifdef VMC
641 if (strlen(vmc1))
642 diaSetLabel(diaCompatConfig, COMPAT_VMC1_ACTION, _l(_STR_RESET));
643 else
644 diaSetLabel(diaCompatConfig, COMPAT_VMC1_ACTION, _l(_STR_USE_GENERIC));
645 if (strlen(vmc2))
646 diaSetLabel(diaCompatConfig, COMPAT_VMC2_ACTION, _l(_STR_RESET));
647 else
648 diaSetLabel(diaCompatConfig, COMPAT_VMC2_ACTION, _l(_STR_USE_GENERIC));
649 #endif
651 result = diaExecuteDialog(diaCompatConfig, result, 1, NULL);
653 if (result == COMPAT_LOADFROMDISC) {
654 char hexDiscID[15];
655 if (sysGetDiscID(hexDiscID) >= 0)
656 diaSetString(diaCompatConfig, COMPAT_GAMEID, hexDiscID);
657 else
658 guiMsgBox(_l(_STR_ERROR_LOADING_ID), 0, NULL);
660 #ifdef VMC
661 else if (result == COMPAT_VMC1_DEFINE) {
662 if(guiShowVMCConfig(id, support, vmc1, 0, 0))
663 diaGetString(diaVMC, VMC_NAME, vmc1);
664 } else if (result == COMPAT_VMC2_DEFINE) {
665 if(guiShowVMCConfig(id, support, vmc2, 1, 0))
666 diaGetString(diaVMC, VMC_NAME, vmc2);
667 } else if (result == COMPAT_VMC1_ACTION) {
668 if (strlen(vmc1))
669 vmc1[0] = '\0';
670 else
671 snprintf(vmc1, 32, "generic_%d", 0);
672 } else if (result == COMPAT_VMC2_ACTION) {
673 if (strlen(vmc2))
674 vmc2[0] = '\0';
675 else
676 snprintf(vmc2, 32, "generic_%d", 1);
678 #endif
679 } while (result >= COMPAT_NOEXIT);
681 if (result == COMPAT_REMOVE) {
682 configRemoveKey(configSet, CONFIG_ITEM_DMA);
683 configRemoveKey(configSet, CONFIG_ITEM_COMPAT);
684 configRemoveKey(configSet, CONFIG_ITEM_DNAS);
685 configRemoveKey(configSet, CONFIG_ITEM_ALTSTARTUP);
686 #ifdef VMC
687 configRemoveVMC(configSet, 0);
688 configRemoveVMC(configSet, 1);
689 #endif
690 menuSaveConfig();
691 } else if (result > 0) { // test button pressed or save button
692 compatMode = 0;
693 for (i = 0; i < COMPAT_MODE_COUNT; ++i) {
694 int mdpart;
695 diaGetInt(diaCompatConfig, COMPAT_MODE_BASE + i, &mdpart);
696 compatMode |= (mdpart ? 1 : 0) << i;
699 if (support->haveCompatibilityMode == COMPAT_FULL) {
700 diaGetInt(diaCompatConfig, COMPAT_MODE_BASE + COMPAT_MODE_COUNT, &dmaMode);
701 if (dmaMode != 7)
702 configSetInt(configSet, CONFIG_ITEM_DMA, dmaMode);
703 else
704 configRemoveKey(configSet, CONFIG_ITEM_DMA);
707 if (compatMode != 0)
708 configSetInt(configSet, CONFIG_ITEM_COMPAT, compatMode);
709 else
710 configRemoveKey(configSet, CONFIG_ITEM_COMPAT);
712 diaGetString(diaCompatConfig, COMPAT_GAMEID, hexid);
713 if (hexid[0] != '\0')
714 configSetStr(configSet, CONFIG_ITEM_DNAS, hexid);
716 diaGetString(diaCompatConfig, COMPAT_ALTSTARTUP, altStartup);
717 if (altStartup[0] != '\0')
718 configSetStr(configSet, CONFIG_ITEM_ALTSTARTUP, altStartup);
719 else
720 configRemoveKey(configSet, CONFIG_ITEM_ALTSTARTUP);
722 #ifdef VMC
723 configSetVMC(configSet, vmc1, 0);
724 configSetVMC(configSet, vmc2, 1);
725 guiShowVMCConfig(id, support, vmc1, 0, 1);
726 guiShowVMCConfig(id, support, vmc2, 1, 1);
727 #endif
729 if (result == COMPAT_SAVE)
730 menuSaveConfig();
733 return result;
736 int guiGetOpCompleted(int opid) {
737 return gCompletedOps > opid;
740 int guiDeferUpdate(struct gui_update_t *op) {
741 WaitSema(gSemaId);
743 struct gui_update_list_t* up = (struct gui_update_list_t*) malloc(sizeof(struct gui_update_list_t));
744 up->item = op;
745 up->next = NULL;
747 if (!gUpdateList) {
748 gUpdateList = up;
749 gUpdateEnd = gUpdateList;
750 } else {
751 gUpdateEnd->next = up;
752 gUpdateEnd = up;
755 SignalSema(gSemaId);
757 return gScheduledOps++;
760 static void guiHandleOp(struct gui_update_t* item) {
761 submenu_list_t* result = NULL;
763 switch (item->type) {
764 case GUI_INIT_DONE:
765 gInitComplete = 1;
766 break;
768 case GUI_OP_ADD_MENU:
769 menuAppendItem(item->menu.menu);
770 break;
772 case GUI_OP_APPEND_MENU:
773 result = submenuAppendItem(item->menu.subMenu, item->submenu.icon_id,
774 item->submenu.text, item->submenu.id, item->submenu.text_id);
776 if (!item->menu.menu->submenu) { // first subitem in list
777 item->menu.menu->submenu = result;
778 item->menu.menu->current = result;
779 item->menu.menu->pagestart = result;
780 } else if (item->submenu.selected) { // remember last game feat.
781 item->menu.menu->current = result;
782 item->menu.menu->pagestart = result;
783 item->menu.menu->remindLast = 1;
786 break;
788 case GUI_OP_SELECT_MENU:
789 menuSetSelectedItem(item->menu.menu);
790 screenHandler = &screenHandlers[GUI_SCREEN_MAIN];
791 break;
793 case GUI_OP_CLEAR_SUBMENU:
794 submenuDestroy(item->menu.subMenu);
795 item->menu.menu->submenu = NULL;
796 item->menu.menu->current = NULL;
797 item->menu.menu->pagestart = NULL;
798 break;
800 case GUI_OP_SORT:
801 submenuSort(item->menu.subMenu);
802 item->menu.menu->submenu = *item->menu.subMenu;
804 if (!item->menu.menu->remindLast)
805 item->menu.menu->current = item->menu.menu->submenu;
807 item->menu.menu->pagestart = item->menu.menu->current;
808 break;
810 case GUI_OP_ADD_HINT:
811 // append the hint list in the menu item
812 menuAddHint(item->menu.menu, item->hint.text_id, item->hint.icon_id);
813 break;
815 default:
816 LOG("GUI: ??? (%d)\n", item->type);
820 static void guiHandleDeferredOps(void) {
821 // TODO: Fit into the given time interval, skip rest of operations of over limit
823 while (gUpdateList) {
824 WaitSema(gSemaId);
826 guiHandleOp(gUpdateList->item);
828 struct gui_update_list_t* td = gUpdateList;
829 gUpdateList = gUpdateList->next;
831 free(td);
833 gCompletedOps++;
835 SignalSema(gSemaId);
838 gUpdateEnd = NULL;
841 static int bfadeout = 0x0;
842 static void guiDrawBusy() {
843 if (gTheme->loadingIcon) {
844 GSTEXTURE* texture = thmGetTexture(LOAD0_ICON + guiFrameId % gTheme->loadingIconCount);
845 if (texture && texture->Mem) {
846 u64 mycolor = GS_SETREG_RGBA(0x080, 0x080, 0x080, bfadeout);
847 rmDrawPixmap(texture, gTheme->loadingIcon->posX, gTheme->loadingIcon->posY, gTheme->loadingIcon->aligned, gTheme->loadingIcon->width, gTheme->loadingIcon->height, gTheme->loadingIcon->scaled, mycolor);
852 static int wfadeout = 0x0150;
853 static void guiRenderGreeting() {
854 int fade = wfadeout > 0xFF ? 0xFF : wfadeout;
855 u64 mycolor = GS_SETREG_RGBA(0x10, 0x10, 0x10, fade >> 1);
856 rmDrawRect(0, 0, screenWidth, screenHeight, mycolor);
858 GSTEXTURE* logo = thmGetTexture(LOGO_PICTURE);
859 if (logo) {
860 mycolor = GS_SETREG_RGBA(0x080, 0x080, 0x080, fade >> 1);
861 rmDrawPixmap(logo, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, logo->Width, logo->Height, SCALING_RATIO, mycolor);
864 return;
867 static float mix(float a, float b, float t) {
868 return (1.0 - t) * a + t * b;
871 static float fade(float t) {
872 return fadetbl[(int) (t * FADE_SIZE)];
875 // The same as mix, but with 8 (2*4) values mixed at once
876 static void VU0MixVec(VU_VECTOR *a, VU_VECTOR *b, float mix, VU_VECTOR* res) {
877 asm (
878 "lqc2 vf1, 0(%0)\n" // load the first vector
879 "lqc2 vf2, 0(%1)\n" // load the second vector
880 "lw $2, 0(%2)\n" // load value from ptr to reg
881 "qmtc2 $2, vf3\n" // load the mix value from reg to VU
882 "vaddw.x vf5, vf00, vf00\n" // vf5.x = 1
883 "vsub.x vf4x, vf5x, vf3x\n" // subtract 1 - vf3,x, store the result in vf4.x
884 "vmulax.xyzw ACC, vf1, vf3x\n" // multiply vf1 by vf3.x, store the result in ACC
885 "vmaddx.xyzw vf1, vf2, vf4x\n" // multiply vf2 by vf4.x add ACC, store the result in vf1
886 "sqc2 vf1, 0(%3)\n" // transfer the result in acc to the ee
887 : : "r" (a), "r" (b), "r" (&mix), "r" (res)
891 static float guiCalcPerlin(float x, float y, float z) {
892 // Taken from: http://people.opera.com/patrickl/experiments/canvas/plasma/perlin-noise-classical.js
893 // By Sean McCullough
895 // Find unit grid cell containing point
896 int X = floor(x);
897 int Y = floor(y);
898 int Z = floor(z);
900 // Get relative xyz coordinates of point within that cell
901 x = x - X;
902 y = y - Y;
903 z = z - Z;
905 // Wrap the integer cells at 255 (smaller integer period can be introduced here)
906 X = X & 255;
907 Y = Y & 255;
908 Z = Z & 255;
910 // Calculate a set of eight hashed gradient indices
911 int gi000 = pperm[X + pperm[Y + pperm[Z]]] % 12;
912 int gi001 = pperm[X + pperm[Y + pperm[Z + 1]]] % 12;
913 int gi010 = pperm[X + pperm[Y + 1 + pperm[Z]]] % 12;
914 int gi011 = pperm[X + pperm[Y + 1 + pperm[Z + 1]]] % 12;
915 int gi100 = pperm[X + 1 + pperm[Y + pperm[Z]]] % 12;
916 int gi101 = pperm[X + 1 + pperm[Y + pperm[Z + 1]]] % 12;
917 int gi110 = pperm[X + 1 + pperm[Y + 1 + pperm[Z]]] % 12;
918 int gi111 = pperm[X + 1 + pperm[Y + 1 + pperm[Z + 1]]] % 12;
920 // The gradients of each corner are now:
921 // g000 = grad3[gi000];
922 // g001 = grad3[gi001];
923 // g010 = grad3[gi010];
924 // g011 = grad3[gi011];
925 // g100 = grad3[gi100];
926 // g101 = grad3[gi101];
927 // g110 = grad3[gi110];
928 // g111 = grad3[gi111];
929 // Calculate noise contributions from each of the eight corners
930 VU_VECTOR vec;
931 vec.x = x;
932 vec.y = y;
933 vec.z = z;
934 vec.w = 1;
936 VU_VECTOR a, b;
938 // float n000
939 a.x = Vu0DotProduct(&pgrad3[gi000], &vec);
941 vec.y -= 1;
943 // float n010
944 a.z = Vu0DotProduct(&pgrad3[gi010], &vec);
946 vec.x -= 1;
948 //float n110
949 b.z = Vu0DotProduct(&pgrad3[gi110], &vec);
951 vec.y += 1;
953 // float n100
954 b.x = Vu0DotProduct(&pgrad3[gi100], &vec);
956 vec.z -= 1;
958 // float n101
959 b.y = Vu0DotProduct(&pgrad3[gi101], &vec);
961 vec.y -= 1;
963 // float n111
964 b.w = Vu0DotProduct(&pgrad3[gi111], &vec);
966 vec.x += 1;
968 // float n011
969 a.w = Vu0DotProduct(&pgrad3[gi011], &vec);
971 vec.y += 1;
973 // float n001
974 a.y = Vu0DotProduct(&pgrad3[gi001], &vec);
976 // Compute the fade curve value for each of x, y, z
977 float u = fade(x);
978 float v = fade(y);
979 float w = fade(z);
981 // TODO: Low priority... This could be done on VU0 (xyzw for the first 4 mixes)
982 // The result in sw
983 // Interpolate along x the contributions from each of the corners
984 VU_VECTOR rv;
985 VU0MixVec(&b, &a, u, &rv);
987 // TODO: The VU0MixVec could as well mix the results (as follows) - might improve performance...
988 // Interpolate the four results along y
989 float nxy0 = mix(rv.x, rv.z, v);
990 float nxy1 = mix(rv.y, rv.w, v);
991 // Interpolate the two last results along z
992 float nxyz = mix(nxy0, nxy1, w);
994 return nxyz;
997 static float dir = 0.02;
998 static float perz = -100;
999 static int pery = 0;
1000 static unsigned char curbgColor[3] = { 0, 0, 0 };
1002 static int cdirection(unsigned char a, unsigned char b) {
1003 if (a == b)
1004 return 0;
1005 else if (a > b)
1006 return -1;
1007 else
1008 return 1;
1011 void guiDrawBGPlasma() {
1012 int x, y;
1014 // transition the colors
1015 curbgColor[0] += cdirection(curbgColor[0], gTheme->bgColor[0]);
1016 curbgColor[1] += cdirection(curbgColor[1], gTheme->bgColor[1]);
1017 curbgColor[2] += cdirection(curbgColor[2], gTheme->bgColor[2]);
1019 // it's PLASMA_ROWS_PER_FRAME rows a frame to stop being a resource hog
1020 if (pery >= PLASMA_H) {
1021 pery = 0;
1022 perz += dir;
1024 if (perz > 100.0f || perz < -100.0f)
1025 dir = -dir;
1028 u32 *buf = gBackgroundTex.Mem + PLASMA_W * pery;
1029 int ymax = pery + PLASMA_ROWS_PER_FRAME;
1031 if (ymax > PLASMA_H)
1032 ymax = PLASMA_H;
1034 for (y = pery; y < ymax; y++) {
1035 for (x = 0; x < PLASMA_W; x++) {
1036 u32 fper = guiCalcPerlin((float) (2 * x) / PLASMA_W, (float) (2 * y) / PLASMA_H, perz) * 0x080 + 0x080;
1038 *buf = GS_SETREG_RGBA(
1039 (u32)(fper * curbgColor[0]) >> 8,
1040 (u32)(fper * curbgColor[1]) >> 8,
1041 (u32)(fper * curbgColor[2]) >> 8,
1042 0x080);
1044 ++buf;
1049 pery = ymax;
1050 rmDrawPixmap(&gBackgroundTex, 0, 0, ALIGN_NONE, screenWidth, screenHeight, SCALING_NONE, gDefaultCol);
1053 int guiDrawIconAndText(int iconId, int textId, int font, int x, int y, u64 color) {
1054 GSTEXTURE* iconTex = thmGetTexture(iconId);
1055 if (iconTex && iconTex->Mem) {
1056 rmDrawPixmap(iconTex, x, y, ALIGN_NONE, iconTex->Width, iconTex->Height, SCALING_RATIO, gDefaultCol);
1057 x += iconTex->Width + 2;
1060 x = fntRenderString(font, x, y, ALIGN_NONE, 0, 0, _l(textId), color);
1062 return x;
1065 static void guiDrawOverlays() {
1066 // are there any pending operations?
1067 int pending = ioHasPendingRequests();
1069 if (!pending) {
1070 if (bfadeout > 0x0)
1071 bfadeout -= 0x08;
1072 else
1073 bfadeout = 0x0;
1074 } else {
1075 if (bfadeout < 0x080)
1076 bfadeout += 0x20;
1079 if (bfadeout > 0)
1080 guiDrawBusy();
1082 #ifdef __DEBUG
1083 // fps meter
1084 char fps[20];
1086 if (time_since_last != 0)
1087 snprintf(fps, 20, "%3d ms %3.1f FPS", time_render, 1000.0f / (float) time_since_last);
1088 else
1089 snprintf(fps, 20, "%3d ms ----- FPS", time_render);
1091 fntRenderString(FNT_DEFAULT, screenWidth - 90, 30, ALIGN_CENTER, 0, 0, fps, GS_SETREG_RGBA(0x060, 0x060, 0x060, 0x060));
1092 #endif
1095 static void guiReadPads() {
1096 if (readPads())
1097 guiInactiveFrames = 0;
1098 else
1099 guiInactiveFrames++;
1102 // renders the screen and handles inputs. Also handles screen transitions between numerous
1103 // screen handlers. For now we only have left-to right screen transition
1104 static void guiShow() {
1105 // is there a transmission effect going on or are
1106 // we in a normal rendering state?
1107 if (screenHandlerTarget) {
1108 // advance the effect
1110 // render the old screen, transposed
1111 rmSetTransposition(transIndex * transitionX, transIndex * transitionY);
1112 screenHandler->renderScreen();
1114 // render new screen transposed again
1115 rmSetTransposition((transIndex - transMax) * transitionX, (transIndex - transMax) * transitionY);
1116 screenHandlerTarget->renderScreen();
1118 // reset transposition to zero
1119 rmSetTransposition(0, 0);
1121 // move the transition indicator forward
1122 transIndex += (min(transIndex, transMax - transIndex) >> 1) + 1;
1124 if (transIndex > transMax) {
1125 transitionX = 0;
1126 transitionY = 0;
1127 screenHandler = screenHandlerTarget;
1128 screenHandlerTarget = NULL;
1130 } else
1131 // render with the set screen handler
1132 screenHandler->renderScreen();
1135 void guiIntroLoop(void) {
1136 int endIntro = 0;
1137 while (!endIntro) {
1138 guiStartFrame();
1140 guiReadPads();
1142 if (wfadeout < 0x0FF)
1143 guiShow();
1145 if (gInitComplete)
1146 wfadeout--;
1148 if (wfadeout > 0)
1149 guiRenderGreeting();
1150 else
1151 endIntro = 1;
1153 guiHandleDeferredOps();
1155 guiEndFrame();
1157 if (!screenHandlerTarget && screenHandler)
1158 screenHandler->handleInput();
1162 void guiMainLoop(void) {
1163 while (!gTerminate) {
1164 guiStartFrame();
1166 // Read the pad states to prepare for input processing in the screen handler
1167 guiReadPads();
1169 // handle inputs and render screen
1170 guiShow();
1172 // Render overlaying gui thingies :)
1173 guiDrawOverlays();
1175 // handle deferred operations
1176 guiHandleDeferredOps();
1178 guiEndFrame();
1180 if (gFrameHook)
1181 gFrameHook();
1183 // if not transiting, handle input
1184 // done here so we can use renderman if needed
1185 if (!screenHandlerTarget && screenHandler)
1186 screenHandler->handleInput();
1190 void guiSetFrameHook(gui_callback_t cback) {
1191 gFrameHook = cback;
1194 void guiSwitchScreen(int target, int transition) {
1195 if (transition == TRANSITION_LEFT) {
1196 transitionX = 1;
1197 transMax = screenWidth;
1198 } else if (transition == TRANSITION_RIGHT) {
1199 transitionX = -1;
1200 transMax = screenWidth;
1201 } else if (transition == TRANSITION_UP) {
1202 transitionY = 1;
1203 transMax = screenHeight;
1204 } else if (transition == TRANSITION_DOWN) {
1205 transitionY = -1;
1206 transMax = screenHeight;
1208 transIndex = 0;
1210 screenHandlerTarget = &screenHandlers[target];
1213 struct gui_update_t *guiOpCreate(gui_op_type_t type) {
1214 struct gui_update_t *op = (struct gui_update_t *) malloc(sizeof(struct gui_update_t));
1215 memset(op, 0, sizeof(struct gui_update_t));
1216 op->type = type;
1217 return op;
1220 void guiUpdateScrollSpeed(void) {
1221 // sanitize the settings
1222 if ((gScrollSpeed < 0) || (gScrollSpeed > 2))
1223 gScrollSpeed = 1;
1225 // update the pad delays for KEY_UP and KEY_DOWN
1226 // default delay is 7
1227 // fast - 100 ms
1228 // medium - 300 ms
1229 // slow - 500 ms
1230 setButtonDelay(KEY_UP, 500 - gScrollSpeed * 200); // 0,1,2 -> 500, 300, 100
1231 setButtonDelay(KEY_DOWN, 500 - gScrollSpeed * 200);
1234 void guiUpdateScreenScale(void) {
1235 if (gWideScreen)
1236 wideScreenScale = 0.75f;
1237 else
1238 wideScreenScale = 1.0f;
1240 // apply the scaling to renderman and font rendering
1241 rmSetAspectRatio(wideScreenScale, 1.0f);
1242 fntSetAspectRatio(wideScreenScale, 1.0f);
1245 int guiMsgBox(const char* text, int addAccept, struct UIItem *ui) {
1246 int terminate = 0;
1247 while (!terminate) {
1248 guiStartFrame();
1250 readPads();
1252 if (getKeyOn(KEY_CIRCLE))
1253 terminate = 1;
1254 else if (getKeyOn(KEY_CROSS))
1255 terminate = 2;
1257 if (ui)
1258 diaRenderUI(ui, screenHandler->inMenu, NULL, 0);
1259 else
1260 guiShow();
1262 rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
1264 rmDrawLine(50, 75, screenWidth - 50, 75, gColWhite);
1265 rmDrawLine(50, 410, screenWidth - 50, 410, gColWhite);
1267 fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, text, gTheme->textColor);
1268 guiDrawIconAndText(CIRCLE_ICON, _STR_O_BACK, FNT_DEFAULT, 500, 417, gTheme->selTextColor);
1269 if (addAccept)
1270 guiDrawIconAndText(CROSS_ICON, _STR_X_ACCEPT, FNT_DEFAULT, 70, 417, gTheme->selTextColor);
1272 guiEndFrame();
1275 return terminate - 1;
1278 void guiHandleDeferedIO(int *ptr, const unsigned char* message, int type, void *data) {
1279 ioPutRequest(type, data);
1281 while (*ptr)
1282 guiRenderTextScreen(message);
1285 void guiRenderTextScreen(const unsigned char* message) {
1286 guiStartFrame();
1288 guiShow();
1290 rmDrawRect(0, 0, screenWidth, screenHeight, gColDarker);
1292 fntRenderString(FNT_DEFAULT, screenWidth >> 1, gTheme->usedHeight >> 1, ALIGN_CENTER, 0, 0, message, gTheme->textColor);
1294 guiDrawOverlays();
1296 guiEndFrame();