-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.c
76 lines (63 loc) · 1.28 KB
/
sound.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
69
70
71
72
73
74
75
#include "sound.h"
#include <AgbDefine.h>
#include <AgbMemoryMap.h>
extern u16 *sound_tbl[];
SND_STATIC sndStatic;
static void snd_stop(void);
void snd_init(void)
{
*(vu16 *)REG_SOUNDCNT_X=SOUND_DMG_ON;
*(vu16 *)REG_SOUNDCNT_L=SOUND_DMG_ALL_SO_ON<<8
| 7<<SOUND_SO1_LEVEL_SHIFT
| 7<<SOUND_SO2_LEVEL_SHIFT;
*(vu16 *)REG_SOUNDCNT_H=SOUND_DMG_MIX_FULL;
*(vu16 *)REG_SOUNDBIAS=3<<14 | 0x200;
snd_stop();
}
void snd_syncVBlank(void)
{
u8 i;
vu16 *soundCnt;
if(sndStatic.time==(u8)-1)
return;
if(sndStatic.time==0) {
for(;;) {
sndStatic.time=*sndStatic.playPtr>>8;
soundCnt=(vu16 *)REG_SOUND1CNT;
if(sndStatic.time==(u8)-2) {
sndStatic.playPtr=sndStatic.basePtr;
continue;
}
if(sndStatic.time==(u8)-1) {
for(i=0;i<3;i++)
*soundCnt++=0;
return;
}
*(vu16 *)REG_SOUND1CNT_X=0;
for(i=0;i<3;i++) {
*soundCnt=*sndStatic.playPtr;
if(i<2) {
soundCnt++;
sndStatic.playPtr++;
}
}
*soundCnt=*sndStatic.playPtr++;
break;
}
}
sndStatic.time--;
}
void snd_play(u8 num)
{
if(sndStatic.sfxNum>num&&sndStatic.time!=(u8)-1)
return;
sndStatic.playPtr=sound_tbl[num];
sndStatic.basePtr=sndStatic.playPtr;
sndStatic.time=0;
sndStatic.sfxNum=num;
}
static void snd_stop(void)
{
sndStatic.sfxNum=0;
sndStatic.time=-1;
}