1 // Create a unique name for each of the functions
2 #define FN(a,b,c,d,e,f,g) RenderSprite ## a ## _ ## b ## _ROT ## c ## d ## e ## _CLIPX ## f ## g
3 #define FUNCTIONNAME(a,b,c,d,e,f,g) FN(a,b,c,d,e,f,g)
4 
5 #if ROT == 0
6  #define ADVANCEWORD pPixel += ((BPP >> 3) * 16)
7  #define ADVANCEROW pRow += ((BPP >> 3) * XSIZE)
8 #else
9  #error unsupported rotation angle specified
10 #endif
11 
12 #if EIGHTBIT == 0
13  #define DEPTH _16
14 #elif EIGHTBIT == 1
15  #define DEPTH _256
16 #else
17  #error illegal eightbit value
18 #endif
19 
20 #define TESTCOLOUR(x) x
21 
22 #if ZBUFFER == 0
23  #define ZBUF _NOZBUFFER
24  #define ADVANCEZWORD
25  #define ADVANCEZROW
26  #define TESTZBUF(a) 1
27  #define WRITEZBUF(a)
28 #elif ZBUFFER == 1
29  #define ZBUF _RZBUFFER
30  #define ADVANCEZWORD pZPixel += 16
31  #define ADVANCEZROW pZRow += XSIZE
32  #define TESTZBUF(a) (pZPixel[a] <= nZPos)
33  #define WRITEZBUF(a)
34 #elif ZBUFFER == 2
35  #define ZBUF _WZBUFFER
36  #define ADVANCEZWORD pZPixel += 16
37  #define ADVANCEZROW pZRow += XSIZE
38  #define TESTZBUF(a) 1
39  #define WRITEZBUF(a) pZPixel[a] = nZPos
40 #elif ZBUFFER == 3
41  #define ZBUF _RWZBUFFER
42  #define ADVANCEZWORD pZPixel += 16
43  #define ADVANCEZROW pZRow += XSIZE
44  #define TESTZBUF(a) (pZPixel[a] <= nZPos)
45  #define WRITEZBUF(a) pZPixel[a] = nZPos
46 #else
47  #error unsupported zbuffer mode specified.
48 #endif
49 
50 #if BPP == 16
51  #define PLOTPIXEL(a,b) if (TESTCOLOUR(b) && TESTZBUF(a)) {						\
52    	WRITEZBUF(a);																\
53 	*((UINT16*)(pPixel + a * 2)) = (UINT16)pSpritePalette[b];	\
54  }
55 #elif BPP == 24
56  #define PLOTPIXEL(a,b) if (TESTCOLOUR(b) && TESTZBUF(a)) {						\
57 	WRITEZBUF(a);																\
58 	UINT32 nRGB = pSpritePalette[b];										\
59 	pPixel[a * 3 + 0] = (UINT8)nRGB;									\
60 	pPixel[a * 3 + 1] = (UINT8)(nRGB >> 8);								\
61 	pPixel[a * 3 + 2] = (UINT8)(nRGB >> 16);							\
62  }
63 #elif BPP == 32
64  #define PLOTPIXEL(a,b) if (TESTCOLOUR(b) && TESTZBUF(a)) {						\
65 	WRITEZBUF(a);																\
66 	*((UINT32*)(pPixel + a * 4)) = (UINT32)pSpritePalette[b];		\
67  }
68 #else
69  #error unsupported bitdepth specified.
70 #endif
71 
72 #if XFLIP == 0
73  #define FLIP _NOFLIP
74 #elif XFLIP == 1
75  #define FLIP _FLIPX
76 #else
77  #error illegal XFLIP value
78 #endif
79 
80 #if ZOOM == 0
81  #define ZOOMMODE _NOZOOM
82 #elif ZOOM == 1
83  #define ZOOMMODE _ZOOMXY
84 #else
85  #error unsupported rowscroll mode specified.
86 #endif
87 
88 #if XFLIP == 0
89  #define OFFSET(a) a
90  #define CLIP(a,b) if (nColumn >= (XSIZE - a)) { continue; }			\
91 	if (nXPos >= (0 - a)) { b }
92 #else
93  #define OFFSET(a) (15 - a)
94  #define CLIP(a,b) if (nColumn >= (0 - a) && nColumn < (XSIZE - a)) { b }
95 #endif
96 
97 #if EIGHTBIT == 0
98  #define PLOT8_CLIP(x)		  				 	 	     				\
99 	CLIP(OFFSET((x + 0)), PLOTPIXEL(OFFSET((x + 0)), nColour & 0x0F));	\
100 	nColour >>= 4;														\
101 	CLIP(OFFSET((x + 1)), PLOTPIXEL(OFFSET((x + 1)), nColour & 0x0F));	\
102 																		\
103 	nColour >>= 4;														\
104 	CLIP(OFFSET((x + 2)), PLOTPIXEL(OFFSET((x + 2)), nColour & 0x0F));	\
105 	nColour >>= 4;														\
106 	CLIP(OFFSET((x + 3)), PLOTPIXEL(OFFSET((x + 3)), nColour & 0x0F));	\
107 																		\
108 	nColour >>= 4;														\
109 	CLIP(OFFSET((x + 4)), PLOTPIXEL(OFFSET((x + 4)), nColour & 0x0F));	\
110 	nColour >>= 4;														\
111 	CLIP(OFFSET((x + 5)), PLOTPIXEL(OFFSET((x + 5)), nColour & 0x0F));	\
112 																		\
113 	nColour >>= 4;														\
114 	CLIP(OFFSET((x + 6)), PLOTPIXEL(OFFSET((x + 6)), nColour & 0x0F));	\
115 	nColour >>= 4;														\
116 	CLIP(OFFSET((x + 7)), PLOTPIXEL(OFFSET((x + 7)), nColour & 0x0F));
117 
118  #define PLOT8_NOCLIP(x)		   										\
119 	PLOTPIXEL(OFFSET((x + 0)), nColour & 0x0F);							\
120 	nColour >>= 4;														\
121 	PLOTPIXEL(OFFSET((x + 1)), nColour & 0x0F);							\
122 																		\
123 	nColour >>= 4;														\
124 	PLOTPIXEL(OFFSET((x + 2)), nColour & 0x0F);							\
125 	nColour >>= 4;														\
126 	PLOTPIXEL(OFFSET((x + 3)), nColour & 0x0F);							\
127 																		\
128 	nColour >>= 4;														\
129 	PLOTPIXEL(OFFSET((x + 4)), nColour & 0x0F);							\
130 	nColour >>= 4;														\
131 	PLOTPIXEL(OFFSET((x + 5)), nColour & 0x0F);							\
132 																		\
133 	nColour >>= 4;														\
134 	PLOTPIXEL(OFFSET((x + 6)), nColour & 0x0F);							\
135 	nColour >>= 4;														\
136 	PLOTPIXEL(OFFSET((x + 7)), nColour & 0x0F);
137 #else
138  #define PLOT4_CLIP(x) 				 	 	    		 				\
139 	CLIP(OFFSET((x + 0)), PLOTPIXEL(OFFSET((x + 0)), nColour & 0xFF));	\
140 	nColour >>= 8;	  													\
141 	CLIP(OFFSET((x + 1)), PLOTPIXEL(OFFSET((x + 1)), nColour & 0xFF));	\
142 	nColour >>= 8;	  													\
143 																	  	\
144 	CLIP(OFFSET((x + 2)), PLOTPIXEL(OFFSET((x + 2)), nColour & 0xFF));	\
145 	nColour >>= 8;														\
146 	CLIP(OFFSET((x + 3)), PLOTPIXEL(OFFSET((x + 3)), nColour & 0xFF));
147 
148  #define PLOT4_NOCLIP(x)	   											\
149 	PLOTPIXEL(OFFSET((x + 0)), nColour & 0xFF);							\
150 	nColour >>= 8;														\
151 	PLOTPIXEL(OFFSET((x + 1)), nColour & 0xFF);							\
152 	nColour >>= 8;														\
153 																		\
154 	PLOTPIXEL(OFFSET((x + 2)), nColour & 0xFF);							\
155 	nColour >>= 8;														\
156 	PLOTPIXEL(OFFSET((x + 3)), nColour & 0xFF);
157 #endif
158 
FUNCTIONNAME(BPP,XSIZE,ROT,FLIP,ZOOMMODE,ZBUF,DEPTH)159 static void FUNCTIONNAME(BPP,XSIZE,ROT,FLIP,ZOOMMODE,ZBUF,DEPTH)()
160 {
161 // Create an empty function if unsupported features are requested
162 #if ROT == 0
163 
164 	INT32 x, nColumn;
165 	INT32 nColour;
166 
167  #if ZBUFFER == 0
168 	for (nSpriteRow = 0; nSpriteRow < nYSize; ADVANCEROW, nSpriteRow++, pSpriteData += nSpriteRowSize) {
169  #else
170 		for (nSpriteRow = 0; nSpriteRow < nYSize; ADVANCEROW, ADVANCEZROW, nSpriteRow++, pSpriteData += nSpriteRowSize) {
171  #endif
172 		nColumn = nXPos;
173 
174  #if ZBUFFER == 0
175   #if XFLIP == 0
176 		for (x = (0 << EIGHTBIT), pPixel = pRow; x < nXSize; x += (2 << EIGHTBIT), nColumn += 16, ADVANCEWORD) {
177   #else
178 		for (x = nXSize - (2 << EIGHTBIT), pPixel = pRow; x >= 0; x -= (2 << EIGHTBIT), nColumn += 16, ADVANCEWORD) {
179   #endif
180  #else
181   #if XFLIP == 0
182 		for (x = 0, pPixel = pRow, pZPixel = pZRow; x < nXSize; x += (2 << EIGHTBIT), nColumn += 16, ADVANCEWORD, ADVANCEZWORD) {
183   #else
184 		for (x = nXSize - (2 << EIGHTBIT), pPixel = pRow, pZPixel = pZRow; x >= 0; x -= (2 << EIGHTBIT), nColumn += 16, ADVANCEWORD, ADVANCEZWORD) {
185   #endif
186  #endif
187 
188  #if EIGHTBIT == 0
189 			if (nColumn >= 0 && nColumn < (XSIZE - 16)) {
190   #if XFLIP == 0
191 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
192 				PLOT8_NOCLIP(0);
193 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
194 				PLOT8_NOCLIP(8);
195   #else
196 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
197 				PLOT8_NOCLIP(8);
198 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
199 				PLOT8_NOCLIP(0);
200   #endif
201 			} else {
202   #if XFLIP == 0
203 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
204 				PLOT8_CLIP(0);
205 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
206 				PLOT8_CLIP(8);
207   #else
208 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
209 				PLOT8_CLIP(8);
210 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
211 				PLOT8_CLIP(0);
212   #endif
213  #else
214 			if (nColumn >= 0 && nColumn < (XSIZE - 16)) {
215   #if XFLIP == 0
216 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
217 				PLOT4_NOCLIP(0);
218 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
219 				PLOT4_NOCLIP(4);
220 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 2]);
221 				PLOT4_NOCLIP(8);
222 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 3]);
223 				PLOT4_NOCLIP(12);
224   #else
225 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 3]);
226 				PLOT4_NOCLIP(12);
227 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 2]);
228 				PLOT4_NOCLIP(8);
229 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
230 				PLOT4_NOCLIP(4);
231 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
232 				PLOT4_NOCLIP(0);
233   #endif
234 			} else {
235   #if XFLIP == 0
236 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
237 				PLOT4_CLIP(0);
238 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
239 				PLOT4_CLIP(4);
240 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 2]);
241 				PLOT4_CLIP(8);
242 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 3]);
243 				PLOT4_CLIP(12);
244   #else
245 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 3]);
246 				PLOT4_CLIP(12);
247 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 2]);
248 				PLOT4_CLIP(8);
249 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x + 1]);
250 				PLOT4_CLIP(4);
251 				nColour = BURN_ENDIAN_SWAP_INT32(pSpriteData[x]);
252 				PLOT4_CLIP(0);
253   #endif
254  #endif
255 			}
256 		}
257 	}
258 #endif
259 }
260 
261 #undef PLOT4_CLIP
262 #undef PLOT4_NOCLIP
263 #undef PLOT8_CLIP
264 #undef PLOT8_NOCLIP
265 #undef OFFSET
266 #undef FLIP
267 #undef PLOTPIXEL
268 #undef CLIP
269 #undef TESTCOLOUR
270 #undef ADVANCEZROW
271 #undef ADVANCEZWORD
272 #undef ADVANCEROW
273 #undef ADVANCEWORD
274 #undef TESTZBUF
275 #undef WRITEZBUF
276 #undef ZBUF
277 #undef ZOOMMODE
278 #undef DEPTH
279 #undef FUNCTIONNAME
280 #undef FN
281 
282