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

removed getActiveEditor(), global sourcefile/assemblyfile (needs work)

This commit is contained in:
Steven Hugg 2018-07-03 08:22:21 -06:00
parent a94156d7cd
commit 1222077ed0
2 changed files with 94 additions and 74 deletions

159
src/ui.js
View File

@ -58,12 +58,9 @@ function newWorker() {
var userPaused; var userPaused;
var active_editor;
var current_output; var current_output;
var current_preset_entry; var current_preset_entry;
var main_file_id; var main_file_id;
var assemblyfile;
var sourcefile;
var symbolmap; var symbolmap;
var addr2symbol; var addr2symbol;
var compparams; var compparams;
@ -117,6 +114,9 @@ function initProject() {
function SourceEditor(path, mode) { function SourceEditor(path, mode) {
var self = this; var self = this;
var editor; var editor;
var fnprefix = getFilenamePrefix(getFilenameForPath(path));
var dirtylisting = true;
var sourcefile;
self.createDiv = function(parent, text) { self.createDiv = function(parent, text) {
var div = document.createElement('div'); var div = document.createElement('div');
@ -203,17 +203,18 @@ function SourceEditor(path, mode) {
self.clearErrors = function() { self.clearErrors = function() {
editor.clearGutter("gutter-info"); editor.clearGutter("gutter-info");
// TODO: set current line marker refreshDebugState();
dirtylisting = true;
} }
// TODO: update gutter only when refreshing this window // TODO: update gutter only when refreshing this window
self.updateListing = function(sourcefile) { self.updateListing = function(_sourcefile) {
sourcefile = _sourcefile;
// update editor annotations // update editor annotations
editor.clearGutter("gutter-info"); editor.clearGutter("gutter-info");
editor.clearGutter("gutter-bytes"); editor.clearGutter("gutter-bytes");
editor.clearGutter("gutter-offset"); editor.clearGutter("gutter-offset");
editor.clearGutter("gutter-clock"); editor.clearGutter("gutter-clock");
// TODO: support multiple files (use local sourcefile)
var lstlines = sourcefile.lines || []; var lstlines = sourcefile.lines || [];
for (var info of lstlines) { for (var info of lstlines) {
if (info.offset >= 0) { if (info.offset >= 0) {
@ -265,20 +266,39 @@ function SourceEditor(path, mode) {
} }
} }
self.refresh = function() { function refreshDebugState() {
// TODO: only use local sourcefile self.clearCurrentLine();
var state = lastDebugState; var state = lastDebugState;
if (state && state.c) { if (state && state.c) {
var PC = state.c.PC; var PC = state.c.PC;
var line = sourcefile.findLineForOffset(PC); var line = sourcefile.findLineForOffset(PC);
if (line >= 0) { if (line >= 0) {
console.log("BREAKPOINT", hex(PC), line);
self.setCurrentLine(line); self.setCurrentLine(line);
// TODO: switch to disasm // TODO: switch to disasm?
} }
} }
} }
function refreshListing() {
if (!dirtylisting) return;
dirtylisting = false;
var listings = current_project.getListings();
// find matching listing file (TODO: can CodeProject map this?)
for (var lstfn in listings) {
if (getFilenamePrefix(lstfn) == fnprefix) {
var lst = listings[lstfn];
if (lst.sourcefile) {
self.updateListing(lst.sourcefile); // updates sourcefile variable
}
}
}
}
self.refresh = function() {
refreshListing();
refreshDebugState();
}
self.getLine = function(line) { self.getLine = function(line) {
return editor.getLine(line-1); return editor.getLine(line-1);
} }
@ -287,6 +307,16 @@ function SourceEditor(path, mode) {
return editor.getCursor().line+1; return editor.getCursor().line+1;
} }
self.getCursorPC = function() {
var line = self.getCurrentLine();
while (sourcefile && line >= 0) {
var pc = sourcefile.line2offset[line];
if (pc >= 0) return pc;
line--;
}
return -1;
}
// bitmap editor (TODO: refactor) // bitmap editor (TODO: refactor)
function handleWindowMessage(e) { function handleWindowMessage(e) {
@ -357,9 +387,10 @@ function SourceEditor(path, mode) {
alert("To edit graphics, move cursor to a constant array preceded by a comment in the format:\n\n/*{w:,h:,bpp:,count:...}*/\n\n(See code examples)"); alert("To edit graphics, move cursor to a constant array preceded by a comment in the format:\n\n/*{w:,h:,bpp:,count:...}*/\n\n(See code examples)");
} }
} }
} }
///
function DisassemblerView() { function DisassemblerView() {
var self = this; var self = this;
var disasmview; var disasmview;
@ -386,6 +417,8 @@ function DisassemblerView() {
self.refresh = function() { self.refresh = function() {
var state = lastDebugState || platform.saveState(); var state = lastDebugState || platform.saveState();
var pc = state.c ? state.c.PC : 0; var pc = state.c ? state.c.PC : 0;
var assemblyfile;
// TODO: match assemblyfile
// do we have an assembly listing? // do we have an assembly listing?
if (assemblyfile && assemblyfile.text) { if (assemblyfile && assemblyfile.text) {
var asmtext = assemblyfile.text; var asmtext = assemblyfile.text;
@ -419,14 +452,15 @@ function DisassemblerView() {
var s = ""; var s = "";
while (a < end) { while (a < end) {
var disasm = platform.disassemble(a, platform.readAddress); var disasm = platform.disassemble(a, platform.readAddress);
/* TODO: find source file in current_project
var srclinenum = sourcefile.offset2line[a]; var srclinenum = sourcefile.offset2line[a];
if (srclinenum) { if (srclinenum) {
var srcline = getActiveEditor().getLine(srclinenum); // TODO! var srcline = getActiveEditor().getLine(srclinenum);
if (srcline && srcline.trim().length) { if (srcline && srcline.trim().length) {
s += "; " + srclinenum + ":\t" + srcline + "\n"; s += "; " + srclinenum + ":\t" + srcline + "\n";
curline++; curline++;
} }
} }*/
var bytes = ""; var bytes = "";
for (var i=0; i<disasm.nbytes; i++) for (var i=0; i<disasm.nbytes; i++)
bytes += hex(platform.readAddress(a+i)); bytes += hex(platform.readAddress(a+i));
@ -449,7 +483,21 @@ function DisassemblerView() {
disasmview.setValue(current_output.code); disasmview.setValue(current_output.code);
} }
} }
self.getCursorPC = function() {
var line = disasmview.getCursor().line;
if (line >= 0) {
var toks = disasmview.getLine(line).split(/\s+/);
if (toks && toks.length >= 1) {
var pc = parseInt(toks[0], 16);
if (pc >= 0) return pc;
} }
}
return -1;
}
}
///
function MemoryView() { function MemoryView() {
var self = this; var self = this;
@ -591,7 +639,6 @@ function MemoryView() {
if (dumplines[i].a >= a) if (dumplines[i].a >= a)
return i; return i;
} }
} }
///// /////
@ -666,15 +713,19 @@ function ProjectWindows(containerdiv) {
activewnd.clearErrors(); activewnd.clearErrors();
} }
} }
this.getActive = function() { return activewnd; }
this.getCurrentText = function() {
if (activewnd && activewnd.getValue)
return activewnd.getValue();
else
alert("Please switch to an editor window.");
}
}; };
var projectWindows = new ProjectWindows($("#workspace")[0]); var projectWindows = new ProjectWindows($("#workspace")[0]);
// TODO: support multiple editors, this might should go
function getActiveEditor() {
return active_editor;
}
function refreshWindowList() { function refreshWindowList() {
var ul = $("#windowMenuList").empty(); var ul = $("#windowMenuList").empty();
var separate = false; var separate = false;
@ -755,7 +806,7 @@ function loadProject(preset_id) {
// we need this to build create functions for the editor (TODO?) // we need this to build create functions for the editor (TODO?)
refreshWindowList(); refreshWindowList();
// show main file // show main file
active_editor = projectWindows.createOrShow(preset_id); projectWindows.createOrShow(preset_id);
} }
}); });
} }
@ -842,9 +893,10 @@ function _shareFile(e) {
alert("Please fix errors before sharing."); alert("Please fix errors before sharing.");
return true; return true;
} }
var text = projectWindows.getCurrentText();
if (!text) return false;
var github = new Octokat(); var github = new Octokat();
var files = {}; var files = {};
var text = getActiveEditor().getValue();
files[getCurrentFilename()] = {"content": text}; files[getCurrentFilename()] = {"content": text};
var gistdata = { var gistdata = {
"description": '8bitworkshop.com {"platform":"' + platform_id + '"}', "description": '8bitworkshop.com {"platform":"' + platform_id + '"}',
@ -880,7 +932,9 @@ function _downloadROMImage(e) {
} }
function _downloadSourceFile(e) { function _downloadSourceFile(e) {
var blob = new Blob([getActiveEditor().getValue()], {type: "text/plain;charset=utf-8"}); var text = projectWindows.getCurrentText();
if (!text) return false;
var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
saveAs(blob, getCurrentFilename()); saveAs(blob, getCurrentFilename());
} }
@ -933,28 +987,12 @@ function updateSelector() {
} }
function setCompileOutput(data) { function setCompileOutput(data) {
// TODO: support multiple edit windows
var sed = getActiveEditor();
// errors? mark them in editor // errors? mark them in editor
if (data.errors && data.errors.length > 0) { if (data.errors && data.errors.length > 0) {
projectWindows.setErrors(data.errors); projectWindows.setErrors(data.errors);
toolbar.addClass("has-errors"); toolbar.addClass("has-errors");
} else { } else {
// choose first listing (TODO:support multiple source files) // process symbol map
sourcefile = null;
assemblyfile = null;
if (data.listings) {
var lst;
for (var lstname in data.listings) {
lst = data.listings[lstname];
break;
}
if (lst) {
sourcefile = lst.sourcefile;
assemblyfile = lst.assemblyfile;
}
}
if (!sourcefile) sourcefile = new SourceFile();
symbolmap = data.symbolmap; symbolmap = data.symbolmap;
addr2symbol = invertMap(symbolmap); addr2symbol = invertMap(symbolmap);
if (!addr2symbol[0x0]) addr2symbol[0x0] = '__START__'; // needed for ... if (!addr2symbol[0x0]) addr2symbol[0x0] = '__START__'; // needed for ...
@ -976,19 +1014,18 @@ function setCompileOutput(data) {
current_output = rom; current_output = rom;
//resetProfiler(); //resetProfiler();
} catch (e) { } catch (e) {
console.log(e); // TODO: show error console.log(e);
toolbar.addClass("has-errors"); toolbar.addClass("has-errors");
sed.addErrorMarker(0, e+""); projectWindows.setErrors([{line:0,msg:e+""}]);
current_output = null; current_output = null;
} }
} else if (rom.program_rom_variable) { //TODO: a little wonky... } else if (rom.program_rom_variable) { //TODO: a little wonky...
platform.loadROM(rom.program_rom_variable, rom.program_rom); platform.loadROM(rom.program_rom_variable, rom.program_rom);
rom_changed = true; rom_changed = true;
} }
if (rom_changed || trace_pending_at_pc) { // update all windows (listings)
sed.updateListing(sourcefile);
}
projectWindows.refresh(); projectWindows.refresh();
// compute VCS cycle timing?
if (trace_pending_at_pc) { if (trace_pending_at_pc) {
showLoopTimingForPC(trace_pending_at_pc); showLoopTimingForPC(trace_pending_at_pc);
} }
@ -1051,7 +1088,7 @@ function _resume() {
function resume() { function resume() {
clearBreakpoint(); clearBreakpoint();
if (! platform.isRunning() ) { if (! platform.isRunning() ) {
getActiveEditor().clearCurrentLine(); // TODO projectWindows.refresh();
} }
_resume(); _resume();
userPaused = false; userPaused = false;
@ -1067,27 +1104,9 @@ function singleFrameStep() {
platform.runToVsync(); platform.runToVsync();
} }
// TODO: fix these
function getDisasmViewPC() {
var line = disasmview.getCursor().line;
if (line >= 0) {
var toks = disasmview.getLine(line).split(/\s+/);
if (toks && toks[0].length == 4) {
return parseInt(toks[0], 16);
}
}
}
// TODO: fix this
function getEditorPC() { function getEditorPC() {
var line = getActiveEditor().getCurrentLine(); // TODO var wnd = projectWindows.getActive();
while (line >= 0) { return wnd && wnd.getCursorPC && wnd.getCursorPC();
// TODO: what if in disassembler?
var pc = sourcefile.line2offset[line];
if (pc >= 0) return pc;
line--;
}
return getDisasmViewPC();
} }
function runToCursor() { function runToCursor() {
@ -1127,12 +1146,6 @@ function jumpToLine(ed, i) {
ed.scrollTo(null, t - middleHeight - 5); ed.scrollTo(null, t - middleHeight - 5);
} }
function getVisibleSourceFile() {
// TODO
var div = $("#disassembly");
return div.is(':visible') ? assemblyfile : sourcefile;
}
function resetAndDebug() { function resetAndDebug() {
if (platform.setupDebug && platform.readAddress) { // TODO?? if (platform.setupDebug && platform.readAddress) { // TODO??
clearBreakpoint(); clearBreakpoint();
@ -1250,7 +1263,9 @@ function _fastestFrameRate() {
} }
function _openBitmapEditor() { function _openBitmapEditor() {
getActiveEditor().openBitmapEditorAtCursor(); var wnd = currentWindows.getActive();
if (wnd && wnd.openBitmapEditorAtCursor)
openBitmapEditorAtCursor();
} }
function setupDebugControls(){ function setupDebugControls(){

View File

@ -12,6 +12,11 @@ function getFilenameForPath(s) {
return toks[toks.length-1]; return toks[toks.length-1];
} }
function getFilenamePrefix(s) {
var pos = s.lastIndexOf('.');
return (pos > 0) ? s.substr(0, pos) : s;
}
function hex(v, nd) { function hex(v, nd) {
try { try {
if (!nd) nd = 2; if (!nd) nd = 2;