This repository was archived by the owner on Sep 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGBMod_Player.asm
More file actions
2170 lines (2049 loc) · 55.6 KB
/
GBMod_Player.asm
File metadata and controls
2170 lines (2049 loc) · 55.6 KB
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
; ================================================================
; GBMod replay routine
; ================================================================
; ===================
; Compatibility flags
; ===================
; Whether or not to use "zombie mode" for volume.
; This makes SFX integration non-trivial and additionally
; may not work on all hardware models or emulators.
; CURRENTLY BROKEN - DO NOT USE
def USE_ZOMBIE_MODE = 0
; Whether or not to allow playback of songs larger than a single ROM bank.
; This will result in slightly increased CPU usage, and a small CPU
; usage spike whenever a ROM bank boundary is crossed.
def ENABLE_BIG_SONGS = 1
; ===========
; Player code
; ===========
section "GBMod",rom0
GBMod:
GBM_LoadModule: jp GBMod_LoadModule
GBM_Update: jp GBMod_Update
GBM_Stop: jp GBMod_Stop
; ================================
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
if USE_ZOMBIE_MODE
; zombie mode init
ld a,$F0
ldh [rNR12],a
ldh [rNR22],a
ldh [rNR42],a
ldh [rNR14],a
ldh [rNR24],a
ldh [rNR44],a
ld a,$18
ldh [rNR12],a
ldh [rNR22],a
ldh [rNR44],a
endc
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,[hl+]
and a
jr z,.vblank
.timer
ldh [rTMA],a
ldh [rTIMA],a
ld a,[hl]
ldh [rTAC],a
ld a,1
ld [GBM_EnableTimer],a
jr :+
.vblank
xor a
ldh [rTMA],a
ldh [rTIMA],a
ldh [rTAC],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
ld a,$ff
ld [GBM_PanFlags],a
ld a,[$40f0]
ld [GBM_CurrentPattern],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
; adjust timing for GBC double speed
ld a,[GBM_EnableTimer]
and a
jr z,:+ ; skip ahead if timer is disabled
ldh a,[rKEY1]
cp $ff
jr z,:+ ; if KEY1 returns $FF, we're not on GBC - bail out
bit 7,a
jr z,:+ ; if bit 7 of KEY1 is 0, double speed mode is off - bail out
ld hl,GBM_OddTick
inc [hl]
bit 0,[hl]
ret z
:
; anything that needs to be updated on a per-frame basis should be put here
ld e,0
call GBMod_DoModulation ; pulse 1 vibrato + tremolo
inc e
call GBMod_DoModulation ; pulse 2 vibrato + tremolo
inc e
call GBMod_DoModulation ; wave vibrato
; inc e
; call GBMod_DoModulation ; noise tremolo
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
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
bit 7,a
jr z,:+
sub $40
push af
ld a,[GBM_SongID]
inc a
ld b,a
ld a,[GBM_CurrentBank]
add b
ld [rROMB0],a
pop af
: 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
bit 7,h
jr z,.readPatternData
ld a,[GBM_SongID]
inc a
ld b,a
ld a,[GBM_CurrentBank]
add b
ld [rROMB0],a
ld a,h
xor %11000000
ld h,a
.readPatternData
xor a
ld [GBM_NewNote1],a
ld [GBM_NewNote2],a
ld [GBM_NewNote3],a
ld [GBM_NewNote4],a
; ch1 note
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
push af
cp $ff
jp z,.skip1
cp $fe
jr nz,.nocut1
if USE_ZOMBIE_MODE
xor a
ld [GBM_Vol1],a
ld [GBM_OldVol1],a
ld a,$f0
ldh [rNR12],a
ldh [rNR14],a
ld a,$18
ldh [rNR12],a
else
xor a
ld [GBM_Vol1],a
ldh [rNR12],a
ld a,%10000000
ldh [rNR14],a
endc
jp .skip1
.nocut1
inc hl
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld a,[hl]
dec hl
if ENABLE_BIG_SONGS
bit 6,h
call z,GBM_HandleBankBoundaryBackwards
endc
; cp 1
; jr z,.noreset1
; cp 2
; jr z,.noreset1
call GBM_ResetFreqOffset1
xor a
ld [GBM_ArpTick1],a
ld a,1
ld [GBM_NewNote1],a
.noreset1
pop af
.freq1
ld [GBM_Note1],a
ld e,0
call GBMod_GetFreq2
; ch1 volume
if USE_ZOMBIE_MODE
ld a,[GBM_Vol1]
ld [GBM_OldVol1],a
endc
ld a,[GBM_SkipCH1]
and a
jr nz,.skipvol1
ld a,[hl]
swap a
and $f
jr z,.skipvol1
ld b,a
rla
rla
rla
ld [GBM_Vol1],a
if USE_ZOMBIE_MODE
ld a,[GBM_OldVol1]
sub b
cpl
and $f
push hl
ld l,a
ld h,0
ld bc,GBM_ZombieVolume
add hl,bc
ld c,low(rNR12)
ld a,$18
call .hl1
pop hl
else
ld a,b
swap a
ldh [rNR12],a
set 7,e
endc
if USE_ZOMBIE_MODE
jr .skipvol1
.hl1
jp hl
endc
.skipvol1
; ch1 pulse
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
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
push de
; ch1 command
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld [GBM_Command1],a
ld e,a
; ch1 parameter
ld a,[hl+]
ld d,a
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
and a ; is parameter 00?
jr nz,:+ ; if not, write parameter
ld a,e
and a ; is command 0xy?
jr z,:+
cp $1 ; is command 1xy?
jr z,.skipparam1
cp $2 ; is command 2xy?
jr z,.skipparam1
cp $8 ; is command 8xy?
jr z,:+
cp $a ; is command Axx?
jr z,.skipparam1
cp $b ; is command Bxx?
jr z,:+
cp $c ; is command Cxx?
jr z,:+
; cp $d ; is command Dxx?
; jr z,:+
: ld a,d
ld [GBM_Param1],a
.skipparam1
pop de
; 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]
jp .freq1
.ch2
; ch2 note
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
push af
cp $ff
jp z,.skip2
cp $fe
jr nz,.nocut2
xor a
if USE_ZOMBIE_MODE
xor a
ld [GBM_Vol2],a
ld [GBM_OldVol2],a
ld a,$f0
ldh [rNR22],a
ldh [rNR24],a
ld a,$18
ldh [rNR22],a
else
xor a
ld [GBM_Vol2],a
ldh [rNR22],a
ld a,%10000000
ldh [rNR24],a
endc
jp .skip2
.nocut2
inc hl
ld a,[hl]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
dec hl
if ENABLE_BIG_SONGS
bit 6,h
call z,GBM_HandleBankBoundaryBackwards
endc
; cp 1
; jr z,.noreset2
; cp 2
; jr z,.noreset2
call GBM_ResetFreqOffset2
xor a
ld [GBM_ArpTick2],a
ld a,1
ld [GBM_NewNote2],a
.noreset2
pop af
.freq2
ld [GBM_Note2],a
ld e,1
call GBMod_GetFreq2
; ch2 volume
if USE_ZOMBIE_MODE
ld a,[GBM_Vol2]
ld [GBM_OldVol2],a
endc
ld a,[GBM_SkipCH2]
and a
jr nz,.skipvol2
ld a,[hl]
swap a
and $f
jr z,.skipvol2
ld b,a
rla
rla
rla
ld [GBM_Vol2],a
if USE_ZOMBIE_MODE
ld a,[GBM_OldVol2]
sub b
cpl
and $f
push hl
ld l,a
ld h,0
ld bc,GBM_ZombieVolume
add hl,bc
ld c,low(rNR22)
ld a,$18
call .hl2
pop hl
else
ld a,b
swap a
ldh [rNR22],a
endc
set 7,e
if USE_ZOMBIE_MODE
jr .skipvol2
.hl2
jp hl
endc
.skipvol2
; ch2 pulse
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
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
push de
; ch2 command
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld [GBM_Command2],a
ld e,a
; ch2 parameter
ld a,[hl+]
ld d,a
bit 7,h
call nz,GBM_HandleBankBoundary
and a ; is parameter 00?
jr nz,:+ ; if not, write parameter
ld a,e
and a ; is command 0xy?
jr z,:+
cp $1 ; is command 1xy?
jr z,.skipparam2
cp $2 ; is command 2xy?
jr z,.skipparam2
cp $8 ; is command 8xy?
jr z,:+
cp $a ; is command Axx?
jr z,.skipparam2
cp $b ; is command Bxx?
jr z,:+
cp $c ; is command Cxx?
jr z,:+
; cp $d ; is command Dxx?
; jr z,:+
: ld a,d
ld [GBM_Param2],a
.skipparam2
pop de
; 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]
jp .freq2
.ch3
; ch3 note
.note3
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
push af
cp $ff
jp z,.skip3
cp $fe
jr nz,.nocut3
xor a
ld [GBM_Vol3],a
ldh [rNR32],a
.nocut3
inc hl
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld a,[hl]
dec hl
if ENABLE_BIG_SONGS
bit 6,h
call z,GBM_HandleBankBoundaryBackwards
endc
; cp 1
; jr z,.noreset3
; cp 2
; jr z,.noreset3
call GBM_ResetFreqOffset3
xor a
ld [GBM_ArpTick3],a
ld a,1
ld [GBM_NewNote3],a
.noreset3
pop af
.freq3
ld [GBM_Note3],a
ld e,2
call GBMod_GetFreq2
; ch3 volume
ld a,[hl]
swap a
and $f
jr z,.skipvol3
ld b,a
rla
rla
rla
ld [GBM_Vol3],a
ld a,b
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+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
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
push de
; ch3 command
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld [GBM_Command3],a
ld e,a
; ch3 parameter
ld a,[hl+]
ld d,a
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
and a ; is parameter 00?
jr nz,:+ ; if not, write parameter
ld a,e
and a ; is command 0xy?
jr z,:+
cp $1 ; is command 1xy?
jr z,.skipparam3
cp $2 ; is command 2xy?
jr z,.skipparam3
cp $8 ; is command 8xy?
jr z,:+
cp $a ; is command Axx?
jr z,.skipparam3
cp $b ; is command Bxx?
jr z,:+
cp $c ; is command Cxx?
jr z,:+
; cp $d ; is command Dxx?
; jr z,:+
: ld a,d
ld [GBM_Param3],a
.skipparam3
pop de
; 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]
jp .freq3
.nostopsample3
ld a,l
add 4
ld l,a
jr nc,.ch4
inc h
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
.ch4
; ch4 note
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
cp $ff
jp z,.skip4
cp $fe
jr nz,.freq4
if USE_ZOMBIE_MODE
xor a
ld [GBM_Vol4],a
ld [GBM_OldVol4],a
ld a,$f0
ldh [rNR42],a
ldh [rNR44],a
ld a,$18
ldh [rNR42],a
else
xor a
ld [GBM_Vol4],a
ldh [rNR42],a
ld a,%10000000
ldh [rNR44],a
endc
ld a,1
ld [GBM_NewNote4],a
jp .skip4
.freq4
ld [GBM_Note4],a
push hl
ld hl,NoiseTable
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
ld d,a
pop hl
; ch4 volume
if USE_ZOMBIE_MODE
ld a,[GBM_Vol4]
ld [GBM_OldVol4],a
endc
ld a,[GBM_SkipCH4]
and a
jr nz,.skipvol4
ld a,[hl]
swap a
and $f
jr z,.skipvol4
ld b,a
rla
rla
rla
ld [GBM_Vol4],a
if USE_ZOMBIE_MODE
ld a,[GBM_OldVol4]
sub b
cpl
and $f
push hl
ld l,a
ld h,0
ld bc,GBM_ZombieVolume
add hl,bc
ld c,low(rNR42)
ld a,$18
call .hl4
pop hl
else
ld a,b
swap a
ldh [rNR42],a
endc
set 7,e
if USE_ZOMBIE_MODE
jr .skipvol4
.hl4
jp hl
endc
.skipvol4
; ch4 mode
ld a,[hl+]
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
and a
jr z,.nomode
dec a
and 1
ld [GBM_Mode4],a
and a
jr z,.nomode
set 3,d
.nomode
; ch4 command
push de
ld a,[hl+]
bit 7,h
call nz,GBM_HandleBankBoundary
ld [GBM_Command4],a
ld e,a
; ch1 parameter
ld a,[hl+]
ld d,a
if ENABLE_BIG_SONGS
bit 7,h
call nz,GBM_HandleBankBoundary
endc
and a ; is parameter 00?
jr nz,:+ ; if not, write parameter
ld a,e
and a ; is command 0xy?
jr z,:+
cp $1 ; is command 1xy?
jr z,.skipparam4
cp $2 ; is command 2xy?
jr z,.skipparam4
cp $8 ; is command 8xy?
jr z,:+
cp $a ; is command Axx?
jr z,.skipparam4
cp $b ; is command Bxx?
jr z,:+
cp $c ; is command Cxx?
jr z,:+
; cp $d ; is command Dxx?
; jr z,:+
: ld a,d
ld [GBM_Param4],a
.skipparam4
pop de
; 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]
jp .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
push af
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
pop af
ld hl,$40f0
add l
ld l,a
jr nc,:+
inc h
: ld a,[hl+]
ld [GBM_CurrentPattern],a
swap a
and $f
ld [GBM_CurrentBank],a
.done
macro gbm_command_update
ld a,[GBM_Command\1]
ld hl,.commandTable\1
add a
ld c,a
ld b,0
add hl,bc
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable\1
dw .arp\1 ; 0xy - arp
dw .slideup\1 ; 1xy - note slide up
dw .slidedown\1 ; 2xy - note slide down
dw .portamento\1 ; 3xy - portamento
dw .vibrato\1 ; 4xy - vibrato (handled elsewhere)
dw .portavol\1 ; 5xy - portamento + volume slide
dw .vibvol\1 ; 6xy - vibrato + volume slide
dw .tremolo\1 ; 7xy - tremolo
dw .pan\1 ; 8xy - panning
dw .donech\1 ; 9xy - sample offset (won't be implemented)
dw .volslide\1 ; Axy - volume slide
dw .patjump\1 ; Bxy - pattern jump
dw .donech\1 ; Cxy - set volume (won't be implemented)
dw .patbreak\1 ; Dxy - pattern break
dw .extended\1 ; Exy - extended commands
dw .speed\1 ; Fxy - set module speed
.commandTableExt\1
dw .donech\1 ; E0x - unused
dw .fineportaup\1 ; E1x - fine portamento up
dw .fineportadown\1 ; E2x - fine portamento down
dw .glissando\1 ; E3x - glissando control
dw .vibwave\1 ; E4x - vibrato waveform
dw .finetune\1 ; E5x - finetune
dw .patloop\1 ; E6x - pattern loop
dw .tremwave\1 ; E7x - tremolo waveform
dw .coarsepan\1 ; E8x - set panning
dw .retrig\1 ; E9x - retrigger
dw .finevolup\1 ; EAx - fine volume slide up
dw .finevoldown\1 ; EBx - fine volume slide down
dw .notecut\1 ; ECx - note cut
dw .notedelay\1 ; EDx - note delay
dw .patdelay\1 ; EEx - pattern delay
dw .donech\1 ; EFx - unused
; Exy - extended commands
.extended\1
ld a,[GBM_Param\1]
and $f0
swap a
ld hl,.commandTableExt\1
add a
ld c,a