PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
sprite.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------
2 
3  sprite.h -- definitions for SNES sprites
4 
5  Copyright (C) 2012-2024
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
58 typedef struct
59 {
60  s16 oamx;
61  s16 oamy;
62  u16 oamframeid;
66  u16 dummy1;
67  u16 dummy2;
68 } t_sprites __attribute__((__packed__));
73 typedef struct
74 {
75  s16 metsprofsx;
76  s16 metsprofsy;
81  u16 metsprend;
82  u16 dummy1;
83 } t_metasprites __attribute__((__packed__));
110 extern t_sprites oambuffer[128];
112 extern u8 oamMemory[128 * 4 + 8 * 4];
131 #define REG_OBSEL (*(vuint8 *)0x2101)
132 
151 #define REG_OAMADDL (*(vuint8 *)0x2102)
152 #define REG_OAMADDH (*(vuint8 *)0x2103)
153 
154 /*
155  1st Access: Lower 8bit (even address)
156  2nd Access: Upper 8bit (odd address)
157 */
158 #define REG_OAMDATA (*(vuint8 *)0x2104)
159 #define REG_RDOAM (*(vuint8 *)0x2138)
163 void oamInit(void);
164 
167 void oamUpdate(void);
168 
174 void oamFlip(u16 id, u8 xf, u8 yf);
175 
183 void oamSetAttr(u16 id, u16 xspr, u16 yspr, u16 gfxoffset, u8 attr);
184 
192 #define OAM_ATTR(priority, hflip, vflip, gfxoffset, paletteoffset) ((vflip << 7) | (hflip << 6) | (priority << 4) | (paletteoffset << 1) | ((gfxoffset >> 8) & 1))
193 
204 void oamSet(u16 id, u16 xspr, u16 yspr, u8 priority, u8 hflip, u8 vflip, u16 gfxoffset, u8 paletteoffset);
205 
211 void oamSetXY(u16 id, u16 xspr, u16 yspr);
212 
216 #define oamGetX(id) (oamMemory[id + 0])
217 
221 #define oamGetY(id) (oamMemory[id + 1])
222 
227 void oamSetGfxOffset(u16 id, u16 gfxoffset);
228 
234 void oamSetEx(u16 id, u8 size, u8 hide);
235 
242 void oamSetVisible(u16 id, u8 hide);
243 
248 void oamClear(u16 first, u8 numEntries);
249 
259 void oamInitGfxSet(u8 *tileSource, u16 tileSize, u8 *tilePalette, u16 paletteSize, u8 tilePaletteNumber, u16 address, u8 oamsize);
260 
265 void oamInitGfxAttr(u16 address, u8 oamsize);
266 
274 void oamInitDynamicSprite(u16 gfxsp0adr, u16 gfxsp1adr, u16 oamsp0init, u16 oamsp1init, u8 oamsize);
275 
279 
283 
287 
291 void oamDynamic32Draw(u16 id);
292 
300 void oamFix32Draw(u16 id);
301 
305 void oamDynamic16Draw(u16 id);
306 
314 void oamFix16Draw(u16 id);
315 
319 void oamDynamic8Draw(u16 id);
320 
328 void oamFix8Draw(u16 id);
329 
339 void oamDynamicMetaDraw(u16 id, s16 x, s16 y, u8 *sprmeta);
340 
341 #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 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 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 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 oamInitDynamicSpriteEndFrame(void)
Must be call at the end of the frame, initialize the dynamic sprite engine for the next frame.
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 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.
Dynamic metasprite definition (16 bytes)
Definition: sprite.h:74
u16 dummy1
Definition: sprite.h:82
s16 metsprofsx
Definition: sprite.h:75
s16 metsprofsy
Definition: sprite.h:76
u8 metsprattribute
Definition: sprite.h:78
u8 * metsprgraphics
Definition: sprite.h:80
u8 metsprtype
Definition: sprite.h:79
u16 metsprframeid
Definition: sprite.h:77
u16 metsprend
Definition: sprite.h:81
Dynamic sprite definition (16 bytes)
Definition: sprite.h:59
u16 oamframeid
4 frame index in graphic file of the sprite
Definition: sprite.h:62
s16 oamx
0 x position on the screen
Definition: sprite.h:60
u8 * oamgraphics
8..11 pointer to graphic file
Definition: sprite.h:65
s16 oamy
2 y position on the screen
Definition: sprite.h:61
u8 oamattribute
6 sprite attribute value (vhoopppc v : vertical flip h: horizontal flip o: priority bits p: palette n...
Definition: sprite.h:63
u8 oamrefresh
7 =1 if we need to load graphics from graphic file
Definition: sprite.h:64
u16 dummy1
12..15 to be 16 aligned
Definition: sprite.h:66