From 50ac618e861c242ed702880a6131fa8b14778bc2 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 17 Sep 2018 16:09:09 -0400 Subject: [PATCH] class DebugSymbols to hold symbol info --- src/baseplatform.ts | 23 +++++++++++++++++++++-- src/platform/vcs.ts | 17 ----------------- src/ui.ts | 22 ++++++++++------------ src/views.ts | 8 +++----- test/cli/testworker.js | 2 +- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/baseplatform.ts b/src/baseplatform.ts index cef81f4b..cb042670 100644 --- a/src/baseplatform.ts +++ b/src/baseplatform.ts @@ -1,6 +1,6 @@ import { RAM, RasterVideo, dumpRAM, lookupSymbol } from "./emu"; -import { hex, printFlags } from "./util"; +import { hex, printFlags, invertMap } from "./util"; import { CodeAnalyzer } from "./analysis"; import { disassemble6502 } from "./cpu/disasm6502"; import { disassembleZ80 } from "./cpu/disasmz80"; @@ -38,6 +38,21 @@ export type DisasmLine = { isaddr:boolean }; +export type SymbolMap = {[ident:string]:number}; +export type AddrSymbolMap = {[address:number]:string}; + +export class DebugSymbols { + symbolmap : SymbolMap; // symbol -> address + addr2symbol : AddrSymbolMap; // address -> symbol + + constructor(symbolmap : SymbolMap) { + this.symbolmap = symbolmap; + this.addr2symbol = invertMap(symbolmap); + if (!this.addr2symbol[0x0]) this.addr2symbol[0x0] = '__START__'; // needed for ... + this.addr2symbol[0x10000] = '__END__'; // ... dump memory to work + } +} + export interface Platform { start() : void; reset() : void; @@ -80,6 +95,8 @@ export interface Platform { setRecorder?(recorder : EmuRecorder) : void; advance?(novideo? : boolean) : void; + + debugSymbols? : DebugSymbols; } export interface Preset { @@ -107,6 +124,7 @@ export interface EmuRecorder { export abstract class BasePlatform { recorder : EmuRecorder = null; + debugSymbols : DebugSymbols; abstract loadState(state : EmuState) : void; abstract saveState() : EmuState; @@ -534,10 +552,11 @@ export abstract class BaseZ80Platform extends BaseDebugPlatform { switch (category) { case 'CPU': return cpuStateToLongString_Z80(state.c); case 'Stack': { - var sp = state.c.SP-1; + var sp = (state.c.SP-1) & 0xffff; var start = sp & 0xff00; var end = start + 0xff; if (sp == 0) sp = 0x10000; + console.log(sp,start,end); return dumpStackToString(this, [], start, end, sp, 0xcd); } } diff --git a/src/platform/vcs.ts b/src/platform/vcs.ts index 4ada13f4..9cbbae5c 100644 --- a/src/platform/vcs.ts +++ b/src/platform/vcs.ts @@ -5,7 +5,6 @@ import { PLATFORMS, RAM, newAddressDecoder, dumpRAM } from "../emu"; import { hex, lpad, tobin, byte2signed } from "../util"; import { CodeAnalyzer_vcs } from "../analysis"; import { disassemble6502 } from "../cpu/disasm6502"; -import { platform, symbolmap, addr2symbol } from "../ui"; declare var Javatari : any; declare var jt : any; // 6502 @@ -259,22 +258,6 @@ class VCSPlatform extends BasePlatform { disassemble(pc:number, read:(addr:number)=>number) : DisasmLine { return disassemble6502(pc, read(pc), read(pc+1), read(pc+2)); } - inspect(ident : string) : string { - if (this.isRunning()) return; // only inspect when stopped - var result; - var addr = symbolmap && (symbolmap[ident]); // || symbolmap['_'+ident]); - if (addr >= 0x80 && addr < 0x100) { // in RAM? - var size=4; - result = "$" + hex(addr,4) + ":"; - for (var i=0; i= 0) { - i++; - if (addr2symbol[a]) return addr2symbol[a] + '+' + i; + var addr2symbol = platform.debugSymbols && platform.debugSymbols.addr2symbol; + if (addr2symbol) { + if (addr2symbol[a]) return addr2symbol[a]; + var i=0; + while (--a >= 0) { + i++; + if (addr2symbol[a]) return addr2symbol[a] + '+' + i; + } } return ''; } diff --git a/src/views.ts b/src/views.ts index 1d5fa7cd..3544c9c5 100644 --- a/src/views.ts +++ b/src/views.ts @@ -7,7 +7,7 @@ import { SourceFile, WorkerError } from "./workertypes"; import { Platform, EmuState } from "./baseplatform"; import { hex, lpad, rpad } from "./util"; import { CodeAnalyzer } from "./analysis"; -import { platform, platform_id, compparams, symbolmap, addr2symbol, current_project, lastDebugState } from "./ui"; +import { platform, platform_id, compparams, current_project, lastDebugState } from "./ui"; export interface ProjectView { createDiv(parent:HTMLElement, text:string) : HTMLElement; @@ -429,6 +429,7 @@ export class DisassemblerView implements ProjectView { var pc = state.c ? state.c.PC : 0; var curline = 0; var selline = 0; + var addr2symbol = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {}; // TODO: not perfect disassembler var disassemble = (start, end) => { if (start < 0) start = 0; @@ -652,10 +653,7 @@ export class MemoryView implements ProjectView { // TODO: addr2symbol for ca65; and make it work without symbols getDumpLines() { - var addr2sym = addr2symbol; - if (!addr2sym) addr2sym = {}; - if (!addr2sym[0x0]) addr2sym[0x0] = '__START__'; - addr2sym[0x10000] = '__END__'; + var addr2sym = (platform.debugSymbols && platform.debugSymbols.addr2symbol) || {}; if (!this.dumplines) { this.dumplines = []; var ofs = 0; diff --git a/test/cli/testworker.js b/test/cli/testworker.js index cef5a6ba..c87ba050 100644 --- a/test/cli/testworker.js +++ b/test/cli/testworker.js @@ -175,7 +175,7 @@ describe('Worker', function() { assert.ok(fn); done(err, msg); }; - doBuild(msgs, done2, 2781, 0, 0); + doBuild(msgs, done2, 2764, 0, 0); }); it('should NOT compile verilog example', function(done) { var csource = "foobar";