forked from Rangi42/polishedcrystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusicplayer.asm
2147 lines (1973 loc) · 41.9 KB
/
musicplayer.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Written by Sanqui
; https://github.com/froggestspirit/CrystalComplete/blob/master/misc/musicplayer.asm
INCLUDE "includes.asm"
MP_METER0 EQU $20
MP_METER8 EQU $28
MP_DUTY0 EQU $29
SECTION "Music Player Graphics", ROMX
PianoGFX:
INCBIN "gfx/music_player/piano.2bpp"
MusicTestGFX: ; must come after PianoGFX
INCBIN "gfx/music_player/music_test.2bpp"
NotesGFX:
INCBIN "gfx/music_player/note_lines.2bpp"
WaveformsGFX:
INCBIN "gfx/music_player/waveforms.2bpp"
SECTION "Music Player", ROMX
jrbutton: macro
; assumes hl == hJoyPressed
ld a, [hl]
and \1
jr nz, \2
endm
jpbutton: macro
; assumes hl == hJoyPressed
ld a, [hl]
and \1
jp nz, \2
endm
jrheldbutton: macro
; assumes hl == hJoyDown
ld a, [TextDelayFrames]
and a
jr nz, .no\@
ld a, [hl]
and \1
jr z, .no\@
ld a, \3
ld [TextDelayFrames], a
jr \2
.no\@:
endm
jpheldbutton: macro
; assumes hl == hJoyDown
ld a, [TextDelayFrames]
and a
jr nz, .no\@
ld a, [hl]
and \1
jr z, .no\@
ld a, \3
ld [TextDelayFrames], a
jp \2
.no\@:
endm
MusicPlayerPals:
if !DEF(MONOCHROME)
; bg
RGB 02, 03, 04
RGB 02, 03, 04
RGB 10, 12, 14
RGB 26, 28, 30
; green
RGB 02, 03, 04
RGB 02, 03, 04
RGB 06, 26, 06
RGB 26, 28, 30
; blue
RGB 02, 03, 04
RGB 02, 03, 04
RGB 07, 07, 31
RGB 26, 28, 30
; red
RGB 02, 03, 04
RGB 02, 03, 04
RGB 31, 07, 07
RGB 26, 28, 30
else
rept 4
RGB_MONOCHROME_BLACK
RGB_MONOCHROME_BLACK
RGB_MONOCHROME_DARK
RGB_MONOCHROME_WHITE
endr
endc
MusicPlayerNotePals:
if !DEF(MONOCHROME)
RGB 02, 03, 04 ; bg
RGB 06, 26, 06 ; green
RGB 07, 07, 31 ; blue
RGB 31, 07, 07 ; red
else
RGB_MONOCHROME_BLACK
RGB_MONOCHROME_WHITE
RGB_MONOCHROME_DARK
RGB_MONOCHROME_LIGHT
endc
MusicPlayer::
di
call DoubleSpeed
xor a
ld [rIF], a
ld a, $f
ld [rIE], a
ei
call ClearTileMap
; Load palette
ld a, [rSVBK]
push af
ld a, 5
ld [rSVBK], a
ld hl, MusicPlayerPals
ld de, BGPals
ld bc, 4 palettes
call CopyBytes
ld hl, MusicPlayerNotePals
ld de, OBPals
ld bc, 1 palettes
call CopyBytes
pop af
ld [rSVBK], a
; Apply palettes
xor a
hlcoord 0, 0, AttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call ByteFill
hlcoord 3, 17, AttrMap
ld [hl], $3
hlcoord 8, 17, AttrMap
ld [hl], $2
hlcoord 12, 17, AttrMap
ld [hl], $1
inc hl
ld [hl], $1
call ApplyAttrMap
ld a, $1
ld [hCGBPalUpdate], a
; refresh top two portions
xor a
ld [hBGMapThird], a
call DelayFrame
; Load graphics
ld de, PianoGFX ;
lb bc, BANK(PianoGFX), 32 + 13 ; PianoGFX + MusicTestGFX
ld hl, VTiles2
call Request2bpp
ld de, NotesGFX
lb bc, BANK(NotesGFX), $80
ld hl, VTiles0
call Request2bpp
; Prerender all waveforms
; xor a
;.waveform_loop:
; push af
; call RenderWaveform
; pop af
; inc a
; cp NUM_WAVEFORMS
; jr nz, .waveform_loop
; Rendered waveforms would have difficulty filling their integrals with
; the dark hue. TPP Crystal dealt with this by doubling their width.
; Here we just use a static image.
ld de, WaveformsGFX
lb bc, BANK(WaveformsGFX), NUM_WAVEFORMS * 2
ld hl, VTiles2 tile $40
call Request2bpp
call DelayFrame
; Clear sprites
ld hl, rLCDC
set 7, [hl]
ei
call ClearSprites
; Initialize MusicPlayerWRAM
ld hl, MusicPlayerWRAM
ld bc, MusicPlayerWRAMEnd - MusicPlayerWRAM
xor a
call ByteFill
; Clear wMPNotes
ld a, [rSVBK]
push af
ld a, BANK(wMPNotes)
ld [rSVBK], a
xor a
ld hl, wMPNotes
ld bc, 4 * 256
call ByteFill
pop af
ld [rSVBK], a
; fallthrough
RenderMusicPlayer:
ld bc, SCREEN_WIDTH * MP_HUD_HEIGHT
ld hl, MPTilemap
decoord 0, PIANO_ROLL_HEIGHT
call CopyBytes
ld bc, 4 * 3
ld hl, NoteOAM
ld de, Sprites
call CopyBytes
call DelayFrame
xor a
ld [hOAMUpdate], a ; we will manually do it in LCD interrupt
ld hl, wChannelSelectorSwitches
ld a, NUM_MUSIC_CHANS - 1
.ch_label_loop:
ld [wChannelSelector], a
ld a, [hli]
push hl
call DrawChannelLabel
pop hl
ld a, [wChannelSelector]
dec a
cp -1
jr nz, .ch_label_loop
call DelayFrame
ld a, [rSVBK]
ld [hMPBuffer], a
ld a, [wSongSelection]
; let's see if a song is currently selected
cp NUM_SONGS
jr nc, .bad_selection
and a
jr nz, _RedrawMusicPlayer
.bad_selection
ld a, MUSIC_MAIN_MENU
; fallthrough
_RedrawMusicPlayer:
ld [wSongSelection], a
ld a, -1
ld [wChannelSelector], a
call DrawPianoRollOverlay
; fallthrough
MusicPlayerLoop:
ld a, $4
ld [rSVBK], a
call MPUpdateUIAndGetJoypad
ld hl, hJoyDown
jrheldbutton D_UP, .up, 12
jrheldbutton D_DOWN, .down, 12
jrheldbutton D_LEFT, .left, 12
jrheldbutton D_RIGHT, .right, 12
ld hl, hJoyPressed
jrbutton A_BUTTON, .a
jrbutton B_BUTTON, .b
jrbutton START, .start
jpbutton SELECT, .select
; prioritize refreshing the note display
ld a, 2
ld [hBGMapThird], a
jr MusicPlayerLoop
.left:
; previous song
ld a, [wSongSelection]
dec a
jp nz, _RedrawMusicPlayer
ld a, NUM_SONGS - 1
jp _RedrawMusicPlayer
.right:
; next song
ld a, [wSongSelection]
inc a
cp NUM_SONGS
jp nz, _RedrawMusicPlayer
ld a, 1
jp _RedrawMusicPlayer
.down:
; 10 songs back
ld a, [wSongSelection]
sub MP_LIST_PAGE_SKIP
jr z, .zerofix
cp NUM_SONGS
jp c, _RedrawMusicPlayer
.zerofix
ld a, NUM_SONGS - 1
jp _RedrawMusicPlayer
.up:
; 10 songs ahead
ld a, [wSongSelection]
add MP_LIST_PAGE_SKIP
cp NUM_SONGS
jp c, _RedrawMusicPlayer
ld a, 1
jp _RedrawMusicPlayer
.a:
; restart playing song
ld a, [wSongSelection]
ld e, a
ld d, 0
farcall PlayMusic2
ld hl, wChLastNotes
xor a
ld [hli], a
ld [hli], a
ld [hl], a
inc a
ld hl, wNoteEnded
ld [hli], a
ld [hli], a
ld [hl], a
jp MusicPlayerLoop
.b:
; exit music player
xor a
ld [hMPState], a
ld [hVBlank], a
ld a, [hMPBuffer]
ld [rSVBK], a
call ClearSprites
ld hl, rLCDC
res 2, [hl] ; 8x8 sprites
di
call NormalSpeed
xor a
ld [rIF], a
ld a, $f
ld [rIE], a
ei
ret
.start:
; open song selector
xor a
ld [hMPState], a
ld a, [hMPBuffer]
ld [rSVBK], a
call SongSelector
jp RenderMusicPlayer
.select:
xor a
ld [wChannelSelector], a
hlcoord 3, MP_HUD_TOP
ld a, "◀"
ld [hl], a
; fallthrough
SongEditor:
call MPUpdateUIAndGetJoypad
ld hl, hJoyDown
jrheldbutton D_UP, .up, 10
jpheldbutton D_DOWN, .down, 10
ld hl, hJoyPressed
jrbutton D_LEFT, .left
jrbutton D_RIGHT, .right
jrbutton A_BUTTON, .a
jpbutton START, .start
jpbutton SELECT | B_BUTTON, .select_b
; prioritize refreshing the note display
ld a, 2
ld [hBGMapThird], a
jr SongEditor
.left:
; previous editable field
call ClearChannelSelector
ld a, [wChannelSelector]
dec a
cp -1
jr nz, .no_underflow
ld a, NUM_MP_EDIT_FIELDS - 1 ; MP_EDIT_TEMPO
.no_underflow
ld [wChannelSelector], a
call DrawChannelSelector
jr SongEditor
.right:
; next editable field
call ClearChannelSelector
ld a, [wChannelSelector]
inc a
cp NUM_MP_EDIT_FIELDS
jr nz, .no_overflow
xor a ; ld a, MP_EDIT_CH1
.no_overflow
ld [wChannelSelector], a
call DrawChannelSelector
jp SongEditor
.a:
; for pitch: nothing
; for tempo: enter tempo adjustment mode
; otherwise: toggle editable field
ld a, [wChannelSelector]
cp MP_EDIT_PITCH
jp z, SongEditor
cp MP_EDIT_TEMPO
jp z, AdjustTempo
ld c, a
ld b, 0
ld hl, wChannelSelectorSwitches
add hl, bc
ld a, [hl]
xor 1
ld [hl], a
call DrawChannelLabel
jp SongEditor
.up:
; for ch1/ch2: next duty cycle
; for wave: next waveform
; for noise: next noise set
; for pitch: increase pitch transposition
ld a, [wChannelSelector]
ld hl, .up_jumptable
rst JumpTable
jp SongEditor
.up_jumptable
dw .up_ch1_2 ; MP_EDIT_CH1
dw .up_ch1_2 ; MP_EDIT_CH2
dw .up_wave ; MP_EDIT_WAVE
dw .up_noise ; MP_EDIT_NOISE
dw .up_pitch ; MP_EDIT_PITCH
dw .return ; MP_EDIT_TEMPO
.down:
; for ch1/ch2: previous duty cycle
; for wave: previous waveform
; for noise: previous noise set
; for pitch: decrease pitch transposition
ld a, [wChannelSelector]
ld hl, .down_jumptable
rst JumpTable
jp SongEditor
.down_jumptable:
dw .down_ch1_2 ; MP_EDIT_CH1
dw .down_ch1_2 ; MP_EDIT_CH2
dw .down_wave ; MP_EDIT_WAVE
dw .down_noise ; MP_EDIT_NOISE
dw .down_pitch ; MP_EDIT_PITCH
dw .return ; MP_EDIT_TEMPO
.start:
; toggle piano roll info overlay
ld hl, wSongInfoSwitch
ld a, [hl]
xor 1
ld [hl], a
call DrawPianoRollOverlay
jp SongEditor
.select_b:
; exit song editor
call ClearChannelSelector
xor a ; ld a, MP_EDIT_CH1
ld [wChannelSelector], a
call DrawPitchTransposition
call DrawTempoAdjustment
jp MusicPlayerLoop
.up_ch1_2:
; next duty cycle
ld a, [wChannelSelector]
ld [wTmpCh], a
call GetDutyCycleAddr
ld a, [hl]
lb bc, %11000000, %01000000
and b
cp b
ld a, [hl]
jr nz, .no_ch1_2_overflow
and %00111111
sub c
.no_ch1_2_overflow
add c
jr .change_ch1_2
.down_ch1_2:
; previous duty cycle
ld a, [wChannelSelector]
ld [wTmpCh], a
call GetDutyCycleAddr
ld a, [hl]
lb bc, %11000000, %01000000
and b
and a
ld a, [hl]
jr nz, .no_ch1_2_underflow
add c
and %00111111
.no_ch1_2_underflow
sub c
.change_ch1_2:
ld [hl], a
ld [wCurTrackDuty], a
ret
.up_wave:
; next waveform
ld a, [Channel3Intensity]
and $f
inc a
cp NUM_WAVEFORMS
jr nz, .change_wave
xor a
jr .change_wave
.down_wave:
; previous waveform
ld a, [Channel3Intensity]
and $f
dec a
cp -1
jr nz, .change_wave
ld a, NUM_WAVEFORMS - 1
.change_wave:
ld b, a
ld a, [Channel3Intensity]
and $f0
or b
ld [Channel3Intensity], a
ld [wCurTrackIntensity], a
farcall ReloadWaveform
ret
.up_noise:
; next noise set
ld a, [MusicNoiseSampleSet]
inc a
cp NUM_NOISE_SETS
jr nz, .change_noise
xor a
jr .change_noise
.down_noise:
; previous noise set
ld a, [MusicNoiseSampleSet]
dec a
cp -1
jr nz, .change_noise
ld a, NUM_NOISE_SETS - 1
.change_noise:
ld [MusicNoiseSampleSet], a
.return:
ret
.up_pitch:
; increase pitch transposition
ld a, [wPitchTransposition]
inc a
cp MAX_PITCH_TRANSPOSITION + 1
jr nz, .change_pitch
ld a, -MAX_PITCH_TRANSPOSITION
jr .change_pitch
.down_pitch:
; decrease pitch transposition
ld a, [wPitchTransposition]
dec a
cp -(MAX_PITCH_TRANSPOSITION + 1)
jr nz, .change_pitch
ld a, MAX_PITCH_TRANSPOSITION
.change_pitch:
ld [wPitchTransposition], a
call DrawPitchTransposition
; refresh top two portions
xor a
ld [hBGMapThird], a
jp DelayFrame
AdjustTempo:
ld a, 1
ld [wAdjustingTempo], a
ld a, [wTempoAdjustment]
ld [wTmpValue], a
call DrawChannelSelector
; refresh top two portions
xor a
ld [hBGMapThird], a
call DelayFrame
.loop:
call MPUpdateUIAndGetJoypad
ld hl, hJoyDown
jrheldbutton D_UP, .up, 6
jrheldbutton D_DOWN, .down, 6
jrheldbutton D_RIGHT, .right, 18
jrheldbutton D_LEFT, .left, 18
ld hl, hJoyPressed
jrbutton A_BUTTON, .a
jrbutton B_BUTTON, .b
jrbutton START, .start
; prioritize refreshing the note display
ld a, 2
ld [hBGMapThird], a
jr .loop
.up:
; increase tempo adjustment
ld a, [wTempoAdjustment]
inc a
cp MAX_TEMPO_ADJUSTMENT + 1
jr nz, .change_tempo
ld a, -MAX_TEMPO_ADJUSTMENT
jr .change_tempo
.down:
; decrease tempo adjustment
ld a, [wTempoAdjustment]
dec a
cp -(MAX_TEMPO_ADJUSTMENT + 1)
jr nz, .change_tempo
ld a, MAX_TEMPO_ADJUSTMENT
jr .change_tempo
.right:
; increase tempo adjustment by 10
ld a, [wTempoAdjustment]
cp MAX_TEMPO_ADJUSTMENT - 10 + 1
jr c, .no_overflow_right
cp -MAX_TEMPO_ADJUSTMENT
jr nc, .no_overflow_right
ld a, MAX_TEMPO_ADJUSTMENT - 10
.no_overflow_right
add 10
jr .change_tempo
.left:
; decrease tempo adjustment by 10
ld a, [wTempoAdjustment]
cp MAX_TEMPO_ADJUSTMENT + 1
jr c, .no_underflow_left
cp -(MAX_TEMPO_ADJUSTMENT - 10)
jr nc, .no_underflow_left
ld a, -(MAX_TEMPO_ADJUSTMENT - 10)
.no_underflow_left
sub 10
.change_tempo:
ld [wTempoAdjustment], a
call DrawTempoAdjustment
; refresh top two portions
xor a
ld [hBGMapThird], a
call DelayFrame
jp .loop
.a:
; apply tempo adjustment and exit tempo adjustment mode
ld a, [wSongSelection]
ld e, a
ld d, 0
farcall PlayMusic2
jr .exit
.b:
; discard adjustment and exit tempo adjustment mode
ld a, [wTmpValue]
ld [wTempoAdjustment], a
.exit:
xor a
ld [wAdjustingTempo], a
call DrawChannelSelector
call DrawTempoAdjustment
; refresh top two portions
xor a
ld [hBGMapThird], a
call DelayFrame
jp SongEditor
.start:
; toggle piano roll info overlay
ld hl, wSongInfoSwitch
ld a, [hl]
xor 1
ld [hl], a
call DrawPianoRollOverlay
jp .loop
DrawPianoRollOverlay:
; if this takes too long, don't let the user see blank fields blink in
; disable copying the map during vblank
ld a, 2
ld [hVBlank], a
ld a, " "
hlcoord 0, 0
ld bc, SCREEN_WIDTH * PIANO_ROLL_HEIGHT
call ByteFill
call DrawSongInfo
call DrawChannelSelector
ld a, 5
ld [hVBlank], a
; refresh top two portions
xor a
ld [hBGMapThird], a
jp DelayFrame
DrawPitchTransposition:
hlcoord 15, 1
ld de, _EmptyPitchOrTempo
call PlaceString
ld a, [wChannelSelector]
cp MP_EDIT_PITCH
ld a, [wPitchTransposition]
jr z, .continue
and a
ret z
.continue
ld [hl], "P"
inc hl
lb bc, PRINTNUM_RIGHTALIGN | 1, 2
ld de, wPitchTransposition
jr _PrintSignedNum
DrawTempoAdjustment:
hlcoord 15, 2
ld de, _EmptyPitchOrTempo
call PlaceString
ld a, [wChannelSelector]
cp MP_EDIT_TEMPO
ld a, [wTempoAdjustment]
jr z, .continue
and a
ret z
.continue
ld [hl], "T"
inc hl
lb bc, PRINTNUM_RIGHTALIGN | 1, 3
ld de, wTempoAdjustment
_PrintSignedNum:
bit 7, a
jr nz, .negative
ld a, "+"
jr .printnum
.negative
cpl
inc a
ld de, wTmpValue
ld [de], a
ld a, "-"
.printnum
ld [hli], a
jp PrintNum
_EmptyPitchOrTempo: db " @"
DrawChannelSelector:
call DrawPitchTransposition
call DrawTempoAdjustment
ld a, [wChannelSelector]
cp -1
ret z
cp MP_EDIT_PITCH
jr z, .pitch
cp MP_EDIT_TEMPO
jr z, .tempo
call _LocateChannelSelector
ld [hl], "◀"
ret
.pitch:
hlcoord 14, 1
jr .draw
.tempo:
hlcoord 14, 2
.draw
ld a, [wAdjustingTempo]
and a
ld a, "▶"
jr z, .ok
ld a, "▷"
.ok
ld [hl], a
ret
ClearChannelSelector:
ld a, [wChannelSelector]
cp MP_EDIT_PITCH
jr z, .pitch
cp MP_EDIT_TEMPO
jr z, .tempo
call _LocateChannelSelector
ld [hl], $1e
call DrawPitchTransposition
jr DrawTempoAdjustment
.pitch:
hlcoord 14, 1
jr .clear
.tempo:
hlcoord 14, 2
.clear
ld [hl], " "
ret
_LocateChannelSelector:
ld c, 5
call SimpleMultiply
hlcoord 3, MP_HUD_TOP
add l
ld l, a
ret nc
inc h
ret
DrawChannelLabel:
and a
jr nz, .off
ld de, ChannelsOnTilemaps
jr .draw
.off
ld de, ChannelsOffTilemaps
.draw
ld a, [wChannelSelector]
ld l, a
ld h, 0
add hl
add l
ld l, a
add hl, de
push hl
hlcoord 0, MP_HUD_TOP
ld a, [wChannelSelector]
ld c, 5
call SimpleMultiply
ld e, a
ld d, 0
add hl, de
push hl
pop de
pop hl
rept 3
ld a, [hli]
ld [de], a
inc de
endr
ret
DrawChData:
hlcoord 0, MP_HUD_TOP + 1
.loop:
ld [wTmpCh], a
call _DrawCh1_2_3
inc a
ld de, 2
add hl, de
cp CHAN4
jr c, .loop
; channel 4
hlcoord 18, MP_HUD_TOP + 1
ld a, [MusicNoiseSampleSet]
add "0"
ld [hl], a
hlcoord 17, MP_HUD_TOP + 2
ld a, [wChannelSelectorSwitches + CHAN4]
and a
jr nz, .blank_hit
ld a, [wNoiseHit]
and a
jr z, .blank_hit
ld a, MP_METER8
jr .got_hit
.blank_hit
ld a, " "
.got_hit
ld [hl], a
xor a
ld [wNoiseHit], a
ret
_DrawCh1_2_3:
push af
push hl
call CheckChannelOn
ld a, 0
ld hl, NoteNames
jr c, .blank_note_name
call GetPitchAddr
ld a, [hl]
ld hl, NoteNames
call GetNthString
.blank_note_name
ld e, l
ld d, h
pop hl
push hl
call PlaceString
call GetOctaveAddr
ld d, [hl]
ld a, "8"
sub d
pop hl
inc hl
inc hl
ld [hli], a
ld a, [wTmpCh]
cp CHAN3
jr nc, .no_duty_cycle
push hl
ld de, SCREEN_WIDTH
add hl, de
push hl
call GetDutyCycleAddr
ld a, [hl]
pop hl
and %11000000
swap a
srl a
srl a
add MP_DUTY0
ld [hl], a
pop hl
.no_duty_cycle
push hl
dec hl
dec hl
dec hl
ld a, MP_METER0
ld de, SCREEN_WIDTH
add hl, de
ld [hli], a
ld [hld], a
push hl
call CheckChannelOn
pop hl
ld a, 0 ; not xor a; preserve carry flag
jr c, .blank_volume
push hl
call GetPitchAddr
ld a, [hl]
and a
pop hl
ld a, 0 ; not xor a; preserve carry flag
jr z, .blank_volume
push hl
call GetIntensityAddr
ld a, [hl]
pop hl
.blank_volume
and $f
srl a
add MP_METER0
ld [hli], a
ld [hld], a
ld a, [wTmpCh]
cp 2
jr nz, .finish
hlcoord 12, MP_HUD_TOP + 2
; pick the waveform