PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
input/controller/controller.c
/*---------------------------------------------------------------------------------
snes pad controller demo
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
extern char snesfont, snespal;
//---------------------------------------------------------------------------------
int main(void)
{
unsigned short pad0;
// Initialize SNES
// Initialize text console with our font
consoleInitText(0, 16 * 2, &snesfont, &snespal);
// Draw a wonderful text :P
consoleDrawText(12, 1, "PAD TEST");
consoleDrawText(6, 5, "USE PAD TO SEE VALUE");
// Init background
bgSetGfxPtr(0, 0x2000);
bgSetMapPtr(0, 0x6800, SC_32x32);
// Now Put in 16 color mode
setMode(BG_MODE1, 0);
// Wait for nothing :P
while (1)
{
// Get current #0 pad
pad0 = padsCurrent(0);
// Update display with current pad
switch (pad0)
{
case KEY_A:
consoleDrawText(9, 10, "A PRESSED");
break;
case KEY_B:
consoleDrawText(9, 10, "B PRESSED");
break;
case KEY_SELECT:
consoleDrawText(9, 10, "SELECT PRESSED");
break;
case KEY_START:
consoleDrawText(9, 10, "START PRESSED");
break;
case KEY_RIGHT:
consoleDrawText(9, 10, "RIGHT PRESSED");
break;
case KEY_LEFT:
consoleDrawText(9, 10, "LEFT PRESSED");
break;
case KEY_DOWN:
consoleDrawText(9, 10, "DOWN PRESSED");
break;
case KEY_UP:
consoleDrawText(9, 10, "UP PRESSED");
break;
case KEY_R:
consoleDrawText(9, 10, "R PRESSED");
break;
case KEY_L:
consoleDrawText(9, 10, "L PRESSED");
break;
case KEY_X:
consoleDrawText(9, 10, "X PRESSED");
break;
case KEY_Y:
consoleDrawText(9, 10, "Y PRESSED");
break;
default:
consoleDrawText(9, 10, " ");
break;
}
}
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 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)
#define padsCurrent(value)
Return current value of selected pad.
Definition: input.h:161
@ KEY_UP
pad UP button.
Definition: input.h:55
@ KEY_B
pad B button.
Definition: input.h:49
@ KEY_SELECT
pad SELECT button.
Definition: input.h:50
@ KEY_X
pad X button.
Definition: input.h:58
@ KEY_Y
pad Y button.
Definition: input.h:59
@ KEY_LEFT
pad LEFT button.
Definition: input.h:53
@ KEY_START
pad START button.
Definition: input.h:51
@ KEY_RIGHT
pad RIGHT button.
Definition: input.h:52
@ KEY_R
Right shoulder button.
Definition: input.h:56
@ KEY_A
pad A button.
Definition: input.h:48
@ KEY_DOWN
pad DOWN button.
Definition: input.h:54
@ KEY_L
Left shoulder button.
Definition: input.h:57
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.