Emulate the FIFO insertion glitch (WX variant)

This commit is contained in:
Lior Halphon 2020-02-29 17:06:08 +02:00
parent 955860b463
commit 39b999a68b
2 changed files with 12 additions and 1 deletions

View File

@ -524,6 +524,7 @@ static void render_pixel_if_possible(GB_gameboy_t *gb)
} }
gb->position_in_line++; gb->position_in_line++;
gb->window_is_being_fetched = false;
} }
/* All verified CGB timings are based on CGB CPU E. CGB CPUs >= D are known to have /* All verified CGB timings are based on CGB CPU E. CGB CPUs >= D are known to have
@ -960,10 +961,20 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles)
fifo_clear(&gb->bg_fifo); fifo_clear(&gb->bg_fifo);
gb->fetcher_state = 0; gb->fetcher_state = 0;
window_got_activated = true; window_got_activated = true;
gb->window_is_being_fetched = true;
} }
} }
} }
if (!GB_is_cgb(gb) && gb->wx_triggered && !gb->window_is_being_fetched &&
gb->fetcher_state == 0 && gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7) ) {
// Insert a pixel right at the FIFO's end
gb->bg_fifo.read_end--;
gb->bg_fifo.read_end &= GB_FIFO_LENGTH - 1;
gb->bg_fifo.fifo[gb->bg_fifo.read_end] = (GB_fifo_item_t){0,};
gb->window_is_being_fetched = false;
}
/* Handle objects */ /* Handle objects */
/* When the sprite enabled bit is off, this proccess is skipped entirely on the DMG, but not on the CGB. /* When the sprite enabled bit is off, this proccess is skipped entirely on the DMG, but not on the CGB.
On the CGB, this bit is checked only when the pixel is actually popped from the FIFO. */ On the CGB, this bit is checked only when the pixel is actually popped from the FIFO. */

View File

@ -500,7 +500,7 @@ struct GB_gameboy_internal_s {
uint8_t current_tile_attributes; uint8_t current_tile_attributes;
uint8_t current_tile_data[2]; uint8_t current_tile_data[2];
uint8_t fetcher_state; uint8_t fetcher_state;
GB_PADDING(bool,bg_fifo_paused); bool window_is_being_fetched;
GB_PADDING(bool,oam_fifo_paused); GB_PADDING(bool,oam_fifo_paused);
bool wx_triggered; bool wx_triggered;
uint8_t visible_objs[10]; uint8_t visible_objs[10];