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 [] |
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.
| #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.
| #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.
| #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.
Tile number = ($4500 - $4000) / 16 = 0x50.
| #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).
|
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.
|
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.
| 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.
|
extern |
Palette for the 16x16 sprite.
| u8 palsprite16_end[] |
|
extern |
Palette for the 32x32 sprite.
| u8 palsprite32_end[] |
|
extern |
Palette for the 64x64 sprite.
| u8 palsprite64_end[] |
|
extern |
Palette for the 8x8 sprite.
| u8 palsprite8_end[] |
| u16 selectedItem |
Currently selected OBJ size mode index (0-5), controlled by UP/DOWN.
|
extern |
16x16 sprite tile data
| u8 sprite16_end[] |
|
extern |
32x32 sprite tile data
| u8 sprite32_end[] |
|
extern |
64x64 sprite tile data
| u8 sprite64_end[] |
|
extern |
8x8 sprite tile data (defined in data.asm)
| u8 sprite8_end[] |