further work on release tool

This commit is contained in:
FeralChild64 committed 2019-10-18 22:35:46 +02:00
1 parent 41264c9300
commit ae4b6acc55
3 files changed
+161 -25

No files matched your search

@@ -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
@@ -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
+157 -25
View File
@@ -6,10 +6,21 @@
#include "common.h"
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <ios>
#include <list>
#include <vector>
const std::vector<uint8_t> STR_MEGABAS = { 0x4D, 0x45, 0x47, 0x41, 0x42, 0x41, 0x53, 0x32 };
const std::vector<uint8_t> STR_OR = { 0x4F, 0x52 };
const std::vector<uint8_t> 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<std::string> CMD_fileList;
std::string ENV_developerId;
std::string ENV_timeString;
//
// Common helper functions
@@ -33,6 +45,44 @@ void printUsage()
" <file list>" << "\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<uint8_t> srcFileContent;
std::vector<uint8_t> dstFileContent;
ROMType romType;
};
//
// Global variables
//
std::list<ROMFile> 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<uint8_t> srcFile;
std::vector<uint8_t> 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";
}