mirror of
https://github.com/marketideas/qasm.git
synced 2024-06-02 08:41:27 +00:00
SGQ merge
This commit is contained in:
parent
429131b738
commit
6df441dd46
149
asm.cpp
149
asm.cpp
|
@ -27,7 +27,7 @@ void CLASS::print(uint32_t lineno)
|
|||
{
|
||||
int pcol;
|
||||
uint32_t l, i;
|
||||
int commentcol = 40;
|
||||
//int commentcol;
|
||||
static bool checked = false;
|
||||
static bool nc1 = false;
|
||||
bool nc = false;
|
||||
|
@ -143,30 +143,31 @@ void CLASS::print(uint32_t lineno)
|
|||
pcol += printf(" ");
|
||||
}
|
||||
}
|
||||
pcol += printf("%s", comment.c_str());
|
||||
//pcol += printf("%s", comment.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pcol += printf("%-12s %-8s %-10s ", printlable.c_str(), opcode.c_str(), operand.c_str());
|
||||
if (errorcode > 0)
|
||||
{
|
||||
|
||||
while (pcol < commentcol)
|
||||
{
|
||||
pcol += printf(" ");
|
||||
}
|
||||
pcol += printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pcol < commentcol)
|
||||
{
|
||||
pcol += printf(" ");
|
||||
}
|
||||
pcol += printf("%s", comment.c_str());
|
||||
}
|
||||
}
|
||||
if (errorcode > 0)
|
||||
{
|
||||
while (pcol < commentcol)
|
||||
{
|
||||
pcol += printf(" ");
|
||||
}
|
||||
pcol += printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
while (pcol < commentcol)
|
||||
{
|
||||
pcol += printf(" ");
|
||||
}
|
||||
pcol += printf("%s", comment.c_str());
|
||||
}
|
||||
//printf("\n");
|
||||
|
||||
if ((!nc) && (errorcode > 0))
|
||||
{
|
||||
SetColor(CL_NORMAL | BG_NORMAL);
|
||||
|
@ -232,6 +233,7 @@ void CLASS::clear()
|
|||
operand_expr2 = "";
|
||||
addrtext = "";
|
||||
linemx = 0;
|
||||
commentcol=40;
|
||||
bytect = 0;
|
||||
opflags = 0;
|
||||
pass0bytect = 0;
|
||||
|
@ -415,11 +417,39 @@ void CLASS::errorOut(uint16_t code)
|
|||
|
||||
void CLASS::init(void)
|
||||
{
|
||||
int ts, tabpos;
|
||||
std::string s;
|
||||
|
||||
filenames.clear();
|
||||
starttime = GetTickCount();
|
||||
initialdir = Poco::Path::current();
|
||||
syntax = 0;
|
||||
filecount = 0;
|
||||
|
||||
std::string tabstr = getConfig("reformat.tabs", "8,16,32");
|
||||
tabstr = Poco::trim(tabstr);
|
||||
|
||||
memset(tabs, 0x00, sizeof(tabs));
|
||||
|
||||
Poco::StringTokenizer t(tabstr, ",;", 0);
|
||||
tabpos = 0;
|
||||
for (auto itr = t.begin(); itr != t.end(); ++itr)
|
||||
{
|
||||
s = Poco::trim(*itr);
|
||||
try
|
||||
{
|
||||
ts = Poco::NumberParser::parse(s);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ts = 0;
|
||||
}
|
||||
if ((ts >= 0) && (ts < 240))
|
||||
{
|
||||
tabs[tabpos++] = ts;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CLASS::complete(void)
|
||||
|
@ -730,34 +760,9 @@ CLASS::~CLASS()
|
|||
void CLASS::init(void)
|
||||
{
|
||||
std::string s;
|
||||
int ts, tabpos;
|
||||
lines.clear();
|
||||
|
||||
syntax = SYNTAX_MERLIN;
|
||||
|
||||
std::string tabstr = getConfig("reformat.tabs", "8,16,32");
|
||||
tabstr = Poco::trim(tabstr);
|
||||
|
||||
memset(tabs, 0x00, sizeof(tabs));
|
||||
|
||||
Poco::StringTokenizer t(tabstr, ",;", 0);
|
||||
tabpos = 0;
|
||||
for (auto itr = t.begin(); itr != t.end(); ++itr)
|
||||
{
|
||||
s = Poco::trim(*itr);
|
||||
try
|
||||
{
|
||||
ts = Poco::NumberParser::parse(s);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
ts = 0;
|
||||
}
|
||||
if ((ts >= 0) && (ts < 240))
|
||||
{
|
||||
tabs[tabpos++] = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CLASS::doline(int lineno, std::string line)
|
||||
|
@ -1549,6 +1554,7 @@ void CLASS::process(void)
|
|||
int x;;
|
||||
char c;
|
||||
char buff[256];
|
||||
MerlinLine errLine;
|
||||
std::string op, operand, ls;
|
||||
|
||||
pass = 0;
|
||||
|
@ -1569,6 +1575,12 @@ void CLASS::process(void)
|
|||
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;
|
||||
|
||||
|
@ -1683,6 +1695,16 @@ void CLASS::process(void)
|
|||
}
|
||||
lineno++;
|
||||
}
|
||||
|
||||
// end of file reached here, do some final checks
|
||||
|
||||
if (LUPstack.size() > 0)
|
||||
{
|
||||
errLine.clear();
|
||||
errLine.setError(errUnexpectedEOF);
|
||||
errLine.print(lineno);
|
||||
pass = 2;
|
||||
}
|
||||
pass++;
|
||||
}
|
||||
|
||||
|
@ -1710,44 +1732,7 @@ int CLASS::doline(int lineno, std::string line)
|
|||
l.syntax = syntax;
|
||||
lines.push_back(l);
|
||||
|
||||
|
||||
if (op == "lup")
|
||||
{
|
||||
curLUP.lupoffset = lines.size();
|
||||
LUPstack.push(curLUP);
|
||||
curLUP.luprunning++;
|
||||
curLUP.lupct = 3;
|
||||
}
|
||||
else if (op == "--^")
|
||||
{
|
||||
if (curLUP.luprunning > 0)
|
||||
{
|
||||
while (curLUP.luprunning > 0)
|
||||
{
|
||||
if (curLUP.lupct > 0)
|
||||
{
|
||||
|
||||
curLUP.lupct--;
|
||||
|
||||
}
|
||||
if (curLUP.lupct == 0)
|
||||
{
|
||||
curLUP.luprunning--;
|
||||
curLUP = LUPstack.top();
|
||||
LUPstack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
l.setError(errDuplicateFile);
|
||||
curLUP.luprunning = 0;
|
||||
l.print(0);
|
||||
errorct++;
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
else if ((op == "use") || (op == "put"))
|
||||
if ((op == "use") || (op == "put"))
|
||||
{
|
||||
std::string fn;
|
||||
x = processfile(l.operand, fn);
|
||||
|
|
12
asm.h
12
asm.h
|
@ -61,6 +61,8 @@ enum asmErrors
|
|||
errBadEvaluation,
|
||||
errMalformed,
|
||||
errBadCharacter,
|
||||
errUnexpectedOp,
|
||||
errUnexpectedEOF,
|
||||
errMAX
|
||||
};
|
||||
|
||||
|
@ -90,7 +92,9 @@ const std::string errStrings[errMAX + 1] =
|
|||
"File no access",
|
||||
"Unable to evaluate",
|
||||
"Malformed Operand",
|
||||
"Bad character in input",
|
||||
"Unexpected character in input",
|
||||
"Unexpected opcode",
|
||||
"Unexpected End of File",
|
||||
|
||||
""
|
||||
};
|
||||
|
@ -177,6 +181,7 @@ public:
|
|||
std::string comment;
|
||||
std::string addrtext;
|
||||
uint8_t linemx;
|
||||
uint16_t commentcol;
|
||||
bool showmx;
|
||||
uint32_t lineno;
|
||||
uint32_t flags;
|
||||
|
@ -212,6 +217,8 @@ protected:
|
|||
std::vector<std::string> filenames;
|
||||
uint8_t syntax;
|
||||
uint64_t starttime;
|
||||
uint8_t tabs[10];
|
||||
|
||||
uint32_t filecount; // how many files have been read in (because of included files from source
|
||||
public:
|
||||
uint32_t errorct;
|
||||
|
@ -231,7 +238,6 @@ public:
|
|||
class TMerlinConverter : public TFileProcessor
|
||||
{
|
||||
protected:
|
||||
uint8_t tabs[10];
|
||||
std::vector<MerlinLine> lines;
|
||||
|
||||
public:
|
||||
|
@ -333,8 +339,6 @@ public:
|
|||
|
||||
uint16_t pass;
|
||||
|
||||
bool inDUMSection; // yes if we are in a DUM/DEND section
|
||||
|
||||
T65816Asm();
|
||||
virtual ~T65816Asm();
|
||||
|
||||
|
|
4
eval.cpp
4
eval.cpp
|
@ -26,7 +26,7 @@ std::deque<Token> CLASS::exprToTokens(const std::string& expr)
|
|||
std::deque<Token> tokens;
|
||||
int state = 0;
|
||||
char c;
|
||||
char delim = 0;
|
||||
char delim;
|
||||
std::string ident, asc;
|
||||
|
||||
std::string ops = "+-*//^!.&()";
|
||||
|
@ -379,7 +379,7 @@ int CLASS::parseNumber(std::string n, int64_t &val)
|
|||
|
||||
|
||||
i = 0;
|
||||
l = (int)n.length();
|
||||
l = n.length();
|
||||
s = "";
|
||||
for (i = 0; i < l; i++)
|
||||
{
|
||||
|
|
|
@ -761,8 +761,8 @@ void CLASS::insertOpcodes(void)
|
|||
pushopcode("CHK", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("ERR", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("KBD", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("LUP", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("--^", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("LUP", P_LUP, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("--^", P_LUP, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("MX", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doMX));
|
||||
pushopcode("PAU", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
pushopcode("SW", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
|
||||
|
|
84
psuedo.cpp
84
psuedo.cpp
|
@ -13,6 +13,79 @@ CLASS::~CLASS()
|
|||
|
||||
}
|
||||
|
||||
int CLASS::doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
||||
{
|
||||
UNUSED(opinfo);
|
||||
UNUSED(line);
|
||||
UNUSED(a);
|
||||
int lidx, len;
|
||||
int res = 0;
|
||||
int err = 0;
|
||||
|
||||
std::string op = Poco::toUpper(line.opcode);
|
||||
|
||||
if (op == "LUP")
|
||||
{
|
||||
len = line.lineno - 1; // MerlinLine line numbers are +1 from actual array idx
|
||||
if (len >= 0)
|
||||
{
|
||||
a.LUPstack.push(a.curLUP);
|
||||
|
||||
a.curLUP.lupoffset = len;
|
||||
a.curLUP.lupct = 3; // evaluate here
|
||||
a.curLUP.luprunning++;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("err 3\n");
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
|
||||
if (op == "--^")
|
||||
{
|
||||
if (a.curLUP.luprunning > 0)
|
||||
{
|
||||
lidx = line.lineno - 1;
|
||||
len = lidx - a.curLUP.lupoffset - 1;
|
||||
|
||||
if (a.curLUP.lupct > 0)
|
||||
{
|
||||
a.curLUP.lupct--;
|
||||
if (a.curLUP.lupct != 0)
|
||||
{
|
||||
a.lineno = a.curLUP.lupoffset;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("start=%d end=%d len=%d\n", a.curLUP.lupoffset, lidx, len);
|
||||
if (a.LUPstack.size() > 0)
|
||||
{
|
||||
a.curLUP = a.LUPstack.top();
|
||||
a.LUPstack.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("err 2\n");
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("err 1\n");
|
||||
err = errUnexpectedOp;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (err > 0)
|
||||
{
|
||||
line.setError(err);
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
constexpr unsigned int strhash(const char *str, int h = 0)
|
||||
{
|
||||
return !str[h] ? 5381 : (strhash(str, h + 1) * 33) ^ str[h];
|
||||
|
@ -119,12 +192,6 @@ int CLASS::doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// SGQ - remove when complete
|
||||
line.datafillct = outct;
|
||||
line.datafillbyte = 0xCA;
|
||||
// ===============
|
||||
#endif
|
||||
line.outbytect = outct;
|
||||
return (outct);
|
||||
}
|
||||
|
@ -275,7 +342,6 @@ int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||
bytect = 0;
|
||||
}
|
||||
line.outbytect = bytect;
|
||||
//printf("bytect=%d\n",bytect);
|
||||
return bytect;
|
||||
}
|
||||
|
||||
|
@ -327,6 +393,10 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
|
|||
case P_DATA:
|
||||
res = doDATA(a, line, opinfo);
|
||||
break;
|
||||
case P_LUP:
|
||||
res = doLUP(a, line, opinfo);
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
|
3
psuedo.h
3
psuedo.h
|
@ -15,6 +15,7 @@ enum
|
|||
P_USE,
|
||||
P_HEX,
|
||||
P_DATA,
|
||||
P_LUP,
|
||||
|
||||
P_MAX
|
||||
};
|
||||
|
@ -30,6 +31,8 @@ public:
|
|||
int doDS(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
|
||||
int doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
|
||||
int doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
|
||||
int doLUP(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
|
||||
|
||||
};
|
||||
|
||||
#undef CLASS
|
15
src/main.s
15
src/main.s
|
@ -40,7 +40,7 @@ TSTADDR = $1000 ;absolute address for testing
|
|||
*==========================================================
|
||||
* Data Index DUM section test
|
||||
|
||||
lst
|
||||
lst off
|
||||
DUM 0
|
||||
dum0 ds 1 ;fractional byte
|
||||
dum1 ds 1
|
||||
|
@ -166,7 +166,6 @@ myQuit
|
|||
|
||||
org ;return to ongoing address
|
||||
|
||||
lst
|
||||
lda $FF
|
||||
;Issue #16 (fadden) - Byte reference modifiers are ignored (no way to force DP)
|
||||
lda <$fff0 ;zp
|
||||
|
@ -395,11 +394,17 @@ L00BC bit L00BC
|
|||
db |$01A55A,|$011234
|
||||
|
||||
|
||||
;lup 3
|
||||
;db 0
|
||||
;--^
|
||||
lst
|
||||
lup_start:
|
||||
lup 3
|
||||
;db 0 ; outside
|
||||
;lup 3
|
||||
;db 1 ; inside
|
||||
;--^
|
||||
--^
|
||||
|
||||
|
||||
lst off
|
||||
//]XCODEEND ; Keep this at the end and put your code above this
|
||||
;lst off
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user