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

Dynamic metasprite engine demo — multi-tile characters with VRAM streaming. More...

#include <snes.h>

Functions

void changeObjSize (void)
 Reinitialize sprite engine and upload all tiles during force blank.
 
void drawSprites (void)
 Draw metasprites for the current OBJSEL configuration.
 
void drawText (void)
 Draw the configuration menu text.
 
int main (void)
 Entry point.
 

Variables

static const MetaspriteItem hero16_frame0 []
 16x16 metasprite: 32x48 character (2x3 grid of 16x16)
 
static const MetaspriteItem hero32_frame0 []
 32x32 metasprite: 64x64 character (2x2 grid of 32x32)
 
static const MetaspriteItem hero8_frame0 []
 8x8 metasprite: 16x16 character (2x2 grid of 8x8)
 
u16 pad0
 
u16 selectedItem
 
u8 spritehero16_til []
 
u8 spritehero32_pal []
 
u8 spritehero32_til []
 
u8 spritehero8_til []
 

Detailed Description

Dynamic metasprite engine demo — multi-tile characters with VRAM streaming.

Demonstrates oamMetaDrawDyn(..., size_class): multi-tile sprite characters where each sub-sprite's tiles are streamed to VRAM on demand (dynamic sprite engine). The size_class parameter selects whether the metasprite uses the small or large half of the configured size pair. Three OBJSEL configurations are selectable via D-PAD:

  • Config 0: 8/16 — 16x16 metasprite (LARGE) + 8x8 metasprite (SMALL)
  • Config 1: 8/32 — 32x32 metasprite (LARGE) + 8x8 metasprite (SMALL)
  • Config 2: 16/32 — 32x32 metasprite (LARGE) + 16x16 metasprite (SMALL)

Ported from PVSnesLib DynamicEngineMetaSprite example.

SNES Concepts
  • Dynamic VRAM tile streaming for multi-tile sprite characters
  • MetaspriteItem arrays defining sub-sprite layout
  • OBJSEL size configuration (8/16, 8/32, 16/32)
  • oambuffer[] state management for metasprite sub-sprites
What to Observe
  • Two sprite characters visible on screen
  • D-PAD UP/DOWN switches between 3 OBJSEL configurations
  • Menu cursor ">" indicates current selection
  • Sprites change size when switching configurations
Modules Used
console, sprite, sprite_dynamic, sprite_dynamic_meta, sprite_lut, dma, background, text, input
See also
sprite.h

Function Documentation

◆ changeObjSize()

void changeObjSize ( void  )

Reinitialize sprite engine and upload all tiles during force blank.

Uses force blank for a glitch-free OBJSEL switch. The current configuration can enqueue >7 entries (config 2 hits 10), and the NMI auto-flush hook drains 7 per VBlank, so oamDynamicDrainQueue loops WaitForVBlank() until the queue is empty before we release force blank. NMI suppresses the end-frame "hide stale sprites" path during the drain so the just-queued sprites are not pushed off-screen.

◆ drawSprites()

static void drawSprites ( void  )

Draw metasprites for the current OBJSEL configuration.

Render metasprites using oamDrawMeta() for the current size mode.

oamDrawMeta() reads metasprite frame data (tile offsets + positions) and populates multiple OAM entries to compose a large character from smaller hardware sprite pieces. It returns the next available OAM ID, allowing multiple metasprites to be drawn without ID conflicts.

Each size mode uses a different combination of LARGE and SMALL sprites to render two characters: one larger (left) and one smaller (right).

< First tile of 16x16 sheet (192)

< First tile of 8x8 sheet (288)

< First tile of 32x32 sheet

< First tile of 8x8 sheet (288)

< First tile of 32x32 sheet

< First tile of 16x16 sheet (192)

◆ drawText()

void drawText ( void  )

Draw the configuration menu text.

◆ main()

int main ( void  )

Entry point.

Variable Documentation

◆ hero16_frame0

const MetaspriteItem hero16_frame0[]
static
Initial value:
= {
METASPR_ITEM(0, 0, 0, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(16, 0, 1, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(0, 16, 2, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(16, 16, 3, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(0, 32, 4, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(16, 32, 5, OBJ_PAL(0) | OBJ_PRIO(3)),
}
#define OBJ_PRIO(prio)
Metasprite priority attribute macro.
Definition sprite.h:479
#define METASPR_ITEM(dx, dy, tile, attr)
Metasprite item macro (PVSnesLib compatible)
Definition sprite.h:467
#define METASPR_TERM
End marker for metasprite data (dx = -128)
Definition sprite.h:470
#define OBJ_PAL(pal)
Metasprite palette attribute macro.
Definition sprite.h:476

16x16 metasprite: 32x48 character (2x3 grid of 16x16)

◆ hero32_frame0

const MetaspriteItem hero32_frame0[]
static
Initial value:
= {
METASPR_ITEM(0, 0, 0, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(32, 0, 1, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(0, 32, 6, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(32, 32, 7, OBJ_PAL(0) | OBJ_PRIO(3)),
}

32x32 metasprite: 64x64 character (2x2 grid of 32x32)

◆ hero8_frame0

const MetaspriteItem hero8_frame0[]
static
Initial value:
= {
METASPR_ITEM(0, 0, 0, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(8, 0, 1, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(0, 8, 8, OBJ_PAL(0) | OBJ_PRIO(3)),
METASPR_ITEM(8, 8, 9, OBJ_PAL(0) | OBJ_PRIO(3)),
}

8x8 metasprite: 16x16 character (2x2 grid of 8x8)

◆ pad0

u16 pad0

◆ selectedItem

u16 selectedItem

◆ spritehero16_til

u8 spritehero16_til[]
extern

◆ spritehero32_pal

u8 spritehero32_pal[]
extern

◆ spritehero32_til

u8 spritehero32_til[]
extern

◆ spritehero8_til

u8 spritehero8_til[]
extern