PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
batch.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004 TyRaNiD <tiraniddo@hotmail.com>
3 * Copyright (c) 2004,2007 Lukasz Bruun <mail@lukasz.dk>
4 *
5 * See the file LICENSE included with this distribution for licensing terms.
6 */
7
13#include "types.h"
14#include "sifman.h"
15#include "intrman.h"
16#include "libsd.h"
17#include "spu2regs.h"
18
19u32 BatchData __attribute__((aligned(16)));
20
21s32 SifDmaBatch(u32 ee_addr, void *iop_addr, u32 size)
22{
24 s32 intr_stat;
25 s32 dma_id;
26
27 dma.src = iop_addr;
28 dma.dest = (void *)ee_addr;
29 dma.size = size;
30 dma.attr = 0;
31
32 CpuSuspendIntr((int *)&intr_stat);
33 dma_id = SifSetDma(&dma, SIF_DMA_TO_EE);
34 CpuResumeIntr(intr_stat);
35
36 while(SifDmaStat(dma_id) >= 0);
37
38 if(dma_id == 0) return -1;
39
40 return 0;
41}
42
43int sceSdProcBatch(sceSdBatch *batch, u32 *rets, u32 num)
44{
45 s32 loop;
46 s32 ret;
47
48 for(loop = 0; (u32)loop < num; loop++)
49 {
50 ret = 0;
51
52 switch(batch[loop].func)
53 {
54 case SD_BATCH_SETPARAM:
55 sceSdSetParam(batch[loop].entry, batch[loop].value);
56 break;
57 case SD_BATCH_GETPARAM:
58 ret = sceSdGetParam(batch[loop].entry);
59 break;
60 case SD_BATCH_SETSWITCH:
61 sceSdSetSwitch(batch[loop].entry, batch[loop].value);
62 break;
63 case SD_BATCH_GETSWITCH:
64 ret = sceSdGetSwitch(batch[loop].entry);
65 break;
66 case SD_BATCH_SETADDR:
67 sceSdSetAddr(batch[loop].entry, batch[loop].value);
68 break;
69 case SD_BATCH_GETADDR:
70 ret = sceSdGetAddr(batch[loop].entry);
71 break;
72 case SD_BATCH_SETCORE:
73 sceSdSetCoreAttr(batch[loop].entry, batch[loop].value);
74 break;
75 case SD_BATCH_GETCORE:
76 ret = sceSdGetCoreAttr(batch[loop].entry);
77 break;
78 case SD_BATCH_WRITEIOP:
79 *((u32 *) batch[loop].value) = batch[loop].entry;
80 break;
81 case SD_BATCH_WRITEEE:
82 BatchData = batch[loop].entry;
83 SifDmaBatch(batch[loop].value, &BatchData, 4);
84 break;
85 case SD_BATCH_EERETURN:
86 SifDmaBatch(batch[loop].value, rets, batch[loop].entry);
87 break;
88 default:
89 return -1 - loop;
90 }
91
92 if(rets) rets[loop] = ret;
93 }
94
95 return loop;
96}
97
98int sceSdProcBatchEx(sceSdBatch *batch, u32 *rets, u32 num, u32 voice)
99{
100 s32 loop;
101 s32 ret;
102 s32 voice_loop;
103 s32 cmd_count;
104
105 cmd_count = 0;
106
107 for(loop = 0; (u32)loop < num; loop++)
108 {
109 ret = 0;
110 switch(batch[loop].func)
111 {
112 case SD_BATCH_SETPARAM:
113 {
114 if((batch[loop].entry & 0x3E) != 0x3E)
115 {
116 sceSdSetParam(batch[loop].entry, batch[loop].value);
117 }
118 else
119 {
120 for(voice_loop = 0; voice_loop < 24; voice_loop++)
121 {
122 if(voice & (1 << voice_loop))
123 {
124 sceSdSetParam((batch[loop].entry & 0xFFC1) | (1 << (voice_loop + 1)), batch[loop].value);
125 cmd_count++;
126 }
127 }
128 cmd_count--;
129 }
130 } break;
131
132 case SD_BATCH_GETPARAM:
133 {
134 if((batch[loop].entry & 0x3E) != 0x3E)
135 {
136 ret = sceSdGetParam(batch[loop].entry);
137 }
138 else
139 {
140 for(voice_loop = 0; voice_loop < 24; voice_loop++)
141 {
142 if(voice & (1 << voice_loop))
143 {
144 ret = sceSdGetParam((batch[loop].entry & 0xFFC1) | (1 << (voice_loop + 1)));
145 cmd_count++;
146 }
147
148 if(rets)
149 {
150 rets[cmd_count] = ret;
151 }
152 }
153
154 cmd_count--;
155 }
156 } break;
157
158 case SD_BATCH_SETSWITCH:
159 sceSdSetSwitch(batch[loop].entry, batch[loop].value);
160 break;
161
162 case SD_BATCH_GETSWITCH:
163 ret = sceSdGetSwitch(batch[loop].entry);
164 break;
165
166 case SD_BATCH_SETADDR:
167 {
168 if((batch[loop].entry & 0x3E) != 0x3E)
169 {
170 sceSdSetAddr(batch[loop].entry, batch[loop].value);
171 }
172 else
173 {
174 for(voice_loop = 0; voice_loop < 24; voice_loop++)
175 {
176 if(voice & (1 << voice_loop))
177 {
178 sceSdSetAddr((batch[loop].entry & 0xFFC1) | (1 << (voice_loop + 1)), batch[loop].value);
179 cmd_count++;
180 }
181 }
182 }
183 cmd_count--;
184 } break;
185
186 case SD_BATCH_GETADDR:
187 {
188 if((batch[loop].entry & 0x3E) != 0x3E)
189 {
190 ret = sceSdGetAddr(batch[loop].entry);
191 }
192 else
193 {
194 for(voice_loop = 0; voice_loop < 24; voice_loop++)
195 {
196 if(voice & (1 << voice_loop))
197 {
198 ret = sceSdGetAddr((batch[loop].entry & 0xFFC1) | (1 << (voice_loop + 1)));
199 cmd_count++;
200 }
201
202 if(rets)
203 {
204 rets[cmd_count] = ret;
205 }
206 }
207 }
208 cmd_count--;
209 } break;
210
211 case SD_BATCH_SETCORE:
212 sceSdSetCoreAttr(batch[loop].entry, batch[loop].value);
213 break;
214
215 case SD_BATCH_GETCORE:
216 ret = sceSdGetCoreAttr(batch[loop].entry);
217 break;
218
219 case SD_BATCH_WRITEIOP:
220 *((u32 *) batch[loop].value) = batch[loop].entry;
221 break;
222
223 case SD_BATCH_WRITEEE:
224 BatchData = batch[loop].entry;
225 SifDmaBatch(batch[loop].value, &BatchData, 4);
226 break;
227
228 case SD_BATCH_EERETURN:
229 SifDmaBatch(batch[loop].value, rets, batch[loop].entry);
230 break;
231 default:
232 return -1 - cmd_count;
233 }
234
235 if(rets)
236 {
237 rets[cmd_count] = ret;
238 }
239 cmd_count++;
240 }
241
242 return cmd_count;
243}
int CpuResumeIntr(int state)
Definition intrman.c:227
int CpuSuspendIntr(int *state)
Definition intrman.c:205