diff --git a/src/ppu.cpp b/src/ppu.cpp index 8842c32..8f0935e 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -49,9 +49,8 @@ void PPU::update() // OAM logic goes here.. if (m_clocks_into_frame % 80 == 0) { - // Clear FIFOs - m_pixel_fifo.background = {}; - m_pixel_fifo.oam = {}; + // Reset FIFO + m_pixel_fifo = {}; m_state = State::PixelTransfer; } @@ -83,9 +82,7 @@ void PPU::update() if (m_clocks_into_frame % (80 + 172 + 204) == 0) { m_lcd_y_coordinate++; if (m_lcd_y_coordinate == 154) { - m_lcd_y_coordinate = 0; - m_clocks_into_frame = 0; - m_state = State::OAMSearch; + resetFrame(); } } @@ -160,7 +157,8 @@ void PPU::pixelFifo() // Read the tile map index uint16_t offset = (((m_viewport_y + m_lcd_y_coordinate) / TILE_HEIGHT) * 32) - + ((m_viewport_x + m_lcd_x_coordinate) / TILE_WIDTH); + + ((m_viewport_x + m_pixel_fifo.x_coordinate) / TILE_WIDTH); + m_pixel_fifo.x_coordinate += 8; m_pixel_fifo.tile_index = Emu::the().readMemory(bg_tile_map_address + offset) & 0xff; // Set the tile line we're currently on @@ -305,8 +303,4 @@ void PPU::resetFrame() m_clocks_into_frame = 0; m_lcd_x_coordinate = 0; m_lcd_y_coordinate = 0; - - // Clear FIFOs - m_pixel_fifo.background = {}; - m_pixel_fifo.oam = {}; } diff --git a/src/ppu.h b/src/ppu.h index 5695ba6..a88fa1a 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -64,6 +64,7 @@ public: State state = State::TileIndex; bool step = false; + uint8_t x_coordinate = 0; uint8_t tile_index = 0; uint8_t tile_line = 0; uint8_t pixels_lsb = 0;