Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBJ Window interaction with objects is inaccurate #275

Closed
Vulcalien opened this issue Feb 3, 2023 · 9 comments
Closed

OBJ Window interaction with objects is inaccurate #275

Vulcalien opened this issue Feb 3, 2023 · 9 comments
Assignees

Comments

@Vulcalien
Copy link
Contributor

In GBATEK documentation, in describing the OBJ Window, there is this line:
The color, palette, and display priority of these OBJs are ignored.
NBA seems to have this behavior, but on hardware it doesn't seem to be true.


I made a test ROM that shows the difference in behavior.

The Test object (OBJ 0) is a red square.
The Mask object (OBJ 1) is in OBJ Window mode.
The Background is BG0.

By pressing any button, the priority of them will change.

For example, the behavior is different for BG: 0, Test: 1, Mask: 0


This might be some sort of "garbage" result on hardware that isn't emulated.
It may have to do with Test being OBJ 0 and Mask being OBJ 1. I haven't tried the opposite order.

ROM: test.zip
Source Code: source.zip

@fleroviux
Copy link
Member

That's an interesting find. I will definitely look into this, but please allow a little bit of time, since I'm in the middle of rewriting my PPU emulation at the moment.

@Vulcalien
Copy link
Contributor Author

No hurry! The improved PPU emulation is surely more important than a small bug not being emulated.

@fleroviux
Copy link
Member

This looks like another instance of the sprite priority bug. Window OBJs seem to update the priority in the sprite line buffer, even if the pixel is transparent. This means the window sprite, since it is rendered after the test sprite, can force the test sprite to become visible outside the sprite window where the two sprites overlap.

@fleroviux
Copy link
Member

@Vulcalien this bug should be fixed in the latest development build

@Vulcalien
Copy link
Contributor Author

Vulcalien commented May 25, 2023

I can confirm that the newest version [^1] of NBA runs the test ROM exactly like hardware!

However, it isn't fully accurate yet. I tried running the game in which I originally found the bug and now NBA is showing "too much".


I've included another test ROM: this time it's a modified version of that game showing the exact situation where the inaccuracy occurs.

What works

In the demo, the player is holding a lantern, causing four sprites in OBJ window mode (the lantern's light) to make the area visible. Unlike all other sprites that have priority 2, the lantern light's sprites have priority 0 (which causes the weird behavior). The newest version of NBA correctly shows the zombies "on top" of the dark area.

What doesn't work

But if the inventory is opened (by pressing B), we see the first difference in behavior. On NBA the player is drawn on top of the menu, while on hardware the player is hidden. When opening the menu, the player will put the lantern away and a small square of light around him will appear. This square is an OBJ window sprite with priority 0.

The second inaccuracy can be seen after closing the menu (B again), getting close to a zombie and opening the menu again. NBA shows every part of the zombie that is inside the square of light, while on hardware the zombie's sprite appears dotted.

nba-hw_behavior-difference[^2]


Sorry for the long text, and thanks for caring so much about accuracy!

ROM: minicraft_debug.zip


[^1] I tested both the nightly build and a compiled version of the master branch.
[^2] The expected behavior image is drawn, not a screenshot, so most likely the pixels are not exact.

@fleroviux fleroviux reopened this May 26, 2023
@Vulcalien
Copy link
Contributor Author

Intuition: maybe the pixel priority is updated only if that pixel is outside of the window?

That would make sense, because the menu has BG priority 0 and the pixels drawn on top of it appear to have OBJ priority 0.

@fleroviux
Copy link
Member

Intuition: maybe the pixel priority is updated only if that pixel is outside of the window?

Yes, I was actually testing exactly that in this moment, lol! That seems to fix this issue. This is so cursed haha.

@fleroviux
Copy link
Member

@Vulcalien this should be fixed in the latest dev build now.

@Vulcalien
Copy link
Contributor Author

It works! Exactly the same behavior as on hardware. All the pixels are in the right place.
The new code makes perfect sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants