1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-23 18:31:08 +00:00

setMainFile() starts 1st build; multiple listing files for DASM includes; updated tests

This commit is contained in:
Steven Hugg 2018-08-04 10:21:50 -04:00
parent cfb5f7f59d
commit 0cb8ea7661
8 changed files with 65 additions and 17 deletions

View File

@ -117,6 +117,7 @@ var JSNESPlatform = function(mainElement) {
this.loadROM = function(title, data) {
var romstr = String.fromCharCode.apply(null, data);
nes.loadROM(romstr);
frameindex = 0;
}
this.getOpcodeMetadata = getOpcodeMetadata_6502;

View File

@ -206,7 +206,7 @@ export class CodeProject {
}
sendBuild() {
var self = this;
if (!this.mainpath) throw "need to call setMainFile first";
var maindata = this.getFile(this.mainpath);
var text = typeof maindata === "string" ? maindata : '';
this.loadFileDependencies(text, (err, depends) => {
@ -233,13 +233,18 @@ export class CodeProject {
updateFile(path:string, text:FileData) {
this.updateFileInStore(path, text); // TODO: isBinary
this.filedata[path] = text;
if (this.okToSend()) {
if (!this.mainpath) this.mainpath = path;
if (this.okToSend() && this.mainpath) {
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
this.sendBuild();
}
};
setMainFile(path:string) {
this.mainpath = path;
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
this.sendBuild();
}
processBuildResult(data:WorkerResult) {
// TODO: link listings with source files
this.listings = data.listings;

View File

@ -198,6 +198,8 @@ function loadProject(preset_id:string) {
refreshWindowList();
// show main file
projectWindows.createOrShow(preset_id); // TODO: add checkmark
// build project
current_project.setMainFile(preset_id);
}
});
}

View File

@ -65,6 +65,7 @@ export class SourceEditor implements ProjectView {
this.newEditor(div);
if (text)
this.setText(text); // TODO: this calls setCode() and builds... it shouldn't
this.setupEditor();
return div;
}
@ -79,6 +80,9 @@ export class SourceEditor implements ProjectView {
gutters: isAsm ? ["CodeMirror-linenumbers", "gutter-offset", "gutter-bytes", "gutter-clock", "gutter-info"]
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
});
}
setupEditor() {
var timer;
this.editor.on('changes', (ed, changeobj) => {
clearTimeout(timer);
@ -231,16 +235,22 @@ export class SourceEditor implements ProjectView {
}
}
refreshDebugState(moveCursor:boolean) {
this.clearCurrentLine();
getActiveLine() {
var state = lastDebugState;
if (state && state.c) {
if (state && state.c && this.sourcefile) {
var PC = state.c.PC;
var line = this.sourcefile.findLineForOffset(PC);
if (line >= 0) {
this.setCurrentLine(line, moveCursor);
// TODO: switch to disasm?
}
return line;
} else
return -1;
}
refreshDebugState(moveCursor:boolean) {
this.clearCurrentLine();
var line = this.getActiveLine();
if (line >= 0) {
this.setCurrentLine(line, moveCursor);
// TODO: switch to disasm?
}
}
@ -454,7 +464,7 @@ export class ListingView extends DisassemblerView implements ProjectView {
}
disasmview.setValue(asmtext);
var findPC = platform.getDebugCallback() ? pc : -1;
if (findPC >= 0) {
if (findPC >= 0 && this.assemblyfile) {
var lineno = this.assemblyfile.findLineForOffset(findPC);
if (lineno && moveCursor) {
// set cursor while debugging

View File

@ -57,6 +57,8 @@ export class ProjectWindows {
}
refresh(moveCursor:boolean) {
// TODO: activate window that contains debug line?
// refresh current window
if (this.activewnd && this.activewnd.refresh)
this.activewnd.refresh(moveCursor);
}

View File

@ -525,11 +525,21 @@ function assembleDASM(step) {
var sympath = step.prefix+'.sym';
execMain(step, Module, [step.path, "-l"+lstpath, "-o"+binpath, "-s"+sympath ]);
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
// parse main listing, get errors
var listing = parseDASMListing(alst, unresolved, step.path);
errors = errors.concat(listing.errors);
if (errors.length) {
return {errors:errors};
}
var listings = {};
listings[lstpath] = {lines:listing.lines};
// parse include files
for (var fn of step.files) {
if (fn != step.path) {
var lst = parseDASMListing(alst, unresolved, fn);
listings[fn] = lst; // TODO: foo.asm.lst
}
}
var aout = FS.readFile(binpath);
var asym = FS.readFile(lstpath, {'encoding':'utf8'});
putWorkFile(binpath, aout);
@ -539,8 +549,6 @@ function assembleDASM(step) {
// TODO: what if listing or symbols change?
if (!anyTargetChanged(step, [binpath/*, lstpath, sympath*/]))
return;
var listings = {};
listings[lstpath] = {lines:listing.lines};
var symbolmap = {};
for (var s of asym.split("\n")) {
var toks = s.split(" ");

View File

@ -79,13 +79,13 @@ describe('Store', function() {
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
project.loadFiles(['test'], function(err, result) {
assert.equal(null, err);
assert.deepEqual([ { path: 'test', filename: 'test', data: 'a' } ], result);
assert.deepEqual([ { path: 'test', filename: 'test', data: 'a', link:true } ], result);
done();
});
});
});
it('Should build project', function(done) {
it('Should build linked project', function(done) {
localStorage.clear();
localItems['__migrated__TEST'] = 'true';
var msgs = [];
@ -94,7 +94,7 @@ describe('Store', function() {
{ preload: 'dasm', platform: '_TEST' },
{
buildsteps: [
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile:true },
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile:true, files:["test.a"] },
],
updates: [
{ path: "test.a", data: " lda #0" }
@ -111,6 +111,7 @@ describe('Store', function() {
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
project.callbackBuildStatus = function(b) { msgs.push(b) };
project.updateFile('test.a', ' lda #0');
project.setMainFile('test.a');
project.updateFile('test.a', ' lda #1'); // don't send twice (yet)
assert.deepEqual(msgs, expectmsgs);
store.getItem('test.a', function(err, result) {
@ -122,7 +123,7 @@ describe('Store', function() {
// lines: [ { line: 3, offset: 61440, insns: 'a9 00', iscode: true } ] }
it('Should build project', function(done) {
it('Should build asm project', function(done) {
localStorage.clear();
localItems['__migrated__TEST'] = 'true';
var msgs = [];

19
test/cli/testutil.js Normal file
View File

@ -0,0 +1,19 @@
var vm = require('vm');
var fs = require('fs');
var assert = require('assert');
var includeInThisContext = function(path) {
var code = fs.readFileSync(path);
vm.runInThisContext(code, path);
};
includeInThisContext("gen/emu.js");
includeInThisContext("gen/util.js");
includeInThisContext("src/platform/nes.js");
describe('LZG', function() {
it('Should decode LZG', function() {
var rom = new Uint8Array(new lzgmini().decode(NES_CONIO_ROM_LZG));
assert.equal(40977, rom.length);
});
});