Skip to content

Commit

Permalink
Merge pull request #63 from halemmerich/emulator
Browse files Browse the repository at this point in the history
Allow more callbacks for incoming data from the emulator
  • Loading branch information
gfwilliams authored May 9, 2024
2 parents 7e90950 + be09dc4 commit e892f68
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ var factoryFlashMemory;
// Log of messages from app
var appLog = "";
var lastOutputLine = "";
var consoleOutputCallback;

function onConsoleOutput(txt) {
appLog += txt + "\n";
lastOutputLine = txt;
if (consoleOutputCallback)
consoleOutputCallback(txt);
else
console.log("EMSCRIPTEN:", txt);
}

/* Initialise the emulator,
options = {
EMULATOR : "banglejs"/"banglejs2"
DEVICEID : "BANGLEJS"/"BANGLEJS2"
rxCallback : function(int) - called every time a character received
consoleOutputCallback : function(str) - called when a while line is received
}
*/
exports.init = function(options) {
if (options.EMULATOR)
EMULATOR = options.EMULATOR;
Expand All @@ -29,8 +43,10 @@ exports.init = function(options) {
eval(require("fs").readFileSync(DIR_IDE + "/emu/emu_"+EMULATOR+".js").toString());
eval(require("fs").readFileSync(DIR_IDE + "/emu/common.js").toString()/*.replace('console.log("EMSCRIPTEN:"', '//console.log("EMSCRIPTEN:"')*/);

jsRXCallback = function() {};
jsRXCallback = options.rxCallback ? options.rxCallback : function() {};
jsUpdateGfx = function() {};
if (options.consoleOutputCallback)
consoleOutputCallback = options.consoleOutputCallback;

factoryFlashMemory = new Uint8Array(FLASH_SIZE);
factoryFlashMemory.fill(255);
Expand Down

0 comments on commit e892f68

Please sign in to comment.