From ae4b6acc557b19eb4e15aaa8d51a5b53d0eea689 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 18 Oct 2019 22:35:46 +0200 Subject: [PATCH] further work on release tool --- .../rom_revision/bf52.rom_revision_basic.s | 2 + .../rom_revision/e4b7.rom_revision_kernal.s | 2 + src/release.cc | 182 +++++++++++++++--- 3 files changed, 161 insertions(+), 25 deletions(-) diff --git a/c64/basic/rom_revision/bf52.rom_revision_basic.s b/c64/basic/rom_revision/bf52.rom_revision_basic.s index 9281af14..30c9e65d 100644 --- a/c64/basic/rom_revision/bf52.rom_revision_basic.s +++ b/c64/basic/rom_revision/bf52.rom_revision_basic.s @@ -19,6 +19,8 @@ rom_revision_basic: rom_revision_basic_string: + // $BF55 + .text "(DEVEL SNAPSHOT)" // actual ROM revision string; up to 16 characters .byte $00 // marks the end of string diff --git a/c64/basic/rom_revision/e4b7.rom_revision_kernal.s b/c64/basic/rom_revision/e4b7.rom_revision_kernal.s index f3c7f34d..996baeec 100644 --- a/c64/basic/rom_revision/e4b7.rom_revision_kernal.s +++ b/c64/basic/rom_revision/e4b7.rom_revision_kernal.s @@ -33,6 +33,8 @@ rom_revision_kernal: rom_revision_kernal_string: + // $E4BC + .text "(DEVEL SNAPSHOT)" // actual ROM revision string; up to 16 characters .byte $00 // marks the end of string diff --git a/src/release.cc b/src/release.cc index cd3c466e..bb5e9c46 100644 --- a/src/release.cc +++ b/src/release.cc @@ -6,10 +6,21 @@ #include "common.h" #include +#include #include #include +#include +#include +#include #include +#include + +const std::vector STR_MEGABAS = { 0x4D, 0x45, 0x47, 0x41, 0x42, 0x41, 0x53, 0x32 }; +const std::vector STR_OR = { 0x4F, 0x52 }; +const std::vector STR_SNAPSHOT = { 0x28, 0x44, 0x45, 0x56, 0x45, 0x4C, 0x20, 0x53, + 0x4E, 0x41, 0x50, 0x53, 0x48, 0x4F, 0x54, 0x29, + 0x00 }; // // Command and enviroment line settings @@ -21,6 +32,7 @@ std::string CMD_outDir = "./bin"; std::list CMD_fileList; std::string ENV_developerId; +std::string ENV_timeString; // // Common helper functions @@ -33,6 +45,44 @@ void printUsage() " " << "\n\n"; } +// +// Class definitions +// + +enum class ROMType +{ + ROM_UNKNOWN, + ROM_BASIC, + ROM_KERNAL +}; + +class ROMFile +{ +public: + + ROMFile(const std::string &baseFileName); + +private: + + void readSrcFile(); + void readDstFile(); + + void recognizeFiles(); + + std::string baseFileName; + + std::vector srcFileContent; + std::vector dstFileContent; + + ROMType romType; +}; + +// +// Global variables +// + +std::list GLOBAL_ROMFiles; + // // Top-level functions // @@ -63,7 +113,7 @@ void parseCommandLine(int argc, char **argv) if (CMD_fileList.empty()) { printUsage(); ERROR("empty file list"); } } -void getEnvironmentSettings() +void getDeveloperId() { const char* id = getenv("OPEN_ROMS_DEVELOPER_ID"); @@ -90,16 +140,35 @@ void getEnvironmentSettings() } } +void getDate() +{ + time_t t = time(NULL); + struct tm tm = *localtime(&t); + + const std::string year = std::to_string(tm.tm_year % 100); + const std::string month = std::to_string(tm.tm_mon + 1); + const std::string day = std::to_string(tm.tm_mday); + + const std::string zero = "0"; + + + ENV_timeString = (year.size() == 2 ? year : zero + year) + + (month.size() == 2 ? month : zero + month) + + (day.size() == 2 ? day : zero + day); + + if (ENV_timeString.size() != 6) ERROR("could not retrieve date"); +} + void printBanner() { printBannerLineTop(); - std::cout << "// Preparing ROM set release by '" << ENV_developerId << "'\n"; + std::cout << "// Preparing ROM set release " << ENV_timeString << "-" << ENV_developerId << "\n"; printBannerLineBottom(); } void readFiles() { - // XXX + for (auto &fileName : CMD_fileList) GLOBAL_ROMFiles.push_back(ROMFile(fileName)); } void embedVersionString() @@ -112,24 +181,6 @@ void writeFiles() // XXX } -// -// Class definitions -// - -class ROMFile -{ -public: - - ROMFile(const std::string &baseFileName); - -private: - - std::string baseFileName; - - std::vector srcFile; - std::vector dstFile; -} - // // Main function // @@ -137,7 +188,8 @@ private: int main(int argc, char **argv) { parseCommandLine(argc, argv); - getEnvironmentSettings(); + getDeveloperId(); + getDate(); printBanner(); @@ -145,17 +197,97 @@ int main(int argc, char **argv) embedVersionString(); writeFiles(); - ERROR("This tool is not finished yet"); + std::cout << "\n\nXXX This tool is not finished yet\n\n"; - return 0; + return 1; } // // Class 'ROMFile' // -ROMFile::ROMFile(const std::string &baseFileName) +ROMFile::ROMFile(const std::string &baseFileName) : + baseFileName(baseFileName), + romType(ROMType::ROM_UNKNOWN) { + readSrcFile(); + readDstFile(); + + recognizeFiles(); +} + +void ROMFile::readSrcFile() +{ + // Read the source file + + const std::string srcFileNamePath = CMD_inDir + DIR_SEPARATOR + baseFileName; + + std::ifstream srcFile; + srcFile.open(srcFileNamePath, std::ios::in | std::ios::binary | std::ios::ate); + + if (!srcFile.good()) ERROR(std::string("unable to open ROM file '") + srcFileNamePath + "'"); + + auto srcSize = srcFile.tellg(); + if (srcSize != 8192) ERROR(std::string("incorrect size of ROM file '") + srcFileNamePath + "'"); + + srcFileContent.resize(8192); + srcFile.seekg (0, srcFile.beg); + srcFile.read((char *) srcFileContent.data(), srcFileContent.size()); + + if (!srcFile.good()) ERROR(std::string("unable to read ROM file '") + srcFileNamePath + "'"); + srcFile.close(); +} + +void ROMFile::readDstFile() +{ + // Read the destination file (if exists and it's size matches) + + const std::string dstFileNamePath = CMD_outDir + DIR_SEPARATOR + baseFileName; + + std::ifstream dstFile; + dstFile.open(dstFileNamePath, std::ios::in | std::ios::binary | std::ios::ate); + + bool continueReading = dstFile.good(); + + if (continueReading && dstFile.tellg() != 8192) continueReading = false; + + if (continueReading) + { + dstFileContent.resize(8192); + dstFile.seekg (0, dstFile.beg); + dstFile.read((char *) dstFileContent.data(), dstFileContent.size()); + } + + if (!dstFile.good()) dstFileContent.resize(0); + dstFile.close(); +} + +void ROMFile::recognizeFiles() +{ + // Recognize source file type + + std::cout << baseFileName << " "; + + if ((memcmp(&srcFileContent[0x0004], STR_MEGABAS.data(), STR_MEGABAS.size()) == 0) && + (memcmp(&srcFileContent[0x1F52], STR_OR.data(), STR_OR.size()) == 0) && + (memcmp(&srcFileContent[0x1F55], STR_SNAPSHOT.data(), STR_SNAPSHOT.size()) == 0)) + { + romType = ROMType::ROM_BASIC; + } + else if (srcFileContent[0x1F80] == 0xF0 && + (memcmp(&srcFileContent[0x04B9], STR_OR.data(), STR_OR.size()) == 0) && + (memcmp(&srcFileContent[0x04BC], STR_SNAPSHOT.data(), STR_SNAPSHOT.size()) == 0)) + { + romType = ROMType::ROM_KERNAL; + } + else + { + ERROR(std::string("'") + CMD_inDir + DIR_SEPARATOR + baseFileName + + "' is not a supported unversioned Open ROMs image"); + } + // XXX + std::cout << baseFileName << " "; + std::cout << "\n"; }