Browse Source

Emulator: Add register sharing to processing units

master
Riyyi 2 years ago
parent
commit
0e67e7e2cc
  1. 15
      src/cpu.cpp
  2. 4
      src/emu.h
  3. 11
      src/main.cpp
  4. 2
      src/ppu.cpp
  5. 5
      src/processing-unit.cpp
  6. 9
      src/processing-unit.h

15
src/cpu.cpp

@ -13,6 +13,16 @@
CPU::CPU(uint32_t frequency)
: ProcessingUnit(frequency)
{
m_shared_registers.emplace("a", &m_a);
m_shared_registers.emplace("bc", &m_bc);
m_shared_registers.emplace("de", &m_de);
m_shared_registers.emplace("hl", &m_hl);
m_shared_registers.emplace("sp", &m_sp);
m_shared_registers.emplace("pc", &m_pc);
m_shared_registers.emplace("z", &m_z);
m_shared_registers.emplace("n", &m_n);
m_shared_registers.emplace("h", &m_h);
m_shared_registers.emplace("c", &m_c);
}
CPU::~CPU()
@ -26,7 +36,10 @@ void CPU::update()
// Read next opcode
}
print("This is an update from the CPU\n");
m_a = 6;
m_bc = 732;
// print("This is an update from the CPU\n");
}
void CPU::add(uint8_t opcode, uint8_t immediate)

4
src/emu.h

@ -22,6 +22,10 @@ public:
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
uint32_t readMemory(const char* memory_space, uint32_t location);
// -------------------------------------
ProcessingUnit* processingUnit(const char* name) const { return m_processing_units.at(name); }
private:
uint32_t m_frequency { 0 };
double m_timestep { 0 };

11
src/main.cpp

@ -3,13 +3,17 @@
#include "cpu.h"
#include "emu.h"
#include "ppu.h"
#include "ruc/format/print.h"
#include "ruc/timer.h"
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
ruc::Timer t;
printf("%fms\n", t.elapsedNanoseconds() / 1000000.0);
print("{}ms\n", t.elapsedNanoseconds() / 1000000.0);
Emu::the().init(8000000);
@ -24,6 +28,11 @@ int main(int argc, char* argv[])
Emu::the().addMemorySpace("ROM", 1024);
Emu::the().addMemorySpace("CARDROM", 1024);
// Get shared register
Emu::the().processingUnit("cpu")->update();
print("{}\n", *Emu::the().processingUnit("cpu")->sharedRegister("a"));
print("{}\n", *Emu::the().processingUnit("cpu")->sharedRegister("bc"));
while (true) {
Emu::the().update();
}

2
src/ppu.cpp

@ -20,5 +20,5 @@ PPU ::~PPU()
void PPU::update()
{
print("ppu update\n");
// print("ppu update\n");
}

5
src/processing-unit.cpp

@ -17,8 +17,3 @@ ProcessingUnit::ProcessingUnit(uint32_t frequency)
ProcessingUnit::~ProcessingUnit()
{
}
uint32_t ProcessingUnit::frequency()
{
return m_frequency;
}

9
src/processing-unit.h

@ -8,6 +8,7 @@
#pragma once
#include <cstdint> // uint32_t
#include <unordered_map>
class ProcessingUnit {
public:
@ -16,8 +17,12 @@ public:
virtual void update() = 0;
uint32_t frequency();
// -------------------------------------
private:
uint32_t frequency() const { return m_frequency; };
uint32_t* sharedRegister(const char* shared_register) const { return m_shared_registers.at(shared_register); }
protected:
uint32_t m_frequency { 0 };
std::unordered_map<const char*, uint32_t*> m_shared_registers;
};

Loading…
Cancel
Save