Why is Castlevania displaying these lines in title screen?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
rodri042
Posts: 9
Joined: Wed Mar 06, 2019 11:57 pm

Why is Castlevania displaying these lines in title screen?

Post by rodri042 »

See pic: https://imgur.com/a/frBl0Tl

I recently add support for 8x16 sprites in my PPU. The rest of the game looks good, so I think it's an off-by-one error but I can't find it. Any ideas? 😅

I uploaded my sprite rendering code at:
renderSprites: https://gist.github.com/rodri042/3ac148 ... 1441a911ca
OAM: https://gist.github.com/rodri042/448b38 ... 28779df618
Sprite: https://gist.github.com/rodri042/04c173 ... 5f6a51f5d8
User avatar
Gilbert
Posts: 564
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Why is Castlevania displaying these lines in title screen?

Post by Gilbert »

The sprites are drawn one line too high.
The reason being on real hardware sprites are drawn one line lower than the Y coordinate you set in the OAM, i.e. if byte 0 of a sprite's attribute 0 is set to '0', it's drawn at line 1 and there is no way to draw a sprite starting from line 0.
rodri042
Posts: 9
Joined: Wed Mar 06, 2019 11:57 pm

Re: Why is Castlevania displaying these lines in title screen?

Post by rodri042 »

Thanks Gilbert! Adding +1 to every sprite Y fixed it :D

I guess this also affects sprite 0 hit? After adding this fix, now I have a glitch where SMB sets the scrolling too late so the topmost lines of the clouds are off (https://imgur.com/a/JOzA9Qx).
Anyway, the emulator now passes more tests from blargg's sprite_hit_tests ROM and sprite 0 hit is triggered exactly on scanline=30, so the previous problem was probably masking this new bug.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Why is Castlevania displaying these lines in title screen?

Post by Pokun »

https://www.nesdev.org/wiki/PPU_registers#PPUSTATUS wrote: Sprite 0 Hit. Set when a nonzero pixel of sprite 0 overlaps a nonzero background pixel, cleared at dot 1 of the pre-render line. Used for raster timing.
So yeah, sprite position is important for determining when sprite 0 hit flag will be set.
Post Reply