Browse Source

Emulator: Fix pixel FIFO x-coordinate offset

master
Riyyi 2 years ago
parent
commit
00ceacaf52
  1. 16
      src/ppu.cpp
  2. 1
      src/ppu.h

16
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 = {};
}

1
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;

Loading…
Cancel
Save