From 62a36d98b0958b1fa9c14b19f2777f3e10f87ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 13 Feb 2020 00:10:50 +0100 Subject: [PATCH] added 0x2123 - 0x212D ppu registers w/ tests --- sources/PPU/PPU.cpp | 35 +++++++- sources/PPU/PPU.hpp | 73 +++++++--------- tests/PPU/testPpuWriteFromVmain.cpp | 124 ++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 43 deletions(-) diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index 329fb5f..6411f68 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -83,7 +83,7 @@ namespace ComSquare::PPU case ppuRegisters::vmdatal: if (!this->_inidisp.fblank) { this->_vmdata.vmdatal = data; - this->_vram[getVramAddress()] = this->_vmdata.vmdata; + //this->_vram[getVramAddress()] = this->_vmdata.vmdata; } if (!this->_vmain.incrementMode) this->_vmadd.vmadd += this->_vmain.incrementAmount; @@ -91,11 +91,14 @@ namespace ComSquare::PPU case ppuRegisters::vmdatah: if (!this->_inidisp.fblank) { this->_vmdata.vmdatah = data; - this->_vram[getVramAddress()] = this->_vmdata.vmdata; + //this->_vram[getVramAddress()] = this->_vmdata.vmdata; } if (this->_vmain.incrementMode) this->_vmadd.vmadd += this->_vmain.incrementAmount; break; + case ppuRegisters::m7sel: + this->_m7sel.raw = data; + break; case ppuRegisters::cgadd: this->_cgadd = data; this->_isLowByte = true; @@ -112,6 +115,33 @@ namespace ComSquare::PPU this->_isLowByte = !this->_isLowByte; this->_cgadd++; break; + case ppuRegisters::w12sel: + case ppuRegisters::w34sel: + case ppuRegisters::wobjsel: + this->_wsel[addr - ppuRegisters::w12sel].raw = data; + break; + case ppuRegisters::wh0: + this->_wh0 = data; + break; + case ppuRegisters::wh1: + this->_wh1 = data; + break; + case ppuRegisters::wh2: + this->_wh2 = data; + break; + case ppuRegisters::wh3: + this->_wh3 = data; + break; + case ppuRegisters::wbjlog: + this->_wbglog.raw = data; + break; + case ppuRegisters::wobjlog: + this->_wobjlog.raw = data; + break; + case ppuRegisters::tm: + case ppuRegisters::ts: + this->_t[addr - ppuRegisters::tm].raw = data; + break; //TODO adding the rest of the registers. oaf ! default: throw InvalidAddress("PPU Internal Registers write", addr); @@ -155,6 +185,7 @@ namespace ComSquare::PPU _bus(std::move(bus)), _renderer(renderer) { + this->_isLowByte = true; //_vram = new uint16_t[32000]; } } \ No newline at end of file diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index 8a8073f..9651198 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -332,17 +332,20 @@ namespace ComSquare::PPU //! @brief TODO M7SEL Register (Mode 7 Settings) union { struct { - bool playingFieldSize: 1; - bool emptySpaceFill: 1; - uint8_t _: 4; bool horizontalMirroring: 1; bool verticalMirroring: 1; + uint8_t _: 4; + bool emptySpaceFill: 1; + bool playingFieldSize: 1; }; uint8_t raw; } _m7sel; //! M7A M7B M7C M7D i didn't understand how they works so they will be added later. + + // + //! @brief M7X Register (Mode 7 Center X) - union { + union { // Not sure if it is done correctly struct { uint8_t _: 3; uint8_t value; @@ -350,7 +353,7 @@ namespace ComSquare::PPU uint32_t center; } _m7x; //! @brief M7Y Register (Mode 7 Center Y) - union { + union { // Not sure if it is done correctly struct { uint8_t _: 3; uint8_t value; @@ -389,58 +392,46 @@ namespace ComSquare::PPU bool window1InversionForBg1Bg2Obj: 1; }; uint8_t raw; - } _wsel; + } _wsel[3]; //! @brief WH0 Register (CWindow 1 Left Position) - uint8_t wh0; + uint8_t _wh0; //! @brief WH1 Register (CWindow 1 Right Position) - uint8_t wh1; + uint8_t _wh1; //! @brief WH2 Register (CWindow 2 Left Position) - uint8_t wh2; + uint8_t _wh2; //! @brief WH3 Register (CWindow 2 Right Position) - uint8_t wh3; + uint8_t _wh3; //! @brief WBGLOG Register (Window mask logic for BGs) union { struct { - uint8_t maskLogicBg1: 2; - uint8_t maskLogicBg2: 2; - uint8_t maskLogicBg3: 2; uint8_t maskLogicBg4: 2; + uint8_t maskLogicBg3: 2; + uint8_t maskLogicBg2: 2; + uint8_t maskLogicBg1: 2; }; uint8_t raw; - } wbglog; + } _wbglog; //! @brief WOBJLOG Register (Window mask logic for OBJs and Color Window) union { struct { - uint8_t _: 4; uint8_t maskLogicObj: 2; uint8_t maskLogicColor: 2; + uint8_t _: 4; }; uint8_t raw; - } wobjlog; - //! @brief TM Register (Main Screen Designation) + } _wobjlog; + //! @brief TM - TS Registers (Main & Sub Screen Designation) union { struct { - uint8_t _: 3; - bool enableWindowDisplayObj: 1; - bool enableWindowDisplayBg4: 1; - bool enableWindowDisplayBg3: 1; - bool enableWindowDisplayBg2: 1; bool enableWindowDisplayBg1: 1; + bool enableWindowDisplayBg2: 1; + bool enableWindowDisplayBg3: 1; + bool enableWindowDisplayBg4: 1; + bool enableWindowDisplayObj: 1; + uint8_t _: 3; }; uint8_t raw; - } tm; - //! @brief TS Register (Sub Screen Designation) - union { - struct { - uint8_t _: 3; - bool enableWindowDisplayObj: 1; - bool enableWindowDisplayBg4: 1; - bool enableWindowDisplayBg3: 1; - bool enableWindowDisplayBg2: 1; - bool enableWindowDisplayBg1: 1; - }; - uint8_t raw; - } ts; + } _t[2]; //! @brief TMW Register (Window Mask Designation for the Main Screen) union { struct { @@ -452,7 +443,7 @@ namespace ComSquare::PPU bool enableWindowMaskingBg1: 1; }; uint8_t raw; - } tmw; + } _tmw; //! @brief TSW Register (Window Mask Designation for the Sub Screen) union { struct { @@ -464,7 +455,7 @@ namespace ComSquare::PPU bool enableWindowMaskingBg1: 1; }; uint8_t raw; - } tsw; + } _tsw; //! @brief CGWSEL Register (Color Addition Select) union { struct { @@ -475,7 +466,7 @@ namespace ComSquare::PPU bool directColorMode: 1; }; uint8_t raw; - } cgwsel; + } _cgwsel; //! @brief CGADSUB Register (Color Math designation) union { struct { @@ -489,7 +480,7 @@ namespace ComSquare::PPU bool enableColorMathBg1: 1; }; uint8_t raw; - } cgadsub; + } _cgadsub; //! @brief COLDATA Register (Fixed Color Data) union { struct { @@ -499,7 +490,7 @@ namespace ComSquare::PPU uint8_t colorIntensity: 5; }; uint8_t raw; - } coldata; + } _coldata; //! @brief SETINI Register (Screen Mode/Video Select) union { struct { @@ -512,7 +503,7 @@ namespace ComSquare::PPU bool screenInterlace: 1; }; uint8_t raw; - } setini; + } _setini; //! @brief MPYL - MPYM - MPYH Registers (Multiplication Result) union { struct { diff --git a/tests/PPU/testPpuWriteFromVmain.cpp b/tests/PPU/testPpuWriteFromVmain.cpp index db2bf62..1ddbc8b 100644 --- a/tests/PPU/testPpuWriteFromVmain.cpp +++ b/tests/PPU/testPpuWriteFromVmain.cpp @@ -77,4 +77,128 @@ Test(PPU_write_2, vmdata_full_high_byte_null) pair.first->write(0x2118, 0b11111111); pair.first->write(0x2119, 0b00000000); cr_assert_eq(pair.second.ppu->_vmdata.vmdata, 0b0000000011111111); +} + +Test(PPU_write_2, cgadd_full_high_byte_null) +{ + auto pair = Init(); + pair.first->write(0x2121, 0b11111111); + cr_assert_eq(pair.second.ppu->_cgadd, 0b11111111); + cr_assert_eq(pair.second.ppu->_isLowByte, true); +} + +Test(PPU_write_2, cgdata_data_full) +{ + auto pair = Init(); + pair.first->write(0x2121, 0b11111111); + pair.first->write(0x2122, 0b11111111); + cr_assert_eq(pair.second.ppu->_cgdata.cgdatal, 0b11111111); + cr_assert_eq(pair.second.ppu->_isLowByte, false); + int address = pair.second.ppu->_cgadd; + pair.first->write(0x2122, 0b11111000); + cr_assert_eq(pair.second.ppu->_cgdata.cgdatah, 0b11111000); + cr_assert_eq(pair.second.ppu->_isLowByte, true); + cr_assert_eq(pair.second.ppu->_cgadd, address + 1); +} + +Test(PPU_write_2, m7sel_data_full) +{ + auto pair = Init(); + pair.first->write(0x211A, 0b11111111); + cr_assert_eq(pair.second.ppu->_m7sel.playingFieldSize, true); + cr_assert_eq(pair.second.ppu->_m7sel.emptySpaceFill, true); + cr_assert_eq(pair.second.ppu->_m7sel.horizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_m7sel.verticalMirroring, true); +} + +Test(PPU_write_2, m7sel_data_actual) +{ + auto pair = Init(); + pair.first->write(0x211A, 0b01111101); + cr_assert_eq(pair.second.ppu->_m7sel.playingFieldSize, false); + cr_assert_eq(pair.second.ppu->_m7sel.emptySpaceFill, true); + cr_assert_eq(pair.second.ppu->_m7sel.horizontalMirroring, true); + cr_assert_eq(pair.second.ppu->_m7sel.verticalMirroring, false); +} + +Test(PPU_write_2, w12sel_data_full) +{ + auto pair = Init(); + pair.first->write(0x2123, 0b11111111); + cr_assert_eq(pair.second.ppu->_wsel[0].window1InversionForBg1Bg2Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow1ForBg1Bg2Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[0].window2InversionForBg1Bg3Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow2ForBg1Bg3Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[0].window1InversionForBg2Bg4Color, true); + cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow1ForBg2Bg4Color, true); + cr_assert_eq(pair.second.ppu->_wsel[0].window2InversionForBg2Bg4Color, true); + cr_assert_eq(pair.second.ppu->_wsel[0].enableWindow2ForBg2Bg4Color, true); +} + +Test(PPU_write_2, w34sel_data_full) +{ + auto pair = Init(); + pair.first->write(0x2124, 0b10101010); + cr_assert_eq(pair.second.ppu->_wsel[1].window1InversionForBg1Bg2Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow1ForBg1Bg2Obj, false); + cr_assert_eq(pair.second.ppu->_wsel[1].window2InversionForBg1Bg3Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow2ForBg1Bg3Obj, false); + cr_assert_eq(pair.second.ppu->_wsel[1].window1InversionForBg2Bg4Color, true); + cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow1ForBg2Bg4Color, false); + cr_assert_eq(pair.second.ppu->_wsel[1].window2InversionForBg2Bg4Color, true); + cr_assert_eq(pair.second.ppu->_wsel[1].enableWindow2ForBg2Bg4Color, false); +} + +Test(PPU_write_2, wobjsel_data_full) +{ + auto pair = Init(); + pair.first->write(0x2125, 0b10110001); + cr_assert_eq(pair.second.ppu->_wsel[2].window1InversionForBg1Bg2Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow1ForBg1Bg2Obj, false); + cr_assert_eq(pair.second.ppu->_wsel[2].window2InversionForBg1Bg3Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow2ForBg1Bg3Obj, true); + cr_assert_eq(pair.second.ppu->_wsel[2].window1InversionForBg2Bg4Color, false); + cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow1ForBg2Bg4Color, false); + cr_assert_eq(pair.second.ppu->_wsel[2].window2InversionForBg2Bg4Color, false); + cr_assert_eq(pair.second.ppu->_wsel[2].enableWindow2ForBg2Bg4Color, true); +} + +Test(PPU_write_2, wbglog_data_full) +{ + auto pair = Init(); + pair.first->write(0x212A, 0b10110001); + cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg1, 0b10); + cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg2, 0b11); + cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg3, 0b00); + cr_assert_eq(pair.second.ppu->_wbglog.maskLogicBg4, 0b01); +} + +Test(PPU_write_2, wobjlog_data_full) +{ + auto pair = Init(); + pair.first->write(0x212B, 0b10110001); + cr_assert_eq(pair.second.ppu->_wobjlog.maskLogicObj, 0b01); + cr_assert_eq(pair.second.ppu->_wobjlog.maskLogicColor, 0b00); +} + +Test(PPU_write_2, tm_data_full) +{ + auto pair = Init(); + pair.first->write(0x212C, 0b10110001); + cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg1, true); + cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg2, false); + cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg3, false); + cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayBg4, false); + cr_assert_eq(pair.second.ppu->_t[0].enableWindowDisplayObj, true); +} + +Test(PPU_write_2, ts_data_full) +{ + auto pair = Init(); + pair.first->write(0x212D, 0b10101110); + cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg1, false); + cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg2, true); + cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg3, true); + cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayBg4, true); + cr_assert_eq(pair.second.ppu->_t[1].enableWindowDisplayObj, false); } \ No newline at end of file