|
|
@ -7,32 +7,38 @@ |
|
|
|
void Emu::init(uint32_t frequency) |
|
|
|
void Emu::init(uint32_t frequency) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_frequency = frequency; |
|
|
|
m_frequency = frequency; |
|
|
|
|
|
|
|
m_timestep = 1.0 / m_frequency * 1000000; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Emu::update() |
|
|
|
void Emu::update() |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (auto unit : m_processing_units) { |
|
|
|
double time = m_timer.elapsedNanoseconds() / 1000.0; |
|
|
|
if (m_cycle % (m_frequency / unit->frequency()) == 0) { |
|
|
|
m_cycle_time += (time - m_previous_time); |
|
|
|
unit->update(); |
|
|
|
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++; |
|
|
|
} |
|
|
|
} |
|
|
|
m_cycle++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Emu::addProcessingUnit(ProcessingUnit* processing_unit) |
|
|
|
void Emu::addProcessingUnit(const char* name, ProcessingUnit* processing_unit) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_processing_units.push_back(processing_unit); |
|
|
|
m_processing_units.emplace(name, processing_unit); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Emu::addMemorySpace(const char* name, uint32_t size) |
|
|
|
void Emu::addMemorySpace(const char* name, uint32_t size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<uint8_t> memory(size); |
|
|
|
std::vector<uint32_t> memory(size); |
|
|
|
m_memory_spaces.emplace(name, memory); |
|
|
|
m_memory_spaces.emplace(name, memory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Emu::writeMemory(const char* memory_space, uint32_t location, uint8_t value) |
|
|
|
void Emu::writeMemory(const char* memory_space, uint32_t location, uint32_t value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
print("{} {} {}\n", memory_space, location, value); |
|
|
|
|
|
|
|
m_memory_spaces[memory_space][location] = value; |
|
|
|
m_memory_spaces[memory_space][location] = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|