More accurate emulation of the SCX register

This commit is contained in:
Lior Halphon 2016-06-11 17:58:00 +03:00
parent b7e999b242
commit d7d8da3fa9
2 changed files with 6 additions and 6 deletions

View File

@ -99,7 +99,7 @@ static uint32_t get_pixel(GB_gameboy_t *gb, unsigned char x, unsigned char y)
y -= gb->effective_window_y; y -= gb->effective_window_y;
} }
else { else {
x += gb->io_registers[GB_IO_SCX]; x += gb->effective_scx;
y += gb->io_registers[GB_IO_SCY]; y += gb->io_registers[GB_IO_SCY];
} }
if (gb->io_registers[GB_IO_LCDC] & 0x08 && !in_window) { 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) { if (gb->effective_window_enabled && gb->effective_window_y == 0xFF) {
gb->effective_window_y = gb->io_registers[GB_IO_LY]; 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->effective_scx = gb->io_registers[GB_IO_SCX];
gb->previous_lcdc_x = gb->line_x_bias; gb->previous_lcdc_x = - (gb->effective_scx & 0x7);
goto updateSTAT; 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++) { for (;gb->previous_lcdc_x < current_lcdc_x; gb->previous_lcdc_x++) {
if (gb->previous_lcdc_x >= 160) { if (gb->previous_lcdc_x >= 160) {
continue; continue;

View File

@ -268,7 +268,7 @@ typedef struct GB_gameboy_s {
bool effective_window_enabled; bool effective_window_enabled;
unsigned char effective_window_y; unsigned char effective_window_y;
bool stat_interrupt_line; 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 */ /* Unsaved data. This includes all pointers, as well as everything that shouldn't be on a save state */