forked from n64decomp/sm64
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.c
73 lines (57 loc) · 1.67 KB
/
main.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
#include <stdio.h>
#include "nds_include.h"
#include <fat.h>
#include "audio/data.h"
#include "audio/external.h"
#include "audio/load.h"
#include "audio/seqplayer.h"
#include "game/game_init.h"
#include "nds_renderer.h"
u8 nds_audio_state;
static u8 audio_step;
void exec_display_list(struct SPTask *spTask) {
draw_frame((Gfx*)spTask->task.t.data_ptr);
}
static void update_audio(void) {
// Update audio at the ARM7's request
if (nds_audio_state == 0) {
// Update the audio logic at 30 Hz
if ((audio_step = (audio_step + 1) & 7) == 0) {
update_game_sound();
gAudioFrameCount += 2;
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
}
// Update the sequences at 240 Hz
process_sequences(0);
} else if (nds_audio_state == 1) {
// Disable audio
for (int i = 0; i < 16; i++) {
gNotes[i].enabled = false;
}
nds_audio_state = 2;
}
// Tell the ARM7 it can go ahead
IPC_SendSync(0);
}
int main(void) {
static u64 pool[0x165000 / sizeof(u64)];
main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0]));
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);
setCpuClock(true);
renderer_init();
#ifdef LIBFAT
if (!fatInitDefault()) {
printf("Failed to initialize libfat!\n");
}
#endif
audio_init();
sound_init();
// Set up audio on the ARM9 side
irqSet(IRQ_IPC_SYNC, update_audio);
irqEnable(IRQ_IPC_SYNC);
// Give the ARM7 a pointer to the audio data
fifoSendValue32(FIFO_USER_01, (u32)gNotes);
// Run the game
thread5_game_loop(NULL);
return 0;
}