Skip to content

Commit

Permalink
Fixes for issues #4 #5 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Arakula committed May 5, 2022
1 parent c94bf33 commit d47eb05
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 41 deletions.
18 changes: 10 additions & 8 deletions Dasm6500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ uint8_t Dasm650X::m6500_codes[512] =
_ill ,_nom, _and ,_zpx, _rol ,_zpx, _ill ,_nom, /* 34..37 */
_sec ,_imp, _and ,_aby, _ill ,_nom, _ill ,_nom, /* 38..3B */
_ill ,_nom, _and ,_abx, _rol ,_abx, _ill ,_nom, /* 3C..3F */
_rti ,_acc, _eor ,_idx, _ill ,_nom, _ill ,_nom, /* 40..43 */
_rti ,_imp, _eor ,_idx, _ill ,_nom, _ill ,_nom, /* 40..43 */
_ill ,_nom, _eor ,_zpg, _lsr ,_zpg, _ill ,_nom, /* 44..47 */
_pha ,_imp, _eor ,_imm, _lsr ,_acc, _ill ,_nom, /* 48..4B */
_jmp ,_abs, _eor ,_abs, _lsr ,_abs, _ill ,_nom, /* 4C..4F */
Expand Down Expand Up @@ -198,7 +198,7 @@ OpCode Dasm650X::opcodes[mnemo6500_count] =
{ "INX", Data }, /* _inx */
{ "INY", Data }, /* _iny */
{ "JMP", Code }, /* _jmp */
{ "JSR", Data }, /* _jsr */
{ "JSR", Code }, /* _jsr */
{ "LDA", Data }, /* _lda */
{ "LDX", Data }, /* _ldx */
{ "LDY", Data }, /* _ldy */
Expand Down Expand Up @@ -682,6 +682,7 @@ if (lbltxt.find_first_of("+-") == string::npos)
slabel = Label2String(laddr, 4, true, laddr, bus);
smnemo = "EQU";
sparm = Address2String(laddr, bus);
Disassembler::DisassembleLabel(label, slabel, smnemo, sparm, bus);
return true;
}
return false;
Expand All @@ -704,6 +705,7 @@ bool Dasm650X::DisassembleDefLabel
slabel = label->GetText();
smnemo = "EQU";
sparm = label->GetDefinition();
Disassembler::DisassembleDefLabel(label, slabel, smnemo, sparm, bus);
return true;
}

