more options, cleanup of command line options

This commit is contained in:
Shawn Quick 2023-02-07 12:34:52 -08:00
parent 107598bb02
commit 88e0251a16
9 changed files with 268 additions and 164 deletions

13
.vscode/launch.json vendored
View File

@ -2,24 +2,25 @@
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"name": "Debug",
"type": "cppdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"program": "${workspaceFolder}/build/qasm",
"args": [
" -d -d -d",
"${workspaceFolder}/test.s"
"${workspaceFolder}/test.s",
"-s",
"-d"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": true,
//"externalConsole": true,
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
"value": "${env:PATH}:${workspaceFolder}/build"
},
{
"name": "OTHER_VALUE",

13
asm.cpp
View File

@ -34,6 +34,7 @@ void CLASS::print(uint32_t lineno)
uint32_t l, i, savpcol, pcol;
bool commentprinted = false;
uint8_t commentcol = tabs[2];
bool force=false;
uint32_t b = 4; // how many bytes show on the first line
@ -61,15 +62,17 @@ void CLASS::print(uint32_t lineno)
}
printf("\n");
}
force=true;
flags &= (~FLAG_NOLINEPRINT);
}
bool np=(flags & FLAG_NOLINEPRINT);
bool np=(flags & FLAG_NOLINEPRINT)?true:false;
if (options->isQuiet())
np=true;
if (options->isList())
np=false;
if (force)
np=false;
if (np)
{
return;
@ -553,9 +556,9 @@ CLASS::~CLASS()
{
}
void CLASS::setProduct(string product)
void CLASS::setLanguage(string lang)
{
options.setProduct(product);
options.setLanguage(lang);
}
void CLASS::errorOut(uint16_t code)
@ -2615,7 +2618,7 @@ void CLASS::process(void)
{
errorct++;
}
if (((!skiplist) && (listing) && (pass == 1)) || (line.errorcode != 0))
if (((!skiplist) && (listing) && (pass == 1)) || (line.errorcode != 0) || (options.isList()))
{
line.print(lineno);
}

2
asm.h
View File

@ -249,7 +249,7 @@ public:
virtual void process(void);
virtual void complete(void);
virtual void errorOut(uint16_t code);
virtual void setProduct(string product);
virtual void setLanguage(string lang);
};

View File

