comparison src/video/nds/SDL_ndsvideo.c @ 2698:e1da92da346c gsoc2008_nds

Clean up.
author Darren Alton <dalton@stevens.edu>
date Wed, 27 Aug 2008 04:23:38 +0000
parents c04a266c277a
children
comparison
equal deleted inserted replaced
2697:c9121b04cffa 2698:e1da92da346c
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 /* SDL Nintendo DS video driver implementation 24 /* SDL Nintendo DS video driver implementation
25 * based on dummy driver: 25 * based on dummy driver:
26 * 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
27 * 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
28 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga. 28 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
29 */ 29 */
30 30
31 #include <stdio.h> 31 #include <stdio.h>
41 41
42 #include "SDL_ndsvideo.h" 42 #include "SDL_ndsvideo.h"
43 #include "SDL_ndsevents_c.h" 43 #include "SDL_ndsevents_c.h"
44 #include "SDL_ndsrender_c.h" 44 #include "SDL_ndsrender_c.h"
45 45
46
47
48 #define TRACE
49 //#define TRACE printf
50
51
52
53 #define NDSVID_DRIVER_NAME "nds" 46 #define NDSVID_DRIVER_NAME "nds"
54 47
55 /* Initialization/Query functions */ 48 /* Initialization/Query functions */
56 static int NDS_VideoInit(_THIS); 49 static int NDS_VideoInit(_THIS);
57 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode); 50 static int NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
60 53
61 /* SDL NDS driver bootstrap functions */ 54 /* SDL NDS driver bootstrap functions */
62 static int 55 static int
63 NDS_Available(void) 56 NDS_Available(void)
64 { 57 {
65 /*const char *envr = SDL_getenv("SDL_VIDEODRIVER");*/ 58 return (1); /* always here */
66 /*printf("NDS_Available()\n"); */
67 return (1);
68 } 59 }
69 60
70 static void 61 static void
71 NDS_DeleteDevice(SDL_VideoDevice * device) 62 NDS_DeleteDevice(SDL_VideoDevice * device)
72 { 63 {
75 66
76 static SDL_VideoDevice * 67 static SDL_VideoDevice *
77 NDS_CreateDevice(int devindex) 68 NDS_CreateDevice(int devindex)
78 { 69 {
79 SDL_VideoDevice *device; 70 SDL_VideoDevice *device;
80 /*printf("NDS_CreateDevice(%d)\n", devindex); */
81 71
82 TRACE("+NDS_CreateDevice\n");
83 /* Initialize all variables that we clean on shutdown */ 72 /* Initialize all variables that we clean on shutdown */
84 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); 73 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
85 if (!device) { 74 if (!device) {
86 SDL_OutOfMemory(); 75 SDL_OutOfMemory();
87 if (device) { 76 if (device) {
98 87
99 device->num_displays = 2; /* DS = dual screens */ 88 device->num_displays = 2; /* DS = dual screens */
100 89
101 device->free = NDS_DeleteDevice; 90 device->free = NDS_DeleteDevice;
102 91
103 TRACE("-NDS_CreateDevice\n");
104 return device; 92 return device;
105 } 93 }
106 94
107 VideoBootStrap NDS_bootstrap = { 95 VideoBootStrap NDS_bootstrap = {
108 NDSVID_DRIVER_NAME, "SDL NDS video driver", 96 NDSVID_DRIVER_NAME, "SDL NDS video driver",
113 NDS_VideoInit(_THIS) 101 NDS_VideoInit(_THIS)
114 { 102 {
115 SDL_DisplayMode mode; 103 SDL_DisplayMode mode;
116 int i; 104 int i;
117 105
118 TRACE("+NDS_VideoInit\n");
119 /* simple 256x192x16x60 for now */ 106 /* simple 256x192x16x60 for now */
120 mode.w = 256; 107 mode.w = 256;
121 mode.h = 192; 108 mode.h = 192;
122 mode.format = SDL_PIXELFORMAT_ABGR1555; 109 mode.format = SDL_PIXELFORMAT_ABGR1555;
123 mode.refresh_rate = 60; 110 mode.refresh_rate = 60;
124 mode.driverdata = NULL; 111 mode.driverdata = NULL;
125 112
126 SDL_AddBasicVideoDisplay(&mode); 113 SDL_AddBasicVideoDisplay(&mode);
127 SDL_AddRenderDriver(0, &NDS_RenderDriver); 114 SDL_AddRenderDriver(0, &NDS_RenderDriver);
128 /*SDL_AddBasicVideoDisplay(&mode); two screens, same mode. uncomment later
129 SDL_AddRenderDriver(1, &NDS_RenderDriver);*/
130 115
131 SDL_zero(mode); 116 SDL_zero(mode);
132 SDL_AddDisplayMode(0, &mode); 117 SDL_AddDisplayMode(0, &mode);
133 118
134 /* hackish stuff to get things up and running for now, and for a console */
135 powerON(POWER_ALL_2D); 119 powerON(POWER_ALL_2D);
136 irqInit(); 120 irqInit();
137 irqEnable(IRQ_VBLANK); 121 irqEnable(IRQ_VBLANK);
138 NDS_SetDisplayMode(_this, &mode); 122 NDS_SetDisplayMode(_this, &mode);
139 123
140 TRACE("-NDS_VideoInit\n");
141 return 0; 124 return 0;
142 } 125 }
143 126
144 static int 127 static int
145 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode) 128 NDS_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
146 { 129 {
147 TRACE("+NDS_SetDisplayMode\n");
148 /* right now this function is just hard-coded for 256x192 ABGR1555 */ 130 /* right now this function is just hard-coded for 256x192 ABGR1555 */
149 videoSetMode(MODE_5_2D | 131 videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_BG_EXT_PALETTE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_1D_BMP | DISPLAY_SPR_1D_BMP_SIZE_256 | /* (try 128 if 256 is trouble.) */
150 DISPLAY_BG2_ACTIVE | 132 DISPLAY_SPR_ACTIVE | DISPLAY_SPR_EXT_PALETTE); /* display on main core
151 DISPLAY_BG3_ACTIVE | 133 with lots of flags set for
152 DISPLAY_BG_EXT_PALETTE | 134 flexibility/capacity to render */
153 DISPLAY_SPR_1D_LAYOUT |
154 DISPLAY_SPR_1D_BMP |
155 DISPLAY_SPR_1D_BMP_SIZE_256 | /* try 128 if 256 is trouble. */
156 DISPLAY_SPR_ACTIVE |
157 DISPLAY_SPR_EXT_PALETTE); /* display on main core
158 with lots of flags set for
159 flexibility/capacity to render */
160 135
161 /* hopefully these cover all the various things we might need to do */ 136 /* hopefully these cover all the various things we might need to do */
162 vramSetBankA(VRAM_A_MAIN_BG_0x06000000); 137 vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
163 vramSetBankB(VRAM_B_MAIN_BG_0x06020000); 138 vramSetBankB(VRAM_B_MAIN_BG_0x06020000);
164 vramSetBankC(VRAM_C_SUB_BG_0x06200000); 139 vramSetBankC(VRAM_C_SUB_BG_0x06200000);
165 vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */ 140 vramSetBankD(VRAM_D_MAIN_BG_0x06040000); /* not a typo. vram d can't sub */
166 vramSetBankE(VRAM_E_MAIN_SPRITE); 141 vramSetBankE(VRAM_E_MAIN_SPRITE);
167 vramSetBankF(VRAM_F_OBJ_EXT_PALETTE); 142 vramSetBankF(VRAM_F_OBJ_EXT_PALETTE);
168 vramSetBankG(VRAM_G_BG_EXT_PALETTE); 143 vramSetBankG(VRAM_G_BG_EXT_PALETTE);
169 vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); 144 vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
170 vramSetBankI(VRAM_I_SUB_SPRITE); 145 vramSetBankI(VRAM_I_SUB_SPRITE);
171 146
172 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub 147 videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); /* debug text on sub
173 TODO: this will change 148 TODO: this will change
174 when multi-head is 149 when multi-head is
175 introduced in render */ 150 introduced in render */
176 151
177 TRACE("-NDS_SetDisplayMode\n");
178 return 0; 152 return 0;
179 } 153 }
180 154
181 void 155 void
182 NDS_VideoQuit(_THIS) 156 NDS_VideoQuit(_THIS)
183 { 157 {
184 TRACE("+NDS_VideoQuit\n");
185 videoSetMode(DISPLAY_SCREEN_OFF); 158 videoSetMode(DISPLAY_SCREEN_OFF);
186 videoSetModeSub(DISPLAY_SCREEN_OFF); 159 videoSetModeSub(DISPLAY_SCREEN_OFF);
187 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); 160 vramSetMainBanks(VRAM_A_LCD, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD);
188 vramSetBankE(VRAM_E_LCD); 161 vramSetBankE(VRAM_E_LCD);
189 vramSetBankF(VRAM_F_LCD); 162 vramSetBankF(VRAM_F_LCD);
190 vramSetBankG(VRAM_G_LCD); 163 vramSetBankG(VRAM_G_LCD);
191 vramSetBankH(VRAM_H_LCD); 164 vramSetBankH(VRAM_H_LCD);
192 vramSetBankI(VRAM_I_LCD); 165 vramSetBankI(VRAM_I_LCD);
193 TRACE("-NDS_VideoQuit\n");
194 } 166 }
195 167
196 /* vi: set ts=4 sw=4 expandtab: */ 168 /* vi: set ts=4 sw=4 expandtab: */