Skip to content

Commit

Permalink
[MC6809] Improve register print
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Jun 17, 2024
1 parent 9956450 commit c725422
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
76 changes: 43 additions & 33 deletions debugger/mc6809/regs_mc6809.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,35 @@ const char *RegsMc6809::cpuName() const {
}

void RegsMc6809::print() const {
// clang-format off
// 012345678901234567890123456789012345678901234567890123456789012
static constexpr char line1[] = "DP=xx PC=xxxx S=xxxx U=xxxx Y=xxxx X=xxxx A=xx B=xx CC=EFHINZVC";
// clang-format on
static constexpr char line1[] =
// 2345678901234567890123456789012345678901234567890123456789012
"PC=xxxx S=xxxx X=xxxx Y=xxxx U=xxxx A=xx B=xx DP=xx CC=EFHINZVC";
static auto &buffer1 = *new CharBuffer(line1);
buffer1.hex8(3, _dp);
buffer1.hex16(9, _pc);
buffer1.hex16(16, _s);
buffer1.hex16(23, _u);
buffer1.hex16(30, _y);
buffer1.hex16(37, _x);
buffer1.hex8(44, _a);
buffer1.hex8(49, _b);
buffer1.hex16(3, _pc);
buffer1.hex16(10, _s);
buffer1.hex16(17, _x);
buffer1.hex16(24, _y);
buffer1.hex16(31, _u);
buffer1.hex8(38, _a);
buffer1.hex8(43, _b);
buffer1.hex8(49, _dp);
buffer1.bits(55, _cc, 0x80, line1 + 55);
cli.print(buffer1);
if (_type == SW_HD6309) {
// 0123456789012345
static constexpr char line2[] = " W=xxxx V=xxxx N";
static auto &buffer2 = *new CharBuffer(line2);
buffer2.hex8(3, _e);
buffer2.hex8(5, _f);
buffer2.hex16(10, _v);
buffer2[14] = _native6309 ? ' ' : 0;
cli.print(buffer2);
}
cli.println();
cli.println(buffer1);
_pins.idle();
if (_type == SW_MC6809)
return;

static constexpr char line2[] =
// 234567890123456789012345678901234567890123456789
" D=xxxx W=xxxx V=xxxx E=xx F=xx MD=x";
static auto &buffer2 = *new CharBuffer(line2);
buffer2.hex16(17, _d());
buffer2.hex16(24, _w());
buffer2.hex16(31, _v);
buffer2.hex8(38, _e);
buffer2.hex8(43, _f);
buffer2.hex1(49, _md);
cli.println(buffer2);
_pins.idle();
}

