PPU's constructor added and started read and write for the PPU

This commit is contained in:
Clément Le Bihan
2020-01-28 16:29:18 +01:00
parent 8fc7f8627a
commit 9f10efa630
2 changed files with 72 additions and 1 deletions
+58
View File
@@ -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);
}
}
}
+14 -1
View File
@@ -6,11 +6,12 @@
#define COMSQUARE_PPU_HPP
#include <stdint-gcc.h>
#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