Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h1romas4/9fdbcd45c4d6bdd87312dc3ca83059be to your computer and use it in GitHub Desktop.
Save h1romas4/9fdbcd45c4d6bdd87312dc3ca83059be to your computer and use it in GitHub Desktop.
From 2913041b0dc763fcb324c718c338d91747cd4233 Mon Sep 17 00:00:00 2001
From: h1romas4 <h1romas4@gmail.com>
Date: Wed, 4 May 2022 16:50:30 +0900
Subject: [PATCH] support z88dk map symble file
---
src/SymbolManager.cpp | 3 +++
src/SymbolTable.cpp | 32 +++++++++++++++++++++++++++++++-
src/SymbolTable.h | 2 ++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/SymbolManager.cpp b/src/SymbolManager.cpp
index 60c392c..dc09976 100644
--- a/src/SymbolManager.cpp
+++ b/src/SymbolManager.cpp
@@ -127,6 +127,7 @@ void SymbolManager::addFile()
<< "tniASM 1.x symbol files (*.sym)"
<< "asMSX 0.x symbol files (*.sym)"
<< "HiTech C symbol files (*.sym)"
+ << "Z88DK map files (*.map)"
<< "HiTech C link map files (*.map)"
<< "NoICE command files (*.noi)"
<< "pasmo symbol files (*.symbol *.publics *.sys)";
@@ -149,6 +150,8 @@ void SymbolManager::addFile()
read = symTable.readFile(n, SymbolTable::ASMSX_FILE);
} else if (f.startsWith("HiTech C symbol")) {
read = symTable.readFile(n, SymbolTable::HTC_FILE);
+ } else if (f.startsWith("Z88DK map")) {
+ read = symTable.readFile(n, SymbolTable::Z88DK_FILE);
} else if (f.startsWith("HiTech C link")) {
read = symTable.readFile(n, SymbolTable::LINKMAP_FILE);
} else if (f.startsWith("NoICE")) {
diff --git a/src/SymbolTable.cpp b/src/SymbolTable.cpp
index 8c77f3a..8c41ad5 100644
--- a/src/SymbolTable.cpp
+++ b/src/SymbolTable.cpp
@@ -185,7 +185,9 @@ bool SymbolTable::readFile(const QString& filename, FileType type)
if (type == DETECT_FILE) {
if (filename.toLower().endsWith(".map")) {
// HiTech link map file
- type = LINKMAP_FILE;
+ // TODO: Z88DK hack
+ // type = LINKMAP_FILE;
+ type = Z88DK_FILE;
} else if (filename.toLower().endsWith(".sym")) {
// auto detect which sym file
QFile file(filename);
@@ -230,6 +232,8 @@ bool SymbolTable::readFile(const QString& filename, FileType type)
return readASMSXFile(filename);
case HTC_FILE:
return readHTCFile(filename);
+ case Z88DK_FILE:
+ return readZ88DKFile(filename);
case LINKMAP_FILE:
return readLinkMapFile(filename);
case NOICE_FILE:
@@ -420,6 +424,32 @@ bool SymbolTable::readNoICEFile(const QString& filename)
return true;
}
+bool SymbolTable::readZ88DKFile(const QString& filename)
+{
+ QFile file(filename);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ return false;
+ }
+
+ appendFile(filename, Z88DK_FILE);
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ QStringList l = line.split(QRegExp("(\t+)|( +)"));
+ if (l.size() < 3) continue;
+ // ex. $0001
+ // printf("@@@ %s", l.at(2).mid(1, 4).toStdString().c_str());
+ std::optional<int> value = parseValue("0x" + l.at(2).mid(1, 4));
+ if (!value) continue;
+ // hack ex. $FFFFFFFFFFFF03B6
+ if (value == 0xffff) continue;
+ auto* sym = new Symbol(l.at(0), value.value());
+ sym->setSource(&symbolFiles.back().fileName);
+ add(sym);
+ }
+ return true;
+}
+
bool SymbolTable::readLinkMapFile(const QString& filename)
{
const QString magic("Machine type");
diff --git a/src/SymbolTable.h b/src/SymbolTable.h
index 7a4f491..5b7ad72 100644
--- a/src/SymbolTable.h
+++ b/src/SymbolTable.h
@@ -82,6 +82,7 @@ public:
ASMSX_FILE,
LINKMAP_FILE,
HTC_FILE,
+ Z88DK_FILE,
NOICE_FILE,
PASMO_FILE
};
@@ -129,6 +130,7 @@ private:
bool readASMSXFile(const QString& filename);
bool readSJASMFile(const QString& filename);
bool readHTCFile(const QString& filename);
+ bool readZ88DKFile(const QString& filename);
bool readNoICEFile(const QString& filename);
bool readLinkMapFile(const QString& filename);
bool readPASMOFile(const QString& filename);
--
2.34.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment