Add skeletal disassembler to the 6809 processor.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-26 19:08:07 +01:00
parent 735f70e717
commit a22c5a5c78
4 changed files with 122 additions and 0 deletions

33
MC6809/inc/Disassembly.h Normal file
View File

@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include <string>
#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;
};
}

View File

@ -0,0 +1,81 @@
#include "stdafx.h"
#include "Disassembly.h"
#include <sstream>
#include <iomanip>
#include <functional>
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));
}

View File

@ -19,10 +19,12 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\inc\Disassembly.h" />
<ClInclude Include="..\inc\mc6809.h" />
<ClInclude Include="..\inc\stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Disassembly.cpp" />
<ClCompile Include="mc6809.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@ -17,6 +17,9 @@
<ClInclude Include="..\inc\mc6809.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\Disassembly.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@ -25,5 +28,8 @@
<ClCompile Include="mc6809.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Disassembly.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>