From 5c4b2b0ca4762fe10dd65144b6ee1e3fd560dc67 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Fri, 27 Dec 2019 13:19:11 -0600 Subject: [PATCH] openRelevantListing() not ready until listings are fixed, "folder/file.ext" normalized --- src/common/baseplatform.ts | 2 +- src/ide/project.ts | 5 +++-- src/ide/ui.ts | 29 +++++++++++++++++++---------- src/ide/windows.ts | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/common/baseplatform.ts b/src/common/baseplatform.ts index b9f68d62..b464d3e0 100644 --- a/src/common/baseplatform.ts +++ b/src/common/baseplatform.ts @@ -312,7 +312,7 @@ export abstract class BaseDebugPlatform extends BasePlatform { runUntilReturn() { var SP0 = this.getSP(); this.runEval( (c:CpuState) : boolean => { - return c.SP > SP0; + return c.SP > SP0; // TODO: check for RTS/RET opcode }); } runToFrameClock(clock : number) : void { diff --git a/src/ide/project.ts b/src/ide/project.ts index 2c33aba3..43fdba53 100644 --- a/src/ide/project.ts +++ b/src/ide/project.ts @@ -12,7 +12,9 @@ export class CodeProject { filedata : {[path:string]:FileData} = {}; listings : CodeListingMap; segments : Segment[]; + // TODO: mainpath and mainPath !??!!? mainpath : string; + mainPath : string; pendingWorkerMessages = 0; tools_preloaded = {}; callbackBuildResult : BuildResultCallback; @@ -22,7 +24,6 @@ export class CodeProject { platform : Platform; store : any; callbackGetRemote : GetRemoteCallback; - mainPath : string; isCompiling : boolean = false; constructor(worker, platform_id:string, platform, store) { @@ -328,5 +329,5 @@ export class CodeProject { } return path; } - + } diff --git a/src/ide/ui.ts b/src/ide/ui.ts index e35a0846..0ab28784 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -230,8 +230,9 @@ function refreshWindowList() { // add other source files current_project.iterateFiles( (id, text) => { - if (text && id != current_project.mainPath) + if (text && id != current_project.mainPath) { addEditorItem(id); + } }); // add listings @@ -301,7 +302,7 @@ function loadMainWindow(preset_id:string) { async function loadProject(preset_id:string) { // set current file ID - // TODO: this is done twice + // TODO: this is done twice (mainPath and mainpath!) current_project.mainPath = preset_id; setLastPreset(preset_id); // load files from storage or web URLs @@ -1095,27 +1096,35 @@ function checkRunReady() { } function openRelevantListing(state: EmuState) { + // if already on disassembly window, retain it + if (projectWindows.getActive() instanceof Views.DisassemblerView) return; + // search through listings var listings = current_project.getListings(); if (listings) { var pc = state.c ? (state.c.EPC || state.c.PC) : 0; for (var lstfn in listings) { - var lst = listings[lstfn]; - var file = lst.assemblyfile || lst.sourcefile; - var lineno = file && file.findLineForOffset(pc, 16); // TODO: const - console.log(pc,lstfn,lineno); - if (lineno !== null) { - projectWindows.createOrShow(lstfn, true); - return; + var wndid = projectWindows.findWindowWithFilePrefix(lstfn); + console.log(lstfn,wndid); + if (projectWindows.isWindow(wndid)) { + var lst = listings[lstfn]; + var file = lst.assemblyfile || lst.sourcefile; + var lineno = file && file.findLineForOffset(pc, 16); // TODO: const + console.log(hex(pc,4), wndid, lstfn, lineno); + if (lineno !== null) { + projectWindows.createOrShow(wndid, true); + return; + } } } } + // if no appropriate listing found, use disassembly view projectWindows.createOrShow("#disasm", true); } function uiDebugCallback(state: EmuState) { lastDebugState = state; showDebugInfo(state); - //openRelevantListing(state); + // TODO: openRelevantListing(state); projectWindows.refresh(true); // move cursor debugTickPaused = true; } diff --git a/src/ide/windows.ts b/src/ide/windows.ts index 33ad4d9b..669d3954 100644 --- a/src/ide/windows.ts +++ b/src/ide/windows.ts @@ -4,6 +4,7 @@ import $ = require("jquery"); import { CodeProject } from "./project"; import { WorkerError, FileData } from "../common/workertypes"; import { ProjectView } from "./views"; +import { getFilenamePrefix, getFilenameForPath } from "../common/util"; type WindowCreateFunction = (id:string) => ProjectView; type WindowShowFunction = (id:string, view:ProjectView) => void; @@ -28,6 +29,10 @@ export class ProjectWindows { } // TODO: delete windows ever? + isWindow(id:string) : boolean { + return this.id2createfn[id] != null; + } + setCreateFunc(id:string, createfn:WindowCreateFunction) : void { this.id2createfn[id] = createfn; } @@ -150,4 +155,13 @@ export class ProjectWindows { } } } + + findWindowWithFilePrefix(filename : string) : string { + filename = getFilenameForPath(getFilenamePrefix(filename)); + for (var fileid in this.id2createfn) { + console.log(filename, getFilenamePrefix(fileid)); + if (getFilenameForPath(getFilenamePrefix(fileid)) == filename) return fileid; + } + return null; + } };