From 2278082cbb5400e5965710cfcdf6a0a06de8d1ed Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Fri, 25 Aug 2023 18:01:38 +0300 Subject: [PATCH] More PPU code --- src/Ppu.cpp | 14 +++++++++++--- src/Ppu.h | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Ppu.cpp b/src/Ppu.cpp index 789ab0e..25ee7df 100644 --- a/src/Ppu.cpp +++ b/src/Ppu.cpp @@ -6,7 +6,7 @@ namespace nes { - Ppu::Ppu(): _column{}, _scanline{} { + Ppu::Ppu(): _column{}, _scanline{}, _status{} { _frameBuffer = std::make_unique(SCREEN_WIDTH*SCREEN_HEIGHT); } @@ -32,11 +32,19 @@ namespace nes { } void Ppu::write(uint16_t address, uint8_t value) { - + switch (address) { + default: + break; + } } uint8_t Ppu::read(uint16_t address) { - return 0; + switch (address) { + case Status: + uint8_t value = _status.value & 0xE0; + _status.verticalBlank = 0; + return value; + } } void Ppu::setPixel(uint16_t row, uint16_t column, Pixel pixel) { diff --git a/src/Ppu.h b/src/Ppu.h index 954dbac..67d6481 100644 --- a/src/Ppu.h +++ b/src/Ppu.h @@ -23,6 +23,27 @@ namespace nes { static constexpr uint16_t SCREEN_WIDTH = 256; static constexpr uint16_t SCREEN_HEIGHT = 240; + enum ControlAddress: uint16_t { + Control = 0x0000, + Mask = 0x0001, + Status = 0x0002, + OamAddress = 0x0003, + OamData = 0x0004, + Scroll = 0x0005, + PpuAddress = 0x0006, + PpuData = 0x0007 + }; + + union StatusRegister { + struct { + uint8_t unused: 5; + uint8_t spriteOverflow: 1; + uint8_t spriteZeroHit: 1; + uint8_t verticalBlank: 1; + }; + uint8_t value; + }; + public: Ppu(); void tick(); @@ -36,6 +57,7 @@ namespace nes { private: int16_t _column; int16_t _scanline; + StatusRegister _status; std::unique_ptr _frameBuffer; };