Emulator: Remove bootrom as separate Emu member variable
This commit is contained in:
+9
-9
@@ -23,7 +23,6 @@ CPU::CPU(uint32_t frequency)
|
||||
, m_e(0x56)
|
||||
, m_h(0x0)
|
||||
, m_l(0x0d)
|
||||
// , m_pc(0x100)
|
||||
, m_pc(0x0)
|
||||
, m_sp(0xfffe)
|
||||
// Flags
|
||||
@@ -65,7 +64,8 @@ void CPU::update()
|
||||
m_wait_cycles--;
|
||||
if (m_wait_cycles <= 0) {
|
||||
// Read next opcode
|
||||
uint8_t opcode = peekBootrom();
|
||||
uint8_t opcode = peekMemory();
|
||||
VERIFY(m_opcode_lookup_table.find(opcode) != m_opcode_lookup_table.end(), "opcode {:#x} not implemented", opcode);
|
||||
m_opcode_lookup_table[opcode]();
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ void CPU::update()
|
||||
|
||||
void CPU::add()
|
||||
{
|
||||
uint8_t opcode = consumeBootrom();
|
||||
uint8_t immediate = consumeBootrom();
|
||||
uint8_t opcode = consumeMemory();
|
||||
uint8_t immediate = consumeMemory();
|
||||
switch (opcode) {
|
||||
case 0xc6: // ADD A,d8
|
||||
// Program counter +2
|
||||
@@ -103,7 +103,7 @@ void CPU::add()
|
||||
|
||||
void CPU::ld16()
|
||||
{
|
||||
uint8_t opcode = consumeBootrom();
|
||||
uint8_t opcode = consumeMemory();
|
||||
switch (opcode) {
|
||||
case 0x01: {
|
||||
m_wait_cycles += 12;
|
||||
@@ -130,14 +130,14 @@ void CPU::ld16()
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
uint8_t CPU::peekBootrom(int32_t offset) const
|
||||
uint8_t CPU::peekMemory(int32_t offset) const
|
||||
{
|
||||
return Emu::the().bootrom()[m_pc + offset];
|
||||
return Emu::the().readMemory(m_pc + offset);
|
||||
}
|
||||
|
||||
uint8_t CPU::consumeBootrom()
|
||||
uint8_t CPU::consumeMemory()
|
||||
{
|
||||
return Emu::the().bootrom()[m_pc++];
|
||||
return Emu::the().readMemory(m_pc++);
|
||||
}
|
||||
|
||||
void CPU::setBc(uint32_t value)
|
||||
|
||||
@@ -52,10 +52,10 @@ public:
|
||||
// Miscellaneous Instructions
|
||||
|
||||
private:
|
||||
uint8_t peekBootrom(int32_t offset = 0) const;
|
||||
uint8_t consumeBootrom();
|
||||
uint8_t peekMemory(int32_t offset = 0) const;
|
||||
uint8_t consumeMemory();
|
||||
|
||||
uint32_t immediate16() { return (consumeBootrom() << 8) | consumeBootrom(); }
|
||||
uint32_t immediate16() { return (consumeMemory() << 8) | consumeMemory(); }
|
||||
|
||||
void setBc(uint32_t value);
|
||||
void setDe(uint32_t value);
|
||||
|
||||
+1
-3
@@ -10,15 +10,13 @@
|
||||
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include "ruc/file.h"
|
||||
#include "ruc/format/print.h"
|
||||
#include "ruc/meta/assert.h"
|
||||
|
||||
void Emu::init(uint32_t frequency, std::string_view bootrom)
|
||||
void Emu::init(uint32_t frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
m_timestep = 1.0 / m_frequency * 1000000;
|
||||
m_bootrom = ruc::File(bootrom.data()).data();
|
||||
}
|
||||
|
||||
void Emu::update()
|
||||
|
||||
@@ -30,7 +30,7 @@ class Emu final : public ruc::Singleton<Emu> {
|
||||
public:
|
||||
Emu(s) {}
|
||||
|
||||
void init(uint32_t frequency, std::string_view bootrom);
|
||||
void init(uint32_t frequency);
|
||||
|
||||
void update();
|
||||
|
||||
@@ -44,8 +44,6 @@ public:
|
||||
|
||||
ProcessingUnit* processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||
|
||||
std::string_view bootrom() const { return m_bootrom; }
|
||||
|
||||
private:
|
||||
uint32_t m_frequency { 0 };
|
||||
double m_timestep { 0 };
|
||||
@@ -57,6 +55,4 @@ private:
|
||||
|
||||
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<std::string_view, MemorySpace> m_memory_spaces;
|
||||
|
||||
std::string m_bootrom;
|
||||
};
|
||||
|
||||
+4
-4
@@ -20,7 +20,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
print("{}ms\n", t.elapsedNanoseconds() / 1000000.0);
|
||||
|
||||
Emu::the().init(8000000, "gbc_bios.bin");
|
||||
Emu::the().init(8000000);
|
||||
|
||||
CPU cpu(8000000);
|
||||
PPU ppu(4000000);
|
||||
@@ -36,9 +36,9 @@ int main(int argc, char* argv[])
|
||||
Emu::the().addMemorySpace("CARDRAM", 0xa000, 0xbfff); // 8KiB
|
||||
Emu::the().addMemorySpace("WRAM1", 0xc000, 0xcfff, 1); // 4 KiB, Work RAM
|
||||
Emu::the().addMemorySpace("WRAM2", 0xd000, 0xdfff, 7); // 4 KiB * 7 banks, Work RAM
|
||||
Emu::the().addMemorySpace("ECHORAM", 0xe000, 0xfdff, 1); // 7679B, Mirror of 0xc000~0xddff
|
||||
Emu::the().addMemorySpace("OAM", 0xfe00, 0xfe9f, 1); // 4KiB, Object Attribute Memory (VRAM Sprite Attribute Table)
|
||||
Emu::the().addMemorySpace("HRAM", 0xff80, 0xfffe, 1); // 126B, High RAM (CPU cache)
|
||||
Emu::the().addMemorySpace("ECHORAM", 0xe000, 0xfdff, 1); // 7680B, Mirror of 0xc000~0xddff
|
||||
Emu::the().addMemorySpace("OAM", 0xfe00, 0xfe9f, 1); // 160B, Object Attribute Memory (VRAM Sprite Attribute Table)
|
||||
Emu::the().addMemorySpace("HRAM", 0xff80, 0xfffe, 1); // 127B, High RAM (CPU cache)
|
||||
|
||||
// Get shared register
|
||||
print("{}\n", *Emu::the().processingUnit("cpu")->sharedRegister("a"));
|
||||
|
||||
Reference in New Issue
Block a user