-
Notifications
You must be signed in to change notification settings - Fork 0
/
GBMod_Player.asm
2112 lines (2031 loc) · 42.9 KB
/
GBMod_Player.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
; ================================================================
; XM2GB replay routine
; ================================================================
; NOTE: For best results, place player code in ROM0.
; ===========
; Player code
; ===========
section "GBMod",rom0
GBMod:
GBM_LoadModule: jp GBMod_LoadModule
GBM_Update: jp GBMod_Update
GBM_Stop: jp GBMod_Stop
; db "XM2GB by DevEd | email: deved8@gmail.com"
; ================================
GBMod_LoadModule:
push af
push bc
push hl
di
ld [GBM_SongID],a
xor a
ld hl,GBM_RAM_Start+1
ld b,(GBM_RAM_End-GBM_RAM_Start+1)-2
.clearloop
ld [hl+],a
dec b
jr nz,.clearloop
inc a
ld [GBM_ModuleTimer],a
ld [GBM_TickTimer],a
ldh [rNR52],a ; disable sound (clears all sound registers)
or $80
ldh [rNR52],a ; enable sound
or $7f
ldh [rNR51],a ; all channels to SO1+SO2
xor %10001000
ldh [rNR50],a ; master volume 7
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
ld hl,$4000
ld a,[hl+]
ld [GBM_PatternCount],a
ld a,[hl+]
ld [GBM_PatTableSize],a
ld a,[hl+]
ld [GBM_ModuleSpeed],a
ld a,[hl+]
ld [GBM_TickSpeed],a
ld a,[hl+]
ld [GBM_SongDataOffset],a
ld a,[hl]
ld [GBM_SongDataOffset+1],a
ld a,$ff
ld [GBM_LastWave],a
ld a,1
ld [GBM_DoPlay],a
ld [GBM_CmdTick1],a
ld [GBM_CmdTick2],a
ld [GBM_CmdTick3],a
ld [GBM_CmdTick4],a
sub 2
ld [GBM_PanFlags],a
pop hl
pop bc
pop af
reti
; ================================
GBMod_Stop:
xor a
ld hl,GBM_RAM_Start
ld b,GBM_RAM_End-GBM_RAM_Start
.clearloop
ld [hl+],a
dec b
jr nz,.clearloop
ldh [rNR52],a ; disable sound (clears all sound registers)
or $80
ldh [rNR52],a ; enable sound
or $7f
ldh [rNR51],a ; all channels to SO1+SO2
xor %10001000
ldh [rNR50],a ; master volume 7
ret
; ================================
GBMod_Update:
ld a,[GBM_DoPlay]
and a
ret z
; anything that needs to be updated on a per-frame basis should be put here
ld e,0
call GBMod_DoVib ; pulse 1 vibrato
inc e
call GBMod_DoVib ; pulse 2 vibrato
inc e
call GBMod_DoVib ; pulse 3 vibrato
; sample playback
ld a,[GBM_SamplePlaying]
and a
call nz,GBMod_UpdateSample
ld a,[GBM_TickTimer]
dec a
ld [GBM_TickTimer],a
ret nz
ld a,[GBM_TickSpeed]
ld [GBM_TickTimer],a
ld a,[GBM_ModuleTimer]
dec a
ld [GBM_ModuleTimer],a
jp nz,GBMod_UpdateCommands
xor a
ld [GBM_SpeedChanged],a
ld a,[GBM_ModuleSpeed]
ld [GBM_ModuleTimer],a
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
ld hl,GBM_SongDataOffset
ld a,[hl+]
ld b,a
ld a,[hl]
add $40
ld h,a
ld l,b
; get pattern offset
ld a,[GBM_CurrentPattern]
and a
jr z,.getRow
add a
add a
add h
ld h,a
.getRow
ld a,[GBM_CurrentRow]
and a
jr z,.readPatternData
ld b,a
swap a
and $f0
ld e,a
ld a,b
swap a
and $0f
ld d,a
add hl,de
.readPatternData
; ch1 note
ld a,[hl+]
push af
cp $ff
jr z,.skip1
cp $fe
jr nz,.nocut1
xor a
ld [GBM_Vol1],a
.nocut1
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset1
cp 2
jr z,.noreset1
call GBM_ResetFreqOffset1
.noreset1
pop af
.freq1
ld [GBM_Note1],a
ld e,0
call GBMod_GetFreq2
; ch1 volume
ld a,[GBM_SkipCH1]
and a
jr nz,.skipvol1
ld a,[GBM_Command1]
cp $a
jr z,.skipvol1
ld a,[hl]
swap a
and $f
jr z,.skipvol1
ld b,a
rla
rla
rla
ld [GBM_Vol1],a
ld a,b
swap a
ldh [rNR12],a
set 7,e
.skipvol1
; ch1 pulse
ld a,[hl+]
ld b,a
ld a,[GBM_SkipCH1]
and a
jr nz,.skippulse1
ld a,b
and $f
jr z,.skippulse1
dec a
ld [GBM_Pulse1],a
swap a
rla
rla
ldh [rNR11],a
.skippulse1
; ch1 command
ld a,[hl+]
ld [GBM_Command1],a
; ch1 param
ld a,[hl+]
ld [GBM_Param1],a
; update freq
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jr .ch2
.skip1
pop af
ld a,[GBM_Note1]
jr .freq1
.ch2
; ch2 note
ld a,[hl+]
push af
cp $ff
jr z,.skip2
cp $fe
jr nz,.nocut2
xor a
ld [GBM_Vol2],a
.nocut2
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset2
cp 2
jr z,.noreset2
call GBM_ResetFreqOffset2
.noreset2
pop af
.freq2
ld [GBM_Note2],a
ld e,1
call GBMod_GetFreq2
; ch2 volume
ld a,[GBM_SkipCH2]
and a
jr nz,.skipvol2
ld a,[GBM_Command2]
cp $a
jr z,.skipvol2
ld a,[hl]
swap a
and $f
jr z,.skipvol2
ld b,a
rla
rla
rla
ld [GBM_Vol2],a
ld a,b
swap a
ldh [rNR22],a
set 7,e
.skipvol2
; ch2 pulse
ld a,[hl+]
ld b,a
ld a,[GBM_SkipCH2]
and a
jr nz,.skippulse2
ld a,b
and $f
jr z,.skippulse2
dec a
ld [GBM_Pulse2],a
swap a
rla
rla
ldh [rNR21],a
.skippulse2
; ch2 command
ld a,[hl+]
ld [GBM_Command2],a
; ch2 param
ld a,[hl+]
ld [GBM_Param2],a
; update freq
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jr .ch3
.skip2
pop af
ld a,[GBM_Note2]
jr .freq2
.ch3
; ch3 note
ld a,[GBM_SamplePlaying]
and a
jp nz,.sample3
.note3
ld a,[hl+]
push af
cp $ff
jr z,.skip3
cp $fe
jr nz,.nocut3
xor a
ld [GBM_Vol3],a
.nocut3
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset3
cp 2
jr z,.noreset3
call GBM_ResetFreqOffset3
.noreset3
pop af
cp $80
jr z,.playsample3
.freq3
ld [GBM_Note3],a
ld e,2
call GBMod_GetFreq2
; ch3 volume
ld a,[hl]
swap a
and $f
jr z,.skipvol3
ld [GBM_Vol3],a
call GBMod_GetVol3
ld b,a
ld a,[GBM_OldVol3]
cp b
jr z,.skipvol3
ld a,[GBM_SkipCH3]
and a
jr nz,.skipvol3
ld a,b
ldh [rNR32],a
set 7,e
.skipvol3
ld [GBM_OldVol3],a
; ch3 wave
ld a,[hl+]
dec a
and $f
cp 15
jr z,.continue3
ld b,a
ld a,[GBM_LastWave]
cp b
jr z,.continue3
ld a,b
ld [GBM_Wave3],a
ld [GBM_LastWave],a
push hl
call GBM_LoadWave
set 7,e
pop hl
.continue3
; ch3 command
ld a,[hl+]
ld [GBM_Command3],a
; ch3 param
ld a,[hl+]
ld [GBM_Param3],a
; update freq
ld a,[GBM_SkipCH3]
and a
jr nz,.ch4
ld a,d
ldh [rNR33],a
ld a,e
ldh [rNR34],a
jr .ch4
.skip3
pop af
ld a,[GBM_Note3]
jr .freq3
.playsample3
ld a,[hl+]
call GBMod_PlaySample
jr .continue3
.sample3
ld a,[hl]
cp $ff
jr z,.nostopsample3
xor a
ld [GBM_SamplePlaying],a
jp .note3
.nostopsample3
ld a,l
add 4
ld l,a
jr nc,.ch4
inc h
.ch4
; ch4 note
ld a,[hl+]
cp $ff
jr z,.skip4
cp $fe
jr nz,.freq4
xor a
ld [GBM_Vol4],a
.freq4
ld [GBM_Note4],a
push hl
ld hl,NoiseTable
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl+]
ld d,a
pop hl
; ch4 volume
ld a,[GBM_SkipCH4]
and a
jr nz,.skipvol4
inc hl
ld a,[hl]
dec hl
cp $a
jr nz,.disablecmd4
.dovol4
ld a,[hl]
swap a
and $f
ld b,a
rla
rla
rla
ld [GBM_Vol4],a
ld a,b
swap a
ldh [rNR42],a
jr .skipvol4
.disablecmd4
xor a
ld [GBM_Command4],a
jr .dovol4
.skipvol4
; ch4 mode
ld a,[hl+]
and a
jr z,.nomode
dec a
and 1
ld [GBM_Mode4],a
and a
jr z,.nomode
set 3,d
.nomode
; ch4 command
ld a,[hl+]
ld [GBM_Command4],a
; ch4 param
ld a,[hl+]
ld [GBM_Param4],a
; set freq
ld a,[GBM_SkipCH4]
and a
jr nz,.updateRow
ld a,d
ldh [rNR43],a
ld a,$80
ldh [rNR44],a
jr .updateRow
.skip4
ld a,[GBM_Note4]
jr .freq4
.updateRow
call GBM_ResetCommandTick
ld a,[GBM_CurrentRow]
inc a
cp 64
jr z,.nextPattern
ld [GBM_CurrentRow],a
jr .done
.nextPattern
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld b,a
ld a,[GBM_PatTableSize]
cp b
jr z,.loopSong
ld a,b
ld [GBM_PatTablePos],a
jr .setPattern
.loopSong
xor a
ld [GBM_PatTablePos],a
.setPattern
ld hl,$40f0
add l
ld l,a
ld a,[hl+]
ld [GBM_CurrentPattern],a
.done
GBMod_UpdateCommands:
ld a,$ff
ld [GBM_PanFlags],a
; ch1
ld a,[GBM_Command1]
ld hl,.commandTable1
add a
add l
ld l,a
jr nc,.nocarry1
inc h
.nocarry1
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable1
dw .arp1 ; 0xy - arp
dw .slideup1 ; 1xy - note slide up
dw .slidedown1 ; 2xy - note slide down
dw .ch2 ; 3xy - portamento (NYI)
dw .ch2 ; 4xy - vibrato (handled elsewhere)
dw .ch2 ; 5xy - portamento + volume slide (NYI)
dw .ch2 ; 6xy - vibrato + volume slide (NYI)
dw .ch2 ; 7xy - tremolo (NYI)
dw .pan1 ; 8xy - panning
dw .ch2 ; 9xy - sample offset (won't be implemented)
dw .volslide1 ; Axy - volume slide
dw .patjump1 ; Bxy - pattern jump
dw .ch2 ; Cxy - set volume (won't be implemented)
dw .patbreak1 ; Dxy - pattern break
dw .ch2 ; Exy - extended commands (NYI)
dw .speed1 ; Fxy - set module speed
.arp1
ld a,[GBM_Param1]
and a
jp z,.ch2
ld a,[GBM_ArpTick1]
inc a
cp 4
jr nz,.noresetarp1
ld a,1
.noresetarp1
ld [GBM_ArpTick1],a
ld a,[GBM_Param1]
ld b,a
ld a,[GBM_Note1]
ld c,a
ld a,[GBM_ArpTick1]
dec a
call GBMod_DoArp
ld a,[GBM_SkipCH1]
and a
jp nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jp .ch2
.slideup1
ld a,[GBM_Param1]
ld b,a
ld e,0
call GBMod_DoPitchSlide
ld a,[GBM_Note1]
call GBMod_GetFreq2
jp .dosetfreq1
.slidedown1
; read tick speed
ld a,[GBM_Param1]
ld b,a
ld e,0
call GBMod_DoPitchSlide
ld a,[GBM_Note1]
call GBMod_GetFreq2
jp .dosetfreq1
.pan1
ld a,[GBM_Param1]
cpl
and $11
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .ch2
.patbreak1
ld a,[GBM_Param1]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command1],a
ld [GBM_Param1],a
jp .done
.patjump1
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param1]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command1],a
ld [GBM_Param1],a
jp .done
.volslide1
ld a,[GBM_ModuleSpeed]
ld b,a
ld a,[GBM_ModuleTimer]
cp b
jr z,.ch2 ; skip first tick
ld a,[GBM_Param1]
cp $10
jr c,.volslide1_dec
.volslide1_inc
swap a
and $f
ld b,a
ld a,[GBM_Vol1]
add b
jr .volslide1_nocarry
.volslide1_dec
ld b,a
ld a,[GBM_Vol1]
sub b
jr nc,.volslide1_nocarry
xor a
.volslide1_nocarry
ld [GBM_Vol1],a
rra
rra
rra
and $f
ld b,a
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,b
swap a
ld [rNR12],a
ld a,[GBM_Note1]
call GBMod_GetFreq
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
or $80
ldh [rNR14],a
jr .ch2
.dosetfreq1
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jr .ch2
.speed1
ld a,[GBM_SpeedChanged]
and a
jr nz,.ch2
ld a,[GBM_Param1]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.ch2
ld a,[GBM_Command1]
cp 4
jr nz,.novib1
ld a,[GBM_Note1]
call GBMod_GetFreq
ld h,d
ld l,e
ld a,[GBM_FreqOffset1]
add h
ld h,a
jr nc,.continue1
inc l
.continue1
ld a,[GBM_SkipCH1]
and a
jr nz,.novib1
ld a,h
ldh [rNR13],a
ld a,l
ldh [rNR14],a
.novib1
ld a,[GBM_Command2]
ld hl,.commandTable2
add a
add l
ld l,a
jr nc,.nocarry2
inc h
.nocarry2
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable2
dw .arp2 ; 0xy - arp
dw .slideup2 ; 1xy - note slide up
dw .slidedown2 ; 2xy - note slide down
dw .ch3 ; 3xy - portamento (NYI)
dw .ch3 ; 4xy - vibrato (handled elsewhere)
dw .ch3 ; 5xy - portamento + volume slide (NYI)
dw .ch3 ; 6xy - vibrato + volume slide (NYI)
dw .ch3 ; 7xy - tremolo (NYI)
dw .pan2 ; 8xy - panning
dw .ch3 ; 9xy - sample offset (won't be implemented)
dw .volslide2 ; Axy - volume slide
dw .patjump2 ; Bxy - pattern jump
dw .ch3 ; Cxy - set volume (won't be implemented)
dw .patbreak2 ; Dxy - pattern break
dw .ch3 ; Exy - extended commands (NYI)
dw .speed2 ; Fxy - set module speed
.arp2
ld a,[GBM_Param2]
and a
jp z,.ch3
ld a,[GBM_ArpTick2]
inc a
cp 4
jr nz,.noresetarp2
ld a,1
.noresetarp2
ld [GBM_ArpTick2],a
ld a,[GBM_Param2]
ld b,a
ld a,[GBM_Note2]
ld c,a
ld a,[GBM_ArpTick2]
dec a
call GBMod_DoArp
ld a,[GBM_SkipCH2]
and a
jp nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jp .ch3
.slideup2
ld a,[GBM_Param2]
ld b,a
ld e,1
call GBMod_DoPitchSlide
ld a,[GBM_Note2]
call GBMod_GetFreq2
jp .dosetfreq2
.slidedown2
; read tick speed
ld a,[GBM_Param2]
ld b,a
ld e,1
call GBMod_DoPitchSlide
ld a,[GBM_Note2]
call GBMod_GetFreq2
jp .dosetfreq2
.pan2
ld a,[GBM_Param2]
cpl
and $11
rla
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .ch3
.patbreak2
ld a,[GBM_Param2]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command2],a
ld [GBM_Param2],a
jp .done
.patjump2
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param2]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command2],a
ld [GBM_Param2],a
jp .done
.volslide2
ld a,[GBM_ModuleSpeed]
ld b,a
ld a,[GBM_ModuleTimer]
cp b
jr z,.ch3 ; skip first tick
ld a,[GBM_Param2]
cp $10
jr c,.volslide2_dec
.volslide2_inc
swap a
and $f
ld b,a
ld a,[GBM_Vol2]
add b
jr .volslide2_nocarry
.volslide2_dec
ld b,a
ld a,[GBM_Vol2]
sub b
jr nc,.volslide2_nocarry
xor a
.volslide2_nocarry
ld [GBM_Vol2],a
rra
rra
rra
and $f
ld b,a
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,b
swap a
ld [rNR22],a
ld a,[GBM_Note2]
call GBMod_GetFreq
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
or $80
ldh [rNR24],a
jr .ch3
.dosetfreq2
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jr .ch3
.speed2
ld a,[GBM_SpeedChanged]
and a
jr nz,.ch3
ld a,[GBM_Param2]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.ch3
ld a,[GBM_Command2]
cp 4
jr nz,.novib2
ld a,[GBM_Note2]
call GBMod_GetFreq
ld h,d
ld l,e
ld a,[GBM_FreqOffset2]
add h
ld h,a
jr nc,.continue2
inc l
.continue2
ld a,[GBM_SkipCH2]
and a
jr nz,.novib2
ld a,h
ldh [rNR23],a
ld a,l
ldh [rNR24],a
.novib2
ld a,[GBM_Command3]
ld hl,.commandTable3
add a
add l
ld l,a
jr nc,.nocarry3
inc h
.nocarry3
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable3
dw .arp3 ; 0xy - arp
dw .slideup3 ; 1xy - note slide up
dw .slidedown3 ; 2xy - note slide down
dw .ch4 ; 3xy - portamento (NYI)
dw .ch4 ; 4xy - vibrato (handled elsewhere)
dw .ch4 ; 5xy - portamento + volume slide (NYI)
dw .ch4 ; 6xy - vibrato + volume slide (NYI)
dw .ch4 ; 7xy - tremolo (doesn't apply for CH3)
dw .pan3 ; 8xy - panning
dw .ch4 ; 9xy - sample offset (won't be implemented)
dw .ch4 ; Axy - volume slide (doesn't apply for CH3)
dw .patjump3 ; Bxy - pattern jump
dw .ch4 ; Cxy - set volume (won't be implemented)
dw .patbreak3 ; Dxy - pattern break
dw .ch4 ; Exy - extended commands (NYI)
dw .speed3 ; Fxy - set module speed
.arp3
ld a,[GBM_Param3]
and a
jp z,.ch4
ld a,[GBM_ArpTick3]
inc a
cp 4
jr nz,.noresetarp3
ld a,1
.noresetarp3
ld [GBM_ArpTick3],a
ld a,[GBM_Param3]
ld b,a
ld a,[GBM_Note3]
ld c,a
ld a,[GBM_ArpTick3]
dec a