diff --git a/src/cpu.cpp b/src/cpu.cpp index 07f83bc..1f220f6 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -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::parse(Parser& parser) +{ + parser.parseSpecifier(specifier, Parser::ParameterType::UserDefined); +} + +void Formatter::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 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()); +} diff --git a/src/cpu.h b/src/cpu.h index 106a9cb..925dd73 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -12,6 +12,7 @@ #include #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 : Formatter { + void parse(Parser& parser); + void format(Builder& builder, const CPU& value) const; +};