Commit 20d965e

Nick committed on
Added crappy initial vibrato impl
commit 20d965eb4b12c2afde20137ab310c5b37bf2631a parent 1a82660
2 changed files +161−23
Addedcrap.py +26−0
@@ -0,0 +1,26 @@
1 '''def saw(t):
2 return t & 255
3
4 def saw2(t):
5 return t & 31
6
7 for i in range(0,64,1):
8 print(saw2(i))
9 '''
10
11 def percentage(n):
12 x = 0
13 for i in range(0, 5):
14 if (i & n) == 0:
15 x += 1
16 #print(n, x/100, sep='\t')
17 return x/5
18
19 d = {}
20 for i in range(16):
21 p = percentage(i)
22 if p not in d:
23 d[p] = bin(i) + ", " + hex(i)
24
25 for item in d.items():
26 print(item)
Modifieddriver.z80 +135−23
@@ -153,6 +153,11 @@ arps:
153 rept 64 153 rept 64
154 dn C5, 00, $047 154 dn C5, 00, $047
155 endr 155 endr
156 vib:
157 dn C5, 00, $000
158 rept 63
159 dn 90, 00, $443
160 endr
156 updown: 161 updown:
157 dn C4, 00, $105 162 dn C4, 00, $105
158 rept 31 163 rept 31
@@ -184,7 +189,8 @@ channel1:
184 channel_period1: dw 189 channel_period1: dw
185 toneporta_target1: dw 190 toneporta_target1: dw
186 channel_note1: db 191 channel_note1: db
187 ds 3 ;; Just padding at the moment but may contain more stuff later 192 vibrato_tremolo_phase1: db
193 ds 2 ;; Just padding at the moment but may contain more stuff later
188 194
189 ;;;;;;;;;;; 195 ;;;;;;;;;;;
190 ;;Channel 2 196 ;;Channel 2
@@ -193,7 +199,8 @@ channel2:
193 channel_period2: dw 199 channel_period2: dw
194 toneporta_target2: dw 200 toneporta_target2: dw
195 channel_note2: db 201 channel_note2: db
196 ds 3 202 vibrato_tremolo_phase2: db
203 ds 2
197 204
198 ;;;;;;;;;;; 205 ;;;;;;;;;;;
199 ;;Channel 3 206 ;;Channel 3
@@ -202,7 +209,8 @@ channel3:
202 channel_period3: dw 209 channel_period3: dw
203 toneporta_target3: dw 210 toneporta_target3: dw
204 channel_note3: db 211 channel_note3: db
205 ds 3 212 vibrato_tremolo_phase3: db
213 ds 2
206 214
207 ;;;;;;;;;;; 215 ;;;;;;;;;;;
208 ;;Channel 4 216 ;;Channel 4
@@ -211,7 +219,8 @@ channel4:
211 channel_period4: dw 219 channel_period4: dw
212 toneporta_target4: dw 220 toneporta_target4: dw
213 channel_note4: db 221 channel_note4: db
214 ds 3 222 vibrato_tremolo_phase4: db
223 ds 2
215 224
216 row: ds 1 225 row: ds 1
217 tick: ds 1 226 tick: ds 1
@@ -289,7 +298,7 @@ _addr = _addr + 1
289 ld a, [rSTAT] 298 ld a, [rSTAT]
290 or a, STATF_LYC 299 or a, STATF_LYC
291 ld [rSTAT], a 300 ld [rSTAT], a
292 ld a, 0 301 xor a ; ld a, 0
293 ld [rLYC], a 302 ld [rLYC], a
294 303
295 ld a, IEF_LCDC ; IEF_VBLANK; | IEF_LCDC ; IEF_HILO | IEF_TIMER 304 ld a, IEF_LCDC ; IEF_VBLANK; | IEF_LCDC ; IEF_HILO | IEF_TIMER
@@ -342,12 +351,11 @@ _lookup_note:
342 ld b, a 351 ld b, a
343 352
344 ld a, [hl] 353 ld a, [hl]
345 ld [channel_note2], a
346 354
347 _try_convert_note:
348 cp LAST_NOTE 355 cp LAST_NOTE
349 jp c, _convert_note 356 ret nc
350 ret 357
358 ld [channel_note2], a
351 359
352 _convert_note: 360 _convert_note:
353 ;; Call with: 361 ;; Call with:
@@ -356,10 +364,12 @@ _convert_note:
356 364
357 add a, a ;; double it to get index into hi/lo table 365 add a, a ;; double it to get index into hi/lo table
358 366
359 LD H, 0 367 ld hl, note_table
360 LD L, A 368 add_a_to_hl
361 LD DE, note_table 369 ; LD H, 0
362 ADD HL, DE 370 ; LD L, A
371 ; LD DE, note_table
372 ; ADD HL, DE
363 LD A, [HL+] 373 LD A, [HL+]
364 ;; INC HL 374 ;; INC HL
365 LD H, [HL] 375 LD H, [HL]
@@ -438,7 +448,7 @@ _playnote1:
438 448
439 ld a, h 449 ld a, h
440 ld [channel_period1+1], a 450 ld [channel_period1+1], a
441 or %00000000 451 or %10000000
442 ld [rAUD1HIGH], a 452 ld [rAUD1HIGH], a
443 453
444 ret 454 ret
@@ -469,7 +479,7 @@ _playnote2:
469 ld [rAUD2LOW], a 479 ld [rAUD2LOW], a
470 ld a, h 480 ld a, h
471 ld [channel_period2+1], a 481 ld [channel_period2+1], a
472 or %00000000 482 or %10000000
473 ld [rAUD2HIGH], a 483 ld [rAUD2HIGH], a
474 ret 484 ret
475 485
@@ -551,6 +561,8 @@ _doeffect:
551 sub l 561 sub l
552 ld h, a 562 ld h, a
553 563
564 ld b, e
565
554 jp hl 566 jp hl
555 567
556 .jump: 568 .jump:
@@ -559,7 +571,7 @@ _doeffect:
559 jp fx_porta_up ;1xy 571 jp fx_porta_up ;1xy
560 jp fx_porta_down ;2xy 572 jp fx_porta_down ;2xy
561 jp fx_toneporta ;3xy 573 jp fx_toneporta ;3xy
562 jp fx_no_op ;fx_vibrato ;4xy 574 jp fx_vibrato ;4xy
563 jp fx_no_op ;fx_toneporta_volslide ;5xy 575 jp fx_no_op ;fx_toneporta_volslide ;5xy
564 jp fx_no_op ;fx_vibrato_volslide ;6xy 576 jp fx_no_op ;fx_vibrato_volslide ;6xy
565 jp fx_no_op ;fx_tremolo ;7xy 577 jp fx_no_op ;fx_tremolo ;7xy
@@ -590,8 +602,110 @@ setup_channel_pointer:
590 fx_no_op: 602 fx_no_op:
591 ret 603 ret
592 604
605 fx_set_volume:
606 ;; B: channel
607 ;; C: effect parameters
608
609 ;; free registers: A, D, E, H, L
610
611
612
613 fx_vibrato:
614 ;; B: channel
615 ;; C: effect parameters
616
617 ;; free registers: A, D, E, H, L
618
619 ;; Extremely poor man's vibrato.
620 ;; Speed values:
621 ;; (0x0 = 1.0)
622 ;; (0x1 = 0.5)
623 ;; (0x3 = 0.25)
624 ;; (0x7 = 0.125)
625 ;; (0xf = 0.0625)
626 ld d, 4
627 call setup_channel_pointer
628
629 ld a, c
630 and %11110000
631 swap a
632 ld d, a
633
634 ld a, [tick]
635 and d
636 ld a, [hl]
637 jr z, .go_up
638 .restore:
639 call _convert_note
640 jr .finish_vibrato
641 .go_up:
642 call _convert_note
643 ld a, c
644 and %00001111
645 add_a_to_hl
646 .finish_vibrato:
647 ld d, h
648 ld e, l
649 jp _update_channel
650
651 ;; TODO: Come back and make this work later.
652
653 ; fx_vibrato2:
654 ; ld b, e ;; so we have access to DE
655 ; ;; B: channel
656 ; ;; C: effect parameters
657
658 ; ;; free registers: A, D, E, H, L
659
660 ; ;; This isn't really a sine vibrato, it's the same thing as ProTracker's
661 ; ;; "ramp down" setting, basically a sawtooth wave. Fortunately in most cases,
662 ; ;; this sounds exactly the same, and we don't need to store a sine table.
663
664 ; ;; Point at the vibrato phase
665 ; ld d, 5
666 ; call setup_channel_pointer
667
668 ; ld e, [hl]
669 ; inc [hl]
670 ; dec hl
671
672 ; ld a, [hl]
673 ; call _convert_note
674
675 ; ;; load D with speed
676 ; ld a, c
677 ; and %11110000
678 ; ld d, a
679 ; swap d
680
681 ; xor a ; ld a, 0
682
683 ; ;; Multiply E ("time") by D (speed) (at most 16 cycles...)
684 ; ;; TODO: Find faster multiplication?
685 ; .mult1:
686 ; add e
687 ; dec d
688 ; jr nz, .mult1
689
690 ; ;; Multiply by depth into a 16 bit value
691 ; ld e, a ; D is already empty
692 ; ; ld hl, 0
693
694 ; ;; Load E with depth
695 ; ld a, c
696 ; and %00001111
697 ; .mult2:
698 ; add hl, de
699 ; dec a
700 ; jr nz, .mult2
701
702 ; ld d, h
703 ; ld e, l
704
705 ; jp _update_channel
706
707
593 fx_arpeggio: 708 fx_arpeggio:
594 ld b, e ;; so we have access to DE
595 ;; B: channel 709 ;; B: channel
596 ;; C: effect parameters 710 ;; C: effect parameters
597 711
@@ -612,6 +726,7 @@ fx_arpeggio:
612 add_a_to_hl 726 add_a_to_hl
613 jp hl 727 jp hl
614 728
729 ;; TODO: Make this work when TICKS != 6
615 .arp_options: 730 .arp_options:
616 jr .set_arp1 731 jr .set_arp1
617 jr .set_arp2 732 jr .set_arp2
@@ -637,7 +752,6 @@ fx_arpeggio:
637 jp _update_channel 752 jp _update_channel
638 753
639 fx_porta_up: 754 fx_porta_up:
640 ld b, e ;; so we have access to DE
641 ;; B: channel 755 ;; B: channel
642 ;; C: effect parameters 756 ;; C: effect parameters
643 757
@@ -662,7 +776,6 @@ fx_porta_up:
662 ;; TODO: Maybe merge with fx_porta_up, since they're so similar? Would need 776 ;; TODO: Maybe merge with fx_porta_up, since they're so similar? Would need
663 ;; to find a way to compare against effect code. 777 ;; to find a way to compare against effect code.
664 fx_porta_down: 778 fx_porta_down:
665 ld b, e ;; so we have access to DE
666 ;; B: channel 779 ;; B: channel
667 ;; C: effect parameters 780 ;; C: effect parameters
668 781
@@ -686,7 +799,6 @@ fx_porta_down:
686 799
687 800
688 fx_toneporta: 801 fx_toneporta:
689 ld b, e ;; so we have access to DE
690 ;; B: channel 802 ;; B: channel
691 ;; C: effect parameters 803 ;; C: effect parameters
692 804
@@ -857,7 +969,7 @@ process_tick:
857 969
858 _newrow: 970 _newrow:
859 ;; Reset tick to 0 971 ;; Reset tick to 0
860 ld a, 0 972 xor a ; ld a, 0
861 ld [tick], a 973 ld [tick], a
862 974
863 ;; Increment row. 975 ;; Increment row.
@@ -873,14 +985,14 @@ _newrow:
873 add a, 2 985 add a, 2
874 cp b 986 cp b
875 jr nz, .update_current_order 987 jr nz, .update_current_order
876 ld a, 0 988 xor a ; ld a, 0
877 .update_current_order: 989 .update_current_order:
878 ld [current_order], a 990 ld [current_order], a
879 ld c, a 991 ld c, a
880 992
881 call _refresh_patterns 993 call _refresh_patterns
882 994
883 ld a, 0 995 xor a ; ld a, 0
884 ld [row], a 996 ld [row], a
885 reti 997 reti
886 998