From a5e51f71404e604fe3918853549f8cc8b8a93d92 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 27 Aug 2018 10:43:12 +0100 Subject: [PATCH] Simplify the 6809 disassembler usage a little. Signed-off-by: Adrian Conlon --- MC6809/inc/Disassembly.h | 6 ++++++ MC6809/src/Disassembly.cpp | 37 +++++++++++++++++++++++++++++++++++++ MC6809/test/Board.cpp | 27 +++++++-------------------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/MC6809/inc/Disassembly.h b/MC6809/inc/Disassembly.h index 95f282f..5bbd780 100644 --- a/MC6809/inc/Disassembly.h +++ b/MC6809/inc/Disassembly.h @@ -11,12 +11,18 @@ namespace EightBit { Disassembly(mc6809& processor); std::string disassemble(uint16_t current); + std::string disassemble(register16_t current); + std::string disassemble(); + + std::string dumpState(); static std::string dump_Flags(uint8_t value); static std::string dump_ByteValue(uint8_t value); static std::string dump_RelativeValue(int8_t value); static std::string dump_WordValue(uint16_t value); + static std::string dump_WordValue(register16_t value); static std::string dump_RelativeValue(int16_t value); + static std::string dump_RelativeValue(register16_t value); private: mc6809& m_cpu; diff --git a/MC6809/src/Disassembly.cpp b/MC6809/src/Disassembly.cpp index e47d492..38c39a9 100644 --- a/MC6809/src/Disassembly.cpp +++ b/MC6809/src/Disassembly.cpp @@ -40,18 +40,55 @@ std::string EightBit::Disassembly::dump_RelativeValue(int8_t value) { return output.str(); } +std::string EightBit::Disassembly::dump_WordValue(register16_t value) { + return dump_WordValue(value.word); +} + std::string EightBit::Disassembly::dump_WordValue(uint16_t value) { std::ostringstream output; dump(output, value, 4); return output.str(); } +std::string EightBit::Disassembly::dump_RelativeValue(register16_t value) { + return dump_RelativeValue((int16_t)value.word); +} + std::string EightBit::Disassembly::dump_RelativeValue(int16_t value) { std::ostringstream output; output << (int)value; return output.str(); } +// + +std::string EightBit::Disassembly::dumpState() { + + std::ostringstream output; + + output << std::hex; + output << "PC=" << dump_WordValue(CPU().PC()) << ":"; + output << "CC=" << dump_Flags(CPU().CC()) << ","; + output << "D=" << dump_WordValue(CPU().D()) << ","; + output << "X=" << dump_WordValue(CPU().X()) << ","; + output << "Y=" << dump_WordValue(CPU().Y()) << ","; + output << "U=" << dump_WordValue(CPU().U()) << ","; + output << "S=" << dump_WordValue(CPU().S()) << ","; + output << "DP=" << dump_ByteValue(CPU().DP()) << "\t"; + + return output.str(); +} + +// + +std::string EightBit::Disassembly::disassemble() { + return disassemble(CPU().PC()); +} + +std::string EightBit::Disassembly::disassemble(register16_t current) { + return disassemble(current.word); +} + std::string EightBit::Disassembly::disassemble(uint16_t current) { m_address = current; diff --git a/MC6809/test/Board.cpp b/MC6809/test/Board.cpp index 4e6d569..0505c10 100644 --- a/MC6809/test/Board.cpp +++ b/MC6809/test/Board.cpp @@ -27,26 +27,13 @@ void Board::initialise() { CPU().reset(); } -void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809& cpu) { - - auto address = cpu.PC().word; - auto cell = peek(address); - - const auto disassembled = m_disassembler.disassemble(address); - if (!disassembled.empty()) { - - std::cout << std::hex; - std::cout << "PC=" << EightBit::Disassembly::dump_WordValue(address) << ":"; - std::cout << "CC=" << EightBit::Disassembly::dump_Flags(CPU().CC()) << ","; - std::cout << "D=" << EightBit::Disassembly::dump_WordValue(CPU().D().word) << ","; - std::cout << "X=" << EightBit::Disassembly::dump_WordValue(CPU().X().word) << ","; - std::cout << "Y=" << EightBit::Disassembly::dump_WordValue(CPU().Y().word) << ","; - std::cout << "U=" << EightBit::Disassembly::dump_WordValue(CPU().U().word) << ","; - std::cout << "S=" << EightBit::Disassembly::dump_WordValue(CPU().S().word) << ","; - std::cout << "DP=" << EightBit::Disassembly::dump_ByteValue(CPU().DP()) << "\t"; - - std::cout << disassembled << std::endl; - } +void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) { + const auto disassembled = m_disassembler.disassemble(); + if (!disassembled.empty()) + std::cout + << m_disassembler.dumpState() + << disassembled + << std::endl; } uint8_t& Board::reference(uint16_t address) {