main window displaying the value of all the cgram

This commit is contained in:
Clément Le Bihan
2020-02-15 17:57:54 +01:00
parent c831562a7c
commit 0b2146be2f
2 changed files with 40 additions and 20 deletions
+39 -19
View File
@@ -3,6 +3,7 @@
//
#include <iostream>
#include <bitset>
#include "PPU.hpp"
#include "../Exceptions/NotImplementedException.hpp"
#include "../Exceptions/InvalidAddress.hpp"
@@ -40,7 +41,7 @@ namespace ComSquare::PPU
break;
case ppuRegisters::oamdata:
this->_oamdata = data;
throw InvalidAddress("oamdata", addr);
//throw InvalidAddress("oamdata", addr);
std::cout << "oamdata" << std::endl;
// the oamAddress have to be calculated if fblank or not (not implemented)
_oamram.write(this->_oamadd.oamAddress, this->_oamdata);
@@ -88,6 +89,7 @@ namespace ComSquare::PPU
case 0b11:
this->_incrementAmount = 128;
}
break;
case ppuRegisters::vmaddl:
this->_vmadd.vmaddl = data;
break;
@@ -95,7 +97,7 @@ namespace ComSquare::PPU
this->_vmadd.vmaddh = data;
break;
case ppuRegisters::vmdatal:
throw InvalidAddress("vmdata", addr);
//throw InvalidAddress("vmdata", addr);
std::cout << "vmdatal" << std::endl;
if (!this->_inidisp.fblank) {
this->_vmdata.vmdatal = data;
@@ -121,19 +123,20 @@ namespace ComSquare::PPU
this->_isLowByte = true;
break;
case ppuRegisters::cgdata:
throw InvalidAddress("cgdata", addr);
//throw InvalidAddress("cgdata", addr);
if (this->_isLowByte) {
std::cout << "cgadatal" << std::endl;
//std::cout << "cgadatal" << std::endl;
this->_cgdata.cgdatal = data;
this->_cgram.write(this->_cgadd, this->_cgdata.raw);
//this->_cgram.write(this->_cgadd, this->_cgdata.raw);
//this->_cgadd++;
}
else {
std::cout << "cgadatah" << std::endl;
//std::cout << "cgadatah" << std::endl;
this->_cgdata.cgdatah = data;
this->_cgram.write(this->_cgadd, this->_cgdata.raw);
this->_cgadd++;
}
this->_isLowByte = !this->_isLowByte;
this->_cgadd++;
break;
case ppuRegisters::w12sel:
case ppuRegisters::w34sel:
@@ -203,28 +206,45 @@ namespace ComSquare::PPU
void PPU::update(unsigned cycles)
{
(void)cycles;
int inc = 0;
//uint32_t pixelTmp = 0xFFFFFFFF;
//pixelTmp |= this->_inidisp.brightness;
/*this->_bus->write(0x2121, 0);
for (uint16_t value = 0; value <= 256; value++) {
this->_bus->write(0x2122, 0b11100000);
this->_bus->write(0x2122, 0b00000011);
}*/
uint16_t tmp;
uint8_t red;
uint8_t green;
uint8_t blue;
uint32_t pixelTmp = 0x000000FF;
//std::cout << "update" << std::endl;
if (!this->_inidisp.fblank) {
for (int x = 0; x < 448; x++) {
for (int y = 0; y < 512; y++) {
if (inc == 0xFA00)
inc = 0;
//std::cout << "holy" << std::endl;
this->_renderer.putPixel(x, y, (uint32_t)this->_vram.read(inc++));
for (int y = 0; y <= 255; y++) {
tmp = this->_cgram.read(y);
//std::cout << "tmp " << std::bitset<16>(tmp) << std::endl;
blue = (tmp & 0x7D00U) >> 10U;
green = (tmp & 0x03E0U) >> 5U;
red = (tmp & 0x001FU);
//std::cout << "red " << std::bitset<8>(red) << std::endl;
//std::cout << "green " << std::bitset<8>(green) << std::endl;
//std::cout << "blue " << std::bitset<8>(blue) << std::endl;
pixelTmp += (red * 256U / 32U) << 24U;
pixelTmp += (green * 256U / 32U) << 16U;
pixelTmp += (blue * 256U / 32U) << 8U;
//std::cout << "value of pixel " << std::hex << pixelTmp << " pour inc " << std::dec << y << std::endl;
for (int x = 0; x < 100; x++)
this->_renderer.putPixel(x, y, pixelTmp);
pixelTmp = 0xFF;
}
}
}
//std::cout << "cgadata2" << std::endl;
this->_renderer.drawScreen();
}
PPU::PPU(const std::shared_ptr<Memory::MemoryBus> &bus, Renderer::IRenderer &renderer):
_renderer(renderer),
_bus(std::move(bus)),
_vram(64000),
_vram(65536),
_oamram(544),
_cgram(512)
{
+1 -1
View File
@@ -340,7 +340,7 @@ namespace ComSquare::PPU
uint8_t raw;
} _vmain;
//! @brief Store the real value of the increment Amount (1, 32, 128) instead of 0,1 or 2
uint8_t _incrementAmount;
uint8_t _incrementAmount = 1;
//! @brief VMADD Register (VRAM Address)
union {
struct {