PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
objects/nogravityobject/nogravityobjects.c
/*---------------------------------------------------------------------------------
map & object example scrolling with object engine and no gravity variables
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
// Includes to have object prototypes
#include "link.h"
// Graphics available outside the file
extern char tileset, tilesetend, tilepal, pallink, tilesetdef, tilesetatt; // for map & tileset of map
extern char sprlink, sprlink_end, pallink; // for link sprite
extern char mapzelda, objzelda;
u16 sprnum; // to manage update of each sprite on screen
//---------------------------------------------------------------------------------
int main(void)
{
// Initialize SNES
// Init layer with tiles and init also map length 0x6800 is mandatory for map engine
bgInitTileSet(0, &tileset, &tilepal, 0, (&tilesetend - &tileset), 16 * 2, BG_16COLORS, 0x2000);
bgSetMapPtr(0, 0x6800, SC_64x32);
// Init Sprites palette
setPalette(&pallink, 128 + 0 * 16, 16 * 2);
// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
// Init sprite engine (0x0000 for large, 0x1000 for small)
oamInitDynamicSprite(0x0000, 0x1000, 0, 0, OBJ_SIZE8_L16);
// Object engine activate
// Init function for state machine
objInitFunctions(0, &linkinit, &linkupdate, NULL);
// Load all objects into memory
objLoadObjects((char *)&objzelda);
// Load map in memory and update it regarding current location of the sprite
mapLoad((u8 *)&mapzelda, (u8 *)&tilesetdef, (u8 *)&tilesetatt);
// Screen activated
// generic playing loop
while (1)
{
// Update the map regarding the camera
mapUpdateCamera(*linkox, *linkoy);
// Update all the available objects
// prepare next frame and wait vblank
}
return 0;
}
void bgSetDisable(u8 bgNumber)
Disable a BG in the actual SNES mode.
void bgSetMapPtr(u8 bgNumber, u16 address, u8 mapSize)
Change Background Map address.
void bgInitTileSet(u8 bgNumber, u8 *tileSource, u8 *tilePalette, u8 paletteEntry, u16 tileSize, u16 paletteSize, u16 colorMode, u16 address)
Initializes a Tile Set and Loads the Tile GFX into VRAM.
void consoleInit(void)
Initialize console.
void WaitForVBlank(void)
Wait for vblank interrupt
void mapVblank(void)
Display map regarding current buffer (must be done once per frame, near Vblank)
void mapUpdate(void)
Update map regarding current camera position (must be done once per frame)
void mapLoad(u8 *layer1map, u8 *layertiles, u8 *tilesprop)
Load map definition into memory.
void mapUpdateCamera(u16 xpos, u16 ypos)
Update map camera (must be done once per frame)
void objInitFunctions(u8 objtype, void *initfct, void *updfct, void *reffct)
Initialize the object type functions (initialize, update)
void objUpdateAll(void)
call update function for all objects currently active (if they are in "virtual screen" coordinates).
void objInitEngine(void)
Initialize object engine, need to be called once.
void objLoadObjects(u8 *sourceO)
Load all objects for a specific table in memory.
the master include file for snes applications.
void oamVramQueueUpdate(void)
Update VRAM graphics for sprites 32x32, 16x16 and 8x8 (can but call in Vblank if needed).
#define OBJ_SIZE8_L16
default OAM size 8x8 (SM) and 16x16 (LG) pix for OBJSEL register
Definition: sprite.h:39
void oamInitDynamicSpriteEndFrame(void)
Must be call at the end of the frame, initialize the dynamic sprite engine for the next frame.
void oamInitDynamicSprite(u16 gfxsp0adr, u16 gfxsp1adr, u16 oamsp0init, u16 oamsp1init, u8 oamsize)
initialize the dynamic sprite engine with each sprite size entries
void setScreenOn(void)
Put screen On.
#define setPalette(palette, paletteEntry, paletteSize)
Change a palette in CGRAM.
Definition: video.h:388
void setMode(u8 mode, u8 size)
Set the SNES hardware to operate in new display mode.