add command and stdin_cmd features to emscripten RA. update libretro.js to show how commands could be sent over emscripten stdin. (#15017)

Co-authored-by: Joseph C. Osborn <jcoa2018@pomona.edu>
This commit is contained in:
Joe Osborn 2023-02-24 13:06:04 -08:00 committed by GitHub
parent d4677790eb
commit e1afca5392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -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);