@@ -31,8 +31,16 @@ add_a_to_de: MACRO |
| 31 |
add_a_to_r16 d, e |
31 |
add_a_to_r16 d, e |
| 32 |
ENDM |
32 |
ENDM |
| 33 |
|
33 |
|
|
|
34 |
ret_dont_call_playnote: MACRO |
|
|
35 |
pop hl |
|
|
36 |
pop af |
|
|
37 |
ld a, 6 |
|
|
38 |
add_a_to_hl |
|
|
39 |
jp hl |
|
|
40 |
ENDM |
|
|
41 |
|
| 34 |
; Constants |
42 |
; Constants |
| 35 |
STACK_SIZE EQU 20 |
43 |
STACK_SIZE EQU $7A |
| 36 |
;; Stack starts at $FFFE |
44 |
;; Stack starts at $FFFE |
| 37 |
|
45 |
|
| 38 |
PATTERN_LENGTH EQU 64 |
46 |
PATTERN_LENGTH EQU 64 |
@@ -229,6 +237,38 @@ setpan: |
| 229 |
dn 90, 00, 00 |
237 |
dn 90, 00, 00 |
| 230 |
endr |
238 |
endr |
| 231 |
|
239 |
|
|
|
240 |
;;;;;;;;;;;;;;;; |
|
|
241 |
;; Instruments |
|
|
242 |
;;;;;;;;;;;;;;;; |
|
|
243 |
|
|
|
244 |
;; Instruments come in blocks. |
|
|
245 |
|
|
|
246 |
instruments: |
|
|
247 |
|
|
|
248 |
;; Format for channels 1 and 2: |
|
|
249 |
|
|
|
250 |
square_instrument: |
|
|
251 |
.sweep: db ; unused for channel 2 |
|
|
252 |
.length_and_duty: db %10000000 |
|
|
253 |
.envelope: db %11110000 |
|
|
254 |
.unused: db |
|
|
255 |
|
|
|
256 |
;; Format for channel 3: |
|
|
257 |
|
|
|
258 |
voice_instrument: |
|
|
259 |
.length: db |
|
|
260 |
.volume: db |
|
|
261 |
.wave: db |
|
|
262 |
.unused: db |
|
|
263 |
|
|
|
264 |
;; Format for channel 4: |
|
|
265 |
|
|
|
266 |
noise_instrument: |
|
|
267 |
.length: db |
|
|
268 |
.envelope: db |
|
|
269 |
.step_and_ratio: db |
|
|
270 |
.unused: db |
|
|
271 |
|
| 232 |
SECTION "Playback variables", WRAM0 |
272 |
SECTION "Playback variables", WRAM0 |
| 233 |
pattern1: dw |
273 |
pattern1: dw |
| 234 |
pattern2: dw |
274 |
pattern2: dw |
@@ -408,16 +448,13 @@ ENDM |
| 408 |
load_pattern order4, pattern4 |
448 |
load_pattern order4, pattern4 |
| 409 |
ret |
449 |
ret |
| 410 |
|
450 |
|
| 411 |
_lookup_note: |
451 |
_load_note_data: |
| 412 |
;; Call with: |
452 |
;; Call with: |
| 413 |
;; Pattern pointer in BC |
453 |
;; Pattern pointer in BC |
| 414 |
;; channel_noteX pointer in DE |
|
|
| 415 |
|
|
|
| 416 |
;; Stores note period value in HL |
|
|
| 417 |
;; Stores instrument/effect code in B |
|
|
| 418 |
;; Stores effect params in C |
|
|
| 419 |
;; Stores note number in the memory pointed to by DE |
|
|
| 420 |
|
454 |
|
|
|
455 |
;; Stores instrument/effect code in B |
|
|
456 |
;; Stores effect params in C |
|
|
457 |
;; Stores note number in A |
| 421 |
ld a, [row] |
458 |
ld a, [row] |
| 422 |
ld h, a |
459 |
ld h, a |
| 423 |
;; Multiply by 3 for the note value |
460 |
;; Multiply by 3 for the note value |
@@ -434,6 +471,19 @@ _lookup_note: |
| 434 |
ld b, a |
471 |
ld b, a |
| 435 |
|
472 |
|
| 436 |
ld a, [hl] |
473 |
ld a, [hl] |
|
|
474 |
|
|
|
475 |
ret |
|
|
476 |
|
|
|
477 |
_lookup_note: |
|
|
478 |
;; Call with: |
|
|
479 |
;; Pattern pointer in BC |
|
|
480 |
;; channel_noteX pointer in DE |
|
|
481 |
|
|
|
482 |
;; Stores note period value in HL |
|
|
483 |
;; Stores instrument/effect code in B |
|
|
484 |
;; Stores effect params in C |
|
|
485 |
;; Stores note number in the memory pointed to by DE |
|
|
486 |
call _load_note_data |
| 437 |
ld hl, 0 |
487 |
ld hl, 0 |
| 438 |
|
488 |
|
| 439 |
;; If the note we found is greater than LAST_NOTE, then it's not a valid note |
489 |
;; If the note we found is greater than LAST_NOTE, then it's not a valid note |
@@ -506,11 +556,6 @@ _update_channel4: |
| 506 |
ld [rAUD4GO], a |
556 |
ld [rAUD4GO], a |
| 507 |
ret |
557 |
ret |
| 508 |
|
558 |
|
| 509 |
strip_instrument: MACRO |
|
|
| 510 |
ld a, b |
|
|
| 511 |
and %00001111 |
|
|
| 512 |
ENDM |
|
|
| 513 |
|
|
|
| 514 |
;;;;;;; |
559 |
;;;;;;; |
| 515 |
;; Note playing routines. Need to either consolidate these or find some |
560 |
;; Note playing routines. Need to either consolidate these or find some |
| 516 |
;; better way of doing effects that happen on the first tick. |
561 |
;; better way of doing effects that happen on the first tick. |
@@ -811,11 +856,7 @@ fx_note_delay: |
| 811 |
|
856 |
|
| 812 |
;; Don't call _playnote. This is done by grabbing the return |
857 |
;; Don't call _playnote. This is done by grabbing the return |
| 813 |
;; address and manually skipping the next call instruction. |
858 |
;; address and manually skipping the next call instruction. |
| 814 |
pop hl |
859 |
ret_dont_call_playnote |
| 815 |
pop af |
|
|
| 816 |
ld a, 6 |
|
|
| 817 |
add_a_to_hl |
|
|
| 818 |
jp hl |
|
|
| 819 |
|
860 |
|
| 820 |
.play_note: |
861 |
.play_note: |
| 821 |
ld a, [tick] |
862 |
ld a, [tick] |
@@ -1127,11 +1168,7 @@ fx_toneporta: |
| 1127 |
;; Don't call _playnote. This is done by grabbing the return |
1168 |
;; Don't call _playnote. This is done by grabbing the return |
| 1128 |
;; address and manually skipping the next call instruction. |
1169 |
;; address and manually skipping the next call instruction. |
| 1129 |
.return_skip: |
1170 |
.return_skip: |
| 1130 |
pop hl |
1171 |
ret_dont_call_playnote |
| 1131 |
pop af |
|
|
| 1132 |
ld a, 6 |
|
|
| 1133 |
add_a_to_hl |
|
|
| 1134 |
jp hl |
|
|
| 1135 |
|
1172 |
|
| 1136 |
.do_toneporta: |
1173 |
.do_toneporta: |
| 1137 |
;; B: channel |
1174 |
;; B: channel |
@@ -1223,17 +1260,40 @@ loadShort: MACRO |
| 1223 |
ld \2, a |
1260 |
ld \2, a |
| 1224 |
ENDM |
1261 |
ENDM |
| 1225 |
|
1262 |
|
|
|
1263 |
_setup_instrument_pointer: |
|
|
1264 |
ld a, b |
|
|
1265 |
and %11110000 |
|
|
1266 |
swap a |
|
|
1267 |
|
|
|
1268 |
;; Shift left twice to multiply by 4 |
|
|
1269 |
sla a |
|
|
1270 |
sla a |
|
|
1271 |
|
|
|
1272 |
ld de, instruments |
|
|
1273 |
add_a_to_de |
|
|
1274 |
ret |
|
|
1275 |
|
| 1226 |
_dosound: |
1276 |
_dosound: |
| 1227 |
ld a, [tick] |
1277 |
ld a, [tick] |
| 1228 |
or a |
1278 |
or a |
| 1229 |
jp nz, .process_effects |
1279 |
jp nz, .process_effects |
| 1230 |
|
1280 |
|
|
|
1281 |
;; Note playback |
|
|
1282 |
|
| 1231 |
loadShort pattern1, b, c |
1283 |
loadShort pattern1, b, c |
| 1232 |
ld de, channel_note1 |
1284 |
ld de, channel_note1 |
| 1233 |
call _lookup_note |
1285 |
call _lookup_note |
| 1234 |
|
1286 |
push af |
| 1235 |
jr nc, .do_setvol1 |
1287 |
jr nc, .do_setvol1 |
| 1236 |
ld a, %11110000 |
1288 |
|
|
|
1289 |
call _setup_instrument_pointer |
|
|
1290 |
ld a, [de] |
|
|
1291 |
inc de |
|
|
1292 |
ld [rAUD1SWEEP], a |
|
|
1293 |
ld a, [de] |
|
|
1294 |
inc de |
|
|
1295 |
ld [rAUD1LEN], a |
|
|
1296 |
ld a, [de] |
| 1237 |
ld [rAUD1ENV], a |
1297 |
ld [rAUD1ENV], a |
| 1238 |
|
1298 |
|
| 1239 |
.do_setvol1: |
1299 |
.do_setvol1: |
@@ -1242,8 +1302,6 @@ _dosound: |
| 1242 |
ld a, l |
1302 |
ld a, l |
| 1243 |
ld [temp_note_value+1], a |
1303 |
ld [temp_note_value+1], a |
| 1244 |
|
1304 |
|
| 1245 |
push af |
|
|
| 1246 |
|
|
|
| 1247 |
ld e, 0 |
1305 |
ld e, 0 |
| 1248 |
call _doeffect |
1306 |
call _doeffect |
| 1249 |
|
1307 |
|
@@ -1340,7 +1398,7 @@ _dosound: |
| 1340 |
|
1398 |
|
| 1341 |
loadShort pattern1, b, c |
1399 |
loadShort pattern1, b, c |
| 1342 |
ld de, channel_note1 |
1400 |
ld de, channel_note1 |
| 1343 |
call _lookup_note |
1401 |
call _load_note_data |
| 1344 |
|
1402 |
|
| 1345 |
ld a, c |
1403 |
ld a, c |
| 1346 |
cp 0 |
1404 |
cp 0 |
@@ -1352,7 +1410,7 @@ _dosound: |
| 1352 |
.after_effect1: |
1410 |
.after_effect1: |
| 1353 |
loadShort pattern2, b, c |
1411 |
loadShort pattern2, b, c |
| 1354 |
ld de, channel_note2 |
1412 |
ld de, channel_note2 |
| 1355 |
call _lookup_note |
1413 |
call _load_note_data |
| 1356 |
|
1414 |
|
| 1357 |
ld a, c |
1415 |
ld a, c |
| 1358 |
cp 0 |
1416 |
cp 0 |
@@ -1364,7 +1422,7 @@ _dosound: |
| 1364 |
.after_effect2: |
1422 |
.after_effect2: |
| 1365 |
loadShort pattern3, b, c |
1423 |
loadShort pattern3, b, c |
| 1366 |
ld de, channel_note3 |
1424 |
ld de, channel_note3 |
| 1367 |
call _lookup_note |
1425 |
call _load_note_data |
| 1368 |
|
1426 |
|
| 1369 |
ld a, c |
1427 |
ld a, c |
| 1370 |
cp 0 |
1428 |
cp 0 |
@@ -1376,7 +1434,7 @@ _dosound: |
| 1376 |
.after_effect3: |
1434 |
.after_effect3: |
| 1377 |
loadShort pattern4, b, c |
1435 |
loadShort pattern4, b, c |
| 1378 |
ld de, channel_note4 |
1436 |
ld de, channel_note4 |
| 1379 |
call _lookup_note |
1437 |
call _load_note_data |
| 1380 |
|
1438 |
|
| 1381 |
ld a, c |
1439 |
ld a, c |
| 1382 |
cp 0 |
1440 |
cp 0 |