XaiJu
Lizardrive
Lizardrive

patreon


SEGA Megadrive game development #2

More about graphics

As we have seen previously, VDP’s VRAM is used to store graphics. This is done in order to offload 68000 processor.

We will now get a little bit more into details by reviewing essential notions for game development.

Palettes

Colors must be picked according to a set of 512 colors available (https://en.wikipedia.org/wiki/List_of_video_game_console_palettes#Mega_Drive/Genesis).

Megadrive is able to handle 4 palettes, each containing 16 colors, allowing to simultaneously display up to 64 colors (but first palettes’ color is considered as transparent).

Back in the days, developers found ways of displaying more colors on screen as explained in this short video: https://www.youtube.com/watch?v=1lHDsXMwBwk. This trick will nevertheless not work properly on emulators and console clones.  

Tiles

Like other game consoles did back in the days, VDP is handling graphics based on 8*8 pixel patterns. Such a square is called a tile.

Each tile is stored in the VRAM. Flipped tiles can be drawn on screen without taking more space in VRAM. This is very useful when drawing a scenery (think about the four corners of a room for instance).

Each tile is using one and only one palette.

Tiles cannot be placed freely. Instead, they must be placed at multiple of 8 position, starting from top left of the screen.

The following piece of code represents one tile with pixels using colors ranging from 0 to 4 (0 being allocated to transparency):

<code>const u32 tile[8]=
{
               0x00111100,
               0x01144110,
               0x11244211,
               0x11244211,
               0x11222211,
               0x11222211,
               0x01122110,
               0x00111100
};</code>

Once displayed, this tile will look like a ring.

Sprites 

Like tiles, sprites are also made of 8*8 squares and use one palette.  

A sprite can be as big as up to 4*4 tiles (meaning 32*32 pixels).  

Bigger sprites can me made by assembling several sprites. In that case, they are called meta-sprites.

Console is able to handle up to 80 sprites simultaneously.  

Sprites may blink in case there are too many displayed on a same line (around 20 sprites).

Sprites are also stored in VRAM, starting from a specific memory range. Once memory is full, it may start overwriting sprites based on FIFO, leading to visual glitches. It is therefore essential to recycle sprites as much as possible rather than adding new ones.

Unlike tiles, sprites can be placed anywhere on screen.

Sprites are commonly used to display characters, bullets, vehicles… But some tricks may be used in order to cope with console’s limitation and impress player. For example, a huge monster taking half the screen may actually be made of both tiles and sprites.

Planes

Megadrive is working with 3 different planes: 2 (plan A et B) for tiles and 1 for sprites.

Plan A and B are scrollable and can have custom sizes.  

Sprite plane has a fixed size (512*512) and cannot be scrolled.

By default, priority is set a such: 


You can therefore imagine drawing a skybox on plan B, ground and buildings on plan A, and place your character’s sprites on Sprites plan.

While this already is sufficient to handle most situations, different priorities can be defined for both plans and sprites. It is therefore totally possible to have a sprite go below a tile of plan B at a specific position.

Each of these planes are redrawn on each screen refresh (either 60Hz or 50Hz depending on hardware’s region).

Recommended tool

In order to check VRAM’s content, I use the emulator Gens with Kmod:
 


It is a good way of controlling that your code is behaving properly (i.e. that you do not waste VRAM / overwrite something important).

Among other features, Gens Kmod allows you to enable/disable specific planes. This can help you understand how talented developers have built complex visuals.


More Creators