Adding PPU stub class

This commit is contained in:
Selim Mustafaev 2023-08-24 00:15:05 +03:00
parent d3401cd3af
commit 4abf87e278
5 changed files with 58 additions and 2 deletions

View File

@ -16,7 +16,7 @@ add_executable(nes
src/Mapper/Mapper.cpp
src/Mapper/Mapper.h
src/Mapper/Mapper0.cpp
src/Mapper/Mapper0.h)
src/Mapper/Mapper0.h src/Ppu.cpp src/Ppu.h)
find_package(SDL2 CONFIG REQUIRED)
target_link_libraries(nes PRIVATE SDL2::SDL2)

View File

@ -29,7 +29,10 @@ namespace nes {
size_t ticks = 0;
while (ticks <= 15000) {
_cpu->tick();
_ppu->tick();
if(ticks % 3 == 0) {
_cpu->tick();
}
ticks++;
}

View File

@ -7,6 +7,8 @@
#include "Cpu.h"
#include "Cartridge.h"
#include "Ppu.h"
#include <filesystem>
#include <optional>
@ -22,6 +24,7 @@ namespace nes {
private:
std::unique_ptr<Cpu> _cpu;
std::shared_ptr<Ppu> _ppu;
std::shared_ptr<Cartridge> _cartridge;
};

26
src/Ppu.cpp Normal file
View File

@ -0,0 +1,26 @@
//
// Created by selim on 8/22/23.
//
#include "Ppu.h"
namespace nes {
Ppu::Ppu(): _column{}, _scanline{} {
}
void Ppu::tick() {
_column++;
if(_column >= 341) {
_column = 0;
_scanline++;
if(_scanline >= 261) {
_scanline = -1;
}
}
}
}

24
src/Ppu.h Normal file
View File

@ -0,0 +1,24 @@
//
// Created by selim on 8/22/23.
//
#ifndef NES_PPU_H
#define NES_PPU_H
#include <cstdint>
namespace nes {
class Ppu {
public:
Ppu();
void tick();
private:
int16_t _column;
int16_t _scanline;
};
}
#endif //NES_PPU_H