Difference between revisions of "Sega Mega Drive/Scrolling"

From Sega Retro

(Created page with "The Sega Mega Drive is able to '''scroll''' the background and foreground (planes B & A) independently, both horizontally and vertically. ==Horizontal scrolling== Horizon...")
 
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
The [[Sega Mega Drive]] is able to '''scroll''' the background and foreground (planes B & A) independently, both horizontally and vertically.
+
The [[Sega Mega Drive]] is able to '''scroll''' the background and foreground ([[Sega Mega Drive/Planes|planes]] B & A) independently, both horizontally and vertically.
  
 
==Horizontal scrolling==
 
==Horizontal scrolling==
 
Horizontal scrolling is controlled by a table located in VRAM. The address for the table is set by [[Sega Mega Drive/VDP registers#0D|VDP register $0D]], while the format is set by [[Sega Mega Drive/VDP registers#0B|register $0B]]. There are three possible settings for this register:
 
Horizontal scrolling is controlled by a table located in VRAM. The address for the table is set by [[Sega Mega Drive/VDP registers#0D|VDP register $0D]], while the format is set by [[Sega Mega Drive/VDP registers#0B|register $0B]]. There are three possible settings for this register:
  
{|
+
{|class="prettytable"
! Type || Space in VRAM || Format || Code
+
! Type || Space in VRAM || Format || Code to set VDP
 
|-
 
|-
 
| Whole screen
 
| Whole screen
Line 15: Line 15:
 
|-
 
|-
 
| 8 pixel strips
 
| 8 pixel strips
| 112 ($70) bytes (NTSC)<br>120 ($78) bytes (PAL)
+
| 896 ($380) bytes (NTSC)<br>960 ($3C0) bytes (PAL)
| <tt>FFFF BBBB FFFF BBBB FFFF BBBB...</tt>
+
| <tt>FFFF BBBB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000<br>FFFF BBBB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000<br>FFFF BBBB...</tt>
* Alternating words control foreground and background strips
+
* 1st word controls 1st foreground strip
 +
* 2nd word controls 1st background strip
 +
* The next 14 words are unused, then the pattern repeats for the 2nd strip etc.
 
| <tt>move.w #$8B02,($c00004).l</tt>
 
| <tt>move.w #$8B02,($c00004).l</tt>
 
|-
 
|-
Line 28: Line 30:
  
 
==Vertical scrolling==
 
==Vertical scrolling==
 +
The vertical scrolling table is located in VSRAM. Its format is set by [[Sega Mega Drive/VDP registers#0B|register $0B]]. There are only two types of vertical scrolling: whole screen and 16 pixel strips:
 +
 +
{|class="prettytable"
 +
! Type || Space in VSRAM || Format || Code to set VDP
 +
|-
 +
| Whole screen
 +
| 4 bytes
 +
| <tt>FFFF BBBB</tt>
 +
* 1st word controls foreground
 +
* 2nd word controls background
 +
| As above.
 +
|-
 +
| 16 pixel strips
 +
| 64 ($40) bytes (256 pixel wide mode)<br>80 ($50) bytes (320 pixel wide mode)
 +
| <tt>FFFF BBBB FFFF BBBB FFFF BBBB...</tt>
 +
* Alternating words control foreground and background strips
 +
| with whole screen horizontal:<pre>move.w #$8B04,($c00004).l</pre>
 +
with 8 pixel horizontal:<pre>move.w #$8B06,($c00004).l</pre>
 +
with scanline horizontal:<pre>move.w #$8B07,($c00004).l</pre>
 +
|}
 +
 +
==Format==
 +
One word is used to define how much each scrollable unit (whole screen, strip or scanline) is shifted:
 +
 +
{{bitfield|0|0|0|0|0|0|S9-S8;2}}{{bitfield|S7-S0;8}}
 +
* '''S9-S0:''' Number of pixels to shift. Between 0 and 1024 ($400).
 +
* ''n.b.'' [[Sega Mega Drive/Planes|Nametables]] are at most 1024 pixels wide or tall. Planes "wrap around", so it's not possible to have part of the screen with no plane.
  
[[Category:Sega Mega Drive|Scrolling]]
+
[[Category:Mega Drive technical information|Scrolling]]
[[Category:Unofficial documentation]]
 

Latest revision as of 08:55, 3 October 2020

The Sega Mega Drive is able to scroll the background and foreground (planes B & A) independently, both horizontally and vertically.

Horizontal scrolling

Horizontal scrolling is controlled by a table located in VRAM. The address for the table is set by VDP register $0D, while the format is set by register $0B. There are three possible settings for this register:

Type Space in VRAM Format Code to set VDP
Whole screen 4 bytes FFFF BBBB
  • 1st word controls foreground
  • 2nd word controls background
move.w #$8B00,($c00004).l
8 pixel strips 896 ($380) bytes (NTSC)
960 ($3C0) bytes (PAL)
FFFF BBBB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
FFFF BBBB 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
FFFF BBBB...
  • 1st word controls 1st foreground strip
  • 2nd word controls 1st background strip
  • The next 14 words are unused, then the pattern repeats for the 2nd strip etc.
move.w #$8B02,($c00004).l
Per scanline 896 ($380) bytes (NTSC)
960 ($3C0) bytes (PAL)
FFFF BBBB FFFF BBBB FFFF BBBB...
  • Alternating words control foreground and background scanlines
move.w #$8B03,($c00004).l

Vertical scrolling

The vertical scrolling table is located in VSRAM. Its format is set by register $0B. There are only two types of vertical scrolling: whole screen and 16 pixel strips:

Type Space in VSRAM Format Code to set VDP
Whole screen 4 bytes FFFF BBBB
  • 1st word controls foreground
  • 2nd word controls background
As above.
16 pixel strips 64 ($40) bytes (256 pixel wide mode)
80 ($50) bytes (320 pixel wide mode)
FFFF BBBB FFFF BBBB FFFF BBBB...
  • Alternating words control foreground and background strips
with whole screen horizontal:
move.w #$8B04,($c00004).l
with 8 pixel horizontal:
move.w #$8B06,($c00004).l
with scanline horizontal:
move.w #$8B07,($c00004).l

Format

One word is used to define how much each scrollable unit (whole screen, strip or scanline) is shifted:

7
6
5
4
3
2
1
0

0
0
0
0
0
0
S9-S8
7
6
5
4
3
2
1
0

S7-S0
  • S9-S0: Number of pixels to shift. Between 0 and 1024 ($400).
  • n.b. Nametables are at most 1024 pixels wide or tall. Planes "wrap around", so it's not possible to have part of the screen with no plane.