From 677f21b0eeb8f9ce56fc509fa174559b6a0d3e67 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Tue, 7 May 2024 23:36:00 +0200 Subject: [PATCH 1/2] Allow more callbacks for incoming data from the emulator --- lib/emulator.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/emulator.js b/lib/emulator.js index f7c82ec..db2621b 100644 --- a/lib/emulator.js +++ b/lib/emulator.js @@ -13,10 +13,15 @@ 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); } exports.init = function(options) { @@ -29,8 +34,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); From be09dc48b42319878c6ec440cdc75ecdd404ec86 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 9 May 2024 14:59:25 +0100 Subject: [PATCH 2/2] comments --- lib/emulator.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/emulator.js b/lib/emulator.js index db2621b..10d5524 100644 --- a/lib/emulator.js +++ b/lib/emulator.js @@ -24,6 +24,15 @@ function onConsoleOutput(txt) { 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;