PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
seqinit.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "libsnd2_internal.h"
12
13s16 _SsInitSoundSeq(s16 seq_no, s16 vab_id, u8 *addr)
14{
15 int v4;
16 libsnd2_sequence_struct_t *score_struct;
17 int v8;
18 u8 v9;
19 u8 v11;
20 u8 v12;
21 u8 v13;
22 u8 v14;
23 int tempo;
24 int delta_value;
25 unsigned int v20;
26 int tmp1;
27 unsigned int tmp2;
28
29 score_struct = &_ss_score[seq_no][0];
30 score_struct->m_vab_id = vab_id;
31 score_struct->m_resolution_of_quarter_note = 0;
32 score_struct->m_unk18 = 0;
33 score_struct->m_unk19 = 0;
34 score_struct->m_unk1E = 0;
35 score_struct->m_fn_idx = 0;
36 score_struct->m_unk1B = 0;
37 score_struct->m_unk1F = 0;
38 score_struct->m_channel_idx = 0;
39 score_struct->m_unk84 = 0;
40 score_struct->m_unk88 = 0;
41 score_struct->m_tempo = 0;
42 score_struct->m_unk56 = 0;
43 score_struct->m_l_count = 1;
44 score_struct->m_unk21 = 0;
45 score_struct->m_play_mode = SSPLAY_PAUSE;
46 score_struct->m_delta_value = 0;
47 score_struct->m_unk1C = 0;
48 score_struct->m_unk1D = 0;
49 score_struct->m_unk15 = 0;
50 score_struct->m_running_status = 0;
51 score_struct->m_channel_mute = 0;
52 score_struct->m_rhythm_n = 0;
53 score_struct->m_rhythm_d = 0;
54 for ( v4 = 0; v4 < 16; v4 += 1 )
55 {
56 score_struct->m_programs[v4] = v4;
57 score_struct->m_panpot[v4] = 64;
58 score_struct->m_vol[v4] = 127;
59 }
60 score_struct->m_unk52 = 1;
61 score_struct->m_seq_ptr = addr;
62 v8 = *addr;
63 score_struct->m_seq_ptr += 7;
64 if ( v8 != 83 && v8 != 112 )
65 {
66 printf("This is an old SEQ Data Format.\n");
67 return 0;
68 }
69 v9 = *(score_struct->m_seq_ptr);
70 score_struct->m_seq_ptr += 1;
71 if ( v9 != 1 )
72 {
73 printf("This is not SEQ Data.\n");
74 return -1;
75 }
76 v11 = *(score_struct->m_seq_ptr);
77 score_struct->m_seq_ptr += 1;
78 v12 = *(score_struct->m_seq_ptr);
79 score_struct->m_seq_ptr += 1;
80 score_struct->m_resolution_of_quarter_note = v12 | (v11 << 8);
81 v13 = *(score_struct->m_seq_ptr);
82 score_struct->m_seq_ptr += 1;
83 v14 = *(score_struct->m_seq_ptr);
84 score_struct->m_seq_ptr += 1;
85 tempo = 60000000 / ((v13 << 16) | (v14 << 8) | *(score_struct->m_seq_ptr));
86 score_struct->m_seq_ptr += 1;
87 score_struct->m_tempo = tempo;
88 score_struct->m_unk94 = score_struct->m_tempo;
89 score_struct->m_rhythm_n = *(score_struct->m_seq_ptr);
90 score_struct->m_seq_ptr += 1;
91 score_struct->m_rhythm_d = *(score_struct->m_seq_ptr);
92 score_struct->m_seq_ptr += 1;
93 delta_value = _SsReadDeltaValue(seq_no, 0);
94 v20 = score_struct->m_resolution_of_quarter_note * score_struct->m_tempo;
95 score_struct->m_unk84 = delta_value;
96 score_struct->m_delta_value = delta_value;
97 score_struct->m_unk10 = 0;
98 score_struct->m_unk08 = score_struct->m_seq_ptr;
99 score_struct->m_unk04 = score_struct->m_seq_ptr;
100 score_struct->m_unk0C = score_struct->m_seq_ptr;
101 tmp1 = VBLANK_MINUS;
102 tmp2 = 60 * tmp1;
103 if ( 10 * v20 < (unsigned int)(60 * tmp1) )
104 {
105 unsigned int v25;
106
107 if ( !v20 )
108 __builtin_trap();
109 v25 = 600 * tmp1 / v20;
110 score_struct->m_unk52 = v25;
111 score_struct->m_unk54 = v25;
112 }
113 else
114 {
115 unsigned int v27;
116 unsigned int v28;
117
118 v27 = 10 * score_struct->m_resolution_of_quarter_note * score_struct->m_tempo / tmp2;
119 v28 = 10 * score_struct->m_resolution_of_quarter_note * score_struct->m_tempo % tmp2;
120 score_struct->m_unk52 = -1;
121 score_struct->m_unk54 = v27;
122 if ( (unsigned int)(30 * tmp1) < v28 )
123 {
124 score_struct->m_unk54 = v27 + 1;
125 }
126 }
127 score_struct->m_unk56 = score_struct->m_unk54;
128 return 0;
129}