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