PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
maps/tiled/tiled.c
/*---------------------------------------------------------------------------------
map example with tiled conversion
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
// Graphics available outside the file
extern char tileset, tilesetend, tilesetpal; // for map & tileset of map
extern char mapkungfu, tilesetdef, tilesetatt;
u16 pad0; // pad variable
s16 mapscx; // camera x variable
u8 keyl, keyr; // to update move
//---------------------------------------------------------------------------------
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 * 3, BG_16COLORS, 0x2000);
bgSetMapPtr(0, 0x6800, SC_64x32);
// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
// Screen activated
// Load map in memory and update it regarding current location of the sprite
mapLoad((u8 *)&mapkungfu, (u8 *)&tilesetdef, (u8 *)&tilesetatt);
// generic playing loop
mapscx = 16 * 8; // middle of screen
keyl = keyr = 0;
while (1)
{
// Update the map regarding the camera
// Get pad and update camera regarding pad
pad0 = padsCurrent(0);
// go to the left & right
if (pad0 & KEY_LEFT)
{
if (mapscx > 16 * 8)
mapscx--;
}
if (pad0 & KEY_RIGHT)
{
if (mapscx < (208 * 8))
mapscx++;
}
// update camera regarding scrolling
mapUpdateCamera(mapscx, 0);
// 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.
#define padsCurrent(value)
Return current value of selected pad.
Definition: input.h:161
@ KEY_LEFT
pad LEFT button.
Definition: input.h:53
@ KEY_RIGHT
pad RIGHT button.
Definition: input.h:52
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)
the master include file for snes applications.
void setScreenOn(void)
Put screen On.
void setMode(u8 mode, u8 size)
Set the SNES hardware to operate in new display mode.