Skip to content

Commit

Permalink
Mnemonic redefinition enhancements
Browse files Browse the repository at this point in the history
Made mnemo directive more capable
Added accparm option for 650x
  • Loading branch information
Arakula committed Oct 11, 2022
1 parent 7b897ba commit 6ada59c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Dasm6500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ forceExtendedAddr = true;
forceDirectAddr = true;
closeCC = false;
useDPLabels = false;
accparm = true;
textZpgAddr = "p-<";
textAbsAddr = "p->";

Expand Down Expand Up @@ -286,6 +287,9 @@ AddOption("forcezpgaddr","{string}\tstring pattern to use for forced zero-page a
AddOption("forceabsaddr","{string}\tstring pattern to use for forced absolute addressing",
static_cast<PSetter>(&Dasm650X::Set6500Option),
static_cast<PGetter>(&Dasm650X::Get6500Option));
AddOption("accparm","{string}\taccumulator addressing sets parameter",
static_cast<PSetter>(&Dasm650X::Set6500Option),
static_cast<PGetter>(&Dasm650X::Get6500Option));
}

/*****************************************************************************/
Expand Down Expand Up @@ -334,6 +338,11 @@ else if (lname == "forcezpgaddr")
textZpgAddr = value;
else if (lname == "forceabsaddr")
textAbsAddr = value;
else if (lname == "accparm")
{
accparm = bnValue;
return bIsBool ? 1 : 0;
}
else
return 0; /* only name consumed */

Expand Down Expand Up @@ -361,6 +370,8 @@ else if (lname == "forcezpgaddr")
return textZpgAddr;
else if (lname == "forceabsaddr")
return textAbsAddr;
else if (lname == "accparm")
return accparm ? "on" : "off";

return "";
}
Expand Down Expand Up @@ -911,7 +922,8 @@ switch (mode) /* which mode is this? */
// no need to do anything
break;
case _acc: /* accumulator */
sparm = MnemoCase("A");
if (accparm)
sparm = MnemoCase("A");
break;

case _imm: /* immediate byte */
Expand Down
1 change: 1 addition & 0 deletions Dasm6500.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Dasm650X :
bool forceExtendedAddr;
bool forceDirectAddr;
bool useDPLabels;
bool accparm;
string textAbsAddr, textZpgAddr;
};

Expand Down
57 changes: 57 additions & 0 deletions dasmfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,62 @@ if (!labelEqus || showCode)
return sz;
}

/*****************************************************************************/
/* PostprocessLine : post-process line if mnemonic dictates so */
/*****************************************************************************/

bool Application::PostprocessLine
(
string &sLabel,
string &smnemo,
string &sparm,
string &scomment,
int &labelLen
)
{
size_t pos = smnemo.find("$(");
while (pos != string::npos) /* mnemo containing $( is special, */
{
if (pos > 0 && smnemo[pos - 1] == '\\')
{
smnemo = smnemo.substr(0, pos) + smnemo.substr(pos + 1);
}
else
{
size_t endpos = smnemo.substr(pos).find(")");
if (endpos == string::npos)
break;
endpos++;
string part = lowercase(smnemo.substr(pos, endpos));
if (part == "$(label)")
{
string labelDelim = pDasm->GetOption("ldchar");
if (labelDelim.size() && sLabel.size() &&
sLabel.substr(sLabel.size() - labelDelim.size()) == labelDelim)
sLabel = sLabel.substr(0, sLabel.size() - labelDelim.size());
smnemo = smnemo.substr(0, pos) + sLabel + smnemo.substr(pos + endpos);
sLabel = "";
}
else if (part == "$(parm)")
{
smnemo = smnemo.substr(0, pos) + sparm + smnemo.substr(pos + endpos);
sparm = "";
}
else if (part == "$(<<)")
{
smnemo = smnemo.substr(0, pos) + smnemo.substr(pos + endpos);
sLabel = smnemo;
smnemo = sparm;
sparm = "";
pos = (size_t)-1;
}
}
pos = smnemo.find("$(", pos + 1);
}

return true;
}

/*****************************************************************************/
/* PrintLine : prints a formatted line to the output */
/*****************************************************************************/
Expand All @@ -927,6 +983,7 @@ if (labelLen < 0) labelLen = this->labelLen;
int nLen = 0;
int nMinLen = labelLen;

