diff --git a/lib/emulator.js b/lib/emulator.js index f7c82ec..10d5524 100644 --- a/lib/emulator.js +++ b/lib/emulator.js @@ -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; @@ -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);