comparison src/video/nds/SDL_ndsrender.c @ 2673:24a6b3588eac gsoc2008_nds

Cleaned up and added joypad support from 1.2.9 NDS port. Also some minor video driver bugfixes.
author Darren Alton <dalton@stevens.edu>
date Thu, 19 Jun 2008 07:11:35 +0000
parents 74ac057679d5
children 6386764eb222
comparison
equal deleted inserted replaced
2672:74ac057679d5 2673:24a6b3588eac
66 /* this is mainly hackish testing/debugging stuff to get cleaned up soon 66 /* this is mainly hackish testing/debugging stuff to get cleaned up soon
67 anything named sdlds_blah shouldn't make it into the stable version 67 anything named sdlds_blah shouldn't make it into the stable version
68 */ 68 */
69 69
70 u16 70 u16
71 sdlds_rgb2bgr(u16 c) { 71 sdlds_rgb2bgr(u16 c)
72 /* hack to get the colors right until I actually add BGR555 to the headers */ 72 {
73 /* hack to get the proper colors until I actually get BGR555 to work right */
73 u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b; 74 u16 Rmask = 0x7C00, Bmask = 0x001F, GAmask = 0x83E0, r, b;
74 r = (c & Rmask) >> 10; 75 r = (c & Rmask) >> 10;
75 b = (c & Bmask) << 10; 76 b = (c & Bmask) << 10;
76 return (c & GAmask) | r | b; 77 return (c & GAmask) | r | b;
77 } 78 }
78 79
79 void 80 void
80 sdlds_surf2vram(SDL_Surface * s) 81 sdlds_surf2vram(SDL_Surface * s)
81 { 82 {
82 83 if (s->w == 256) {
83 int i; 84 dmaCopy((u8 *) (s->pixels) + 156 * sizeof(u16),
84 /*for (i = 0; i < 30; ++i) swiWaitForVBlank();*/ 85 VRAM_A, 256 * 192 * sizeof(u16));
85 for (i = 0; i < 256 * 192; ++i) {
86 ((u16 *) VRAM_A)[i] = sdlds_rgb2bgr(((u16 *) (s->pixels))[i+160]);
87 } 86 }
88 } 87 }
89 88
90 void 89 void
91 sdlds_print_pixfmt_info(SDL_PixelFormat *f) { 90 sdlds_print_pixfmt_info(SDL_PixelFormat * f)
92 if(!f) return; 91 {
93 printf("bpp: %d\nRGBA: %x %x %x %x\n", 92 if (!f)
94 f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask); 93 return;
94 printf("bpp: %d\nRGBA: %x %x %x %x\n",
95 f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
95 } 96 }
96 97
97 void 98 void
98 sdlds_print_surface_info(SDL_Surface *s) { 99 sdlds_print_surface_info(SDL_Surface * s)
99 if(!s) return; 100 {
100 printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n", 101 if (!s)
101 s->flags, s->w, s->h, s->pitch, s->locked, s->refcount); 102 return;
102 sdlds_print_pixfmt_info(s->format); 103 printf("flags: %x\nsize: %dx%d, pitch: %d\nlocked: %d, refcount: %d\n",
104 s->flags, s->w, s->h, s->pitch, s->locked, s->refcount);
105 sdlds_print_pixfmt_info(s->format);
103 } 106 }
104 107
105 108
106 109
107 SDL_Renderer * 110 SDL_Renderer *
111 SDL_DisplayMode *displayMode = &display->current_mode; 114 SDL_DisplayMode *displayMode = &display->current_mode;
112 SDL_Renderer *renderer; 115 SDL_Renderer *renderer;
113 SDL_NDS_RenderData *data; 116 SDL_NDS_RenderData *data;
114 int i, n; 117 int i, n;
115 int bpp = 15; 118 int bpp = 15;
116 /*/ 119 Uint32 Rmask, Gmask, Bmask, Amask;
117 Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000; 120 /* Uint32 Rmask = 0x7C00, Gmask = 0x03E0, Bmask = 0x001F, Amask = 0x8000;
118 /*/
119 Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000; 121 Uint32 Rmask = 0x001F, Gmask = 0x03E0, Bmask = 0x7C00, Amask = 0x8000;
120 //*/ 122 */
121 123
122 #if 0 124 #if 0
123 printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags); 125 printf("SDL_NDS_CreateRenderer(window, 0x%x)\n", flags);
124 printf(" window: (%d,%d), %dx%d\n", 126 printf(" window: (%d,%d), %dx%d\n",
125 window->x, window->y, window->w, window->h); 127 window->x, window->y, window->w, window->h);
126 #endif 128 #endif
127 129
128 /* hard coded this to ARGB1555 for now 130 /* hard coded this to BGR555 for now */
129 if (!SDL_PixelFormatEnumToMasks 131 if (!SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_BGR555, &bpp,
130 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { 132 &Rmask, &Gmask, &Bmask, &Amask)) {
131 SDL_SetError("Unknown display format"); 133 SDL_SetError("Unknown display format");
132 return NULL; 134 return NULL;
133 } */ 135 }
134 136
135 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); 137 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
136 if (!renderer) { 138 if (!renderer) {
137 SDL_OutOfMemory(); 139 SDL_OutOfMemory();
138 return NULL; 140 return NULL;
166 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY; 168 renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
167 n = 1; 169 n = 1;
168 } 170 }
169 for (i = 0; i < n; ++i) { 171 for (i = 0; i < n; ++i) {
170 data->screens[i] = 172 data->screens[i] =
171 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask, Amask); 173 SDL_CreateRGBSurface(0, 256, 192, bpp, Rmask, Gmask, Bmask,
174 Amask);
172 if (!data->screens[i]) { 175 if (!data->screens[i]) {
173 SDL_NDS_DestroyRenderer(renderer); 176 SDL_NDS_DestroyRenderer(renderer);
174 return NULL; 177 return NULL;
175 } 178 }
176 SDL_SetSurfacePalette(data->screens[i], display->palette); 179 SDL_SetSurfacePalette(data->screens[i], display->palette);
180 sdlds_print_surface_info(data->screens[i]);
177 } 181 }
178 182
179 data->current_screen = 0; 183 data->current_screen = 0;
180 data->ultimate_answer = 42; 184 data->ultimate_answer = 42;
181 185
225 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 229 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
226 SDL_Surface *target = data->screens[data->current_screen]; 230 SDL_Surface *target = data->screens[data->current_screen];
227 SDL_Rect real_srcrect = *srcrect; 231 SDL_Rect real_srcrect = *srcrect;
228 SDL_Rect real_dstrect = *dstrect; 232 SDL_Rect real_dstrect = *dstrect;
229 /*sdlds_print_surface_info(surface); 233 /*sdlds_print_surface_info(surface);
230 sdlds_print_surface_info(target);*/ 234 sdlds_print_surface_info(target); */
231 sdlds_surf2vram(surface); 235 sdlds_surf2vram(surface);
232 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 236 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
233 } 237 }
234 #if 0 238 #if 0
235 /* copy it directly to vram */ 239 /* copy it directly to vram */
238 int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h; 242 int dx = dstrect->x, dy = dstrect->y, dw = dstrect->w, dh = dstrect->h;
239 int si, sj, di, dj; 243 int si, sj, di, dj;
240 for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) { 244 for (sj = 0, dj = 0; sj < sh && dj < dh; ++sj, ++dj) {
241 for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) { 245 for (si = 0, di = 0; si < sw && di < dw; ++si, ++di) {
242 VRAM_A[(dj + dy) * 256 + di + dx] = 246 VRAM_A[(dj + dy) * 256 + di + dx] =
243 ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si + sx]; 247 ((Uint16 *) surface->pixels)[(sj + sy) * (surface->w) + si +
248 sx];
244 } 249 }
245 } 250 }
246 return 0; 251 return 0;
247 #endif 252 #endif
248 } 253 }
250 255
251 static void 256 static void
252 SDL_NDS_RenderPresent(SDL_Renderer * renderer) 257 SDL_NDS_RenderPresent(SDL_Renderer * renderer)
253 { 258 {
254 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata; 259 SDL_NDS_RenderData *data = (SDL_NDS_RenderData *) renderer->driverdata;
260 int i;
255 #if 0 261 #if 0
256 printf("SDL_NDS_RenderPresent(renderer)\n"); 262 printf("SDL_NDS_RenderPresent(renderer)\n");
257 printf(" renderer: %s\n", renderer->info.name); 263 printf(" renderer: %s\n", renderer->info.name);
258 #endif 264 #endif
259 /* Send the data to the display */ 265 /* Send the data to the display */
260 /*sdlds_surf2vram(data->screens[data->current_screen]);*/ 266
261 267 /* hack to fix the pixel format until I figure out why BGR doesn't work */
268 for (i = 0; i < 256 * 192; ++i) {
269 VRAM_A[i] = sdlds_rgb2bgr(VRAM_A[i]);
270 }
262 /* Update the flipping chain, if any */ 271 /* Update the flipping chain, if any */
263 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { 272 if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
264 data->current_screen = (data->current_screen + 1) % 2; 273 data->current_screen = (data->current_screen + 1) % 2;
265 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) { 274 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
266 data->current_screen = (data->current_screen + 1) % 3; 275 data->current_screen = (data->current_screen + 1) % 3;