Difference between revisions of "Sega Mega Drive/Sprites"

From Sega Retro

(Created page with "On the Sega Mega Drive, '''sprites''' occupy a layer on top of the background and foreground planes. Each sprite consists of between 1 and 16...")
 
 
(5 intermediate revisions by one other user not shown)
Line 19: Line 19:
 
* '''VF/HF:''' Vertical & horizontal flipping. 1 = flipped; 0 = normal.
 
* '''VF/HF:''' Vertical & horizontal flipping. 1 = flipped; 0 = normal.
 
* '''GFX:''' Tile number from VRAM. i.e. VRAM address to read graphics data, divided by $20.
 
* '''GFX:''' Tile number from VRAM. i.e. VRAM address to read graphics data, divided by $20.
* '''NEXT:''' Next sprite number to jump to. Later sprites go on top of earlier ones. The final sprite must jump to 0.
+
* '''NEXT:''' Next sprite number to jump to. Earlier sprites go on top of later ones. The final sprite must jump to 0.
  
 
===Position===
 
===Position===
 +
Sprites can be placed in a 512x512 area, with the visible screen starting at the 128,128 position. This diagram shows the NTSC screen in 256 or 320 pixel wide modes in green, with additional PAL resolution in yellow. Sprites in the red area may be partially visible if they are near the edge of the screen. The diagram on the right shows equivalents in interlaced double resolution mode (vertical coordinates are all doubled).
 +
 +
{| style="background:none"
 +
|
 +
{| style="width:auto; background:none" cellspacing="0"
 +
|style="padding:0px;"| [[File:Spritepos MD.svg]]
 +
|style="vertical-align:top; padding:0px"| <div style="position:relative">
 +
<div style="border-top:solid 1px red; padding-left:10px; position:absolute; top:0px">&nbsp;&nbsp;&nbsp;0</div>
 +
<div style="border-top:solid 1px green; padding-left:10px; position:absolute; top:128px">128</div>
 +
<div style="border-top:solid 1px green; padding-left:10px; position:absolute; top:351px">351</div>
 +
<div style="border-top:solid 1px gold; padding-left:10px; position:absolute; top:367px">367</div>
 +
<div style="border-top:solid 1px red; padding-left:10px; position:absolute; top:511px">511</div>
 +
</div>
 +
|-
 +
|style="padding:0px"| <div style="position:relative; height:30px">
 +
<div style="border-left:solid 1px red; padding-top:10px; position:absolute; left:0px">0</div>
 +
<div style="border-left:solid 1px green; padding-top:10px; position:absolute; left:128px">128</div>
 +
<div style="border-left:solid 1px green; padding-top:10px; position:absolute; left:383px">383</div>
 +
<div style="border-left:solid 1px green; padding-top:10px; position:absolute; left:447px">447</div>
 +
<div style="border-left:solid 1px red; padding-top:10px; position:absolute; left:511px">511</div>
 +
</div>
 +
|
 +
|}
 +
|
 +
{| style="width:auto; background:none" cellspacing="0"
 +
|style="padding:0px;"| [[File:Spriteposint MD.svg|256px]]
 +
|style="vertical-align:top; padding:0px"| <div style="position:relative">
 +
<div style="border-top:solid 1px red; padding-left:10px; position:absolute; top:0px">&nbsp;&nbsp;&nbsp;0</div>
 +
<div style="border-top:solid 1px blue; padding-left:10px; position:absolute; top:128px">256</div>
 +
<div style="border-top:solid 1px blue; padding-left:10px; position:absolute; top:351px">703</div>
 +
<div style="border-top:solid 1px magenta; padding-left:10px; position:absolute; top:367px">735</div>
 +
<div style="border-top:solid 1px red; padding-left:10px; position:absolute; top:511px">511</div>
 +
</div>
 +
|-
 +
|style="padding:0px"| <div style="position:relative; height:30px">
 +
<div style="border-left:solid 1px red; padding-top:10px; position:absolute; left:0px">0</div>
 +
<div style="border-left:solid 1px blue; padding-top:10px; position:absolute; left:64px">128</div>
 +
<div style="border-left:solid 1px blue; padding-top:10px; position:absolute; left:191px">383</div>
 +
<div style="border-left:solid 1px blue; padding-top:10px; position:absolute; left:223px">447</div>
 +
<div style="border-left:solid 1px red; padding-top:10px; position:absolute; left:255px">511</div>
 +
</div>
 +
|
 +
|}
 +
|}
  
 
===Size===
 
===Size===
 +
