diff --git a/src/ppu.c b/src/ppu.c index 0f1a0b2..929f4b0 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -89,6 +89,10 @@ static inline void nes_ppu_internal_copy_y(nes_ppu* ppu) { ((ppu->t & 0x7000U) >> 12); } +static inline void nes_ppu_internal_copy_v(nes_ppu* ppu) { + ppu->addr = ppu->t; +} + void nes_ppu_write(nes_ppu* ppu, uint16_t addr, uint8_t val) { PPU_LOG("PPU: W-> $%04x %02x\n", addr, val); @@ -236,6 +240,9 @@ nes_ppu_Result nes_ppu_run(nes_ppu* ppu, int cycles) { if (ppu->scanline == 0) { nes_ppu_internal_copy_y(ppu); } + if (ppu->mask & (ppu_Mask_Sprite | ppu_Mask_Back)) { + nes_ppu_internal_copy_v(ppu); + } } if ( NULL != ppu->mapper->scanline && diff --git a/src/sdl_render.c b/src/sdl_render.c index b6acd9a..76215b9 100644 --- a/src/sdl_render.c +++ b/src/sdl_render.c @@ -560,7 +560,7 @@ static void render_scanline(nes_ppu* ppu, int line, if (line >= 0) { // Emulate the happy part of the backdrop override quirk - int pal_idx = (ppu->addr >= nes_ppu_mem_pal_start) ? + int pal_idx = ((ppu->addr & 0x3FFFU) >= nes_ppu_mem_pal_start) ? (ppu->addr & (nes_ppu_mem_pal_size - 1)) : 0; SDL_Color ext = nes_palette[ppu->palette[pal_idx]]; SDL_FillRect(data->target, &dst_rect, ((int)ext.r << 16) |