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