8bitworkshop/gen/worker/tools/z80.js

69 lines
2.8 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assembleZMAC = void 0;
const builder_1 = require("../builder");
const listingutils_1 = require("../listingutils");
const wasmutils_1 = require("../wasmutils");
function assembleZMAC(step) {
(0, wasmutils_1.loadNative)("zmac");
var hexout, lstout, binout;
var errors = [];
var params = step.params;
(0, builder_1.gatherFiles)(step, { mainFilePath: "main.asm" });
var lstpath = step.prefix + ".lst";
var binpath = step.prefix + ".cim";
if ((0, builder_1.staleFiles)(step, [binpath])) {
/*
error1.asm(4) : 'l18d4' Undeclared
JP L18D4
error1.asm(11): warning: 'foobar' treated as label (instruction typo?)
Add a colon or move to first column to stop this warning.
1 errors (see listing if no diagnostics appeared here)
*/
var ZMAC = wasmutils_1.emglobal.zmac({
instantiateWasm: (0, wasmutils_1.moduleInstFn)('zmac'),
noInitialRun: true,
//logReadFiles:true,
print: wasmutils_1.print_fn,
printErr: (0, listingutils_1.makeErrorMatcher)(errors, /([^( ]+)\s*[(](\d+)[)]\s*:\s*(.+)/, 2, 3, step.path),
});
var FS = ZMAC.FS;
(0, builder_1.populateFiles)(step, FS);
// TODO: don't know why CIM (hexary) doesn't work
(0, wasmutils_1.execMain)(step, ZMAC, ['-z', '-c', '--oo', 'lst,cim', step.path]);
if (errors.length) {
return { errors: errors };
}
lstout = FS.readFile("zout/" + lstpath, { encoding: 'utf8' });
binout = FS.readFile("zout/" + binpath, { encoding: 'binary' });
(0, builder_1.putWorkFile)(binpath, binout);
(0, builder_1.putWorkFile)(lstpath, lstout);
if (!(0, builder_1.anyTargetChanged)(step, [binpath, lstpath]))
return;
// 230: 1739+7+x 017A 1600 L017A: LD D,00h
var lines = (0, listingutils_1.parseListing)(lstout, /\s*(\d+):\s*([0-9a-f]+)\s+([0-9a-f]+)\s+(.+)/i, 1, 2, 3);
var listings = {};
listings[lstpath] = { lines: lines };
// parse symbol table
var symbolmap = {};
var sympos = lstout.indexOf('Symbol Table:');
if (sympos > 0) {
var symout = lstout.slice(sympos + 14);
symout.split('\n').forEach(function (l) {
var m = l.match(/(\S+)\s+([= ]*)([0-9a-f]+)/i);
if (m) {
symbolmap[m[1]] = parseInt(m[3], 16);
}
});
}
return {
output: binout,
listings: listings,
errors: errors,
symbolmap: symbolmap
};
}
}
exports.assembleZMAC = assembleZMAC;
//# sourceMappingURL=z80.js.map