PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
objects/mapandobjects/mapandobjects.c
/*---------------------------------------------------------------------------------
map example scrolling with object engine
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
// Includes to have object prototypes
#include "mario.h"
#include "goomba.h"
#include "koopatroopa.h"
// Graphics available outside the file
extern char tileset, tilesetend, tilesetpal,tilesetdef, tilesetatt; // for map & tileset of map
extern char mapmario, objmario;
extern char palsprite; // for all sprites
u16 nbobjects; // to init more than sprite object in map
//---------------------------------------------------------------------------------
int main(void)
{
// Initialize SNES
// Init layer with tiles and init also map length 0x6800 is mandatory for map engine
bgInitTileSet(0, &tileset, &tilesetpal, 0, (&tilesetend - &tileset), 16 * 2, BG_16COLORS, 0x2000);
bgSetMapPtr(0, 0x6800, SC_64x32);
// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
// Init Sprites palette
setPalette(&palsprite, 128 + 0 * 16, 16 * 2);
// 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
nbobjects=1; // mario is always number 0
objInitFunctions(0, &marioinit, &marioupdate, NULL);
objInitFunctions(1, &goombainit, &goombaupdate, NULL);
objInitFunctions(2, &koopatroopainit, &koopatroopaupdate, NULL);
// Load all objects into memory
objLoadObjects((char *)&objmario);
// Load map in memory and update it regarding current location of the sprite
mapLoad((u8 *)&mapmario, (u8 *)&tilesetdef, (u8 *)&tilesetatt);
// Screen activated
// generic playing loop
while (1)
{
// Update the map regarding the camera
// Update all the available objects
// Wait vblank and display map on screen
}
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 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.