2961
|
1 /* Copyright (C) 2006 yopyop
|
|
2 yopyop156@ifrance.com
|
|
3 yopyop156.ifrance.com
|
|
4
|
|
5 Copyright (C) 2006-2007 Theo Berkau
|
|
6 Copyright (C) 2007 shash
|
|
7
|
|
8 This file is part of DeSmuME
|
|
9
|
|
10 DeSmuME is free software; you can redistribute it and/or modify
|
|
11 it under the terms of the GNU General Public License as published by
|
|
12 the Free Software Foundation; either version 2 of the License, or
|
|
13 (at your option) any later version.
|
|
14
|
|
15 DeSmuME is distributed in the hope that it will be useful,
|
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 GNU General Public License for more details.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License
|
|
21 along with DeSmuME; if not, write to the Free Software
|
|
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24
|
|
25 #ifndef GPU_H
|
|
26 #define GPU_H
|
|
27
|
|
28 #include "ARM9.h"
|
|
29 #include <stdio.h>
|
|
30 #include "mem.h"
|
|
31 #include "registers.h"
|
|
32 #include "FIFO.h"
|
|
33 #include "MMU.h"
|
|
34
|
|
35 #ifdef __cplusplus
|
|
36 extern "C" {
|
|
37 #endif
|
|
38
|
|
39
|
|
40 /*******************************************************************************
|
|
41 this structure is for display control,
|
|
42 it holds flags for general display
|
|
43 *******************************************************************************/
|
|
44
|
|
45 #ifdef WORDS_BIGENDIAN
|
|
46 struct _DISPCNT
|
|
47 {
|
|
48 /* 7*/ u8 ForceBlank:1; // A+B:
|
|
49 /* 6*/ u8 OBJ_BMP_mapping:1; // A+B: 0=2D (128KB), 1=1D (128..256KB)
|
|
50 /* 5*/ u8 OBJ_BMP_2D_dim:1; // A+B: 0=128x512, 1=256x256 pixels
|
|
51 /* 4*/ u8 OBJ_Tile_1D:1; // A+B: 0=2D (32KB), 1=1D (32..256KB)
|
|
52 /* 3*/ u8 BG0_3D:1; // A : 0=2D, 1=3D
|
|
53 /* 0*/ u8 BG_Mode:3; // A+B:
|
|
54 /*15*/ u8 WinOBJ_Enable:1; // A+B: 0=disable, 1=Enable
|
|
55 /*14*/ u8 Win1_Enable:1; // A+B: 0=disable, 1=Enable
|
|
56 /*13*/ u8 Win0_Enable:1; // A+B: 0=disable, 1=Enable
|
|
57 /*12*/ u8 OBJ_Enable:1; // A+B: 0=disable, 1=Enable
|
|
58 /*11*/ u8 BG3_Enable:1; // A+B: 0=disable, 1=Enable
|
|
59 /*10*/ u8 BG2_Enable:1; // A+B: 0=disable, 1=Enable
|
|
60 /* 9*/ u8 BG1_Enable:1; // A+B: 0=disable, 1=Enable
|
|
61 /* 8*/ u8 BG0_Enable:1; // A+B: 0=disable, 1=Enable
|
|
62 /*23*/ u8 OBJ_HBlank_process:1; // A+B: OBJ processed during HBlank (GBA bit5)
|
|
63 /*22*/ u8 OBJ_BMP_1D_Bound:1; // A :
|
|
64 /*20*/ u8 OBJ_Tile_1D_Bound:2; // A+B:
|
|
65 /*18*/ u8 VRAM_Block:2; // A : VRAM block (0..3=A..D)
|
|
66
|
|
67 /*16*/ u8 DisplayMode:2; // A+B: coreA(0..3) coreB(0..1) GBA(Green Swap)
|
|
68 // 0=off (white screen)
|
|
69 // 1=on (normal BG & OBJ layers)
|
|
70 // 2=VRAM display (coreA only)
|
|
71 // 3=RAM display (coreA only, DMA transfers)
|
|
72
|
|
73 /*31*/ u8 ExOBJPalette_Enable:1; // A+B: 0=disable, 1=Enable OBJ extended Palette
|
|
74 /*30*/ u8 ExBGxPalette_Enable:1; // A+B: 0=disable, 1=Enable BG extended Palette
|
|
75 /*27*/ u8 ScreenBase_Block:3; // A : Screen Base (64K step)
|
|
76 /*24*/ u8 CharacBase_Block:3; // A : Character Base (64K step)
|
|
77 };
|
|
78 #else
|
|
79 struct _DISPCNT
|
|
80 {
|
|
81 /* 0*/ u8 BG_Mode:3; // A+B:
|
|
82 /* 3*/ u8 BG0_3D:1; // A : 0=2D, 1=3D
|
|
83 /* 4*/ u8 OBJ_Tile_1D:1; // A+B: 0=2D (32KB), 1=1D (32..256KB)
|
|
84 /* 5*/ u8 OBJ_BMP_2D_dim:1; // A+B: 0=128x512, 1=256x256 pixels
|
|
85 /* 6*/ u8 OBJ_BMP_mapping:1; // A+B: 0=2D (128KB), 1=1D (128..256KB)
|
|
86
|
|
87 // 7-15 same as GBA
|
|
88 /* 7*/ u8 ForceBlank:1; // A+B:
|
|
89 /* 8*/ u8 BG0_Enable:1; // A+B: 0=disable, 1=Enable
|
|
90 /* 9*/ u8 BG1_Enable:1; // A+B: 0=disable, 1=Enable
|
|
91 /*10*/ u8 BG2_Enable:1; // A+B: 0=disable, 1=Enable
|
|
92 /*11*/ u8 BG3_Enable:1; // A+B: 0=disable, 1=Enable
|
|
93 /*12*/ u8 OBJ_Enable:1; // A+B: 0=disable, 1=Enable
|
|
94 /*13*/ u8 Win0_Enable:1; // A+B: 0=disable, 1=Enable
|
|
95 /*14*/ u8 Win1_Enable:1; // A+B: 0=disable, 1=Enable
|
|
96 /*15*/ u8 WinOBJ_Enable:1; // A+B: 0=disable, 1=Enable
|
|
97
|
|
98 /*16*/ u8 DisplayMode:2; // A+B: coreA(0..3) coreB(0..1) GBA(Green Swap)
|
|
99 // 0=off (white screen)
|
|
100 // 1=on (normal BG & OBJ layers)
|
|
101 // 2=VRAM display (coreA only)
|
|
102 // 3=RAM display (coreA only, DMA transfers)
|
|
103
|
|
104 /*18*/ u8 VRAM_Block:2; // A : VRAM block (0..3=A..D)
|
|
105 /*20*/ u8 OBJ_Tile_1D_Bound:2; // A+B:
|
|
106 /*22*/ u8 OBJ_BMP_1D_Bound:1; // A :
|
|
107 /*23*/ u8 OBJ_HBlank_process:1; // A+B: OBJ processed during HBlank (GBA bit5)
|
|
108 /*24*/ u8 CharacBase_Block:3; // A : Character Base (64K step)
|
|
109 /*27*/ u8 ScreenBase_Block:3; // A : Screen Base (64K step)
|
|
110 /*30*/ u8 ExBGxPalette_Enable:1; // A+B: 0=disable, 1=Enable BG extended Palette
|
|
111 /*31*/ u8 ExOBJPalette_Enable:1; // A+B: 0=disable, 1=Enable OBJ extended Palette
|
|
112 };
|
|
113 #endif
|
|
114
|
|
115 typedef union
|
|
116 {
|
|
117 struct _DISPCNT bits;
|
|
118 u32 val;
|
|
119 } DISPCNT;
|
|
120 #define BGxENABLED(cnt,num) ((num<8)? ((cnt.val>>8) & num):0)
|
|
121
|
|
122
|
|
123
|
|
124
|
|
125 /*******************************************************************************
|
|
126 this structure is for display control of a specific layer,
|
|
127 there are 4 background layers
|
|
128 their priority indicate which one to draw on top of the other
|
|
129 some flags indicate special drawing mode, size, FX
|
|
130 *******************************************************************************/
|
|
131
|
|
132 #ifdef WORDS_BIGENDIAN
|
|
133 struct _BGxCNT
|
|
134 {
|
|
135 /* 7*/ u8 Palette_256:1; // 0=16x16, 1=1*256 palette
|
|
136 /* 6*/ u8 Mosaic_Enable:1; // 0=disable, 1=Enable mosaic
|
|
137 /* 2*/ u8 CharacBase_Block:4; // individual character base offset (n*16KB)
|
|
138 /* 0*/ u8 Priority:2; // 0..3=high..low
|
|
139 /*14*/ u8 ScreenSize:2; // text : 256x256 512x256 256x512 512x512
|
|
140 // x/rot/s : 128x128 256x256 512x512 1024x1024
|
|
141 // bmp : 128x128 256x256 512x256 512x512
|
|
142 // large : 512x1024 1024x512 - -
|
|
143 /*13*/ u8 PaletteSet_Wrap:1; // BG0 extended palette set 0=set0, 1=set2
|
|
144 // BG1 extended palette set 0=set1, 1=set3
|
|
145 // BG2 overflow area wraparound 0=off, 1=wrap
|
|
146 // BG3 overflow area wraparound 0=off, 1=wrap
|
|
147 /* 8*/ u8 ScreenBase_Block:5; // individual screen base offset (text n*2KB, BMP n*16KB)
|
|
148 };
|
|
149 #else
|
|
150 struct _BGxCNT
|
|
151 {
|
|
152 /* 0*/ u8 Priority:2; // 0..3=high..low
|
|
153 /* 2*/ u8 CharacBase_Block:4; // individual character base offset (n*16KB)
|
|
154 /* 6*/ u8 Mosaic_Enable:1; // 0=disable, 1=Enable mosaic
|
|
155 /* 7*/ u8 Palette_256:1; // 0=16x16, 1=1*256 palette
|
|
156 /* 8*/ u8 ScreenBase_Block:5; // individual screen base offset (text n*2KB, BMP n*16KB)
|
|
157 /*13*/ u8 PaletteSet_Wrap:1; // BG0 extended palette set 0=set0, 1=set2
|
|
158 // BG1 extended palette set 0=set1, 1=set3
|
|
159 // BG2 overflow area wraparound 0=off, 1=wrap
|
|
160 // BG3 overflow area wraparound 0=off, 1=wrap
|
|
161 /*14*/ u8 ScreenSize:2; // text : 256x256 512x256 256x512 512x512
|
|
162 // x/rot/s : 128x128 256x256 512x512 1024x1024
|
|
163 // bmp : 128x128 256x256 512x256 512x512
|
|
164 // large : 512x1024 1024x512 - -
|
|
165 };
|
|
166 #endif
|
|
167
|
|
168
|
|
169 typedef union
|
|
170 {
|
|
171 struct _BGxCNT bits;
|
|
172 u16 val;
|
|
173 } BGxCNT;
|
|
174
|
|
175 /*******************************************************************************
|
|
176 this structure is for background offset
|
|
177 *******************************************************************************/
|
|
178
|
|
179 typedef struct {
|
|
180 u16 BGxHOFS;
|
|
181 u16 BGxVOFS;
|
|
182 } BGxOFS;
|
|
183
|
|
184 /*******************************************************************************
|
|
185 this structure is for rotoscale parameters
|
|
186 *******************************************************************************/
|
|
187
|
|
188 typedef struct {
|
|
189 s16 BGxPA;
|
|
190 s16 BGxPB;
|
|
191 s16 BGxPC;
|
|
192 s16 BGxPD;
|
|
193 s32 BGxX;
|
|
194 s32 BGxY;
|
|
195 } BGxPARMS;
|
|
196
|
|
197
|
|
198 /*******************************************************************************
|
|
199 these structures are for window description,
|
|
200 windows are square regions and can "subclass"
|
|
201 background layers or object layers (i.e window controls the layers)
|
|
202
|
|
203 screen
|
|
204 |
|
|
205 +-- Window0/Window1/OBJwindow/OutOfWindows
|
|
206 |
|
|
207 +-- BG0/BG1/BG2/BG3/OBJ
|
|
208 *******************************************************************************/
|
|
209
|
|
210 typedef union {
|
|
211 struct {
|
|
212 u8 end:8;
|
|
213 u8 start:8;
|
|
214 } bits ;
|
|
215 u16 val;
|
|
216 } WINxDIM;
|
|
217
|
|
218 #ifdef WORDS_BIGENDIAN
|
|
219 typedef struct {
|
|
220 /* 6*/ u8 :2;
|
|
221 /* 5*/ u8 WINx_Effect_Enable:1;
|
|
222 /* 4*/ u8 WINx_OBJ_Enable:1;
|
|
223 /* 3*/ u8 WINx_BG3_Enable:1;
|
|
224 /* 2*/ u8 WINx_BG2_Enable:1;
|
|
225 /* 1*/ u8 WINx_BG1_Enable:1;
|
|
226 /* 0*/ u8 WINx_BG0_Enable:1;
|
|
227 } WINxBIT;
|
|
228 #else
|
|
229 typedef struct {
|
|
230 /* 0*/ u8 WINx_BG0_Enable:1;
|
|
231 /* 1*/ u8 WINx_BG1_Enable:1;
|
|
232 /* 2*/ u8 WINx_BG2_Enable:1;
|
|
233 /* 3*/ u8 WINx_BG3_Enable:1;
|
|
234 /* 4*/ u8 WINx_OBJ_Enable:1;
|
|
235 /* 5*/ u8 WINx_Effect_Enable:1;
|
|
236 /* 6*/ u8 :2;
|
|
237 } WINxBIT;
|
|
238 #endif
|
|
239
|
|
240 #ifdef WORDS_BIGENDIAN
|
|
241 typedef union {
|
|
242 struct {
|
|
243 WINxBIT win0;
|
|
244 WINxBIT win1;
|
|
245 } bits;
|
|
246 struct {
|
|
247 u8 :3;
|
|
248 u8 win0_en:5;
|
|
249 u8 :3;
|
|
250 u8 win1_en:5;
|
|
251 } packed_bits;
|
|
252 struct {
|
|
253 u8 low;
|
|
254 u8 high;
|
|
255 } bytes;
|
|
256 u16 val ;
|
|
257 } WINxCNT ;
|
|
258 #else
|
|
259 typedef union {
|
|
260 struct {
|
|
261 WINxBIT win0;
|
|
262 WINxBIT win1;
|
|
263 } bits;
|
|
264 struct {
|
|
265 u8 win0_en:5;
|
|
266 u8 :3;
|
|
267 u8 win1_en:5;
|
|
268 u8 :3;
|
|
269 } packed_bits;
|
|
270 struct {
|
|
271 u8 low;
|
|
272 u8 high;
|
|
273 } bytes;
|
|
274 u16 val ;
|
|
275 } WINxCNT ;
|
|
276 #endif
|
|
277
|
|
278 /*
|
|
279 typedef struct {
|
|
280 WINxDIM WIN0H;
|
|
281 WINxDIM WIN1H;
|
|
282 WINxDIM WIN0V;
|
|
283 WINxDIM WIN1V;
|
|
284 WINxCNT WININ;
|
|
285 WINxCNT WINOUT;
|
|
286 } WINCNT;
|
|
287 */
|
|
288
|
|
289 /*******************************************************************************
|
|
290 this structure is for miscellanous settings
|
|
291 //TODO: needs further description
|
|
292 *******************************************************************************/
|
|
293
|
|
294 typedef struct {
|
|
295 u16 MOSAIC;
|
|
296 u16 unused1;
|
|
297 u16 unused2;//BLDCNT;
|
|
298 u16 unused3;//BLDALPHA;
|
|
299 u16 unused4;//BLDY;
|
|
300 u16 unused5;
|
|
301 /*
|
|
302 u16 unused6;
|
|
303 u16 unused7;
|
|
304 u16 unused8;
|
|
305 u16 unused9;
|
|
306 */
|
|
307 } MISCCNT;
|
|
308
|
|
309
|
|
310 /*******************************************************************************
|
|
311 this structure is for 3D settings
|
|
312 *******************************************************************************/
|
|
313
|
|
314 struct _DISP3DCNT
|
|
315 {
|
|
316 /* 0*/ u8 EnableTexMapping:1; //
|
|
317 /* 1*/ u8 PolygonShading:1; // 0=Toon Shading, 1=Highlight Shading
|
|
318 /* 2*/ u8 EnableAlphaTest:1; // see ALPHA_TEST_REF
|
|
319 /* 3*/ u8 EnableAlphaBlending:1; // see various Alpha values
|
|
320 /* 4*/ u8 EnableAntiAliasing:1; //
|
|
321 /* 5*/ u8 EnableEdgeMarking:1; // see EDGE_COLOR
|
|
322 /* 6*/ u8 FogOnlyAlpha:1; // 0=Alpha and Color, 1=Only Alpha (see FOG_COLOR)
|
|
323 /* 7*/ u8 EnableFog:1; // Fog Master Enable
|
|
324 /* 8*/ u8 FogShiftSHR:4; // 0..10 SHR-Divider (see FOG_OFFSET)
|
|
325 /*12*/ u8 AckColorBufferUnderflow:1; // Color Buffer RDLINES Underflow (0=None, 1=Underflow/Acknowledge)
|
|
326 /*13*/ u8 AckVertexRAMOverflow:1; // Polygon/Vertex RAM Overflow (0=None, 1=Overflow/Acknowledge)
|
|
327 /*14*/ u8 RearPlaneMode:1; // 0=Blank, 1=Bitmap
|
|
328 /*15*/ u8 :1;
|
|
329 /*16*/ u16 :16;
|
|
330 };
|
|
331
|
|
332 typedef union
|
|
333 {
|
|
334 struct _DISP3DCNT bits;
|
|
335 u32 val;
|
|
336 } DISP3DCNT;
|
|
337
|
|
338 /*******************************************************************************
|
|
339 this structure is for capture control (core A only)
|
|
340
|
|
341 source:
|
|
342 http://nocash.emubase.de/gbatek.htm#dsvideocaptureandmainmemorydisplaymode
|
|
343 *******************************************************************************/
|
|
344
|
|
345 struct _DISPCAPCNT
|
|
346 {
|
|
347 /* 0*/ u8 BlendFactor_A:5; // 0..16 = Blending Factor for Source A
|
|
348 /* 5*/ u8 :3; //
|
|
349 /* 8*/ u8 BlendFactor_B:5; // 0..16 = Blending Factor for Source B
|
|
350 /*13*/ u8 :3; //
|
|
351 /*16*/ u8 VRAM_Write_Block:2; // 0..3 = VRAM A..D
|
|
352 /*18*/ u8 VRAM_Write_Offset:2; // n x 0x08000
|
|
353 /*20*/ u8 Capture_Size:2; // 0=128x128, 1=256x64, 2=256x128, 3=256x192 dots
|
|
354 /*22*/ u8 :2; //
|
|
355 /*24*/ u8 Source_A:1; // 0=Graphics Screen BG+3D+OBJ, 1=3D Screen
|
|
356 /*25*/ u8 Source_B:1; // 0=VRAM, 1=Main Memory Display FIFO
|
|
357 /*26*/ u8 VRAM_Read_Offset:2; // n x 0x08000
|
|
358 /*28*/ u8 :1; //
|
|
359 /*29*/ u8 Capture_Source:2; // 0=Source A, 1=Source B, 2/3=Sources A+B blended
|
|
360 /*31*/ u8 Capture_Enable:1; // 0=Disable/Ready, 1=Enable/Busy
|
|
361 };
|
|
362
|
|
363 typedef union
|
|
364 {
|
|
365 struct _DISPCAPCNT bits;
|
|
366 u32 val;
|
|
367 } DISPCAPCNT;
|
|
368
|
|
369
|
|
370 /*******************************************************************************
|
|
371 this structure holds everything and should be mapped to
|
|
372 * core A : 0x04000000
|
|
373 * core B : 0x04001000
|
|
374 *******************************************************************************/
|
|
375
|
|
376 typedef struct _reg_dispx {
|
|
377 DISPCNT dispx_DISPCNT; // 0x0400x000
|
|
378 u16 dispA_DISPSTAT; // 0x04000004
|
|
379 u16 dispx_VCOUNT; // 0x0400x006
|
|
380 BGxCNT dispx_BGxCNT[4]; // 0x0400x008
|
|
381 BGxOFS dispx_BGxOFS[4]; // 0x0400x010
|
|
382 BGxPARMS dispx_BG2PARMS; // 0x0400x020
|
|
383 BGxPARMS dispx_BG3PARMS; // 0x0400x030
|
|
384 u8 filler[12]; // 0x0400x040
|
|
385 MISCCNT dispx_MISC; // 0x0400x04C
|
|
386 DISP3DCNT dispA_DISP3DCNT; // 0x04000060
|
|
387 DISPCAPCNT dispA_DISPCAPCNT; // 0x04000064
|
|
388 u32 dispA_DISPMMEMFIFO; // 0x04000068
|
|
389 } REG_DISPx ;
|
|
390
|
|
391
|
|
392
|
|
393
|
|
394
|
|
395
|
|
396
|
|
397
|
|
398 #ifndef min
|
|
399 #define min(a,b) (((a)<(b))?(a):(b))
|
|
400 #endif
|
|
401
|
|
402 #ifndef max
|
|
403 #define max(a,b) (((a)>(b))?(a):(b))
|
|
404 #endif
|
|
405
|
|
406 typedef BOOL (*fun_gl_Begin) (int screen);
|
|
407 typedef void (*fun_gl_End) (int screen);
|
|
408 // the GUI should use this function prior to all gl calls
|
|
409 // if call to beg succeeds opengl draw
|
|
410 void register_gl_fun(fun_gl_Begin beg,fun_gl_End end);
|
|
411
|
|
412 #define GPU_MAIN 0
|
|
413 #define GPU_SUB 1
|
|
414
|
|
415 /* human readable bitmask names */
|
|
416 #define ADDRESS_STEP_512B 0x00200
|
|
417 #define ADDRESS_STEP_1KB 0x00400
|
|
418 #define ADDRESS_STEP_2KB 0x00800
|
|
419 #define ADDRESS_STEP_4KB 0x01000
|
|
420 #define ADDRESS_STEP_8KB 0x02000
|
|
421 #define ADDRESS_STEP_16KB 0x04000
|
|
422 #define ADDRESS_STEP_32KB 0x08000
|
|
423 #define ADDRESS_STEP_64kB 0x10000
|
|
424
|
|
425 #ifdef WORDS_BIGENDIAN
|
|
426 struct _TILEENTRY
|
|
427 {
|
|
428 /*14*/ unsigned Palette:4;
|
|
429 /*13*/ unsigned VFlip:1; // VERTICAL FLIP (top<-->bottom)
|
|
430 /*12*/ unsigned HFlip:1; // HORIZONTAL FLIP (left<-->right)
|
|
431 /* 0*/ unsigned TileNum:10;
|
|
432 };
|
|
433 #else
|
|
434 struct _TILEENTRY
|
|
435 {
|
|
436 /* 0*/ unsigned TileNum:10;
|
|
437 /*12*/ unsigned HFlip:1; // HORIZONTAL FLIP (left<-->right)
|
|
438 /*13*/ unsigned VFlip:1; // VERTICAL FLIP (top<-->bottom)
|
|
439 /*14*/ unsigned Palette:4;
|
|
440 };
|
|
441 #endif
|
|
442 typedef union
|
|
443 {
|
|
444 struct _TILEENTRY bits;
|
|
445 u16 val;
|
|
446 } TILEENTRY;
|
|
447
|
|
448 struct _ROTOCOORD
|
|
449 {
|
|
450 /* 0*/ unsigned Fraction:8;
|
|
451 /* 8*/ signed Integer:24;
|
|
452 // /*28*/ unsigned :4;
|
|
453 };
|
|
454 typedef union
|
|
455 {
|
|
456 struct _ROTOCOORD bits;
|
|
457 s32 val;
|
|
458 } ROTOCOORD;
|
|
459
|
|
460
|
|
461 /*
|
|
462 this structure is for color representation,
|
|
463 it holds 5 meaningful bits per color channel (red,green,blue)
|
|
464 and 1 meaningful bit for alpha representation
|
|
465 this bit can be unused or used for special FX
|
|
466 */
|
|
467
|
|
468 struct _COLOR { // abgr x555
|
|
469 #ifdef WORDS_BIGENDIAN
|
|
470 unsigned alpha:1; // sometimes it is unused (pad)
|
|
471 unsigned blue:5;
|
|
472 unsigned green:5;
|
|
473 unsigned red:5;
|
|
474 #else
|
|
475 unsigned red:5;
|
|
476 unsigned green:5;
|
|
477 unsigned blue:5;
|
|
478 unsigned alpha:1; // sometimes it is unused (pad)
|
|
479 #endif
|
|
480 };
|
|
481 struct _COLORx { // abgr x555
|
|
482 unsigned bgr:15;
|
|
483 unsigned alpha:1; // sometimes it is unused (pad)
|
|
484 };
|
|
485
|
|
486 typedef union
|
|
487 {
|
|
488 struct _COLOR bits;
|
|
489 struct _COLORx bitx;
|
|
490 u16 val;
|
|
491 } COLOR;
|
|
492
|
|
493 struct _COLOR32 { // ARGB
|
|
494 unsigned :3;
|
|
495 unsigned blue:5;
|
|
496 unsigned :3;
|
|
497 unsigned green:5;
|
|
498 unsigned :3;
|
|
499 unsigned red:5;
|
|
500 unsigned :7;
|
|
501 unsigned alpha:1; // sometimes it is unused (pad)
|
|
502 };
|
|
503
|
|
504 typedef union
|
|
505 {
|
|
506 struct _COLOR32 bits;
|
|
507 u32 val;
|
|
508 } COLOR32;
|
|
509
|
|
510 #define COLOR_16_32(w,i) \
|
|
511 /* doesnt matter who's 16bit who's 32bit */ \
|
|
512 i.bits.red = w.bits.red; \
|
|
513 i.bits.green = w.bits.green; \
|
|
514 i.bits.blue = w.bits.blue; \
|
|
515 i.bits.alpha = w.bits.alpha;
|
|
516
|
|
517
|
|
518
|
|
519
|
|
520
|
|
521
|
|
522 /*
|
|
523 this structure is for Sprite description,
|
|
524 it holds flags & transformations for 1 sprite
|
|
525 (max 128 OBJs / screen)
|
|
526 ref: http://www.bottledlight.com/ds/index.php/Video/Sprites
|
|
527 */
|
|
528
|
|
529 typedef struct
|
|
530 {
|
|
531 #ifdef WORDS_BIGENDIAN
|
|
532 // attr0
|
|
533 /* 0*/ unsigned Y:8;
|
|
534 /*14*/ unsigned Shape:2; // (00: Square, 01: Wide, 10: Tall, 11: Illegal)
|
|
535 /*13*/ unsigned Depth:1; // (0: 16, 1: 256)
|
|
536 /*12*/ unsigned Mosaic:1; // (1: Enabled)
|
|
537 /*10*/ unsigned Mode:2; // (00: Normal, 01: Transparent, 10: Object window, 11: Bitmap)
|
|
538 /* 8*/ unsigned RotScale:2; // (00: Normal, 01: Rot/scale, 10: Disabled, 11: Double-size rot/scale)
|
|
539 // attr1
|
|
540 /* 0*/ signed X:9;
|
|
541 /*14*/ unsigned Size:2;
|
|
542 /*13*/ unsigned VFlip:1;
|
|
543 /*12*/ unsigned HFlip:1;
|
|
544 /* 9*/ unsigned RotScalIndex:3; // Rot/scale matrix index
|
|
545 // attr2
|
|
546 /* 0*/ unsigned TileIndex:10;
|
|
547 /*12*/ unsigned PaletteIndex:4;
|
|
548 /*10*/ unsigned Priority:2;
|
|
549 // attr3
|
|
550 unsigned attr3:16;
|
|
551 #else
|
|
552 // attr0
|
|
553 /* 0*/ unsigned Y:8;
|
|
554 /* 8*/ unsigned RotScale:2; // (00: Normal, 01: Rot/scale, 10: Disabled, 11: Double-size rot/scale)
|
|
555 /*10*/ unsigned Mode:2; // (00: Normal, 01: Transparent, 10: Object window, 11: Bitmap)
|
|
556 /*12*/ unsigned Mosaic:1; // (1: Enabled)
|
|
557 /*13*/ unsigned Depth:1; // (0: 16, 1: 256)
|
|
558 /*14*/ unsigned Shape:2; // (00: Square, 01: Wide, 10: Tall, 11: Illegal)
|
|
559 // attr1
|
|
560 /* 0*/ signed X:9;
|
|
561 /* 9*/ unsigned RotScalIndex:3; // Rot/scale matrix index
|
|
562 /*12*/ unsigned HFlip:1;
|
|
563 /*13*/ unsigned VFlip:1;
|
|
564 /*14*/ unsigned Size:2;
|
|
565 // attr2
|
|
566 /* 0*/ unsigned TileIndex:10;
|
|
567 /*10*/ unsigned Priority:2;
|
|
568 /*12*/ unsigned PaletteIndex:4;
|
|
569 // attr3
|
|
570 unsigned attr3:16;
|
|
571 #endif
|
|
572 } _OAM_;
|
|
573
|
|
574 typedef struct
|
|
575 {
|
|
576 u16 attr0;
|
|
577 u16 attr1;
|
|
578 u16 attr2;
|
|
579 u16 attr3;
|
|
580 } OAM;
|
|
581
|
|
582
|
|
583
|
|
584 typedef struct
|
|
585 {
|
|
586 s16 x;
|
|
587 s16 y;
|
|
588 } size;
|
|
589
|
|
590
|
|
591
|
|
592
|
|
593 /*
|
|
594 this structure holds information
|
|
595 for rendering.
|
|
596 */
|
|
597
|
|
598 #define NB_PRIORITIES 4
|
|
599 #define NB_BG 4
|
|
600 typedef struct
|
|
601 {
|
|
602 u8 BGs[NB_BG], nbBGs;
|
|
603 u8 PixelsX[256];
|
|
604 // doh ! yoda says : 256 pixels we can have...
|
|
605 u16 nbPixelsX;
|
|
606 } itemsForPriority_t;
|
|
607
|
|
608
|
|
609 typedef struct _GPU GPU;
|
|
610
|
|
611 struct _GPU
|
|
612 {
|
|
613 // some structs are becoming redundant
|
|
614 // some functions too (no need to recopy some vars as it is done by MMU)
|
|
615 REG_DISPx * dispx_st;
|
|
616
|
|
617 DISPCAPCNT dispCapCnt;
|
|
618 BOOL LayersEnable[5];
|
|
619 itemsForPriority_t itemsForPriority[NB_PRIORITIES];
|
|
620 u8 sprWin[256][256];
|
|
621
|
|
622 #define BGBmpBB BG_bmp_ram
|
|
623 #define BGChBB BG_tile_ram
|
|
624
|
|
625 u8 *(BG_bmp_ram[4]);
|
|
626 u8 *(BG_tile_ram[4]);
|
|
627 u8 *(BG_map_ram[4]);
|
|
628
|
|
629 u8 BGExtPalSlot[4];
|
|
630 u32 BGSize[4][2];
|
|
631
|
|
632 u8 lcd;
|
|
633 u8 core;
|
|
634
|
|
635 u8 dispMode;
|
|
636 u8 vramBlock;
|
|
637
|
|
638 BOOL dispBG[4];
|
|
639 BOOL dispOBJ;
|
|
640
|
|
641 OAM * oam;
|
|
642 u8 * sprMem;
|
|
643 u8 sprBoundary;
|
|
644 u8 sprBMPBoundary;
|
|
645 u8 sprBMPMode;
|
|
646 u32 sprEnable;
|
|
647
|
|
648 u8 WIN0H0;
|
|
649 u8 WIN0H1;
|
|
650 u8 WIN0V0;
|
|
651 u8 WIN0V1;
|
|
652
|
|
653 u8 WIN1H0;
|
|
654 u8 WIN1H1;
|
|
655 u8 WIN1V0;
|
|
656 u8 WIN1V1;
|
|
657
|
|
658 u8 WININ0;
|
|
659 u8 WININ0_SPECIAL;
|
|
660 u8 WININ1;
|
|
661 u8 WININ1_SPECIAL;
|
|
662
|
|
663 u8 WINOUT;
|
|
664 u8 WINOUT_SPECIAL;
|
|
665 u8 WINOBJ;
|
|
666 u8 WINOBJ_SPECIAL;
|
|
667
|
|
668 u8 WIN0_ENABLED;
|
|
669 u8 WIN1_ENABLED;
|
|
670 u8 WINOBJ_ENABLED;
|
|
671
|
|
672 u16 BLDCNT;
|
|
673 u8 BLDALPHA_EVA;
|
|
674 u8 BLDALPHA_EVB;
|
|
675 u8 BLDY_EVY;
|
|
676
|
|
677 u8 MasterBrightMode;
|
|
678 u32 MasterBrightFactor;
|
|
679
|
|
680 BOOL (*setFinalColorSpr)(const GPU *gpu, u32 passing, u8 bgnum, u8 *dst, u16 color, u16 x, u16 y);
|
|
681 BOOL (*setFinalColorBck)(const GPU *gpu, u32 passing, u8 bgnum, u8 *dst, u16 color, u16 x, u16 y);
|
|
682 void (*spriteRender) (GPU * gpu, u16 l, u8 * dst, u8 * prioTab);
|
|
683 };
|
|
684 /*
|
|
685 // normally should have same addresses
|
|
686 static void REG_DISPx_pack_test(GPU * gpu)
|
|
687 {
|
|
688 REG_DISPx * r = gpu->dispx_st;
|
|
689 printf ("%08x %02x\n", r, (long)(&r->dispx_DISPCNT) - (long)r);
|
|
690 printf ("\t%02x\n", (long)(&r->dispA_DISPSTAT) - (long)r);
|
|
691 printf ("\t%02x\n", (long)(&r->dispx_VCOUNT) - (long)r);
|
|
692 printf ("\t%02x\n", (long)(&r->dispx_BGxCNT[0]) - (long)r);
|
|
693 printf ("\t%02x\n", (long)(&r->dispx_BGxOFS[0]) - (long)r);
|
|
694 printf ("\t%02x\n", (long)(&r->dispx_BG2PARMS) - (long)r);
|
|
695 printf ("\t%02x\n", (long)(&r->dispx_BG3PARMS) - (long)r);
|
|
696 printf ("\t%02x\n", (long)(&r->dispx_WINCNT) - (long)r);
|
|
697 printf ("\t%02x\n", (long)(&r->dispx_MISC) - (long)r);
|
|
698 printf ("\t%02x\n", (long)(&r->dispA_DISP3DCNT) - (long)r);
|
|
699 printf ("\t%02x\n", (long)(&r->dispA_DISPCAPCNT) - (long)r);
|
|
700 printf ("\t%02x\n", (long)(&r->dispA_DISPMMEMFIFO) - (long)r);
|
|
701 }
|
|
702 */
|
|
703
|
|
704 extern u8 GPU_screen[4*256*192];
|
|
705
|
|
706
|
|
707 GPU * GPU_Init(u8 l);
|
|
708 void GPU_Reset(GPU *g, u8 l);
|
|
709 void GPU_DeInit(GPU *);
|
|
710
|
|
711 void textBG(const GPU * gpu, u8 num, u8 * DST); //Draw text based background
|
|
712 void rotBG(GPU * gpu, u8 num, u8 * DST);
|
|
713 void extRotBG(GPU * gpu, u8 num, u8 * DST);
|
|
714 void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab);
|
|
715 void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab);
|
|
716
|
|
717 extern short sizeTab[4][4][2];
|
|
718 extern size sprSizeTab[4][4];
|
|
719 extern s8 mode2type[8][4];
|
|
720 extern void (*modeRender[8][4])(GPU * gpu, u8 num, u16 l, u8 * DST);
|
|
721
|
|
722 typedef struct {
|
|
723 GPU * gpu;
|
|
724 u16 offset;
|
|
725 } NDS_Screen;
|
|
726
|
|
727 extern NDS_Screen MainScreen;
|
|
728 extern NDS_Screen SubScreen;
|
|
729
|
|
730 int Screen_Init(int coreid);
|
|
731 void Screen_Reset(void);
|
|
732 void Screen_DeInit(void);
|
|
733
|
|
734 extern MMU_struct MMU;
|
|
735
|
|
736
|
|
737
|
|
738 #define GFXCORE_DEFAULT -1
|
|
739 #define GFXCORE_DUMMY 0
|
|
740
|
|
741 #define GFXCORE_FULLSCREEN (1 << 0)
|
|
742
|
|
743 typedef struct
|
|
744 {
|
|
745 int id; // ID number for core(see above defines)
|
|
746 const char *Name; // Name of core
|
|
747 int flags; // What features the core supports(full screen, etc.)
|
|
748 int (*Init)(); // Initializes stuff related to core
|
|
749 void (*DeInit)(); // Deinitializes stuff related to core
|
|
750 void (*Resize)(int width, int height, BOOL fullscreen); // Resizes window or fullscreen
|
|
751 void (*OnScreenText)(char *string, ...); // For handling save state messages, etc.
|
|
752 } GraphicsInterface_struct;
|
|
753
|
|
754 extern GraphicsInterface_struct GFXDummy;
|
|
755
|
|
756 void GPU_setVideoProp(GPU *, u32 p);
|
|
757 void GPU_setBGProp(GPU *, u16 num, u16 p);
|
|
758
|
|
759 void GPU_setBLDCNT(GPU *gpu, u16 v) ;
|
|
760 void GPU_setBLDALPHA(GPU *gpu, u16 v) ;
|
|
761 void GPU_setBLDY(GPU *gpu, u16 v) ;
|
|
762 void GPU_setMOSAIC(GPU *gpu, u16 v) ;
|
|
763
|
|
764
|
|
765 void GPU_remove(GPU *, u8 num);
|
|
766 void GPU_addBack(GPU *, u8 num);
|
|
767
|
|
768 int GPU_ChangeGraphicsCore(int coreid);
|
|
769
|
|
770 void GPU_set_DISPCAPCNT(GPU * gpu, u32 val) ;
|
|
771 void GPU_ligne(NDS_Screen * screen, u16 l) ;
|
|
772 void GPU_setMasterBrightness (GPU *gpu, u16 val);
|
|
773
|
|
774 void GPU_setWIN0_H (GPU *gpu, u16 val);
|
|
775 void GPU_setWIN0_H0 (GPU *gpu, u8 val);
|
|
776 void GPU_setWIN0_H1 (GPU *gpu, u8 val);
|
|
777
|
|
778 void GPU_setWIN0_V (GPU *gpu, u16 val);
|
|
779 void GPU_setWIN0_V0 (GPU *gpu, u8 val);
|
|
780 void GPU_setWIN0_V1 (GPU *gpu, u8 val);
|
|
781
|
|
782 void GPU_setWIN1_H (GPU *gpu, u16 val);
|
|
783 void GPU_setWIN1_H0 (GPU *gpu, u8 val);
|
|
784 void GPU_setWIN1_H1 (GPU *gpu, u8 val);
|
|
785
|
|
786 void GPU_setWIN1_V (GPU *gpu, u16 val);
|
|
787 void GPU_setWIN1_V0 (GPU *gpu, u8 val);
|
|
788 void GPU_setWIN1_V1 (GPU *gpu, u8 val);
|
|
789
|
|
790 void GPU_setWININ (GPU *gpu, u16 val);
|
|
791 void GPU_setWININ0 (GPU *gpu, u8 val);
|
|
792 void GPU_setWININ1 (GPU *gpu, u8 val);
|
|
793
|
|
794 void GPU_setWINOUT16(GPU *gpu, u16 val);
|
|
795 void GPU_setWINOUT (GPU *gpu, u8 val);
|
|
796 void GPU_setWINOBJ (GPU *gpu, u8 val);
|
|
797
|
|
798 void GPU_setBLDCNT_LOW (GPU *gpu, u8 val);
|
|
799 void GPU_setBLDCNT_HIGH (GPU *gpu, u8 val);
|
|
800 void GPU_setBLDCNT (GPU *gpu, u16 val);
|
|
801
|
|
802 void GPU_setBLDALPHA (GPU *gpu, u16 val);
|
|
803 void GPU_setBLDALPHA_EVA(GPU *gpu, u8 val);
|
|
804 void GPU_setBLDALPHA_EVB(GPU *gpu, u8 val);
|
|
805
|
|
806 void GPU_setBLDY_EVY (GPU *gpu, u8 val);
|
|
807
|
|
808 #ifdef __cplusplus
|
|
809 }
|
|
810 #endif
|
|
811
|
|
812 #endif
|
|
813
|