PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
graphics/Backgrounds/Mode1Scroll/Mode1Scroll.c
/*---------------------------------------------------------------------------------
Simple tile mode 1 with scrolling demo
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
extern char patterns, patterns_end;
extern char palette;
extern char map, map_end;
extern char snesfont, snespal;
//---------------------------------------------------------------------------------
int main(void)
{
u16 scrX = 0, scrY = 0;
u16 pad0, move;
// Initialize SNES
// Initialize text console with our font
consoleInitText(0, 16 * 2, &snesfont, &snespal);
// Copy tiles to VRAM
bgInitTileSet(1, &patterns, &palette, 0, (&patterns_end - &patterns), 16 * 2, BG_16COLORS, 0x4000);
// Copy Map to VRAM
bgInitMapSet(1, &map, (&map_end - &map), SC_64x64, 0x1000);
// Init background
bgSetGfxPtr(0, 0x2000);
bgSetMapPtr(0, 0x6800, SC_32x32);
// Now Put in 16 color mode and disable last BG
setMode(BG_MODE1, 0);
// Wait for nothing :P
while (1)
{
// no move currently
move = 0;
// Refresh pad values
// Get current #0 pad
pad0 = padsCurrent(0);
// Update scrolling with current pad
switch (pad0)
{
case KEY_RIGHT:
scrX += 2;
move = 1;
break;
case KEY_LEFT:
scrX -= 2;
move = 1;
break;
case KEY_DOWN:
scrY += 2;
move = 1;
break;
case KEY_UP:
scrY -= 2;
move = 1;
break;
}
if (move)
bgSetScroll(1, scrX, scrY);
// Just inform user
consoleDrawText(0, 0, "SCR X=%d Y=%d", scrX, scrY);
}
return 0;
}
void bgSetGfxPtr(u8 bgNumber, u16 address)
Definition of each background address.
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 bgSetScroll(u8 bgNumber, u16 x, u16 y)
Sets the scroll hardware to the specified location.
void bgInitMapSet(u8 bgNumber, u8 *mapSource, u16 mapSize, u8 sizeMode, u16 address)
Initializes a Map Set and loads it into SNES VRAM.
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 consoleSetTextVramAdr(u16 vramfont)
Change text graphics address (4K aligned)
void consoleInitText(u8 palnum, u8 palsize, u8 *tilfont, u8 *palfont)
Initialize the Text System.
void consoleInit(void)
Initialize console.
void consoleDrawText(u16 x, u16 y, char *fmt,...)
Output formatted string on a screen (tiles mode)
void consoleSetTextOffset(u16 offsetfont)
Change text Background map address for display (must be BG address)
void consoleSetTextVramBGAdr(u16 offsetfont)
Change text Background map address for display (must be BG address)
void scanPads(void)
Wait for pad ready and read pad values in.
#define padsCurrent(value)
Return current value of selected pad.
Definition: input.h:161
@ KEY_UP
pad UP button.
Definition: input.h:55
@ KEY_LEFT
pad LEFT button.
Definition: input.h:53
@ KEY_RIGHT
pad RIGHT button.
Definition: input.h:52
@ KEY_DOWN
pad DOWN button.
Definition: input.h:54
void WaitForVBlank(void)
Wait for vblank interrupt
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.