forked from FireEmblemUniverse/fireemblem8u
/
soundroom.c
1618 lines (1252 loc) · 34.7 KB
/
soundroom.c
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 "global.h"
#include "hardware.h"
#include "fontgrp.h"
#include "uiutils.h"
#include "bm.h"
#include "m4a.h"
#include "soundwrapper.h"
#include "bmlib.h"
#include "ctc.h"
#include "sysutil.h"
#include "bmsave.h"
#include "soundroom.h"
// TODO: Implicit declarations
void PutMenuScrollBarAt(int, int);
void UpdateMenuScrollBarConfig(int, int, int, int);
ProcPtr StartMenuScrollBarExt(ProcPtr, int, int, int, int);
struct VolumeGraphBufferProc
{
/* 00 */ PROC_HEADER;
/* 2C */ int unk_2c;
};
struct SoundRoomSpriteDrawProc
{
/* 00 */ PROC_HEADER;
/* 2C */ int unk_2c;
};
struct Unknown_08A212DC
{
u8 x;
u8 y;
} __attribute__((packed));
struct Unknown201F148
{
/* 00 */ struct Font font;
/* 18 */ struct Text text[7];
/* 50 */ u16 unk_50;
};
extern struct Unknown201F148 gUnk_SoundRoom_0201F148;
extern u8 gSoundRoomVolumeGraphBuffer[][0x31];
extern u8 gUnknown_08A2C908[]; // gfx
extern u16 gUnknown_08A01EE4[]; // pal
extern u16 gUnknown_08A01F04[]; // pal
extern u8 gUnknown_08A2C4C8[]; // tsa
extern u8 gUnknown_08A2C5A8[]; // tsa
extern u8 gUnknown_08A2D32C[]; // gfx
extern u16 gUnknown_08A2E1B8[]; // pal
extern u8 Img_SoundRoomUiElements[];
extern u16 Pal_SoundRoomUiElements[];
extern u8 gUnknown_08A2C92C[];
extern u8 gUnknown_08A2C7A4[];
u16 * CONST_DATA gUnknown_08A212D4 = (u16 *)gGenericBuffer;
void * CONST_DATA gUnknown_08A212D8 = gGenericBuffer + 0x800;
struct Unknown_08A212DC * CONST_DATA gUnknown_08A212DC = (void *)(gGenericBuffer + 0x1000);
s8 * CONST_DATA gSoundRoomShuffleBuffer = gGenericBuffer + 0x1200;
//! FE8U = 0x080AEC7C
bool IsSoundRoomCompleted(struct SoundRoomProc * proc)
{
if (proc->completionPercent == 100)
{
return TRUE;
}
return FALSE;
}
//! FE8U = 0x080AEC90
bool sub_80AEC90(void)
{
return FALSE;
}
//! FE8U = 0x080AEC94
int CountTotalSoundRoomSongs(void)
{
int i = 0;
do
{
if (gSoundRoomTable[i].bgmId < 0)
{
break;
}
i++;
} while (1);
return i;
}
//! FE8U = 0x080AECB4
int CountSecretSoundRoomSongs(void)
{
int i = 0;
int count = 0;
do
{
if (gSoundRoomTable[i].bgmId < 0)
{
return count;
}
if (gSoundRoomTable[i].displayCondFunc != NULL)
{
count++;
}
i++;
} while (1);
}
//! FE8U = 0x080AECEC
bool IsSoundRoomSongPlayable(struct SoundRoomProc * proc, int flag)
{
if ((*(proc->flags + (flag >> 5)) >> (flag & 0x1f)) & 1)
{
return TRUE;
}
return FALSE;
}
//! FE8U = 0x080AED10
int CountDisplayedSoundRoomSongs(struct SoundRoomProc * proc)
{
int i = 0;
int result = 0;
do
{
if (gSoundRoomTable[i].bgmId < 0)
{
return result;
}
if (gSoundRoomTable[i].displayCondFunc != NULL)
{
if ((*(proc->flags + (i >> 5)) >> (i & 0x1f)) & 1)
{
result = i + 1;
}
}
else
{
result = i + 1;
}
i++;
} while (1);
}
//! FE8U = 0x080AED64
void InitSoundRoomSongData(struct SoundRoomProc * proc)
{
struct SoundRoomSaveData soundRoomData;
proc->totalSongs = CountTotalSoundRoomSongs();
CpuFill16(0, proc->flags, 0x10);
proc->playableSongs = 0;
if (LoadAndVerifySoundRoomData(&soundRoomData))
{
int i;
for (i = 0; gSoundRoomTable[i].bgmId > -1; i++)
{
if (gSoundRoomTable[i].displayCondFunc != NULL)
{
continue;
}
if ((soundRoomData.flags[gSoundRoomTable[i].bgmId >> 5] >> (gSoundRoomTable[i].bgmId & 0x1f)) & 1)
{
*(proc->flags + (i >> 5)) |= 1 << (i & 0x1f);
proc->playableSongs++;
}
}
proc->completionPercent = (proc->playableSongs * 100) / (proc->totalSongs - CountSecretSoundRoomSongs());
for (i = 0; gSoundRoomTable[i].bgmId > -1; i++)
{
if (gSoundRoomTable[i].displayCondFunc == NULL)
{
continue;
}
if (!((soundRoomData.flags[gSoundRoomTable[i].bgmId >> 5] >> (gSoundRoomTable[i].bgmId & 0x1f)) & 1))
{
if (!gSoundRoomTable[i].displayCondFunc(proc))
{
continue;
}
}
*(proc->flags + (i >> 5)) |= 1 << (i & 0x1f);
proc->playableSongs++;
proc->unk_2e = 1;
}
}
proc->totalSongs = CountDisplayedSoundRoomSongs(proc);
return;
}
//! FE8U = 0x080AEEC0
void sub_80AEEC0(void)
{
return;
}
//! FE8U = 0x080AEEC4
void SoundRoomSongChange_FadeOutPrevious(struct Proc * proc)
{
struct SoundRoomProc * parent = proc->proc_parent;
CallSomeSoundMaybe(0, 0x100, 0, 0x78, proc);
parent->unk_3f = 1;
return;
}
//! FE8U = 0x080AEEE8
void SoundRoomSongChange_StartNext(struct Proc * proc)
{
struct SoundRoomProc * parent = proc->proc_parent;
StartSoundRoomSong(parent, gSoundRoomShuffleBuffer[parent->shuffleIndex], 0);
DrawSoundRoomSongTitle(parent->currentSongIdx);
parent->unk_3f = 0;
return;
}
// clang-format off
struct ProcCmd CONST_DATA gProcScr_SoundRoomSongChange[] =
{
PROC_CALL(SoundRoomSongChange_FadeOutPrevious),
PROC_YIELD,
PROC_CALL(SoundRoomSongChange_StartNext),
PROC_END,
};
// clang-format on
//! FE8U = 0x080AEF24
void PlayNextShuffledSong(struct SoundRoomProc * proc)
{
Proc_Start(gProcScr_SoundRoomSongChange, proc);
proc->shuffleIndex++;
if ((gSoundRoomShuffleBuffer[proc->shuffleIndex] == -1) || (proc->shuffleIndex == 0x80))
{
proc->shuffleIndex = 0;
}
return;
}
//! FE8U = 0x080AEF64
void InitSoundRoomShuffleBuffer(struct SoundRoomProc * proc)
{
int seed1;
int seed2;
int it;
int i;
int numAvailableSongs;
for (i = 0; i < 0x80; i++)
{
gSoundRoomShuffleBuffer[i] = -1;
}
seed1 = GetGameClock() & 0x7f;
it = seed1;
i = 0;
do
{
// TODO: Permuter; addition does not seem to match here
if ((*(proc->flags - -(it >> 5)) >> (it & 0x1f)) & 1)
{
gSoundRoomShuffleBuffer[i] = it;
i++;
}
it = ((it + 1) % 0x80);
} while (it != seed1);
numAvailableSongs = i;
seed2 = GetGameClock() + 0x7b;
for (i = 0; i < 0x100; i++)
{
int idx1;
int idx2;
seed2 = ((seed2 * 0xd) + 1) % 0x8000;
idx1 = (seed2 >> 8) % numAvailableSongs;
seed2 = ((seed2 * 0xd) + 1) % 0x8000;
idx2 = (seed2 >> 8) % numAvailableSongs;
if (idx1 != idx2)
{
gSoundRoomShuffleBuffer[idx1] = gSoundRoomShuffleBuffer[idx1] + gSoundRoomShuffleBuffer[idx2];
gSoundRoomShuffleBuffer[idx2] = gSoundRoomShuffleBuffer[idx1] - gSoundRoomShuffleBuffer[idx2];
gSoundRoomShuffleBuffer[idx1] = gSoundRoomShuffleBuffer[idx1] - gSoundRoomShuffleBuffer[idx2];
}
}
proc->shuffleIndex = 0;
if ((*(proc->flags + (proc->curIndex >> 5)) >> (proc->curIndex & 0x1f)) & 1)
{
for (; gSoundRoomShuffleBuffer[proc->shuffleIndex] != proc->curIndex; proc->shuffleIndex++)
{
if (proc->shuffleIndex == 0x80)
{
proc->shuffleIndex = 0;
goto _080AF0C4;
}
}
}
_080AF0C4:
proc->isSongPlaying = 1;
PlayNextShuffledSong(proc);
return;
}
//! FE8U = 0x080AF0E0
bool SoundRoom_StartNextSong_Positive(struct SoundRoomProc * proc)
{
u8 idx;
for (idx = (proc->currentSongIdx + 1) & 0x7f;; idx = (idx + 1), idx &= 0x7f)
{
if (!(((*(proc->flags + (idx >> 5))) >> (idx & 0x1f)) & 1))
{
continue;
}
if (StartSoundRoomSong(proc, idx, 0x20))
{
DrawSoundRoomSongTitle(proc->currentSongIdx);
return TRUE;
}
return FALSE;
}
}
//! FE8U = 0x080AF140
bool SoundRoom_StartNextSong_Negative(struct SoundRoomProc * proc)
{
u8 idx;
for (idx = (proc->currentSongIdx - 1) & 0x7f;; idx = (idx - 1), idx &= 0x7f)
{
if (!(((*(proc->flags + (idx >> 5))) >> (idx & 0x1f)) & 1))
{
continue;
}
if (StartSoundRoomSong(proc, idx, 0x20))
{
DrawSoundRoomSongTitle(proc->currentSongIdx);
return TRUE;
}
return FALSE;
}
}
//! FE8U = 0x080AF1A0
void UpdateVolumeGraphBuffer(int bufferIndex, int value)
{
int i;
for (i = 0; i < 0x30; i++)
{
gSoundRoomVolumeGraphBuffer[bufferIndex][i] = gSoundRoomVolumeGraphBuffer[bufferIndex][i + 1];
}
gSoundRoomVolumeGraphBuffer[bufferIndex][0x30] = value;
return;
}
//! FE8U = 0x080AF1D8
void InitSoundRoomVolumeGraph(void)
{
int i;
for (i = 0; i < 0x31; i++)
{
gSoundRoomVolumeGraphBuffer[0][i] = 0;
gSoundRoomVolumeGraphBuffer[1][i] = 0;
}
Decompress(Img_SoundRoomVolumeGraph, (void *)0x06010800);
ApplyPalettes(Pal_SoundRoomVolumeGraph, 0x1D, 3);
return;
}
//! FE8U = 0x080AF220
void VolumeGraphBuffer_Init(struct VolumeGraphBufferProc * proc)
{
proc->unk_2c = 0;
return;
}
//! FE8U = 0x080AF228
void VolumeGraphBuffer_Null(void)
{
return;
}
struct SoundInfo * CONST_DATA gpSoundInfo = &gSoundInfo;
//! FE8U = 0x080AF22C
void VolumeGraphBuffer_Loop(struct VolumeGraphBufferProc * proc)
{
int i;
u8 r7 = 0;
u8 r5 = 0;
u8 r8 = -1;
u8 ip = -1;
for (i = 0; i < 0xe0; i++)
{
gUnknown_08A212DC[i].x = (u8)(gpSoundInfo->pcmBuffer[PCM_DMA_BUF_SIZE + proc->unk_2c] - 0x80) >> 1;
gUnknown_08A212DC[i].y = 0xf0 - ((u8)((gpSoundInfo->pcmBuffer[proc->unk_2c]) - 0x80) >> 1);
r5 = r5 > gUnknown_08A212DC[i].x ? r5 : gUnknown_08A212DC[i].x;
ip = ip < gUnknown_08A212DC[i].x ? ip : gUnknown_08A212DC[i].x;
r7 = r7 > gUnknown_08A212DC[i].y ? r7 : gUnknown_08A212DC[i].y;
r8 = r8 < gUnknown_08A212DC[i].y ? r8 : gUnknown_08A212DC[i].y;
proc->unk_2c++;
if (proc->unk_2c >= PCM_DMA_BUF_SIZE)
{
proc->unk_2c -= PCM_DMA_BUF_SIZE;
}
}
r5 = (r5 - ip) < 0x3f ? r5 - ip : 0x3f;
r7 = (r7 - r8) < 0x3f ? r7 - r8 : 0x3f;
UpdateVolumeGraphBuffer(0, (r5 * 3) / 4);
UpdateVolumeGraphBuffer(1, (r7 * 3) / 4);
return;
}
// clang-format off
struct ProcCmd CONST_DATA gProcScr_VolumeGraphBuffer[] =
{
PROC_YIELD,
PROC_CALL(VolumeGraphBuffer_Init),
PROC_YIELD,
PROC_CALL(VolumeGraphBuffer_Null),
PROC_REPEAT(VolumeGraphBuffer_Loop),
PROC_END,
};
// clang-format on
//! FE8U = 0x080AF338
void sub_80AF338(struct SoundRoomProc * proc)
{
int currentSegment = proc->bgYOffset;
int totalRows = (proc->totalSongs + 3) / 4;
UpdateMenuScrollBarConfig(8, currentSegment, totalRows, 5);
return;
}
//! FE8U = 0x080AF350
void sub_80AF350(struct SoundRoomProc * proc)
{
int x = (proc->curIndex & 3) * 32 + 96;
int y = (proc->curIndex >> 2) * 16;
int r2 = (proc->bgYOffset - 64);
y = y - r2;
ShowSysHandCursor(x, y, 2, 0x800);
return;
}
//! FE8U = 0x080AF378
s8 sub_80AF378(struct SoundRoomProc * proc)
{
int adjusted = ((proc->curIndex / 4) * 16 - proc->bgYOffset) / 16;
if (proc->bgYOffset != 0 && adjusted <= 0)
{
return -1;
}
if ((proc->bgYOffset / 16) + 5 > (proc->totalSongs - 1) / 4)
{
return 0;
}
else if (adjusted < 4)
{
return 0;
}
else
{
return +1;
}
}
//! FE8U = 0x080AF3C8
void sub_80AF3C8(struct SoundRoomProc * proc)
{
int i;
int color;
int var = ((proc->bgYOffset >> 4) - 1) * 4;
BG_Fill(gBG2TilemapBuffer, 0);
for (i = var; i < (var + 28); i++)
{
color = TEXT_COLOR_SYSTEM_GRAY;
if (i < 0)
{
continue;
}
if (i >= proc->totalSongs)
{
break;
}
if (IsSoundRoomSongPlayable(proc, i))
{
color = TEXT_COLOR_SYSTEM_WHITE;
}
else
{
if ((gSoundRoomTable[i].displayCondFunc) != 0)
{
PutTwoSpecialChar(
gBG2TilemapBuffer + TILEMAP_INDEX(12 + (i % 4) * 4, (((i / 4) * 2 + 8) & 0x1f)),
TEXT_COLOR_SYSTEM_GRAY, TEXT_SPECIAL_DASH, TEXT_SPECIAL_DASH);
continue;
}
}
if (i >= 99)
{
PutNumber(gBG2TilemapBuffer + TILEMAP_INDEX(13 + (i % 4) * 4, (((i / 4) * 2 + 8) & 0x1f)), color, i + 1);
}
else
{
PutNumber2Digit(
gBG2TilemapBuffer + TILEMAP_INDEX(13 + (i % 4) * 4, (((i / 4) * 2 + 8) & 0x1f)), color, i + 1);
}
}
BG_EnableSyncByMask(BG2_SYNC_BIT);
return;
}
void sub_80AF4D0(u16 * tm, struct SoundRoomProc * proc)
{
PutText(&gUnk_SoundRoom_0201F148.text[0], tm);
PutNumber(
tm + 8, (proc->completionPercent == 100) ? TEXT_COLOR_SYSTEM_GREEN : TEXT_COLOR_SYSTEM_BLUE,
proc->completionPercent);
PutText(&gUnk_SoundRoom_0201F148.text[6], tm + 9);
return;
}
void TickCurrentSongTime(struct SoundRoomProc * proc)
{
if (proc->currentSongTime != 0)
{
proc->currentSongTime++;
}
return;
}
//! FE8U = 0x080AF524
void SoundRoomUi_Init(struct SoundRoomProc * proc)
{
SetupBackgrounds(NULL);
ResetTextFont();
ResetText();
LoadObjUIGfx();
LoadUiFrameGraphics();
InitSystemTextFont();
SetDispEnable(1, 1, 1, 1, 1);
gLCDControlBuffer.bg0cnt.priority = 0;
gLCDControlBuffer.bg1cnt.priority = 2;
gLCDControlBuffer.bg2cnt.priority = 1;
gLCDControlBuffer.bg3cnt.priority = 3;
SetWinEnable(0, 0, 0);
RegisterBlankTile(0);
BG_Fill(gBG0TilemapBuffer, 0);
BG_Fill(gBG1TilemapBuffer, 0);
BG_Fill(gBG2TilemapBuffer, 0);
BG_Fill(gBG3TilemapBuffer, 0);
BG_EnableSyncByMask(BG0_SYNC_BIT | BG1_SYNC_BIT | BG2_SYNC_BIT | BG3_SYNC_BIT);
proc->curIndex = 0;
proc->unk_37 = 0;
proc->bgYOffset = 0;
proc->unk_3b = 0;
proc->unk_3c = 0;
proc->unk_3d = 0;
proc->unk_3e = 0;
proc->unk_2f = 0;
proc->isSongPlaying = 0;
proc->currentSongIdx = -1;
proc->unk_2e = 0;
proc->currentSongTime = 0;
proc->unk_3f = 0;
InitSoundRoomSongData(proc);
sub_80AFF30();
TryDrawSoundRoomSongTitle(proc);
ResetSysHandCursor(proc);
DisplaySysHandCursorTextShadow(0x280, 2);
sub_80AF350(proc);
sub_80AF3C8(proc);
StartMenuScrollBarExt(proc, 216, 72, 0x1000, 3);
sub_80AF338(proc);
Decompress(gUnknown_08A2C908, (void *)0x06004000);
ApplyPalette(gUnknown_08A01EE4, 4);
ApplyPalette(gUnknown_08A01F04, 5);
CallARM_FillTileRect(TILEMAP_LOCATED(gBG1TilemapBuffer, 1, 7), gUnknown_08A2C4C8, 0x1000);
CallARM_FillTileRect(TILEMAP_LOCATED(gBG1TilemapBuffer, 11, 5), gUnknown_08A2C5A8, 0x1000);
sub_80AF4D0(TILEMAP_LOCATED(gBG0TilemapBuffer, 15, 6), proc);
Decompress(gUnknown_08A2D32C, (void *)0x06016000);
ApplyPalette(gUnknown_08A2E1B8, 0x1C);
BG_SetPosition(BG_0, 0, 0);
BG_SetPosition(BG_2, -4, 0);
SetWinEnable(1, 0, 0);
SetWin0Layers(1, 1, 1, 1, 1);
SetWin0Box(4, 66, 240, 144);
SetWOutLayers(1, 1, 0, 1, 1);
Decompress(Img_SoundRoomUiElements, (void *)0x06012000);
ApplyPalettes(Pal_SoundRoomUiElements, 0x13, 3);
DrawSoundRoomSprites(proc);
SetBlendAlpha(15, 3);
SetBlendTargetA(0, 1, 0, 0, 0);
SetBlendTargetB(0, 0, 0, 1, 0);
StartMuralBackground(proc, NULL, 0xe);
StartGreenText(proc);
InitSoundRoomVolumeGraph();
StartParallelWorker(TickCurrentSongTime, proc);
Proc_Start(gProcScr_VolumeGraphBuffer, proc);
return;
}
//! FE8U = 0x080AF7F4
bool StartSoundRoomSong(struct SoundRoomProc * proc, int index, int flagsMaybe)
{
if (MusicProc4Exists())
{
return FALSE;
}
proc->currentSongIdx = index;
proc->currentSongTime = 1;
CallSomeSoundMaybe(gSoundRoomTable[index].bgmId, 0x100, 0x100, flagsMaybe, NULL);
return TRUE;
}
//! FE8U = 0x080AF840
void StopSoundRoomSong(struct SoundRoomProc * proc)
{
if (MusicProc4Exists())
{
return;
}
proc->currentSongTime = 0;
CallSomeSoundMaybe(0, 0x100, 0, 0x18, 0);
proc->unk_2f = 0;
proc->isSongPlaying = 0;
return;
}
//! FE8U = 0x080AF878
void TryDrawSoundRoomSongTitle(struct SoundRoomProc * proc)
{
if (IsSoundRoomSongPlayable(proc, proc->curIndex))
{
DrawSoundRoomSongTitle(proc->curIndex);
}
else
{
DrawSoundRoomSongTitle(-1);
}
return;
}
//! FE8U = 0x080AF8A0
void SoundRoomUi_Loop_MainKeyHandler(struct SoundRoomProc * proc)
{
int moveAmt = 0;
if (proc->unk_37 == 0)
{
u16 keys = gKeyStatusPtr->repeatedKeys;
proc->unk_38 = 4;
if (gKeyStatusPtr->heldKeys & L_BUTTON)
{
keys = gKeyStatusPtr->heldKeys;
proc->unk_38 = 8;
}
if (keys & DPAD_UP)
{
moveAmt = -4;
}
if (keys & DPAD_DOWN)
{
moveAmt = +4;
}
if (keys & DPAD_LEFT)
{
u32 tmp = proc->curIndex;
if ((tmp & 3) != 0)
{
moveAmt = -1;
}
}
if (keys & DPAD_RIGHT)
{
u32 tmp = proc->curIndex;
if ((tmp & 3) < 3)
{
moveAmt = +1;
}
}
if (moveAmt != 0)
{
if ((proc->curIndex + moveAmt) < 0)
{
return;
}
if ((proc->curIndex + moveAmt) >= proc->totalSongs)
{
return;
}
proc->curIndex += moveAmt;
TryDrawSoundRoomSongTitle(proc);
proc->unk_37 = sub_80AF378(proc);
if (proc->unk_37 != 0)
{
if (proc->unk_37 == -1)
{
Proc_Goto(proc, 10);
}
if (proc->unk_37 == +1)
{
Proc_Goto(proc, 11);
}
sub_80AF3C8(proc);
}
else
{
sub_80AF350(proc);
}
}
}
if (proc->unk_37 != 0)
{
int tmp;
proc->bgYOffset = proc->unk_37 * proc->unk_38 + proc->bgYOffset;
BG_SetPosition(2, -4, proc->bgYOffset & 0xff);
tmp = proc->bgYOffset;
if ((tmp & 0xf) == 0)
{
proc->unk_37 = 0;
}
sub_80AF338(proc);
return;
}
if (gKeyStatusPtr->newKeys & START_BUTTON)
{
StopSoundRoomSong(proc);
return;
}
if (gKeyStatusPtr->newKeys & A_BUTTON)
{
if (IsSoundRoomSongPlayable(proc, proc->curIndex))
{
StartSoundRoomSong(proc, proc->curIndex, 0x20);
return;
}
PlaySoundEffect(0x6c);
return;
}
if (gKeyStatusPtr->newKeys & SELECT_BUTTON)
{
if (MusicProc4Exists())
{
return;
}
Proc_Goto(proc, 2);
return;
}
if (gKeyStatusPtr->newKeys & B_BUTTON)
{
Proc_Goto(proc, 3);
return;
}
return;
}
//! FE8U = 0x080AFA64
void SoundRoomUi_RestartTitleMusic(struct SoundRoomProc * proc)
{
if (!MusicProc4Exists())
{
CallSomeSoundMaybe(0x43, 0, 0xc0, 0x18, 0);
Proc_Break(proc);
}
return;
}
//! FE8U = 0x080AFA94
void SoundRoomUi_OnEnd(struct SoundRoomProc * proc)
{
EndMuralBackground();
EndAllProcChildren(proc);
Proc_EndEach(gProcScr_VolumeGraphBuffer);
return;
}
//! FE8U = 0x080AFAB4
void sub_80AFAB4(struct SoundRoomProc * proc)
{
proc->unk_3c = -proc->unk_3b / 3;
proc->unk_3d = (-(proc->unk_3b) * 2) / 3;
proc->unk_3e = proc->unk_3b;
BG_Fill(gBG0TilemapBuffer, 0);
BG_Fill(gBG1TilemapBuffer, 0);
BG_Fill(gBG2TilemapBuffer, 0);
sub_80AC844(gUnknown_08A212D4, 0, 7, 1, proc->unk_3d + 1, 7, 10, 11);
sub_80AC844(gUnknown_08A212D4, 10, 5, 1, proc->unk_3e + 11, 5, 18, 14);
sub_80AC844(gUnknown_08A212D8, 12, 0, 2, proc->unk_3e + 12, 0, 16, 32);
sub_80AC844(gUnknown_08A212D8, 0, 0, 0, proc->unk_3e + 15, 6, 10, 2);
PutMenuScrollBarAt(proc->unk_3e * 8 + 216, 72);
BG_EnableSyncByMask(BG0_SYNC_BIT | BG1_SYNC_BIT | BG2_SYNC_BIT);
return;
}
//! FE8U = 0x080AFBBC
void SoundRoomUi_80AFBBC(struct SoundRoomProc * proc)
{
proc->unk_3b = 0;
CallARM_FillTileRect(TILEMAP_LOCATED(gUnknown_08A212D4, 0, 7), gUnknown_08A2C4C8, 0x1000);
CallARM_FillTileRect(TILEMAP_LOCATED(gUnknown_08A212D4, 10, 5), gUnknown_08A2C5A8, 0x1000);
CpuFastCopy(gBG2TilemapBuffer, gUnknown_08A212D8, 0x800);
sub_80AF4D0(gUnknown_08A212D8, proc);
CallARM_FillTileRect(TILEMAP_LOCATED(gBG1TilemapBuffer, 2, 19), gUnknown_08A2C92C, 0x1200);
CallARM_FillTileRect(TILEMAP_LOCATED(gUnknown_08A212D4, 1, 25), gUnknown_08A2C7A4, 0x1000);
HideSysHandCursor();
proc->unk_3a = 0;
return;
}
//! FE8U = 0x080AFC60
void SoundRoomUi_Loop_MainUiSlideOut(struct SoundRoomProc * proc)
{
int tmp;
proc->unk_3a++;
tmp = ((proc->unk_3a * 2 + proc->unk_3a) << 3) * proc->unk_3a;
proc->unk_3b = tmp >> 6;
sub_80AFAB4(proc);
if (proc->unk_3b == 24)
{
Proc_Break(proc);
}
return;
}
//! FE8U = 0x080AFC98
void SoundRoomUi_80AFC98(struct SoundRoomProc * proc)
{
if (gKeyStatusPtr->newKeys & (A_BUTTON | SELECT_BUTTON))
{
return;
}
if (gKeyStatusPtr->newKeys & DPAD_LEFT)
{
SoundRoom_StartNextSong_Positive(proc);
return;
}