Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/macros/scripts/audio.asm
1271 views
1
MACRO channel_count
2
ASSERT 0 < (\1) && (\1) <= NUM_MUSIC_CHANS, \
3
"channel_count must be 1-{d:NUM_MUSIC_CHANS}"
4
DEF _num_channels = \1 - 1
5
ENDM
6
7
MACRO channel
8
ASSERT 0 < (\1) && (\1) <= NUM_CHANNELS, \
9
"channel id must be 1-{d:NUM_CHANNELS}"
10
dn (_num_channels << 2), \1 - 1 ; channel id
11
dw \2 ; address
12
DEF _num_channels = 0
13
ENDM
14
15
const_def $10
16
17
; arguments: length [0, 7], pitch change [-7, 7]
18
; length: length of time between pitch shifts
19
; sometimes used with a value >7 in which case the MSB is ignored
20
; pitch change: positive value means increase in pitch, negative value means decrease in pitch
21
; small magnitude means quick change, large magnitude means slow change
22
; in signed magnitude representation, so a value of 8 is the same as (negative) 0
23
const pitch_sweep_cmd ; $10
24
MACRO pitch_sweep
25
db pitch_sweep_cmd
26
IF \2 < 0
27
dn \1, %1000 | (\2 * -1)
28
ELSE
29
dn \1, \2
30
ENDC
31
ENDM
32
33
const_next $20
34
35
const sfx_note_cmd ; $20
36
37
; arguments: length [0, 15], volume [0, 15], fade [-7, 7], frequency
38
; fade: positive value means decrease in volume, negative value means increase in volume
39
; small magnitude means quick change, large magnitude means slow change
40
; in signed magnitude representation, so a value of 8 is the same as (negative) 0
41
DEF square_note_cmd EQU sfx_note_cmd ; $20
42
MACRO square_note
43
db square_note_cmd | \1
44
IF \3 < 0
45
dn \2, %1000 | (\3 * -1)
46
ELSE
47
dn \2, \3
48
ENDC
49
dw \4
50
ENDM
51
52
; arguments: length [0, 15], volume [0, 15], fade [-7, 7], frequency
53
; fade: positive value means decrease in volume, negative value means increase in volume
54
; small magnitude means quick change, large magnitude means slow change
55
; in signed magnitude representation, so a value of 8 is the same as (negative) 0
56
DEF noise_note_cmd EQU sfx_note_cmd ; $20
57
MACRO noise_note
58
db noise_note_cmd | \1
59
IF \3 < 0
60
dn \2, %1000 | (\3 * -1)
61
ELSE
62
dn \2, \3
63
ENDC
64
db \4
65
ENDM
66
67
; arguments: pitch, length [1, 16]
68
MACRO note
69
dn \1, \2 - 1
70
ENDM
71
72
const_next $b0
73
74
; arguments: instrument [1, 19], length [1, 16]
75
const drum_note_cmd ; $b0
76
MACRO drum_note
77
db drum_note_cmd | (\2 - 1)
78
db \1
79
ENDM
80
81
; arguments: instrument, length [1, 16]
82
; like drum_note but one 1 byte instead of 2
83
; can only be used with instruments 1-10, excluding 2
84
; unused
85
MACRO drum_note_short
86
note \1, \2
87
ENDM
88
89
const_next $c0
90
91
; arguments: length [1, 16]
92
const rest_cmd ; $c0
93
MACRO rest
94
db rest_cmd | (\1 - 1)
95
ENDM
96
97
const_next $d0
98
99
; arguments: speed [0, 15], volume [0, 15], fade [-7, 7]
100
; fade: positive value means decrease in volume, negative value means increase in volume
101
; small magnitude means quick change, large magnitude means slow change
102
; in signed magnitude representation, so a value of 8 is the same as (negative) 0
103
const note_type_cmd ; $d0
104
MACRO note_type
105
db note_type_cmd | \1
106
IF \3 < 0
107
dn \2, %1000 | (\3 * -1)
108
ELSE
109
dn \2, \3
110
ENDC
111
ENDM
112
113
; arguments: speed [0, 15]
114
DEF drum_speed_cmd EQU note_type_cmd ; $d0
115
MACRO drum_speed
116
db drum_speed_cmd | \1
117
ENDM
118
119
const_next $e0
120
121
; arguments: octave [1, 8]
122
const octave_cmd ; $e0
123
MACRO octave
124
db octave_cmd | (8 - \1)
125
ENDM
126
127
const_next $e8
128
129
; when enabled, effective frequency used is incremented by 1
130
const toggle_perfect_pitch_cmd ; $e8
131
MACRO toggle_perfect_pitch
132
db toggle_perfect_pitch_cmd
133
ENDM
134
135
const_skip ; $e9
136
137
; arguments: delay [0, 255], depth [0, 15], rate [0, 15]
138
; delay: time delay until vibrato effect begins
139
; depth: amplitude of vibrato wave
140
; rate: frequency of vibrato wave
141
const vibrato_cmd ; $ea
142
MACRO vibrato
143
db vibrato_cmd
144
db \1
145
dn \2, \3
146
ENDM
147
148
; arguments: length [1, 256], octave [1, 8], pitch
149
const pitch_slide_cmd ; $eb
150
MACRO pitch_slide
151
db pitch_slide_cmd
152
db \1 - 1
153
dn 8 - \2, \3
154
ENDM
155
156
; arguments: duty cycle [0, 3] (12.5%, 25%, 50%, 75%)
157
const duty_cycle_cmd ; $ec
158
MACRO duty_cycle
159
db duty_cycle_cmd
160
db \1
161
ENDM
162
163
; arguments: tempo [0, $ffff]
164
; used to calculate note delay counters
165
; so a smaller value means music plays faster
166
; ideally should be set to $100 or less to guarantee no overflow
167
; if larger than $100, large note speed or note length values might cause overflow
168
; stored in big endian
169
const tempo_cmd ; $ed
170
MACRO tempo
171
db tempo_cmd
172
db HIGH(\1), LOW(\1)
173
ENDM
174
175
; arguments: left output enable mask, right output enable mask
176
const stereo_panning_cmd ; $ee
177
MACRO stereo_panning
178
db stereo_panning_cmd
179
dn \1, \2
180
ENDM
181
182
const unknownmusic0xef_cmd ; $ef
183
MACRO unknownmusic0xef
184
db unknownmusic0xef_cmd
185
db \1
186
ENDM
187
188
; arguments: left master volume [0, 7], right master volume [0, 7]
189
const volume_cmd ; $f0
190
MACRO volume
191
db volume_cmd
192
dn \1, \2
193
ENDM
194
195
const_next $f8
196
197
; when enabled, the sfx data is interpreted as music data
198
const execute_music_cmd ; $f8
199
MACRO execute_music
200
db execute_music_cmd
201
ENDM
202
203
const_next $fc
204
205
; arguments: duty cycle 1, duty cycle 2, duty cycle 3, duty cycle 4
206
const duty_cycle_pattern_cmd ; $fc
207
MACRO duty_cycle_pattern
208
db duty_cycle_pattern_cmd
209
db \1 << 6 | \2 << 4 | \3 << 2 | \4
210
ENDM
211
212
; arguments: address
213
const sound_call_cmd ; $fd
214
MACRO sound_call
215
db sound_call_cmd
216
dw \1
217
ENDM
218
219
; arguments: count, address
220
const sound_loop_cmd ; $fe
221
MACRO sound_loop
222
db sound_loop_cmd
223
db \1
224
dw \2
225
ENDM
226
227
const sound_ret_cmd ; $ff
228
MACRO sound_ret
229
db sound_ret_cmd
230
ENDM
231
232