1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin GX library
3   File:     GXVert.h
4 
5   Copyright 1998-2002 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: GXVert.h,v $
14   Revision 1.3  2007/01/11 00:47:44  aka
15   Removed win32.h.
16 
17   Revision 1.2  2006/02/04 11:56:46  hashida
18   (none)
19 
20   Revision 1.1.1.1  2005/12/29 06:53:28  hiratsu
21   Initial import.
22 
23   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
24   Ported from dolphin source tree.
25 
26 
27     12    2002/07/24 9:08 Hirose
28     Resolved version conflicts.
29 
30     11    2001/06/11 7:52p Tian
31     Integrated SN changes
32 
33     10    2001/05/07 6:45p Tian
34     Fixes for SN compiler
35 
36     9    2001/04/17 5:29p Tian
37     Changed all inlines to static inline
38 
39     8     2000/12/15 6:23p Stevera
40 
41     7     2000/12/15 5:07p Stevera
42     Divided some complex lines up in order to maintain compatibility with
43     Visual C++.
44 
45     6    2000/11/01 11:13a Hirose
46     Flag fix EPPC -> !EMU
47 
48     5    2000/09/29 9:51p Hirose
49     Replaced "MAC" flag by better alternatives
50 
51     4     2000/07/07 6:00p Dante
52     PC Compatibility
53 
54     3     2000/02/01 7:22p Alligator
55     Second GX update from ArtX
56 
57     2     2000/01/18 1:51p Tian
58     Updated GXFIFO_ADDR for MINNOW_MARLIN target
59 
60     22    1999/11/18 3:35p Carl
61     Added debug version definitions (for using non-inlined code).
62 
63     21    1999/11/17 6:33p Carl
64     Added support for emulator display list creation.
65 
66     20    1999/11/03 6:41p Yasu
67     Fixed remained macros
68 
69     19    1999/11/03 6:21p Yasu
70     Replaced GX*1u8,u16 with GX*1x8,x16
71 
72     18    1999/10/22 4:09p Yasu
73     Activated all of Position 2D functions and TexCoord 1D functions
74 
75     17    1999/10/19 6:44p Yasu
76     Deleted GXNormal9* functions
77 
78     16    1999/10/04 6:39p Hirose
79     Fixed GXPackedRGB5A3 to match 8-level alpha implementation
80 
81     15     1999/09/23 4:12p Hirose
82     Added (u16) cast to GX Packed Color format macros
83 
84     14     1999/09/21 4:59p Alligator
85     Added 9 element normals
86 
87     13    1999/09/01 11:35a Ryan
88 
89     12     1999/08/24 8:49p Yasu
90     Added RGBA packing macros.
91 
92     11     1999/08/21 2:55p Yasu
93     Appended entries of GXPosition2* and GXTexCoord1*.
94 
95     10    1999/08/18 1:32a Shiki
96     Changed fifo address to the final address (0xCC008000).
97 
98     9     1999/07/29 3:52p Yasu
99     Added GXMatrixIndex1u8(u8) in EPPC section.
100 
101     8     1999/07/23 12:30p Alligator
102     Fixed pnmtx index per vertex emulation
103 
104     7     1999/07/16 2:57p Alligator
105     Changed fifo address to 0xa0000000 to trap exceptions
106 
107     6     1999/07/16 2:32p Alligator
108     Used GXVertex for debug and non-debug version of EPPC library for now.
109 
110     5     1999/07/16 1:24p Alligator
111     Put wgpipe address depends only on EPPC flag
112 
113     4     1999/07/14 9:19p Yoshya01
114     Appended inline Vertex API functions for EPPC.
115 
116     3     1999/06/04 2:46p Ryan
117 
118     2     1999/06/03 3:16p Ryan
119 
120     1     1999/06/01 2:04p Ryan
121 
122   $NoKeywords: $
123  *---------------------------------------------------------------------------*/
124 
125 #ifndef __GXVERT_H__
126 #define __GXVERT_H__
127 
128 // NOTE: This file closely mirrors GXVert.c.
129 //        Don't change this file without considering that one too,
130 //        and vice-versa.
131 
132 /********************************/
133 #ifdef __cplusplus
134 extern "C" {
135 #endif
136 
137 /*>*******************************(*)*******************************<*/
138 #ifndef EMU // Real hardware
139 /*---------------------------------------------*
140  * Write gather pipe for GFXFifo               *
141  *---------------------------------------------*/
142 #ifndef MINNOW
143 #define   GXFIFO_ADDR   0xCC008000
144 #else // MINNOW
145 #define   GXFIFO_ADDR   0x1C008000
146 #endif// MINNOW
147 
148 #include  <revolution/base/PPCWGPipe.h>
149 // SN-Phil: Removed 'extern', added AT_ADDRESS
150 volatile PPCWGPipe GXWGFifo AT_ADDRESS(GXFIFO_ADDR) ;
151 
152 #endif // !EMU
153 /*---------------------------------------------------------------------------*/
154 
155 #if defined(EMU) || defined(WIN32)
156 /*---------------------------------------------*
157  * Display list support for emulator           *
158  *---------------------------------------------*/
159 
160 #include <revolution/gx/GXEmVert.h>
161 
162 extern u8* __EmBuffPtr;
163 extern u8* __EmBuffTop;
164 extern GXBool __EmDisplayListInProgress;
165 
166 #endif // EMU
167 
168 /*---------------------------------------------------------------------------*/
169 /*---------------------------------------------*
170  * GXVertex functions                          *
171  *---------------------------------------------*/
172 //-------------------------------
173 // Define gfx function templates
174 //-------------------------------
175 //
176 // Templates syntax:
177 //  __GXCDEF (function_prefix, num_of_components, component_type)
178 //  __GXCDEFX(function_name, num_of_comps, src_comp_type, dest_comp_type)
179 //
180 #define __GXCDEF(prfx,n,t)  __GXCDEF##n(prfx##n##t,t,t)
181 #define __GXCDEFX(func,n,t) __GXCDEF##n(func,t,t)
182 
183 #ifdef _DEBUG
184 
185 // 1 component
186 #define __GXCDEF1(func,ts,td) \
187     void func(const ts x);
188 
189 // 2 components
190 #define __GXCDEF2(func,ts,td) \
191     void func(const ts x, const ts y);
192 
193 // 3 components
194 #define __GXCDEF3(func,ts,td) \
195     void func(const ts x, const ts y, const ts z);
196 
197 // 4 components
198 #define __GXCDEF4(func,ts,td) \
199     void func(const ts x, const ts y, const ts z, const ts w);
200 
201 
202 #else // ifdef _DEBUG
203 /*---------------------------------------------*
204  * For emulator                                *
205  *---------------------------------------------*/
206 #if defined(EMU)
207 
208 // 1 component
209 #define __GXCDEF1(func,ts,td) \
210     static inline void func(const ts x)  \
211     {                             \
212         if (__EmDisplayListInProgress) { \
213 			*((td *) __EmBuffPtr) = (td) x; \
214 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
215         } else {                  \
216             Em##func(x);          \
217         }                         \
218         return;                   \
219     }
220 
221 // 2 components
222 #define __GXCDEF2(func,ts,td) \
223     static inline void func(const ts x, const ts y) \
224     {                             \
225         if (__EmDisplayListInProgress) { \
226 			*((td *) __EmBuffPtr) = (td) x; \
227 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
228 			*((td *) __EmBuffPtr) = (td) y; \
229 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
230         } else {                  \
231             Em##func(x, y);       \
232         }                         \
233         return;                   \
234     }
235 
236 // 3 components
237 #define __GXCDEF3(func,ts,td) \
238     static inline void func(const ts x, const ts y, const ts z) \
239     {                             \
240         if (__EmDisplayListInProgress) { \
241 			*((td *) __EmBuffPtr) = (td) x; \
242 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
243 			*((td *) __EmBuffPtr) = (td) y; \
244 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
245 			*((td *) __EmBuffPtr) = (td) z; \
246 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
247         } else {                  \
248             Em##func(x, y, z);    \
249         }                         \
250         return;                   \
251     }
252 
253 // 4 components
254 #define __GXCDEF4(func,ts,td) \
255     static inline void func(const ts x, const ts y, const ts z, const ts w) \
256     {                             \
257         if (__EmDisplayListInProgress) { \
258 			*((td *) __EmBuffPtr) = (td) x; \
259 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
260 			*((td *) __EmBuffPtr) = (td) y; \
261 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
262 			*((td *) __EmBuffPtr) = (td) z; \
263 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
264 			*((td *) __EmBuffPtr) = (td) w; \
265 			__EmBuffPtr = __EmBuffPtr + sizeof(td); \
266         } else {                  \
267             Em##func(x, y, z, w); \
268         }                         \
269         return;                   \
270     }
271 
272 #endif // ifdef EMU
273 
274 /*---------------------------------------------*
275  * For real hardware                           *
276  *---------------------------------------------*/
277 #ifndef EMU
278 
279 // 1 component
280 #define __GXCDEF1(func,ts,td) \
281     static inline void func(const ts x) \
282     {                         \
283         GXWGFifo.td = (td) x; \
284         return;               \
285     }
286 
287 // 2 components
288 #define __GXCDEF2(func,ts,td) \
289     static inline void func(const ts x, const ts y) \
290     {                         \
291         GXWGFifo.td = (td) x; \
292         GXWGFifo.td = (td) y; \
293         return;               \
294     }
295 
296 // 3 components
297 #define __GXCDEF3(func,ts,td) \
298     static inline void func(const ts x, const ts y, const ts z) \
299     {                         \
300         GXWGFifo.td = (td) x; \
301         GXWGFifo.td = (td) y; \
302         GXWGFifo.td = (td) z; \
303         return;               \
304     }
305 
306 // 4 components
307 #define __GXCDEF4(func,ts,td) \
308     static inline void func(const ts x, const ts y, const ts z, const ts w) \
309     {                         \
310         GXWGFifo.td = (td) x; \
311         GXWGFifo.td = (td) y; \
312         GXWGFifo.td = (td) z; \
313         GXWGFifo.td = (td) w; \
314         return;               \
315     }
316 
317 #endif // ifndef EMU
318 
319 #endif // ifdef _DEBUG else
320 
321 //---------------------------
322 // Generate inline functions
323 //---------------------------
324 //---- GXCmd[n][t] ----
325 __GXCDEF( GXCmd, 1, u8  )
326 __GXCDEF( GXCmd, 1, u16 )
327 __GXCDEF( GXCmd, 1, u32 )
328 
329 //---- GXParam[n][t] ----
330 __GXCDEF( GXParam, 1, u8  )
331 __GXCDEF( GXParam, 1, u16 )
332 __GXCDEF( GXParam, 1, u32 )
333 __GXCDEF( GXParam, 1, s8  )
334 __GXCDEF( GXParam, 1, s16 )
335 __GXCDEF( GXParam, 1, s32 )
336 __GXCDEF( GXParam, 1, f32 )
337 __GXCDEF( GXParam, 3, f32 ) // For light
338 __GXCDEF( GXParam, 4, f32 ) // For matrix
339 
340 //---- GXPosition[n][t] ----
341   // For GX_POS_XYZ
342 __GXCDEF( GXPosition, 3, f32 )
343 __GXCDEF( GXPosition, 3, u8  )
344 __GXCDEF( GXPosition, 3, s8  )
345 __GXCDEF( GXPosition, 3, u16 )
346 __GXCDEF( GXPosition, 3, s16 )
347   // For GX_POS_XY
348 __GXCDEF( GXPosition, 2, f32 )
349 __GXCDEF( GXPosition, 2, u8  )
350 __GXCDEF( GXPosition, 2, s8  )
351 __GXCDEF( GXPosition, 2, u16 )
352 __GXCDEF( GXPosition, 2, s16 )
353   // For Index
354 __GXCDEFX( GXPosition1x16, 1, u16 )
355 __GXCDEFX( GXPosition1x8,  1, u8  )
356 
357 //---- GXNormal[n][t] ----
358   // For GX_NRM or GX_NBT
359 __GXCDEF( GXNormal, 3, f32 )
360 __GXCDEF( GXNormal, 3, s16 )
361 __GXCDEF( GXNormal, 3, s8  )
362   // For Index
363 __GXCDEFX( GXNormal1x16, 1, u16 )
364 __GXCDEFX( GXNormal1x8,  1, u8  )
365 
366 //---- GXColor[n][t] ----
367   // For GX_CLR_RGBA8 or RGBX8
368 __GXCDEF( GXColor, 4, u8  )
369 __GXCDEF( GXColor, 1, u32 )
370   // For GX_CLR_RGBA6 or RGB8
371 __GXCDEF( GXColor, 3, u8  )
372   // For GX_CLR_RGBA4 or RGB565
373 __GXCDEF( GXColor, 1, u16 )
374   // For Index
375 __GXCDEFX( GXColor1x16, 1, u16 )
376 __GXCDEFX( GXColor1x8,  1, u8  )
377 
378 //---- GXTexCoord[n][t] ----
379   // For GX_TEX_ST
380 __GXCDEF( GXTexCoord, 2, f32 )
381 __GXCDEF( GXTexCoord, 2, s16 )
382 __GXCDEF( GXTexCoord, 2, u16 )
383 __GXCDEF( GXTexCoord, 2, s8  )
384 __GXCDEF( GXTexCoord, 2, u8  )
385   // For GX_TEX_S
386 __GXCDEF( GXTexCoord, 1, f32 )
387 __GXCDEF( GXTexCoord, 1, s16 )
388 __GXCDEF( GXTexCoord, 1, u16 )
389 __GXCDEF( GXTexCoord, 1, s8  )
390 __GXCDEF( GXTexCoord, 1, u8  )
391   // For Index
392 __GXCDEFX( GXTexCoord1x16, 1, u16 )
393 __GXCDEFX( GXTexCoord1x8,  1, u8  )
394 
395 //---- GXMatrixIndex* ----
396 // GXMatrixIndex1u8
397 __GXCDEF( GXMatrixIndex, 1, u8 )
398 #define GXMatrixIndex1x8    GXMatrixIndex1u8
399 
400 //------------------------
401 // Undefine all templates
402 //------------------------
403 #undef  __GXCDEF
404 #undef  __GXCDEFX
405 #undef  __GXCDEF1
406 #undef  __GXCDEF2
407 #undef  __GXCDEF3
408 #undef  __GXCDEF4
409 
410 /*---------------------------------------------------------------------------*/
411 // Packing macro for a several color format
412 #define	GXPackedRGB565(r,g,b)   \
413 	((u16)((((r)&0xf8)<<8)|(((g)&0xfc)<<3)|(((b)&0xf8)>>3)))
414 #define	GXPackedRGBA4(r,g,b,a)  \
415 	((u16)((((r)&0xf0)<<8)|(((g)&0xf0)<<4)|(((b)&0xf0)   )|(((a)&0xf0)>>4)))
416 #define	GXPackedRGB5A3(r,g,b,a) \
417 	((u16)((a)>=224 ? \
418 	((((r)&0xf8)<<7)|(((g)&0xf8)<<2)|(((b)&0xf8)>>3)|(1<<15)): \
419 	((((r)&0xf0)<<4)|(((g)&0xf0)   )|(((b)&0xf0)>>4)|(((a)&0xe0)<<7))))
420 
421 #ifdef __cplusplus
422 }
423 #endif
424 
425 #endif  // __GXVERT_H__
426