Merge pull request #5 from lroathe/master

Fix P_HEX enum
This commit is contained in:
Lane Roathe 2019-11-14 18:50:40 -08:00 committed by GitHub
commit 80d1c739d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 207 additions and 75 deletions

View File

@ -9,9 +9,10 @@ set(LIBRARY_NAME pal)
set(FIND_LIBRARY_USE_LIB64_PATHS TRUE)
include(./lib${LIBRARY_NAME}/cmake/CMakeHeader.txt)
set ( PROJECT_NAME "qasm" )
set(SOURCE
${PROJECT_ROOT}/${PROJECT_ID}.cpp
${PROJECT_ROOT}/${PROJECT_NAME}.cpp
${PROJECT_ROOT}/asm.cpp
${PROJECT_ROOT}/opcodes.cpp
${PROJECT_ROOT}/eval.cpp

13
asm.cpp
View File

@ -348,7 +348,9 @@ void CLASS::complete(void)
uint64_t n = GetTickCount();
if (isDebug())
{
printf("Processing Time: %llu ms\n", n - starttime);
//cout << "Processing Time: " << n-starttime << " ms" << endl;
printf("Processing Time: %" PRIu64 " ms\n",n-starttime);
//printf("Processing Time: %llu ms\n", n - starttime);
}
}
@ -1048,7 +1050,8 @@ int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
if (isDebug() > 2)
{
int c = SetColor(CL_RED);
printf("eval Error=%d %08llX |%s|\n", res, result, eval.badsymbol.c_str());
cout << "eval Error=" << res << "0x" << std::hex << result << std::dec << eval.badsymbol << endl;
//printf("eval Error=%d %08llX |%s|\n", res, result, eval.badsymbol.c_str());
SetColor(c);
}
}
@ -1058,7 +1061,8 @@ int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
value = result;
if ((listing) && (pass > 0) && (isDebug() > 2))
{
printf("EV1=%08llX '%c'\n", v1, line.expr_shift);
cout << "EV1=0x" << std::hex << v1 << " '" << std::dec << line.expr_shift << ";" << endl;
//printf("EV1=%08llX '%c'\n", v1, line.expr_shift);
}
if (v1 >= 0x10000)
{
@ -1077,7 +1081,8 @@ int CLASS::evaluate(MerlinLine &line, std::string expr, int64_t &value)
}
if (isDebug() >= 3)
{
printf("Eval Result: %08llX (status=%d)\n", value, res);
cout << "Eval Result: 0x" << std::hex << value << std::dec << "(status=" << res << ")" << endl;
//printf("Eval Result: %08llX (status=%d)\n", value, res);
}
return (res);
}

View File

@ -731,7 +731,7 @@ void CLASS::insertOpcodes(void)
pushopcode("DB", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("ADR", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("ADRL", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("HEX", p_HEX, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("HEX", P_HEX, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DS", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DO", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("ELSE", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));

View File

@ -17,7 +17,7 @@ int CLASS::doDS(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
int res = 0;
int32_t v = line.expr_value;
if (line.eval_result!=0)
if (line.eval_result != 0)
{
line.setError(errForwardRef);
}
@ -29,13 +29,13 @@ int CLASS::doDS(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
res = v;
if (a.pass>0)
if (a.pass > 0)
{
for (int i=0;i<v;i++)
for (int32_t i = 0; i < v; i++)
{
line.outbytes.push_back(0x00);
}
line.outbytect=v;
line.outbytect = v;
}
}
@ -88,67 +88,69 @@ int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
int CLASS::doHEX(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
int res = 0;
std::vector<std::string> values;
values.clear();
int res = 0;
std::vector<std::string> values;
values.clear();
std::string os = Poco::toUpper(Poco::trim(line.operand));
std::string vs = "0123456789ABCDEF";
std::string hex = "";
std::string os = Poco::toUpper(Poco::trim(line.operand));
std::string vs = "0123456789ABCDEF";
std::string hex = "";
for( int i = 0; i < os.length(); ++i )
{
char c = os[i];
for ( uint32_t i = 0; i < os.length(); ++i )
{
char c = os[i];
// Check for a comma if needed, and continue to next char if found
if( hex.length() == 0 && c == ',' )
continue;
if( vs.find(c) == std::string::npos )
{
line.setError(errBadOperand);
return -1;
}
// Check for a comma if needed, and continue to next char if found
if ( hex.length() == 0 && c == ',' )
{
continue;
}
// Got a good char, append to hex string and see if we've got a byte
hex.append(1, c);
if( hex.length() == 2 )
{
// Got 2 chars (1 byte), so store in values array
values.push_back(hex);
hex.clear();
}
}
if ( vs.find(c) == std::string::npos )
{
line.setError(errBadOperand);
return -1;
}
// We can't have an odd character dangling around!
if( hex.size() != 0 )
{
line.setError(errOverflow);
return -1;
}
// Got a good char, append to hex string and see if we've got a byte
hex.append(1, c);
if ( hex.length() == 2 )
{
// Got 2 chars (1 byte), so store in values array
values.push_back(hex);
hex.clear();
}
}
int byteCnt = (int)values.size();
a.PC.currentpc += byteCnt;
// We can't have an odd character dangling around!
if ( hex.size() != 0 )
{
line.setError(errOverflow);
return -1;
}
if (a.pass > 0)
{
for( int i = 0; i < values.size(); ++i )
{
std::string s = "$";
s.append(values[i]);
int64_t v;
if( 0 == a.evaluate(line, s, v) )
{
line.outbytes.push_back((uint8_t)v);
}
}
line.outbytect = byteCnt;
}
int byteCnt = (int)values.size();
a.PC.currentpc += byteCnt;
if (a.pass > 0)
{
for ( uint32_t i = 0; i < values.size(); ++i )
{
std::string s = "$";
s.append(values[i]);
int64_t v;
if ( 0 == a.evaluate(line, s, v) )
{
line.outbytes.push_back((uint8_t)v);
}
}
line.outbytect = byteCnt;
}
else
{
line.pass0bytect = byteCnt;
}
return res;
{
line.pass0bytect = byteCnt;
}
return res;
}
int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
@ -175,16 +177,16 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
res = doDUM(a, line, opinfo);
break;
case P_ORG:
if (line.operand.length()>0)
if (line.operand.length() > 0)
{
a.PC.orgsave=a.PC.currentpc;
a.PC.orgsave = a.PC.currentpc;
a.PC.currentpc = line.expr_value;
line.startpc=line.expr_value;
line.startpc = line.expr_value;
}
else
{
a.PC.currentpc = a.PC.orgsave;
line.startpc=a.PC.orgsave;
line.startpc = a.PC.orgsave;
}
break;
@ -196,9 +198,9 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
res = doLST(a, line, opinfo);
break;
] case p_HEX:
res = doHEX(a, line, opinfo);
break;
case P_HEX:
res = doHEX(a, line, opinfo);
break;
}
return (res);
}

View File

@ -13,7 +13,7 @@ enum
P_DS,
P_PUT,
P_USE,
p_HEX,
P_HEX,
P_MAX
};

1
qasm.h
View File

@ -1,4 +1,5 @@
#pragma once
#include "inttypes.h"
#include "palPoco.h"
#include "pallogger.h"
#include "eventtask.h"

View File

@ -80,9 +80,13 @@ START
; --- Test all instructions in all their modes, with as many variants as possible ---
;adc (ZP,x)
adc (0,x)
adc ($80,x)
adc (_tmp,x)
adc (_tmp+0,x)
@ -185,6 +189,127 @@ myQuit
lda: $05
ldal $05
lda $45
lda $2345
lda $012345
ldaz $2345
lda: $45
ldal $012345
ldal $2345
ldal $45
lda <$2345
lda >$2345
lda <$012345
lda >$012345
lda ^$012345
lda |$012345
ora $45
ora $2345
ora $012345
oraz $2345
ora: $45
oral $012345
oral $2345
oral $45
ora <$2345
ora >$2345
ora <$012345
ora >$012345
ora ^$012345
ora |$012345
and $45
and $2345
and $012345
andz $2345
and: $45
andl $012345
andl $2345
andl $45
and <$2345
and >$2345
and <$012345
and >$012345
and ^$012345
and |$012345
eor $45
eor $2345
eor $012345
eorz $2345
eor: $45
eorl $012345
eorl $2345
eorl $45
eor <$2345
eor >$2345
eor <$012345
eor >$012345
eor ^$012345
eor |$012345
adc $45
adc $2345
adc $012345
adcz $2345
adc: $45
adcl $012345
adcl $2345
adcl $45
adc <$2345
adc >$2345
adc <$012345
adc >$012345
adc ^$012345
adc |$012345
sta $45
sta $2345
sta $012345
staz $2345
sta: $45
stal $012345
stal $2345
stal $45
sta <$2345
sta >$2345
sta <$012345
sta >$012345
sta ^$012345
sta |$012345
cmp $45
cmp $2345
cmp $012345
cmpz $2345
cmp: $45
cmpl $012345
cmpl $2345
cmpl $45
cmp <$2345
cmp >$2345
cmp <$012345
cmp >$012345
cmp ^$012345
cmp |$012345
sbc $45
sbc $2345
sbc $012345
sbcz $2345
sbc: $45
sbcl $012345
sbcl $2345
sbcl $45
sbc <$2345
sbc >$2345
sbc <$012345
sbc >$012345
sbc ^$012345
sbc |$012345
asll $1234
lda <$fff0+24 ;zp
lda >$fff0+24 ;ABS (lo word)
@ -235,14 +360,12 @@ L00BC bit L00BC
ldx L00BC,y
stx L00BC,y
* Data Storage Tests
hex 11,22,33,44,55,66,77,88,99
hex 11,22,33,44,55,66,77,88,99
hex 112233445566778899
hex aabb,cc,ddee,ff
//]XCODEEND ; Keep this at the end and put your code above this
lst off
;lst off