nesdev.com
http://forums.nesdev.com/

Sprites beyond the top edge of the screen
http://forums.nesdev.com/viewtopic.php?f=3&t=14488
Page 1 of 2

Author:  colinvella [ Mon Jul 04, 2016 8:45 am ]
Post subject:  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?

Author:  Joe [ Mon Jul 04, 2016 8:52 am ]
Post subject:  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.

Author:  tepples [ Mon Jul 04, 2016 9:30 am ]
Post subject:  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.

Author:  colinvella [ Mon Jul 04, 2016 12:36 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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

Author:  colinvella [ Mon Jul 04, 2016 12:42 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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.

Author:  rainwarrior [ Mon Jul 04, 2016 12:44 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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.

Author:  rainwarrior [ Mon Jul 04, 2016 12:52 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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.

Author:  lidnariq [ Mon Jul 04, 2016 1:06 pm ]
Post subject:  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.

Author:  rainwarrior [ Mon Jul 04, 2016 1:11 pm ]
Post subject:  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.

Author:  colinvella [ Mon Jul 04, 2016 1:56 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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.

Author:  colinvella [ Mon Jul 04, 2016 1:58 pm ]
Post subject:  Re: Sprites beyond the top edge of the screen

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.

Author:  tepples [ Mon Jul 04, 2016 1:59 pm ]
Post subject:  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.

Author:  colinvella [ Mon Jul 04, 2016 2:02 pm ]
Post subject:  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.

Author:  koitsu [ Mon Jul 04, 2016 2:14 pm ]
Post subject:  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.

Author:  Bregalad [ Tue Jul 05, 2016 12:11 am ]
Post subject:  Re: Sprites beyond the top edge of the screen

Quote:
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.

Page 1 of 2 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/