all repos — mgba @ 5ba2d00504a70bb3dd4ba7bd196d0ee851cc53d3

mGBA Game Boy Advance Emulator

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 "core/core.h"
  9#include "core/serialize.h"
 10#include "feature/gui/gui-config.h"
 11#include "gba/gba.h"
 12#include "gba/input.h"
 13#include "gba/interface.h"
 14#include "util/gui/file-select.h"
 15#include "util/gui/font.h"
 16#include "util/gui/menu.h"
 17#include "util/memory.h"
 18#include "util/png-io.h"
 19#include "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");
 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
169	char path[PATH_MAX];
170	mCoreConfigDirectory(path, PATH_MAX);
171	strncat(path, PATH_SEP "log", PATH_MAX - strlen(path));
172	logger.vf = VFileOpen(path, O_CREAT | O_WRONLY | O_APPEND);
173	mLogSetDefaultLogger(&logger.d);
174
175	const char* lastPath = mCoreConfigGetValue(&runner->config, "lastDirectory");
176	if (lastPath) {
177		strncpy(runner->params.currentPath, lastPath, PATH_MAX - 1);
178		runner->params.currentPath[PATH_MAX - 1] = '\0';
179	}
180}
181
182void mGUIDeinit(struct mGUIRunner* runner) {
183	if (runner->teardown) {
184		runner->teardown(runner);
185	}
186	CircleBufferDeinit(&runner->fpsBuffer);
187	mInputMapDeinit(&runner->params.keyMap);
188	mCoreConfigDeinit(&runner->config);
189	if (logger.vf) {
190		logger.vf->close(logger.vf);
191		logger.vf = NULL;
192	}
193}
194
195static void _log(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) {
196	struct mGUILogger* guiLogger = (struct mGUILogger*) logger;
197	if (!guiLogger->vf) {
198		return;
199	}
200	if (!(guiLogger->logLevel & level)) {
201		return;
202	}
203
204	char log[256] = {0};
205	vsnprintf(log, sizeof(log) - 1, format, args);
206	char log2[256] = {0};
207	size_t len = snprintf(log2, sizeof(log2) - 1, "%s: %s\n", mLogCategoryName(category), log);
208	if (len >= sizeof(log2)) {
209		len = sizeof(log2) - 1;
210	}
211	guiLogger->vf->write(guiLogger->vf, log2, len);
212}
213
214void mGUIRun(struct mGUIRunner* runner, const char* path) {
215	struct mGUIBackground drawState = {
216		.d = {
217			.draw = _drawState
218		},
219		.p = runner,
220		.screenshot = 0,
221		.screenshotId = 0
222	};
223	struct GUIMenu pauseMenu = {
224		.title = "Game Paused",
225		.index = 0,
226		.background = &runner->background.d
227	};
228	struct GUIMenu stateSaveMenu = {
229		.title = "Save state",
230		.index = 0,
231		.background = &drawState.d
232	};
233	struct GUIMenu stateLoadMenu = {
234		.title = "Load state",
235		.index = 0,
236		.background = &drawState.d
237	};
238	GUIMenuItemListInit(&pauseMenu.items, 0);
239	GUIMenuItemListInit(&stateSaveMenu.items, 9);
240	GUIMenuItemListInit(&stateLoadMenu.items, 9);
241	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Unpause", .data = (void*) RUNNER_CONTINUE };
242	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Save state", .submenu = &stateSaveMenu };
243	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Load state", .submenu = &stateLoadMenu };
244
245	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 1", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_1) };
246	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 2", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_2) };
247	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 3", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_3) };
248	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 4", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_4) };
249	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 5", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_5) };
250	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 6", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_6) };
251	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 7", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_7) };
252	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 8", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_8) };
253	*GUIMenuItemListAppend(&stateSaveMenu.items) = (struct GUIMenuItem) { .title = "State 9", .data = (void*) (RUNNER_SAVE_STATE | RUNNER_STATE_9) };
254
255	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 1", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_1) };
256	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 2", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_2) };
257	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 3", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_3) };
258	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 4", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_4) };
259	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 5", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_5) };
260	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 6", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_6) };
261	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 7", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_7) };
262	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 8", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_8) };
263	*GUIMenuItemListAppend(&stateLoadMenu.items) = (struct GUIMenuItem) { .title = "State 9", .data = (void*) (RUNNER_LOAD_STATE | RUNNER_STATE_9) };
264
265	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Take screenshot", .data = (void*) RUNNER_SCREENSHOT };
266	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Configure", .data = (void*) RUNNER_CONFIG };
267	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Reset game", .data = (void*) RUNNER_RESET };
268	*GUIMenuItemListAppend(&pauseMenu.items) = (struct GUIMenuItem) { .title = "Exit game", .data = (void*) RUNNER_EXIT };
269
270	runner->params.drawStart();
271	if (runner->params.guiPrepare) {
272		runner->params.guiPrepare();
273	}
274	GUIFontPrint(runner->params.font, runner->params.width / 2, (GUIFontHeight(runner->params.font) + runner->params.height) / 2, GUI_ALIGN_HCENTER, 0xFFFFFFFF, "Loading...");
275	if (runner->params.guiFinish) {
276		runner->params.guiFinish();
277	}
278	runner->params.drawEnd();
279
280	bool found = false;
281	mLOG(GUI_RUNNER, INFO, "Attempting to load %s", path);
282	runner->core = mCoreFind(path);
283	if (runner->core) {
284		mLOG(GUI_RUNNER, INFO, "Found core");
285		runner->core->init(runner->core);
286		mInputMapInit(&runner->core->inputMap, &GBAInputInfo);
287		found = mCoreLoadFile(runner->core, path);
288		if (!found) {
289			mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path);
290			runner->core->deinit(runner->core);
291		}
292	}
293
294	if (!found) {
295		mLOG(GUI_RUNNER, WARN, "Failed to find core for %s!", path);
296		GUIShowMessageBox(&runner->params, GUI_MESSAGE_BOX_OK, 240, "Load failed!");
297		return;
298	}
299	if (runner->core->platform(runner->core) == PLATFORM_GBA) {
300		((struct GBA*) runner->core->board)->luminanceSource = &runner->luminanceSource.d;
301	}
302	mLOG(GUI_RUNNER, DEBUG, "Loading config...");
303	mCoreLoadForeignConfig(runner->core, &runner->config);
304	logger.logLevel = runner->core->opts.logLevel;
305
306	mLOG(GUI_RUNNER, DEBUG, "Loading save...");
307	mCoreAutoloadSave(runner->core);
308	if (runner->setup) {
309		mLOG(GUI_RUNNER, DEBUG, "Setting up runner...");
310		runner->setup(runner);
311	}
312	if (runner->config.port && runner->keySources) {
313		mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
314		size_t i;
315		for (i = 0; runner->keySources[i].id; ++i) {
316			mInputMapLoad(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
317		}
318	}
319	mLOG(GUI_RUNNER, DEBUG, "Reseting...");
320	runner->core->reset(runner->core);
321	mLOG(GUI_RUNNER, DEBUG, "Reset!");
322	bool running = true;
323	if (runner->gameLoaded) {
324		runner->gameLoaded(runner);
325	}
326	mLOG(GUI_RUNNER, INFO, "Game starting");
327	while (running) {
328		CircleBufferClear(&runner->fpsBuffer);
329		runner->totalDelta = 0;
330		runner->fps = 0;
331		struct timeval tv;
332		gettimeofday(&tv, 0);
333		runner->lastFpsCheck = 1000000LL * tv.tv_sec + tv.tv_usec;
334
335		while (true) {
336#ifdef _3DS
337			running = aptMainLoop();
338			if (!running) {
339				break;
340			}
341#endif
342			uint32_t guiKeys;
343			uint32_t heldKeys;
344			GUIPollInput(&runner->params, &guiKeys, &heldKeys);
345			if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
346				break;
347			}
348			if (guiKeys & (1 << mGUI_INPUT_INCREASE_BRIGHTNESS)) {
349				if (runner->luminanceSource.luxLevel < 10) {
350					++runner->luminanceSource.luxLevel;
351				}
352			}
353			if (guiKeys & (1 << mGUI_INPUT_DECREASE_BRIGHTNESS)) {
354				if (runner->luminanceSource.luxLevel > 0) {
355					--runner->luminanceSource.luxLevel;
356				}
357			}
358			if (guiKeys & (1 << mGUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) {
359				runner->incrementScreenMode(runner);
360			}
361			if (guiKeys & (1 << mGUI_INPUT_SCREENSHOT)) {
362				mCoreTakeScreenshot(runner->core);
363			}
364			if (heldKeys & (1 << mGUI_INPUT_FAST_FORWARD)) {
365				runner->setFrameLimiter(runner, false);
366			} else {
367				runner->setFrameLimiter(runner, true);
368			}
369			uint16_t keys = runner->pollGameInput(runner);
370			if (runner->prepareForFrame) {
371				runner->prepareForFrame(runner);
372			}
373			runner->core->setKeys(runner->core, keys);
374			runner->core->runFrame(runner->core);
375			if (runner->drawFrame) {
376				int drawFps = false;
377				mCoreConfigGetIntValue(&runner->config, "fpsCounter", &drawFps);
378
379				runner->params.drawStart();
380				runner->drawFrame(runner, false);
381				if (drawFps) {
382					if (runner->params.guiPrepare) {
383						runner->params.guiPrepare();
384					}
385					GUIFontPrintf(runner->params.font, 0, GUIFontHeight(runner->params.font), GUI_ALIGN_LEFT, 0x7FFFFFFF, "%.2f fps", runner->fps);
386					if (runner->params.guiFinish) {
387						runner->params.guiFinish();
388					}
389				}
390				runner->params.drawEnd();
391
392				if (runner->core->frameCounter(runner->core) % FPS_GRANULARITY == 0) {
393					if (drawFps) {
394						struct timeval tv;
395						gettimeofday(&tv, 0);
396						uint64_t t = 1000000LL * tv.tv_sec + tv.tv_usec;
397						uint64_t delta = t - runner->lastFpsCheck;
398						runner->lastFpsCheck = t;
399						if (delta > 0x7FFFFFFFLL) {
400							CircleBufferClear(&runner->fpsBuffer);
401							runner->fps = 0;
402						}
403						if (CircleBufferSize(&runner->fpsBuffer) == CircleBufferCapacity(&runner->fpsBuffer)) {
404							int32_t last;
405							CircleBufferRead32(&runner->fpsBuffer, &last);
406							runner->totalDelta -= last;
407						}
408						CircleBufferWrite32(&runner->fpsBuffer, delta);
409						runner->totalDelta += delta;
410						runner->fps = (CircleBufferSize(&runner->fpsBuffer) * FPS_GRANULARITY * 1000000.0f) / (runner->totalDelta * sizeof(uint32_t));
411					}
412				}
413			}
414		}
415
416		if (runner->paused) {
417			runner->paused(runner);
418		}
419		GUIInvalidateKeys(&runner->params);
420		uint32_t keys = 0xFFFFFFFF; // Huge hack to avoid an extra variable!
421		struct GUIMenuItem* item;
422		enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
423		if (reason == GUI_MENU_EXIT_ACCEPT) {
424			switch (((int) item->data) & RUNNER_COMMAND_MASK) {
425			case RUNNER_EXIT:
426				running = false;
427				keys = 0;
428				break;
429			case RUNNER_RESET:
430				runner->core->reset(runner->core);
431				break;
432			case RUNNER_SAVE_STATE:
433				mCoreSaveState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA);
434				break;
435			case RUNNER_LOAD_STATE:
436				mCoreLoadState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT);
437				break;
438			case RUNNER_SCREENSHOT:
439				mCoreTakeScreenshot(runner->core);
440				break;
441			case RUNNER_CONFIG:
442				mGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
443				break;
444			case RUNNER_CONTINUE:
445				break;
446			}
447		}
448		int frames = 0;
449		GUIPollInput(&runner->params, 0, &keys);
450		while (keys && frames < 30) {
451			++frames;
452			runner->params.drawStart();
453			runner->drawFrame(runner, true);
454			runner->params.drawEnd();
455			GUIPollInput(&runner->params, 0, &keys);
456		}
457		if (runner->unpaused) {
458			runner->unpaused(runner);
459		}
460	}
461	mLOG(GUI_RUNNER, DEBUG, "Shutting down...");
462	if (runner->gameUnloaded) {
463		runner->gameUnloaded(runner);
464	}
465	mLOG(GUI_RUNNER, DEBUG, "Unloading game...");
466	runner->core->unloadROM(runner->core);
467	drawState.screenshotId = 0;
468	if (drawState.screenshot) {
469		unsigned w, h;
470		runner->core->desiredVideoDimensions(runner->core, &w, &h);
471		mappedMemoryFree(drawState.screenshot, w * h * 4);
472	}
473
474	if (runner->config.port) {
475		mLOG(GUI_RUNNER, DEBUG, "Saving key sources...");
476		if (runner->keySources) {
477			size_t i;
478			for (i = 0; runner->keySources[i].id; ++i) {
479				mInputMapSave(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
480				mInputMapSave(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
481			}
482		}
483		mCoreConfigSave(&runner->config);
484	}
485	mInputMapDeinit(&runner->core->inputMap);
486	mLOG(GUI_RUNNER, DEBUG, "Deinitializing core...");
487	runner->core->deinit(runner->core);
488
489	GUIMenuItemListDeinit(&pauseMenu.items);
490	GUIMenuItemListDeinit(&stateSaveMenu.items);
491	GUIMenuItemListDeinit(&stateLoadMenu.items);
492	mLOG(GUI_RUNNER, INFO, "Game stopped!");
493}
494
495void mGUIRunloop(struct mGUIRunner* runner) {
496	if (runner->keySources) {
497		mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
498		size_t i;
499		for (i = 0; runner->keySources[i].id; ++i) {
500			mInputMapLoad(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
501		}
502	}
503	while (true) {
504		char path[PATH_MAX];
505		if (!GUISelectFile(&runner->params, path, sizeof(path), 0)) {
506			break;
507		}
508		mCoreConfigSetValue(&runner->config, "lastDirectory", runner->params.currentPath);
509		mCoreConfigSave(&runner->config);
510		mGUIRun(runner, path);
511	}
512}