Expand Down Expand Up @@ -978,7 +980,7 @@ if (addr == NO_ADDRESS && prevaddr == NO_ADDRESS)
{
LineChange chg;
changes.push_back(chg); /* append empty line before END */
chg.oper = "END";
chg.oper = MnemoCase("END");
if (load != NO_ADDRESS && /* if entry point address given */
bLoadLabel) /* and labelling wanted */
chg.opnds = Label2String(load, 4, true, load);
Expand All @@ -1005,14 +1007,14 @@ else // no bus check necessary, there's only one
changes.push_back(chg);
if (prevphase != NO_ADDRESS && prevphstart != curphstart)
{
chg.oper = "DEPHASE";
chg.oper = MnemoCase("DEPHASE");
changes.push_back(chg);
changes.push_back(LineChange());
}
if (addr != NO_ADDRESS)
{
// TODO: check how that interferes with PIC!
chg.oper = "ORG";
chg.oper = MnemoCase("ORG");
chg.opnds = Number2String(addr, 4, NO_ADDRESS);
changes.push_back(chg);
if (curphase != NO_ADDRESS &&
Expand All @@ -1021,7 +1023,7 @@ else // no bus check necessary, there's only one
// && curphase != addr
)
{
chg.oper = "PHASE";
chg.oper = MnemoCase("PHASE");
chg.opnds = Number2String(curphase, 4, NO_ADDRESS);
changes.push_back(chg);
}
Expand Down Expand Up @@ -1061,7 +1063,7 @@ uint8_t Dasm6501::m6501_codes[512] =
_ill ,_nom, _and ,_zpx, _rol ,_zpx, _rla,_zpx|_und, /* 34..37 */
_sec ,_imp, _and ,_aby, _ill ,_nom, _rla,_aby|_und, /* 38..3B */
_ill ,_nom, _and ,_abx, _rol ,_abx, _rla,_abx|_und, /* 3C..3F */
_rti ,_acc, _eor ,_idx, _ill ,_nom, _sre,_idx|_und, /* 40..43 */
_rti ,_imp, _eor ,_idx, _ill ,_nom, _sre,_idx|_und, /* 40..43 */
_ill ,_nom, _eor ,_zpg, _lsr ,_zpg, _sre,_zpg|_und, /* 44..47 */
_pha ,_imp, _eor ,_imm, _lsr ,_acc, _alr,_imm|_und, /* 48..4B */
_jmp ,_abs, _eor ,_abs, _lsr ,_abs, _sre,_abs|_und, /* 4C..4F */
Expand Down Expand Up @@ -1285,7 +1287,7 @@ uint8_t Dasm65C02::m65c02_codes[512] =
_bit ,_zpx, _and ,_zpx, _rol ,_zpx, _rmb ,_zpb, /* 34..37 */
_sec ,_imp, _and ,_aby, _dec ,_imp, _ill ,_nom, /* 38..3B */
_bit ,_abx, _and ,_abx, _rol ,_abx, _bbr ,_bbt, /* 3C..3F */
_rti ,_acc, _eor ,_idx, _ill ,_nom, _ill ,_nom, /* 40..43 */
_rti ,_imp, _eor ,_idx, _ill ,_nom, _ill ,_nom, /* 40..43 */
_ill ,_nom, _eor ,_zpg, _lsr ,_zpg, _rmb ,_zpb, /* 44..47 */
_pha ,_imp, _eor ,_imm, _lsr ,_acc, _ill ,_nom, /* 48..4B */
_jmp ,_abs, _eor ,_abs, _lsr ,_abs, _bbr ,_bbt, /* 4C..4F */
Expand Down
12 changes: 7 additions & 5 deletions Dasm6800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ if (lbltxt.find_first_of("+-") == string::npos)
slabel = Label2String(laddr, 4, true, laddr, bus);
smnemo = "EQU";
sparm = Address2String(laddr, bus);
Disassembler::DisassembleLabel(label, slabel, smnemo, sparm, bus);
return true;
}
return false;
Expand All @@ -895,6 +896,7 @@ bool Dasm6800::DisassembleDefLabel
slabel = label->GetText();
smnemo = "EQU";
sparm = label->GetDefinition();
Disassembler::DisassembleDefLabel(label, slabel, smnemo, sparm, bus);
return true;
}

