Merge pull request #11 from lroathe/master

HEX fix, start of ASC work
This commit is contained in:
Lane Roathe 2019-11-17 16:16:45 -08:00 committed by GitHub
commit 60bc85a823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 134 additions and 73 deletions

23
asm.cpp
View File

@ -56,7 +56,7 @@ void CLASS::print(uint32_t lineno)
printf("\n%s in line: %d", errStrings[errorcode].c_str(), lineno + 1);
if (errorText != "")
{
printf("%s", errorText.c_str());
printf(" (%s)", errorText.c_str());
}
printf("\n");
}
@ -213,7 +213,11 @@ void CLASS::print(uint32_t lineno)
{
pcol += printf(" ");
}
pcol += printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str());
pcol += printf(":[Error] %s", errStrings[errorcode].c_str());
if (errorText.length() > 0)
{
pcol += printf(" (%s)",errorText.c_str());
}
}
else if (!commentprinted)
{
@ -1357,7 +1361,6 @@ void CLASS::initpass(void)
s = Poco::trim(Poco::toUpper(s));
cpumode = MODE_65816;
mx = 0x00;
if (s == "M65816")
{
@ -1377,10 +1380,15 @@ void CLASS::initpass(void)
else
{
printf("Unknown CPU type in .ini\n");
mx = 0x00;
}
mx = getInt("asm.startmx", mx);;
savepath = getConfig("option.objfile", "");
relocatable = false;
currentsym = NULL;
currentsymstr="";
currentsymstr = "";
lineno = 0;
errorct = 0;
passcomplete = false;
@ -1407,7 +1415,6 @@ void CLASS::initpass(void)
}
curLUP.clear();
curDO.clear();
savepath = "";
}
void CLASS::complete(void)
@ -1419,10 +1426,6 @@ 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);
@ -1763,7 +1766,7 @@ void CLASS::process(void)
if (c != ':')
{
currentsym = findSymbol(line.lable);
currentsymstr=line.lable;
currentsymstr = line.lable;
}
break;
}

View File

