-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoundSystem.inc
296 lines (264 loc) · 8.54 KB
/
SoundSystem.inc
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
IF !DEF(SOUNDSYSTEM_INC)
SOUNDSYSTEM_INC = 1
;===============================
; Usage
;===============================
; There are two main routines: SoundSystem_Init and SoundSystem_Process.
; SoundSystem_Init is called just once to initialize the system, and
; SoundSystem_Process needs to be called once a frame to drive the player.
;
; SoundSystem behavior and the features it has is controlled via the
; SoundSystem.def file. Based on the definitions there, SoundSystem will
; include/exclude features. Some options have trade-offs which are described
; in the template SoundSystem.def file provided in the release materials.
;
; General Notes
; - To make SoundSystem as efficient as possible, it will not preserve any
; registers at the call sites. This means that it is up to you to preserve
; anything before making any SoundSystem call. It is perhaps safest/easiest
; to think that all registers are used and ROM/WRAM banks changed*.
;
; *depending on the definitions in SoundSystem.def
;===============================
; Main Driver Functions
;===============================
;-------------------------------
; SoundSystem_Init
;
; This prepares SoundSystem for use. It must be called before any other
; SoundSystem functions can be called.
;
; Arguments:
; None
;
; Example:
; call SoundSystem_Init
;-------------------------------
; SoundSystem_Process
;
; This is the 'heartbeat' of the driver so it should be called every frame.
; The exact time (in a VBlank or during a frame) isn't important; provided it
; is called at a regular interval.
;
; CPU usage is dependent on the audio SoundSystem is processing. Each effect
; has a cost and so the CPU time is not fixed.
;
; Notes:
; - Registers will not be preserved.
; - ROM/WRAM banks could change (based on SoundSystem.def settings).
;
; Arguments:
; None
;
; Example:
; ; preserve any registers, if applicable
; call SoundSystem_Process
; ; switch ROM bank, if applicable
; ; switch WRAM bank, if applicable
;===============================
; Song (Music) Features
;===============================
;-------------------------------
; Music_PrepareInst
;
; In order for music to be playable with Music_Play (see below), it needs to
; be 'prepared' first. This routine tells SoundSystem where the instrument
; table resides, which can be in a different location where the actual music
; order table (pattern data) resides.
;
; Notes:
; - This needs to be called before every call to Music_Play.
; - The instrument table is part of the data that is exported by GB Tracker.
; Labeled as 'SFX Table' at the end of the exported data (the symbol starts
; with 'Inst_').
;
; Arguments:
; BC - bank id where the instrument table resides
; DE - pointer to the instrument table
;
; Example:
; ld bc,BANK(Inst_s11space)
; ld de,Inst_s11space
; call Music_PrepareInst
;-------------------------------
; Music_Play
;
; This is the trigger to start music actually playing (and processed by
; SoundSystem_Process). The order table data can reside in a different
; location to the instrument data. SoundSystem will handle bank swapping
; as and when it needs to.
;
; Notes:
; - Music_PrepareInst needs to be called before this.
; - The music table is part of the data that is exported by GB Tracker.
; Labeled as 'Order Table' before the SFX data in the exported data.
;
; Arguments:
; BC - bank id where the order table resides
; DE - pointer to the order table
;
; Example:
; ld bc,BANK(Music_s11space)
; ld de,Music_s11space
; call Music_Play
;-------------------------------
; Music_Pause
;
; This pauses music playback. After the music is paused, it is safe to
; call SoundSystem_Process and sound effects can still be triggered.
; Call Music_Resume (see below) to continue the music playback.
;
; Notes:
; - Subsequent calls to Music_Pause have no effect.
; - Calling Music_Pause before Music_Play has no effect, but best
; practice is to only call Music_Pause after Music_Play.
;
; Arguments:
; None
;
; Example:
; call Music_Pause
;-------------------------------
; Music_Resume
;
; This resumes music playback after Music_Pause (see above) has called.
;
; Notes:
; - Subsequent calls to Music_Resume have no effect, but best practice is to
; only call Music_Resume after Music_Pause.
;
; Arguments:
; None
;
; Example:
; call Music_Resume
;===============================
; Sound Effect (SFX) Features
;===============================
;-------------------------------
; SFX_Prepare
;
; In order for one-shot sound effects (SFX) to be playable with SFX_Play (see
; below), they need to be 'prepared' first. This routine tells SoundSystem
; where the sound effects table resides, which can be in a different location
; where the music data resides.
;
; Notes:
; - This needs to be called just once per 'set' of sound effects. Once called,
; any number of SFX_Play calls can be made.
; - Typically, sound effects are kept separate to any music data.
; - The sfx table is part of the data that is exported by GB Tracker.
; Commented as 'SFX Table' in the exported data (the symbol starts with 'SFX').
;
; Arguments:
; BC - bank id where the sfx table resides
; DE - pointer to the sfx table
;
; Example:
; ld bc,BANK(SFX_Table)
; ld de,SFX_Table
; call SFX_Prepare
;-------------------------------
; SFX_Play
;
; This is the trigger to start a one-shot sound effect actually playing (and
; processed by SoundSystem_Process).
;
; Notes:
; - SFX_Prepare needs to be called before this.
; - The note will only take affect if the sound doesn't set a note in its
; start command.
;
; Arguments:
; B - id (not byte offset) of the sound effect to play
; C - note (frequency) at which to play the sound effect, 0-71
; 6 octaves of 12 notes: C_2 (0) to B_7 (71), middle C is C_4 (24)
; See SoundSystemNotes.inc for specific values.
;
; Example:
; ld b,COOL_SFX_1
; ld c,C_4
; ;ld bc,(COOL_SFX_1<<8)|C_4 ; or this way as an optimization
; call SFX_Play
;-------------------------------
; SFX_Stop
;
; This immediately terminates all one-shot sound effects from playing.
;
; Notes:
; - It is safe to call this multiple times or of SFX_Play hasn't been called.
;
; Arguments:
; None
;
; Example:
; call SFX_Stop
;-------------------------------
; SFX_LockChannel3
; SFX_UnlockChannel3
;
; This pair of routines affect the wave channel (channel 3) of the GameBoy.
; Locking the channel will prevent music and other sound effects from using
; that channel until it is unlocked again.
;
; Notes:
; - Subsequent calls to either SFX_LockChannel3 or SFX_UnlockChannel3 have no
; effect. Only the first call changes behavior.
; - Channel 3 is unlocked by default.
;
; Arguments:
; None
;
; Example:
; call SFX_LockChannel3
; ...
; call SFX_UnlockChannel3
;===============================
; Miscellaneous Features
;===============================
;-------------------------------
; Playback State
;
; You can check the playback state by inspecting wMusicPlayState. EQUates are
; provided below for possible values: either stopped or playing.
MUSIC_STATE_STOPPED EQU 0
MUSIC_STATE_PLAYING EQU 1
;-------------------------------
; Synchronization
;
; The tracker has a mechanism that provides a way to synchronize the code with
; the music via the Zxx Flag Command. This sends a value ($00-$FF) to the code
; to be processed however applicable (or ignored).
;
; wMusicSyncData
;
; Notes:
; - This is a raw value and not further processed by SoundSystem so it is
; entirely managed the musician.
;-------------------------------
; VU Meters
;
; SoundSystem can provide data that can drive a VU-meter type display. This is
; disabled by default, but access to that data is provided by setting
; SOUNDSYSTEM_ENABLE_VUM in SoundSystem.def to 1.
;
; If enabled, the data (value $0-$F) is in 4 1-byte variables, one per channel:
; 'wVUMeter1' = channel 1
; 'wVUMeter2' = channel 2
; 'wVUMeter3' = channel 3
; 'wVUMeter4' = channel 4
;
; They are contiguous in memory so you can access them as an array if needed.
;
; Notes:
; - CPU, code size, and RAM usage is slightly more if this is enabled.
;-------------------------------
; Identity
;
; There are two symbols that can be used for attribution:
; SoundSystem_Version
; SoundSystem_Author
;
; Notes:
; - These are NULL-terminated strings.
ENDC ; SOUNDSYSTEM_INC