PostprocessLine(sLabel, smnemo, sparm, scomment, labelLen);
if (sLabel.size())
{
nLen += fprintf(out, "%s", sLabel.c_str());
Expand Down
3 changes: 2 additions & 1 deletion dasmfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ using namespace std;
/* Global definitions */
/*****************************************************************************/

#define DASMFW_VERSION "0.32"
#define DASMFW_VERSION "0.33"

// set these to int64_t once 64bit processors become part of the framework
typedef uint32_t cadr_t; /* container for maximal code address*/
Expand Down Expand Up @@ -229,6 +229,7 @@ class Application
adr_t DisassembleLine(adr_t addr, string sComDel, string sComHdr, string labelDelim, int bus = BusCode);
bool PrintLine(string sLabel = "", string smnemo = "", string sparm = "", string scomment = "", int labelLen = -1);
bool PrintLabelEqu(Label *pLabel, string sLabel = "");
bool PostprocessLine(string &sLabel, string &smnemo, string &sparm, string &scomment, int &labelLen);
bool LoadInfo(string fileName, vector<string> &loadStack, bool bProcInfo = true, bool bSetDasm = false);
int ParseInfoRange(string value, adr_t &from, adr_t &to, adr_t &step, bool remapped = true);
int ParseOption
Expand Down
23 changes: 22 additions & 1 deletion dasmfw.htm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>
<h1>dasmfw / the DisASseMbler FrameWork</h1>

<p align="right">Copyright (c) 2015-2021 Hermann Seib<br />
<p align="right">Copyright (c) 2015-2022 Hermann Seib<br />
Parts Copyright (c) 2000 Arto Salmi<br />
Parts Copyright (c) 2013 Colin Bourassa<br />
Parts Copyright (c) 2014-2015 Rainer Buchty</p>
Expand Down Expand Up @@ -255,6 +255,21 @@ <h3>Disassembler Options</h3>
<dd>can be used to force the disassembler to emit mnemonics in uppercase (<b><i>on</i></b>) or
lowercase (<b><i>off</i></b>) characters; if not given (same as <b><i>default</i></b>),
it uses the default mode implemented by the respective disassembler</dd>
<dt><b>mnemo <i>org repl</i></b></dt>
<dd>can be used to redefine any of the mnemonics a disassembler emits. The list of mnemonics is
disassembler-dependent, of course, but the underlying logic is implemented for all of them.<br />
If, for example, you create a disassembly that should be run through an assembler that uses
<b>.byte</b> instead of <b>fcb</b> to emit a certain byte, just put<br />
<b>mnemo fcb .byte</b><br />
into the info file.<br />
For more complex changes, <b>mnemo</b> can also contain the following specialties in the replacement part:<br />
<b>$(label)</b> can be used to embed the label of the instruction (if any) at this position in the instruction;<br />
<b>$(parm)</b> can be used to embed the parameter(s) at this position in the instruction;<br />
<b>$(&lt;&lt;)</b> can be used to "shift left" the resulting mnemonic plus parameters into the label position.<br />
Complicated? Well, here's an example: if the assembler expects a construct like <b>*=addr</b> instead of the
commonly used <b>ORG addr</b>, you can add <b>mnemo org \*=$(parm)</b> to the info file (the backslash is necessary
since dasmfw would think this is the start of a comment in the info file otherwise).
</dd>
</dl>
<p>The following options are disassembler-specific; some are only available for specific
disassemblers. If in doubt, invoking dasmfw with the command line
Expand Down Expand Up @@ -345,6 +360,12 @@ <h3>Disassembler Options</h3>
understood officially undefined opcodes. These can be made available; however,
since using these instructions can lead to quite problematic program behavior,
it's normally turned off.</dd>
<dt><b>accparm <i>on|off</i><br />noaccparm</b></dt>
<dd>For 650x-based disassemblers only.<br />
Some instructions can be written with or without an <b>A</b> parameter (accumulator-based);
depending on the assembler in question, this may be required or lead to errors, so output of
the accumulator register can be turned off.<br />
Default is on.</dd>
<dt><b>flex <i>on|off</i><br />noflex</b></dt>
<dd>For 6809-based disassemblers only.<br />
If the file in question is known to be a binary for the FLEX9 operating system, dasmfw can
Expand Down
3 changes: 2 additions & 1 deletion history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ v0.29 2022-05-20 "option offset,begin,end,bus,interleave" info file statements p
v0.30 2022-06-06 Updates to 6502 disassembler
v0.31 2022-06-08 Added mnemo info file directive
Added boppcom option for 68HC11
v0.32 2022-10-10 begin and end options didn't work as intended; they should now.
v0.32 2022-10-10 begin and end options didn't work as intended; they should now.
v0.33 2022-10-11 Added some features to the mnemo directive

0 comments on commit 6ada59c

Please sign in to comment.