Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6da0184713 | ||
|
|
de2237fac2 | ||
|
|
83d3a33e14 | ||
|
|
cef2ebd926 | ||
|
|
57576aaf9b | ||
|
|
4df59970da | ||
|
|
915db7dc85 |
+2
-1
@@ -7,7 +7,8 @@
|
||||
|
||||
#include "apu.h"
|
||||
|
||||
APU::APU(unsigned int frequency) : ProcessingUnit(frequency)
|
||||
APU::APU(unsigned int frequency)
|
||||
: ProcessingUnit(frequency)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+26
-3
@@ -9,7 +9,8 @@
|
||||
#include "emu.h"
|
||||
#include <iostream>
|
||||
|
||||
CPU::CPU(unsigned int frequency) : ProcessingUnit(frequency)
|
||||
CPU::CPU(unsigned int frequency)
|
||||
: ProcessingUnit(frequency)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -17,8 +18,30 @@ CPU::~CPU()
|
||||
{
|
||||
}
|
||||
|
||||
void CPU::update() {
|
||||
void CPU::update()
|
||||
{
|
||||
printf("This is an update from the CPU\n");
|
||||
Emu::the().writeMemory("RAM", 123, 42);
|
||||
printf("fff");
|
||||
}
|
||||
}
|
||||
|
||||
void CPU::add(uint8_t byte, uint8_t immediate)
|
||||
{
|
||||
switch (byte) {
|
||||
case 0xc6: // ADD A,d8
|
||||
// program_counter += 2;
|
||||
// clock += 8;
|
||||
|
||||
// Flags: Z0HC
|
||||
m_z = (m_af >> 8) + immediate == 0;
|
||||
m_n = 0;
|
||||
m_h = (m_af >> 8) + immediate > 16;
|
||||
m_c = (m_af >> 8) + immediate > 255;
|
||||
|
||||
// A = A + r
|
||||
m_af = m_af + (immediate << 8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ public:
|
||||
virtual ~CPU();
|
||||
|
||||
void update() override;
|
||||
|
||||
|
||||
// 8-bit Arithmetic and Logic Instructions
|
||||
|
||||
void add(uint8_t byte, uint8_t immediate = 0);
|
||||
|
||||
// 16-bit Arithmetic Instructions
|
||||
|
||||
// Bit Operations Instructions
|
||||
|
||||
+22
-15
@@ -1,12 +1,16 @@
|
||||
#include "emu.h"
|
||||
#include "cpu.h"
|
||||
#include <iostream>
|
||||
#include <cstdint> // uint8_t, uint32_t
|
||||
|
||||
void Emu::init(unsigned int frequency) {
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include "ruc/format/print.h"
|
||||
|
||||
void Emu::init(uint32_t frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
}
|
||||
|
||||
void Emu::update() {
|
||||
void Emu::update()
|
||||
{
|
||||
for (auto unit : m_processing_units) {
|
||||
if (m_cycle % (m_frequency / unit->frequency()) == 0) {
|
||||
unit->update();
|
||||
@@ -15,21 +19,24 @@ void Emu::update() {
|
||||
m_cycle++;
|
||||
}
|
||||
|
||||
void Emu::addProcessingUnit(ProcessingUnit* processing_unit) {
|
||||
void Emu::addProcessingUnit(ProcessingUnit* processing_unit)
|
||||
{
|
||||
m_processing_units.push_back(processing_unit);
|
||||
}
|
||||
|
||||
void Emu::addMemorySpace(const char* name, int size) {
|
||||
std::vector<uint8_t> memory;
|
||||
memory.reserve(size);
|
||||
void Emu::addMemorySpace(const char* name, uint32_t size)
|
||||
{
|
||||
std::vector<uint8_t> memory(size);
|
||||
m_memory_spaces.emplace(name, memory);
|
||||
}
|
||||
|
||||
void Emu::writeMemory(const char* memory_space, unsigned int location, uint8_t value) {
|
||||
// printf("%s %d %d", memory_space, location, value);
|
||||
// m_memory_spaces[memory_space][location] = value;
|
||||
void Emu::writeMemory(const char* memory_space, uint32_t location, uint8_t value)
|
||||
{
|
||||
print("{} {} {}\n", memory_space, location, value);
|
||||
m_memory_spaces[memory_space][location] = value;
|
||||
}
|
||||
|
||||
uint8_t Emu::readMemory(const char* memory_space, unsigned int location){
|
||||
// return m_memory_spaces[memory_space][location];
|
||||
}
|
||||
uint8_t Emu::readMemory(const char* memory_space, uint32_t location)
|
||||
{
|
||||
return m_memory_spaces[memory_space][location];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <cstdint> // uint8_t, uint32_t
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "processing-unit.h"
|
||||
#include "ruc/singleton.h"
|
||||
@@ -11,20 +11,20 @@ class Emu final : public ruc::Singleton<Emu> {
|
||||
public:
|
||||
Emu(s) {}
|
||||
|
||||
void init(unsigned int frequency);
|
||||
void init(uint32_t frequency);
|
||||
|
||||
void update();
|
||||
|
||||
void addProcessingUnit(ProcessingUnit* processing_unit);
|
||||
void addMemorySpace(const char* name, int size);
|
||||
void addMemorySpace(const char* name, uint32_t size);
|
||||
|
||||
void writeMemory(const char* memory_space, unsigned int location, uint8_t value);
|
||||
void writeMemory(const char* memory_space, uint32_t location, uint8_t value);
|
||||
|
||||
uint8_t readMemory(const char* memory_space, unsigned int location);
|
||||
uint8_t readMemory(const char* memory_space, uint32_t location);
|
||||
|
||||
private:
|
||||
unsigned int m_frequency;
|
||||
unsigned int m_cycle = 0;
|
||||
uint32_t m_frequency;
|
||||
uint32_t m_cycle = 0;
|
||||
|
||||
std::vector<ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<const char*, std::vector<uint8_t>> m_memory_spaces;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "emu.h"
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
#include "ppu.h"
|
||||
#include "ruc/timer.h"
|
||||
|
||||
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
Emu::the().addMemorySpace("RAM", 1024);
|
||||
|
||||
for(int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
Emu::the().update();
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -8,7 +8,8 @@
|
||||
#include "ppu.h"
|
||||
#include <iostream>
|
||||
|
||||
PPU ::PPU(unsigned int frequency) : ProcessingUnit(frequency)
|
||||
PPU ::PPU(unsigned int frequency)
|
||||
: ProcessingUnit(frequency)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -16,6 +17,7 @@ PPU ::~PPU()
|
||||
{
|
||||
}
|
||||
|
||||
void PPU::update() {
|
||||
void PPU::update()
|
||||
{
|
||||
printf("ppu update\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ class PPU final : public ProcessingUnit {
|
||||
public:
|
||||
PPU(unsigned int frequency);
|
||||
virtual ~PPU();
|
||||
|
||||
virtual void update() override;
|
||||
};
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "processing-unit.h"
|
||||
#include <iostream>
|
||||
#include <cstdint> // uint32_t
|
||||
|
||||
ProcessingUnit::ProcessingUnit(unsigned int frequency) : m_frequency(frequency)
|
||||
#include "processing-unit.h"
|
||||
|
||||
ProcessingUnit::ProcessingUnit(uint32_t frequency)
|
||||
: m_frequency(frequency)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -16,6 +18,7 @@ ProcessingUnit::~ProcessingUnit()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int ProcessingUnit::frequency() {
|
||||
uint32_t ProcessingUnit::frequency()
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
|
||||
class ProcessingUnit {
|
||||
public:
|
||||
ProcessingUnit(unsigned int frequency);
|
||||
ProcessingUnit(uint32_t frequency);
|
||||
virtual ~ProcessingUnit();
|
||||
|
||||
virtual void update() = 0;
|
||||
|
||||
unsigned int frequency();
|
||||
uint32_t frequency();
|
||||
|
||||
private:
|
||||
unsigned int m_frequency;
|
||||
uint32_t m_frequency { 0 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user