From 4abf87e2783828ef59071e229f2ba5b7fbe62c0d Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Thu, 24 Aug 2023 00:15:05 +0300 Subject: [PATCH] Adding PPU stub class --- CMakeLists.txt | 2 +- src/Nes.cpp | 5 ++++- src/Nes.h | 3 +++ src/Ppu.cpp | 26 ++++++++++++++++++++++++++ src/Ppu.h | 24 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Ppu.cpp create mode 100644 src/Ppu.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1851550..350a802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/src/Nes.cpp b/src/Nes.cpp index a7bfb0b..c00c28c 100644 --- a/src/Nes.cpp +++ b/src/Nes.cpp @@ -29,7 +29,10 @@ namespace nes { size_t ticks = 0; while (ticks <= 15000) { - _cpu->tick(); + _ppu->tick(); + if(ticks % 3 == 0) { + _cpu->tick(); + } ticks++; } diff --git a/src/Nes.h b/src/Nes.h index 8b245b5..8f607f9 100644 --- a/src/Nes.h +++ b/src/Nes.h @@ -7,6 +7,8 @@ #include "Cpu.h" #include "Cartridge.h" +#include "Ppu.h" + #include #include @@ -22,6 +24,7 @@ namespace nes { private: std::unique_ptr _cpu; + std::shared_ptr _ppu; std::shared_ptr _cartridge; }; diff --git a/src/Ppu.cpp b/src/Ppu.cpp new file mode 100644 index 0000000..6592ab3 --- /dev/null +++ b/src/Ppu.cpp @@ -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; + } + } + } +} \ No newline at end of file diff --git a/src/Ppu.h b/src/Ppu.h new file mode 100644 index 0000000..b00cdfa --- /dev/null +++ b/src/Ppu.h @@ -0,0 +1,24 @@ +// +// Created by selim on 8/22/23. +// + +#ifndef NES_PPU_H +#define NES_PPU_H + +#include + +namespace nes { + + class Ppu { + public: + Ppu(); + void tick(); + + private: + int16_t _column; + int16_t _scanline; + }; + +} + +#endif //NES_PPU_H