1 | /*****************************************************************************\ |
2 | Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. |
3 | This file is licensed under the Snes9x License. |
4 | For further information, consult the LICENSE file in the root directory. |
5 | \*****************************************************************************/ |
6 | |
7 | #ifndef _DSP1_H_ |
8 | #define _DSP1_H_ |
9 | |
10 | enum |
11 | { |
12 | M_DSP1_LOROM_S, |
13 | M_DSP1_LOROM_L, |
14 | M_DSP1_HIROM, |
15 | M_DSP2_LOROM, |
16 | M_DSP3_LOROM, |
17 | M_DSP4_LOROM |
18 | }; |
19 | |
20 | struct SDSP0 |
21 | { |
22 | uint32 maptype; |
23 | uint32 boundary; |
24 | }; |
25 | |
26 | struct SDSP1 |
27 | { |
28 | bool8 waiting4command; |
29 | bool8 first_parameter; |
30 | uint8 command; |
31 | uint32 in_count; |
32 | uint32 in_index; |
33 | uint32 out_count; |
34 | uint32 out_index; |
35 | uint8 parameters[512]; |
36 | uint8 output[512]; |
37 | |
38 | int16 CentreX; |
39 | int16 CentreY; |
40 | int16 VOffset; |
41 | |
42 | int16 VPlane_C; |
43 | int16 VPlane_E; |
44 | |
45 | // Azimuth and Zenith angles |
46 | int16 SinAas; |
47 | int16 CosAas; |
48 | int16 SinAzs; |
49 | int16 CosAzs; |
50 | |
51 | // Clipped Zenith angle |
52 | int16 SinAZS; |
53 | int16 CosAZS; |
54 | int16 SecAZS_C1; |
55 | int16 SecAZS_E1; |
56 | int16 SecAZS_C2; |
57 | int16 SecAZS_E2; |
58 | |
59 | int16 Nx; |
60 | int16 Ny; |
61 | int16 Nz; |
62 | int16 Gx; |
63 | int16 Gy; |
64 | int16 Gz; |
65 | int16 C_Les; |
66 | int16 E_Les; |
67 | int16 G_Les; |
68 | |
69 | int16 matrixA[3][3]; |
70 | int16 matrixB[3][3]; |
71 | int16 matrixC[3][3]; |
72 | |
73 | int16 Op00Multiplicand; |
74 | int16 Op00Multiplier; |
75 | int16 Op00Result; |
76 | |
77 | int16 Op20Multiplicand; |
78 | int16 Op20Multiplier; |
79 | int16 Op20Result; |
80 | |
81 | int16 Op10Coefficient; |
82 | int16 Op10Exponent; |
83 | int16 Op10CoefficientR; |
84 | int16 Op10ExponentR; |
85 | |
86 | int16 Op04Angle; |
87 | int16 Op04Radius; |
88 | int16 Op04Sin; |
89 | int16 Op04Cos; |
90 | |
91 | int16 Op0CA; |
92 | int16 Op0CX1; |
93 | int16 Op0CY1; |
94 | int16 Op0CX2; |
95 | int16 Op0CY2; |
96 | |
97 | int16 Op02FX; |
98 | int16 Op02FY; |
99 | int16 Op02FZ; |
100 | int16 Op02LFE; |
101 | int16 Op02LES; |
102 | int16 Op02AAS; |
103 | int16 Op02AZS; |
104 | int16 Op02VOF; |
105 | int16 Op02VVA; |
106 | int16 Op02CX; |
107 | int16 Op02CY; |
108 | |
109 | int16 Op0AVS; |
110 | int16 Op0AA; |
111 | int16 Op0AB; |
112 | int16 Op0AC; |
113 | int16 Op0AD; |
114 | |
115 | int16 Op06X; |
116 | int16 Op06Y; |
117 | int16 Op06Z; |
118 | int16 Op06H; |
119 | int16 Op06V; |
120 | int16 Op06M; |
121 | |
122 | int16 Op01m; |
123 | int16 Op01Zr; |
124 | int16 Op01Xr; |
125 | int16 Op01Yr; |
126 | |
127 | int16 Op11m; |
128 | int16 Op11Zr; |
129 | int16 Op11Xr; |
130 | int16 Op11Yr; |
131 | |
132 | int16 Op21m; |
133 | int16 Op21Zr; |
134 | int16 Op21Xr; |
135 | int16 Op21Yr; |
136 | |
137 | int16 Op0DX; |
138 | int16 Op0DY; |
139 | int16 Op0DZ; |
140 | int16 Op0DF; |
141 | int16 Op0DL; |
142 | int16 Op0DU; |
143 | |
144 | int16 Op1DX; |
145 | int16 Op1DY; |
146 | int16 Op1DZ; |
147 | int16 Op1DF; |
148 | int16 Op1DL; |
149 | int16 Op1DU; |
150 | |
151 | int16 Op2DX; |
152 | int16 Op2DY; |
153 | int16 Op2DZ; |
154 | int16 Op2DF; |
155 | int16 Op2DL; |
156 | int16 Op2DU; |
157 | |
158 | int16 Op03F; |
159 | int16 Op03L; |
160 | int16 Op03U; |
161 | int16 Op03X; |
162 | int16 Op03Y; |
163 | int16 Op03Z; |
164 | |
165 | int16 Op13F; |
166 | int16 Op13L; |
167 | int16 Op13U; |
168 | int16 Op13X; |
169 | int16 Op13Y; |
170 | int16 Op13Z; |
171 | |
172 | int16 Op23F; |
173 | int16 Op23L; |
174 | int16 Op23U; |
175 | int16 Op23X; |
176 | int16 Op23Y; |
177 | int16 Op23Z; |
178 | |
179 | int16 Op14Zr; |
180 | int16 Op14Xr; |
181 | int16 Op14Yr; |
182 | int16 Op14U; |
183 | int16 Op14F; |
184 | int16 Op14L; |
185 | int16 Op14Zrr; |
186 | int16 Op14Xrr; |
187 | int16 Op14Yrr; |
188 | |
189 | int16 Op0EH; |
190 | int16 Op0EV; |
191 | int16 Op0EX; |
192 | int16 Op0EY; |
193 | |
194 | int16 Op0BX; |
195 | int16 Op0BY; |
196 | int16 Op0BZ; |
197 | int16 Op0BS; |
198 | |
199 | int16 Op1BX; |
200 | int16 Op1BY; |
201 | int16 Op1BZ; |
202 | int16 Op1BS; |
203 | |
204 | int16 Op2BX; |
205 | int16 Op2BY; |
206 | int16 Op2BZ; |
207 | int16 Op2BS; |
208 | |
209 | int16 Op28X; |
210 | int16 Op28Y; |
211 | int16 Op28Z; |
212 | int16 Op28R; |
213 | |
214 | int16 Op1CX; |
215 | int16 Op1CY; |
216 | int16 Op1CZ; |
217 | int16 Op1CXBR; |
218 | int16 Op1CYBR; |
219 | int16 Op1CZBR; |
220 | int16 Op1CXAR; |
221 | int16 Op1CYAR; |
222 | int16 Op1CZAR; |
223 | int16 Op1CX1; |
224 | int16 Op1CY1; |
225 | int16 Op1CZ1; |
226 | int16 Op1CX2; |
227 | int16 Op1CY2; |
228 | int16 Op1CZ2; |
229 | |
230 | uint16 Op0FRamsize; |
231 | uint16 Op0FPass; |
232 | |
233 | int16 Op2FUnknown; |
234 | int16 Op2FSize; |
235 | |
236 | int16 Op08X; |
237 | int16 Op08Y; |
238 | int16 Op08Z; |
239 | int16 Op08Ll; |
240 | int16 Op08Lh; |
241 | |
242 | int16 Op18X; |
243 | int16 Op18Y; |
244 | int16 Op18Z; |
245 | int16 Op18R; |
246 | int16 Op18D; |
247 | |
248 | int16 Op38X; |
249 | int16 Op38Y; |
250 | int16 Op38Z; |
251 | int16 Op38R; |
252 | int16 Op38D; |
253 | }; |
254 | |
255 | struct SDSP2 |
256 | { |
257 | bool8 waiting4command; |
258 | uint8 command; |
259 | uint32 in_count; |
260 | uint32 in_index; |
261 | uint32 out_count; |
262 | uint32 out_index; |
263 | uint8 parameters[512]; |
264 | uint8 output[512]; |
265 | |
266 | bool8 Op05HasLen; |
267 | int32 Op05Len; |
268 | uint8 Op05Transparent; |
269 | |
270 | bool8 Op06HasLen; |
271 | int32 Op06Len; |
272 | |
273 | uint16 Op09Word1; |
274 | uint16 Op09Word2; |
275 | |
276 | bool8 Op0DHasLen; |
277 | int32 Op0DOutLen; |
278 | int32 Op0DInLen; |
279 | }; |
280 | |
281 | struct SDSP3 |
282 | { |
283 | uint16 DR; |
284 | uint16 SR; |
285 | uint16 MemoryIndex; |
286 | |
287 | int16 WinLo; |
288 | int16 WinHi; |
289 | int16 AddLo; |
290 | int16 AddHi; |
291 | |
292 | uint16 Codewords; |
293 | uint16 Outwords; |
294 | uint16 Symbol; |
295 | uint16 BitCount; |
296 | uint16 Index; |
297 | uint16 Codes[512]; |
298 | uint16 BitsLeft; |
299 | uint16 ReqBits; |
300 | uint16 ReqData; |
301 | uint16 BitCommand; |
302 | uint8 BaseLength; |
303 | uint16 BaseCodes; |
304 | uint16 BaseCode; |
305 | uint8 CodeLengths[8]; |
306 | uint16 CodeOffsets[8]; |
307 | uint16 LZCode; |
308 | uint8 LZLength; |
309 | |
310 | uint16 X; |
311 | uint16 Y; |
312 | |
313 | uint8 Bitmap[8]; |
314 | uint8 Bitplane[8]; |
315 | uint16 BMIndex; |
316 | uint16 BPIndex; |
317 | uint16 Count; |
318 | |
319 | int16 op3e_x; |
320 | int16 op3e_y; |
321 | |
322 | int16 op1e_terrain[0x2000]; |
323 | int16 op1e_cost[0x2000]; |
324 | int16 op1e_weight[0x2000]; |
325 | |
326 | int16 op1e_cell; |
327 | int16 op1e_turn; |
328 | int16 op1e_search; |
329 | |
330 | int16 op1e_x; |
331 | int16 op1e_y; |
332 | |
333 | int16 op1e_min_radius; |
334 | int16 op1e_max_radius; |
335 | |
336 | int16 op1e_max_search_radius; |
337 | int16 op1e_max_path_radius; |
338 | |
339 | int16 op1e_lcv_radius; |
340 | int16 op1e_lcv_steps; |
341 | int16 op1e_lcv_turns; |
342 | }; |
343 | |
344 | struct SDSP4 |
345 | { |
346 | bool8 waiting4command; |
347 | bool8 half_command; |
348 | uint16 command; |
349 | uint32 in_count; |
350 | uint32 in_index; |
351 | uint32 out_count; |
352 | uint32 out_index; |
353 | uint8 parameters[512]; |
354 | uint8 output[512]; |
355 | uint8 byte; |
356 | uint16 address; |
357 | |
358 | // op control |
359 | int8 Logic; // controls op flow |
360 | |
361 | // projection format |
362 | int16 lcv; // loop-control variable |
363 | int16 distance; // z-position into virtual world |
364 | int16 raster; // current raster line |
365 | int16 segments; // number of raster lines drawn |
366 | |
367 | // 1.15.16 or 1.15.0 [sign, integer, fraction] |
368 | int32 world_x; // line of x-projection in world |
369 | int32 world_y; // line of y-projection in world |
370 | int32 world_dx; // projection line x-delta |
371 | int32 world_dy; // projection line y-delta |
372 | int16 world_ddx; // x-delta increment |
373 | int16 world_ddy; // y-delta increment |
374 | int32 world_xenv; // world x-shaping factor |
375 | int16 world_yofs; // world y-vertical scroll |
376 | int16 view_x1; // current viewer-x |
377 | int16 view_y1; // current viewer-y |
378 | int16 view_x2; // future viewer-x |
379 | int16 view_y2; // future viewer-y |
380 | int16 view_dx; // view x-delta factor |
381 | int16 view_dy; // view y-delta factor |
382 | int16 view_xofs1; // current viewer x-vertical scroll |
383 | int16 view_yofs1; // current viewer y-vertical scroll |
384 | int16 view_xofs2; // future viewer x-vertical scroll |
385 | int16 view_yofs2; // future viewer y-vertical scroll |
386 | int16 view_yofsenv; // y-scroll shaping factor |
387 | int16 view_turnoff_x; // road turnoff data |
388 | int16 view_turnoff_dx; // road turnoff delta factor |
389 | |
390 | // drawing area |
391 | int16 viewport_cx; // x-center of viewport window |
392 | int16 viewport_cy; // y-center of render window |
393 | int16 viewport_left; // x-left of viewport |
394 | int16 viewport_right; // x-right of viewport |
395 | int16 viewport_top; // y-top of viewport |
396 | int16 viewport_bottom; // y-bottom of viewport |
397 | |
398 | // sprite structure |
399 | int16 sprite_x; // projected x-pos of sprite |
400 | int16 sprite_y; // projected y-pos of sprite |
401 | int16 sprite_attr; // obj attributes |
402 | bool8 sprite_size; // sprite size: 8x8 or 16x16 |
403 | int16 sprite_clipy; // visible line to clip pixels off |
404 | int16 sprite_count; |
405 | |
406 | // generic projection variables designed for two solid polygons + two polygon sides |
407 | int16 poly_clipLf[2][2]; // left clip boundary |
408 | int16 poly_clipRt[2][2]; // right clip boundary |
409 | int16 poly_ptr[2][2]; // HDMA structure pointers |
410 | int16 poly_raster[2][2]; // current raster line below horizon |
411 | int16 poly_top[2][2]; // top clip boundary |
412 | int16 poly_bottom[2][2]; // bottom clip boundary |
413 | int16 poly_cx[2][2]; // center for left/right points |
414 | int16 poly_start[2]; // current projection points |
415 | int16 poly_plane[2]; // previous z-plane distance |
416 | |
417 | // OAM |
418 | int16 OAM_attr[16]; // OAM (size, MSB) data |
419 | int16 OAM_index; // index into OAM table |
420 | int16 OAM_bits; // offset into OAM table |
421 | int16 OAM_RowMax; // maximum number of tiles per 8 aligned pixels (row) |
422 | int16 OAM_Row[32]; // current number of tiles per row |
423 | }; |
424 | |
425 | extern struct SDSP0 DSP0; |
426 | extern struct SDSP1 DSP1; |
427 | extern struct SDSP2 DSP2; |
428 | extern struct SDSP3 DSP3; |
429 | extern struct SDSP4 DSP4; |
430 | |
431 | uint8 S9xGetDSP (uint16); |
432 | void S9xSetDSP (uint8, uint16); |
433 | void S9xResetDSP (void); |
434 | uint8 DSP1GetByte (uint16); |
435 | void DSP1SetByte (uint8, uint16); |
436 | uint8 DSP2GetByte (uint16); |
437 | void DSP2SetByte (uint8, uint16); |
438 | uint8 DSP3GetByte (uint16); |
439 | void DSP3SetByte (uint8, uint16); |
440 | uint8 DSP4GetByte (uint16); |
441 | void DSP4SetByte (uint8, uint16); |
442 | void DSP3_Reset (void); |
443 | |
444 | extern uint8 (*GetDSP) (uint16); |
445 | extern void (*SetDSP) (uint8, uint16); |
446 | |
447 | #endif |
448 | |