From fa50f7b080f1de64e1859d1694ea79c143945c58 Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Sat, 22 Feb 2025 10:45:23 -0800 Subject: [PATCH] fixup upload paths, show use of new emscripten cmd interface --- pkg/emscripten/libretro-thread/libretro.js | 61 ++----------------- .../libretro-thread/libretro.worker.js | 2 +- 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/pkg/emscripten/libretro-thread/libretro.js b/pkg/emscripten/libretro-thread/libretro.js index 8d0a3e87407..e5cb6d0e178 100644 --- a/pkg/emscripten/libretro-thread/libretro.js +++ b/pkg/emscripten/libretro-thread/libretro.js @@ -14,64 +14,15 @@ var Module = { noImageDecoding: true, noAudioDecoding: true, - encoder: new TextEncoder(), - message_queue: [], - message_out: [], - message_accum: "", - - retroArchSend: function(msg) { - let bytes = this.encoder.encode(msg + "\n"); - this.message_queue.push([bytes, 0]); - }, - retroArchRecv: function() { - let out = this.message_out.shift(); - if (out == null && this.message_accum != "") { - out = this.message_accum; - this.message_accum = ""; - } - return out; - }, + retroArchSend: function(msg) { + this.EmscriptenSendCommand(msg); + }, + retroArchRecv: function() { + return this.EmscriptenReceiveCommandReply(); + }, preRun: [ function(module) { Module.ENV['OPFS'] = "/home/web_user/retroarch"; - }, - function(module) { - function stdin() { - // Return ASCII code of character, or null if no input - while (module.message_queue.length > 0) { - var msg = module.message_queue[0][0]; - var index = module.message_queue[0][1]; - if (index >= msg.length) { - module.message_queue.shift(); - } else { - module.message_queue[0][1] = index + 1; - // assumption: msg is a uint8array - return msg[index]; - } - } - return null; - } - - function stdout(c) { - if (c == null) { - // flush - if (module.message_accum != "") { - module.message_out.push(module.message_accum); - module.message_accum = ""; - } - } else { - let s = String.fromCharCode(c); - if (s == "\n") { - if (module.message_accum != "") { - module.message_out.push(module.message_accum); - module.message_accum = ""; - } - } else { - module.message_accum = module.message_accum + s; - } - } - } - module.FS.init(stdin, stdout); } ], postRun: [], diff --git a/pkg/emscripten/libretro-thread/libretro.worker.js b/pkg/emscripten/libretro-thread/libretro.worker.js index cbb24c6862e..f7d5954a433 100644 --- a/pkg/emscripten/libretro-thread/libretro.worker.js +++ b/pkg/emscripten/libretro-thread/libretro.worker.js @@ -60,7 +60,7 @@ onmessage = async (msg) => { } postMessage({command:"loaded_bundle", time:resp.headers.get("last-modified")}); } else if(msg.data.command == "upload_file") { - await writeFile("/home/web_user/retroarch/userdata/content/"+msg.data.name, new Uint8Array(msg.data.data)); + await writeFile("userdata/content/"+msg.data.name, new Uint8Array(msg.data.data)); postMessage({command:"uploaded_file",name:msg.data.name}); } }