mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-28 16:43:35 +00:00
fixing errors and now starting to render w mode 0 [test] memory inserted in PPU constructor
This commit is contained in:
+103
-10
@@ -15,9 +15,9 @@
|
||||
namespace ComSquare::PPU
|
||||
{
|
||||
PPU::PPU(Renderer::IRenderer &renderer):
|
||||
vram(new Ram::Ram(65536, ComSquare::VRam, "VRAM")),
|
||||
oamram(new Ram::Ram(544, ComSquare::OAMRam, "OAMRAM")),
|
||||
cgram(new Ram::Ram(512, ComSquare::CGRam, "CGRAM")),
|
||||
vram(new Ram::Ram(VRAMSIZE, ComSquare::VRam, "VRAM")),
|
||||
oamram(new Ram::Ram(OAMRAMSIZE, ComSquare::OAMRam, "OAMRAM")),
|
||||
cgram(new Ram::Ram(CGRAMSIZE, ComSquare::CGRam, "CGRAM")),
|
||||
_renderer(renderer),
|
||||
_backgrounds{
|
||||
Background(*this, 1, false),
|
||||
@@ -31,13 +31,105 @@ namespace ComSquare::PPU
|
||||
}
|
||||
{
|
||||
this->_registers._isLowByte = true;
|
||||
for (int i = 0; i < 512; i++) {
|
||||
/*for (int i = 0; i < 512; i++) {
|
||||
this->cgram->write_internal(i, random() % 255);
|
||||
}*/
|
||||
|
||||
//colors for the cgram
|
||||
this->cgram->write_internal(2, 0xE0);
|
||||
this->cgram->write_internal(3, 0x7F);
|
||||
this->cgram->write_internal(4, 0x1F);
|
||||
this->cgram->write_internal(6, 0xFF);
|
||||
this->cgram->write_internal(7, 0x03);
|
||||
this->cgram->write_internal(66, 0xE0);
|
||||
this->cgram->write_internal(67, 0x7F);
|
||||
|
||||
//tiles
|
||||
int vram_test[] = {
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
|
||||
0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
|
||||
03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0xff,0xff,0xff,0xff,
|
||||
0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xff,0xff,0xff,0xff,
|
||||
00,0xc0,0x00,0xe0,0x00,0x70,0x00,0x38,0x00,0x1c,0x00,0x0e,0x00,0x07,0x00,0x03,
|
||||
00,0x03,0x00,0x07,0x00,0x0e,0x00,0x1c,0x00,0x38,0x00,0x70,0x00,0xe0,0x00,0xc0,
|
||||
00,0x07,0x00,0x0f,0x00,0x18,0x00,0x30,0x00,0x60,0x00,0xc0,0x00,0xc0,0x00,0xc0,
|
||||
00,0xe0,0x00,0xf0,0x00,0x18,0x00,0x0c,0x00,0x06,0x00,0x03,0x00,0x03,0x00,0x03,
|
||||
0xfc,0x00,0xf8,0x00,0xf0,0x00,0xe0,0x00,0xc0,0x00,0x80,0x00,0x00,0x00,0x00,0x00,
|
||||
0x3f,0x00,0x1f,0x00,0x0f,0x00,0x07,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
|
||||
0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,
|
||||
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0xff,0xff,0xff,0xff,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
|
||||
0xff,0xff,0xff,0xff,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,
|
||||
00,0x03,0x00,0x07,0x00,0x0e,0x00,0x1c,0x00,0x38,0x00,0x70,0x00,0xe0,0x00,0xc0,
|
||||
00,0xc0,0x00,0xe0,0x00,0x70,0x00,0x38,0x00,0x1c,0x00,0x0e,0x00,0x07,0x00,0x03,
|
||||
00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0x60,0x00,0x30,0x00,0x18,0x00,0x0f,0x00,0x07,
|
||||
00,0x03,0x00,0x03,0x00,0x03,0x00,0x06,0x00,0x0c,0x00,0x18,0x00,0xf0,0x00,0xe0,
|
||||
00,0x00,0x00,0x00,0x80,0x00,0xc0,0x00,0xe0,0x00,0xf0,0x00,0xf8,0x00,0xfc,0x00,
|
||||
00,0x00,0x00,0x00,0x01,0x00,0x03,0x00,0x07,0x00,0x0f,00,0x1f,00,0x3f,00, -1
|
||||
};
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i, vram_test[i]);
|
||||
}
|
||||
int vram_test_2[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1};
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i + 0x8000, vram_test_2[i]);
|
||||
}
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i, vram_test[i]);
|
||||
}
|
||||
int vram_test_3[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1};
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i + 0x8080, vram_test_3[i]);
|
||||
}
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i, vram_test[i]);
|
||||
}
|
||||
int vram_test_4[] = {8, 00, 02, 00, 0x0A, 00, 02, 00, 0x0A, 00, 00, 00, 00, 00, 00, -1};
|
||||
for (int i = 0; vram_test[i] != -1; i++) {
|
||||
this->vram->write_internal(i + 0x8100, vram_test_4[i]);
|
||||
}
|
||||
this->vram->write_internal(0x8040, 04);
|
||||
this->vram->write_internal(0x8042, 06);
|
||||
this->vram->write_internal(0x8044, 04);
|
||||
this->vram->write_internal(0x8046, 06);
|
||||
this->vram->write_internal(0x8048, 04);
|
||||
|
||||
this->vram->write_internal(0x80C0, 04);
|
||||
this->vram->write_internal(0x80C2, 06);
|
||||
this->vram->write_internal(0x80C4, 04);
|
||||
this->vram->write_internal(0x80C6, 06);
|
||||
this->vram->write_internal(0x80C8, 04);
|
||||
|
||||
//registers
|
||||
|
||||
this->_registers._bgmode.bgMode = 0;
|
||||
this->_registers._bgmode.characterSizeBg1 = true;
|
||||
this->_registers._bgmode.characterSizeBg2 = true;
|
||||
|
||||
this->_registers._bgsc[0].tilemapAddress = 0x4000U >> 10U;
|
||||
this->_registers._bgsc[1].tilemapAddress = 0x6000U >> 10U;
|
||||
this->_backgrounds[0].setTileMapStartAddress(this->getTileMapStartAddress(1));
|
||||
this->_backgrounds[1].setTileMapStartAddress(this->getTileMapStartAddress(1));
|
||||
this->_backgrounds[2].setTileMapStartAddress(this->getTileMapStartAddress(2));
|
||||
this->_backgrounds[3].setTileMapStartAddress(this->getTileMapStartAddress(2));
|
||||
|
||||
this->_registers._t[0].enableWindowDisplayBg1 = true;
|
||||
this->_registers._t[0].enableWindowDisplayBg2 = true;
|
||||
}
|
||||
|
||||
uint8_t PPU::read(uint24_t addr)
|
||||
{
|
||||
return 0;
|
||||
switch (addr) {
|
||||
case ppuRegisters::mpyl:
|
||||
return this->_registers._mpy.mpyl;
|
||||
@@ -66,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;
|
||||
@@ -469,7 +562,7 @@ namespace ComSquare::PPU
|
||||
|
||||
uint16_t PPU::getTileMapStartAddress(int bgNumber)
|
||||
{
|
||||
return this->_registers._bgsc[bgNumber - 1].tilemapAddress << 1U;
|
||||
return this->_registers._bgsc[bgNumber - 1].tilemapAddress << 11U;
|
||||
}
|
||||
|
||||
uint16_t PPU::getTileSetAddress(int bgNumber)
|
||||
@@ -498,9 +591,9 @@ namespace ComSquare::PPU
|
||||
|
||||
colorPalette = this->cgram->read_internal(0);
|
||||
colorPalette += this->cgram->read_internal(1) << 8U;
|
||||
for (unsigned long i = 0; i < this->_mainScreen.size(); i++)
|
||||
for (unsigned long j = 0; j < this->_mainScreen[i].size(); j++)
|
||||
this->_mainScreen[i][j] = getRealColor(colorPalette);
|
||||
for (unsigned long i = 0; i < this->_subScreen.size(); i++)
|
||||
for (unsigned long j = 0; j < this->_subScreen[i].size(); j++)
|
||||
this->_subScreen[i][j] = getRealColor(colorPalette);
|
||||
// the buffer is overwrite if necessary by a new bg so the background priority is from back to front
|
||||
// the starting palette index isn't implemented
|
||||
switch (this->_registers._bgmode.bgMode) {
|
||||
@@ -603,8 +696,8 @@ namespace ComSquare::PPU
|
||||
int i = bg.bgNumber + bg.priority;
|
||||
|
||||
if (this->_registers._t[0].raw & (1U << (bg.bgNumber - 1U)))
|
||||
this->add_buffer(this->_mainScreen, this->_backgrounds[i].buffer);
|
||||
this->add_buffer(this->_mainScreen, bg.buffer);
|
||||
if (this->_registers._t[1].raw & (1U << (bg.bgNumber - 1U)))
|
||||
this->add_buffer(this->_subScreen, this->_backgrounds[i].buffer);
|
||||
this->add_buffer(this->_subScreen, bg.buffer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user