PVSnesLib  4.6.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_SIZEL 0
56#define OBJ_SIZES 1
57#define OBJ_PAL(palofs) (palofs << 1)
58#define OBJ_FLIPX (0x40)
59#define OBJ_FLIPY (0x80)
60#define OBJ_PRIO(prio) (prio << 4)
65typedef struct
66{
67 s16 oamx;
68 s16 oamy;
73 u16 dummy1;
74 u16 dummy2;
75} t_sprites; // __attribute__((__packed__)); /*!< seems to do nothing */
76
80typedef struct
81{
88 //u16 metsprend; /*!< 12..13 0xFFFF if it is the end of meta sprite definition */
89 //u16 dummy1; /*!< 14..15 to be 16 aligned */
90} t_metasprites; // __attribute__((__packed__)); /*!< seems to do nothing */
91
105typedef struct {
106 u16 dx, dy;
107 u16 dtile;
108 u8 props;
109 u8 unused; // to be sure to align on 16 bits
111
112#define metasprite_end -128
113#define METASPR_ITEM(dx,dy,dt,a) {(dx),(dy),(dt),(a)}
114#define METASPR_TERM {metasprite_end}
115
141extern t_sprites oambuffer[128];
148extern u8 oamMemory[128 * 4 + 8 * 4];
149
167#define REG_OBSEL (*(vuint8 *)0x2101)
168
187#define REG_OAMADDL (*(vuint8 *)0x2102)
188#define REG_OAMADDH (*(vuint8 *)0x2103)
189
190/*
191 1st Access: Lower 8bit (even address)
192 2nd Access: Upper 8bit (odd address)
193*/
194#define REG_OAMDATA (*(vuint8 *)0x2104)
195#define REG_RDOAM (*(vuint8 *)0x2138)
199void oamInit(void);
200
203void oamUpdate(void);
204
210void oamFlip(u16 id, u8 xf, u8 yf);
211
219void oamSetAttr(u16 id, u16 xspr, u16 yspr, u16 gfxoffset, u8 attr);
220
228#define OAM_ATTR(priority, hflip, vflip, gfxoffset, paletteoffset) ((vflip << 7) | (hflip << 6) | (priority << 4) | (paletteoffset << 1) | ((gfxoffset >> 8) & 1))
229
240void oamSet(u16 id, u16 xspr, u16 yspr, u8 priority, u8 hflip, u8 vflip, u16 gfxoffset, u8 paletteoffset);
241
247void oamSetXY(u16 id, u16 xspr, u16 yspr);
248
252#define oamGetX(id) (oamMemory[id + 0])
253
257#define oamGetY(id) (oamMemory[id + 1])
258
263void oamSetGfxOffset(u16 id, u16 gfxoffset);
264
270void oamSetEx(u16 id, u8 size, u8 hide);
271
278void oamSetVisible(u16 id, u8 hide);
279
284void oamClear(u16 first, u8 numEntries);
285
295void oamInitGfxSet(u8 *tileSource, u16 tileSize, u8 *tilePalette, u16 paletteSize, u8 tilePaletteNumber, u16 address, u8 oamsize);
296
301void oamInitGfxAttr(u16 address, u8 oamsize);
302
310void oamInitDynamicSprite(u16 gfxsp0adr, u16 gfxsp1adr, u16 oamsp0init, u16 oamsp1init, u8 oamsize);
311
315
319
323
327void oamDynamic32Draw(u16 id);
328
336void oamFix32Draw(u16 id);
337
341void oamDynamic16Draw(u16 id);
342
350void oamFix16Draw(u16 id);
351
355void oamDynamic8Draw(u16 id);
356
364void oamFix8Draw(u16 id);
365
375void oamDynamicMetaDraw(u16 id, s16 x, s16 y, u8 *sprmeta);
376
388void oamMetaDrawDyn32(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr);
389
402void oamMetaDraw32(u16 id, s16 x,s16 y, u8 *sprmeta, u16 ofsgfx);
403
415void oamMetaDrawDyn16(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr, u16 sprsize);
416
429void oamMetaDraw16(u16 id, s16 x,s16 y, u8 *sprmeta,u16 sprsize, u16 ofsgfx);
430
442void oamMetaDrawDyn8(u16 id, s16 x,s16 y, u8 *sprmeta,u8 *gfxptr);
443
456void oamMetaDraw8(u16 id, s16 x,s16 y, u8 *sprmeta, u16 ofsgfx);
457
458#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:105
Dynamic metasprite definition (16 bytes)
Definition sprite.h:81
s16 metsprofsx
Definition sprite.h:82
s16 metsprofsy
Definition sprite.h:83
u8 metsprattribute
Definition sprite.h:85
u8 * metsprgraphics
Definition sprite.h:87
u8 metsprtype
Definition sprite.h:86
u16 metsprframeid
Definition sprite.h:84
Dynamic sprite definition (16 bytes)
Definition sprite.h:66
u16 oamframeid
4 frame index in graphic file of the sprite
Definition sprite.h:69
s16 oamx
0 x position on the screen
Definition sprite.h:67
u8 * oamgraphics
8..11 pointer to graphic file
Definition sprite.h:72
s16 oamy
2 y position on the screen
Definition sprite.h:68
u8 oamattribute
6 sprite attribute value (vhoopppc v : vertical flip h: horizontal flip o: priority bits p: palette n...
Definition sprite.h:70
u8 oamrefresh
7 =1 if we need to load graphics from graphic file
Definition sprite.h:71
u16 dummy1
12..15 to be 16 aligned
Definition sprite.h:73