Sprite display area

SGDK only sub forum

Moderator: Stef

Post Reply
s7jones
Newbie
Posts: 1
Joined: Sat Feb 06, 2016 1:29 pm

Sprite display area

Post by s7jones » Sat Feb 06, 2016 2:52 pm

Hi SpritesMind.net,

Thanks to Stephane-D for first directing me.
I have some questions about sprites and sprites display area.

Sega Drive resolutions (from Wikipedia):
320 x 224 NTSC
320 x 240 PAL

This page (http://cgfm2.emuviews.com/txt/genvdp.txt) says that:
> "Sprites are positioned in a virtual 512x512 space. The display starts at
> coordinate 128, 128, and takes up a space equal to the size of the physical
> display. (usually 256x224 or 320x224) This system is convenient for
> programmers; unwanted sprites can easily be hidden off screen, and sprites
> can be shown partially at the top and left screen edges."
This page (http://md.squee.co/VDP#Sprites) says that:
> The range X values is 0 through 551, but the displayable X values begins at 128, up to 383 or 447, depending on horizontal mode. The sprite's Y position values are from 0 through 551, but the displayable values start at 128 and go up to 351 or 367 depending on vertical mode.
And I'm also referencing the sprite tutorial at (https://github.com/Stephane-D/SGDK/wiki ... -%28old%29)

What I don't understand:
  • The second link says that the X and Y can change between 0 and 551, but the first and third link says that the sprite plane is "fixed size (512x512 in common case)". Is 551 a spelling mistake, should it be 511?
From the second link, the sprite attribute table has 9 bits for horizontal position and 10 bits for vertical position, so this is 2^9 - 1 = 511 and 2^10 - 1 = 1023 respectively.

I'm writing a simple game of "Snake" using SGDK. I have a 8x8 px sprite, and every N frames the position is changed by 8 depending on his direction.

What I see on GensKmod is that when the Snake moves horizontally his X values go between 128 and 383. But when going vertically his Y values go between 0 and 1023.
The resolution displayed by the emulator is 320 x 224, sprite horizontal displayable width 383 - 128 is only 255 pixels, less than my screen resolution.

What I don't understand:
  • Why is it that SGDK has defaulted to a displayable horizontal resolution of 128 to 383, how do I change it to be 128 to 447?
  • Why is it that my sprites horizontal position is restricted to the sprite displayable area of 128 to 383, but that his vertical position uses the full 10 bits?
  • How come the vertical position is not restricted to 128 to 351?
  • How come the horizontal position cannot use the full 9 bit of 0 to 511?
Any appreciation you could give would be helpful.

If necessary I can try and make a short video explaining my questions.

Thank you,
Sam.

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Sprite display area

Post by r57shell » Sun Feb 07, 2016 5:46 pm

All that confusion comes from using ambigious things.
"Sprite visible position" - is ambigious term. All what it can do, is confuse you.

To describe sprite positioning on screen in complete way, all you have to do is to say:
1) all sprites is rects, axis aligned.
2) two axis: x, y. X is horizontal axis. Y is vertical axis.
3) Coords by X increasing from left to right. Coords by Y increasing from top to bottom.
4) Coords of sprite defining its top left corner.
5) Coords of screen top left corner is at (128, 128)
6) All coords are unsigned, and thus range is restricted only by bits count reserved for them.

From (6) you can say, that if x has n bits, then it has max value ((2^n)-1). I don't remember how many bits each coord has, so don't ask.
From (5) you can say, that if sprite has coords (128, 128), then its top left corner is right at top left corner of screen.

Now, why "Sprite visible position" - is ambigious term.
Because:
1) if sprite is 16x8 and has only single non-transparent pixel at its (0,0) pixel
and this one pixel is not visible on screen at the moment because sprite coords are (113,128)
should this sprite be considered visible?
2) You can say, that it should be considered as visible, because its top right corner is on screen, at coords (129, 128). Thus, rightmost pixel of sprite is on (128,128).
But then, what if I change sprite size, to 8x8? Its top right corner becomes (121,128). And obviously, none of sprite pixels on screen.
3) Also, in mode 256x224, you won't see sprite with coords (128+256,128). But in mode 320x224 you will.

Summary. Visibility depends on sprite size, tile data, and screen mode.
Image

Post Reply