19 Sam Lantinga |
19 Sam Lantinga |
20 slouken@libsdl.org |
20 slouken@libsdl.org |
21 */ |
21 */ |
22 #include "SDL_config.h" |
22 #include "SDL_config.h" |
23 |
23 |
24 /* Dummy SDL video driver implementation; this is just enough to make an |
24 /* SDL Nintendo DS video driver implementation |
25 * SDL-based application THINK it's got a working video driver, for |
25 * based on dummy driver: |
26 * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it, |
|
27 * and also for use as a collection of stubs when porting SDL to a new |
|
28 * platform for which you haven't yet written a valid video driver. |
|
29 * |
|
30 * This is also a great way to determine bottlenecks: if you think that SDL |
|
31 * is a performance problem for a given platform, enable this driver, and |
|
32 * then see if your application runs faster without video overhead. |
|
33 * |
|
34 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion |
26 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion |
35 * of this was cut-and-pasted from Stephane Peter's work in the AAlib |
27 * of this was cut-and-pasted from Stephane Peter's work in the AAlib |
36 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. |
28 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. |
37 */ |
29 */ |
38 |
30 |
39 #include <stdio.h> |
31 #include <stdio.h> |
40 #include <stdlib.h> |
32 #include <stdlib.h> |
41 #include <nds.h> |
33 #include <nds.h> |
|
34 #include <nds/arm9/sprite.h> |
|
35 #include <nds/arm9/trig_lut.h> |
|
36 #include <nds/arm9/video.h> |
42 |
37 |
43 #include "SDL_video.h" |
38 #include "SDL_video.h" |
44 #include "SDL_mouse.h" |
39 #include "SDL_mouse.h" |
45 #include "../SDL_sysvideo.h" |
40 #include "../SDL_sysvideo.h" |
46 #include "../SDL_pixels_c.h" |
41 #include "../SDL_pixels_c.h" |
55 /* Initialization/Query functions */ |
50 /* Initialization/Query functions */ |
56 static int NDS_VideoInit(_THIS); |
51 static int NDS_VideoInit(_THIS); |
57 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); |
52 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); |
58 static void NDS_VideoQuit(_THIS); |
53 static void NDS_VideoQuit(_THIS); |
59 |
54 |
60 /* DUMMY driver bootstrap functions */ |
55 /* NDS sprite-related functions */ |
61 |
56 |
|
57 #define SPRITE_DMA_CHANNEL 3 |
|
58 #define SPRITE_ANGLE_MASK 0x01FF |
|
59 |
|
60 void |
|
61 NDS_OAM_Update(tOAM *oam) |
|
62 { |
|
63 DC_FlushAll(); |
|
64 dmaCopyHalfWords(SPRITE_DMA_CHANNEL, oam->spriteBuffer, OAM, |
|
65 SPRITE_COUNT * sizeof(SpriteEntry)); |
|
66 } |
|
67 |
|
68 void |
|
69 NDS_OAM_RotateSprite(SpriteRotation *spriteRotation, u16 angle) |
|
70 { |
|
71 s16 s = SIN[angle & SPRITE_ANGLE_MASK] >> 4; |
|
72 s16 c = COS[angle & SPRITE_ANGLE_MASK] >> 4; |
|
73 |
|
74 spriteRotation->hdx = c; |
|
75 spriteRotation->hdy = s; |
|
76 spriteRotation->vdx = -s; |
|
77 spriteRotation->vdy = c; |
|
78 } |
|
79 |
|
80 void |
|
81 NDS_OAM_Init(tOAM *oam) |
|
82 { |
|
83 int i; |
|
84 for(i = 0; i < SPRITE_COUNT; i++) { |
|
85 oam->spriteBuffer[i].attribute[0] = ATTR0_DISABLED; |
|
86 oam->spriteBuffer[i].attribute[1] = 0; |
|
87 oam->spriteBuffer[i].attribute[2] = 0; |
|
88 } |
|
89 for(i = 0; i < MATRIX_COUNT; i++) { |
|
90 NDS_OAM_RotateSprite(&(oam->matrixBuffer[i]), 0); |
|
91 } |
|
92 swiWaitForVBlank(); |
|
93 NDS_OAM_Update(oam); |
|
94 } |
|
95 |
|
96 void |
|
97 NDS_OAM_HideSprite(SpriteEntry *spriteEntry) |
|
98 { |
|
99 spriteEntry->isRotoscale = 0; |
|
100 spriteEntry->isHidden = 1; |
|
101 } |
|
102 |
|
103 void |
|
104 NDS_OAM_ShowSprite(SpriteEntry *spriteEntry, int affine, int double_bound) |
|
105 { |
|
106 if (affine) { |
|
107 spriteEntry->isRotoscale = 1; |
|
108 spriteEntry->rsDouble = double_bound; |
|
109 } else { |
|
110 spriteEntry->isHidden = 0; |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 /* SDL NDS driver bootstrap functions */ |
62 static int |
116 static int |
63 NDS_Available(void) |
117 NDS_Available(void) |
64 { |
118 { |
65 const char *envr = SDL_getenv("SDL_VIDEODRIVER"); |
119 /*const char *envr = SDL_getenv("SDL_VIDEODRIVER");*/ |
66 /*printf("NDS_Available()\n"); */ |
120 /*printf("NDS_Available()\n"); */ |
67 return (1); |
121 return (1); |
68 } |
122 } |
69 |
123 |
70 static void |
124 static void |
77 NDS_CreateDevice(int devindex) |
131 NDS_CreateDevice(int devindex) |
78 { |
132 { |
79 SDL_VideoDevice *device; |
133 SDL_VideoDevice *device; |
80 /*printf("NDS_CreateDevice(%d)\n", devindex); */ |
134 /*printf("NDS_CreateDevice(%d)\n", devindex); */ |
81 |
135 |
|
136 printf("+NDS_CreateDevice\n"); |
82 /* Initialize all variables that we clean on shutdown */ |
137 /* Initialize all variables that we clean on shutdown */ |
83 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); |
138 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); |
84 if (!device) { |
139 if (!device) { |
85 SDL_OutOfMemory(); |
140 SDL_OutOfMemory(); |
86 if (device) { |
141 if (device) { |
127 |
184 |
128 SDL_zero(mode); |
185 SDL_zero(mode); |
129 SDL_AddDisplayMode(0, &mode); |
186 SDL_AddDisplayMode(0, &mode); |
130 |
187 |
131 /* hackish stuff to get things up and running for now, and for a console */ |
188 /* hackish stuff to get things up and running for now, and for a console */ |
132 powerON(POWER_ALL); |
189 powerON(POWER_ALL_2D); |
133 irqInit(); |
190 irqInit(); |
134 irqEnable(IRQ_VBLANK); |
191 irqEnable(IRQ_VBLANK); |
135 NDS_SetDisplayMode(_this, &mode); |
192 NDS_SetDisplayMode(_this, &mode); |
|
193 printf("-NDS_VideoInit\n"); |
136 return 0; |
194 return 0; |
137 } |
195 } |
138 |
196 |
139 static int |
197 static int |
140 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) |
198 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) |
141 { |
199 { |
|
200 printf("+NDS_SetDisplayMode\n"); |
142 /* right now this function is just hard-coded for 256x192 ABGR1555 */ |
201 /* right now this function is just hard-coded for 256x192 ABGR1555 */ |
143 videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */ |
202 videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE); /* display on main core */ |
144 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */ |
203 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub */ |
145 vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_LCD, |
204 vramSetMainBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, |
146 VRAM_C_SUB_BG, VRAM_D_LCD); |
205 VRAM_C_SUB_BG_0x06200000, VRAM_C_SUB_BG_0x06220000); |
147 |
206 vramSetBankE(VRAM_E_MAIN_SPRITE); |
148 /* set up console for debug text 'n stuff */ |
207 /* set up console for debug text 'n stuff */ |
149 SUB_BG0_CR = BG_MAP_BASE(31); |
208 SUB_BG0_CR = BG_MAP_BASE(31); |
150 BG_PALETTE_SUB[255] = RGB15(31, 31, 31); |
209 BG_PALETTE_SUB[255] = RGB15(31, 31, 31); |
|
210 /* debugging purposes, uncomment this later. then remove it & add 2screen. |
151 consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31), |
211 consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31), |
152 (u16 *) CHAR_BASE_BLOCK_SUB(0), 16); |
212 (u16 *) CHAR_BASE_BLOCK_SUB(0), 16);*/ |
153 |
213 printf("-NDS_SetDisplayMode\n"); |
154 #if 0 |
|
155 /* we should be using this as a texture for rendering, not as a framebuffer */ |
|
156 /* maps well to the 256x192 screen anyway. note: need VRAM_B for bigger */ |
|
157 BACKGROUND.control[3] = BG_BMP16_256x256; |
|
158 /* affine transformation matrix. nothing too fancy here */ |
|
159 BG3_XDX = 0x100; |
|
160 BG3_XDY = 0; |
|
161 BG3_YDX = 0; |
|
162 BG3_YDY = 0x100; |
|
163 /* x/y position */ |
|
164 BG3_CX = 0; |
|
165 BG3_CY = 0; |
|
166 #endif |
|
167 return 0; |
214 return 0; |
168 } |
215 } |
169 |
216 |
170 void |
217 void |
171 NDS_VideoQuit(_THIS) |
218 NDS_VideoQuit(_THIS) |
172 { |
219 { |
|
220 printf("+NDS_VideoQuit\n"); |
173 videoSetMode(DISPLAY_SCREEN_OFF); |
221 videoSetMode(DISPLAY_SCREEN_OFF); |
174 videoSetModeSub(DISPLAY_SCREEN_OFF); |
222 videoSetModeSub(DISPLAY_SCREEN_OFF); |
175 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); |
223 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); |
|
224 printf("-NDS_VideoQuit\n"); |
176 } |
225 } |
177 |
226 |
178 /* vi: set ts=4 sw=4 expandtab: */ |
227 /* vi: set ts=4 sw=4 expandtab: */ |