starting clarify code

This commit is contained in:
Clément Le Bihan
2020-09-07 00:33:22 +02:00
parent f00f8d931e
commit fa97b2ab38
4 changed files with 17 additions and 9 deletions

View File

@@ -29,18 +29,18 @@ namespace ComSquare::PPU
{ {
uint16_t vramAddress = this->_TileMapStartAddress; uint16_t vramAddress = this->_TileMapStartAddress;
Vector2<int> offset(0, 0); Vector2<int> offset(0, 0);
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * 32; this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH;
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * 32; this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) { if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) {
drawBasicTileMap(vramAddress, offset); drawBasicTileMap(vramAddress, offset);
} }
vramAddress+= 0x800; vramAddress += 0x800;
offset.x += 32 * this->_characterSize.x; offset.x += NB_CHARACTER_WIDTH * this->_characterSize.x;
if (i == 2) { if (i == 2) {
offset.x = 0; offset.x = 0;
offset.y += 32 * this->_characterSize.y; offset.y += NB_CHARACTER_HEIGHT * this->_characterSize.y;
} }
} }
} }
@@ -57,7 +57,9 @@ namespace ComSquare::PPU
tileData.raw = data; tileData.raw = data;
palette = getPalette(tileData.palette); palette = getPalette(tileData.palette);
// TODO explain X and Y and rethink the formula // TODO explain X and Y and rethink the formula
graphicAddress = this->_tileSetAddress + (tileData.posX * 16 * this->_bpp * 8) + (tileData.posY * this->_bpp * 8); // X horizontal
// Y vertical
graphicAddress = this->_tileSetAddress + (tileData.posY * 16 * this->_bpp * 8) + (tileData.posX * this->_bpp * 8);
for (int i = 0; i < this->_characterSize.y; i++) { for (int i = 0; i < this->_characterSize.y; i++) {
for (int j = 0; j < this->_characterSize.x; j++) { for (int j = 0; j < this->_characterSize.x; j++) {
reference = getTilePixelReference(graphicAddress, index); reference = getTilePixelReference(graphicAddress, index);
@@ -129,6 +131,7 @@ namespace ComSquare::PPU
uint16_t vramAddress = baseAddress; uint16_t vramAddress = baseAddress;
while (vramAddress < baseAddress + 0x800) { while (vramAddress < baseAddress + 0x800) {
// TODO function to read 2 bytes (LSB order or bits reversed)
tileMapValue = this->_vram->read_internal(vramAddress); tileMapValue = this->_vram->read_internal(vramAddress);
tileMapValue += this->_vram->read_internal(vramAddress + 1) << 8U; tileMapValue += this->_vram->read_internal(vramAddress + 1) << 8U;
drawBgTile(tileMapValue, {(pos.x * this->_characterSize.x) + offset.x, (pos.y * this->_characterSize.y) + offset.y}); drawBgTile(tileMapValue, {(pos.x * this->_characterSize.x) + offset.x, (pos.y * this->_characterSize.y) + offset.y});

View File

@@ -19,6 +19,8 @@ namespace ComSquare::PPU
{ {
class PPU; class PPU;
class Background { class Background {
#define NB_CHARACTER_WIDTH 32
#define NB_CHARACTER_HEIGHT 32
private: private:
Vector2<int> _tileMaps; Vector2<int> _tileMaps;
Vector2<int> _characterSize; Vector2<int> _characterSize;
@@ -39,6 +41,7 @@ namespace ComSquare::PPU
//! @brief draw a tilemap 32x32 starting at baseAddress //! @brief draw a tilemap 32x32 starting at baseAddress
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset); void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
public: public:
// TODO getter setter for priority and bgNumber
bool priority; bool priority;
int bgNumber; int bgNumber;
Vector2<int> backgroundSize; Vector2<int> backgroundSize;

View File

@@ -38,7 +38,7 @@ namespace ComSquare::PPU
//colors for the cgram //colors for the cgram
this->cgram->write_internal(2, 0xE0); this->cgram->write_internal(2, 0xE0);
this->cgram->write_internal(3, 0x7F); this->cgram->write_internal(3, 0x7F);
this->cgram->write_internal(4, 0x0F); // 0x1F this->cgram->write_internal(4, 0x1F); // 0x1F
this->cgram->write_internal(6, 0xFF); this->cgram->write_internal(6, 0xFF);
this->cgram->write_internal(7, 0x03); this->cgram->write_internal(7, 0x03);
this->cgram->write_internal(66, 0xE0); this->cgram->write_internal(66, 0xE0);
@@ -129,6 +129,7 @@ namespace ComSquare::PPU
uint8_t PPU::read(uint24_t addr) uint8_t PPU::read(uint24_t addr)
{ {
return 0;
switch (addr) { switch (addr) {
case ppuRegisters::mpyl: case ppuRegisters::mpyl:
return this->_registers._mpy.mpyl; return this->_registers._mpy.mpyl;
@@ -157,6 +158,7 @@ namespace ComSquare::PPU
void PPU::write(uint24_t addr, uint8_t data) void PPU::write(uint24_t addr, uint8_t data)
{ {
return;
switch (addr) { switch (addr) {
case ppuRegisters::inidisp: case ppuRegisters::inidisp:
this->_registers._inidisp.raw = data; this->_registers._inidisp.raw = data;

View File

@@ -11,8 +11,8 @@ namespace ComSquare::PPU
{ {
union TileMapData { union TileMapData {
struct { struct {
uint8_t posY: 4; uint8_t posX: 4;
uint8_t posX: 6; uint8_t posY: 6;
uint8_t palette: 3; uint8_t palette: 3;
bool tilePriority: 1; bool tilePriority: 1;
bool horizontalFlip: 1; bool horizontalFlip: 1;