PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
graphics/Effects/Window/Window.c
/*---------------------------------------------------------------------------------
Simple window effect in mode 1
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
#include <string.h>
extern char patternsbg1, patternsbg1_end;
extern char patternsbg2, patternsbg2_end;
extern char palettebg1, palettebg1_end;
extern char palettebg2, palettebg2_end;
extern char mapbg1, mapbg1_end;
extern char mapbg2, mapbg2_end;
u8 pada,padb,padx;
u16 pad0;
// NOTE, if the # of scanlines has the upper bit $80 set
// it indicates a number of single scanline waits
const u8 tablelefttriangle[]=
{
60, 0xff, // if left is > right, it won't show.
0x80 | 64, // 64 lines of single entries
0x7f,0x7e,0x7d,0x7c,0x7b,0x7a,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,0x71,0x70,
0x6f,0x6e,0x6d,0x6c,0x6b,0x6a,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62,0x61,0x60,
0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,
0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
0xff,0
};
const u8 tablerighttriangle[]=
{
60, 0x00, // Disable window for 60 scanlines
0x80 | 64, // 64 lines of single entries
0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,
0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,
0x9f,0x9e,0x9d,0x9c,0x9b,0x9a,0x99,0x98,0x97,0x96,0x95,0x94,0x93,0x92,0x91,0x90,
0x8f,0x8e,0x8d,0x8c,0x8b,0x8a,0x89,0x88,0x87,0x86,0x85,0x84,0x83,0x82,0x81,
0x00,0
};
//---------------------------------------------------------------------------------
int main(void)
{
// Copy tiles to VRAM
bgInitTileSet(0, &patternsbg1, &palettebg1, 0, (&patternsbg1_end - &patternsbg1), 16*1*2, BG_16COLORS, 0x4000);
bgInitTileSet(1, &patternsbg2, &palettebg2, 1, (&patternsbg2_end - &patternsbg2), 16*1*2, BG_16COLORS, 0x6000);
// Copy Map to VRAM
bgInitMapSet(0, &mapbg1, (&mapbg1_end - &mapbg1), SC_32x32, 0x0000);
bgInitMapSet(1, &mapbg2, (&mapbg2_end - &mapbg2), SC_32x32, 0x1000);
// Now Put in 16 color mode and disable other BGs except 1st and 2nd one
setMode(BG_MODE1, 0);
// Initialize the window effect on bg1 & bg2
setModeHdmaWindow(MSWIN_BG1 | MSWIN_BG2, MSWIN1_BG1MSKENABLE | MSWIN1_BG2MSKENABLE | MSWIN1_BG1MSKOUT | MSWIN1_BG2MSKOUT, (u8 *) &tablelefttriangle, (u8 *) &tablerighttriangle);
// Wait for nothing :P
while (1)
{
// Get current #0 pad
pad0 = padsCurrent(0);
// only bg1 with A
if (pad0 & KEY_A) {
if (!pada) {
pada=1;
setModeHdmaWindow(MSWIN_BG1, MSWIN1_BG1MSKENABLE | MSWIN1_BG1MSKOUT, (u8 *) &tablelefttriangle, (u8 *) &tablerighttriangle);
}
}
else pada=0;
// only bg2 with X
if (pad0 & KEY_X) {
if (!padx) {
padx=1;
setModeHdmaWindow(MSWIN_BG2, MSWIN1_BG2MSKENABLE | MSWIN1_BG2MSKOUT, (u8 *) &tablelefttriangle, (u8 *) &tablerighttriangle);
}
}
else padx=0;
// bg1 & bg2 with B
if (pad0 & KEY_B) {
if (!padb) {
padb=1;
setModeHdmaWindow(MSWIN_BG1 | MSWIN_BG2, MSWIN1_BG1MSKENABLE | MSWIN1_BG2MSKENABLE | MSWIN1_BG1MSKOUT | MSWIN1_BG2MSKOUT, (u8 *) &tablelefttriangle, (u8 *) &tablerighttriangle);
}
}
else padb=0;
// Wait vblank sync
}
return 0;
}
void bgSetDisable(u8 bgNumber)
Disable a BG in the actual SNES mode.
void bgSetEnable(u8 bgNumber)
Enable 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.
#define MSWIN1_BG1MSKENABLE
Window 1 area BG1 enable.
Definition dma.h:58
#define MSWIN_BG1
Bit defines for the window area main screen effect.
Definition dma.h:52
#define MSWIN1_BG1MSKOUT
Window 1 area BG1 inside (0) outside(1)
Definition dma.h:57
#define MSWIN1_BG2MSKOUT
Window 1 area BG2 inside (0) outside(1)
Definition dma.h:61
#define MSWIN1_BG2MSKENABLE
Window 1 area BG2 enable.
Definition dma.h:62
#define MSWIN_BG2
Main Screen BG2 disable background.
Definition dma.h:53
#define padsCurrent(value)
Return current value of selected pad.
Definition input.h:198
@ KEY_B
pad B button.
Definition input.h:52
@ KEY_X
pad X button.
Definition input.h:61
@ KEY_A
pad A button.
Definition input.h:51
void WaitForVBlank(void)
Waits for a 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.