From 476133abd04fc27cdff5ab22d90cca13090de3d7 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 3 Mar 2018 20:51:38 +0200 Subject: [PATCH] The scrolled y value is cached and not recalculated --- Core/display.c | 14 +++++--------- Core/gb.h | 5 +++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Core/display.c b/Core/display.c index 22cd847..f6c0e57 100755 --- a/Core/display.c +++ b/Core/display.c @@ -444,12 +444,6 @@ static void render_pixel_if_possible(GB_gameboy_t *gb) } gb->position_in_line++; } - -static inline uint8_t scrolled_y(GB_gameboy_t *gb) -{ - return gb->current_line + (gb->in_window? - gb->io_registers[GB_IO_WY] - gb->wy_diff : gb->io_registers[GB_IO_SCY]); -} - void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) { @@ -593,7 +587,9 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) else if (gb->io_registers[GB_IO_LCDC] & 0x40 && gb->in_window) { map = 0x1C00; } - gb->current_tile = gb->vram[map + gb->fetcher_x + scrolled_y(gb) / 8 * 32]; + gb->fetcher_y = + gb->current_line + (gb->in_window? - gb->io_registers[GB_IO_WY] - gb->wy_diff : gb->io_registers[GB_IO_SCY]); + gb->current_tile = gb->vram[map + gb->fetcher_x + gb->fetcher_y / 8 * 32]; gb->fetcher_x++; gb->fetcher_x &= 0x1f; } @@ -607,13 +603,13 @@ void GB_display_run(GB_gameboy_t *gb, uint8_t cycles) gb->current_tile_address = (int8_t)gb->current_tile * 0x10 + 0x1000; } gb->current_tile_data[0] = - gb->vram[gb->current_tile_address + (scrolled_y(gb) & 7) * 2]; + gb->vram[gb->current_tile_address + (gb->fetcher_y & 7) * 2]; } break; case GB_FETCHER_GET_TILE_DATA_HIGH: { gb->current_tile_data[1] = - gb->vram[gb->current_tile_address + (scrolled_y(gb) & 7) * 2 + 1]; + gb->vram[gb->current_tile_address + (gb->fetcher_y & 7) * 2 + 1]; } break; diff --git a/Core/gb.h b/Core/gb.h index b4ff2ab..56215c1 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -401,14 +401,15 @@ struct GB_gameboy_internal_s { bool oam_write_blocked; bool vram_write_blocked; bool window_disabled_while_active; - uint8_t effective_scy; // SCY is latched when starting to draw a tile + uint8_t effective_scy; // Todo: delete me! uint8_t current_line; uint16_t ly_for_comparison; GB_fifo_t bg_fifo, oam_fifo; uint8_t fetcher_x; + uint8_t fetcher_y; uint16_t cycles_for_line; uint8_t current_tile; - uint16_t current_tile_address; // TODO: is this actually cached? If not, it could be used to "mix" two tiles + uint16_t current_tile_address; uint8_t current_tile_data[2]; enum { GB_FETCHER_GET_TILE,