merge point

This commit is contained in:
marketideas 2019-11-12 20:32:10 -08:00
parent 308c485a11
commit aa439c41b1
12 changed files with 168 additions and 102 deletions

View File

@ -22,6 +22,7 @@ include_directories(BEFORE
${PROJECT_ROOT}
${PROJECT_ROOT}/lib${LIBRARY_NAME}/include/${LIBRARY_NAME}
${Poco_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
)
add_subdirectory(${PROJECT_ROOT}/lib${LIBRARY_NAME})
@ -30,11 +31,20 @@ include(${PROJECT_ROOT}/lib${LIBRARY_NAME}/cmake/CMakeApp.txt)
add_executable( ${PROJECT_NAME} ${SOURCE})
#message ( STATUS "OpenSSL Libraries: " ${OPENSSL_LIBRARIES} )
#message ( STATUS "OpenSSL Include : " ${OPENSSL_INCLUDE_DIR} )
#message ( STATUS "Poco Libraries : " ${Poco_LIBRARIES} )
#message ( STATUS "Poco Include : " ${Poco_INCLUDE_DIRS} )
#message ( STATUS "Poco Found : " ${Poco_FOUND} )
#message ( STATUS "Poco Found : " ${CMAKE_SOURCE_DIR} )
target_link_libraries (
${PROJECT_NAME}
${LIBRARY_NAME}
pthread
${Poco_LIBRARIES}
${OPENSSL_LIBRARIES}
)
include(./lib${LIBRARY_NAME}/cmake/CMakeCommands.txt)

View File

@ -35,11 +35,13 @@ install:
reformat:
qasm -r src/main.s
asm:
test1:
qasm src/main.s
-qasm src/main.s
test2:
qasm src/testfile.s
-qasm src/testfile.s

178
asm.cpp
View File

@ -25,7 +25,8 @@ void CLASS::setError(uint32_t ecode)
void CLASS::print(uint32_t lineno)
{
int i, l;
int i, l, pcol;
int commentcol = 40;
l = outbytect;
@ -56,58 +57,78 @@ void CLASS::print(uint32_t lineno)
}
int b = 4;
//printf("%02X ", addressmode);
//printf("%6d", lineno + 1);
pcol = 0;
if (!empty)
{
printf("%02X/%04X:", (startpc >> 16), startpc & 0xFFFF);
pcol += printf("%02X/%04X:", (startpc >> 16), startpc & 0xFFFF);
}
else
{
printf(" ");
pcol += printf(" ");
}
for (i = 0; i < l; i++)
{
printf("%02X ", outbytes[i]);
pcol += printf("%02X ", outbytes[i]);
}
for (i = l; i < b; i++)
{
printf(" ");
pcol += printf(" ");
}
if (showmx)
{
if (outbytect > 0)
{
printf("%%%c%c ", linemx & 02 ? '1' : '0', linemx & 01 ? '1' : '0');
pcol += printf("%%%c%c ", linemx & 02 ? '1' : '0', linemx & 01 ? '1' : '0');
}
else
{
printf(" ");
pcol += printf(" ");
}
}
if (isDebug() > 1)
{
printf("%02X ", addressmode & 0xFF);
pcol += printf("%02X ", addressmode & 0xFF);
}
printf("%6d ", lineno + 1);
pcol += printf("%6d ", lineno + 1);
pcol = 0; // reset pcol here because this is where source code starts
if (empty)
{
printf("%s", comment.c_str());
if (comment.length() > 0)
{
if (comment[0] == ';')
{
while (pcol < commentcol)
{
pcol += printf(" ");
}
}
pcol += printf("%s", comment.c_str());
}
}
else
{
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());
if (errorcode > 0)
{
printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str());
while (pcol < commentcol)
{
pcol += printf(" ");
}
pcol += printf(":[Error] %s %s", errStrings[errorcode].c_str(), errorText.c_str());
}
else
{
printf("%s", comment.c_str());
while (pcol < commentcol)
{
pcol += printf(" ");
}
pcol += printf("%s", comment.c_str());
}
}
if (errorcode > 0)
@ -448,30 +469,30 @@ CLASS::~CLASS()
void CLASS::init(void)
{
std::string s;
int ts,tabpos;
int ts, tabpos;
lines.clear();
std::string tabstr=getConfig("reformat.tabs","8,16,32");
tabstr=Poco::trim(tabstr);
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)
Poco::StringTokenizer t(tabstr, ",;", 0);
tabpos = 0;
for (auto itr = t.begin(); itr != t.end(); ++itr)
{
s=Poco::trim(*itr);
s = Poco::trim(*itr);
try
{
ts=Poco::NumberParser::parse(s);
ts = Poco::NumberParser::parse(s);
}
catch(...)
catch (...)
{
ts=0;
ts = 0;
}
if ((ts>=0) && (ts<240))
if ((ts >= 0) && (ts < 240))
{
tabs[tabpos++]=ts;
tabs[tabpos++] = ts;
}
}
}
@ -486,7 +507,7 @@ int CLASS::doline(int lineno, std::string line)
void CLASS::process(void)
{
uint32_t len, t,pos;
uint32_t len, t, pos;
uint32_t ct = lines.size();
@ -494,38 +515,62 @@ void CLASS::process(void)
{
MerlinLine &line = lines[lineno];
pos=0;
pos = 0;
len = 0;
t = tabs[pos++];
len = printf("%s ", line.printlable.c_str());
while (len < t)
if ((line.lable.length() == 0)
&& (line.opcode.length() == 0)
&& (line.operand.length() == 0))
{
len += printf(" ");
if (line.comment.length() > 0)
{
char c = line.comment[0];
if ((c == '*') || (c == '/'))
{
printf("%s", line.comment.c_str());
}
else
{
t = tabs[2];
while (len < t)
{
len += printf(" ");
}
printf("%s", line.comment.c_str());
}
}
printf("\n");
}
t = tabs[pos++];
len = printf("%s ", line.opcode.c_str());
while (len < t)
else
{
len += printf(" ");
}
t = tabs[pos++];
len = printf("%s ", line.printlable.c_str());
while (len < t)
{
len += printf(" ");
}
t = tabs[pos++];
len = printf("%s ", line.operand.c_str());
while (len < t)
{
len += printf(" ");
}
t = tabs[pos++];
len += printf("%s ", line.opcode.c_str());
while (len < t)
{
len += printf(" ");
}
t = tabs[pos++];
len = printf("%s", line.comment.c_str());
while (len < t)
{
len += printf(" ");
}
len+=printf("\n");
t = tabs[pos++];
len += printf("%s ", line.operand.c_str());
while (len < t)
{
len += printf(" ");
}
t = tabs[pos++];
len += printf("%s", line.comment.c_str());
while (len < t)
{
len += printf(" ");
}
len += printf("\n");
}
}
}
@ -848,8 +893,8 @@ void CLASS::initpass(void)
skiplist = false;
origin = 0x8000;
currentpc = origin;
PC.origin = 0x8000;
PC.currentpc = PC.origin;
s = getConfig("asm.cpu", "M65816");
s = Poco::trim(Poco::toUpper(s));
@ -878,18 +923,22 @@ void CLASS::initpass(void)
}
relocatable = false;
currentsym = NULL;
totalbytes = 0;
PC.totalbytes = 0;
lineno = 0;
errorct = 0;
passcomplete = false;
variables.clear(); // clear the variables for each pass
while (!PCstack.empty())
{
PCstack.pop();
}
savepath = "";
}
void CLASS::complete(void)
{
printf("\n\n=== Assembly Complete: %d bytes %u errors.\n", totalbytes, errorct);
printf("\n\n=== Assembly Complete: %d bytes %u errors.\n", PC.totalbytes, errorct);
if (savepath != "")
{
@ -1014,9 +1063,12 @@ int CLASS::getAddrMode(MerlinLine & line)
if ((s != "^") && (s != "<") && (s != ">") && (s != "|"))
{
bool v = true;
if (i > 0)
if (mode == syn_abs)
{
v = valEx.match(s, 0, 0);
if (i > 0)
{
v = valEx.match(s, 0, 0);
}
}
if (!v)
{
@ -1098,7 +1150,7 @@ void CLASS::process(void)
op = Poco::toLower(line->opcode);
operand = Poco::toLower(line->operand);
line->startpc = currentpc;
line->startpc = PC.currentpc;
line->linemx = mx;
line->bytect = 0;
line->showmx = showmx;
@ -1118,7 +1170,7 @@ void CLASS::process(void)
case ':':
break;
default:
sym = addSymbol(line->lable, currentpc, false);
sym = addSymbol(line->lable, PC.currentpc, false);
if (sym == NULL) { dupsym = true; }
break;
}
@ -1161,8 +1213,8 @@ void CLASS::process(void)
line->errorText = line->operand_expr;
}
line->bytect = x;
currentpc += x;
totalbytes += x;
PC.currentpc += x;
PC.totalbytes += x;
}
if (pass == 0)
{

18
asm.h
View File

@ -94,6 +94,14 @@ enum
#define FLAG_LONGADDR 0x01
class TOriginSection
{
public:
uint32_t origin;
uint32_t currentpc;
uint32_t totalbytes;
};
class MerlinLine
{
public:
@ -156,7 +164,7 @@ class TMerlinConverter : public TFileProcessor
protected:
uint8_t tabs[10];
std::vector<MerlinLine> lines;
public:
TMerlinConverter();
virtual ~TMerlinConverter();
@ -216,9 +224,10 @@ public:
bool passcomplete;
bool relocatable;
bool skiplist; // used if lst is on, but LST opcode turns it off
uint32_t totalbytes;
uint32_t lineno;
uint32_t origin;
//uint32_t origin;
//uint32_t currentpc;
std::string savepath;
TSymbol *currentsym;
std::vector<MerlinLine> lines;
@ -227,10 +236,11 @@ public:
Poco::HashMap<std::string, TSymbol> symbols;
Poco::HashMap<std::string, TSymbol> variables;
TOriginSection PC;
std::stack<TOriginSection> PCstack;
TPsuedoOp *psuedoops;
uint16_t pass;
uint32_t currentpc;
T65816Asm();
virtual ~T65816Asm();

View File

@ -50,6 +50,8 @@
set(Poco_HINTS
/usr/local
/usr/local/include
/usr/include
C:/AppliedInformatics
${Poco_DIR}
$ENV{Poco_DIR}

View File

@ -218,7 +218,7 @@ std::deque<Token> CLASS::shuntingYard(const std::deque<Token>& tokens)
token.type = Token::Type::Number;
if (token.str == "*")
{
sprintf(buff, "%u", assembler.currentpc);
sprintf(buff, "%u", assembler.PC.currentpc);
token.str = buff;
}
else

View File

@ -696,8 +696,8 @@ void CLASS::insertOpcodes(void)
pushopcode("SAV", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("TYP", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("END", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doEND));
pushopcode("DUM", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DEND", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DUM", P_DUM, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DEND",P_DEND, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("AST", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("CYC", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));
pushopcode("DAT", 0x00, OP_PSUEDO, OPHANDLER(&CLASS::doPSEUDO));

View File

@ -12,6 +12,13 @@ CLASS::~CLASS()
}
int CLASS::doDUM(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
int res=-1;
bool isdend=((opinfo.opcode==P_DEND)?true:false);
return(res);
}
int CLASS::doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
{
std::string s;
@ -43,10 +50,12 @@ int CLASS::ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo)
default:
res = -1; // undefined p-op
line.setError(errUnimplemented);
break;
case P_DUM:
case P_DEND:
res=doDUM(a,line,opinfo);
case P_ORG:
a.currentpc = line.expr_value;
a.PC.currentpc = line.expr_value;
break;
case P_SAV:
a.savepath = line.operand;

View File

@ -8,6 +8,8 @@ enum
P_ORG = 1,
P_LST,
P_SAV,
P_DUM,
P_DEND,
P_MAX
};
@ -19,6 +21,8 @@ public:
~CLASS();
int ProcessOpcode(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
int doLST(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
int doDUM(T65816Asm &a, MerlinLine &line, TSymbol &opinfo);
};

View File

@ -27,7 +27,8 @@ cpu=M65816
trackrep=false
[reformat]
tabs=12; 16; 20
tabs=12; 18; 36
;tabs=0;0;0

View File

@ -10,34 +10,8 @@
xc
xc
mx %00
exprdp = $A5
expr = $6789
exprL = $123456
//]XCODESTART ; Keep this at the start and put your code after this
lda expr,S
lda (expr,S),Y
lda #expr
lda (expr,X)
lda (expr),y
lda (expr)
lda [exprL],x
lda [exprL]
lda expr,x
lda expr,y
mvp expr,expr1
lda expr
lda expr
ldal expr
jmp expr
jmp (expr)
lda #<exprL
lda #>exprL
lda #^exprL
lda #|exprL
end
*==========================================================
* monitor addresses

View File

@ -208,13 +208,15 @@ startA0
ldx dp
lda [dp]
tay
lda #immed
lda #10
tax
plb
ldy expr
lda expr
ldx expr
ldal lexpr
lst off
end
startB0
bcs startB0