2017-01-06 00:14:12 +00:00
|
|
|
"use strict";
|
2017-01-09 21:28:20 +00:00
|
|
|
|
2017-01-26 05:09:57 +00:00
|
|
|
var PLATFORM_PARAMS = {
|
|
|
|
'mw8080bw': {
|
|
|
|
code_start: 0x0,
|
|
|
|
code_size: 0x2000,
|
|
|
|
data_start: 0x2000,
|
|
|
|
data_size: 0x400,
|
|
|
|
},
|
|
|
|
'vicdual': {
|
|
|
|
code_start: 0x0,
|
|
|
|
code_size: 0x4000,
|
2017-02-18 22:50:51 +00:00
|
|
|
data_start: 0xe400,
|
2017-01-26 05:09:57 +00:00
|
|
|
data_size: 0x400,
|
|
|
|
},
|
|
|
|
'galaxian': {
|
|
|
|
code_start: 0x0,
|
|
|
|
code_size: 0x4000,
|
|
|
|
data_start: 0x4000,
|
|
|
|
data_size: 0x400,
|
|
|
|
},
|
2017-02-15 21:03:52 +00:00
|
|
|
'galaxian-scramble': {
|
|
|
|
code_start: 0x0,
|
|
|
|
code_size: 0x5020,
|
|
|
|
data_start: 0x4000,
|
|
|
|
data_size: 0x400,
|
|
|
|
},
|
2017-01-29 21:06:05 +00:00
|
|
|
'williams-z80': {
|
|
|
|
code_start: 0x0,
|
|
|
|
code_size: 0x9000,
|
|
|
|
data_start: 0x9000,
|
|
|
|
data_size: 0x3000,
|
|
|
|
},
|
2017-02-05 04:19:54 +00:00
|
|
|
'vector-z80color': {
|
2017-02-01 18:21:17 +00:00
|
|
|
code_start: 0x0,
|
2017-02-05 04:19:54 +00:00
|
|
|
code_size: 0x8000,
|
|
|
|
data_start: 0xe000,
|
|
|
|
data_size: 0x2000,
|
2017-02-01 18:21:17 +00:00
|
|
|
},
|
2017-01-26 05:09:57 +00:00
|
|
|
};
|
|
|
|
|
2017-01-14 02:31:04 +00:00
|
|
|
var loaded = {}
|
|
|
|
function load(modulename) {
|
|
|
|
if (!loaded[modulename]) {
|
|
|
|
importScripts(modulename+".js");
|
|
|
|
loaded[modulename] = 1;
|
|
|
|
}
|
|
|
|
}
|
2017-01-10 08:18:54 +00:00
|
|
|
// 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();
|
|
|
|
|
2017-01-23 21:21:45 +00:00
|
|
|
var fsMeta = {};
|
|
|
|
var fsBlob = {};
|
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
// load filesystems for CC65 and others asynchronously
|
2017-01-23 21:21:45 +00:00
|
|
|
function loadFilesystem(name) {
|
2017-01-06 00:14:12 +00:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'blob';
|
2017-01-23 21:21:45 +00:00
|
|
|
xhr.open("GET", "fs"+name+".data", false); // synchronous request
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr.send(null);
|
2017-01-23 21:21:45 +00:00
|
|
|
fsBlob[name] = xhr.response;
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'json';
|
2017-01-23 21:21:45 +00:00
|
|
|
xhr.open("GET", "fs"+name+".js.metadata", false); // synchronous request
|
2017-01-06 00:14:12 +00:00
|
|
|
xhr.send(null);
|
2017-01-23 21:21:45 +00:00
|
|
|
fsMeta[name] = xhr.response;
|
|
|
|
console.log("Loaded "+name+" filesystem", fsMeta[name].files.length, 'files', fsBlob[name].size, 'bytes');
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
// mount the filesystem at /share
|
2017-01-23 21:21:45 +00:00
|
|
|
function setupFS(FS, name) {
|
2017-01-06 00:14:12 +00:00
|
|
|
FS.mkdir('/share');
|
|
|
|
FS.mount(FS.filesystems['WORKERFS'], {
|
2017-01-23 21:21:45 +00:00
|
|
|
packages: [{ metadata: fsMeta[name], blob: fsBlob[name] }]
|
2017-01-06 00:14:12 +00:00
|
|
|
}, '/share');
|
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
|
2017-01-04 21:07:59 +00:00
|
|
|
var DASM_MAIN_FILENAME = "main.a";
|
|
|
|
var DASM_PREAMBLE = "\tprocessor 6502\n";
|
|
|
|
var DASM_PREAMBLE_LINES = 1;
|
2016-12-16 01:21:51 +00:00
|
|
|
|
2017-01-12 16:22:27 +00:00
|
|
|
var print_fn = function(s) {
|
|
|
|
console.log(s);
|
|
|
|
//console.log(new Error().stack);
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
|
2017-01-13 02:21:35 +00:00
|
|
|
// test.c(6) : warning 85: in function main unreferenced local variable : 'x'
|
2017-01-16 15:35:19 +00:00
|
|
|
// main.a (4): error: Unknown Mnemonic 'xxx'.
|
2017-01-22 14:35:04 +00:00
|
|
|
// at 2: warning 190: ISO C forbids an empty source file
|
2017-01-16 15:35:19 +00:00
|
|
|
var re_msvc = /([^(]+)\s*[(](\d+)[)]\s*:\s*(.+?):\s*(.*)/;
|
|
|
|
var re_msvc2 = /\s*(at)\s+(\d+)\s*(:)\s*(.*)/;
|
2017-01-13 02:21:35 +00:00
|
|
|
var msvc_errors;
|
|
|
|
|
|
|
|
function match_msvc(s) {
|
2017-01-15 03:46:12 +00:00
|
|
|
var matches = re_msvc.exec(s) || re_msvc2.exec(s);
|
2017-01-13 02:21:35 +00:00
|
|
|
if (matches) {
|
2017-01-16 15:35:19 +00:00
|
|
|
var errline = parseInt(matches[2]);
|
2017-01-14 02:31:04 +00:00
|
|
|
msvc_errors.push({
|
2017-01-13 02:21:35 +00:00
|
|
|
line:errline,
|
2017-02-20 23:50:29 +00:00
|
|
|
file:matches[1],
|
2017-02-01 18:21:17 +00:00
|
|
|
type:matches[3],
|
2017-01-16 15:35:19 +00:00
|
|
|
msg:matches[4]
|
2017-01-13 02:21:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 21:21:45 +00:00
|
|
|
function makeErrorMatcher(errors, regex, iline, imsg) {
|
|
|
|
return function(s) {
|
|
|
|
var matches = regex.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errors.push({
|
|
|
|
line:parseInt(matches[iline]),
|
|
|
|
msg:matches[imsg]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function extractErrors(regex, strings) {
|
|
|
|
var errors = [];
|
|
|
|
var matcher = makeErrorMatcher(errors, regex, 1, 2);
|
|
|
|
for (var i=0; i<strings.length; i++) {
|
|
|
|
matcher(strings[i]);
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:46:12 +00:00
|
|
|
function parseListing(code, lineMatch, iline, ioffset, iinsns) {
|
2017-01-14 02:31:04 +00:00
|
|
|
var lines = [];
|
|
|
|
for (var line of code.split(/\r?\n/)) {
|
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
2017-01-15 03:46:12 +00:00
|
|
|
var linenum = parseInt(linem[iline]);
|
|
|
|
var offset = parseInt(linem[ioffset], 16);
|
|
|
|
var insns = linem[iinsns];
|
2017-01-14 02:31:04 +00:00
|
|
|
if (insns) {
|
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
|
|
|
offset:offset,
|
|
|
|
insns:insns,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2017-01-15 18:31:52 +00:00
|
|
|
function parseSourceLines(code, lineMatch, offsetMatch) {
|
|
|
|
var lines = [];
|
|
|
|
var lastlinenum = 0;
|
|
|
|
for (var line of code.split(/\r?\n/)) {
|
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
lastlinenum = parseInt(linem[1]);
|
|
|
|
} else if (lastlinenum) {
|
|
|
|
var linem = offsetMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
var offset = parseInt(linem[1], 16);
|
|
|
|
lines.push({
|
|
|
|
line:lastlinenum,
|
|
|
|
offset:offset,
|
|
|
|
});
|
|
|
|
lastlinenum = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:07:59 +00:00
|
|
|
function parseDASMListing(code, unresolved) {
|
2016-12-16 01:21:51 +00:00
|
|
|
// 4 08ee a9 00 start lda #01workermain.js:23:5
|
2017-01-16 15:35:19 +00:00
|
|
|
var lineMatch = /\s*(\d+)\s+(\S+)\s+([0-9a-f]+)\s+([0-9a-f][0-9a-f ]+)?\s+(.+)?/;
|
2016-12-16 01:21:51 +00:00
|
|
|
var equMatch = /\bequ\b/;
|
|
|
|
var errors = [];
|
|
|
|
var lines = [];
|
|
|
|
var lastline = 0;
|
|
|
|
for (var line of code.split(/\r?\n/)) {
|
|
|
|
var linem = lineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
2017-01-04 21:07:59 +00:00
|
|
|
var linenum = parseInt(linem[1]) - DASM_PREAMBLE_LINES;
|
2016-12-16 01:21:51 +00:00
|
|
|
var filename = linem[2];
|
|
|
|
var offset = parseInt(linem[3], 16);
|
|
|
|
var insns = linem[4];
|
|
|
|
var restline = linem[5];
|
|
|
|
// inside of main file?
|
2017-01-04 21:07:59 +00:00
|
|
|
if (filename == DASM_MAIN_FILENAME) {
|
2016-12-16 01:21:51 +00:00
|
|
|
if (insns && !restline.match(equMatch)) {
|
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
|
|
|
offset:offset,
|
|
|
|
insns:insns,
|
|
|
|
iscode:restline[0] != '.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
lastline = linenum;
|
|
|
|
} else {
|
|
|
|
// inside of macro or include file
|
2017-01-16 15:35:19 +00:00
|
|
|
if (insns && linem[3] && lastline>0) {
|
2016-12-16 01:21:51 +00:00
|
|
|
lines.push({
|
|
|
|
line:lastline+1,
|
|
|
|
offset:offset,
|
|
|
|
insns:null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: check filename too
|
|
|
|
// TODO: better symbol test (word boundaries)
|
2017-01-03 15:43:40 +00:00
|
|
|
for (var key in unresolved) {
|
2016-12-16 01:21:51 +00:00
|
|
|
var pos = restline ? restline.indexOf(key) : line.indexOf(key);
|
|
|
|
if (pos >= 0) {
|
|
|
|
errors.push({
|
|
|
|
line:linenum,
|
|
|
|
msg:"Unresolved symbol '" + key + "'"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 15:35:19 +00:00
|
|
|
var errm = re_msvc.exec(line);
|
2016-12-16 01:21:51 +00:00
|
|
|
if (errm) {
|
|
|
|
errors.push({
|
2017-01-16 15:35:19 +00:00
|
|
|
line:parseInt(errm[2]),
|
|
|
|
msg:errm[4]
|
2016-12-16 01:21:51 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {lines:lines, errors:errors};
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:07:59 +00:00
|
|
|
function assembleDASM(code) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("dasm");
|
2016-12-16 01:21:51 +00:00
|
|
|
var re_usl = /(\w+)\s+0000\s+[?][?][?][?]/;
|
|
|
|
var unresolved = {};
|
2017-01-06 00:14:12 +00:00
|
|
|
function match_fn(s) {
|
2016-12-16 01:21:51 +00:00
|
|
|
var matches = re_usl.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
unresolved[matches[1]] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var Module = DASM({
|
|
|
|
noInitialRun:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:match_fn
|
2016-12-16 01:21:51 +00:00
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
2017-01-04 21:07:59 +00:00
|
|
|
FS.writeFile(DASM_MAIN_FILENAME, DASM_PREAMBLE + code);
|
2017-01-16 15:35:19 +00:00
|
|
|
Module.callMain([DASM_MAIN_FILENAME, "-la.lst"/*, "-v3", "-sa.sym"*/]);
|
2016-12-16 01:21:51 +00:00
|
|
|
var aout = FS.readFile("a.out");
|
|
|
|
var alst = FS.readFile("a.lst", {'encoding':'utf8'});
|
2017-01-16 15:35:19 +00:00
|
|
|
//var asym = FS.readFile("a.sym", {'encoding':'utf8'});
|
2017-01-04 21:07:59 +00:00
|
|
|
var listing = parseDASMListing(alst, unresolved);
|
2017-01-10 08:18:54 +00:00
|
|
|
return {
|
|
|
|
output:aout.slice(2),
|
2017-01-15 03:46:12 +00:00
|
|
|
lines:listing.lines,
|
|
|
|
errors:listing.errors,
|
2017-01-10 08:18:54 +00:00
|
|
|
intermediate:{listing:alst},
|
|
|
|
};
|
2017-01-04 21:07:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 00:14:12 +00:00
|
|
|
// TODO: not quite done
|
2017-01-04 21:07:59 +00:00
|
|
|
function assembleACME(code) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("acme");
|
2017-01-10 08:18:54 +00:00
|
|
|
// stderr
|
|
|
|
var re_err2 = /(Error|Warning) - File (.+?), line (\d+) ([^:]+) (.*)/;
|
|
|
|
var errors = [];
|
|
|
|
var errline = 0;
|
2017-01-06 00:14:12 +00:00
|
|
|
function match_fn(s) {
|
2017-01-10 08:18:54 +00:00
|
|
|
var matches = re_err2.exec(s);
|
2017-01-04 21:07:59 +00:00
|
|
|
if (matches) {
|
2017-01-10 08:18:54 +00:00
|
|
|
errors.push({
|
|
|
|
line:1, // TODO: parseInt(matches[3]),
|
|
|
|
msg:matches[0] // TODO: matches[5]
|
|
|
|
});
|
2017-01-04 21:07:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var Module = ACME({
|
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
print:match_fn,
|
|
|
|
printErr:match_fn
|
2017-01-04 21:07:59 +00:00
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
|
|
|
FS.writeFile("main.a", code);
|
2017-01-13 02:21:35 +00:00
|
|
|
// TODO: --msvc
|
2017-01-04 21:07:59 +00:00
|
|
|
Module.callMain(["-o", "a.out", "-r", "a.rpt", "-l", "a.sym", "--setpc", "24576", "main.a"]);
|
2017-01-10 08:18:54 +00:00
|
|
|
if (errors.length) {
|
2017-01-15 03:46:12 +00:00
|
|
|
return {errors:errors};
|
2017-01-10 08:18:54 +00:00
|
|
|
}
|
2017-01-04 21:07:59 +00:00
|
|
|
var aout = FS.readFile("a.out");
|
2017-01-13 02:21:35 +00:00
|
|
|
var alst = FS.readFile("a.rpt", {'encoding':'utf8'});
|
|
|
|
var asym = FS.readFile("a.sym", {'encoding':'utf8'});
|
2017-01-15 03:46:12 +00:00
|
|
|
var listing = parseDASMListing(alst, {}); // TODO
|
2017-01-10 08:18:54 +00:00
|
|
|
return {
|
|
|
|
output:aout,
|
2017-01-15 03:46:12 +00:00
|
|
|
lines:listing.lines,
|
|
|
|
errors:listing.errors,
|
2017-01-10 08:18:54 +00:00
|
|
|
intermediate:{listing:alst, symbols:asym},
|
|
|
|
};
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|
|
|
|
|
2017-01-13 02:21:35 +00:00
|
|
|
function setupStdin(fs, code) {
|
|
|
|
var i = 0;
|
|
|
|
fs.init(
|
|
|
|
function() { return i<code.length ? code.charCodeAt(i++) : null; }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-04 21:07:59 +00:00
|
|
|
function compilePLASMA(code) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("plasm");
|
2017-01-10 08:18:54 +00:00
|
|
|
// stdout
|
2017-01-04 21:07:59 +00:00
|
|
|
var outstr = "";
|
|
|
|
function out_fn(s) { outstr += s; outstr += "\n"; }
|
2017-01-10 08:18:54 +00:00
|
|
|
// stderr
|
|
|
|
var re_err1 = /\s*(\d+):.*/;
|
|
|
|
var re_err2 = /Error: (.*)/;
|
|
|
|
var errors = [];
|
|
|
|
var errline = 0;
|
|
|
|
function match_fn(s) {
|
|
|
|
var matches = re_err1.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errline = parseInt(matches[1]);
|
|
|
|
}
|
|
|
|
matches = re_err2.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
|
|
|
msg:matches[1]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-04 21:07:59 +00:00
|
|
|
var Module = PLASM({
|
|
|
|
noInitialRun:true,
|
|
|
|
noFSInit:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
print:out_fn,
|
|
|
|
printErr:match_fn,
|
2017-01-04 21:07:59 +00:00
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
|
|
|
var output = [];
|
2017-01-13 02:21:35 +00:00
|
|
|
setupStdin(FS, code);
|
|
|
|
//FS.writeFile("main.pla", code);
|
2017-01-04 21:07:59 +00:00
|
|
|
Module.callMain(["-A"]);
|
2017-01-09 21:28:20 +00:00
|
|
|
outstr = "INTERP = $e044\n" + outstr; // TODO
|
2017-01-10 08:18:54 +00:00
|
|
|
if (errors.length) {
|
2017-01-15 03:46:12 +00:00
|
|
|
return {errors:errors};
|
2017-01-10 08:18:54 +00:00
|
|
|
}
|
2017-01-04 21:07:59 +00:00
|
|
|
return assembleACME(outstr);
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
function parseCA65Listing(code, mapfile) {
|
|
|
|
// CODE 00603E 00637C 00033F 00001
|
|
|
|
var mapMatch = /^CODE\s+([0-9A-F]+)/m.exec(mapfile);
|
|
|
|
var codeofs = 0x6000;
|
|
|
|
if (mapMatch) {
|
|
|
|
var codeofs = parseInt(mapMatch[1], 16);
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
// .dbg line, "main.c", 1
|
|
|
|
var dbgLineMatch = /([0-9a-fA-F]+)([r]?)\s+(\d+)\s+[.]dbg\s+line,\s+\S+,\s+(\d+)/;
|
|
|
|
var errors = [];
|
|
|
|
var lines = [];
|
|
|
|
var lastlinenum = 0;
|
|
|
|
for (var line of code.split(/\r?\n/)) {
|
|
|
|
var linem = dbgLineMatch.exec(line);
|
|
|
|
if (linem && linem[1]) {
|
|
|
|
var offset = parseInt(linem[1], 16);
|
|
|
|
var linenum = parseInt(linem[4]);
|
|
|
|
lines.push({
|
|
|
|
line:linenum,
|
2017-01-10 08:18:54 +00:00
|
|
|
offset:offset + codeofs,
|
2017-01-06 00:14:12 +00:00
|
|
|
insns:null
|
|
|
|
});
|
|
|
|
//console.log(linem, lastlinenum, lines[lines.length-1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {lines:lines, errors:errors};
|
|
|
|
}
|
|
|
|
|
2017-01-10 08:18:54 +00:00
|
|
|
function assemblelinkCA65(code, platform, warnings) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("ca65");
|
|
|
|
load("ld65");
|
2017-01-06 00:14:12 +00:00
|
|
|
var objout, lstout;
|
|
|
|
{
|
|
|
|
var CA65 = ca65({
|
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
//logReadFiles:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:print_fn,
|
|
|
|
printErr:print_fn,
|
|
|
|
});
|
|
|
|
var FS = CA65['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, '65');
|
2017-01-06 00:14:12 +00:00
|
|
|
FS.writeFile("main.s", code, {encoding:'utf8'});
|
|
|
|
CA65.callMain(['-v', '-g', '-I', '/share/asminc', '-l', 'main.lst', "main.s"]);
|
|
|
|
objout = FS.readFile("main.o", {encoding:'binary'});
|
|
|
|
lstout = FS.readFile("main.lst", {encoding:'utf8'});
|
|
|
|
}{
|
|
|
|
var LD65 = ld65({
|
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
//logReadFiles:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:print_fn,
|
|
|
|
printErr:print_fn,
|
|
|
|
});
|
|
|
|
var FS = LD65['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, '65');
|
2017-01-06 00:14:12 +00:00
|
|
|
FS.writeFile("main.o", objout, {encoding:'binary'});
|
|
|
|
LD65.callMain(['--cfg-path', '/share/cfg', '--lib-path', '/share/lib',
|
|
|
|
'--start-addr', '0x6000', // TODO
|
|
|
|
'-t', platform, '-o', 'main', '-m', 'main.map', 'main.o', platform+'.lib']);
|
|
|
|
var aout = FS.readFile("main", {encoding:'binary'});
|
|
|
|
var mapout = FS.readFile("main.map", {encoding:'utf8'});
|
2017-01-15 03:46:12 +00:00
|
|
|
var listing = parseCA65Listing(lstout, mapout);
|
2017-01-10 08:18:54 +00:00
|
|
|
return {
|
|
|
|
output:aout.slice(4),
|
2017-01-15 03:46:12 +00:00
|
|
|
lines:listing.lines,
|
|
|
|
errors:listing.errors,
|
2017-01-10 08:18:54 +00:00
|
|
|
intermediate:{listing:lstout, map:mapout},
|
|
|
|
};
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function compileCC65(code, platform) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("cc65");
|
2017-01-10 08:18:54 +00:00
|
|
|
// stderr
|
|
|
|
var re_err1 = /.*?(\d+).*?: (.+)/;
|
|
|
|
var errors = [];
|
|
|
|
var errline = 0;
|
|
|
|
function match_fn(s) {
|
2017-02-01 18:21:17 +00:00
|
|
|
console.log(s);
|
2017-01-10 08:18:54 +00:00
|
|
|
var matches = re_err1.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
errline = parseInt(matches[1]);
|
|
|
|
errors.push({
|
|
|
|
line:errline,
|
|
|
|
msg:matches[2]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
var CC65 = cc65({
|
|
|
|
noInitialRun:true,
|
2017-01-10 08:18:54 +00:00
|
|
|
//logReadFiles:true,
|
2017-01-06 00:14:12 +00:00
|
|
|
print:print_fn,
|
2017-01-10 08:18:54 +00:00
|
|
|
printErr:match_fn,
|
2017-01-06 00:14:12 +00:00
|
|
|
});
|
|
|
|
var FS = CC65['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, '65');
|
2017-01-06 00:14:12 +00:00
|
|
|
FS.writeFile("main.c", code, {encoding:'utf8'});
|
2017-01-10 08:18:54 +00:00
|
|
|
CC65.callMain(['-v', '-T', '-g', /*'-Cl',*/ '-Oirs', '-I', '/share/include', '-t', platform, "main.c"]);
|
|
|
|
try {
|
|
|
|
var asmout = FS.readFile("main.s", {encoding:'utf8'});
|
|
|
|
return assemblelinkCA65(asmout, platform, errors);
|
|
|
|
} catch(e) {
|
2017-01-15 03:46:12 +00:00
|
|
|
return {errors:errors};
|
2017-01-10 08:18:54 +00:00
|
|
|
}
|
2017-01-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 04:47:12 +00:00
|
|
|
function assembleZ80ASM(code, platform) {
|
2017-01-14 02:31:04 +00:00
|
|
|
load("z80asm");
|
2017-01-15 18:31:52 +00:00
|
|
|
var origin = 0; // TODO: configurable
|
2017-01-13 02:21:35 +00:00
|
|
|
var Module = z80asm({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:print_fn,
|
2017-02-15 21:03:52 +00:00
|
|
|
TOTAL_MEMORY:256*1024*1024,
|
2017-01-13 02:21:35 +00:00
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
|
|
|
//setupFS(FS);
|
|
|
|
// changes for dialect
|
|
|
|
code = code.replace(".optsdcc -mz80","");
|
2017-01-15 03:46:12 +00:00
|
|
|
code = code.replace(/^(\w+)\s*=/gim,"DEFC $1 =");
|
2017-01-13 02:21:35 +00:00
|
|
|
code = code.replace(/\tXREF /gi,"\tEXTERN ");
|
|
|
|
code = code.replace(/\tXDEF /gi,"\tPUBLIC ");
|
|
|
|
FS.writeFile("main.asm", code);
|
|
|
|
try {
|
2017-01-15 18:31:52 +00:00
|
|
|
Module.callMain(["-b", "-s", "-l", "-m", "-g", "--origin=" + origin.toString(16), "main.asm"]);
|
2017-01-13 02:21:35 +00:00
|
|
|
try {
|
|
|
|
var aerr = FS.readFile("main.err", {'encoding':'utf8'}); // TODO
|
2017-01-14 02:31:04 +00:00
|
|
|
if (aerr.length) {
|
2017-01-23 21:21:45 +00:00
|
|
|
return {errors:extractErrors(/.+? line (\d+): (.+)/, aerr.split("\n"))};
|
2017-01-14 02:31:04 +00:00
|
|
|
}
|
2017-01-13 02:21:35 +00:00
|
|
|
// Warning at file 'test.asm' line 9: 'XREF' is deprecated, use 'EXTERN' instead
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
77 0000 ;test.c:5: return 0;
|
|
|
|
78 0000 21 00 00 ld hl,$0000
|
|
|
|
*/
|
|
|
|
var alst = FS.readFile("main.lst", {'encoding':'utf8'}); // TODO
|
|
|
|
/*
|
|
|
|
_main = 0000, G: test
|
|
|
|
l_main00101 = 0003, L: test
|
|
|
|
*/
|
|
|
|
var amap = FS.readFile("main.map", {'encoding':'utf8'}); // TODO
|
|
|
|
var aout = FS.readFile("main.bin", {'encoding':'binary'});
|
2017-01-15 18:31:52 +00:00
|
|
|
var asmlines = parseListing(alst, /^(\d+)\s+([0-9A-F]+)\s+([0-9A-F][0-9A-F ]*[0-9A-F])\s+/i, 1, 2, 3, 4);
|
|
|
|
var srclines = parseListing(alst, /^(\d+)\s+([0-9A-F]+)\s+;[(]null[)]:(\d+)/i, 3, 2, 1);
|
2017-01-13 02:21:35 +00:00
|
|
|
return {
|
|
|
|
output:aout,
|
2017-01-15 03:46:12 +00:00
|
|
|
errors:[],
|
2017-01-16 04:47:12 +00:00
|
|
|
lines:asmlines,
|
|
|
|
srclines:srclines,
|
2017-01-13 02:21:35 +00:00
|
|
|
intermediate:{listing:alst, mapfile:amap},
|
|
|
|
};
|
|
|
|
} catch (e) {
|
2017-01-14 02:31:04 +00:00
|
|
|
throw (e);
|
2017-01-13 02:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 18:31:52 +00:00
|
|
|
function hexToArray(s, ofs) {
|
|
|
|
var buf = new ArrayBuffer(s.length/2);
|
|
|
|
var arr = new Uint8Array(buf);
|
|
|
|
for (var i=0; i<arr.length; i++) {
|
|
|
|
arr[i] = parseInt(s.slice(i*2+ofs,i*2+ofs+2), 16);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseIHX(ihx, code_start, code_size) {
|
|
|
|
var output = new Uint8Array(new ArrayBuffer(code_size));
|
|
|
|
for (var s of ihx.split("\n")) {
|
|
|
|
if (s[0] == ':') {
|
|
|
|
var arr = hexToArray(s, 1);
|
|
|
|
var count = arr[0];
|
|
|
|
var address = (arr[1]<<8) + arr[2] - code_start;
|
|
|
|
var rectype = arr[3];
|
|
|
|
if (rectype == 0) {
|
|
|
|
for (var i=0; i<count; i++) {
|
|
|
|
var b = arr[4+i];
|
|
|
|
output[i+address] = b;
|
|
|
|
}
|
|
|
|
} else if (rectype == 1) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-16 04:47:12 +00:00
|
|
|
function assemblelinkSDASZ80(code, platform) {
|
2017-01-15 18:31:52 +00:00
|
|
|
load("sdasz80");
|
|
|
|
load("sdldz80");
|
|
|
|
var objout, lstout, symout;
|
|
|
|
var params = PLATFORM_PARAMS[platform];
|
|
|
|
if (!params) throw Error("Platform not supported: " + platform);
|
|
|
|
{
|
|
|
|
msvc_errors = [];
|
2017-01-22 14:35:04 +00:00
|
|
|
//?ASxxxx-Error-<o> in line 1 of main.asm null
|
|
|
|
// <o> .org in REL area or directive / mnemonic error
|
|
|
|
var match_asm_re = / <\w> (.+)/; // TODO
|
|
|
|
function match_asm_fn(s) {
|
|
|
|
var matches = match_asm_re.exec(s);
|
2017-01-15 18:31:52 +00:00
|
|
|
if (matches) {
|
2017-01-22 14:35:04 +00:00
|
|
|
var errline = parseInt(matches[2]);
|
2017-01-15 18:31:52 +00:00
|
|
|
msvc_errors.push({
|
|
|
|
line:1, // TODO: errline,
|
|
|
|
msg:matches[1]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var ASZ80 = sdasz80({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
2017-01-22 14:35:04 +00:00
|
|
|
print:match_asm_fn,
|
|
|
|
printErr:match_asm_fn,
|
2017-01-15 18:31:52 +00:00
|
|
|
});
|
|
|
|
var FS = ASZ80['FS'];
|
|
|
|
FS.writeFile("main.asm", code, {encoding:'utf8'});
|
|
|
|
ASZ80.callMain(['-plosgffwy', 'main.asm']);
|
|
|
|
if (msvc_errors.length) {
|
|
|
|
return {errors:msvc_errors};
|
|
|
|
}
|
|
|
|
objout = FS.readFile("main.rel", {encoding:'utf8'});
|
|
|
|
lstout = FS.readFile("main.lst", {encoding:'utf8'});
|
2017-01-16 04:47:12 +00:00
|
|
|
//symout = FS.readFile("main.sym", {encoding:'utf8'});
|
2017-01-15 18:31:52 +00:00
|
|
|
}{
|
2017-01-22 14:35:04 +00:00
|
|
|
//?ASlink-Warning-Undefined Global '__divsint' referenced by module 'main'
|
|
|
|
var match_aslink_re = /\?ASlink-(\w+)-(.+)/;
|
|
|
|
function match_aslink_fn(s) {
|
|
|
|
var matches = match_aslink_re.exec(s);
|
|
|
|
if (matches) {
|
|
|
|
msvc_errors.push({
|
|
|
|
line:1,
|
|
|
|
msg:matches[2]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-01-15 18:31:52 +00:00
|
|
|
var LDZ80 = sdldz80({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
2017-01-22 14:35:04 +00:00
|
|
|
print:match_aslink_fn,
|
|
|
|
printErr:match_aslink_fn,
|
2017-01-15 18:31:52 +00:00
|
|
|
});
|
|
|
|
var FS = LDZ80['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, 'sdcc');
|
2017-01-15 18:31:52 +00:00
|
|
|
FS.writeFile("main.rel", objout, {encoding:'utf8'});
|
2017-01-23 21:21:45 +00:00
|
|
|
FS.writeFile("main.lst", lstout, {encoding:'utf8'});
|
|
|
|
LDZ80.callMain(['-mjwxyu', '-i', 'main.ihx',
|
2017-01-15 18:31:52 +00:00
|
|
|
'-b', '_CODE=0x'+params.code_start.toString(16),
|
|
|
|
'-b', '_DATA=0x'+params.data_start.toString(16),
|
2017-01-23 21:21:45 +00:00
|
|
|
'-k', '/share/lib/z80',
|
|
|
|
'-l', 'z80',
|
2017-01-15 18:31:52 +00:00
|
|
|
'main.rel']);
|
|
|
|
var hexout = FS.readFile("main.ihx", {encoding:'utf8'});
|
|
|
|
var mapout = FS.readFile("main.noi", {encoding:'utf8'});
|
2017-01-23 21:21:45 +00:00
|
|
|
var rstout = FS.readFile("main.rst", {encoding:'utf8'});
|
2017-01-16 04:47:12 +00:00
|
|
|
//var dbgout = FS.readFile("main.cdb", {encoding:'utf8'});
|
2017-01-15 18:31:52 +00:00
|
|
|
// 0000 21 02 00 [10] 52 ld hl, #2
|
|
|
|
// TODO: offset by start address?
|
|
|
|
var asmlines = parseListing(lstout, /^\s*([0-9A-F]+)\s+([0-9A-F][0-9A-F r]*[0-9A-F])\s+\[([0-9 ]+)\]\s+(\d+) (.*)/i, 4, 1, 2, 5, 3);
|
2017-01-22 14:35:04 +00:00
|
|
|
var srclines = parseSourceLines(lstout, /^\s+\d+ ;<stdin>:(\d+):/i, /^\s*([0-9A-F]{4})/i);
|
2017-01-16 04:47:12 +00:00
|
|
|
// parse symbol map
|
|
|
|
var symbolmap = {};
|
|
|
|
for (var s of mapout.split("\n")) {
|
|
|
|
var toks = s.split(" ");
|
|
|
|
if (s[0] == 'DEF') {
|
|
|
|
symbolmap[s[1]] = s[2];
|
|
|
|
}
|
|
|
|
}
|
2017-01-15 18:31:52 +00:00
|
|
|
return {
|
|
|
|
output:parseIHX(hexout, params.code_start, params.code_size),
|
2017-01-16 04:47:12 +00:00
|
|
|
lines:asmlines,
|
|
|
|
srclines:srclines,
|
2017-01-15 18:31:52 +00:00
|
|
|
errors:msvc_errors, // TODO?
|
2017-01-16 04:47:12 +00:00
|
|
|
symbolmap:symbolmap,
|
2017-01-23 21:21:45 +00:00
|
|
|
intermediate:{listing:rstout},
|
2017-01-15 18:31:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-13 02:21:35 +00:00
|
|
|
function compileSDCC(code, platform) {
|
2017-01-22 14:35:04 +00:00
|
|
|
var preproc = preprocessMCPP(code, platform);
|
|
|
|
if (preproc.errors) return preproc;
|
|
|
|
else code = preproc.code;
|
|
|
|
|
2017-01-14 02:31:04 +00:00
|
|
|
load("sdcc");
|
2017-01-15 18:31:52 +00:00
|
|
|
var params = PLATFORM_PARAMS[platform];
|
|
|
|
if (!params) throw Error("Platform not supported: " + platform);
|
2017-01-13 02:21:35 +00:00
|
|
|
var SDCC = sdcc({
|
|
|
|
noInitialRun:true,
|
|
|
|
noFSInit:true,
|
|
|
|
print:print_fn,
|
|
|
|
printErr:match_msvc,
|
|
|
|
});
|
|
|
|
var FS = SDCC['FS'];
|
|
|
|
setupStdin(FS, code);
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, 'sdcc');
|
2017-01-13 02:21:35 +00:00
|
|
|
//FS.writeFile("main.c", code, {encoding:'utf8'});
|
|
|
|
msvc_errors = [];
|
2017-02-01 18:21:17 +00:00
|
|
|
SDCC.callMain(['--vc', '--std-sdcc99', '-mz80', //'-Wall',
|
2017-01-22 14:35:04 +00:00
|
|
|
'--c1mode', // '--debug',
|
|
|
|
//'-S', 'main.c',
|
2017-01-15 18:31:52 +00:00
|
|
|
//'--asm=z80asm',
|
2017-02-18 22:50:51 +00:00
|
|
|
'--less-pedantic',
|
2017-02-20 23:50:29 +00:00
|
|
|
//'--fomit-frame-pointer',
|
|
|
|
'--opt-code-speed',
|
2017-01-22 14:35:04 +00:00
|
|
|
'-o', 'main.asm']);
|
2017-02-05 04:19:54 +00:00
|
|
|
/*
|
2017-02-01 18:21:17 +00:00
|
|
|
// ignore if all are warnings (TODO?)
|
|
|
|
var nwarnings = 0;
|
|
|
|
for (var err of msvc_errors) {
|
|
|
|
if (err.type && err.type.startsWith("warning"))
|
|
|
|
nwarnings++;
|
|
|
|
}
|
2017-02-05 04:19:54 +00:00
|
|
|
*/
|
2017-02-20 23:50:29 +00:00
|
|
|
// TODO: preprocessor errors w/ correct file
|
2017-02-05 04:19:54 +00:00
|
|
|
if (msvc_errors.length /* && nwarnings < msvc_errors.length*/) {
|
2017-01-15 03:46:12 +00:00
|
|
|
return {errors:msvc_errors};
|
2017-01-13 02:21:35 +00:00
|
|
|
}
|
2017-01-29 21:06:05 +00:00
|
|
|
try {
|
|
|
|
var asmout = FS.readFile("main.asm", {encoding:'utf8'});
|
2017-02-18 22:50:51 +00:00
|
|
|
asmout = " .area _HOME\n .area _CODE\n .area _INITIALIZER\n .area _DATA\n .area _INITIALIZED\n .area _BSEG\n .area _BSS\n .area _HEAP\n" + asmout;
|
|
|
|
//asmout = asmout.replace(".area _INITIALIZER",".area _CODE");
|
2017-01-29 21:06:05 +00:00
|
|
|
} catch (e) {
|
2017-02-01 18:21:17 +00:00
|
|
|
msvc_errors.push({line:1, msg:e+""});
|
|
|
|
return {errors:msvc_errors};
|
2017-01-29 21:06:05 +00:00
|
|
|
}
|
2017-01-16 04:47:12 +00:00
|
|
|
var warnings = msvc_errors;
|
2017-02-01 18:21:17 +00:00
|
|
|
try {
|
|
|
|
var result = assemblelinkSDASZ80(asmout, platform, true);
|
|
|
|
} catch (e) {
|
|
|
|
msvc_errors.push({line:1, msg:e+""});
|
|
|
|
return {errors:msvc_errors};
|
|
|
|
}
|
2017-01-16 04:47:12 +00:00
|
|
|
result.asmlines = result.lines;
|
|
|
|
result.lines = result.srclines;
|
|
|
|
result.srclines = null;
|
2017-02-01 18:21:17 +00:00
|
|
|
//result.errors = result.errors.concat(warnings);
|
2017-01-15 18:31:52 +00:00
|
|
|
return result;
|
2017-01-13 02:21:35 +00:00
|
|
|
}
|
|
|
|
|
2017-01-21 13:13:36 +00:00
|
|
|
function assembleXASM6809(code, platform) {
|
|
|
|
load("xasm6809");
|
|
|
|
var origin = 0; // TODO: configurable
|
|
|
|
var alst = "";
|
|
|
|
var lasterror = null;
|
|
|
|
msvc_errors = [];
|
|
|
|
function match_fn(s) {
|
|
|
|
alst += s;
|
|
|
|
alst += "\n";
|
|
|
|
if (lasterror) {
|
|
|
|
var line = parseInt(s.slice(0,5));
|
|
|
|
msvc_errors.push({
|
|
|
|
line:line,
|
|
|
|
msg:lasterror
|
|
|
|
});
|
|
|
|
lasterror = null;
|
|
|
|
}
|
|
|
|
else if (s.startsWith("***** ")) {
|
|
|
|
lasterror = s.slice(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var Module = xasm6809({
|
|
|
|
noInitialRun:true,
|
|
|
|
//logReadFiles:true,
|
|
|
|
print:match_fn,
|
|
|
|
printErr:print_fn
|
|
|
|
});
|
|
|
|
var FS = Module['FS'];
|
|
|
|
//setupFS(FS);
|
|
|
|
FS.writeFile("main.asm", code);
|
|
|
|
Module.callMain(["-c", "-l", "-s", "-y", "-o=main.bin", "main.asm"]);
|
|
|
|
try {
|
|
|
|
var aout = FS.readFile("main.bin", {encoding:'binary'});
|
|
|
|
// 00001 0000 [ 2] 1048 asld
|
|
|
|
var asmlines = parseListing(alst, /^\s*([0-9A-F]+)\s+([0-9A-F]+)\s+\[([0-9 ]+)\]\s+(\d+) (.*)/i, 1, 2, 4, 5, 3);
|
|
|
|
return {
|
|
|
|
output:aout,
|
|
|
|
errors:msvc_errors,
|
|
|
|
lines:asmlines,
|
|
|
|
intermediate:{listing:alst},
|
|
|
|
};
|
|
|
|
} catch(e) {
|
|
|
|
return {errors:msvc_errors}; // TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 14:35:04 +00:00
|
|
|
function preprocessMCPP(code, platform) {
|
|
|
|
load("mcpp");
|
2017-01-23 21:21:45 +00:00
|
|
|
// <stdin>:2: error: Can't open include file "foo.h"
|
|
|
|
var errors = [];
|
|
|
|
var match_fn = makeErrorMatcher(errors, /<stdin>:(\d+): (.+)/, 1, 2);
|
2017-01-22 14:35:04 +00:00
|
|
|
var MCPP = mcpp({
|
|
|
|
noInitialRun:true,
|
|
|
|
noFSInit:true,
|
|
|
|
print:print_fn,
|
2017-01-23 21:21:45 +00:00
|
|
|
printErr:match_fn,
|
2017-01-22 14:35:04 +00:00
|
|
|
});
|
|
|
|
var FS = MCPP['FS'];
|
2017-01-23 21:21:45 +00:00
|
|
|
setupFS(FS, 'sdcc');
|
2017-01-22 14:35:04 +00:00
|
|
|
FS.writeFile("main.c", code, {encoding:'utf8'});
|
2017-01-23 21:21:45 +00:00
|
|
|
MCPP.callMain([
|
|
|
|
"-D", "__8BITWORKSHOP__",
|
2017-01-29 21:06:05 +00:00
|
|
|
"-D", platform.toUpperCase().replace('-','_'),
|
2017-02-20 23:50:29 +00:00
|
|
|
"-D", "__SDCC_z80",
|
2017-01-23 21:21:45 +00:00
|
|
|
"-I", "/share/include",
|
|
|
|
"-Q",
|
|
|
|
"main.c", "main.i"]);
|
2017-01-22 14:35:04 +00:00
|
|
|
try {
|
2017-01-23 21:21:45 +00:00
|
|
|
var iout = FS.readFile("main.i", {encoding:'utf8'});
|
|
|
|
iout = iout.replace(/^#line /gm,'\n# ');
|
2017-01-22 14:35:04 +00:00
|
|
|
} catch (e) {
|
2017-01-23 21:21:45 +00:00
|
|
|
errors.push({line:1, msg:e+""});
|
2017-01-22 14:35:04 +00:00
|
|
|
}
|
2017-01-23 21:21:45 +00:00
|
|
|
try {
|
|
|
|
var errout = FS.readFile("mcpp.err", {encoding:'utf8'});
|
|
|
|
if (errout.length) {
|
|
|
|
// //main.c:2: error: Can't open include file "stdiosd.h"
|
2017-01-29 21:06:05 +00:00
|
|
|
var errors = extractErrors(/[^:]+:(\d+): (.+)/, errout.split("\n"));
|
|
|
|
if (errors.length == 0) {
|
|
|
|
errors = [{line:1, msg:errout}];
|
|
|
|
}
|
|
|
|
return {errors: errors};
|
2017-01-23 21:21:45 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
//
|
2017-01-22 14:35:04 +00:00
|
|
|
}
|
|
|
|
return {code:iout};
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:46:12 +00:00
|
|
|
var TOOLS = {
|
2017-01-04 21:07:59 +00:00
|
|
|
'dasm': assembleDASM,
|
2017-01-15 03:46:12 +00:00
|
|
|
'acme': assembleACME,
|
2017-01-04 21:07:59 +00:00
|
|
|
'plasm': compilePLASMA,
|
2017-01-06 00:14:12 +00:00
|
|
|
'cc65': compileCC65,
|
|
|
|
'ca65': assemblelinkCA65,
|
2017-01-13 02:21:35 +00:00
|
|
|
'z80asm': assembleZ80ASM,
|
2017-01-15 18:31:52 +00:00
|
|
|
'sdasz80': assemblelinkSDASZ80,
|
2017-01-13 02:21:35 +00:00
|
|
|
'sdcc': compileSDCC,
|
2017-01-21 13:13:36 +00:00
|
|
|
'xasm6809': assembleXASM6809,
|
2017-01-04 21:07:59 +00:00
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
|
2017-01-23 21:21:45 +00:00
|
|
|
var TOOL_PRELOADFS = {
|
|
|
|
'cc65': '65',
|
|
|
|
'ca65': '65',
|
|
|
|
'sdasz80': 'sdcc',
|
|
|
|
'sdcc': 'sdcc',
|
|
|
|
}
|
|
|
|
|
2016-12-16 01:21:51 +00:00
|
|
|
onmessage = function(e) {
|
2017-01-23 21:21:45 +00:00
|
|
|
// (preload)
|
|
|
|
if (e.data.preload) {
|
|
|
|
var fs = TOOL_PRELOADFS[e.data.preload];
|
|
|
|
if (fs && !fsMeta[fs]) loadFilesystem(fs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// (code,platform,tool)
|
2016-12-16 01:21:51 +00:00
|
|
|
var code = e.data.code;
|
2017-01-12 02:02:23 +00:00
|
|
|
var platform = e.data.platform;
|
2017-01-15 03:46:12 +00:00
|
|
|
var toolfn = TOOLS[e.data.tool];
|
2017-01-04 21:07:59 +00:00
|
|
|
if (!toolfn) throw "no tool named " + e.data.tool;
|
2017-01-12 02:02:23 +00:00
|
|
|
var result = toolfn(code, platform);
|
2017-01-06 00:14:12 +00:00
|
|
|
if (result) {
|
|
|
|
postMessage(result);
|
|
|
|
}
|
2016-12-16 01:21:51 +00:00
|
|
|
}
|