-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathm4a_1.s
1916 lines (1854 loc) · 38.7 KB
/
m4a_1.s
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
.include "asm/macros.inc"
.include "constants/gba_constants.inc"
.include "constants/m4a_constants.inc"
.syntax unified
.text
thumb_func_start umul3232H32
umul3232H32:
adr r2, __umul3232H32
bx r2
.arm
__umul3232H32:
umull r2, r3, r0, r1
add r0, r3, 0
bx lr
thumb_func_end umul3232H32
thumb_func_start SoundMain
SoundMain:
ldr r0, lt_SOUND_INFO_PTR
ldr r0, [r0]
ldr r2, lt_ID_NUMBER
ldr r3, [r0, o_SoundInfo_ident]
cmp r2, r3
beq SoundMain_1
bx lr @ Exit the function if ident doesn't match ID_NUMBER.
SoundMain_1:
adds r3, 1
str r3, [r0, o_SoundInfo_ident]
push {r4-r7,lr}
mov r1, r8
mov r2, r9
mov r3, r10
mov r4, r11
push {r0-r4}
sub sp, 0x18
ldrb r1, [r0, o_SoundInfo_maxLines]
cmp r1, 0 @ if maxLines is 0, there is no maximum
beq SoundMain_3
ldr r2, lt_REG_VCOUNT
ldrb r2, [r2]
cmp r2, VCOUNT_VBLANK
bhs SoundMain_2
adds r2, TOTAL_SCANLINES
SoundMain_2:
adds r1, r2
SoundMain_3:
str r1, [sp, 0x14]
ldr r3, [r0, o_SoundInfo_MPlayMainHead]
cmp r3, 0
beq SoundMain_4
ldr r0, [r0, o_SoundInfo_musicPlayerHead]
bl _081DD25E
ldr r0, [sp, 0x18]
SoundMain_4:
ldr r3, [r0, o_SoundInfo_CgbSound]
bl _081DD25E
ldr r0, [sp, 0x18]
ldr r3, [r0, o_SoundInfo_pcmSamplesPerVBlank]
mov r8, r3
ldr r5, lt_o_SoundInfo_pcmBuffer
adds r5, r0
ldrb r4, [r0, o_SoundInfo_pcmDmaCounter]
subs r7, r4, 1
bls SoundMain_5
ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod]
subs r1, r7
mov r2, r8
muls r2, r1
adds r5, r2
SoundMain_5:
str r5, [sp, 0x8]
ldr r6, lt_PCM_DMA_BUF_SIZE
ldr r3, lt_SoundMainRAM_Buffer
bx r3
.align 2, 0
lt_SOUND_INFO_PTR: .word SOUND_INFO_PTR
lt_ID_NUMBER: .word ID_NUMBER
lt_SoundMainRAM_Buffer: .word SoundMainRAM_Buffer + 1
lt_REG_VCOUNT: .word REG_VCOUNT
lt_o_SoundInfo_pcmBuffer: .word o_SoundInfo_pcmBuffer
lt_PCM_DMA_BUF_SIZE: .word PCM_DMA_BUF_SIZE
thumb_func_end SoundMain
thumb_func_start SoundMainRAM
SoundMainRAM:
ldrb r3, [r0, o_SoundInfo_reverb]
cmp r3, 0
beq SoundMainRAM_NoReverb
adr r1, SoundMainRAM_Reverb
bx r1
.arm
SoundMainRAM_Reverb:
cmp r4, 0x2
addeq r7, r0, o_SoundInfo_pcmBuffer
addne r7, r5, r8
mov r4, r8
_081DCEC4:
ldrsb r0, [r5, r6]
ldrsb r1, [r5]
add r0, r0, r1
ldrsb r1, [r7, r6]
add r0, r0, r1
ldrsb r1, [r7], 0x1
add r0, r0, r1
mul r1, r0, r3
mov r0, r1, asr 9
tst r0, 0x80
addne r0, r0, 0x1
strb r0, [r5, r6]
strb r0, [r5], 0x1
subs r4, r4, 0x1
bgt _081DCEC4
adr r0, _081DCF36 + 1 @ plus 1 because THUMB
bx r0
.thumb
SoundMainRAM_NoReverb:
movs r0, 0
mov r1, r8
adds r6, r5
lsrs r1, 3
bcc SoundMainRAM_NoReverb_Ok
stm r5!, {r0}
stm r6!, {r0}
SoundMainRAM_NoReverb_Ok:
lsrs r1, 1
bcc SoundMainRAM_NoReverb_Loop
stm r5!, {r0}
stm r6!, {r0}
stm r5!, {r0}
stm r6!, {r0}
SoundMainRAM_NoReverb_Loop:
stm r5!, {r0}
stm r6!, {r0}
stm r5!, {r0}
stm r6!, {r0}
stm r5!, {r0}
stm r6!, {r0}
stm r5!, {r0}
stm r6!, {r0}
subs r1, 1
bgt SoundMainRAM_NoReverb_Loop
_081DCF36:
ldr r4, [sp, 0x18]
ldr r0, [r4, o_SoundInfo_divFreq]
mov r12, r0
ldrb r0, [r4, o_SoundInfo_maxChans]
adds r4, o_SoundInfo_chans
SoundMainRAM_ChanLoop:
str r0, [sp, 0x4]
ldr r3, [r4, o_SoundChannel_wav]
ldr r0, [sp, 0x14]
cmp r0, 0
beq _081DCF60
ldr r1, =REG_VCOUNT
ldrb r1, [r1]
cmp r1, VCOUNT_VBLANK
bhs _081DCF54
adds r1, TOTAL_SCANLINES
_081DCF54:
cmp r1, r0
blo _081DCF60
b _081DD24A
.pool
_081DCF60:
ldrb r6, [r4, o_SoundChannel_statusFlags]
movs r0, SOUND_CHANNEL_SF_ON
tst r0, r6
bne _081DCF6A
b _081DD240
_081DCF6A:
movs r0, SOUND_CHANNEL_SF_START
tst r0, r6
beq _081DCFA0
movs r0, SOUND_CHANNEL_SF_STOP
tst r0, r6
bne _081DCFB0
movs r6, SOUND_CHANNEL_SF_ENV_ATTACK
strb r6, [r4, o_SoundChannel_statusFlags]
adds r0, r3, 0
adds r0, o_WaveData_data
ldr r1, [r4, o_SoundChannel_count]
adds r0, r1
str r0, [r4, o_SoundChannel_currentPointer]
ldr r0, [r3, o_WaveData_size]
subs r0, r1
str r0, [r4, o_SoundChannel_count]
movs r5, 0
strb r5, [r4, o_SoundChannel_envelopeVolume]
str r5, [r4, o_SoundChannel_fw]
ldrb r2, [r3, o_WaveData_flags]
movs r0, WAVE_DATA_FLAG_LOOP
tst r0, r2
beq _081DCFF8
movs r0, SOUND_CHANNEL_SF_LOOP
orrs r6, r0
strb r6, [r4, o_SoundChannel_statusFlags]
b _081DCFF8
_081DCFA0:
ldrb r5, [r4, o_SoundChannel_envelopeVolume]
movs r0, SOUND_CHANNEL_SF_IEC
tst r0, r6
beq _081DCFB6
ldrb r0, [r4, o_SoundChannel_pseudoEchoLength]
subs r0, 1
strb r0, [r4, o_SoundChannel_pseudoEchoLength]
bhi _081DD006
_081DCFB0:
movs r0, 0
strb r0, [r4, o_SoundChannel_statusFlags]
b _081DD240
_081DCFB6:
movs r0, SOUND_CHANNEL_SF_STOP
tst r0, r6
beq _081DCFD6
ldrb r0, [r4, o_SoundChannel_release]
muls r5, r0
lsrs r5, 8
ldrb r0, [r4, o_SoundChannel_pseudoEchoVolume]
cmp r5, r0
bhi _081DD006
_081DCFC8:
ldrb r5, [r4, o_SoundChannel_pseudoEchoVolume]
cmp r5, 0
beq _081DCFB0
movs r0, SOUND_CHANNEL_SF_IEC
orrs r6, r0
strb r6, [r4, o_SoundChannel_statusFlags]
b _081DD006
_081DCFD6:
movs r2, SOUND_CHANNEL_SF_ENV
ands r2, r6
cmp r2, SOUND_CHANNEL_SF_ENV_DECAY
bne _081DCFF4
ldrb r0, [r4, o_SoundChannel_decay]
muls r5, r0
lsrs r5, 8
ldrb r0, [r4, o_SoundChannel_sustain]
cmp r5, r0
bhi _081DD006
adds r5, r0, 0
beq _081DCFC8
subs r6, 0x1
strb r6, [r4, o_SoundChannel_statusFlags]
b _081DD006
_081DCFF4:
cmp r2, SOUND_CHANNEL_SF_ENV_ATTACK
bne _081DD006
_081DCFF8:
ldrb r0, [r4, o_SoundChannel_attack]
adds r5, r0
cmp r5, 0xFF
bcc _081DD006
movs r5, 0xFF
subs r6, 0x1
strb r6, [r4, o_SoundChannel_statusFlags]
_081DD006:
strb r5, [r4, o_SoundChannel_envelopeVolume]
ldr r0, [sp, 0x18]
ldrb r0, [r0, o_SoundChannel_release]
adds r0, 0x1
muls r0, r5
lsrs r5, r0, 4
ldrb r0, [r4, o_SoundChannel_rightVolume]
muls r0, r5
lsrs r0, 8
strb r0, [r4, o_SoundChannel_envelopeVolumeRight]
ldrb r0, [r4, o_SoundChannel_leftVolume]
muls r0, r5
lsrs r0, 8
strb r0, [r4, o_SoundChannel_envelopeVolumeLeft]
movs r0, SOUND_CHANNEL_SF_LOOP
ands r0, r6
str r0, [sp, 0x10]
beq _081DD03A
adds r0, r3, 0
adds r0, o_WaveData_data
ldr r1, [r3, o_WaveData_loopStart]
adds r0, r1
str r0, [sp, 0xC]
ldr r0, [r3, o_WaveData_size]
subs r0, r1
str r0, [sp, 0x10]
_081DD03A:
ldr r5, [sp, 0x8]
ldr r2, [r4, o_SoundChannel_count]
ldr r3, [r4, o_SoundChannel_currentPointer]
adr r0, _081DD044
bx r0
.arm
_081DD044:
str r8, [sp]
ldr r9, [r4, o_SoundChannel_fw]
ldrb r10, [r4, o_SoundChannel_envelopeVolumeRight]
ldrb r11, [r4, o_SoundChannel_envelopeVolumeLeft]
ldrb r0, [r4, o_SoundChannel_type]
tst r0, TONEDATA_TYPE_CMP | TONEDATA_TYPE_REV
beq _081DD068
bl SoundMainRAM_Unk1
b _081DD228
_081DD068:
mov r10, r10, lsl 16
mov r11, r11, lsl 16
ldrb r0, [r4, o_SoundChannel_type]
tst r0, 0x8
beq _081DD19C
_081DD07C:
cmp r2, 0x4
ble _081DD0EC
subs r2, r2, r8
movgt r9, 0
bgt _081DD0A8
mov r9, r8
add r2, r2, r8
sub r8, r2, 0x4
sub r9, r9, r8
ands r2, r2, 0x3
moveq r2, 0x4
_081DD0A8:
ldr r6, [r5]
ldr r7, [r5, PCM_DMA_BUF_SIZE]
_081DD0B0:
ldrsb r0, [r3], 0x1
mul r1, r10, r0
bic r1, r1, 0xFF0000
add r6, r1, r6, ror 8
mul r1, r11, r0
bic r1, r1, 0xFF0000
add r7, r1, r7, ror 8
adds r5, r5, 0x40000000
bcc _081DD0B0
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
subs r8, r8, 0x4
bgt _081DD0A8
adds r8, r8, r9
beq _081DD22C
_081DD0EC:
ldr r6, [r5]
ldr r7, [r5, PCM_DMA_BUF_SIZE]
_081DD0F4:
ldrsb r0, [r3], 0x1
mul r1, r10, r0
bic r1, r1, 0xFF0000
add r6, r1, r6, ror 8
mul r1, r11, r0
bic r1, r1, 0xFF0000
add r7, r1, r7, ror 8
subs r2, r2, 0x1
beq _081DD164
_081DD118:
adds r5, r5, 0x40000000
bcc _081DD0F4
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
subs r8, r8, 0x4
bgt _081DD07C
b _081DD22C
_081DD134:
ldr r0, [sp, 0x18]
cmp r0, 0
beq _081DD158
ldr r3, [sp, 0x14]
rsb lr, r2, 0
_081DD148:
adds r2, r0, r2
bgt _081DD1FC
sub lr, lr, r0
b _081DD148
_081DD158:
pop {r4,r12}
mov r2, 0
b _081DD174
_081DD164:
ldr r2, [sp, 0x10]
cmp r2, 0
ldrne r3, [sp, 0xC]
bne _081DD118
_081DD174:
strb r2, [r4, o_SoundChannel_statusFlags]
mov r0, r5, lsr 30
bic r5, r5, 0xC0000000
rsb r0, r0, 0x3
mov r0, r0, lsl 3
mov r6, r6, ror r0
mov r7, r7, ror r0
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
b _081DD234
_081DD19C:
push {r4,r12}
ldr r1, [r4, o_SoundChannel_frequency]
mul r4, r12, r1
ldrsb r0, [r3]
ldrsb r1, [r3, 0x1]!
sub r1, r1, r0
_081DD1B4:
ldr r6, [r5]
ldr r7, [r5, PCM_DMA_BUF_SIZE]
_081DD1BC:
mul lr, r9, r1
add lr, r0, lr, asr 23
mul r12, r10, lr
bic r12, r12, 0xFF0000
add r6, r12, r6, ror 8
mul r12, r11, lr
bic r12, r12, 0xFF0000
add r7, r12, r7, ror 8
add r9, r9, r4
movs lr, r9, lsr 23
beq _081DD208
bic r9, r9, 0x3F800000
subs r2, r2, lr
ble _081DD134
subs lr, lr, 0x1
addeq r0, r0, r1
_081DD1FC:
ldrsbne r0, [r3, lr]!
ldrsb r1, [r3, 0x1]!
sub r1, r1, r0
_081DD208:
adds r5, r5, 0x40000000
bcc _081DD1BC
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
subs r8, r8, 0x4
bgt _081DD1B4
sub r3, r3, 0x1
pop {r4,r12}
_081DD228:
str r9, [r4, o_SoundChannel_fw]
_081DD22C:
str r2, [r4, o_SoundChannel_count]
str r3, [r4, o_SoundChannel_currentPointer]
_081DD234:
ldr r8, [sp]
add r0, pc, 0x1
bx r0
.thumb
_081DD240:
ldr r0, [sp, 0x4]
subs r0, 1
ble _081DD24A
adds r4, SoundChannel_size
b SoundMainRAM_ChanLoop
_081DD24A:
ldr r0, [sp, 0x18]
ldr r3, =ID_NUMBER
str r3, [r0]
add sp, 0x1C
pop {r0-r7}
mov r8, r0
mov r9, r1
mov r10, r2
mov r11, r3
pop {r3}
_081DD25E:
bx r3
.pool
thumb_func_end SoundMainRAM
@ Not present in GBA SDK 3.0
arm_func_start SoundMainRAM_Unk1
SoundMainRAM_Unk1:
ldr r6, [r4, o_SoundChannel_wav]
ldrb r0, [r4, o_SoundChannel_statusFlags]
tst r0, SOUND_CHANNEL_SF_SPECIAL
bne _081DD2B4
orr r0, r0, SOUND_CHANNEL_SF_SPECIAL
strb r0, [r4, o_SoundChannel_statusFlags]
ldrb r0, [r4, o_SoundChannel_type]
tst r0, TONEDATA_TYPE_REV
beq _081DD29C
ldr r1, [r6, o_WaveData_size]
add r1, r1, r6, lsl 1
add r1, r1, 0x20
sub r3, r1, r3
str r3, [r4, o_SoundChannel_currentPointer]
_081DD29C:
ldrh r0, [r6, o_WaveData_type]
cmp r0, 0
beq _081DD2B4
sub r3, r3, r6
sub r3, r3, 0x10
str r3, [r4, o_SoundChannel_currentPointer]
_081DD2B4:
push {r8,r12,lr}
mov r10, r10, lsl 16
mov r11, r11, lsl 16
ldr r1, [r4, o_SoundChannel_frequency]
ldrb r0, [r4, o_SoundChannel_type]
tst r0, TONEDATA_TYPE_FIX
movne r8, 0x800000
muleq r8, r12, r1
ldrh r0, [r6, o_WaveData_type]
cmp r0, 0
beq _081DD468
mov r0, 0xFF000000
str r0, [r4, o_SoundChannel_xpi]
ldrb r0, [r4, o_SoundChannel_type]
tst r0, TONEDATA_TYPE_REV
bne _081DD3C0
bl SoundMainRAM_Unk2
mov r0, r1
add r3, r3, 0x1
bl SoundMainRAM_Unk2
sub r1, r1, r0
_081DD308:
ldr r6, [r5]
ldr r7, [r5, PCM_DMA_BUF_SIZE]
_081DD310:
mul lr, r9, r1
add lr, r0, lr, asr 23
mul r12, r10, lr
bic r12, r12, 0xFF0000
add r6, r12, r6, ror 8
mul r12, r11, lr
bic r12, r12, 0xFF0000
add r7, r12, r7, ror 8
add r9, r9, r8
movs lr, r9, lsr 23
beq _081DD370
bic r9, r9, 0x3F800000
subs r2, r2, lr
ble _081DD398
subs lr, lr, 0x1
bne _081DD358
add r0, r0, r1
b _081DD364
_081DD358:
add r3, r3, lr
bl SoundMainRAM_Unk2
mov r0, r1
_081DD364:
add r3, r3, 0x1
bl SoundMainRAM_Unk2
sub r1, r1, r0
_081DD370:
adds r5, r5, 0x40000000
bcc _081DD310
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
ldr r6, [sp]
subs r6, r6, 0x4
str r6, [sp]
bgt _081DD308
sub r3, r3, 0x1
b _081DD4F0
_081DD398:
ldr r0, [sp, 0x1C]
cmp r0, 0
beq _081DD4F4
ldr r3, [r4, o_SoundChannel_wav]
ldr r3, [r3, o_WaveData_loopStart]
rsb lr, r2, 0
_081DD3B0:
adds r2, r2, r0
bgt _081DD358
sub lr, lr, r0
b _081DD3B0
_081DD3C0:
sub r3, r3, 0x1
bl SoundMainRAM_Unk2
mov r0, r1
sub r3, r3, 0x1
bl SoundMainRAM_Unk2
sub r1, r1, r0
_081DD3D8:
ldr r6, [r5]
ldr r7, [r5, PCM_DMA_BUF_SIZE]
_081DD3E0:
mul lr, r9, r1
add lr, r0, lr, asr 23
mul r12, r10, lr
bic r12, r12, 0xFF0000
add r6, r12, r6, ror 8
mul r12, r11, lr
bic r12, r12, 0xFF0000
add r7, r12, r7, ror 8
add r9, r9, r8
movs lr, r9, lsr 23
beq _081DD440
bic r9, r9, 0x3F800000
subs r2, r2, lr
ble _081DD4F4
subs lr, lr, 0x1
bne _081DD428
add r0, r0, r1
b _081DD434
_081DD428:
sub r3, r3, lr
bl SoundMainRAM_Unk2
mov r0, r1
_081DD434:
sub r3, r3, 0x1
bl SoundMainRAM_Unk2
sub r1, r1, r0
_081DD440:
adds r5, r5, 0x40000000
bcc _081DD3E0
str r7, [r5, PCM_DMA_BUF_SIZE]
str r6, [r5], 0x4
ldr r6, [sp]
subs r6, r6, 0x4
str r6, [sp]
bgt _081DD3D8
add r3, r3, 0x2
b _081DD4F0
_081DD468:
ldrb r0, [r4, o_SoundChannel_type]
tst r0, TONEDATA_TYPE_REV
beq _081DD4F0
ldrsb r0, [r3, -0x1]!
ldrsb r1, [r3, -0x1]
sub r1, r1, r0
_081DD480:
ldr r6, [r5]
ldr r7, [r5, 0x630]
_081DD488:
mul lr, r9, r1
add lr, r0, lr, asr 23
mul r12, r10, lr
bic r12, r12, 0xFF0000
add r6, r12, r6, ror 8
mul r12, r11, lr
bic r12, r12, 0xFF0000
add r7, r12, r7, ror 8
add r9, r9, r8
movs lr, r9, lsr 23
beq _081DD4CC
bic r9, r9, 0x3F800000
subs r2, r2, lr
ble _081DD4F4
ldrsb r0, [r3, -lr]!
ldrsb r1, [r3, -0x1]
sub r1, r1, r0
_081DD4CC:
adds r5, r5, 0x40000000
bcc _081DD488
str r7, [r5, 0x630]
str r6, [r5], 0x4
ldr r6, [sp]
subs r6, r6, 0x4
str r6, [sp]
bgt _081DD480
add r3, r3, 0x1
_081DD4F0:
pop {r8,r12,pc}
_081DD4F4:
mov r2, 0
strb r2, [r4, o_SoundChannel_statusFlags]
mov r0, r5, lsr 30
bic r5, r5, 0xC0000000
rsb r0, r0, 0x3
mov r0, r0, lsl 3
mov r6, r6, ror r0
mov r7, r7, ror r0
str r7, [r5, 0x630]
str r6, [r5], 0x4
pop {r8,r12,pc}
arm_func_end SoundMainRAM_Unk1
@ Not present in GBA SDK 3.0
arm_func_start SoundMainRAM_Unk2
SoundMainRAM_Unk2:
push {r0,r2,r5-r7,lr}
mov r0, r3, lsr 6
ldr r1, [r4, o_SoundChannel_xpi]
cmp r0, r1
beq _081DD594
str r0, [r4, o_SoundChannel_xpi]
mov r1, 0x21
mul r2, r1, r0
ldr r1, [r4, o_SoundChannel_wav]
add r2, r2, r1
add r2, r2, 0x10
ldr r5, =sDecodingBuffer
ldr r6, =gDeltaEncodingTable
mov r7, 0x40
ldrb lr, [r2], 1
strb lr, [r5], 1
ldrb r1, [r2], 1
b _081DD57C
_081DD568:
ldrb r1, [r2], 1
mov r0, r1, lsr 4
ldrsb r0, [r6, r0]
add lr, lr, r0
strb lr, [r5], 1
_081DD57C:
and r0, r1, 0xF
ldrsb r0, [r6, r0]
add lr, lr, r0
strb lr, [r5], 1
subs r7, r7, 2
bgt _081DD568
_081DD594:
ldr r5, =sDecodingBuffer
and r0, r3, 0x3F
ldrsb r1, [r5, r0]
pop {r0,r2,r5-r7,pc}
.pool
arm_func_end SoundMainRAM_Unk2
thumb_func_start SoundMainBTM
SoundMainBTM:
mov r12, r4
movs r1, 0
movs r2, 0
movs r3, 0
movs r4, 0
stm r0!, {r1-r4}
stm r0!, {r1-r4}
stm r0!, {r1-r4}
stm r0!, {r1-r4}
mov r4, r12
bx lr
thumb_func_end SoundMainBTM
thumb_func_start RealClearChain
RealClearChain:
ldr r3, [r0, o_SoundChannel_track]
cmp r3, 0
beq _081DD5E2
ldr r1, [r0, o_SoundChannel_nextChannelPointer]
ldr r2, [r0, o_SoundChannel_prevChannelPointer]
cmp r2, 0
beq _081DD5D6
str r1, [r2, o_SoundChannel_nextChannelPointer]
b _081DD5D8
_081DD5D6:
str r1, [r3, o_MusicPlayerTrack_chan]
_081DD5D8:
cmp r1, 0
beq _081DD5DE
str r2, [r1, o_SoundChannel_prevChannelPointer]
_081DD5DE:
movs r1, 0
str r1, [r0, o_SoundChannel_track]
_081DD5E2:
bx lr
thumb_func_end RealClearChain
thumb_func_start ply_fine
ply_fine:
push {r4,r5,lr}
adds r5, r1, 0
ldr r4, [r5, o_MusicPlayerTrack_chan]
cmp r4, 0
beq ply_fine_done
ply_fine_loop:
ldrb r1, [r4, o_SoundChannel_statusFlags]
movs r0, SOUND_CHANNEL_SF_ON
tst r0, r1
beq ply_fine_ok
movs r0, SOUND_CHANNEL_SF_STOP
orrs r1, r0
strb r1, [r4, o_SoundChannel_statusFlags]
ply_fine_ok:
adds r0, r4, 0
bl RealClearChain
ldr r4, [r4, o_SoundChannel_nextChannelPointer]
cmp r4, 0
bne ply_fine_loop
ply_fine_done:
movs r0, 0
strb r0, [r5, o_MusicPlayerTrack_flags]
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end ply_fine
thumb_func_start MPlayJumpTableCopy
MPlayJumpTableCopy:
mov r12, lr
movs r1, 0x24
ldr r2, lt_MPlayJumpTableTemplate
MPlayJumpTableCopy_Loop:
ldr r3, [r2]
bl chk_adr_r2
stm r0!, {r3}
adds r2, 0x4
subs r1, 0x1
bgt MPlayJumpTableCopy_Loop
bx r12
thumb_func_end MPlayJumpTableCopy
.align 2, 0
.thumb_func
ldrb_r3_r2:
ldrb r3, [r2]
@ This attempts to protect against reading anything from the BIOS ROM
@ besides the jump table template.
@ It assumes that the jump table template is located at the end of the ROM.
.thumb_func
chk_adr_r2:
push {r0}
lsrs r0, r2, 25
bne chk_adr_r2_done @ if adr >= 0x2000000 (i.e. not in BIOS ROM), accept it
ldr r0, lt_MPlayJumpTableTemplate
cmp r2, r0
blo chk_adr_r2_reject @ if adr < gMPlayJumpTableTemplate, reject it
lsrs r0, r2, 14
beq chk_adr_r2_done @ if adr < 0x40000 (i.e. in BIOS ROM), accept it
chk_adr_r2_reject:
movs r3, 0
chk_adr_r2_done:
pop {r0}
bx lr
.align 2, 0
lt_MPlayJumpTableTemplate: .word gMPlayJumpTableTemplate
thumb_func_start ld_r3_tp_adr_i
ld_r3_tp_adr_i:
ldr r2, [r1, o_MusicPlayerTrack_cmdPtr]
_081DD64A:
adds r3, r2, 0x1
str r3, [r1, o_MusicPlayerTrack_cmdPtr]
ldrb r3, [r2]
b chk_adr_r2
thumb_func_end ld_r3_tp_adr_i
thumb_func_start ply_goto
ply_goto:
push {lr}
ply_goto_1:
ldr r2, [r1, o_MusicPlayerTrack_cmdPtr]
ldrb r0, [r2, 0x3]
lsls r0, 8
ldrb r3, [r2, 0x2]
orrs r0, r3
lsls r0, 8
ldrb r3, [r2, 0x1]
orrs r0, r3
lsls r0, 8
bl ldrb_r3_r2
orrs r0, r3
str r0, [r1, o_MusicPlayerTrack_cmdPtr]
pop {r0}
bx r0
thumb_func_end ply_goto
thumb_func_start ply_patt
ply_patt:
ldrb r2, [r1, o_MusicPlayerTrack_patternLevel]
cmp r2, 3
bhs ply_patt_done
lsls r2, 2
adds r3, r1, r2
ldr r2, [r1, o_MusicPlayerTrack_cmdPtr]
adds r2, 0x4
str r2, [r3, o_MusicPlayerTrack_patternStack]
ldrb r2, [r1, o_MusicPlayerTrack_patternLevel]
adds r2, 1
strb r2, [r1, o_MusicPlayerTrack_patternLevel]
b ply_goto
ply_patt_done:
b ply_fine
thumb_func_end ply_patt
thumb_func_start ply_pend
ply_pend:
ldrb r2, [r1, o_MusicPlayerTrack_patternLevel]
cmp r2, 0
beq ply_pend_done
subs r2, 1
strb r2, [r1, o_MusicPlayerTrack_patternLevel]
lsls r2, 2
adds r3, r1, r2
ldr r2, [r3, o_MusicPlayerTrack_patternStack]
str r2, [r1, o_MusicPlayerTrack_cmdPtr]
ply_pend_done:
bx lr
thumb_func_end ply_pend
thumb_func_start ply_rept
ply_rept:
push {lr}
ldr r2, [r1, o_MusicPlayerTrack_cmdPtr]
ldrb r3, [r2]
cmp r3, 0
bne ply_rept_1
adds r2, 1
str r2, [r1, o_MusicPlayerTrack_cmdPtr]
b ply_goto_1
ply_rept_1:
ldrb r3, [r1, o_MusicPlayerTrack_repN]
adds r3, 1
strb r3, [r1, o_MusicPlayerTrack_repN]
mov r12, r3
bl ld_r3_tp_adr_i
cmp r12, r3
bhs ply_rept_2
b ply_goto_1
ply_rept_2:
movs r3, 0
strb r3, [r1, o_MusicPlayerTrack_repN]
adds r2, 5
str r2, [r1, o_MusicPlayerTrack_cmdPtr]
pop {r0}
bx r0
thumb_func_end ply_rept
thumb_func_start ply_prio
ply_prio:
mov r12, lr
bl ld_r3_tp_adr_i
strb r3, [r1, o_MusicPlayerTrack_priority]
bx r12
thumb_func_end ply_prio
thumb_func_start ply_tempo
ply_tempo:
mov r12, lr
bl ld_r3_tp_adr_i
lsls r3, 1
strh r3, [r0, o_MusicPlayerInfo_tempoD]
ldrh r2, [r0, o_MusicPlayerInfo_tempoU]
muls r3, r2
lsrs r3, 8
strh r3, [r0, o_MusicPlayerInfo_tempoI]
bx r12
thumb_func_end ply_tempo
thumb_func_start ply_keysh
ply_keysh:
mov r12, lr
bl ld_r3_tp_adr_i
strb r3, [r1, o_MusicPlayerTrack_keyShift]
ldrb r3, [r1, o_MusicPlayerTrack_flags]
movs r2, 0xC
orrs r3, r2
strb r3, [r1, o_MusicPlayerTrack_flags]
bx r12
thumb_func_end ply_keysh
thumb_func_start ply_voice
ply_voice:
mov r12, lr
ldr r2, [r1, o_MusicPlayerTrack_cmdPtr]
ldrb r3, [r2]
adds r2, 1
str r2, [r1, o_MusicPlayerTrack_cmdPtr]
lsls r2, r3, 1
adds r2, r3
lsls r2, 2
ldr r3, [r0, o_MusicPlayerInfo_tone]
adds r2, r3
ldr r3, [r2, o_ToneData_type]
bl chk_adr_r2
str r3, [r1, o_MusicPlayerTrack_ToneData_type]
ldr r3, [r2, o_ToneData_wav]
bl chk_adr_r2
str r3, [r1, o_MusicPlayerTrack_ToneData_wav]
ldr r3, [r2, o_ToneData_attack]
bl chk_adr_r2
str r3, [r1, o_MusicPlayerTrack_ToneData_attack]
bx r12
thumb_func_end ply_voice
thumb_func_start ply_vol
ply_vol:
mov r12, lr
bl ld_r3_tp_adr_i
strb r3, [r1, o_MusicPlayerTrack_vol]
ldrb r3, [r1, o_MusicPlayerTrack_flags]
movs r2, MPT_FLG_VOLCHG
orrs r3, r2
strb r3, [r1, o_MusicPlayerTrack_flags]
bx r12
thumb_func_end ply_vol
thumb_func_start ply_pan
ply_pan:
mov r12, lr
bl ld_r3_tp_adr_i
subs r3, C_V
strb r3, [r1, o_MusicPlayerTrack_pan]
ldrb r3, [r1, o_MusicPlayerTrack_flags]
movs r2, MPT_FLG_VOLCHG
orrs r3, r2
strb r3, [r1, o_MusicPlayerTrack_flags]
bx r12
thumb_func_end ply_pan
thumb_func_start ply_bend
ply_bend:
mov r12, lr
bl ld_r3_tp_adr_i
subs r3, C_V
strb r3, [r1, o_MusicPlayerTrack_bend]
ldrb r3, [r1, o_MusicPlayerTrack_flags]