binji / binjgb

Gameboy emulator implemented in C, that also runs in the browser
https://binji.github.io/binjgb/
MIT License
528 stars 60 forks source link

OAM priority calculation #54

Open taylorplewe opened 5 months ago

taylorplewe commented 5 months ago

As per these gbdev.io docs, when it comes to drawing an OAM pixel, the Gameboy first calculates which of 2 overlapping objects has higher priority; and THEN considers the winning object's BG priority bit. This can be exploited to "mask" objects (see INTERACTION WITH "BG OVER OBJ" FLAG in the article.)

Currently on binjgb, this behavior does not occur; it calculates the BG priority bit of all objects and renders whatever is on top.

On my local version of binjgb, I was able to fix this by inserting the following lines to emulator.c:

image image image

which seems like a hacky solution, but you can see a working version on my demo GB game.

I'm unable to open a pull request as I'm unable to create a branch but this is the issue and a potential solution!

binji commented 4 months ago

Thanks for reporting this! I probably should finally get around to implementing the proper rendering pipeline, which should fix issues like this. But in the meantime, I'll take a look at fixing this perhaps doing something simpler.