Fixed SDL window rendering on macOS

This commit is contained in:
Selim Mustafaev 2023-09-06 00:18:38 +03:00
parent 53a54b084d
commit c6f65e5ad2
3 changed files with 24 additions and 3 deletions

View File

@ -14,13 +14,16 @@ int main() {
device.setNewFrameCallback(std::bind(&nes::SdlWindow::drawFrame, &window, _1));
//device.insertCartridge("/home/selim/Downloads/nestest.nes");
device.insertCartridge("C:\\Users\\selim\\Documents\\nestest.nes");
device.insertCartridge("/Users/selim/Documents/nestest.nes");
SDL_Event e;
uint64_t cycles = 0;
while (cycles < 1000000000) {
device.tick();
cycles++;
while(SDL_PollEvent(&e));
//int64_t us = static_cast<int64_t>(1000000000.0/(60*nes::Ppu::SCREEN_WIDTH*nes::Ppu::SCREEN_HEIGHT));
//std::this_thread::sleep_for(std::chrono::nanoseconds(1));
}

View File

@ -92,10 +92,17 @@ namespace nes {
_status.verticalBlank = 0;
}
//
// Preloading some data ahead of time
if ((_column >= 2 && _column < 258) || (_column >= 321 && _column < 338)) {
// Every 8 ticks extract info about next tile
// Spread the work across those 8 ticks
switch ((_column - 1) % 8) {
case 0:
_nextBgTile.id = internalRead(0x2000 + _vRamAddress.value & 0x0FFF);
break;
case 2:
//_nextBgTile.attribute
break;
}
}
}

View File

@ -18,6 +18,9 @@ namespace nes {
uint8_t G = 0;
uint8_t B = 0;
uint8_t A = 0xFF;
Pixel(): R{}, G{}, B{}, A{} {}
Pixel(uint8_t R, uint8_t G, uint8_t B): R{R}, G{G}, B{B}, A{0xFF} {}
};
class Ppu {
@ -86,6 +89,13 @@ namespace nes {
uint16_t value;
};
struct TileInfo {
uint8_t id;
uint8_t attribute;
uint8_t lsb;
uint8_t msb;
};
public:
Ppu();
bool tick();
@ -114,6 +124,7 @@ namespace nes {
bool _addressWriteInProgress;
uint8_t _dataTemp;
uint8_t _fineX;
TileInfo _nextBgTile;
private:
std::unique_ptr<uint8_t[]> _nameTable;