From 022eaa04388afe0de565e8a0f9324aacbd5538ab Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 10:48:01 -0800 Subject: [PATCH 01/10] test --- asm.cpp | 23 ++++++++++++++-------- asm.h | 8 +++----- psuedo.cpp | 58 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/asm.cpp b/asm.cpp index 21b39d9..125352f 100644 --- a/asm.cpp +++ b/asm.cpp @@ -34,7 +34,7 @@ void CLASS::print(uint32_t lineno) uint32_t b = 4; // how many bytes show on the first line - bool merlinstyle=true; + bool merlinstyle = true; if (datafillct > 0) { @@ -53,7 +53,7 @@ void CLASS::print(uint32_t lineno) if (merlinstyle) { //printf("errorcode=%d\n",errorcode); - printf("%s in line: %d", errStrings[errorcode].c_str(), lineno+1); + printf("%s in line: %d", errStrings[errorcode].c_str(), lineno + 1); if (errorText != "") { printf("%s", errorText.c_str()); @@ -1086,6 +1086,7 @@ int CLASS::callOpCode(std::string op, MerlinLine &line) { int res = -1; char c; + std::string s; if (op.length() == 4) // check for 4 digit 'L' opcodes { @@ -1101,7 +1102,12 @@ int CLASS::callOpCode(std::string op, MerlinLine &line) line.flags |= FLAG_FORCELONG; // 3 byte address break; default: // any char but 'L' as in Merlin 16+ - if ((c != 'D') || (Poco::toUpper(op) != "DEND")) + s = Poco::toUpper(op); + if ((s == "ELSE") || (s == "DEND")) + { + break; + } + if (c != 'D') { op = op.substr(0, 3); line.flags |= FLAG_FORCEABS; // 2 byte address @@ -1249,7 +1255,6 @@ void CLASS::initpass(void) allowdup = getBool("asm.allowduplicate", true); skiplist = false; - generateCode = true; PC.origin = 0x8000; PC.currentpc = PC.origin; @@ -1583,14 +1588,15 @@ int CLASS::substituteVariables(MerlinLine & line) return (res); } +// this function determines if code generation is turned off (IF,DO,LUP,MAC, etc bool CLASS::codeSkipped(void) { bool res = false; - if (curLUP.lupskip) - { - res = true; - } + res = (curLUP.lupskip) ? true : res; + res = (curDO.doskip) ? true : res; + + //printf("codeskip: %d\n",res); return (res); } @@ -1690,6 +1696,7 @@ void CLASS::process(void) if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc) { x = 0; + line.outbytect=0; } if (x > 0) diff --git a/asm.h b/asm.h index d64fd7c..1ccab1c 100644 --- a/asm.h +++ b/asm.h @@ -79,7 +79,7 @@ const std::string errStrings[errMAX + 1] = "Unimplemented Instruction", "Fatal", "Unsupported Addressing Mode", - "Unknown Opcode", + "Bad opcode", "Opcode not available under CPU mode", "Byte output differs between passes", "Relative branch offset too large", @@ -282,11 +282,11 @@ public: clear(); } void clear(void) { - dooff=false; + doskip=false; value=0; } uint32_t value; - bool dooff; + bool doskip; }; class TSymbol; @@ -345,8 +345,6 @@ public: bool skiplist; // used if lst is on, but LST opcode turns it off uint32_t lineno; - bool generateCode; - std::string savepath; TSymbol *currentsym; std::vector lines; diff --git a/psuedo.cpp b/psuedo.cpp index 6b27881..0cdde64 100644 --- a/psuedo.cpp +++ b/psuedo.cpp @@ -22,12 +22,13 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) int64_t eval_result = 0; uint8_t shift; + uint32_t result32; int res = 0; int err = 0; std::string op = Poco::toUpper(line.opcode); - std::string oper = Poco::toUpper(line.operand); - + std::string oper = Poco::toUpper(line.operand_expr); + result32=0xFFFFFFFF; if (op == "IF") { @@ -40,37 +41,47 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) if (op == "DO") { + a.DOstack.push(a.curDO); + if (oper == "") { err = errIllegalCharOperand; + a.curDO.doskip=false; goto out; } - //line.flags |= FLAG_NOLINEPRINT; - shift = 0; eval_result = 0; - int x = eval.evaluate(line.operand, eval_result, shift); - a.curDO.dooff = (eval_result & 0xFFFFFF); // evaluate here + int x = eval.evaluate(line.operand_expr, eval_result, shift); if (x < 0) { - a.curDO.dooff = false; + a.curDO.doskip = false; err = errBadLabel; if (a.pass == 0) { err = errForwardRef; } + goto out; } - a.DOstack.push(a.curDO); + result32 = eval_result & 0xFFFFFFFF; + a.curDO.doskip = (result32!=0) ? false : true; + goto out; } if (op == "ELSE") { - //line.flags |= FLAG_NOLINEPRINT; - a.curDO.dooff = !a.curDO.dooff; + if (a.DOstack.size() > 0) + { + //line.flags |= FLAG_NOLINEPRINT; + a.curDO.doskip = !a.curDO.doskip; + } + else + { + err = errUnexpectedOp; + } goto out; } @@ -80,20 +91,21 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) if (a.DOstack.size() > 0) { - // kind of a silent error here, just make sure we reinitialize - a.curDO.dooff = false; a.curDO = a.DOstack.top(); a.DOstack.pop(); } else { // kind of a silent error here, just make sure we reinitialize - a.curDO.dooff = false; + err = errUnexpectedOp; + a.curDO.doskip=false; } goto out; } out: + //printf("DO eval: %08X %s\n", result32, a.curDO.doskip ? "true" : "false"); + if (err > 0) { line.setError(err); @@ -124,7 +136,7 @@ int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) shift = 0; eval_result = 0; - int x = eval.evaluate(line.operand, eval_result, shift); + int x = eval.evaluate(line.operand_expr, eval_result, shift); a.LUPstack.push(a.curLUP); @@ -209,7 +221,7 @@ int CLASS::doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) int outct = 0; int wordsize = 2; int endian = 0; - std::string oper = line.operand; + std::string oper = line.operand_expr; std::string op = Poco::toUpper(Poco::trim(line.opcode)); Poco::StringTokenizer tok(oper, ",", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY); @@ -325,16 +337,6 @@ int CLASS::doDS(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) line.datafillbyte = line.eval_result & 0xFF; line.datafillct = v; -#if 0 - if (a.pass > 0) - { - for (int i = 0; i < v; i++) - { - line.outbytes.push_back(0x00); - } - line.outbytect = v; - } -#endif } return (res); @@ -372,7 +374,7 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) std::string s; if (a.pass > 0) { - s = Poco::toUpper(Poco::trim(line.operand)); + s = Poco::toUpper(Poco::trim(line.operand_expr)); if ((s == "") || (s == "ON") || (line.expr_value > 0)) { //printf("ON\n"); @@ -393,7 +395,7 @@ int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) { UNUSED(opinfo); - std::string os = Poco::toUpper(Poco::trim(line.operand)); + std::string os = Poco::toUpper(Poco::trim(line.operand_expr)); uint32_t bytect = 0; uint8_t b = 0; @@ -490,7 +492,7 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) break; case P_ORG: - if (line.operand.length() > 0) + if (line.operand_expr.length() > 0) { a.PC.orgsave = a.PC.currentpc; a.PC.currentpc = line.expr_value; From a6d239f87aeff45442399c848140265777444677 Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 11:14:51 -0800 Subject: [PATCH 02/10] test --- asm.cpp | 9 +++++++-- asm.h | 5 ++++- opcodes.cpp | 2 +- psuedo.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ psuedo.h | 6 +++--- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/asm.cpp b/asm.cpp index 125352f..9d28d19 100644 --- a/asm.cpp +++ b/asm.cpp @@ -208,7 +208,7 @@ void CLASS::print(uint32_t lineno) } uint32_t ct = 1; - if (obc > b) + if ((obc > b) && ((truncdata&0x01)==0)) { ct = 0; uint8_t db; @@ -1293,7 +1293,7 @@ void CLASS::initpass(void) passcomplete = false; dumstartaddr = 0; dumstart = 0; - + truncdata=0; variables.clear(); // clear the variables for each pass while (!PCstack.empty()) @@ -1308,6 +1308,10 @@ void CLASS::initpass(void) { DOstack.pop(); } + while (!LSTstack.empty()) + { + LSTstack.pop(); + } curLUP.clear(); curDO.clear(); savepath = ""; @@ -1622,6 +1626,7 @@ void CLASS::process(void) line.eval_result = 0; line.lineno = lineno + 1; + line.truncdata=truncdata; //printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str()); op = Poco::toLower(line.opcode); diff --git a/asm.h b/asm.h index 1ccab1c..a8f3b7b 100644 --- a/asm.h +++ b/asm.h @@ -189,6 +189,7 @@ public: uint8_t linemx; uint16_t commentcol; bool showmx; + uint8_t truncdata; uint32_t lineno; uint32_t flags; uint16_t opflags; @@ -330,7 +331,6 @@ class T65816Asm : public TFileProcessor public: // options bool casesen; - bool listing; bool showmx; bool trackrep; bool merlincompat; @@ -356,10 +356,13 @@ public: TOriginSection PC; TLUPstruct curLUP; TDOstruct curDO; + bool listing; + uint8_t truncdata; // for the TR opcode std::stack PCstack; std::stack LUPstack; std::stack DOstack; + std::stack LSTstack; TPsuedoOp *psuedoops; diff --git a/opcodes.cpp b/opcodes.cpp index f4f8b20..b1f60a3 100644 --- a/opcodes.cpp +++ b/opcodes.cpp @@ -738,7 +738,7 @@ void CLASS::insertOpcodes(void) pushopcode("PAG", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("TTL", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("SKP", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); - pushopcode("TR", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); + pushopcode("TR", P_TR, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("ASC", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("DCI", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("INV", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); diff --git a/psuedo.cpp b/psuedo.cpp index 0cdde64..ff7f736 100644 --- a/psuedo.cpp +++ b/psuedo.cpp @@ -27,8 +27,8 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) int err = 0; std::string op = Poco::toUpper(line.opcode); - std::string oper = Poco::toUpper(line.operand_expr); - result32=0xFFFFFFFF; + std::string oper = line.operand_expr; + result32 = 0xFFFFFFFF; if (op == "IF") { @@ -46,7 +46,7 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) if (oper == "") { err = errIllegalCharOperand; - a.curDO.doskip=false; + a.curDO.doskip = false; goto out; } @@ -66,7 +66,7 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) } result32 = eval_result & 0xFFFFFFFF; - a.curDO.doskip = (result32!=0) ? false : true; + a.curDO.doskip = (result32 != 0) ? false : true; goto out; } @@ -98,7 +98,7 @@ int CLASS::doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) { // kind of a silent error here, just make sure we reinitialize err = errUnexpectedOp; - a.curDO.doskip=false; + a.curDO.doskip = false; } goto out; } @@ -375,7 +375,15 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) if (a.pass > 0) { s = Poco::toUpper(Poco::trim(line.operand_expr)); - if ((s == "") || (s == "ON") || (line.expr_value > 0)) + if (s == "RTN") + { + if (a.LSTstack.size()) + { + a.listing = a.LSTstack.top(); + a.LSTstack.pop(); + } + } + else if ((s == "ON") || (line.expr_value > 0)) { //printf("ON\n"); a.skiplist = true; @@ -391,6 +399,29 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) return (0); } +int CLASS::doTR(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) +{ + UNUSED(opinfo); + + std::string s; + if (a.pass > 0) + { + s = Poco::toUpper(Poco::trim(line.operand_expr)); + if (s == "ADR") + { + a.truncdata |= 0x03; + } + else if ((s == "ON") || (line.expr_value > 0)) + { + a.truncdata |= 0x01;; + } + else if ((s == "OFF") || (line.expr_value == 0)) + { + a.truncdata = 0x00; + } + } + return (0); +} int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) { UNUSED(opinfo); @@ -523,6 +554,9 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) case P_DO: res = doDO(a, line, opinfo); break; + case P_TR: + res=doTR(a,line,opinfo); + break; } return (res); diff --git a/psuedo.h b/psuedo.h index 00b1613..d59a38f 100644 --- a/psuedo.h +++ b/psuedo.h @@ -17,6 +17,7 @@ enum P_DATA, P_LUP, P_DO, + P_TR, P_MAX }; @@ -33,9 +34,8 @@ public: int doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo); int doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo); int doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo); - int doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);; - - + int doDO(T65816Asm &a, MerlinLine &line, TSymbol &opinfo); + int doTR(T65816Asm &a, MerlinLine &line, TSymbol &opinfo); }; #undef CLASS \ No newline at end of file From 96ae01d615b852658941f5f4c4c40ccf70364af0 Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 17:36:22 -0800 Subject: [PATCH 03/10] test --- CMakeLists.txt | 7 +++++++ ciderpress/diskimg/CMakeLists.txt | 2 ++ ciderpress/diskimg/DDD.cpp | 2 +- ciderpress/diskimg/DOS33.cpp | 2 +- ciderpress/diskimg/Gutenberg.cpp | 12 +++++++----- ciderpress/diskimg/HFS.cpp | 4 ++-- ciderpress/diskimg/Nibble35.cpp | 2 +- ciderpress/diskimg/OzDOS.cpp | 8 ++++---- ciderpress/diskimg/Pascal.cpp | 4 ++-- ciderpress/diskimg/ProDOS.cpp | 4 ++-- ciderpress/diskimg/UNIDOS.cpp | 10 +++++----- ciderpress/diskimg/libhfs/CMakeLists.txt | 2 +- ciderpress/nufxlib/Archive.c | 7 +++++++ qasm.cpp | 1 + 14 files changed, 43 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cbb532..b208ae4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(LIBRARY_NAME pal) set(FIND_LIBRARY_USE_LIB64_PATHS TRUE) include(./lib${LIBRARY_NAME}/cmake/CMakeHeader.txt) + set ( PROJECT_NAME "qasm" ) set(SOURCE @@ -25,20 +26,26 @@ find_package(Poco REQUIRED Foundation Util XML JSON ) include_directories(BEFORE ${PROJECT_ROOT} ${PROJECT_ROOT}/lib${LIBRARY_NAME}/include/${LIBRARY_NAME} + ${PROJECT_ROOT}/ciderpress/diskimg #${OPENSSL_INCLUDE_DIR} ${Poco_INCLUDE_DIRS} ) +add_subdirectory(${PROJECT_ROOT}/ciderpress/nufxlib) +add_subdirectory(${PROJECT_ROOT}/ciderpress/diskimg) + add_subdirectory(${PROJECT_ROOT}/lib${LIBRARY_NAME}) include(${PROJECT_ROOT}/lib${LIBRARY_NAME}/cmake/CMakeApp.txt) add_executable( ${PROJECT_NAME} ${SOURCE}) +#link_directories( ${link_directories} ./build/ciderpress/diskimg target_link_libraries ( ${PROJECT_NAME} ${LIBRARY_NAME} pthread +${PROJECT_ROOT}/ciderpress/diskimg ${Poco_LIBRARIES} ) diff --git a/ciderpress/diskimg/CMakeLists.txt b/ciderpress/diskimg/CMakeLists.txt index eeca5b6..7b4f0d5 100644 --- a/ciderpress/diskimg/CMakeLists.txt +++ b/ciderpress/diskimg/CMakeLists.txt @@ -22,6 +22,8 @@ set(CMAKE_C_FLAGS_RELEASE "${RELEASE_OPT}") set(FIND_LIBRARY_USE_LIB64_PATHS TRUE) +add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/libhfs) + set (SOURCE ASPI.cpp DiskFS.cpp diff --git a/ciderpress/diskimg/DDD.cpp b/ciderpress/diskimg/DDD.cpp index b0c7cb7..c600211 100644 --- a/ciderpress/diskimg/DDD.cpp +++ b/ciderpress/diskimg/DDD.cpp @@ -80,7 +80,7 @@ SST disk. const int kNumSymbols = 256; const int kNumFavorites = 20; const int kRLEDelim = 0x97; // value MUST have high bit set -const int kMaxExcessByteCount = WrapperDDD::kMaxDDDZeroCount + 1; +//const int kMaxExcessByteCount = WrapperDDD::kMaxDDDZeroCount + 1; //const int kTrackLen = 4096; //const int kNumTracks = 35; diff --git a/ciderpress/diskimg/DOS33.cpp b/ciderpress/diskimg/DOS33.cpp index af71f9c..0b61083 100644 --- a/ciderpress/diskimg/DOS33.cpp +++ b/ciderpress/diskimg/DOS33.cpp @@ -20,7 +20,7 @@ * =========================================================================== */ -const int kMaxSectors = 32; +//const int kMaxSectors = 32; const int kSctSize = 256; /* do we need a way to override these? */ diff --git a/ciderpress/diskimg/Gutenberg.cpp b/ciderpress/diskimg/Gutenberg.cpp index 7cc5a5d..7225e66 100644 --- a/ciderpress/diskimg/Gutenberg.cpp +++ b/ciderpress/diskimg/Gutenberg.cpp @@ -64,7 +64,7 @@ header followed by 6502 instructions). There's no apparent link between the value and the type of data in the file. */ -const int kMaxSectors = 32; +//const int kMaxSectors = 32; const int kMaxVolNameLen = 9; const int kSctSize = 256; const int kVTOCTrack = 17; @@ -73,20 +73,22 @@ const int kCatalogEntryOffset = 0x10; // first entry in cat sect starts here const int kCatalogEntrySize = 16; // length in bytes of catalog entries const int kCatalogEntriesPerSect = 15; // #of entries per catalog sector const int kEntryDeleted = 0x40; // this is used to designate deleted files -const int kEntryUnused = 0x00; // this is track# in never-used entries -const int kMaxTSPairs = 0x7a; // 122 entries for 256-byte sectors -const int kTSOffset = 0x0c; // first T/S entry in a T/S list +//const int kEntryUnused = 0x00; // this is track# in never-used entries +//const int kMaxTSPairs = 0x7a; // 122 entries for 256-byte sectors +//const int kTSOffset = 0x0c; // first T/S entry in a T/S list -const int kMaxTSIterations = 32; +//const int kMaxTSIterations = 32; /* * Get a pointer to the Nth entry in a catalog sector. */ +#if 0 static inline uint8_t* GetCatalogEntryPtr(uint8_t* basePtr, int entryNum) { assert(entryNum >= 0 && entryNum < kCatalogEntriesPerSect); return basePtr + kCatalogEntryOffset + entryNum * kCatalogEntrySize; } +#endif /* diff --git a/ciderpress/diskimg/HFS.cpp b/ciderpress/diskimg/HFS.cpp index fb8a7f9..dfd1536 100644 --- a/ciderpress/diskimg/HFS.cpp +++ b/ciderpress/diskimg/HFS.cpp @@ -1771,8 +1771,8 @@ char* A2FileHFS::GetLibHFSPathName(void) const } else if (fileType == 0x04 && auxType == 0x0000) { strcpy(pCreator, "pdos"); strcpy(pType, "TEXT"); - } else if (fileType >= 0 && fileType <= 0xff && - auxType >= 0 && auxType <= 0xffff) + } else if (fileType <= 0xff && + auxType <= 0xffff) { pType[0] = 'p'; pType[1] = (uint8_t) fileType; diff --git a/ciderpress/diskimg/Nibble35.cpp b/ciderpress/diskimg/Nibble35.cpp index a0efeef..67e213d 100644 --- a/ciderpress/diskimg/Nibble35.cpp +++ b/ciderpress/diskimg/Nibble35.cpp @@ -53,7 +53,7 @@ const int kDataChecksumLen = 3; const int kChunkSize35 = 175; // ceil(524 / 3) const int kOffsetToChecksum = 699; const int kNibblizedOutputLen = (kOffsetToChecksum + 4); -const int kMaxDataReach = 48; // should only be 6 bytes */ +//const int kMaxDataReach = 48; // should only be 6 bytes */ enum { kAddrProlog0 = 0xd5, diff --git a/ciderpress/diskimg/OzDOS.cpp b/ciderpress/diskimg/OzDOS.cpp index 9167a40..0bac55d 100644 --- a/ciderpress/diskimg/OzDOS.cpp +++ b/ciderpress/diskimg/OzDOS.cpp @@ -27,12 +27,12 @@ const int kVTOCTrack = 17; const int kVTOCSector = 0; const int kSctSize = 256; -const int kCatalogEntrySize = 0x23; // length in bytes of catalog entries -const int kCatalogEntriesPerSect = 7; // #of entries per catalog sector +//const int kCatalogEntrySize = 0x23; // length in bytes of catalog entries +//const int kCatalogEntriesPerSect = 7; // #of entries per catalog sector const int kMaxTSPairs = 0x7a; // 122 entries for 256-byte sectors -const int kTSOffset = 0x0c; // first T/S entry in a T/S list +//const int kTSOffset = 0x0c; // first T/S entry in a T/S list -const int kMaxTSIterations = 32; +//const int kMaxTSIterations = 32; const int kMaxCatalogIterations = 64; diff --git a/ciderpress/diskimg/Pascal.cpp b/ciderpress/diskimg/Pascal.cpp index 1ebc080..4d615e7 100644 --- a/ciderpress/diskimg/Pascal.cpp +++ b/ciderpress/diskimg/Pascal.cpp @@ -20,7 +20,7 @@ const int kBlkSize = 512; const int kVolHeaderBlock = 2; // first directory block -const int kMaxCatalogIterations = 64; // should be short, linear catalog +//const int kMaxCatalogIterations = 64; // should be short, linear catalog const int kHugeDir = 32; static const char* kInvalidNameChars = "$=?,[#:"; @@ -1506,7 +1506,7 @@ uint32_t A2FilePascal::GetFileType(void) const year = ptm->tm_year; // years since 1900 if (year >= 100) year -= 100; - if (year < 0 || year >= 100) { + if (year >= 100) { LOGW("WHOOPS: got year %u from %d", year, ptm->tm_year); year = 70; } diff --git a/ciderpress/diskimg/ProDOS.cpp b/ciderpress/diskimg/ProDOS.cpp index 2a60d10..02b78d6 100644 --- a/ciderpress/diskimg/ProDOS.cpp +++ b/ciderpress/diskimg/ProDOS.cpp @@ -1975,7 +1975,7 @@ DIError DiskFSProDOS::CreateFile(const CreateParms* pParms, A2File** ppNewFile) */ dirEntryPtr[0x00] = (pParms->storageType << 4) | strlen(upperName); strncpy((char*) &dirEntryPtr[0x01], upperName, A2FileProDOS::kMaxFileName); - if (pParms->fileType >= 0 && pParms->fileType <= 0xff) + if (pParms->fileType <= 0xff) dirEntryPtr[0x10] = (uint8_t) pParms->fileType; else dirEntryPtr[0x10] = 0; // HFS long type? @@ -1996,7 +1996,7 @@ DIError DiskFSProDOS::CreateFile(const CreateParms* pParms, A2File** ppNewFile) PutShortLE(&dirEntryPtr[0x1c], 0); // version, min_version } dirEntryPtr[0x1e] = pParms->access; - if (pParms->auxType >= 0 && pParms->auxType <= 0xffff) + if (pParms->auxType <= 0xffff) PutShortLE(&dirEntryPtr[0x1f], (uint16_t) pParms->auxType); else PutShortLE(&dirEntryPtr[0x1f], 0); diff --git a/ciderpress/diskimg/UNIDOS.cpp b/ciderpress/diskimg/UNIDOS.cpp index f47dd7a..f33144e 100644 --- a/ciderpress/diskimg/UNIDOS.cpp +++ b/ciderpress/diskimg/UNIDOS.cpp @@ -31,13 +31,13 @@ const int kVTOCTrack = 17; const int kVTOCSector = 0; const int kSctSize = 256; -const int kCatalogEntrySize = 0x23; // length in bytes of catalog entries -const int kCatalogEntriesPerSect = 7; // #of entries per catalog sector +//const int kCatalogEntrySize = 0x23; // length in bytes of catalog entries +//const int kCatalogEntriesPerSect = 7; // #of entries per catalog sector const int kMaxTSPairs = 0x7a; // 122 entries for 256-byte sectors -const int kTSOffset = 0x0c; // first T/S entry in a T/S list +//const int kTSOffset = 0x0c; // first T/S entry in a T/S list -const int kMaxTSIterations = 32; -const int kMaxCatalogIterations = 64; +//const int kMaxTSIterations = 32; +//const int kMaxCatalogIterations = 64; /* diff --git a/ciderpress/diskimg/libhfs/CMakeLists.txt b/ciderpress/diskimg/libhfs/CMakeLists.txt index 5a5c63c..185b3e3 100644 --- a/ciderpress/diskimg/libhfs/CMakeLists.txt +++ b/ciderpress/diskimg/libhfs/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_BUILD_TYPE DEBUG) set(BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(PROJECT_NAME diskimg) +set(PROJECT_NAME hfs) set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) project(${PROJECT_NAME}) diff --git a/ciderpress/nufxlib/Archive.c b/ciderpress/nufxlib/Archive.c index 7c97cb3..616573f 100644 --- a/ciderpress/nufxlib/Archive.c +++ b/ciderpress/nufxlib/Archive.c @@ -862,8 +862,15 @@ static NuError Nu_OpenTempFile(UNICHAR* fileNameUNI, FILE** pFp) #else char* result; +#if 1 DBUG(("+++ Using mktemp\n")); result = mktemp(fileNameUNI); +#else + char fbuff[256]; + sprintf(fbuff,"%s%s",fileNameUNI,"XXXXXX"); + result=mkstemp(); +#endif + if (result == NULL) { Nu_ReportError(NU_BLOB, kNuErrNone, "mktemp failed on '%s'", fileNameUNI); diff --git a/qasm.cpp b/qasm.cpp index 22e034d..4f60331 100644 --- a/qasm.cpp +++ b/qasm.cpp @@ -1,5 +1,6 @@ #include "app.h" #include "asm.h" +#include "DiskImg.h" #define CLASS PAL_APPCLASS From 02bdd29e79280341cf4844f851eb83d211697394 Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 18:27:19 -0800 Subject: [PATCH 04/10] test --- CMakeLists.txt | 23 +++++++++++++++++------ qasm.cpp | 10 ++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b208ae4..20ee519 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") project(QAsm) +set(CIDER "0") + set(CMAKE_BUILD_TYPE DEBUG) set(APPVERSION "4.0.9") set(LIBRARY_NAME pal) @@ -21,31 +23,40 @@ set(SOURCE ) #find_package(OpenSSL REQUIRED) -find_package(Poco REQUIRED Foundation Util XML JSON ) +find_package( Poco REQUIRED Foundation Util XML JSON ) +find_package( ZLIB ) include_directories(BEFORE ${PROJECT_ROOT} ${PROJECT_ROOT}/lib${LIBRARY_NAME}/include/${LIBRARY_NAME} - ${PROJECT_ROOT}/ciderpress/diskimg #${OPENSSL_INCLUDE_DIR} ${Poco_INCLUDE_DIRS} ) +include(${PROJECT_ROOT}/lib${LIBRARY_NAME}/cmake/CMakeApp.txt) + +set (CIDERLIBS "" ) +if ( ${CIDER} ) +add_definitions(-DCIDERPRESS) +include_directories(AFTER ${PROJECT_ROOT}/ciderpress/diskimg) add_subdirectory(${PROJECT_ROOT}/ciderpress/nufxlib) add_subdirectory(${PROJECT_ROOT}/ciderpress/diskimg) -add_subdirectory(${PROJECT_ROOT}/lib${LIBRARY_NAME}) +find_library(DISKIMG_LIB libnufx_static.a ${PROJECT_ROOT}/build ) +find_library(HFS_LIB libnufx_static.a ${PROJECT_ROOT}/build ) +find_library(NUFX_LIB libnufx_static.a ${PROJECT_ROOT}/build ) +set (CIDERLIBS diskimg_static hfs_static nufx_static ${ZLIB_LIBRARIES}) +endif ( ${CIDER} ) -include(${PROJECT_ROOT}/lib${LIBRARY_NAME}/cmake/CMakeApp.txt) +add_subdirectory(${PROJECT_ROOT}/lib${LIBRARY_NAME}) add_executable( ${PROJECT_NAME} ${SOURCE}) -#link_directories( ${link_directories} ./build/ciderpress/diskimg target_link_libraries ( ${PROJECT_NAME} ${LIBRARY_NAME} pthread -${PROJECT_ROOT}/ciderpress/diskimg +${CIDERLIBS} ${Poco_LIBRARIES} ) diff --git a/qasm.cpp b/qasm.cpp index 4f60331..958c157 100644 --- a/qasm.cpp +++ b/qasm.cpp @@ -1,6 +1,8 @@ #include "app.h" #include "asm.h" +#ifdef CIDERPRESS #include "DiskImg.h" +#endif #define CLASS PAL_APPCLASS @@ -29,6 +31,14 @@ void CLASS::displayVersion() s = "-debug"; #endif cerr << "quickASM 16++ v" << (std::string)STRINGIFY(APPVERSION) << s << endl; + +#ifdef CIDERPRESS + DiskImgLib::Global::AppInit(); + DiskImgLib::DiskImg prodos; + + DiskImgLib::Global::AppCleanup(); +#endif + } int CLASS::runServerApp(PAL_EVENTMANAGER *em) From 6664a3e10325da77b945e3242d4c5bc674160e4b Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 19:33:22 -0800 Subject: [PATCH 05/10] if/else/fin and some lst work --- asm.cpp | 61 ++++++++++++++++++++++++++++++++++---------------- asm.h | 4 ++-- qasm.ini | 2 +- src/main.s | 2 +- src/testfile.s | 2 +- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/asm.cpp b/asm.cpp index 9d28d19..6794f22 100644 --- a/asm.cpp +++ b/asm.cpp @@ -25,12 +25,12 @@ void CLASS::setError(uint32_t ecode) void CLASS::print(uint32_t lineno) { - int pcol; - uint32_t l, i; - //int commentcol; + uint32_t l, i, savpcol, pcol; + bool commentprinted = false; static bool checked = false; static bool nc1 = false; bool nc = false; + uint8_t commentcol=tabs[2]; uint32_t b = 4; // how many bytes show on the first line @@ -53,7 +53,7 @@ void CLASS::print(uint32_t lineno) if (merlinstyle) { //printf("errorcode=%d\n",errorcode); - printf("%s in line: %d", errStrings[errorcode].c_str(), lineno + 1); + printf("\n%s in line: %d", errStrings[errorcode].c_str(), lineno + 1); if (errorText != "") { printf("%s", errorText.c_str()); @@ -155,6 +155,7 @@ void CLASS::print(uint32_t lineno) pcol += printf("%02X ", addressmode & 0xFF); } + savpcol = pcol; // this is how many bytes are in the side margin pcol = 0; // reset pcol here because this is where source code starts if (empty) @@ -168,15 +169,43 @@ void CLASS::print(uint32_t lineno) pcol += printf(" "); } } - else + //else { - pcol += printf("%s", comment.c_str()); + int comct = 0; + for (uint32_t cc = 0; cc < comment.length(); cc++) + { + pcol += printf("%c", comment[cc]); + comct++; + if ((comment[cc] <= ' ') && (pcol >= (commentcol + savpcol + 10))) + { + printf("\n"); + pcol = 0; + while (pcol < (commentcol + savpcol)) + { + pcol += printf(" "); + } + } + } + //pcol += printf("%s", comment.c_str()); + } + commentprinted = true; } } else { - pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str()); + pcol += printf("%s ",printlable.c_str()); + while (pcol < tabs[0]) + { + pcol += printf(" "); + } + pcol+=printf("%s ",opcode.c_str()); + while (pcol < tabs[1]) + { + pcol += printf(" "); + } + pcol+=printf("%s ",operand.c_str()); + //pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str()); } if ((errorcode > 0) && (!merlinstyle)) { @@ -186,7 +215,7 @@ void CLASS::print(uint32_t lineno) } pcol += printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str()); } - else + else if (!commentprinted) { while (pcol < commentcol) { @@ -208,7 +237,7 @@ void CLASS::print(uint32_t lineno) } uint32_t ct = 1; - if ((obc > b) && ((truncdata&0x01)==0)) + if ((obc > b) && ((truncdata & 0x01) == 0)) { ct = 0; uint8_t db; @@ -261,7 +290,6 @@ void CLASS::clear() operand_expr2 = ""; addrtext = ""; linemx = 0; - commentcol = 40; bytect = 0; opflags = 0; pass0bytect = 0; @@ -1293,7 +1321,7 @@ void CLASS::initpass(void) passcomplete = false; dumstartaddr = 0; dumstart = 0; - truncdata=0; + truncdata = 0; variables.clear(); // clear the variables for each pass while (!PCstack.empty()) @@ -1626,19 +1654,14 @@ void CLASS::process(void) line.eval_result = 0; line.lineno = lineno + 1; - line.truncdata=truncdata; + line.truncdata = truncdata; + memcpy(line.tabs,tabs,sizeof(tabs)); //printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str()); op = Poco::toLower(line.opcode); operand = Poco::toLower(line.operand); line.startpc = PC.currentpc; line.linemx = mx; - uint16_t cc = tabs[2]; - if (cc == 0) - { - cc = 40; - } - line.commentcol = cc; line.bytect = 0; line.showmx = showmx; @@ -1701,7 +1724,7 @@ void CLASS::process(void) if ((x > 0) && (codeSkipped())) // has a psuedo-op turned off code generation? (LUP, IF, etc) { x = 0; - line.outbytect=0; + line.outbytect = 0; } if (x > 0) diff --git a/asm.h b/asm.h index a8f3b7b..475b87f 100644 --- a/asm.h +++ b/asm.h @@ -187,7 +187,7 @@ public: std::string comment; std::string addrtext; uint8_t linemx; - uint16_t commentcol; + uint8_t tabs[16]; bool showmx; uint8_t truncdata; uint32_t lineno; @@ -224,7 +224,7 @@ protected: std::vector filenames; uint8_t syntax; uint64_t starttime; - uint8_t tabs[10]; + uint8_t tabs[16]; uint32_t filecount; // how many files have been read in (because of included files from source public: diff --git a/qasm.ini b/qasm.ini index 0a540a9..a5047e2 100644 --- a/qasm.ini +++ b/qasm.ini @@ -31,7 +31,7 @@ merlincompatible=true symcolumns=3 [reformat] -tabs=12; 18; 30; +tabs=12; 18; 30 ;tabs=0;0;0 diff --git a/src/main.s b/src/main.s index 1b0d1db..ce2e595 100644 --- a/src/main.s +++ b/src/main.s @@ -13,10 +13,10 @@ xc mx %00 + *========================================================== * monitor addresses - TEXT = $FB39 ;Reset text window TABV = $FB5B ;Complete vtab, using contents of 'A' MONBELL = $FBE4 ;random bell noise! diff --git a/src/testfile.s b/src/testfile.s index 4fdb318..6ea6045 100644 --- a/src/testfile.s +++ b/src/testfile.s @@ -308,5 +308,5 @@ startF0 inc expr,x sbcl lexpr,x lst off - sav ./test.bin + sav /tmp/test.bin From 140121f13e5aeccff4195acd4b52f7b01910e95f Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 20:39:09 -0800 Subject: [PATCH 06/10] opcodes working again --- asm.cpp | 8 +++++ asm.h | 2 +- opcodes.cpp | 89 ++++++++++++++++++++++++++++++-------------------- opcodes.h | 3 -- qasm.ini | 2 +- src/testfile.s | 11 ++++--- 6 files changed, 70 insertions(+), 45 deletions(-) delete mode 100644 opcodes.h diff --git a/asm.cpp b/asm.cpp index 6794f22..e6db75c 100644 --- a/asm.cpp +++ b/asm.cpp @@ -1165,6 +1165,10 @@ int CLASS::callOpCode(std::string op, MerlinLine &line) line.flags |= FLAG_FORCELONG; break; } + if (line.expr_value>=0x100) + { + line.flags|=FLAG_FORCEABS; + } auto itr = opcodes.find(Poco::toUpper(op)); @@ -1354,6 +1358,10 @@ void CLASS::complete(void) std::string currentdir = Poco::Path::current(); savepath = processFilename(savepath, currentdir, 0); + if (isDebug()>=1) + { + savepath+="1"; // append this to the end to help with testing against other assemblers + } printf("saving to file: %s\n", savepath.c_str()); std::ofstream f(savepath); diff --git a/asm.h b/asm.h index 475b87f..53d1ded 100644 --- a/asm.h +++ b/asm.h @@ -34,8 +34,8 @@ // these ORd bits specify specific classes of opcodes and subgroups #define OP_STD (0x1000 | OP_CLASS1) #define OP_ASL (0x2000 | OP_CLASS2) -#define OP_STX (0x3000 | OP_CLASS2) #define OP_C0 (0x4000 | OP_CLASS0) +#define OP_STX (0x8000 | OP_ASL|OP_CLASS2) enum asmErrors { diff --git a/opcodes.cpp b/opcodes.cpp index b1f60a3..ba86a8a 100644 --- a/opcodes.cpp +++ b/opcodes.cpp @@ -449,6 +449,7 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) cc = (sym.stype >> 8) & 0x03; amode = 0xFF; + if ((sym.stype & OP_C0) == OP_C0) { uint8_t cc = 0; @@ -540,15 +541,25 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) } if ((opflags & OP_STX) == OP_STX) - //if ((opcode == "STX") || (opcode == "LDX") || (opcode == "DEC") || (opcode == "INC")) { if (m == syn_implied) { err = true; } - if (m == syn_absx) + if (m==syn_imm) { - //err = true; + if ((mx&0x01)==0) + { + bytelen++; + } + } + if ((m == syn_absx) || (m == syn_abs) || (m==syn_absy)) + { + if ((line.flags & FLAG_FORCEABS) || (line.expr_value >= 0x100)) + { + bytelen++; + amode += 2; + } } if (cpumode >= MODE_65C02) { @@ -576,11 +587,25 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) } } } - if (line.flags&FLAG_FORCELONG) + else { - line.setError(errBadAddressMode); + if ((m == syn_absx) || (m==syn_abs)) + { + if ((line.flags & FLAG_FORCEABS) || (line.expr_value >= 0x100)) + { + bytelen++; + amode += 2; + } + } + } - goto out; + + if (line.flags & FLAG_FORCELONG) + { + err = errBadAddressMode; + //line.setError(errBadAddressMode); + } + goto outop; } if (m == syn_imm) @@ -598,16 +623,9 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) else if ((m == syn_abs) || (m == syn_absx) || (m == syn_absy)) { - if (isDebug() > 2) - { - printf("flgs=%08X\n", line.flags); - } - - - if ((((line.flags & FLAG_DP) == 0) && ((line.flags & FLAG_FORCEDP) == 0)) - || (line.flags & FLAG_FORCEABS) - ) + || (line.flags & FLAG_FORCEABS) + ) { bytelen++; if (amode != 6) @@ -648,7 +666,7 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) { if (line.flags & FLAG_FORCELONG) { - bytelen=3; + bytelen = 3; } } @@ -657,6 +675,7 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) } +outop: op |= (amode & 0x07) << 2; op |= cc; @@ -751,11 +770,11 @@ void CLASS::insertOpcodes(void) pushopcode("DFB", P_DATA, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("DB", P_DATA, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("ADR", P_DATA, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); - pushopcode("ADRL",P_DATA, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); + pushopcode("ADRL", P_DATA, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("HEX", P_HEX, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("DS", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("DO", P_DO, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); - pushopcode("ELSE",P_DO, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); + pushopcode("ELSE", P_DO, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("IF", P_DO, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("FIN", P_DO, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); pushopcode("CHK", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); @@ -773,9 +792,9 @@ void CLASS::insertOpcodes(void) pushopcode("<<<", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO)); - pushopcode("ADC", 0x03, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("AND", 0x01, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("ASL", 0x00, OP_ASL|OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("ADC", 0x03, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("AND", 0x01, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("ASL", 0x00, OP_ASL | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("BCC", 0x02, 0, OPHANDLER(&CLASS::doBRANCH)); pushopcode("BLT", 0x02, 0, OPHANDLER(&CLASS::doBRANCH)); pushopcode("BCS", 0x82, 0, OPHANDLER(&CLASS::doBRANCH)); @@ -799,25 +818,25 @@ void CLASS::insertOpcodes(void) pushopcode("COP", 0x02, 1, OPHANDLER(&CLASS::doAddress)); pushopcode("CPX", 0x07, OP_C0 | OP_XY, OPHANDLER(&CLASS::doBase6502)); pushopcode("CPY", 0x06, OP_C0 | OP_XY, OPHANDLER(&CLASS::doBase6502)); - pushopcode("DEC", 0x06, OP_STX | OP_SPECIAL |OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("DEC", 0x06, OP_STX | OP_SPECIAL | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("DEX", 0xCA, OP_XY, OPHANDLER(&CLASS::doBYTE)); pushopcode("DEY", 0x88, OP_XY, OPHANDLER(&CLASS::doBYTE)); - pushopcode("EOR", 0x02, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("INC", 0x07, OP_STX|OP_A | OP_SPECIAL, OPHANDLER(&CLASS::doBase6502)); + pushopcode("EOR", 0x02, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("INC", 0x07, OP_STX | OP_A | OP_SPECIAL, OPHANDLER(&CLASS::doBase6502)); pushopcode("INX", 0xE8, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("INY", 0xC8, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("JML", 0x00, 0, OPHANDLER(&CLASS::doJMP)); pushopcode("JMP", 0x01, 0, OPHANDLER(&CLASS::doJMP)); pushopcode("JSL", 0x02, 0, OPHANDLER(&CLASS::doJMP)); pushopcode("JSR", 0x03, 0, OPHANDLER(&CLASS::doJMP)); - pushopcode("LDA", 0x05, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("LDX", 0x05, OP_STX|OP_XY, OPHANDLER(&CLASS::doBase6502)); - pushopcode("LDY", 0x05, OP_C0|OP_XY, OPHANDLER(&CLASS::doBase6502)); - pushopcode("LSR", 0x02, OP_ASL|OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("LDA", 0x05, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("LDX", 0x05, OP_STX | OP_XY, OPHANDLER(&CLASS::doBase6502)); + pushopcode("LDY", 0x05, OP_C0 | OP_XY, OPHANDLER(&CLASS::doBase6502)); + pushopcode("LSR", 0x02, OP_ASL | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("MVN", 0x00, 0, OPHANDLER(&CLASS::doMVN)); pushopcode("MVP", 0x01, 0, OPHANDLER(&CLASS::doMVN)); pushopcode("NOP", 0xEA, 0, OPHANDLER(&CLASS::doBYTE)); - pushopcode("ORA", 0x00, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("ORA", 0x00, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("PEA", 0xF4, 2, OPHANDLER(&CLASS::doAddress)); pushopcode("PEI", 0xD4, 1, OPHANDLER(&CLASS::doAddress)); pushopcode("PER", 0x62, 2, OPHANDLER(&CLASS::doPER)); @@ -835,20 +854,20 @@ void CLASS::insertOpcodes(void) pushopcode("PLX", 0xFA, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("PLY", 0x7A, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("REP", 0xC2, 1, OPHANDLER(&CLASS::doAddress)); - pushopcode("ROL", 0x01, OP_ASL|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("ROR", 0x03, OP_ASL|OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("ROL", 0x01, OP_ASL | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("ROR", 0x03, OP_ASL | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("RTI", 0x40, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("RTL", 0x6B, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("RTS", 0x60, 0, OPHANDLER(&CLASS::doBYTE)); - pushopcode("SBC", 0x07, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("SBC", 0x07, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); pushopcode("SEC", 0x38, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("SED", 0xF8, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("SEI", 0x78, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("SEP", 0xE2, 1, OPHANDLER(&CLASS::doAddress)); pushopcode("STP", 0xDB, 0, OPHANDLER(&CLASS::doBYTE)); - pushopcode("STA", 0x04, OP_STD|OP_A, OPHANDLER(&CLASS::doBase6502)); - pushopcode("STX", 0x04, OP_STX|OP_XY, OPHANDLER(&CLASS::doBase6502)); - pushopcode("STY", 0x04, OP_C0|OP_XY, OPHANDLER(&CLASS::doBase6502)); + pushopcode("STA", 0x04, OP_STD | OP_A, OPHANDLER(&CLASS::doBase6502)); + pushopcode("STX", 0x04, OP_STX | OP_XY, OPHANDLER(&CLASS::doBase6502)); + pushopcode("STY", 0x04, OP_C0 | OP_XY, OPHANDLER(&CLASS::doBase6502)); pushopcode("STZ", 0x01, OP_A, OPHANDLER(&CLASS::doNoPattern)); pushopcode("TAX", 0xAA, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TAY", 0xA8, 0, OPHANDLER(&CLASS::doBYTE)); diff --git a/opcodes.h b/opcodes.h deleted file mode 100644 index 45dcbb0..0000000 --- a/opcodes.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - - diff --git a/qasm.ini b/qasm.ini index a5047e2..8e64e5e 100644 --- a/qasm.ini +++ b/qasm.ini @@ -4,7 +4,7 @@ logdir=/var/log/mylog logfile=mylog.log [option] -debug=1 +debug=2 nocolor=false ;debug must be an integer. Code can use this as a level diff --git a/src/testfile.s b/src/testfile.s index 6ea6045..3bb6669 100644 --- a/src/testfile.s +++ b/src/testfile.s @@ -8,16 +8,16 @@ MXX = %00 mx MXX org $4000 -dp: = $A5 +dp = $A5 expr = $0405 lexpr = $010203 immed = $123456 neg equ -16 -]var1 = v1234 +//]var1 = v1234 ;lst off -start00: +:start00: brk ;$00 ora (dp,x) cop $BA @@ -219,7 +219,7 @@ startA0 startB0 bcs startB0 lda (dp),y - lda dp,s + lda (dp) lda (dp,s),y ldy dp,x lda dp,x @@ -233,6 +233,7 @@ startB0 lda expr,x ldx expr,y ldal lexpr,x + lst off startC0 cpy #immed @@ -308,5 +309,5 @@ startF0 inc expr,x sbcl lexpr,x lst off - sav /tmp/test.bin + sav ./test.bin From 046335d9db2be3402153d272ac870a6354ddb463 Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 21:03:19 -0800 Subject: [PATCH 07/10] fixed formatter --- asm.cpp | 1 + src/testfile.s | 585 ++++++++++++++++++++++++------------------------- 2 files changed, 293 insertions(+), 293 deletions(-) diff --git a/asm.cpp b/asm.cpp index e6db75c..c4c65e0 100644 --- a/asm.cpp +++ b/asm.cpp @@ -815,6 +815,7 @@ CLASS::~CLASS() } void CLASS::init(void) { + TFileProcessor::init(); std::string s; lines.clear(); diff --git a/src/testfile.s b/src/testfile.s index 3bb6669..5491052 100644 --- a/src/testfile.s +++ b/src/testfile.s @@ -1,313 +1,312 @@ - ;lst off - xc off - xc - xc + ;lst off + xc off + xc + xc -MXX = %00 +MXX = %00 - mx MXX - org $4000 + mx MXX + org $4000 -dp = $A5 -expr = $0405 -lexpr = $010203 -immed = $123456 -neg equ -16 +dp = $A5 +expr = $0405 +lexpr = $010203 +immed = $123456 +neg equ -16 -//]var1 = v1234 +//]var1 = v1234 - ;lst off -:start00: - brk ;$00 - ora (dp,x) - cop $BA - ora $BC,S - tsb dp - ora dp - asl dp - ora [dp] - php - ora #immed - asl - phd - tsb expr - ora expr - asl expr - oral lexpr - ;end + ;lst off +start00: + brk ;$00 + ora (dp,x) + cop $BA + ora $BC,S + tsb dp + ora dp + asl dp + ora [dp] + php + ora #immed + asl + phd + tsb expr + ora expr + asl expr + oral lexpr + ;end -start10 - bpl start10 - ora (dp),y - ora (dp) - ora (dp,s),y - trb dp - ora dp,x - asl dp,x - ora [dp],y - clc - ora expr,y - inc - tcs - trb expr - ora expr,x - asl expr,x - oral lexpr,x +start10 + bpl start10 + ora (dp),y + ora (dp) + ora (dp,s),y + trb dp + ora dp,x + asl dp,x + ora [dp],y + clc + ora expr,y + inc + tcs + trb expr + ora expr,x + asl expr,x + oral lexpr,x -start20 - jsr expr - and (dp,x) - jsl lexpr - and dp,s - bit dp - and dp - rol dp - and [dp] - plp - and #immed - rol - pld - bit expr - and expr - rol expr - andl lexpr +start20 + jsr expr + and (dp,x) + jsl lexpr + and dp,s + bit dp + and dp + rol dp + and [dp] + plp + and #immed + rol + pld + bit expr + and expr + rol expr + andl lexpr -start30 - bmi start30 - and (dp),y - and (dp) - and (dp,s),y - bit dp,x - and dp,x - rol dp,x - and [dp],y - sec - and expr,y - dec - tsc - bit expr,x - and expr,x - rol expr,x - andl lexpr,x +start30 + bmi start30 + and (dp),y + and (dp) + and (dp,s),y + bit dp,x + and dp,x + rol dp,x + and [dp],y + sec + and expr,y + dec + tsc + bit expr,x + and expr,x + rol expr,x + andl lexpr,x -start40 - rti - eor (dp,x) - wdm $01 - eor dp,s - mvp dp,dp+1 - eor dp - lsr dp - eor [dp] - pha - eor #immed - lsr - phk - jmp expr - eor expr - lsr expr - eorl lexpr +start40 + rti + eor (dp,x) + wdm $01 + eor dp,s + mvp dp,dp+1 + eor dp + lsr dp + eor [dp] + pha + eor #immed + lsr + phk + jmp expr + eor expr + lsr expr + eorl lexpr -start50 - bvc start50 - eor (dp),y - eor (dp) - eor (dp,s),y - mvn dp,dp+1 - eor dp,x - lsr dp,x - eor [dp],y - cli - eor expr,y - phy - tcd - jml lexpr - eor expr,x - lsr expr,x - eorl lexpr,x +start50 + bvc start50 + eor (dp),y + eor (dp) + eor (dp,s),y + mvn dp,dp+1 + eor dp,x + lsr dp,x + eor [dp],y + cli + eor expr,y + phy + tcd + jml lexpr + eor expr,x + lsr expr,x + eorl lexpr,x -start60 - rts - adc (dp,x) - per start60 - adc dp,s - stz dp - adc dp - ror dp - adc [dp] - pla - adc #immed - ror - rtl - jmp (expr) - adc expr - ror expr - adcl lexpr +start60 + rts + adc (dp,x) + per start60 + adc dp,s + stz dp + adc dp + ror dp + adc [dp] + pla + adc #immed + ror + rtl + jmp (expr) + adc expr + ror expr + adcl lexpr -start70 - bvs start70 - adc (dp),y - adc (dp) - adc (dp,s),y - stz dp,x - adc dp,x - ror dp,x - adc [dp],y - sei - adc expr,y - ply - tdc - jmp (expr,x) - adc expr,x - ror expr,x - adcl expr,x +start70 + bvs start70 + adc (dp),y + adc (dp) + adc (dp,s),y + stz dp,x + adc dp,x + ror dp,x + adc [dp],y + sei + adc expr,y + ply + tdc + jmp (expr,x) + adc expr,x + ror expr,x + adcl expr,x -start80 - bra start80 - sta (dp,x) - brl start80 - sta dp,s - sty dp - sta dp - stx dp - sta [dp] - dey - bit #immed - txa - phb - sty expr - sta expr - stx expr - stal lexpr +start80 + bra start80 + sta (dp,x) + brl start80 + sta dp,s + sty dp + sta dp + stx dp + sta [dp] + dey + bit #immed + txa + phb + sty expr + sta expr + stx expr + stal lexpr -start90 - bcc start90 - sta (dp),y - sta (dp) - sta (dp,s),y - sty dp,x - sta dp,x - stx dp,y - sta [dp],y - tya - sta expr,y - txs - txy - stz expr - sta expr,x - stz expr,x - stal lexpr,x +start90 + bcc start90 + sta (dp),y + sta (dp) + sta (dp,s),y + sty dp,x + sta dp,x + stx dp,y + sta [dp],y + tya + sta expr,y + txs + txy + stz expr + sta expr,x + stz expr,x + stal lexpr,x -startA0 - ldy #immed - lda (dp,x) - ldx #immed - lda dp,s - ldy dp - lda dp - ldx dp - lda [dp] - tay - lda #immed - tax - plb - ldy expr - lda expr - ldx expr - ldal lexpr +startA0 + ldy #immed + lda (dp,x) + ldx #immed + lda dp,s + ldy dp + lda dp + ldx dp + lda [dp] + tay + lda #immed + tax + plb + ldy expr + lda expr + ldx expr + ldal lexpr -startB0 - bcs startB0 - lda (dp),y - lda (dp) - lda (dp,s),y - ldy dp,x - lda dp,x - ldx dp,y - lda [dp],y - clv - lda expr,y - tsx - tyx - ldy expr,x - lda expr,x - ldx expr,y - ldal lexpr,x - lst off +startB0 + bcs startB0 + lda (dp),y + lda (dp) + lda (dp,s),y + ldy dp,x + lda dp,x + ldx dp,y + lda [dp],y + clv + lda expr,y + tsx + tyx + ldy expr,x + lda expr,x + ldx expr,y + ldal lexpr,x -startC0 - cpy #immed - cmp (dp,x) - rep #$FF - mx MXX - cmp dp,s - cpy dp - cmp dp - dec dp - cmp [dp] - iny - cmp #immed - dex - wai - cpy expr - cmp expr - dec expr - cmpl lexpr +startC0 + cpy #immed + cmp (dp,x) + rep #$FF + mx MXX + cmp dp,s + cpy dp + cmp dp + dec dp + cmp [dp] + iny + cmp #immed + dex + wai + cpy expr + cmp expr + dec expr + cmpl lexpr -startD0 - bne startD0 - cmp (dp),y - cmp (dp) - cmp (dp,s),y - pei dp - cmp dp,x - dec dp,x - cmp [dp],y - cld - cmp expr,y - phx - stp - jml [lexpr] - cmp expr,x - dec expr,x - cmpl lexpr,x +startD0 + bne startD0 + cmp (dp),y + cmp (dp) + cmp (dp,s),y + pei dp + cmp dp,x + dec dp,x + cmp [dp],y + cld + cmp expr,y + phx + stp + jml [lexpr] + cmp expr,x + dec expr,x + cmpl lexpr,x -startE0 - cpx #immed - sbc (dp,x) - sep #$FF - mx MXX - sbc dp,s - cpx dp - sbc dp - inc dp - sbc [dp] - inx - sbc #immed - nop - xba - cpx expr - sbc expr - inc expr - sbcl lexpr +startE0 + cpx #immed + sbc (dp,x) + sep #$FF + mx MXX + sbc dp,s + cpx dp + sbc dp + inc dp + sbc [dp] + inx + sbc #immed + nop + xba + cpx expr + sbc expr + inc expr + sbcl lexpr + +startF0 + beq startF0 + sbc (dp),y + sbc (dp) + sbc (dp,s),y + pea startF0 + sbc dp,x + inc dp,x + sbc [dp],y + sed + sbc expr,y + plx + xce + jsr (expr,x) + sbc expr,x + inc expr,x + sbcl lexpr,x + lst off + sav ./test.bin -startF0 - beq startF0 - sbc (dp),y - sbc (dp) - sbc (dp,s),y - pea startF0 - sbc dp,x - inc dp,x - sbc [dp],y - sed - sbc expr,y - plx - xce - jsr (expr,x) - sbc expr,x - inc expr,x - sbcl lexpr,x - lst off - sav ./test.bin - From 5e2fdd7b78952d96f888beef576472e972d8ca9a Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 21:18:52 -0800 Subject: [PATCH 08/10] debug and release builds in Makefile --- CMakeLists.txt | 2 +- Makefile | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20ee519..69c1a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(QAsm) set(CIDER "0") -set(CMAKE_BUILD_TYPE DEBUG) +#set(CMAKE_BUILD_TYPE DEBUG) set(APPVERSION "4.0.9") set(LIBRARY_NAME pal) set(FIND_LIBRARY_USE_LIB64_PATHS TRUE) diff --git a/Makefile b/Makefile index 26eaecd..2f4db08 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,17 @@ all: -mkdir -p ./build -cd ./build && cmake .. && $(MAKE) $S +release: + -rm -rf ./build + -mkdir -p ./build + -cd ./build && cmake -DCMAKE_BUILD_TYPE=RELEASE .. && $(MAKE) $S + +debug: + -rm -rf ./build + -mkdir -p ./build + -cd ./build && cmake -DCMAKE_BUILD_TYPE=DEBUG .. && $(MAKE) $S + + distclean: rm -rf ./build From 9009f5a222996b359fe2559f3cdf46f40cdcddcb Mon Sep 17 00:00:00 2001 From: marketideas Date: Sat, 16 Nov 2019 22:48:24 -0800 Subject: [PATCH 09/10] test --- CMakeLists.txt | 3 +++ asm.h | 2 +- opcodes.cpp | 42 +++++++++++++++++++++++++++++++++++------- psuedo.cpp | 7 ++++++- qasm.ini | 4 ++-- src/testfile.s | 4 ++-- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69c1a71..4415f58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,10 @@ set(SOURCE #find_package(OpenSSL REQUIRED) find_package( Poco REQUIRED Foundation Util XML JSON ) + +if ( ${CIDER} ) find_package( ZLIB ) +endif ( ${CIDER} ) include_directories(BEFORE ${PROJECT_ROOT} diff --git a/asm.h b/asm.h index 53d1ded..963f5c0 100644 --- a/asm.h +++ b/asm.h @@ -82,7 +82,7 @@ const std::string errStrings[errMAX + 1] = "Bad opcode", "Opcode not available under CPU mode", "Byte output differs between passes", - "Relative branch offset too large", + "Bad branch", "Forward Reference to symbol", "Unable to redefine symbol", "Duplicate Symbol", diff --git a/opcodes.cpp b/opcodes.cpp index ba86a8a..38bddf5 100644 --- a/opcodes.cpp +++ b/opcodes.cpp @@ -416,15 +416,38 @@ int CLASS::doBRANCH(MerlinLine & line, TSymbol & sym) int32_t o32 = (int32_t)(o64 & 0xFFFFFFFF); int32_t offset = o32 - line.startpc - res; - // SGQ should check under/over flows - + bool err = false; + if (res == 2) // short branch + { + if ((offset < -128) || (offset > 127)) + { + err = true; + op=0x00; // merlin does this + } + } + else if (res == 3) // long branch + { + if ((offset < -32768) || (offset > 32767)) + { + err = true; + // for BRL, merlin DOES NOT kill the opcode + //op=0x00; // merlin does this + } + } //printf("offset %d\n", offset); + setOpcode(line, op); for (i = 0; i < (res - 1); i++) { - line.outbytes.push_back(offset >> (i * 8)); + uint8_t v=(offset >> (i*8)); + v=err?0x00:v; + line.outbytes.push_back(v); } line.outbytect = res; + if (err) + { + line.setError(errBadBranch); + } } return (res); } @@ -546,14 +569,14 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) { err = true; } - if (m==syn_imm) + if (m == syn_imm) { - if ((mx&0x01)==0) + if ((mx & 0x01) == 0) { bytelen++; } } - if ((m == syn_absx) || (m == syn_abs) || (m==syn_absy)) + if ((m == syn_absx) || (m == syn_abs) || (m == syn_absy)) { if ((line.flags & FLAG_FORCEABS) || (line.expr_value >= 0x100)) { @@ -589,7 +612,7 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym) } else { - if ((m == syn_absx) || (m==syn_abs)) + if ((m == syn_absx) || (m == syn_abs)) { if ((line.flags & FLAG_FORCEABS) || (line.expr_value >= 0x100)) { @@ -872,11 +895,15 @@ void CLASS::insertOpcodes(void) pushopcode("TAX", 0xAA, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TAY", 0xA8, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TCD", 0x5B, 0, OPHANDLER(&CLASS::doBYTE)); + pushopcode("TAD", 0x5B, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TCS", 0x1B, 0, OPHANDLER(&CLASS::doBYTE)); + pushopcode("TAS", 0x1B, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TDC", 0x7B, 0, OPHANDLER(&CLASS::doBYTE)); + pushopcode("TDA", 0x7B, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TRB", 0x03, OP_A, OPHANDLER(&CLASS::doNoPattern)); pushopcode("TSB", 0x02, OP_A, OPHANDLER(&CLASS::doNoPattern)); pushopcode("TSC", 0x3B, 0, OPHANDLER(&CLASS::doBYTE)); + pushopcode("TSA", 0x3B, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TSX", 0xBA, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TXA", 0x8A, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("TXS", 0x9A, 0, OPHANDLER(&CLASS::doBYTE)); @@ -886,6 +913,7 @@ void CLASS::insertOpcodes(void) pushopcode("WAI", 0xCB, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("WDM", 0x42, 1, OPHANDLER(&CLASS::doAddress)); pushopcode("XBA", 0xEB, 0, OPHANDLER(&CLASS::doBYTE)); + pushopcode("SWA", 0xEB, 0, OPHANDLER(&CLASS::doBYTE)); pushopcode("XCE", 0xFB, 0, OPHANDLER(&CLASS::doBYTE)); } diff --git a/psuedo.cpp b/psuedo.cpp index ff7f736..6e2c07a 100644 --- a/psuedo.cpp +++ b/psuedo.cpp @@ -375,7 +375,12 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo) if (a.pass > 0) { s = Poco::toUpper(Poco::trim(line.operand_expr)); - if (s == "RTN") + if (s=="") + { + a.listing=true; + a.skiplist=true; + } + else if (s == "RTN") { if (a.LSTstack.size()) { diff --git a/qasm.ini b/qasm.ini index 8e64e5e..a0e4d4a 100644 --- a/qasm.ini +++ b/qasm.ini @@ -4,7 +4,7 @@ logdir=/var/log/mylog logfile=mylog.log [option] -debug=2 +debug=1 nocolor=false ;debug must be an integer. Code can use this as a level @@ -21,7 +21,7 @@ path5=dirpath5 [asm] casesen=true -showmx=true +showmx=false lst=true ; can be M6502, M65C02, M65816 cpu=M65816 diff --git a/src/testfile.s b/src/testfile.s index 5491052..c120a8d 100644 --- a/src/testfile.s +++ b/src/testfile.s @@ -14,10 +14,10 @@ lexpr = $010203 immed = $123456 neg equ -16 -//]var1 = v1234 +]var1 = v1234 ;lst off -start00: +start00 brk ;$00 ora (dp,x) cop $BA From 18c6987d347dd0cd483c6fd70bea69dd37f59f3c Mon Sep 17 00:00:00 2001 From: marketideas Date: Sun, 17 Nov 2019 08:02:55 -0800 Subject: [PATCH 10/10] test --- asm.cpp | 151 ++++++++++++++++++++++++++++++++++++++++--------------- asm.h | 1 + eval.cpp | 4 +- 3 files changed, 113 insertions(+), 43 deletions(-) diff --git a/asm.cpp b/asm.cpp index c4c65e0..a0292d4 100644 --- a/asm.cpp +++ b/asm.cpp @@ -30,7 +30,7 @@ void CLASS::print(uint32_t lineno) static bool checked = false; static bool nc1 = false; bool nc = false; - uint8_t commentcol=tabs[2]; + uint8_t commentcol = tabs[2]; uint32_t b = 4; // how many bytes show on the first line @@ -194,17 +194,17 @@ void CLASS::print(uint32_t lineno) } else { - pcol += printf("%s ",printlable.c_str()); + pcol += printf("%s ", printlable.c_str()); while (pcol < tabs[0]) { pcol += printf(" "); } - pcol+=printf("%s ",opcode.c_str()); + pcol += printf("%s ", opcode.c_str()); while (pcol < tabs[1]) { pcol += printf(" "); } - pcol+=printf("%s ",operand.c_str()); + pcol += printf("%s ", operand.c_str()); //pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str()); } if ((errorcode > 0) && (!merlinstyle)) @@ -945,32 +945,69 @@ TSymbol *CLASS::addSymbol(std::string sym, uint32_t val, bool replace) TSymbol *res = NULL; TSymbol *fnd = NULL; - fnd = findSymbol(sym); - - if ((fnd != NULL) && (!replace)) + if (sym.length() > 0) { - return (NULL); // it is a duplicate - } + TSymbol s; + s.name = sym; + s.opcode = 0; + s.namelc = Poco::toLower(sym); + s.stype = 0; + s.value = val; + s.used = false; + s.cb = NULL; + std::pair p(Poco::toUpper(sym), s); - if (fnd != NULL) - { - //printf("replacing symbol: %s %08X\n",sym.c_str(),val); - fnd->value = val; - return (fnd); - } + if (sym[0] == ':') + { + //local symbol + if (currentsym == NULL) + { + goto out; + } + else + { + fnd = findSymbol(sym); + if ((fnd != NULL) && (!replace)) + { + goto out; + } - //printf("addSymbol |%s|\n",sym.c_str()); - TSymbol s; - s.name = sym; - s.opcode = 0; - s.namelc = Poco::toLower(sym); - s.stype = 0; - s.value = val; - s.used = false; - s.cb = NULL; - std::pair p(Poco::toUpper(sym), s); - symbols.insert(p); - res = findSymbol(sym); + if (fnd != NULL) + { + fnd->value = val; + res = fnd; + goto out; + } + if (currentsym != NULL) + { + currentsym->locals.insert(p); + } + res = findSymbol(sym); + goto out; + } + } + else + { + fnd = findSymbol(sym); + + if ((fnd != NULL) && (!replace)) + { + goto out; + } + + if (fnd != NULL) + { + //printf("replacing symbol: %s %08X\n",sym.c_str(),val); + fnd->value = val; + res = fnd; + goto out; + } + + symbols.insert(p); + res = findSymbol(sym); + } + } +out: return (res); } @@ -978,15 +1015,37 @@ TSymbol *CLASS::findSymbol(std::string symname) { TSymbol *res = NULL; - //printf("finding: %s\n",symname.c_str()); - auto itr = symbols.find(Poco::toUpper(symname)); - if (itr != symbols.end()) + if (symname.length() > 0) { - //printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value); - res = &itr->second; - - return (res); + if (symname[0] == ':') + { + if (currentsym == NULL) + { + goto out; + } + else + { + auto itr = currentsym->locals.find(Poco::toUpper(symname)); + if (itr != currentsym->locals.end()) + { + res = &itr->second; + goto out; + } + } + } + else + { + //printf("finding: %s\n",symname.c_str()); + auto itr = symbols.find(Poco::toUpper(symname)); + if (itr != symbols.end()) + { + //printf("Found: %s 0x%08X\n",itr->second.name.c_str(),itr->second.value); + res = &itr->second; + goto out; + } + } } +out: return (res); } @@ -1166,9 +1225,9 @@ int CLASS::callOpCode(std::string op, MerlinLine &line) line.flags |= FLAG_FORCELONG; break; } - if (line.expr_value>=0x100) + if (line.expr_value >= 0x100) { - line.flags|=FLAG_FORCEABS; + line.flags |= FLAG_FORCEABS; } @@ -1321,6 +1380,7 @@ void CLASS::initpass(void) } relocatable = false; currentsym = NULL; + currentsymstr=""; lineno = 0; errorct = 0; passcomplete = false; @@ -1359,9 +1419,9 @@ void CLASS::complete(void) std::string currentdir = Poco::Path::current(); savepath = processFilename(savepath, currentdir, 0); - if (isDebug()>=1) + if (isDebug() >= 1) { - savepath+="1"; // append this to the end to help with testing against other assemblers + savepath += "1"; // append this to the end to help with testing against other assemblers } printf("saving to file: %s\n", savepath.c_str()); @@ -1664,7 +1724,7 @@ void CLASS::process(void) line.eval_result = 0; line.lineno = lineno + 1; line.truncdata = truncdata; - memcpy(line.tabs,tabs,sizeof(tabs)); + memcpy(line.tabs, tabs, sizeof(tabs)); //printf("lineno: %d %d |%s|\n",lineno,l,line.operand.c_str()); op = Poco::toLower(line.opcode); @@ -1688,13 +1748,22 @@ void CLASS::process(void) sym = addVariable(line.lable, ls, true); if (sym == NULL) { dupsym = true; } break; + case ':': - break; default: if (pass == 0) { sym = addSymbol(line.lable, PC.currentpc, false); - if (sym == NULL) { dupsym = true; } + if (sym == NULL) + { + dupsym = true; + line.setError(errDupSymbol); + } + } + if (c != ':') + { + currentsym = findSymbol(line.lable); + currentsymstr=line.lable; } break; } diff --git a/asm.h b/asm.h index 963f5c0..6d6225b 100644 --- a/asm.h +++ b/asm.h @@ -347,6 +347,7 @@ public: std::string savepath; TSymbol *currentsym; + std::string currentsymstr; std::vector lines; Poco::HashMapopcodes; Poco::HashMap macros; diff --git a/eval.cpp b/eval.cpp index 2f9fd69..8b1d461 100644 --- a/eval.cpp +++ b/eval.cpp @@ -225,9 +225,9 @@ std::deque CLASS::shuntingYard(const std::deque& tokens) } else { - //printf("symbol find |%s|\n",token.str.c_str()); - sym = assembler.findSymbol(token.str); + //printf("symbol find |%s| %p\n",token.str.c_str(),sym); + if (sym != NULL) { sym->used = true;