Compare commits
4
Commits
e3c3875195
...
85d54c9bcb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85d54c9bcb | ||
|
|
3163d0cb95 | ||
|
|
7f8f8fd493 | ||
|
|
b82ec9eb11 |
+15
-17
@@ -13,25 +13,23 @@
|
||||
|
||||
CPU::CPU(uint32_t frequency)
|
||||
: ProcessingUnit(frequency)
|
||||
{
|
||||
// CGB registers
|
||||
// https://gbdev.io/pandocs/Power_Up_Sequence.html#cpu-registers
|
||||
m_a = 0x11;
|
||||
m_b = 0x0;
|
||||
m_c = 0x0;
|
||||
m_d = 0xff;
|
||||
m_e = 0x56;
|
||||
m_h = 0x0;
|
||||
m_l = 0x0d;
|
||||
m_pc = 0x100;
|
||||
m_sp = 0xffe;
|
||||
|
||||
// CGB registers
|
||||
, m_a(0x11)
|
||||
, m_b(0x0)
|
||||
, m_c(0x0)
|
||||
, m_d(0xff)
|
||||
, m_e(0x56)
|
||||
, m_h(0x0)
|
||||
, m_l(0x0d)
|
||||
, m_pc(0x100)
|
||||
, m_sp(0xffe)
|
||||
// Flags
|
||||
m_zf = 0x1;
|
||||
m_nf = 0x0;
|
||||
m_hf = 0x0;
|
||||
m_cf = 0x0;
|
||||
|
||||
, m_zf(0x1)
|
||||
, m_nf(0x0)
|
||||
, m_hf(0x0)
|
||||
, m_cf(0x0)
|
||||
{
|
||||
m_shared_registers.emplace("a", &m_a);
|
||||
m_shared_registers.emplace("b", &m_b);
|
||||
m_shared_registers.emplace("c", &m_c);
|
||||
|
||||
+8
-5
@@ -1,13 +1,16 @@
|
||||
#include <cstdint> // uint32_t
|
||||
#include <string_view>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include "ruc/file.h"
|
||||
#include "ruc/format/print.h"
|
||||
|
||||
void Emu::init(uint32_t frequency)
|
||||
void Emu::init(uint32_t frequency, std::string_view bootrom)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
m_timestep = 1.0 / m_frequency * 1000000;
|
||||
m_bootrom = ruc::File(bootrom.data()).data();
|
||||
}
|
||||
|
||||
void Emu::update()
|
||||
@@ -26,23 +29,23 @@ void Emu::update()
|
||||
}
|
||||
}
|
||||
|
||||
void Emu::addProcessingUnit(const char* name, ProcessingUnit* processing_unit)
|
||||
void Emu::addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit)
|
||||
{
|
||||
m_processing_units.emplace(name, processing_unit);
|
||||
}
|
||||
|
||||
void Emu::addMemorySpace(const char* name, uint32_t size)
|
||||
void Emu::addMemorySpace(std::string_view name, uint32_t size)
|
||||
{
|
||||
std::vector<uint32_t> memory(size);
|
||||
m_memory_spaces.emplace(name, memory);
|
||||
}
|
||||
|
||||
void Emu::writeMemory(const char* memory_space, uint32_t location, uint32_t value)
|
||||
void Emu::writeMemory(std::string_view memory_space, uint32_t location, uint32_t value)
|
||||
{
|
||||
m_memory_spaces[memory_space][location] = value;
|
||||
}
|
||||
|
||||
uint32_t Emu::readMemory(const char* memory_space, uint32_t location)
|
||||
uint32_t Emu::readMemory(std::string_view memory_space, uint32_t location)
|
||||
{
|
||||
return m_memory_spaces[memory_space][location];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -12,19 +13,19 @@ class Emu final : public ruc::Singleton<Emu> {
|
||||
public:
|
||||
Emu(s) {}
|
||||
|
||||
void init(uint32_t frequency);
|
||||
void init(uint32_t frequency, std::string_view bootrom);
|
||||
|
||||
void update();
|
||||
|
||||
void addProcessingUnit(const char* name, ProcessingUnit* processing_unit);
|
||||
void addMemorySpace(const char* name, uint32_t size);
|
||||
void addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit);
|
||||
void addMemorySpace(std::string_view name, uint32_t size);
|
||||
|
||||
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
|
||||
uint32_t readMemory(const char* memory_space, uint32_t location);
|
||||
void writeMemory(std::string_view memory_space, uint32_t location, uint32_t value);
|
||||
uint32_t readMemory(std::string_view memory_space, uint32_t location);
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
ProcessingUnit* processingUnit(const char* name) const { return m_processing_units.at(name); }
|
||||
ProcessingUnit* processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||
|
||||
private:
|
||||
uint32_t m_frequency { 0 };
|
||||
@@ -35,6 +36,8 @@ private:
|
||||
|
||||
ruc::Timer m_timer;
|
||||
|
||||
std::unordered_map<const char*, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<const char*, std::vector<uint32_t>> m_memory_spaces;
|
||||
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<std::string_view, std::vector<uint32_t>> m_memory_spaces;
|
||||
|
||||
std::string_view m_bootrom;
|
||||
};
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
print("{}ms\n", t.elapsedNanoseconds() / 1000000.0);
|
||||
|
||||
Emu::the().init(8000000);
|
||||
Emu::the().init(8000000, "gbc_bios.bin");
|
||||
|
||||
CPU cpu(8000000);
|
||||
PPU ppu(4000000);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
class ProcessingUnit {
|
||||
@@ -20,9 +21,9 @@ public:
|
||||
// -------------------------------------
|
||||
|
||||
uint32_t frequency() const { return m_frequency; };
|
||||
uint32_t* sharedRegister(const char* shared_register) const { return m_shared_registers.at(shared_register); }
|
||||
uint32_t* sharedRegister(std::string_view 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;
|
||||
std::unordered_map<std::string_view, uint32_t*> m_shared_registers;
|
||||
};
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/ruc updated: b5e55f13d3...94eb1dd173
Reference in New Issue
Block a user