KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
pvr.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  dc/pvr.h
4  Copyright (C) 2002 Dan Potter
5 
6  Low-level PVR 3D interface for the DC
7  Note: this API does _not_ handle any sort of transformations
8  (including perspective!) so for that, you should look to KGL.
9 */
10 
11 /** \file dc/pvr.h
12  \brief Low-level PVR (3D hardware) interface.
13 
14  This file provides support for using the PVR 3D hardware in the Dreamcast.
15  Note that this does not handle any sort of perspective transformations or
16  anything of the like. This is just a very thin wrapper around the actual
17  hardware support.
18 
19  This file is used for pretty much everything related to the PVR, from memory
20  management to actual primitive rendering.
21 
22  \author Dan Potter
23  \author Roger Cattermole
24  \author Paul Boese
25  \author Brian Paul
26  \author Lawrence Sebald
27  \author Benoit Miller
28 */
29 
30 #ifndef __DC_PVR_H
31 #define __DC_PVR_H
32 
33 #include <sys/cdefs.h>
34 __BEGIN_DECLS
35 
36 #include <arch/types.h>
37 #include <dc/sq.h>
38 #include <kos/img.h>
39 
40 /* Data types ********************************************************/
41 
42 /** \brief PVR texture memory pointer.
43 
44  Unlike the old "TA" system, PVR pointers in the new system are actually SH-4
45  compatible pointers and can be used directly in place of ta_txr_map().
46 
47  Not that anyone probably even remembers the old TA system anymore... */
48 typedef void * pvr_ptr_t;
49 
50 /** \brief PVR list specification.
51 
52  Each primitive in the PVR is submitted to one of the hardware primitive
53  lists. This type is an identifier for a list.
54 
55  \see pvr_lists
56 */
58 
59 /** \brief PVR polygon context.
60 
61  You should use this more human readable format for specifying your polygon
62  contexts, and then compile them into polygon headers when you are ready to
63  start using them.
64 
65  This has embedded structures in it for two reasons; the first reason is to
66  make it easier for me to add new stuff later without breaking existing code.
67  The second reason is to make it more readable and usable.
68 
69  Unfortunately, it seems that Doxygen chokes up a little bit on this
70  structure, and others like it. The documentation should still be mostly
71  understandable though...
72 
73  \headerfile dc/pvr.h
74 */
75 typedef struct {
76  int list_type; /**< \brief Primitive list
77  \see pvr_lists */
78  struct {
79  int alpha; /**< \brief Enable or disable alpha outside modifier
80  \see pvr_alpha_switch */
81  int shading; /**< \brief Shading type
82  \see pvr_shading_types */
83  int fog_type; /**< \brief Fog type outside modifier
84  \see pvr_fog_types */
85  int culling; /**< \brief Culling mode
86  \see pvr_cull_modes */
87  int color_clamp; /**< \brief Color clamp enable/disable outside modifier
88  \see pvr_colclamp_switch */
89  int clip_mode; /**< \brief Clipping mode
90  \see pvr_clip_modes */
91  int modifier_mode; /**< \brief Modifier mode */
92  int alpha2; /**< \brief Enable/disable alpha inside modifier
93  \see pvr_alpha_switch */
94  int fog_type2; /**< \brief Fog type inside modifier
95  \see pvr_fog_types */
96  int color_clamp2; /**< \brief Color clamp enable/disable inside modifier
97  \see pvr_colclamp_switch */
98  } gen; /**< \brief General parameters */
99  struct {
100  int src; /**< \brief Source blending mode outside modifier
101  \see pvr_blend_modes */
102  int dst; /**< \brief Dest blending mode outside modifier
103  \see pvr_blend_modes */
104  int src_enable; /**< \brief Source blending enable outside modifier
105  \see pvr_blend_switch */
106  int dst_enable; /**< \brief Dest blending enable outside modifier
107  \see pvr_blend_switch */
108  int src2; /**< \brief Source blending mode inside modifier
109  \see pvr_blend_modes */
110  int dst2; /**< \brief Dest blending mode inside modifier
111  \see pvr_blend_modes */
112  int src_enable2; /**< \brief Source blending mode inside modifier
113  \see pvr_blend_switch */
114  int dst_enable2; /**< \brief Dest blending mode inside modifier
115  \see pvr_blend_switch */
116  } blend; /**< \brief Blending parameters */
117  struct {
118  int color; /**< \brief Color format in vertex
119  \see pvr_color_fmts */
120  int uv; /**< \brief U/V data format in vertex
121  \see pvr_uv_fmts */
122  int modifier; /**< \brief Enable or disable modifier effect
123  \see pvr_mod_switch */
124  } fmt; /**< \brief Format control */
125  struct {
126  int comparison; /**< \brief Depth comparison mode
127  \see pvr_depth_modes */
128  int write; /**< \brief Enable or disable depth writes
129  \see pvr_depth_switch */
130  } depth; /**< \brief Depth comparison/write modes */
131  struct {
132  int enable; /**< \brief Enable/disable texturing
133  \see pvr_txr_switch */
134  int filter; /**< \brief Filtering mode
135  \see pvr_filter_modes */
136  int mipmap; /**< \brief Enable/disable mipmaps
137  \see pvr_mip_switch */
138  int mipmap_bias; /**< \brief Mipmap bias
139  \see pvr_mip_bias */
140  int uv_flip; /**< \brief Enable/disable U/V flipping
141  \see pvr_uv_flip */
142  int uv_clamp; /**< \brief Enable/disable U/V clamping
143  \see pvr_uv_clamp */
144  int alpha; /**< \brief Enable/disable texture alpha
145  \see pvr_txralpha_switch */
146  int env; /**< \brief Texture color contribution
147  \see pvr_txrenv_modes */
148  int width; /**< \brief Texture width (requires a power of 2) */
149  int height; /**< \brief Texture height (requires a power of 2) */
150  int format; /**< \brief Texture format
151  \see pvr_txr_fmts */
152  pvr_ptr_t base; /**< \brief Texture pointer */
153  } txr; /**< \brief Texturing params outside modifier */
154  struct {
155  int enable; /**< \brief Enable/disable texturing
156  \see pvr_txr_switch */
157  int filter; /**< \brief Filtering mode
158  \see pvr_filter_modes */
159  int mipmap; /**< \brief Enable/disable mipmaps
160  \see pvr_mip_switch */
161  int mipmap_bias; /**< \brief Mipmap bias
162  \see pvr_mip_bias */
163  int uv_flip; /**< \brief Enable/disable U/V flipping
164  \see pvr_uv_flip */
165  int uv_clamp; /**< \brief Enable/disable U/V clamping
166  \see pvr_uv_clamp */
167  int alpha; /**< \brief Enable/disable texture alpha
168  \see pvr_txralpha_switch */
169  int env; /**< \brief Texture color contribution
170  \see pvr_txrenv_modes */
171  int width; /**< \brief Texture width (requires a power of 2) */
172  int height; /**< \brief Texture height (requires a power of 2) */
173  int format; /**< \brief Texture format
174  \see pvr_txr_fmts */
175  pvr_ptr_t base; /**< \brief Texture pointer */
176  } txr2; /**< \brief Texturing params inside modifier */
178 
179 /** \brief PVR sprite context.
180 
181  You should use this more human readable format for specifying your sprite
182  contexts, and then compile them into sprite headers when you are ready to
183  start using them.
184 
185  Unfortunately, it seems that Doxygen chokes up a little bit on this
186  structure, and others like it. The documentation should still be mostly
187  understandable though...
188 
189  \headerfile dc/pvr.h
190 */
191 typedef struct {
192  int list_type; /**< \brief Primitive list
193  \see pvr_lists */
194  struct {
195  int alpha; /**< \brief Enable or disable alpha outside modifier
196  \see pvr_alpha_switch */
197  int fog_type; /**< \brief Fog type outside modifier
198  \see pvr_fog_types */
199  int culling; /**< \brief Culling mode
200  \see pvr_cull_modes */
201  int color_clamp; /**< \brief Color clamp enable/disable outside modifier
202  \see pvr_colclamp_switch */
203  int clip_mode; /**< \brief Clipping mode
204  \see pvr_clip_modes */
205  } gen; /**< \brief General parameters */
206  struct {
207  int src; /**< \brief Source blending mode outside modifier
208  \see pvr_blend_modes */
209  int dst; /**< \brief Dest blending mode outside modifier
210  \see pvr_blend_modes */
211  int src_enable; /**< \brief Source blending enable outside modifier
212  \see pvr_blend_switch */
213  int dst_enable; /**< \brief Dest blending enable outside modifier
214  \see pvr_blend_switch */
215  } blend;
216  struct {
217  int comparison; /**< \brief Depth comparison mode
218  \see pvr_depth_modes */
219  int write; /**< \brief Enable or disable depth writes
220  \see pvr_depth_switch */
221  } depth; /**< \brief Depth comparison/write modes */
222  struct {
223  int enable; /**< \brief Enable/disable texturing
224  \see pvr_txr_switch */
225  int filter; /**< \brief Filtering mode
226  \see pvr_filter_modes */
227  int mipmap; /**< \brief Enable/disable mipmaps
228  \see pvr_mip_switch */
229  int mipmap_bias; /**< \brief Mipmap bias
230  \see pvr_mip_bias */
231  int uv_flip; /**< \brief Enable/disable U/V flipping
232  \see pvr_uv_flip */
233  int uv_clamp; /**< \brief Enable/disable U/V clamping
234  \see pvr_uv_clamp */
235  int alpha; /**< \brief Enable/disable texture alpha
236  \see pvr_txralpha_switch */
237  int width; /**< \brief Texture width (requires a power of 2) */
238  int height; /**< \brief Texture height (requires a power of 2) */
239  int format; /**< \brief Texture format
240  \see pvr_txr_fmts */
241  pvr_ptr_t base; /**< \brief Texture pointer */
242  } txr; /**< \brief Texturing params */
244 
245 /* Constants for the above structure; thanks to Benoit Miller for these */
246 
247 /** \defgroup pvr_lists PVR primitive list types
248 
249  Each primitive submitted to the PVR must be placed in one of these lists,
250  depending on its characteristics.
251 
252  @{
253 */
254 #define PVR_LIST_OP_POLY 0 /**< \brief Opaque polygon list */
255 #define PVR_LIST_OP_MOD 1 /**< \brief Opaque modifier list */
256 #define PVR_LIST_TR_POLY 2 /**< \brief Translucent polygon list */
257 #define PVR_LIST_TR_MOD 3 /**< \brief Translucent modifier list*/
258 #define PVR_LIST_PT_POLY 4 /**< \brief Punch-thru polygon list */
259 /** @} */
260 
261 /** \defgroup pvr_shading_types PVR shading modes
262 
263  Each polygon can define how it wants to be shaded, be it with flat or
264  Gouraud shading using these constants in the appropriate place in its
265  pvr_poly_cxt_t.
266 
267  @{
268 */
269 #define PVR_SHADE_FLAT 0 /**< \brief Use flat shading */
270 #define PVR_SHADE_GOURAUD 1 /**< \brief Use Gouraud shading */
271 /** @} */
272 
273 /** \defgroup pvr_depth_modes PVR depth comparison modes
274 
275  These set the depth function used for comparisons.
276 
277  @{
278 */
279 #define PVR_DEPTHCMP_NEVER 0 /**< \brief Never pass */
280 #define PVR_DEPTHCMP_LESS 1 /**< \brief Less than */
281 #define PVR_DEPTHCMP_EQUAL 2 /**< \brief Equal to */
282 #define PVR_DEPTHCMP_LEQUAL 3 /**< \brief Less than or equal to */
283 #define PVR_DEPTHCMP_GREATER 4 /**< \brief Greater than */
284 #define PVR_DEPTHCMP_NOTEQUAL 5 /**< \brief Not equal to */
285 #define PVR_DEPTHCMP_GEQUAL 6 /**< \brief Greater than or equal to */
286 #define PVR_DEPTHCMP_ALWAYS 7 /**< \brief Always pass */
287 /** @} */
288 
289 /** \defgroup pvr_cull_modes PVR culling modes
290 
291  These culling modes can be set by polygons to determine when they are
292  culled. They work pretty much as you'd expect them to if you've ever used
293  any 3D hardware before.
294 
295  @{
296 */
297 #define PVR_CULLING_NONE 0 /**< \brief Disable culling */
298 #define PVR_CULLING_SMALL 1 /**< \brief Cull if small */
299 #define PVR_CULLING_CCW 2 /**< \brief Cull if counterclockwise */
300 #define PVR_CULLING_CW 3 /**< \brief Cull if clockwise */
301 /** @} */
302 
303 /** \defgroup pvr_depth_switch Enable or disable PVR depth writes
304  @{
305 */
306 #define PVR_DEPTHWRITE_ENABLE 0 /**< \brief Update the Z value */
307 #define PVR_DEPTHWRITE_DISABLE 1 /**< \brief Do not update the Z value */
308 /** @} */
309 
310 /** \defgroup pvr_txr_switch Enable or disable texturing on polygons
311  @{
312 */
313 #define PVR_TEXTURE_DISABLE 0 /**< \brief Disable texturing */
314 #define PVR_TEXTURE_ENABLE 1 /**< \brief Enable texturing */
315 /** @} */
316 
317 /** \defgroup pvr_blend_modes PVR blending modes
318 
319  These are all the blending modes that can be done with regard to alpha
320  blending on the PVR.
321 
322  @{
323 */
324 #define PVR_BLEND_ZERO 0 /**< \brief None of this color */
325 #define PVR_BLEND_ONE 1 /**< \brief All of this color */
326 #define PVR_BLEND_DESTCOLOR 2 /**< \brief Destination color */
327 #define PVR_BLEND_INVDESTCOLOR 3 /**< \brief Inverse of destination color */
328 #define PVR_BLEND_SRCALPHA 4 /**< \brief Blend with source alpha */
329 #define PVR_BLEND_INVSRCALPHA 5 /**< \brief Blend with inverse source alpha */
330 #define PVR_BLEND_DESTALPHA 6 /**< \brief Blend with destination alpha */
331 #define PVR_BLEND_INVDESTALPHA 7 /**< \brief Blend with inverse destination alpha */
332 /** @} */
333 
334 /** \defgroup pvr_blend_switch Enable or disable blending
335  @{
336 */
337 #define PVR_BLEND_DISABLE 0 /**< \brief Disable blending */
338 #define PVR_BLEND_ENABLE 1 /**< \brief Enable blending */
339 /** @} */
340 
341 /** \defgroup pvr_fog_types PVR fog modes
342 
343  Each polygon can decide what fog type is used with regard to it using these
344  constants in its pvr_poly_cxt_t.
345 
346  @{
347 */
348 #define PVR_FOG_TABLE 0 /**< \brief Table fog */
349 #define PVR_FOG_VERTEX 1 /**< \brief Vertex fog */
350 #define PVR_FOG_DISABLE 2 /**< \brief Disable fog */
351 #define PVR_FOG_TABLE2 3 /**< \brief Table fog mode 2 */
352 /** @} */
353 
354 /** \defgroup pvr_clip_modes PVR clipping modes
355 
356  These control how primitives are clipped against the user clipping area.
357 
358  @{
359 */
360 #define PVR_USERCLIP_DISABLE 0 /**< \brief Disable clipping */
361 #define PVR_USERCLIP_INSIDE 2 /**< \brief Enable clipping inside area */
362 #define PVR_USERCLIP_OUTSIDE 3 /**< \brief Enable clipping outside area */
363 /** @} */
364 
365 /** \defgroup pvr_colclamp_switch Enable or disable color clamping
366 
367  Enabling color clamping will clamp colors between the minimum and maximum
368  values before any sort of fog processing.
369 
370  @{
371 */
372 #define PVR_CLRCLAMP_DISABLE 0 /**< \brief Disable color clamping */
373 #define PVR_CLRCLAMP_ENABLE 1 /**< \brief Enable color clamping */
374 /** @} */
375 
376 /** \defgroup pvr_alpha_switch Enable or disable alpha blending
377 
378  This causes the alpha value in the vertex color to be paid attention to. It
379  really only makes sense to enable this for translucent or punch-thru polys.
380 
381  @{
382 */
383 #define PVR_ALPHA_DISABLE 0 /**< \brief Disable alpha blending */
384 #define PVR_ALPHA_ENABLE 1 /**< \brief Enable alpha blending */
385 /** @} */
386 
387 /** \defgroup pvr_txralpha_switch Enable or disable texture alpha blending
388 
389  This causes the alpha value in the texel color to be paid attention to. It
390  really only makes sense to enable this for translucent or punch-thru polys.
391 
392  @{
393 */
394 #define PVR_TXRALPHA_ENABLE 0 /**< \brief Enable alpha blending */
395 #define PVR_TXRALPHA_DISABLE 1 /**< \brief Disable alpha blending */
396 /** @} */
397 
398 /** \defgroup pvr_uv_flip Enable or disable U/V flipping on the PVR
399  @{
400 */
401 #define PVR_UVFLIP_NONE 0 /**< \brief No flipped coordinates */
402 #define PVR_UVFLIP_V 1 /**< \brief Flip V only */
403 #define PVR_UVFLIP_U 2 /**< \brief Flip U only */
404 #define PVR_UVFLIP_UV 3 /**< \brief Flip U and V */
405 /** @} */
406 
407 /** \defgroup pvr_uv_clamp Enable or disable clamping of U/V on the PVR
408  @{
409 */
410 #define PVR_UVCLAMP_NONE 0 /**< \brief Disable clamping */
411 #define PVR_UVCLAMP_V 1 /**< \brief Clamp V only */
412 #define PVR_UVCLAMP_U 2 /**< \brief Clamp U only */
413 #define PVR_UVCLAMP_UV 3 /**< \brief Clamp U and V */
414 /** @} */
415 
416 /** \defgroup pvr_filter_modes PVR texture sampling modes
417  @{
418 */
419 #define PVR_FILTER_NONE 0 /**< \brief No filtering (point sample) */
420 #define PVR_FILTER_NEAREST 0 /**< \brief No filtering (point sample) */
421 #define PVR_FILTER_BILINEAR 2 /**< \brief Bilinear interpolation */
422 #define PVR_FILTER_TRILINEAR1 4 /**< \brief Trilinear interpolation pass 1 */
423 #define PVR_FILTER_TRILINEAR2 6 /**< \brief Trilinear interpolation pass 2 */
424 /** @} */
425 
426 /** \defgroup pvr_mip_bias PVR mipmap bias modes
427  @{
428 */
429 #define PVR_MIPBIAS_NORMAL PVR_MIPBIAS_1_00 /* txr_mipmap_bias */
430 #define PVR_MIPBIAS_0_25 1
431 #define PVR_MIPBIAS_0_50 2
432 #define PVR_MIPBIAS_0_75 3
433 #define PVR_MIPBIAS_1_00 4
434 #define PVR_MIPBIAS_1_25 5
435 #define PVR_MIPBIAS_1_50 6
436 #define PVR_MIPBIAS_1_75 7
437 #define PVR_MIPBIAS_2_00 8
438 #define PVR_MIPBIAS_2_25 9
439 #define PVR_MIPBIAS_2_50 10
440 #define PVR_MIPBIAS_2_75 11
441 #define PVR_MIPBIAS_3_00 12
442 #define PVR_MIPBIAS_3_25 13
443 #define PVR_MIPBIAS_3_50 14
444 #define PVR_MIPBIAS_3_75 15
445 /** @} */
446 
447 /** \defgroup pvr_txrenv_modes Texture color calculation modes
448  @{
449 */
450 #define PVR_TXRENV_REPLACE 0 /**< \brief C = Ct, A = At */
451 #define PVR_TXRENV_MODULATE 1 /**< \brief C = Cs * Ct, A = At */
452 #define PVR_TXRENV_DECAL 2 /**< \brief C = (Cs * At) + (Cs * (1-At)), A = As */
453 #define PVR_TXRENV_MODULATEALPHA 3 /**< \brief C = Cs * Ct, A = As * At */
454 /** @} */
455 
456 /** \defgroup pvr_mip_switch Enable or disable PVR mipmap processing
457  @{
458 */
459 #define PVR_MIPMAP_DISABLE 0 /**< \brief Disable mipmap processing */
460 #define PVR_MIPMAP_ENABLE 1 /**< \brief Enable mipmap processing */
461 /** @} */
462 
463 /** \defgroup pvr_txr_fmts PVR texture formats
464 
465  These are the texture formats that the PVR supports. Note that some of
466  these, you can OR together with other values.
467 
468  @{
469 */
470 #define PVR_TXRFMT_NONE 0 /**< \brief No texture */
471 #define PVR_TXRFMT_VQ_DISABLE (0 << 30) /**< \brief Not VQ encoded */
472 #define PVR_TXRFMT_VQ_ENABLE (1 << 30) /**< \brief VQ encoded */
473 #define PVR_TXRFMT_ARGB1555 (0 << 27) /**< \brief 16-bit ARGB1555 */
474 #define PVR_TXRFMT_RGB565 (1 << 27) /**< \brief 16-bit RGB565 */
475 #define PVR_TXRFMT_ARGB4444 (2 << 27) /**< \brief 16-bit ARGB4444 */
476 #define PVR_TXRFMT_YUV422 (3 << 27) /**< \brief YUV422 format */
477 #define PVR_TXRFMT_BUMP (4 << 27) /**< \brief Bumpmap format */
478 #define PVR_TXRFMT_PAL4BPP (5 << 27) /**< \brief 4BPP paletted format */
479 #define PVR_TXRFMT_PAL8BPP (6 << 27) /**< \brief 8BPP paletted format */
480 #define PVR_TXRFMT_TWIDDLED (0 << 26) /**< \brief Texture is twiddled */
481 #define PVR_TXRFMT_NONTWIDDLED (1 << 26) /**< \brief Texture is not twiddled */
482 #define PVR_TXRFMT_NOSTRIDE (0 << 21) /**< \brief Texture is not strided */
483 #define PVR_TXRFMT_STRIDE (1 << 21) /**< \brief Texture is strided */
484 
485 /* OR one of these into your texture format if you need it. Note that
486  these coincide with the twiddled/stride bits, so you can't have a
487  non-twiddled/strided texture that's paletted! */
488 /** \brief 8BPP palette selector
489  \param x The palette index */
490 #define PVR_TXRFMT_8BPP_PAL(x) ((x) << 25)
491 
492 /** \brief 4BPP palette selector
493  \param x The palette index */
494 #define PVR_TXRFMT_4BPP_PAL(x) ((x) << 21)
495 /** @} */
496 
497 /** \defgroup pvr_color_fmts PVR vertex color formats
498 
499  These control how colors are represented in polygon data.
500 
501  @{
502 */
503 #define PVR_CLRFMT_ARGBPACKED 0 /**< \brief 32-bit integer ARGB */
504 #define PVR_CLRFMT_4FLOATS 1 /**< \brief 4 floating point values */
505 #define PVR_CLRFMT_INTENSITY 2 /**< \brief Intensity color */
506 #define PVR_CLRFMT_INTENSITY_PREV 3 /**< \brief Use last intensity */
507 /** @} */
508 
509 /** \defgroup pvr_uv_fmts PVR U/V data format control
510  @{
511 */
512 #define PVR_UVFMT_32BIT 0 /**< \brief 32-bit floating point U/V */
513 #define PVR_UVFMT_16BIT 1 /**< \brief 16-bit floating point U/V */
514 /** @} */
515 
516 /** \defgroup pvr_mod_switch Enable or disable modifier effects
517  @{
518 */
519 #define PVR_MODIFIER_DISABLE 0 /**< \brief Disable modifier effects */
520 #define PVR_MODIFIER_ENABLE 1 /**< \brief Enable modifier effects */
521 /** @} */
522 
523 #define PVR_MODIFIER_CHEAP_SHADOW 0
524 #define PVR_MODIFIER_NORMAL 1
525 
526 /** \defgroup pvr_mod_modes Modifier volume mode parameters
527 
528  All triangles in a single modifier volume should be of the other poly type,
529  except for the last one. That should be either of the other two types,
530  depending on whether you want an inclusion or exclusion volume.
531 
532  @{
533 */
534 #define PVR_MODIFIER_OTHER_POLY 0 /**< \brief Not the last polygon in the volume */
535 #define PVR_MODIFIER_INCLUDE_LAST_POLY 1 /**< \brief Last polygon, inclusion volume */
536 #define PVR_MODIFIER_EXCLUDE_LAST_POLY 2 /**< \brief Last polygon, exclusion volume */
537 /** @} */
538 
539 
540 /** \brief PVR polygon header.
541 
542  This is the hardware equivalent of a rendering context; you'll create one of
543  these from your pvr_poly_cxt_t and use it for submission to the hardware.
544 
545  \headerfile dc/pvr.h
546 */
547 typedef struct {
548  uint32 cmd; /**< \brief TA command */
549  uint32 mode1; /**< \brief Parameter word 1 */
550  uint32 mode2; /**< \brief Parameter word 2 */
551  uint32 mode3; /**< \brief Parameter word 3 */
552  uint32 d1; /**< \brief Dummy value */
553  uint32 d2; /**< \brief Dummy value */
554  uint32 d3; /**< \brief Dummy value */
555  uint32 d4; /**< \brief Dummy value */
557 
558 /** \brief PVR polygon header with intensity color.
559 
560  This is the equivalent of pvr_poly_hdr_t, but for use with intensity color.
561 
562  \headerfile dc/pvr.h
563 */
564 typedef struct {
565  uint32 cmd; /**< \brief TA command */
566  uint32 mode1; /**< \brief Parameter word 1 */
567  uint32 mode2; /**< \brief Parameter word 2 */
568  uint32 mode3; /**< \brief Parameter word 3 */
569  float a; /**< \brief Face color alpha component */
570  float r; /**< \brief Face color red component */
571  float g; /**< \brief Face color green component */
572  float b; /**< \brief Face color blue component */
574 
575 /** \brief PVR polygon header to be used with modifier volumes.
576 
577  This is the equivalent of a pvr_poly_hdr_t for use when a polygon is to be
578  used with modifier volumes.
579 
580  \headerfile dc/pvr.h
581 */
582 typedef struct {
583  uint32 cmd; /**< \brief TA command */
584  uint32 mode1; /**< \brief Parameter word 1 */
585  uint32 mode2_0; /**< \brief Parameter word 2 (outside volume) */
586  uint32 mode3_0; /**< \brief Parameter word 3 (outside volume) */
587  uint32 mode2_1; /**< \brief Parameter word 2 (inside volume) */
588  uint32 mode3_1; /**< \brief Parameter word 3 (inside volume) */
589  uint32 d1; /**< \brief Dummy value */
590  uint32 d2; /**< \brief Dummy value */
592 
593 /** \brief PVR polygon header specifically for sprites.
594 
595  This is the equivalent of a pvr_poly_hdr_t for use when a quad/sprite is to
596  be rendered. Note that the color data is here, not in the vertices.
597 
598  \headerfile dc/pvr.h
599 */
600 typedef struct {
601  uint32 cmd; /**< \brief TA command */
602  uint32 mode1; /**< \brief Parameter word 1 */
603  uint32 mode2; /**< \brief Parameter word 2 */
604  uint32 mode3; /**< \brief Parameter word 3 */
605  uint32 argb; /**< \brief Sprite face color */
606  uint32 oargb; /**< \brief Sprite offset color */
607  uint32 d1; /**< \brief Dummy value */
608  uint32 d2; /**< \brief Dummy value */
610 
611 /** \brief Modifier volume header.
612 
613  This is the header that should be submitted when dealing with setting a
614  modifier volume.
615 
616  \headerfile dc/pvr.h
617 */
618 typedef struct {
619  uint32 cmd; /**< \brief TA command */
620  uint32 mode1; /**< \brief Parameter word 1 */
621  uint32 d1; /**< \brief Dummy value */
622  uint32 d2; /**< \brief Dummy value */
623  uint32 d3; /**< \brief Dummy value */
624  uint32 d4; /**< \brief Dummy value */
625  uint32 d5; /**< \brief Dummy value */
626  uint32 d6; /**< \brief Dummy value */
627 } pvr_mod_hdr_t;
628 
629 /** \brief Generic PVR vertex type.
630 
631  The PVR chip itself supports many more vertex types, but this is the main
632  one that can be used with both textured and non-textured polygons, and is
633  fairly fast.
634 
635  \headerfile dc/pvr.h
636 */
637 typedef struct {
638  uint32 flags; /**< \brief TA command (vertex flags) */
639  float x; /**< \brief X coordinate */
640  float y; /**< \brief Y coordinate */
641  float z; /**< \brief Z coordinate */
642  float u; /**< \brief Texture U coordinate */
643  float v; /**< \brief Texture V coordinate */
644  uint32 argb; /**< \brief Vertex color */
645  uint32 oargb; /**< \brief Vertex offset color */
646 } pvr_vertex_t;
647 
648 /** \brief PVR vertex type: Non-textured, packed color, affected by modifier
649  volume.
650 
651  This vertex type has two copies of colors. The second color is used when
652  enclosed within a modifier volume.
653 
654  \headerfile dc/pvr.h
655 */
656 typedef struct {
657  uint32 flags; /**< \brief TA command (vertex flags) */
658  float x; /**< \brief X coordinate */
659  float y; /**< \brief Y coordinate */
660  float z; /**< \brief Z coordinate */
661  uint32 argb0; /**< \brief Vertex color (outside volume) */
662  uint32 argb1; /**< \brief Vertex color (inside volume) */
663  uint32 d1; /**< \brief Dummy value */
664  uint32 d2; /**< \brief Dummy value */
666 
667 /** \brief PVR vertex type: Textured, packed color, affected by modifer volume.
668 
669  Note that this vertex type has two copies of colors, offset colors, and
670  texture coords. The second set of texture coords, colors, and offset colors
671  are used when enclosed within a modifer volume.
672 
673  \headerfile dc/pvr.h
674 */
675 typedef struct {
676  uint32 flags; /**< \brief TA command (vertex flags) */
677  float x; /**< \brief X coordinate */
678  float y; /**< \brief Y coordinate */
679  float z; /**< \brief Z coordinate */
680  float u0; /**< \brief Texture U coordinate (outside) */
681  float v0; /**< \brief Texture V coordinate (outside) */
682  uint32 argb0; /**< \brief Vertex color (outside) */
683  uint32 oargb0; /**< \brief Vertex offset color (outside) */
684  float u1; /**< \brief Texture U coordinate (inside) */
685  float v1; /**< \brief Texture V coordinate (inside) */
686  uint32 argb1; /**< \brief Vertex color (inside) */
687  uint32 oargb1; /**< \brief Vertex offset color (inside) */
688  uint32 d1; /**< \brief Dummy value */
689  uint32 d2; /**< \brief Dummy value */
690  uint32 d3; /**< \brief Dummy value */
691  uint32 d4; /**< \brief Dummy value */
693 
694 /** \brief PVR vertex type: Textured sprite.
695 
696  This vertex type is to be used with the sprite polygon header and the sprite
697  related commands to draw textured sprites. Note that there is on fourth Z
698  coordinate. I suppose it just gets interpolated?
699 
700  The U/V coordinates in here are in the 16-bit per coordinate form. Also,
701  like the fourth Z value, there is no fourth U or V, so it must get
702  interpolated from the others.
703 
704  \headerfile dc/pvr.h
705 */
706 typedef struct {
707  uint32 flags; /**< \brief TA command (vertex flags) */
708  float ax; /**< \brief First X coordinate */
709  float ay; /**< \brief First Y coordinate */
710  float az; /**< \brief First Z coordinate */
711  float bx; /**< \brief Second X coordinate */
712  float by; /**< \brief Second Y coordinate */
713  float bz; /**< \brief Second Z coordinate */
714  float cx; /**< \brief Third X coordinate */
715  float cy; /**< \brief Third Y coordinate */
716  float cz; /**< \brief Third Z coordinate */
717  float dx; /**< \brief Fourth X coordinate */
718  float dy; /**< \brief Fourth Y coordinate */
719  uint32 dummy; /**< \brief Dummy value */
720  uint32 auv; /**< \brief First U/V texture coordinates */
721  uint32 buv; /**< \brief Second U/V texture coordinates */
722  uint32 cuv; /**< \brief Third U/V texture coordinates */
724 
725 /** \brief PVR vertex type: Untextured sprite.
726 
727  This vertex type is to be used with the sprite polygon header and the sprite
728  related commands to draw untextured sprites (aka, quads).
729 */
730 typedef struct {
731  uint32 flags; /**< \brief TA command (vertex flags) */
732  float ax; /**< \brief First X coordinate */
733  float ay; /**< \brief First Y coordinate */
734  float az; /**< \brief First Z coordinate */
735  float bx; /**< \brief Second X coordinate */
736  float by; /**< \brief Second Y coordinate */
737  float bz; /**< \brief Second Z coordinate */
738  float cx; /**< \brief Third X coordinate */
739  float cy; /**< \brief Third Y coordinate */
740  float cz; /**< \brief Third Z coordinate */
741  float dx; /**< \brief Fourth X coordinate */
742  float dy; /**< \brief Fourth Y coordinate */
743  uint32 d1; /**< \brief Dummy value */
744  uint32 d2; /**< \brief Dummy value */
745  uint32 d3; /**< \brief Dummy value */
746  uint32 d4; /**< \brief Dummy value */
748 
749 /** \brief PVR vertex type: Modifier volume.
750 
751  This vertex type is to be used with the modifier volume header to specify
752  triangular modifier areas.
753 */
754 typedef struct {
755  uint32 flags; /**< \brief TA command (vertex flags) */
756  float ax; /**< \brief First X coordinate */
757  float ay; /**< \brief First Y coordinate */
758  float az; /**< \brief First Z coordinate */
759  float bx; /**< \brief Second X coordinate */
760  float by; /**< \brief Second Y coordinate */
761  float bz; /**< \brief Second Z coordinate */
762  float cx; /**< \brief Third X coordinate */
763  float cy; /**< \brief Third Y coordinate */
764  float cz; /**< \brief Third Z coordinate */
765  uint32 d1; /**< \brief Dummy value */
766  uint32 d2; /**< \brief Dummy value */
767  uint32 d3; /**< \brief Dummy value */
768  uint32 d4; /**< \brief Dummy value */
769  uint32 d5; /**< \brief Dummy value */
770  uint32 d6; /**< \brief Dummy value */
772 
773 /** \brief Pack four floating point color values into a 32-bit integer form.
774 
775  All of the color values should be between 0 and 1.
776 
777  \param a Alpha value
778  \param r Red value
779  \param g Green value
780  \param b Blue value
781  \return The packed color value
782 */
783 #define PVR_PACK_COLOR(a, r, g, b) ( \
784  ( ((uint8)( a * 255 ) ) << 24 ) | \
785  ( ((uint8)( r * 255 ) ) << 16 ) | \
786  ( ((uint8)( g * 255 ) ) << 8 ) | \
787  ( ((uint8)( b * 255 ) ) << 0 ) )
788 
789 /** \brief Pack two floating point coordinates into one 32-bit value,
790  truncating them to 16-bits each.
791 
792  \param u First coordinate to pack
793  \param v Second coordinate to pack
794  \return The packed coordinates
795 */
796 static inline uint32 PVR_PACK_16BIT_UV(float u, float v) {
797  return (((*((uint32 *) &u)) >> 0) & 0xFFFF0000) |
798  (((*((uint32 *) &v)) >> 16) & 0x0000FFFF);
799 }
800 
801 /* ... other vertex structs omitted for now ... */
802 
803 /** \defgroup pvr_commands TA command values
804 
805  These are are appropriate values for TA commands. Use whatever goes with the
806  primitive type you're using.
807 
808  @{
809 */
810 #define PVR_CMD_POLYHDR 0x80840000 /**< \brief PVR polygon header.
811 Striplength set to 2 */
812 #define PVR_CMD_VERTEX 0xe0000000 /**< \brief PVR vertex data */
813 #define PVR_CMD_VERTEX_EOL 0xf0000000 /**< \brief PVR vertex, end of strip */
814 #define PVR_CMD_USERCLIP 0x20000000 /**< \brief PVR user clipping area */
815 #define PVR_CMD_MODIFIER 0x80000000 /**< \brief PVR modifier volume */
816 #define PVR_CMD_SPRITE 0xA0000000 /**< \brief PVR sprite header */
817 /** @} */
818 
819 /** \defgroup pvr_bitmasks Constants and bitmasks for handling polygon
820  headers.
821 
822  Note that thanks to the arrangement of constants, this is mainly a matter of
823  bit shifting to compile headers...
824 
825  @{
826 */
827 #define PVR_TA_CMD_TYPE_SHIFT 24
828 #define PVR_TA_CMD_TYPE_MASK (7 << PVR_TA_CMD_TYPE_SHIFT)
829 
830 #define PVR_TA_CMD_USERCLIP_SHIFT 16
831 #define PVR_TA_CMD_USERCLIP_MASK (3 << PVR_TA_CMD_USERCLIP_SHIFT)
832 
833 #define PVR_TA_CMD_CLRFMT_SHIFT 4
834 #define PVR_TA_CMD_CLRFMT_MASK (7 << PVR_TA_CMD_CLRFMT_SHIFT)
835 
836 #define PVR_TA_CMD_SHADE_SHIFT 1
837 #define PVR_TA_CMD_SHADE_MASK (1 << PVR_TA_CMD_SHADE_SHIFT)
838 
839 #define PVR_TA_CMD_UVFMT_SHIFT 0
840 #define PVR_TA_CMD_UVFMT_MASK (1 << PVR_TA_CMD_UVFMT_SHIFT)
841 
842 #define PVR_TA_CMD_MODIFIER_SHIFT 7
843 #define PVR_TA_CMD_MODIFIER_MASK (1 << PVR_TA_CMD_MODIFIER_SHIFT)
844 
845 #define PVR_TA_CMD_MODIFIERMODE_SHIFT 6
846 #define PVR_TA_CMD_MODIFIERMODE_MASK (1 << PVR_TA_CMD_MODIFIERMODE_SHIFT)
847 
848 #define PVR_TA_PM1_DEPTHCMP_SHIFT 29
849 #define PVR_TA_PM1_DEPTHCMP_MASK (7 << PVR_TA_PM1_DEPTHCMP_SHIFT)
850 
851 #define PVR_TA_PM1_CULLING_SHIFT 27
852 #define PVR_TA_PM1_CULLING_MASK (3 << PVR_TA_PM1_CULLING_SHIFT)
853 
854 #define PVR_TA_PM1_DEPTHWRITE_SHIFT 26
855 #define PVR_TA_PM1_DEPTHWRITE_MASK (1 << PVR_TA_PM1_DEPTHWRITE_SHIFT)
856 
857 #define PVR_TA_PM1_TXRENABLE_SHIFT 25
858 #define PVR_TA_PM1_TXRENABLE_MASK (1 << PVR_TA_PM1_TXRENABLE_SHIFT)
859 
860 #define PVR_TA_PM1_MODIFIERINST_SHIFT 29
861 #define PVR_TA_PM1_MODIFIERINST_MASK (3 << PVR_TA_PM1_MODIFIERINST_SHIFT)
862 
863 #define PVR_TA_PM2_SRCBLEND_SHIFT 29
864 #define PVR_TA_PM2_SRCBLEND_MASK (7 << PVR_TA_PM2_SRCBLEND_SHIFT)
865 
866 #define PVR_TA_PM2_DSTBLEND_SHIFT 26
867 #define PVR_TA_PM2_DSTBLEND_MASK (7 << PVR_TA_PM2_DSTBLEND_SHIFT)
868 
869 #define PVR_TA_PM2_SRCENABLE_SHIFT 25
870 #define PVR_TA_PM2_SRCENABLE_MASK (1 << PVR_TA_PM2_SRCENABLE_SHIFT)
871 
872 #define PVR_TA_PM2_DSTENABLE_SHIFT 24
873 #define PVR_TA_PM2_DSTENABLE_MASK (1 << PVR_TA_PM2_DSTENABLE_SHIFT)
874 
875 #define PVR_TA_PM2_FOG_SHIFT 22
876 #define PVR_TA_PM2_FOG_MASK (3 << PVR_TA_PM2_FOG_SHIFT)
877 
878 #define PVR_TA_PM2_CLAMP_SHIFT 21
879 #define PVR_TA_PM2_CLAMP_MASK (1 << PVR_TA_PM2_CLAMP_SHIFT)
880 
881 #define PVR_TA_PM2_ALPHA_SHIFT 20
882 #define PVR_TA_PM2_ALPHA_MASK (1 << PVR_TA_PM2_ALPHA_SHIFT)
883 
884 #define PVR_TA_PM2_TXRALPHA_SHIFT 19
885 #define PVR_TA_PM2_TXRALPHA_MASK (1 << PVR_TA_PM2_TXRALPHA_SHIFT)
886 
887 #define PVR_TA_PM2_UVFLIP_SHIFT 17
888 #define PVR_TA_PM2_UVFLIP_MASK (3 << PVR_TA_PM2_UVFLIP_SHIFT)
889 
890 #define PVR_TA_PM2_UVCLAMP_SHIFT 15
891 #define PVR_TA_PM2_UVCLAMP_MASK (3 << PVR_TA_PM2_UVCLAMP_SHIFT)
892 
893 #define PVR_TA_PM2_FILTER_SHIFT 12
894 #define PVR_TA_PM2_FILTER_MASK (7 << PVR_TA_PM2_FILTER_SHIFT)
895 
896 #define PVR_TA_PM2_MIPBIAS_SHIFT 8
897 #define PVR_TA_PM2_MIPBIAS_MASK (15 << PVR_TA_PM2_MIPBIAS_SHIFT)
898 
899 #define PVR_TA_PM2_TXRENV_SHIFT 6
900 #define PVR_TA_PM2_TXRENV_MASK (3 << PVR_TA_PM2_TXRENV_SHIFT)
901 
902 #define PVR_TA_PM2_USIZE_SHIFT 3
903 #define PVR_TA_PM2_USIZE_MASK (7 << PVR_TA_PM2_USIZE_SHIFT)
904 
905 #define PVR_TA_PM2_VSIZE_SHIFT 0
906 #define PVR_TA_PM2_VSIZE_MASK (7 << PVR_TA_PM2_VSIZE_SHIFT)
907 
908 #define PVR_TA_PM3_MIPMAP_SHIFT 31
909 #define PVR_TA_PM3_MIPMAP_MASK (1 << PVR_TA_PM3_MIPMAP_SHIFT)
910 
911 #define PVR_TA_PM3_TXRFMT_SHIFT 0
912 #define PVR_TA_PM3_TXRFMT_MASK 0xffffffff
913 /** @} */
914 
915 /**** Register macros ***************************************************/
916 
917 /* We use these macros to do all PVR register access, so that it's
918  simple later on to hook them for debugging or whatnot. */
919 
920 /** \brief Retrieve a PVR register value
921  \param REG The register to fetch
922  \return The value of that register (32-bits)
923 */
924 #define PVR_GET(REG) (* ( (uint32*)( 0xa05f8000 + (REG) ) ) )
925 
926 /** \brief Set a PVR register value
927  \param REG The register to set
928  \param VALUE The value to set in the register (32-bits)
929 */
930 #define PVR_SET(REG, VALUE) PVR_GET(REG) = (VALUE)
931 
932 /* The registers themselves; these are from Maiwe's powervr-reg.txt */
933 /* Note that 2D specific registers have been excluded for now (like
934  vsync, hsync, v/h size, etc) */
935 
936 /** \defgroup pvr_regs Offsets to registers of the PVR
937  @{
938 */
939 #define PVR_ID 0x0000 /**< \brief Chip ID */
940 #define PVR_REVISION 0x0004 /**< \brief Chip revision */
941 #define PVR_RESET 0x0008 /**< \brief Reset pins */
942 #define PVR_ISP_START 0x0014 /**< \brief Start the ISP/TSP */
943 #define PVR_UNK_0018 0x0018 /**< \brief ?? */
944 #define PVR_ISP_VERTBUF_ADDR 0x0020 /**< \brief Vertex buffer address for scene rendering */
945 #define PVR_ISP_TILEMAT_ADDR 0x002c /**< \brief Tile matrix address for scene rendering */
946 #define PVR_SPANSORT_CFG 0x0030 /**< \brief ?? -- write 0x101 for now */
947 #define PVR_FB_CFG_1 0x0044 /**< \brief Framebuffer config 1 */
948 #define PVR_FB_CFG_2 0x0048 /**< \brief Framebuffer config 2 */
949 #define PVR_RENDER_MODULO 0x004c /**< \brief Render modulo */
950 #define PVR_RENDER_ADDR 0x0060 /**< \brief Render output address */
951 #define PVR_RENDER_ADDR_2 0x0064 /**< \brief Output for strip-buffering */
952 #define PVR_PCLIP_X 0x0068 /**< \brief Horizontal clipping area */
953 #define PVR_PCLIP_Y 0x006c /**< \brief Vertical clipping area */
954 #define PVR_CHEAP_SHADOW 0x0074 /**< \brief Cheap shadow control */
955 #define PVR_OBJECT_CLIP 0x0078 /**< \brief Distance for polygon culling */
956 #define PVR_UNK_007C 0x007c /**< \brief ?? -- write 0x0027df77 for now */
957 #define PVR_UNK_0080 0x0080 /**< \brief ?? -- write 7 for now */
958 #define PVR_TEXTURE_CLIP 0x0084 /**< \brief Distance for texture clipping */
959 #define PVR_BGPLANE_Z 0x0088 /**< \brief Distance for background plane */
960 #define PVR_BGPLANE_CFG 0x008c /**< \brief Background plane config */
961 #define PVR_UNK_0098 0x0098 /**< \brief ?? -- write 0x00800408 for now */
962 #define PVR_UNK_00A0 0x00a0 /**< \brief ?? -- write 0x20 for now */
963 #define PVR_UNK_00A8 0x00a8 /**< \brief ?? -- write 0x15d1c951 for now */
964 #define PVR_FOG_TABLE_COLOR 0x00b0 /**< \brief Table fog color */
965 #define PVR_FOG_VERTEX_COLOR 0x00b4 /**< \brief Vertex fog color */
966 #define PVR_FOG_DENSITY 0x00b8 /**< \brief Fog density coefficient */
967 #define PVR_COLOR_CLAMP_MAX 0x00bc /**< \brief RGB Color clamp max */
968 #define PVR_COLOR_CLAMP_MIN 0x00c0 /**< \brief RGB Color clamp min */
969 #define PVR_GUN_POS 0x00c4 /**< \brief Light gun position */
970 #define PVR_UNK_00C8 0x00c8 /**< \brief ?? -- write same as border H in 00d4 << 16 */
971 #define PVR_VPOS_IRQ 0x00cc /**< \brief Vertical position IRQ */
972 #define PVR_TEXTURE_MODULO 0x00e4 /**< \brief Output texture width modulo */
973 #define PVR_VIDEO_CFG 0x00e8 /**< \brief Misc video config */
974 #define PVR_SCALER_CFG 0x00f4 /**< \brief Smoothing scaler */
975 #define PVR_PALETTE_CFG 0x0108 /**< \brief Palette format */
976 #define PVR_SYNC_STATUS 0x010c /**< \brief V/H blank status */
977 #define PVR_UNK_0110 0x0110 /**< \brief ?? -- write 0x93f39 for now */
978 #define PVR_UNK_0114 0x0114 /**< \brief ?? -- write 0x200000 for now */
979 #define PVR_UNK_0118 0x0118 /**< \brief ?? -- write 0x8040 for now */
980 #define PVR_TA_OPB_START 0x0124 /**< \brief Object Pointer Buffer start for TA usage */
981 #define PVR_TA_VERTBUF_START 0x0128 /**< \brief Vertex buffer start for TA usage */
982 #define PVR_TA_OPB_END 0x012c /**< \brief OPB end for TA usage */
983 #define PVR_TA_VERTBUF_END 0x0130 /**< \brief Vertex buffer end for TA usage */
984 #define PVR_TA_OPB_POS 0x0134 /**< \brief Top used memory location in OPB for TA usage */
985 #define PVR_TA_VERTBUF_POS 0x0138 /**< \brief Top used memory location in vertbuf for TA usage */
986 #define PVR_TILEMAT_CFG 0x013c /**< \brief Tile matrix size config */
987 #define PVR_OPB_CFG 0x0140 /**< \brief Active lists / list size */
988 #define PVR_TA_INIT 0x0144 /**< \brief Initialize vertex reg. params */
989 #define PVR_YUV_ADDR 0x0148 /**< \brief YUV conversion destination */
990 #define PVR_YUV_CFG_1 0x014c /**< \brief YUV configuration */
991 #define PVR_UNK_0160 0x0160 /**< \brief ?? */
992 #define PVR_TA_OPB_INIT 0x0164 /**< \brief Object pointer buffer position init */
993 #define PVR_FOG_TABLE_BASE 0x0200 /**< \brief Base of the fog table */
994 #define PVR_PALETTE_TABLE_BASE 0x1000 /**< \brief Base of the palette table */
995 /** @} */
996 
997 /* Useful memory locations */
998 #define PVR_TA_INPUT 0x10000000 /**< \brief TA command input */
999 #define PVR_RAM_BASE 0xa5000000 /**< \brief PVR RAM (raw) */
1000 #define PVR_RAM_INT_BASE 0xa4000000 /**< \brief PVR RAM (interleaved) */
1001 
1002 #define PVR_RAM_SIZE (8*1024*1024) /**< \brief RAM size in bytes */
1003 
1004 #define PVR_RAM_TOP (PVR_RAM_BASE + PVR_RAM_SIZE) /**< \brief Top of raw PVR RAM */
1005 #define PVR_RAM_INT_TOP (PVR_RAM_INT_BASE + PVR_RAM_SIZE) /**< \brief Top of int PVR RAM */
1006 
1007 /* Register content defines, as needed; these will be filled in over time
1008  as the implementation requires them. There's too many to do otherwise. */
1009 
1010 /** \defgroup pvr_reset_vals Values used to reset parts of the PVR
1011 
1012  These values are written to the PVR_RESET register in order to reset the
1013  system or to take it out of reset.
1014 
1015  @{
1016 */
1017 #define PVR_RESET_ALL 0xffffffff /**< \brief Reset the wole PVR */
1018 #define PVR_RESET_NONE 0x00000000 /**< \brief Cancel reset state */
1019 #define PVR_RESET_TA 0x00000001 /**< \brief Reset only the TA */
1020 #define PVR_RESET_ISPTSP 0x00000002 /**< \brief Reset only the ISP/TSP */
1021 /** @} */
1022 
1023 #define PVR_ISP_START_GO 0xffffffff /**< \brief Write to the PVR_ISP_START register to start rendering */
1024 
1025 #define PVR_TA_INIT_GO 0x80000000 /**< \brief Write to the PVR_TA_INIT register to confirm settings */
1026 
1027 
1028 /* Initialization ****************************************************/
1029 
1030 /* Initialization and shutdown: stuff you should only ever have to do
1031  once in your program. */
1032 
1033 /** \defgroup pvr_binsizes Available sizes for primitive bins
1034  @{
1035 */
1036 #define PVR_BINSIZE_0 0 /**< \brief 0-length (disables the list) */
1037 #define PVR_BINSIZE_8 8 /**< \brief 8-word (32-byte) length */
1038 #define PVR_BINSIZE_16 16 /**< \brief 16-word (64-byte) length */
1039 #define PVR_BINSIZE_32 32 /**< \brief 32-word (128-byte) length */
1040 /** @} */
1041 
1042 /** \brief PVR initialization structure
1043 
1044  This structure defines how the PVR initializes various parts of the system,
1045  including the primitive bin sizes, the vertex buffer size, and whether
1046  vertex DMA will be enabled.
1047 
1048  You essentially fill one of these in, and pass it to pvr_init().
1049 
1050  \headerfile dc/pvr.h
1051 */
1052 typedef struct {
1053  /** \brief Bin sizes.
1054 
1055  The bins go in the following order: opaque polygons, opaque modifiers,
1056  translucent polygons, translucent modifiers, punch-thrus
1057  */
1058  int opb_sizes[5];
1059 
1060  /** \brief Vertex buffer size (should be a nice round number) */
1062 
1063  /** \brief Enable vertex DMA?
1064 
1065  Set to non-zero if we want to enable vertex DMA mode. Note that if this
1066  is set, then _all_ enabled lists need to have a vertex buffer assigned,
1067  even if you never use that list for anything.
1068  */
1070 
1071  /** \brief Enable horizontal scaling?
1072 
1073  Set to non-zero if horizontal scaling is to be enabled. By enabling this
1074  setting and stretching your image to double the native screen width, you
1075  can get horizontal full-screen anti-aliasing. */
1078 
1079 /** \brief Initialize the PVR chip to ready status.
1080 
1081  This function enables the specified lists and uses the specified parameters.
1082  Note that bins and vertex buffers come from the texture memory pool, so only
1083  allocate what you actually need. Expects that a 2D mode was initialized
1084  already using the vid_* API.
1085 
1086  \param params The set of parameters to initialize with
1087  \retval 0 On success
1088  \retval -1 If the PVR has already been initialized or the video
1089  mode active is not suitable for 3D
1090 */
1091 int pvr_init(pvr_init_params_t *params);
1092 
1093 /** \brief Simple PVR initialization.
1094 
1095  This simpler function initializes the PVR using 16/16 for the opaque
1096  and translucent lists' bin sizes, and 0's for everything else. It sets 512KB
1097  of vertex buffer. This is equivalent to the old ta_init_defaults() for now.
1098 
1099  \retval 0 On success
1100  \retval -1 If the PVR has already been initialized or the video
1101  mode active is not suitable for 3D
1102 */
1103 int pvr_init_defaults();
1104 
1105 /** \brief Shut down the PVR chip from ready status.
1106 
1107  This essentially leaves the video system in 2D mode as it was before the
1108  init.
1109 
1110  \retval 0 On success
1111  \retval -1 If the PVR has not been initialized
1112 */
1113 int pvr_shutdown();
1114 
1115 
1116 /* Misc parameters ***************************************************/
1117 
1118 /* These are miscellaneous parameters you can set which affect the
1119  rendering process. */
1120 
1121 /** \brief Set the background plane color.
1122 
1123  This function sets the color of the area of the screen not covered by any
1124  other polygons.
1125 
1126  \param r Red component of the color to set
1127  \param g Green component of the color to set
1128  \param b Blue component of the color to set
1129 */
1130 void pvr_set_bg_color(float r, float g, float b);
1131 
1132 /** \brief Retrieve the current VBlank count.
1133 
1134  This function retrieves the number of VBlank interrupts that have occurred
1135  since the PVR was initialized.
1136 
1137  \return The number of VBlanks since init
1138 */
1139 int pvr_get_vbl_count();
1140 
1141 /* Statistics structure */
1142 /** \brief PVR statistics structure.
1143 
1144  This structure is used to hold various statistics about the operation of the
1145  PVR since initialization.
1146 
1147  \headerfile dc/pvr.h
1148 */
1149 typedef struct pvr_stats {
1150  uint32 enabled_list_mask; /**< \brief Which lists are enabled? */
1151  uint32 vbl_count; /**< \brief VBlank count */
1152  int frame_last_time; /**< \brief Ready-to-Ready length for the last frame in milliseconds */
1153  float frame_rate; /**< \brief Current frame rate (per second) */
1154  int reg_last_time; /**< \brief Registration time for the last frame in milliseconds */
1155  int rnd_last_time; /**< \brief Rendering time for the last frame in milliseconds */
1156  int vtx_buffer_used; /**< \brief Number of bytes used in the vertex buffer for the last frame */
1157  int vtx_buffer_used_max;/**< \brief Number of bytes used in the vertex buffer for the largest frame */
1158  int buf_last_time; /**< \brief DMA buffer file time for the last frame in milliseconds */
1159  uint32 frame_count; /**< \brief Total number of rendered/viewed frames */
1160  /* ... more later as it's implemented ... */
1161 } pvr_stats_t;
1162 
1163 /** \brief Get the current statistics from the PVR.
1164 
1165  This function fills in the pvr_stats_t structure passed in with the current
1166  statistics of the system.
1167 
1168  \param stat The statistics structure to fill in. Must not be
1169  NULL
1170  \retval 0 On success
1171  \retval -1 If the PVR is not initialized
1172 */
1173 int pvr_get_stats(pvr_stats_t *stat);
1174 
1175 
1176 /* Palette management ************************************************/
1177 
1178 /* In addition to its 16-bit truecolor modes, the PVR also supports some
1179  nice paletted modes. These aren't useful for super high quality images
1180  most of the time, but they can be useful for doing some interesting
1181  special effects, like the old cheap "worm hole". */
1182 
1183 /** \defgroup pvr_palfmts PVR palette formats
1184 
1185  Entries in the PVR's palettes can be of any of these formats. Note that you
1186  can only have one format active at a time.
1187 
1188  @{
1189 */
1190 #define PVR_PAL_ARGB1555 0 /**< \brief 16-bit ARGB1555 palette format */
1191 #define PVR_PAL_RGB565 1 /**< \brief 16-bit RGB565 palette format */
1192 #define PVR_PAL_ARGB4444 2 /**< \brief 16-bit ARGB4444 palette format */
1193 #define PVR_PAL_ARGB8888 3 /**< \brief 32-bit ARGB8888 palette format */
1194 /** @} */
1195 
1196 /** \brief Set the palette format.
1197 
1198  This function sets the currently active palette format on the PVR. Each
1199  entry in the palette table is 32-bits in length, regardless of what color
1200  format is in use.
1201 
1202  Be sure to use care when using the PVR_PAL_ARGB8888 format. Rendering speed
1203  is greatly affected (cut about in half) if you use any filtering with
1204  paletted textures with ARGB8888 entries in the palette.
1205 
1206  \param fmt The format to use
1207  \see pvr_palfmts
1208 */
1209 void pvr_set_pal_format(int fmt);
1210 
1211 /** \brief Set a palette value.
1212 
1213  Note that while the color format is variable, each entry is still 32-bits in
1214  length regardless (and you only get a total of 1024 of them). If using one
1215  of the 16-bit palette formats, only the low-order 16-bits of the entry are
1216  valid, and the high bits should be filled in with 0.
1217 
1218  \param idx The index to set to (0-1023)
1219  \param value The color value to set in that palette entry
1220 */
1221 static inline void pvr_set_pal_entry(uint32 idx, uint32 value) {
1222  PVR_SET(PVR_PALETTE_TABLE_BASE + 4 * idx, value);
1223 }
1224 
1225 
1226 /* Hardware Fog parameters *******************************************/
1227 
1228 /* Thanks to Paul Boese for figuring this stuff out */
1229 
1230 /** \brief Set the table fog color.
1231 
1232  This function sets the color of fog for table fog. 0-1 range for all colors.
1233 
1234  \param a Alpha value of the fog
1235  \param r Red value of the fog
1236  \param g Green value of the fog
1237  \param b Blue value of the fog
1238 */
1239 void pvr_fog_table_color(float a, float r, float g, float b);
1240 
1241 /** \brief Set the vertex fog color.
1242 
1243  This function sets the fog color for vertex fog. 0-1 range for all colors.
1244  This function is currently not implemented, as vertex fog is not supported
1245  by KOS. Calling this function will cause an assertion failure.
1246 
1247  \param a Alpha value of the fog
1248  \param r Red value of the fog
1249  \param g Green value of the fog
1250  \param b Blue value of the fog
1251 */
1252 void pvr_fog_vertex_color(float a, float r, float g, float b);
1253 
1254 /** \brief Set the fog far depth.
1255 
1256  This function sets the PVR_FOG_DENSITY register appropriately for the
1257  specified value.
1258 
1259  \param d The depth to set
1260 */
1261 void pvr_fog_far_depth(float d);
1262 
1263 /** \brief Initialize the fog table using an exp2 algorithm (like GL_EXP2).
1264 
1265  This function will automatically set the PVR_FOG_DENSITY register to
1266  259.999999 as a part of its processing, then set up the fog table.
1267 
1268  \param density Fog density value
1269 */
1270 void pvr_fog_table_exp2(float density);
1271 
1272 /** \brief Initialize the fog table using an exp algorithm (like GL_EXP).
1273 
1274  This function will automatically set the PVR_FOG_DENSITY register to
1275  259.999999 as a part of its processing, then set up the fog table.
1276 
1277  \param density Fog density value
1278 */
1279 void pvr_fog_table_exp(float density);
1280 
1281 /** \brief Initialize the fog table using a linear algorithm (like GL_LINEAR).
1282 
1283  This function will set the PVR_FOG_DENSITY register to the as appropriate
1284  for the end value, and initialize the fog table for perspectively correct
1285  linear fog.
1286 
1287  \param start Fog start point
1288  \param end Fog end point
1289 */
1290 void pvr_fog_table_linear(float start, float end);
1291 
1292 /** \brief Set a custom fog table from float values
1293 
1294  This function allows you to specify whatever values you need to for your fog
1295  parameters. All values should be clamped between 0 and 1, and its your
1296  responsibility to set up the PVR_FOG_DENSITY register by calling
1297  pvr_fog_far_depth() with an appropriate value. The table passed in should
1298  have 129 entries, where the 0th entry is farthest from the eye and the last
1299  entry is nearest. Higher values = heavier fog.
1300 
1301  \param tbl1 The table of fog values to set
1302 */
1303 void pvr_fog_table_custom(float tbl1[]);
1304 
1305 
1306 /* Memory management *************************************************/
1307 
1308 /* PVR memory management in KOS uses a modified dlmalloc; see the
1309  source file pvr_mem_core.c for more info. */
1310 
1311 /** \brief Allocate a chunk of memory from texture space.
1312 
1313  This function acts as the memory allocator for the PVR texture RAM pool. It
1314  acts exactly as one would expect a malloc() function to act, returning a
1315  normal pointer that can be directly written to if one desires to do so. All
1316  allocations will be aligned to a 32-byte boundary.
1317 
1318  \param size The amount of memory to allocate
1319  \return A pointer to the memory on success, NULL on error
1320 */
1321 pvr_ptr_t pvr_mem_malloc(size_t size);
1322 
1323 /** \brief Free a block of allocated memory in the PVR RAM pool.
1324 
1325  This function frees memory previously allocated with pvr_mem_malloc().
1326 
1327  \param chunk The location of the start of the block to free
1328 */
1329 void pvr_mem_free(pvr_ptr_t chunk);
1330 
1331 /** \brief Return the number of bytes available still in the PVR RAM pool.
1332  \return The number of bytes available
1333 */
1335 
1336 /** \brief Reset the PVR RAM pool.
1337 
1338  This will essentially free any blocks allocated within the pool. There's
1339  generally not many good reasons for doing this.
1340 */
1341 void pvr_mem_reset();
1342 
1343 /** \brief Print the list of allocated blocks in the PVR RAM pool.
1344 
1345  This function only works if you've enabled KM_DBG in pvr_mem.c.
1346 */
1347 void pvr_mem_print_list();
1348 
1349 /** \brief Print statistics about the PVR RAM pool.
1350 
1351  This prints out statistics like what malloc_stats() provides. Also, if
1352  KM_DBG is enabled in pvr_mem.c, it prints the list of allocated blocks.
1353 */
1354 void pvr_mem_stats();
1355 
1356 /* Scene rendering ***************************************************/
1357 
1358 /* This API is used to submit triangle strips to the PVR via the TA
1359  interace in the chip.
1360 
1361  An important side note about the PVR is that all primitive types
1362  must be submitted grouped together. If you have 10 polygons for each
1363  list type, then the PVR must receive them via the TA by list type,
1364  with a list delimiter in between.
1365 
1366  So there are two modes you can use here. The first mode allows you to
1367  submit data directly to the TA. Your data will be forwarded to the
1368  chip for processing as it is fed to the PVR module. If your data
1369  is easily sorted into the primitive types, then this is the fastest
1370  mode for submitting data.
1371 
1372  The second mode allows you to submit data via main-RAM vertex buffers,
1373  which will be queued until the proper primitive type is active. In this
1374  case, each piece of data is copied into the vertex buffer while the
1375  wrong list is activated, and when the proper list becomes activated,
1376  the data is all sent at once. Ideally this would be via DMA, right
1377  now it is by store queues. This has the advantage of allowing you to
1378  send data in any order and have the PVR functions resolve how it should
1379  get sent to the hardware, but it is slower.
1380 
1381  The nice thing is that any combination of these modes can be used. You
1382  can assign a vertex buffer for any list, and it will be used to hold the
1383  incoming vertex data until the proper list has come up. Or if the proper
1384  list is already up, the data will be submitted directly. So if most of
1385  your polygons are opaque, and you only have a couple of translucents,
1386  you can set a small buffer to gather translucent data and then it will
1387  get sent when you do a pvr_end_scene().
1388 
1389  Thanks to Mikael Kalms for the idea for this API.
1390 
1391  Another somewhat subtle point that bears mentioning is that in the normal
1392  case (interrupts enabled) an interrupt handler will automatically take
1393  care of starting a frame rendering (after scene_finish()) and also
1394  flipping pages when appropriate. */
1395 
1396 /** \brief Is vertex DMA enabled?
1397  \return Non-zero if vertex DMA was enabled at init time
1398 */
1400 
1401 /** \brief Setup a vertex buffer for one of the list types.
1402 
1403  If the specified list type already has a vertex buffer, it will be replaced
1404  by the new one. Note that each buffer should actually be twice as long as
1405  what you will need to hold two frames worth of data).
1406 
1407  You should generally not try to do this at any time besides before a frame
1408  is begun, or Bad Things May Happen.
1409 
1410  \param list The primitive list to set the buffer for.
1411  \param buffer The location of the buffer in main RAM. This must be
1412  aligned to a 32-byte boundary.
1413  \param len The length of the buffer. This must be a multiple of
1414  64, and must be at least 128 (even if you're not
1415  using the list).
1416  \return The old buffer location (if any)
1417 */
1418 void * pvr_set_vertbuf(pvr_list_t list, void * buffer, int len);
1419 
1420 /** \brief Retrieve a pointer to the current output location in the DMA buffer
1421  for the requested list.
1422 
1423  Vertex DMA must globally be enabled for this to work. Data may be added to
1424  this buffer by the user program directly; however, make sure to call
1425  pvr_vertbuf_written() to notify the system of any such changes.
1426 
1427  \param list The primitive list to get the buffer for.
1428  \return The tail of that list's buffer.
1429 */
1430 void * pvr_vertbuf_tail(pvr_list_t list);
1431 
1432 /** \brief Notify the PVR system that data have been written into the output
1433  buffer for the given list.
1434 
1435  This should always be done after writing data directly to these buffers or
1436  it will get overwritten by other data.
1437 
1438  \param list The primitive list that was modified.
1439  \param amt Number of bytes written. Must be a multiple of 32.
1440 */
1441 void pvr_vertbuf_written(pvr_list_t list, uint32 amt);
1442 
1443 /** \brief Begin collecting data for a frame of 3D output to the off-screen
1444  frame buffer.
1445 
1446  You must call this function (or pvr_scene_begin_txr()) for ever frame of
1447  output.
1448 */
1449 void pvr_scene_begin();
1450 
1451 /** \brief Begin collecting data for a frame of 3D output to the specified
1452  texture.
1453 
1454  This function currently only supports outputting at the same size as the
1455  actual screen. Thus, make sure rx and ry are at least large enough for that.
1456  For a 640x480 output, rx will generally be 1024 on input and ry 512, as
1457  these are the smallest values that are powers of two and will hold the full
1458  screen sized output.
1459 
1460  \param txr The texture to render to.
1461  \param rx Width of the texture buffer (in pixels).
1462  \param ry Height of the texture buffer (in pixels).
1463 */
1464 void pvr_scene_begin_txr(pvr_ptr_t txr, uint32 *rx, uint32 *ry);
1465 
1466 /** \brief Begin collecting data for the given list type.
1467 
1468  Lists do not have to be submitted in any particular order, but all types of
1469  a list must be submitted at once (unless vertex DMA mode is enabled).
1470 
1471  Note that there is no need to call this function in DMA mode unless you want
1472  to make use of pvr_prim() for compatibility. This function will
1473  automatically call pvr_list_finish() if a list is already opened before
1474  opening the new list.
1475 
1476  \param list The list to open.
1477  \retval 0 On success.
1478  \retval -1 If the specified list has already been closed.
1479 */
1480 int pvr_list_begin(pvr_list_t list);
1481 
1482 /** \brief End collecting data for the current list type.
1483 
1484  Lists can never be opened again within a single frame once they have been
1485  closed. Thus submitting a primitive that belongs in a closed list is
1486  considered an error. Closing a list that is already closed is also an error.
1487 
1488  Note that if you open a list but do not submit any primitives, a blank one
1489  will be submitted to satisfy the hardware. If vertex DMA mode is enabled,
1490  then this simply sets the current list pointer to no list, and none of the
1491  above restrictions apply.
1492 
1493  \retval 0 On success.
1494  \retval -1 On error.
1495 */
1496 int pvr_list_finish();
1497 
1498 /** \brief Submit a primitive of the current list type.
1499 
1500  Note that any values submitted in this fashion will go directly to the
1501  hardware without any sort of buffering, and submitting a primitive of the
1502  wrong type will quite likely ruin your scene. Note that this also will not
1503  work if you haven't begun any list types (i.e., all data is queued). If DMA
1504  is enabled, the primitive will be appended to the end of the currently
1505  selected list's buffer.
1506 
1507  \param data The primitive to submit.
1508  \param size The length of the primitive, in bytes. Must be a
1509  multiple of 32.
1510  \retval 0 On success.
1511  \retval -1 On error.
1512 */
1513 int pvr_prim(void * data, int size);
1514 
1515 /** \brief Direct Rendering state variable type. */
1517 
1518 /** \brief Initialize a state variable for Direct Rendering.
1519 
1520  \param vtx_buf_ptr A variable of type pvr_dr_state_t to init.
1521 */
1522 #define pvr_dr_init(vtx_buf_ptr) do { \
1523  (vtx_buf_ptr) = 0; \
1524  QACR0 = ((((uint32)PVR_TA_INPUT) >> 26) << 2) & 0x1c; \
1525  QACR1 = ((((uint32)PVR_TA_INPUT) >> 26) << 2) & 0x1c; \
1526  } while (0)
1527 
1528 /** \brief Obtain the target address for Direct Rendering.
1529 
1530  \param vtx_buf_ptr State variable for Direct Rendering. Should be of
1531  type pvr_dr_state_t, and must have been initialized
1532  previously in the scene with pvr_dr_init().
1533  \return A write-only destination address where a primitive
1534  should be written to get ready to submit it to the
1535  TA in DR mode.
1536 */
1537 #define pvr_dr_target(vtx_buf_ptr) \
1538  ({ (vtx_buf_ptr) ^= 32; \
1539  (pvr_vertex_t *)(0xe0000000 | (vtx_buf_ptr)); \
1540  })
1541 
1542 /** \brief Commit a primitive written into the Direct Rendering target address.
1543 
1544  \param addr The address returned by pvr_dr_target(), after you
1545  have written the primitive to it.
1546 */
1547 #define pvr_dr_commit(addr) __asm__ __volatile__("pref @%0" : : "r" (addr))
1548 
1549 /** \brief Submit a primitive of the given list type.
1550 
1551  Data will be queued in a vertex buffer, thus one must be available for the
1552  list specified (will be asserted by the code).
1553 
1554  \param list The list to submit to.
1555  \param data The primitive to submit.
1556  \param size The size of the primitive in bytes. This must be a
1557  multiple of 32.
1558  \retval 0 On success.
1559  \retval -1 On error.
1560 */
1561 int pvr_list_prim(pvr_list_t list, void * data, int size);
1562 
1563 /** \brief Flush the buffered data of the given list type to the TA.
1564 
1565  This function is currently not implemented, and calling it will result in an
1566  assertion failure. It is intended to be used later in a "hybrid" mode where
1567  both direct and DMA TA submission is possible.
1568 
1569  \param list The list to flush.
1570  \retval -1 On error (it is not possible to succeed).
1571 */
1572 int pvr_list_flush(pvr_list_t list);
1573 
1574 /** \brief Call this after you have finished submitting all data for a frame.
1575 
1576  Once this has been called, you can not submit any more data until one of the
1577  pvr_scene_begin() or pvr_scene_begin_txr() functions is called again.
1578 
1579  \retval 0 On success.
1580  \retval -1 On error (no scene started).
1581 */
1582 int pvr_scene_finish();
1583 
1584 /** \brief Block the caller until the PVR system is ready for another frame to
1585  be submitted.
1586 
1587  The PVR system allocates enough space for two frames: one in data collection
1588  mode, and another in rendering mode. If a frame is currently rendering, and
1589  another frame has already been closed, then the caller cannot do anything
1590  else until the rendering frame completes. Note also that the new frame
1591  cannot be activated except during a vertical blanking period, so this
1592  essentially waits until a rendered frame is complete and a vertical blank
1593  happens.
1594 
1595  \retval 0 On success. A new scene can be started now.
1596  \retval -1 On error. Something is probably very wrong...
1597 */
1598 int pvr_wait_ready();
1599 
1600 /** \brief Check if the PVR system is ready for another frame to be submitted.
1601 
1602  \retval 0 If the PVR is ready for a new scene. You must call
1603  pvr_wait_ready() afterwards, before starting a new
1604  scene.
1605  \retval -1 If the PVR is not ready for a new scene yet.
1606 */
1607 int pvr_check_ready();
1608 
1609 
1610 /* Primitive handling ************************************************/
1611 
1612 /* These functions help you prepare primitives for loading into the
1613  PVR for scene processing. */
1614 
1615 /** \brief Compile a polygon context into a polygon header.
1616 
1617  This function compiles a pvr_poly_cxt_t into the form needed by the hardware
1618  for rendering. This is for use with normal polygon headers.
1619 
1620  \param dst Where to store the compiled header.
1621  \param src The context to compile.
1622 */
1624 
1625 /** \brief Fill in a polygon context for non-textured polygons.
1626 
1627  This function fills in a pvr_poly_cxt_t with default parameters appropriate
1628  for rendering a non-textured polygon in the given list.
1629 
1630  \param dst Where to store the polygon context.
1631  \param list The primitive list to be used.
1632 */
1633 void pvr_poly_cxt_col(pvr_poly_cxt_t *dst, pvr_list_t list);
1634 
1635 /** \brief Fill in a polygon context for a textured polygon.
1636 
1637  This function fills in a pvr_poly_cxt_t with default parameters appropriate
1638  for rendering a textured polygon in the given list.
1639 
1640  \param dst Where to store the polygon context.
1641  \param list The primitive list to be used.
1642  \param textureformat The format of the texture used.
1643  \param tw The width of the texture, in pixels.
1644  \param th The height of the texture, in pixels.
1645  \param textureaddr A pointer to the texture.
1646  \param filtering The type of filtering to use.
1647 
1648  \see pvr_txr_fmts
1649  \see pvr_filter_modes
1650 */
1652  int textureformat, int tw, int th, pvr_ptr_t textureaddr,
1653  int filtering);
1654 
1655 /** \brief Compile a sprite context into a sprite header.
1656 
1657  This function compiles a pvr_sprite_cxt_t into the form needed by the
1658  hardware for rendering. This is for use with sprite headers.
1659 
1660  \param dst Where to store the compiled header.
1661  \param src The context to compile.
1662 */
1664  pvr_sprite_cxt_t *src);
1665 
1666 /** \brief Fill in a sprite context for non-textured sprites.
1667 
1668  This function fills in a pvr_sprite_cxt_t with default parameters
1669  appropriate for rendering a non-textured sprite in the given list.
1670 
1671  \param dst Where to store the sprite context.
1672  \param list The primitive list to be used.
1673 */
1675 
1676 /** \brief Fill in a sprite context for a textured sprite.
1677 
1678  This function fills in a pvr_sprite_cxt_t with default parameters
1679  appropriate for rendering a textured sprite in the given list.
1680 
1681  \param dst Where to store the sprite context.
1682  \param list The primitive list to be used.
1683  \param textureformat The format of the texture used.
1684  \param tw The width of the texture, in pixels.
1685  \param th The height of the texture, in pixels.
1686  \param textureaddr A pointer to the texture.
1687  \param filtering The type of filtering to use.
1688 
1689  \see pvr_txr_fmts
1690  \see pvr_filter_modes
1691 */
1693  int textureformat, int tw, int th, pvr_ptr_t textureaddr,
1694  int filtering);
1695 
1696 /** \brief Create a modifier volume header.
1697 
1698  This function fills in a modifier volume header with the parameters
1699  specified. Note that unlike for polygons and sprites, there is no context
1700  step for modifiers.
1701 
1702  \param dst Where to store the modifier header.
1703  \param list The primitive list to be used.
1704  \param mode The mode for this modifier.
1705  \param cull The culling mode to use.
1706 
1707  \see pvr_mod_modes
1708  \see pvr_cull_modes
1709 */
1710 void pvr_mod_compile(pvr_mod_hdr_t *dst, pvr_list_t list, uint32 mode,
1711  uint32 cull);
1712 
1713 /** \brief Compile a polygon context into a polygon header that is affected by
1714  modifier volumes.
1715 
1716  This function works pretty similarly to pvr_poly_compile(), but compiles
1717  into the header type that is affected by a modifier volume. The context
1718  should have been created with either pvr_poly_cxt_col_mod() or
1719  pvr_poly_cxt_txr_mod().
1720 
1721  \param dst Where to store the compiled header.
1722  \param src The context to compile.
1723 */
1725 
1726 /** \brief Fill in a polygon context for non-textured polygons affected by a
1727  modifier volume.
1728 
1729  This function fills in a pvr_poly_cxt_t with default parameters appropriate
1730  for rendering a non-textured polygon in the given list that will be affected
1731  by modifier volumes.
1732 
1733  \param dst Where to store the polygon context.
1734  \param list The primitive list to be used.
1735 */
1737 
1738 /** \brief Fill in a polygon context for a textured polygon affected by
1739  modifier volumes.
1740 
1741  This function fills in a pvr_poly_cxt_t with default parameters appropriate
1742  for rendering a textured polygon in the given list and being affected by
1743  modifier volumes.
1744 
1745  \param dst Where to store the polygon context.
1746  \param list The primitive list to be used.
1747  \param textureformat The format of the texture used (outside).
1748  \param tw The width of the texture, in pixels (outside).
1749  \param th The height of the texture, in pixels (outside).
1750  \param textureaddr A pointer to the texture (outside).
1751  \param filtering The type of filtering to use (outside).
1752  \param textureformat2 The format of the texture used (inside).
1753  \param tw2 The width of the texture, in pixels (inside).
1754  \param th2 The height of the texture, in pixels (inside).
1755  \param textureaddr2 A pointer to the texture (inside).
1756  \param filtering2 The type of filtering to use (inside).
1757 
1758  \see pvr_txr_fmts
1759  \see pvr_filter_modes
1760 */
1762  int textureformat, int tw, int th,
1763  pvr_ptr_t textureaddr, int filtering,
1764  int textureformat2, int tw2, int th2,
1765  pvr_ptr_t textureaddr2, int filtering2);
1766 
1767 /* Texture handling **************************************************/
1768 
1769 /* Helper functions for handling texture tasks of various kinds. */
1770 
1771 /** \brief Load raw texture data from an SH-4 buffer into PVR RAM.
1772 
1773  This essentially just acts as a memcpy() from main RAM to PVR RAM, using
1774  the store queues.
1775 
1776  \param src The location in main RAM holding the texture.
1777  \param dst The location in PVR RAM to copy to.
1778  \param count The size of the texture in bytes (must be a multiple
1779  of 32).
1780 */
1781 void pvr_txr_load(void * src, pvr_ptr_t dst, uint32 count);
1782 
1783 /** \defgroup pvr_txrload_constants Texture loading constants
1784 
1785  These are constants for the flags parameter to pvr_txr_load_ex() or
1786  pvr_txr_load_kimg().
1787 
1788  @{
1789 */
1790 #define PVR_TXRLOAD_4BPP 0x01 /**< \brief 4BPP format */
1791 #define PVR_TXRLOAD_8BPP 0x02 /**< \brief 8BPP format */
1792 #define PVR_TXRLOAD_16BPP 0x03 /**< \brief 16BPP format */
1793 #define PVR_TXRLOAD_FMT_MASK 0x0f /**< \brief Bits used for basic formats */
1794 
1795 #define PVR_TXRLOAD_VQ_LOAD 0x10 /**< \brief Do VQ encoding (not supported yet, if ever) */
1796 #define PVR_TXRLOAD_INVERT_Y 0x20 /**< \brief Invert the Y axis while loading */
1797 #define PVR_TXRLOAD_FMT_VQ 0x40 /**< \brief Texture is already VQ encoded */
1798 #define PVR_TXRLOAD_FMT_TWIDDLED 0x80 /**< \brief Texture is already twiddled */
1799 #define PVR_TXRLOAD_FMT_NOTWIDDLE 0x80 /**< \brief Don't twiddle the texture while loading */
1800 #define PVR_TXRLOAD_DMA 0x8000 /**< \brief Use DMA to load the texture */
1801 #define PVR_TXRLOAD_NONBLOCK 0x4000 /**< \brief Use non-blocking loads (only for DMA) */
1802 #define PVR_TXRLOAD_SQ 0x2000 /**< \brief Use store queues to load */
1803 /** @} */
1804 
1805 /** \brief Load texture data from an SH-4 buffer into PVR RAM, twiddling it in
1806  the process.
1807 
1808  This function loads a texture to the PVR's RAM with the specified set of
1809  flags. It will currently always twiddle the data, whether you ask it to or
1810  not, and many of the parameters are just plain not supported at all...
1811  Pretty much the only supported flag, other than the format ones is the
1812  PVR_TXRLOAD_INVERT_Y one.
1813 
1814  This will be slower than using pvr_txr_load() in pretty much all cases, so
1815  unless you need to twiddle your texture, just use that instead.
1816 
1817  \param src The location to copy from.
1818  \param dst The location to copy to.
1819  \param w The width of the texture, in pixels.
1820  \param h The height of the texture, in pixels.
1821  \param flags Some set of flags, ORed together.
1822 
1823  \see pvr_txrload_constants
1824 */
1825 void pvr_txr_load_ex(void * src, pvr_ptr_t dst, uint32 w, uint32 h, uint32 flags);
1826 
1827 /** \brief Load a KOS Platform Independent Image (subject to constraint
1828  checking).
1829 
1830  This function loads a KOS Platform Independent image to the PVR's RAM with
1831  the specified set of flags. This function, unlike pvr_txr_load_ex() supports
1832  everything in the flags available, other than what's explicitly marked as
1833  not supported.
1834 
1835  \param img The image to load.
1836  \param dst The location to copy to.
1837  \param flags Some set of flags, ORed together.
1838 
1839  \see pvr_txrload_constants
1840 */
1841 void pvr_txr_load_kimg(kos_img_t *img, pvr_ptr_t dst, uint32 flags);
1842 
1843 
1844 /* PVR DMA ***********************************************************/
1845 
1846 /** \brief PVR DMA interrupt callback type.
1847 
1848  Functions that act as callbacks when DMA completes should be of this type.
1849  These functions will be called inside an interrupt context, so don't try to
1850  use anything that might stall.
1851 
1852  \param data User data passed in to the pvr_dma_transfer()
1853  function.
1854 */
1855 typedef void (*pvr_dma_callback_t)(ptr_t data);
1856 
1857 /** \brief Perform a DMA transfer to the PVR.
1858 
1859  This function copies a block of data to the PVR or its memory via DMA. There
1860  are all kinds of constraints that must be fulfilled to actually do this, so
1861  make sure to read all the fine print with the parameter list.
1862 
1863  If a callback is specified, it will be called in an interrupt context, so
1864  keep that in mind in writing the callback.
1865 
1866  \param src Where to copy from. Must be 32-byte aligned.
1867  \param dest Where to copy to. Must be 32-byte aligned.
1868  \param count The number of bytes to copy. Must be a multiple of
1869  32.
1870  \param type The type of DMA transfer to do (see list of modes).
1871  \param block Non-zero if you want the function to block until the
1872  DMA completes.
1873  \param callback A function to call upon completion of the DMA.
1874  \param cbdata Data to pass to the callback function.
1875  \retval 0 On success.
1876  \retval -1 On failure. Sets errno as appropriate.
1877 
1878  \par Error Conditions:
1879  \em EINPROGRESS - DMA already in progress \n
1880  \em EFAULT - dest is not 32-byte aligned \n
1881  \em EIO - I/O error
1882 
1883  \see pvr_dma_modes
1884 */
1885 int pvr_dma_transfer(void * src, uint32 dest, uint32 count, int type,
1886  int block, pvr_dma_callback_t callback, ptr_t cbdata);
1887 
1888 /** \defgroup pvr_dma_modes Transfer modes with PVR DMA
1889  @{
1890 */
1891 #define PVR_DMA_VRAM64 0 /**< \brief Transfer to VRAM in interleaved mode */
1892 #define PVR_DMA_VRAM32 1 /**< \brief Transfer to VRAM in linear mode */
1893 #define PVR_DMA_TA 2 /**< \brief Transfer to the tile accelerator */
1894 /** @} */
1895 
1896 /** \brief Load a texture using PVR DMA.
1897 
1898  This is essentially a convenience wrapper for pvr_dma_transfer(), so all
1899  notes that apply to it also apply here.
1900 
1901  \param src Where to copy from. Must be 32-byte aligned.
1902  \param dest Where to copy to. Must be 32-byte aligned.
1903  \param count The number of bytes to copy. Must be a multiple of
1904  32.
1905  \param block Non-zero if you want the function to block until the
1906  DMA completes.
1907  \param callback A function to call upon completion of the DMA.
1908  \param cbdata Data to pass to the callback function.
1909  \retval 0 On success.
1910  \retval -1 On failure. Sets errno as appropriate.
1911 
1912  \par Error Conditions:
1913  \em EINPROGRESS - DMA already in progress \n
1914  \em EFAULT - dest is not 32-byte aligned \n
1915  \em EIO - I/O error
1916 */
1917 int pvr_txr_load_dma(void * src, pvr_ptr_t dest, uint32 count, int block,
1918  pvr_dma_callback_t callback, ptr_t cbdata);
1919 
1920 /** \brief Load vertex data to the TA using PVR DMA.
1921 
1922  This is essentially a convenience wrapper for pvr_dma_transfer(), so all
1923  notes that apply to it also apply here.
1924 
1925  \param src Where to copy from. Must be 32-byte aligned.
1926  \param count The number of bytes to copy. Must be a multiple of
1927  32.
1928  \param block Non-zero if you want the function to block until the
1929  DMA completes.
1930  \param callback A function to call upon completion of the DMA.
1931  \param cbdata Data to pass to the callback function.
1932  \retval 0 On success.
1933  \retval -1 On failure. Sets errno as appropriate.
1934 
1935  \par Error Conditions:
1936  \em EINPROGRESS - DMA already in progress \n
1937  \em EFAULT - dest is not 32-byte aligned \n
1938  \em EIO - I/O error
1939  */
1940 int pvr_dma_load_ta(void * src, uint32 count, int block,
1941  pvr_dma_callback_t callback, ptr_t cbdata);
1942 
1943 /** \brief Is PVR DMA is inactive?
1944  \return Non-zero if there is no PVR DMA active, thus a DMA
1945  can begin or 0 if there is an active DMA.
1946 */
1947 int pvr_dma_ready();
1948 
1949 /** \brief Initialize PVR DMA. */
1950 void pvr_dma_init();
1951 
1952 /** \brief Shut down PVR DMA. */
1953 void pvr_dma_shutdown();
1954 
1955 /*********************************************************************/
1956 
1957 
1958 __END_DECLS
1959 
1960 #endif
1961