-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsounds.i
324 lines (275 loc) · 6.91 KB
/
sounds.i
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# 1 "sounds.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "sounds.c"
# 1 "sounds.h" 1
void setupSounds();
void playSoundA( const unsigned char* sound, int length, int frequency, int loops);
void playSoundB( const unsigned char* sound, int length, int frequency, int loops);
void muteSound();
void unmuteSound();
void stopSound();
void stopSoundA();
void stopSoundB();
void pauseSound();
void unpauseSound();
void setupInterrupts();
void interruptHandler();
typedef struct {
const unsigned char* data;
int length;
int frequency;
int isPlaying;
int loops;
int duration;
int priority;
int vbCount;
} SOUND;
# 2 "sounds.c" 2
# 1 "main.h" 1
# 14 "main.h"
void init();
void update();
void draw();
void goToSplash();
void updateSplash();
void goToInstructions();
void updateInstructions();
void goToControls();
void updateControls();
void initGame();
void goToGame();
void updateGame();
void goToPause();
void updatePause();
void goToWin();
void updateWin();
void goToLose();
void updateLose();
void hideSprites();
int catsRemaining;
int lives;
int time;
int timetwo;
int hOff;
int gamehOff;
int hurt;
int hurtCount;
int move;
int catFrame;
enum {CNORM, CBACK, CFRONT };
int direction;
enum { RIGHT, LEFT };
typedef struct {
int row;
int col;
int rd;
int cd;
int width;
int height;
int moveState;
int currFrame;
int direction;
int aniCounter;
int active;
int stopRange;
int maxJumpSpeed;
int racc;
int possibleRow;
} PLAYER;
typedef struct {
int row;
int col;
int rd;
int cd;
int width;
int height;
int active;
int living;
int catFrame;
int moveState;
int aniCounter;
} CAT;
typedef struct {
int row;
int col;
int rd;
int cd;
int width;
int height;
int active;
} FRIDGE;
typedef struct {
int row;
int col;
int cd;
int width;
int height;
int active;
int direction;
} BULLET;
typedef struct {
int row;
int col;
int cd;
int width;
int height;
int active;
} HEALTH;
# 3 "sounds.c" 2
# 1 "myLib.h" 1
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
extern unsigned short *videoBuffer;
# 52 "myLib.h"
extern unsigned short *videoBuffer;
# 68 "myLib.h"
void drawRect4(int row, int col, int height, int width, unsigned char colorIndex);
void waitForVblank();
int sprintf (char *string, const char *form, ...);
void flipPage();
void loadPalette(volatile const unsigned short* palette);
void drawImage4(volatile const unsigned short* image, int row, int col, int height, int width);
void drawBackgroundImage4(volatile const unsigned short* image);
char *short2bin(short x, char arr[]);
extern unsigned int oldButtons;
extern unsigned int buttons;
# 110 "myLib.h"
void DMANow(int channel, volatile const void* source, volatile const void* destination, unsigned int control);
# 119 "myLib.h"
typedef volatile struct {
volatile const void *src;
volatile const void *dst;
volatile unsigned int cnt;
} DMA;
extern DMA *dma;
# 210 "myLib.h"
typedef struct { u16 tileimg[8192]; } charblock;
typedef struct { u16 tilemap[1024]; } screenblock;
# 274 "myLib.h"
typedef struct{
unsigned short attr0;
unsigned short attr1;
unsigned short attr2;
unsigned short fill;
}OBJ_ATTR;
typedef struct {
int row;
int col;
} Sprite;
# 4 "sounds.c" 2
SOUND soundA;
SOUND soundB;
void setupSounds() {
*(volatile u16 *)0x04000084 = (1<<7);
*(volatile u16*)0x04000082 = (1<<1) |
(1<<2) |
(3<<8) |
(0<<10) |
(1<<11) |
(1<<3) |
(3<<12) |
(1<<14) |
(1<<15);
*(u16*)0x04000080 = 0;
}
void playSoundA( const unsigned char* sound, int length, int frequency, int loops) {
dma[1].cnt = 0;
int ticks = (16777216)/frequency;
DMANow(1, sound, (void*)0x040000A0, (2 << 21) | (3 << 28) | (1 << 25) | (1 << 26));
*(volatile unsigned short*)0x4000102 = 0;
*(volatile unsigned short*)0x4000100 = -ticks;
*(volatile unsigned short*)0x4000102 = (1<<7);
soundA.length = length;
soundA.frequency = frequency;
soundA.isPlaying = 1;
soundA.loops = loops;
soundA.duration = (((59.727)*length)/frequency);
soundA.data = sound;
soundA.vbCount = 0;
}
void playSoundB( const unsigned char* sound, int length, int frequency, int loops) {
dma[2].cnt = 0;
int ticks = (16777216)/frequency;
DMANow(2, sound, (void*)0x040000A4, (2 << 21) | (3 << 28) | (1 << 25) | (1 << 26));
*(volatile unsigned short*)0x4000106 = 0;
*(volatile unsigned short*)0x4000104 = -ticks;
*(volatile unsigned short*)0x4000106 = (1<<7);
soundB.length = length;
soundB.frequency = frequency;
soundB.isPlaying = 1;
soundB.loops = loops;
soundB.duration = (((59.727)*length)/frequency);
soundB.data = sound;
soundB.vbCount = 0;
}
void pauseSound() {
soundA.isPlaying = 0;
*(volatile unsigned short*)0x4000102 = 0;
soundB.isPlaying = 0;
*(volatile unsigned short*)0x4000106 = 0;
}
void unpauseSound() {
soundA.isPlaying = 1;
*(volatile unsigned short*)0x4000102 = (1<<7);
soundB.isPlaying = 1;
*(volatile unsigned short*)0x4000106 = (1<<7);
}
void stopSound() {
dma[1].cnt = 0;
dma[2].cnt = 0;
soundA.isPlaying = 0;
*(volatile unsigned short*)0x4000102 = 0;
soundB.isPlaying = 0;
*(volatile unsigned short*)0x4000106 = 0;
}
void stopSoundA() {
dma[1].cnt = 0;
soundA.isPlaying = 0;
*(volatile unsigned short*)0x4000102 = 0;
}
void stopSoundB() {
dma[2].cnt = 0;
soundB.isPlaying = 0;
*(volatile unsigned short*)0x4000106 = 0;
}
void setupInterrupts() {
*(unsigned short*)0x4000208 = 0;
*(unsigned int*)0x3007FFC = (unsigned int) interruptHandler;
*(unsigned short*)0x4000200 |= 1 << 0;
*(unsigned short*)0x4000004 |= 1 << 3;
*(unsigned short*)0x4000208 = 1;
}
void interruptHandler() {
*(unsigned short*)0x4000208 = 0;
if(*(volatile unsigned short*)0x4000202 & 1 << 0)
{
if (soundA.isPlaying) {
soundA.vbCount++;
if (soundA.vbCount > soundA.duration) {
if (soundA.loops) {
playSoundA(soundA.data, soundA.length, soundA.frequency, soundA.loops);
} else {
dma[1].cnt = 0;
soundA.isPlaying = 0;
*(volatile unsigned short*)0x4000102 = 0;
}
}
}
if (soundB.isPlaying) {
soundB.vbCount++;
if (soundB.vbCount > soundB.duration) {
if (soundB.loops) {
playSoundB(soundB.data, soundB.length, soundB.frequency, soundB.loops);
} else {
dma[2].cnt = 0;
soundB.isPlaying = 0;
*(volatile unsigned short*)0x4000106 = 0;
}
}
}
*(volatile unsigned short*)0x4000202 = 1 << 0;
}
*(unsigned short*)0x4000208 = 1;
}