From bfa1c07ea44924cdceb202d99d756cf73be21ffb Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 28 Dec 2017 14:18:17 +0000 Subject: [PATCH] Change a couple of small formatting quirks in the disassembler to better match "nestest". Signed-off-by: Adrian Conlon --- M6502/inc/Disassembly.h | 4 +++- M6502/src/Disassembly.cpp | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/M6502/inc/Disassembly.h b/M6502/inc/Disassembly.h index 5180be7..a1e7bce 100644 --- a/M6502/inc/Disassembly.h +++ b/M6502/inc/Disassembly.h @@ -64,7 +64,7 @@ namespace EightBit { } std::string AM_Immediate() const { - return "#" + AM_Immediate_dump(); + return "#$" + AM_Immediate_dump(); } std::string AM_Absolute_dump() const { @@ -315,6 +315,8 @@ namespace EightBit { #pragma endregion 6502 addressing modes + static void dump(std::ostream& out, int value, int width); + uint8_t getByte(uint16_t address) const; std::string dump_Byte(uint16_t address) const; diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index 6eb8a4f..772ff51 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -25,15 +25,19 @@ std::string EightBit::Disassembly::dump_Flags(uint8_t value) const { 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) const { std::ostringstream output; - output << std::hex << std::setw(2) << std::setfill('0') << (int)value; + dump(output, value, 2); return output.str(); } std::string EightBit::Disassembly::dump_WordValue(uint16_t value) const { std::ostringstream output; - output << std::hex << std::setw(4) << std::setfill('0') << (int)value; + dump(output, value, 4); return output.str(); } @@ -47,7 +51,7 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const { auto cell = bus.peek(current); - output << dump_ByteValue(cell); + output << dump_ByteValue(cell) << " "; auto byte = bus.peek(current + 1); uint16_t relative = processor.PC().word + 2 + (int8_t)byte; @@ -332,7 +336,7 @@ std::string EightBit::Disassembly::dump_Byte(uint16_t address) const { } std::string EightBit::Disassembly::dump_DByte(uint16_t address) const { - return dump_Byte(address) + dump_Byte(address + 1); + return dump_Byte(address) + " " + dump_Byte(address + 1); } ////