Emulator: Add Formatter for CPU class
This commit is contained in:
+32
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include "ruc/format/color.h"
|
||||
#include "ruc/format/print.h"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
@@ -416,3 +417,34 @@ uint32_t CPU::ffRead(uint32_t address)
|
||||
{
|
||||
return Emu::the().readMemory(address | (0xff << 8)) & 0x00ff;
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
void Formatter<CPU>::parse(Parser& parser)
|
||||
{
|
||||
parser.parseSpecifier(specifier, Parser::ParameterType::UserDefined);
|
||||
}
|
||||
|
||||
void Formatter<CPU>::format(Builder& builder, const CPU& value) const
|
||||
{
|
||||
if (!specifier.alternativeForm) {
|
||||
builder.putString(
|
||||
::format("| AF {:#06x} | BC {:#06x} | DE {:#06x} | HL {:#06x} | PC {:#06x} | SP {:#06x} |",
|
||||
value.af(), value.bc(), value.de(), value.hl(), value.pc(), value.sp()));
|
||||
return;
|
||||
}
|
||||
|
||||
Formatter<uint32_t> formatter { .specifier = specifier };
|
||||
builder.putString("AF: ");
|
||||
formatter.format(builder, value.af());
|
||||
builder.putString("\nBC: ");
|
||||
formatter.format(builder, value.bc());
|
||||
builder.putString("\nDE: ");
|
||||
formatter.format(builder, value.de());
|
||||
builder.putString("\nHL: ");
|
||||
formatter.format(builder, value.hl());
|
||||
builder.putString("\nPC: ");
|
||||
formatter.format(builder, value.pc());
|
||||
builder.putString("\nSP: ");
|
||||
formatter.format(builder, value.sp());
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "processing-unit.h"
|
||||
#include "ruc/format/formatter.h"
|
||||
|
||||
class CPU final : public ProcessingUnit {
|
||||
public:
|
||||
@@ -95,3 +96,9 @@ private:
|
||||
|
||||
int8_t m_wait_cycles { 0 };
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ruc::format::Formatter<CPU> : Formatter<uint32_t> {
|
||||
void parse(Parser& parser);
|
||||
void format(Builder& builder, const CPU& value) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user