@ -18,9 +18,9 @@
]
},
"asm": {
"syntax": "merlin16plus",
"language": "merlin16plus",
"cpu": "M6502",
"startmx": 3,
"start_mx": 2,
"listmode": "on",
"casesen": true,
"start_lst": false,

View File

@ -21,16 +21,13 @@ programOption PAL::appOptions[] =
//{ "config", "f", "load configuration data from a <file>", "<file>", false, false},
{ "exec", "x", "execute a command [asm, link, format, script] default=asm", "<command>", false, false},
{ "objfile", "o", "write output to <objfile>", "<objfile>", false, false},
{ "instruction", "i", "force the CPU instruction set ('xc' ingored) [6502, 65C02, 65816]", "<cpu>", false, false},
{ "instruction", "i", "force the CPU instruction set ('xc' ignored) [6502, 65C02, 65816]", "<cpu>", false, false},
{ "type", "t", "enforce syntax/features/bugs of other assembler [qasm, merlin8, merlin16, merlin16plus, merlin32, orca, apw, mpw, lisa, ca65]", "<type>", false, false},
{ "quiet", "q", "print as little as possible, equivalent to lst off in the assembler ('lst' opcodes will be ignored)", "", false, true},
{ "list", "l", "force assembly listing ('lst' opcodes will be ignored)", "", false, true},
{ "color", "c", "colorize the output", "", false, true},
{ "parms", "p", "show the working parameters/options", "", false, true},
{ "settings", "s", "show the working settings/options", "", false, true},
{ "", "", "", "", false, false}
};
@ -85,20 +82,34 @@ int CLASS::runCommandLineApp(void)
std::string appPath;
std::string fname;
//uint32_t syntax;
string product="";
string language="";
string syn;
bool settings;
int res = -1;
ConfigOptions options;
//Poco::Util::Application::instance().config()
utils=new QUtils();
//LOG_NOTE << "this is it!" << endl;
startdirectory = Poco::Path::current();
appPath=utils->getAppPath();
if (commandargs.size() == 0)
settings=getBool("option.settings",false);
if (isDebug()>0)
{
printf("num args: %ld\n",commandargs.size());
for (unsigned long i=0; i<commandargs.size(); i++)
{
printf("commandarg[%ld] |%s|\n",i,commandargs[i].c_str());
}
}
//string help=getConfig("option.help","0");
//printf("help=|%s|\n",help.c_str());
//if(help!="0")
//{
// displayHelp();
// printf("help!\n");
// return(-4);
//}
if ((commandargs.size() == 0) && (!settings))
{
displayHelp();
return (res);
@ -110,20 +121,34 @@ int CLASS::runCommandLineApp(void)
options.ReadFile(Poco::Path::current()+"/parms.json");
syn="QASM";
//syn=options.GetString("assembler.syntax","QASM");
string cmdsyn = Poco::toUpper(getConfig("option.type", ""));
//printf("cmdsyn: |%s|\n",cmdsyn.c_str());
if (cmdsyn!="")
{
syn=cmdsyn; // if they overrode the syntax on the command line, use it
}
syn=Poco::toUpper(syn); // if they overrode the syntax on the command line, use it
syn=Poco::trim(syn);
syn=Poco::toUpper(syn);
product=Poco::trim(syn);
if (!options.supportedLanguage(syn))
{
printf("Unsupported Language Type\n");
return(-1);
}
syn=options.convertLanguage(syn);
if (settings)
{
int x=options.printDefaults(syn);
return(x);
}
language=syn;
if (isDebug()>0)
{
printf("SYNTAX: |%s|\n",syn.c_str());
printf("SYNTAX: |%s|\n",language.c_str());
}
try
@ -143,12 +168,18 @@ int CLASS::runCommandLineApp(void)
for (ArgVec::const_iterator it = commandargs.begin(); it != commandargs.end(); ++it)
{
int32_t format_flags=CONVERT_LINUX;
Poco::File fn(*it);
string arg=*it;
Poco::File fn(arg);
int x;
std::string p = fn.path();
Poco::Path path(p);
//logger().information(path.toString());
if (!fn.exists())
{
break;
}
std::string e = toUpper(path.getExtension());
std::string cmd = Poco::toUpper(getConfig("option.exec", "asm"));
@ -206,7 +237,7 @@ int CLASS::runCommandLineApp(void)
try
{
t->init();
t->setProduct(product);
t->setLanguage(language);
t->format_flags=format_flags;
std::string f = path.toString();
@ -240,7 +271,7 @@ int CLASS::runCommandLineApp(void)
try
{
t->init();
t->setProduct(product);
t->setLanguage(language);
std::string f = path.toString();
@ -277,7 +308,7 @@ int CLASS::runCommandLineApp(void)
try
{
t->init();
t->setProduct(product);
t->setLanguage(language);
std::string f = path.toString();
t->filename = f;

1
qasm.h
View File

@ -28,7 +28,6 @@ protected:
virtual void displayVersion();
public:
QOptions options;
};

View File

@ -1,87 +1,2 @@
#include <app.h>
#undef CLASS
#define CLASS QOptions
CLASS::CLASS()
{
jsonin="";
jsonobj=NULL;
parser.reset();
parser.setAllowComments(true);
}
int CLASS::ReadFile(string path)
{
int ret=-1;
Poco::FileInputStream fs(path);
Poco::StreamCopier::copyToString(fs,jsonin);
parser.reset();
parser.setAllowComments(true);
jsonobj=parser.parse(jsonin);
config.load(path);
//config.enumerate(key,range);
return(ret);
}
Dynamic::Var CLASS::GetObject(string name)
{
JSON::Query q(jsonobj);
Dynamic::Var jresult=q.find(name);
return(jresult);
}
bool CLASS::GetBool(string name, bool def)
{
bool res=def;
try
{
Dynamic::Var jresult=GetObject(name);
if (!jresult.isEmpty())
{
if (jresult.isArray())
{
}
else if (jresult.isBoolean())
{
res=jresult;
}
}
}
catch(...)
{
res=def;
}
return(res);
}
string CLASS::GetString(string name, string def)
{
string res=def;
try
{
Dynamic::Var jresult=GetObject(name);
if (!jresult.isEmpty())
{
if (jresult.isArray())
{
}
else if (jresult.isString())
{
res=jresult.toString();
}
}
}
catch(...)
{
res=def;
}
return(res);
}

View File

@ -1,6 +1,8 @@
#pragma once
#include "qasm.h"
using namespace Poco;
#define MAX_PREFIX 32
#define MODE_6502 0
@ -26,12 +28,19 @@
#define OPTION_M16_PLUS 0x8000
class myLayeredConfiguration : public Poco::Util::LayeredConfiguration
{
public:
myLayeredConfiguration() : Poco::Util::LayeredConfiguration() {};
~myLayeredConfiguration() {};
};
#undef CLASS
#define CLASS ConfigOptions
class CLASS
{
protected:
vector<shared_ptr<JSONConfiguration>> configs;
//vector<shared_ptr<JSONConfiguration>> configs;
public:
Poco::JSON::Parser parser;
@ -40,8 +49,8 @@ public:
uint16_t format_flags;
uint16_t cpu_mode;
string product;
uint16_t productlevel;
string language;
uint16_t langlevel;
string prefixes[MAX_PREFIX];
uint8_t start_mx;
@ -61,14 +70,14 @@ public:
int16_t linebytes;
int16_t overflowbytes;
//Poco::Util::LayeredConfiguration config;
myLayeredConfiguration config;
bool usecolor;
CLASS()
{
setDefaults();
setProduct("QASM");
setLanguage("QASM");
}
~CLASS()
{
@ -83,7 +92,7 @@ public:
bool useColor(void)
{
bool res=false;
if (getBool("option.color",false))
if (PAL::getBool("option.color",false))
{
res=true;
}
@ -97,17 +106,57 @@ public:
bool isQuiet(void)
{
bool res;
res=getBool("option.quiet",false);
res=PAL::getBool("option.quiet",false);
if (isDebug()>0)
{
res=false;
}
return(res);
}
bool isList(void)
{
bool res;
res=getBool("option.list",false);
res=PAL::getBool("option.list",false);
//printf("list: %d\n",res);
return(res);
}
int printDefaults(string lang)
{
int res=-1;
string l=Poco::toUpper(lang);
if (l=="")
{
l=Poco::toUpper(language);
}
if (l!="")
{
setLanguage(l);
setCurrent();
printf("Defaults for language (%s)\n",language.c_str());
printf("\tLanguage:\t\t\t\t\t%s\n",language.c_str());
printf("\t\tlanguageLevel:\t\t\t\t%d\n",langlevel);
printf("\t\tcpu_mode:\t\t\t\t%d\n",cpu_mode);
printf("\t\tstart_mx:\t\t\t\t%d\n",start_mx);
printf("\t\tPrefixes:\n");
for (int i=0; i<MAX_PREFIX; i++)
{
if (prefixes[i].length()>0)
{
printf("\t\t\t%02d:\t\t\t%s\n",i,prefixes[i].c_str());
}
}
//uint16_t format_flags;
//bool start_listmode;
//bool listmode;
}
return(res);
}
@ -148,6 +197,7 @@ public:
if (success)
{
//configs.push_back(shared_ptr<JSONConfiguration>(jc));
config.add(jc);
ret=0;
}
else
@ -159,13 +209,6 @@ public:
return(ret);
}
void printCurrentOptions(void)
{
printf("Current Options:");
printf(" product: %s\n",product.c_str());
//printf(" start_mx: \%%02d\n",start_mx);
}
bool isMerlin32(void)
{
return(true);
@ -176,11 +219,15 @@ public:
return(false);
}
void setCurrent(void)
{
start_mx=GetInteger("asm.start_mx",3);
}
void setDefaults(void)
{
cpu_mode=MODE_6502;
product="QASM";
productlevel=0;
language="QASM";
langlevel=0;
for (int i=0; i<MAX_PREFIX; i++)
{
prefixes[i]="";
@ -204,43 +251,149 @@ public:
usecolor=true;
}
void setProduct(string productName)
void setLanguage(string lang)
{
string old=productName;
string pn=Poco::toUpper(productName);
//printf("request language options to %s from %s\n",lang.c_str(),language.c_str());
string old=language;
string pn=Poco::toUpper(lang);
if (old!=pn)
{
printf("setting product options to %s\n",pn.c_str());
productName=pn;
//printf("setting language options to %s\n",pn.c_str());
language=pn;
setCurrent();
if (pn=="QASM")
{
setQASM();
}
}
}
string convertLanguage(string lang)
{
string res;
res=lang;
res=trim(res);
res=toUpper(res);
if (res=="MERLIN16+")
{
res="MERLIN16PLUS";
}
if (res=="MERLIN8")
{
res="MERLIN";
}
return(res);
}
bool supportedLanguage(string lang)
{
bool res=false;
string r=toUpper(lang);
r=trim(r);
r=trim(r);
if (r=="MERLIN")
{
res=true;
}
else if (r=="MERLIN8")
{
res=true;
}
else if (r=="MERLIN16")
{
res=true;
}
else if (r=="MERLIN16PLUS")
{
res=true;
}
else if (r=="MERLIN16+")
{
res=true;
}
else if (r=="MERLIN32")
{
res=true;
}
else if (r=="QASM")
{
res=true;
}
return(res);
}
void setQASM()
{
}
bool GetBool(string name, bool def)
{
bool res=def;
try
{
//Dynamic::Var jresult=GetObject(name);
//if (!jresult.isEmpty())
//{
// if (jresult.isArray())
// {
// }
// else if (jresult.isBoolean())
// {
// res=jresult;
// }
//}
}
catch(...)
{
res=def;
}
return(res);
}
string GetString(string name, string def)
{
string res=def;
try
{
//config
}
catch(...)
{
res=def;
}
return(res);
}
int32_t GetInteger(string name, int32_t def)
{
int32_t res=def;
#if 0
std::vector<std::string> keys;
config.keys(keys);
for (unsigned int i=0;i<keys.size();i++)
{
printf("key[%d]: %s\n",i,keys[i].c_str());
}
#endif
try
{
res=config.getInt(name);
}
catch(...)
{
res=def;
//throw;
}
return(res);
}
};
#undef CLASS
#define CLASS QOptions
class CLASS
{
public:
Poco::Util::JSONConfiguration config;
Poco::JSON::Parser parser;
string jsonin;
Dynamic::Var jsonobj=NULL;
CLASS();
int ReadFile(string path);
Dynamic::Var GetObject(string name);
bool GetBool(string name, bool def=false);
string GetString(string name, string def="");
};
#undef CLASS

12
test.s
View File

@ -1,8 +1,10 @@
lst off
* [QASM] SYNTAX MERLIN16
* [QASM] Filetype $06
* [QASM] AuxType $2000
* [QASM] Volume TESTASM test.2mg 800K prodos 2mg
* [QASM] save TESTASM :SOURCE:${FILE}.bin
* [QASM] copyto TESTASM :SOURCE:${FILE}.bin
xc off
@ -20,7 +22,7 @@ begin
;]m equ *
; lda begin
; lda ]m
lst on
;lst on
;end
_mymac mac
@ -32,7 +34,7 @@ _mymac mac
_ascmac mac
asc ]1,]2,8D
eom
lst off
;lst off
;var 'one';'two';'three'
justlable ;line with just a lable
start
@ -51,9 +53,9 @@ another lda #$00 ;line with everything
--^
]1 nop
nop
lst
;lst
bra ]1
;typ $06
sav 0/test.bin
lst off
;lst off