Skip to content

Commit

Permalink
upmnemo option now also influences register names
Browse files Browse the repository at this point in the history
Plus updates to 6502 disassembler
  • Loading branch information
Arakula committed May 9, 2022
1 parent 91156bb commit ae59477
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 144 deletions.
46 changes: 27 additions & 19 deletions Dasm6309.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,39 +495,39 @@ if (T & 0x80)
switch (T & 0x1F)
{
case 0x07:
buf = sformat("E,%c", R);
buf = MnemoCase(sformat("E,%c", R));
break;
case 0x17:
buf = sformat("[E,%c]", R);
buf = MnemoCase(sformat("[E,%c]", R));
break;
case 0x0A:
buf = sformat("F,%c",R);
buf = MnemoCase(sformat("F,%c",R));
break;
case 0x1A:
buf = sformat("[F,%c]",R);
buf = MnemoCase(sformat("[F,%c]",R));
break;
case 0x0E:
buf = sformat("W,%c",R);
buf = MnemoCase(sformat("W,%c",R));
break;
case 0x1E:
buf = sformat("[W,%c]",R);
buf = MnemoCase(sformat("[W,%c]",R));
break;
default:
switch (T)
{
case 0x8F:
buf = sformat(",W");
buf = MnemoCase(sformat(",W"));
break;
case 0x90:
buf = sformat("[,W]");
buf = MnemoCase(sformat("[,W]"));
break;
case 0xAF:
{
bGetLabel = !IsConst(PC);
lbl = bGetLabel ? NULL : FindLabel(PC, Const);
W = GetUWord(PC);
string slbl = lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
buf = sformat("%s,W", slbl.c_str());
buf = sformat("%s,%s", slbl.c_str(), MnemoCase("W").c_str());
PC += 2;
}
break;
Expand All @@ -537,21 +537,21 @@ if (T & 0x80)
lbl = bGetLabel ? NULL : FindLabel(PC, Const);
W = GetUWord(PC);
string slbl = lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
buf = sformat("[%s,W]", slbl.c_str());
buf = sformat("[%s,%s]", slbl.c_str(),MnemoCase("W").c_str());
PC += 2;
}
break;
case 0xCF:
buf = sformat(",W++");
buf = MnemoCase(sformat(",W++"));
break;
case 0xD0:
buf = sformat("[,W++]");
buf = MnemoCase(sformat("[,W++]"));
break;
case 0xEF:
buf = sformat(",--W");
buf = MnemoCase(sformat(",--W"));
break;
case 0xF0:
buf = sformat("[,--W]");
buf = MnemoCase(sformat("[,--W]"));
break;
default:
return Dasm6809::IndexString(pc);
Expand Down Expand Up @@ -812,7 +812,7 @@ switch (mode) /* which mode is this? */
T = GetUByte(PC);
string slbl = lbl ? lbl->GetText() : Number2String(T, 2, PC);
sparm = sformat("%s,%d,%s,%s%s",
bit_r[M >> 6],
MnemoCase(bit_r[M >> 6]).c_str(),
(M >> 3) & 7,
snum.c_str(),
(forceDirectAddr || GetForcedAddr(PC)) ? "<" : "",
Expand All @@ -823,22 +823,30 @@ switch (mode) /* which mode is this? */

case _t1: /* Block Transfer r0+,r1+ */
T = GetUByte(PC++);
sparm = sformat("%s+,%s+", I, block_r[T >> 4], block_r[T & 0xF]);
sparm = sformat("%s+,%s+", I,
MnemoCase(block_r[T >> 4]).c_str(),
MnemoCase(block_r[T & 0xF]).c_str());
break;

case _t2: /* Block Transfer r0-,r1- */
T = GetUByte(PC++);
sparm = sformat("%s-,%s-", I, block_r[T >> 4], block_r[T & 0xF]);
sparm = sformat("%s-,%s-", I,
MnemoCase(block_r[T >> 4]).c_str(),
MnemoCase(block_r[T & 0xF]).c_str());
break;

case _t3: /* Block Transfer r0+,r1 */
T = GetUByte(PC++);
sparm = sformat("%s+,%s", I, block_r[T >> 4], block_r[T & 0xF]);
sparm = sformat("%s+,%s", I,
MnemoCase(block_r[T >> 4]).c_str(),
MnemoCase(block_r[T & 0xF]).c_str());
break;

case _t4: /* Block Transfer r0,r1+ */
T = GetUByte(PC++);
sparm = sformat("%-7s %s,%s+", I, block_r[T >> 4], block_r[T & 0xF]);
sparm = sformat("%-7s %s,%s+", I,
MnemoCase(block_r[T >> 4]).c_str(),
MnemoCase(block_r[T & 0xF]).c_str());
break;

case _iml: /* immediate 32-bit */
Expand Down
83 changes: 72 additions & 11 deletions Dasm6500.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@
/* Copyright (C) Hermann Seib *
***************************************************************************/

#if 0
Little TODO notepad ...

"<" and ">" for forced addressing modes are obviously not used in the 6502
assembler world. So be it. There seem to be other methods:

Kick: append .abs or .a to the mnemonic (Absolute mode) or
append .zp or .z to the mnemonic (Zeropage mode)

dasm: .a, .z (plus various others) FORCE mnemonic extensions

ACME: append +1 (zeropage), +2 (absolute 16bit), +3 (absolute 24bit for 65816)
to mnemo

as65: nothing to be found in the manual

Most, if not all, of the above assemblers would also interpret constants
given with leading zeroes (like $00xx) as implicit absolute and without ($xx)
as zero page addressing, but that is not something I'd rely on. Also, it's
only usable for constants and equates - but not, for example, labels in
the zero page.

For the moment, I'm going with .a and .z, but that is surely not enough.
as65, for example, obviously can't handle that.

To go for maximum compatibility, options would be necessary to define
- whether forced addressing is to be done at all (OK, got that)
- a potential mnemonic addition (like the .a and .z currently in use)
- a potential parameter prefix (like the < and > of old)
The "$00 means zero page, $0000 means absolute address" approach is not
something that can be easily incorporated (and, as mentioned, incomplete),
so I see neither reason nor a way to implement that.

#endif

/*****************************************************************************/
/* Dasm650X.cpp : 650X disassembler implementation */
/*****************************************************************************/
Expand Down Expand Up @@ -104,7 +139,7 @@ uint8_t Dasm650X::m6500_codes[512] =
_ill ,_nom, _ora ,_zpx, _asl ,_zpx, _ill ,_nom, /* 14..17 */
_clc ,_imp, _ora ,_aby, _ill ,_nom, _ill ,_nom, /* 18..1B */
_ill ,_nom, _ora ,_abx, _asl ,_abx, _ill ,_nom, /* 1C..1F */
_jsr ,_abs, _and ,_idx, _ill ,_nom, _ill ,_nom, /* 20..23 */
_jsr,_abs|_nof,_and ,_idx, _ill ,_nom, _ill ,_nom, /* 20..23 */
_bit ,_zpg, _and ,_zpg, _rol ,_zpg, _ill ,_nom, /* 24..27 */
_plp ,_imp, _and ,_imm, _rol ,_acc, _ill ,_nom, /* 28..2B */
_bit ,_abs, _and ,_abs, _rol ,_abs, _ill ,_nom, /* 2C..2F */
Expand Down Expand Up @@ -627,6 +662,7 @@ switch (mode) /* which mode is this ? */
break;

case _abs: /* absolute */
case _abs|_nof: /* absolute, no forced addressing */
case _abx: /* absolute,X */
case _aby: /* absolute,Y */
bSetLabel = !IsConst(PC);
Expand Down Expand Up @@ -857,7 +893,7 @@ switch (mode) /* which mode is this? */
// no need to do anything
break;
case _acc: /* accumulator */
sparm = "A";
sparm = MnemoCase("A");
break;

case _imm: /* immediate byte */
Expand Down Expand Up @@ -887,26 +923,33 @@ switch (mode) /* which mode is this? */
W = (uint16_t)dp | T;
if (bGetLabel)
W = (uint16_t)PhaseInner(W, PC);
#if 1
if (GetForcedAddr(PC))
smnemo += ".Z";
sparm = lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#else
sparm = GetForcedAddr(PC) ? "<" : "";
sparm += lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#endif
}
else // if no direct page, this can't be interpreted as a label
sparm = (lbl ? lbl->GetText() : Number2String(T, 2, PC));
if (mode == _zpx)
sparm += ",X";
sparm += MnemoCase(",X");
else if (mode == _zpy)
sparm += ",Y";
sparm += MnemoCase(",Y");
else if (mode == _ind)
sparm = "(" + sparm + ")";
else if (mode == _idx)
sparm = "(" + sparm + ",X)";
sparm = "(" + sparm + MnemoCase(",X)");
else if (mode == _idy)
sparm = "(" + sparm + "),Y";
sparm = "(" + sparm + MnemoCase("),Y");
PC++;
}
break;

