"use strict"; var loaded = {} function load(modulename) { if (!loaded[modulename]) { importScripts(modulename+".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(); }; var window = noop(); window.CSSStyleDeclaration = noop(); window.CSSStyleDeclaration.setProperty = noop(); window.Element = noop(); window.Element.setAttribute = noop(); window.Element.setAttributeNS = noop(); window.navigator = noop(); var document = noop(); document.documentElement = noop(); document.documentElement.style = noop(); // load filesystems for CC65 and others asynchronously var fsMeta, fsBlob; { var xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; xhr.open("GET", "fs65.data", false); // synchronous request xhr.send(null); fsBlob = xhr.response; xhr = new XMLHttpRequest(); xhr.responseType = 'json'; xhr.open("GET", "fs65.js.metadata", false); // synchronous request xhr.send(null); fsMeta = xhr.response; console.log("Loaded filesystem", fsMeta.files.length, 'files', fsBlob.size, 'bytes'); } // mount the filesystem at /share function setupFS(FS) { FS.mkdir('/share'); FS.mount(FS.filesystems['WORKERFS'], { packages: [{ metadata: fsMeta, blob: fsBlob }] }, '/share'); } function extractErrors(strings, regex) { var errors = []; for (var i=0; i= 0) { errors.push({ line:linenum, msg:"Unresolved symbol '" + key + "'" }); } } } var errm = errorMatch.exec(line); if (errm) { errors.push({ line:parseInt(errm[1]), msg:errm[2] }) } } return {lines:lines, errors:errors}; } function assembleDASM(code) { load("dasm"); var re_usl = /(\w+)\s+0000\s+[?][?][?][?]/; var unresolved = {}; function match_fn(s) { var matches = re_usl.exec(s); if (matches) { unresolved[matches[1]] = 0; } } var Module = DASM({ noInitialRun:true, print:match_fn }); var FS = Module['FS']; FS.writeFile(DASM_MAIN_FILENAME, DASM_PREAMBLE + code); Module.callMain([DASM_MAIN_FILENAME, "-v3", "-la.lst"]); var aout = FS.readFile("a.out"); var alst = FS.readFile("a.lst", {'encoding':'utf8'}); var listing = parseDASMListing(alst, unresolved); return { exitstatus:Module.EXITSTATUS, output:aout.slice(2), lines:listing.lines, errors:listing.errors, intermediate:{listing:alst}, }; } // TODO: not quite done function assembleACME(code) { load("acme"); // stderr var re_err2 = /(Error|Warning) - File (.+?), line (\d+) ([^:]+) (.*)/; var errors = []; var errline = 0; function match_fn(s) { var matches = re_err2.exec(s); if (matches) { errors.push({ line:1, // TODO: parseInt(matches[3]), msg:matches[0] // TODO: matches[5] }); } } var Module = ACME({ noInitialRun:true, print:match_fn, printErr:match_fn }); var FS = Module['FS']; FS.writeFile("main.a", code); // TODO: --msvc Module.callMain(["-o", "a.out", "-r", "a.rpt", "-l", "a.sym", "--setpc", "24576", "main.a"]); if (errors.length) { return {errors:errors}; } var aout = FS.readFile("a.out"); var alst = FS.readFile("a.rpt", {'encoding':'utf8'}); var asym = FS.readFile("a.sym", {'encoding':'utf8'}); var listing = parseDASMListing(alst, {}); // TODO return { exitstatus:Module.EXITSTATUS, output:aout, lines:listing.lines, errors:listing.errors, intermediate:{listing:alst, symbols:asym}, }; } function setupStdin(fs, code) { var i = 0; fs.init( function() { return i