From 52ed2ca55e02cf3e7386d849d900e6ab0a3c5307 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 23 Sep 2016 18:30:07 +0300 Subject: [PATCH] Corrected BG enable's behavior (Fixes visual glitch with Krusty's Funhouse) --- Core/display.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Core/display.c b/Core/display.c index 8f12f23..580ea90 100755 --- a/Core/display.c +++ b/Core/display.c @@ -144,31 +144,29 @@ static uint32_t get_pixel(GB_gameboy_t *gb, uint8_t x, uint8_t y) return gb->sprite_palletes_rgb[sprite_palette * 4 + sprite_pixel]; } - if (!bg_enabled) { - return gb->background_palletes_rgb[0]; - } + if (bg_enabled) { + if (gb->io_registers[GB_IO_LCDC] & 0x10) { + tile_address = tile * 0x10; + } + else { + tile_address = (int8_t) tile * 0x10 + 0x1000; + } + if (attributes & 0x8) { + tile_address += 0x2000; + } - if (gb->io_registers[GB_IO_LCDC] & 0x10) { - tile_address = tile * 0x10; - } - else { - tile_address = (int8_t) tile * 0x10 + 0x1000; - } - if (attributes & 0x8) { - tile_address += 0x2000; - } + if (attributes & 0x20) { + x = ~x; + } - if (attributes & 0x20) { - x = ~x; - } + if (attributes & 0x40) { + y = ~y; + } - if (attributes & 0x40) { - y = ~y; + background_pixel = (((gb->vram[tile_address + (y & 7) * 2 ] >> ((~x)&7)) & 1 ) | + ((gb->vram[tile_address + (y & 7) * 2 + 1] >> ((~x)&7)) & 1) << 1 ); } - background_pixel = (((gb->vram[tile_address + (y & 7) * 2 ] >> ((~x)&7)) & 1 ) | - ((gb->vram[tile_address + (y & 7) * 2 + 1] >> ((~x)&7)) & 1) << 1 ); - if (priority && sprite_pixel && !background_pixel) { if (!gb->cgb_mode) { sprite_pixel = (gb->io_registers[use_obp1? GB_IO_OBP1:GB_IO_OBP0] >> (sprite_pixel << 1)) & 3;