Skip to content

Commit

Permalink
fixup upload paths, show use of new emscripten cmd interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeOsborn committed Feb 22, 2025
1 parent 5e870ec commit fa50f7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
61 changes: 6 additions & 55 deletions pkg/emscripten/libretro-thread/libretro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
2 changes: 1 addition & 1 deletion pkg/emscripten/libretro-thread/libretro.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

0 comments on commit fa50f7b

Please sign in to comment.