mirror of
https://github.com/marketideas/qasm.git
synced 2024-06-02 08:41:27 +00:00
might be broken, work on addressing modes and shift operators < > | ^
This commit is contained in:
parent
88e0251a16
commit
4380f4e8ca
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
@ -9,8 +9,8 @@
|
||||||
"program": "${workspaceFolder}/build/qasm",
|
"program": "${workspaceFolder}/build/qasm",
|
||||||
"args": [
|
"args": [
|
||||||
"${workspaceFolder}/test.s",
|
"${workspaceFolder}/test.s",
|
||||||
"-s",
|
"-d",
|
||||||
"-d"
|
"-l"
|
||||||
],
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
|
|
202
asm.cpp
202
asm.cpp
|
@ -11,12 +11,12 @@
|
||||||
#define CLASS MerlinLine
|
#define CLASS MerlinLine
|
||||||
|
|
||||||
|
|
||||||
CLASS::CLASS(ConfigOptions &opt) //: options(opt)
|
CLASS::CLASS(ConfigOptions &opt) : options(&opt)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CLASS::CLASS(std::string line, ConfigOptions &opt) //: options(opt)
|
CLASS::CLASS(std::string line, ConfigOptions &opt) : options(&opt)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
set(line);
|
set(line);
|
||||||
|
@ -68,11 +68,17 @@ void CLASS::print(uint32_t lineno)
|
||||||
|
|
||||||
bool np=(flags & FLAG_NOLINEPRINT)?true:false;
|
bool np=(flags & FLAG_NOLINEPRINT)?true:false;
|
||||||
if (options->isQuiet())
|
if (options->isQuiet())
|
||||||
|
{
|
||||||
np=true;
|
np=true;
|
||||||
|
}
|
||||||
if (options->isList())
|
if (options->isList())
|
||||||
|
{
|
||||||
np=false;
|
np=false;
|
||||||
|
}
|
||||||
if (force)
|
if (force)
|
||||||
|
{
|
||||||
np=false;
|
np=false;
|
||||||
|
}
|
||||||
if (np)
|
if (np)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -221,6 +227,8 @@ void CLASS::print(uint32_t lineno)
|
||||||
}
|
}
|
||||||
//pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
//pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
||||||
}
|
}
|
||||||
|
//printf("merlinerrors=%d\n",merlinerrors);
|
||||||
|
//merlinerrors=false;
|
||||||
if ((errorcode > 0) && (!merlinerrors))
|
if ((errorcode > 0) && (!merlinerrors))
|
||||||
{
|
{
|
||||||
while (pcol < commentcol)
|
while (pcol < commentcol)
|
||||||
|
@ -245,7 +253,7 @@ void CLASS::print(uint32_t lineno)
|
||||||
|
|
||||||
if ((options->useColor()) && (errorcode > 0))
|
if ((options->useColor()) && (errorcode > 0))
|
||||||
{
|
{
|
||||||
SetColor(CL_NORMAL | BG_NORMAL);
|
SetColor(CL_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t obc = datafillct;
|
uint32_t obc = datafillct;
|
||||||
|
@ -297,6 +305,7 @@ void CLASS::print(uint32_t lineno)
|
||||||
|
|
||||||
void CLASS::clear()
|
void CLASS::clear()
|
||||||
{
|
{
|
||||||
|
shiftchar=0;
|
||||||
wholetext = "";
|
wholetext = "";
|
||||||
lable = "";
|
lable = "";
|
||||||
printlable = "";
|
printlable = "";
|
||||||
|
@ -305,6 +314,7 @@ void CLASS::clear()
|
||||||
operand = "";
|
operand = "";
|
||||||
printoperand = "";
|
printoperand = "";
|
||||||
orig_operand="";
|
orig_operand="";
|
||||||
|
strippedoperand="";
|
||||||
comment = "";
|
comment = "";
|
||||||
operand_expr = "";
|
operand_expr = "";
|
||||||
operand_expr2 = "";
|
operand_expr2 = "";
|
||||||
|
@ -317,16 +327,15 @@ void CLASS::clear()
|
||||||
startpc = 0;
|
startpc = 0;
|
||||||
errorcode = 0;
|
errorcode = 0;
|
||||||
errorText = "";
|
errorText = "";
|
||||||
outbytect = 0;
|
|
||||||
datafillct = 0;
|
datafillct = 0;
|
||||||
datafillbyte = 0;
|
datafillbyte = 0;
|
||||||
lineno = 0;
|
lineno = 0;
|
||||||
outbytes.clear();
|
|
||||||
addressmode = 0;
|
addressmode = 0;
|
||||||
expr_value = 0;
|
expr_value = 0;
|
||||||
eval_result = 0;
|
eval_result = 0;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
outbytes.clear();
|
outbytes.clear();
|
||||||
|
outbytect = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string operEx[] =
|
std::string operEx[] =
|
||||||
|
@ -556,9 +565,9 @@ CLASS::~CLASS()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLASS::setLanguage(string lang)
|
void CLASS::setLanguage(string lang,bool force)
|
||||||
{
|
{
|
||||||
options.setLanguage(lang);
|
options.setLanguage(lang,force);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLASS::errorOut(uint16_t code)
|
void CLASS::errorOut(uint16_t code)
|
||||||
|
@ -614,7 +623,7 @@ void CLASS::complete(void)
|
||||||
//cout << "Processing Time: " << n - starttime << "ms" << endl;
|
//cout << "Processing Time: " << n - starttime << "ms" << endl;
|
||||||
uint64_t x = n - starttime;
|
uint64_t x = n - starttime;
|
||||||
uint32_t x1 = x & 0xFFFFFFFF;
|
uint32_t x1 = x & 0xFFFFFFFF;
|
||||||
if ((!getBool("option.quiet",false)) && (isDebug()>0))
|
//if ((!getBool("option.quiet",false)) && (isDebug()>0))
|
||||||
{
|
{
|
||||||
printf("Elapsed time: %u ms\n", x1);
|
printf("Elapsed time: %u ms\n", x1);
|
||||||
}
|
}
|
||||||
|
@ -1639,7 +1648,7 @@ int CLASS::callOpCode(std::string op, MerlinLine &line)
|
||||||
break;
|
break;
|
||||||
case '>':
|
case '>':
|
||||||
#if 0
|
#if 0
|
||||||
if ((syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
if (options.isMerlin32())
|
||||||
{
|
{
|
||||||
// bug in M32 or not, do what it does
|
// bug in M32 or not, do what it does
|
||||||
line.flags |= FLAG_FORCEABS;
|
line.flags |= FLAG_FORCEABS;
|
||||||
|
@ -1768,16 +1777,17 @@ void CLASS::initpass(void)
|
||||||
showmx = getBool("asm.showmx", true);
|
showmx = getBool("asm.showmx", true);
|
||||||
merlinerrors = getBool("asm.merlinerrors", true);
|
merlinerrors = getBool("asm.merlinerrors", true);
|
||||||
|
|
||||||
|
outputbytes.clear();
|
||||||
trackrep = getBool("asm.trackrep", false);
|
trackrep = getBool("asm.trackrep", false);
|
||||||
if (syntax == SYNTAX_MERLIN32)
|
if (options.isMerlin32())
|
||||||
{
|
{
|
||||||
trackrep = true; // can't turn this off in M32
|
trackrep = true; // can't turn this off in M32
|
||||||
}
|
}
|
||||||
else if (syntax == SYNTAX_MERLIN)
|
else if (options.isMerlin())
|
||||||
{
|
{
|
||||||
trackrep = false; // can't turn this ON in M16
|
trackrep = false; // can't turn this ON in M16
|
||||||
}
|
}
|
||||||
else if (syntax == SYNTAX_QASM)
|
else if (options.isQASM())
|
||||||
{
|
{
|
||||||
// we will allow this to be settable default off
|
// we will allow this to be settable default off
|
||||||
trackrep = false;
|
trackrep = false;
|
||||||
|
@ -1797,6 +1807,10 @@ void CLASS::initpass(void)
|
||||||
s = getConfig("asm.cpu", "M6502");
|
s = getConfig("asm.cpu", "M6502");
|
||||||
s = Poco::trim(Poco::toUpper(s));
|
s = Poco::trim(Poco::toUpper(s));
|
||||||
|
|
||||||
|
s=PAL::getString("option.instruction","");
|
||||||
|
if (s!="")
|
||||||
|
{
|
||||||
|
printf("CPU command line %s\n",s.c_str());
|
||||||
cpumode = MODE_65816;
|
cpumode = MODE_65816;
|
||||||
mx = 0x03;
|
mx = 0x03;
|
||||||
|
|
||||||
|
@ -1820,6 +1834,7 @@ void CLASS::initpass(void)
|
||||||
printf("Unknown CPU type in .ini\n");
|
printf("Unknown CPU type in .ini\n");
|
||||||
mx = 0x03;
|
mx = 0x03;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mx = getInt("asm.startmx", mx);;
|
mx = getInt("asm.startmx", mx);;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1829,7 +1844,7 @@ void CLASS::initpass(void)
|
||||||
lastcarry = false;
|
lastcarry = false;
|
||||||
relocatable = false;
|
relocatable = false;
|
||||||
currentsym = NULL;
|
currentsym = NULL;
|
||||||
if ((syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
if (options.isMerlin32())
|
||||||
{
|
{
|
||||||
// M32 allows locals that don't have a global above. this is the catchall for that
|
// 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;
|
currentsym = &topSymbol; // this is the default symbol for :locals without a global above;
|
||||||
|
@ -1875,20 +1890,25 @@ void CLASS::initpass(void)
|
||||||
|
|
||||||
void CLASS::complete(void)
|
void CLASS::complete(void)
|
||||||
{
|
{
|
||||||
|
bool writeerr=false;
|
||||||
if (savepath != "")
|
if (savepath != "")
|
||||||
{
|
{
|
||||||
if (errorct == 0)
|
if (errorct == 0)
|
||||||
{
|
{
|
||||||
std::string currentdir = Poco::Path::current();
|
std::string currentdir = Poco::Path::current();
|
||||||
|
|
||||||
savepath = processFilename(savepath, currentdir, 0);
|
//savepath = processFilename(savepath, currentdir, 0);
|
||||||
|
savepath=options.formatPath(savepath);
|
||||||
if (!options.isQuiet())
|
if (!options.isQuiet())
|
||||||
{
|
{
|
||||||
printf("saving to file: %s\n", savepath.c_str());
|
printf("saving to file: %s\n", savepath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ofstream f(savepath);
|
std::ofstream f(savepath, std::ios::out|std::ios::trunc);
|
||||||
|
|
||||||
|
if (f.is_open())
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
uint32_t lineno = 0;
|
uint32_t lineno = 0;
|
||||||
uint32_t l = (uint32_t)lines.size();
|
uint32_t l = (uint32_t)lines.size();
|
||||||
while (lineno < l)
|
while (lineno < l)
|
||||||
|
@ -1910,11 +1930,36 @@ void CLASS::complete(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
for (unsigned int i=0; i<outputbytes.size(); i++)
|
||||||
|
{
|
||||||
|
f.put(outputbytes[i]);
|
||||||
|
}
|
||||||
|
f.flush();
|
||||||
|
//printf("outbytect=%ld\n",outputbytes.size());
|
||||||
|
|
||||||
|
if (f.fail())
|
||||||
|
{
|
||||||
|
writeerr=true;
|
||||||
|
}
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
writeerr=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("\nErrors in assembly. Output not SAVED.\n\n");
|
printf("\nErrors in assembly. Output not SAVED.\n\n");
|
||||||
}
|
}
|
||||||
|
if (writeerr)
|
||||||
|
{
|
||||||
|
printf("unable to save file.\n"); // TODO SGQ need to push error up the so exit code is non-zero
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((!options.isQuiet()) || (options.isList()))
|
if ((!options.isQuiet()) || (options.isList()))
|
||||||
{
|
{
|
||||||
|
@ -2001,12 +2046,77 @@ int CLASS::getAddrMode(MerlinLine & line)
|
||||||
int idx, x;
|
int idx, x;
|
||||||
std::string s, oper;
|
std::string s, oper;
|
||||||
std::vector<std::string> groups;
|
std::vector<std::string> groups;
|
||||||
|
char shiftchar;
|
||||||
|
|
||||||
oper = line.operand;
|
oper = line.operand;
|
||||||
|
int l=oper.length();
|
||||||
if ((line.opcode.length() == 0) || (line.operand.length() == 0))
|
if ((line.opcode.length() == 0) || (l <= 0))
|
||||||
{
|
{
|
||||||
return (syn_implied);
|
return (syn_none);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool supportbar=false;
|
||||||
|
bool modified=false;
|
||||||
|
|
||||||
|
shiftchar=oper[0];
|
||||||
|
if (shiftchar=='#')
|
||||||
|
{
|
||||||
|
shiftchar=0;
|
||||||
|
if (l>1)
|
||||||
|
{
|
||||||
|
shiftchar=oper[1];
|
||||||
|
|
||||||
|
//oper=oper.substr(1);
|
||||||
|
//oper="#"+oper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shiftchar=='^')
|
||||||
|
{
|
||||||
|
if (options.isMerlin())
|
||||||
|
{
|
||||||
|
return(syn_err);
|
||||||
|
//shiftchar=0x00; // merlin8 does not support the bank addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shiftchar=='|')
|
||||||
|
{
|
||||||
|
if (options.isMerlinCompat())
|
||||||
|
{
|
||||||
|
if ((options.isMerlin() || options.isMerlin16())) // merlin8 and merlin16 do not support the bar
|
||||||
|
{
|
||||||
|
return(syn_err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
supportbar=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((shiftchar=='^') || (shiftchar=='<') || (shiftchar=='>') || (supportbar && shiftchar=='|'))
|
||||||
|
{
|
||||||
|
modified=true;
|
||||||
|
}
|
||||||
|
if (supportbar)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
if (modified)
|
||||||
|
{
|
||||||
|
line.shiftchar=shiftchar;
|
||||||
|
if (oper[0]=='#')
|
||||||
|
{
|
||||||
|
oper=oper.substr(2);
|
||||||
|
oper="#"+oper;
|
||||||
|
l=oper.length();
|
||||||
|
}
|
||||||
|
else if (shiftchar!=0)
|
||||||
|
{
|
||||||
|
oper=oper.substr(1);
|
||||||
|
l=oper.length();
|
||||||
|
}
|
||||||
|
printf("old: |%s| new: |%s|\n",line.operand.c_str(),oper.c_str());
|
||||||
|
line.strippedoperand=oper;
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
@ -2136,6 +2246,32 @@ int CLASS::parseOperand(MerlinLine & line)
|
||||||
{
|
{
|
||||||
//errorOut(errBadAddressMode);
|
//errorOut(errBadAddressMode);
|
||||||
}
|
}
|
||||||
|
printf("addressmode=%d %s\n",res,addrModeEnglish(res).c_str());
|
||||||
|
return (res);
|
||||||
|
}
|
||||||
|
|
||||||
|
string CLASS::addrModeEnglish(int mode)
|
||||||
|
{
|
||||||
|
string res="<none>";
|
||||||
|
switch(mode)
|
||||||
|
{
|
||||||
|
case syn_err: res="addrmode_error";break;
|
||||||
|
case syn_none: res="addrmode_none";break;
|
||||||
|
case syn_implied: res="implied";break;
|
||||||
|
case syn_s: res="dp,s";break;
|
||||||
|
case syn_sy: res="(dp,s),y";break;
|
||||||
|
case syn_imm: res="#immediate";break;
|
||||||
|
case syn_diix: res="(dp,x)";break;
|
||||||
|
case syn_diiy: res="(dp),y";break;
|
||||||
|
case syn_di: res="(dp)";break;
|
||||||
|
case syn_iyl: res="[expr],y";break;
|
||||||
|
case syn_dil: res="[expr]";break;
|
||||||
|
case syn_absx: res="abs,x";break;
|
||||||
|
case syn_absy: res="abs,y";break;
|
||||||
|
case syn_bm: res="block move";break;
|
||||||
|
case syn_abs: res="absolute";break;
|
||||||
|
default: res="addr_mode bad";break;
|
||||||
|
}
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2580,6 +2716,24 @@ void CLASS::process(void)
|
||||||
line.errorText = line.operand_expr;
|
line.errorText = line.operand_expr;
|
||||||
}
|
}
|
||||||
line.bytect = x;
|
line.bytect = x;
|
||||||
|
if (pass>0)
|
||||||
|
{
|
||||||
|
if ((line.flags & FLAG_INDUM) == 0) // don't write bytes if inside DUM section
|
||||||
|
{
|
||||||
|
for (unsigned int i=0; i<line.outbytes.size(); i++)
|
||||||
|
{
|
||||||
|
outputbytes.push_back(line.outbytes[i]);
|
||||||
|
}
|
||||||
|
if (line.datafillct>0)
|
||||||
|
{
|
||||||
|
for (int i=0; i<line.datafillct; i++)
|
||||||
|
{
|
||||||
|
outputbytes.push_back(line.datafillbyte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PC.currentpc += x;
|
PC.currentpc += x;
|
||||||
PC.totalbytes += x;
|
PC.totalbytes += x;
|
||||||
}
|
}
|
||||||
|
@ -2623,6 +2777,9 @@ void CLASS::process(void)
|
||||||
line.print(lineno);
|
line.print(lineno);
|
||||||
}
|
}
|
||||||
skiplist = false;
|
skiplist = false;
|
||||||
|
line.outbytes.clear(); // clear the outbytes on the line so LUP works correctly
|
||||||
|
line.outbytect=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
}
|
}
|
||||||
|
@ -2654,15 +2811,6 @@ int CLASS::doline(int lineno, std::string line)
|
||||||
MerlinLine l(line,options);
|
MerlinLine l(line,options);
|
||||||
|
|
||||||
op = Poco::toLower(l.opcode);
|
op = Poco::toLower(l.opcode);
|
||||||
if (op == "merlin")
|
|
||||||
{
|
|
||||||
syntax = SYNTAX_MERLIN;
|
|
||||||
}
|
|
||||||
else if (op == "orca")
|
|
||||||
{
|
|
||||||
syntax = SYNTAX_ORCA;
|
|
||||||
}
|
|
||||||
//l.syntax = syntax;
|
|
||||||
lines.push_back(l);
|
lines.push_back(l);
|
||||||
|
|
||||||
if ((op == "use") || (op == "put"))
|
if ((op == "use") || (op == "put"))
|
||||||
|
|
12
asm.h
12
asm.h
|
@ -37,6 +37,7 @@ enum asmErrors
|
||||||
{
|
{
|
||||||
errNone,
|
errNone,
|
||||||
errWarn,
|
errWarn,
|
||||||
|
errDebug,
|
||||||
errIncomplete,
|
errIncomplete,
|
||||||
errUnimplemented,
|
errUnimplemented,
|
||||||
errFatal,
|
errFatal,
|
||||||
|
@ -72,6 +73,7 @@ const std::string errStrings[errMAX + 1] =
|
||||||
{
|
{
|
||||||
"No Error",
|
"No Error",
|
||||||
"Warning",
|
"Warning",
|
||||||
|
"Debug Error",
|
||||||
"Unfinished Opcode",
|
"Unfinished Opcode",
|
||||||
"Unimplemented Instruction",
|
"Unimplemented Instruction",
|
||||||
"Fatal",
|
"Fatal",
|
||||||
|
@ -181,6 +183,7 @@ public:
|
||||||
std::string lable;
|
std::string lable;
|
||||||
std::string printlable;
|
std::string printlable;
|
||||||
std::string printoperand;
|
std::string printoperand;
|
||||||
|
std::string strippedoperand;
|
||||||
std::string opcode;
|
std::string opcode;
|
||||||
std::string opcodelower;
|
std::string opcodelower;
|
||||||
std::string orig_operand;
|
std::string orig_operand;
|
||||||
|
@ -189,6 +192,7 @@ public:
|
||||||
std::string operand_expr2;
|
std::string operand_expr2;
|
||||||
std::string comment;
|
std::string comment;
|
||||||
std::string addrtext;
|
std::string addrtext;
|
||||||
|
char shiftchar;
|
||||||
uint8_t linemx;
|
uint8_t linemx;
|
||||||
uint8_t tabs[16];
|
uint8_t tabs[16];
|
||||||
bool showmx;
|
bool showmx;
|
||||||
|
@ -228,7 +232,7 @@ protected:
|
||||||
int win_rows;
|
int win_rows;
|
||||||
std::string initialdir;
|
std::string initialdir;
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
uint32_t syntax;
|
//uint32_t syntax;
|
||||||
uint64_t starttime;
|
uint64_t starttime;
|
||||||
uint8_t tabs[16];
|
uint8_t tabs[16];
|
||||||
|
|
||||||
|
@ -249,7 +253,7 @@ public:
|
||||||
virtual void process(void);
|
virtual void process(void);
|
||||||
virtual void complete(void);
|
virtual void complete(void);
|
||||||
virtual void errorOut(uint16_t code);
|
virtual void errorOut(uint16_t code);
|
||||||
virtual void setLanguage(string lang);
|
virtual void setLanguage(string lang,bool force);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -403,6 +407,9 @@ class TPsuedoOp;
|
||||||
|
|
||||||
class T65816Asm : public TFileProcessor
|
class T65816Asm : public TFileProcessor
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
std::vector<uint8_t> outputbytes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// options
|
// options
|
||||||
bool casesen;
|
bool casesen;
|
||||||
|
@ -486,6 +493,7 @@ public:
|
||||||
|
|
||||||
int parseOperand(MerlinLine &line);
|
int parseOperand(MerlinLine &line);
|
||||||
int getAddrMode(MerlinLine &line);
|
int getAddrMode(MerlinLine &line);
|
||||||
|
string addrModeEnglish(int mode);
|
||||||
void setOpcode(MerlinLine &line, uint8_t op);
|
void setOpcode(MerlinLine &line, uint8_t op);
|
||||||
|
|
||||||
|
|
||||||
|
|
2
eval.cpp
2
eval.cpp
|
@ -607,7 +607,7 @@ int CLASS::evaluate(std::string & e, int64_t &res, uint8_t &_shiftmode)
|
||||||
std::string expr = Poco::trim(e);
|
std::string expr = Poco::trim(e);
|
||||||
expr += " "; // add a space at end to make parsing easier
|
expr += " "; // add a space at end to make parsing easier
|
||||||
|
|
||||||
if (isDebug() >= 1)
|
if (isDebug() >= 3)
|
||||||
{
|
{
|
||||||
printf("eval: expression: |%s|\n", expr.c_str());
|
printf("eval: expression: |%s|\n", expr.c_str());
|
||||||
}
|
}
|
||||||
|
|
101
opcodes.cpp
101
opcodes.cpp
|
@ -7,6 +7,7 @@ void CLASS::setOpcode(MerlinLine &line, uint8_t op)
|
||||||
{
|
{
|
||||||
if (pass > 0)
|
if (pass > 0)
|
||||||
{
|
{
|
||||||
|
//printf("cpumode=%d\n",cpumode);
|
||||||
if (cpumode < MODE_65816) // instructions are valid if we are in 65816
|
if (cpumode < MODE_65816) // instructions are valid if we are in 65816
|
||||||
{
|
{
|
||||||
uint8_t m = opCodeCompatibility[op];
|
uint8_t m = opCodeCompatibility[op];
|
||||||
|
@ -40,6 +41,15 @@ int CLASS::doXC(MerlinLine &line, TSymbol &sym)
|
||||||
std::string s;
|
std::string s;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
if (options.isMerlin()) // in merlin8 mode we don't support XC psuedoop
|
||||||
|
{
|
||||||
|
if (line.errorcode == 0) // don't replace other errors
|
||||||
|
{
|
||||||
|
line.setError(errIncompatibleOpcode);
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
if (cpumode < MODE_65816)
|
if (cpumode < MODE_65816)
|
||||||
{
|
{
|
||||||
cpumode++;
|
cpumode++;
|
||||||
|
@ -571,12 +581,24 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym)
|
||||||
{
|
{
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
case syn_diix: amode = 0; break;
|
case syn_diix:
|
||||||
case syn_abs: amode = 1; break;
|
amode = 0;
|
||||||
case syn_imm: amode = 2; break;
|
break;
|
||||||
case syn_diiy: amode = 4; break;
|
case syn_abs:
|
||||||
case syn_absx: amode = 5; break;
|
amode = 1;
|
||||||
case syn_absy: amode = 6; break;
|
break;
|
||||||
|
case syn_imm:
|
||||||
|
amode = 2;
|
||||||
|
break;
|
||||||
|
case syn_diiy:
|
||||||
|
amode = 4;
|
||||||
|
break;
|
||||||
|
case syn_absx:
|
||||||
|
amode = 5;
|
||||||
|
break;
|
||||||
|
case syn_absy:
|
||||||
|
amode = 6;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
err = true;
|
err = true;
|
||||||
break;
|
break;
|
||||||
|
@ -586,16 +608,25 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym)
|
||||||
{
|
{
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
case syn_imm: amode = 0; break;
|
case syn_imm:
|
||||||
case syn_abs: amode = 1; break;
|
amode = 0;
|
||||||
case syn_implied: amode = 2; bytelen = 0; break;
|
break;
|
||||||
|
case syn_abs:
|
||||||
|
amode = 1;
|
||||||
|
break;
|
||||||
|
case syn_implied:
|
||||||
|
amode = 2;
|
||||||
|
bytelen = 0;
|
||||||
|
break;
|
||||||
case syn_absy:
|
case syn_absy:
|
||||||
if ((opflags & OP_STX) == OP_STX)
|
if ((opflags & OP_STX) == OP_STX)
|
||||||
{
|
{
|
||||||
amode = 5;
|
amode = 5;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case syn_absx: amode = 5; break; // this is actually Y addressing because X register is used
|
case syn_absx:
|
||||||
|
amode = 5;
|
||||||
|
break; // this is actually Y addressing because X register is used
|
||||||
default:
|
default:
|
||||||
err = true;
|
err = true;
|
||||||
break;
|
break;
|
||||||
|
@ -715,13 +746,28 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym)
|
||||||
err = false;
|
err = false;
|
||||||
switch (m)
|
switch (m)
|
||||||
{
|
{
|
||||||
case syn_s: amode = 0; break;
|
case syn_s:
|
||||||
case syn_sy: amode = 4; break;
|
amode = 0;
|
||||||
case syn_di: cc = 0x02; amode = 4; break;
|
break;
|
||||||
case syn_iyl: amode = 5; break;
|
case syn_sy:
|
||||||
case syn_dil: amode = 1; break;
|
amode = 4;
|
||||||
case syn_absx: amode = 7; break;
|
break;
|
||||||
case syn_abs: amode = 3; break;
|
case syn_di:
|
||||||
|
cc = 0x02;
|
||||||
|
amode = 4;
|
||||||
|
break;
|
||||||
|
case syn_iyl:
|
||||||
|
amode = 5;
|
||||||
|
break;
|
||||||
|
case syn_dil:
|
||||||
|
amode = 1;
|
||||||
|
break;
|
||||||
|
case syn_absx:
|
||||||
|
amode = 7;
|
||||||
|
break;
|
||||||
|
case syn_abs:
|
||||||
|
amode = 3;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
//printf("bad syn_mode=%d\n", m);
|
//printf("bad syn_mode=%d\n", m);
|
||||||
err = true;
|
err = true;
|
||||||
|
@ -750,15 +796,29 @@ out:
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
line.setError(errBadAddressMode);
|
line.setError(errBadAddressMode);
|
||||||
//printf("bad address mode %d\n",line.addressmode);
|
printf("bad address mode %d\n",line.addressmode);
|
||||||
op = 0x00;
|
op = 0x00;
|
||||||
res = 0;
|
res = 0;
|
||||||
bytelen = 0;
|
bytelen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
res += bytelen;
|
res += bytelen;
|
||||||
|
//if (options.isMerlin32())
|
||||||
|
{
|
||||||
|
if ((op==0xB9) || (op==0x79) || (op==0xF9) || (op==0x99))
|
||||||
|
{
|
||||||
|
// there are 4 instructions that don't have (dp),y addressing so convert to (abs),
|
||||||
|
if (bytelen<2)
|
||||||
|
{
|
||||||
|
res++;
|
||||||
|
bytelen++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((pass > 0) && (res > 0))
|
if ((pass > 0) && (res > 0))
|
||||||
{
|
{
|
||||||
|
|
||||||
setOpcode(line, op);
|
setOpcode(line, op);
|
||||||
for (i = 0; i < (res - 1); i++)
|
for (i = 0; i < (res - 1); i++)
|
||||||
{
|
{
|
||||||
|
@ -794,8 +854,10 @@ int CLASS::doBYTE(MerlinLine & line, TSymbol & sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SGQ merlin32 apparently tracks XCE instructions when tracking MX status
|
// SGQ merlin32 apparently tracks XCE instructions when tracking MX status
|
||||||
// who know how they determine this. I am assuming the NEXT instruction
|
// who knows how they determine this. I am assuming the NEXT instruction
|
||||||
// after a SEC/CLC instruction must be an XCE
|
// after a SEC/CLC instruction must be an XCE
|
||||||
|
if (options.isMerlin32())
|
||||||
|
{
|
||||||
if (sym.opcode == 0x38) // SEC
|
if (sym.opcode == 0x38) // SEC
|
||||||
{
|
{
|
||||||
lastcarry = true;
|
lastcarry = true;
|
||||||
|
@ -814,6 +876,7 @@ int CLASS::doBYTE(MerlinLine & line, TSymbol & sym)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (res);
|
return (res);
|
||||||
|
|
16
parms.json
16
parms.json
|
@ -7,20 +7,26 @@
|
||||||
"0": "${PWD}"
|
"0": "${PWD}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"1": "0/source"
|
"1": "${QASM_BASE}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"2": "0/object"
|
"2": "0/object"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"3": "0/macros"
|
"3": "1/macros"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"4": "1/toolmacs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"5": "../backup"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"language": "qasm",
|
||||||
"asm": {
|
"asm": {
|
||||||
"language": "merlin16plus",
|
"cpu": "M65816",
|
||||||
"cpu": "M6502",
|
"start_mx": 0,
|
||||||
"start_mx": 2,
|
|
||||||
"listmode": "on",
|
"listmode": "on",
|
||||||
"casesen": true,
|
"casesen": true,
|
||||||
"start_lst": false,
|
"start_lst": false,
|
||||||
|
|
22
psuedo.cpp
22
psuedo.cpp
|
@ -793,6 +793,7 @@ int CLASS::doASC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
uint8_t delimiter = 0;
|
uint8_t delimiter = 0;
|
||||||
uint32_t ss = 0;
|
uint32_t ss = 0;
|
||||||
uint32_t lastdelimidx = 0;
|
uint32_t lastdelimidx = 0;
|
||||||
|
bool dci = false;
|
||||||
|
|
||||||
std::vector<uint8_t> bytes;
|
std::vector<uint8_t> bytes;
|
||||||
|
|
||||||
|
@ -890,7 +891,6 @@ int CLASS::doASC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
bool dci = false;
|
|
||||||
uint8_t andval = 0xFF;
|
uint8_t andval = 0xFF;
|
||||||
uint8_t orval = 0x00;
|
uint8_t orval = 0x00;
|
||||||
uint8_t addlen = 0;
|
uint8_t addlen = 0;
|
||||||
|
@ -956,6 +956,19 @@ int CLASS::doASC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
b |= orval;
|
b |= orval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((line.options->isMerlin32()) || (line.options->isMerlin16plus()))
|
||||||
|
{
|
||||||
|
// invert last byte of total bytes out
|
||||||
|
|
||||||
|
if ((dci) && ((i+1)>=truebytect))
|
||||||
|
{
|
||||||
|
b^=0x80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("bug\n");
|
||||||
|
// invert last byte of last string (old merlin way (pre-merlin16+))
|
||||||
if (dci && (i == lastdelimidx))
|
if (dci && (i == lastdelimidx))
|
||||||
{
|
{
|
||||||
// SGQ BUG - Merlin16+ does it like Merlin32 and now does the last
|
// SGQ BUG - Merlin16+ does it like Merlin32 and now does the last
|
||||||
|
@ -980,6 +993,7 @@ int CLASS::doASC(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
b &= 0x7F;
|
b &= 0x7F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
line.outbytes.push_back(b);
|
line.outbytes.push_back(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1047,8 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Merlin32 seems to have a bug where ORG seems like it can only be 16 bits
|
// Merlin32 seems to have a bug where ORG seems like it can only be 16 bits
|
||||||
if ((line.syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
//if ((line.syntax & SYNTAX_MERLIN32) == SYNTAX_MERLIN32)
|
||||||
|
if (options.isMerlin32())
|
||||||
{
|
{
|
||||||
// so clear the bank word in all variables
|
// so clear the bank word in all variables
|
||||||
a.PC.orgsave &= 0xFFFF;
|
a.PC.orgsave &= 0xFFFF;
|
||||||
|
@ -1048,7 +1063,8 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||||
sp = getConfig("option.objfile", "");
|
sp = getConfig("option.objfile", "");
|
||||||
if (sp=="")
|
if (sp=="")
|
||||||
{
|
{
|
||||||
a.savepath = a.processFilename(line.operand, Poco::Path::current(), 0);
|
//a.savepath = a.processFilename(line.operand, Poco::Path::current(), 0);
|
||||||
|
a.savepath=line.operand;
|
||||||
}
|
}
|
||||||
else // if they specified an output name on the command line, use it.
|
else // if they specified an output name on the command line, use it.
|
||||||
{
|
{
|
||||||
|
|
16
qasm.cpp
16
qasm.cpp
|
@ -115,10 +115,11 @@ int CLASS::runCommandLineApp(void)
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ReadFile(Poco::Path::config()+"/parms.json");
|
//printf("apppath: |%s|\n",appPath.c_str());
|
||||||
options.ReadFile(appPath+"/parms.json");
|
options.ReadFile(Poco::Path::config()+"/parms.json",false);
|
||||||
options.ReadFile(Poco::Path::configHome()+"/parms.json");
|
options.ReadFile(appPath+"/parms.json",true);
|
||||||
options.ReadFile(Poco::Path::current()+"/parms.json");
|
options.ReadFile(Poco::Path::configHome()+"/parms.json",false);
|
||||||
|
options.ReadFile(Poco::Path::current()+"/parms.json",false);
|
||||||
|
|
||||||
syn="QASM";
|
syn="QASM";
|
||||||
|
|
||||||
|
@ -145,6 +146,7 @@ int CLASS::runCommandLineApp(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
language=syn;
|
language=syn;
|
||||||
|
options.setLanguage(syn,true);
|
||||||
|
|
||||||
if (isDebug()>0)
|
if (isDebug()>0)
|
||||||
{
|
{
|
||||||
|
@ -237,7 +239,7 @@ int CLASS::runCommandLineApp(void)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
t->init();
|
t->init();
|
||||||
t->setLanguage(language);
|
t->setLanguage(language,true);
|
||||||
t->format_flags=format_flags;
|
t->format_flags=format_flags;
|
||||||
|
|
||||||
std::string f = path.toString();
|
std::string f = path.toString();
|
||||||
|
@ -271,7 +273,7 @@ int CLASS::runCommandLineApp(void)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
t->init();
|
t->init();
|
||||||
t->setLanguage(language);
|
t->setLanguage(language,true);
|
||||||
|
|
||||||
|
|
||||||
std::string f = path.toString();
|
std::string f = path.toString();
|
||||||
|
@ -308,7 +310,7 @@ int CLASS::runCommandLineApp(void)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
t->init();
|
t->init();
|
||||||
t->setLanguage(language);
|
t->setLanguage(language,true);
|
||||||
|
|
||||||
std::string f = path.toString();
|
std::string f = path.toString();
|
||||||
t->filename = f;
|
t->filename = f;
|
||||||
|
|
335
qoptions.h
335
qoptions.h
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
using namespace Poco;
|
using namespace Poco;
|
||||||
|
|
||||||
|
#define ENV_QASM "QASM_BASE"
|
||||||
|
|
||||||
#define MAX_PREFIX 32
|
#define MAX_PREFIX 32
|
||||||
|
|
||||||
#define MODE_6502 0
|
#define MODE_6502 0
|
||||||
|
@ -10,13 +12,15 @@ using namespace Poco;
|
||||||
#define MODE_65816 2
|
#define MODE_65816 2
|
||||||
|
|
||||||
#define SYNTAX_MERLIN 0x01
|
#define SYNTAX_MERLIN 0x01
|
||||||
#define SYNTAX_MERLIN32 0x02
|
#define SYNTAX_MERLIN16 0x02
|
||||||
#define SYNTAX_APW 0x04
|
#define SYNTAX_MERLIN16PLUS 0x04
|
||||||
#define SYNTAX_MPW 0x08
|
#define SYNTAX_MERLIN32 0x08
|
||||||
#define SYNTAX_ORCA 0x10
|
#define SYNTAX_APW 0x10
|
||||||
#define SYNTAX_CC65 0x20
|
#define SYNTAX_MPW 0x20
|
||||||
#define SYNTAX_LISA 0x40
|
#define SYNTAX_ORCA 0x40
|
||||||
#define SYNTAX_QASM (0x80 | SYNTAX_MERLIN)
|
#define SYNTAX_CC65 0x80
|
||||||
|
#define SYNTAX_LISA 0x100
|
||||||
|
#define SYNTAX_QASM (0x200 | SYNTAX_MERLIN)
|
||||||
|
|
||||||
#define OPTION_ALLOW_A_OPERAND 0x0100
|
#define OPTION_ALLOW_A_OPERAND 0x0100
|
||||||
#define OPTION_ALLOW_LOCAL 0x0200
|
#define OPTION_ALLOW_LOCAL 0x0200
|
||||||
|
@ -41,11 +45,11 @@ class CLASS
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
//vector<shared_ptr<JSONConfiguration>> configs;
|
//vector<shared_ptr<JSONConfiguration>> configs;
|
||||||
|
vector<std::string> valid_files;
|
||||||
public:
|
public:
|
||||||
Poco::JSON::Parser parser;
|
//Poco::JSON::Parser parser;
|
||||||
string jsonin;
|
//string jsonin;
|
||||||
Dynamic::Var jsonobj=NULL;
|
//Dynamic::Var jsonobj=NULL;
|
||||||
uint16_t format_flags;
|
uint16_t format_flags;
|
||||||
|
|
||||||
uint16_t cpu_mode;
|
uint16_t cpu_mode;
|
||||||
|
@ -70,23 +74,34 @@ public:
|
||||||
int16_t linebytes;
|
int16_t linebytes;
|
||||||
int16_t overflowbytes;
|
int16_t overflowbytes;
|
||||||
|
|
||||||
myLayeredConfiguration config;
|
myLayeredConfiguration *config=NULL;
|
||||||
|
|
||||||
bool usecolor;
|
bool usecolor;
|
||||||
|
|
||||||
CLASS()
|
CLASS()
|
||||||
{
|
{
|
||||||
|
language="";
|
||||||
|
setEnvironment();
|
||||||
|
clear();
|
||||||
setDefaults();
|
setDefaults();
|
||||||
setLanguage("QASM");
|
setLanguage("QASM",true);
|
||||||
|
setCurrent();
|
||||||
}
|
}
|
||||||
~CLASS()
|
~CLASS()
|
||||||
{
|
{
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
//configs.clear();
|
if (config!=NULL)
|
||||||
|
{
|
||||||
|
delete config;
|
||||||
|
config=NULL;
|
||||||
|
}
|
||||||
|
config=new myLayeredConfiguration();
|
||||||
|
valid_files.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool useColor(void)
|
bool useColor(void)
|
||||||
|
@ -125,6 +140,8 @@ public:
|
||||||
int printDefaults(string lang)
|
int printDefaults(string lang)
|
||||||
{
|
{
|
||||||
int res=-1;
|
int res=-1;
|
||||||
|
string s;
|
||||||
|
int i;
|
||||||
string l=Poco::toUpper(lang);
|
string l=Poco::toUpper(lang);
|
||||||
if (l=="")
|
if (l=="")
|
||||||
{
|
{
|
||||||
|
@ -132,24 +149,46 @@ public:
|
||||||
}
|
}
|
||||||
if (l!="")
|
if (l!="")
|
||||||
{
|
{
|
||||||
setLanguage(l);
|
setLanguage(l,false);
|
||||||
setCurrent();
|
setCurrent();
|
||||||
printf("Defaults for language (%s)\n",language.c_str());
|
printf("Defaults for language (%s)\n",language.c_str());
|
||||||
printf("\tLanguage:\t\t\t\t\t%s\n",language.c_str());
|
printf("\t\tLanguage:\t\t\t%s\n",language.c_str());
|
||||||
printf("\t\tlanguageLevel:\t\t\t\t%d\n",langlevel);
|
printf("\t\tlanguageLevel:\t\t\t%d\n",langlevel);
|
||||||
printf("\t\tcpu_mode:\t\t\t\t%d\n",cpu_mode);
|
s="<unknown>";
|
||||||
printf("\t\tstart_mx:\t\t\t\t%d\n",start_mx);
|
switch(cpu_mode)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
s="M6502";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
s="M65C02";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
s="M65816";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf("\t\tcpu_mode:\t\t\t%s\n",s.c_str());
|
||||||
|
printf("\t\tstart_mx:\t\t\t%%%d%d\n",start_mx&0x02?1:0,start_mx&0x01?1:0);
|
||||||
|
//printf("\t\tstart_mx:\t\t\t%d\n",start_mx);
|
||||||
printf("\t\tPrefixes:\n");
|
printf("\t\tPrefixes:\n");
|
||||||
|
|
||||||
for (int i=0; i<MAX_PREFIX; i++)
|
for (i=0; i<MAX_PREFIX; i++)
|
||||||
{
|
{
|
||||||
if (prefixes[i].length()>0)
|
if (prefixes[i].length()>0)
|
||||||
{
|
{
|
||||||
printf("\t\t\t%02d:\t\t\t%s\n",i,prefixes[i].c_str());
|
printf("\t\t\t%2d:\t%s\n",i,prefixes[i].c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
for (unsigned long ii=0; ii<valid_files.size(); ii++)
|
||||||
|
{
|
||||||
|
if (prefixes[ii].length()>0)
|
||||||
|
{
|
||||||
|
printf("\t\tSettings files read: \t%s\n",valid_files[ii].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
//uint16_t format_flags;
|
//uint16_t format_flags;
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,21 +199,64 @@ public:
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ReadFile(string path)
|
string getAppPath()
|
||||||
{
|
{
|
||||||
|
char buff[PATH_MAX+1];
|
||||||
|
char *x;
|
||||||
|
|
||||||
|
string res="";
|
||||||
|
res=Poco::Util::Application::instance().commandPath();
|
||||||
|
x=realpath(res.c_str(),buff);
|
||||||
|
if (x!=NULL)
|
||||||
|
{
|
||||||
|
res=buff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res="";
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
int ReadFile(string path, bool backtrack)
|
||||||
|
{
|
||||||
|
//int levels=0;
|
||||||
|
bool done=false;
|
||||||
int ret=-1;
|
int ret=-1;
|
||||||
|
unsigned long ii;
|
||||||
Poco::Util::JSONConfiguration *jc;
|
Poco::Util::JSONConfiguration *jc;
|
||||||
|
|
||||||
|
while(!done)
|
||||||
|
{
|
||||||
Poco::Path pp(path);
|
Poco::Path pp(path);
|
||||||
//pp=pp.expand();
|
//pp=pp.absolute(Poco::Path("/"));
|
||||||
|
pp=pp.absolute();
|
||||||
|
|
||||||
|
std::string basename=pp.getFileName();
|
||||||
|
|
||||||
Poco::File pf(pp);
|
Poco::File pf(pp);
|
||||||
if (isDebug()>1)
|
if (isDebug()>1)
|
||||||
{
|
{
|
||||||
printf("parmsfile: %s\n",pp.toString().c_str());
|
//pf.
|
||||||
|
printf(" %d parmsfile: %s ",backtrack,pf.path().c_str());
|
||||||
}
|
}
|
||||||
if ((pf.exists()) && (pf.canRead()) && ((pf.isFile()) || (pf.isLink())))
|
if ((pf.exists()) && (pf.canRead()) && ((pf.isFile()) || (pf.isLink())))
|
||||||
{
|
{
|
||||||
|
if (isDebug()>1)
|
||||||
|
{
|
||||||
|
printf("...found!\n");
|
||||||
|
}
|
||||||
//printf("OK: %s\n",pp.toString().c_str());
|
//printf("OK: %s\n",pp.toString().c_str());
|
||||||
|
done=false;
|
||||||
|
for (ii=0; ii<valid_files.size(); ii++)
|
||||||
|
{
|
||||||
|
if (pf.path()==valid_files[ii])
|
||||||
|
{
|
||||||
|
done=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!done)
|
||||||
|
{
|
||||||
|
done=true; // we found a valid file
|
||||||
|
|
||||||
jc=new Poco::Util::JSONConfiguration();
|
jc=new Poco::Util::JSONConfiguration();
|
||||||
//Poco::FileInputStream fs(path);
|
//Poco::FileInputStream fs(path);
|
||||||
|
@ -197,13 +279,49 @@ public:
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
//configs.push_back(shared_ptr<JSONConfiguration>(jc));
|
//configs.push_back(shared_ptr<JSONConfiguration>(jc));
|
||||||
config.add(jc);
|
config->add(jc);
|
||||||
|
valid_files.push_back(pp.toString());
|
||||||
ret=0;
|
ret=0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("unable to load/parts file: %s\n",pp.toString().c_str());
|
delete jc;
|
||||||
|
jc=NULL;
|
||||||
|
printf("...unable to load/parts file: %s\n",pp.toString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isDebug()>1)
|
||||||
|
{
|
||||||
|
printf("...not found\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!backtrack)
|
||||||
|
{
|
||||||
|
done=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!done)
|
||||||
|
{
|
||||||
|
//string ss=pp.current();
|
||||||
|
string ss=pp.toString();
|
||||||
|
pp=pp.popDirectory();
|
||||||
|
string ss1=pp.toString();
|
||||||
|
|
||||||
|
//printf("|%s| |%s|\n",ss.c_str(),ss1.c_str());
|
||||||
|
//assert(0);
|
||||||
|
path=ss1;
|
||||||
|
pp=Path(path);
|
||||||
|
if (path=="/")
|
||||||
|
{
|
||||||
|
done=true;
|
||||||
|
}
|
||||||
|
//path=path+"/"+basename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
|
@ -211,17 +329,162 @@ public:
|
||||||
|
|
||||||
bool isMerlin32(void)
|
bool isMerlin32(void)
|
||||||
{
|
{
|
||||||
return(true);
|
bool res=false;
|
||||||
|
if (language=="MERLIN32")
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMerlin(void)
|
bool isMerlin(void)
|
||||||
{
|
{
|
||||||
return(false);
|
bool res=false;
|
||||||
|
if (language=="MERLIN")
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
bool isQASM(void)
|
||||||
|
{
|
||||||
|
bool res=false;
|
||||||
|
if (language=="QASM")
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMerlinCompat()
|
||||||
|
{
|
||||||
|
bool res=false;
|
||||||
|
string s=language;
|
||||||
|
if (s=="QASM")
|
||||||
|
{
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
bool b=s.find("MERLIN"); // any of the merlin varieties
|
||||||
|
if (b)
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMerlin16(void)
|
||||||
|
{
|
||||||
|
bool res=false;
|
||||||
|
if (language=="MERLIN16")
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMerlin16plus(void)
|
||||||
|
{
|
||||||
|
bool res=false;
|
||||||
|
if (language=="MERLIN16PLUS")
|
||||||
|
{
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEnvironment()
|
||||||
|
{
|
||||||
|
string s="";
|
||||||
|
//s=Poco::Environment::get("QASM");
|
||||||
|
if (!Poco::Environment::has(ENV_QASM))
|
||||||
|
{
|
||||||
|
s=Poco::Util::Application::instance().commandPath();
|
||||||
|
Poco::Path pp(getAppPath());
|
||||||
|
pp=pp.absolute(Poco::Path());
|
||||||
|
//pp=pp.absolute(Poco::Path("/"));
|
||||||
|
s=pp.toString();
|
||||||
|
//printf("program: %s\n",s.c_str());
|
||||||
|
Poco::Environment::set(ENV_QASM,s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
string formatPath(string p)
|
||||||
|
{
|
||||||
|
string res=p;
|
||||||
|
string s;
|
||||||
|
Poco::Path pp(p);
|
||||||
|
s=pp.expand(pp.toString()); // replace environment variable references
|
||||||
|
pp=Poco::Path(s);
|
||||||
|
if (s!="")
|
||||||
|
{
|
||||||
|
|
||||||
|
Poco::StringTokenizer toks(s,"/");
|
||||||
|
if (toks.count()>0)
|
||||||
|
{
|
||||||
|
uint32_t n;
|
||||||
|
bool success=false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
n=Poco::NumberParser::parseUnsigned(toks[0]);
|
||||||
|
if (n<MAX_PREFIX)
|
||||||
|
{
|
||||||
|
success=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
success=false;
|
||||||
|
}
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
s=s.substr(toks[0].length(),s.length());
|
||||||
|
s=prefixes[n]+s;
|
||||||
|
pp=Poco::Path(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//pp=pp.absolute(Poco::Path("/"));
|
||||||
|
pp=pp.absolute();
|
||||||
|
res=pp.toString();
|
||||||
|
}
|
||||||
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrent(void)
|
void setCurrent(void)
|
||||||
{
|
{
|
||||||
|
char buff[1024];
|
||||||
|
string s,n;
|
||||||
|
int i;
|
||||||
|
|
||||||
start_mx=GetInteger("asm.start_mx",3);
|
start_mx=GetInteger("asm.start_mx",3);
|
||||||
|
for (i=0; i<MAX_PREFIX; i++)
|
||||||
|
{
|
||||||
|
sprintf(buff,"general.prefix[%d].%d",i,i);
|
||||||
|
n=buff;
|
||||||
|
n=GetString(n,"");
|
||||||
|
n=formatPath(n);
|
||||||
|
prefixes[i]=n;
|
||||||
|
}
|
||||||
|
s=GetString("asm.cpu","M6502");
|
||||||
|
if (s=="M6502")
|
||||||
|
{
|
||||||
|
cpu_mode=MODE_6502;
|
||||||
|
}
|
||||||
|
else if (s=="M65C02")
|
||||||
|
{
|
||||||
|
cpu_mode=MODE_65C02;
|
||||||
|
}
|
||||||
|
else if (s=="M65816")
|
||||||
|
{
|
||||||
|
cpu_mode=MODE_65816;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("unknown cpu_mode in settings (%s) [M6502, M65C02, M65816]\n",s.c_str());
|
||||||
|
cpu_mode=MODE_6502;
|
||||||
|
}
|
||||||
|
|
||||||
|
allowDuplicate=GetBool("asm.allowduplicate",false);
|
||||||
}
|
}
|
||||||
void setDefaults(void)
|
void setDefaults(void)
|
||||||
{
|
{
|
||||||
|
@ -251,15 +514,15 @@ public:
|
||||||
usecolor=true;
|
usecolor=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLanguage(string lang)
|
void setLanguage(string lang, bool force)
|
||||||
{
|
{
|
||||||
//printf("request language options to %s from %s\n",lang.c_str(),language.c_str());
|
//printf("request language options to %s from %s\n",lang.c_str(),language.c_str());
|
||||||
|
|
||||||
string old=language;
|
string old=language;
|
||||||
string pn=Poco::toUpper(lang);
|
string pn=Poco::toUpper(lang);
|
||||||
if (old!=pn)
|
if ((old!=pn) || (force))
|
||||||
{
|
{
|
||||||
//printf("setting language options to %s\n",pn.c_str());
|
printf("setting language options to %s\n",pn.c_str());
|
||||||
language=pn;
|
language=pn;
|
||||||
setCurrent();
|
setCurrent();
|
||||||
if (pn=="QASM")
|
if (pn=="QASM")
|
||||||
|
@ -333,6 +596,8 @@ public:
|
||||||
bool res=def;
|
bool res=def;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
res=config->getBool(name);
|
||||||
|
|
||||||
//Dynamic::Var jresult=GetObject(name);
|
//Dynamic::Var jresult=GetObject(name);
|
||||||
//if (!jresult.isEmpty())
|
//if (!jresult.isEmpty())
|
||||||
//{
|
//{
|
||||||
|
@ -358,7 +623,7 @@ public:
|
||||||
string res=def;
|
string res=def;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//config
|
res=config->getString(name);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
@ -373,7 +638,7 @@ public:
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
config.keys(keys);
|
config->keys(keys);
|
||||||
for (unsigned int i=0; i<keys.size(); i++)
|
for (unsigned int i=0; i<keys.size(); i++)
|
||||||
{
|
{
|
||||||
printf("key[%d]: %s\n",i,keys[i].c_str());
|
printf("key[%d]: %s\n",i,keys[i].c_str());
|
||||||
|
@ -382,7 +647,7 @@ public:
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
res=config.getInt(name);
|
res=config->getInt(name);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
|
10
runtests.sh
10
runtests.sh
|
@ -29,10 +29,14 @@ for S in $SRC ; do
|
||||||
BASE=${BASE/.s/}
|
BASE=${BASE/.s/}
|
||||||
#./qasm -o 0/$OUTDIR/$S1 ./testdata/$S
|
#./qasm -o 0/$OUTDIR/$S1 ./testdata/$S
|
||||||
|
|
||||||
./qasm --syntax merlin32 -o 0/$OUTDIR/$S1 ./testdata/$S >> $TMPFILE
|
./qasm -l -t merlin32 -i M65816 -o 0/$OUTDIR/$S1 ./testdata/$S >> $TMPFILE
|
||||||
|
|
||||||
|
X="./qasm -l -t merlin32 -i M65816 -o 0/$OUTDIR/$S1 ./testdata/$S"
|
||||||
|
#echo $X
|
||||||
|
|
||||||
R=?$
|
R=?$
|
||||||
#echo $S " " $S1
|
#echo $S " " $S1
|
||||||
|
#cat $TMPFILE
|
||||||
R=`cat $TMPFILE | grep "End qASM assembly"`
|
R=`cat $TMPFILE | grep "End qASM assembly"`
|
||||||
E=`echo $R | awk -e '{ print $6; }'`
|
E=`echo $R | awk -e '{ print $6; }'`
|
||||||
ect=`echo $(($E))`
|
ect=`echo $(($E))`
|
||||||
|
@ -64,8 +68,12 @@ for S in $SRC ; do
|
||||||
if [ $pct != 0 ] ; then
|
if [ $pct != 0 ] ; then
|
||||||
printf 'FAIL: (%3s) ' $ect
|
printf 'FAIL: (%3s) ' $ect
|
||||||
printf '%s ' $CX
|
printf '%s ' $CX
|
||||||
|
echo " $S"
|
||||||
|
|
||||||
FAILCT=$(($FAILCT+1))
|
FAILCT=$(($FAILCT+1))
|
||||||
|
cat $TMPFILE
|
||||||
|
echo $X
|
||||||
|
exit 255
|
||||||
else
|
else
|
||||||
printf "PASS: "
|
printf "PASS: "
|
||||||
fi
|
fi
|
||||||
|
|
33
test.s
33
test.s
|
@ -10,9 +10,36 @@
|
||||||
xc off
|
xc off
|
||||||
xc
|
xc
|
||||||
xc
|
xc
|
||||||
|
lst
|
||||||
;lst OFF
|
;lst OFF
|
||||||
ZP equ $00
|
ZP equ $00
|
||||||
org $2000
|
org $2000
|
||||||
|
lda $04,y
|
||||||
|
adc $04,y
|
||||||
|
sbc $04,y
|
||||||
|
sta $04,y
|
||||||
|
|
||||||
|
lda <$fff0 ;zp
|
||||||
|
lda >$fff0 ;ABS (lo word)
|
||||||
|
lda ^$fff0 ;ABS (hi word)
|
||||||
|
lda |$fff0 ;ABS (long in 65816 mode)
|
||||||
|
lda <$FFF0+$FFFF
|
||||||
|
|
||||||
|
lda <$fff0+24 ;zp
|
||||||
|
lda >$fff0+24 ;ABS (lo word)
|
||||||
|
lda ^$fff0+24 ;ABS (hi word)
|
||||||
|
lda |$fff0+24 ;ABS (long in 65816 mode)
|
||||||
|
|
||||||
|
lda #<$fff0 ;zp
|
||||||
|
lda #>$fff0 ;ABS (lo word)
|
||||||
|
lda #^$fff0 ;ABS (hi word)
|
||||||
|
lda #<$FFF0+$FFFF
|
||||||
|
lda #>$FFF0+$FFFF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lst off
|
||||||
|
end
|
||||||
ora ($00)
|
ora ($00)
|
||||||
lda ($00)
|
lda ($00)
|
||||||
bit: $FFFE,X
|
bit: $FFFE,X
|
||||||
|
@ -51,11 +78,15 @@ another lda #$00 ;line with everything
|
||||||
lda ]m
|
lda ]m
|
||||||
bra ]m
|
bra ]m
|
||||||
--^
|
--^
|
||||||
|
sav 2/test.bin
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
]1 nop
|
]1 nop
|
||||||
nop
|
nop
|
||||||
;lst
|
;lst
|
||||||
bra ]1
|
bra ]1
|
||||||
|
|
||||||
;typ $06
|
;typ $06
|
||||||
sav 0/test.bin
|
db 255
|
||||||
;lst off
|
;lst off
|
||||||
|
|
1
testdata/2001-allops-zero-6502.S
vendored
1
testdata/2001-allops-zero-6502.S
vendored
|
@ -3,6 +3,7 @@
|
||||||
;
|
;
|
||||||
; Assembler: Merlin 32
|
; Assembler: Merlin 32
|
||||||
|
|
||||||
|
xc off
|
||||||
ZP EQU $00
|
ZP EQU $00
|
||||||
ABS EQU $0000
|
ABS EQU $0000
|
||||||
|
|
||||||
|
|
4
testdata/2006-operand-formats.S
vendored
4
testdata/2006-operand-formats.S
vendored
|
@ -4,7 +4,9 @@
|
||||||
; Assembler: Merlin 32
|
; Assembler: Merlin 32
|
||||||
|
|
||||||
org $1000
|
org $1000
|
||||||
|
xc off
|
||||||
|
xc
|
||||||
|
xc
|
||||||
; 65816 with short regs
|
; 65816 with short regs
|
||||||
clc
|
clc
|
||||||
xce
|
xce
|
||||||
|
|
4
testdata/2007-labels-and-symbols.S
vendored
4
testdata/2007-labels-and-symbols.S
vendored
|
@ -2,7 +2,9 @@
|
||||||
; See the LICENSE.txt file for distribution terms (Apache 2.0).
|
; See the LICENSE.txt file for distribution terms (Apache 2.0).
|
||||||
;
|
;
|
||||||
; Assembler: Merlin 32
|
; Assembler: Merlin 32
|
||||||
|
xc off
|
||||||
|
xc
|
||||||
|
xc
|
||||||
absl equ $1029
|
absl equ $1029
|
||||||
absh equ $feed
|
absh equ $feed
|
||||||
zip equ $cd
|
zip equ $cd
|
||||||
|
|
6
testdata/3001-runfile.S
vendored
6
testdata/3001-runfile.S
vendored
|
@ -1,4 +1,4 @@
|
||||||
;lst off
|
lst off
|
||||||
*
|
*
|
||||||
* main.s
|
* main.s
|
||||||
* Merlin32 Test
|
* Merlin32 Test
|
||||||
|
@ -105,10 +105,12 @@ START
|
||||||
sta _num1+dum0,x
|
sta _num1+dum0,x
|
||||||
stz _num1+dum0,x
|
stz _num1+dum0,x
|
||||||
|
|
||||||
|
lst
|
||||||
lda _num1+dum0,y ;these assemble to abs accesses: lda $00C0,y
|
lda _num1+dum0,y ;these assemble to abs accesses: lda $00C0,y
|
||||||
adc _num1+dum0,y
|
adc _num1+dum0,y
|
||||||
sbc _num1+dum0,y
|
sbc _num1+dum0,y
|
||||||
sta _num1+dum0,y
|
sta _num1+dum0,y
|
||||||
|
lst off
|
||||||
|
|
||||||
; Label & branching tests
|
; Label & branching tests
|
||||||
GetKey ldx $C000
|
GetKey ldx $C000
|
||||||
|
@ -402,5 +404,5 @@ lup_start:
|
||||||
|
|
||||||
;lst off
|
;lst off
|
||||||
//]XCODEEND ; Keep this at the end and put your code above this
|
//]XCODEEND ; Keep this at the end and put your code above this
|
||||||
;lst off
|
lst off
|
||||||
|
|
||||||
|
|
4
testdata/3015-amacc.S
vendored
4
testdata/3015-amacc.S
vendored
|
@ -1,6 +1,10 @@
|
||||||
*
|
*
|
||||||
* explicit a operand (inc a, etc) is dropped.
|
* explicit a operand (inc a, etc) is dropped.
|
||||||
*
|
*
|
||||||
|
xc OFF
|
||||||
|
xc
|
||||||
|
xc
|
||||||
|
mx %11
|
||||||
|
|
||||||
inc a
|
inc a
|
||||||
dec a
|
dec a
|
||||||
|
|
Loading…
Reference in New Issue
Block a user