Expand Down Expand Up @@ -1239,7 +1241,7 @@ if (addr == NO_ADDRESS && prevaddr == NO_ADDRESS)
{
LineChange chg;
changes.push_back(chg); /* append empty line before END */
chg.oper = "END";
chg.oper = MnemoCase("END");
if (load != NO_ADDRESS && /* if entry point address given */
bLoadLabel) /* and labelling wanted */
chg.opnds = Label2String(load, 4, true, load);
Expand All @@ -1266,7 +1268,7 @@ else // no bus check necessary, there's only one
changes.push_back(chg);
if (prevphase != NO_ADDRESS && prevphstart != curphstart)
{
chg.oper = "DEPHASE";
chg.oper = MnemoCase("DEPHASE");
changes.push_back(chg);
changes.push_back(LineChange());
}
Expand All @@ -1277,14 +1279,14 @@ else // no bus check necessary, there's only one
{
if (prevaddr != NO_ADDRESS)
{
chg.oper = "ORG";
chg.oper = MnemoCase("ORG");
chg.opnds = "* + ";
chg.opnds += Number2String(addr - (prevaddr + prevsz), 4, NO_ADDRESS);
}
}
else
{
chg.oper = "ORG";
chg.oper = MnemoCase("ORG");
chg.opnds = Number2String(addr, 4, NO_ADDRESS);
changes.push_back(chg);
}
Expand All @@ -1294,7 +1296,7 @@ else // no bus check necessary, there's only one
// && curphase != addr
)
{
chg.oper = "PHASE";
chg.oper = MnemoCase("PHASE");
chg.opnds = Number2String(curphase, 4, NO_ADDRESS);
changes.push_back(chg);
}
Expand Down
10 changes: 6 additions & 4 deletions Dasm68000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ if (lbltxt.find_first_of("+-") == string::npos)
slabel = Label2String(laddr, GetBusWidth() / 4, true, laddr, bus);
smnemo = "EQU";
sparm = Address2String(laddr, bus);
Disassembler::DisassembleLabel(label, slabel, smnemo, sparm, bus);
return true;
}
return false;
Expand All @@ -1609,6 +1610,7 @@ bool Dasm68000::DisassembleDefLabel
slabel = label->GetText();
smnemo = "EQU";
sparm = label->GetDefinition();
Disassembler::DisassembleDefLabel(label, slabel, smnemo, sparm, bus);
return true;
}

Expand Down Expand Up @@ -2705,7 +2707,7 @@ if (addr == NO_ADDRESS && prevaddr == NO_ADDRESS)
{
LineChange chg;
changes.push_back(chg); /* append empty line before END */
chg.oper = "END";
chg.oper = MnemoCase("END");
if (load != NO_ADDRESS && /* if entry point address given */
bLoadLabel) /* and labelling wanted */
chg.opnds = Label2String(load, GetBusWidth() / 4, true, load);
Expand All @@ -2731,14 +2733,14 @@ else // no bus check necessary, there's only one
changes.push_back(chg);
if (prevphase != NO_ADDRESS && prevphstart != curphstart)
{
chg.oper = "DEPHASE";
chg.oper = MnemoCase("DEPHASE");
changes.push_back(chg);
changes.push_back(LineChange());
}
if (addr != NO_ADDRESS)
{
// TODO: check how that interferes with PIC!
chg.oper = "ORG";
chg.oper = MnemoCase("ORG");
chg.opnds = Number2String(addr, 6, NO_ADDRESS);
changes.push_back(chg);
if (curphase != NO_ADDRESS &&
Expand All @@ -2747,7 +2749,7 @@ else // no bus check necessary, there's only one
// && curphase != addr
)
{
chg.oper = "PHASE";
chg.oper = MnemoCase("PHASE");
chg.opnds = Number2String(curphase, 6, NO_ADDRESS);
changes.push_back(chg);
}
Expand Down
2 changes: 1 addition & 1 deletion Dasm6809.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ if (!bAfterLine) /* if before the address */
{
LineChange chg;
changes.push_back(chg);
chg.oper = "SETDP";
chg.oper = MnemoCase("SETDP");
if (dp != NO_ADDRESS)
chg.opnds = sformat("$%02X", dp >> 8);
changes.push_back(chg);
Expand Down
16 changes: 9 additions & 7 deletions DasmAvr8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,7 @@ if (label->GetText().find_first_of("+-") == string::npos)
smnemo = mnemo[(bus == BusIO) ? _d_port : _d_equ].mne;
sparm = Label2String(laddr, 4, true, laddr, bus) + sequdelim[avr_gcc] +
Address2String(laddr, bus);
Disassembler::DisassembleLabel(label, slabel, smnemo, sparm, bus);
return true;
}
return false;
Expand Down Expand Up @@ -1531,6 +1532,7 @@ else
smnemo = mnemo[_d_equ].mne;
sparm = label->GetText() + sequdelim[avr_gcc] + label->GetDefinition();
}
Disassembler::DisassembleDefLabel(label, slabel, smnemo, sparm, bus);
return true;
}

