Skip to content

Commit

Permalink
Add support for reading Comet symbols (#63)
Browse files Browse the repository at this point in the history
If the Comet assembler is loaded we'll load the current symbol table for the
debugger. This is only done if user symbols aren't available from another
source.
  • Loading branch information
simonowen committed Aug 22, 2021
1 parent d277f83 commit 5950274
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Base/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,40 @@ static bool Load(const std::string& path, AddrToSym& symtab, SymToAddr* valtab_p
return true;
}

static bool LoadComet(AddrToSym& symtab, SymToAddr& valtab)
{
symtab.clear();
valtab.clear();

auto mem = std::string(PageReadPtr(0x1c) + 0x1000, PageReadPtr(0x1c) + 0x1200);
if (mem.find("COMET Z80 assembler") == mem.npos)
return false;

auto sym_ptr = PageReadPtr(0x1b) + 0x3fff;
if (!*sym_ptr)
return false;

while (*sym_ptr)
{
auto len = *sym_ptr;
auto name = std::string(sym_ptr - len, sym_ptr);
std::reverse(name.begin(), name.end());
sym_ptr -= static_cast<size_t>(1) + len;

auto flags = sym_ptr[0];
if (flags == 0xff)
{
auto value = (sym_ptr[-2] << 8) | sym_ptr[-1];
symtab[value] = name;
valtab[tolower(name)] = value;
}

sym_ptr -= 3;
}

return true;
}

void Update(const std::string& path)
{
if (port_symbols.empty())
Expand All @@ -119,8 +153,8 @@ void Update(const std::string& path)
Load(OSD::MakeFilePath(PathType::Resource, "samrom.map"), rom_symbols, &rom_values);
if (samdos2_symbols.empty())
Load(OSD::MakeFilePath(PathType::Resource, "samdos2.map"), samdos2_symbols, &samdos2_values);
if (!path.empty())
Load(path, ram_symbols, &symbol_values);
if (!path.empty() && !Load(path, ram_symbols, &symbol_values))
LoadComet(ram_symbols, symbol_values);
}

std::optional<int> LookupSymbol(const std::string& symbol)
Expand Down

0 comments on commit 5950274

Please sign in to comment.