1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-23 03:29:39 +00:00

editor uses markText to show current pc line, show state when paused

This commit is contained in:
Steven Hugg 2020-08-10 22:08:31 -05:00
parent d92cc5542d
commit 5269585fd0
5 changed files with 35 additions and 17 deletions

View File

@ -16,6 +16,12 @@
.gutter-info {
width: 1em;
}
.currentpc-span {
background-color: #7e2a70;
}
.currentpc-marker {
color: #ff66ee;
}
.tooltipbox {
position: relative;
display: inline-block;

View File

@ -814,8 +814,7 @@ export class BASICParser {
///// BASIC DIALECTS
// TODO
// TODO: require END statement, check FOR condition at start of loop
export const ECMA55_MINIMAL : BASICOptions = {
dialectName: "ECMA55",
asciiOnly : true,

View File

@ -515,11 +515,11 @@ export class BASICRuntime {
${lexpr} = value;
`
});
return `this.running=false;
return `this.running=false; this.curpc--;
this.input(${prompt}, ${stmt.args.length}).then((vals) => {
let valid = 1;
${setvals}
if (!valid) this.curpc--;
if (valid) this.curpc++;
this.running=true;
this.resume();
})`;
@ -641,10 +641,10 @@ export class BASICRuntime {
do__GET(stmt : basic.GET_Statement) {
var lexpr = this.assign2js(stmt.lexpr);
// TODO: single key input
return `this.running=false;
return `this.running=false; this.curpc--;
this.input().then((vals) => {
${lexpr} = this.convert(${JSON.stringify(stmt.lexpr.name)}, vals[0]);
this.running=true;
this.running=true; this.curpc++;
this.resume();
})`;
}

View File

@ -1890,6 +1890,7 @@ function globalErrorHandler(msgevent) {
werr = Object.create(err.$loc);
werr.msg = msg;
console.log(werr);
projectWindows.refresh(false);
}
showErrorAlert([werr]);
}

View File

@ -89,6 +89,7 @@ export class SourceEditor implements ProjectView {
dirtylisting = true;
sourcefile : SourceFile;
currentDebugLine : SourceLocation;
markCurrentPC; // TextMarker
errormsgs = [];
errorwidgets = [];
inspectWidget;
@ -331,20 +332,22 @@ export class SourceEditor implements ProjectView {
var addCurrentMarker = (line:SourceLocation) => {
var div = document.createElement("div");
div.style.color = '#66ffff';
div.classList.add('currentpc-marker');
div.appendChild(document.createTextNode("\u25b6"));
this.editor.setGutterMarker(line, "gutter-info", div);
this.editor.setGutterMarker(line.line-1, "gutter-info", div);
}
this.clearCurrentLine(moveCursor);
if (line) {
addCurrentMarker(line);
if (moveCursor) {
if (line.start || line.end)
this.editor.setSelection({line:line.line-1,ch:line.start}, {line:line.line-1,ch:line.end||line.start+1}, {scroll:true});
else
this.editor.setSelection({line:line.line-1,ch:0}, {line:line.line,ch:0}, {scroll:true});
this.editor.setCursor({line:line.line-1,ch:line.start||0}, {scroll:true});
}
var markOpts = {className:'currentpc-span', inclusiveLeft:true};
if (line.start || line.end)
this.markCurrentPC = this.editor.markText({line:line.line-1,ch:line.start}, {line:line.line-1,ch:line.end||line.start+1}, markOpts);
else
this.markCurrentPC = this.editor.markText({line:line.line-1,ch:0}, {line:line.line,ch:0}, markOpts);
this.currentDebugLine = line;
}
}
@ -355,18 +358,27 @@ export class SourceEditor implements ProjectView {
if (moveCursor) this.editor.setSelection(this.editor.getCursor());
this.currentDebugLine = null;
}
if (this.markCurrentPC) {
this.markCurrentPC.clear();
this.markCurrentPC = null;
}
}
getActiveLine() : SourceLocation {
var state = lastDebugState;
if (this.sourcefile && state) {
var EPC = (state && state.c && (state.c.EPC || state.c.PC)); // || (platform.getPC && platform.getPC());
var res = this.sourcefile.findLineForOffset(EPC, 15);
return res;
if (this.sourcefile) {
var cpustate = lastDebugState && lastDebugState.c;
if (!cpustate && platform.getCPUState && !platform.isRunning())
cpustate = platform.getCPUState();
if (cpustate) {
var EPC = (cpustate && (cpustate.EPC || cpustate.PC));
var res = this.sourcefile.findLineForOffset(EPC, 15);
return res;
}
}
}
refreshDebugState(moveCursor:boolean) {
// TODO: only if line changed
this.clearCurrentLine(moveCursor);
var line = this.getActiveLine();
if (line) {