diff --git a/Core/display.c b/Core/display.c index 5bae908..4daa502 100644 --- a/Core/display.c +++ b/Core/display.c @@ -99,7 +99,7 @@ static uint32_t get_pixel(GB_gameboy_t *gb, unsigned char x, unsigned char y) y -= gb->effective_window_y; } else { - x += gb->io_registers[GB_IO_SCX]; + x += gb->effective_scx; y += gb->io_registers[GB_IO_SCY]; } if (gb->io_registers[GB_IO_LCDC] & 0x08 && !in_window) { @@ -353,13 +353,13 @@ void display_run(GB_gameboy_t *gb) if (gb->effective_window_enabled && gb->effective_window_y == 0xFF) { gb->effective_window_y = gb->io_registers[GB_IO_LY]; } - /* Todo: Figure out how the Gameboy handles in-line changes to SCX */ - gb->line_x_bias = - (gb->io_registers[GB_IO_SCX] & 0x7); - gb->previous_lcdc_x = gb->line_x_bias; + + gb->effective_scx = gb->io_registers[GB_IO_SCX]; + gb->previous_lcdc_x = - (gb->effective_scx & 0x7); goto updateSTAT; } - signed short current_lcdc_x = ((gb->display_cycles % 456 - 80) & ~7) + gb->line_x_bias; + signed short current_lcdc_x = ((gb->display_cycles % 456 - 80) & ~7) - (gb->effective_scx & 0x7); for (;gb->previous_lcdc_x < current_lcdc_x; gb->previous_lcdc_x++) { if (gb->previous_lcdc_x >= 160) { continue; diff --git a/Core/gb.h b/Core/gb.h index e8d99d4..e89cc59 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -268,7 +268,7 @@ typedef struct GB_gameboy_s { bool effective_window_enabled; unsigned char effective_window_y; bool stat_interrupt_line; - signed char line_x_bias; + unsigned char effective_scx; ); /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */