deltabeard / Peanut-GB

A Game Boy (DMG) emulator single header library written in C99. Performance is prioritised over accuracy.
https://projects.deltabeard.com/peanutgb/
283 stars 40 forks source link

First frame after reenabling LCD isn't white #33

Open pinobatch opened 5 years ago

pinobatch commented 5 years ago

When the program turns on rendering by changing bit 7 of LCDC ($FF40) from 0 to 1, the PPU goes straight to the start of rendering (scanline 0) without sending the vsync pulse to the LCD. This causes the LCD to display a white screen for one frame. (On monochrome systems, this is the same whiter-than-white shade displayed when rendering is off.) Some games, such as Pokémon Pinball, use this blank frame to prepare things before the first visible frame, such as the sprite display list to be DMA copied to OAM during the first vblank.

Though recent BGB emulates this quirk, mGBA, WasmBoy, and Peanut-GB do not. This causes 1 frame of corruption to appear in Pokémon Pinball and numerous other games after a screen transition. Many games on KiGB's compatibility list are there because of this quirk. Affected games may include A Boy and His Blob, Boxing by Tonkin House, Captain Knick-Knack, HyperDunk, Hyper Lode Runner, and Xiang Pu -- Dong Hai Dao Chang Suo.

I've attached a test ROM for this quirk, which repeatedly turns the LCD on for one frame before turning it off.

deltabeard commented 2 years ago

Thanks for the bug report and for writing & providing the test ROM. As mentioned in the commit, I think this is a partial fix, so I will leave this issue open. I need to do more testing, especially with Pokemon Pinball to see if this commit actually fixes the problem. Below is a before and after test of the firstwhite.gb ROM.

Before: BEFORE_FIRSTWHITE_0000000000

After: AFTER_FIRSTWHITE_0000000000