mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-01-11 08:30:02 +00:00
setMainFile() starts 1st build; multiple listing files for DASM includes; updated tests
This commit is contained in:
parent
cfb5f7f59d
commit
0cb8ea7661
@ -117,6 +117,7 @@ var JSNESPlatform = function(mainElement) {
|
|||||||
this.loadROM = function(title, data) {
|
this.loadROM = function(title, data) {
|
||||||
var romstr = String.fromCharCode.apply(null, data);
|
var romstr = String.fromCharCode.apply(null, data);
|
||||||
nes.loadROM(romstr);
|
nes.loadROM(romstr);
|
||||||
|
frameindex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getOpcodeMetadata = getOpcodeMetadata_6502;
|
this.getOpcodeMetadata = getOpcodeMetadata_6502;
|
||||||
|
@ -206,7 +206,7 @@ export class CodeProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendBuild() {
|
sendBuild() {
|
||||||
var self = this;
|
if (!this.mainpath) throw "need to call setMainFile first";
|
||||||
var maindata = this.getFile(this.mainpath);
|
var maindata = this.getFile(this.mainpath);
|
||||||
var text = typeof maindata === "string" ? maindata : '';
|
var text = typeof maindata === "string" ? maindata : '';
|
||||||
this.loadFileDependencies(text, (err, depends) => {
|
this.loadFileDependencies(text, (err, depends) => {
|
||||||
@ -233,13 +233,18 @@ export class CodeProject {
|
|||||||
updateFile(path:string, text:FileData) {
|
updateFile(path:string, text:FileData) {
|
||||||
this.updateFileInStore(path, text); // TODO: isBinary
|
this.updateFileInStore(path, text); // TODO: isBinary
|
||||||
this.filedata[path] = text;
|
this.filedata[path] = text;
|
||||||
if (this.okToSend()) {
|
if (this.okToSend() && this.mainpath) {
|
||||||
if (!this.mainpath) this.mainpath = path;
|
|
||||||
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
|
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
|
||||||
this.sendBuild();
|
this.sendBuild();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setMainFile(path:string) {
|
||||||
|
this.mainpath = path;
|
||||||
|
if (this.callbackBuildStatus) this.callbackBuildStatus(true);
|
||||||
|
this.sendBuild();
|
||||||
|
}
|
||||||
|
|
||||||
processBuildResult(data:WorkerResult) {
|
processBuildResult(data:WorkerResult) {
|
||||||
// TODO: link listings with source files
|
// TODO: link listings with source files
|
||||||
this.listings = data.listings;
|
this.listings = data.listings;
|
||||||
|
@ -198,6 +198,8 @@ function loadProject(preset_id:string) {
|
|||||||
refreshWindowList();
|
refreshWindowList();
|
||||||
// show main file
|
// show main file
|
||||||
projectWindows.createOrShow(preset_id); // TODO: add checkmark
|
projectWindows.createOrShow(preset_id); // TODO: add checkmark
|
||||||
|
// build project
|
||||||
|
current_project.setMainFile(preset_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
20
src/views.ts
20
src/views.ts
@ -65,6 +65,7 @@ export class SourceEditor implements ProjectView {
|
|||||||
this.newEditor(div);
|
this.newEditor(div);
|
||||||
if (text)
|
if (text)
|
||||||
this.setText(text); // TODO: this calls setCode() and builds... it shouldn't
|
this.setText(text); // TODO: this calls setCode() and builds... it shouldn't
|
||||||
|
this.setupEditor();
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +80,9 @@ export class SourceEditor implements ProjectView {
|
|||||||
gutters: isAsm ? ["CodeMirror-linenumbers", "gutter-offset", "gutter-bytes", "gutter-clock", "gutter-info"]
|
gutters: isAsm ? ["CodeMirror-linenumbers", "gutter-offset", "gutter-bytes", "gutter-clock", "gutter-info"]
|
||||||
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
|
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setupEditor() {
|
||||||
var timer;
|
var timer;
|
||||||
this.editor.on('changes', (ed, changeobj) => {
|
this.editor.on('changes', (ed, changeobj) => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
@ -231,18 +235,24 @@ export class SourceEditor implements ProjectView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshDebugState(moveCursor:boolean) {
|
getActiveLine() {
|
||||||
this.clearCurrentLine();
|
|
||||||
var state = lastDebugState;
|
var state = lastDebugState;
|
||||||
if (state && state.c) {
|
if (state && state.c && this.sourcefile) {
|
||||||
var PC = state.c.PC;
|
var PC = state.c.PC;
|
||||||
var line = this.sourcefile.findLineForOffset(PC);
|
var line = this.sourcefile.findLineForOffset(PC);
|
||||||
|
return line;
|
||||||
|
} else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDebugState(moveCursor:boolean) {
|
||||||
|
this.clearCurrentLine();
|
||||||
|
var line = this.getActiveLine();
|
||||||
if (line >= 0) {
|
if (line >= 0) {
|
||||||
this.setCurrentLine(line, moveCursor);
|
this.setCurrentLine(line, moveCursor);
|
||||||
// TODO: switch to disasm?
|
// TODO: switch to disasm?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
refreshListing() {
|
refreshListing() {
|
||||||
if (!this.dirtylisting) return;
|
if (!this.dirtylisting) return;
|
||||||
@ -454,7 +464,7 @@ export class ListingView extends DisassemblerView implements ProjectView {
|
|||||||
}
|
}
|
||||||
disasmview.setValue(asmtext);
|
disasmview.setValue(asmtext);
|
||||||
var findPC = platform.getDebugCallback() ? pc : -1;
|
var findPC = platform.getDebugCallback() ? pc : -1;
|
||||||
if (findPC >= 0) {
|
if (findPC >= 0 && this.assemblyfile) {
|
||||||
var lineno = this.assemblyfile.findLineForOffset(findPC);
|
var lineno = this.assemblyfile.findLineForOffset(findPC);
|
||||||
if (lineno && moveCursor) {
|
if (lineno && moveCursor) {
|
||||||
// set cursor while debugging
|
// set cursor while debugging
|
||||||
|
@ -57,6 +57,8 @@ export class ProjectWindows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh(moveCursor:boolean) {
|
refresh(moveCursor:boolean) {
|
||||||
|
// TODO: activate window that contains debug line?
|
||||||
|
// refresh current window
|
||||||
if (this.activewnd && this.activewnd.refresh)
|
if (this.activewnd && this.activewnd.refresh)
|
||||||
this.activewnd.refresh(moveCursor);
|
this.activewnd.refresh(moveCursor);
|
||||||
}
|
}
|
||||||
|
@ -525,11 +525,21 @@ function assembleDASM(step) {
|
|||||||
var sympath = step.prefix+'.sym';
|
var sympath = step.prefix+'.sym';
|
||||||
execMain(step, Module, [step.path, "-l"+lstpath, "-o"+binpath, "-s"+sympath ]);
|
execMain(step, Module, [step.path, "-l"+lstpath, "-o"+binpath, "-s"+sympath ]);
|
||||||
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
|
var alst = FS.readFile(lstpath, {'encoding':'utf8'});
|
||||||
|
// parse main listing, get errors
|
||||||
var listing = parseDASMListing(alst, unresolved, step.path);
|
var listing = parseDASMListing(alst, unresolved, step.path);
|
||||||
errors = errors.concat(listing.errors);
|
errors = errors.concat(listing.errors);
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
return {errors:errors};
|
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 aout = FS.readFile(binpath);
|
||||||
var asym = FS.readFile(lstpath, {'encoding':'utf8'});
|
var asym = FS.readFile(lstpath, {'encoding':'utf8'});
|
||||||
putWorkFile(binpath, aout);
|
putWorkFile(binpath, aout);
|
||||||
@ -539,8 +549,6 @@ function assembleDASM(step) {
|
|||||||
// TODO: what if listing or symbols change?
|
// TODO: what if listing or symbols change?
|
||||||
if (!anyTargetChanged(step, [binpath/*, lstpath, sympath*/]))
|
if (!anyTargetChanged(step, [binpath/*, lstpath, sympath*/]))
|
||||||
return;
|
return;
|
||||||
var listings = {};
|
|
||||||
listings[lstpath] = {lines:listing.lines};
|
|
||||||
var symbolmap = {};
|
var symbolmap = {};
|
||||||
for (var s of asym.split("\n")) {
|
for (var s of asym.split("\n")) {
|
||||||
var toks = s.split(" ");
|
var toks = s.split(" ");
|
||||||
|
@ -79,13 +79,13 @@ describe('Store', function() {
|
|||||||
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
||||||
project.loadFiles(['test'], function(err, result) {
|
project.loadFiles(['test'], function(err, result) {
|
||||||
assert.equal(null, err);
|
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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should build project', function(done) {
|
it('Should build linked project', function(done) {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
localItems['__migrated__TEST'] = 'true';
|
localItems['__migrated__TEST'] = 'true';
|
||||||
var msgs = [];
|
var msgs = [];
|
||||||
@ -94,7 +94,7 @@ describe('Store', function() {
|
|||||||
{ preload: 'dasm', platform: '_TEST' },
|
{ preload: 'dasm', platform: '_TEST' },
|
||||||
{
|
{
|
||||||
buildsteps: [
|
buildsteps: [
|
||||||
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile:true },
|
{ path: "test.a", platform: "_TEST", tool: "dasm", mainfile:true, files:["test.a"] },
|
||||||
],
|
],
|
||||||
updates: [
|
updates: [
|
||||||
{ path: "test.a", data: " lda #0" }
|
{ path: "test.a", data: " lda #0" }
|
||||||
@ -111,6 +111,7 @@ describe('Store', function() {
|
|||||||
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
var project = new prj.CodeProject(worker, test_platform_id, platform, store);
|
||||||
project.callbackBuildStatus = function(b) { msgs.push(b) };
|
project.callbackBuildStatus = function(b) { msgs.push(b) };
|
||||||
project.updateFile('test.a', ' lda #0');
|
project.updateFile('test.a', ' lda #0');
|
||||||
|
project.setMainFile('test.a');
|
||||||
project.updateFile('test.a', ' lda #1'); // don't send twice (yet)
|
project.updateFile('test.a', ' lda #1'); // don't send twice (yet)
|
||||||
assert.deepEqual(msgs, expectmsgs);
|
assert.deepEqual(msgs, expectmsgs);
|
||||||
store.getItem('test.a', function(err, result) {
|
store.getItem('test.a', function(err, result) {
|
||||||
@ -122,7 +123,7 @@ describe('Store', function() {
|
|||||||
|
|
||||||
// lines: [ { line: 3, offset: 61440, insns: 'a9 00', iscode: true } ] }
|
// 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();
|
localStorage.clear();
|
||||||
localItems['__migrated__TEST'] = 'true';
|
localItems['__migrated__TEST'] = 'true';
|
||||||
var msgs = [];
|
var msgs = [];
|
||||||
|
19
test/cli/testutil.js
Normal file
19
test/cli/testutil.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user