PVSnesLib  4.3.0
Documentation to code in C or ASM for the Nintendo SNES
audio/effects/effects.c
/*---------------------------------------------------------------------------------
Simple effect sound demo
/*\ WARNING effects must be 1st IT file in convertion
all musics must be after IT file
each combination of a music + effect must be lower than 60K
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>
#include "res/soundbank.h"
extern char snesfont, snespal;
extern char SOUNDBANK__;
u8 i, keyapressed = 0,keylpressed = 0,keyrpressed = 0;
//---------------------------------------------------------------------------------
int main(void)
{
// Initialize sound engine (take some time)
// Initialize SNES
// Initialize text console with our font
consoleInitText(0, 16 * 2, &snesfont, &snespal);
// Set give soundbank
spcSetBank(&SOUNDBANK__);
// Init background
bgSetGfxPtr(0, 0x2000);
bgSetMapPtr(0, 0x6800, SC_32x32);
// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
// Load all effects
for (i=0;i<5;i++) {
}
// Draw a wonderfull text :P
consoleDrawText(5, 10, "Press A to play effect !");
consoleDrawText(5, 11, "Press L and R to change !");
// Wait for nothing :P
// Wait for nothing :D !
i=0;
consoleDrawText(7, 14, "Effect: tada");
while (1)
{
// Refresh pad values and test key a (without repeating sound if still pressed)
if (padsCurrent(0) & KEY_A)
{
if (keyapressed == 0)
{
keyapressed = 1;
// Play effect
spcEffect(8,i,15*16+8); // (u16 pitch,u16 sfxIndex, u8 volpan); pitch=1=4Khz , 2=8khz, 8=32Khz
}
}
else
keyapressed = 0;
{
if (keylpressed == 0)
{
keylpressed = 1;
if (i>0) i--;
if (i==0)
consoleDrawText(7, 14, "Effect: tada ");
else if (i==1)
consoleDrawText(7, 14, "Effect: Hall Strings ");
else if (i==2)
consoleDrawText(7, 14, "Effect: Honky Tonk Piano");
else if (i==3)
consoleDrawText(7, 14, "Effect: Marimba 1 ");
else if (i==4)
consoleDrawText(7, 14, "Effect: Cowbell ");
}
}
else
keylpressed = 0;
{
if (keyrpressed == 0)
{
keyrpressed = 1;
if (i<5) i++;
if (i==0)
consoleDrawText(7, 14, "Effect: tada ");
else if (i==1)
consoleDrawText(7, 14, "Effect: Hall Strings ");
else if (i==2)
consoleDrawText(7, 14, "Effect: Honky Tonk Piano");
else if (i==3)
consoleDrawText(7, 14, "Effect: Marimba 1 ");
else if (i==4)
consoleDrawText(7, 14, "Effect: Cowbell ");
}
}
else
keyrpressed = 0;
// Update music / sfx stream and wait vbl
}
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)
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_LEFT
pad LEFT button.
Definition: input.h:53
@ KEY_RIGHT
pad RIGHT button.
Definition: input.h:52
@ KEY_A
pad A button.
Definition: input.h:48
void WaitForVBlank(void)
Wait for vblank interrupt
the master include file for snes applications.
void spcLoadEffect(u16 sfxIndex)
load sound effect into sm-spc. this function may take some time to execute
void spcEffect(u16 pitch, u16 sfxIndex, u8 volpan)
Play sound effect (load with spcLoadEffect)
void spcSetBank(u8 *bank)
set soundbank origin. soundbank must have dedicated bank(s)
void spcProcess(void)
Process messages This function will try to give messages to the spc until a few scanlines pass.
void spcBoot(void)
boots the spc700 with sm-spc. call once at startup
void spcStop(void)
stop playing the current module.
void setScreenOn(void)
Put screen On.
void setMode(u8 mode, u8 size)
Set the SNES hardware to operate in new display mode.