From 2c44ffbe391d18032c9099f6cafb92a77158480d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 30 Mar 2018 02:53:49 +0300 Subject: [PATCH] More accurate fetcher penalty emulation, fixed intr_2_mode0_timing_sprites_nops, affects #54 --- Core/display.c | 13 ++++++------- Core/gb.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Core/display.c b/Core/display.c index 15cbbe4..4215197 100644 --- a/Core/display.c +++ b/Core/display.c @@ -555,14 +555,11 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) (gb->io_registers[GB_IO_LCDC] & 2 || gb->is_cgb) && gb->obj_comperators[gb->n_visible_objs - 1] == (uint8_t)(gb->position_in_line + 8)) { - if (!gb->fetching_objects) { + if (gb->fetcher_stop_penalty == 0) { /* Penalty for interrupting the fetcher */ - uint8_t penalty = (uint8_t[]){5, 4, 3, 2, 1, 0, 0, 0}[gb->fetcher_state * 2 + gb->fetcher_divisor]; - gb->cycles_for_line += penalty; - GB_SLEEP(gb, display, 19, penalty); + gb->fetcher_stop_penalty = (uint8_t[]){5, 4, 3, 2, 1, 0, 0, 0}[gb->fetcher_state * 2 + gb->fetcher_divisor]; } - gb->fetching_objects = true; gb->cycles_for_line += 6; GB_SLEEP(gb, display, 20, 6); GB_object_t *object = &objects[gb->visible_objs[gb->n_visible_objs - 1]]; @@ -593,8 +590,6 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->n_visible_objs--; } - gb->fetching_objects = false; - /* Handle window */ /* Todo: Timing not verified by test ROM */ @@ -671,6 +666,10 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) render_pixel_if_possible(gb); if (push) { + gb->cycles_for_line += gb->fetcher_stop_penalty; + GB_SLEEP(gb, display, 19, gb->fetcher_stop_penalty); + gb->fetcher_stop_penalty = 0; + fifo_push_bg_row(&gb->bg_fifo, gb->current_tile_data[0], gb->current_tile_data[1], gb->current_tile_attributes & 7, gb->current_tile_attributes & 0x80, gb->current_tile_attributes & 0x20); gb->bg_fifo_paused = false; diff --git a/Core/gb.h b/Core/gb.h index 43bb611..6d4fe1b 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -425,7 +425,7 @@ struct GB_gameboy_internal_s { uint8_t visible_objs[10]; uint8_t obj_comperators[10]; uint8_t n_visible_objs; - bool fetching_objects; + uint8_t fetcher_stop_penalty; uint8_t oam_search_index; uint8_t accessed_oam_row; );