case _abs: /* absolute */
case _abs|_nof: /* absolute, no forced addressing */
case _abx: /* absolute,X */
case _aby: /* absolute,Y */
{
Expand All @@ -921,14 +964,20 @@ switch (mode) /* which mode is this? */
dp = GetDirectPage(addr);
if (dp == DEFAULT_ADDRESS)
dp = 0;
if (forceExtendedAddr && (W & (uint16_t)0xff00) == (uint16_t)dp)
if (forceExtendedAddr &&
(W & (uint16_t)0xff00) == (uint16_t)dp &&
!(mode & _nof))
#if 1
smnemo += ".A";
#else
sparm = ">" + slbl;
else
#endif
sparm = slbl;
if (mode == _abx)
sparm += ",X";
sparm += MnemoCase(",X");
else if (mode == _aby)
sparm += ",Y";
sparm += MnemoCase(",Y");
PC += 2;
}
break;
Expand Down Expand Up @@ -1055,7 +1104,7 @@ uint8_t Dasm6501::m6501_codes[512] =
_ill ,_nom, _ora ,_zpx, _asl ,_zpx, _slo,_zpx|_und, /* 14..17 */
_clc ,_imp, _ora ,_aby, _ill ,_nom, _slo,_aby|_und, /* 18..1B */
_ill ,_nom, _ora ,_abx, _asl ,_abx, _slo,_abx|_und, /* 1C..1F */
_jsr ,_abs, _and ,_idx, _ill ,_nom, _rla,_idx|_und, /* 20..23 */
_jsr,_abs|_nof,_and ,_idx, _ill ,_nom, _rla,_idx|_und, /* 20..23 */
_bit ,_zpg, _and ,_zpg, _rol ,_zpg, _rla,_zpg|_und, /* 24..27 */
_plp ,_imp, _and ,_imm, _rol ,_acc, _anc,_imm|_und, /* 28..2B */
_bit ,_abs, _and ,_abs, _rol ,_abs, _rla,_abs|_und, /* 2C..2F */
Expand Down Expand Up @@ -1279,7 +1328,7 @@ uint8_t Dasm65C02::m65c02_codes[512] =
_trb ,_zpg, _ora ,_zpx, _asl ,_zpx, _rmb ,_zpb, /* 14..17 */
_clc ,_imp, _ora ,_aby, _inc ,_imp, _ill ,_nom, /* 18..1B */
_trb ,_abs, _ora ,_abx, _asl ,_abx, _bbr ,_bbt, /* 1C..1F */
_jsr ,_abs, _and ,_idx, _ill ,_nom, _ill ,_nom, /* 20..23 */
_jsr,_abs|_nof,_and ,_idx, _ill ,_nom, _ill ,_nom, /* 20..23 */
_bit ,_zpg, _and ,_zpg, _rol ,_zpg, _rmb ,_zpb, /* 24..27 */
_plp ,_imp, _and ,_imm, _rol ,_acc, _ill ,_nom, /* 28..2B */
_bit ,_abs, _and ,_abs, _rol ,_abs, _bbr ,_bbt, /* 2C..2F */
Expand Down Expand Up @@ -1491,8 +1540,14 @@ switch (mode) /* which mode is this? */
W = (uint16_t)dp | T;
if (bGetLabel)
W = (uint16_t)PhaseInner(W, PC);
#if 1
if (GetForcedAddr(PC))
smnemo += ".Z";
sparm = lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#else
sparm = GetForcedAddr(PC) ? "<" : "";
sparm += lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#endif
}
else // if no direct page, this can't be interpreted as a label
sparm = (lbl ? lbl->GetText() : Number2String(T, 2, PC));
Expand All @@ -1518,8 +1573,14 @@ switch (mode) /* which mode is this? */
W = (uint16_t)dp | T;
if (bGetLabel)
W = (uint16_t)PhaseInner(W, PC);
#if 1
if (GetForcedAddr(PC))
smnemo += ".Z";
sparm = lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#else
sparm = GetForcedAddr(PC) ? "<" : "";
sparm += lbl ? lbl->GetText() : Label2String(W, 4, bGetLabel, PC);
#endif
}
else // if no direct page, this can't be interpreted as a label
sparm = (lbl ? lbl->GetText() : Number2String(T, 2, PC));
Expand Down
1 change: 1 addition & 0 deletions Dasm6500.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Dasm650X :
_rel, /* relative */

addrmodes6500_count,
_nof = 0x40 /* no forced addressing (JSR) */
};

// 6500 mnemonics
Expand Down
2 changes: 1 addition & 1 deletion Dasm6800.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Dasm6800 :
virtual string Address2String(adr_t addr, int bus = BusCode)
{ (void)bus; return sformat("$%04X", addr); }
virtual adr_t FetchInstructionDetails(adr_t PC, uint8_t &instpg, uint8_t &instb, uint8_t &mode, int &MI, const char *&I, string *smnemo = NULL);
virtual string GetIx8IndexReg(uint8_t instpg) { (void)instpg; return ",X"; }
virtual string GetIx8IndexReg(uint8_t instpg) { (void)instpg; return MnemoCase(",X"); }
virtual bool SetConvenience(uint8_t instpg, uint16_t u2, string &smnemo, adr_t &PC);

protected:
Expand Down
Loading

0 comments on commit ae59477

Please sign in to comment.