-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsounds.c
232 lines (201 loc) · 5.53 KB
/
sounds.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "music.c"
int exit_music;
void setNote(Note *n){
switch((*n).i){
case MELODY:
NR10_REG = 0x00U; //pitch sweep
NR11_REG = 0x84U; //wave duty
NR12_REG = (*n).env; //envelope
NR13_REG = (UBYTE)frequencies[(*n).p]; //low bits of frequency
NR14_REG = 0x80U | ((UWORD)frequencies[(*n).p]>>8); //high bits of frequency (and sound reset)
break;
case HARMONY:
NR10_REG = 0x00U;
NR11_REG = 0x00U; //wave duty for harmony is different
NR12_REG = (*n).env;
NR13_REG = (UBYTE)frequencies[(*n).p];
NR14_REG = 0x80U | ((UWORD)frequencies[(*n).p]>>8);
break;
case SNARE:
NR21_REG = 0x00U;
NR22_REG = (*n).env;
NR23_REG = (UBYTE)frequencies[(*n).p];
NR24_REG = 0x80U | ((UWORD)frequencies[(*n).p]>>8);
NR51_REG |= 0x22;
break;
case WAVE:
break;
case CYMBAL:
NR41_REG = 30;
NR42_REG = 55;
NR43_REG = 50;
NR44_REG = 0xC0U;
NR51_REG |= 0x88;
break;
}
}
void init_sounds() {
//NR52_REG = 0x80; //Master control and status flags
//NR51_REG = 0x11; //Sound Output terminal select (1: enabled; 0: disabled)
//NR50_REG = 0x77; //Vin (input line on cart connector) / Main Output Volume
NR52_REG = 0xFFU;
NR51_REG = 0x00U;
NR50_REG = 0x77U;
}
void play_gameplay_music(){
//if (muteChannel1 == 0)
// setNote(&song_gameplay_ch1[currentBeat]);
//setNote(&song_gameplay_ch2[currentBeat]);
//if (muteChannel4 == 0)
// setNote(&song_gameplay_ch4[currentBeat]);
setNote(&game_ch1[currentBeat]);
setNote(&game_ch2[currentBeat]);
NR51_REG |= 0x11U;
}
void play_jingle() {
setNote(&jingle[0]);
NR51_REG |= 0x11U;
delay(100);
setNote(&jingle[1]);
NR51_REG |= 0x11U;
delay(100);
setNote(&jingle[2]);
NR51_REG |= 0x11U;
}
void play_win() {
setNote(&you_win[0]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[1]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[2]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[3]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[4]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[5]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[6]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[7]);
NR51_REG |= 0x11U;
delay(200);
setNote(&you_win[8]);
NR51_REG |= 0x11U;
}
void update_music(){
if (timerCounter >= 14){
timerCounter = 0;
if (currentBeat < 31) //song length - 1
{
currentBeat++;
}
else
{
currentBeat = 0;
}
play_gameplay_music();
}
timerCounter++;
/*if (muteChannel1 != 0)
{
muteChannel1++;
if (muteChannel1 > 10)
muteChannel1 = 0;
}
if (muteChannel4 != 0)
{
muteChannel4++;
if (muteChannel4 > 10)
muteChannel4 = 0;
}*/
}
///
void pewpew() {
NR10_REG = 0x1E; //$FF10 -- $FF14: Channel 1, Referred to as NR10-NR14
NR11_REG = 0x10;
NR12_REG = 0xF3;
NR13_REG = 0x00;
NR14_REG = 0x87;
}
void walk_sound() {
int length;
int envinit;
int envmode;
int envsteps;
int polyfreq;
int polystep;
int polydiv;
int consecutive;
int initialflag;
length = 2; /* 0 - 63 */
envinit = 15; /* 0 - 15 */
envsteps = 1; /* 0 - 7 */
envmode = 0; /* 0 = decrease 1 = increase */
polyfreq = 4; /* 0 - 7 */
polystep = 0; /* 0 - 1 */
polydiv = 5; /* 0 - 7 */
consecutive = 0; /* 0 - 1 */
initialflag = 1; /* 0 - 1 */
NR41_REG = length;
NR42_REG = (envsteps + (envmode * 8) + (envinit * 16));
NR43_REG = (polydiv + (polystep * 8) + (polyfreq * 16));
NR44_REG = (consecutive * 64) + 128;
}
void error_sound()
{
int sweeptime;
int sweepmode;
int sweepshifts;
int patternduty;
int soundlength;
int envinit;
int envmode;
int envsteps;
unsigned int freql;
int freqh;
int consecutive;
int initialflag;
sweeptime = 7; /* 0-7 */
sweepmode = 1; /* 0-1 */
sweepshifts = 1; /* 0 - 7 */
patternduty = 1; /* 0-3 */
soundlength = 0; /* 0 - 63 */
envinit = 15; /* 0 - 15 */
envmode = 0; /* 0-1 */
envsteps = 2; /* 0 - 7 */
freql = 000;
freqh = 5;
consecutive = 0;
initialflag = 1;
NR10_REG = (sweepshifts + (sweepmode * 8) + (sweeptime * 16));
NR11_REG = (soundlength + (patternduty * 32));
NR12_REG = (envsteps + (envmode * 8) + (envinit * 16));
NR13_REG = freql;
NR14_REG = (freqh + (consecutive * 64) + (initialflag * 128));
delay(100);
sweeptime = 7; /* 0-7 */
sweepmode = 1; /* 0-1 */
sweepshifts = 2; /* 0 - 7 */
patternduty = 3; /* 0-3 */
soundlength = 0; /* 0 - 63 */
envinit = 15; /* 0 - 15 */
envmode = 0; /* 0-1 */
envsteps = 2; /* 0 - 7 */
freql = 000;
freqh = 4;
consecutive = 0;
initialflag = 1;
NR10_REG = (sweepshifts + (sweepmode * 8) + (sweeptime * 16));
NR11_REG = (soundlength + (patternduty * 32));
NR12_REG = (envsteps + (envmode * 8) + (envinit * 16));
NR13_REG = freql;
NR14_REG = (freqh + (consecutive * 64) + (initialflag * 128));
}