From 2f79abe46190de57a0c73d59da542dddf81c8d4d Mon Sep 17 00:00:00 2001 From: Shawn Quick Date: Sun, 5 Feb 2023 10:49:07 -0800 Subject: [PATCH] work on cmake-tools under vscode, adding syntax checking, and script processing --- .vscode/c_cpp_properties.json | 35 +++++ .vscode/launch.json | 39 +++++ CMakeLists.txt | 31 +++- Makefile | 41 ++--- asm.cpp | 64 +++++--- asm.h | 43 ++++-- cider.cpp | 62 ++++++++ cider.h | 22 +++ config.h | 4 +- diskimg/CMakeLists.txt | 11 +- diskimg/Global.cpp | 3 +- lup.s | 5 +- merlintests.sh | 1 + opcodes.cpp | 3 + qasm.json => parms.json | 12 +- qasm.cpp | 281 ++++++++++++++++++++++------------ qasm.h | 13 +- qasm.ini | 43 ------ qoptions.cpp | 84 ++++++++++ qoptions.h | 21 +++ testdata/3000-addresses.S | 4 +- util.cpp | 11 ++ util.h | 5 + 23 files changed, 618 insertions(+), 220 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 cider.cpp create mode 100644 cider.h rename qasm.json => parms.json (60%) delete mode 100644 qasm.ini create mode 100644 qoptions.cpp create mode 100644 qoptions.h create mode 100644 util.cpp create mode 100644 util.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..1f6715b --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,35 @@ +{ + "version": 4, + "env": { + "def_include": [ + "${workspaceRoot}/libpal/include", + "${workspaceRoot}/libpal/include/pal", + "${workspaceRoot}/nufxlib", + "${workspaceRoot}/diskimg", + "${workspaceRoot}/libhfs", + "${workspaceRoot}" + ] + }, + "configurations": [ + { + "name": "CMake", + "configurationProvider": "ms-vscode.cmake-tools", + "includePath": [ + "${def_include}" + ], + "browse": { + "path": [ + "${def_include}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db" + }, + //"compilerPath": "/usr/bin/clang++", + //"compilerArgs": [ + // "-Wall" + //], + "compileCommands": "${workspaceFolder}/compile_commands.json", + //"intelliSenseMode": "linux-clang-x64", + } + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..230606d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,39 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + // Resolved by CMake Tools: + "program": "${command:cmake.launchTargetPath}", + "args": [ + "${workspaceFolder}/test.s" + ], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "externalConsole": true, + "environment": [ + { + // add the directory where our target was built to the PATHs + // it gets resolved by CMake Tools: + "name": "PATH", + "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" + }, + { + "name": "OTHER_VALUE", + "value": "Something something" + } + ], + //"console": "externalTerminal", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce133a..60c37f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,19 @@ cmake_minimum_required(VERSION 3.0) -#set (CMAKE_VERBOSE_MAKEFILE "1") + +set(CIDER "1") +#set (CMAKE_C_COMPILER /usr/bin/clang) +#set (CMAKE_CXX_COMPILER /usr/bin/clang++) + set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) -#set (CMAKE_C_COMPILER /usr/bin/clang) -#set (CMAKE_CXX_COMPILER /usr/bin/clang) - +set (CMAKE_VERBOSE_MAKEFILE "1") project(QAsm) -set(CIDER "1") -set(APPVERSION "4.0.9") +set(APPVERSION "4.0.10") set(LIBRARY_NAME pal) set(FIND_LIBRARY_USE_LIB64_PATHS TRUE) @@ -22,12 +23,28 @@ set(FIND_LIBRARY_USE_LIB64_PATHS TRUE) set ( PROJECT_NAME "qasm" ) +set(ALL_DEFINES ) +set(ALL_FLAGS "-Wall -Wno-unused-const-variable" ) +set(DEBUG_OPT "-D_DEBUG -DDEBUG -O0 -g3 ${ALL_FLAGS} " ) +set(RELEASE_OPT "-O3 ${ALL_FLAGS} " ) + +set(CMAKE_C_FLAGS "${ALL_FLAGS}") +set(CMAKE_CXX_FLAGS "${ALL_FLAGS}") + +set(CMAKE_CXX_FLAGS_DEBUG "${DEBUG_OPT}") +set(CMAKE_CXX_FLAGS_RELEASE "${RELEASE_OPT}") +set(CMAKE_C_FLAGS_DEBUG "${DEBUG_OPT}") +set(CMAKE_C_FLAGS_RELEASE "${RELEASE_OPT}") + + set(SOURCE ${PROJECT_ROOT}/${PROJECT_NAME}.cpp ${PROJECT_ROOT}/asm.cpp ${PROJECT_ROOT}/opcodes.cpp ${PROJECT_ROOT}/eval.cpp ${PROJECT_ROOT}/psuedo.cpp + ${PROJECT_ROOT}/qoptions.cpp + ${PROJECT_ROOT}/cider.cpp ) #find_package(OpenSSL REQUIRED) @@ -50,6 +67,8 @@ include_directories(BEFORE set (CIDERLIBS "" ) if ( ${CIDER} ) add_definitions(-DCIDERPRESS) +add_definitions(-DAPPVERSION=${APPVERSION}) + include_directories(AFTER ${PROJECT_ROOT}/diskimg) add_subdirectory(${PROJECT_ROOT}/libhfs) add_subdirectory(${PROJECT_ROOT}/nufxlib) diff --git a/Makefile b/Makefile index 8762073..d8eca69 100644 --- a/Makefile +++ b/Makefile @@ -9,16 +9,16 @@ export CC=gcc endif V?= -S= +export S= ifneq ("$V","") -S="VERBOSE=1" +export S="VERBOSE=1" else .SILENT: endif all: -mkdir -p ./build - -cd ./build && cmake -DCMAKE_BUILD_TYPE=DEBUG .. && $(MAKE) $S + -cd ./build && $(MAKE) $S release: -rm -rf ./build @@ -30,24 +30,13 @@ debug: -mkdir -p ./build -cd ./build && cmake -DCMAKE_BUILD_TYPE=DEBUG .. && $(MAKE) $S - - -hfs: - -mkdir -p ./libhfs/build - cd ./libhfs/build && cmake .. && $(MAKE) - -nufx: - cd ./nufxlib && $(MAKE) clean && ./configure && $(MAKE) - -distclean: - -rm -rf ./build +distclean: clean -rm -rf ./qasmout -rm -rf ./m32out + -rm -rf ./libhfs/build ./nufxlib/build ./diskimg/build ./libpal/build clean: - -rm -rf ./build - -rm -rf ./testout - -rm -rf ./libhfs/build ./nufxlib/build ./diskimg/build ./libpal/build + -rm -rf ./build *.2mg test.bin depend: @@ -63,15 +52,18 @@ install: -cd ./build && cmake -P cmake_install.cmake reformat: - qasm -x REFORMAT src/main.s - -compare: - -bcompare . ../lane_qasm & + qasm -x REFORMAT test.s asm: - + +tests: + -rm -rf ./m32out/* ./qasmout/* + merlintests.sh + runtests.sh + + test1: - -qasm testdata/3001-lroathe.S + -qasm testdata/3001-runfile.S test2: -qasm testdata/3002-testfile.S @@ -79,7 +71,8 @@ test2: test3: -qasm testdata/3003-var.S - +gsplus: + daemon -- /usr/bin/xterm -e "cd /mnt/nas/gsplus && ./gsplus" diff --git a/asm.cpp b/asm.cpp index aaa5f5a..47b652e 100644 --- a/asm.cpp +++ b/asm.cpp @@ -1,4 +1,5 @@ #define ADD_ERROR_STRINGS + #include "asm.h" #include "eval.h" #include "psuedo.h" @@ -301,7 +302,6 @@ void CLASS::print(uint32_t lineno) void CLASS::clear() { - syntax = SYNTAX_MERLIN; wholetext = ""; lable = ""; printlable = ""; @@ -539,6 +539,7 @@ CLASS::CLASS() { int x; errorct = 0; + syntax=SYNTAX_QASM; win_columns = -1; win_rows = -1; @@ -557,6 +558,11 @@ CLASS::~CLASS() { } +void CLASS::setSyntax(uint32_t syn) +{ + syntax=syn; +} + void CLASS::errorOut(uint16_t code) { printf("error: %d\n", code); @@ -570,23 +576,8 @@ void CLASS::init(void) filenames.clear(); starttime = GetTickCount(); initialdir = Poco::Path::current(); - syntax = SYNTAX_MERLIN; filecount = 0; - - s = getConfig("option.syntax", "merlin16"); - s = Poco::toUpper(Poco::trim(s)); - if ((s == "MERLIN") || (s == "MERLIN16")) - { - syntax = SYNTAX_MERLIN; - } - else if (s == "MERLIN32") - { - syntax = SYNTAX_MERLIN32; - } - else if (s == "QASM") - { - syntax = SYNTAX_QASM; - } + syntax = SYNTAX_QASM; std::string tabstr = getConfig("reformat.tabs", "8,16,32"); tabstr = Poco::trim(tabstr); @@ -916,6 +907,32 @@ int CLASS::processfile(std::string p, std::string &newfilename) return (res); } +#undef CLASS +#define CLASS TImageProcessor + +CLASS::CLASS() : TFileProcessor() +{ + +} +CLASS::~TImageProcessor() +{ + +} + +int CLASS::doline(int lineno, std::string line) +{ + printf("%05d: %s\n",lineno,line.c_str()); + return(0); +} +void CLASS::process(void) +{ + +} +void CLASS::complete(void) +{ + +} + #undef CLASS #define CLASS TMerlinConverter CLASS::CLASS() : TFileProcessor() @@ -929,8 +946,6 @@ void CLASS::init(void) TFileProcessor::init(); std::string s; lines.clear(); - - syntax = SYNTAX_MERLIN; } int CLASS::doline(int lineno, std::string line) @@ -947,6 +962,7 @@ void CLASS::process(void) char buff[128*1024]; uint32_t ct = (uint32_t)lines.size(); + uint8_t orval=0x80; uint32_t len, tlen,t, pos,i; @@ -1008,7 +1024,7 @@ void CLASS::process(void) { len += sprintf(&buff[len+tlen]," "); } - if (syntax==SYNTAX_MERLIN) + if (syntax ==SYNTAX_MERLIN) len += sprintf(&buff[len+tlen],"\r"); else len += sprintf(&buff[len+tlen],"\n"); @@ -1025,7 +1041,7 @@ void CLASS::process(void) if (c==0x20) { if (tct<3) - buff[i]=0xA0; + buff[i]=0x20 | orval; else { buff[i]=0x20; @@ -1044,7 +1060,7 @@ void CLASS::process(void) } else { - buff[i]=c|0x80; + buff[i]=c|orval; } } FILE *f=NULL; @@ -1264,7 +1280,7 @@ TSymbol * CLASS::addVariable(std::string symname, std::string val, TVariable &va if (fnd != NULL) { - printf("replacing symbol: %s %s\n",sym.c_str(),val.c_str()); + //printf("replacing symbol: %s %s\n",sym.c_str(),val.c_str()); fnd->var_text = val; return (fnd); } @@ -1279,7 +1295,7 @@ TSymbol * CLASS::addVariable(std::string symname, std::string val, TVariable &va s.used = false; s.cb = NULL; - printf("addvariable: %s %s\n", s.name.c_str(), s.var_text.c_str()); + //printf("addvariable: %s %s\n", s.name.c_str(), s.var_text.c_str()); std::pair p(sym, s); vars.vars.insert(p); diff --git a/asm.h b/asm.h index ac4523f..a246ea5 100644 --- a/asm.h +++ b/asm.h @@ -1,4 +1,6 @@ + #pragma once + #include "app.h" // #define OPHANDLER(ACB) std::bind(ACB, this, std::placeholders::_1, std::placeholders::_2) @@ -7,11 +9,13 @@ #define MODE_65C02 1 #define MODE_65816 2 -#define SYNTAX_MERLIN 0 -#define SYNTAX_MERLIN32 0x01 -#define SYNTAX_APW 0x02 -#define SYNTAX_ORCA 0x04 -#define SYNTAX_QASM (0x08 | SYNTAX_MERLIN32) +#define SYNTAX_MERLIN 0x01 +#define SYNTAX_MERLIN32 0x02 +#define SYNTAX_APW 0x04 +#define SYNTAX_MPW 0x08 +#define SYNTAX_ORCA 0x10 +#define SYNTAX_CC65 0x20 +#define SYNTAX_QASM (0x80 | SYNTAX_MERLIN) #define OPTION_ALLOW_A_OPERAND 0x0100 #define OPTION_ALLOW_LOCAL 0x0200 #define OPTION_ALLOW_COLON 0x0400 @@ -246,6 +250,7 @@ protected: uint8_t tabs[16]; uint32_t filecount; // how many files have been read in (because of included files from source + public: uint32_t errorct; std::string filename; @@ -259,6 +264,20 @@ public: virtual void process(void); virtual void complete(void); virtual void errorOut(uint16_t code); + virtual void setSyntax(uint32_t syn); +}; + +class TImageProcessor : public TFileProcessor +{ +protected: + std::vector lines; + +public: + TImageProcessor(); + virtual ~TImageProcessor(); + virtual int doline(int lineno, std::string line); + virtual void process(void); + virtual void complete(void); }; class TMerlinConverter : public TFileProcessor @@ -352,13 +371,13 @@ public: class TVariable { public: - uint32_t id; - Poco::HashMap vars; - TVariable() - { - // SGQ - must fix this so it is guaranteed unique for each one - id=rand(); - } + uint32_t id; + Poco::HashMap vars; + TVariable() + { + // SGQ - must fix this so it is guaranteed unique for each one + id=rand(); + } }; class TMacro diff --git a/cider.cpp b/cider.cpp new file mode 100644 index 0000000..f7d6a8f --- /dev/null +++ b/cider.cpp @@ -0,0 +1,62 @@ +#include "asm.h" +#include "eval.h" +#include "psuedo.h" +#include +#include +#include + +#include +#include +#define CLASS CiderPress + +using namespace DiskImgLib; +using DiskImgLib::DiskImg; + +void dbgMessage(const char *file, int line, const char *msg) +{ + + printf("DEBUG: %s\n",msg); +} + +CLASS::CLASS() +{ + if (!Global::GetAppInitCalled()) + { + DiskImgLib::Global::SetDebugMsgHandler(dbgMessage); + DiskImgLib::Global::AppInit(); + } +} + +int CLASS::RunScript(string path) +{ + int res=-1; + + + + return(res); +} + +int CLASS::CreateVolume(string OSName, string VolName, uint64_t size, CIDER_VOLFORMAT format) +{ + int interr=-1; + DIError err; + DiskImg *img=new DiskImg(); + if (format==CP_PRODOS) + { + + err=img->CreateImage(OSName.c_str(),VolName.c_str(), + DiskImg::kOuterFormatNone, + DiskImg::kFileFormat2MG, + DiskImg::kPhysicalFormatSectors, + NULL, + DiskImg::kSectorOrderProDOS, + DiskImg::kFormatGenericProDOSOrd, + size/256, + false + ); + printf("create error: %d\n",err); + if (err== kDIErrNone ) + interr=0; + } + return (interr); +} diff --git a/cider.h b/cider.h new file mode 100644 index 0000000..f006dfc --- /dev/null +++ b/cider.h @@ -0,0 +1,22 @@ +#pragma once + +#include "asm.h" +#include "eval.h" +#include "psuedo.h" +#include +#include +#include +#include "DiskImg.h" + +#define CLASS CiderPress + +enum CIDER_VOLFORMAT {CP_PRODOS,CP_HFS}; +class CLASS +{ + public: + CLASS(); + int CreateVolume(string OSName, string VolName, uint64_t size, CIDER_VOLFORMAT format); + int RunScript(string path); +}; + +#undef CLASS \ No newline at end of file diff --git a/config.h b/config.h index cd47cb2..ce82ecb 100644 --- a/config.h +++ b/config.h @@ -10,12 +10,12 @@ #define USE_LOGGER //#define USE_NET //#define USE_SSL -//#define USE_JSON +#define USE_JSON //#define USE_XML #define NO_TTY_SETUP // help text #define HELP_USAGE " " -#define HELP_PURPOSE "\nMerlin 8/16(+) Compatible 65816 Development Tool" +#define HELP_PURPOSE "\nMerlin 8/16(+)/32 Compatible 65816 Development Tool" diff --git a/diskimg/CMakeLists.txt b/diskimg/CMakeLists.txt index 4ec63de..0adcb72 100644 --- a/diskimg/CMakeLists.txt +++ b/diskimg/CMakeLists.txt @@ -8,7 +8,16 @@ set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) project(${PROJECT_NAME}) -set(ALL_DEFINES " " ) + +#set (ALL_DEFINES "\ +#-DSTDC_HEADERS=1 -DHAVE_FDOPEN=1 -DHAVE_FTRUNCATE=1 -DHAVE_LOCALTIME_R=1 -DHAVE_MEMMOVE=1 \ +#-DHAVE_MKDIR=1 -DHAVE_MKSTEMP=1 -DHAVE_MKTIME=1 -DHAVE_SNPRINTF=1 -DHAVE_STRCASECMP=1 -DHAVE_STRNCASECMP=1 -DHAVE_STRERROR=1 \ +#-DHAVE_STRTOUL=1 -DHAVE_TIMELOCAL=1 -DHAVE_VSNPRINTF=1 -DHAVE_FCNTL_H=1 -DHAVE_MALLOC_H=1 -DHAVE_STDLIB_H=1 -DHAVE_SYS_STAT_H=1 \ +#-DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_UNISTD_H=1 -DHAVE_UTIME_H=1 -DSPRINTF_RETURNS_INT=1 -DSNPRINTF_DECLARED=1 \ +#-DVSNPRINTF_DECLARED=1 -DENABLE_SQ=1 -DENABLE_LZW=1 -DENABLE_LZC=1 -DENABLE_DEFLATE=1 \ +#" +#) + set(DEBUG_OPT "-D_DEBUG -DDEBUG -O0 -g3 " ) set(RELEASE_OPT "-O3 " ) diff --git a/diskimg/Global.cpp b/diskimg/Global.cpp index f949e60..39fc1a1 100644 --- a/diskimg/Global.cpp +++ b/diskimg/Global.cpp @@ -172,7 +172,7 @@ Global::DebugMsgHandler Global::SetDebugMsgHandler(DebugMsgHandler handler) return; } - char buf[512]; + char buf[1024]; va_list args; va_start(args, fmt); @@ -187,5 +187,6 @@ Global::DebugMsgHandler Global::SetDebugMsgHandler(DebugMsgHandler handler) buf[sizeof(buf)-1] = '\0'; + (*gDebugMsgHandler)(file, line, buf); } diff --git a/lup.s b/lup.s index c91ebcc..9251c78 100644 --- a/lup.s +++ b/lup.s @@ -1,7 +1,6 @@ + xc + xc lst on - xc off - xc - xc org $2000 macro mac diff --git a/merlintests.sh b/merlintests.sh index dcf3146..1d3d03d 100755 --- a/merlintests.sh +++ b/merlintests.sh @@ -16,6 +16,7 @@ SRC=`ls ./testdata | grep -E '^([0-9]+)(.*)\.[Ss]'` for S in $SRC ; do + echo "merlin32 $S" S1=$S S1=${S1/.S/} S1=${S1/.s/} diff --git a/opcodes.cpp b/opcodes.cpp index fedc8d3..3226664 100644 --- a/opcodes.cpp +++ b/opcodes.cpp @@ -309,6 +309,9 @@ int CLASS::doAddress(MerlinLine &line, TSymbol &sym) res = 1 + sym.stype; if (pass > 0) { + //if (isMerlin816()) + //{ + //} switch(line.expr_shift) { case '^': diff --git a/qasm.json b/parms.json similarity index 60% rename from qasm.json rename to parms.json index d7c21ab..6da923e 100644 --- a/qasm.json +++ b/parms.json @@ -1,18 +1,26 @@ { + "version": "1.1", "general": { "prefix": [ { - "0": "{PWD}" + "0": "${PWD}" }, { "1": "0/source" }, { "2": "0/object" + }, + { + "3": "0/macros" } ] }, - "assembler": {}, + "assembler": { + "cpu_default": "6502", + "syntax": "merlin", + "listmode": "on" + }, "linker": {}, "format": { "tabs": "12,18,30" diff --git a/qasm.cpp b/qasm.cpp index 407f100..a7cc4d6 100644 --- a/qasm.cpp +++ b/qasm.cpp @@ -1,11 +1,12 @@ #include "app.h" #include "asm.h" #ifdef CIDERPRESS -#include "DiskImg.h" +#include "cider.h" #endif #define CLASS PAL_APPCLASS + // return a pointer to the actual Application class PAL_BASEAPP *PAL::appFactory(void) { @@ -19,9 +20,9 @@ programOption PAL::appOptions[] = { "debug", "d", "enable debug info (repeat for more verbosity)", "", false, true}, #endif //{ "config", "f", "load configuration data from a ", "", false, false}, - { "exec", "x", "execute a command [asm, link, reformat,disk] default=asm", "", false, false}, + { "exec", "x", "execute a command [asm, link, reformat, script] default=asm", "", false, false}, { "objfile", "o", "write output to file", "", false, false}, - { "syntax", "s", "enforce syntax of other assembler [merlin16, merlin32]", "", false, false}, + { "syntax", "s", "enforce syntax of other assembler [qasm, merlin, merlin32, ORCA, APW, MPW, CC65]", "", false, false}, { "", "", "", "", false, false} @@ -36,50 +37,29 @@ void CLASS::displayVersion() #endif cerr << "quickASM 16++ v" << (std::string)STRINGIFY(APPVERSION) << s << endl; -#ifdef CIDERPRESS - DiskImgLib::Global::AppInit(); - DiskImgLib::DiskImg prodos; +//#ifdef CIDERPRESS +// DiskImgLib::Global::AppInit(); +// DiskImgLib::DiskImg prodos; - DiskImgLib::Global::AppCleanup(); -#endif +// DiskImgLib::Global::AppCleanup(); +//#endif } -#ifdef SERVERAPP -int CLASS::runServerApp(PAL_EVENTMANAGER *em) -{ - int res = -1; - if (em != NULL) - { - PAL_BASEAPP::runServerApp(em); -#if 0 - PAL_HTTPSERVERTASK *server = new PAL_HTTPSERVERTASK("httptask"); - if (server != NULL) - { - em->startTask(server); - server->initServer(getConfig("http.listen", "0.0.0.0:9080"), false, 64); - res = 0; - } -#endif - } - return (res); -} -#endif - void CLASS::showerror(int ecode, std::string fname) { std::string s; switch (ecode) { - case -2: - s = "Permission Denied"; - break; - case -3: - s = "File not found"; - break; - default: - s = "Unknown Error"; - break; + case -2: + s = "Permission Denied"; + break; + case -3: + s = "File not found"; + break; + default: + s = "Unknown Error"; + break; } if (ecode < -1) { @@ -88,13 +68,15 @@ void CLASS::showerror(int ecode, std::string fname) } } +// int main(int argc, char *argv[]) +// this is where libpal calls to run a command line program int CLASS::runCommandLineApp(void) { TFileProcessor *t = NULL; std::string line; std::string startdirectory; std::string fname; - + uint32_t syntax; int res = -1; @@ -106,84 +88,187 @@ int CLASS::runCommandLineApp(void) return (res); } - for (ArgVec::const_iterator it = commandargs.begin(); it != commandargs.end(); ++it) + options.ReadFile(startdirectory+"/parms.json"); + + string syn=options.GetString("assembler.syntax","QASM"); + + string cmdsyn = Poco::toUpper(getConfig("option.syntax", "")); + if (cmdsyn!="") { - Poco::File fn(*it); - int x; - std::string p = fn.path(); - Poco::Path path(p); - //logger().information(path.toString()); + syn=cmdsyn; // if they overrode the syntax on the command line, use it + } - std::string e = toUpper(path.getExtension()); + syn=Poco::toUpper(syn); + syn=Poco::trim(syn); + syntax=SYNTAX_QASM; + if ((syn=="MERLIN") || (syn=="MERLIN16") || (syn=="MERLIN8") || (syn=="MERLIN16+")) + { + syntax=SYNTAX_MERLIN; + } + else if (syn=="MERLIN32") + { + syntax=SYNTAX_MERLIN32; + } + else if (syn=="QASM") + { + syntax=SYNTAX_QASM; + } + else if (syn=="APW") + { + syntax=SYNTAX_APW; + } + else if (syn=="ORCA") + { + syntax=SYNTAX_ORCA; + } + else if (syn=="MPW") + { + syntax=SYNTAX_MPW; + } + else if (syn=="CC65") + { + syntax=SYNTAX_CC65; + } - std::string cmd = Poco::toUpper(getConfig("option.exec", "asm")); + printf("SYNTAX: |%s|\n",syn.c_str()); - //printf("DEBUG=%d\n",isDebug()); - if (cmd.length() > 0) + try + { +#ifdef CIDERPRESS + + //CiderPress *cp=new CiderPress(); + //int err=cp->CreateVolume("./a2.2mg","PRODOS1",800*1024,CP_PRODOS); + //printf("volume create: %d\n",err); + + //cp->RunScript(startdirectory+"/disk_commands.txt"); + + //delete(cp); + +#endif + + for (ArgVec::const_iterator it = commandargs.begin(); it != commandargs.end(); ++it) { - if (cmd == "REFORMAT") + Poco::File fn(*it); + int x; + std::string p = fn.path(); + Poco::Path path(p); + //logger().information(path.toString()); + + std::string e = toUpper(path.getExtension()); + + std::string cmd = Poco::toUpper(getConfig("option.exec", "asm")); + + //printf("DEBUG=%d\n",isDebug()); + if (cmd.length() > 0) { - res = 0; - t = new TMerlinConverter(); - if (t != NULL) + if (cmd == "REFORMAT") { - try + res = 0; + t = new TMerlinConverter(); + if (t != NULL) { - t->init(); - std::string f = path.toString(); - t->filename = f; - x = t->processfile(f, fname); - if (x == 0) + try { - t->process(); - t->complete(); + t->init(); + t->setSyntax(syntax); + + std::string f = path.toString(); + t->filename = f; + x = t->processfile(f, fname); + if (x == 0) + { + t->process(); + t->complete(); + } + else + { + showerror(x, fname); + t->errorct = 1; + } + res = (t->errorct > 0) ? -1 : 0; } - else + catch (...) { - showerror(x, fname); - t->errorct = 1; + delete t; + t = NULL; } - res = (t->errorct > 0) ? -1 : 0; - } - catch (...) - { - delete t; - t = NULL; } } - } - else if (cmd == "ASM") - { - int x; - t = new T65816Asm(); - if (t != NULL) + else if (cmd == "ASM") { - try + int x; + t = new T65816Asm(); + if (t != NULL) { - t->init(); - std::string f = path.toString(); - t->filename = f; - x = t->processfile(f, fname); - f = t->filename; - if (x == 0) + try { - t->process(); - t->complete(); + t->init(); + t->setSyntax(syntax); + + std::string f = path.toString(); + t->filename = f; + x = t->processfile(f, fname); + f = t->filename; + if (x == 0) + { + t->process(); + t->complete(); + } + else + { + showerror(x, fname); + t->errorct = 1; + } + res = (t->errorct > 0) ? -1 : 0; } - else + catch(const std::exception& e) { - showerror(x, fname); - t->errorct = 1; + delete t; + t = NULL; } - res = (t->errorct > 0) ? -1 : 0; + if (chdir(startdirectory.c_str())) {}; // return us back to where we were } - catch (...) - { - delete t; - t = NULL; - } - if (chdir(startdirectory.c_str())) {}; // return us back to where we were } +#ifdef CIDERPRESS + else if (cmd == "SCRIPT") + { + res = 0; + t = new TImageProcessor(); + if (t!=NULL) + { + try + { + t->init(); + t->setSyntax(syntax); + + std::string f = path.toString(); + t->filename = f; + x = t->processfile(f, fname); + f = t->filename; + if (x == 0) + { + t->process(); + t->complete(); + } + else + { + showerror(x, fname); + t->errorct = 1; + } + res = (t->errorct > 0) ? -1 : 0; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + if (t!=NULL) + { + delete t; + t=NULL; + } + } + } + } +#endif else { printf("not supported type\n"); @@ -195,6 +280,12 @@ int CLASS::runCommandLineApp(void) } } } + catch(...) + { +#ifdef CIDERPRESS + DiskImgLib::Global::AppCleanup(); +#endif + } return (res); } diff --git a/qasm.h b/qasm.h index 752cf2b..b26efb3 100644 --- a/qasm.h +++ b/qasm.h @@ -1,11 +1,13 @@ #pragma once #include -#include "palPoco.h" -#include "pallogger.h" -#include "eventtask.h" -#include "baseapp.h" -#include "httpserver.h" +#include +#include +#include +#include +#include "qoptions.h" +#include "util.h" +//#include #ifndef UNUSED #define UNUSED (void) @@ -25,6 +27,7 @@ protected: virtual void displayVersion(); public: + QOptions options; }; #undef CLASS diff --git a/qasm.ini b/qasm.ini deleted file mode 100644 index 8071c16..0000000 --- a/qasm.ini +++ /dev/null @@ -1,43 +0,0 @@ -[log] -loglevel=0; -logdir=/var/log/mylog -logfile=mylog.log - -[option] -;==debug must be an integer. Code can use this as a level -;debug=0 -nocolor=false -;syntax=merlin32 - -[application] -timezone=America/Los_Angeles - -[global] -; path0 can not be set. It will always be the linux 'pwd' at the time of launch -path0={PWD} -path1=0/macros -path2=0/output -path3=0/src -path4= -path5=dirpath5 - -[asm] -casesen=true -showmx=true -startmx=3 -lst=true -; can be M6502, M65C02, M65816 -cpu=M65816 -trackrep=true -allowduplicate=true -merlinerrors=true -symcolumns=3 - -[reformat] -tabs=12;18;30 - - - - - - diff --git a/qoptions.cpp b/qoptions.cpp new file mode 100644 index 0000000..ef136b3 --- /dev/null +++ b/qoptions.cpp @@ -0,0 +1,84 @@ + +#include + +#undef CLASS +#define CLASS QOptions + +CLASS::CLASS() +{ + jsonin=""; + jsonobj=NULL; + parser.reset(); +} + +int CLASS::ReadFile(string path) +{ + int ret=-1; + + Poco::FileInputStream fs(path); + Poco::StreamCopier::copyToString(fs,jsonin); + jsonobj=parser.parse(jsonin); + + config.load(path); + //config.enumerate(key,range); + return(ret); +} + +Dynamic::Var CLASS::GetObject(string name) +{ + JSON::Query q(jsonobj); + Dynamic::Var jresult=q.find(name); + return(jresult); +} + +bool CLASS::GetBool(string name, bool def) +{ + bool res=def; + try + { + Dynamic::Var jresult=GetObject(name); + if (!jresult.isEmpty()) + { + if (jresult.isArray()) + { + + } + else if (jresult.isBoolean()) + { + res=jresult; + } + } + } + catch(...) + { + res=def; + } + return(res); +} + +string CLASS::GetString(string name, string def) +{ + string res=def; + try + { + Dynamic::Var jresult=GetObject(name); + if (!jresult.isEmpty()) + { + if (jresult.isArray()) + { + + } + else if (jresult.isString()) + { + res=jresult.toString(); + } + } + } + catch(...) + { + res=def; + } + return(res); +} + + diff --git a/qoptions.h b/qoptions.h new file mode 100644 index 0000000..dba7d09 --- /dev/null +++ b/qoptions.h @@ -0,0 +1,21 @@ +#pragma once +#include "app.h" + +#define CLASS QOptions + +class CLASS +{ +public: + Poco::Util::JSONConfiguration config; + Poco::JSON::Parser parser; + string jsonin; + Dynamic::Var jsonobj=NULL; + CLASS(); + int ReadFile(string path); + Dynamic::Var GetObject(string name); + + bool GetBool(string name, bool def=false); + string GetString(string name, string def=""); +}; + +#undef CLASS \ No newline at end of file diff --git a/testdata/3000-addresses.S b/testdata/3000-addresses.S index d99592b..79c630a 100644 --- a/testdata/3000-addresses.S +++ b/testdata/3000-addresses.S @@ -5,7 +5,7 @@ bank02 equ $020000 bank03 equ $030000 -dp equ $A5 +dp equ $55 long equ $020304 mx %00 @@ -17,7 +17,7 @@ start nop lda dp lda dp - lda ^dp + lda #^dp ; just ^dp is illegal in Merlin16 lda |dp lda #long lda # + +bool isMerlin32(void) +{ + return(false); +} + +bool isMerlin816(void) +{ + return(true); +} diff --git a/util.h b/util.h new file mode 100644 index 0000000..691941d --- /dev/null +++ b/util.h @@ -0,0 +1,5 @@ +#pragma once +#include + +bool isMerlin32(void); +bool isMerlin816(void); \ No newline at end of file