diff --git a/asm.cpp b/asm.cpp index 307cf1c..71b7c50 100644 --- a/asm.cpp +++ b/asm.cpp @@ -416,9 +416,9 @@ void CLASS::set(std::string line) restofline = Poco::trim(tline.substr(i, tline.length())) + " "; //printf("ROL: |%s|\n",restofline.c_str()); - if (restofline=="") + if (restofline == "") { - i=l; + i = l; break; } strs.clear(); @@ -493,15 +493,16 @@ void CLASS::set(std::string line) x = lable.length(); if (x > 1) { - // SGQ M32 syntax -#if 1 - while ((x > 1) && (lable[x - 1] == ':')) + // M32 syntax allows a colon after lable, and it is not part of the lable + if ((syntax & SYNTAX_MERLIN32)==SYNTAX_MERLIN32) { - lable = lable.substr(0, x - 1); - x--; + while ((x > 1) && (lable[x - 1] == ':')) + { + lable = lable.substr(0, x - 1); + x--; + } + //printf("linelable: |%s|\n", lable.c_str()); } - //printf("linelable: |%s|\n", lable.c_str()); -#endif } opcodelower = Poco::toLower(opcode); @@ -532,9 +533,24 @@ void CLASS::init(void) filenames.clear(); starttime = GetTickCount(); initialdir = Poco::Path::current(); - syntax = 0; + 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; + } + std::string tabstr = getConfig("reformat.tabs", "8,16,32"); tabstr = Poco::trim(tabstr); @@ -1422,6 +1438,21 @@ void CLASS::initpass(void) merlinerrors = getBool("asm.merlinerrors", true); trackrep = getBool("asm.trackrep", false); + if (syntax == SYNTAX_MERLIN32) + { + trackrep = true; // can't turn this off in M32 + } + else if (syntax == SYNTAX_MERLIN) + { + trackrep = false; // can't turn this ON in M16 + } + else if (syntax == SYNTAX_QASM) + { + // we will allow this to be settable default off + trackrep = false; + trackrep = getBool("asm.trackrep", trackrep); + + } //merlincompat = getBool("asm.merlincompatible", true); allowdup = getBool("asm.allowduplicate", true); @@ -1464,7 +1495,12 @@ void CLASS::initpass(void) lastcarry = false; relocatable = false; - currentsym = &topSymbol; // this is the default symbol for :locals without a global above; + currentsym = NULL; + if ((syntax & SYNTAX_MERLIN32)==SYNTAX_MERLIN32) + { + // M32 allows locals that don't have a global above. this is the catchall for that + currentsym = &topSymbol; // this is the default symbol for :locals without a global above; + } currentsymstr = ""; lineno = 0; errorct = 0; @@ -1668,18 +1704,17 @@ int CLASS::getAddrMode(MerlinLine & line) // symbol is defined later, we will generate different // bytes on the next pass - if (Poco::toUpper(oper) == "A") // check the whole operand, not just the expression + if ((line.syntax&SYNTAX_MERLIN32) == SYNTAX_MERLIN32) { - // SGQ - // Merlin32 supports the 'A" operand for immediate - // mode for opcodes like "ROR A". Problem is, Merlin16 - // does not, and 'A' could be a lable. - TSymbol *sym = findSymbol("A"); - if (sym == NULL) + if (Poco::toUpper(oper) == "A") // check the whole operand, not just the expression { - line.flags |= FLAG_FORCEIMPLIED; - mode = syn_implied; // if the label hasn't been defined yet, assume Immediate addressing - goto out; + TSymbol *sym = findSymbol("A"); + if (sym == NULL) + { + line.flags |= FLAG_FORCEIMPLIED; + mode = syn_implied; // if the label hasn't been defined yet, assume Immediate addressing + goto out; + } } } } @@ -1861,6 +1896,7 @@ void CLASS::process(void) line.linemx = mx; line.bytect = 0; line.showmx = showmx; + line.syntax = syntax; line.merlinerrors = merlinerrors; if ((line.lable != "")) diff --git a/asm.h b/asm.h index d4ffb6c..b6ed183 100644 --- a/asm.h +++ b/asm.h @@ -8,8 +8,17 @@ #define MODE_65816 2 #define SYNTAX_MERLIN 0 -#define SYNTAX_APW 1 -#define SYNTAX_ORCA 2 +#define SYNTAX_MERLIN32 0x01 +#define SYNTAX_APW 0x02 +#define SYNTAX_ORCA 0x04 +#define SYNTAX_QASM (0x08 | SYNTAX_MERLIN32) +#define OPTION_ALLOW_A_OPERAND 0x0100 +#define OPTION_ALLOW_LOCAL 0x0200 +#define OPTION_ALLOW_COLON 0x0400 +#define OPTION_FORCE_REPSEP 0x0800 +#define OPTION_NO_REPSEP 0x1000 +#define OPTION_CFG_REPSEP 0x2000 + #define FLAG_FORCELONG 0x01 #define FLAG_FORCEABS 0x02 @@ -177,7 +186,7 @@ class MerlinLine { public: - uint8_t syntax; + uint32_t syntax; std::string lable; std::string printlable; std::string opcode; @@ -224,7 +233,7 @@ class TFileProcessor protected: std::string initialdir; std::vector filenames; - uint8_t syntax; + uint32_t syntax; uint64_t starttime; uint8_t tabs[16]; @@ -335,7 +344,6 @@ public: bool casesen; bool showmx; bool trackrep; - //bool merlincompat; bool merlinerrors; bool allowdup; uint8_t mx; diff --git a/qasm.cpp b/qasm.cpp index 8c06b3f..c065ecd 100644 --- a/qasm.cpp +++ b/qasm.cpp @@ -18,9 +18,11 @@ programOption PAL::appOptions[] = #ifdef DEBUG { "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] default=asm", " ", false, false}, - { "objfile", "o", "write output to file", " ", false, false}, + //{ "config", "f", "load configuration data from a ", "", false, false}, + { "exec", "x", "execute a command [asm, link, reformat] default=asm", "", false, false}, + { "objfile", "o", "write output to file", "", false, false}, + { "syntax", "s", "enforce syntax of other assembler [merlin16, merlin32]", "", false, false}, + { "", "", "", "", false, false} }; diff --git a/qasm.ini b/qasm.ini index 9ba320a..9769696 100644 --- a/qasm.ini +++ b/qasm.ini @@ -6,7 +6,7 @@ logfile=mylog.log [option] debug=1 nocolor=false -syntax=merlin +;syntax=merlin32 ;debug must be an integer. Code can use this as a level [application] @@ -27,7 +27,7 @@ startmx=3 lst=true ; can be M6502, M65C02, M65816 cpu=M65816 -trackrep=false +trackrep=true allowduplicate=true merlinerrors=true symcolumns=3 diff --git a/runtests.sh b/runtests.sh index 8cbb574..6e4ae83 100755 --- a/runtests.sh +++ b/runtests.sh @@ -29,7 +29,7 @@ for S in $SRC ; do BASE=${BASE/.s/} #./qasm -o 0/$OUTDIR/$S1 ./testdata/$S - ./qasm -o 0/$OUTDIR/$S1 ./testdata/$S >> $TMPFILE + ./qasm --syntax merlin32 -o 0/$OUTDIR/$S1 ./testdata/$S >> $TMPFILE R=?$ #echo $S " " $S1