src/feature/gui/gui-runner.c (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "gui-runner.h"
7
8#include <mgba/core/core.h>
9#include <mgba/core/serialize.h>
10#include "feature/gui/gui-config.h"
11#include <mgba/internal/gba/gba.h>
12#include <mgba/internal/gba/input.h>
13#include <mgba/gba/interface.h>
14#include <mgba-util/gui/file-select.h>
15#include <mgba-util/gui/font.h>
16#include <mgba-util/gui/menu.h>
17#include <mgba-util/memory.h>
18#include <mgba-util/png-io.h>
19#include <mgba-util/vfs.h>
20
21#ifdef _3DS
22#include <3ds.h>
23#endif
24
25#include <sys/time.h>
26
27mLOG_DECLARE_CATEGORY(GUI_RUNNER);
28mLOG_DEFINE_CATEGORY(GUI_RUNNER, "GUI Runner", "gui.runner");
29
30#define FPS_GRANULARITY 120
31#define FPS_BUFFER_SIZE 3
32
33enum {
34 RUNNER_CONTINUE = 1,
35 RUNNER_EXIT,
36 RUNNER_SAVE_STATE,
37 RUNNER_LOAD_STATE,
38 RUNNER_SCREENSHOT,
39 RUNNER_CONFIG,
40 RUNNER_RESET,
41 RUNNER_COMMAND_MASK = 0xFFFF,
42
43 RUNNER_STATE_1 = 0x10000,
44 RUNNER_STATE_2 = 0x20000,
45 RUNNER_STATE_3 = 0x30000,
46 RUNNER_STATE_4 = 0x40000,
47 RUNNER_STATE_5 = 0x50000,
48 RUNNER_STATE_6 = 0x60000,
49 RUNNER_STATE_7 = 0x70000,
50 RUNNER_STATE_8 = 0x80000,
51 RUNNER_STATE_9 = 0x90000,
52};
53
54static const struct mInputPlatformInfo _mGUIKeyInfo = {
55 .platformName = "gui",
56 .keyId = (const char*[GUI_INPUT_MAX]) {
57 "Select",
58 "Back",
59 "Cancel",
60 "Up",
61 "Down",
62 "Left",
63 "Right",
64 [mGUI_INPUT_INCREASE_BRIGHTNESS] = "Increase solar brightness",
65 [mGUI_INPUT_DECREASE_BRIGHTNESS] = "Decrease solar brightness",
66 [mGUI_INPUT_SCREEN_MODE] = "Screen mode",
67 [mGUI_INPUT_SCREENSHOT] = "Take screenshot",
68 [mGUI_INPUT_FAST_FORWARD] = "Fast forward",
69 },
70 .nKeys = GUI_INPUT_MAX
71};
72
73static void _log(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args);
74
75static struct mGUILogger {
76 struct mLogger d;
77 struct VFile* vf;
78 int logLevel;
79} logger = {
80 .d = {
81 .log = _log
82 },
83 .vf = NULL,
84 .logLevel = 0
85};
86
87static void _drawBackground(struct GUIBackground* background, void* context) {
88 UNUSED(context);
89 struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
90 if (gbaBackground->p->drawFrame) {
91 gbaBackground->p->drawFrame(gbaBackground->p, true);
92 }
93}
94
95static void _drawState(struct GUIBackground* background, void* id) {
96 struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
97 int stateId = ((int) id) >> 16;
98 if (gbaBackground->p->drawScreenshot) {
99 unsigned w, h;
100 gbaBackground->p->core->desiredVideoDimensions(gbaBackground->p->core, &w, &h);
101 if (gbaBackground->screenshot && gbaBackground->screenshotId == (int) id) {
102 gbaBackground->p->drawScreenshot(gbaBackground->p, gbaBackground->screenshot, w, h, true);
103 return;
104 }
105 struct VFile* vf = mCoreGetState(gbaBackground->p->core, stateId, false);
106 color_t* pixels = gbaBackground->screenshot;
107 if (!pixels) {
108 pixels = anonymousMemoryMap(w * h * 4);
109 gbaBackground->screenshot = pixels;
110 }
111 bool success = false;
112 if (vf && isPNG(vf) && pixels) {
113 png_structp png = PNGReadOpen(vf, PNG_HEADER_BYTES);
114 png_infop info = png_create_info_struct(png);
115 png_infop end = png_create_info_struct(png);
116 if (png && info && end) {
117 success = PNGReadHeader(png, info);
118 success = success && PNGReadPixels(png, info, pixels, w, h, w);
119 success = success && PNGReadFooter(png, end);
120 }
121 PNGReadClose(png, info, end);
122 }
123 if (vf) {
124 vf->close(vf);
125 }
126 if (success) {
127 gbaBackground->p->drawScreenshot(gbaBackground->p, pixels, w, h, true);
128 gbaBackground->screenshotId = (int) id;
129 } else if (gbaBackground->p->drawFrame) {
130 gbaBackground->p->drawFrame(gbaBackground->p, true);
131 }
132 }
133}
134
135static void _updateLux(struct GBALuminanceSource* lux) {
136 UNUSED(lux);
137}
138
139static uint8_t _readLux(struct GBALuminanceSource* lux) {
140 struct mGUIRunnerLux* runnerLux = (struct mGUIRunnerLux*) lux;
141 int value = 0x16;
142 if (runnerLux->luxLevel > 0) {
143 value += GBA_LUX_LEVELS[runnerLux->luxLevel - 1];
144 }
145 return 0xFF - value;
146}
147
148void mGUIInit(struct mGUIRunner* runner, const char* port) {
149 GUIInit(&runner->params);
150 runner->port = port;
151 runner->core = NULL;
152 runner->luminanceSource.d.readLuminance = _readLux;
153 runner->luminanceSource.d.sample = _updateLux;
154 runner->luminanceSource.luxLevel = 0;
155 runner->background.d.draw = _drawBackground;
156 runner->background.p = runner;
157 runner->fps = 0;
158 runner->lastFpsCheck = 0;
159 runner->totalDelta = 0;
160 CircleBufferInit(&runner->fpsBuffer, FPS_BUFFER_SIZE * sizeof(uint32_t));
161
162 mInputMapInit(&runner->params.keyMap, &_mGUIKeyInfo);
163 mCoreConfigInit(&runner->config, runner->port);
164 // TODO: Do we need to load more defaults?
165 mCoreConfigSetDefaultIntValue(&runner->config, "volume", 0x100);
166 mCoreConfigSetDefaultValue(&runner->config, "idleOptimization", "detect");
167 mCoreConfigLoad(&runner->config);
168 mCoreConfigGetIntValue(&runner->config, "logLevel", &logger.logLevel);
169
170 char path[PATH_MAX];
171 mCoreConfigDirectory(path, PATH_MAX);
172 strncat(path, PATH_SEP "log", PATH_MAX - strlen(path));
173 logger.vf = VFileOpen(path, O_CREAT | O_WRONLY | O_APPEND);
174 mLogSetDefaultLogger(&logger.d);
175
176 const char* lastPath = mCoreConfigGetValue(&runner->config, "lastDirectory");
177 if (lastPath) {
178 strncpy(runner->params.currentPath, lastPath, PATH_MAX - 1);
179 runner->params.currentPath[PATH_MAX - 1] = '\0';
180 }
181}
182
183void mGUIDeinit(struct mGUIRunner* runner) {
184 if (runner->teardown) {
185 runner->teardown(runner);
186 }
187 CircleBufferDeinit(&runner->fpsBuffer);
188 mInputMapDeinit(&runner->params.keyMap);
189 mCoreConfigDeinit(&runner->config);
190 if (logger.vf) {
191 logger.vf->close(logger.vf);
192 logger.vf = NULL;
193 }
194}
195
196static void _log(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) {
197 struct mGUILogger* guiLogger = (struct mGUILogger*) logger;
198 if (!guiLogger->vf) {
199 return;
200 }
201 if (!(guiLogger->logLevel & level)) {
202 return;
203 }
204
205 char log[256] = {0};
206 vsnprintf(log, sizeof(log) - 1, format, args);
207 char log2[256] = {0};
208 size_t len = snprintf(log2, sizeof(log2) - 1, "%s: %s\n", mLogCategoryName(category), log);
209 if (len >= sizeof(log2)) {
210 len = sizeof(log2) - 1;
211 }
212 guiLogger->vf->write(guiLogger->vf, log2, len);
213}
214
215void mGUIRun(struct mGUIRunner* runner, const char* path) {
216 struct mGUIBackground drawState = {
217 .d = {
218 .draw = _drawState
219 },
220 .p = runner,
221 .screenshot = 0,
222 .screenshotId = 0
223 };
224 struct GUIMenu pauseMenu = {
225 .title = "Game Paused",
226 .index = 0,
227 .background = &runner->background.d
228 };
229 struct GUIMenu stateSaveMenu = {
230 .title = "Save state",
231 .index = 0,
232 .background = &drawState.d
233 };
234 struct GUIMenu stateLoadMenu = {
235 .title = "Load state",
236 .index = 0,
237 .background = &drawState.d
238 };
239 GUIMenuItemListInit(&pauseMenu.items, 0);
240 GUIMenuItemListInit(&stateSaveMenu.items, 9);
241 GUIMenuItemListInit(&stateLoadMenu.items, 9);
242 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE };
243 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Save state", .submenu = &stateSaveMenu };
244 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Load state", .submenu = &stateLoadMenu };
245
246 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 1", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_1) };
247 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 2", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_2) };
248 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 3", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_3) };
249 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 4", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_4) };
250 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 5", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_5) };
251 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 6", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_6) };
252 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 7", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_7) };
253 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 8", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_8) };
254 *GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 9", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_9) };
255
256 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 1", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_1) };
257 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 2", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_2) };
258 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 3", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_3) };
259 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 4", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_4) };
260 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 5", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_5) };
261 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 6", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_6) };
262 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 7", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_7) };
263 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 8", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_8) };
264 *GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 9", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_9) };
265
266 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Take screenshot", .data = (void*) RUNNER_SCREENSHOT };
267 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Configure", .data = (void*) RUNNER_CONFIG };
268 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Reset game", .data = (void*) RUNNER_RESET };
269 *GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT };
270
271 runner->params.drawStart();
272 if (runner->params.guiPrepare) {
273 runner->params.guiPrepare();
274 }
275 GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_ALIGN_HCENTER, 0xFFFFFFFF, "Loading...");
276 if (runner->params.guiFinish) {
277 runner->params.guiFinish();
278 }
279 runner->params.drawEnd();
280
281 bool found = false;
282 mLOG(GUI_RUNNER, INFO, "Attempting to load %s", path);
283 runner->core = mCoreFind(path);
284 if (runner->core) {
285 mLOG(GUI_RUNNER, INFO, "Found core");
286 runner->core->init(runner->core);
287 mCoreInitConfig(runner->core, runner->port);
288 mInputMapInit(&runner->core->inputMap, &GBAInputInfo);
289 found = mCoreLoadFile(runner->core, path);
290 if (!found) {
291 mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path);
292 runner->core->deinit(runner->core);
293 }
294 }
295
296 if (!found) {
297 mLOG(GUI_RUNNER, WARN, "Failed to find core for %s!", path);
298 GUIShowMessageBox(&runner->params, GUI_MESSAGE_BOX_OK, 240, "Load failed!");
299 return;
300 }
301 if (runner->core->platform(runner->core) == PLATFORM_GBA) {
302 runner->core->setPeripheral(runner->core, mPERIPH_GBA_LUMINANCE, &runner->luminanceSource.d);
303 }
304 mLOG(GUI_RUNNER, DEBUG, "Loading config...");
305 mCoreLoadForeignConfig(runner->core, &runner->config);
306
307 mLOG(GUI_RUNNER, DEBUG, "Loading save...");
308 mCoreAutoloadSave(runner->core);
309 mCoreAutoloadCheats(runner->core);
310 if (runner->setup) {
311 mLOG(GUI_RUNNER, DEBUG, "Setting up runner...");
312 runner->setup(runner);
313 }
314 if (runner->config.port && runner->keySources) {
315 mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
316 size_t i;
317 for (i = 0; runner->keySources[i].id; ++i) {
318 mInputMapLoad(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
319 }
320 }
321 mLOG(GUI_RUNNER, DEBUG, "Reseting...");
322 runner->core->reset(runner->core);
323 mLOG(GUI_RUNNER, DEBUG, "Reset!");
324 bool running = true;
325 if (runner->gameLoaded) {
326 runner->gameLoaded(runner);
327 }
328 mLOG(GUI_RUNNER, INFO, "Game starting");
329 while (running) {
330 CircleBufferClear(&runner->fpsBuffer);
331 runner->totalDelta = 0;
332 runner->fps = 0;
333 struct timeval tv;
334 gettimeofday(&tv, 0);
335 runner->lastFpsCheck = 1000000LL * tv.tv_sec + tv.tv_usec;
336
337 while (true) {
338#ifdef _3DS
339 running = aptMainLoop();
340 if (!running) {
341 break;
342 }
343#endif
344 uint32_t guiKeys;
345 uint32_t heldKeys;
346 GUIPollInput(&runner->params, &guiKeys, &heldKeys);
347 if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
348 break;
349 }
350 if (guiKeys & (1 << mGUI_INPUT_INCREASE_BRIGHTNESS)) {
351 if (runner->luminanceSource.luxLevel < 10) {
352 ++runner->luminanceSource.luxLevel;
353 }
354 }
355 if (guiKeys & (1 << mGUI_INPUT_DECREASE_BRIGHTNESS)) {
356 if (runner->luminanceSource.luxLevel > 0) {
357 --runner->luminanceSource.luxLevel;
358 }
359 }
360 if (guiKeys & (1 << mGUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) {
361 runner->incrementScreenMode(runner);
362 }
363 if (guiKeys & (1 << mGUI_INPUT_SCREENSHOT)) {
364 mCoreTakeScreenshot(runner->core);
365 }
366 if (heldKeys & (1 << mGUI_INPUT_FAST_FORWARD)) {
367 runner->setFrameLimiter(runner, false);
368 } else {
369 runner->setFrameLimiter(runner, true);
370 }
371 uint16_t keys = runner->pollGameInput(runner);
372 if (runner->prepareForFrame) {
373 runner->prepareForFrame(runner);
374 }
375 runner->core->setKeys(runner->core, keys);
376 runner->core->runFrame(runner->core);
377 if (runner->drawFrame) {
378 int drawFps = false;
379 mCoreConfigGetIntValue(&runner->config, "fpsCounter", &drawFps);
380
381 runner->params.drawStart();
382 runner->drawFrame(runner, false);
383 if (drawFps) {
384 if (runner->params.guiPrepare) {
385 runner->params.guiPrepare();
386 }
387 GUIFontPrintf(runner->params.font, 0, GUIFontHeight(runner->params.font), GUI_ALIGN_LEFT, 0x7FFFFFFF, "%.2f fps", runner->fps);
388 if (runner->params.guiFinish) {
389 runner->params.guiFinish();
390 }
391 }
392 runner->params.drawEnd();
393
394 if (runner->core->frameCounter(runner->core) % FPS_GRANULARITY == 0) {
395 if (drawFps) {
396 struct timeval tv;
397 gettimeofday(&tv, 0);
398 uint64_t t = 1000000LL * tv.tv_sec + tv.tv_usec;
399 uint64_t delta = t - runner->lastFpsCheck;
400 runner->lastFpsCheck = t;
401 if (delta > 0x7FFFFFFFLL) {
402 CircleBufferClear(&runner->fpsBuffer);
403 runner->fps = 0;
404 }
405 if (CircleBufferSize(&runner->fpsBuffer) == CircleBufferCapacity(&runner->fpsBuffer)) {
406 int32_t last;
407 CircleBufferRead32(&runner->fpsBuffer, &last);
408 runner->totalDelta -= last;
409 }
410 CircleBufferWrite32(&runner->fpsBuffer, delta);
411 runner->totalDelta += delta;
412 runner->fps = (CircleBufferSize(&runner->fpsBuffer) * FPS_GRANULARITY * 1000000.0f) / (runner->totalDelta * sizeof(uint32_t));
413 }
414 }
415 }
416 }
417
418 if (runner->paused) {
419 runner->paused(runner);
420 }
421 GUIInvalidateKeys(&runner->params);
422 uint32_t keys = 0xFFFFFFFF; // Huge hack to avoid an extra variable!
423 struct GUIMenuItem* item;
424 enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
425 if (reason == GUI_MENU_EXIT_ACCEPT) {
426 switch (((int) item->data) & RUNNER_COMMAND_MASK) {
427 case RUNNER_EXIT:
428 running = false;
429 keys = 0;
430 break;
431 case RUNNER_RESET:
432 runner->core->reset(runner->core);
433 break;
434 case RUNNER_SAVE_STATE:
435 mCoreSaveState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA);
436 break;
437 case RUNNER_LOAD_STATE:
438 mCoreLoadState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT | SAVESTATE_RTC);
439 break;
440 case RUNNER_SCREENSHOT:
441 mCoreTakeScreenshot(runner->core);
442 break;
443 case RUNNER_CONFIG:
444 mGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
445 break;
446 case RUNNER_CONTINUE:
447 break;
448 }
449 }
450 int frames = 0;
451 GUIPollInput(&runner->params, 0, &keys);
452 while (keys && frames < 30) {
453 ++frames;
454 runner->params.drawStart();
455 runner->drawFrame(runner, true);
456 runner->params.drawEnd();
457 GUIPollInput(&runner->params, 0, &keys);
458 }
459 if (runner->unpaused) {
460 runner->unpaused(runner);
461 }
462 }
463 mLOG(GUI_RUNNER, DEBUG, "Shutting down...");
464 if (runner->gameUnloaded) {
465 runner->gameUnloaded(runner);
466 }
467 mLOG(GUI_RUNNER, DEBUG, "Unloading game...");
468 runner->core->unloadROM(runner->core);
469 drawState.screenshotId = 0;
470 if (drawState.screenshot) {
471 unsigned w, h;
472 runner->core->desiredVideoDimensions(runner->core, &w, &h);
473 mappedMemoryFree(drawState.screenshot, w * h * 4);
474 }
475
476 if (runner->config.port) {
477 mLOG(GUI_RUNNER, DEBUG, "Saving key sources...");
478 if (runner->keySources) {
479 size_t i;
480 for (i = 0; runner->keySources[i].id; ++i) {
481 mInputMapSave(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
482 mInputMapSave(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
483 }
484 }
485 mCoreConfigSave(&runner->config);
486 }
487 mInputMapDeinit(&runner->core->inputMap);
488 mLOG(GUI_RUNNER, DEBUG, "Deinitializing core...");
489 runner->core->deinit(runner->core);
490
491 GUIMenuItemListDeinit(&pauseMenu.items);
492 GUIMenuItemListDeinit(&stateSaveMenu.items);
493 GUIMenuItemListDeinit(&stateLoadMenu.items);
494 mLOG(GUI_RUNNER, INFO, "Game stopped!");
495}
496
497void mGUIRunloop(struct mGUIRunner* runner) {
498 if (runner->keySources) {
499 mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
500 size_t i;
501 for (i = 0; runner->keySources[i].id; ++i) {
502 mInputMapLoad(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
503 }
504 }
505 while (true) {
506 char path[PATH_MAX];
507 if (!GUISelectFile(&runner->params, path, sizeof(path), 0)) {
508 break;
509 }
510 mCoreConfigSetValue(&runner->config, "lastDirectory", runner->params.currentPath);
511 mCoreConfigSave(&runner->config);
512 mGUIRun(runner, path);
513 }
514}