From 00d6b8aefaa0d74e125cded8a797a80f690027fe Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 5 Nov 2017 13:34:00 -0500 Subject: [PATCH] trying to get MAME debugging and WASM working to no avail --- emsrc/sdcc/boost.sh | 4 ++-- emsrc/sdcc/emcc-local.sh | 2 +- emsrc/sdcc/howto.txt | 6 +++++ src/emu.js | 16 ++++++++++++- src/worker/workermain.js | 50 +++++++++++++++++++++++++++++++--------- 5 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 emsrc/sdcc/howto.txt diff --git a/emsrc/sdcc/boost.sh b/emsrc/sdcc/boost.sh index d63fa069..11a46af7 100644 --- a/emsrc/sdcc/boost.sh +++ b/emsrc/sdcc/boost.sh @@ -2,7 +2,7 @@ rm -fr /tmp/boost mkdir /tmp/boost cd /tmp/boost -tar xjf ~/PuzzlingPlans/8bitworkshop/emsrc/sdcc/boost* +tar xjf ~/PuzzlingPlans/8bitworkshop/emsrc/sdcc/boost*.bz2 cd boost_1_63_0 emconfigure ./bootstrap.sh -emmake ./b2 install --prefix=/home/huggvey/emsdk-portable/emscripten/1.37.9/system --with-graph link=static variant=release threading=single runtime-link=static +emmake ./b2 install --prefix=$EMSCRIPTEN/system --with-graph link=static variant=release threading=single runtime-link=static diff --git a/emsrc/sdcc/emcc-local.sh b/emsrc/sdcc/emcc-local.sh index b4bf77db..72058a35 100644 --- a/emsrc/sdcc/emcc-local.sh +++ b/emsrc/sdcc/emcc-local.sh @@ -45,7 +45,7 @@ emmake make echo Making JS files... popd -mkdir -p ./js +mkdir -p ./js ./wasm cp /tmp/sdcc/sdcc/bin/sdcc js/sdcc.bc cp /tmp/sdcc/sdcc/bin/sdasz80 js/sdasz80.bc cp /tmp/sdcc/sdcc/bin/sdldz80 js/sdldz80.bc diff --git a/emsrc/sdcc/howto.txt b/emsrc/sdcc/howto.txt new file mode 100644 index 00000000..5fe19944 --- /dev/null +++ b/emsrc/sdcc/howto.txt @@ -0,0 +1,6 @@ + +1. Install Emscripten + a. bash boost.sh +2. Install texinfo +3. cp Makefile.local and emcc-local.sh to ~/sdcc +4. bash emcc-local.sh diff --git a/src/emu.js b/src/emu.js index 60c11fdb..c0842f88 100644 --- a/src/emu.js +++ b/src/emu.js @@ -946,7 +946,7 @@ var BaseMAMEPlatform = function() { var script = document.createElement('script'); window.JSMESS = {}; window.Module = { - arguments: [opts.driver, '-verbose', '-window', '-nokeepaspect', '-resolution', canvas.width+'x'+canvas.height, '-cart', romfn], + arguments: [opts.driver, '-debug', '-verbose', '-window', '-nokeepaspect', '-resolution', canvas.width+'x'+canvas.height, '-cart', romfn], screenIsReadOnly: true, print: bufferConsoleOutput, canvas:video.canvas, @@ -966,6 +966,7 @@ var BaseMAMEPlatform = function() { } FS.mkdir('/emulator'); FS.writeFile(romfn, romdata, {encoding:'binary'}); + FS.writeFile('/debug.ini', 'debugger none\n', {encoding:'utf8'}); if (opts.preInit) { opts.preInit(self); } @@ -1042,8 +1043,21 @@ var BaseMAMEPlatform = function() { return parseInt(console_vars.v[0]); } + // DEBUGGING SUPPORT + + var onBreakpointHit; + this.getDebugCallback = function() { // TODO } + this.setupDebug = function(callback) { + onBreakpointHit = callback; + } + this.step = function() { + self.readAddress(0); + //self.luacall('cpu.debug()\n') + self.luacall('debugger = manager:machine().debugger()') + self.luacall('print(debugger)') // TODO + } } diff --git a/src/worker/workermain.js b/src/worker/workermain.js index 0c171ee3..19156568 100644 --- a/src/worker/workermain.js +++ b/src/worker/workermain.js @@ -82,13 +82,6 @@ var PLATFORM_PARAMS = { }, }; -var loaded = {} -function load(modulename, debug) { - if (!loaded[modulename]) { - importScripts(modulename+(debug?"."+debug+".js":".js")); - loaded[modulename] = 1; - } -} // shim out window and document objects for security // https://github.com/mbostock/d3/issues/1053 var noop = function() { return new Function(); }; @@ -105,6 +98,7 @@ document.documentElement.style = noop(); var fsMeta = {}; var fsBlob = {}; +var wasmBlob = {}; // load filesystems for CC65 and others asynchronously function loadFilesystem(name) { @@ -121,6 +115,30 @@ function loadFilesystem(name) { console.log("Loaded "+name+" filesystem", fsMeta[name].files.length, 'files', fsBlob[name].size, 'bytes'); } +var loaded = {} +function load(modulename, debug) { + if (!loaded[modulename]) { + importScripts(modulename+(debug?"."+debug+".js":".js")); + loaded[modulename] = 1; + } +} +function loadWASM(modulename, debug) { + if (!loaded[modulename]) { + importScripts("wasm/" + modulename+(debug?"."+debug+".js":".js")); + var xhr = new XMLHttpRequest(); + xhr.responseType = 'arraybuffer'; + xhr.open("GET", "wasm/"+modulename+".wasm", false); // synchronous request + xhr.send(null); + if (xhr.response) { + wasmBlob[modulename] = xhr.response; //new Uint8Array(xhr.response); + console.log("Loaded " + modulename + ".wasm"); + loaded[modulename] = 1; + } else { + throw Error("Could not load WASM file"); + } + } +} + var ATARI_CFG = "FEATURES {\nSTARTADDRESS: default = $9000;\n}\n" + "MEMORY {\n" @@ -781,21 +799,31 @@ function assemblelinkSDASZ80(code, platform) { } } +var sdcc; function compileSDCC(code, platform) { var preproc = preprocessMCPP(code, platform); if (preproc.errors) return preproc; else code = preproc.code; - load("sdcc"); - //load("wasm/sdcc"); - //console.profile("sdcc"); var params = PLATFORM_PARAMS[platform]; if (!params) throw Error("Platform not supported: " + platform); + + load("sdcc"); + //loadWASM("sdcc"); + //var wasmmod = new WebAssembly.Module(wasmBlob['sdcc']); + //var wasminst = new WebAssembly.Instance(wasmmod); + //var webasm = WebAssembly.instantiate(wasmBlob['sdcc']).then(foo => console.log(foo)); var SDCC = sdcc({ + instantiateWasm: function(info, recv) { + var inst = new WebAssembly.Instance(wasmmod, info); + recv(inst); + return true; + }, + //wasmBinary: wasmBlob['sdcc'], noInitialRun:true, noFSInit:true, print:print_fn, - printErr:match_msvc, + printErr:match_msvc, // console.log TOTAL_MEMORY:256*1024*1024, }); var FS = SDCC['FS'];