comparison src/video/vgl/SDL_vglvideo.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
43 #include "SDL_vglevents_c.h" 43 #include "SDL_vglevents_c.h"
44 #include "SDL_vglmouse_c.h" 44 #include "SDL_vglmouse_c.h"
45 45
46 46
47 /* Initialization/Query functions */ 47 /* Initialization/Query functions */
48 static int VGL_VideoInit (_THIS, SDL_PixelFormat * vformat); 48 static int VGL_VideoInit(_THIS, SDL_PixelFormat * vformat);
49 static SDL_Rect **VGL_ListModes (_THIS, SDL_PixelFormat * format, 49 static SDL_Rect **VGL_ListModes(_THIS, SDL_PixelFormat * format,
50 Uint32 flags); 50 Uint32 flags);
51 static SDL_Surface *VGL_SetVideoMode (_THIS, SDL_Surface * current, int width, 51 static SDL_Surface *VGL_SetVideoMode(_THIS, SDL_Surface * current, int width,
52 int height, int bpp, Uint32 flags); 52 int height, int bpp, Uint32 flags);
53 static int VGL_SetColors (_THIS, int firstcolor, int ncolors, 53 static int VGL_SetColors(_THIS, int firstcolor, int ncolors,
54 SDL_Color * colors); 54 SDL_Color * colors);
55 static void VGL_VideoQuit (_THIS); 55 static void VGL_VideoQuit(_THIS);
56 56
57 /* Hardware surface functions */ 57 /* Hardware surface functions */
58 static int VGL_AllocHWSurface (_THIS, SDL_Surface * surface); 58 static int VGL_AllocHWSurface(_THIS, SDL_Surface * surface);
59 static int VGL_LockHWSurface (_THIS, SDL_Surface * surface); 59 static int VGL_LockHWSurface(_THIS, SDL_Surface * surface);
60 static int VGL_FlipHWSurface (_THIS, SDL_Surface * surface); 60 static int VGL_FlipHWSurface(_THIS, SDL_Surface * surface);
61 static void VGL_UnlockHWSurface (_THIS, SDL_Surface * surface); 61 static void VGL_UnlockHWSurface(_THIS, SDL_Surface * surface);
62 static void VGL_FreeHWSurface (_THIS, SDL_Surface * surface); 62 static void VGL_FreeHWSurface(_THIS, SDL_Surface * surface);
63 63
64 /* Misc function */ 64 /* Misc function */
65 static VGLMode **VGLListModes (int depth, int mem_model); 65 static VGLMode **VGLListModes(int depth, int mem_model);
66 static void VGLWaitRetrace (void); 66 static void VGLWaitRetrace(void);
67 67
68 /* VGL driver bootstrap functions */ 68 /* VGL driver bootstrap functions */
69 69
70 static int 70 static int
71 VGL_Available (void) 71 VGL_Available(void)
72 { 72 {
73 /* 73 /*
74 * Check to see if we are root and stdin is a 74 * Check to see if we are root and stdin is a
75 * virtual console. Also try to ensure that 75 * virtual console. Also try to ensure that
76 * modes other than 320x200 are available 76 * modes other than 320x200 are available
81 console = STDIN_FILENO; 81 console = STDIN_FILENO;
82 if (console >= 0) { 82 if (console >= 0) {
83 struct stat sb; 83 struct stat sb;
84 struct vt_mode dummy; 84 struct vt_mode dummy;
85 85
86 if ((fstat (console, &sb) < 0) || 86 if ((fstat(console, &sb) < 0) ||
87 (ioctl (console, VT_GETMODE, &dummy) < 0)) { 87 (ioctl(console, VT_GETMODE, &dummy) < 0)) {
88 console = -1; 88 console = -1;
89 } 89 }
90 } 90 }
91 if (geteuid () != 0 && console == -1) 91 if (geteuid() != 0 && console == -1)
92 return 0; 92 return 0;
93 93
94 modes = VGLListModes (8, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); 94 modes = VGLListModes(8, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
95 hires_available = 0; 95 hires_available = 0;
96 for (i = 0; modes[i] != NULL; i++) { 96 for (i = 0; modes[i] != NULL; i++) {
97 if ((modes[i]->ModeInfo.Xsize > 320) && 97 if ((modes[i]->ModeInfo.Xsize > 320) &&
98 (modes[i]->ModeInfo.Ysize > 200) && 98 (modes[i]->ModeInfo.Ysize > 200) &&
99 ((modes[i]->ModeInfo.Type == VIDBUF8) || 99 ((modes[i]->ModeInfo.Type == VIDBUF8) ||
105 } 105 }
106 return hires_available; 106 return hires_available;
107 } 107 }
108 108
109 static void 109 static void
110 VGL_DeleteDevice (SDL_VideoDevice * device) 110 VGL_DeleteDevice(SDL_VideoDevice * device)
111 { 111 {
112 SDL_free (device->hidden); 112 SDL_free(device->hidden);
113 SDL_free (device); 113 SDL_free(device);
114 } 114 }
115 115
116 static SDL_VideoDevice * 116 static SDL_VideoDevice *
117 VGL_CreateDevice (int devindex) 117 VGL_CreateDevice(int devindex)
118 { 118 {
119 SDL_VideoDevice *device; 119 SDL_VideoDevice *device;
120 120
121 /* Initialize all variables that we clean on shutdown */ 121 /* Initialize all variables that we clean on shutdown */
122 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 122 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
123 if (device) { 123 if (device) {
124 SDL_memset (device, 0, (sizeof *device)); 124 SDL_memset(device, 0, (sizeof *device));
125 device->hidden = (struct SDL_PrivateVideoData *) 125 device->hidden = (struct SDL_PrivateVideoData *)
126 SDL_malloc ((sizeof *device->hidden)); 126 SDL_malloc((sizeof *device->hidden));
127 } 127 }
128 if ((device == NULL) || (device->hidden == NULL)) { 128 if ((device == NULL) || (device->hidden == NULL)) {
129 SDL_OutOfMemory (); 129 SDL_OutOfMemory();
130 if (device) { 130 if (device) {
131 SDL_free (device); 131 SDL_free(device);
132 } 132 }
133 return (0); 133 return (0);
134 } 134 }
135 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 135 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
136 136
137 /* Set the function pointers */ 137 /* Set the function pointers */
138 device->VideoInit = VGL_VideoInit; 138 device->VideoInit = VGL_VideoInit;
139 device->ListModes = VGL_ListModes; 139 device->ListModes = VGL_ListModes;
140 device->SetVideoMode = VGL_SetVideoMode; 140 device->SetVideoMode = VGL_SetVideoMode;
169 "vgl", "FreeBSD libVGL", 169 "vgl", "FreeBSD libVGL",
170 VGL_Available, VGL_CreateDevice 170 VGL_Available, VGL_CreateDevice
171 }; 171 };
172 172
173 static int 173 static int
174 VGL_AddMode (_THIS, VGLMode * inmode) 174 VGL_AddMode(_THIS, VGLMode * inmode)
175 { 175 {
176 SDL_Rect *mode; 176 SDL_Rect *mode;
177 177
178 int i, index; 178 int i, index;
179 int next_mode; 179 int next_mode;
189 (mode->h == inmode->ModeInfo.Ysize)) 189 (mode->h == inmode->ModeInfo.Ysize))
190 return 0; 190 return 0;
191 } 191 }
192 192
193 /* Set up the new video mode rectangle */ 193 /* Set up the new video mode rectangle */
194 mode = (SDL_Rect *) SDL_malloc (sizeof *mode); 194 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
195 if (mode == NULL) { 195 if (mode == NULL) {
196 SDL_OutOfMemory (); 196 SDL_OutOfMemory();
197 return -1; 197 return -1;
198 } 198 }
199 mode->x = 0; 199 mode->x = 0;
200 mode->y = 0; 200 mode->y = 0;
201 mode->w = inmode->ModeInfo.Xsize; 201 mode->w = inmode->ModeInfo.Xsize;
202 mode->h = inmode->ModeInfo.Ysize; 202 mode->h = inmode->ModeInfo.Ysize;
203 203
204 /* Allocate the new list of modes, and fill in the new mode */ 204 /* Allocate the new list of modes, and fill in the new mode */
205 next_mode = SDL_nummodes[index]; 205 next_mode = SDL_nummodes[index];
206 SDL_modelist[index] = (SDL_Rect **) 206 SDL_modelist[index] = (SDL_Rect **)
207 SDL_realloc (SDL_modelist[index], 207 SDL_realloc(SDL_modelist[index],
208 (1 + next_mode + 1) * sizeof (SDL_Rect *)); 208 (1 + next_mode + 1) * sizeof(SDL_Rect *));
209 if (SDL_modelist[index] == NULL) { 209 if (SDL_modelist[index] == NULL) {
210 SDL_OutOfMemory (); 210 SDL_OutOfMemory();
211 SDL_nummodes[index] = 0; 211 SDL_nummodes[index] = 0;
212 SDL_free (mode); 212 SDL_free(mode);
213 return -1; 213 return -1;
214 } 214 }
215 SDL_modelist[index][next_mode] = mode; 215 SDL_modelist[index][next_mode] = mode;
216 SDL_modelist[index][next_mode + 1] = NULL; 216 SDL_modelist[index][next_mode + 1] = NULL;
217 SDL_nummodes[index]++; 217 SDL_nummodes[index]++;
218 218
219 return 0; 219 return 0;
220 } 220 }
221 221
222 static void 222 static void
223 VGL_UpdateVideoInfo (_THIS) 223 VGL_UpdateVideoInfo(_THIS)
224 { 224 {
225 this->info.wm_available = 0; 225 this->info.wm_available = 0;
226 this->info.hw_available = 1; 226 this->info.hw_available = 1;
227 this->info.video_mem = 0; 227 this->info.video_mem = 0;
228 if (VGLCurMode == NULL) { 228 if (VGLCurMode == NULL) {
233 VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.Ysize; 233 VGLCurMode->ModeInfo.Xsize * VGLCurMode->ModeInfo.Ysize;
234 } 234 }
235 } 235 }
236 236
237 int 237 int
238 VGL_VideoInit (_THIS, SDL_PixelFormat * vformat) 238 VGL_VideoInit(_THIS, SDL_PixelFormat * vformat)
239 { 239 {
240 int i; 240 int i;
241 int total_modes; 241 int total_modes;
242 VGLMode **modes; 242 VGLMode **modes;
243 243
246 SDL_nummodes[i] = 0; 246 SDL_nummodes[i] = 0;
247 SDL_modelist[i] = NULL; 247 SDL_modelist[i] = NULL;
248 } 248 }
249 249
250 /* Enable mouse and keyboard support */ 250 /* Enable mouse and keyboard support */
251 if (SDL_getenv ("SDL_NO_RAWKBD") == NULL) { 251 if (SDL_getenv("SDL_NO_RAWKBD") == NULL) {
252 if (VGLKeyboardInit (VGL_CODEKEYS) != 0) { 252 if (VGLKeyboardInit(VGL_CODEKEYS) != 0) {
253 SDL_SetError ("Unable to initialize keyboard"); 253 SDL_SetError("Unable to initialize keyboard");
254 return -1; 254 return -1;
255 } 255 }
256 } else { 256 } else {
257 warnx ("Requiest to put keyboard into a raw mode ignored"); 257 warnx("Requiest to put keyboard into a raw mode ignored");
258 } 258 }
259 if (VGL_initkeymaps (STDIN_FILENO) != 0) { 259 if (VGL_initkeymaps(STDIN_FILENO) != 0) {
260 SDL_SetError ("Unable to initialize keymap"); 260 SDL_SetError("Unable to initialize keymap");
261 return -1; 261 return -1;
262 } 262 }
263 if (VGL_initmouse (STDIN_FILENO) != 0) { 263 if (VGL_initmouse(STDIN_FILENO) != 0) {
264 SDL_SetError ("Unable to initialize mouse"); 264 SDL_SetError("Unable to initialize mouse");
265 return -1; 265 return -1;
266 } 266 }
267 267
268 /* Determine the current screen size */ 268 /* Determine the current screen size */
269 if (VGLCurMode != NULL) { 269 if (VGLCurMode != NULL) {
277 else 277 else
278 vformat->BitsPerPixel = 16; /* Good default */ 278 vformat->BitsPerPixel = 16; /* Good default */
279 279
280 /* Query for the list of available video modes */ 280 /* Query for the list of available video modes */
281 total_modes = 0; 281 total_modes = 0;
282 modes = VGLListModes (-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); 282 modes = VGLListModes(-1, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
283 for (i = 0; modes[i] != NULL; i++) { 283 for (i = 0; modes[i] != NULL; i++) {
284 if ((modes[i]->ModeInfo.Type == VIDBUF8) || 284 if ((modes[i]->ModeInfo.Type == VIDBUF8) ||
285 (modes[i]->ModeInfo.Type == VIDBUF16) || 285 (modes[i]->ModeInfo.Type == VIDBUF16) ||
286 (modes[i]->ModeInfo.Type == VIDBUF32)) { 286 (modes[i]->ModeInfo.Type == VIDBUF32)) {
287 VGL_AddMode (this, modes[i]); 287 VGL_AddMode(this, modes[i]);
288 total_modes++; 288 total_modes++;
289 } 289 }
290 } 290 }
291 if (total_modes == 0) { 291 if (total_modes == 0) {
292 SDL_SetError ("No linear video modes available"); 292 SDL_SetError("No linear video modes available");
293 return -1; 293 return -1;
294 } 294 }
295 295
296 /* Fill in our hardware acceleration capabilities */ 296 /* Fill in our hardware acceleration capabilities */
297 VGL_UpdateVideoInfo (this); 297 VGL_UpdateVideoInfo(this);
298 298
299 /* Create the hardware surface lock mutex */ 299 /* Create the hardware surface lock mutex */
300 hw_lock = SDL_CreateMutex (); 300 hw_lock = SDL_CreateMutex();
301 if (hw_lock == NULL) { 301 if (hw_lock == NULL) {
302 SDL_SetError ("Unable to create lock mutex"); 302 SDL_SetError("Unable to create lock mutex");
303 VGL_VideoQuit (this); 303 VGL_VideoQuit(this);
304 return -1; 304 return -1;
305 } 305 }
306 306
307 /* We're done! */ 307 /* We're done! */
308 return 0; 308 return 0;
309 } 309 }
310 310
311 SDL_Rect ** 311 SDL_Rect **
312 VGL_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 312 VGL_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
313 { 313 {
314 return SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]; 314 return SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
315 } 315 }
316 316
317 /* Various screen update functions available */ 317 /* Various screen update functions available */
318 static void VGL_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); 318 static void VGL_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
319 static void VGL_BankedUpdate (_THIS, int numrects, SDL_Rect * rects); 319 static void VGL_BankedUpdate(_THIS, int numrects, SDL_Rect * rects);
320 320
321 SDL_Surface * 321 SDL_Surface *
322 VGL_SetVideoMode (_THIS, SDL_Surface * current, 322 VGL_SetVideoMode(_THIS, SDL_Surface * current,
323 int width, int height, int bpp, Uint32 flags) 323 int width, int height, int bpp, Uint32 flags)
324 { 324 {
325 int mode_found; 325 int mode_found;
326 int i; 326 int i;
327 VGLMode **modes; 327 VGLMode **modes;
328 328
329 modes = VGLListModes (bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED); 329 modes = VGLListModes(bpp, V_INFO_MM_DIRECT | V_INFO_MM_PACKED);
330 mode_found = 0; 330 mode_found = 0;
331 for (i = 0; modes[i] != NULL; i++) { 331 for (i = 0; modes[i] != NULL; i++) {
332 if ((modes[i]->ModeInfo.Xsize == width) && 332 if ((modes[i]->ModeInfo.Xsize == width) &&
333 (modes[i]->ModeInfo.Ysize == height) && 333 (modes[i]->ModeInfo.Ysize == height) &&
334 ((modes[i]->ModeInfo.Type == VIDBUF8) || 334 ((modes[i]->ModeInfo.Type == VIDBUF8) ||
337 mode_found = 1; 337 mode_found = 1;
338 break; 338 break;
339 } 339 }
340 } 340 }
341 if (mode_found == 0) { 341 if (mode_found == 0) {
342 SDL_SetError ("No matching video mode found"); 342 SDL_SetError("No matching video mode found");
343 return NULL; 343 return NULL;
344 } 344 }
345 345
346 /* Shutdown previous videomode (if any) */ 346 /* Shutdown previous videomode (if any) */
347 if (VGLCurMode != NULL) 347 if (VGLCurMode != NULL)
348 VGLEnd (); 348 VGLEnd();
349 349
350 /* Try to set the requested linear video mode */ 350 /* Try to set the requested linear video mode */
351 if (VGLInit (modes[i]->ModeId) != 0) { 351 if (VGLInit(modes[i]->ModeId) != 0) {
352 SDL_SetError ("Unable to switch to requested mode"); 352 SDL_SetError("Unable to switch to requested mode");
353 return NULL; 353 return NULL;
354 } 354 }
355 355
356 VGLCurMode = SDL_realloc (VGLCurMode, sizeof (VGLMode)); 356 VGLCurMode = SDL_realloc(VGLCurMode, sizeof(VGLMode));
357 VGLCurMode->ModeInfo = *VGLDisplay; 357 VGLCurMode->ModeInfo = *VGLDisplay;
358 VGLCurMode->Depth = modes[i]->Depth; 358 VGLCurMode->Depth = modes[i]->Depth;
359 VGLCurMode->ModeId = modes[i]->ModeId; 359 VGLCurMode->ModeId = modes[i]->ModeId;
360 VGLCurMode->Rmask = modes[i]->Rmask; 360 VGLCurMode->Rmask = modes[i]->Rmask;
361 VGLCurMode->Gmask = modes[i]->Gmask; 361 VGLCurMode->Gmask = modes[i]->Gmask;
382 current->flags |= SDL_DOUBLEBUF; 382 current->flags |= SDL_DOUBLEBUF;
383 flip_page = 0; 383 flip_page = 0;
384 flip_address[0] = (byte *) current->pixels; 384 flip_address[0] = (byte *) current->pixels;
385 flip_address[1] = (byte *) current->pixels + 385 flip_address[1] = (byte *) current->pixels +
386 current->h * current->pitch; 386 current->h * current->pitch;
387 VGL_FlipHWSurface (this, current); 387 VGL_FlipHWSurface(this, current);
388 } 388 }
389 } 389 }
390 390
391 if (!SDL_ReallocFormat (current, modes[i]->Depth, VGLCurMode->Rmask, 391 if (!SDL_ReallocFormat(current, modes[i]->Depth, VGLCurMode->Rmask,
392 VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) { 392 VGLCurMode->Gmask, VGLCurMode->Bmask, 0)) {
393 return NULL; 393 return NULL;
394 } 394 }
395 395
396 /* Update hardware acceleration info */ 396 /* Update hardware acceleration info */
397 VGL_UpdateVideoInfo (this); 397 VGL_UpdateVideoInfo(this);
398 398
399 /* Set the blit function */ 399 /* Set the blit function */
400 this->UpdateRects = VGL_DirectUpdate; 400 this->UpdateRects = VGL_DirectUpdate;
401 401
402 /* We're done */ 402 /* We're done */
403 return current; 403 return current;
404 } 404 }
405 405
406 /* We don't actually allow hardware surfaces other than the main one */ 406 /* We don't actually allow hardware surfaces other than the main one */
407 static int 407 static int
408 VGL_AllocHWSurface (_THIS, SDL_Surface * surface) 408 VGL_AllocHWSurface(_THIS, SDL_Surface * surface)
409 { 409 {
410 return -1; 410 return -1;
411 } 411 }
412 static void 412 static void
413 VGL_FreeHWSurface (_THIS, SDL_Surface * surface) 413 VGL_FreeHWSurface(_THIS, SDL_Surface * surface)
414 { 414 {
415 return; 415 return;
416 } 416 }
417 417
418 /* We need to wait for vertical retrace on page flipped displays */ 418 /* We need to wait for vertical retrace on page flipped displays */
419 static int 419 static int
420 VGL_LockHWSurface (_THIS, SDL_Surface * surface) 420 VGL_LockHWSurface(_THIS, SDL_Surface * surface)
421 { 421 {
422 if (surface == SDL_VideoSurface) { 422 if (surface == SDL_VideoSurface) {
423 SDL_mutexP (hw_lock); 423 SDL_mutexP(hw_lock);
424 } 424 }
425 return 0; 425 return 0;
426 } 426 }
427 static void 427 static void
428 VGL_UnlockHWSurface (_THIS, SDL_Surface * surface) 428 VGL_UnlockHWSurface(_THIS, SDL_Surface * surface)
429 { 429 {
430 if (surface == SDL_VideoSurface) { 430 if (surface == SDL_VideoSurface) {
431 SDL_mutexV (hw_lock); 431 SDL_mutexV(hw_lock);
432 } 432 }
433 } 433 }
434 434
435 static int 435 static int
436 VGL_FlipHWSurface (_THIS, SDL_Surface * surface) 436 VGL_FlipHWSurface(_THIS, SDL_Surface * surface)
437 { 437 {
438 // VGLWaitRetrace(); 438 // VGLWaitRetrace();
439 if (VGLPanScreen (VGLDisplay, 0, flip_page * surface->h) < 0) { 439 if (VGLPanScreen(VGLDisplay, 0, flip_page * surface->h) < 0) {
440 SDL_SetError ("VGLPanSreen() failed"); 440 SDL_SetError("VGLPanSreen() failed");
441 return -1; 441 return -1;
442 } 442 }
443 443
444 flip_page = !flip_page; 444 flip_page = !flip_page;
445 surface->pixels = flip_address[flip_page]; 445 surface->pixels = flip_address[flip_page];
446 446
447 return 0; 447 return 0;
448 } 448 }
449 449
450 static void 450 static void
451 VGL_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) 451 VGL_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
452 { 452 {
453 return; 453 return;
454 } 454 }
455 455
456 static void 456 static void
457 VGL_BankedUpdate (_THIS, int numrects, SDL_Rect * rects) 457 VGL_BankedUpdate(_THIS, int numrects, SDL_Rect * rects)
458 { 458 {
459 return; 459 return;
460 } 460 }
461 461
462 int 462 int
463 VGL_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 463 VGL_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
464 { 464 {
465 int i; 465 int i;
466 466
467 for (i = 0; i < ncolors; i++) { 467 for (i = 0; i < ncolors; i++) {
468 VGLSetPaletteIndex (firstcolor + i, 468 VGLSetPaletteIndex(firstcolor + i,
469 colors[i].r >> 2, 469 colors[i].r >> 2,
470 colors[i].g >> 2, colors[i].b >> 2); 470 colors[i].g >> 2, colors[i].b >> 2);
471 } 471 }
472 return 1; 472 return 1;
473 } 473 }
474 474
475 /* Note: If we are terminated, this could be called in the middle of 475 /* Note: If we are terminated, this could be called in the middle of
476 another SDL video routine -- notably UpdateRects. 476 another SDL video routine -- notably UpdateRects.
477 */ 477 */
478 void 478 void
479 VGL_VideoQuit (_THIS) 479 VGL_VideoQuit(_THIS)
480 { 480 {
481 int i, j; 481 int i, j;
482 482
483 /* Return the keyboard to the normal state */ 483 /* Return the keyboard to the normal state */
484 VGLKeyboardEnd (); 484 VGLKeyboardEnd();
485 485
486 /* Reset the console video mode if we actually initialised one */ 486 /* Reset the console video mode if we actually initialised one */
487 if (VGLCurMode != NULL) { 487 if (VGLCurMode != NULL) {
488 VGLEnd (); 488 VGLEnd();
489 SDL_free (VGLCurMode); 489 SDL_free(VGLCurMode);
490 VGLCurMode = NULL; 490 VGLCurMode = NULL;
491 } 491 }
492 492
493 /* Clear the lock mutex */ 493 /* Clear the lock mutex */
494 if (hw_lock != NULL) { 494 if (hw_lock != NULL) {
495 SDL_DestroyMutex (hw_lock); 495 SDL_DestroyMutex(hw_lock);
496 hw_lock = NULL; 496 hw_lock = NULL;
497 } 497 }
498 498
499 /* Free video mode lists */ 499 /* Free video mode lists */
500 for (i = 0; i < NUM_MODELISTS; i++) { 500 for (i = 0; i < NUM_MODELISTS; i++) {
501 if (SDL_modelist[i] != NULL) { 501 if (SDL_modelist[i] != NULL) {
502 for (j = 0; SDL_modelist[i][j] != NULL; ++j) { 502 for (j = 0; SDL_modelist[i][j] != NULL; ++j) {
503 SDL_free (SDL_modelist[i][j]); 503 SDL_free(SDL_modelist[i][j]);
504 } 504 }
505 SDL_free (SDL_modelist[i]); 505 SDL_free(SDL_modelist[i]);
506 SDL_modelist[i] = NULL; 506 SDL_modelist[i] = NULL;
507 } 507 }
508 } 508 }
509 509
510 if (this->screen && (this->screen->flags & SDL_HWSURFACE)) { 510 if (this->screen && (this->screen->flags & SDL_HWSURFACE)) {
516 #define VGL_RED_INDEX 0 516 #define VGL_RED_INDEX 0
517 #define VGL_GREEN_INDEX 1 517 #define VGL_GREEN_INDEX 1
518 #define VGL_BLUE_INDEX 2 518 #define VGL_BLUE_INDEX 2
519 519
520 static VGLMode ** 520 static VGLMode **
521 VGLListModes (int depth, int mem_model) 521 VGLListModes(int depth, int mem_model)
522 { 522 {
523 static VGLMode **modes = NULL; 523 static VGLMode **modes = NULL;
524 524
525 VGLBitmap *vminfop; 525 VGLBitmap *vminfop;
526 VGLMode **modesp, *modescp; 526 VGLMode **modesp, *modescp;
527 video_info_t minfo; 527 video_info_t minfo;
528 int adptype, i, modenum; 528 int adptype, i, modenum;
529 529
530 if (modes == NULL) { 530 if (modes == NULL) {
531 modes = SDL_malloc (sizeof (VGLMode *) * M_VESA_MODE_MAX); 531 modes = SDL_malloc(sizeof(VGLMode *) * M_VESA_MODE_MAX);
532 bzero (modes, sizeof (VGLMode *) * M_VESA_MODE_MAX); 532 bzero(modes, sizeof(VGLMode *) * M_VESA_MODE_MAX);
533 } 533 }
534 modesp = modes; 534 modesp = modes;
535 535
536 for (modenum = 0; modenum < M_VESA_MODE_MAX; modenum++) { 536 for (modenum = 0; modenum < M_VESA_MODE_MAX; modenum++) {
537 minfo.vi_mode = modenum; 537 minfo.vi_mode = modenum;
538 if (ioctl (0, CONS_MODEINFO, &minfo) 538 if (ioctl(0, CONS_MODEINFO, &minfo)
539 || ioctl (0, CONS_CURRENT, &adptype)) 539 || ioctl(0, CONS_CURRENT, &adptype))
540 continue; 540 continue;
541 if (minfo.vi_mode != modenum) 541 if (minfo.vi_mode != modenum)
542 continue; 542 continue;
543 if ((minfo.vi_flags & V_INFO_GRAPHICS) == 0) 543 if ((minfo.vi_flags & V_INFO_GRAPHICS) == 0)
544 continue; 544 continue;
546 continue; 546 continue;
547 if ((depth > 1) && (minfo.vi_depth != depth)) 547 if ((depth > 1) && (minfo.vi_depth != depth))
548 continue; 548 continue;
549 549
550 /* reallocf can fail */ 550 /* reallocf can fail */
551 if ((*modesp = reallocf (*modesp, sizeof (VGLMode))) == NULL) 551 if ((*modesp = reallocf(*modesp, sizeof(VGLMode))) == NULL)
552 return NULL; 552 return NULL;
553 modescp = *modesp; 553 modescp = *modesp;
554 554
555 vminfop = &(modescp->ModeInfo); 555 vminfop = &(modescp->ModeInfo);
556 bzero (vminfop, sizeof (VGLBitmap)); 556 bzero(vminfop, sizeof(VGLBitmap));
557 557
558 vminfop->Type = NOBUF; 558 vminfop->Type = NOBUF;
559 559
560 vminfop->PixelBytes = 1; /* Good default value */ 560 vminfop->PixelBytes = 1; /* Good default value */
561 switch (minfo.vi_mem_model) { 561 switch (minfo.vi_mem_model) {
620 vminfop->Ysize = minfo.vi_height; 620 vminfop->Ysize = minfo.vi_height;
621 modescp->Depth = minfo.vi_depth; 621 modescp->Depth = minfo.vi_depth;
622 622
623 /* XXX */ 623 /* XXX */
624 if (minfo.vi_mode >= M_VESA_BASE) 624 if (minfo.vi_mode >= M_VESA_BASE)
625 modescp->ModeId = _IO ('V', minfo.vi_mode - M_VESA_BASE); 625 modescp->ModeId = _IO('V', minfo.vi_mode - M_VESA_BASE);
626 else 626 else
627 modescp->ModeId = _IO ('S', minfo.vi_mode); 627 modescp->ModeId = _IO('S', minfo.vi_mode);
628 628
629 /* Sort list */ 629 /* Sort list */
630 for (i = 0; modes + i < modesp; i++) { 630 for (i = 0; modes + i < modesp; i++) {
631 if (modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize > 631 if (modes[i]->ModeInfo.Xsize * modes[i]->ModeInfo.Ysize >
632 vminfop->Xsize * modes[i]->ModeInfo.Ysize) 632 vminfop->Xsize * modes[i]->ModeInfo.Ysize)
643 643
644 modesp++; 644 modesp++;
645 } 645 }
646 646
647 if (*modesp != NULL) { 647 if (*modesp != NULL) {
648 SDL_free (*modesp); 648 SDL_free(*modesp);
649 *modesp = NULL; 649 *modesp = NULL;
650 } 650 }
651 651
652 return modes; 652 return modes;
653 } 653 }
654 654
655 static void 655 static void
656 VGLWaitRetrace (void) 656 VGLWaitRetrace(void)
657 { 657 {
658 while (!(inb (0x3DA) & 8)); 658 while (!(inb(0x3DA) & 8));
659 while (inb (0x3DA) & 8); 659 while (inb(0x3DA) & 8);
660 } 660 }
661 661
662 /* vi: set ts=4 sw=4 expandtab: */ 662 /* vi: set ts=4 sw=4 expandtab: */