migrated to ACME assembler
commit 145d64aa6e78838ed07cefed372f0ad6a4687e97 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 20:16:57 2020 +0200 ACME adaptation commit 885209d7822286744ea53232ae7461472a01d5d6 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 19:57:25 2020 +0200 ACME adaptation commit 334d84486bc603551887e7cbeb59d329f2224cc7 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 18:29:15 2020 +0200 ACME adaptation commit b5966f49bcd8f0ca79cbec93819a31238924707e Author: FeralChild64 <you@example.com> Date: Sun Sep 20 18:09:31 2020 +0200 ACME adaptation commit 786536a93a5eab5e676fca99625b4eb094a554e7 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 17:24:48 2020 +0200 ACME adaptation commit 704c70dfb1f5d68775d6f3da220803b8a3990f56 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 15:07:12 2020 +0200 ACME adaptation commit 136874964c9083b375f151475310f9636871fc72 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 14:45:14 2020 +0200 ACME adaptation commit 8eca0d5700b72d04336e72c5cd3a68e18b85f96d Author: FeralChild64 <you@example.com> Date: Sun Sep 20 14:06:52 2020 +0200 ACME adaptation commit 11d29eb7ee318239d782f85498b6d0524624d5c4 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 13:56:45 2020 +0200 ACME apaptation commit c9b5e5e04cceb92c66bc027e6440bc0f7c5a499f Author: FeralChild64 <you@example.com> Date: Sun Sep 20 13:49:04 2020 +0200 ACME adaptation commit f5cc254cbc921f07863807468cb3fe26b410b409 Author: FeralChild64 <you@example.com> Date: Sun Sep 20 13:01:18 2020 +0200 ACME adaptation commit e135a27bf9c30cc0965379c954564e06406303b1 Author: FeralChild64 <you@example.com> Date: Sat Sep 19 21:55:01 2020 +0200 ACME adaptation commit e9dfddf90d9e2795e88b7da40ae050d733faeb56 Author: FeralChild64 <you@example.com> Date: Sat Sep 19 21:48:47 2020 +0200 Makefile fix commit 07030104c65cf5e5beeacf6d629ccb9245e58657 Author: FeralChild64 <you@example.com> Date: Sat Sep 19 21:42:00 2020 +0200 ACME adaptation commit f824362ee5bcfbffca86c430b57773b2ffd65655 Author: FeralChild64 <you@example.com> Date: Sat Sep 19 20:14:56 2020 +0200 ACME adaptation commit 3a3c59007dcd4940d89b8669f34ca56b61c25fdf Author: FeralChild64 <you@example.com> Date: Fri Sep 18 21:51:45 2020 +0200 ACME adaptation commit 6790ef7bc88a41de2881c69b7524dd4ab8c74b5d Author: FeralChild64 <you@example.com> Date: Fri Sep 18 20:35:23 2020 +0200 ACME adaptation commit 38ad18b90e9ec713aa7ca49576b3388ce1733357 Author: FeralChild64 <you@example.com> Date: Fri Sep 18 18:46:20 2020 +0200 ACME adaptation commit 541340371122a9702f7b2d9771c298223cffd0e9 Author: FeralChild64 <you@example.com> Date: Fri Sep 18 16:49:46 2020 +0200 ACME adaptation commit 25cfd5e186459be1a260d3eb8cfff767838de370 Author: FeralChild64 <you@example.com> Date: Thu Sep 17 20:13:33 2020 +0200 ACME adaptation commit f61599444d5b1d03d8fd8e4a6a7c3b85069bedb3 Author: FeralChild64 <you@example.com> Date: Thu Sep 17 19:29:23 2020 +0200 ACME adaptation commit b290be31ec7bb2e5723607697da1bbc621c84429 Author: FeralChild64 <you@example.com> Date: Thu Sep 17 17:20:14 2020 +0200 ACME adaptation commit 877be9e856880d98fd4bcb25b42aaaacda9dc463 Author: FeralChild64 <you@example.com> Date: Wed Sep 16 21:47:38 2020 +0200 ACME adaptation commit bb20edaf85d386e41d5c2f715b745b68fbd3362e Author: FeralChild64 <you@example.com> Date: Wed Sep 16 21:31:30 2020 +0200 ACME adaptation commit c5d31bd8685abce37c8e254d15aac20bd1570d9f Author: FeralChild64 <you@example.com> Date: Wed Sep 16 18:40:49 2020 +0200 ACME adaptation commit 29349826b38f8a89649171559dc8cf24c560aff1 Author: FeralChild64 <you@example.com> Date: Mon Sep 14 23:35:47 2020 +0200 ACME adaptation commit 8bcd6a621c4b11766d0cf34f79858ba90a67248e Author: FeralChild64 <you@example.com> Date: Mon Sep 14 22:52:25 2020 +0200 ACME adaptation commit e87a69edc2ce4bfcc460c31e08dcc352a985f88d Author: FeralChild64 <you@example.com> Date: Mon Sep 14 22:43:27 2020 +0200 ACME adaptation commit f49a097bd52e96d00b866c02bda7121e4543233c Author: FeralChild64 <you@example.com> Date: Mon Sep 14 19:02:07 2020 +0200 ACME adaptation commit fa0e9214a633b8e8f867cc70925b390940dcd426 Author: FeralChild64 <you@example.com> Date: Mon Sep 14 17:47:19 2020 +0200 ACME adaptation commit 1b763b91e7a03e426227129c7f22f0ce57a4c197 Author: FeralChild64 <you@example.com> Date: Mon Sep 14 17:17:10 2020 +0200 ACME adaptation commit e92a4b57b232cd85eb1e71090b8a89c7c8461ebc Author: FeralChild64 <you@example.com> Date: Mon Sep 14 17:15:37 2020 +0200 ACME adaptation commit de3c693e8a7e73ea5289198946058e3240894e6a Author: FeralChild64 <you@example.com> Date: Mon Sep 14 17:10:05 2020 +0200 ACME adaptation commit f9bd7ae0f04e932d613be9ed5cb19af9be5d338e Author: FeralChild64 <you@example.com> Date: Sun Sep 13 14:34:44 2020 +0200 ACME adaptation commit 694dee52555dbfc2b1f7f452a9671ff51106c057 Author: FeralChild64 <you@example.com> Date: Sun Sep 13 14:16:14 2020 +0200 ACME adaptation commit 0af2c55edfcd22942d9f25417eb0d35f55b71604 Author: FeralChild64 <you@example.com> Date: Fri Sep 11 17:38:09 2020 +0200 ACME adaptation commit 2015e17334bd56a1e8a13a5abc098d9c2e7ea44f Author: FeralChild64 <you@example.com> Date: Fri Sep 11 16:46:05 2020 +0200 ACME adaptation commit b1e972162798d60f4483cd6cc261e856c20c2c8c Author: FeralChild64 <you@example.com> Date: Fri Sep 11 16:24:31 2020 +0200 ACME adaptation commit 9d027e868466901ba53bf074a79ec8cf16273021 Author: FeralChild64 <you@example.com> Date: Fri Sep 11 15:04:31 2020 +0200 ACME adaptation commit 957186deddd1aa4f3b4f1aa1f421e4239a584e57 Author: FeralChild64 <you@example.com> Date: Thu Sep 10 22:49:07 2020 +0200 ACME adaptation commit b8060f67a455cfac109f08d96b62c360d693b931 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 23:07:28 2020 +0200 ACME adaptation commit e54d004568f44bbfe5c070ef1d7cf3544112e497 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 22:58:20 2020 +0200 ACME adaptation commit f90b77f073c5a605cb31c6ee451f65c8a8aff7d8 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 22:12:09 2020 +0200 ACME adaptation commit b211bb4afcd9c58fe1f5c92f3007717d611cd531 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 22:01:40 2020 +0200 ACME adaptation commit 8d7ea343b07e9e08e5f77f3c414758a6cffd0440 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 21:38:34 2020 +0200 ACME adaptation commit 46413eb0d92d6400aba0ff8dfe556e61e8a44d78 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 21:07:47 2020 +0200 ACME adaptation commit 9f98f69ecc21f7b74a5eb89e247f5a2c6fcb655d Author: FeralChild64 <you@example.com> Date: Wed Sep 9 20:05:03 2020 +0200 ACME adaptation commit 7bb9f1cadc682c7e0a4a6796739d860d473ca110 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 19:55:12 2020 +0200 ACME adaptation commit 5fc115392b5bdca6b56f67ad866b1884d2d2bdf8 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 19:31:10 2020 +0200 ACME adaptation commit b7940fc60e568d859df9e3156f6bacc6d685b2cc Author: FeralChild64 <you@example.com> Date: Wed Sep 9 19:16:09 2020 +0200 ACME adaptation commit 56288cb97197561afa0816b29c134ec1190e8eab Author: FeralChild64 <you@example.com> Date: Wed Sep 9 18:48:23 2020 +0200 ACME adaptation commit 10401a60fc7922a53d782120ef6795d889140218 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 16:34:16 2020 +0200 ACME adaptation commit 8ce76e4d2b56837a691ae84b1a412a2ae32a157b Author: FeralChild64 <you@example.com> Date: Wed Sep 9 16:20:44 2020 +0200 ACME adaptation commit 33fade899fa6172ea6b5b5f6683bb61f544429fd Author: FeralChild64 <you@example.com> Date: Wed Sep 9 15:28:46 2020 +0200 ACME adaptation commit a416f04734402fcfbc57a933731376df2e0180a1 Author: FeralChild64 <you@example.com> Date: Wed Sep 9 12:40:03 2020 +0200 ACME adaptation commit f8daee005b1d29f6912723be2ac94bc5fbeb0508 Author: FeralChild64 <you@example.com> Date: Mon Sep 7 23:29:54 2020 +0200 ACME adaptation commit 83fe6bdd0b08a44fdbfc6eefe323a4b194ccaf5b Author: FeralChild64 <you@example.com> Date: Mon Sep 7 22:23:16 2020 +0200 ACME adaptation commit cb1f75620b9c83000a15c9c7f7acefdfee79a979 Author: FeralChild64 <you@example.com> Date: Mon Sep 7 19:23:12 2020 +0200 ACME adaptation commit e524d517c933ae1f0aeb49764d307fadb4845025 Author: FeralChild64 <you@example.com> Date: Sun Sep 6 08:24:25 2020 +0200 ACME adaptation - replaced comments commit 2ab572c3a21f4a78a7312d0e684bc11d91d1717a Author: FeralChild64 <you@example.com> Date: Sat Sep 5 17:59:10 2020 +0200 ACME adaptation - replaced the assembler
This commit is contained in:
1 parent
bfc8291e41
commit
c8d255130c
685 files changed
+15835
-16296
No files matched your search
+186
-51
@@ -20,18 +20,16 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
const std::string ASM_CMD = "java -jar ";
|
||||
|
||||
const std::string LAB_OUT_START = "__routine_START_";
|
||||
const std::string LAB_OUT_END = "__routine_END_";
|
||||
const std::string LAB_IN_START = ".label __routine_START_";
|
||||
const std::string LAB_IN_END = ".label __routine_END_";
|
||||
const std::string LAB_IN_START = "\t" + LAB_OUT_START;
|
||||
const std::string LAB_IN_END = "\t" + LAB_OUT_END;
|
||||
|
||||
//
|
||||
// Command line settings
|
||||
//
|
||||
|
||||
std::string CMD_assFile = "KickAss.jar";
|
||||
std::string CMD_assembler = "./acme";
|
||||
std::string CMD_outFile = "OUT.BIN";
|
||||
std::string CMD_outDir = "./out";
|
||||
std::string CMD_segName = "MAIN";
|
||||
@@ -49,7 +47,7 @@ std::list<std::string> CMD_inList;
|
||||
void printUsage()
|
||||
{
|
||||
std::cout << "\n" <<
|
||||
"usage: build_segment [-a <assembler jar file>] [-o <out file>] [-d <out dir>]" << "\n" <<
|
||||
"usage: build_segment [-a <assembler command>] [-o <out file>] [-d <out dir>]" << "\n" <<
|
||||
" [-l <start/low address>] [-h <end/high address>]" << "\n" <<
|
||||
" [-s <segment name>] [-i <segment display info>]" << "\n" <<
|
||||
" [-r <rom layout>]" << "\n" <<
|
||||
@@ -70,6 +68,16 @@ void printBannerBinCompile()
|
||||
printBannerLineBottom();
|
||||
}
|
||||
|
||||
std::string toLabel(const std::string &fileName)
|
||||
{
|
||||
std::string retVal = fileName;
|
||||
|
||||
std::replace(retVal.begin(), retVal.end(), ',', '_');
|
||||
std::replace(retVal.begin(), retVal.end(), '.', '_');
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//
|
||||
// Class definitions
|
||||
//
|
||||
@@ -80,15 +88,24 @@ public:
|
||||
SourceFile(const std::string &fileName, const std::string &dirName);
|
||||
|
||||
void preprocess();
|
||||
bool preprocessLine(const std::string &line);
|
||||
void preprocessLine(const std::string &line, uint32_t lineNum);
|
||||
void preprocessLine_Alias(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter, uint32_t lineNum);
|
||||
void preprocessLine_Import(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter);
|
||||
void preprocessLine_Layout(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter);
|
||||
|
||||
bool nameMatch(const std::string &token, const std::string &name);
|
||||
|
||||
std::string fileName;
|
||||
std::string dirName;
|
||||
|
||||
bool layoutProcessingDone;
|
||||
bool ignore;
|
||||
bool floating;
|
||||
bool high;
|
||||
|
||||
std::map<std::string, std::list<std::pair<std::string, uint16_t>>> symbolImports;
|
||||
std::map<uint32_t, std::pair<std::string, uint16_t>> symbolAliases;
|
||||
|
||||
std::vector<char> content;
|
||||
|
||||
std::string label;
|
||||
@@ -166,7 +183,7 @@ void parseCommandLine(int argc, char **argv)
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
case 'a': CMD_assFile = optarg; break;
|
||||
case 'a': CMD_assembler = optarg; break;
|
||||
case 'o': CMD_outFile = optarg; break;
|
||||
case 'd': CMD_outDir = optarg; break;
|
||||
case 's': CMD_segName = optarg; break;
|
||||
@@ -291,15 +308,15 @@ void calcRoutineSizes()
|
||||
// Start at $100, so that no local data gets accesses using ZP addressing modes
|
||||
// during this pass, which would otherwise upset things later
|
||||
|
||||
outFile << "\n" << ".segment " << CMD_segName << " [start=$100, min=$100, max=$FFFF]" << "\n";
|
||||
outFile << "#define SEGMENT_" << CMD_segName << "\n";
|
||||
outFile << "#define ROM_LAYOUT_" << CMD_romLayout << "\n";
|
||||
outFile << "\n" << "*=$100" << "\n";
|
||||
outFile << "!set SEGMENT_" << CMD_segName << " = 1\n";
|
||||
outFile << "!set ROM_LAYOUT_" << CMD_romLayout << " = 1\n";
|
||||
|
||||
for (const auto &sourceFile : GLOBAL_sourceFiles)
|
||||
{
|
||||
outFile << "\n\n\n\n";
|
||||
outFile << "/* Source file: " << sourceFile.fileName << " */" << "\n\n";
|
||||
outFile << ".memblock \"" << sourceFile.fileName << "\"" << "\n";
|
||||
outFile << ";--- Source file " << sourceFile.fileName << "\n\n";
|
||||
outFile << "!zone " << toLabel(sourceFile.fileName) << "\n\n";
|
||||
outFile << LAB_OUT_START << sourceFile.label << ":" << "\n\n";
|
||||
|
||||
outFile << std::string(sourceFile.content.begin(), sourceFile.content.end());
|
||||
@@ -313,8 +330,9 @@ void calcRoutineSizes()
|
||||
|
||||
// All written - now launch the assembler
|
||||
|
||||
const std::string cmd = "cd " + filePath + " && " + ASM_CMD + CMD_assFile + " " +
|
||||
outFileNameBare + " -symbolfile -o /dev/null";
|
||||
const std::string cmd = "cd " + filePath + " && " + CMD_assembler +
|
||||
" --color --outfile /dev/null --symbollist " + CMD_segName + "_sizetest.sym " +
|
||||
outFileNameBare;
|
||||
std::cout << "command: " << cmd << "\n" << std::flush;
|
||||
if (0 != system(cmd.c_str()))
|
||||
{
|
||||
@@ -348,8 +366,8 @@ void calcRoutineSizes()
|
||||
|
||||
auto eqPos = line.rfind('=');
|
||||
|
||||
auto address = strtol(line.substr(eqPos + 2).c_str(), nullptr ,16);
|
||||
std::string refLabel = line.substr(0, eqPos);
|
||||
auto address = strtol(line.substr(eqPos + 3).c_str(), nullptr , 16);
|
||||
std::string refLabel = line.substr(0, eqPos - 1);
|
||||
|
||||
for (auto &sourceFile : GLOBAL_sourceFiles)
|
||||
{
|
||||
@@ -494,32 +512,32 @@ void compileSegment()
|
||||
// First combine everything into one assembler file
|
||||
|
||||
const std::string outFileNameBare = CMD_segName + "_combined.s";
|
||||
const std::string vlfFileNamePath = CMD_segName + "_combined.vs";
|
||||
const std::string repFileNamePath = CMD_segName + "_combined.rep";
|
||||
const std::string symFileNamePath = CMD_segName + "_combined.sym";
|
||||
const std::string filePath = CMD_outDir + DIR_SEPARATOR;
|
||||
const std::string outFileNamePath = filePath + outFileNameBare;
|
||||
unlink(outFileNamePath.c_str());
|
||||
unlink(vlfFileNamePath.c_str());
|
||||
unlink(repFileNamePath.c_str());
|
||||
unlink(symFileNamePath.c_str());
|
||||
std::ofstream outFile(outFileNamePath, std::fstream::out | std::fstream::trunc);
|
||||
if (!outFile.good()) ERROR(std::string("can't open temporary file '") + outFileNamePath + "'");
|
||||
|
||||
// Write the header
|
||||
|
||||
outFile << "\n" <<
|
||||
".segment " << CMD_segName <<
|
||||
" [start=$" << std::hex << CMD_loAddress <<
|
||||
", min=$" << std::hex << CMD_loAddress <<
|
||||
", max=$" << std::hex << CMD_hiAddress <<
|
||||
", outBin=\"" << CMD_outFile << "\", fill]" <<
|
||||
"\n";
|
||||
outFile << "#define SEGMENT_" << CMD_segName << "\n";
|
||||
outFile << "#define ROM_LAYOUT_" << CMD_romLayout << "\n";
|
||||
outFile << ".namespace " << CMD_segName << " {" << "\n\n";
|
||||
outFile << "!set SEGMENT_" << CMD_segName << " = 1\n";
|
||||
outFile << "!set ROM_LAYOUT_" << CMD_romLayout << " = 1\n\n";
|
||||
outFile << "\t* = $" << std::hex << CMD_loAddress << ", INVISIBLE\n";
|
||||
outFile << "\t!fill $" << std::hex << (CMD_hiAddress + 1 - CMD_loAddress) << "\n\n";
|
||||
|
||||
// Write files which only contain definitions (no routines)
|
||||
|
||||
for (const auto &sourceFile : GLOBAL_sourceFiles_noCode)
|
||||
{
|
||||
outFile << "\n\n\n\n";
|
||||
outFile << "/* Source file: " << sourceFile.fileName << " */" << "\n\n";
|
||||
outFile << ".memblock \"" << sourceFile.fileName << "\"" << "\n";
|
||||
outFile << ";--- Source file " << sourceFile.fileName << "\n\n";
|
||||
outFile << "!zone " << toLabel(sourceFile.fileName) << "\n\n";
|
||||
outFile << std::string(sourceFile.content.begin(), sourceFile.content.end());
|
||||
outFile << "\n";
|
||||
}
|
||||
@@ -529,22 +547,27 @@ void compileSegment()
|
||||
for (const auto &routine : GLOBAL_binningProblem.fixedRoutines)
|
||||
{
|
||||
outFile << "\n\n\n\n";
|
||||
outFile << "/* Source file: " << routine.second->fileName << " */" << "\n\n";
|
||||
outFile << ".memblock \"" << routine.second->fileName << "\"" << "\n";
|
||||
outFile << ";--- Source file " << routine.second->fileName << "\n\n";
|
||||
outFile << "!zone " << toLabel(routine.second->fileName) << "\n\n";
|
||||
outFile << "\t* = $" << std::hex << routine.first << "\n\n";
|
||||
outFile << std::string(routine.second->content.begin(), routine.second->content.end());
|
||||
outFile << "\n";
|
||||
}
|
||||
|
||||
outFile << "\n\n" << "} // namespace" << "\n";
|
||||
outFile << "\n\n";
|
||||
|
||||
if (!outFile.good()) ERROR(std::string("error writing temporary file '") + outFileNamePath + "'");
|
||||
outFile.close();
|
||||
|
||||
// All written - now launch the assembler
|
||||
|
||||
const std::string cmd = "cd " + filePath + " && " + ASM_CMD + CMD_assFile + " " +
|
||||
outFileNameBare + " -symbolfile -vicesymbols -o " + CMD_outFile;
|
||||
const std::string cmd = "cd " + filePath + " && " + CMD_assembler +
|
||||
" --strict-segments --color" +
|
||||
" --outfile " + CMD_outFile +
|
||||
" --symbollist " + symFileNamePath +
|
||||
" --vicelabels " + vlfFileNamePath +
|
||||
" --report " + repFileNamePath +
|
||||
" " + outFileNameBare;
|
||||
std::cout << "command: " << cmd << "\n" << std::flush;
|
||||
if (0 != system(cmd.c_str()))
|
||||
{
|
||||
@@ -582,6 +605,7 @@ int main(int argc, char **argv)
|
||||
SourceFile::SourceFile(const std::string &fileName, const std::string &dirName) :
|
||||
fileName(fileName),
|
||||
dirName(dirName),
|
||||
layoutProcessingDone(false),
|
||||
ignore(false),
|
||||
floating(false),
|
||||
high(false),
|
||||
@@ -638,30 +662,65 @@ SourceFile::SourceFile(const std::string &fileName, const std::string &dirName)
|
||||
|
||||
preprocess();
|
||||
|
||||
// Generate KickAss compatible label from the file name
|
||||
// Generate assembler compatible label from the file name
|
||||
|
||||
label = fileName.substr(0, fileName.length() - 2);
|
||||
|
||||
std::replace(label.begin(), label.end(), '.', '_');
|
||||
std::replace(label.begin(), label.end(), ',', '_');
|
||||
label = toLabel(fileName);
|
||||
}
|
||||
|
||||
void SourceFile::preprocess()
|
||||
{
|
||||
std::string contentStr(content.begin(), content.end());
|
||||
std::istringstream stream(contentStr);
|
||||
std::istringstream stream1(contentStr);
|
||||
std::istringstream stream2(contentStr);
|
||||
std::string line;
|
||||
uint32_t lineNum = 0;
|
||||
|
||||
while (std::getline(stream, line))
|
||||
// Preprocess all the lines
|
||||
|
||||
while (std::getline(stream1, line))
|
||||
{
|
||||
lineNum++;
|
||||
|
||||
if (line.empty()) continue;
|
||||
std::replace(line.begin(), line.end(), '\t', ' ');
|
||||
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
|
||||
if (!preprocessLine(line)) break;
|
||||
preprocessLine(line, lineNum - 1);
|
||||
}
|
||||
|
||||
// Replace content with preprocessed one
|
||||
|
||||
std::string spacing;
|
||||
content.clear();
|
||||
lineNum = 0;
|
||||
|
||||
size_t maxSymLen = 0;
|
||||
for (const auto &symbolAlias : symbolAliases) maxSymLen = std::max(maxSymLen, symbolAlias.second.first.length());
|
||||
|
||||
while (std::getline(stream2, line))
|
||||
{
|
||||
if (symbolAliases.find(lineNum) != symbolAliases.end())
|
||||
{
|
||||
std::ostringstream alias;
|
||||
spacing.resize(maxSymLen + 2 - symbolAliases[lineNum].first.length(), ' ');
|
||||
alias << "!addr " << symbolAliases[lineNum].first << spacing << "= $" <<
|
||||
std::hex << symbolAliases[lineNum].second << " " << line;
|
||||
const std::string aliasStr = alias.str();
|
||||
content.insert(content.end(), aliasStr.begin(), aliasStr.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
content.insert(content.end(), line.begin(), line.end());
|
||||
}
|
||||
|
||||
content.push_back('\n');
|
||||
lineNum++;
|
||||
}
|
||||
|
||||
symbolAliases.clear();
|
||||
symbolImports.clear();
|
||||
}
|
||||
|
||||
bool SourceFile::preprocessLine(const std::string &line)
|
||||
void SourceFile::preprocessLine(const std::string &line, uint32_t lineNum)
|
||||
{
|
||||
// Split the line into tokens
|
||||
|
||||
@@ -674,7 +733,7 @@ bool SourceFile::preprocessLine(const std::string &line)
|
||||
if (token.empty()) continue;
|
||||
tokens.push_back(token);
|
||||
}
|
||||
if (tokens.empty()) return true;
|
||||
if (tokens.empty()) return;
|
||||
|
||||
// Now preprocess line using the token list
|
||||
|
||||
@@ -682,19 +741,94 @@ bool SourceFile::preprocessLine(const std::string &line)
|
||||
|
||||
// Injest the comment token
|
||||
|
||||
if ((iter++)->compare("//") != 0 || iter == tokens.end()) return true;
|
||||
if ((iter++)->compare(";;") != 0 || iter == tokens.end()) return;
|
||||
|
||||
// Check if supported directive
|
||||
|
||||
if ((iter++)->compare("#LAYOUT#") != 0) return true;
|
||||
if (iter->compare("#ALIAS#") == 0) preprocessLine_Alias(tokens, ++iter, lineNum);
|
||||
else if (iter->compare("#IMPORT#") == 0) preprocessLine_Import(tokens, ++iter);
|
||||
else if (iter->compare("#LAYOUT#") == 0) preprocessLine_Layout(tokens, ++iter);
|
||||
}
|
||||
|
||||
void SourceFile::preprocessLine_Alias(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter, uint32_t lineNum)
|
||||
{
|
||||
if (ignore) return;
|
||||
|
||||
// Extract symbol, namespace, and target
|
||||
|
||||
if (iter == tokens.end()) ERROR("syntax error, missing symbol in '#ALIAS#'");
|
||||
std::string symbol = *(iter++);
|
||||
|
||||
if (iter == tokens.end() || (iter++)->compare("=") != 0) ERROR("syntax error, expected assignment in '#ALIAS#'");
|
||||
if (iter == tokens.end()) ERROR("syntax error, missing namespace/target in '#ALIAS#'");
|
||||
|
||||
auto dotPos = iter->rfind('.');
|
||||
std::string symNameSpace = iter->substr(0, dotPos);
|
||||
std::string symTarget = iter->substr(dotPos + 1, std::string::npos);
|
||||
|
||||
if (symNameSpace.empty()) ERROR("syntax error, missing namespace in '#ALIAS#'");
|
||||
if (symTarget.empty()) ERROR("syntax error, missing target in '#ALIAS#'");
|
||||
|
||||
// Put the alias - if address found
|
||||
|
||||
for (const auto &alias : symbolImports[symNameSpace])
|
||||
{
|
||||
if (alias.first.compare(symTarget) != 0) continue;
|
||||
|
||||
symbolAliases[lineNum] = std::pair<std::string, uint16_t>(symbol, alias.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SourceFile::preprocessLine_Import(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter)
|
||||
{
|
||||
if (ignore) return;
|
||||
|
||||
if (iter == tokens.end()) ERROR("syntax error, missing namespace in '#IMPORT#'");
|
||||
std::string symNameSpace = *(iter++);
|
||||
|
||||
if (iter == tokens.end() || iter->compare("=") != 0) ERROR("syntax error, expected assignment in '#IMPORT#'");
|
||||
|
||||
while (++iter != tokens.end())
|
||||
{
|
||||
// Try to import sumbols for the file
|
||||
|
||||
std::ifstream impFile;
|
||||
impFile.open(CMD_outDir + DIR_SEPARATOR + *iter);
|
||||
if (!impFile.good())
|
||||
{
|
||||
impFile.close();
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(impFile, line))
|
||||
{
|
||||
// Import label and address
|
||||
|
||||
auto eqPos = line.rfind('=');
|
||||
|
||||
auto address = strtol(line.substr(eqPos + 3).c_str(), nullptr , 16);
|
||||
std::string label = line.substr(1, eqPos - 2);
|
||||
|
||||
symbolImports[symNameSpace].push_back(std::pair<std::string, uint16_t>(label, address));
|
||||
}
|
||||
|
||||
impFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void SourceFile::preprocessLine_Layout(const std::list<std::string> &tokens, std::list<std::string>::iterator &iter)
|
||||
{
|
||||
if (layoutProcessingDone) return;
|
||||
|
||||
// Check if segment name and rom layout match
|
||||
|
||||
if (iter == tokens.end()) ERROR("syntax error, missing rom layout in '#LAYOUT#'");
|
||||
if (!nameMatch(*(iter++), CMD_romLayout)) return true;
|
||||
if (!nameMatch(*(iter++), CMD_romLayout)) return;
|
||||
|
||||
if (iter == tokens.end()) ERROR("syntax error, missing segment name in '#LAYOUT#'");
|
||||
if (!nameMatch(*(iter++), CMD_segName)) return true;
|
||||
if (!nameMatch(*(iter++), CMD_segName)) return;
|
||||
|
||||
// Retrieve and apply action
|
||||
|
||||
@@ -720,14 +854,15 @@ bool SourceFile::preprocessLine(const std::string &line)
|
||||
}
|
||||
else if (iter->compare("#TAKE") != 0)
|
||||
{
|
||||
ERROR(std::string("syntax error, unsupported action '") + token + "' in '#LAYOUT#'");
|
||||
ERROR(std::string("syntax error, unsupported action '") + *iter + "' in '#LAYOUT#'");
|
||||
}
|
||||
|
||||
// Tell the caller to finish processing the file
|
||||
// Mark the file - to tell that layout processing is finished
|
||||
|
||||
return false;
|
||||
layoutProcessingDone = true;
|
||||
}
|
||||
|
||||
|
||||
bool SourceFile::nameMatch(const std::string &token, const std::string &name)
|
||||
{
|
||||
return (token.compare("*") == 0) || (token.compare(name) == 0);
|
||||
|
||||
@@ -202,7 +202,7 @@ std::string toAssemblerString(const std::string &constName, double constValue)
|
||||
outFloat[4],
|
||||
constValue);
|
||||
|
||||
std::string outDef = std::string("\n.macro put_const_") + constName + "()\n{\n\t.byte " + buf + "\n}\n";
|
||||
std::string outDef = std::string("\n!macro PUT_CONST_") + constName + " {\n\t!byte " + buf + "\n}\n";
|
||||
|
||||
return outDef;
|
||||
}
|
||||
|
||||
+34
-34
@@ -1229,7 +1229,7 @@ void DataSet::generateConfigDepStrings()
|
||||
|
||||
// List found
|
||||
|
||||
if (GLOBAL_ConfigOptions["CONFIG_SHOW_FEATURES"] || GLOBAL_ConfigOptions["CONFIG_MB_MEGA_65"])
|
||||
if (GLOBAL_ConfigOptions["CONFIG_SHOW_FEATURES"] || GLOBAL_ConfigOptions["CONFIG_MB_M65"])
|
||||
{
|
||||
StringEntry newEntry1 = { true, true, true, true, "STR_PAL", "PAL\r" };
|
||||
StringEntry newEntry2 = { true, true, true, true, "STR_NTSC", "NTSC\r" };
|
||||
@@ -1244,13 +1244,13 @@ void DataSet::generateConfigDepStrings()
|
||||
stringEntryList.list.push_back(newEntry);
|
||||
}
|
||||
|
||||
if (GLOBAL_ConfigOptions["CONFIG_MB_MEGA_65"])
|
||||
if (GLOBAL_ConfigOptions["CONFIG_MB_M65"])
|
||||
{
|
||||
StringEntry newEntry = { false, true, false, false, "STR_SI_FEATURES", featureStrM65 };
|
||||
stringEntryList.list.push_back(newEntry);
|
||||
}
|
||||
|
||||
if (!GLOBAL_ConfigOptions["CONFIG_BRAND_CUSTOM_BUILD"] || GLOBAL_ConfigOptions["CONFIG_MB_MEGA_65"])
|
||||
if (!GLOBAL_ConfigOptions["CONFIG_BRAND_CUSTOM_BUILD"] || GLOBAL_ConfigOptions["CONFIG_MB_M65"])
|
||||
{
|
||||
StringEntry newEntry = { true, true, true, true, "STR_PRE_REV", "RELEASE " };
|
||||
stringEntryList.list.push_back(newEntry);
|
||||
@@ -1498,9 +1498,9 @@ void DataSet::encodeStringsFreq()
|
||||
|
||||
void DataSet::putCharEncoding(std::ostringstream &stream, uint8_t idx, char character, bool is3n)
|
||||
{
|
||||
stream << "\t.byte $" << std::uppercase << std::hex <<
|
||||
stream << "\t!byte $" << std::uppercase << std::hex <<
|
||||
std::setfill('0') << std::setw(2) << +character <<
|
||||
" // " << std::setfill(is3n ? '0' : ' ') << std::setw(2) << +idx;
|
||||
" ; " << std::setfill(is3n ? '0' : ' ') << std::setw(2) << +idx;
|
||||
|
||||
std::string petscii;
|
||||
|
||||
@@ -1530,7 +1530,7 @@ void DataSet::prepareOutput_1n_3n(std::ostringstream &stream)
|
||||
|
||||
// Export all nibble-encoded characters
|
||||
|
||||
stream << std::endl << ".macro put_packed_as_1n() // characters encoded as 1 nibble" << std::endl << "{" << std::endl;
|
||||
stream << std::endl << "!macro PUT_PACKED_AS_1N { ; characters encoded as 1 nibble" << std::endl << std::endl;
|
||||
|
||||
idx = 0;
|
||||
for (const auto& encoding : as1n)
|
||||
@@ -1542,13 +1542,13 @@ void DataSet::prepareOutput_1n_3n(std::ostringstream &stream)
|
||||
|
||||
// Export all byte-encoded characters
|
||||
|
||||
stream << std::endl << ".macro put_packed_as_3n() // characters encoded as 3 nibbles" << std::endl << "{" << std::endl;
|
||||
stream << std::endl << "!macro PUT_PACKED_AS_3N { ; characters encoded as 3 nibbles" << std::endl << std::endl;
|
||||
|
||||
idx = 0;
|
||||
for (const auto& encoding : as3n)
|
||||
{
|
||||
if (idx == tk__packed_as_3n) stream << std::endl <<
|
||||
"\t// Characters below are not used by any BASIC keyword" << std::endl << std::endl;
|
||||
"\t; Characters below are not used by any BASIC keyword" << std::endl << std::endl;
|
||||
|
||||
putCharEncoding(stream, ++idx, encoding, true);
|
||||
}
|
||||
@@ -1571,7 +1571,7 @@ void DataSet::prepareOutput_labels(std::ostringstream &stream,
|
||||
|
||||
if (!stringEncoded.empty())
|
||||
{
|
||||
stream << ".label IDX__" << stringEntry.alias <<
|
||||
stream << "!set IDX__" << stringEntry.alias <<
|
||||
std::string(maxAliasLen - stringEntry.alias.length(), ' ') << " = $" <<
|
||||
std::uppercase << std::hex << std::setfill('0') << std::setw(2) << +idx << std::endl;
|
||||
}
|
||||
@@ -1584,14 +1584,14 @@ void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
{
|
||||
if (isCompressionLvl2(stringEntryList))
|
||||
{
|
||||
stream << std::endl << ".macro put_packed_dict_";
|
||||
stream << std::endl << "!macro PUT_PACKED_DICT_";
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << std::endl << ".macro put_packed_freq_";
|
||||
stream << std::endl << "!macro PUT_PACKED_FREQ_";
|
||||
}
|
||||
|
||||
stream << stringEntryList.name << "()" << std::endl << "{" << std::endl;
|
||||
stream << stringEntryList.name << " {" << std::endl << std::endl;
|
||||
|
||||
enum LastStr { NONE, SKIPPED, WRITTEN } lastStr = LastStr::NONE;
|
||||
for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++)
|
||||
@@ -1603,7 +1603,7 @@ void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
if (stringEntryList.type == ListType::DICTIONARY) ERROR("internal error"); // should never happen
|
||||
|
||||
if (lastStr == LastStr::WRITTEN) stream << std::endl;
|
||||
stream << "\t.byte $00 // skipped " << stringEntryList.list[idxString].alias << std::endl;
|
||||
stream << "\t!byte $00 ; skipped " << stringEntryList.list[idxString].alias << std::endl;
|
||||
lastStr = LastStr::SKIPPED;
|
||||
}
|
||||
else
|
||||
@@ -1614,12 +1614,12 @@ void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
|
||||
if (stringEntryList.type != ListType::DICTIONARY)
|
||||
{
|
||||
stream << "\t// IDX__" << stringEntryList.list[idxString].alias << std::endl;
|
||||
stream << "\t; IDX__" << stringEntryList.list[idxString].alias << std::endl;
|
||||
}
|
||||
|
||||
// Output the source string - as a comment
|
||||
|
||||
stream << "\t// '";
|
||||
stream << "\t; '";
|
||||
for (auto &character : stringEntryList.list[idxString].string)
|
||||
{
|
||||
if (character >= 32 && character <= 132 && character != 39 && character != 34)
|
||||
@@ -1639,7 +1639,7 @@ void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
|
||||
// Output the encoding
|
||||
|
||||
stream << "\t.byte ";
|
||||
stream << "\t!byte ";
|
||||
|
||||
bool first = true;
|
||||
for (const auto &charEncoded : stringEncoded)
|
||||
@@ -1665,8 +1665,8 @@ void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
|
||||
if (stringEntryList.type == ListType::KEYWORDS)
|
||||
{
|
||||
stream << std::endl << "\t// Marker - end of the keyword list" << std::endl;
|
||||
stream << "\t.byte $FF, $FF" << std::endl;
|
||||
stream << std::endl << "\t; Marker - end of the keyword list" << std::endl;
|
||||
stream << "\t!byte $FF, $FF" << std::endl;
|
||||
}
|
||||
|
||||
stream << "}" << std::endl;
|
||||
@@ -1677,7 +1677,7 @@ void DataSet::prepareOutput()
|
||||
// Convert our encoded strings to a KickAssembler source
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << std::endl << "#if ROM_LAYOUT_" << layoutName() << std::endl;
|
||||
stream << std::endl << "!ifdef ROM_LAYOUT_" << layoutName() << " {"<< std::endl;
|
||||
|
||||
// Export 1-nibble and 3-nibble encoding data
|
||||
|
||||
@@ -1685,8 +1685,8 @@ void DataSet::prepareOutput()
|
||||
|
||||
// Export additional data for the tokenizer
|
||||
|
||||
stream << std::endl << ".label TK__PACKED_AS_3N = $" << std::hex << +tk__packed_as_3n <<
|
||||
std::endl << ".label TK__MAX_KEYWORD_LEN = " << std::dec << +tk__max_keyword_len << std::endl;
|
||||
stream << std::endl << "!set TK__PACKED_AS_3N = $" << std::hex << +tk__packed_as_3n <<
|
||||
std::endl << "!set TK__MAX_KEYWORD_LEN = " << std::dec << +tk__max_keyword_len << std::endl;
|
||||
|
||||
// Export encoded strings
|
||||
|
||||
@@ -1705,7 +1705,7 @@ void DataSet::prepareOutput()
|
||||
|
||||
if (stringEntryList.type == ListType::KEYWORDS)
|
||||
{
|
||||
stream << std::endl << ".label TK__MAXTOKEN_" << stringEntryList.name << " = " <<
|
||||
stream << std::endl << "!set TK__MAXTOKEN_" << stringEntryList.name << " = " <<
|
||||
std::dec << stringEncodedList.size() << std::endl;
|
||||
}
|
||||
|
||||
@@ -1716,7 +1716,7 @@ void DataSet::prepareOutput()
|
||||
|
||||
// Finalize the file stream
|
||||
|
||||
stream << std::endl << "#endif // ROM_LAYOUT_" << layoutName() << std::endl;
|
||||
stream << std::endl << "} ; ROM_LAYOUT_" << layoutName() << std::endl;
|
||||
outFileContent = stream.str();
|
||||
}
|
||||
|
||||
@@ -1748,21 +1748,21 @@ void parseConfigFile()
|
||||
std::getline(cnfFile, workStr);
|
||||
if (cnfFile.bad()) ERROR("error reading configuration file");
|
||||
workStr = std::regex_replace(workStr, std::regex("^[ \t]+"), "");
|
||||
|
||||
|
||||
// Skip lines which are not preprocessor definitions
|
||||
|
||||
if (workStr.empty() || workStr[0] != '#') continue;
|
||||
if (workStr.empty() || workStr[0] != '!') continue;
|
||||
|
||||
// Make sure this is '#define '
|
||||
// Make sure this is '!set '
|
||||
|
||||
if (!std::regex_match(workStr, std::regex("^#define[ \t].*")))
|
||||
if (!std::regex_match(workStr, std::regex("^\\!set[ \t].*")))
|
||||
{
|
||||
ERROR(std::string("only '#define' preprocessor directives allowed in config files - line ") + std::to_string(lineNum));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get rid of the directive and trailing spaces/comments
|
||||
// Get rid of the directive and trailing spaces/values/comments
|
||||
|
||||
workStr = std::regex_replace(workStr, std::regex("^#define[ \t]+"), "");
|
||||
workStr = std::regex_replace(workStr, std::regex("^\\!set[ \t]+"), "");
|
||||
workStr = std::regex_replace(workStr, std::regex("[ \t]+.*"), "");
|
||||
|
||||
// Add definitin to config option map
|
||||
@@ -1784,7 +1784,7 @@ void printUsage()
|
||||
void printBanner()
|
||||
{
|
||||
printBannerLineTop();
|
||||
std::cout << "// Generating compressed messages and BASIC tokens\n";
|
||||
std::cout << "; Generating compressed messages and BASIC tokens\n";
|
||||
printBannerLineBottom();
|
||||
}
|
||||
|
||||
@@ -1824,7 +1824,7 @@ void writeStrings()
|
||||
|
||||
outputString = dataSetX16.getOutput();
|
||||
}
|
||||
else if (GLOBAL_ConfigOptions["CONFIG_PLATFORM_COMMODORE_64"] && GLOBAL_ConfigOptions["CONFIG_MB_MEGA_65"])
|
||||
else if (GLOBAL_ConfigOptions["CONFIG_PLATFORM_COMMODORE_64"] && GLOBAL_ConfigOptions["CONFIG_MB_M65"])
|
||||
{
|
||||
DataSetM65 dataSetM65;
|
||||
|
||||
@@ -1841,7 +1841,7 @@ void writeStrings()
|
||||
|
||||
outputString = dataSetM65.getOutput();
|
||||
}
|
||||
else if (GLOBAL_ConfigOptions["CONFIG_PLATFORM_COMMODORE_64"] && GLOBAL_ConfigOptions["CONFIG_MB_ULTIMATE_64"])
|
||||
else if (GLOBAL_ConfigOptions["CONFIG_PLATFORM_COMMODORE_64"] && GLOBAL_ConfigOptions["CONFIG_MB_U64"])
|
||||
{
|
||||
DataSetU64 dataSetU64;
|
||||
|
||||
@@ -1887,7 +1887,7 @@ void writeStrings()
|
||||
|
||||
// Write header
|
||||
|
||||
outFile << "//\n// Generated file - do not edit\n//";
|
||||
outFile << ";\n; Generated file - do not edit\n;";
|
||||
|
||||
// Write packed strings
|
||||
|
||||
|
||||
Reference in new issue
Block a user