diff --git a/main.cpp b/main.cpp index 302094a..1dd10a2 100644 --- a/main.cpp +++ b/main.cpp @@ -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(1000000000.0/(60*nes::Ppu::SCREEN_WIDTH*nes::Ppu::SCREEN_HEIGHT)); //std::this_thread::sleep_for(std::chrono::nanoseconds(1)); } diff --git a/src/Ppu.cpp b/src/Ppu.cpp index 9c7fc78..f501fca 100644 --- a/src/Ppu.cpp +++ b/src/Ppu.cpp @@ -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; } } } diff --git a/src/Ppu.h b/src/Ppu.h index 0313b37..df9ca4c 100644 --- a/src/Ppu.h +++ b/src/Ppu.h @@ -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 _nameTable;