Expand Down Expand Up @@ -1561,7 +1563,7 @@ if (addr == NO_ADDRESS && prevaddr == NO_ADDRESS)
// and since there's no entry point to be set anyway, it's unnecessary
LineChange chg;
changes.push_back(chg); /* append empty line before END */
chg.oper = mnemo[_d_exit].mne;
chg.oper = MnemoCase(mnemo[_d_exit].mne);
#if 0
if (load != NO_ADDRESS && /* if entry point address given */
bLoadLabel) /* and labelling wanted */
Expand All @@ -1581,9 +1583,9 @@ else
changes.push_back(chg); /* append empty line before segment */
if (bus == BusCode || bus == BusData || bus == BusEEPROM)
{
chg.oper = mnemo[(bus == BusEEPROM) ? _d_eseg :
(bus == BusData) ? _d_dseg :
_d_cseg].mne;
chg.oper = MnemoCase(mnemo[(bus == BusEEPROM) ? _d_eseg :
(bus == BusData) ? _d_dseg :
_d_cseg].mne);
changes.push_back(chg);
}
}
Expand All @@ -1598,7 +1600,7 @@ else
changes.push_back(chg);
if (addr != NO_ADDRESS)
{
chg.oper = mnemo[_d_org].mne;
chg.oper = MnemoCase(mnemo[_d_org].mne);
chg.opnds = Number2String(addr, 4, NO_ADDRESS, bus);
changes.push_back(chg);
changes.push_back(LineChange());
Expand Down Expand Up @@ -1634,12 +1636,12 @@ else
LineChange chg2;
chg2.label = "#endif";
changes.push_back(chg2);
chg.label = mnemo[_d_def].mne;
chg.label = MnemoCase(mnemo[_d_def].mne);
chg.opnds = RegName(lbl->GetRegister(), false);
}
else
{
chg.oper = mnemo[_d_def].mne;
chg.oper = MnemoCase(mnemo[_d_def].mne);
chg.opnds = sformat("%s%sR%d", txt.c_str(), sdefdelim[avr_gcc], lbl->GetRegister());
}
changes.push_back(chg);
Expand Down
16 changes: 16 additions & 0 deletions Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ bSetSysVec = true;
bMultiLabel = false;
bAutoLabel = false;
bPIC = false;
nMnemoUpper = -1; // don't care

// set up options table
// base class uses one generic option setter/getter pair (not mandatory)
Expand Down Expand Up @@ -178,6 +179,9 @@ AddOption("sysvec", "{off|on}\tset system vector labels",
AddOption("pic", "{off|on}\tdiasassemble as position-indpendent code",
&Disassembler::DisassemblerSetOption,
&Disassembler::DisassemblerGetOption);
AddOption("upmnemo", "{off|on}\tdiasassemble mnemonics in UPPERCASE format",
&Disassembler::DisassemblerSetOption,
&Disassembler::DisassemblerGetOption);
}

/*****************************************************************************/
Expand Down Expand Up @@ -427,6 +431,14 @@ else if (lname == "pic")
bPIC = bnValue;
return bIsBool ? 1 : 0;
}
else if (lname == "upmnemo")
{
if (lvalue == "default")
nMnemoUpper = -1;
else
nMnemoUpper = bnValue;
return bIsBool ? 1 : 0;
}
else
return 0; /* only option consumed */

Expand Down Expand Up @@ -471,6 +483,10 @@ else if (lname == "multilabel") oval = bMultiLabel ? "on" : "off";
else if (lname == "autolabel") oval = bAutoLabel ? "on" : "off";
else if (lname == "sysvec") oval = bSetSysVec ? "on" : "off";
else if (lname == "pic") oval = bPIC ? "on" : "off";
else if (lname == "upmnemo") oval =
(nMnemoUpper < 0) ? "default" :
(nMnemoUpper > 0) ? "on" :
"off";
return oval;
}

