Simplify wx=166 code

This commit is contained in:
Lior Halphon
2024-07-14 13:00:39 +03:00
parent 0c9cf8d594
commit 64cf389edf
3 changed files with 14 additions and 23 deletions

View File

@@ -795,7 +795,6 @@ static void advance_fetcher_state_machine(GB_gameboy_t *gb, unsigned *cycles)
if (!(gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE)) { if (!(gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE)) {
gb->wx_triggered = false; gb->wx_triggered = false;
gb->wx166_glitch = false;
} }
if (gb->io_registers[GB_IO_LCDC] & GB_LCDC_BG_MAP && !gb->wx_triggered) { if (gb->io_registers[GB_IO_LCDC] & GB_LCDC_BG_MAP && !gb->wx_triggered) {
@@ -1330,7 +1329,7 @@ static inline uint16_t mode3_batching_length(GB_gameboy_t *gb)
if (gb->hdma_on) return 0; if (gb->hdma_on) return 0;
if (gb->stopped) return 0; if (gb->stopped) return 0;
if (GB_is_dma_active(gb)) return 0; if (GB_is_dma_active(gb)) return 0;
if (gb->wx166_glitch) return 0; if (gb->wx_triggered) return 0;
if (gb->wy_triggered) { if (gb->wy_triggered) {
if (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE) { if (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE) {
if ((gb->io_registers[GB_IO_WX] < 8 || gb->io_registers[GB_IO_WX] == 166)) { if ((gb->io_registers[GB_IO_WX] < 8 || gb->io_registers[GB_IO_WX] == 166)) {
@@ -1531,7 +1530,6 @@ void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force)
gb->vram_read_blocked = true; gb->vram_read_blocked = true;
gb->vram_write_blocked = true; gb->vram_write_blocked = true;
gb->wx_triggered = false; gb->wx_triggered = false;
gb->wx166_glitch = false;
goto mode_3_start; goto mode_3_start;
// Mode 3 abort, state 9 // Mode 3 abort, state 9
@@ -1576,7 +1574,6 @@ void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force)
while (true) { while (true) {
/* Lines 0 - 143 */ /* Lines 0 - 143 */
gb->window_y = -1;
for (; gb->current_line < LINES; gb->current_line++) { for (; gb->current_line < LINES; gb->current_line++) {
if (unlikely(gb->lcd_line_callback)) { if (unlikely(gb->lcd_line_callback)) {
gb->lcd_line_callback(gb, gb->current_line); gb->lcd_line_callback(gb, gb->current_line);
@@ -1698,22 +1695,14 @@ void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force)
that point. The code should be updated to represent this, and this will fix the time travel hack in that point. The code should be updated to represent this, and this will fix the time travel hack in
WX's access conflict code. */ WX's access conflict code. */
if (!gb->wx_triggered && (gb->wy_triggered || (gb->current_line == 0 && gb->wx166_glitch)) && (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE)) { if (!gb->wx_triggered && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE)) {
bool should_activate_window = false; bool should_activate_window = false;
bool glitch_activate = false;
if (gb->io_registers[GB_IO_WX] == 0) { if (gb->io_registers[GB_IO_WX] == 0) {
static const uint8_t scx_to_wx0_comparisons[] = {-7, -1, -2, -3, -4, -5, -6, -6}; static const uint8_t scx_to_wx0_comparisons[] = {-7, -1, -2, -3, -4, -5, -6, -6};
if (gb->position_in_line == scx_to_wx0_comparisons[gb->io_registers[GB_IO_SCX] & 7]) { if (gb->position_in_line == scx_to_wx0_comparisons[gb->io_registers[GB_IO_SCX] & 7]) {
should_activate_window = true; should_activate_window = true;
} }
} }
else if (gb->wx166_glitch) {
if (gb->position_in_line == (uint8_t)-16) {
should_activate_window = true;
glitch_activate = true;
}
gb->wx166_glitch = false;
}
else if (gb->io_registers[GB_IO_WX] < 166 + GB_is_cgb(gb)) { else if (gb->io_registers[GB_IO_WX] < 166 + GB_is_cgb(gb)) {
if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7)) { if (gb->io_registers[GB_IO_WX] == (uint8_t) (gb->position_in_line + 7)) {
should_activate_window = true; should_activate_window = true;
@@ -1732,10 +1721,8 @@ void GB_display_run(GB_gameboy_t *gb, unsigned cycles, bool force)
if (should_activate_window) { if (should_activate_window) {
gb->window_y++; gb->window_y++;
gb->window_tile_x = glitch_activate; gb->window_tile_x = 0;
if (!glitch_activate) { fifo_clear(&gb->bg_fifo);
fifo_clear(&gb->bg_fifo);
}
/* TODO: Verify fetcher access timings in this case */ /* TODO: Verify fetcher access timings in this case */
if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) { if (gb->io_registers[GB_IO_WX] == 0 && (gb->io_registers[GB_IO_SCX] & 7)) {
gb->cycles_for_line++; gb->cycles_for_line++;
@@ -1880,14 +1867,19 @@ skip_slow_mode_3:
} }
/* TODO: Verify timing */ /* TODO: Verify timing { */
if (gb->current_line == 143) {
gb->window_y = -1;
}
if (!GB_is_cgb(gb) && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE) && gb->io_registers[GB_IO_WX] == 166) { if (!GB_is_cgb(gb) && gb->wy_triggered && (gb->io_registers[GB_IO_LCDC] & GB_LCDC_WIN_ENABLE) && gb->io_registers[GB_IO_WX] == 166) {
gb->wx166_glitch = true; gb->wx_triggered = true;
gb->window_tile_x = 1;
gb->window_y++;
} }
else { else {
gb->wx166_glitch = false; gb->wx_triggered = false;
} }
gb->wx_triggered = false; /* } */
if (!gb->cgb_double_speed) { if (!gb->cgb_double_speed) {
gb->io_registers[GB_IO_STAT] &= ~3; gb->io_registers[GB_IO_STAT] &= ~3;

View File

@@ -607,7 +607,7 @@ struct GB_gameboy_internal_s {
uint8_t current_tile_data[2]; uint8_t current_tile_data[2];
uint8_t fetcher_state; uint8_t fetcher_state;
bool window_is_being_fetched; bool window_is_being_fetched;
bool wx166_glitch; GB_PADDING(bool, wx166_glitch);
bool wx_triggered; bool wx_triggered;
uint8_t visible_objs[10]; uint8_t visible_objs[10];
uint8_t objects_x[10]; uint8_t objects_x[10];

View File

@@ -1522,7 +1522,6 @@ static void write_high_memory(GB_gameboy_t *gb, uint16_t addr, uint8_t value)
gb->io_registers[GB_IO_LCDC] = value; gb->io_registers[GB_IO_LCDC] = value;
if (!(value & GB_LCDC_WIN_ENABLE)) { if (!(value & GB_LCDC_WIN_ENABLE)) {
gb->wx_triggered = false; gb->wx_triggered = false;
gb->wx166_glitch = false;
} }
return; return;