Loading...
Searching...
No Matches
main.c File Reference

Interactive demo of all six SNES OBJ size modes. More...

#include <snes.h>

Macros

#define ADRSPRITE   0x4100
 VRAM word address where the "small" sprite tiles are loaded.
 
#define ADRSPRITLARGE   0x4500
 VRAM word address where the "large" sprite tiles are loaded.
 
#define PALETTESPRSIZE   PALETTE_16_SIZE
 Size of one 16-color sprite palette in bytes (16 colors x 2 bytes)
 
#define TILE_LARGE   0x0050
 OAM tile number for the large sprite, relative to OBJSEL name base $4000.
 
#define TILE_SMALL   0x0010
 OAM tile number for the small sprite, relative to OBJSEL name base $4000.
 

Functions

static void changeObjSize (void)
 Load sprite tiles for the selected size mode under force blank.
 
static void drawCursor (void)
 Draw the selection cursor next to the currently selected menu item.
 
int main (void)
 Entry point: interactive demo of all six SNES OBJ size modes.
 

Variables

u8 palsprite16 []
 Palette for the 16x16 sprite.
 
u8 palsprite16_end []
 
u8 palsprite32 []
 Palette for the 32x32 sprite.
 
u8 palsprite32_end []
 
u8 palsprite64 []
 Palette for the 64x64 sprite.
 
u8 palsprite64_end []
 
u8 palsprite8 []
 Palette for the 8x8 sprite.
 
u8 palsprite8_end []
 
u16 selectedItem
 Currently selected OBJ size mode index (0-5), controlled by UP/DOWN.
 
u8 sprite16 []
 16x16 sprite tile data
 
u8 sprite16_end []
 
u8 sprite32 []
 32x32 sprite tile data
 
u8 sprite32_end []
 
u8 sprite64 []
 64x64 sprite tile data
 
u8 sprite64_end []
 
u8 sprite8 []
 8x8 sprite tile data (defined in data.asm)
 
u8 sprite8_end []
 

Detailed Description

Interactive demo of all six SNES OBJ size modes.

The SNES PPU supports six sprite size combinations, configured globally via the OBJSEL register ($2101, bits 7-5). Each mode defines a "small" and "large" size that all 128 OAM entries share. Individual sprites select small or large via bit 1 of their OAM high-table entry.

This example provides a text menu (UP/DOWN to navigate) that cycles through all six modes: 8/16, 8/32, 8/64, 16/32, 16/64, 32/64. Each selection reloads the appropriate sprite tiles via DMA under force blank (large sprites like 64x64 exceed the ~4KB VBlank DMA budget) and displays one small and one large sprite side by side.

Based on PVSnesLib ObjectSize example.

SNES Concepts
  • OBJSEL register ($2101): 6 size modes (bits 7-5) and name base (bits 1-0)
  • OAM high table size bit: selects small or large per sprite
  • Force blank for large VRAM transfers that exceed VBlank DMA budget
  • Sprite tile numbering relative to the OBJSEL name base address
What to Observe
  • A text menu listing all 6 size combinations with a cursor
  • Press UP/DOWN to select a mode
  • One small sprite (left) and one large sprite (right) are shown
  • Notice how the same tile data renders at different pixel sizes
Modules Used
console, sprite, dma, text, text4bpp, input, background
See also
sprite.h, dma.h, input.h, video.h

Macro Definition Documentation

◆ ADRSPRITE

#define ADRSPRITE   0x4100

VRAM word address where the "small" sprite tiles are loaded.

Placed at $4100 (offset $100 from name base $4000), giving tile number $0010 = ($4100 - $4000) / 16. The offset from the name base determines the OAM tile number used to reference these tiles.

◆ ADRSPRITLARGE

#define ADRSPRITLARGE   0x4500

VRAM word address where the "large" sprite tiles are loaded.

At $4500 (tile number $0050 from name base $4000). Placed after the small sprite tiles to avoid VRAM overlap.

◆ PALETTESPRSIZE

#define PALETTESPRSIZE   PALETTE_16_SIZE

Size of one 16-color sprite palette in bytes (16 colors x 2 bytes)

◆ TILE_LARGE

#define TILE_LARGE   0x0050

OAM tile number for the large sprite, relative to OBJSEL name base $4000.

Tile number = ($4500 - $4000) / 16 = 0x50.

◆ TILE_SMALL

#define TILE_SMALL   0x0010

OAM tile number for the small sprite, relative to OBJSEL name base $4000.

Tile number = (VRAM_address - name_base) / 16 = ($4100 - $4000) / 16 = 0x10. The divisor of 16 is because each tile occupies 16 VRAM words (32 bytes for 4bpp).

Function Documentation

◆ changeObjSize()

static void changeObjSize ( void  )
static

Load sprite tiles for the selected size mode under force blank.

Force blank (INIDISP bit 7 = 1) disables rendering, giving unlimited time for VRAM writes. This is necessary because large sprites (32x32, 64x64) require more than the ~4KB VBlank DMA budget to transfer.

For each mode, the small sprite tiles are loaded with oamInitGfxSet() (which also sets OBJSEL) and the large sprite tiles are loaded separately via dmaCopyVram(). Each size uses a different palette loaded to CGRAM address 128+16 (sprite palette slot 1).

After loading, two OAM entries are configured: one small sprite on the left and one large sprite on the right.

◆ drawCursor()

static void drawCursor ( void  )
static

Draw the selection cursor next to the currently selected menu item.

Places a ">" character at the selected row and a space at all others. The tilemap is auto-flushed by the NMI handler during the next VBlank.

◆ main()

int main ( void  )

Entry point: interactive demo of all six SNES OBJ size modes.

Displays a text menu listing the six OBJSEL size combinations (8/16, 8/32, 8/64, 16/32, 16/64, 32/64). The user navigates with UP/DOWN to switch modes, which triggers a force-blank reload of the appropriate sprite tiles.

Returns
Never returns (infinite loop).

Variable Documentation

◆ palsprite16

u8 palsprite16[]
extern

Palette for the 16x16 sprite.

◆ palsprite16_end

u8 palsprite16_end[]

◆ palsprite32

u8 palsprite32[]
extern

Palette for the 32x32 sprite.

◆ palsprite32_end

u8 palsprite32_end[]

◆ palsprite64

u8 palsprite64[]
extern

Palette for the 64x64 sprite.

◆ palsprite64_end

u8 palsprite64_end[]

◆ palsprite8

u8 palsprite8[]
extern

Palette for the 8x8 sprite.

◆ palsprite8_end

u8 palsprite8_end[]

◆ selectedItem

u16 selectedItem

Currently selected OBJ size mode index (0-5), controlled by UP/DOWN.

◆ sprite16

u8 sprite16[]
extern

16x16 sprite tile data

◆ sprite16_end

u8 sprite16_end[]

◆ sprite32

u8 sprite32[]
extern

32x32 sprite tile data

◆ sprite32_end

u8 sprite32_end[]

◆ sprite64

u8 sprite64[]
extern

64x64 sprite tile data

◆ sprite64_end

u8 sprite64_end[]

◆ sprite8

u8 sprite8[]
extern

8x8 sprite tile data (defined in data.asm)

◆ sprite8_end

u8 sprite8_end[]