@ -182,7 +182,7 @@ int CLASS::doMVN(MerlinLine &line, TSymbol &sym)
{
value = 0xFFFFFFFF;
line.setError(errBadOperand);
line.errorText = line.operand_expr2;
//line.errorText = line.operand_expr2;
}
setOpcode(line, op);
@ -226,7 +226,7 @@ int CLASS::doNoPattern(MerlinLine &line, TSymbol &sym)
op = (m == syn_abs ? 0x64 : op);
op = (m == syn_absx ? 0x74 : op);
if ((op != 0) && (line.expr_value >= 0x100))
if ((op != 0) && ((line.expr_value >= 0x100) || (line.flags&FLAG_FORCEABS)))
{
res++;
op = (op == 0x64) ? 0x9C : op;
@ -236,7 +236,7 @@ int CLASS::doNoPattern(MerlinLine &line, TSymbol &sym)
case 2: // TSB
res++;
op = (m == syn_abs ? 0x04 : op);
if ((op != 0) && (line.expr_value >= 0x100))
if ((op != 0) && ((line.expr_value >= 0x100) || (line.flags&FLAG_FORCEABS)))
{
res++;
op = 0x0C;
@ -245,7 +245,7 @@ int CLASS::doNoPattern(MerlinLine &line, TSymbol &sym)
case 3: // TRB
res++;
op = (m == syn_abs ? 0x14 : op);
if ((op != 0) && (line.expr_value >= 0x100))
if ((op != 0) && ((line.expr_value >= 0x100) || (line.flags&FLAG_FORCEABS)))
{
res++;
op = 0x1C;
@ -487,14 +487,9 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym)
cc = 0x01;
op = 0x80;
bbb = 0x02;
//if ((mx&0x02)==0)
//{
// bytelen++;
//}
}
else if ((bbb > 0) && (line.expr_value >= 0x100))
else if ((bbb > 0) && ((line.expr_value >= 0x100) || (line.flags&FLAG_FORCEABS)))
{
bbb |= 0x02;
bytelen++;
@ -576,6 +571,10 @@ int CLASS::doBase6502(MerlinLine & line, TSymbol & sym)
bytelen++;
}
}
if ( ((m==syn_absx) || (m==syn_diix)) && ((sym.opcode==4) || (sym.opcode==5))) // these are STX,LDX
{
err=true;
}
if ((m == syn_absx) || (m == syn_abs) || (m == syn_absy))
{
if ((line.flags & FLAG_FORCEABS) || (line.expr_value >= 0x100))
@ -829,7 +828,7 @@ void CLASS::insertOpcodes(void)
pushopcode("BNE", 0x03, 0, OPHANDLER(&CLASS::doBRANCH));
pushopcode("BPL", 0x00, 0, OPHANDLER(&CLASS::doBRANCH));
pushopcode("BRA", 0x40, 0, OPHANDLER(&CLASS::doBRANCH));
pushopcode("BRK", 0x00, 0, OPHANDLER(&CLASS::doBYTE));
pushopcode("BRK", 0x00, 1, OPHANDLER(&CLASS::doAddress));
pushopcode("BRL", 0x20, 0, OPHANDLER(&CLASS::doBRANCH));
pushopcode("BVC", 0x01, 0, OPHANDLER(&CLASS::doBRANCH));
pushopcode("BVS", 0x81, 0, OPHANDLER(&CLASS::doBRANCH));

View File

@ -221,8 +221,11 @@ int CLASS::doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
int outct = 0;
int wordsize = 2;
int endian = 0;
std::string oper = line.operand_expr;
std::string oper = line.operand;
std::string op = Poco::toUpper(Poco::trim(line.opcode));
//printf("DFB TOK1 : |%s|\n", oper.c_str());
Poco::StringTokenizer tok(oper, ",", Poco::StringTokenizer::TOK_TRIM |
Poco::StringTokenizer::TOK_IGNORE_EMPTY);
@ -255,38 +258,49 @@ int CLASS::doDATA(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
for (auto itr = tok.begin(); itr != tok.end(); ++itr)
{
//printf("%s\n",(*itr).c_str());
//evaluate each of these strings, check for errors on pass 2
std::string expr = *itr;
//printf("DFB TOK : |%s|\n", expr.c_str());
int64_t eval_result = 0;
uint8_t shift;
int r;
uint8_t b;
shift = 0;
r = eval.evaluate(expr, eval_result, shift);
if (r < 0)
if (expr.length() > 0)
{
//printf("eval error %d |%s|\n", r,expr.c_str());
if (a.pass > 0)
if (expr[0] == '#')
{
line.setError(errBadEvaluation);
expr[0] = ' ';
expr = Poco::trim(expr);
}
shift = 0;
eval_result = 0;
//printf("DFB EVAL: |%s|\n", expr.c_str());
r = eval.evaluate(expr, eval_result, shift);
if (r < 0)
{
//printf("error\n");
if (a.pass > 0)
{
line.setError(errBadEvaluation);
}
}
if (shift == '>')
{
eval_result = (eval_result) & 0xFF;
}
if (shift == '<')
{
eval_result = (eval_result >> 8) & 0xFF;
}
else if ((shift == '^') || (shift == '|'))
{
eval_result = (eval_result >> 16) & 0xFF;
}
}
if (shift == '>')
{
eval_result = (eval_result) & 0xFF;
}
if (shift == '<')
{
eval_result = (eval_result >> 8) & 0xFF;
}
else if ((shift == '^') || (shift == '|'))
{
eval_result = (eval_result >> 16) & 0xFF;
}
outct += wordsize;
if (a.pass > 0)
@ -375,10 +389,10 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
if (a.pass > 0)
{
s = Poco::toUpper(Poco::trim(line.operand_expr));
if (s=="")
if (s == "")
{
a.listing=true;
a.skiplist=true;
a.listing = true;
a.skiplist = true;
}
else if (s == "RTN")
{
@ -427,44 +441,47 @@ int CLASS::doTR(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
}
return (0);
}
char hexVal( char c )
{
char v = -1;
if ((c >= '0') && (c <= '9'))
{
v = c - '0';
}
else if ((c >= 'a') && (c <= 'f'))
{
v = c - 'a' + 10;
}
else if ((c >= 'A') && (c <= 'F'))
{
v = c - 'A' + 10;
}
return v;
}
int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
UNUSED(opinfo);
std::string os = Poco::toUpper(Poco::trim(line.operand_expr));
std::string os = Poco::trim(line.operand);
uint32_t bytect = 0;
uint8_t b = 0;
uint8_t ct = 0;
if (os.length() == 0)
{
// case where HEX has no operand, Merlin does not flag as error
//line.setError(errIllegalCharOperand);
bytect = 0;
goto out;
}
for ( uint32_t i = 0; i < os.length(); ++i )
{
char c = os[i];
if ((c >= '0') && (c <= '9'))
{
c = c - '0';
}
else if ((c >= 'a') && (c <= 'f'))
{
c = c - 'a' + 10;
}
else if ((c >= 'A') && (c <= 'F'))
{
c = c - 'A' + 10;
}
else if (c == ',')
if (c == ',')
{
continue;
}
else
c = hexVal(c);
if( c < 0 )
{
line.setError(errIllegalCharOperand);
bytect = 0;
@ -492,6 +509,7 @@ int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
bytect++;
}
}
if (ct & 0x01) // we got an odd number of nibbles
{
line.setError(errBadOperand);
@ -502,7 +520,6 @@ out:
return bytect;
}
int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
int res = 0;
@ -560,7 +577,7 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
res = doDO(a, line, opinfo);
break;
case P_TR:
res=doTR(a,line,opinfo);
res = doTR(a, line, opinfo);
break;
}

View File

@ -20,6 +20,8 @@ programOption PAL::appOptions[] =
#endif
//{ "config", "f", "load configuration data from a <file>", " <file>", false, false},
{ "exec", "x", "execute a command [asm, link, reformat] default=asm", " <command>", false, false},
{ "objfile", "o", "write output to file", " <file>", false, false},
{ "", "", "", "", false, false}
};

View File

@ -21,7 +21,8 @@ path5=dirpath5
[asm]
casesen=true
showmx=false
showmx=true
startmx=3
lst=true
; can be M6502, M65C02, M65816
cpu=M65816

31
runtests.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
OUTDIR=./testout
TMPFILE=/tmp/qasm_out.txt
rm -f $TMPFILE
rm -rf $OUTDIR
mkdir -p $OUTDIR
SRC=`ls ./testdata`
for S in $SRC ; do
rm -f $TMPFILE
S1=$S
S1=${S1/.S/.bin}
S1=${S1/.s/.bin}
./qasm -o 0/$OUTDIR/$S1 ./testdata/$S >> $TMPFILE
R=?$
echo $S " " $S1
cat $TMPFILE | grep "End qASM assembly"
done
ls -l $OUTDIR

View File

@ -360,11 +360,12 @@ L00BC bit L00BC
* Data Storage Tests
hex ;no error
hex 11,22,33,44,55,66,77,88,99
hex 112233445566778899F
hex 112233445I566778899FF
hex aabb,CC,0123456789ABCDEFabcdef,ff
hex aabb,CC,0123456789abcdefABCDEF,ff
ds 36
da $A55A

View File

@ -2,6 +2,8 @@
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Assembler: Merlin 32
ABS equ $A55A
ZP equ $FF
ORG $1000

View File

@ -2,6 +2,11 @@
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Assembler: Merlin 32
MV0 equ $FE0000
MV1 equi $FF0000
ABS equ $A55A
ZP equ $FF
ORG $1000

View File

@ -2,7 +2,8 @@
; See the LICENSE.txt file for distribution terms (Apache 2.0).
;
; Assembler: Merlin 32
ABS equ $A55A
ZP equ $FF
ORG $1000
JSR PostBRK

1
testdata/qasm vendored
View File

@ -1 +0,0 @@
../qasm