PVSnesLib  4.5.0
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
sprite.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------------------
2
3 sprite.h -- definitions for SNES sprites
4
5 Copyright (C) 2012-2025
6 Alekmaul
7
8 This software is provided 'as-is', without any express or implied
9 warranty. In no event will the authors be held liable for any
10 damages arising from the use of this software.
11
12 Permission is granted to anyone to use this software for any
13 purpose, including commercial applications, and to alter it and
14 redistribute it freely, subject to the following restrictions:
15
16 1. The origin of this software must not be misrepresented; you
17 must not claim that you wrote the original software. If you use
18 this software in a product, an acknowledgment in the product
19 documentation would be appreciated but is not required.
20
21 2. Altered source versions must be plainly marked as such, and
22 must not be misrepresented as being the original software.
23
24 3. This notice may not be removed or altered from any source
25 distribution.
26
27---------------------------------------------------------------------------------*/
32#ifndef SNES_SPRITES_INCLUDE
33#define SNES_SPRITES_INCLUDE
34
35#include <snes/snestypes.h>
36
37#define ATTR2_DISABLED (0xe8)
38
39#define OBJ_SIZE8_L16 (0 << 5)
40#define OBJ_SIZE8_L32 (1 << 5)
41#define OBJ_SIZE8_L64 (2 << 5)
42#define OBJ_SIZE16_L32 (3 << 5)
43#define OBJ_SIZE16_L64 (4 << 5)
44#define OBJ_SIZE32_L64 (5 << 5)
46#define OBJ_SMALL (0)
47#define OBJ_LARGE (1)
48#define OBJ_SHOW (0)
49#define OBJ_HIDE (1)
50
51#define OBJ_SPRITE32 1
52#define OBJ_SPRITE16 2
53#define OBJ_SPRITE8 4
55#define OBJ_PAL(palofs) (palofs << 1)
56#define OBJ_FLIPX (0x40)
57#define OBJ_FLIPY (0x80)
58#define OBJ_PRIO(prio) (prio << 4)
63typedef struct
64{
65 s16 oamx;
66 s16 oamy;
71 u16 dummy1;
72 u16 dummy2;
73} t_sprites __attribute__((__packed__));
78typedef struct
79{
86 //u16 metsprend; /*!< 12..13 0xFFFF if it is the end of meta sprite definition */
87 //u16 dummy1; /*!< 14..15 to be 16 aligned */
88} t_metasprites __attribute__((__packed__));
103typedef struct {
104 u16 dx, dy;
105 u16 dtile;
106 u8 props;
107 u8 unused; // to be sure to align on 16 bits
109
110#define metasprite_end -128
111#define METASPR_ITEM(dx,dy,dt,a) {(dx),(dy),(dt),(a)}
112#define METASPR_TERM {metasprite_end}
113
139extern t_sprites oambuffer[128];
146extern u8 oamMemory[128 * 4 + 8 * 4];
147
165#define REG_OBSEL (*(vuint8 *)0x2101)
166
185#define REG_OAMADDL (*(vuint8 *)0x2102)
186#define REG_OAMADDH (*(vuint8 *)0x2103)
187
188/*
189 1st Access: Lower 8bit (even address)
190 2nd Access: Upper 8bit (odd address)
191*/
192#define REG_OAMDATA (*(vuint8 *)0x2104)
193#define REG_RDOAM (*(vuint8 *)0x2138)
197void oamInit(void);
198
201void oamUpdate(void);
202
208void oamFlip(u16 id, u8 xf, u8 yf);
209
217void oamSetAttr(u16 id, u16 xspr, u16 yspr, u16 gfxoffset, u8 attr);
218
226#define OAM_ATTR(priority, hflip, vflip, gfxoffset, paletteoffset) ((vflip << 7) | (hflip << 6) | (priority << 4) | (paletteoffset << 1) | ((gfxoffset >> 8) & 1))
227
238void oamSet(u16 id, u16 xspr, u16 yspr, u8 priority, u8 hflip, u8 vflip, u16 gfxoffset, u8 paletteoffset);
239
245void oamSetXY(u16 id, u16 xspr, u16 yspr);
246
250#define oamGetX(id) (oamMemory[id + 0])
251
255#define oamGetY(id) (oamMemory[id + 1])
256
261void oamSetGfxOffset(u16 id, u16 gfxoffset);
262
268void oamSetEx(u16 id, u8 size, u8 hide);
269
276void oamSetVisible(u16 id, u8 hide);
277
282void oamClear(u16 first, u8 numEntries);
283
293void oamInitGfxSet(u8 *tileSource, u16 tileSize, u8 *tilePalette, u16 paletteSize, u8 tilePaletteNumber, u16 address, u8 oamsize);
294
299void oamInitGfxAttr(u16 address, u8 oamsize);
300
308void oamInitDynamicSprite(u16 gfxsp0adr, u16 gfxsp1adr, u16 oamsp0init, u16 oamsp1init, u8 oamsize);
309
313
317
321
325void oamDynamic32Draw(u16 id);
326
334void oamFix32Draw(u16 id);
335
339void oamDynamic16Draw(u16 id);
340
348void oamFix16Draw(u16 id);
349
353void oamDynamic8Draw(u16 id);
354
362void oamFix8Draw(u16 id);
363
373void oamDynamicMetaDraw(u16 id, s16 x, s16 y, u8 *sprmeta);
374
386void oamMetaDrawDyn32(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr);
387
400void oamMetaDraw32(u16 id, s16 x,s16 y, u8 *sprmeta, u16 ofsgfx);
401
413void oamMetaDrawDyn16(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr, u16 sprsize);
414
427void oamMetaDraw16(u16 id, s16 x,s16 y, u8 *sprmeta,u16 sprsize, u16 ofsgfx);
428
440void oamMetaDrawDyn8(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr);
441
454void oamMetaDraw8(u16 id, s16 x,s16 y, u8 *sprmeta, u16 ofsgfx);
455
456#endif // SNES_SPRITES_INCLUDE
Custom types used by libsnes.
void oamFix32Draw(u16 id)
Add a 32x32 sprite on screen. oambuffer[id] needs to be populate before. !
void oamClear(u16 first, u8 numEntries)
Hides the sprites in the supplied range: if count is zero all 128 sprites will be hidden.
t_sprites oambuffer[128]
Sprite Table (from no$sns help file) Contains data for 128 OBJs. OAM Size is 512+32 Bytes....
void oamInit(void)
Initializes the 2D sprite engine.
void oamMetaDrawDyn16(u16 id, s16 x, s16 y, u8 *sprmeta, u8 *gfxptr, u16 sprsize)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamSetVisible(u16 id, u8 hide)
Hide or show a sprite.
void oamSetEx(u16 id, u8 size, u8 hide)
Put the correct size and hide or show a sprite.
void oamInitGfxSet(u8 *tileSource, u16 tileSize, u8 *tilePalette, u16 paletteSize, u8 tilePaletteNumber, u16 address, u8 oamsize)
Initializes a sprites Gfx and Loads the GFX into VRAM.
void oamSetXY(u16 id, u16 xspr, u16 yspr)
sets an oam coordinate to the supplied values
void oamVramQueueUpdate(void)
Update VRAM graphics for sprites 32x32, 16x16 and 8x8 (can but call in Vblank if needed).
void oamDynamic8Draw(u16 id)
Add a 8x8 sprite on screen. oambuffer[id] needs to be populate before.
void oamInitDynamicSpriteScreen(void)
Init Dynamic sprite engine on a screen (can be useful if you do not want to refresh sprite each frame...
void oamMetaDrawDyn8(u16 id, s16 x, s16 y, u8 *sprmeta, u8 *gfxptr)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamDynamicMetaDraw(u16 id, s16 x, s16 y, u8 *sprmeta)
Add a Meta sprite on screen (can be composed of 8x8,16x16 or 32x32 sprites). oambuffer[id] needs to b...
u8 oamMemory[128 *4+8 *4]
to address oam table low and high
void oamUpdate(void)
Write all OBJ descriptors to OAM.
void oamSetAttr(u16 id, u16 xspr, u16 yspr, u16 gfxoffset, u8 attr)
sets an oam entry to the supplied values
void oamMetaDraw16(u16 id, s16 x, s16 y, u8 *sprmeta, u16 sprsize, u16 ofsgfx)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamSetGfxOffset(u16 id, u16 gfxoffset)
sets an oam graphic offset to the supplied values
void oamSet(u16 id, u16 xspr, u16 yspr, u8 priority, u8 hflip, u8 vflip, u16 gfxoffset, u8 paletteoffset)
sets an oam entry to the supplied values
void oamFix16Draw(u16 id)
Add a 16x16 sprite on screen. oambuffer[id] needs to be populate before. !
void oamMetaDraw32(u16 id, s16 x, s16 y, u8 *sprmeta, u16 ofsgfx)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamInitDynamicSpriteEndFrame(void)
Must be call at the end of the frame, initialize the dynamic sprite engine for the next frame.
void oamMetaDraw8(u16 id, s16 x, s16 y, u8 *sprmeta, u16 ofsgfx)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamInitGfxAttr(u16 address, u8 oamsize)
Initializes the default sprite size and address in VRAM.
void oamInitDynamicSprite(u16 gfxsp0adr, u16 gfxsp1adr, u16 oamsp0init, u16 oamsp1init, u8 oamsize)
initialize the dynamic sprite engine with each sprite size entries
void oamFix8Draw(u16 id)
Add a 8x8 sprite on screen. oambuffer[id] needs to be populate before. !
void oamDynamic16Draw(u16 id)
Add a 16x16 sprite on screen. oambuffer[id] needs to be populate before.
void oamMetaDrawDyn32(u16 id, s16 x, s16 y, u8 *sprmeta, u8 *gfxptr)
Add a Meta sprite on screen (can be composed only of 16x16 sprites). oambuffer[id] needs to be popula...
void oamFlip(u16 id, u8 xf, u8 yf)
sets an oam entry to the supplied values
void oamDynamic32Draw(u16 id)
Add a 32x32 sprite on screen. oambuffer[id] needs to be populate before.
Definition sprite.h:103
Dynamic metasprite definition (16 bytes)
Definition sprite.h:79
s16 metsprofsx
Definition sprite.h:80
s16 metsprofsy
Definition sprite.h:81
u8 metsprattribute
Definition sprite.h:83
u8 * metsprgraphics
Definition sprite.h:85
u8 metsprtype
Definition sprite.h:84
u16 metsprframeid
Definition sprite.h:82
Dynamic sprite definition (16 bytes)
Definition sprite.h:64
u16 oamframeid
4 frame index in graphic file of the sprite
Definition sprite.h:67
s16 oamx
0 x position on the screen
Definition sprite.h:65
u8 * oamgraphics
8..11 pointer to graphic file
Definition sprite.h:70
s16 oamy
2 y position on the screen
Definition sprite.h:66
u8 oamattribute
6 sprite attribute value (vhoopppc v : vertical flip h: horizontal flip o: priority bits p: palette n...
Definition sprite.h:68
u8 oamrefresh
7 =1 if we need to load graphics from graphic file
Definition sprite.h:69
u16 dummy1
12..15 to be 16 aligned
Definition sprite.h:71