2018-07-06 00:13:07 +00:00
|
|
|
|
2018-08-27 13:28:31 +00:00
|
|
|
//import CodeMirror = require("codemirror");
|
2019-10-26 01:55:50 +00:00
|
|
|
import { SourceFile, WorkerError, Segment, FileData } from "../common/workertypes";
|
2020-01-04 23:11:14 +00:00
|
|
|
import { Platform, EmuState, lookupSymbol, BaseDebugPlatform, BaseZ80MachinePlatform, BaseZ80Platform, CpuState } from "../common/baseplatform";
|
2019-10-26 01:55:50 +00:00
|
|
|
import { hex, lpad, rpad, safeident, rgb2bgr } from "../common/util";
|
|
|
|
import { CodeAnalyzer } from "../common/analysis";
|
2020-01-04 23:11:14 +00:00
|
|
|
import { platform, platform_id, compparams, current_project, lastDebugState, projectWindows, runToPC } from "./ui";
|
2019-10-26 01:55:50 +00:00
|
|
|
import { ProbeRecorder, ProbeFlags } from "../common/recorder";
|
2020-07-11 20:26:59 +00:00
|
|
|
import { getMousePos, dumpRAM, Toolbar } from "../common/emu";
|
2019-10-26 01:55:50 +00:00
|
|
|
import * as pixed from "./pixeleditor";
|
2019-03-27 20:19:16 +00:00
|
|
|
declare var Mousetrap;
|
2018-07-07 14:55:27 +00:00
|
|
|
|
|
|
|
export interface ProjectView {
|
2019-10-19 15:29:40 +00:00
|
|
|
createDiv(parent:HTMLElement) : HTMLElement;
|
2019-03-08 01:00:12 +00:00
|
|
|
setVisible?(showing : boolean) : void;
|
2018-08-02 17:08:37 +00:00
|
|
|
refresh(moveCursor:boolean) : void;
|
2018-07-08 03:10:51 +00:00
|
|
|
tick?() : void;
|
2018-12-08 00:28:11 +00:00
|
|
|
getPath?() : string;
|
2018-07-08 03:10:51 +00:00
|
|
|
getValue?() : string;
|
2018-08-21 14:16:47 +00:00
|
|
|
setText?(text : string) : void;
|
2018-11-24 20:43:08 +00:00
|
|
|
insertText?(text : string) : void;
|
2018-07-07 14:55:27 +00:00
|
|
|
getCursorPC?() : number;
|
|
|
|
getSourceFile?() : SourceFile;
|
2018-07-08 03:10:51 +00:00
|
|
|
setGutterBytes?(line:number, s:string) : void;
|
2018-07-26 19:47:09 +00:00
|
|
|
markErrors?(errors:WorkerError[]) : void;
|
2018-07-08 03:10:51 +00:00
|
|
|
clearErrors?() : void;
|
2018-08-17 19:13:58 +00:00
|
|
|
setTimingResult?(result:CodeAnalyzer) : void;
|
2019-03-03 20:37:22 +00:00
|
|
|
recreateOnResize? : boolean;
|
2019-03-27 20:19:16 +00:00
|
|
|
undoStep?() : void;
|
2018-07-07 14:55:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
declare var CodeMirror;
|
|
|
|
declare var VirtualList;
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
// helper function for editor
|
2018-07-06 02:37:19 +00:00
|
|
|
function jumpToLine(ed, i:number) {
|
|
|
|
var t = ed.charCoords({line: i, ch: 0}, "local").top;
|
|
|
|
var middleHeight = ed.getScrollerElement().offsetHeight / 2;
|
|
|
|
ed.scrollTo(null, t - middleHeight - 5);
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2019-03-03 20:37:22 +00:00
|
|
|
function createTextSpan(text:string, className:string) : HTMLElement {
|
|
|
|
var span = document.createElement("span");
|
|
|
|
span.setAttribute("class", className);
|
|
|
|
span.appendChild(document.createTextNode(text));
|
|
|
|
return span;
|
|
|
|
}
|
|
|
|
|
2018-12-01 11:48:33 +00:00
|
|
|
// TODO: https://stackoverflow.com/questions/10463518/converting-em-to-px-in-javascript-and-getting-default-font-size
|
2018-07-07 14:55:27 +00:00
|
|
|
function getVisibleEditorLineHeight() : number{
|
2018-12-01 11:48:33 +00:00
|
|
|
return $("#booksMenuButton").first().height();
|
2018-07-07 14:55:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 14:51:41 +00:00
|
|
|
function newDiv(parent?, cls? : string) {
|
|
|
|
var div = $(document.createElement("div"));
|
|
|
|
if (parent) div.appendTo(parent)
|
|
|
|
if (cls) div.addClass(cls);
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
/////
|
|
|
|
|
2018-10-05 13:36:10 +00:00
|
|
|
const MAX_ERRORS = 200;
|
|
|
|
|
2020-07-06 23:53:20 +00:00
|
|
|
const MODEDEFS = {
|
|
|
|
default: { theme: 'mbo' }, // NOTE: Not merged w/ other modes
|
|
|
|
'6502': { isAsm: true },
|
|
|
|
z80: { isAsm: true },
|
|
|
|
jsasm: { isAsm: true },
|
|
|
|
gas: { isAsm: true },
|
|
|
|
inform6: { theme: 'cobalt' },
|
|
|
|
markdown: { lineWrap: true },
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-08 03:10:51 +00:00
|
|
|
export class SourceEditor implements ProjectView {
|
2018-07-07 14:55:27 +00:00
|
|
|
constructor(path:string, mode:string) {
|
|
|
|
this.path = path;
|
|
|
|
this.mode = mode;
|
|
|
|
}
|
|
|
|
path : string;
|
|
|
|
mode : string;
|
|
|
|
editor;
|
|
|
|
dirtylisting = true;
|
|
|
|
sourcefile : SourceFile;
|
|
|
|
currentDebugLine : number;
|
2018-07-26 19:47:09 +00:00
|
|
|
errormsgs = [];
|
2018-07-20 21:25:52 +00:00
|
|
|
errorwidgets = [];
|
2018-08-27 13:28:31 +00:00
|
|
|
inspectWidget;
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2019-10-19 15:29:40 +00:00
|
|
|
createDiv(parent:HTMLElement) {
|
2018-07-06 00:13:07 +00:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.setAttribute("class", "editor");
|
|
|
|
parent.appendChild(div);
|
2019-10-19 15:29:40 +00:00
|
|
|
var text = current_project.getFile(this.path) as string;
|
2018-11-28 18:54:42 +00:00
|
|
|
var asmOverride = text && this.mode=='verilog' && /__asm\b([\s\S]+?)\b__endasm\b/.test(text);
|
|
|
|
this.newEditor(div, asmOverride);
|
2019-03-27 13:02:01 +00:00
|
|
|
if (text) {
|
2018-07-07 14:55:27 +00:00
|
|
|
this.setText(text); // TODO: this calls setCode() and builds... it shouldn't
|
2019-03-27 13:02:01 +00:00
|
|
|
}
|
2018-08-04 14:21:50 +00:00
|
|
|
this.setupEditor();
|
2018-07-06 00:13:07 +00:00
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
2018-11-28 18:54:42 +00:00
|
|
|
newEditor(parent:HTMLElement, isAsmOverride?:boolean) {
|
2020-07-06 23:53:20 +00:00
|
|
|
var modedef = MODEDEFS[this.mode] || MODEDEFS.default;
|
|
|
|
var isAsm = isAsmOverride || modedef.isAsm;
|
|
|
|
var lineWrap = modedef.lineWrap;
|
|
|
|
var theme = modedef.theme || MODEDEFS.default.theme;
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor = CodeMirror(parent, {
|
2020-07-06 23:53:20 +00:00
|
|
|
theme: theme,
|
2018-07-06 00:13:07 +00:00
|
|
|
lineNumbers: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
tabSize: 8,
|
|
|
|
indentAuto: true,
|
2018-11-21 16:53:33 +00:00
|
|
|
lineWrapping: lineWrap,
|
2018-07-06 00:13:07 +00:00
|
|
|
gutters: isAsm ? ["CodeMirror-linenumbers", "gutter-offset", "gutter-bytes", "gutter-clock", "gutter-info"]
|
|
|
|
: ["CodeMirror-linenumbers", "gutter-offset", "gutter-info"],
|
|
|
|
});
|
2018-08-04 14:21:50 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-04 14:21:50 +00:00
|
|
|
setupEditor() {
|
2018-07-06 00:13:07 +00:00
|
|
|
var timer;
|
2020-01-04 23:11:14 +00:00
|
|
|
// update file in project (and recompile) when edits made
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor.on('changes', (ed, changeobj) => {
|
2018-07-06 00:13:07 +00:00
|
|
|
clearTimeout(timer);
|
2018-07-07 14:55:27 +00:00
|
|
|
timer = setTimeout( () => {
|
|
|
|
current_project.updateFile(this.path, this.editor.getValue());
|
2018-07-20 21:25:52 +00:00
|
|
|
}, 300);
|
2018-07-06 00:13:07 +00:00
|
|
|
});
|
2020-01-04 23:11:14 +00:00
|
|
|
// inspect symbol when it's highlighted (double-click)
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor.on('cursorActivity', (ed) => {
|
|
|
|
var start = this.editor.getCursor(true);
|
|
|
|
var end = this.editor.getCursor(false);
|
2018-08-27 13:28:31 +00:00
|
|
|
if (start.line == end.line && start.ch < end.ch && end.ch-start.ch < 80) {
|
2018-07-07 14:55:27 +00:00
|
|
|
var name = this.editor.getSelection();
|
2018-08-27 13:28:31 +00:00
|
|
|
this.inspect(name);
|
2018-07-06 00:13:07 +00:00
|
|
|
} else {
|
2018-08-27 13:28:31 +00:00
|
|
|
this.inspect(null);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
});
|
2020-01-04 23:11:14 +00:00
|
|
|
// gutter clicked
|
|
|
|
this.editor.on("gutterClick", (cm, n) => {
|
|
|
|
this.toggleBreakpoint(n);
|
|
|
|
});
|
|
|
|
// set editor mode for highlighting, etc
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor.setOption("mode", this.mode);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2020-01-04 23:11:14 +00:00
|
|
|
|
2018-08-27 13:28:31 +00:00
|
|
|
inspect(ident : string) : void {
|
|
|
|
var result;
|
|
|
|
if (platform.inspect) {
|
|
|
|
result = platform.inspect(ident);
|
|
|
|
}
|
|
|
|
if (this.inspectWidget) {
|
|
|
|
this.inspectWidget.clear();
|
|
|
|
this.inspectWidget = null;
|
|
|
|
}
|
|
|
|
if (result) {
|
2019-03-03 20:37:22 +00:00
|
|
|
var infospan = createTextSpan(result, "tooltipinfoline");
|
2018-08-27 13:28:31 +00:00
|
|
|
var line = this.editor.getCursor().line;
|
|
|
|
this.inspectWidget = this.editor.addLineWidget(line, infospan, {above:false});
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
setText(text:string) {
|
2019-03-27 13:02:01 +00:00
|
|
|
var i,j;
|
|
|
|
var oldtext = this.editor.getValue();
|
|
|
|
if (oldtext != text) {
|
|
|
|
// find minimum range to undo
|
2019-03-27 20:19:16 +00:00
|
|
|
for (i=0; i<oldtext.length && i<text.length && text[i] == oldtext[i]; i++) { }
|
|
|
|
for (j=0; j<oldtext.length && j<text.length && text[text.length-1-j] == oldtext[oldtext.length-1-j]; j++) { }
|
2019-03-27 13:02:01 +00:00
|
|
|
//console.log(i,j,oldtext.substring(i,oldtext.length-j));
|
|
|
|
this.replaceSelection(i, oldtext.length-j, text.substring(i, text.length-j)); // calls setCode()
|
|
|
|
// clear history if setting empty editor
|
|
|
|
if (oldtext == '') {
|
|
|
|
this.editor.clearHistory();
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-11-24 20:43:08 +00:00
|
|
|
insertText(text:string) {
|
|
|
|
var cur = this.editor.getCursor();
|
|
|
|
this.editor.replaceRange(text, cur, cur);
|
|
|
|
}
|
|
|
|
|
2019-03-27 13:02:01 +00:00
|
|
|
replaceSelection(start:number, end:number, text:string) {
|
|
|
|
this.editor.setSelection(this.editor.posFromIndex(start), this.editor.posFromIndex(end));
|
|
|
|
this.editor.replaceSelection(text);
|
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getValue() : string {
|
|
|
|
return this.editor.getValue();
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getPath() : string { return this.path; }
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-07-26 19:47:09 +00:00
|
|
|
addErrorMarker(line:number, msg:string) {
|
2018-07-06 00:13:07 +00:00
|
|
|
var div = document.createElement("div");
|
|
|
|
div.setAttribute("class", "tooltipbox tooltiperror");
|
|
|
|
div.appendChild(document.createTextNode("\u24cd"));
|
2018-07-25 17:29:09 +00:00
|
|
|
this.editor.setGutterMarker(line, "gutter-info", div);
|
2018-07-26 19:47:09 +00:00
|
|
|
this.errormsgs.push({line:line, msg:msg});
|
|
|
|
// expand line widgets when mousing over errors
|
|
|
|
$(div).mouseover((e) => {
|
|
|
|
this.expandErrors();
|
|
|
|
});
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-26 19:47:09 +00:00
|
|
|
addErrorLine(line:number, msg:string) {
|
2019-03-03 20:37:22 +00:00
|
|
|
var errspan = createTextSpan(msg, "tooltiperrorline");
|
2018-07-26 19:47:09 +00:00
|
|
|
this.errorwidgets.push(this.editor.addLineWidget(line, errspan));
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-26 19:47:09 +00:00
|
|
|
expandErrors() {
|
|
|
|
var e;
|
|
|
|
while (e = this.errormsgs.shift()) {
|
|
|
|
this.addErrorLine(e.line, e.msg);
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-26 19:47:09 +00:00
|
|
|
markErrors(errors:WorkerError[]) {
|
2018-07-06 00:13:07 +00:00
|
|
|
// TODO: move cursor to error line if offscreen?
|
2018-07-07 14:55:27 +00:00
|
|
|
this.clearErrors();
|
|
|
|
var numLines = this.editor.lineCount();
|
2018-10-05 13:36:10 +00:00
|
|
|
errors = errors.slice(0, MAX_ERRORS);
|
2018-07-06 00:13:07 +00:00
|
|
|
for (var info of errors) {
|
|
|
|
// only mark errors with this filename, or without any filename
|
2018-07-07 14:55:27 +00:00
|
|
|
if (!info.path || this.path.endsWith(info.path)) {
|
2018-07-06 00:13:07 +00:00
|
|
|
var line = info.line-1;
|
|
|
|
if (line < 0 || line >= numLines) line = 0;
|
2018-07-26 19:47:09 +00:00
|
|
|
this.addErrorMarker(line, info.msg);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
clearErrors() {
|
|
|
|
this.editor.clearGutter("gutter-info");
|
2018-08-02 17:08:37 +00:00
|
|
|
this.refreshDebugState(false);
|
2018-07-07 14:55:27 +00:00
|
|
|
this.dirtylisting = true;
|
2018-07-20 21:25:52 +00:00
|
|
|
// clear line widgets
|
2018-07-26 19:47:09 +00:00
|
|
|
this.errormsgs = [];
|
2018-07-20 21:25:52 +00:00
|
|
|
while (this.errorwidgets.length)
|
|
|
|
this.errorwidgets.shift().clear();
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getSourceFile() : SourceFile { return this.sourcefile; }
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-18 14:21:18 +00:00
|
|
|
updateListing() {
|
2018-07-06 00:13:07 +00:00
|
|
|
// update editor annotations
|
2018-11-28 17:39:10 +00:00
|
|
|
// TODO: recreate editor if gutter-bytes is used (verilog)
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor.clearGutter("gutter-info");
|
|
|
|
this.editor.clearGutter("gutter-bytes");
|
|
|
|
this.editor.clearGutter("gutter-offset");
|
|
|
|
this.editor.clearGutter("gutter-clock");
|
|
|
|
var lstlines = this.sourcefile.lines || [];
|
2018-07-06 00:13:07 +00:00
|
|
|
for (var info of lstlines) {
|
|
|
|
if (info.offset >= 0) {
|
2018-08-02 19:49:30 +00:00
|
|
|
this.setGutter("gutter-offset", info.line-1, hex(info.offset&0xffff,4));
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
if (info.insns) {
|
|
|
|
var insnstr = info.insns.length > 9 ? ("...") : info.insns;
|
2018-08-02 19:49:30 +00:00
|
|
|
this.setGutter("gutter-bytes", info.line-1, insnstr);
|
2018-07-06 00:13:07 +00:00
|
|
|
if (info.iscode) {
|
2018-08-14 20:28:29 +00:00
|
|
|
// TODO: labels trick this part?
|
2019-06-11 13:39:45 +00:00
|
|
|
if (info.cycles) {
|
|
|
|
this.setGutter("gutter-clock", info.line-1, info.cycles+"");
|
|
|
|
} else if (platform.getOpcodeMetadata) {
|
|
|
|
var opcode = parseInt(info.insns.split(" ")[0], 16);
|
2018-07-06 00:13:07 +00:00
|
|
|
var meta = platform.getOpcodeMetadata(opcode, info.offset);
|
|
|
|
var clockstr = meta.minCycles+"";
|
2018-08-02 19:49:30 +00:00
|
|
|
this.setGutter("gutter-clock", info.line-1, clockstr);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-02 19:49:30 +00:00
|
|
|
setGutter(type:string, line:number, text:string) {
|
|
|
|
var lineinfo = this.editor.lineInfo(line);
|
2018-08-05 14:00:53 +00:00
|
|
|
if (lineinfo && lineinfo.gutterMarkers && lineinfo.gutterMarkers[type]) {
|
2018-08-02 19:49:30 +00:00
|
|
|
// do not replace existing marker
|
|
|
|
} else {
|
|
|
|
var textel = document.createTextNode(text);
|
|
|
|
this.editor.setGutterMarker(line, type, textel);
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
setGutterBytes(line:number, s:string) {
|
2018-08-02 19:49:30 +00:00
|
|
|
this.setGutter("gutter-bytes", line-1, s);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-17 19:13:58 +00:00
|
|
|
setTimingResult(result:CodeAnalyzer) : void {
|
|
|
|
this.editor.clearGutter("gutter-bytes");
|
2019-11-12 00:17:33 +00:00
|
|
|
if (this.sourcefile == null) return;
|
2018-08-17 19:13:58 +00:00
|
|
|
// show the lines
|
2018-08-18 00:46:55 +00:00
|
|
|
for (const line of Object.keys(this.sourcefile.line2offset)) {
|
2018-08-17 19:13:58 +00:00
|
|
|
var pc = this.sourcefile.line2offset[line];
|
|
|
|
var minclocks = result.pc2minclocks[pc];
|
|
|
|
var maxclocks = result.pc2maxclocks[pc];
|
|
|
|
if (minclocks>=0 && maxclocks>=0) {
|
|
|
|
var s;
|
|
|
|
if (maxclocks == minclocks)
|
|
|
|
s = minclocks + "";
|
|
|
|
else
|
|
|
|
s = minclocks + "-" + maxclocks;
|
|
|
|
if (maxclocks == result.MAX_CLOCKS)
|
|
|
|
s += "+";
|
|
|
|
this.setGutterBytes(parseInt(line), s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-02 17:08:37 +00:00
|
|
|
setCurrentLine(line:number, moveCursor:boolean) {
|
2018-07-07 14:55:27 +00:00
|
|
|
|
|
|
|
var addCurrentMarker = (line:number) => {
|
2018-07-06 00:13:07 +00:00
|
|
|
var div = document.createElement("div");
|
|
|
|
div.style.color = '#66ffff';
|
|
|
|
div.appendChild(document.createTextNode("\u25b6"));
|
2018-07-07 14:55:27 +00:00
|
|
|
this.editor.setGutterMarker(line, "gutter-info", div);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-07-07 14:55:27 +00:00
|
|
|
|
|
|
|
this.clearCurrentLine();
|
2018-07-06 00:13:07 +00:00
|
|
|
if (line>0) {
|
|
|
|
addCurrentMarker(line-1);
|
2018-08-02 17:08:37 +00:00
|
|
|
if (moveCursor)
|
|
|
|
this.editor.setSelection({line:line,ch:0}, {line:line-1,ch:0}, {scroll:true});
|
2018-07-07 14:55:27 +00:00
|
|
|
this.currentDebugLine = line;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
clearCurrentLine() {
|
|
|
|
if (this.currentDebugLine) {
|
|
|
|
this.editor.clearGutter("gutter-info");
|
|
|
|
this.editor.setSelection(this.editor.getCursor());
|
|
|
|
this.currentDebugLine = 0;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-04 14:21:50 +00:00
|
|
|
getActiveLine() {
|
2018-07-06 00:13:07 +00:00
|
|
|
var state = lastDebugState;
|
2018-08-04 14:21:50 +00:00
|
|
|
if (state && state.c && this.sourcefile) {
|
2018-09-13 00:54:25 +00:00
|
|
|
var EPC = state.c.EPC || state.c.PC;
|
2019-12-27 23:03:09 +00:00
|
|
|
var res = this.sourcefile.findLineForOffset(EPC, 15);
|
|
|
|
return res && res.line;
|
2018-08-04 14:21:50 +00:00
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-08-04 14:21:50 +00:00
|
|
|
refreshDebugState(moveCursor:boolean) {
|
2019-04-22 17:32:34 +00:00
|
|
|
this.clearCurrentLine();
|
2018-08-04 14:21:50 +00:00
|
|
|
var line = this.getActiveLine();
|
|
|
|
if (line >= 0) {
|
|
|
|
this.setCurrentLine(line, moveCursor);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
refreshListing() {
|
2018-08-18 14:21:18 +00:00
|
|
|
// lookup corresponding sourcefile for this file, using listing
|
2018-07-07 14:55:27 +00:00
|
|
|
var lst = current_project.getListingForFile(this.path);
|
2018-08-19 23:25:42 +00:00
|
|
|
if (lst && lst.sourcefile && lst.sourcefile !== this.sourcefile) {
|
2018-08-18 14:21:18 +00:00
|
|
|
this.sourcefile = lst.sourcefile;
|
|
|
|
this.dirtylisting = true;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-08-18 14:21:18 +00:00
|
|
|
if (!this.sourcefile || !this.dirtylisting) return;
|
|
|
|
this.dirtylisting = false;
|
|
|
|
this.updateListing();
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 17:08:37 +00:00
|
|
|
refresh(moveCursor: boolean) {
|
2018-07-07 14:55:27 +00:00
|
|
|
this.refreshListing();
|
2018-08-02 17:08:37 +00:00
|
|
|
this.refreshDebugState(moveCursor);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2020-01-04 23:11:14 +00:00
|
|
|
|
|
|
|
tick() {
|
|
|
|
this.refreshDebugState(false);
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getLine(line : number) {
|
|
|
|
return this.editor.getLine(line-1);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getCurrentLine() : number {
|
|
|
|
return this.editor.getCursor().line+1;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getCursorPC() : number {
|
|
|
|
var line = this.getCurrentLine();
|
|
|
|
while (this.sourcefile && line >= 0) {
|
|
|
|
var pc = this.sourcefile.line2offset[line];
|
2018-07-06 00:13:07 +00:00
|
|
|
if (pc >= 0) return pc;
|
|
|
|
line--;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-27 20:19:16 +00:00
|
|
|
undoStep() {
|
|
|
|
this.editor.execCommand('undo');
|
|
|
|
}
|
2020-01-04 23:11:14 +00:00
|
|
|
|
2020-07-10 21:37:04 +00:00
|
|
|
toggleBreakpoint(lineno: number) {
|
|
|
|
// TODO: we have to always start at beginning of frame
|
2020-01-04 23:11:14 +00:00
|
|
|
if (this.sourcefile != null) {
|
|
|
|
var targetPC = this.sourcefile.line2offset[lineno+1];
|
2020-07-10 21:37:04 +00:00
|
|
|
/*
|
2020-06-06 14:37:59 +00:00
|
|
|
var bpid = "pc" + targetPC;
|
2020-07-10 21:37:04 +00:00
|
|
|
if (platform.hasBreakpoint(bpid)) {
|
|
|
|
platform.clearBreakpoint(bpid);
|
|
|
|
} else {
|
|
|
|
platform.setBreakpoint(bpid, () => {
|
|
|
|
return platform.getPC() == targetPC;
|
|
|
|
});
|
|
|
|
}
|
2020-06-06 14:37:59 +00:00
|
|
|
*/
|
2020-01-04 23:11:14 +00:00
|
|
|
runToPC(targetPC);
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2019-04-24 20:56:53 +00:00
|
|
|
const disasmWindow = 1024; // disassemble this many bytes around cursor
|
2019-04-22 17:32:34 +00:00
|
|
|
|
2018-07-08 03:10:51 +00:00
|
|
|
export class DisassemblerView implements ProjectView {
|
2018-07-07 14:55:27 +00:00
|
|
|
disasmview;
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getDisasmView() { return this.disasmview; }
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
createDiv(parent : HTMLElement) {
|
2018-07-06 00:13:07 +00:00
|
|
|
var div = document.createElement('div');
|
|
|
|
div.setAttribute("class", "editor");
|
|
|
|
parent.appendChild(div);
|
2018-07-07 14:55:27 +00:00
|
|
|
this.newEditor(div);
|
2018-07-06 00:13:07 +00:00
|
|
|
return div;
|
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
newEditor(parent : HTMLElement) {
|
|
|
|
this.disasmview = CodeMirror(parent, {
|
2018-07-06 00:13:07 +00:00
|
|
|
mode: 'z80', // TODO: pick correct one
|
|
|
|
theme: 'cobalt',
|
|
|
|
tabSize: 8,
|
|
|
|
readOnly: true,
|
|
|
|
styleActiveLine: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: too many globals
|
2018-08-02 17:08:37 +00:00
|
|
|
refresh(moveCursor: boolean) {
|
2019-04-07 16:33:01 +00:00
|
|
|
var state = lastDebugState || platform.saveState(); // TODO?
|
2018-07-06 00:13:07 +00:00
|
|
|
var pc = state.c ? state.c.PC : 0;
|
|
|
|
var curline = 0;
|
|
|
|
var selline = 0;
|
2018-09-17 20:09:09 +00:00
|
|
|
var addr2symbol = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {};
|
2018-07-06 00:13:07 +00:00
|
|
|
// TODO: not perfect disassembler
|
2018-07-07 14:55:27 +00:00
|
|
|
var disassemble = (start, end) => {
|
2018-07-06 00:13:07 +00:00
|
|
|
if (start < 0) start = 0;
|
|
|
|
if (end > 0xffff) end = 0xffff;
|
|
|
|
// TODO: use pc2visits
|
|
|
|
var a = start;
|
|
|
|
var s = "";
|
|
|
|
while (a < end) {
|
2018-09-11 00:44:53 +00:00
|
|
|
var disasm = platform.disassemble(a, platform.readAddress.bind(platform));
|
2018-07-06 00:13:07 +00:00
|
|
|
/* TODO: look thru all source files
|
2018-07-07 14:55:27 +00:00
|
|
|
var srclinenum = sourcefile && this.sourcefile.offset2line[a];
|
2018-07-06 00:13:07 +00:00
|
|
|
if (srclinenum) {
|
|
|
|
var srcline = getActiveEditor().getLine(srclinenum);
|
|
|
|
if (srcline && srcline.trim().length) {
|
|
|
|
s += "; " + srclinenum + ":\t" + srcline + "\n";
|
|
|
|
curline++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
var bytes = "";
|
2018-08-28 12:28:53 +00:00
|
|
|
var comment = "";
|
2018-07-06 00:13:07 +00:00
|
|
|
for (var i=0; i<disasm.nbytes; i++)
|
|
|
|
bytes += hex(platform.readAddress(a+i));
|
|
|
|
while (bytes.length < 14)
|
|
|
|
bytes += ' ';
|
2018-08-14 20:28:29 +00:00
|
|
|
var dstr = disasm.line;
|
2019-08-20 12:28:59 +00:00
|
|
|
if (addr2symbol && disasm.isaddr) { // TODO: move out
|
2018-08-14 20:28:29 +00:00
|
|
|
dstr = dstr.replace(/([^#])[$]([0-9A-F]+)/, (substr:string, ...args:any[]):string => {
|
|
|
|
var addr = parseInt(args[1], 16);
|
|
|
|
var sym = addr2symbol[addr];
|
|
|
|
if (sym) return (args[0] + sym);
|
2018-08-15 04:43:52 +00:00
|
|
|
sym = addr2symbol[addr-1];
|
2018-08-14 20:28:29 +00:00
|
|
|
if (sym) return (args[0] + sym + "+1");
|
|
|
|
return substr;
|
|
|
|
});
|
|
|
|
}
|
2018-08-28 12:28:53 +00:00
|
|
|
if (addr2symbol) {
|
|
|
|
var sym = addr2symbol[a];
|
|
|
|
if (sym) {
|
|
|
|
comment = "; " + sym;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var dline = hex(parseInt(a), 4) + "\t" + rpad(bytes,14) + "\t" + rpad(dstr,30) + comment + "\n";
|
2018-07-06 00:13:07 +00:00
|
|
|
s += dline;
|
|
|
|
if (a == pc) selline = curline;
|
|
|
|
curline++;
|
|
|
|
a += disasm.nbytes || 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2019-04-22 17:32:34 +00:00
|
|
|
var text = disassemble(pc-disasmWindow, pc) + disassemble(pc, pc+disasmWindow);
|
2018-07-07 14:55:27 +00:00
|
|
|
this.disasmview.setValue(text);
|
2019-09-17 00:04:14 +00:00
|
|
|
if (moveCursor) {
|
2018-08-02 17:08:37 +00:00
|
|
|
this.disasmview.setCursor(selline, 0);
|
|
|
|
}
|
2019-09-17 00:04:14 +00:00
|
|
|
jumpToLine(this.disasmview, selline);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getCursorPC() : number {
|
|
|
|
var line = this.disasmview.getCursor().line;
|
2018-07-06 00:13:07 +00:00
|
|
|
if (line >= 0) {
|
2018-09-05 02:28:12 +00:00
|
|
|
var toks = this.disasmview.getLine(line).trim().split(/\s+/);
|
2018-07-06 00:13:07 +00:00
|
|
|
if (toks && toks.length >= 1) {
|
|
|
|
var pc = parseInt(toks[0], 16);
|
|
|
|
if (pc >= 0) return pc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2018-07-08 03:10:51 +00:00
|
|
|
export class ListingView extends DisassemblerView implements ProjectView {
|
2018-07-07 14:55:27 +00:00
|
|
|
assemblyfile : SourceFile;
|
2018-08-19 23:25:42 +00:00
|
|
|
path : string;
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-08-19 23:25:42 +00:00
|
|
|
constructor(lstfn : string) {
|
2018-07-07 14:55:27 +00:00
|
|
|
super();
|
2018-08-19 23:25:42 +00:00
|
|
|
this.path = lstfn;
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshListing() {
|
|
|
|
// lookup corresponding assemblyfile for this file, using listing
|
|
|
|
var lst = current_project.getListingForFile(this.path);
|
2019-06-02 01:14:52 +00:00
|
|
|
// TODO?
|
2019-09-29 13:36:20 +00:00
|
|
|
this.assemblyfile = lst && (lst.assemblyfile || lst.sourcefile);
|
2018-07-07 14:55:27 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 17:08:37 +00:00
|
|
|
refresh(moveCursor: boolean) {
|
2018-08-19 23:25:42 +00:00
|
|
|
this.refreshListing();
|
2020-07-06 23:53:20 +00:00
|
|
|
// load listing text into editor
|
|
|
|
if (!this.assemblyfile) return;
|
2018-07-07 14:55:27 +00:00
|
|
|
var asmtext = this.assemblyfile.text;
|
|
|
|
var disasmview = this.getDisasmView();
|
2018-07-06 00:13:07 +00:00
|
|
|
disasmview.setValue(asmtext);
|
2020-07-06 23:53:20 +00:00
|
|
|
// go to PC
|
|
|
|
if (!platform.saveState) return;
|
|
|
|
var state = lastDebugState || platform.saveState();
|
|
|
|
var pc = state.c ? (state.c.EPC || state.c.PC) : 0;
|
2019-09-17 00:04:14 +00:00
|
|
|
if (pc >= 0 && this.assemblyfile) {
|
2019-12-27 23:03:09 +00:00
|
|
|
var res = this.assemblyfile.findLineForOffset(pc, 15);
|
|
|
|
if (res) {
|
2018-07-06 00:13:07 +00:00
|
|
|
// set cursor while debugging
|
2019-09-17 00:04:14 +00:00
|
|
|
if (moveCursor) {
|
2019-12-27 23:03:09 +00:00
|
|
|
disasmview.setCursor(res.line-1, 0);
|
2019-09-17 00:04:14 +00:00
|
|
|
}
|
2019-12-27 23:03:09 +00:00
|
|
|
jumpToLine(disasmview, res.line-1);
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2020-07-04 21:39:41 +00:00
|
|
|
interface VirtualTextLine {
|
|
|
|
text : string;
|
|
|
|
clas? : string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VirtualTextScroller {
|
|
|
|
memorylist;
|
|
|
|
maindiv : HTMLElement;
|
|
|
|
getLineAt : (row:number) => VirtualTextLine;
|
|
|
|
|
|
|
|
constructor(parent : HTMLElement) {
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.setAttribute("class", "memdump");
|
|
|
|
parent.appendChild(div);
|
|
|
|
this.maindiv = div;
|
|
|
|
}
|
|
|
|
|
|
|
|
create(workspace : HTMLElement, maxRowCount : number, fn : (row:number) => VirtualTextLine) {
|
|
|
|
this.getLineAt = fn;
|
|
|
|
this.memorylist = new VirtualList({
|
|
|
|
w: $(workspace).width(),
|
|
|
|
h: $(workspace).height(),
|
|
|
|
itemHeight: getVisibleEditorLineHeight(),
|
|
|
|
totalRows: maxRowCount, // TODO?
|
|
|
|
generatorFn: (row : number) => {
|
|
|
|
var line = fn(row);
|
|
|
|
var linediv = document.createElement("div");
|
|
|
|
linediv.appendChild(document.createTextNode(line.text));
|
|
|
|
if (line.clas != null) linediv.className = line.clas;
|
|
|
|
return linediv;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(this.maindiv).append(this.memorylist.container);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: refactor with elsewhere
|
|
|
|
refresh() {
|
|
|
|
if (this.memorylist) {
|
|
|
|
$(this.maindiv).find('[data-index]').each( (i,e) => {
|
|
|
|
var div = e;
|
|
|
|
var row = parseInt(div.getAttribute('data-index'));
|
|
|
|
var oldtext = div.innerText;
|
|
|
|
var line = this.getLineAt(row);
|
|
|
|
var newtext = line.text;
|
|
|
|
if (oldtext != newtext) {
|
|
|
|
div.innerText = newtext;
|
|
|
|
if (line.clas != null && !div.classList.contains(line.clas)) {
|
|
|
|
var oldclasses = Array.from(div.classList);
|
|
|
|
oldclasses.forEach((c) => div.classList.remove(c));
|
|
|
|
div.classList.add('vrow');
|
|
|
|
div.classList.add(line.clas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
function ignoreSymbol(sym:string) {
|
|
|
|
return sym.endsWith('_SIZE__') || sym.endsWith('_LAST__') || sym.endsWith('STACKSIZE__') || sym.endsWith('FILEOFFS__')
|
|
|
|
|| sym.startsWith('l__') || sym.startsWith('s__') || sym.startsWith('.__.');
|
|
|
|
}
|
|
|
|
|
2018-08-19 23:25:42 +00:00
|
|
|
// TODO: make it use debug state
|
2018-08-24 00:53:37 +00:00
|
|
|
// TODO: make it safe (load/restore state?)
|
2020-07-04 21:39:41 +00:00
|
|
|
// TODO: refactor w/ VirtualTextLine
|
2018-07-08 03:10:51 +00:00
|
|
|
export class MemoryView implements ProjectView {
|
2018-07-07 14:55:27 +00:00
|
|
|
memorylist;
|
|
|
|
dumplines;
|
|
|
|
maindiv : HTMLElement;
|
2019-03-03 20:37:22 +00:00
|
|
|
recreateOnResize = true;
|
2019-08-27 20:10:10 +00:00
|
|
|
totalRows = 0x1400;
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
createDiv(parent : HTMLElement) {
|
|
|
|
var div = document.createElement('div');
|
2018-07-06 00:13:07 +00:00
|
|
|
div.setAttribute("class", "memdump");
|
|
|
|
parent.appendChild(div);
|
2018-09-11 00:44:53 +00:00
|
|
|
this.showMemoryWindow(parent, div);
|
2018-07-07 14:55:27 +00:00
|
|
|
return this.maindiv = div;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-07-07 14:55:27 +00:00
|
|
|
|
2018-09-11 00:44:53 +00:00
|
|
|
showMemoryWindow(workspace:HTMLElement, parent:HTMLElement) {
|
2018-07-07 14:55:27 +00:00
|
|
|
this.memorylist = new VirtualList({
|
2018-09-11 00:44:53 +00:00
|
|
|
w: $(workspace).width(),
|
|
|
|
h: $(workspace).height(),
|
2018-07-06 00:13:07 +00:00
|
|
|
itemHeight: getVisibleEditorLineHeight(),
|
2019-08-27 20:10:10 +00:00
|
|
|
totalRows: this.totalRows,
|
2018-07-07 14:55:27 +00:00
|
|
|
generatorFn: (row : number) => {
|
|
|
|
var s = this.getMemoryLineAt(row);
|
|
|
|
var linediv = document.createElement("div");
|
|
|
|
if (this.dumplines) {
|
|
|
|
var dlr = this.dumplines[row];
|
|
|
|
if (dlr) linediv.classList.add('seg_' + this.getMemorySegment(this.dumplines[row].a));
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-07-07 14:55:27 +00:00
|
|
|
linediv.appendChild(document.createTextNode(s));
|
|
|
|
return linediv;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
});
|
2018-07-07 14:55:27 +00:00
|
|
|
$(parent).append(this.memorylist.container);
|
|
|
|
this.tick();
|
|
|
|
if (compparams && this.dumplines)
|
2019-02-26 15:56:51 +00:00
|
|
|
this.scrollToAddress(compparams.data_start);
|
|
|
|
}
|
2019-03-03 16:32:25 +00:00
|
|
|
|
2019-02-26 15:56:51 +00:00
|
|
|
scrollToAddress(addr : number) {
|
2019-09-03 23:48:12 +00:00
|
|
|
if (this.dumplines) {
|
|
|
|
this.memorylist.scrollToItem(this.findMemoryWindowLine(addr));
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
refresh() {
|
2018-09-15 22:47:40 +00:00
|
|
|
this.dumplines = null;
|
2018-09-18 18:09:51 +00:00
|
|
|
this.tick();
|
2018-07-07 14:55:27 +00:00
|
|
|
}
|
2018-11-21 12:21:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
tick() {
|
|
|
|
if (this.memorylist) {
|
|
|
|
$(this.maindiv).find('[data-index]').each( (i,e) => {
|
2018-07-06 00:13:07 +00:00
|
|
|
var div = $(e);
|
2018-07-07 14:55:27 +00:00
|
|
|
var row = parseInt(div.attr('data-index'));
|
2018-07-06 00:13:07 +00:00
|
|
|
var oldtext = div.text();
|
2018-07-07 14:55:27 +00:00
|
|
|
var newtext = this.getMemoryLineAt(row);
|
2018-07-06 00:13:07 +00:00
|
|
|
if (oldtext != newtext)
|
|
|
|
div.text(newtext);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getMemoryLineAt(row : number) : string {
|
2018-07-06 00:13:07 +00:00
|
|
|
var offset = row * 16;
|
|
|
|
var n1 = 0;
|
|
|
|
var n2 = 16;
|
|
|
|
var sym;
|
2018-07-07 14:55:27 +00:00
|
|
|
if (this.getDumpLines()) {
|
|
|
|
var dl = this.dumplines[row];
|
2018-07-06 00:13:07 +00:00
|
|
|
if (dl) {
|
|
|
|
offset = dl.a & 0xfff0;
|
|
|
|
n1 = dl.a - offset;
|
|
|
|
n2 = n1 + dl.l;
|
|
|
|
sym = dl.s;
|
|
|
|
} else {
|
|
|
|
return '.';
|
|
|
|
}
|
|
|
|
}
|
2018-09-18 18:09:51 +00:00
|
|
|
var s = hex(offset+n1,4) + ' ';
|
2018-07-06 00:13:07 +00:00
|
|
|
for (var i=0; i<n1; i++) s += ' ';
|
|
|
|
if (n1 > 8) s += ' ';
|
|
|
|
for (var i=n1; i<n2; i++) {
|
2019-03-15 01:55:16 +00:00
|
|
|
var read = this.readAddress(offset+i);
|
2018-07-06 00:13:07 +00:00
|
|
|
if (i==8) s += ' ';
|
2019-05-11 19:31:09 +00:00
|
|
|
s += ' ' + (typeof read == 'number' ? hex(read,2) : '??');
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
for (var i=n2; i<16; i++) s += ' ';
|
|
|
|
if (sym) s += ' ' + sym;
|
|
|
|
return s;
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-15 01:55:16 +00:00
|
|
|
readAddress(n : number) {
|
|
|
|
return platform.readAddress(n);
|
|
|
|
}
|
2018-07-06 00:13:07 +00:00
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
getDumpLineAt(line : number) {
|
|
|
|
var d = this.dumplines[line];
|
2018-07-06 00:13:07 +00:00
|
|
|
if (d) {
|
|
|
|
return d.a + " " + d.s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: addr2symbol for ca65; and make it work without symbols
|
2018-07-07 14:55:27 +00:00
|
|
|
getDumpLines() {
|
2018-09-17 20:09:09 +00:00
|
|
|
var addr2sym = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {};
|
2018-09-15 22:47:40 +00:00
|
|
|
if (!this.dumplines) {
|
2018-07-07 14:55:27 +00:00
|
|
|
this.dumplines = [];
|
2018-07-06 00:13:07 +00:00
|
|
|
var ofs = 0;
|
|
|
|
var sym;
|
2018-11-21 12:21:07 +00:00
|
|
|
for (const _nextofs of Object.keys(addr2sym)) {
|
2018-07-06 00:13:07 +00:00
|
|
|
var nextofs = parseInt(_nextofs); // convert from string (stupid JS)
|
2018-09-15 22:47:40 +00:00
|
|
|
var nextsym = addr2sym[nextofs];
|
2018-07-06 00:13:07 +00:00
|
|
|
if (sym) {
|
2019-05-16 17:04:27 +00:00
|
|
|
// ignore certain symbols
|
2020-07-04 21:39:41 +00:00
|
|
|
if (ignoreSymbol(sym)) {
|
2019-05-14 16:01:54 +00:00
|
|
|
sym = '';
|
2020-07-04 21:39:41 +00:00
|
|
|
}
|
|
|
|
while (ofs < nextofs) {
|
|
|
|
var ofs2 = (ofs + 16) & 0xffff0;
|
|
|
|
if (ofs2 > nextofs) ofs2 = nextofs;
|
|
|
|
//if (ofs < 1000) console.log(ofs, ofs2, nextofs, sym);
|
|
|
|
this.dumplines.push({a:ofs, l:ofs2-ofs, s:sym});
|
|
|
|
ofs = ofs2;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sym = nextsym;
|
|
|
|
}
|
|
|
|
}
|
2018-07-07 14:55:27 +00:00
|
|
|
return this.dumplines;
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 15:56:51 +00:00
|
|
|
// TODO: use segments list?
|
2018-07-07 14:55:27 +00:00
|
|
|
getMemorySegment(a:number) : string {
|
2019-03-16 00:34:17 +00:00
|
|
|
if (compparams) {
|
|
|
|
if (a >= compparams.data_start && a < compparams.data_start+compparams.data_size) {
|
|
|
|
if (platform.getSP && a >= platform.getSP() - 15)
|
|
|
|
return 'stack';
|
|
|
|
else
|
|
|
|
return 'data';
|
|
|
|
}
|
|
|
|
else if (a >= compparams.code_start && a < compparams.code_start+(compparams.code_size||compparams.rom_size))
|
|
|
|
return 'code';
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
2019-03-16 00:34:17 +00:00
|
|
|
var segments = current_project.segments;
|
|
|
|
if (segments) {
|
|
|
|
for (var seg of segments) {
|
|
|
|
if (a >= seg.start && a < seg.start+seg.size) {
|
|
|
|
if (seg.type == 'rom') return 'code';
|
|
|
|
if (seg.type == 'ram') return 'data';
|
|
|
|
if (seg.type == 'io') return 'io';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 'unknown';
|
2018-07-06 00:13:07 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 14:55:27 +00:00
|
|
|
findMemoryWindowLine(a:number) : number {
|
|
|
|
for (var i=0; i<this.dumplines.length; i++)
|
|
|
|
if (this.dumplines[i].a >= a)
|
2018-07-06 00:13:07 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2018-12-01 09:45:55 +00:00
|
|
|
|
2019-03-15 01:55:16 +00:00
|
|
|
export class VRAMMemoryView extends MemoryView {
|
2019-08-27 20:10:10 +00:00
|
|
|
totalRows = 0x800;
|
2019-03-15 01:55:16 +00:00
|
|
|
readAddress(n : number) {
|
|
|
|
return platform.readVRAMAddress(n);
|
|
|
|
}
|
|
|
|
getMemorySegment(a:number) : string {
|
|
|
|
return 'video';
|
|
|
|
}
|
|
|
|
getDumpLines() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 09:45:55 +00:00
|
|
|
///
|
|
|
|
|
|
|
|
export class BinaryFileView implements ProjectView {
|
2020-07-08 01:56:44 +00:00
|
|
|
vlist : VirtualTextScroller;
|
2018-12-01 09:45:55 +00:00
|
|
|
maindiv : HTMLElement;
|
2018-12-08 00:28:11 +00:00
|
|
|
path:string;
|
|
|
|
data:Uint8Array;
|
2019-03-03 20:37:22 +00:00
|
|
|
recreateOnResize = true;
|
2018-12-01 09:45:55 +00:00
|
|
|
|
2018-12-08 00:28:11 +00:00
|
|
|
constructor(path:string, data:Uint8Array) {
|
|
|
|
this.path = path;
|
2018-12-01 09:45:55 +00:00
|
|
|
this.data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) {
|
2020-07-08 01:56:44 +00:00
|
|
|
this.vlist = new VirtualTextScroller(parent);
|
|
|
|
this.vlist.create(parent, ((this.data.length+15) >> 4), this.getMemoryLineAt.bind(this));
|
|
|
|
return this.vlist.maindiv;
|
2018-12-01 09:45:55 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 01:56:44 +00:00
|
|
|
getMemoryLineAt(row : number) : VirtualTextLine {
|
2018-12-01 09:45:55 +00:00
|
|
|
var offset = row * 16;
|
|
|
|
var n1 = 0;
|
|
|
|
var n2 = 16;
|
|
|
|
var s = hex(offset+n1,4) + ' ';
|
|
|
|
for (var i=0; i<n1; i++) s += ' ';
|
|
|
|
if (n1 > 8) s += ' ';
|
|
|
|
for (var i=n1; i<n2; i++) {
|
|
|
|
var read = this.data[offset+i];
|
|
|
|
if (i==8) s += ' ';
|
|
|
|
s += ' ' + (read>=0?hex(read,2):' ');
|
|
|
|
}
|
2020-07-08 01:56:44 +00:00
|
|
|
return {text:s};
|
2018-12-01 09:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
2020-07-08 01:56:44 +00:00
|
|
|
this.vlist.refresh();
|
2018-12-01 09:45:55 +00:00
|
|
|
}
|
2020-07-08 01:56:44 +00:00
|
|
|
|
2018-12-08 00:28:11 +00:00
|
|
|
getPath() { return this.path; }
|
2018-12-01 09:45:55 +00:00
|
|
|
}
|
2019-02-21 21:47:25 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
export class MemoryMapView implements ProjectView {
|
|
|
|
maindiv : JQuery;
|
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) {
|
2019-03-22 14:51:41 +00:00
|
|
|
this.maindiv = newDiv(parent, 'vertical-scroll');
|
2020-07-06 17:47:24 +00:00
|
|
|
this.maindiv.css('display', 'grid');
|
|
|
|
this.maindiv.css('grid-template-columns', '5em 40% 40%');
|
2019-02-21 21:47:25 +00:00
|
|
|
return this.maindiv[0];
|
|
|
|
}
|
2019-03-03 16:32:25 +00:00
|
|
|
|
2019-02-21 22:41:59 +00:00
|
|
|
// TODO: overlapping segments (e.g. ROM + LC)
|
2020-07-06 17:47:24 +00:00
|
|
|
addSegment(seg : Segment, newrow : boolean) {
|
|
|
|
if (newrow) {
|
|
|
|
var offset = $('<div class="segment-offset" style="grid-column-start:1"/>');
|
|
|
|
offset.text('$'+hex(seg.start,4));
|
|
|
|
this.maindiv.append(offset);
|
|
|
|
}
|
|
|
|
var segdiv = $('<div class="segment"/>');
|
|
|
|
if (!newrow)
|
|
|
|
segdiv.css('grid-column-start', 3); // make sure it's on right side
|
2019-02-21 21:47:25 +00:00
|
|
|
if (seg.last)
|
|
|
|
segdiv.text(seg.name+" ("+(seg.last-seg.start)+" / "+seg.size+" bytes used)");
|
|
|
|
else
|
|
|
|
segdiv.text(seg.name+" ("+seg.size+" bytes)");
|
|
|
|
if (seg.size >= 256) {
|
|
|
|
var pad = (Math.log(seg.size) - Math.log(256)) * 0.5;
|
|
|
|
segdiv.css('padding-top', pad+'em');
|
|
|
|
segdiv.css('padding-bottom', pad+'em');
|
|
|
|
}
|
|
|
|
if (seg.type) {
|
|
|
|
segdiv.addClass('segment-'+seg.type);
|
|
|
|
}
|
2020-07-06 17:47:24 +00:00
|
|
|
this.maindiv.append(segdiv);
|
|
|
|
//var row = $('<div class="row"/>').append(offset, segdiv);
|
|
|
|
//var container = $('<div class="container"/>').append(row);
|
|
|
|
//this.maindiv.append(container);
|
2019-02-26 15:56:51 +00:00
|
|
|
segdiv.click(() => {
|
|
|
|
var memview = projectWindows.createOrShow('#memory') as MemoryView;
|
|
|
|
memview.scrollToAddress(seg.start);
|
|
|
|
});
|
2019-02-21 21:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.maindiv.empty();
|
|
|
|
var segments = current_project.segments;
|
|
|
|
if (segments) {
|
|
|
|
var curofs = 0;
|
2020-07-06 17:47:24 +00:00
|
|
|
var laststart = -1;
|
2019-02-21 21:47:25 +00:00
|
|
|
for (var seg of segments) {
|
2019-02-21 22:41:59 +00:00
|
|
|
//var used = seg.last ? (seg.last-seg.start) : seg.size;
|
2019-03-13 18:52:30 +00:00
|
|
|
if (seg.start > curofs)
|
2020-07-06 17:47:24 +00:00
|
|
|
this.addSegment({name:'',start:curofs, size:seg.start-curofs}, true);
|
|
|
|
this.addSegment(seg, laststart != seg.start);
|
|
|
|
laststart = seg.start;
|
2019-02-21 22:41:59 +00:00
|
|
|
curofs = seg.start + seg.size;
|
2019-02-21 21:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 16:32:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
// TODO: clear buffer when scrubbing
|
|
|
|
|
2020-01-04 20:14:36 +00:00
|
|
|
abstract class ProbeViewBaseBase {
|
2019-08-24 15:28:04 +00:00
|
|
|
probe : ProbeRecorder;
|
2019-08-27 15:42:23 +00:00
|
|
|
tooldiv : HTMLElement;
|
2020-07-11 20:26:59 +00:00
|
|
|
cumulativeData : boolean = false;
|
2019-08-26 18:28:52 +00:00
|
|
|
|
2020-07-09 18:27:56 +00:00
|
|
|
abstract tick() : void;
|
|
|
|
|
2020-07-11 18:46:47 +00:00
|
|
|
addr2symbol(addr : number) : string {
|
2019-08-27 20:10:10 +00:00
|
|
|
var _addr2sym = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {};
|
2020-07-11 18:46:47 +00:00
|
|
|
return _addr2sym[addr];
|
|
|
|
}
|
|
|
|
|
|
|
|
addr2str(addr : number) : string {
|
|
|
|
var sym = this.addr2symbol(addr);
|
2019-08-27 20:10:10 +00:00
|
|
|
if (typeof sym === 'string')
|
|
|
|
return '$' + hex(addr) + ' (' + sym + ')';
|
|
|
|
else
|
|
|
|
return '$' + hex(addr);
|
|
|
|
}
|
|
|
|
|
2019-08-27 15:42:23 +00:00
|
|
|
showTooltip(s:string) {
|
|
|
|
if (s) {
|
|
|
|
if (!this.tooldiv) {
|
|
|
|
this.tooldiv = document.createElement("div");
|
|
|
|
this.tooldiv.setAttribute("class", "tooltiptrack");
|
|
|
|
document.body.appendChild(this.tooldiv);
|
|
|
|
}
|
|
|
|
$(this.tooldiv).text(s).show();
|
|
|
|
} else {
|
|
|
|
$(this.tooldiv).hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
setVisible(showing : boolean) : void {
|
|
|
|
if (showing) {
|
|
|
|
this.probe = platform.startProbing();
|
2020-07-11 20:26:59 +00:00
|
|
|
this.probe.singleFrame = !this.cumulativeData;
|
2019-08-27 20:10:10 +00:00
|
|
|
this.tick();
|
2019-08-24 15:28:04 +00:00
|
|
|
} else {
|
2020-07-11 20:26:59 +00:00
|
|
|
if (this.probe) this.probe.singleFrame = true;
|
2019-08-24 15:28:04 +00:00
|
|
|
platform.stopProbing();
|
|
|
|
this.probe = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-04 23:11:14 +00:00
|
|
|
redraw( eventfn:(op,addr,col,row,clk,value) => void ) {
|
2019-08-24 15:28:04 +00:00
|
|
|
var p = this.probe;
|
|
|
|
if (!p || !p.idx) return; // if no probe, or if empty
|
|
|
|
var row=0;
|
|
|
|
var col=0;
|
2020-01-04 20:14:36 +00:00
|
|
|
var clk=0;
|
2019-08-24 15:28:04 +00:00
|
|
|
for (var i=0; i<p.idx; i++) {
|
|
|
|
var word = p.buf[i];
|
2020-01-04 23:11:14 +00:00
|
|
|
var addr = word & 0xffff;
|
|
|
|
var value = (word >> 16) & 0xff;
|
2019-08-24 15:28:04 +00:00
|
|
|
var op = word & 0xff000000;
|
|
|
|
switch (op) {
|
|
|
|
case ProbeFlags.SCANLINE: row++; col=0; break;
|
|
|
|
case ProbeFlags.FRAME: row=0; col=0; break;
|
2020-01-04 20:14:36 +00:00
|
|
|
case ProbeFlags.CLOCKS: col += addr; clk += addr; break;
|
2019-08-24 15:28:04 +00:00
|
|
|
default:
|
2020-01-04 23:11:14 +00:00
|
|
|
eventfn(op, addr, col, row, clk, value);
|
2019-08-24 15:28:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-08-27 17:26:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 23:11:14 +00:00
|
|
|
opToString(op:number, addr?:number, value?:number) {
|
2020-01-04 20:14:36 +00:00
|
|
|
var s = "";
|
|
|
|
switch (op) {
|
|
|
|
case ProbeFlags.EXECUTE: s = "Exec"; break;
|
|
|
|
case ProbeFlags.MEM_READ: s = "Read"; break;
|
|
|
|
case ProbeFlags.MEM_WRITE: s = "Write"; break;
|
|
|
|
case ProbeFlags.IO_READ: s = "IO Read"; break;
|
|
|
|
case ProbeFlags.IO_WRITE: s = "IO Write"; break;
|
|
|
|
case ProbeFlags.VRAM_READ: s = "VRAM Read"; break;
|
|
|
|
case ProbeFlags.VRAM_WRITE: s = "VRAM Write"; break;
|
|
|
|
case ProbeFlags.INTERRUPT: s = "Interrupt"; break;
|
|
|
|
case ProbeFlags.ILLEGAL: s = "Error"; break;
|
2020-07-11 23:38:45 +00:00
|
|
|
case ProbeFlags.SP_PUSH: s = "Stack Dec"; break;
|
|
|
|
case ProbeFlags.SP_POP: s = "Stack Inc"; break;
|
2020-01-04 20:14:36 +00:00
|
|
|
default: return "";
|
|
|
|
}
|
2020-01-04 23:11:14 +00:00
|
|
|
if (typeof addr == 'number') s += " " + this.addr2str(addr);
|
2020-01-05 02:45:27 +00:00
|
|
|
if ((op & ProbeFlags.HAS_VALUE) && typeof value == 'number') s += " = $" + hex(value,2);
|
2020-01-04 23:11:14 +00:00
|
|
|
return s;
|
2020-01-04 20:14:36 +00:00
|
|
|
}
|
2020-07-09 18:27:56 +00:00
|
|
|
|
2020-01-04 20:14:36 +00:00
|
|
|
getOpRGB(op:number) : number {
|
|
|
|
switch (op) {
|
|
|
|
case ProbeFlags.EXECUTE: return 0x018001;
|
|
|
|
case ProbeFlags.MEM_READ: return 0x800101;
|
|
|
|
case ProbeFlags.MEM_WRITE: return 0x010180;
|
|
|
|
case ProbeFlags.IO_READ: return 0x018080;
|
|
|
|
case ProbeFlags.IO_WRITE: return 0xc00180;
|
|
|
|
case ProbeFlags.VRAM_READ: return 0x808001;
|
|
|
|
case ProbeFlags.VRAM_WRITE: return 0x4080c0;
|
|
|
|
case ProbeFlags.INTERRUPT: return 0xcfcfcf;
|
|
|
|
case ProbeFlags.ILLEGAL: return 0x3f3fff;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class ProbeViewBase extends ProbeViewBaseBase {
|
|
|
|
|
|
|
|
maindiv : HTMLElement;
|
|
|
|
canvas : HTMLCanvasElement;
|
|
|
|
ctx : CanvasRenderingContext2D;
|
|
|
|
recreateOnResize = true;
|
2020-07-09 18:27:56 +00:00
|
|
|
|
|
|
|
abstract drawEvent(op, addr, col, row);
|
|
|
|
|
2020-01-04 20:14:36 +00:00
|
|
|
createCanvas(parent:HTMLElement, width:number, height:number) {
|
|
|
|
var div = document.createElement('div');
|
|
|
|
var canvas = document.createElement('canvas');
|
|
|
|
canvas.width = width;
|
|
|
|
canvas.height = height;
|
|
|
|
canvas.classList.add('pixelated');
|
|
|
|
canvas.style.width = '100%';
|
|
|
|
canvas.style.height = '90vh'; // i hate css
|
|
|
|
canvas.style.backgroundColor = 'black';
|
|
|
|
canvas.style.cursor = 'crosshair';
|
|
|
|
canvas.onmousemove = (e) => {
|
|
|
|
var pos = getMousePos(canvas, e);
|
|
|
|
this.showTooltip(this.getTooltipText(pos.x, pos.y));
|
|
|
|
$(this.tooldiv).css('left',e.pageX+10).css('top',e.pageY-30);
|
|
|
|
}
|
|
|
|
canvas.onmouseout = (e) => {
|
|
|
|
$(this.tooldiv).hide();
|
|
|
|
}
|
|
|
|
parent.appendChild(div);
|
|
|
|
div.appendChild(canvas);
|
|
|
|
this.canvas = canvas;
|
|
|
|
this.ctx = canvas.getContext('2d');
|
|
|
|
this.initCanvas();
|
|
|
|
return this.maindiv = div;
|
|
|
|
}
|
|
|
|
|
|
|
|
initCanvas() {
|
|
|
|
}
|
|
|
|
|
|
|
|
getTooltipText(x:number, y:number) : string {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
}
|
|
|
|
|
2019-08-27 17:26:25 +00:00
|
|
|
tick() {
|
|
|
|
this.clear();
|
|
|
|
this.redraw(this.drawEvent.bind(this));
|
2019-08-24 15:28:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class ProbeBitmapViewBase extends ProbeViewBase {
|
2019-08-24 22:08:37 +00:00
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
imageData : ImageData;
|
|
|
|
datau32 : Uint32Array;
|
|
|
|
recreateOnResize = false;
|
|
|
|
|
2019-08-25 14:45:36 +00:00
|
|
|
createDiv(parent : HTMLElement) {
|
|
|
|
var width = 160;
|
|
|
|
var height = 262;
|
|
|
|
try {
|
2019-08-27 17:26:25 +00:00
|
|
|
width = Math.ceil(platform['machine']['cpuCyclesPerLine']) || 256; // TODO
|
|
|
|
height = Math.ceil(platform['machine']['numTotalScanlines']) || 262; // TODO
|
2019-08-25 14:45:36 +00:00
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
return this.createCanvas(parent, width, height);
|
|
|
|
}
|
2019-08-24 15:28:04 +00:00
|
|
|
initCanvas() {
|
|
|
|
this.imageData = this.ctx.createImageData(this.canvas.width, this.canvas.height);
|
|
|
|
this.datau32 = new Uint32Array(this.imageData.data.buffer);
|
|
|
|
}
|
2019-08-27 17:26:25 +00:00
|
|
|
getTooltipText(x:number, y:number) : string {
|
|
|
|
x = x|0;
|
|
|
|
y = y|0;
|
|
|
|
var s = "";
|
2020-07-15 21:01:02 +00:00
|
|
|
var lastroutine = null;
|
|
|
|
var lastcol = -1;
|
2020-01-04 23:11:14 +00:00
|
|
|
this.redraw( (op,addr,col,row,clk,value) => {
|
2020-07-15 21:01:02 +00:00
|
|
|
if (op == ProbeFlags.EXECUTE) {
|
|
|
|
lastroutine = this.addr2symbol(addr) || lastroutine;
|
|
|
|
}
|
|
|
|
if (row == y && col <= x) {
|
|
|
|
if (col != lastcol) {
|
|
|
|
s = "";
|
|
|
|
lastcol = col;
|
|
|
|
}
|
|
|
|
if (s == "" && lastroutine) { s += "\n" + lastroutine; }
|
|
|
|
s += "\n" + this.opToString(op, addr, value);
|
2019-08-27 17:26:25 +00:00
|
|
|
}
|
|
|
|
} );
|
2019-08-27 20:10:10 +00:00
|
|
|
return 'X: ' + x + ' Y: ' + y + ' ' + s;
|
|
|
|
}
|
2019-08-27 17:26:25 +00:00
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
this.datau32.fill(0xff000000);
|
|
|
|
}
|
|
|
|
tick() {
|
|
|
|
super.tick();
|
|
|
|
this.ctx.putImageData(this.imageData, 0, 0);
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.datau32.fill(0xff000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 22:08:37 +00:00
|
|
|
export class AddressHeatMapView extends ProbeBitmapViewBase implements ProjectView {
|
2019-08-24 15:28:04 +00:00
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) {
|
|
|
|
return this.createCanvas(parent, 256, 256);
|
|
|
|
}
|
|
|
|
|
2019-08-26 18:28:52 +00:00
|
|
|
clear() {
|
|
|
|
for (var i=0; i<=0xffff; i++) {
|
|
|
|
var v = platform.readAddress(i);
|
|
|
|
var rgb = (v >> 2) | (v & 0x1f);
|
|
|
|
rgb |= (rgb<<8) | (rgb<<16);
|
|
|
|
this.datau32[i] = rgb | 0xff000000;
|
|
|
|
}
|
|
|
|
}
|
2019-08-27 15:42:23 +00:00
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
drawEvent(op, addr, col, row) {
|
2019-08-24 22:08:37 +00:00
|
|
|
var rgb = this.getOpRGB(op);
|
|
|
|
if (!rgb) return;
|
2019-08-24 15:28:04 +00:00
|
|
|
var x = addr & 0xff;
|
|
|
|
var y = (addr >> 8) & 0xff;
|
|
|
|
var data = this.datau32[addr & 0xffff];
|
2019-08-24 22:08:37 +00:00
|
|
|
data = data | rgb | 0xff000000;
|
2019-08-24 15:28:04 +00:00
|
|
|
this.datau32[addr & 0xffff] = data;
|
|
|
|
}
|
|
|
|
|
2019-08-27 15:42:23 +00:00
|
|
|
getTooltipText(x:number, y:number) : string {
|
2019-08-27 20:10:10 +00:00
|
|
|
var a = (x & 0xff) + (y << 8);
|
2020-07-15 21:01:02 +00:00
|
|
|
var s = "";
|
2019-08-27 20:10:10 +00:00
|
|
|
var pc = -1;
|
|
|
|
var already = {};
|
2020-07-15 21:01:02 +00:00
|
|
|
var lastroutine = null;
|
2020-01-04 23:11:14 +00:00
|
|
|
this.redraw( (op,addr,col,row,clk,value) => {
|
2019-08-27 20:10:10 +00:00
|
|
|
if (op == ProbeFlags.EXECUTE) {
|
|
|
|
pc = addr;
|
2020-07-15 21:01:02 +00:00
|
|
|
lastroutine = this.addr2symbol(addr) || lastroutine;
|
2019-08-27 20:10:10 +00:00
|
|
|
}
|
|
|
|
var key = op|pc;
|
|
|
|
if (addr == a && !already[key]) {
|
2020-07-15 21:01:02 +00:00
|
|
|
if (s == "" && lastroutine) { s += "\n" + lastroutine; }
|
|
|
|
s += "\nPC " + this.addr2str(pc) + " " + this.opToString(op, null, value);
|
|
|
|
already[key] = 1;
|
2019-08-27 20:10:10 +00:00
|
|
|
}
|
|
|
|
} );
|
2020-07-15 21:01:02 +00:00
|
|
|
return this.addr2str(a) + s;
|
2019-08-27 20:10:10 +00:00
|
|
|
}
|
2019-08-24 15:28:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-25 14:45:36 +00:00
|
|
|
export class RasterPCHeatMapView extends ProbeBitmapViewBase implements ProjectView {
|
|
|
|
|
|
|
|
drawEvent(op, addr, col, row) {
|
|
|
|
var iofs = col + row * this.canvas.width;
|
2019-08-27 17:26:25 +00:00
|
|
|
var rgb = this.getOpRGB(op);
|
|
|
|
if (!rgb) return;
|
2019-08-25 21:17:03 +00:00
|
|
|
var data = this.datau32[iofs];
|
|
|
|
data = data | rgb | 0xff000000;
|
|
|
|
this.datau32[iofs] = data;
|
2019-08-25 14:45:36 +00:00
|
|
|
}
|
2019-10-16 20:06:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 20:14:36 +00:00
|
|
|
export class ProbeLogView extends ProbeViewBaseBase {
|
2020-07-08 01:56:44 +00:00
|
|
|
vlist : VirtualTextScroller;
|
2020-01-04 20:14:36 +00:00
|
|
|
maindiv : HTMLElement;
|
|
|
|
recreateOnResize = true;
|
|
|
|
dumplines;
|
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) {
|
2020-07-08 01:56:44 +00:00
|
|
|
this.vlist = new VirtualTextScroller(parent);
|
|
|
|
this.vlist.create(parent, 160*262, this.getMemoryLineAt.bind(this));
|
|
|
|
return this.vlist.maindiv;
|
2020-01-04 20:14:36 +00:00
|
|
|
}
|
2020-07-08 01:56:44 +00:00
|
|
|
getMemoryLineAt(row : number) : VirtualTextLine {
|
|
|
|
var s : string = "";
|
|
|
|
var c : string = "seg_data";
|
2020-01-04 20:14:36 +00:00
|
|
|
var line = this.dumplines && this.dumplines[row];
|
|
|
|
if (line != null) {
|
2020-07-08 01:56:44 +00:00
|
|
|
var xtra : string = line.info.join(", ");
|
2020-07-10 12:02:33 +00:00
|
|
|
s = "(" + lpad(line.row,4) + ", " + lpad(line.col,4) + ") " + rpad(line.asm||"",20) + xtra;
|
2020-07-08 01:56:44 +00:00
|
|
|
if (xtra.indexOf("Write ") >= 0) c = "seg_io";
|
2020-07-09 18:27:56 +00:00
|
|
|
// if (xtra.indexOf("Stack ") >= 0) c = "seg_code";
|
2020-07-08 01:56:44 +00:00
|
|
|
}
|
|
|
|
return {text:s, clas:c};
|
2020-01-04 20:14:36 +00:00
|
|
|
}
|
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
}
|
|
|
|
tick() {
|
|
|
|
const isz80 = platform instanceof BaseZ80MachinePlatform || platform instanceof BaseZ80Platform; // TODO?
|
|
|
|
// cache each line in frame
|
|
|
|
this.dumplines = {};
|
2020-01-04 23:11:14 +00:00
|
|
|
this.redraw((op,addr,col,row,clk,value) => {
|
2020-01-04 20:14:36 +00:00
|
|
|
if (isz80) clk >>= 2;
|
|
|
|
var line = this.dumplines[clk];
|
|
|
|
if (line == null) {
|
|
|
|
line = {op:op, addr:addr, row:row, col:col, asm:null, info:[]};
|
|
|
|
this.dumplines[clk] = line;
|
|
|
|
}
|
|
|
|
switch (op) {
|
|
|
|
case ProbeFlags.EXECUTE:
|
|
|
|
if (platform.disassemble) {
|
|
|
|
var disasm = platform.disassemble(addr, platform.readAddress.bind(platform));
|
|
|
|
line.asm = disasm && disasm.line;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-04 23:11:14 +00:00
|
|
|
var xtra = this.opToString(op, addr, value);
|
2020-01-04 20:14:36 +00:00
|
|
|
if (xtra != "") line.info.push(xtra);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2020-07-08 01:56:44 +00:00
|
|
|
this.vlist.refresh();
|
2020-01-04 20:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 15:28:04 +00:00
|
|
|
///
|
|
|
|
|
2020-07-04 21:39:41 +00:00
|
|
|
export class ProbeSymbolView extends ProbeViewBaseBase {
|
|
|
|
vlist : VirtualTextScroller;
|
|
|
|
keys : string[];
|
|
|
|
recreateOnResize = true;
|
|
|
|
dumplines;
|
2020-07-11 20:26:59 +00:00
|
|
|
cumulativeData = true;
|
2020-07-04 21:39:41 +00:00
|
|
|
|
|
|
|
// TODO: auto resize
|
|
|
|
createDiv(parent : HTMLElement) {
|
|
|
|
// TODO: what if symbol list changes?
|
|
|
|
if (platform.debugSymbols && platform.debugSymbols.symbolmap) {
|
|
|
|
this.keys = Array.from(Object.keys(platform.debugSymbols.symbolmap).filter(sym => !ignoreSymbol(sym)));
|
|
|
|
} else {
|
|
|
|
this.keys = ['no symbols defined'];
|
|
|
|
}
|
|
|
|
this.vlist = new VirtualTextScroller(parent);
|
2020-07-11 23:38:45 +00:00
|
|
|
this.vlist.create(parent, this.keys.length + 1, this.getMemoryLineAt.bind(this));
|
2020-07-04 21:39:41 +00:00
|
|
|
return this.vlist.maindiv;
|
|
|
|
}
|
|
|
|
|
|
|
|
getMemoryLineAt(row : number) : VirtualTextLine {
|
2020-07-11 23:38:45 +00:00
|
|
|
// header line
|
|
|
|
if (row == 0) {
|
|
|
|
return {text: lpad("Symbol",35)+lpad("Reads",8)+lpad("Writes",8)};
|
|
|
|
}
|
|
|
|
var sym = this.keys[row-1];
|
2020-07-04 21:39:41 +00:00
|
|
|
var line = this.dumplines && this.dumplines[sym];
|
|
|
|
function getop(op) {
|
|
|
|
var n = line[op] | 0;
|
|
|
|
return lpad(n ? n.toString() : "", 8);
|
|
|
|
}
|
|
|
|
var s : string;
|
|
|
|
var c : string;
|
|
|
|
if (line != null) {
|
|
|
|
s = lpad(sym, 35)
|
|
|
|
+ getop(ProbeFlags.MEM_READ)
|
|
|
|
+ getop(ProbeFlags.MEM_WRITE);
|
|
|
|
if (line[ProbeFlags.EXECUTE])
|
|
|
|
c = 'seg_code';
|
|
|
|
else if (line[ProbeFlags.IO_READ] || line[ProbeFlags.IO_WRITE])
|
|
|
|
c = 'seg_io';
|
|
|
|
else
|
|
|
|
c = 'seg_data';
|
|
|
|
} else {
|
|
|
|
s = lpad(sym, 35);
|
|
|
|
c = 'seg_unknown';
|
|
|
|
}
|
|
|
|
return {text:s, clas:c};
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
tick() {
|
|
|
|
// cache each line in frame
|
|
|
|
this.dumplines = {};
|
|
|
|
this.redraw((op,addr,col,row,clk,value) => {
|
|
|
|
var sym = platform.debugSymbols.addr2symbol[addr];
|
|
|
|
if (sym != null) {
|
|
|
|
var line = this.dumplines[sym];
|
|
|
|
if (line == null) {
|
|
|
|
line = {};
|
|
|
|
this.dumplines[sym] = line;
|
|
|
|
}
|
|
|
|
line[op] = (line[op] | 0) + 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.vlist.refresh();
|
2020-07-11 20:26:59 +00:00
|
|
|
if (this.probe) this.probe.clear(); // clear cumulative data (TODO: doesnt work with seeking or debugging)
|
2020-07-04 21:39:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:56:44 +00:00
|
|
|
///
|
|
|
|
|
2020-07-08 21:21:41 +00:00
|
|
|
const MAX_CHILDREN = 256;
|
2020-07-08 01:56:44 +00:00
|
|
|
const MAX_STRING_LEN = 100;
|
|
|
|
|
2020-07-11 18:46:47 +00:00
|
|
|
var TREE_SHOW_DOLLAR_IDENTS = false;
|
|
|
|
|
2020-07-08 01:56:44 +00:00
|
|
|
class TreeNode {
|
|
|
|
parent : TreeNode;
|
|
|
|
name : string;
|
|
|
|
_div : HTMLElement;
|
|
|
|
_header : HTMLElement;
|
|
|
|
_inline : HTMLElement;
|
|
|
|
_content : HTMLElement;
|
|
|
|
children : Map<string,TreeNode>;
|
|
|
|
expanded = false;
|
|
|
|
level : number;
|
2020-07-09 18:27:56 +00:00
|
|
|
view : ProjectView;
|
2020-07-08 01:56:44 +00:00
|
|
|
|
|
|
|
constructor(parent : TreeNode, name : string) {
|
|
|
|
this.parent = parent;
|
|
|
|
this.name = name;
|
|
|
|
this.children = new Map();
|
|
|
|
this.level = parent ? (parent.level+1) : -1;
|
|
|
|
this.view = parent ? parent.view : null;
|
|
|
|
}
|
|
|
|
getDiv() {
|
|
|
|
if (this._div == null) {
|
|
|
|
this._div = document.createElement("div");
|
|
|
|
this._div.classList.add("vertical-scroll");
|
|
|
|
this._div.classList.add("tree-content");
|
|
|
|
this._header = document.createElement("div");
|
|
|
|
this._header.classList.add("tree-header");
|
|
|
|
this._header.classList.add("tree-level-" + this.level);
|
|
|
|
this._header.append(this.name);
|
|
|
|
this._inline = document.createElement("span");
|
|
|
|
this._inline.classList.add("tree-value");
|
|
|
|
this._header.append(this._inline);
|
|
|
|
this._div.append(this._header);
|
|
|
|
this.parent._content.append(this._div);
|
|
|
|
this._header.onclick = (e) => {
|
|
|
|
this.toggleExpanded();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (this.expanded && this._content == null) {
|
|
|
|
this._content = document.createElement("div");
|
|
|
|
this._div.append(this._content);
|
|
|
|
}
|
|
|
|
else if (!this.expanded && this._content != null) {
|
|
|
|
this._content.remove();
|
|
|
|
this._content = null;
|
|
|
|
this.children.clear();
|
|
|
|
}
|
|
|
|
return this._div;
|
|
|
|
}
|
|
|
|
toggleExpanded() {
|
|
|
|
this.expanded = !this.expanded;
|
|
|
|
this.view.tick();
|
|
|
|
}
|
|
|
|
remove() {
|
|
|
|
this._div.remove();
|
|
|
|
this._div = null;
|
|
|
|
}
|
|
|
|
update(obj : any) {
|
|
|
|
this.getDiv();
|
|
|
|
var text = "";
|
|
|
|
// is it a function? call it first, if we are expanded
|
2020-07-10 21:37:04 +00:00
|
|
|
// TODO: only call functions w/ signature
|
2020-07-08 01:56:44 +00:00
|
|
|
if (typeof obj == 'function' && this._content != null) {
|
|
|
|
obj = obj();
|
|
|
|
}
|
|
|
|
// check null first
|
|
|
|
if (obj == null) {
|
|
|
|
text = obj+"";
|
|
|
|
// primitive types
|
|
|
|
} else if (typeof obj == 'number') {
|
2020-07-09 18:27:56 +00:00
|
|
|
text = obj + "\t($" + hex(obj) + ")";
|
2020-07-08 01:56:44 +00:00
|
|
|
} else if (typeof obj == 'boolean') {
|
|
|
|
text = obj.toString();
|
|
|
|
} else if (typeof obj == 'string') {
|
|
|
|
if (obj.length < MAX_STRING_LEN)
|
|
|
|
text = obj;
|
|
|
|
else
|
|
|
|
text = obj.substring(0, MAX_STRING_LEN) + "...";
|
2020-07-09 12:03:09 +00:00
|
|
|
// typed byte array (TODO: other kinds)
|
|
|
|
} else if (obj.buffer && obj.length <= MAX_CHILDREN) {
|
2020-07-08 01:56:44 +00:00
|
|
|
text = dumpRAM(obj, 0, obj.length);
|
|
|
|
// recurse into object? (or function)
|
|
|
|
} else if (typeof obj == 'object' || typeof obj == 'function') {
|
2020-07-08 21:21:41 +00:00
|
|
|
// only if expanded
|
2020-07-08 01:56:44 +00:00
|
|
|
if (this._content != null) {
|
2020-07-08 21:21:41 +00:00
|
|
|
// split big arrays
|
|
|
|
if (obj.slice && obj.length > MAX_CHILDREN) {
|
|
|
|
let newobj = {};
|
|
|
|
let oldobj = obj;
|
|
|
|
var slicelen = MAX_CHILDREN;
|
|
|
|
while (obj.length / slicelen > MAX_CHILDREN) slicelen *= 2;
|
|
|
|
for (let ofs=0; ofs<oldobj.length; ofs+=slicelen) {
|
|
|
|
newobj["$"+hex(ofs)] = () => { return oldobj.slice(ofs, ofs+slicelen); }
|
|
|
|
}
|
|
|
|
obj = newobj;
|
|
|
|
}
|
|
|
|
// get object keys
|
|
|
|
let names = obj instanceof Array ? Array.from(obj.keys()) : Object.getOwnPropertyNames(obj);
|
2020-07-09 02:57:55 +00:00
|
|
|
if (names.length > MAX_CHILDREN) { // max # of child objects
|
|
|
|
let newobj = {};
|
|
|
|
let oldobj = obj;
|
|
|
|
var slicelen = 100;
|
|
|
|
while (names.length / slicelen > 100) slicelen *= 2;
|
|
|
|
for (let ofs=0; ofs<names.length; ofs+=slicelen) {
|
|
|
|
var newdict = {};
|
|
|
|
for (var i=ofs; i<ofs+slicelen; i++)
|
|
|
|
newdict[names[i]] = oldobj[names[i]];
|
|
|
|
newobj["["+ofs+"...]"] = newdict;
|
|
|
|
}
|
|
|
|
obj = newobj;
|
|
|
|
names = Object.getOwnPropertyNames(obj);
|
2020-07-08 01:56:44 +00:00
|
|
|
}
|
2020-07-09 02:57:55 +00:00
|
|
|
// track deletions
|
|
|
|
let orphans = new Set(this.children.keys());
|
|
|
|
// visit all children
|
|
|
|
names.forEach((name) => {
|
2020-07-11 18:46:47 +00:00
|
|
|
// hide $xxx idents?
|
|
|
|
var hidden = !TREE_SHOW_DOLLAR_IDENTS && typeof name === 'string' && name.startsWith("$$");
|
|
|
|
if (!hidden) {
|
|
|
|
let childnode = this.children.get(name);
|
|
|
|
if (childnode == null) {
|
|
|
|
childnode = new TreeNode(this, name);
|
|
|
|
this.children.set(name, childnode);
|
|
|
|
}
|
|
|
|
childnode.update(obj[name]);
|
2020-07-09 02:57:55 +00:00
|
|
|
}
|
|
|
|
orphans.delete(name);
|
|
|
|
});
|
|
|
|
// remove orphans
|
|
|
|
orphans.forEach((delname) => {
|
|
|
|
let childnode = this.children.get(delname);
|
|
|
|
childnode.remove();
|
|
|
|
this.children.delete(delname);
|
|
|
|
});
|
|
|
|
this._header.classList.add("tree-expanded");
|
|
|
|
this._header.classList.remove("tree-collapsed");
|
2020-07-08 01:56:44 +00:00
|
|
|
} else {
|
|
|
|
this._header.classList.add("tree-collapsed");
|
|
|
|
this._header.classList.remove("tree-expanded");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
text = typeof obj; // fallthrough
|
|
|
|
}
|
|
|
|
// change DOM object if needed
|
|
|
|
if (this._inline.innerText != text) {
|
|
|
|
this._inline.innerText = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 18:27:56 +00:00
|
|
|
function createTreeRootNode(parent : HTMLElement, view : ProjectView) : TreeNode {
|
|
|
|
var mainnode = new TreeNode(null, null);
|
|
|
|
mainnode.view = view;
|
|
|
|
mainnode._content = parent;
|
|
|
|
var root = new TreeNode(mainnode, "/");
|
|
|
|
root.expanded = true;
|
|
|
|
root.getDiv(); // create it
|
|
|
|
root._div.style.padding = '0px';
|
|
|
|
return root; // should be cached
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:56:44 +00:00
|
|
|
export abstract class TreeViewBase implements ProjectView {
|
|
|
|
root : TreeNode;
|
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) : HTMLElement {
|
2020-07-09 18:27:56 +00:00
|
|
|
this.root = createTreeRootNode(parent, this);
|
|
|
|
return this.root.getDiv();
|
2020-07-08 01:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
tick() {
|
|
|
|
this.root.update(this.getRootObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract getRootObject() : Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class StateBrowserView extends TreeViewBase implements ProjectView {
|
|
|
|
getRootObject() { return platform.saveState(); }
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DebugBrowserView extends TreeViewBase implements ProjectView {
|
|
|
|
getRootObject() { return platform.getDebugTree(); }
|
|
|
|
}
|
|
|
|
|
2020-07-09 18:27:56 +00:00
|
|
|
interface CallGraphNode {
|
2020-07-11 18:46:47 +00:00
|
|
|
$$SP : number;
|
2020-07-12 01:29:55 +00:00
|
|
|
$$PC : number;
|
|
|
|
count : number;
|
|
|
|
startLine : number;
|
|
|
|
endLine : number;
|
2020-07-09 18:27:56 +00:00
|
|
|
calls : {[id:string] : CallGraphNode};
|
|
|
|
}
|
|
|
|
|
2020-07-11 20:26:59 +00:00
|
|
|
// TODO: clear stack data when reset?
|
2020-07-09 18:27:56 +00:00
|
|
|
export class CallStackView extends ProbeViewBaseBase implements ProjectView {
|
|
|
|
treeroot : TreeNode;
|
|
|
|
graph : CallGraphNode;
|
|
|
|
stack : CallGraphNode[];
|
|
|
|
lastsp : number;
|
2020-07-11 23:38:45 +00:00
|
|
|
lastpc : number;
|
2020-07-09 18:27:56 +00:00
|
|
|
jsr : boolean;
|
2020-07-11 23:38:45 +00:00
|
|
|
rts : boolean;
|
2020-07-11 20:26:59 +00:00
|
|
|
cumulativeData = true;
|
2020-07-09 18:27:56 +00:00
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) : HTMLElement {
|
|
|
|
this.clear();
|
|
|
|
this.treeroot = createTreeRootNode(parent, this);
|
|
|
|
return this.treeroot.getDiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
tick() {
|
|
|
|
this.treeroot.update(this.getRootObject());
|
2020-07-11 20:26:59 +00:00
|
|
|
if (this.probe) this.probe.clear(); // clear cumulative data (TODO: doesnt work with seeking or debugging)
|
2020-07-09 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
2020-07-10 12:02:33 +00:00
|
|
|
this.graph = null;
|
2020-07-09 18:27:56 +00:00
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset() {
|
2020-07-10 21:37:04 +00:00
|
|
|
this.stack = [];
|
2020-07-09 18:27:56 +00:00
|
|
|
this.lastsp = -1;
|
2020-07-11 23:38:45 +00:00
|
|
|
this.lastpc = 0;
|
2020-07-09 18:27:56 +00:00
|
|
|
this.jsr = false;
|
2020-07-11 23:38:45 +00:00
|
|
|
this.rts = false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 01:29:55 +00:00
|
|
|
newNode(pc : number, sp : number) {
|
|
|
|
return {$$SP:sp, $$PC:pc, count:0, startLine:null, endLine:null, calls:{}};
|
|
|
|
}
|
|
|
|
|
2020-07-11 23:38:45 +00:00
|
|
|
newRoot(pc : number, sp : number) {
|
|
|
|
if (this.stack.length == 0) {
|
2020-07-12 01:29:55 +00:00
|
|
|
this.graph = this.newNode(null, sp);
|
2020-07-11 23:38:45 +00:00
|
|
|
this.stack.unshift(this.graph);
|
|
|
|
} else if (sp > this.stack[0].$$SP) {
|
2020-07-12 01:29:55 +00:00
|
|
|
this.graph = this.newNode(null, sp);
|
|
|
|
this.graph.calls[this.addr2str(pc)] = this.stack[0];
|
2020-07-11 23:38:45 +00:00
|
|
|
this.stack.unshift(this.graph);
|
|
|
|
}
|
2020-07-09 18:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getRootObject() : Object {
|
2020-07-11 20:26:59 +00:00
|
|
|
// TODO: we don't capture every frame, so if we don't start @ the top frame we may have problems
|
2020-07-09 18:27:56 +00:00
|
|
|
this.redraw((op,addr,col,row,clk,value) => {
|
|
|
|
switch (op) {
|
2020-07-10 12:02:33 +00:00
|
|
|
case ProbeFlags.SP_POP:
|
2020-07-11 23:38:45 +00:00
|
|
|
this.newRoot(this.lastpc, this.lastsp);
|
|
|
|
case ProbeFlags.SP_PUSH:
|
2020-07-10 12:02:33 +00:00
|
|
|
if (this.stack.length) {
|
2020-07-10 21:37:04 +00:00
|
|
|
let top = this.stack[this.stack.length-1];
|
2020-07-11 23:38:45 +00:00
|
|
|
var delta = this.lastsp - addr;
|
|
|
|
if ((delta == 2 || delta == 3) && addr < top.$$SP) { // TODO: look for opcode?
|
2020-07-10 12:02:33 +00:00
|
|
|
this.jsr = true;
|
|
|
|
}
|
2020-07-11 23:38:45 +00:00
|
|
|
if ((delta == -2 || delta == -3) && this.stack.length > 1 && addr > top.$$SP) {
|
|
|
|
this.rts = true;
|
2020-07-10 12:02:33 +00:00
|
|
|
}
|
2020-07-09 18:27:56 +00:00
|
|
|
}
|
2020-07-10 21:37:04 +00:00
|
|
|
this.lastsp = addr;
|
2020-07-09 18:27:56 +00:00
|
|
|
break;
|
|
|
|
case ProbeFlags.EXECUTE:
|
2020-07-11 23:38:45 +00:00
|
|
|
// TODO: better check for CALL/RET opcodes
|
|
|
|
if (Math.abs(addr - this.lastpc) >= 4) { // make sure we're jumping a distance (TODO)
|
|
|
|
if (this.jsr && this.stack.length) {
|
|
|
|
let top = this.stack[this.stack.length-1];
|
|
|
|
let sym = this.addr2str(addr);
|
|
|
|
let child = top.calls[sym];
|
2020-07-12 01:29:55 +00:00
|
|
|
if (child == null) {
|
|
|
|
child = top.calls[sym] = this.newNode(addr, this.lastsp);
|
|
|
|
}
|
2020-07-11 23:38:45 +00:00
|
|
|
else if (child.$$PC == null) child.$$PC = addr;
|
|
|
|
//this.stack.forEach((node) => node.count++);
|
|
|
|
this.stack.push(child);
|
|
|
|
child.count++;
|
|
|
|
child.startLine = row;
|
|
|
|
}
|
2020-07-09 18:27:56 +00:00
|
|
|
this.jsr = false;
|
2020-07-11 23:38:45 +00:00
|
|
|
if (this.rts && this.stack.length) {
|
|
|
|
this.stack.pop().endLine = row;
|
|
|
|
}
|
|
|
|
this.rts = false;
|
2020-07-09 18:27:56 +00:00
|
|
|
}
|
2020-07-11 23:38:45 +00:00
|
|
|
this.lastpc = addr;
|
2020-07-09 18:27:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2020-07-11 20:26:59 +00:00
|
|
|
if (this.graph) this.graph['$$Stack'] = this.stack;
|
2020-07-11 23:38:45 +00:00
|
|
|
return TREE_SHOW_DOLLAR_IDENTS ? this.graph : this.graph && this.graph.calls;
|
2020-07-09 18:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-11 18:46:47 +00:00
|
|
|
export class FrameCallsView extends ProbeViewBaseBase implements ProjectView {
|
|
|
|
treeroot : TreeNode;
|
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) : HTMLElement {
|
|
|
|
this.treeroot = createTreeRootNode(parent, this);
|
|
|
|
return this.treeroot.getDiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.tick();
|
|
|
|
}
|
|
|
|
|
|
|
|
tick() {
|
|
|
|
this.treeroot.update(this.getRootObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
getRootObject() : Object {
|
|
|
|
var frame = {};
|
|
|
|
this.redraw((op,addr,col,row,clk,value) => {
|
|
|
|
switch (op) {
|
|
|
|
case ProbeFlags.EXECUTE:
|
|
|
|
let sym = this.addr2symbol(addr);
|
|
|
|
if (sym) {
|
|
|
|
if (!frame[sym]) {
|
|
|
|
frame[sym] = row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
2020-07-09 18:27:56 +00:00
|
|
|
|
2020-07-08 01:56:44 +00:00
|
|
|
|
2020-07-04 21:39:41 +00:00
|
|
|
///
|
|
|
|
|
2019-03-22 14:51:41 +00:00
|
|
|
export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
2019-03-18 18:39:02 +00:00
|
|
|
maindiv : JQuery;
|
2019-03-20 18:10:50 +00:00
|
|
|
cureditordiv : JQuery;
|
2019-03-21 16:13:27 +00:00
|
|
|
cureditelem : JQuery;
|
2019-04-13 13:10:08 +00:00
|
|
|
cureditnode : pixed.PixNode;
|
2019-03-22 14:51:41 +00:00
|
|
|
rootnodes : pixed.PixNode[];
|
2019-03-22 16:32:37 +00:00
|
|
|
deferrednodes : pixed.PixNode[];
|
2019-03-18 18:39:02 +00:00
|
|
|
|
|
|
|
createDiv(parent : HTMLElement) {
|
2019-03-22 14:51:41 +00:00
|
|
|
this.maindiv = newDiv(parent, "vertical-scroll");
|
2019-03-18 18:39:02 +00:00
|
|
|
return this.maindiv[0];
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-22 14:51:41 +00:00
|
|
|
clearAssets() {
|
|
|
|
this.rootnodes = [];
|
2019-03-22 16:32:37 +00:00
|
|
|
this.deferrednodes = [];
|
2019-03-22 14:51:41 +00:00
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-05-15 03:32:19 +00:00
|
|
|
registerAsset(type:string, node:pixed.PixNode, deferred:number) {
|
2019-03-22 14:51:41 +00:00
|
|
|
this.rootnodes.push(node);
|
2019-03-22 16:32:37 +00:00
|
|
|
if (deferred) {
|
2019-05-15 03:32:19 +00:00
|
|
|
if (deferred > 1)
|
|
|
|
this.deferrednodes.push(node);
|
|
|
|
else
|
|
|
|
this.deferrednodes.unshift(node);
|
2019-03-22 16:32:37 +00:00
|
|
|
} else {
|
|
|
|
node.refreshRight();
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-22 16:32:37 +00:00
|
|
|
getPalettes(matchlen : number) : pixed.SelectablePalette[] {
|
|
|
|
var result = [];
|
|
|
|
this.rootnodes.forEach((node) => {
|
|
|
|
while (node != null) {
|
|
|
|
if (node instanceof pixed.PaletteFormatToRGB) {
|
|
|
|
// TODO: move to node class?
|
|
|
|
var palette = node.palette;
|
|
|
|
// match full palette length?
|
|
|
|
if (matchlen == palette.length) {
|
|
|
|
result.push({node:node, name:"Palette", palette:palette});
|
|
|
|
}
|
|
|
|
// look at palette slices
|
|
|
|
if (node.layout) {
|
|
|
|
node.layout.forEach(([name, start, len]) => {
|
|
|
|
if (start < palette.length) {
|
|
|
|
if (len == matchlen) {
|
|
|
|
var rgbs = palette.slice(start, start+len);
|
|
|
|
result.push({node:node, name:name, palette:rgbs});
|
2019-05-27 01:54:37 +00:00
|
|
|
} else if (-len == matchlen) { // reverse order
|
|
|
|
var rgbs = palette.slice(start, start-len);
|
|
|
|
rgbs.reverse();
|
|
|
|
result.push({node:node, name:name, palette:rgbs});
|
2019-03-22 16:32:37 +00:00
|
|
|
} else if (len+1 == matchlen) {
|
|
|
|
var rgbs = new Uint32Array(matchlen);
|
|
|
|
rgbs[0] = palette[0];
|
|
|
|
rgbs.set(palette.slice(start, start+len), 1);
|
|
|
|
result.push({node:node, name:name, palette:rgbs});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = node.right;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTilemaps(matchlen : number) : pixed.SelectableTilemap[] {
|
|
|
|
var result = [];
|
|
|
|
this.rootnodes.forEach((node) => {
|
|
|
|
while (node != null) {
|
|
|
|
if (node instanceof pixed.Palettizer) {
|
2019-05-15 03:32:19 +00:00
|
|
|
var rgbimgs = node.rgbimgs;
|
2019-03-22 19:59:34 +00:00
|
|
|
if (rgbimgs && rgbimgs.length >= matchlen) {
|
2019-03-22 16:32:37 +00:00
|
|
|
result.push({node:node, name:"Tilemap", images:node.images, rgbimgs:rgbimgs}); // TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node = node.right;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
2019-03-22 14:51:41 +00:00
|
|
|
}
|
2019-04-13 13:10:08 +00:00
|
|
|
|
|
|
|
isEditing() {
|
|
|
|
return this.cureditordiv != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentEditNode() {
|
|
|
|
return this.cureditnode;
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-04-13 13:10:08 +00:00
|
|
|
setCurrentEditor(div:JQuery, editing:JQuery, node:pixed.PixNode) {
|
2019-03-26 00:39:53 +00:00
|
|
|
const timeout = 250;
|
2019-03-20 18:10:50 +00:00
|
|
|
if (this.cureditordiv != div) {
|
|
|
|
if (this.cureditordiv) {
|
2019-03-26 00:39:53 +00:00
|
|
|
this.cureditordiv.hide(timeout);
|
2019-03-20 18:10:50 +00:00
|
|
|
this.cureditordiv = null;
|
|
|
|
}
|
|
|
|
if (div) {
|
|
|
|
this.cureditordiv = div;
|
2019-03-26 18:29:47 +00:00
|
|
|
this.cureditordiv.show();
|
2019-03-26 00:39:53 +00:00
|
|
|
this.cureditordiv[0].scrollIntoView({behavior: "smooth", block: "center"});
|
2019-03-26 18:29:47 +00:00
|
|
|
//setTimeout(() => { this.cureditordiv[0].scrollIntoView({behavior: "smooth", block: "center"}) }, timeout);
|
2019-03-20 18:10:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 16:13:27 +00:00
|
|
|
if (this.cureditelem) {
|
2019-03-26 00:39:53 +00:00
|
|
|
this.cureditelem.removeClass('selected');
|
2019-03-21 16:13:27 +00:00
|
|
|
this.cureditelem = null;
|
|
|
|
}
|
|
|
|
if (editing) {
|
|
|
|
this.cureditelem = editing;
|
2019-03-26 00:39:53 +00:00
|
|
|
this.cureditelem.addClass('selected');
|
2019-03-21 16:13:27 +00:00
|
|
|
}
|
2019-04-13 13:10:08 +00:00
|
|
|
while (node.left) {
|
|
|
|
node = node.left;
|
|
|
|
}
|
|
|
|
this.cureditnode = node;
|
2019-03-20 18:10:50 +00:00
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-18 18:39:02 +00:00
|
|
|
scanFileTextForAssets(id : string, data : string) {
|
|
|
|
// scan file for assets
|
|
|
|
// /*{json}*/ or ;;{json};;
|
2019-03-22 14:51:41 +00:00
|
|
|
// TODO: put before ident, look for = {
|
2019-03-18 18:39:02 +00:00
|
|
|
var result = [];
|
|
|
|
var re1 = /[/;][*;]([{].+[}])[*;][/;]/g;
|
|
|
|
var m;
|
|
|
|
while (m = re1.exec(data)) {
|
|
|
|
var start = m.index + m[0].length;
|
|
|
|
var end;
|
|
|
|
// TODO: verilog end
|
2019-03-22 19:59:34 +00:00
|
|
|
if (platform_id == 'verilog') {
|
|
|
|
end = data.indexOf("end", start); // asm
|
|
|
|
} else if (m[0].startsWith(';;')) {
|
2019-03-18 18:39:02 +00:00
|
|
|
end = data.indexOf(';;', start); // asm
|
|
|
|
} else {
|
|
|
|
end = data.indexOf(';', start); // C
|
|
|
|
}
|
2019-03-26 00:39:53 +00:00
|
|
|
//console.log(id, start, end, m[1], data.substring(start,end));
|
2019-03-18 18:39:02 +00:00
|
|
|
if (end > start) {
|
|
|
|
try {
|
|
|
|
var jsontxt = m[1].replace(/([A-Za-z]+):/g, '"$1":'); // fix lenient JSON
|
|
|
|
var json = JSON.parse(jsontxt);
|
|
|
|
// TODO: name?
|
|
|
|
result.push({fileid:id,fmt:json,start:start,end:end});
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 19:59:34 +00:00
|
|
|
// look for DEF_METASPRITE_2x2(playerRStand, 0xd8, 0)
|
|
|
|
// TODO: could also look in ROM
|
|
|
|
var re2 = /DEF_METASPRITE_(\d+)x(\d+)[(](\w+),\s*(\w+),\s*(\w+)/gi;
|
|
|
|
while (m = re2.exec(data)) {
|
|
|
|
var width = parseInt(m[1]);
|
|
|
|
var height = parseInt(m[2]);
|
|
|
|
var ident = m[3];
|
|
|
|
var tile = parseInt(m[4]);
|
|
|
|
var attr = parseInt(m[5]);
|
|
|
|
var metadefs = [];
|
|
|
|
for (var x=0; x<width; x++) {
|
|
|
|
for (var y=0; y<height; y++) {
|
|
|
|
metadefs.push({x:x*8, y:y*8, tile:tile, attr:attr});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var meta = {defs:metadefs,width:width*8,height:height*8};
|
|
|
|
result.push({fileid:id,label:ident,meta:meta});
|
|
|
|
}
|
2019-03-18 18:39:02 +00:00
|
|
|
return result;
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-04-13 13:10:08 +00:00
|
|
|
// TODO: move to pixeleditor.ts?
|
2019-03-26 18:29:47 +00:00
|
|
|
addPaletteEditorViews(parentdiv:JQuery, pal2rgb:pixed.PaletteFormatToRGB, callback) {
|
2019-03-22 14:51:41 +00:00
|
|
|
var adual = $('<div class="asset_dual"/>').appendTo(parentdiv);
|
2019-03-21 16:13:27 +00:00
|
|
|
var aeditor = $('<div class="asset_editor"/>').hide(); // contains editor, when selected
|
2019-03-18 18:39:02 +00:00
|
|
|
// TODO: they need to update when refreshed from right
|
2019-03-21 16:13:27 +00:00
|
|
|
var allrgbimgs = [];
|
2019-03-26 18:29:47 +00:00
|
|
|
pal2rgb.getAllColors().forEach((rgba) => { allrgbimgs.push(new Uint32Array([rgba])); }); // array of array of 1 rgb color (for picker)
|
2019-03-21 16:13:27 +00:00
|
|
|
var atable = $('<table/>').appendTo(adual);
|
|
|
|
aeditor.appendTo(adual);
|
|
|
|
// make default layout if not exists
|
2019-03-26 18:29:47 +00:00
|
|
|
var layout = pal2rgb.layout;
|
2019-03-21 16:13:27 +00:00
|
|
|
if (!layout) {
|
2019-03-26 18:29:47 +00:00
|
|
|
var len = pal2rgb.palette.length;
|
2019-03-26 00:39:53 +00:00
|
|
|
var imgsperline = len > 32 ? 8 : 4; // TODO: use 'n'?
|
2019-03-21 16:13:27 +00:00
|
|
|
layout = [];
|
|
|
|
for (var i=0; i<len; i+=imgsperline) {
|
|
|
|
layout.push(["", i, Math.min(len-i,imgsperline)]);
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
2019-03-21 16:13:27 +00:00
|
|
|
}
|
2019-03-26 18:29:47 +00:00
|
|
|
function updateCell(cell, j) {
|
|
|
|
var val = pal2rgb.words[j];
|
|
|
|
var rgb = pal2rgb.palette[j];
|
|
|
|
var hexcol = '#'+hex(rgb2bgr(rgb),6);
|
|
|
|
var textcol = (rgb & 0x008000) ? 'black' : 'white';
|
|
|
|
cell.text(hex(val,2)).css('background-color',hexcol).css('color',textcol);
|
|
|
|
}
|
2019-03-21 16:13:27 +00:00
|
|
|
// iterate over each row of the layout
|
|
|
|
layout.forEach( ([name, start, len]) => {
|
2019-03-26 18:29:47 +00:00
|
|
|
if (start < pal2rgb.palette.length) { // skip row if out of range
|
2019-03-21 16:13:27 +00:00
|
|
|
var arow = $('<tr/>').appendTo(atable);
|
|
|
|
$('<td/>').text(name).appendTo(arow);
|
|
|
|
var inds = [];
|
2019-05-27 01:54:37 +00:00
|
|
|
for (var k=start; k<start+Math.abs(len); k++)
|
2019-03-21 16:13:27 +00:00
|
|
|
inds.push(k);
|
2019-05-27 01:54:37 +00:00
|
|
|
if (len < 0)
|
|
|
|
inds.reverse();
|
2019-03-21 16:13:27 +00:00
|
|
|
inds.forEach( (i) => {
|
2019-03-26 18:29:47 +00:00
|
|
|
var cell = $('<td/>').addClass('asset_cell asset_editable').appendTo(arow);
|
|
|
|
updateCell(cell, i);
|
2019-03-21 16:13:27 +00:00
|
|
|
cell.click((e) => {
|
|
|
|
var chooser = new pixed.ImageChooser();
|
|
|
|
chooser.rgbimgs = allrgbimgs;
|
|
|
|
chooser.width = 1;
|
|
|
|
chooser.height = 1;
|
|
|
|
chooser.recreate(aeditor, (index, newvalue) => {
|
|
|
|
callback(i, index);
|
2019-03-26 18:29:47 +00:00
|
|
|
updateCell(cell, i);
|
2019-03-21 16:13:27 +00:00
|
|
|
});
|
2019-04-13 13:10:08 +00:00
|
|
|
this.setCurrentEditor(aeditor, cell, pal2rgb);
|
2019-03-21 16:13:27 +00:00
|
|
|
});
|
|
|
|
});
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
2019-03-20 18:10:50 +00:00
|
|
|
});
|
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-22 14:51:41 +00:00
|
|
|
addPixelEditor(parentdiv:JQuery, firstnode:pixed.PixNode, fmt:pixed.PixelEditorImageFormat) {
|
2019-03-20 18:10:50 +00:00
|
|
|
// data -> pixels
|
|
|
|
fmt.xform = 'scale(2)';
|
2019-03-23 14:37:49 +00:00
|
|
|
var mapper = new pixed.Mapper(fmt);
|
2019-03-20 18:10:50 +00:00
|
|
|
// TODO: rotate node?
|
|
|
|
firstnode.addRight(mapper);
|
|
|
|
// pixels -> RGBA
|
2019-03-22 16:32:37 +00:00
|
|
|
var palizer = new pixed.Palettizer(this, fmt);
|
2019-03-20 18:10:50 +00:00
|
|
|
mapper.addRight(palizer);
|
2019-03-21 16:13:27 +00:00
|
|
|
// add view objects
|
2019-03-22 14:51:41 +00:00
|
|
|
palizer.addRight(new pixed.CharmapEditor(this, newDiv(parentdiv), fmt));
|
2019-03-20 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 14:51:41 +00:00
|
|
|
addPaletteEditor(parentdiv:JQuery, firstnode:pixed.PixNode, palfmt?) {
|
2019-03-20 18:10:50 +00:00
|
|
|
// palette -> RGBA
|
2019-03-23 14:37:49 +00:00
|
|
|
var pal2rgb = new pixed.PaletteFormatToRGB(palfmt);
|
2019-03-20 18:10:50 +00:00
|
|
|
firstnode.addRight(pal2rgb);
|
2019-03-22 14:51:41 +00:00
|
|
|
// TODO: refresh twice?
|
2019-03-20 18:10:50 +00:00
|
|
|
firstnode.refreshRight();
|
2019-03-22 14:51:41 +00:00
|
|
|
// TODO: add view objects
|
2019-03-21 16:13:27 +00:00
|
|
|
// TODO: show which one is selected?
|
2019-03-26 18:29:47 +00:00
|
|
|
this.addPaletteEditorViews(parentdiv, pal2rgb,
|
2019-03-21 16:13:27 +00:00
|
|
|
(index, newvalue) => {
|
|
|
|
console.log('set entry', index, '=', newvalue);
|
2019-03-26 18:29:47 +00:00
|
|
|
// TODO: this forces update of palette rgb colors and file data
|
2019-03-21 16:13:27 +00:00
|
|
|
firstnode.words[index] = newvalue;
|
2019-03-26 18:29:47 +00:00
|
|
|
pal2rgb.words = null;
|
|
|
|
pal2rgb.updateRight();
|
|
|
|
pal2rgb.refreshLeft();
|
2019-03-21 16:13:27 +00:00
|
|
|
});
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-04-13 13:10:08 +00:00
|
|
|
ensureFileDiv(fileid : string) : JQuery<HTMLElement> {
|
|
|
|
var divid = this.getFileDivId(fileid);
|
|
|
|
var body = $(document.getElementById(divid));
|
|
|
|
if (body.length === 0) {
|
|
|
|
var filediv = newDiv(this.maindiv, 'asset_file');
|
|
|
|
var header = newDiv(filediv, 'asset_file_header').text(fileid);
|
|
|
|
body = newDiv(filediv).attr('id',divid).addClass('disable-select');
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
2019-03-21 16:13:27 +00:00
|
|
|
refreshAssetsInFile(fileid : string, data : FileData) : number {
|
|
|
|
let nassets = 0;
|
2019-03-22 14:51:41 +00:00
|
|
|
// TODO: check fmt w/h/etc limits
|
|
|
|
// TODO: defer editor creation
|
|
|
|
// TODO: only refresh when needed
|
2019-04-24 17:46:19 +00:00
|
|
|
if (platform_id.startsWith('nes') && fileid.endsWith('.chr') && data instanceof Uint8Array) {
|
2019-03-20 18:10:50 +00:00
|
|
|
// is this a NES CHR?
|
2019-03-26 18:29:47 +00:00
|
|
|
let node = new pixed.FileDataNode(projectWindows, fileid);
|
2019-03-20 18:10:50 +00:00
|
|
|
const neschrfmt = {w:8,h:8,bpp:1,count:(data.length>>4),brev:true,np:2,pofs:8,remap:[0,1,2,4,5,6,7,8,9,10,11,12]}; // TODO
|
2019-04-13 13:10:08 +00:00
|
|
|
this.addPixelEditor(this.ensureFileDiv(fileid), node, neschrfmt);
|
2019-05-15 03:32:19 +00:00
|
|
|
this.registerAsset("charmap", node, 1);
|
2019-03-26 18:29:47 +00:00
|
|
|
nassets++;
|
2019-04-24 17:46:19 +00:00
|
|
|
} else if (platform_id.startsWith('nes') && fileid.endsWith('.pal') && data instanceof Uint8Array) {
|
|
|
|
// is this a NES PAL?
|
|
|
|
let node = new pixed.FileDataNode(projectWindows, fileid);
|
|
|
|
const nespalfmt = {pal:"nes",layout:"nes"};
|
|
|
|
this.addPaletteEditor(this.ensureFileDiv(fileid), node, nespalfmt);
|
2019-05-15 03:32:19 +00:00
|
|
|
this.registerAsset("palette", node, 0);
|
2019-04-24 17:46:19 +00:00
|
|
|
nassets++;
|
2019-03-18 18:39:02 +00:00
|
|
|
} else if (typeof data === 'string') {
|
|
|
|
let textfrags = this.scanFileTextForAssets(fileid, data);
|
|
|
|
for (let frag of textfrags) {
|
2019-03-22 16:32:37 +00:00
|
|
|
if (frag.fmt) {
|
|
|
|
let label = fileid; // TODO: label
|
2019-03-26 18:29:47 +00:00
|
|
|
let node : pixed.PixNode = new pixed.TextDataNode(projectWindows, fileid, label, frag.start, frag.end);
|
2019-03-22 16:32:37 +00:00
|
|
|
let first = node;
|
2019-05-15 03:32:19 +00:00
|
|
|
// rle-compressed? TODO: how to edit?
|
2019-03-22 16:32:37 +00:00
|
|
|
if (frag.fmt.comp == 'rletag') {
|
2019-05-15 03:32:19 +00:00
|
|
|
node = node.addRight(new pixed.Compressor());
|
2019-03-22 16:32:37 +00:00
|
|
|
}
|
|
|
|
// is this a nes nametable?
|
|
|
|
if (frag.fmt.map == 'nesnt') {
|
2019-05-15 03:32:19 +00:00
|
|
|
node = node.addRight(new pixed.NESNametableConverter(this));
|
|
|
|
node = node.addRight(new pixed.Palettizer(this, {w:8,h:8,bpp:4}));
|
|
|
|
const fmt = {w:8*(frag.fmt.w||32),h:8*(frag.fmt.h||30),count:1}; // TODO: can't do custom sizes
|
|
|
|
node = node.addRight(new pixed.MapEditor(this, newDiv(this.ensureFileDiv(fileid)), fmt));
|
|
|
|
this.registerAsset("nametable", first, 2);
|
2019-03-22 16:32:37 +00:00
|
|
|
nassets++;
|
|
|
|
}
|
|
|
|
// is this a bitmap?
|
|
|
|
else if (frag.fmt.w > 0 && frag.fmt.h > 0) {
|
2019-04-13 13:10:08 +00:00
|
|
|
this.addPixelEditor(this.ensureFileDiv(fileid), node, frag.fmt);
|
2019-05-15 03:32:19 +00:00
|
|
|
this.registerAsset("charmap", first, 1);
|
2019-03-22 16:32:37 +00:00
|
|
|
nassets++;
|
|
|
|
}
|
|
|
|
// is this a palette?
|
|
|
|
else if (frag.fmt.pal) {
|
2019-04-13 13:10:08 +00:00
|
|
|
this.addPaletteEditor(this.ensureFileDiv(fileid), node, frag.fmt);
|
2019-05-15 03:32:19 +00:00
|
|
|
this.registerAsset("palette", first, 0);
|
2019-03-22 16:32:37 +00:00
|
|
|
nassets++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// TODO: other kinds of resources?
|
|
|
|
}
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 16:13:27 +00:00
|
|
|
return nassets;
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
|
2019-03-18 18:39:02 +00:00
|
|
|
getFileDivId(id : string) {
|
|
|
|
return '__asset__' + safeident(id);
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:10:50 +00:00
|
|
|
// TODO: recreate editors when refreshing
|
2019-04-07 16:33:01 +00:00
|
|
|
// TODO: look for changes, not moveCursor
|
2019-03-23 14:37:49 +00:00
|
|
|
refresh(moveCursor : boolean) {
|
2019-04-13 13:10:08 +00:00
|
|
|
// clear and refresh all files/nodes?
|
2019-03-23 14:37:49 +00:00
|
|
|
if (moveCursor) {
|
|
|
|
this.maindiv.empty();
|
|
|
|
this.clearAssets();
|
2019-04-13 13:10:08 +00:00
|
|
|
current_project.iterateFiles((fileid, data) => {
|
2019-03-23 14:37:49 +00:00
|
|
|
try {
|
2019-04-13 13:10:08 +00:00
|
|
|
var nassets = this.refreshAssetsInFile(fileid, data);
|
2019-03-23 14:37:49 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
2019-04-13 13:10:08 +00:00
|
|
|
this.ensureFileDiv(fileid).text(e+""); // TODO: error msg?
|
2019-03-23 14:37:49 +00:00
|
|
|
}
|
|
|
|
});
|
2019-03-26 00:39:53 +00:00
|
|
|
console.log("Found " + this.rootnodes.length + " assets");
|
2019-05-15 03:32:19 +00:00
|
|
|
this.deferrednodes.forEach((node) => {
|
|
|
|
try {
|
|
|
|
node.refreshRight();
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
alert(e+"");
|
|
|
|
}
|
|
|
|
});
|
2019-03-23 14:37:49 +00:00
|
|
|
this.deferrednodes = [];
|
2019-03-26 18:29:47 +00:00
|
|
|
} else {
|
2019-04-13 13:10:08 +00:00
|
|
|
// only refresh nodes if not actively editing
|
|
|
|
// since we could be in the middle of an operation that hasn't been committed
|
2019-03-26 18:29:47 +00:00
|
|
|
for (var node of this.rootnodes) {
|
2019-04-13 13:10:08 +00:00
|
|
|
if (node !== this.getCurrentEditNode()) {
|
|
|
|
node.refreshRight();
|
|
|
|
}
|
2019-03-26 18:29:47 +00:00
|
|
|
}
|
2019-03-23 14:37:49 +00:00
|
|
|
}
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 20:19:16 +00:00
|
|
|
setVisible?(showing : boolean) : void {
|
2019-04-05 12:58:26 +00:00
|
|
|
// TODO: make into toolbar?
|
2019-03-27 20:19:16 +00:00
|
|
|
if (showing) {
|
|
|
|
Mousetrap.bind('ctrl+z', projectWindows.undoStep.bind(projectWindows));
|
|
|
|
} else {
|
|
|
|
Mousetrap.unbind('ctrl+z');
|
|
|
|
}
|
|
|
|
}
|
2019-03-22 14:51:41 +00:00
|
|
|
|
2019-03-18 18:39:02 +00:00
|
|
|
}
|