-
Notifications
You must be signed in to change notification settings - Fork 2
/
menu.cpp
672 lines (617 loc) · 21.5 KB
/
menu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include <stdio.h>
#include <string.h>
#include "FrensHelpers.h"
#include <pico.h>
#include <memory>
#include "pico/stdlib.h"
#include "hardware/flash.h"
#include <dvi/dvi.h>
#include <util/exclusive_proc.h>
#include <gamepad.h>
#include "hardware/watchdog.h"
#include "RomLister.h"
#include "menu.h"
#include "nespad.h"
#include "wiipad.h"
#include "shared.h"
#include "font_8x8.h"
#define FONT_CHAR_WIDTH 8
#define FONT_CHAR_HEIGHT 8
#define FONT_N_CHARS 95
#define FONT_FIRST_ASCII 32
#define SCREEN_COLS 32
#define SCREEN_ROWS 29
#define STARTROW 3
#define ENDROW 24
#define PAGESIZE (ENDROW - STARTROW + 1)
#define VISIBLEPATHSIZE (SCREEN_COLS - 3)
extern util::ExclusiveProc exclProc_;
extern std::unique_ptr<dvi::DVI> dvi_;
void screenMode(int incr);
extern WORD SMSPaletteRGB444[];
static char connectedGamePadName[sizeof(io::GamePadState::GamePadName)];
#define CBLACK 0
#define CWHITE 0x3f
#define CRED 3
#define CGREEN 0x40
#define CBLUE 36
#define CLIGHTBLUE 0x63
#define DEFAULT_FGCOLOR CBLACK // 60
#define DEFAULT_BGCOLOR CWHITE
static int fgcolor = DEFAULT_FGCOLOR;
static int bgcolor = DEFAULT_BGCOLOR;
struct charCell
{
uint8_t fgcolor;
uint8_t bgcolor;
char charvalue;
};
#define SCREENBUFCELLS SCREEN_ROWS *SCREEN_COLS
static charCell *screenBuffer;
;
static WORD *WorkLineRom = nullptr;
static constexpr int LEFT = 0x00000004;
static constexpr int RIGHT = 0x00000008;
static constexpr int UP = 0x00000001;
static constexpr int DOWN = 0x00000002;
static constexpr int SELECT = 0x00000002;
static constexpr int START = 0x00000001;
static constexpr int A = 0x00000020;
static constexpr int B = 0x00000010;
// static constexpr int X = 1 << 8;
// static constexpr int Y = 1 << 9;
char getcharslicefrom8x8font(char c, int rowInChar)
{
sizeof(screenBuffer);
return font_8x8[(c - FONT_FIRST_ASCII) + (rowInChar)*FONT_N_CHARS];
}
void RomSelect_DrawLine(int line, int selectedRow)
{
WORD fgcolor, bgcolor;
memset(WorkLineRom, 0, 640);
for (auto i = 0; i < SCREEN_COLS; ++i)
{
int charIndex = i + line / FONT_CHAR_HEIGHT * SCREEN_COLS;
int row = charIndex / SCREEN_COLS;
uint c = screenBuffer[charIndex].charvalue;
if (row == selectedRow)
{
fgcolor = SMSPaletteRGB444[screenBuffer[charIndex].bgcolor];
bgcolor = SMSPaletteRGB444[screenBuffer[charIndex].fgcolor];
}
else
{
fgcolor = SMSPaletteRGB444[screenBuffer[charIndex].fgcolor];
bgcolor = SMSPaletteRGB444[screenBuffer[charIndex].bgcolor];
}
int rowInChar = line % FONT_CHAR_HEIGHT;
char fontSlice = getcharslicefrom8x8font(c, rowInChar); // font_8x8[(c - FONT_FIRST_ASCII) + (rowInChar)*FONT_N_CHARS];
for (auto bit = 0; bit < 8; bit++)
{
if (fontSlice & 1)
{
*WorkLineRom = fgcolor;
}
else
{
*WorkLineRom = bgcolor;
}
fontSlice >>= 1;
WorkLineRom++;
}
}
return;
}
void drawline(int scanline, int selectedRow)
{
// RomSelect_PreDrawLine(scanline);
// RomSelect_DrawLine(scanline - 4, selectedRow);
// InfoNES_PostDrawLine(scanline);
auto b = dvi_->getLineBuffer();
WorkLineRom = b->data() + 32;
RomSelect_DrawLine(scanline - 4, selectedRow);
dvi_->setLineBuffer(scanline, b);
}
static void putText(int x, int y, const char *text, int fgcolor, int bgcolor)
{
if (text != nullptr)
{
auto index = y * SCREEN_COLS + x;
auto maxLen = strlen(text);
if (strlen(text) > SCREEN_COLS - x)
{
maxLen = SCREEN_COLS - x;
}
while (index < SCREENBUFCELLS && *text && maxLen > 0)
{
screenBuffer[index].charvalue = *text++;
screenBuffer[index].fgcolor = fgcolor;
screenBuffer[index].bgcolor = bgcolor;
index++;
maxLen--;
}
}
}
void DrawScreen(int selectedRow)
{
const char *spaces = " ";
char tmpstr[sizeof(connectedGamePadName) + 4];
if (selectedRow != -1)
{
putText(SCREEN_COLS / 2 - strlen(spaces) / 2, SCREEN_ROWS - 1, spaces, bgcolor, bgcolor);
snprintf(tmpstr,sizeof(tmpstr), "- %s -", connectedGamePadName[0] != 0 ? connectedGamePadName : "No USB GamePad");
putText(SCREEN_COLS / 2 - strlen(tmpstr) / 2, SCREEN_ROWS - 1, tmpstr, CBLUE, CWHITE);
}
for (auto line = 4; line < 236; line++)
{
drawline(line, selectedRow);
}
}
void ClearScreen(charCell *screenBuffer, int color)
{
for (auto i = 0; i < SCREENBUFCELLS; i++)
{
screenBuffer[i].bgcolor = color;
screenBuffer[i].fgcolor = color;
screenBuffer[i].charvalue = ' ';
}
}
void displayRoms(Frens::RomLister romlister, int startIndex)
{
char buffer[ROMLISTER_MAXPATH + 4];
char s[SCREEN_COLS + 1];
auto y = STARTROW;
auto entries = romlister.GetEntries();
ClearScreen(screenBuffer, bgcolor);
strcpy(s, "- Pico-SMS+ -");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 0, s, fgcolor, bgcolor);
strcpy(s, "Choose a rom to play:");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 1, s, fgcolor, bgcolor);
for (int i = 1; i < SCREEN_COLS - 1; i++)
{
putText(i, STARTROW - 1, "-", fgcolor, bgcolor);
}
for (int i = 1; i < SCREEN_COLS - 1; i++)
{
putText(i, ENDROW + 1, "-", fgcolor, bgcolor);
}
strcpy(s, "A Select, B Back");
putText(1, ENDROW + 2, s, fgcolor, bgcolor);
putText(SCREEN_COLS - strlen(SWVERSION), SCREEN_ROWS - 1, SWVERSION, fgcolor, bgcolor);
putText(SCREEN_COLS - strlen(PICOHWNAME_) - 1, ENDROW + 2, PICOHWNAME_, fgcolor, bgcolor);
for (auto index = startIndex; index < romlister.Count(); index++)
{
if (y <= ENDROW)
{
auto info = entries[index];
if (info.IsDirectory)
{
snprintf(buffer, SCREEN_COLS - 1, "D %s", info.Path);
}
else
{
snprintf(buffer, SCREEN_COLS - 1, "R %s", info.Path);
}
putText(1, y, buffer, fgcolor, bgcolor);
y++;
}
}
}
void DisplayFatalError(char *error)
{
ClearScreen(screenBuffer, bgcolor);
putText(0, 0, "Fatal error:", fgcolor, bgcolor);
putText(1, 3, error, fgcolor, bgcolor);
while (true)
{
auto frameCount = ProcessAfterFrameIsRendered();
DrawScreen(-1);
}
}
void DisplayEmulatorErrorMessage(char *error)
{
DWORD PAD1_Latch, PAD1_Latch2, pdwSystem;
ClearScreen(screenBuffer, bgcolor);
putText(0, 0, "Error occured:", fgcolor, bgcolor);
putText(0, 3, error, fgcolor, bgcolor);
putText(0, ENDROW, "Press a button to continue.", fgcolor, bgcolor);
while (true)
{
auto frameCount = ProcessAfterFrameIsRendered();
DrawScreen(-1);
processinput(&PAD1_Latch, &PAD1_Latch2, &pdwSystem, false, connectedGamePadName);
if (PAD1_Latch > 0)
{
return;
}
}
}
void showSplashScreen()
{
DWORD PAD1_Latch, PAD1_Latch2, pdwSystem;
char s[SCREEN_COLS + 1];
ClearScreen(screenBuffer, bgcolor);
strcpy(s, "Pico-");
putText(SCREEN_COLS / 2 - (strlen(s) + 4) / 2, 2, s, fgcolor, bgcolor);
putText((SCREEN_COLS / 2 - (strlen(s)) / 2) + 3, 2, "S", CRED, bgcolor);
putText((SCREEN_COLS / 2 - (strlen(s)) / 2) + 4, 2, "M", CGREEN, bgcolor);
putText((SCREEN_COLS / 2 - (strlen(s)) / 2) + 5, 2, "S", CBLUE, bgcolor);
putText((SCREEN_COLS / 2 - (strlen(s)) / 2) + 6, 2, "+", fgcolor, bgcolor);
strcpy(s, "Sega Master System");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 4, s, fgcolor, bgcolor);
strcpy(s, "emulator for RP2040");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 5, s, fgcolor, bgcolor);
strcpy(s, "Pico Port");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 9, s, fgcolor, bgcolor);
strcpy(s, "@frenskefrens");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 10, s, CBLUE, bgcolor);
strcpy(s, "DVI Support");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 13, s, fgcolor, bgcolor);
strcpy(s, "@shuichi_takano");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 14, s, CBLUE, bgcolor);
strcpy(s, "(S)NES/WII controller support");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 17, s, fgcolor, bgcolor);
strcpy(s, "@PaintYourDragon @adafruit");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 18, s, CBLUE, bgcolor);
strcpy(s, "PCB Design");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 21, s, fgcolor, bgcolor);
strcpy(s, "@johnedgarpark");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 22, s, CBLUE, bgcolor);
strcpy(s, "https://github.com/");
putText(SCREEN_COLS / 2 - strlen(s) / 2, 25, s, CBLUE, bgcolor);
strcpy(s, "fhoedemakers/pico-smsplus");
putText(1, 26, s, CBLUE, bgcolor);
int startFrame = -1;
while (true)
{
auto frameCount = ProcessAfterFrameIsRendered();
if (startFrame == -1)
{
startFrame = frameCount;
}
DrawScreen(-1);
processinput(&PAD1_Latch, &PAD1_Latch2, &pdwSystem, false, connectedGamePadName);
PAD1_Latch |= PAD1_Latch2;
if (PAD1_Latch > 0 || (frameCount - startFrame) > 1000)
{
return;
}
if ((frameCount % 30) == 0)
{
for (auto i = 0; i < SCREEN_COLS; i++)
{
auto col = rand() % 63;
putText(i, 0, " ", col, col);
col = rand() % 63;
putText(i, SCREEN_ROWS - 1, " ", col, col);
}
for (auto i = 1; i < SCREEN_ROWS - 1; i++)
{
auto col = rand() % 63;
putText(0, i, " ", col, col);
col = rand() % 63;
putText(SCREEN_COLS - 1, i, " ", col, col);
}
}
}
}
void screenSaver()
{
DWORD PAD1_Latch, PAD1_Latch2, pdwSystem;
WORD frameCount;
while (true)
{
frameCount = ProcessAfterFrameIsRendered();
DrawScreen(-1);
processinput(&PAD1_Latch, &PAD1_Latch2, &pdwSystem, false, connectedGamePadName);
if (PAD1_Latch > 0)
{
return;
}
if ((frameCount % 3) == 0)
{
auto color = rand() % 63;
auto row = rand() % SCREEN_ROWS;
auto column = rand() % SCREEN_COLS;
putText(column, row, " ", color, color);
}
}
}
void clearinput()
{
DWORD PAD1_Latch, PAD1_Latch2, pdwSystem;
while (1)
{
ProcessAfterFrameIsRendered();
DrawScreen(-1);
processinput(&PAD1_Latch, &PAD1_Latch2, &pdwSystem, true, connectedGamePadName);
if (PAD1_Latch == 0)
{
break;
}
}
}
// Global instances of local vars in romselect() some used in Lambda expression later on
static char *selectedRomOrFolder;
static uintptr_t FLASH_ADDRESS;
static bool errorInSavingRom = false;
static char *globalErrorMessage;
//
BYTE *dirbuffer;
void menu(uintptr_t NES_FILE_ADDR, char *errorMessage, bool isFatal, bool reset)
{
FLASH_ADDRESS = NES_FILE_ADDR;
int firstVisibleRowINDEX = 0;
int selectedRow = STARTROW;
char currentDir[FF_MAX_LFN];
int totalFrames = -1;
globalErrorMessage = errorMessage;
FRESULT fr;
DWORD PAD1_Latch, PAD1_Latch2, pdwSystem;
int horzontalScrollIndex = 0;
printf("Starting Menu\n");
screenBuffer = (charCell *)malloc(SCREENBUFCELLS * sizeof(charCell));
size_t ramsize;
// Borrow Emulator RAM buffer for screen.
// screenBuffer = (charCell *)InfoNes_GetRAM(&ramsize);
/// size_t chr_size;
// Borrow ChrBuffer to store directory contents
// void *buffer = InfoNes_GetChrBuf(&chr_size);
size_t bufsize;
dirbuffer = (BYTE *) getcachestorefromemulator(&bufsize);
Frens::RomLister romlister(dirbuffer, bufsize);
clearinput();
if (strlen(errorMessage) > 0)
{
if (isFatal) // SD card not working, show error
{
DisplayFatalError(errorMessage);
}
else
{
DisplayEmulatorErrorMessage(errorMessage); // Emulator cannot start, show error
}
}
else
{
// Show splash screen, only when not reset from emulation
if ( reset == false )
{
showSplashScreen();
} else sleep_ms(300);
}
romlister.list("/");
displayRoms(romlister, firstVisibleRowINDEX);
while (1)
{
auto frameCount = ProcessAfterFrameIsRendered();
auto index = selectedRow - STARTROW + firstVisibleRowINDEX;
auto entries = romlister.GetEntries();
selectedRomOrFolder = (romlister.Count() > 0) ? entries[index].Path : nullptr;
errorInSavingRom = false;
DrawScreen(selectedRow);
processinput(&PAD1_Latch, &PAD1_Latch2, &pdwSystem, false, connectedGamePadName);
PAD1_Latch |= PAD1_Latch2;
if (PAD1_Latch > 0 || pdwSystem > 0)
{
totalFrames = frameCount; // Reset screenSaver
// reset horizontal scroll of highlighted row
horzontalScrollIndex = 0;
putText(3, selectedRow, selectedRomOrFolder, fgcolor, bgcolor);
putText(SCREEN_COLS - 1, selectedRow, " ", bgcolor, bgcolor);
// if ((PAD1_Latch & Y) == Y)
// {
// fgcolor++;
// if (fgcolor > 63)
// {
// fgcolor = 0;
// }
// printf("fgColor++ : %02d (%04x)\n", fgcolor, NesPalette[fgcolor]);
// displayRoms(romlister, firstVisibleRowINDEX);
// }
// else if ((PAD1_Latch & X) == X)
// {
// bgcolor++;
// if (bgcolor > 63)
// {
// bgcolor = 0;
// }
// printf("bgColor++ : %02d (%04x)\n", bgcolor, NesPalette[bgcolor]);
// displayRoms(romlister, firstVisibleRowINDEX);
// }
// else
if ((PAD1_Latch & UP) == UP && selectedRomOrFolder)
{
if (selectedRow > STARTROW)
{
selectedRow--;
}
else
{
if (firstVisibleRowINDEX > 0)
{
firstVisibleRowINDEX--;
displayRoms(romlister, firstVisibleRowINDEX);
}
}
}
else if ((PAD1_Latch & DOWN) == DOWN && selectedRomOrFolder)
{
if (selectedRow < ENDROW && (index) < romlister.Count() - 1)
{
selectedRow++;
}
else
{
if (index < romlister.Count() - 1)
{
firstVisibleRowINDEX++;
displayRoms(romlister, firstVisibleRowINDEX);
}
}
}
else if ((PAD1_Latch & LEFT) == LEFT && selectedRomOrFolder)
{
firstVisibleRowINDEX -= PAGESIZE;
if (firstVisibleRowINDEX < 0)
{
firstVisibleRowINDEX = 0;
}
selectedRow = STARTROW;
displayRoms(romlister, firstVisibleRowINDEX);
}
else if ((PAD1_Latch & RIGHT) == RIGHT && selectedRomOrFolder)
{
if (firstVisibleRowINDEX + PAGESIZE < romlister.Count())
{
firstVisibleRowINDEX += PAGESIZE;
}
selectedRow = STARTROW;
displayRoms(romlister, firstVisibleRowINDEX);
}
else if ((PAD1_Latch & B) == B)
{
fr = f_getcwd(currentDir, 40);
if (fr != FR_OK)
{
printf("Cannot get current dir: %d\n", fr);
}
if (strcmp(currentDir, "/") != 0)
{
romlister.list("..");
firstVisibleRowINDEX = 0;
selectedRow = STARTROW;
displayRoms(romlister, firstVisibleRowINDEX);
}
}
else if ((pdwSystem & START) == START && (pdwSystem & SELECT) != SELECT)
{
// reboot and start emulator with currently loaded game
// Create a file /START indicating not to reflash the already flashed game
// The emulator will delete this file after loading the game
FRESULT fr;
FIL fil;
printf("Creating /START\n");
fr = f_open(&fil, "/START", FA_CREATE_ALWAYS | FA_WRITE);
if (fr == FR_OK)
{
auto bytes = f_puts("START", &fil);
printf("Wrote %d bytes\n", bytes);
fr = f_close(&fil);
if (fr != FR_OK)
{
printf("Cannot close file /START:%d\n", fr);
}
}
else
{
printf("Cannot create file /START:%d\n", fr);
}
break; // reboot
}
else if ((PAD1_Latch & A) == A && selectedRomOrFolder)
{
if (entries[index].IsDirectory)
{
romlister.list(selectedRomOrFolder);
firstVisibleRowINDEX = 0;
selectedRow = STARTROW;
displayRoms(romlister, firstVisibleRowINDEX);
}
else
{
FRESULT fr;
FIL fil;
char curdir[256];
fr = f_getcwd(curdir, sizeof(curdir));
printf("Current dir: %s\n", curdir);
// Create file containing full path name currently loaded rom
// The contents of this file will be used by the emulator to flash and start the correct rom in main.cpp
printf("Creating %s\n", ROMINFOFILE);
fr = f_open(&fil, ROMINFOFILE, FA_CREATE_ALWAYS | FA_WRITE);
if (fr == FR_OK)
{
for (auto i = 0; i < strlen(curdir); i++)
{
int x = f_putc(curdir[i], &fil);
printf("%c", curdir[i]);
if (x < 0)
{
snprintf(globalErrorMessage, 40, "Error writing file %d", fr);
printf("%s\n", globalErrorMessage);
errorInSavingRom = true;
break;
}
}
f_putc('/', &fil);
printf("%c", '/');
for (auto i = 0; i < strlen(selectedRomOrFolder); i++)
{
int x = f_putc(selectedRomOrFolder[i], &fil);
printf("%c", selectedRomOrFolder[i]);
if (x < 0)
{
snprintf(globalErrorMessage, 40, "Error writing file %d", fr);
printf("%s\n", globalErrorMessage);
errorInSavingRom = true;
break;
}
}
printf("\n");
}
else
{
printf("Cannot create %s:%d\n", ROMINFOFILE, fr);
snprintf(globalErrorMessage, 40, "Cannot create %s:%d", ROMINFOFILE, fr);
errorInSavingRom = true;
}
f_close(&fil);
// break out of loop and reboot
// rom will be flashed and started by main.cpp
// Cannot flash here because of lockups (when using wii controller) and sound issues
break;
}
}
}
// scroll selected row horizontally if textsize exceeds rowlength
if (selectedRomOrFolder)
{
if ((frameCount % 30) == 0)
{
if (strlen(selectedRomOrFolder + horzontalScrollIndex) >= VISIBLEPATHSIZE)
{
horzontalScrollIndex++;
}
else
{
horzontalScrollIndex = 0;
}
putText(3, selectedRow, selectedRomOrFolder + horzontalScrollIndex, fgcolor, bgcolor);
putText(SCREEN_COLS - 1, selectedRow, " ", bgcolor, bgcolor);
}
}
if (totalFrames == -1)
{
totalFrames = frameCount;
}
if ((frameCount - totalFrames) > 800)
{
printf("Starting screensaver\n");
totalFrames = -1;
screenSaver();
displayRoms(romlister, firstVisibleRowINDEX);
}
} // while 1
// Wait until user has released all buttons
clearinput();
#if WII_PIN_SDA >= 0 and WII_PIN_SCL >= 0
wiipad_end();
#endif
// Don't return from this function call, but reboot in order to get avoid several problems with sound and lockups (WII-pad)
// After reboot the emulator will and flash start the selected game.
printf("Rebooting...\n");
watchdog_enable(100, 1);
while (1)
;
// Never return
}