GarbAGE (Garbage Accurate GameBoy Emulator)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.2 KiB

#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, std::string_view bootrom)
{
m_frequency = frequency;
m_timestep = 1.0 / m_frequency * 1000000;
m_bootrom = ruc::File(bootrom.data()).data();
}
void Emu::update()
{
double time = m_timer.elapsedNanoseconds() / 1000.0;
m_cycle_time += (time - m_previous_time);
m_previous_time = time;
if (m_cycle_time > m_timestep) {
for (auto unit : m_processing_units) {
if (m_cycle % (m_frequency / unit.second->frequency()) == 0) {
unit.second->update();
}
}
m_cycle_time -= m_timestep;
m_cycle++;
}
}
void Emu::addProcessingUnit(const char* name, ProcessingUnit* processing_unit)
{
m_processing_units.emplace(name, processing_unit);
}
void Emu::addMemorySpace(const char* 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)
{
m_memory_spaces[memory_space][location] = value;
}
uint32_t Emu::readMemory(const char* memory_space, uint32_t location)
{
return m_memory_spaces[memory_space][location];
}