1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 18:33:11 +00:00

initial swag at openRelevantListing(), still needs work on cc65

This commit is contained in:
Steven Hugg 2019-12-27 17:03:09 -06:00
parent a05190da44
commit e1b19b8119
6 changed files with 31 additions and 24 deletions

View File

@ -1270,8 +1270,9 @@ export class WASMMachine implements Machine {
getCPUState() {
this.exports.machine_save_cpu_state(this.sys, this.cpustateptr);
var s = this.cpustatearr;
var pc = s[2] + (s[3]<<8);
return {
PC:s[2] + (s[3]<<8),
PC:pc,
SP:s[9],
A:s[6],
X:s[7],
@ -1282,6 +1283,7 @@ export class WASMMachine implements Machine {
D:s[10] & 8,
V:s[10] & 64,
N:s[10] & 128,
o:this.readConst(pc),
}
}
saveState() {

View File

@ -28,13 +28,13 @@ export class SourceFile {
}
}
}
findLineForOffset(PC:number, lookbehind:number):number {
// TODO: smarter about looking for source lines between two addresses
findLineForOffset(PC:number, lookbehind:number) {
if (this.offset2line) {
for (var i=0; i<=lookbehind; i++) {
var line = this.offset2line[PC];
if (line >= 0) {
//console.log(this.lines.length, PC.toString(16), line);
return line;
return {line:line, offset:PC};
}
PC--;
}

View File

@ -54,6 +54,7 @@ var lastDebugInfo; // last debug info (CPU text)
var debugCategory; // current debug category
var debugTickPaused = false;
var recorderActive = false;
var lastViewClicked = null;
var lastBreakExpr = "c.PC == 0x6000";
@ -205,6 +206,7 @@ function refreshWindowList() {
projectWindows.setShowFunc(id, onopen);
$(a).click( (e) => {
projectWindows.createOrShow(id);
lastViewClicked = id;
});
}
}
@ -1096,36 +1098,38 @@ function checkRunReady() {
}
function openRelevantListing(state: EmuState) {
// if already on disassembly window, retain it
if (projectWindows.getActive() instanceof Views.DisassemblerView) return;
// if we clicked on disassembly window, retain it
if (lastViewClicked == '#disasm' && projectWindows.getActive() instanceof Views.DisassemblerView) return;
// search through listings
var listings = current_project.getListings();
var bestid = "#disasm";
var bestscore = 32;
if (listings) {
var pc = state.c ? (state.c.EPC || state.c.PC) : 0;
for (var lstfn in listings) {
//var wndid = current_project.filename2path[lstfn] || lstfn;
var wndid = projectWindows.findWindowWithFilePrefix(lstfn);
console.log(lstfn,wndid);
//console.log(lstfn,wndid);
if (projectWindows.isWindow(wndid)) {
var lst = listings[lstfn];
var file = lst.assemblyfile || lst.sourcefile;
// TODO: look for closest match, not just first match
var lineno = file && file.findLineForOffset(pc, 16); // TODO: const
console.log(hex(pc,4), wndid, lstfn, lineno);
if (lineno !== null) {
projectWindows.createOrShow(wndid, true);
return;
var file = lst.sourcefile || lst.assemblyfile;
var res = file && file.findLineForOffset(pc, 32); // TODO: const
if (res && pc-res.offset < bestscore) {
bestid = wndid;
bestscore = pc-res.offset;
}
console.log(hex(pc,4), wndid, lstfn, bestid, bestscore);
}
}
}
// if no appropriate listing found, use disassembly view
projectWindows.createOrShow("#disasm", true);
projectWindows.createOrShow(bestid, true);
}
function uiDebugCallback(state: EmuState) {
lastDebugState = state;
showDebugInfo(state);
//openRelevantListing(state);
openRelevantListing(state);
projectWindows.refresh(true); // move cursor
debugTickPaused = true;
}
@ -1175,6 +1179,7 @@ function resume() {
}
_resume();
userPaused = false;
lastViewClicked = null;
}
function togglePause() {

View File

@ -322,8 +322,8 @@ export class SourceEditor implements ProjectView {
var state = lastDebugState;
if (state && state.c && this.sourcefile) {
var EPC = state.c.EPC || state.c.PC;
var line = this.sourcefile.findLineForOffset(EPC, 15);
return line;
var res = this.sourcefile.findLineForOffset(EPC, 15);
return res && res.line;
} else
return -1;
}
@ -509,13 +509,13 @@ export class ListingView extends DisassemblerView implements ProjectView {
var disasmview = this.getDisasmView();
disasmview.setValue(asmtext);
if (pc >= 0 && this.assemblyfile) {
var lineno = this.assemblyfile.findLineForOffset(pc, 15);
if (lineno) {
var res = this.assemblyfile.findLineForOffset(pc, 15);
if (res) {
// set cursor while debugging
if (moveCursor) {
disasmview.setCursor(lineno-1, 0);
disasmview.setCursor(res.line-1, 0);
}
jumpToLine(disasmview, lineno-1);
jumpToLine(disasmview, res.line-1);
}
}
}

View File

@ -160,7 +160,7 @@ export class ProjectWindows {
filename = getFilenameForPath(getFilenamePrefix(filename));
for (var fileid in this.id2createfn) {
// ignore include files (TODO)
if (fileid.toLowerCase().endsWith('.h') || fileid.toLowerCase().endsWith('.inc'))
if (fileid.toLowerCase().endsWith('.h') || fileid.toLowerCase().endsWith('.inc') || fileid.toLowerCase().endsWith('.bas'))
continue;
if (getFilenameForPath(getFilenamePrefix(fileid)) == filename) return fileid;
}

View File

@ -116,7 +116,7 @@ describe('Store', function() {
assert.deepEqual([false], msgs);
var lst = buildresult.listings.test;
console.log(lst);
assert.equal(3, lst.sourcefile.findLineForOffset(61440+15, 15));
assert.deepEqual({line:3,offset:61440}, lst.sourcefile.findLineForOffset(61440+15, 15));
assert.equal(null, lst.sourcefile.findLineForOffset(61440+16, 15));
assert.equal(null, lst.sourcefile.findLineForOffset(61440+1, 0));
assert.equal(null, lst.sourcefile.findLineForOffset(61440-1, 16));