-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathexample8.c
68 lines (48 loc) · 1.03 KB
/
example8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//this example shows music and sound effects use
#include "neslib.h"
//put a string into the nametable
void put_str(unsigned int adr,const char *str)
{
vram_adr(adr);
while(1)
{
if(!*str) break;
vram_put((*str++)-0x20);//-0x20 because ASCII code 0x20 is placed in tile 0 of the CHR
}
}
void main(void)
{
static unsigned char i,pause;
pause=FALSE;
pal_col(1,0x30);//set while color
put_str(NTADR_A(2,2),"MUSIC ANS SFX EXAMPLE");
put_str(NTADR_A(2,4),"A TO PLAY MUSIC");
put_str(NTADR_A(2,5),"B TO STOP MUSIC");
put_str(NTADR_A(2,6),"START TO PAUSE MUSIC");
put_str(NTADR_A(2,8),"D-PAD TO PLAY SFX");
ppu_on_all();//enable rendering
while(1)
{
ppu_wait_frame();
i=pad_trigger(0);
if(i&PAD_A)
{
music_play(0);
pause=FALSE;
}
if(i&PAD_B)
{
music_stop();
pause=FALSE;
}
if(i&PAD_START)
{
pause^=TRUE;
music_pause(pause);
}
if(i&PAD_LEFT) sfx_play(0,0);
if(i&PAD_RIGHT) sfx_play(1,1);
if(i&PAD_UP) sfx_play(2,2);
if(i&PAD_DOWN) sfx_play(3,3);
}
}