Sprites beyond the top edge of the screen
Moderator: Moderators
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Sprites beyond the top edge of the screen
I noticed that some emulators, like Nestopia, handle sprite movement out of the top edge of the screen quite smoothly. A case in point is the intro for Dragon Ball Z - Kyoushuu! Saiya Jin (Japan), in which you see the Z logo (8x8 array of 8x8px sprites) scroll off the top edge smoothly, rather than disappear in 8-pixel wide strips.
I would think that the sensible way to handle this is to interpret the OAM sprite Y position range (240 .. 255) as a signed byte value (-16 .. -1) so that it is easy to calculate that the sprite is within scanline range when in scanlines 0 .. 7. The range 240..255 is invisible as a positive value anyway, however, for 8x8 and 8x16 sprites, this could be used to place them just beyond or straddling the top edge of the screen. Dragon Ball Z seems to use this and Nestopia handles it nicely. I have been less successful with my own implementation, but most likely it is a bug at my end.
What are your thoughts on this?
I would think that the sensible way to handle this is to interpret the OAM sprite Y position range (240 .. 255) as a signed byte value (-16 .. -1) so that it is easy to calculate that the sprite is within scanline range when in scanlines 0 .. 7. The range 240..255 is invisible as a positive value anyway, however, for 8x8 and 8x16 sprites, this could be used to place them just beyond or straddling the top edge of the screen. Dragon Ball Z seems to use this and Nestopia handles it nicely. I have been less successful with my own implementation, but most likely it is a bug at my end.
What are your thoughts on this?
Last edited by colinvella on Mon Jul 04, 2016 12:46 pm, edited 1 time in total.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Re: Sprites beyond the top edge of the screen
Are you sure Nestopia isn't hiding the top 8 scanlines? It's pretty common for NES emulators to hide the top and bottom 8 scanlines.
Re: Sprites beyond the top edge of the screen
In theory, it should be possible to clip a sprite against the top of the screen in software the way Solstice clips everything against the level map. But I don't think any game bothered with that. They just relied on the top 10-16 scanlines just not being visible on consumer NTSC monitors. Many games clipped as a side effect of a top status bar, and those few games that did clipping without a top status bar (e.g. Jurassic Park) did so by switching to a blank CHR bank during the top few scanlines.
If you can spare 8 sprites, you can use those to clip sprites by placing them in front. Add a ninth and you can also use that to determine when to turn on background rendering.
If you can spare 8 sprites, you can use those to clip sprites by placing them in front. Add a ninth and you can also use that to determine when to turn on background rendering.
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Re: Sprites beyond the top edge of the screen
Not sure to be honest, but I did monitor the Y sprite attribute as the Dragonball Logo crossed the top edge and I could see the Y value go down to 0 and then wrap around to 255. I'll need to test furtherJoe wrote:Are you sure Nestopia isn't hiding the top 8 scanlines? It's pretty common for NES emulators to hide the top and bottom 8 scanlines.
Last edited by colinvella on Mon Jul 04, 2016 12:47 pm, edited 1 time in total.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Re: Sprites beyond the top edge of the screen
The logo is a composite 64x64 pixel sprite (save perhaps for missing corners since it is circular) and hence most likely, all sprites are used up. The background is split via the Bandai FCG mapper's IRQ counter, so that the bottom is a rolling sea, whilst the top part shows clouds scrolling out off the horizon. Hence, I doubt it is using IRQ trickery for the top 8 pixels, but I could be wrong.tepples wrote:If you can spare 8 sprites, you can use those to clip sprites by placing them in front. Add a ninth and you can also use that to determine when to turn on background rendering.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Sprites beyond the top edge of the screen
No, the sprites simply do not wrap. Games rely on the fact that placing a sprite at Y=255 makes it appear offscreen.colinvella wrote:I would think that the sensible way to handle this is to interpret the OAM sprite Y position range (240 .. 255) as a signed byte value (-16 .. -1) so that it is easy to calculate that the sprite is within scanline range when in scanlines 0 .. 7. The range 240..255 is invisible as a positive value anyway, however, for 8x8 and 8x16 sprites, this could be used to place them just beyond and straddling the top edge of the screen. Dragon Ball Z seems to use this and Nestopia handles it nicely. I have been less successful with my own implementation, but most likely it is a bug at my end.
As stated, on NTSC the top/bottom ~8 lines are hidden, so the problem isn't visible with 8x8 sprites. On PAL the whole screen is visible, and you can see sprites cut off in games with vertical scrolling.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Sprites beyond the top edge of the screen
Lots of games places sprite Y anywhere from 239 to 255. That doesn't mean they're trying to make them appear at the top of the screen. The NES doesn't do that. All of these Y values mean "offscreen".colinvella wrote:Not sure to be honest, but I did monitor the Y sprite attribute as the Dragonball Logo crossed the top edge and I could see the Y value go down to 0 and then wrap around to 255. I'll need to test further
It might be convenient for a game to use that whole range of numbers, e.g. you could have an enemy that wraps around as it moves off the top and returns from the bottom, so you're going to see games that do it. It doesn't matter, though, because no sprites from that range will display.
Re: Sprites beyond the top edge of the screen
I think colinvella is asking whether it would be a nice augment (the same as the "allow more than 8 sprites per scanline") to treat slightly-negative Y scroll values as off-the-top.
To which I basically have three thoughts:
1- Games probably don't actually comply with that definition, but you won't know if you don't try it
2- It should really only be thought as applicable to PAL consoles anyway, since NTSC televisions already treat small positive values as off-the-top.
3- There should definitely be a toggle for "authentic" behavior instead of "better than reality" behavior.
To which I basically have three thoughts:
1- Games probably don't actually comply with that definition, but you won't know if you don't try it
2- It should really only be thought as applicable to PAL consoles anyway, since NTSC televisions already treat small positive values as off-the-top.
3- There should definitely be a toggle for "authentic" behavior instead of "better than reality" behavior.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Sprites beyond the top edge of the screen
Oh sure, as an option that's not on by default it's perfectly reasonable.
It would still apply to NTSC cropped output when in 8x16 mode, too.
It would still apply to NTSC cropped output when in 8x16 mode, too.
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Re: Sprites beyond the top edge of the screen
Thanks for the clarification. As suggested in another comment, it was mostly a consideration about an aesthetic improvement provided by the emulator, such as, for example, the ability to allow unlimited sprites and not signalling an overflow to prevent flicker (which I am aware, may actually break some games that rely on overflow).rainwarrior wrote:Lots of games places sprite Y anywhere from 239 to 255. That doesn't mean they're trying to make them appear at the top of the screen. The NES doesn't do that. All of these Y values mean "offscreen".
It might be convenient for a game to use that whole range of numbers, e.g. you could have an enemy that wraps around as it moves off the top and returns from the bottom, so you're going to see games that do it. It doesn't matter, though, because no sprites from that range will display.
I will look into the idea of clipping the top 8 rows of pixels.
Last edited by colinvella on Mon Jul 04, 2016 1:59 pm, edited 1 time in total.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Re: Sprites beyond the top edge of the screen
Pretty much on the same wavelength there. Indeed, I have already implemented the 8 sprite per scanline override, but as an aesthetic option that is disabled by default.lidnariq wrote:I think colinvella is asking whether it would be a nice augment (the same as the "allow more than 8 sprites per scanline") to treat slightly-negative Y scroll values as off-the-top.
To which I basically have three thoughts:
1- Games probably don't actually comply with that definition, but you won't know if you don't try it
2- It should really only be thought as applicable to PAL consoles anyway, since NTSC televisions already treat small positive values as off-the-top.
3- There should definitely be a toggle for "authentic" behavior instead of "better than reality" behavior.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Re: Sprites beyond the top edge of the screen
A lot of games would need to be hacked to output these negative values. I know that the metasprite decoder in Haunted: Halloween '85 just skips any horizontal strip whose top isn't within 1-239 pixels from the top of the screen.
- colinvella
- Posts: 74
- Joined: Sun Jun 05, 2016 1:41 pm
Re: Sprites beyond the top edge of the screen
Incidentally, I can confirm that Nestopia, for instance, clips both the top and bottom 8 pixels, regardless of mirroring mode, scrolling etc. That explains why I couldn't eliminate a number of artefacts.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
Re: Sprites beyond the top edge of the screen
The "clipping Nestopia does" is under Options -> Video. Specifically, you're allowed to define the visual screen area for both PAL and NTSC based on horizontal (scanline) and vertical pixel row. The defaults are:
PAL: Left = 0, Right = 255, Top = 1, Bottom = 239
NTSC: Left = 0, Right = 255, Top = 8, Bottom = 231
This looks correct (i.e. like correct behaviour) to me.
PAL: Left = 0, Right = 255, Top = 1, Bottom = 239
NTSC: Left = 0, Right = 255, Top = 8, Bottom = 231
This looks correct (i.e. like correct behaviour) to me.
Re: Sprites beyond the top edge of the screen
Nope, PAL should default to Left=2 and Right=253, and I believe to Top=0.This looks correct (i.e. like correct behaviour) to me.