OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Backgrounds — Mode 6: one hi-res layer with offset-per-tile. More...

#include <snes.h>
#include <snes/tile.h>
#include <snes/math.h>

Macros

#define BANDS   8
 Number of colour bands, one 16x8 tile each.
#define BG1_CHR   0x0000
 VRAM word addresses: BG1 chars, BG1 map, BG3 offset map.
#define BG1_MAP   0x2000
#define BG3_MAP   0x3000
#define OPT_BG1   0x2000
 Offset word bit: apply this word to BG1.

Functions

int main (void)

Variables

static const u16 band_colours [8+1]
 Band colours (palette 0, colours 1..8) and the stripe colour 9.
static u16 cardwords [32]
 The test card's horizontal row: 8 on odd columns, 0 on even.
static u16 maprow [32]
 One tilemap row being built.
u8 opt_card
u8 opt_vertical
static u16 owords [32]
 The offset words of the row that carries the wave.
static u8 px [64]
 One 4bpp character's pixels and its encoding.
static u8 tilebuf [32]
u16 wave_phase
 Probe oracles: wave phase, 1 while the wave is vertical, 1 while the test card is shown.
static u16 zwords [32]
 A row of zero words, for the row that does not.

Detailed Description

Backgrounds — Mode 6: one hi-res layer with offset-per-tile.

Mode 6 is the hi-res member of the offset-per-tile family: a single 4bpp BG1 drawn 512 half-pixels wide, like Mode 5, and BG3 as the offset table, like Mode 2 — one row of horizontal offset words, one row of vertical ones. Like Mode 5, its tiles are always 16 half-pixels wide (character N on the left, N+1 on the right), and that applies to BG3's table too: each offset word moves a 16-half-pixel column, so 32 words still cover the screen (anomie-regs, Backgrounds / Mode 6).

BG1 here is diagonal colour bands drawn in one-half-pixel stripes, a pattern 256-pixel modes cannot show. A sine wave written into the vertical row makes the columns ripple; press A and the wave moves to the horizontal row, and the columns slide sideways instead.

B shows a still test card: every odd column gets the horizontal offset 8 and nothing else, the one bit (bit 3) that falls inside a 16-half-pixel tile. Emulators disagree on it — ares, bsnes and luna shift the column by half a tile, Mesen2 drops the bit — and no reference covers the case in hi-res, so the card is there to be photographed on a console (README).

SNES Concepts
  • Mode 6: setMode(BG_MODE6, 0), BG1 4bpp in hi-res, BG3 = offset map
  • Hi-res: the sub screen draws the even half-pixel columns and the main screen the odd ones, so BG1 goes on both (setMainScreen and setSubScreen), as in Mode 5
  • 16-half-pixel tiles: a map entry for character N draws N and N + 1
  • The offset table as in Mode 2: BG3 row 0 = horizontal words, row 1 = vertical words; bit 13 = apply to BG1; column 0 is never offset
What to Observe
  • Diagonal colour bands with fine vertical stripes ripple up and down as a travelling wave; the leftmost column stays put.
  • Press A: the columns slide sideways instead. A again: back.
  • Press B: the still test card (odd columns offset by 8). B again: back.
Modules Used
console, dma, background, input, math, tile
See also
backgrounds/mode2 (the same table, 256 pixels wide), backgrounds/mode5_hires (hi-res without the table)

Macro Definition Documentation

◆ BANDS

#define BANDS   8

Number of colour bands, one 16x8 tile each.

◆ BG1_CHR

#define BG1_CHR   0x0000

VRAM word addresses: BG1 chars, BG1 map, BG3 offset map.

◆ BG1_MAP

#define BG1_MAP   0x2000

◆ BG3_MAP

#define BG3_MAP   0x3000

◆ OPT_BG1

#define OPT_BG1   0x2000

Offset word bit: apply this word to BG1.

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ band_colours

const u16 band_colours[8+1]
static
Initial value:
= {
RGB(31, 0, 0), RGB(31, 16, 0), RGB(31, 31, 0), RGB(0, 31, 0),
RGB(0, 31, 31), RGB(0, 12, 31), RGB(16, 0, 31), RGB(31, 0, 24),
RGB(4, 4, 8),
}
#define RGB(r, g, b)
Create RGB color value.
Definition video.h:88

Band colours (palette 0, colours 1..8) and the stripe colour 9.

◆ cardwords

u16 cardwords[32]
static

The test card's horizontal row: 8 on odd columns, 0 on even.

◆ maprow

u16 maprow[32]
static

One tilemap row being built.

◆ opt_card

u8 opt_card

◆ opt_vertical

u8 opt_vertical

◆ owords

u16 owords[32]
static

The offset words of the row that carries the wave.

◆ px

u8 px[64]
static

One 4bpp character's pixels and its encoding.

◆ tilebuf

u8 tilebuf[32]
static

◆ wave_phase

u16 wave_phase

Probe oracles: wave phase, 1 while the wave is vertical, 1 while the test card is shown.

◆ zwords

u16 zwords[32]
static

A row of zero words, for the row that does not.