PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ssstart.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
13libsnd2_seq_tick_env_t _snd_seq_tick_env = {60, 1, &SsSeqCalledTbyT, NULL, 0u, 0u, 127u, 0u};
14int _snd_seq_interval = 1;
15
16#ifdef LIB_1300
17void _SsTrapIntrVSync(void)
18{
19 if ( _snd_seq_tick_env.m_vsync_callback )
20 _snd_seq_tick_env.m_vsync_callback();
21 _snd_seq_tick_env.m_tick_callback();
22}
23#endif
24
25#ifdef LIB_1300
26void _SsSeqCalledTbyT_1per2(void)
27{
28 static int n_4 = 0;
29
30 if ( n_4 )
31 {
32 n_4 = 0;
33 _snd_seq_tick_env.m_tick_callback();
34 }
35 else
36 {
37 n_4 = 1;
38 }
39}
40#endif
41
42int _SsTrapIntrProcIOP(void *userdata)
43{
44 _snd_seq_tick_env.m_tick_callback();
45 return *(u32 *)userdata;
46}
47
48static void _SsStart(int start_param)
49{
50 int wait_tmp;
51#ifndef LIB_1300
52 u32 rcount_target;
53 iop_sys_clock_t iop_clock;
54#endif
55
56#ifndef LIB_1300
57 rcount_target = 0x1046;
58#endif
59 for ( wait_tmp = 0; wait_tmp < 999; wait_tmp += 1 )
60 {
61 __asm__ __volatile__("" : "+g"(wait_tmp) : :);
62 }
63 _snd_seq_tick_env.m_alarm_tick = 6;
64 _snd_seq_tick_env.m_vsync_tick = 0;
65 _snd_seq_tick_env.m_unk11 = 0;
66 _snd_seq_tick_env.m_vsync_callback = 0;
67 switch ( _snd_seq_tick_env.m_tick_mode )
68 {
69 case SS_NOTICK0:
70 _snd_seq_tick_env.m_alarm_tick = 127;
71 return;
72 case SS_TICK240:
73 break;
74 case SS_TICK120:
75#ifndef LIB_1300
76 rcount_target = 0x208c;
77#endif
78 break;
79 case SS_TICKVSYNC:
80 _snd_seq_tick_env.m_alarm_tick = 0;
81 if ( !start_param )
82 _snd_seq_tick_env.m_vsync_tick = 1;
83#ifndef LIB_1300
84 else
85 rcount_target = 1;
86#endif
87 break;
88 case SS_TICK60:
89 case SS_TICK50:
90 default:
91 if ( _snd_seq_tick_env.m_manual_tick )
92 return;
93#ifdef LIB_1300
94 if ( _snd_seq_tick_env.m_tick_mode < 70 )
95 {
96 _snd_seq_tick_env.m_unk11 += 1;
97 return;
98 }
99#endif
100#ifndef LIB_1300
101 if ( _snd_seq_tick_env.m_tick_mode == 0 )
102 __builtin_trap();
103 rcount_target = -1000000;
104#endif
105 break;
106 }
107#ifndef LIB_1300
109 if ( _snd_seq_tick_env.m_vsync_tick )
110 {
111 RegisterVblankHandler(0, 64, _SsTrapIntrProcIOP, &_snd_seq_interval);
112 EnableIntr(0);
113 }
114 else if ( _snd_seq_tick_env.m_alarm_tick )
115 {
116 USec2SysClock(rcount_target, &iop_clock);
117 _snd_seq_interval = iop_clock.lo;
118 SetAlarm(&iop_clock, (unsigned int (*)(void *))_SsTrapIntrProcIOP, &_snd_seq_interval);
119 }
120 else
121 {
122 EnableIntr(0);
123 RegisterVblankHandler(0, 64, _SsTrapIntrProcIOP, &_snd_seq_interval);
124 }
126#endif
127}
128
129void SsStart(void)
130{
131 _SsStart(1);
132}
133
134void SsStart2(void)
135{
136 _SsStart(0);
137}
int CpuEnableIntr()
Definition intrman.c:250
int CpuDisableIntr()
Definition intrman.c:238
int EnableIntr(int irq)
Definition intrman.c:346