Commit 556ec6a

Nick committed on
Added 5xx - set master volume and more WIP noise channel
commit 556ec6a54adfd9b135d2a928821cdc95afa3da76 parent 222bdd9
1 changed files +154−86
Modifieddriver.z80 +154−86
@@ -122,10 +122,10 @@ DB "NF"
122 SECTION "Song Data", ROM0 122 SECTION "Song Data", ROM0
123 ;; order_cnt is the number of orders times 2 123 ;; order_cnt is the number of orders times 2
124 order_cnt: db 2 124 order_cnt: db 2
125 order1: dw setpan, tfau_bass, unreal, unreal 125 order1: dw unreal, tfau_bass, unreal, unreal
126 order2: dw empty, tfau_arps, unreal_arps, unreal_arps 126 order2: dw unreal_arps, tfau_arps, unreal_arps, unreal_arps
127 order3: dw empty 127 order3: dw empty
128 order4: dw empty 128 order4: dw drums
129 129
130 lunawaves: 130 lunawaves:
131 include "lunawaves.inc" 131 include "lunawaves.inc"
@@ -319,21 +319,21 @@ _init:
319 call _paint_tile 319 call _paint_tile
320 320
321 ;; Load some wave data (or code) into _AUD3WAVERAM 321 ;; Load some wave data (or code) into _AUD3WAVERAM
322 ld hl, $150 ;; note_table 322 ld hl, $000 ;; note_table
323 _addr = _AUD3WAVERAM 323 _addr = _AUD3WAVERAM
324 REPT 16 324 REPT 16
325 ld a, [hl+] 325 ld a, [hl+]
326 ldh [_addr], a 326 ld [_addr], a
327 _addr = _addr + 1 327 _addr = _addr + 1
328 ENDR 328 ENDR
329 329
330 ;; Enable chanel 3 330 ;; Enable chanel 3
331 ; ld a, $80 331 ld a, %10000000
332 ; ldh [rAUD3ENA], a 332 ld [rAUD3ENA], a
333 ; ld a, $ff 333 ld a, $ff ;; full length (although this does nothing)
334 ; ldh [rAUD3LEN], a 334 ld [rAUD3LEN], a
335 ; ld a, $20 335 ld a, %0000000 ; 0%
336 ; ldh [rAUD3LEVEL], a 336 ld [rAUD3LEVEL], a
337 337
338 ld a, %11110000 338 ld a, %11110000
339 ld [envelope1], a 339 ld [envelope1], a
@@ -347,7 +347,7 @@ _addr = _addr + 1
347 ; Enable sound globally 347 ; Enable sound globally
348 ld a, $80 348 ld a, $80
349 ld [rAUDENA], a 349 ld [rAUDENA], a
350 ; Enable channel 1 in stereo 350 ; Enable all channels in stereo
351 ld a, $FF 351 ld a, $FF
352 ld [rAUDTERM], a 352 ld [rAUDTERM], a
353 ; Set volume 353 ; Set volume
@@ -358,8 +358,8 @@ _addr = _addr + 1
358 call _refresh_patterns 358 call _refresh_patterns
359 359
360 ;; Enable the timer 360 ;; Enable the timer
361 ld a, TACF_START | TACF_4KHZ 361 ; ld a, TACF_START | TACF_4KHZ
362 ld [rTAC], a 362 ; ld [rTAC], a
363 363
364 ;; Enable the HBlank interrupt on scanline 0 364 ;; Enable the HBlank interrupt on scanline 0
365 ld a, [rSTAT] 365 ld a, [rSTAT]
@@ -471,18 +471,21 @@ _update_channel:
471 471
472 _update_channel1: 472 _update_channel1:
473 ld a, e 473 ld a, e
474 ldh [rAUD1LOW], a 474 ld [rAUD1LOW], a
475 ld a, d 475 ld a, d
476 ldh [rAUD1HIGH], a 476 ld [rAUD1HIGH], a
477 ret 477 ret
478 _update_channel2: 478 _update_channel2:
479 ld a, e 479 ld a, e
480 ldh [rAUD2LOW], a 480 ld [rAUD2LOW], a
481 ld a, d 481 ld a, d
482 ldh [rAUD2HIGH], a 482 ld [rAUD2HIGH], a
483 ret 483 ret
484 _update_channel3: 484 _update_channel3:
485 485 ld a, e
486 ld [rAUD3LOW], a
487 ld a, d
488 ld [rAUD3HIGH], a
486 ret 489 ret
487 _update_channel4: 490 _update_channel4:
488 491
@@ -500,15 +503,13 @@ ENDM
500 503
501 _playnote1: 504 _playnote1:
502 ;; Play a note on channel 1 (square wave) 505 ;; Play a note on channel 1 (square wave)
503 ld a, %01111111
504 ld [rAUD1LEN], a
505
506 ld a, [temp_note_value+1] 506 ld a, [temp_note_value+1]
507 ld [channel_period1], a 507 ld [channel_period1], a
508 ld [rAUD1LOW], a 508 ld [rAUD1LOW], a
509 509
510 ld a, [temp_note_value] 510 ld a, [temp_note_value]
511 ld [channel_period1+1], a 511 ld [channel_period1+1], a
512
512 or %10000000 513 or %10000000
513 ld [rAUD1HIGH], a 514 ld [rAUD1HIGH], a
514 515
@@ -516,12 +517,6 @@ _playnote1:
516 517
517 _playnote2: 518 _playnote2:
518 ;; Play a note on channel 2 (square wave) 519 ;; Play a note on channel 2 (square wave)
519 ; ld a, %11110000
520 ; ld [rAUD2ENV], a
521
522 ld a, %01111111 ; $10
523 ld [rAUD2LEN], a
524
525 ld a, [temp_note_value+1] 520 ld a, [temp_note_value+1]
526 ld [channel_period2], a 521 ld [channel_period2], a
527 ld [rAUD2LOW], a 522 ld [rAUD2LOW], a
@@ -559,7 +554,7 @@ _playnote4:
559 ld [rAUD4LEN], a 554 ld [rAUD4LEN], a
560 ld a, %11110001 555 ld a, %11110001
561 ld [rAUD4ENV], a 556 ld [rAUD4ENV], a
562 ld a, l; %01000100 557 ld a, [temp_note_value+1]
563 ld [rAUD4POLY], a 558 ld [rAUD4POLY], a
564 ld a, %10000000 559 ld a, %10000000
565 ld [rAUD4GO], a 560 ld [rAUD4GO], a
@@ -585,12 +580,7 @@ _doeffect:
585 add a, b 580 add a, b
586 581
587 ld hl, .jump 582 ld hl, .jump
588 583 add_a_to_hl
589 add a, l
590 ld l, a
591 adc a, h
592 sub l
593 ld h, a
594 584
595 ld b, e 585 ld b, e
596 ld a, [tick] 586 ld a, [tick]
@@ -605,8 +595,8 @@ _doeffect:
605 jp fx_porta_down ;2xy 595 jp fx_porta_down ;2xy
606 jp fx_toneporta ;3xy 596 jp fx_toneporta ;3xy
607 jp fx_vibrato ;4xy 597 jp fx_vibrato ;4xy
608 jp fx_no_op ;fx_toneporta_volslide ;5xy 598 jp fx_set_master_volume ;5xy
609 jp fx_no_op ;fx_vibrato_volslide ;6xy 599 jp fx_call_routine ;6xy
610 jp fx_note_delay ;7xy 600 jp fx_note_delay ;7xy
611 jp fx_set_pan ;8xy 601 jp fx_set_pan ;8xy
612 jp fx_set_duty ;9xy 602 jp fx_set_duty ;9xy
@@ -632,7 +622,32 @@ setup_channel_pointer:
632 add_a_to_hl 622 add_a_to_hl
633 ret 623 ret
634 624
635 fx_no_op: 625 fx_set_master_volume:
626 ret nz
627 ;; B: channel
628 ;; C: effect parameters
629
630 ;; free registers: A, D, E, H, L
631
632 ;; Upper 4 bits contain volume for left, lower 4 bits for right
633 ;; Format is ?LLL ?RRR where ? is just a random bit, since we don't use
634 ;; the Vin
635
636 ;; This can be used as a more fine grained control over channel 3's output,
637 ;; if you pan it completely.
638
639 ld a, c
640 ld [rAUDVOL], a
641 ret
642
643 fx_call_routine:
644 ;; B: channel
645 ;; C: effect parameters
646
647 ;; free registers: A, D, E, H, L
648
649 ;; TODO
650
636 ret 651 ret
637 652
638 fx_set_pan: 653 fx_set_pan:
@@ -680,6 +695,8 @@ fx_vol_slide:
680 695
681 ;; This is really more of a "retrigger note with lower volume" effect and thus 696 ;; This is really more of a "retrigger note with lower volume" effect and thus
682 ;; isn't really that useful. Instrument envelopes should be used instead. 697 ;; isn't really that useful. Instrument envelopes should be used instead.
698 ;; Might replace this effect with something different if a new effect is
699 ;; ever needed.
683 700
684 ;; B: channel 701 ;; B: channel
685 ;; C: effect parameters 702 ;; C: effect parameters
@@ -700,10 +717,26 @@ fx_vol_slide:
700 ld h, [hl] 717 ld h, [hl]
701 ld l, a 718 ld l, a
702 719
720 ;; setup the up and down params
721 ld a, c
722 and %00001111
723 ld d, a
724
725 ld a, c
726 and %11110000
727 ld e, a
728
703 ld a, [hl] 729 ld a, [hl]
704 and %11110000 730 and %11110000
705 swap a 731 swap a
706 sub c 732 sub d
733 jp nc, .cont1
734 ld a, 0
735 .cont1:
736 add e
737 jp nc, .cont2
738 ld a, $F
739 .cont2:
707 swap a 740 swap a
708 ld [hl+], a 741 ld [hl+], a
709 742
@@ -858,9 +891,28 @@ set_channel_volume:
858 jr c, set_chn_1_vol 891 jr c, set_chn_1_vol
859 jr z, set_chn_2_vol 892 jr z, set_chn_2_vol
860 set_chn_3_vol: 893 set_chn_3_vol:
861 ld a, d 894 ;; "Quantize" the more finely grained volume control down to one of 4 values.
895 ld a, c
896 swap a
897 cp 0
898 jr z, .zero
899 cp 5
900 jr nc, .one
901 cp 10
902 jr nc, .two
903 .three:
904 ld a, %01100000
905 jr .done
906 .two:
907 ld a, %01000000
908 jr .done
909 .one:
910 ld a, %00100000
911 jr .done
912 .zero:
913 ld a, 0
914 .done:
862 ld [rAUD3LEVEL], a 915 ld [rAUD3LEVEL], a
863
864 ret 916 ret
865 set_chn_2_vol: 917 set_chn_2_vol:
866 ; ld a, d 918 ; ld a, d
@@ -1142,11 +1194,11 @@ _dosound:
1142 ld de, channel_note1 1194 ld de, channel_note1
1143 call _lookup_note 1195 call _lookup_note
1144 1196
1145 jr nc, .continue 1197 jr nc, .do_setvol1
1146 ld a, %11110000 1198 ld a, %11110000
1147 ld [rAUD1ENV], a 1199 ld [rAUD1ENV], a
1148 1200
1149 .continue: 1201 .do_setvol1:
1150 ld a, h 1202 ld a, h
1151 ld [temp_note_value], a 1203 ld [temp_note_value], a
1152 ld a, l 1204 ld a, l
@@ -1164,13 +1216,15 @@ _dosound:
1164 call _playnote1 ; 3 bytes 1216 call _playnote1 ; 3 bytes
1165 1217
1166 .after_note1: 1218 .after_note1:
1167 ld a, %11110000
1168 ld [rAUD2ENV], a
1169
1170 loadShort pattern2, b, c 1219 loadShort pattern2, b, c
1171 ld de, channel_note2 1220 ld de, channel_note2
1172 call _lookup_note 1221 call _lookup_note
1173 1222
1223 jr nc, .do_setvol2
1224 ld a, %11110000
1225 ld [rAUD2ENV], a
1226
1227 .do_setvol2:
1174 ld a, h 1228 ld a, h
1175 ld [temp_note_value], a 1229 ld [temp_note_value], a
1176 ld a, l 1230 ld a, l
@@ -1187,53 +1241,55 @@ _dosound:
1187 1241
1188 call _playnote2 ; 3 bytes 1242 call _playnote2 ; 3 bytes
1189 1243
1244 .after_note2:
1245 loadShort pattern3, b, c
1246 ld de, channel_note3
1247 call _lookup_note
1190 1248
1249 ld a, h
1250 ld [temp_note_value], a
1251 ld a, l
1252 ld [temp_note_value+1], a
1191 1253
1254 push af
1192 1255
1193 ; loadShort pattern2, b, c 1256 ld e, 2
1194 ; call _lookup_note 1257 call _doeffect
1195 ; jr nc, .after_note2
1196 1258
1197 ; ld a, h 1259 pop af
1198 ; ld [temp_note_value], a
1199 ; ld a, l
1200 ; ld [temp_note_value+1], a
1201 1260
1202 ; ld e, 1 1261 jr nc, .after_note3
1203 ; call _doeffect
1204 1262
1205 ; call _playnote2 1263 call _playnote3 ; 3 bytes
1206 1264
1207 .after_note2: 1265 .after_note3:
1208 ; loadShort pattern3, b, c 1266 loadShort pattern4, b, c
1209 ; call _lookup_note 1267 ld de, channel_note4
1210 ; jr nc, .after_note3 1268 call _lookup_note
1211 1269
1212 ; ld a, h 1270 jr nc, .do_setvol4
1213 ; ld [temp_note_value], a 1271 ld a, %11110000
1214 ; ld a, l 1272 ld [rAUD4ENV], a
1215 ; ld [temp_note_value+1], a
1216 1273
1217 ; ld e, 2 1274 .do_setvol4:
1218 ; call _doeffect 1275 ld a, h
1276 ld [temp_note_value], a
1277 ld a, l
1278 ld [temp_note_value+1], a
1219 1279
1220 ; call _playnote3 1280 push af
1221 1281
1222 .after_note3: 1282 ld e, 3
1223 ; loadShort pattern4, b, c 1283 call _doeffect
1224 ; call _lookup_note
1225 ; jr nc, process_tick
1226 1284
1227 ; ld a, h 1285 pop af
1228 ; ld [temp_note_value], a
1229 ; ld a, l
1230 ; ld [temp_note_value+1], a
1231 1286
1232 ; ld e, 3 1287 jr nc, .after_note4
1233 ; call _doeffect
1234 1288
1235 ; call _playnote4 1289 call _playnote4 ; 3 bytes
1236 1290
1291 .after_note4:
1292 ;; finally just update the tick/order/row values
1237 jp process_tick 1293 jp process_tick
1238 1294
1239 .process_effects: 1295 .process_effects:
@@ -1263,16 +1319,28 @@ _dosound:
1263 call _doeffect 1319 call _doeffect
1264 1320
1265 .after_effect2: 1321 .after_effect2:
1266 ; loadShort pattern3, b, c 1322 loadShort pattern3, b, c
1267 ; call _lookup_note 1323 ld de, channel_note3
1268 ; ld e, 2 1324 call _lookup_note
1269 ; call _doeffect 1325
1326 ld a, c
1327 cp 0
1328 jr z, .after_effect3
1329
1330 ld e, 2
1331 call _doeffect
1270 1332
1271 .after_effect3: 1333 .after_effect3:
1272 ; loadShort pattern4, b, c 1334 loadShort pattern4, b, c
1273 ; call _lookup_note 1335 ld de, channel_note4
1274 ; ld e, 3 1336 call _lookup_note
1275 ; call _doeffect 1337
1338 ld a, c
1339 cp 0
1340 jr z, .after_effect4
1341
1342 ld e, 3
1343 call _doeffect
1276 1344
1277 .after_effect4: 1345 .after_effect4:
1278 1346