PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
graphics/Effects/ParallaxScrolling/ParallaxScrolling.c
/*---------------------------------------------------------------------------------
Simple parallax scrolling effect demo
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
extern char back, back_end;
extern char palette;
extern char map;
//---------------------------------------------------------------------------------
int main(void)
{
// Initialize SNES
// Read tiles to VRAM
bgInitTileSet(0, &back, &palette, 0, (&back_end - &back), 16 * 2 * 2, BG_16COLORS, 0x1000);
// Copy Map to VRAM
bgInitMapSet(0, &map, 64 * 32 * 2, SC_64x32, 0x0000);
// Now Put in 16 color mode and disable other BGs except 1st one
setMode(BG_MODE1, 0);
// Init HDMA table
// 72 lines with 1 scrolling effect (top of screen)
// Next 88 lines with 2 scrolling effect (middle of screen)
// Next 64 lines with 4 scrolling effect (end of screen)
HDMATable16[0] = 72;
*(u16 *)&(HDMATable16 + 1) = 1;
HDMATable16[3] = 88;
*(u16 *)&(HDMATable16 + 4) = 2;
HDMATable16[6] = 64;
*(u16 *)&(HDMATable16 + 7) = 4;
HDMATable16[9] = 0x00; // end of hdma table
// Wait for key to change gradient
while (1)
{
// Update scrolling
// Change scrolling inside HDMA table
*(u16 *)&(HDMATable16 + 1) += 1;
*(u16 *)&(HDMATable16 + 4) += 2;
*(u16 *)&(HDMATable16 + 7) += 4;
}
return 0;
}
void bgSetDisable(u8 bgNumber)
Disable a BG in the actual SNES mode.
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 consoleInit(void)
Initialize console.
void setParallaxScrolling(u8 bgrnd)
Do a parallax scrolling effect on screen. Use HDMA Channels 3.
u8 HDMATable16[224+1]
HDMA table accessible to change values.
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.