Fixed window behavior

This commit is contained in:
Lior Halphon 2018-03-01 22:03:56 +02:00
parent b702d56547
commit a67db0595b

View File

@ -760,22 +760,21 @@ void GB_window_related_write(GB_gameboy_t *gb, uint8_t addr, uint8_t value)
gb->io_registers[addr] = value; gb->io_registers[addr] = value;
bool after = window_enabled(gb); bool after = window_enabled(gb);
if (before != after && gb->display_cycles < LINES * LINE_LENGTH) { if (before != after && gb->current_line >= LINES) {
/* Window was disabled or enabled outside of vblank */ /* Window was disabled or enabled outside of vblank */
uint8_t current_line = gb->display_cycles / LINE_LENGTH; if (gb->current_line >= gb->io_registers[GB_IO_WY]) {
if (current_line >= gb->io_registers[GB_IO_WY]) {
if (after) { if (after) {
if (!gb->window_disabled_while_active) { if (!gb->window_disabled_while_active) {
/* Window was turned on for the first time this frame while LY > WY, /* Window was turned on for the first time this frame while LY > WY,
should start window in the next line */ should start window in the next line */
gb->wy_diff = current_line + 1 - gb->io_registers[GB_IO_WY]; gb->wy_diff = gb->current_line + 1 - gb->io_registers[GB_IO_WY];
} }
else { else {
gb->wy_diff += current_line; gb->wy_diff += gb->current_line;
} }
} }
else { else {
gb->wy_diff -= current_line; gb->wy_diff -= gb->current_line;
gb->window_disabled_while_active = true; gb->window_disabled_while_active = true;
} }
} }