Sprites consist of between 1 and 16 tiles, which are arranged in the following ways depending on their size setting:
 +
{|
 +
| Size || 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || A || B || C || D || E || F
 +
|-
 +
| Pattern
 +
| <pre>0</pre>
 +
| <pre>0
 +
1</pre>
 +
| <pre>0
 +
1
 +
2</pre>
 +
| <pre>0
 +
1
 +
2
 +
3</pre>
 +
| <pre>01</pre>
 +
| <pre>02
 +
13</pre>
 +
| <pre>03
 +
14
 +
25</pre>
 +
| <pre>04
 +
15
 +
26
 +
37</pre>
 +
| <pre>012</pre>
 +
| <pre>024
 +
135</pre>
 +
| <pre>036
 +
147
 +
258</pre>
 +
| <pre>048
 +
159
 +
26A
 +
37B</pre>
 +
| <pre>0123</pre>
 +
| <pre>0246
 +
1357</pre>
 +
| <pre>0369
 +
147A
 +
258B</pre>
 +
| <pre>048C
 +
159D
 +
26AE
 +
37BF</pre>
 +
|}
 +
 +
==Sprite masking==
 +
* If a sprite has an x coordinate of 0, it will mask any sprites after it in the sprite list that are also on the same scanlines.
 +
** One sprite can mask an area 8, 16, 24 or 32 pixels tall, depending on its height.
 +
* If two sprites have x coordinates of 0 and 1 respectively, they will mask any sprites after them in the sprite list that are on the same scanlines as both sprites.
 +
** Two sprites can mask an area between 1 and 32 pixels tall, depending on their heights and by how much they overlap.
  
[[Category:Sega Mega Drive|Sprites]]
+
[[Category:Mega Drive technical information|Sprites]]
[[Category:Unofficial documentation]]
 

Latest revision as of 07:56, 3 October 2020

On the Sega Mega Drive, sprites occupy a layer on top of the background and foreground planes. Each sprite consists of between 1 and 16 tiles arranged in a grid up to 4x4. Tiles are read from the VRAM sequentially, and arranged in the sprite top-to-bottom then left-to-right. They can use a single palette line each, limiting them to 15 colours (plus 1 transparent), though layering sprites can circumvent this limit.

The VDP can display a maximum of:

  • in 256 pixel (32 cell) wide mode, 64 ($40) sprites per frame, 16 ($10) sprites per scanline.
  • in 320 pixel (40 cell) wide mode, 80 ($50) sprites per frame, 20 ($14) sprites per scanline.

Sprite table

The sprite table is stored in VRAM. It contains a list of all currently displayed sprites, with 8 bytes per sprite in the following format:

7
6
5
4
3
2
1
0

0
0
0
0
0
0
VP
7
6
5
4
3
2
1
0

VP


7
6
5
4
3
2
1
0

0
0
0
0
HS
VS
7
6
5
4
3
2
1
0

0
NEXT


7
6
5
4
3
2
1
0

PR
PL
VF
HF
GFX
7
6
5
4
3
2
1
0

GFX


7
6
5
4
3
2
1
0

0
0
0
0
0
0
0
HP
7
6
5
4
3
2
1
0

HP
  • VP: Vertical position.
  • HP: Horizontal position.
  • HS/VS: Size.
  • PR: Priority. 1 = high; 0 = low.
  • PL: Palette line.
  • VF/HF: Vertical & horizontal flipping. 1 = flipped; 0 = normal.
  • GFX: Tile number from VRAM. i.e. VRAM address to read graphics data, divided by $20.
  • NEXT: Next sprite number to jump to. Earlier sprites go on top of later ones. The final sprite must jump to 0.

Position

Sprites can be placed in a 512x512 area, with the visible screen starting at the 128,128 position. This diagram shows the NTSC screen in 256 or 320 pixel wide modes in green, with additional PAL resolution in yellow. Sprites in the red area may be partially visible if they are near the edge of the screen. The diagram on the right shows equivalents in interlaced double resolution mode (vertical coordinates are all doubled).

Spritepos MD.svg
   0
128
351
367
511
0
128
383
447
511
Spriteposint MD.svg
   0
256
703
735
511
0
128
383
447
511

Size

Sprites consist of between 1 and 16 tiles, which are arranged in the following ways depending on their size setting:

Size 0 1 2 3 4 5 6 7 8 9 A B C D E F
Pattern
0
0
1
0
1
2
0
1
2
3
01
02
13
03
14
25
04
15
26
37
012
024
135
036
147
258
048
159
26A
37B
0123
0246
1357
0369
147A
258B
048C
159D
26AE
37BF

Sprite masking

  • If a sprite has an x coordinate of 0, it will mask any sprites after it in the sprite list that are also on the same scanlines.
    • One sprite can mask an area 8, 16, 24 or 32 pixels tall, depending on its height.
  • If two sprites have x coordinates of 0 and 1 respectively, they will mask any sprites after them in the sprite list that are on the same scanlines as both sprites.
    • Two sprites can mask an area between 1 and 32 pixels tall, depending on their heights and by how much they overlap.