The scrolled y value is cached and not recalculated

This commit is contained in:
Lior Halphon 2018-03-03 20:51:38 +02:00
parent 518746f664
commit 476133abd0
2 changed files with 8 additions and 11 deletions

View File

@ -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;

View File

@ -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,