Expand All @@ -88,10 +91,10 @@ void RegsMc6809::save() {

void RegsMc6809::restore() {
if (_type == SW_HD6309) {
loadMode(_native6309);
loadMode(_md);
loadVW();
}
loadStack(_s - (_native6309 ? 14 : 12));
loadStack(_s - (_md ? 14 : 12));
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
// 1:N:R:r:r:r:r:r:r:r:r:r:r:r:X MC6809
// 1:N:R:r:r:r:r:r:r:r:r:r:r:r:r:r:X HD6309 native
Expand All @@ -101,7 +104,7 @@ void RegsMc6809::restore() {
RTI[cycle++] = _cc;
RTI[cycle++] = _a;
RTI[cycle++] = _b;
if (_native6309) {
if (_md) {
RTI[cycle++] = _e;
RTI[cycle++] = _f;
}
Expand All @@ -114,7 +117,7 @@ void RegsMc6809::restore() {
}

uint8_t RegsMc6809::contextLength() const {
return _native6309 ? 14 : 12;
return _md ? 14 : 12;
}

uint16_t RegsMc6809::capture(const Signals *frame, bool step) {
Expand All @@ -131,15 +134,15 @@ uint16_t RegsMc6809::capture(const Signals *frame, bool step) {

void RegsMc6809::saveContext(uint8_t *context, uint8_t n, uint16_t sp) {
_s = sp;
_native6309 = (n == 14);
_md = (n == 14);
// Capturing writes to stack in little endian order.
_pc = le16(context + 0);
_u = le16(context + 2);
_y = le16(context + 4);
_x = le16(context + 6);
_dp = context[8];
uint8_t i = 8;
if (_native6309) {
if (_md) {
_f = context[++i];
_e = context[++i];
}
Expand Down Expand Up @@ -178,7 +181,7 @@ void RegsMc6809::saveVW() {
0x1F, 0x76, // TFR V,W ; 1:2:x:x:x:x (HD6309)
// ; 1:2:x:x (HD6309 native)
};
_pins.injectReads(TFR, sizeof(TFR), _native6309 ? 4 : 6);
_pins.injectReads(TFR, sizeof(TFR), _md ? 4 : 6);
_pins.injectReads(STW, sizeof(STW));
_pins.captureWrites(buffer, sizeof(buffer));
_v = be16(buffer);
Expand All @@ -193,7 +196,7 @@ void RegsMc6809::loadVW() const {
0x1F, 0x67, // TFR W,V ; 1:2:x:x:x:x (HD6309)
// ; 1:2:x:x (HD6309 native)
};
_pins.injectReads(TFR, sizeof(TFR), _native6309 ? 4 : 6);
_pins.injectReads(TFR, sizeof(TFR), _md ? 4 : 6);
LDW[2] = _e;
LDW[3] = _f;
_pins.injectReads(LDW, sizeof(LDW));
Expand Down Expand Up @@ -232,6 +235,9 @@ constexpr const char *REGS16_6309[] = {
constexpr const char *REGS32_6309[] = {
"Q", // 16
};
constexpr const char *REGS1_6309[] = {
"MD", // 17
};

const Regs::RegList *RegsMc6809::listRegisters(uint8_t n) const {
static constexpr RegList REG_LIST[] = {
Expand All @@ -240,8 +246,9 @@ const Regs::RegList *RegsMc6809::listRegisters(uint8_t n) const {
{REGS8_6309, 2, 12, UINT8_MAX},
{REGS16_6309, 2, 14, UINT16_MAX},
{REGS32_6309, 1, 16, UINT32_MAX},
{REGS1_6309, 1, 17, 1},
};
const auto r = (_type == SW_MC6809) ? 2 : 5;
const auto r = (_type == SW_MC6809) ? 2 : 6;
return n < r ? &REG_LIST[n] : nullptr;
}

Expand Down Expand Up @@ -293,6 +300,9 @@ void RegsMc6809::setRegister(uint8_t reg, uint32_t value) {
case 16:
_q(value);
break;
case 17:
_md = value;
break;
}
}

Expand Down
5 changes: 4 additions & 1 deletion debugger/mc6809/regs_mc6809.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct RegsMc6809 : Regs {
protected:
PinsMc6809 &_pins;
SoftwareType _type;
bool _native6309;

uint16_t _s;
uint16_t _pc;
Expand All @@ -49,17 +48,21 @@ struct RegsMc6809 : Regs {
uint8_t _a;
uint8_t _b;
uint8_t _cc;
uint8_t _md;
uint16_t _d() const { return uint16(_a, _b); }
void _d(uint16_t d) {
_a = hi(d);
_b = lo(d);
}
uint8_t _e;
uint8_t _f;
uint16_t _w() const { return uint16(_e, _f); }
void _w(uint16_t w) {
_e = hi(w);
_f = lo(w);
}
uint16_t _v;
uint32_t _q() const { return uint32(_d(), _w()); }
void _q(uint32_t q) {
_d(hi16(q));
_w(lo16(q));
Expand Down
3 changes: 3 additions & 0 deletions debugger/regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ struct Regs {
static constexpr uint16_t lo16(uint32_t v) {
return static_cast<uint16_t>(v >> 0);
}
static constexpr uint32_t uint32(uint16_t hi, uint16_t lo) {
return static_cast<uint16_t>(hi) << 8 | lo;
}
static void swap8(uint8_t &a, uint8_t &b) {
auto tmp = a;
a = b;
Expand Down

0 comments on commit c725422

Please sign in to comment.