Compare commits
3
Commits
2ee1fa147d
...
0e67e7e2cc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e67e7e2cc | ||
|
|
68f78a0299 | ||
|
|
21da21a760 |
+14
-1
@@ -13,6 +13,16 @@
|
|||||||
CPU::CPU(uint32_t frequency)
|
CPU::CPU(uint32_t frequency)
|
||||||
: ProcessingUnit(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()
|
CPU::~CPU()
|
||||||
@@ -26,7 +36,10 @@ void CPU::update()
|
|||||||
// Read next opcode
|
// 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)
|
void CPU::add(uint8_t opcode, uint8_t immediate)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // int8_t, uint8_t, uint16_t, uint32_t
|
#include <cstdint> // int8_t, uint8_t, uint32_t
|
||||||
|
|
||||||
#include "processing-unit.h"
|
#include "processing-unit.h"
|
||||||
|
|
||||||
@@ -38,18 +38,18 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Registers
|
// Registers
|
||||||
uint8_t m_a { 0 }; // Accumulator
|
uint32_t m_a { 0 }; // Accumulator
|
||||||
uint16_t m_bc { 0 }; // BC
|
uint32_t m_bc { 0 }; // BC
|
||||||
uint16_t m_de { 0 }; // DE
|
uint32_t m_de { 0 }; // DE
|
||||||
uint16_t m_hl { 0 }; // HL
|
uint32_t m_hl { 0 }; // HL
|
||||||
uint16_t m_sp { 0 }; // Stack Pointer
|
uint32_t m_sp { 0 }; // Stack Pointer
|
||||||
uint16_t m_pc { 0 }; // Program Counter
|
uint32_t m_pc { 0 }; // Program Counter
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
uint8_t m_z { 0 }; // Zero flag
|
uint32_t m_z { 0 }; // Zero flag
|
||||||
uint8_t m_n { 0 }; // Subtraction flag (BCD)
|
uint32_t m_n { 0 }; // Subtraction flag (BCD)
|
||||||
uint8_t m_h { 0 }; // Half Carry flag (BCD)
|
uint32_t m_h { 0 }; // Half Carry flag (BCD)
|
||||||
uint8_t m_c { 0 }; // Carry flag
|
uint32_t m_c { 0 }; // Carry flag
|
||||||
|
|
||||||
int8_t m_wait_cycles { 0 };
|
int8_t m_wait_cycles { 0 };
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
#include <cstdint> // uint8_t, uint32_t
|
#include <cstdint> // uint32_t
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
@@ -42,7 +42,7 @@ void Emu::writeMemory(const char* memory_space, uint32_t location, uint32_t valu
|
|||||||
m_memory_spaces[memory_space][location] = value;
|
m_memory_spaces[memory_space][location] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Emu::readMemory(const char* memory_space, uint32_t location)
|
uint32_t Emu::readMemory(const char* memory_space, uint32_t location)
|
||||||
{
|
{
|
||||||
return m_memory_spaces[memory_space][location];
|
return m_memory_spaces[memory_space][location];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint8_t, uint32_t
|
#include <cstdint> // uint32_t
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -20,15 +20,18 @@ public:
|
|||||||
void addMemorySpace(const char* name, uint32_t size);
|
void addMemorySpace(const char* name, uint32_t size);
|
||||||
|
|
||||||
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
|
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
|
||||||
|
uint32_t readMemory(const char* memory_space, uint32_t location);
|
||||||
|
|
||||||
uint8_t readMemory(const char* memory_space, uint32_t location);
|
// -------------------------------------
|
||||||
|
|
||||||
|
ProcessingUnit* processingUnit(const char* name) const { return m_processing_units.at(name); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t m_frequency = 0;
|
uint32_t m_frequency { 0 };
|
||||||
double m_timestep = 0;
|
double m_timestep { 0 };
|
||||||
uint32_t m_cycle = 0;
|
uint32_t m_cycle { 0 };
|
||||||
double m_cycle_time = 0;
|
double m_cycle_time { 0 };
|
||||||
double m_previous_time = 0;
|
double m_previous_time { 0 };
|
||||||
|
|
||||||
ruc::Timer m_timer;
|
ruc::Timer m_timer;
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -3,13 +3,17 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "emu.h"
|
#include "emu.h"
|
||||||
#include "ppu.h"
|
#include "ppu.h"
|
||||||
|
#include "ruc/format/print.h"
|
||||||
#include "ruc/timer.h"
|
#include "ruc/timer.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
ruc::Timer t;
|
ruc::Timer t;
|
||||||
|
|
||||||
printf("%fms\n", t.elapsedNanoseconds() / 1000000.0);
|
print("{}ms\n", t.elapsedNanoseconds() / 1000000.0);
|
||||||
|
|
||||||
Emu::the().init(8000000);
|
Emu::the().init(8000000);
|
||||||
|
|
||||||
@@ -24,6 +28,11 @@ int main(int argc, char* argv[])
|
|||||||
Emu::the().addMemorySpace("ROM", 1024);
|
Emu::the().addMemorySpace("ROM", 1024);
|
||||||
Emu::the().addMemorySpace("CARDROM", 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) {
|
while (true) {
|
||||||
Emu::the().update();
|
Emu::the().update();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -20,5 +20,5 @@ PPU ::~PPU()
|
|||||||
|
|
||||||
void PPU::update()
|
void PPU::update()
|
||||||
{
|
{
|
||||||
print("ppu update\n");
|
// print("ppu update\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,3 @@ ProcessingUnit::ProcessingUnit(uint32_t frequency)
|
|||||||
ProcessingUnit::~ProcessingUnit()
|
ProcessingUnit::~ProcessingUnit()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ProcessingUnit::frequency()
|
|
||||||
{
|
|
||||||
return m_frequency;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint32_t
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
class ProcessingUnit {
|
class ProcessingUnit {
|
||||||
public:
|
public:
|
||||||
@@ -16,8 +17,12 @@ public:
|
|||||||
|
|
||||||
virtual void update() = 0;
|
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 };
|
uint32_t m_frequency { 0 };
|
||||||
|
std::unordered_map<const char*, uint32_t*> m_shared_registers;
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+1
-1
Submodule vendor/ruc updated: 1361ee04f9...b5e55f13d3
Reference in New Issue
Block a user