diff --git a/MC6809/inc/Disassembly.h b/MC6809/inc/Disassembly.h new file mode 100644 index 0000000..b43c3f0 --- /dev/null +++ b/MC6809/inc/Disassembly.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include "mc6809.h" + +namespace EightBit { + class Disassembly { + public: + Disassembly(mc6809& processor); + + std::string disassemble(uint16_t current) const; + + static std::string dump_Flags(uint8_t value); + static std::string dump_ByteValue(uint8_t value); + static std::string dump_WordValue(uint16_t value); + + private: + mc6809& processor; + + mutable uint16_t m_address = 0xffff; + + static void dump(std::ostream& out, int value, int width); + + uint8_t getByte(uint16_t address) const; + uint16_t getWord(uint16_t address) const; + + std::string dump_Byte(uint16_t address) const; + std::string dump_DByte(uint16_t address) const; + std::string dump_Word(uint16_t address) const; + }; +} \ No newline at end of file diff --git a/MC6809/src/Disassembly.cpp b/MC6809/src/Disassembly.cpp new file mode 100644 index 0000000..ecc36f1 --- /dev/null +++ b/MC6809/src/Disassembly.cpp @@ -0,0 +1,81 @@ +#include "stdafx.h" +#include "Disassembly.h" + +#include +#include +#include + +using namespace std::placeholders; + +EightBit::Disassembly::Disassembly(mc6809& targetProcessor) +: processor(targetProcessor) { +} + +std::string EightBit::Disassembly::dump_Flags(uint8_t value) { + std::string returned; + returned += (value & mc6809::EF) ? "E" : "-"; + returned += (value & mc6809::FF) ? "F" : "-"; + returned += (value & mc6809::HF) ? "H" : "-"; + returned += (value & mc6809::IF) ? "I" : "-"; + returned += (value & mc6809::NF) ? "N" : "-"; + returned += (value & mc6809::ZF) ? "Z" : "-"; + returned += (value & mc6809::VF) ? "V" : "-"; + returned += (value & mc6809::CF) ? "C" : "-"; + return returned; +} + +void EightBit::Disassembly::dump(std::ostream& out, int value, int width) { + out << std::hex << std::uppercase << std::setw(width) << std::setfill('0') << value; +} + +std::string EightBit::Disassembly::dump_ByteValue(uint8_t value) { + std::ostringstream output; + dump(output, value, 2); + return output.str(); +} + +std::string EightBit::Disassembly::dump_WordValue(uint16_t value) { + std::ostringstream output; + dump(output, value, 4); + return output.str(); +} + +std::string EightBit::Disassembly::disassemble(uint16_t current) const { + + m_address = current; + + std::ostringstream output; + + auto& bus = processor.BUS(); + + auto cell = bus.peek(current); + + output << dump_ByteValue(cell) << " "; + + return output.str(); +} + +//// + +uint8_t EightBit::Disassembly::getByte(uint16_t address) const { + return processor.BUS().peek(address); +} + +uint16_t EightBit::Disassembly::getWord(uint16_t address) const { + return processor.BUS().peekWord(address); +} + +//// + +std::string EightBit::Disassembly::dump_Byte(uint16_t address) const { + return dump_ByteValue(getByte(address)); +} + +std::string EightBit::Disassembly::dump_DByte(uint16_t address) const { + return dump_Byte(address) + " " + dump_Byte(address + 1); +} + +std::string EightBit::Disassembly::dump_Word(uint16_t address) const { + return dump_WordValue(getWord(address)); +} + \ No newline at end of file diff --git a/MC6809/src/MC6809.vcxproj b/MC6809/src/MC6809.vcxproj index 73b49eb..071bfae 100644 --- a/MC6809/src/MC6809.vcxproj +++ b/MC6809/src/MC6809.vcxproj @@ -19,10 +19,12 @@ + + Create diff --git a/MC6809/src/MC6809.vcxproj.filters b/MC6809/src/MC6809.vcxproj.filters index 7a6a495..0d7fa97 100644 --- a/MC6809/src/MC6809.vcxproj.filters +++ b/MC6809/src/MC6809.vcxproj.filters @@ -17,6 +17,9 @@ Header Files + + Header Files + @@ -25,5 +28,8 @@ Source Files + + Source Files + \ No newline at end of file