Expand Down
34 changes: 27 additions & 7 deletions Disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,27 @@ class Disassembler
// Disassemble a line in the memory area
adr_t Disassemble(adr_t addr, string &smnemo, string &sparm, int maxparmlen, int bus = BusCode)
{
if (IsCode(addr, bus)) return DisassembleCode(addr, smnemo, sparm, bus);
uint32_t flags = 0;
adr_t end = GetConsecutiveData(addr, flags, maxparmlen, bus);
return DisassembleData(addr, end, flags, smnemo, sparm, maxparmlen, bus);
adr_t a;
if (IsCode(addr, bus))
a = DisassembleCode(addr, smnemo, sparm, bus);
else
{
uint32_t flags = 0;
adr_t end = GetConsecutiveData(addr, flags, maxparmlen, bus);
a = DisassembleData(addr, end, flags, smnemo, sparm, maxparmlen, bus);
}
smnemo = MnemoCase(smnemo);
return a;
}
// pass back correct mnemonic and parameters for a label
virtual bool DisassembleLabel(Label *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode)
{ (void)label; (void)slabel; (void)smnemo; (void)sparm; (void)bus;
{ (void)label; (void)slabel; (void)sparm; (void)bus;
smnemo = MnemoCase(smnemo);
return false; } // no changes in base implementation
// pass back correct mnemonic and parameters for a DefLabel
virtual bool DisassembleDefLabel(DefLabel *label, string &slabel, string &smnemo, string &sparm, int bus = BusCode)
{ (void)label; (void)slabel; (void)smnemo; (void)sparm; (void)bus;
{ (void)label; (void)slabel; (void)sparm; (void)bus;
smnemo = MnemoCase(smnemo);
return false; } // no changes in base implementation
// pass back disassembler-specific state changes before/after a disassembly line
struct LineChange
Expand All @@ -690,7 +699,7 @@ class Disassembler
string opnds;
};
virtual bool DisassembleChanges(adr_t addr, adr_t prevaddr, adr_t prevsz, bool bAfterLine, vector<LineChange> &changes, int bus = BusCode)
{ (void)addr; (void)prevaddr; (void)prevsz; (void)bAfterLine; (void)changes; (void)bus;
{ (void)addr; (void)prevaddr; (void)prevsz; (void)bAfterLine; (void)bus;
return changes.size() != 0; } // no additional changes in base implementation
// create hex / ASCII representation of the current area
virtual bool DisassembleHexAsc(adr_t addr, adr_t len, adr_t max, string &sHex, string &sAsc, int bus = BusCode)
Expand Down Expand Up @@ -757,6 +766,15 @@ class Disassembler
{ busbits[bus] = CalcBitsForHighestAddr(GetHighestBusAddr(bus)); }
// calculate consecutive data range (i.e., same type for all)
virtual adr_t GetConsecutiveData(adr_t addr, uint32_t &flags, int maxparmlen, int bus = BusCode);
// set the correct case for mnemonics output
virtual string MnemoCase(string smnemo)
{
if (nMnemoUpper < 0)
return smnemo;
else if (nMnemoUpper > 0)
return uppercase(smnemo);
return lowercase(smnemo);
}

public:
// return address bits for a specific bus
Expand Down Expand Up @@ -912,6 +930,8 @@ class Disassembler
bool bAutoLabel;
// flag whether to disassemble as position-independent code
bool bPIC;
// flag whether to emit uppercase or lowercase mnemonics
int nMnemoUpper;
// default display format
MemAttribute::Display defaultDisplay;
// disassembler-specific comment start character
Expand Down
Loading

1 comment on commit d47eb05

@phillipeaton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I look forward to testing this tonight, thanks for the impressively-quick turnaround!

Please sign in to comment.