From 1db03b5921d2615a9225237d13726b31ad57f044 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 17 Oct 2019 21:55:27 +0200 Subject: [PATCH] started work on release tool --- Makefile | 5 +- STATUS.md | 1 + src/build_segment.cc | 51 +------------- src/common.h | 58 ++++++++++++++++ src/release.cc | 161 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 225 insertions(+), 51 deletions(-) create mode 100644 src/common.h create mode 100644 src/release.cc diff --git a/Makefile b/Makefile index 6e67c942..4e92e5e0 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ TOOL_COLLECT_DATA = build/tools/collect_data TOOL_COMPRESS_TEXT = build/tools/compress_text TOOL_PNGPREPARE = build/tools/pngprepare TOOL_BUILD_SEGMENT = build/tools/build_segment +TOOL_RELEASE = build/tools/release TOOL_SIMILARITY = build/tools/similarity TOOL_ASSEMBLER = assembler/KickAss.jar @@ -67,7 +68,7 @@ all: $(STD_TARGET_LIST) $(EXT_TARGET_LIST) clean: @rm -rf build -updatebin: $(STD_TARGET_LIST) +updatebin: $(STD_TARGET_LIST) $(STD_TOOL_RELEASE) cp build/chargen.rom bin/chargen.rom cp build/basic_generic.rom bin/basic_generic.rom cp build/kernal_generic.rom bin/kernal_generic.rom @@ -90,7 +91,7 @@ build/tools/%: src/%.c @mkdir -p build/tools $(CC) -O2 -Wall -o $@ $< -build/tools/%: src/%.cc +build/tools/%: src/%.cc src/common.h @mkdir -p build/tools $(CXX) -O2 -Wall -o $@ $< diff --git a/STATUS.md b/STATUS.md index 28523aaa..a535689f 100644 --- a/STATUS.md +++ b/STATUS.md @@ -160,6 +160,7 @@ Not all of them - only these we want to have implemented. | `$EA31` | default IRQ | PARTIAL | | | `$EA7E` | ack CIA1 + below | DONE | | | `$EA81` | ret from IRQ/NMI | DONE | | +| `$F142` | get key from buffer | DONE | | | `$FD30` | default vectors | DONE | | | `$FE47` | default NMI | PARTIAL | | | `$FE66` | default BRK | DONE | | diff --git a/src/build_segment.cc b/src/build_segment.cc index 9c55842e..3d36888d 100644 --- a/src/build_segment.cc +++ b/src/build_segment.cc @@ -3,6 +3,8 @@ // source files, placing routines where they need to live // +#include "common.h" + #include #include #include @@ -13,19 +15,11 @@ #include #include #include -#include -#include #include #include #include #include -#if defined(WIN32) || defined(_WIN32) - #define DIR_SEPARATOR "\\" -#else - #define DIR_SEPARATOR "/" -#endif - const std::string ASM_CMD = "java -jar "; const std::string LAB_OUT_START = "__routine_START_"; @@ -33,8 +27,6 @@ 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 BANNER_LINE = "//-------------------------------------------------------------------------------------------"; - // // Command line settings // @@ -53,17 +45,6 @@ std::list CMD_inList; // Common helper functions // -void ERROR() -{ - exit(-1); -} - -void ERROR(const std::string &message) -{ - std::cout << "\n" << "ERROR: " << message << "\n\n"; - exit(-1); -} - void printUsage() { std::cout << "\n" << @@ -73,16 +54,6 @@ void printUsage() " " << "\n\n"; } -void printBannerLineTop() -{ - std::cout << "\n\n\n" << BANNER_LINE << "\n"; -} - -void printBannerLineBottom() -{ - std::cout << BANNER_LINE << "\n\n"; -} - void printBannerCollectAnalyse() { printBannerLineTop(); @@ -101,24 +72,6 @@ void printBannerBinCompile() // Class definitions // -class DualStream -{ -public: - DualStream(std::ostream& str1, std::ostream& str2) : str1(str1), str2(str2) {} - - template DualStream &operator<<(const T& x) - { - str1 << x; - str2 << x; - - return *this; - } - -private: - std::ostream& str1; - std::ostream& str2; -}; - class SourceFile { public: diff --git a/src/common.h b/src/common.h new file mode 100644 index 00000000..861d6f0e --- /dev/null +++ b/src/common.h @@ -0,0 +1,58 @@ +// +// Common parts of utilities written in C++ +// for providing uniform user experience +// + +#include +#include + + +#if defined(WIN32) || defined(_WIN32) + #define DIR_SEPARATOR "\\" +#else + #define DIR_SEPARATOR "/" +#endif + + +const std::string BANNER_LINE = "//-------------------------------------------------------------------------------------------"; + + +void ERROR() +{ + exit(-1); +} + +void ERROR(const std::string &message) +{ + std::cout << "\n" << "ERROR: " << message << "\n\n"; + exit(-1); +} + +void printBannerLineTop() +{ + std::cout << "\n\n\n" << BANNER_LINE << "\n"; +} + +void printBannerLineBottom() +{ + std::cout << BANNER_LINE << "\n\n"; +} + + +class DualStream +{ +public: + DualStream(std::ostream& str1, std::ostream& str2) : str1(str1), str2(str2) {} + + template DualStream &operator<<(const T& x) + { + str1 << x; + str2 << x; + + return *this; + } + +private: + std::ostream& str1; + std::ostream& str2; +}; diff --git a/src/release.cc b/src/release.cc new file mode 100644 index 00000000..cd3c466e --- /dev/null +++ b/src/release.cc @@ -0,0 +1,161 @@ +// +// Utility to prepare a release with automatically +// assigned version numbers +// + +#include "common.h" + +#include +#include + +#include +#include + +// +// Command and enviroment line settings +// + +std::string CMD_inDir = "./build"; +std::string CMD_outDir = "./bin"; + +std::list CMD_fileList; + +std::string ENV_developerId; + +// +// Common helper functions +// + +void printUsage() +{ + std::cout << "\n" << + "usage: release [-i ] [-o ]" << "\n" << + " " << "\n\n"; +} + +// +// Top-level functions +// + +void parseCommandLine(int argc, char **argv) +{ + int opt; + + // Retrieve command line options + + while ((opt = getopt(argc, argv, "i:o:")) != -1) + { + switch(opt) + { + case 'i': CMD_inDir = optarg; break; + case 'o': CMD_outDir = optarg; break; + default: printUsage(); ERROR(); + } + } + + // Retrieve file/directory list + + for (int idx = optind; idx < argc; idx++) + { + CMD_fileList.push_back(argv[idx]); + } + + if (CMD_fileList.empty()) { printUsage(); ERROR("empty file list"); } +} + +void getEnvironmentSettings() +{ + const char* id = getenv("OPEN_ROMS_DEVELOPER_ID"); + + // Check whether the developer ID is suitable + + if (id == nullptr) + { + ERROR("environment variable OPEN_ROMS_DEVELOPER_ID not set"); + } + + ENV_developerId = id; + + if (ENV_developerId.length() < 2 || ENV_developerId.length() > 3) + { + ERROR("OPEN_ROMS_DEVELOPER_ID has to be 2 or 3 characters long"); + } + + for (const char &c : ENV_developerId) + { + if (!(c >= 'A' && c <= 'Z')) + { + ERROR("OPEN_ROMS_DEVELOPER_ID can only contain uppercase letters"); + } + } +} + +void printBanner() +{ + printBannerLineTop(); + std::cout << "// Preparing ROM set release by '" << ENV_developerId << "'\n"; + printBannerLineBottom(); +} + +void readFiles() +{ + // XXX +} + +void embedVersionString() +{ + // XXX +} + +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 +// + +int main(int argc, char **argv) +{ + parseCommandLine(argc, argv); + getEnvironmentSettings(); + + printBanner(); + + readFiles(); + embedVersionString(); + writeFiles(); + + ERROR("This tool is not finished yet"); + + return 0; +} + +// +// Class 'ROMFile' +// + +ROMFile::ROMFile(const std::string &baseFileName) +{ + // XXX + +}