Browse Source

Emulator: Add Formatter for CPU class

master
Riyyi 2 years ago
parent
commit
446a777e40
  1. 32
      src/cpu.cpp
  2. 7
      src/cpu.h

32
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<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());
}

7
src/cpu.h

@ -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;
};

Loading…
Cancel
Save