pinobatch / libbet

Libbet and the Magic Floor - a puzzle game for Game Boy
zlib License
35 stars 1 forks source link

Make fade smoother using flickering #9

Closed pinobatch closed 5 years ago

pinobatch commented 5 years ago

Tests with the "Motion blur" activity of 144p Test Suite show that flickering is an effective way to create intermediate gray levels on the slow LCD of a Game Boy (DMG) or Game Boy pocket (MGB). We can use this for fading or for distinguishing Libbet's skin tone from her clothes.

For each of ten palette entries (four in BGP and three each in OBP0 and OBP1), store a target density from 0 (white) to 6 (black) and a residue from 0 to 63. Also store a single screen-wide fade level from 0 to 32.

Each frame, calculate the 2-bit hardware density for each palette entry with these steps:

  1. Multiply the target density by the fade level, producing a result in 0 to 192. (Can be done with unrolled A=B*C loop.)
  2. Add the residue.
  3. Copy bits 7-6 of the result to the hardware bit density.
  4. Write bits 5-0 back to the residue.

Currently the fade routine uses a scale of 0 to 248. This will first need to be changed to 0 to 32.