diff --git a/src/baseplatform.ts b/src/baseplatform.ts index b8115089..13e8f8e9 100644 --- a/src/baseplatform.ts +++ b/src/baseplatform.ts @@ -1,5 +1,5 @@ -import { RAM, RasterVideo, dumpRAM, lookupSymbol } from "./emu"; +import { RAM, RasterVideo, dumpRAM } from "./emu"; import { hex, printFlags, invertMap } from "./util"; import { CodeAnalyzer } from "./analysis"; import { disassemble6502 } from "./cpu/disasm6502"; @@ -932,7 +932,7 @@ export function dumpStackToString(platform:Platform, mem:Uint8Array|number[], st var opcode = read(addr + jsrofs); // might be out of bounds if (opcode == jsrop) { // JSR s += "\n$" + hex(sp) + ": "; - s += hex(addr,4) + " " + lookupSymbol(addr); + s += hex(addr,4) + " " + lookupSymbol(platform, addr); sp++; nraw = 0; } else { @@ -944,3 +944,20 @@ export function dumpStackToString(platform:Platform, mem:Uint8Array|number[], st } return s+"\n"; } + +export function lookupSymbol(platform:Platform, addr:number) { + var start = addr; + var foundsym; + var addr2symbol = platform.debugSymbols && platform.debugSymbols.addr2symbol; + while (addr2symbol && addr >= 0) { + var sym = addr2symbol[addr]; + if (sym && sym.startsWith('_')) { // return first C symbol we find + return addr2symbol[addr] + " + " + (start-addr); + } else if (sym && !foundsym) { // cache first non-C symbol found + foundsym = sym; + } + addr--; + } + return foundsym || ""; +} + diff --git a/src/emu.ts b/src/emu.ts index c5d785b5..7d75af36 100644 --- a/src/emu.ts +++ b/src/emu.ts @@ -445,22 +445,3 @@ export function newAddressDecoder(table : AddressDecoderEntry[], options?:Addres return new (AddressDecoder as any)(table, options); } -// STACK DUMP - -var addr2symbol = {}; // address to symbol name map (TODO: import) - -export function lookupSymbol(addr) { - var start = addr; - var foundsym; - while (addr2symbol && addr >= 0) { - var sym = addr2symbol[addr]; - if (sym && sym.startsWith('_')) { // return first C symbol we find - return addr2symbol[addr] + " + " + (start-addr); - } else if (sym && !foundsym) { // cache first non-C symbol found - foundsym = sym; - } - addr--; - } - return foundsym || ""; -} -