deltabeard / Peanut-GB

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

Main sprite disappears in some games #69

Closed YouMakeTech closed 1 year ago

YouMakeTech commented 1 year ago

Sometimes, in some (of my favorite :-)) games (e.g. Metroid II and Batman The Animated Series), the main sprite disappears. Please see example of the beginning of Metroid II, right at the beginning after the main menu: Screenshot from 2022-12-11 08-27-32

deltabeard commented 1 year ago

I tested this with v1.0.0 and the problem occurs there too so I don't think that this is a new issue. I'm working on a debugger to make it easier to discover the reason for these issues. I'll get back to this once I've finished the debugger on branch https://github.com/deltabeard/Peanut-GB/tree/debugger.

deltabeard commented 1 year ago

The sprites are loading correctly, which is good. So it must be an issue somewhere in __gb_draw_line(). Looking at the BGB VRAM viewer, it seems that the sprite is hidden when it has higher priority. This sprite priority setting must be incorrectly ignored by Peanut-GB somwhere.

Peanut-GB Debugger

deltabeard commented 1 year ago

I think I've fixed the issue in commit 878bc90a9766cfef5cb57ba64b8a0269a20bc326. Please check.

METROID2

The background draws over the sprite when required, making it look like Samus is walking behind the bush as shown in the animation above. The extra logic required to get this working will have some impact on LCD drawing performance though.

YouMakeTech commented 1 year ago

I'll check today. You're awesome. Thanks!

YouMakeTech commented 1 year ago

Thanks Mahyar, it works great. No noticeable change in performance

deltabeard commented 1 year ago

The changes made seem to introduce some drawing errors in other games now. In certain instances, the sprites will appear miscoloured or overlayed incorrectly. For example, in Super Mario Land 2 when Mario is going into a pipe, the sprite appears inverted colours:

MARIOLAND2_0000000015

The Jigglypuff in the opening animation in Pokemon R/B is incorrectly overlayed on Gengar on some frames. POKEMON BLUE.webm POKEMON BLUE

I'll reopen this issue so that I can find a better resolution than the current fix.

deltabeard commented 1 year ago

The issue should be fixed properly now. Before, it was assumed that color 0 of the BG palette was transparent, but in some games like Metroid, colour 0 is black, and instead colour 3 is white.