1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-02 12:41:30 +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() { getCPUState() {
this.exports.machine_save_cpu_state(this.sys, this.cpustateptr); this.exports.machine_save_cpu_state(this.sys, this.cpustateptr);
var s = this.cpustatearr; var s = this.cpustatearr;
var pc = s[2] + (s[3]<<8);
return { return {
PC:s[2] + (s[3]<<8), PC:pc,
SP:s[9], SP:s[9],
A:s[6], A:s[6],
X:s[7], X:s[7],
@ -1282,6 +1283,7 @@ export class WASMMachine implements Machine {
D:s[10] & 8, D:s[10] & 8,
V:s[10] & 64, V:s[10] & 64,
N:s[10] & 128, N:s[10] & 128,
o:this.readConst(pc),
} }
} }
saveState() { 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) { if (this.offset2line) {
for (var i=0; i<=lookbehind; i++) { for (var i=0; i<=lookbehind; i++) {
var line = this.offset2line[PC]; var line = this.offset2line[PC];
if (line >= 0) { if (line >= 0) {
//console.log(this.lines.length, PC.toString(16), line); return {line:line, offset:PC};
return line;
} }
PC--; PC--;
} }

View File

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

View File

@ -322,8 +322,8 @@ export class SourceEditor implements ProjectView {
var state = lastDebugState; var state = lastDebugState;
if (state && state.c && this.sourcefile) { if (state && state.c && this.sourcefile) {
var EPC = state.c.EPC || state.c.PC; var EPC = state.c.EPC || state.c.PC;
var line = this.sourcefile.findLineForOffset(EPC, 15); var res = this.sourcefile.findLineForOffset(EPC, 15);
return line; return res && res.line;
} else } else
return -1; return -1;
} }
@ -509,13 +509,13 @@ export class ListingView extends DisassemblerView implements ProjectView {
var disasmview = this.getDisasmView(); var disasmview = this.getDisasmView();
disasmview.setValue(asmtext); disasmview.setValue(asmtext);
if (pc >= 0 && this.assemblyfile) { if (pc >= 0 && this.assemblyfile) {
var lineno = this.assemblyfile.findLineForOffset(pc, 15); var res = this.assemblyfile.findLineForOffset(pc, 15);
if (lineno) { if (res) {
// set cursor while debugging // set cursor while debugging
if (moveCursor) { 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)); filename = getFilenameForPath(getFilenamePrefix(filename));
for (var fileid in this.id2createfn) { for (var fileid in this.id2createfn) {
// ignore include files (TODO) // 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; continue;
if (getFilenameForPath(getFilenamePrefix(fileid)) == filename) return fileid; if (getFilenameForPath(getFilenamePrefix(fileid)) == filename) return fileid;
} }

View File

@ -116,7 +116,7 @@ describe('Store', function() {
assert.deepEqual([false], msgs); assert.deepEqual([false], msgs);
var lst = buildresult.listings.test; var lst = buildresult.listings.test;
console.log(lst); 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+16, 15));
assert.equal(null, lst.sourcefile.findLineForOffset(61440+1, 0)); assert.equal(null, lst.sourcefile.findLineForOffset(61440+1, 0));
assert.equal(null, lst.sourcefile.findLineForOffset(61440-1, 16)); assert.equal(null, lst.sourcefile.findLineForOffset(61440-1, 16));