Commit 1d84f7a

Nick committed on
WIP Instruments
commit 1d84f7a343e300f3a1afc8ac739e123361bad775 parent 40eb501
3 changed files +98−46
Modifieddriver-format.txt +6−6
@@ -2,11 +2,11 @@
2 0000.0000-0000-0000.0000.0000 2 0000.0000-0000-0000.0000.0000
3 3
4 Stuff to do: 4 Stuff to do:
5 5 - Implement instruments
6 - Make tick stuff happen on ticks other than zero (and multiple times) 6 - Implement routines
7 - Get rid of popping and pushing HL
8 7
9 If note value is greater than 71 then it's considered to be an empty note cell. 8 If note value is greater than 71 then it's considered to be an empty note cell.
9 Will probably add some sort of RLE encoding later with special notes greater than 71.
10 10
11 00 is an empty instrument cell. 11 00 is an empty instrument cell.
12 12
@@ -17,9 +17,9 @@ If note value is greater than 71 then it's considered to be an empty note cell.
17 2 - Slide down 17 2 - Slide down
18 3 - Toneporta 18 3 - Toneporta
19 4 - Vibrato 19 4 - Vibrato
20 5 - Toneporta + volslide 20 5 - Set master volume
21 6 - Vibrato + volslide 21 6 - Call routine
22 7 - Tremolo 22 7 - Note delay
23 8 - Set panning 23 8 - Set panning
24 9 - Set duty cycle 24 9 - Set duty cycle
25 A - Volslide 25 A - Volslide
Modifieddriver.z80 +91−33
@@ -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
Modifiedunreal.inc +1−7
@@ -1,10 +1,4 @@
1 dn: MACRO ;; (note, instr, effect) 1 dn F5, 00, $F07
2 db \1
3 db ((\2 << 4) | (\3 >> 8))
4 db LOW(\3)
5 ENDM
6
7 dn F5, 11, $F07
8 dn G#5, 00, $316 2 dn G#5, 00, $316
9 dn C6, 00, $316 3 dn C6, 00, $316
10 dn F6, 00, $316 4 dn F6, 00, $316