comparison src/video/aalib/SDL_aavideo.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
39 #include "SDL_aamouse_c.h" 39 #include "SDL_aamouse_c.h"
40 40
41 #include <aalib.h> 41 #include <aalib.h>
42 42
43 /* Initialization/Query functions */ 43 /* Initialization/Query functions */
44 static int AA_VideoInit (_THIS, SDL_PixelFormat * vformat); 44 static int AA_VideoInit(_THIS, SDL_PixelFormat * vformat);
45 static SDL_Rect **AA_ListModes (_THIS, SDL_PixelFormat * format, 45 static SDL_Rect **AA_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
46 Uint32 flags); 46 static SDL_Surface *AA_SetVideoMode(_THIS, SDL_Surface * current, int width,
47 static SDL_Surface *AA_SetVideoMode (_THIS, SDL_Surface * current, int width, 47 int height, int bpp, Uint32 flags);
48 int height, int bpp, Uint32 flags); 48 static int AA_SetColors(_THIS, int firstcolor, int ncolors,
49 static int AA_SetColors (_THIS, int firstcolor, int ncolors, 49 SDL_Color * colors);
50 SDL_Color * colors); 50 static void AA_VideoQuit(_THIS);
51 static void AA_VideoQuit (_THIS);
52 51
53 /* Hardware surface functions */ 52 /* Hardware surface functions */
54 static int AA_AllocHWSurface (_THIS, SDL_Surface * surface); 53 static int AA_AllocHWSurface(_THIS, SDL_Surface * surface);
55 static int AA_LockHWSurface (_THIS, SDL_Surface * surface); 54 static int AA_LockHWSurface(_THIS, SDL_Surface * surface);
56 static int AA_FlipHWSurface (_THIS, SDL_Surface * surface); 55 static int AA_FlipHWSurface(_THIS, SDL_Surface * surface);
57 static void AA_UnlockHWSurface (_THIS, SDL_Surface * surface); 56 static void AA_UnlockHWSurface(_THIS, SDL_Surface * surface);
58 static void AA_FreeHWSurface (_THIS, SDL_Surface * surface); 57 static void AA_FreeHWSurface(_THIS, SDL_Surface * surface);
59 58
60 /* Cache the VideoDevice struct */ 59 /* Cache the VideoDevice struct */
61 static struct SDL_VideoDevice *local_this; 60 static struct SDL_VideoDevice *local_this;
62 61
63 /* AAlib driver bootstrap functions */ 62 /* AAlib driver bootstrap functions */
64 63
65 static int 64 static int
66 AA_Available (void) 65 AA_Available(void)
67 { 66 {
68 return 1; /* Always available ! */ 67 return 1; /* Always available ! */
69 } 68 }
70 69
71 static void 70 static void
72 AA_DeleteDevice (SDL_VideoDevice * device) 71 AA_DeleteDevice(SDL_VideoDevice * device)
73 { 72 {
74 SDL_free (device->hidden); 73 SDL_free(device->hidden);
75 SDL_free (device); 74 SDL_free(device);
76 } 75 }
77 76
78 static SDL_VideoDevice * 77 static SDL_VideoDevice *
79 AA_CreateDevice (int devindex) 78 AA_CreateDevice(int devindex)
80 { 79 {
81 SDL_VideoDevice *device; 80 SDL_VideoDevice *device;
82 81
83 /* Initialize all variables that we clean on shutdown */ 82 /* Initialize all variables that we clean on shutdown */
84 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 83 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
85 if (device) { 84 if (device) {
86 SDL_memset (device, 0, (sizeof *device)); 85 SDL_memset(device, 0, (sizeof *device));
87 device->hidden = (struct SDL_PrivateVideoData *) 86 device->hidden = (struct SDL_PrivateVideoData *)
88 SDL_malloc ((sizeof *device->hidden)); 87 SDL_malloc((sizeof *device->hidden));
89 } 88 }
90 if ((device == NULL) || (device->hidden == NULL)) { 89 if ((device == NULL) || (device->hidden == NULL)) {
91 SDL_OutOfMemory (); 90 SDL_OutOfMemory();
92 if (device) { 91 if (device) {
93 SDL_free (device); 92 SDL_free(device);
94 } 93 }
95 return (0); 94 return (0);
96 } 95 }
97 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 96 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
98 97
99 /* Set the function pointers */ 98 /* Set the function pointers */
100 device->VideoInit = AA_VideoInit; 99 device->VideoInit = AA_VideoInit;
101 device->ListModes = AA_ListModes; 100 device->ListModes = AA_ListModes;
102 device->SetVideoMode = AA_SetVideoMode; 101 device->SetVideoMode = AA_SetVideoMode;
129 VideoBootStrap AALIB_bootstrap = { 128 VideoBootStrap AALIB_bootstrap = {
130 "aalib", "ASCII Art Library", 129 "aalib", "ASCII Art Library",
131 AA_Available, AA_CreateDevice 130 AA_Available, AA_CreateDevice
132 }; 131 };
133 132
134 static void AA_ResizeHandler (aa_context *); 133 static void AA_ResizeHandler(aa_context *);
135 134
136 int 135 int
137 AA_VideoInit (_THIS, SDL_PixelFormat * vformat) 136 AA_VideoInit(_THIS, SDL_PixelFormat * vformat)
138 { 137 {
139 int keyboard; 138 int keyboard;
140 int i; 139 int i;
141 140
142 /* Initialize all variables that we clean on shutdown */ 141 /* Initialize all variables that we clean on shutdown */
143 for (i = 0; i < SDL_NUMMODES; ++i) { 142 for (i = 0; i < SDL_NUMMODES; ++i) {
144 SDL_modelist[i] = SDL_malloc (sizeof (SDL_Rect)); 143 SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
145 SDL_modelist[i]->x = SDL_modelist[i]->y = 0; 144 SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
146 } 145 }
147 /* Modes sorted largest to smallest */ 146 /* Modes sorted largest to smallest */
148 SDL_modelist[0]->w = 1024; 147 SDL_modelist[0]->w = 1024;
149 SDL_modelist[0]->h = 768; 148 SDL_modelist[0]->h = 768;
159 SDL_modelist[5]->h = 200; 158 SDL_modelist[5]->h = 200;
160 SDL_modelist[6] = NULL; 159 SDL_modelist[6] = NULL;
161 160
162 /* Initialize the library */ 161 /* Initialize the library */
163 162
164 AA_mutex = SDL_CreateMutex (); 163 AA_mutex = SDL_CreateMutex();
165 164
166 aa_parseoptions (NULL, NULL, NULL, NULL); 165 aa_parseoptions(NULL, NULL, NULL, NULL);
167 166
168 AA_context = aa_autoinit (&aa_defparams); 167 AA_context = aa_autoinit(&aa_defparams);
169 if (!AA_context) { 168 if (!AA_context) {
170 SDL_SetError ("Unable to initialize AAlib"); 169 SDL_SetError("Unable to initialize AAlib");
171 return (-1); 170 return (-1);
172 } 171 }
173 172
174 /* Enable mouse and keyboard support */ 173 /* Enable mouse and keyboard support */
175 174
176 if (!aa_autoinitkbd (AA_context, AA_SENDRELEASE)) { 175 if (!aa_autoinitkbd(AA_context, AA_SENDRELEASE)) {
177 SDL_SetError ("Unable to initialize AAlib keyboard"); 176 SDL_SetError("Unable to initialize AAlib keyboard");
178 return (-1); 177 return (-1);
179 } 178 }
180 if (!aa_autoinitmouse (AA_context, AA_SENDRELEASE)) { 179 if (!aa_autoinitmouse(AA_context, AA_SENDRELEASE)) {
181 fprintf (stderr, "Warning: Unable to initialize AAlib mouse"); 180 fprintf(stderr, "Warning: Unable to initialize AAlib mouse");
182 } 181 }
183 AA_rparams = aa_getrenderparams (); 182 AA_rparams = aa_getrenderparams();
184 183
185 local_this = this; 184 local_this = this;
186 185
187 aa_resizehandler (AA_context, AA_ResizeHandler); 186 aa_resizehandler(AA_context, AA_ResizeHandler);
188 187
189 fprintf (stderr, "Using AAlib driver: %s (%s)\n", 188 fprintf(stderr, "Using AAlib driver: %s (%s)\n",
190 AA_context->driver->name, AA_context->driver->shortname); 189 AA_context->driver->name, AA_context->driver->shortname);
191 190
192 AA_in_x11 = (SDL_strcmp (AA_context->driver->shortname, "X11") == 0); 191 AA_in_x11 = (SDL_strcmp(AA_context->driver->shortname, "X11") == 0);
193 /* Determine the screen depth (use default 8-bit depth) */ 192 /* Determine the screen depth (use default 8-bit depth) */
194 vformat->BitsPerPixel = 8; 193 vformat->BitsPerPixel = 8;
195 vformat->BytesPerPixel = 1; 194 vformat->BytesPerPixel = 1;
196 195
197 /* We're done! */ 196 /* We're done! */
198 return (0); 197 return (0);
199 } 198 }
200 199
201 SDL_Rect ** 200 SDL_Rect **
202 AA_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 201 AA_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
203 { 202 {
204 if (format->BitsPerPixel != 8) 203 if (format->BitsPerPixel != 8)
205 return NULL; 204 return NULL;
206 205
207 if (flags & SDL_FULLSCREEN) { 206 if (flags & SDL_FULLSCREEN) {
214 /* From aavga.c 213 /* From aavga.c
215 AAlib does not give us the choice of the actual resolution, thus we have to simulate additional 214 AAlib does not give us the choice of the actual resolution, thus we have to simulate additional
216 resolution by scaling down manually each frame 215 resolution by scaling down manually each frame
217 */ 216 */
218 static void 217 static void
219 fastscale (register char *b1, register char *b2, int x1, int x2, int y1, 218 fastscale(register char *b1, register char *b2, int x1, int x2, int y1,
220 int y2) 219 int y2)
221 { 220 {
222 register int ex, spx = 0, ddx, ddx1; 221 register int ex, spx = 0, ddx, ddx1;
223 int ddy1, ddy, spy = 0, ey; 222 int ddy1, ddy, spy = 0, ey;
224 int x; 223 int x;
225 char *bb1 = b1; 224 char *bb1 = b1;
255 b1 = bb1; 254 b1 = bb1;
256 } 255 }
257 } 256 }
258 257
259 /* Various screen update functions available */ 258 /* Various screen update functions available */
260 static void AA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); 259 static void AA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
261 260
262 SDL_Surface * 261 SDL_Surface *
263 AA_SetVideoMode (_THIS, SDL_Surface * current, 262 AA_SetVideoMode(_THIS, SDL_Surface * current,
264 int width, int height, int bpp, Uint32 flags) 263 int width, int height, int bpp, Uint32 flags)
265 { 264 {
266 int mode; 265 int mode;
267 266
268 if (AA_buffer) { 267 if (AA_buffer) {
269 SDL_free (AA_buffer); 268 SDL_free(AA_buffer);
270 } 269 }
271 270
272 AA_buffer = SDL_malloc (width * height); 271 AA_buffer = SDL_malloc(width * height);
273 if (!AA_buffer) { 272 if (!AA_buffer) {
274 SDL_SetError ("Couldn't allocate buffer for requested mode"); 273 SDL_SetError("Couldn't allocate buffer for requested mode");
275 return (NULL); 274 return (NULL);
276 } 275 }
277 276
278 /* printf("Setting mode %dx%d\n", width, height); */ 277 /* printf("Setting mode %dx%d\n", width, height); */
279 278
280 SDL_memset (aa_image (AA_context), 0, 279 SDL_memset(aa_image(AA_context), 0,
281 aa_imgwidth (AA_context) * aa_imgheight (AA_context)); 280 aa_imgwidth(AA_context) * aa_imgheight(AA_context));
282 SDL_memset (AA_buffer, 0, width * height); 281 SDL_memset(AA_buffer, 0, width * height);
283 282
284 /* Allocate the new pixel format for the screen */ 283 /* Allocate the new pixel format for the screen */
285 if (!SDL_ReallocFormat (current, 8, 0, 0, 0, 0)) { 284 if (!SDL_ReallocFormat(current, 8, 0, 0, 0, 0)) {
286 return (NULL); 285 return (NULL);
287 } 286 }
288 287
289 /* Set up the new mode framebuffer */ 288 /* Set up the new mode framebuffer */
290 current->flags = SDL_FULLSCREEN; 289 current->flags = SDL_FULLSCREEN;
291 AA_w = current->w = width; 290 AA_w = current->w = width;
292 AA_h = current->h = height; 291 AA_h = current->h = height;
293 current->pitch = current->w; 292 current->pitch = current->w;
294 current->pixels = AA_buffer; 293 current->pixels = AA_buffer;
295 294
296 AA_x_ratio = ((double) aa_imgwidth (AA_context)) / ((double) width); 295 AA_x_ratio = ((double) aa_imgwidth(AA_context)) / ((double) width);
297 AA_y_ratio = ((double) aa_imgheight (AA_context)) / ((double) height); 296 AA_y_ratio = ((double) aa_imgheight(AA_context)) / ((double) height);
298 297
299 /* Set the blit function */ 298 /* Set the blit function */
300 this->UpdateRects = AA_DirectUpdate; 299 this->UpdateRects = AA_DirectUpdate;
301 300
302 /* We're done */ 301 /* We're done */
303 return (current); 302 return (current);
304 } 303 }
305 304
306 static void 305 static void
307 AA_ResizeHandler (aa_context * context) 306 AA_ResizeHandler(aa_context * context)
308 { 307 {
309 aa_resize (context); 308 aa_resize(context);
310 local_this->hidden->x_ratio = 309 local_this->hidden->x_ratio =
311 ((double) aa_imgwidth (context)) / ((double) local_this->screen->w); 310 ((double) aa_imgwidth(context)) / ((double) local_this->screen->w);
312 local_this->hidden->y_ratio = 311 local_this->hidden->y_ratio =
313 ((double) aa_imgheight (context)) / ((double) local_this->screen->h); 312 ((double) aa_imgheight(context)) / ((double) local_this->screen->h);
314 313
315 fastscale (local_this->hidden->buffer, aa_image (context), 314 fastscale(local_this->hidden->buffer, aa_image(context),
316 local_this->hidden->w, aa_imgwidth (context), 315 local_this->hidden->w, aa_imgwidth(context),
317 local_this->hidden->h, aa_imgheight (context)); 316 local_this->hidden->h, aa_imgheight(context));
318 aa_renderpalette (context, local_this->hidden->palette, 317 aa_renderpalette(context, local_this->hidden->palette,
319 local_this->hidden->rparams, 0, 0, 318 local_this->hidden->rparams, 0, 0,
320 aa_scrwidth (context), aa_scrheight (context)); 319 aa_scrwidth(context), aa_scrheight(context));
321 aa_flush (context); 320 aa_flush(context);
322 } 321 }
323 322
324 /* We don't actually allow hardware surfaces other than the main one */ 323 /* We don't actually allow hardware surfaces other than the main one */
325 static int 324 static int
326 AA_AllocHWSurface (_THIS, SDL_Surface * surface) 325 AA_AllocHWSurface(_THIS, SDL_Surface * surface)
327 { 326 {
328 return (-1); 327 return (-1);
329 } 328 }
330 static void 329 static void
331 AA_FreeHWSurface (_THIS, SDL_Surface * surface) 330 AA_FreeHWSurface(_THIS, SDL_Surface * surface)
332 { 331 {
333 return; 332 return;
334 } 333 }
335 334
336 /* We need to wait for vertical retrace on page flipped displays */ 335 /* We need to wait for vertical retrace on page flipped displays */
337 static int 336 static int
338 AA_LockHWSurface (_THIS, SDL_Surface * surface) 337 AA_LockHWSurface(_THIS, SDL_Surface * surface)
339 { 338 {
340 /* TODO ? */ 339 /* TODO ? */
341 return (0); 340 return (0);
342 } 341 }
343 static void 342 static void
344 AA_UnlockHWSurface (_THIS, SDL_Surface * surface) 343 AA_UnlockHWSurface(_THIS, SDL_Surface * surface)
345 { 344 {
346 return; 345 return;
347 } 346 }
348 347
349 /* FIXME: How is this done with AAlib? */ 348 /* FIXME: How is this done with AAlib? */
350 static int 349 static int
351 AA_FlipHWSurface (_THIS, SDL_Surface * surface) 350 AA_FlipHWSurface(_THIS, SDL_Surface * surface)
352 { 351 {
353 SDL_mutexP (AA_mutex); 352 SDL_mutexP(AA_mutex);
354 aa_flush (AA_context); 353 aa_flush(AA_context);
355 SDL_mutexV (AA_mutex); 354 SDL_mutexV(AA_mutex);
356 return (0); 355 return (0);
357 } 356 }
358 357
359 static void 358 static void
360 AA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) 359 AA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
361 { 360 {
362 int i; 361 int i;
363 SDL_Rect *rect; 362 SDL_Rect *rect;
364 363
365 fastscale (AA_buffer, aa_image (AA_context), AA_w, 364 fastscale(AA_buffer, aa_image(AA_context), AA_w,
366 aa_imgwidth (AA_context), AA_h, aa_imgheight (AA_context)); 365 aa_imgwidth(AA_context), AA_h, aa_imgheight(AA_context));
367 #if 1 366 #if 1
368 aa_renderpalette (AA_context, AA_palette, AA_rparams, 0, 0, 367 aa_renderpalette(AA_context, AA_palette, AA_rparams, 0, 0,
369 aa_scrwidth (AA_context), aa_scrheight (AA_context)); 368 aa_scrwidth(AA_context), aa_scrheight(AA_context));
370 #else 369 #else
371 /* Render only the rectangles in the list */ 370 /* Render only the rectangles in the list */
372 printf ("Update rects : "); 371 printf("Update rects : ");
373 for (i = 0; i < numrects; ++i) { 372 for (i = 0; i < numrects; ++i) {
374 rect = &rects[i]; 373 rect = &rects[i];
375 printf ("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h); 374 printf("(%d,%d-%d,%d)", rect->x, rect->y, rect->w, rect->h);
376 aa_renderpalette (AA_context, AA_palette, AA_rparams, 375 aa_renderpalette(AA_context, AA_palette, AA_rparams,
377 rect->x * AA_x_ratio, rect->y * AA_y_ratio, 376 rect->x * AA_x_ratio, rect->y * AA_y_ratio,
378 rect->w * AA_x_ratio, rect->h * AA_y_ratio); 377 rect->w * AA_x_ratio, rect->h * AA_y_ratio);
379 } 378 }
380 printf ("\n"); 379 printf("\n");
381 #endif 380 #endif
382 SDL_mutexP (AA_mutex); 381 SDL_mutexP(AA_mutex);
383 aa_flush (AA_context); 382 aa_flush(AA_context);
384 SDL_mutexV (AA_mutex); 383 SDL_mutexV(AA_mutex);
385 return; 384 return;
386 } 385 }
387 386
388 int 387 int
389 AA_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 388 AA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
390 { 389 {
391 int i; 390 int i;
392 391
393 for (i = 0; i < ncolors; i++) { 392 for (i = 0; i < ncolors; i++) {
394 aa_setpalette (AA_palette, firstcolor + i, 393 aa_setpalette(AA_palette, firstcolor + i,
395 colors[i].r >> 2, colors[i].g >> 2, colors[i].b >> 2); 394 colors[i].r >> 2, colors[i].g >> 2, colors[i].b >> 2);
396 } 395 }
397 return (1); 396 return (1);
398 } 397 }
399 398
400 /* Note: If we are terminated, this could be called in the middle of 399 /* Note: If we are terminated, this could be called in the middle of
401 another SDL video routine -- notably UpdateRects. 400 another SDL video routine -- notably UpdateRects.
402 */ 401 */
403 void 402 void
404 AA_VideoQuit (_THIS) 403 AA_VideoQuit(_THIS)
405 { 404 {
406 int i; 405 int i;
407 406
408 aa_uninitkbd (AA_context); 407 aa_uninitkbd(AA_context);
409 aa_uninitmouse (AA_context); 408 aa_uninitmouse(AA_context);
410 409
411 /* Free video mode lists */ 410 /* Free video mode lists */
412 for (i = 0; i < SDL_NUMMODES; ++i) { 411 for (i = 0; i < SDL_NUMMODES; ++i) {
413 if (SDL_modelist[i] != NULL) { 412 if (SDL_modelist[i] != NULL) {
414 SDL_free (SDL_modelist[i]); 413 SDL_free(SDL_modelist[i]);
415 SDL_modelist[i] = NULL; 414 SDL_modelist[i] = NULL;
416 } 415 }
417 } 416 }
418 417
419 aa_close (AA_context); 418 aa_close(AA_context);
420 419
421 SDL_DestroyMutex (AA_mutex); 420 SDL_DestroyMutex(AA_mutex);
422 421
423 this->screen->pixels = NULL; 422 this->screen->pixels = NULL;
424 } 423 }
425 424
426 /* vi: set ts=4 sw=4 expandtab: */ 425 /* vi: set ts=4 sw=4 expandtab: */