-
Notifications
You must be signed in to change notification settings - Fork 1
/
sound.c
95 lines (84 loc) · 2.41 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdint.h>
#include "cd.h"
#include "sound.h"
#include "pcmsys.h"
static void sound_external_audio_enable(uint8_t vol_l, uint8_t vol_r)
{
volatile uint16_t *slot_ptr;
// Max sound volume is 7
if (vol_l > 7) {
vol_l = 7;
}
if (vol_r > 7) {
vol_r = 7;
}
// Setup SCSP Slot 16 and Slot 17 for playing
slot_ptr = (volatile uint16_t *)(0x25B00000 + (0x20 * 16));
slot_ptr[0] = 0x1000;
slot_ptr[1] = 0x0000;
slot_ptr[2] = 0x0000;
slot_ptr[3] = 0x0000;
slot_ptr[4] = 0x0000;
slot_ptr[5] = 0x0000;
slot_ptr[6] = 0x00FF;
slot_ptr[7] = 0x0000;
slot_ptr[8] = 0x0000;
slot_ptr[9] = 0x0000;
slot_ptr[10] = 0x0000;
slot_ptr[11] = 0x001F | (vol_l << 5);
slot_ptr[12] = 0x0000;
slot_ptr[13] = 0x0000;
slot_ptr[14] = 0x0000;
slot_ptr[15] = 0x0000;
slot_ptr = (volatile uint16_t *)(0x25B00000 + (0x20 * 17));
slot_ptr[0] = 0x1000;
slot_ptr[1] = 0x0000;
slot_ptr[2] = 0x0000;
slot_ptr[3] = 0x0000;
slot_ptr[4] = 0x0000;
slot_ptr[5] = 0x0000;
slot_ptr[6] = 0x00FF;
slot_ptr[7] = 0x0000;
slot_ptr[8] = 0x0000;
slot_ptr[9] = 0x0000;
slot_ptr[10] = 0x0000;
slot_ptr[11] = 0x000F | (vol_r << 5);
slot_ptr[12] = 0x0000;
slot_ptr[13] = 0x0000;
slot_ptr[14] = 0x0000;
slot_ptr[15] = 0x0000;
*((volatile uint16_t *)(0x25B00400)) = 0x020F;
}
// Must be called after cd_init
void
sound_init(void)
{
sound_external_audio_enable(5, 5);
pcmsys_load_driver();
pcmsys_load_8bit_pcm("EXPLOSIO.PCM", 8000);
pcmsys_load_8bit_pcm("JUMP.PCM", 8000);
pcmsys_load_8bit_pcm("DASH.PCM", 8000);
}
void
sound_vblank_in(void)
{
m68k_com->start = 1;
}
void
sound_cdda(int track)
{
/* CdcPly ply; */
/* CDC_PLY_STYPE(&ply) = CDC_PTYPE_TNO; //track number */
/* CDC_PLY_STNO(&ply) = track; */
/* CDC_PLY_SIDX(&ply) = 1; */
/* CDC_PLY_ETYPE(&ply) = CDC_PTYPE_TNO; */
/* CDC_PLY_ETNO(&ply) = track + 1; */
/* CDC_PLY_EIDX(&ply) = 99; */
/* CDC_PLY_PMODE(&ply) = CDC_PM_DFL | 0xf; //0xf = infinite repetitions */
/* CDC_CdPlay(&ply); */
}
void
sound_play(short num)
{
pcm_play(num, PCM_SEMI, 6);
}