From 0e3d2770d92e12603d4426d3aace7b09814298d3 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 27 Mar 2018 22:13:08 +0300 Subject: [PATCH] =?UTF-8?q?Properly=20handle=20cases=20where=20an=20object?= =?UTF-8?q?=E2=80=99s=20X=20position=20is=20modified=20between=20the=20OAM?= =?UTF-8?q?=20mode=20and=20rendering=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/display.c | 6 ++++-- Core/gb.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/display.c b/Core/display.c index b614dca..15cbbe4 100755 --- a/Core/display.c +++ b/Core/display.c @@ -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 */ diff --git a/Core/gb.h b/Core/gb.h index bf836cc..37685b4 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -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;