Changing screen resolution
Note: if you just want to use 256×224 or 320×224 (like nearly every game) then the first section has everything you need to know.
Setting the video mode
You'll need the VDP register constants here.
The Mega Drive has a bunch of different screen resolutions. Changing the
screen resolution is pretty easy: we need to write to VDP register $8Cxx
(VDPREG_MODE4
) with the new video mode. This register also
lets you toggle shadow/highlight, so we
may as well go over that.
Iwis says
What comes below is a simplification that gets the job done, if you want more details check the VDP register documentation linked above.
The value we need to write is as follows:
- Bits 7 and 0 determine the horizontal resolution
- Bits 2 and 1 determine the vertical resolution
(see remarks on 448px mode)
- Both 0: 224px high (using 8×8 tiles)
- Both 1: 448px high (using 8×16 tiles)
- Bit 3 determines whether shadow/highlight is set
- 0: shadow/highlight disabled
- 1: shadow/highlight enabled
So first we need to make a list of every possible combination:
GFXMODE_256x224: equ %00000000
GFXMODE_320x224: equ %10000001
GFXMODE_256x448: equ %00000110
GFXMODE_320x448: equ %10000111
GFXMODE_256x224_SH: equ %00001000
GFXMODE_320x224_SH: equ %10001001
GFXMODE_256x448_SH: equ %00001110
GFXMODE_320x448_SH: equ %10001111
Now we can change the video mode by writing to the register:
move.w #VDPREG_MODE4|GFXMODE_320x224, (VdpCtrl)
Or better yet, wrap it into a macro:
SetGfxMode macro mode
move.w #VDPREG_MODE4|(mode), (VdpCtrl)
endm
; Then when we need it:
SetGfxMode GFXMODE_320x224
Regarding 448px high modes
The 448px high video mode is better known as interlaced mode (because of the way the screen is refreshed). This mode doubles the vertical resolution and hence tiles are 8×16 pixels instead of the usual 8×8.
This is what you should be aware of (especially the first two):
- 8×16 tiles are, as you may expect, two consecutive 8×8 tiles glued together.
- For the most part coordinates are adjusted accordingly, i.e. both scroll and sprite vertical position are doubled in resolution. The main difference would be for raster effects, which are still treated like low resolution (see below why).
- As mentioned, this mode is "interlaced". This means that first it renders the even lines, next the odd lines, then even, then odd, etc. This means it will take two vertical blank interrupts to draw the whole screen, so expect some minor artifacts if you keep updating at full speed (Sonic 2 gets away with it, so don't worry much).
- Due to the above, horizontal blank interrupts still come at the
"low" resolution, which affects raster effects. If you still want to
do raster effects at the higher resolution, you can check whether
it's even or odd by reading from
$C00004
(VdpCtrl
) and checking bit 4 (0 = even lines, 1 = odd lines).
240px/480px high resolution
Actually there's more to it: the Mega Drive has a setting that lets it
show 30 tiles vertically. The catches: it's in VDP register $81xx
(VDPREG_MODE2
) and,
more importantly, only works properly on PAL systems,
which can heavily limit its usefulness.
Bit 3 toggles whether the screen is 28 or 30 tiles high (note that if the game is running on a NTSC system, you must set this bit to 0 or the console will misbehave):
About H32/H40/V28/V30
Sometimes you may heard video modes being referred to as H40 or the like (and mentioned earlier in this page). This nomeclature refers to the size of the screen in tiles:
- H32: 32 tiles horizontally
- H40: 40 tiles horizontally
- V28: 28 tiles vertically
- V30: 30 tiles vertically