PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
s_sav.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 "libspu2_internal.h"
12
13unsigned int _SpuSetAnyVoice(int on_off_flags, unsigned int voice_bits, int word_idx1, int word_idx2)
14{
15 // Unofficial: Fixed _spu_RQ and _spu_RQmask access offsets
16 int p_register_1;
17 int p_register_2;
18 unsigned int ret_bits;
19
20 if ( (_spu_env & 1) != 0 )
21 {
22 p_register_1 = _spu_RQ[word_idx1 - 188];
23 p_register_2 = (u8)_spu_RQ[word_idx2 - 188];
24 }
25 else
26 {
27 p_register_1 = _spu_RXX[512 * _spu_core + word_idx1];
28 p_register_2 = (u8)_spu_RXX[512 * _spu_core + word_idx2];
29 }
30 ret_bits = p_register_1 | (p_register_2 << 16);
31 switch ( on_off_flags )
32 {
33 case SPU_OFF:
34 if ( (_spu_env & 1) != 0 )
35 {
36 _spu_RQ[word_idx1 - 188] &= ~(u16)voice_bits;
37 _spu_RQ[word_idx2 - 188] &= ~((voice_bits >> 16) & 0xFF);
38 _spu_RQmask |= 1 << ((word_idx1 - 190) >> 1);
39 if ( (1 << ((word_idx1 - 190) >> 1)) == 16 )
40 {
41 _spu_RQmask |= 8;
42 }
43 }
44 else
45 {
46 _spu_RXX[512 * _spu_core + word_idx1] &= ~(u16)voice_bits;
47 _spu_RXX[512 * _spu_core + word_idx2] &= ~((voice_bits >> 16 & 0xFF));
48 }
49 ret_bits &= ~(voice_bits & 0xFFFFFF);
50 break;
51 case SPU_ON:
52 if ( (_spu_env & 1) != 0 )
53 {
54 _spu_RQ[word_idx1 - 188] |= voice_bits;
55 _spu_RQ[word_idx2 - 188] |= (voice_bits >> 16) & 0xFF;
56 _spu_RQmask |= 1 << ((word_idx1 - 190) >> 1);
57 if ( (1 << ((word_idx1 - 190) >> 1)) == 16 )
58 {
59 _spu_RQmask |= 8;
60 }
61 }
62 else
63 {
64 _spu_RXX[512 * _spu_core + word_idx1] |= voice_bits;
65 _spu_RXX[512 * _spu_core + word_idx2] |= (voice_bits >> 16) & 0xFF;
66 }
67 ret_bits |= voice_bits & 0xFFFFFF;
68 break;
69 case SPU_BIT:
70 if ( (_spu_env & 1) != 0 )
71 {
72 _spu_RQ[word_idx1 - 188] = voice_bits;
73 _spu_RQ[word_idx2 - 188] = (voice_bits >> 16) & 0xFF;
74 _spu_RQmask |= 1 << ((word_idx1 - 190) >> 1);
75 if ( (1 << ((word_idx1 - 190) >> 1)) == 16 )
76 {
77 _spu_RQmask |= 8;
78 }
79 }
80 else
81 {
82 _spu_RXX[512 * _spu_core + word_idx1] = voice_bits;
83 _spu_RXX[512 * _spu_core + word_idx2] = (voice_bits >> 16) & 0xFF;
84 }
85 ret_bits = voice_bits & 0xFFFFFF;
86 break;
87 default:
88 break;
89 }
90 return ret_bits & 0xFFFFFF;
91}