mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-20 14:15:11 +00:00
starting clarify code
This commit is contained in:
@@ -29,18 +29,18 @@ namespace ComSquare::PPU
|
||||
{
|
||||
uint16_t vramAddress = this->_TileMapStartAddress;
|
||||
Vector2<int> offset(0, 0);
|
||||
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * 32;
|
||||
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * 32;
|
||||
this->backgroundSize.x = this->_tileMaps.x * this->_characterSize.x * NB_CHARACTER_WIDTH;
|
||||
this->backgroundSize.y = this->_tileMaps.y * this->_characterSize.y * NB_CHARACTER_HEIGHT;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!(i == 1 && this->_tileMaps.x == 1) && !(i > 1 && this->_tileMaps.y == 1)) {
|
||||
drawBasicTileMap(vramAddress, offset);
|
||||
}
|
||||
vramAddress += 0x800;
|
||||
offset.x += 32 * this->_characterSize.x;
|
||||
offset.x += NB_CHARACTER_WIDTH * this->_characterSize.x;
|
||||
if (i == 2) {
|
||||
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;
|
||||
palette = getPalette(tileData.palette);
|
||||
// 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 j = 0; j < this->_characterSize.x; j++) {
|
||||
reference = getTilePixelReference(graphicAddress, index);
|
||||
@@ -129,6 +131,7 @@ namespace ComSquare::PPU
|
||||
uint16_t vramAddress = baseAddress;
|
||||
|
||||
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 + 1) << 8U;
|
||||
drawBgTile(tileMapValue, {(pos.x * this->_characterSize.x) + offset.x, (pos.y * this->_characterSize.y) + offset.y});
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace ComSquare::PPU
|
||||
{
|
||||
class PPU;
|
||||
class Background {
|
||||
#define NB_CHARACTER_WIDTH 32
|
||||
#define NB_CHARACTER_HEIGHT 32
|
||||
private:
|
||||
Vector2<int> _tileMaps;
|
||||
Vector2<int> _characterSize;
|
||||
@@ -39,6 +41,7 @@ namespace ComSquare::PPU
|
||||
//! @brief draw a tilemap 32x32 starting at baseAddress
|
||||
void drawBasicTileMap(uint16_t baseAddress, Vector2<int> offset);
|
||||
public:
|
||||
// TODO getter setter for priority and bgNumber
|
||||
bool priority;
|
||||
int bgNumber;
|
||||
Vector2<int> backgroundSize;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace ComSquare::PPU
|
||||
//colors for the cgram
|
||||
this->cgram->write_internal(2, 0xE0);
|
||||
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(7, 0x03);
|
||||
this->cgram->write_internal(66, 0xE0);
|
||||
@@ -129,6 +129,7 @@ namespace ComSquare::PPU
|
||||
|
||||
uint8_t PPU::read(uint24_t addr)
|
||||
{
|
||||
return 0;
|
||||
switch (addr) {
|
||||
case ppuRegisters::mpyl:
|
||||
return this->_registers._mpy.mpyl;
|
||||
@@ -157,6 +158,7 @@ namespace ComSquare::PPU
|
||||
|
||||
void PPU::write(uint24_t addr, uint8_t data)
|
||||
{
|
||||
return;
|
||||
switch (addr) {
|
||||
case ppuRegisters::inidisp:
|
||||
this->_registers._inidisp.raw = data;
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace ComSquare::PPU
|
||||
{
|
||||
union TileMapData {
|
||||
struct {
|
||||
uint8_t posY: 4;
|
||||
uint8_t posX: 6;
|
||||
uint8_t posX: 4;
|
||||
uint8_t posY: 6;
|
||||
uint8_t palette: 3;
|
||||
bool tilePriority: 1;
|
||||
bool horizontalFlip: 1;
|
||||
|
||||
Reference in New Issue
Block a user