From 9f10efa630ee991df9c6b56a55e022eeb5dd0b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 28 Jan 2020 16:29:18 +0100 Subject: [PATCH] PPU's constructor added and started read and write for the PPU --- sources/PPU/PPU.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++ sources/PPU/PPU.hpp | 15 +++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 90a06b1..2a1537a 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -3,3 +3,61 @@ // #include "PPU.hpp" +#include "../Exceptions/NotImplementedException.hpp" +#include "../Exceptions/InvalidAddress.hpp" + +namespace ComSquare::PPU +{ + uint8_t PPU::read(uint24_t addr) { + switch (addr) { + case 0x34: + return this->mpy.mpyl; + case 0x35: + return this->mpy.mpym; + case 0x36: + return this->mpy.mpyh; + default: + throw InvalidAddress("PPU Internal Registers read", addr); + } + } + + void PPU::write(uint24_t addr, uint8_t data) { + switch (addr) { + case 0x00: + this->inidisp.raw = data; + break; + case 0x01: + this->obsel.raw = data; + break; + case 0x02: + this->oamadd.oamaddl = data; + break; + case 0x03: + this->oamadd.oamaddh = data; + break; + case 0x04: + this->oamdata = data; + break; + case 0x05: + this->bgmode.raw = data; + break; + case 0x06: + this->mosaic.raw = data; + break; + case 0x07: + this->bg1sc.raw = data; + break; + case 0x08: + this->bg2sc.raw = data; + break; + case 0x09: + this->bg3sc.raw = data; + break; + case 0x0A: + this->bg4sc.raw = data; + break; + default: + throw InvalidAddress("PPU Internal Registers write", addr); + } + } +} \ No newline at end of file diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index 5972d55..28cdef2 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -6,11 +6,12 @@ #define COMSQUARE_PPU_HPP #include +#include "../Memory/IMemory.hpp" namespace ComSquare::PPU { //! @brief The struct containing all the registers the PPU - class PPU { + class PPU : public IMemory { private: //! @brief INIDISP Register (F-blank and Brightness) union { @@ -377,6 +378,18 @@ namespace ComSquare::PPU }; uint32_t mpy; } mpy; + public: + explicit PPU() = default; + //! @brief Read data from the component. + //! @param addr The local address to read from (0x0 should refer to the first byte of this component). + //! @throw This function should thrown an InvalidAddress for address that are not mapped to the component. + //! @return Return the data at the address given as parameter. + uint8_t read(uint24_t addr) override; + //! @brief Write data to this component. + //! @param addr The local address to write data (0x0 should refer to the first byte of this component). + //! @param data The new data to write. + //! @throw This function should thrown an InvalidAddress for address that are not mapped to the component. + void write(uint24_t addr, uint8_t data) override; }; } #endif //COMSQUARE_PPU_HPP