diff --git a/Makefile.emscripten b/Makefile.emscripten index 7a67c5b8ea..2dae31fbba 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -41,6 +41,8 @@ HAVE_STATIC_VIDEO_FILTERS = 1 HAVE_STATIC_AUDIO_FILTERS = 1 HAVE_STB_FONT = 1 HAVE_CONFIGFILE = 1 +HAVE_COMMAND = 1 +HAVE_STDIN_CMD = 1 HAVE_CHEATS = 1 HAVE_IBXM = 1 HAVE_CORE_INFO_CACHE = 1 diff --git a/pkg/emscripten/libretro/libretro.js b/pkg/emscripten/libretro/libretro.js index 5240f07eff..48a3e233c8 100644 --- a/pkg/emscripten/libretro/libretro.js +++ b/pkg/emscripten/libretro/libretro.js @@ -191,16 +191,43 @@ function uploadData(data,name) FS.unlink(name); } +var encoder = new TextEncoder(); +var message_queue = []; + +function retroArchSend(msg) { + var bytes = encoder.encode(msg+"\n"); + message_queue.push([bytes,0]); +} + var Module = { noInitialRun: true, arguments: ["-v", "--menu"], - preRun: [], + preRun: [ + function() { + function stdin() { + // Return ASCII code of character, or null if no input + while(message_queue.length > 0){ + var msg = message_queue[0][0]; + var index = message_queue[0][1]; + if(index >= msg.length) { + message_queue.shift(); + } else { + message_queue[0][1] = index+1; + // assumption: msg is a uint8array + return msg[index]; + } + } + return null; + } + FS.init(stdin); + } + ], postRun: [], onRuntimeInitialized: function() { appInitialized(); - }, + }, print: function(text) { console.log(text);