Properly handle cases where an object’s X position is modified between the OAM mode and rendering mode

This commit is contained in:
Lior Halphon 2018-03-27 22:13:08 +03:00
parent 0912a30bb9
commit 0e3d2770d9
2 changed files with 5 additions and 2 deletions

View File

@ -302,10 +302,12 @@ static void add_object_from_index(GB_gameboy_t *gb, unsigned index)
if (y <= gb->current_line && y + (height_16? 16 : 8) > gb->current_line) {
unsigned j = 0;
for (; j < gb->n_visible_objs; j++) {
if (objects[gb->visible_objs[j]].x <= objects[index].x) break;
if (gb->obj_comperators[j] <= objects[index].x) break;
}
memmove(gb->visible_objs + j + 1, gb->visible_objs + j, gb->n_visible_objs - j);
memmove(gb->obj_comperators + j + 1, gb->obj_comperators + j, gb->n_visible_objs - j);
gb->visible_objs[j] = index;
gb->obj_comperators[j] = objects[index].x;
gb->n_visible_objs++;
}
}
@ -551,7 +553,7 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles)
On the CGB, this bit is checked only when the pixel is actually popped from the FIFO. */
while (gb->n_visible_objs != 0 &&
(gb->io_registers[GB_IO_LCDC] & 2 || gb->is_cgb) &&
objects[gb->visible_objs[gb->n_visible_objs - 1]].x == (uint8_t)(gb->position_in_line + 8)) {
gb->obj_comperators[gb->n_visible_objs - 1] == (uint8_t)(gb->position_in_line + 8)) {
if (!gb->fetching_objects) {
/* Penalty for interrupting the fetcher */

View File

@ -424,6 +424,7 @@ struct GB_gameboy_internal_s {
bool oam_fifo_paused;
bool in_window;
uint8_t visible_objs[10];
uint8_t obj_comperators[10];
uint8_t n_visible_objs;
bool fetching_objects;
uint8_t oam_search_index;