all repos — mgba @ 000f232c582b0981b66d48d7af799e97faffad8e

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 <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
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		mCoreConfigInit(&runner->core->config, runner->port);
287		mInputMapInit(&runner->core->inputMap, &GBAInputInfo);
288		found = mCoreLoadFile(runner->core, path);
289		if (!found) {
290			mLOG(GUI_RUNNER, WARN, "Failed to load %s!", path);
291			runner->core->deinit(runner->core);
292		}
293	}
294
295	if (!found) {
296		mLOG(GUI_RUNNER, WARN, "Failed to find core for %s!", path);
297		GUIShowMessageBox(&runner->params, GUI_MESSAGE_BOX_OK, 240, "Load failed!");
298		return;
299	}
300	if (runner->core->platform(runner->core) == PLATFORM_GBA) {
301		((struct GBA*) runner->core->board)->luminanceSource = &runner->luminanceSource.d;
302	}
303	mLOG(GUI_RUNNER, DEBUG, "Loading config...");
304	mCoreLoadForeignConfig(runner->core, &runner->config);
305	logger.logLevel = runner->core->opts.logLevel;
306
307	mLOG(GUI_RUNNER, DEBUG, "Loading save...");
308	mCoreAutoloadSave(runner->core);
309	if (runner->setup) {
310		mLOG(GUI_RUNNER, DEBUG, "Setting up runner...");
311		runner->setup(runner);
312	}
313	if (runner->config.port && runner->keySources) {
314		mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
315		size_t i;
316		for (i = 0; runner->keySources[i].id; ++i) {
317			mInputMapLoad(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
318		}
319	}
320	mLOG(GUI_RUNNER, DEBUG, "Reseting...");
321	runner->core->reset(runner->core);
322	mLOG(GUI_RUNNER, DEBUG, "Reset!");
323	bool running = true;
324	if (runner->gameLoaded) {
325		runner->gameLoaded(runner);
326	}
327	mLOG(GUI_RUNNER, INFO, "Game starting");
328	while (running) {
329		CircleBufferClear(&runner->fpsBuffer);
330		runner->totalDelta = 0;
331		runner->fps = 0;
332		struct timeval tv;
333		gettimeofday(&tv, 0);
334		runner->lastFpsCheck = 1000000LL * tv.tv_sec + tv.tv_usec;
335
336		while (true) {
337#ifdef _3DS
338			running = aptMainLoop();
339			if (!running) {
340				break;
341			}
342#endif
343			uint32_t guiKeys;
344			uint32_t heldKeys;
345			GUIPollInput(&runner->params, &guiKeys, &heldKeys);
346			if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
347				break;
348			}
349			if (guiKeys & (1 << mGUI_INPUT_INCREASE_BRIGHTNESS)) {
350				if (runner->luminanceSource.luxLevel < 10) {
351					++runner->luminanceSource.luxLevel;
352				}
353			}
354			if (guiKeys & (1 << mGUI_INPUT_DECREASE_BRIGHTNESS)) {
355				if (runner->luminanceSource.luxLevel > 0) {
356					--runner->luminanceSource.luxLevel;
357				}
358			}
359			if (guiKeys & (1 << mGUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) {
360				runner->incrementScreenMode(runner);
361			}
362			if (guiKeys & (1 << mGUI_INPUT_SCREENSHOT)) {
363				mCoreTakeScreenshot(runner->core);
364			}
365			if (heldKeys & (1 << mGUI_INPUT_FAST_FORWARD)) {
366				runner->setFrameLimiter(runner, false);
367			} else {
368				runner->setFrameLimiter(runner, true);
369			}
370			uint16_t keys = runner->pollGameInput(runner);
371			if (runner->prepareForFrame) {
372				runner->prepareForFrame(runner);
373			}
374			runner->core->setKeys(runner->core, keys);
375			runner->core->runFrame(runner->core);
376			if (runner->drawFrame) {
377				int drawFps = false;
378				mCoreConfigGetIntValue(&runner->config, "fpsCounter", &drawFps);
379
380				runner->params.drawStart();
381				runner->drawFrame(runner, false);
382				if (drawFps) {
383					if (runner->params.guiPrepare) {
384						runner->params.guiPrepare();
385					}
386					GUIFontPrintf(runner->params.font, 0, GUIFontHeight(runner->params.font), GUI_ALIGN_LEFT, 0x7FFFFFFF, "%.2f fps", runner->fps);
387					if (runner->params.guiFinish) {
388						runner->params.guiFinish();
389					}
390				}
391				runner->params.drawEnd();
392
393				if (runner->core->frameCounter(runner->core) % FPS_GRANULARITY == 0) {
394					if (drawFps) {
395						struct timeval tv;
396						gettimeofday(&tv, 0);
397						uint64_t t = 1000000LL * tv.tv_sec + tv.tv_usec;
398						uint64_t delta = t - runner->lastFpsCheck;
399						runner->lastFpsCheck = t;
400						if (delta > 0x7FFFFFFFLL) {
401							CircleBufferClear(&runner->fpsBuffer);
402							runner->fps = 0;
403						}
404						if (CircleBufferSize(&runner->fpsBuffer) == CircleBufferCapacity(&runner->fpsBuffer)) {
405							int32_t last;
406							CircleBufferRead32(&runner->fpsBuffer, &last);
407							runner->totalDelta -= last;
408						}
409						CircleBufferWrite32(&runner->fpsBuffer, delta);
410						runner->totalDelta += delta;
411						runner->fps = (CircleBufferSize(&runner->fpsBuffer) * FPS_GRANULARITY * 1000000.0f) / (runner->totalDelta * sizeof(uint32_t));
412					}
413				}
414			}
415		}
416
417		if (runner->paused) {
418			runner->paused(runner);
419		}
420		GUIInvalidateKeys(&runner->params);
421		uint32_t keys = 0xFFFFFFFF; // Huge hack to avoid an extra variable!
422		struct GUIMenuItem* item;
423		enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
424		if (reason == GUI_MENU_EXIT_ACCEPT) {
425			switch (((int) item->data) & RUNNER_COMMAND_MASK) {
426			case RUNNER_EXIT:
427				running = false;
428				keys = 0;
429				break;
430			case RUNNER_RESET:
431				runner->core->reset(runner->core);
432				break;
433			case RUNNER_SAVE_STATE:
434				mCoreSaveState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT | SAVESTATE_SAVEDATA);
435				break;
436			case RUNNER_LOAD_STATE:
437				mCoreLoadState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT | SAVESTATE_RTC);
438				break;
439			case RUNNER_SCREENSHOT:
440				mCoreTakeScreenshot(runner->core);
441				break;
442			case RUNNER_CONFIG:
443				mGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
444				break;
445			case RUNNER_CONTINUE:
446				break;
447			}
448		}
449		int frames = 0;
450		GUIPollInput(&runner->params, 0, &keys);
451		while (keys && frames < 30) {
452			++frames;
453			runner->params.drawStart();
454			runner->drawFrame(runner, true);
455			runner->params.drawEnd();
456			GUIPollInput(&runner->params, 0, &keys);
457		}
458		if (runner->unpaused) {
459			runner->unpaused(runner);
460		}
461	}
462	mLOG(GUI_RUNNER, DEBUG, "Shutting down...");
463	if (runner->gameUnloaded) {
464		runner->gameUnloaded(runner);
465	}
466	mLOG(GUI_RUNNER, DEBUG, "Unloading game...");
467	runner->core->unloadROM(runner->core);
468	drawState.screenshotId = 0;
469	if (drawState.screenshot) {
470		unsigned w, h;
471		runner->core->desiredVideoDimensions(runner->core, &w, &h);
472		mappedMemoryFree(drawState.screenshot, w * h * 4);
473	}
474
475	if (runner->config.port) {
476		mLOG(GUI_RUNNER, DEBUG, "Saving key sources...");
477		if (runner->keySources) {
478			size_t i;
479			for (i = 0; runner->keySources[i].id; ++i) {
480				mInputMapSave(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
481				mInputMapSave(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
482			}
483		}
484		mCoreConfigSave(&runner->config);
485	}
486	mInputMapDeinit(&runner->core->inputMap);
487	mLOG(GUI_RUNNER, DEBUG, "Deinitializing core...");
488	runner->core->deinit(runner->core);
489
490	GUIMenuItemListDeinit(&pauseMenu.items);
491	GUIMenuItemListDeinit(&stateSaveMenu.items);
492	GUIMenuItemListDeinit(&stateLoadMenu.items);
493	mLOG(GUI_RUNNER, INFO, "Game stopped!");
494}
495
496void mGUIRunloop(struct mGUIRunner* runner) {
497	if (runner->keySources) {
498		mLOG(GUI_RUNNER, DEBUG, "Loading key sources for %s...", runner->config.port);
499		size_t i;
500		for (i = 0; runner->keySources[i].id; ++i) {
501			mInputMapLoad(&runner->params.keyMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->config));
502		}
503	}
504	while (true) {
505		char path[PATH_MAX];
506		if (!GUISelectFile(&runner->params, path, sizeof(path), 0)) {
507			break;
508		}
509		mCoreConfigSetValue(&runner->config, "lastDirectory", runner->params.currentPath);
510		mCoreConfigSave(&runner->config);
511		mGUIRun(runner, path);
512	}
513}