Sprites beyond the top edge of the screen

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Sprites beyond the top edge of the screen

Post by colinvella »

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?
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/
Joe
Posts: 650
Joined: Mon Apr 01, 2013 11:17 pm

Re: Sprites beyond the top edge of the screen

Post by Joe »

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.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Sprites beyond the top edge of the screen

Post by tepples »

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.
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Sprites beyond the top edge of the screen

Post by colinvella »

Joe 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.
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
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/
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Sprites beyond the top edge of the screen

Post by colinvella »

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.
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.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sprites beyond the top edge of the screen

Post by rainwarrior »

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.
No, the sprites simply do not wrap. Games rely on the fact that placing a sprite at Y=255 makes it appear offscreen.

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.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sprites beyond the top edge of the screen

Post by rainwarrior »

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
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.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Sprites beyond the top edge of the screen

Post by lidnariq »

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.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Sprites beyond the top edge of the screen

Post by rainwarrior »

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.
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Sprites beyond the top edge of the screen

Post by colinvella »

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.
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).

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/
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Sprites beyond the top edge of the screen

Post by colinvella »

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.
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.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Sprites beyond the top edge of the screen

Post by tepples »

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.
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Sprites beyond the top edge of the screen

Post by colinvella »

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/
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Sprites beyond the top edge of the screen

Post by koitsu »

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.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Sprites beyond the top edge of the screen

Post by Bregalad »

This looks correct (i.e. like correct behaviour) to me.
Nope, PAL should default to Left=2 and Right=253, and I believe to Top=0.
Post Reply