Actions

Sega Mega Drive/Shadow and highlight

From Sega Retro

Shadow and highlight is a feature of the Sega Mega Drive VDP which allows the brightness of pixels to be adjusted to three different levels: normal, shadow and highlight. This increases the potential palette of colours from 512 to around 1536 (some of those will be duplicates). It also triples the number of colours that can be displayed on screen simultaneously.

Enable shadow and highlight mode

Shadow and highlight mode is controlled by mode register 4 (register $0C). The same register also controls screen resolution (320 or 256 pixel wide mode) and interlace mode.

The following code will set the appropriate register:

move.w #$8Cxx,($c00004).l

Replace xx with one of the following values:

Interlace
disable enable double
Resolution 320 pixels wide 89 8B 8F
256 pixels wide 08 0A 0E

Rules

  • A tile on the foreground (plane A) with low priority is shadowed, with high priority it's normal.
    • Background (plane B) pixels are shadowed if the foreground is.
    • If a background tile has high priority, it will appear normal and on top of a low priority foreground tile.
    • Sprites are shadowed if the foreground is, unless their high priority bit is set, in which case they appear normal.
  • A pixel in a sprite using palette line 4, colour 15 will highlight the pixel beneath it (planes only).
    • If the pixel is shadowed by the first rule, it will appear normal.
  • A pixel in a sprite using palette line 4, colour 16 will shadow the pixel beneath it (planes only).
    • If the pixel is shadowed by the first rule, it will appear shadowed.
  • Sprites can't shadow/highlight other sprites. If sprite with a shadow/highlight pixel occludes another sprite, the plane will be visible through that pixel (with shadow/highlight applied).
  • Normal sprites can cover shadow/highlight sprites if they have a higher priority, as expected.
  • Pixels in sprites using colour 15 of palette lines 1, 2 or 3 will always appear normal. Possibly a bug.

Shadow and highlight palette.svg

Disable shadow and highlight mode

The shadow/highlight enable bit is located in register 12 (Mode Set Register No. 4), which also contains settings for screen width and interlacing.

Use this instruction to set Mode Set Register No. 4 to the value $xx:

move.w #$8Cxx,($c00004).l

To determine the value of $xx, use the following chart. The resulting value will be in binary, which can be converted to hexadecimal using a calculator:

MSB LSB
Reg. #12 RS0 0 0 0 S/TE LSM0 LSM1 RS1

RS0/RS1 controls screen width:

  • 00: 256 pixels (32 cells)
  • 11: 320 pixels (40 cells)

LSM0/LSM1 controls interlacing:

  • 00: No interlacing
  • 01: Interlacing Mode 1
  • 11: Interlacing Mode 2 (double resolution)

S/TE controls shadow/highlight:

  • 0: Disabled
  • 1: Enabled