comparison src/video/fbcon/SDL_fbvideo.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
146 1600, 1200, /*? */ 0, 272, 48, 32, 5, 152, 5, 0, 0}, /* 60 Hz */ 146 1600, 1200, /*? */ 0, 272, 48, 32, 5, 152, 5, 0, 0}, /* 60 Hz */
147 #endif 147 #endif
148 }; 148 };
149 149
150 /* Initialization/Query functions */ 150 /* Initialization/Query functions */
151 static int FB_VideoInit (_THIS, SDL_PixelFormat * vformat); 151 static int FB_VideoInit(_THIS, SDL_PixelFormat * vformat);
152 static SDL_Rect **FB_ListModes (_THIS, SDL_PixelFormat * format, 152 static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags);
153 Uint32 flags); 153 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface * current, int width,
154 static SDL_Surface *FB_SetVideoMode (_THIS, SDL_Surface * current, int width, 154 int height, int bpp, Uint32 flags);
155 int height, int bpp, Uint32 flags);
156 #ifdef VGA16_FBCON_SUPPORT 155 #ifdef VGA16_FBCON_SUPPORT
157 static SDL_Surface *FB_SetVGA16Mode (_THIS, SDL_Surface * current, int width, 156 static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface * current, int width,
158 int height, int bpp, Uint32 flags); 157 int height, int bpp, Uint32 flags);
159 #endif 158 #endif
160 static int FB_SetColors (_THIS, int firstcolor, int ncolors, 159 static int FB_SetColors(_THIS, int firstcolor, int ncolors,
161 SDL_Color * colors); 160 SDL_Color * colors);
162 static void FB_VideoQuit (_THIS); 161 static void FB_VideoQuit(_THIS);
163 162
164 /* Hardware surface functions */ 163 /* Hardware surface functions */
165 static int FB_InitHWSurfaces (_THIS, SDL_Surface * screen, char *base, 164 static int FB_InitHWSurfaces(_THIS, SDL_Surface * screen, char *base,
166 int size); 165 int size);
167 static void FB_FreeHWSurfaces (_THIS); 166 static void FB_FreeHWSurfaces(_THIS);
168 static int FB_AllocHWSurface (_THIS, SDL_Surface * surface); 167 static int FB_AllocHWSurface(_THIS, SDL_Surface * surface);
169 static int FB_LockHWSurface (_THIS, SDL_Surface * surface); 168 static int FB_LockHWSurface(_THIS, SDL_Surface * surface);
170 static void FB_UnlockHWSurface (_THIS, SDL_Surface * surface); 169 static void FB_UnlockHWSurface(_THIS, SDL_Surface * surface);
171 static void FB_FreeHWSurface (_THIS, SDL_Surface * surface); 170 static void FB_FreeHWSurface(_THIS, SDL_Surface * surface);
172 static void FB_WaitVBL (_THIS); 171 static void FB_WaitVBL(_THIS);
173 static void FB_WaitIdle (_THIS); 172 static void FB_WaitIdle(_THIS);
174 static int FB_FlipHWSurface (_THIS, SDL_Surface * surface); 173 static int FB_FlipHWSurface(_THIS, SDL_Surface * surface);
175 174
176 /* Internal palette functions */ 175 /* Internal palette functions */
177 static void FB_SavePalette (_THIS, struct fb_fix_screeninfo *finfo, 176 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,
178 struct fb_var_screeninfo *vinfo); 177 struct fb_var_screeninfo *vinfo);
179 static void FB_RestorePalette (_THIS); 178 static void FB_RestorePalette(_THIS);
180 179
181 /* Small wrapper for mmap() so we can play nicely with no-mmu hosts 180 /* Small wrapper for mmap() so we can play nicely with no-mmu hosts
182 * (non-mmu hosts disallow the MAP_SHARED flag) */ 181 * (non-mmu hosts disallow the MAP_SHARED flag) */
183 182
184 static void * 183 static void *
185 do_mmap (void *start, size_t length, int prot, int flags, int fd, 184 do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
186 off_t offset)
187 { 185 {
188 void *ret; 186 void *ret;
189 ret = mmap (start, length, prot, flags, fd, offset); 187 ret = mmap(start, length, prot, flags, fd, offset);
190 if (ret == (char *) -1 && (flags & MAP_SHARED)) { 188 if (ret == (char *) -1 && (flags & MAP_SHARED)) {
191 ret = mmap (start, length, prot, 189 ret = mmap(start, length, prot,
192 (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset); 190 (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
193 } 191 }
194 return ret; 192 return ret;
195 } 193 }
196 194
197 /* FB driver bootstrap functions */ 195 /* FB driver bootstrap functions */
198 196
199 static int 197 static int
200 FB_Available (void) 198 FB_Available(void)
201 { 199 {
202 int console = -1; 200 int console = -1;
203 /* Added check for /fb/0 (devfs) */ 201 /* Added check for /fb/0 (devfs) */
204 /* but - use environment variable first... if it fails, still check defaults */ 202 /* but - use environment variable first... if it fails, still check defaults */
205 int idx = 0; 203 int idx = 0;
206 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL }; 204 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL };
207 205
208 SDL_fbdevs[0] = SDL_getenv ("SDL_FBDEV"); 206 SDL_fbdevs[0] = SDL_getenv("SDL_FBDEV");
209 if (!SDL_fbdevs[0]) 207 if (!SDL_fbdevs[0])
210 idx++; 208 idx++;
211 for (; SDL_fbdevs[idx]; idx++) { 209 for (; SDL_fbdevs[idx]; idx++) {
212 console = open (SDL_fbdevs[idx], O_RDWR, 0); 210 console = open(SDL_fbdevs[idx], O_RDWR, 0);
213 if (console >= 0) { 211 if (console >= 0) {
214 close (console); 212 close(console);
215 break; 213 break;
216 } 214 }
217 } 215 }
218 return (console >= 0); 216 return (console >= 0);
219 } 217 }
220 218
221 static void 219 static void
222 FB_DeleteDevice (SDL_VideoDevice * device) 220 FB_DeleteDevice(SDL_VideoDevice * device)
223 { 221 {
224 SDL_free (device->hidden); 222 SDL_free(device->hidden);
225 SDL_free (device); 223 SDL_free(device);
226 } 224 }
227 225
228 static SDL_VideoDevice * 226 static SDL_VideoDevice *
229 FB_CreateDevice (int devindex) 227 FB_CreateDevice(int devindex)
230 { 228 {
231 SDL_VideoDevice *this; 229 SDL_VideoDevice *this;
232 230
233 /* Initialize all variables that we clean on shutdown */ 231 /* Initialize all variables that we clean on shutdown */
234 this = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 232 this = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
235 if (this) { 233 if (this) {
236 SDL_memset (this, 0, (sizeof *this)); 234 SDL_memset(this, 0, (sizeof *this));
237 this->hidden = (struct SDL_PrivateVideoData *) 235 this->hidden = (struct SDL_PrivateVideoData *)
238 SDL_malloc ((sizeof *this->hidden)); 236 SDL_malloc((sizeof *this->hidden));
239 } 237 }
240 if ((this == NULL) || (this->hidden == NULL)) { 238 if ((this == NULL) || (this->hidden == NULL)) {
241 SDL_OutOfMemory (); 239 SDL_OutOfMemory();
242 if (this) { 240 if (this) {
243 SDL_free (this); 241 SDL_free(this);
244 } 242 }
245 return (0); 243 return (0);
246 } 244 }
247 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 245 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
248 wait_vbl = FB_WaitVBL; 246 wait_vbl = FB_WaitVBL;
249 wait_idle = FB_WaitIdle; 247 wait_idle = FB_WaitIdle;
250 mouse_fd = -1; 248 mouse_fd = -1;
251 keyboard_fd = -1; 249 keyboard_fd = -1;
252 250
285 }; 283 };
286 284
287 #define FB_MODES_DB "/etc/fb.modes" 285 #define FB_MODES_DB "/etc/fb.modes"
288 286
289 static int 287 static int
290 read_fbmodes_line (FILE * f, char *line, int length) 288 read_fbmodes_line(FILE * f, char *line, int length)
291 { 289 {
292 int blank; 290 int blank;
293 char *c; 291 char *c;
294 int i; 292 int i;
295 293
296 blank = 0; 294 blank = 0;
297 /* find a relevant line */ 295 /* find a relevant line */
298 do { 296 do {
299 if (fgets (line, length, f) <= 0) 297 if (fgets(line, length, f) <= 0)
300 return 0; 298 return 0;
301 c = line; 299 c = line;
302 while (((*c == '\t') || (*c == ' ')) && (*c != 0)) 300 while (((*c == '\t') || (*c == ' ')) && (*c != 0))
303 c++; 301 c++;
304 302
317 while (c[i] != 0); 315 while (c[i] != 0);
318 return 1; 316 return 1;
319 } 317 }
320 318
321 static int 319 static int
322 read_fbmodes_mode (FILE * f, struct fb_var_screeninfo *vinfo) 320 read_fbmodes_mode(FILE * f, struct fb_var_screeninfo *vinfo)
323 { 321 {
324 char line[1024]; 322 char line[1024];
325 char option[256]; 323 char option[256];
326 324
327 /* Find a "geometry" */ 325 /* Find a "geometry" */
328 do { 326 do {
329 if (read_fbmodes_line (f, line, sizeof (line)) == 0) 327 if (read_fbmodes_line(f, line, sizeof(line)) == 0)
330 return 0; 328 return 0;
331 if (SDL_strncmp (line, "geometry", 8) == 0) 329 if (SDL_strncmp(line, "geometry", 8) == 0)
332 break; 330 break;
333 } 331 }
334 while (1); 332 while (1);
335 333
336 SDL_sscanf (line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres, 334 SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres,
337 &vinfo->xres_virtual, &vinfo->yres_virtual, 335 &vinfo->xres_virtual, &vinfo->yres_virtual,
338 &vinfo->bits_per_pixel); 336 &vinfo->bits_per_pixel);
339 if (read_fbmodes_line (f, line, sizeof (line)) == 0) 337 if (read_fbmodes_line(f, line, sizeof(line)) == 0)
340 return 0; 338 return 0;
341 339
342 SDL_sscanf (line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock, 340 SDL_sscanf(line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock,
343 &vinfo->left_margin, &vinfo->right_margin, 341 &vinfo->left_margin, &vinfo->right_margin,
344 &vinfo->upper_margin, &vinfo->lower_margin, &vinfo->hsync_len, 342 &vinfo->upper_margin, &vinfo->lower_margin, &vinfo->hsync_len,
345 &vinfo->vsync_len); 343 &vinfo->vsync_len);
346 344
347 vinfo->sync = 0; 345 vinfo->sync = 0;
348 vinfo->vmode = FB_VMODE_NONINTERLACED; 346 vinfo->vmode = FB_VMODE_NONINTERLACED;
349 347
350 /* Parse misc options */ 348 /* Parse misc options */
351 do { 349 do {
352 if (read_fbmodes_line (f, line, sizeof (line)) == 0) 350 if (read_fbmodes_line(f, line, sizeof(line)) == 0)
353 return 0; 351 return 0;
354 352
355 if (SDL_strncmp (line, "hsync", 5) == 0) { 353 if (SDL_strncmp(line, "hsync", 5) == 0) {
356 SDL_sscanf (line, "hsync %s", option); 354 SDL_sscanf(line, "hsync %s", option);
357 if (SDL_strncmp (option, "high", 4) == 0) 355 if (SDL_strncmp(option, "high", 4) == 0)
358 vinfo->sync |= FB_SYNC_HOR_HIGH_ACT; 356 vinfo->sync |= FB_SYNC_HOR_HIGH_ACT;
359 } else if (SDL_strncmp (line, "vsync", 5) == 0) { 357 } else if (SDL_strncmp(line, "vsync", 5) == 0) {
360 SDL_sscanf (line, "vsync %s", option); 358 SDL_sscanf(line, "vsync %s", option);
361 if (SDL_strncmp (option, "high", 4) == 0) 359 if (SDL_strncmp(option, "high", 4) == 0)
362 vinfo->sync |= FB_SYNC_VERT_HIGH_ACT; 360 vinfo->sync |= FB_SYNC_VERT_HIGH_ACT;
363 } else if (SDL_strncmp (line, "csync", 5) == 0) { 361 } else if (SDL_strncmp(line, "csync", 5) == 0) {
364 SDL_sscanf (line, "csync %s", option); 362 SDL_sscanf(line, "csync %s", option);
365 if (SDL_strncmp (option, "high", 4) == 0) 363 if (SDL_strncmp(option, "high", 4) == 0)
366 vinfo->sync |= FB_SYNC_COMP_HIGH_ACT; 364 vinfo->sync |= FB_SYNC_COMP_HIGH_ACT;
367 } else if (SDL_strncmp (line, "extsync", 5) == 0) { 365 } else if (SDL_strncmp(line, "extsync", 5) == 0) {
368 SDL_sscanf (line, "extsync %s", option); 366 SDL_sscanf(line, "extsync %s", option);
369 if (SDL_strncmp (option, "true", 4) == 0) 367 if (SDL_strncmp(option, "true", 4) == 0)
370 vinfo->sync |= FB_SYNC_EXT; 368 vinfo->sync |= FB_SYNC_EXT;
371 } else if (SDL_strncmp (line, "laced", 5) == 0) { 369 } else if (SDL_strncmp(line, "laced", 5) == 0) {
372 SDL_sscanf (line, "laced %s", option); 370 SDL_sscanf(line, "laced %s", option);
373 if (SDL_strncmp (option, "true", 4) == 0) 371 if (SDL_strncmp(option, "true", 4) == 0)
374 vinfo->vmode |= FB_VMODE_INTERLACED; 372 vinfo->vmode |= FB_VMODE_INTERLACED;
375 } else if (SDL_strncmp (line, "double", 6) == 0) { 373 } else if (SDL_strncmp(line, "double", 6) == 0) {
376 SDL_sscanf (line, "double %s", option); 374 SDL_sscanf(line, "double %s", option);
377 if (SDL_strncmp (option, "true", 4) == 0) 375 if (SDL_strncmp(option, "true", 4) == 0)
378 vinfo->vmode |= FB_VMODE_DOUBLE; 376 vinfo->vmode |= FB_VMODE_DOUBLE;
379 } 377 }
380 } 378 }
381 while (SDL_strncmp (line, "endmode", 7) != 0); 379 while (SDL_strncmp(line, "endmode", 7) != 0);
382 380
383 return 1; 381 return 1;
384 } 382 }
385 383
386 static int 384 static int
387 FB_CheckMode (_THIS, struct fb_var_screeninfo *vinfo, 385 FB_CheckMode(_THIS, struct fb_var_screeninfo *vinfo,
388 int index, unsigned int *w, unsigned int *h) 386 int index, unsigned int *w, unsigned int *h)
389 { 387 {
390 int mode_okay; 388 int mode_okay;
391 389
392 mode_okay = 0; 390 mode_okay = 0;
393 vinfo->bits_per_pixel = (index + 1) * 8; 391 vinfo->bits_per_pixel = (index + 1) * 8;
394 vinfo->xres = *w; 392 vinfo->xres = *w;
395 vinfo->xres_virtual = *w; 393 vinfo->xres_virtual = *w;
396 vinfo->yres = *h; 394 vinfo->yres = *h;
397 vinfo->yres_virtual = *h; 395 vinfo->yres_virtual = *h;
398 vinfo->activate = FB_ACTIVATE_TEST; 396 vinfo->activate = FB_ACTIVATE_TEST;
399 if (ioctl (console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0) { 397 if (ioctl(console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0) {
400 #ifdef FBCON_DEBUG 398 #ifdef FBCON_DEBUG
401 fprintf (stderr, 399 fprintf(stderr,
402 "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n", 400 "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n",
403 *w, *h, (index + 1) * 8, vinfo->xres, vinfo->yres, 401 *w, *h, (index + 1) * 8, vinfo->xres, vinfo->yres,
404 vinfo->bits_per_pixel); 402 vinfo->bits_per_pixel);
405 #endif 403 #endif
406 if ((((vinfo->bits_per_pixel + 7) / 8) - 1) == index) { 404 if ((((vinfo->bits_per_pixel + 7) / 8) - 1) == index) {
407 *w = vinfo->xres; 405 *w = vinfo->xres;
408 *h = vinfo->yres; 406 *h = vinfo->yres;
409 mode_okay = 1; 407 mode_okay = 1;
411 } 409 }
412 return mode_okay; 410 return mode_okay;
413 } 411 }
414 412
415 static int 413 static int
416 FB_AddMode (_THIS, int index, unsigned int w, unsigned int h, 414 FB_AddMode(_THIS, int index, unsigned int w, unsigned int h,
417 int check_timings) 415 int check_timings)
418 { 416 {
419 SDL_Rect *mode; 417 SDL_Rect *mode;
420 int i; 418 int i;
421 int next_mode; 419 int next_mode;
422 420
423 /* Check to see if we already have this mode */ 421 /* Check to see if we already have this mode */
424 if (SDL_nummodes[index] > 0) { 422 if (SDL_nummodes[index] > 0) {
425 mode = SDL_modelist[index][SDL_nummodes[index] - 1]; 423 mode = SDL_modelist[index][SDL_nummodes[index] - 1];
426 if ((mode->w == w) && (mode->h == h)) { 424 if ((mode->w == w) && (mode->h == h)) {
427 #ifdef FBCON_DEBUG 425 #ifdef FBCON_DEBUG
428 fprintf (stderr, 426 fprintf(stderr,
429 "We already have mode %dx%d at %d bytes per pixel\n", 427 "We already have mode %dx%d at %d bytes per pixel\n",
430 w, h, index + 1); 428 w, h, index + 1);
431 #endif 429 #endif
432 return (0); 430 return (0);
433 } 431 }
434 } 432 }
435 433
436 /* Only allow a mode if we have a valid timing for it */ 434 /* Only allow a mode if we have a valid timing for it */
437 if (check_timings) { 435 if (check_timings) {
438 int found_timing = 0; 436 int found_timing = 0;
439 for (i = 0; i < (sizeof (vesa_timings) / sizeof (vesa_timings[0])); 437 for (i = 0; i < (sizeof(vesa_timings) / sizeof(vesa_timings[0])); ++i) {
440 ++i) {
441 if ((w == vesa_timings[i].xres) && 438 if ((w == vesa_timings[i].xres) &&
442 (h == vesa_timings[i].yres) && vesa_timings[i].pixclock) { 439 (h == vesa_timings[i].yres) && vesa_timings[i].pixclock) {
443 found_timing = 1; 440 found_timing = 1;
444 break; 441 break;
445 } 442 }
446 } 443 }
447 if (!found_timing) { 444 if (!found_timing) {
448 #ifdef FBCON_DEBUG 445 #ifdef FBCON_DEBUG
449 fprintf (stderr, "No valid timing line for mode %dx%d\n", w, h); 446 fprintf(stderr, "No valid timing line for mode %dx%d\n", w, h);
450 #endif 447 #endif
451 return (0); 448 return (0);
452 } 449 }
453 } 450 }
454 451
455 /* Set up the new video mode rectangle */ 452 /* Set up the new video mode rectangle */
456 mode = (SDL_Rect *) SDL_malloc (sizeof *mode); 453 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
457 if (mode == NULL) { 454 if (mode == NULL) {
458 SDL_OutOfMemory (); 455 SDL_OutOfMemory();
459 return (-1); 456 return (-1);
460 } 457 }
461 mode->x = 0; 458 mode->x = 0;
462 mode->y = 0; 459 mode->y = 0;
463 mode->w = w; 460 mode->w = w;
464 mode->h = h; 461 mode->h = h;
465 #ifdef FBCON_DEBUG 462 #ifdef FBCON_DEBUG
466 fprintf (stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, 463 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h,
467 index + 1); 464 index + 1);
468 #endif 465 #endif
469 466
470 /* Allocate the new list of modes, and fill in the new mode */ 467 /* Allocate the new list of modes, and fill in the new mode */
471 next_mode = SDL_nummodes[index]; 468 next_mode = SDL_nummodes[index];
472 SDL_modelist[index] = (SDL_Rect **) 469 SDL_modelist[index] = (SDL_Rect **)
473 SDL_realloc (SDL_modelist[index], 470 SDL_realloc(SDL_modelist[index],
474 (1 + next_mode + 1) * sizeof (SDL_Rect *)); 471 (1 + next_mode + 1) * sizeof(SDL_Rect *));
475 if (SDL_modelist[index] == NULL) { 472 if (SDL_modelist[index] == NULL) {
476 SDL_OutOfMemory (); 473 SDL_OutOfMemory();
477 SDL_nummodes[index] = 0; 474 SDL_nummodes[index] = 0;
478 SDL_free (mode); 475 SDL_free(mode);
479 return (-1); 476 return (-1);
480 } 477 }
481 SDL_modelist[index][next_mode] = mode; 478 SDL_modelist[index][next_mode] = mode;
482 SDL_modelist[index][next_mode + 1] = NULL; 479 SDL_modelist[index][next_mode + 1] = NULL;
483 SDL_nummodes[index]++; 480 SDL_nummodes[index]++;
484 481
485 return (0); 482 return (0);
486 } 483 }
487 484
488 static int 485 static int
489 cmpmodes (const void *va, const void *vb) 486 cmpmodes(const void *va, const void *vb)
490 { 487 {
491 const SDL_Rect *a = *(const SDL_Rect **) va; 488 const SDL_Rect *a = *(const SDL_Rect **) va;
492 const SDL_Rect *b = *(const SDL_Rect **) vb; 489 const SDL_Rect *b = *(const SDL_Rect **) vb;
493 if (a->h == b->h) 490 if (a->h == b->h)
494 return b->w - a->w; 491 return b->w - a->w;
495 else 492 else
496 return b->h - a->h; 493 return b->h - a->h;
497 } 494 }
498 495
499 static void 496 static void
500 FB_SortModes (_THIS) 497 FB_SortModes(_THIS)
501 { 498 {
502 int i; 499 int i;
503 for (i = 0; i < NUM_MODELISTS; ++i) { 500 for (i = 0; i < NUM_MODELISTS; ++i) {
504 if (SDL_nummodes[i] > 0) { 501 if (SDL_nummodes[i] > 0) {
505 SDL_qsort (SDL_modelist[i], SDL_nummodes[i], 502 SDL_qsort(SDL_modelist[i], SDL_nummodes[i],
506 sizeof *SDL_modelist[i], cmpmodes); 503 sizeof *SDL_modelist[i], cmpmodes);
507 } 504 }
508 } 505 }
509 } 506 }
510 507
511 static int 508 static int
512 FB_VideoInit (_THIS, SDL_PixelFormat * vformat) 509 FB_VideoInit(_THIS, SDL_PixelFormat * vformat)
513 { 510 {
514 struct fb_fix_screeninfo finfo; 511 struct fb_fix_screeninfo finfo;
515 struct fb_var_screeninfo vinfo; 512 struct fb_var_screeninfo vinfo;
516 int i, j; 513 int i, j;
517 int current_index; 514 int current_index;
519 unsigned int current_h; 516 unsigned int current_h;
520 const char *SDL_fbdev; 517 const char *SDL_fbdev;
521 FILE *modesdb; 518 FILE *modesdb;
522 519
523 /* Initialize the library */ 520 /* Initialize the library */
524 SDL_fbdev = SDL_getenv ("SDL_FBDEV"); 521 SDL_fbdev = SDL_getenv("SDL_FBDEV");
525 if (SDL_fbdev == NULL) { 522 if (SDL_fbdev == NULL) {
526 SDL_fbdev = "/dev/fb0"; 523 SDL_fbdev = "/dev/fb0";
527 } 524 }
528 console_fd = open (SDL_fbdev, O_RDWR, 0); 525 console_fd = open(SDL_fbdev, O_RDWR, 0);
529 if (console_fd < 0) { 526 if (console_fd < 0) {
530 SDL_SetError ("Unable to open %s", SDL_fbdev); 527 SDL_SetError("Unable to open %s", SDL_fbdev);
531 return (-1); 528 return (-1);
532 } 529 }
533 #if !SDL_THREADS_DISABLED 530 #if !SDL_THREADS_DISABLED
534 /* Create the hardware surface lock mutex */ 531 /* Create the hardware surface lock mutex */
535 hw_lock = SDL_CreateMutex (); 532 hw_lock = SDL_CreateMutex();
536 if (hw_lock == NULL) { 533 if (hw_lock == NULL) {
537 SDL_SetError ("Unable to create lock mutex"); 534 SDL_SetError("Unable to create lock mutex");
538 FB_VideoQuit (this); 535 FB_VideoQuit(this);
539 return (-1); 536 return (-1);
540 } 537 }
541 #endif 538 #endif
542 539
543 /* Get the type of video hardware */ 540 /* Get the type of video hardware */
544 if (ioctl (console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) { 541 if (ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
545 SDL_SetError ("Couldn't get console hardware info"); 542 SDL_SetError("Couldn't get console hardware info");
546 FB_VideoQuit (this); 543 FB_VideoQuit(this);
547 return (-1); 544 return (-1);
548 } 545 }
549 switch (finfo.type) { 546 switch (finfo.type) {
550 case FB_TYPE_PACKED_PIXELS: 547 case FB_TYPE_PACKED_PIXELS:
551 /* Supported, no worries.. */ 548 /* Supported, no worries.. */
552 break; 549 break;
553 #ifdef VGA16_FBCON_SUPPORT 550 #ifdef VGA16_FBCON_SUPPORT
554 case FB_TYPE_VGA_PLANES: 551 case FB_TYPE_VGA_PLANES:
555 /* VGA16 is supported, but that's it */ 552 /* VGA16 is supported, but that's it */
556 if (finfo.type_aux == FB_AUX_VGA_PLANES_VGA4) { 553 if (finfo.type_aux == FB_AUX_VGA_PLANES_VGA4) {
557 if (ioperm (0x3b4, 0x3df - 0x3b4 + 1, 1) < 0) { 554 if (ioperm(0x3b4, 0x3df - 0x3b4 + 1, 1) < 0) {
558 SDL_SetError ("No I/O port permissions"); 555 SDL_SetError("No I/O port permissions");
559 FB_VideoQuit (this); 556 FB_VideoQuit(this);
560 return (-1); 557 return (-1);
561 } 558 }
562 this->SetVideoMode = FB_SetVGA16Mode; 559 this->SetVideoMode = FB_SetVGA16Mode;
563 break; 560 break;
564 } 561 }
565 /* Fall through to unsupported case */ 562 /* Fall through to unsupported case */
566 #endif /* VGA16_FBCON_SUPPORT */ 563 #endif /* VGA16_FBCON_SUPPORT */
567 default: 564 default:
568 SDL_SetError ("Unsupported console hardware"); 565 SDL_SetError("Unsupported console hardware");
569 FB_VideoQuit (this); 566 FB_VideoQuit(this);
570 return (-1); 567 return (-1);
571 } 568 }
572 switch (finfo.visual) { 569 switch (finfo.visual) {
573 case FB_VISUAL_TRUECOLOR: 570 case FB_VISUAL_TRUECOLOR:
574 case FB_VISUAL_PSEUDOCOLOR: 571 case FB_VISUAL_PSEUDOCOLOR:
575 case FB_VISUAL_STATIC_PSEUDOCOLOR: 572 case FB_VISUAL_STATIC_PSEUDOCOLOR:
576 case FB_VISUAL_DIRECTCOLOR: 573 case FB_VISUAL_DIRECTCOLOR:
577 break; 574 break;
578 default: 575 default:
579 SDL_SetError ("Unsupported console hardware"); 576 SDL_SetError("Unsupported console hardware");
580 FB_VideoQuit (this); 577 FB_VideoQuit(this);
581 return (-1); 578 return (-1);
582 } 579 }
583 580
584 /* Check if the user wants to disable hardware acceleration */ 581 /* Check if the user wants to disable hardware acceleration */
585 { 582 {
586 const char *fb_accel; 583 const char *fb_accel;
587 fb_accel = SDL_getenv ("SDL_FBACCEL"); 584 fb_accel = SDL_getenv("SDL_FBACCEL");
588 if (fb_accel) { 585 if (fb_accel) {
589 finfo.accel = SDL_atoi (fb_accel); 586 finfo.accel = SDL_atoi(fb_accel);
590 } 587 }
591 } 588 }
592 589
593 /* Memory map the device, compensating for buggy PPC mmap() */ 590 /* Memory map the device, compensating for buggy PPC mmap() */
594 mapped_offset = (((long) finfo.smem_start) - 591 mapped_offset = (((long) finfo.smem_start) -
595 (((long) finfo.smem_start) & ~(PAGE_SIZE - 1))); 592 (((long) finfo.smem_start) & ~(PAGE_SIZE - 1)));
596 mapped_memlen = finfo.smem_len + mapped_offset; 593 mapped_memlen = finfo.smem_len + mapped_offset;
597 mapped_mem = do_mmap (NULL, mapped_memlen, 594 mapped_mem = do_mmap(NULL, mapped_memlen,
598 PROT_READ | PROT_WRITE, MAP_SHARED, console_fd, 0); 595 PROT_READ | PROT_WRITE, MAP_SHARED, console_fd, 0);
599 if (mapped_mem == (char *) -1) { 596 if (mapped_mem == (char *) -1) {
600 SDL_SetError ("Unable to memory map the video hardware"); 597 SDL_SetError("Unable to memory map the video hardware");
601 mapped_mem = NULL; 598 mapped_mem = NULL;
602 FB_VideoQuit (this); 599 FB_VideoQuit(this);
603 return (-1); 600 return (-1);
604 } 601 }
605 602
606 /* Determine the current screen depth */ 603 /* Determine the current screen depth */
607 if (ioctl (console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { 604 if (ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
608 SDL_SetError ("Couldn't get console pixel format"); 605 SDL_SetError("Couldn't get console pixel format");
609 FB_VideoQuit (this); 606 FB_VideoQuit(this);
610 return (-1); 607 return (-1);
611 } 608 }
612 vformat->BitsPerPixel = vinfo.bits_per_pixel; 609 vformat->BitsPerPixel = vinfo.bits_per_pixel;
613 if (vformat->BitsPerPixel < 8) { 610 if (vformat->BitsPerPixel < 8) {
614 /* Assuming VGA16, we handle this via a shadow framebuffer */ 611 /* Assuming VGA16, we handle this via a shadow framebuffer */
627 vformat->Bmask |= (0x00000001 << vinfo.blue.offset); 624 vformat->Bmask |= (0x00000001 << vinfo.blue.offset);
628 } 625 }
629 saved_vinfo = vinfo; 626 saved_vinfo = vinfo;
630 627
631 /* Save hardware palette, if needed */ 628 /* Save hardware palette, if needed */
632 FB_SavePalette (this, &finfo, &vinfo); 629 FB_SavePalette(this, &finfo, &vinfo);
633 630
634 /* If the I/O registers are available, memory map them so we 631 /* If the I/O registers are available, memory map them so we
635 can take advantage of any supported hardware acceleration. 632 can take advantage of any supported hardware acceleration.
636 */ 633 */
637 vinfo.accel_flags = 0; /* Temporarily reserve registers */ 634 vinfo.accel_flags = 0; /* Temporarily reserve registers */
638 ioctl (console_fd, FBIOPUT_VSCREENINFO, &vinfo); 635 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
639 if (finfo.accel && finfo.mmio_len) { 636 if (finfo.accel && finfo.mmio_len) {
640 mapped_iolen = finfo.mmio_len; 637 mapped_iolen = finfo.mmio_len;
641 mapped_io = do_mmap (NULL, mapped_iolen, PROT_READ | PROT_WRITE, 638 mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ | PROT_WRITE,
642 MAP_SHARED, console_fd, mapped_memlen); 639 MAP_SHARED, console_fd, mapped_memlen);
643 if (mapped_io == (char *) -1) { 640 if (mapped_io == (char *) -1) {
644 /* Hmm, failed to memory map I/O registers */ 641 /* Hmm, failed to memory map I/O registers */
645 mapped_io = NULL; 642 mapped_io = NULL;
646 } 643 }
647 } 644 }
648 645
649 /* Query for the list of available video modes */ 646 /* Query for the list of available video modes */
650 current_w = vinfo.xres; 647 current_w = vinfo.xres;
651 current_h = vinfo.yres; 648 current_h = vinfo.yres;
652 current_index = ((vinfo.bits_per_pixel + 7) / 8) - 1; 649 current_index = ((vinfo.bits_per_pixel + 7) / 8) - 1;
653 modesdb = fopen (FB_MODES_DB, "r"); 650 modesdb = fopen(FB_MODES_DB, "r");
654 for (i = 0; i < NUM_MODELISTS; ++i) { 651 for (i = 0; i < NUM_MODELISTS; ++i) {
655 SDL_nummodes[i] = 0; 652 SDL_nummodes[i] = 0;
656 SDL_modelist[i] = NULL; 653 SDL_modelist[i] = NULL;
657 } 654 }
658 if (SDL_getenv ("SDL_FB_BROKEN_MODES") != NULL) { 655 if (SDL_getenv("SDL_FB_BROKEN_MODES") != NULL) {
659 FB_AddMode (this, current_index, current_w, current_h, 0); 656 FB_AddMode(this, current_index, current_w, current_h, 0);
660 } else if (modesdb) { 657 } else if (modesdb) {
661 while (read_fbmodes_mode (modesdb, &vinfo)) { 658 while (read_fbmodes_mode(modesdb, &vinfo)) {
662 for (i = 0; i < NUM_MODELISTS; ++i) { 659 for (i = 0; i < NUM_MODELISTS; ++i) {
663 unsigned int w, h; 660 unsigned int w, h;
664 661
665 /* See if we are querying for the current mode */ 662 /* See if we are querying for the current mode */
666 w = vinfo.xres; 663 w = vinfo.xres;
667 h = vinfo.yres; 664 h = vinfo.yres;
668 if (i == current_index) { 665 if (i == current_index) {
669 if ((current_w > w) || (current_h > h)) { 666 if ((current_w > w) || (current_h > h)) {
670 /* Only check once */ 667 /* Only check once */
671 FB_AddMode (this, i, current_w, current_h, 0); 668 FB_AddMode(this, i, current_w, current_h, 0);
672 current_index = -1; 669 current_index = -1;
673 } 670 }
674 } 671 }
675 if (FB_CheckMode (this, &vinfo, i, &w, &h)) { 672 if (FB_CheckMode(this, &vinfo, i, &w, &h)) {
676 FB_AddMode (this, i, w, h, 0); 673 FB_AddMode(this, i, w, h, 0);
677 } 674 }
678 } 675 }
679 } 676 }
680 fclose (modesdb); 677 fclose(modesdb);
681 FB_SortModes (this); 678 FB_SortModes(this);
682 } else { 679 } else {
683 for (i = 0; i < NUM_MODELISTS; ++i) { 680 for (i = 0; i < NUM_MODELISTS; ++i) {
684 for (j = 0; j < (sizeof (checkres) / sizeof (checkres[0])); ++j) { 681 for (j = 0; j < (sizeof(checkres) / sizeof(checkres[0])); ++j) {
685 unsigned int w, h; 682 unsigned int w, h;
686 683
687 /* See if we are querying for the current mode */ 684 /* See if we are querying for the current mode */
688 w = checkres[j].w; 685 w = checkres[j].w;
689 h = checkres[j].h; 686 h = checkres[j].h;
690 if (i == current_index) { 687 if (i == current_index) {
691 if ((current_w > w) || (current_h > h)) { 688 if ((current_w > w) || (current_h > h)) {
692 /* Only check once */ 689 /* Only check once */
693 FB_AddMode (this, i, current_w, current_h, 0); 690 FB_AddMode(this, i, current_w, current_h, 0);
694 current_index = -1; 691 current_index = -1;
695 } 692 }
696 } 693 }
697 if (FB_CheckMode (this, &vinfo, i, &w, &h)) { 694 if (FB_CheckMode(this, &vinfo, i, &w, &h)) {
698 FB_AddMode (this, i, w, h, 1); 695 FB_AddMode(this, i, w, h, 1);
699 } 696 }
700 } 697 }
701 } 698 }
702 } 699 }
703 700
715 case FB_ACCEL_MATROX_MGA2164W_AGP: 712 case FB_ACCEL_MATROX_MGA2164W_AGP:
716 case FB_ACCEL_MATROX_MGAG100: 713 case FB_ACCEL_MATROX_MGAG100:
717 /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */ 714 /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */
718 case FB_ACCEL_MATROX_MGAG400: 715 case FB_ACCEL_MATROX_MGAG400:
719 #ifdef FBACCEL_DEBUG 716 #ifdef FBACCEL_DEBUG
720 printf ("Matrox hardware accelerator!\n"); 717 printf("Matrox hardware accelerator!\n");
721 #endif 718 #endif
722 FB_MatroxAccel (this, finfo.accel); 719 FB_MatroxAccel(this, finfo.accel);
723 break; 720 break;
724 case FB_ACCEL_3DFX_BANSHEE: 721 case FB_ACCEL_3DFX_BANSHEE:
725 #ifdef FBACCEL_DEBUG 722 #ifdef FBACCEL_DEBUG
726 printf ("3DFX hardware accelerator!\n"); 723 printf("3DFX hardware accelerator!\n");
727 #endif 724 #endif
728 FB_3DfxAccel (this, finfo.accel); 725 FB_3DfxAccel(this, finfo.accel);
729 break; 726 break;
730 case FB_ACCEL_NV3: 727 case FB_ACCEL_NV3:
731 case FB_ACCEL_NV4: 728 case FB_ACCEL_NV4:
732 #ifdef FBACCEL_DEBUG 729 #ifdef FBACCEL_DEBUG
733 printf ("NVidia hardware accelerator!\n"); 730 printf("NVidia hardware accelerator!\n");
734 #endif 731 #endif
735 FB_RivaAccel (this, finfo.accel); 732 FB_RivaAccel(this, finfo.accel);
736 break; 733 break;
737 default: 734 default:
738 #ifdef FBACCEL_DEBUG 735 #ifdef FBACCEL_DEBUG
739 printf ("Unknown hardware accelerator.\n"); 736 printf("Unknown hardware accelerator.\n");
740 #endif 737 #endif
741 break; 738 break;
742 } 739 }
743 } 740 }
744 741
745 /* Enable mouse and keyboard support */ 742 /* Enable mouse and keyboard support */
746 if (FB_OpenKeyboard (this) < 0) { 743 if (FB_OpenKeyboard(this) < 0) {
747 FB_VideoQuit (this); 744 FB_VideoQuit(this);
748 return (-1); 745 return (-1);
749 } 746 }
750 if (FB_OpenMouse (this) < 0) { 747 if (FB_OpenMouse(this) < 0) {
751 const char *sdl_nomouse; 748 const char *sdl_nomouse;
752 749
753 sdl_nomouse = SDL_getenv ("SDL_NOMOUSE"); 750 sdl_nomouse = SDL_getenv("SDL_NOMOUSE");
754 if (!sdl_nomouse) { 751 if (!sdl_nomouse) {
755 SDL_SetError ("Unable to open mouse"); 752 SDL_SetError("Unable to open mouse");
756 FB_VideoQuit (this); 753 FB_VideoQuit(this);
757 return (-1); 754 return (-1);
758 } 755 }
759 } 756 }
760 757
761 /* We're done! */ 758 /* We're done! */
762 return (0); 759 return (0);
763 } 760 }
764 761
765 static SDL_Rect ** 762 static SDL_Rect **
766 FB_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 763 FB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
767 { 764 {
768 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); 765 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
769 } 766 }
770 767
771 /* Various screen update functions available */ 768 /* Various screen update functions available */
772 static void FB_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); 769 static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
773 #ifdef VGA16_FBCON_SUPPORT 770 #ifdef VGA16_FBCON_SUPPORT
774 static void FB_VGA16Update (_THIS, int numrects, SDL_Rect * rects); 771 static void FB_VGA16Update(_THIS, int numrects, SDL_Rect * rects);
775 #endif 772 #endif
776 773
777 #ifdef FBCON_DEBUG 774 #ifdef FBCON_DEBUG
778 static void 775 static void
779 print_vinfo (struct fb_var_screeninfo *vinfo) 776 print_vinfo(struct fb_var_screeninfo *vinfo)
780 { 777 {
781 fprintf (stderr, "Printing vinfo:\n"); 778 fprintf(stderr, "Printing vinfo:\n");
782 fprintf (stderr, "\txres: %d\n", vinfo->xres); 779 fprintf(stderr, "\txres: %d\n", vinfo->xres);
783 fprintf (stderr, "\tyres: %d\n", vinfo->yres); 780 fprintf(stderr, "\tyres: %d\n", vinfo->yres);
784 fprintf (stderr, "\txres_virtual: %d\n", vinfo->xres_virtual); 781 fprintf(stderr, "\txres_virtual: %d\n", vinfo->xres_virtual);
785 fprintf (stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual); 782 fprintf(stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual);
786 fprintf (stderr, "\txoffset: %d\n", vinfo->xoffset); 783 fprintf(stderr, "\txoffset: %d\n", vinfo->xoffset);
787 fprintf (stderr, "\tyoffset: %d\n", vinfo->yoffset); 784 fprintf(stderr, "\tyoffset: %d\n", vinfo->yoffset);
788 fprintf (stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel); 785 fprintf(stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel);
789 fprintf (stderr, "\tgrayscale: %d\n", vinfo->grayscale); 786 fprintf(stderr, "\tgrayscale: %d\n", vinfo->grayscale);
790 fprintf (stderr, "\tnonstd: %d\n", vinfo->nonstd); 787 fprintf(stderr, "\tnonstd: %d\n", vinfo->nonstd);
791 fprintf (stderr, "\tactivate: %d\n", vinfo->activate); 788 fprintf(stderr, "\tactivate: %d\n", vinfo->activate);
792 fprintf (stderr, "\theight: %d\n", vinfo->height); 789 fprintf(stderr, "\theight: %d\n", vinfo->height);
793 fprintf (stderr, "\twidth: %d\n", vinfo->width); 790 fprintf(stderr, "\twidth: %d\n", vinfo->width);
794 fprintf (stderr, "\taccel_flags: %d\n", vinfo->accel_flags); 791 fprintf(stderr, "\taccel_flags: %d\n", vinfo->accel_flags);
795 fprintf (stderr, "\tpixclock: %d\n", vinfo->pixclock); 792 fprintf(stderr, "\tpixclock: %d\n", vinfo->pixclock);
796 fprintf (stderr, "\tleft_margin: %d\n", vinfo->left_margin); 793 fprintf(stderr, "\tleft_margin: %d\n", vinfo->left_margin);
797 fprintf (stderr, "\tright_margin: %d\n", vinfo->right_margin); 794 fprintf(stderr, "\tright_margin: %d\n", vinfo->right_margin);
798 fprintf (stderr, "\tupper_margin: %d\n", vinfo->upper_margin); 795 fprintf(stderr, "\tupper_margin: %d\n", vinfo->upper_margin);
799 fprintf (stderr, "\tlower_margin: %d\n", vinfo->lower_margin); 796 fprintf(stderr, "\tlower_margin: %d\n", vinfo->lower_margin);
800 fprintf (stderr, "\thsync_len: %d\n", vinfo->hsync_len); 797 fprintf(stderr, "\thsync_len: %d\n", vinfo->hsync_len);
801 fprintf (stderr, "\tvsync_len: %d\n", vinfo->vsync_len); 798 fprintf(stderr, "\tvsync_len: %d\n", vinfo->vsync_len);
802 fprintf (stderr, "\tsync: %d\n", vinfo->sync); 799 fprintf(stderr, "\tsync: %d\n", vinfo->sync);
803 fprintf (stderr, "\tvmode: %d\n", vinfo->vmode); 800 fprintf(stderr, "\tvmode: %d\n", vinfo->vmode);
804 fprintf (stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset); 801 fprintf(stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset);
805 fprintf (stderr, "\tgreen: %d/%d\n", vinfo->green.length, 802 fprintf(stderr, "\tgreen: %d/%d\n", vinfo->green.length,
806 vinfo->green.offset); 803 vinfo->green.offset);
807 fprintf (stderr, "\tblue: %d/%d\n", vinfo->blue.length, 804 fprintf(stderr, "\tblue: %d/%d\n", vinfo->blue.length,
808 vinfo->blue.offset); 805 vinfo->blue.offset);
809 fprintf (stderr, "\talpha: %d/%d\n", vinfo->transp.length, 806 fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length,
810 vinfo->transp.offset); 807 vinfo->transp.offset);
811 } 808 }
812 static void 809 static void
813 print_finfo (struct fb_fix_screeninfo *finfo) 810 print_finfo(struct fb_fix_screeninfo *finfo)
814 { 811 {
815 fprintf (stderr, "Printing finfo:\n"); 812 fprintf(stderr, "Printing finfo:\n");
816 fprintf (stderr, "\tsmem_start = %p\n", (char *) finfo->smem_start); 813 fprintf(stderr, "\tsmem_start = %p\n", (char *) finfo->smem_start);
817 fprintf (stderr, "\tsmem_len = %d\n", finfo->smem_len); 814 fprintf(stderr, "\tsmem_len = %d\n", finfo->smem_len);
818 fprintf (stderr, "\ttype = %d\n", finfo->type); 815 fprintf(stderr, "\ttype = %d\n", finfo->type);
819 fprintf (stderr, "\ttype_aux = %d\n", finfo->type_aux); 816 fprintf(stderr, "\ttype_aux = %d\n", finfo->type_aux);
820 fprintf (stderr, "\tvisual = %d\n", finfo->visual); 817 fprintf(stderr, "\tvisual = %d\n", finfo->visual);
821 fprintf (stderr, "\txpanstep = %d\n", finfo->xpanstep); 818 fprintf(stderr, "\txpanstep = %d\n", finfo->xpanstep);
822 fprintf (stderr, "\typanstep = %d\n", finfo->ypanstep); 819 fprintf(stderr, "\typanstep = %d\n", finfo->ypanstep);
823 fprintf (stderr, "\tywrapstep = %d\n", finfo->ywrapstep); 820 fprintf(stderr, "\tywrapstep = %d\n", finfo->ywrapstep);
824 fprintf (stderr, "\tline_length = %d\n", finfo->line_length); 821 fprintf(stderr, "\tline_length = %d\n", finfo->line_length);
825 fprintf (stderr, "\tmmio_start = %p\n", (char *) finfo->mmio_start); 822 fprintf(stderr, "\tmmio_start = %p\n", (char *) finfo->mmio_start);
826 fprintf (stderr, "\tmmio_len = %d\n", finfo->mmio_len); 823 fprintf(stderr, "\tmmio_len = %d\n", finfo->mmio_len);
827 fprintf (stderr, "\taccel = %d\n", finfo->accel); 824 fprintf(stderr, "\taccel = %d\n", finfo->accel);
828 } 825 }
829 #endif 826 #endif
830 827
831 static int 828 static int
832 choose_fbmodes_mode (struct fb_var_screeninfo *vinfo) 829 choose_fbmodes_mode(struct fb_var_screeninfo *vinfo)
833 { 830 {
834 int matched; 831 int matched;
835 FILE *modesdb; 832 FILE *modesdb;
836 struct fb_var_screeninfo cinfo; 833 struct fb_var_screeninfo cinfo;
837 834
838 matched = 0; 835 matched = 0;
839 modesdb = fopen (FB_MODES_DB, "r"); 836 modesdb = fopen(FB_MODES_DB, "r");
840 if (modesdb) { 837 if (modesdb) {
841 /* Parse the mode definition file */ 838 /* Parse the mode definition file */
842 while (read_fbmodes_mode (modesdb, &cinfo)) { 839 while (read_fbmodes_mode(modesdb, &cinfo)) {
843 if ((vinfo->xres == cinfo.xres && vinfo->yres == cinfo.yres) 840 if ((vinfo->xres == cinfo.xres && vinfo->yres == cinfo.yres)
844 && (!matched 841 && (!matched
845 || (vinfo->bits_per_pixel == cinfo.bits_per_pixel))) { 842 || (vinfo->bits_per_pixel == cinfo.bits_per_pixel))) {
846 vinfo->pixclock = cinfo.pixclock; 843 vinfo->pixclock = cinfo.pixclock;
847 vinfo->left_margin = cinfo.left_margin; 844 vinfo->left_margin = cinfo.left_margin;
854 break; 851 break;
855 } 852 }
856 matched = 1; 853 matched = 1;
857 } 854 }
858 } 855 }
859 fclose (modesdb); 856 fclose(modesdb);
860 } 857 }
861 return (matched); 858 return (matched);
862 } 859 }
863 860
864 static int 861 static int
865 choose_vesa_mode (struct fb_var_screeninfo *vinfo) 862 choose_vesa_mode(struct fb_var_screeninfo *vinfo)
866 { 863 {
867 int matched; 864 int matched;
868 int i; 865 int i;
869 866
870 /* Check for VESA timings */ 867 /* Check for VESA timings */
871 matched = 0; 868 matched = 0;
872 for (i = 0; i < (sizeof (vesa_timings) / sizeof (vesa_timings[0])); ++i) { 869 for (i = 0; i < (sizeof(vesa_timings) / sizeof(vesa_timings[0])); ++i) {
873 if ((vinfo->xres == vesa_timings[i].xres) && 870 if ((vinfo->xres == vesa_timings[i].xres) &&
874 (vinfo->yres == vesa_timings[i].yres)) { 871 (vinfo->yres == vesa_timings[i].yres)) {
875 #ifdef FBCON_DEBUG 872 #ifdef FBCON_DEBUG
876 fprintf (stderr, "Using VESA timings for %dx%d\n", 873 fprintf(stderr, "Using VESA timings for %dx%d\n",
877 vinfo->xres, vinfo->yres); 874 vinfo->xres, vinfo->yres);
878 #endif 875 #endif
879 if (vesa_timings[i].pixclock) { 876 if (vesa_timings[i].pixclock) {
880 vinfo->pixclock = vesa_timings[i].pixclock; 877 vinfo->pixclock = vesa_timings[i].pixclock;
881 } 878 }
882 vinfo->left_margin = vesa_timings[i].left; 879 vinfo->left_margin = vesa_timings[i].left;
894 return (matched); 891 return (matched);
895 } 892 }
896 893
897 #ifdef VGA16_FBCON_SUPPORT 894 #ifdef VGA16_FBCON_SUPPORT
898 static SDL_Surface * 895 static SDL_Surface *
899 FB_SetVGA16Mode (_THIS, SDL_Surface * current, 896 FB_SetVGA16Mode(_THIS, SDL_Surface * current,
900 int width, int height, int bpp, Uint32 flags) 897 int width, int height, int bpp, Uint32 flags)
901 { 898 {
902 struct fb_fix_screeninfo finfo; 899 struct fb_fix_screeninfo finfo;
903 struct fb_var_screeninfo vinfo; 900 struct fb_var_screeninfo vinfo;
904 901
905 /* Set the terminal into graphics mode */ 902 /* Set the terminal into graphics mode */
906 if (FB_EnterGraphicsMode (this) < 0) { 903 if (FB_EnterGraphicsMode(this) < 0) {
907 return (NULL); 904 return (NULL);
908 } 905 }
909 906
910 /* Restore the original palette */ 907 /* Restore the original palette */
911 FB_RestorePalette (this); 908 FB_RestorePalette(this);
912 909
913 /* Set the video mode and get the final screen format */ 910 /* Set the video mode and get the final screen format */
914 if (ioctl (console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { 911 if (ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
915 SDL_SetError ("Couldn't get console screen info"); 912 SDL_SetError("Couldn't get console screen info");
916 return (NULL); 913 return (NULL);
917 } 914 }
918 cache_vinfo = vinfo; 915 cache_vinfo = vinfo;
919 #ifdef FBCON_DEBUG 916 #ifdef FBCON_DEBUG
920 fprintf (stderr, "Printing actual vinfo:\n"); 917 fprintf(stderr, "Printing actual vinfo:\n");
921 print_vinfo (&vinfo); 918 print_vinfo(&vinfo);
922 #endif 919 #endif
923 if (!SDL_ReallocFormat (current, bpp, 0, 0, 0, 0)) { 920 if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) {
924 return (NULL); 921 return (NULL);
925 } 922 }
926 current->format->palette->ncolors = 16; 923 current->format->palette->ncolors = 16;
927 924
928 /* Get the fixed information about the console hardware. 925 /* Get the fixed information about the console hardware.
929 This is necessary since finfo.line_length changes. 926 This is necessary since finfo.line_length changes.
930 */ 927 */
931 if (ioctl (console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) { 928 if (ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
932 SDL_SetError ("Couldn't get console hardware info"); 929 SDL_SetError("Couldn't get console hardware info");
933 return (NULL); 930 return (NULL);
934 } 931 }
935 #ifdef FBCON_DEBUG 932 #ifdef FBCON_DEBUG
936 fprintf (stderr, "Printing actual finfo:\n"); 933 fprintf(stderr, "Printing actual finfo:\n");
937 print_finfo (&finfo); 934 print_finfo(&finfo);
938 #endif 935 #endif
939 936
940 /* Save hardware palette, if needed */ 937 /* Save hardware palette, if needed */
941 FB_SavePalette (this, &finfo, &vinfo); 938 FB_SavePalette(this, &finfo, &vinfo);
942 939
943 /* Set up the new mode framebuffer */ 940 /* Set up the new mode framebuffer */
944 current->flags = SDL_FULLSCREEN; 941 current->flags = SDL_FULLSCREEN;
945 current->w = vinfo.xres; 942 current->w = vinfo.xres;
946 current->h = vinfo.yres; 943 current->h = vinfo.yres;
947 current->pitch = current->w; 944 current->pitch = current->w;
948 current->pixels = SDL_malloc (current->h * current->pitch); 945 current->pixels = SDL_malloc(current->h * current->pitch);
949 946
950 /* Set the update rectangle function */ 947 /* Set the update rectangle function */
951 this->UpdateRects = FB_VGA16Update; 948 this->UpdateRects = FB_VGA16Update;
952 949
953 /* We're done */ 950 /* We're done */
954 return (current); 951 return (current);
955 } 952 }
956 #endif /* VGA16_FBCON_SUPPORT */ 953 #endif /* VGA16_FBCON_SUPPORT */
957 954
958 static SDL_Surface * 955 static SDL_Surface *
959 FB_SetVideoMode (_THIS, SDL_Surface * current, 956 FB_SetVideoMode(_THIS, SDL_Surface * current,
960 int width, int height, int bpp, Uint32 flags) 957 int width, int height, int bpp, Uint32 flags)
961 { 958 {
962 struct fb_fix_screeninfo finfo; 959 struct fb_fix_screeninfo finfo;
963 struct fb_var_screeninfo vinfo; 960 struct fb_var_screeninfo vinfo;
964 int i; 961 int i;
965 Uint32 Rmask; 962 Uint32 Rmask;
967 Uint32 Bmask; 964 Uint32 Bmask;
968 char *surfaces_mem; 965 char *surfaces_mem;
969 int surfaces_len; 966 int surfaces_len;
970 967
971 /* Set the terminal into graphics mode */ 968 /* Set the terminal into graphics mode */
972 if (FB_EnterGraphicsMode (this) < 0) { 969 if (FB_EnterGraphicsMode(this) < 0) {
973 return (NULL); 970 return (NULL);
974 } 971 }
975 972
976 /* Restore the original palette */ 973 /* Restore the original palette */
977 FB_RestorePalette (this); 974 FB_RestorePalette(this);
978 975
979 /* Set the video mode and get the final screen format */ 976 /* Set the video mode and get the final screen format */
980 if (ioctl (console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) { 977 if (ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0) {
981 SDL_SetError ("Couldn't get console screen info"); 978 SDL_SetError("Couldn't get console screen info");
982 return (NULL); 979 return (NULL);
983 } 980 }
984 #ifdef FBCON_DEBUG 981 #ifdef FBCON_DEBUG
985 fprintf (stderr, "Printing original vinfo:\n"); 982 fprintf(stderr, "Printing original vinfo:\n");
986 print_vinfo (&vinfo); 983 print_vinfo(&vinfo);
987 #endif 984 #endif
988 if ((vinfo.xres != width) || (vinfo.yres != height) || 985 if ((vinfo.xres != width) || (vinfo.yres != height) ||
989 (vinfo.bits_per_pixel != bpp) || (flags & SDL_DOUBLEBUF)) { 986 (vinfo.bits_per_pixel != bpp) || (flags & SDL_DOUBLEBUF)) {
990 vinfo.activate = FB_ACTIVATE_NOW; 987 vinfo.activate = FB_ACTIVATE_NOW;
991 vinfo.accel_flags = 0; 988 vinfo.accel_flags = 0;
1002 vinfo.yoffset = 0; 999 vinfo.yoffset = 0;
1003 vinfo.red.length = vinfo.red.offset = 0; 1000 vinfo.red.length = vinfo.red.offset = 0;
1004 vinfo.green.length = vinfo.green.offset = 0; 1001 vinfo.green.length = vinfo.green.offset = 0;
1005 vinfo.blue.length = vinfo.blue.offset = 0; 1002 vinfo.blue.length = vinfo.blue.offset = 0;
1006 vinfo.transp.length = vinfo.transp.offset = 0; 1003 vinfo.transp.length = vinfo.transp.offset = 0;
1007 if (!choose_fbmodes_mode (&vinfo)) { 1004 if (!choose_fbmodes_mode(&vinfo)) {
1008 choose_vesa_mode (&vinfo); 1005 choose_vesa_mode(&vinfo);
1009 } 1006 }
1010 #ifdef FBCON_DEBUG 1007 #ifdef FBCON_DEBUG
1011 fprintf (stderr, "Printing wanted vinfo:\n"); 1008 fprintf(stderr, "Printing wanted vinfo:\n");
1012 print_vinfo (&vinfo); 1009 print_vinfo(&vinfo);
1013 #endif 1010 #endif
1014 if (ioctl (console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { 1011 if (ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
1015 vinfo.yres_virtual = height; 1012 vinfo.yres_virtual = height;
1016 if (ioctl (console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) { 1013 if (ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0) {
1017 SDL_SetError ("Couldn't set console screen info"); 1014 SDL_SetError("Couldn't set console screen info");
1018 return (NULL); 1015 return (NULL);
1019 } 1016 }
1020 } 1017 }
1021 } else { 1018 } else {
1022 int maxheight; 1019 int maxheight;
1031 vinfo.yres_virtual = maxheight; 1028 vinfo.yres_virtual = maxheight;
1032 } 1029 }
1033 } 1030 }
1034 cache_vinfo = vinfo; 1031 cache_vinfo = vinfo;
1035 #ifdef FBCON_DEBUG 1032 #ifdef FBCON_DEBUG
1036 fprintf (stderr, "Printing actual vinfo:\n"); 1033 fprintf(stderr, "Printing actual vinfo:\n");
1037 print_vinfo (&vinfo); 1034 print_vinfo(&vinfo);
1038 #endif 1035 #endif
1039 Rmask = 0; 1036 Rmask = 0;
1040 for (i = 0; i < vinfo.red.length; ++i) { 1037 for (i = 0; i < vinfo.red.length; ++i) {
1041 Rmask <<= 1; 1038 Rmask <<= 1;
1042 Rmask |= (0x00000001 << vinfo.red.offset); 1039 Rmask |= (0x00000001 << vinfo.red.offset);
1049 Bmask = 0; 1046 Bmask = 0;
1050 for (i = 0; i < vinfo.blue.length; ++i) { 1047 for (i = 0; i < vinfo.blue.length; ++i) {
1051 Bmask <<= 1; 1048 Bmask <<= 1;
1052 Bmask |= (0x00000001 << vinfo.blue.offset); 1049 Bmask |= (0x00000001 << vinfo.blue.offset);
1053 } 1050 }
1054 if (!SDL_ReallocFormat (current, vinfo.bits_per_pixel, 1051 if (!SDL_ReallocFormat(current, vinfo.bits_per_pixel,
1055 Rmask, Gmask, Bmask, 0)) { 1052 Rmask, Gmask, Bmask, 0)) {
1056 return (NULL); 1053 return (NULL);
1057 } 1054 }
1058 1055
1059 /* Get the fixed information about the console hardware. 1056 /* Get the fixed information about the console hardware.
1060 This is necessary since finfo.line_length changes. 1057 This is necessary since finfo.line_length changes.
1061 */ 1058 */
1062 if (ioctl (console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) { 1059 if (ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
1063 SDL_SetError ("Couldn't get console hardware info"); 1060 SDL_SetError("Couldn't get console hardware info");
1064 return (NULL); 1061 return (NULL);
1065 } 1062 }
1066 1063
1067 /* Save hardware palette, if needed */ 1064 /* Save hardware palette, if needed */
1068 FB_SavePalette (this, &finfo, &vinfo); 1065 FB_SavePalette(this, &finfo, &vinfo);
1069 1066
1070 /* Set up the new mode framebuffer */ 1067 /* Set up the new mode framebuffer */
1071 current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); 1068 current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
1072 current->w = vinfo.xres; 1069 current->w = vinfo.xres;
1073 current->h = vinfo.yres; 1070 current->h = vinfo.yres;
1076 1073
1077 /* Set up the information for hardware surfaces */ 1074 /* Set up the information for hardware surfaces */
1078 surfaces_mem = (char *) current->pixels + 1075 surfaces_mem = (char *) current->pixels +
1079 vinfo.yres_virtual * current->pitch; 1076 vinfo.yres_virtual * current->pitch;
1080 surfaces_len = (mapped_memlen - (surfaces_mem - mapped_mem)); 1077 surfaces_len = (mapped_memlen - (surfaces_mem - mapped_mem));
1081 FB_FreeHWSurfaces (this); 1078 FB_FreeHWSurfaces(this);
1082 FB_InitHWSurfaces (this, current, surfaces_mem, surfaces_len); 1079 FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len);
1083 1080
1084 /* Let the application know we have a hardware palette */ 1081 /* Let the application know we have a hardware palette */
1085 switch (finfo.visual) { 1082 switch (finfo.visual) {
1086 case FB_VISUAL_PSEUDOCOLOR: 1083 case FB_VISUAL_PSEUDOCOLOR:
1087 current->flags |= SDL_HWPALETTE; 1084 current->flags |= SDL_HWPALETTE;
1097 flip_page = 0; 1094 flip_page = 0;
1098 flip_address[0] = (char *) current->pixels; 1095 flip_address[0] = (char *) current->pixels;
1099 flip_address[1] = (char *) current->pixels + 1096 flip_address[1] = (char *) current->pixels +
1100 current->h * current->pitch; 1097 current->h * current->pitch;
1101 this->screen = current; 1098 this->screen = current;
1102 FB_FlipHWSurface (this, current); 1099 FB_FlipHWSurface(this, current);
1103 this->screen = NULL; 1100 this->screen = NULL;
1104 } 1101 }
1105 } 1102 }
1106 1103
1107 /* Set the update rectangle function */ 1104 /* Set the update rectangle function */
1111 return (current); 1108 return (current);
1112 } 1109 }
1113 1110
1114 #ifdef FBCON_DEBUG 1111 #ifdef FBCON_DEBUG
1115 void 1112 void
1116 FB_DumpHWSurfaces (_THIS) 1113 FB_DumpHWSurfaces(_THIS)
1117 { 1114 {
1118 vidmem_bucket *bucket; 1115 vidmem_bucket *bucket;
1119 1116
1120 printf ("Memory left: %d (%d total)\n", surfaces_memleft, 1117 printf("Memory left: %d (%d total)\n", surfaces_memleft,
1121 surfaces_memtotal); 1118 surfaces_memtotal);
1122 printf ("\n"); 1119 printf("\n");
1123 printf (" Base Size\n"); 1120 printf(" Base Size\n");
1124 for (bucket = &surfaces; bucket; bucket = bucket->next) { 1121 for (bucket = &surfaces; bucket; bucket = bucket->next) {
1125 printf ("Bucket: %p, %d (%s)\n", bucket->base, bucket->size, 1122 printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size,
1126 bucket->used ? "used" : "free"); 1123 bucket->used ? "used" : "free");
1127 if (bucket->prev) { 1124 if (bucket->prev) {
1128 if (bucket->base != bucket->prev->base + bucket->prev->size) { 1125 if (bucket->base != bucket->prev->base + bucket->prev->size) {
1129 printf ("Warning, corrupt bucket list! (prev)\n"); 1126 printf("Warning, corrupt bucket list! (prev)\n");
1130 } 1127 }
1131 } else { 1128 } else {
1132 if (bucket != &surfaces) { 1129 if (bucket != &surfaces) {
1133 printf ("Warning, corrupt bucket list! (!prev)\n"); 1130 printf("Warning, corrupt bucket list! (!prev)\n");
1134 } 1131 }
1135 } 1132 }
1136 if (bucket->next) { 1133 if (bucket->next) {
1137 if (bucket->next->base != bucket->base + bucket->size) { 1134 if (bucket->next->base != bucket->base + bucket->size) {
1138 printf ("Warning, corrupt bucket list! (next)\n"); 1135 printf("Warning, corrupt bucket list! (next)\n");
1139 } 1136 }
1140 } 1137 }
1141 } 1138 }
1142 printf ("\n"); 1139 printf("\n");
1143 } 1140 }
1144 #endif 1141 #endif
1145 1142
1146 static int 1143 static int
1147 FB_InitHWSurfaces (_THIS, SDL_Surface * screen, char *base, int size) 1144 FB_InitHWSurfaces(_THIS, SDL_Surface * screen, char *base, int size)
1148 { 1145 {
1149 vidmem_bucket *bucket; 1146 vidmem_bucket *bucket;
1150 1147
1151 surfaces_memtotal = size; 1148 surfaces_memtotal = size;
1152 surfaces_memleft = size; 1149 surfaces_memleft = size;
1153 1150
1154 if (surfaces_memleft > 0) { 1151 if (surfaces_memleft > 0) {
1155 bucket = (vidmem_bucket *) SDL_malloc (sizeof (*bucket)); 1152 bucket = (vidmem_bucket *) SDL_malloc(sizeof(*bucket));
1156 if (bucket == NULL) { 1153 if (bucket == NULL) {
1157 SDL_OutOfMemory (); 1154 SDL_OutOfMemory();
1158 return (-1); 1155 return (-1);
1159 } 1156 }
1160 bucket->prev = &surfaces; 1157 bucket->prev = &surfaces;
1161 bucket->used = 0; 1158 bucket->used = 0;
1162 bucket->dirty = 0; 1159 bucket->dirty = 0;
1175 surfaces.next = bucket; 1172 surfaces.next = bucket;
1176 screen->hwdata = (struct private_hwdata *) &surfaces; 1173 screen->hwdata = (struct private_hwdata *) &surfaces;
1177 return (0); 1174 return (0);
1178 } 1175 }
1179 static void 1176 static void
1180 FB_FreeHWSurfaces (_THIS) 1177 FB_FreeHWSurfaces(_THIS)
1181 { 1178 {
1182 vidmem_bucket *bucket, *freeable; 1179 vidmem_bucket *bucket, *freeable;
1183 1180
1184 bucket = surfaces.next; 1181 bucket = surfaces.next;
1185 while (bucket) { 1182 while (bucket) {
1186 freeable = bucket; 1183 freeable = bucket;
1187 bucket = bucket->next; 1184 bucket = bucket->next;
1188 SDL_free (freeable); 1185 SDL_free(freeable);
1189 } 1186 }
1190 surfaces.next = NULL; 1187 surfaces.next = NULL;
1191 } 1188 }
1192 1189
1193 static int 1190 static int
1194 FB_AllocHWSurface (_THIS, SDL_Surface * surface) 1191 FB_AllocHWSurface(_THIS, SDL_Surface * surface)
1195 { 1192 {
1196 vidmem_bucket *bucket; 1193 vidmem_bucket *bucket;
1197 int size; 1194 int size;
1198 int extra; 1195 int extra;
1199 1196
1201 Some blitters require the pitch between two hardware surfaces 1198 Some blitters require the pitch between two hardware surfaces
1202 to be the same. Others have interesting alignment restrictions. 1199 to be the same. Others have interesting alignment restrictions.
1203 Until someone who knows these details looks at the code... 1200 Until someone who knows these details looks at the code...
1204 */ 1201 */
1205 if (surface->pitch > SDL_VideoSurface->pitch) { 1202 if (surface->pitch > SDL_VideoSurface->pitch) {
1206 SDL_SetError ("Surface requested wider than screen"); 1203 SDL_SetError("Surface requested wider than screen");
1207 return (-1); 1204 return (-1);
1208 } 1205 }
1209 surface->pitch = SDL_VideoSurface->pitch; 1206 surface->pitch = SDL_VideoSurface->pitch;
1210 size = surface->h * surface->pitch; 1207 size = surface->h * surface->pitch;
1211 #ifdef FBCON_DEBUG 1208 #ifdef FBCON_DEBUG
1212 fprintf (stderr, "Allocating bucket of %d bytes\n", size); 1209 fprintf(stderr, "Allocating bucket of %d bytes\n", size);
1213 #endif 1210 #endif
1214 1211
1215 /* Quick check for available mem */ 1212 /* Quick check for available mem */
1216 if (size > surfaces_memleft) { 1213 if (size > surfaces_memleft) {
1217 SDL_SetError ("Not enough video memory"); 1214 SDL_SetError("Not enough video memory");
1218 return (-1); 1215 return (-1);
1219 } 1216 }
1220 1217
1221 /* Search for an empty bucket big enough */ 1218 /* Search for an empty bucket big enough */
1222 for (bucket = &surfaces; bucket; bucket = bucket->next) { 1219 for (bucket = &surfaces; bucket; bucket = bucket->next) {
1223 if (!bucket->used && (size <= bucket->size)) { 1220 if (!bucket->used && (size <= bucket->size)) {
1224 break; 1221 break;
1225 } 1222 }
1226 } 1223 }
1227 if (bucket == NULL) { 1224 if (bucket == NULL) {
1228 SDL_SetError ("Video memory too fragmented"); 1225 SDL_SetError("Video memory too fragmented");
1229 return (-1); 1226 return (-1);
1230 } 1227 }
1231 1228
1232 /* Create a new bucket for left-over memory */ 1229 /* Create a new bucket for left-over memory */
1233 extra = (bucket->size - size); 1230 extra = (bucket->size - size);
1234 if (extra) { 1231 if (extra) {
1235 vidmem_bucket *newbucket; 1232 vidmem_bucket *newbucket;
1236 1233
1237 #ifdef FBCON_DEBUG 1234 #ifdef FBCON_DEBUG
1238 fprintf (stderr, "Adding new free bucket of %d bytes\n", extra); 1235 fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
1239 #endif 1236 #endif
1240 newbucket = (vidmem_bucket *) SDL_malloc (sizeof (*newbucket)); 1237 newbucket = (vidmem_bucket *) SDL_malloc(sizeof(*newbucket));
1241 if (newbucket == NULL) { 1238 if (newbucket == NULL) {
1242 SDL_OutOfMemory (); 1239 SDL_OutOfMemory();
1243 return (-1); 1240 return (-1);
1244 } 1241 }
1245 newbucket->prev = bucket; 1242 newbucket->prev = bucket;
1246 newbucket->used = 0; 1243 newbucket->used = 0;
1247 newbucket->base = bucket->base + size; 1244 newbucket->base = bucket->base + size;
1256 /* Set the current bucket values and return it! */ 1253 /* Set the current bucket values and return it! */
1257 bucket->used = 1; 1254 bucket->used = 1;
1258 bucket->size = size; 1255 bucket->size = size;
1259 bucket->dirty = 0; 1256 bucket->dirty = 0;
1260 #ifdef FBCON_DEBUG 1257 #ifdef FBCON_DEBUG
1261 fprintf (stderr, "Allocated %d bytes at %p\n", bucket->size, 1258 fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base);
1262 bucket->base);
1263 #endif 1259 #endif
1264 surfaces_memleft -= size; 1260 surfaces_memleft -= size;
1265 surface->flags |= SDL_HWSURFACE; 1261 surface->flags |= SDL_HWSURFACE;
1266 surface->pixels = bucket->base; 1262 surface->pixels = bucket->base;
1267 surface->hwdata = (struct private_hwdata *) bucket; 1263 surface->hwdata = (struct private_hwdata *) bucket;
1268 return (0); 1264 return (0);
1269 } 1265 }
1270 static void 1266 static void
1271 FB_FreeHWSurface (_THIS, SDL_Surface * surface) 1267 FB_FreeHWSurface(_THIS, SDL_Surface * surface)
1272 { 1268 {
1273 vidmem_bucket *bucket, *freeable; 1269 vidmem_bucket *bucket, *freeable;
1274 1270
1275 /* Look for the bucket in the current list */ 1271 /* Look for the bucket in the current list */
1276 for (bucket = &surfaces; bucket; bucket = bucket->next) { 1272 for (bucket = &surfaces; bucket; bucket = bucket->next) {
1279 } 1275 }
1280 } 1276 }
1281 if (bucket && bucket->used) { 1277 if (bucket && bucket->used) {
1282 /* Add the memory back to the total */ 1278 /* Add the memory back to the total */
1283 #ifdef DGA_DEBUG 1279 #ifdef DGA_DEBUG
1284 printf ("Freeing bucket of %d bytes\n", bucket->size); 1280 printf("Freeing bucket of %d bytes\n", bucket->size);
1285 #endif 1281 #endif
1286 surfaces_memleft += bucket->size; 1282 surfaces_memleft += bucket->size;
1287 1283
1288 /* Can we merge the space with surrounding buckets? */ 1284 /* Can we merge the space with surrounding buckets? */
1289 bucket->used = 0; 1285 bucket->used = 0;
1290 if (bucket->next && !bucket->next->used) { 1286 if (bucket->next && !bucket->next->used) {
1291 #ifdef DGA_DEBUG 1287 #ifdef DGA_DEBUG
1292 printf ("Merging with next bucket, for %d total bytes\n", 1288 printf("Merging with next bucket, for %d total bytes\n",
1293 bucket->size + bucket->next->size); 1289 bucket->size + bucket->next->size);
1294 #endif 1290 #endif
1295 freeable = bucket->next; 1291 freeable = bucket->next;
1296 bucket->size += bucket->next->size; 1292 bucket->size += bucket->next->size;
1297 bucket->next = bucket->next->next; 1293 bucket->next = bucket->next->next;
1298 if (bucket->next) { 1294 if (bucket->next) {
1299 bucket->next->prev = bucket; 1295 bucket->next->prev = bucket;
1300 } 1296 }
1301 SDL_free (freeable); 1297 SDL_free(freeable);
1302 } 1298 }
1303 if (bucket->prev && !bucket->prev->used) { 1299 if (bucket->prev && !bucket->prev->used) {
1304 #ifdef DGA_DEBUG 1300 #ifdef DGA_DEBUG
1305 printf ("Merging with previous bucket, for %d total bytes\n", 1301 printf("Merging with previous bucket, for %d total bytes\n",
1306 bucket->prev->size + bucket->size); 1302 bucket->prev->size + bucket->size);
1307 #endif 1303 #endif
1308 freeable = bucket; 1304 freeable = bucket;
1309 bucket->prev->size += bucket->size; 1305 bucket->prev->size += bucket->size;
1310 bucket->prev->next = bucket->next; 1306 bucket->prev->next = bucket->next;
1311 if (bucket->next) { 1307 if (bucket->next) {
1312 bucket->next->prev = bucket->prev; 1308 bucket->next->prev = bucket->prev;
1313 } 1309 }
1314 SDL_free (freeable); 1310 SDL_free(freeable);
1315 } 1311 }
1316 } 1312 }
1317 surface->pixels = NULL; 1313 surface->pixels = NULL;
1318 surface->hwdata = NULL; 1314 surface->hwdata = NULL;
1319 } 1315 }
1320 1316
1321 static int 1317 static int
1322 FB_LockHWSurface (_THIS, SDL_Surface * surface) 1318 FB_LockHWSurface(_THIS, SDL_Surface * surface)
1323 { 1319 {
1324 if (switched_away) { 1320 if (switched_away) {
1325 return -2; /* no hardware access */ 1321 return -2; /* no hardware access */
1326 } 1322 }
1327 if (surface == this->screen) { 1323 if (surface == this->screen) {
1328 SDL_mutexP (hw_lock); 1324 SDL_mutexP(hw_lock);
1329 if (FB_IsSurfaceBusy (surface)) { 1325 if (FB_IsSurfaceBusy(surface)) {
1330 FB_WaitBusySurfaces (this); 1326 FB_WaitBusySurfaces(this);
1331 } 1327 }
1332 } else { 1328 } else {
1333 if (FB_IsSurfaceBusy (surface)) { 1329 if (FB_IsSurfaceBusy(surface)) {
1334 FB_WaitBusySurfaces (this); 1330 FB_WaitBusySurfaces(this);
1335 } 1331 }
1336 } 1332 }
1337 return (0); 1333 return (0);
1338 } 1334 }
1339 static void 1335 static void
1340 FB_UnlockHWSurface (_THIS, SDL_Surface * surface) 1336 FB_UnlockHWSurface(_THIS, SDL_Surface * surface)
1341 { 1337 {
1342 if (surface == this->screen) { 1338 if (surface == this->screen) {
1343 SDL_mutexV (hw_lock); 1339 SDL_mutexV(hw_lock);
1344 } 1340 }
1345 } 1341 }
1346 1342
1347 static void 1343 static void
1348 FB_WaitVBL (_THIS) 1344 FB_WaitVBL(_THIS)
1349 { 1345 {
1350 #ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */ 1346 #ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */
1351 ioctl (console_fd, FBIOWAITRETRACE, 0); 1347 ioctl(console_fd, FBIOWAITRETRACE, 0);
1352 #endif 1348 #endif
1353 return; 1349 return;
1354 } 1350 }
1355 1351
1356 static void 1352 static void
1357 FB_WaitIdle (_THIS) 1353 FB_WaitIdle(_THIS)
1358 { 1354 {
1359 return; 1355 return;
1360 } 1356 }
1361 1357
1362 static int 1358 static int
1363 FB_FlipHWSurface (_THIS, SDL_Surface * surface) 1359 FB_FlipHWSurface(_THIS, SDL_Surface * surface)
1364 { 1360 {
1365 if (switched_away) { 1361 if (switched_away) {
1366 return -2; /* no hardware access */ 1362 return -2; /* no hardware access */
1367 } 1363 }
1368 1364
1369 /* Wait for vertical retrace and then flip display */ 1365 /* Wait for vertical retrace and then flip display */
1370 cache_vinfo.yoffset = flip_page * surface->h; 1366 cache_vinfo.yoffset = flip_page * surface->h;
1371 if (FB_IsSurfaceBusy (this->screen)) { 1367 if (FB_IsSurfaceBusy(this->screen)) {
1372 FB_WaitBusySurfaces (this); 1368 FB_WaitBusySurfaces(this);
1373 } 1369 }
1374 wait_vbl (this); 1370 wait_vbl(this);
1375 if (ioctl (console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0) { 1371 if (ioctl(console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0) {
1376 SDL_SetError ("ioctl(FBIOPAN_DISPLAY) failed"); 1372 SDL_SetError("ioctl(FBIOPAN_DISPLAY) failed");
1377 return (-1); 1373 return (-1);
1378 } 1374 }
1379 flip_page = !flip_page; 1375 flip_page = !flip_page;
1380 1376
1381 surface->pixels = flip_address[flip_page]; 1377 surface->pixels = flip_address[flip_page];
1382 return (0); 1378 return (0);
1383 } 1379 }
1384 1380
1385 static void 1381 static void
1386 FB_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) 1382 FB_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
1387 { 1383 {
1388 /* The application is already updating the visible video memory */ 1384 /* The application is already updating the visible video memory */
1389 return; 1385 return;
1390 } 1386 }
1391 1387
1397 #define writeSeq(index, value) \ 1393 #define writeSeq(index, value) \
1398 outb(index, 0x3C4); \ 1394 outb(index, 0x3C4); \
1399 outb(value, 0x3C5); 1395 outb(value, 0x3C5);
1400 1396
1401 static void 1397 static void
1402 FB_VGA16Update (_THIS, int numrects, SDL_Rect * rects) 1398 FB_VGA16Update(_THIS, int numrects, SDL_Rect * rects)
1403 { 1399 {
1404 SDL_Surface *screen; 1400 SDL_Surface *screen;
1405 int width, height, FBPitch, left, i, j, SRCPitch, phase; 1401 int width, height, FBPitch, left, i, j, SRCPitch, phase;
1406 register Uint32 m; 1402 register Uint32 m;
1407 Uint8 s1, s2, s3, s4; 1403 Uint8 s1, s2, s3, s4;
1414 1410
1415 screen = this->screen; 1411 screen = this->screen;
1416 FBPitch = screen->w >> 3; 1412 FBPitch = screen->w >> 3;
1417 SRCPitch = screen->pitch >> 2; 1413 SRCPitch = screen->pitch >> 2;
1418 1414
1419 writeGr (0x03, 0x00); 1415 writeGr(0x03, 0x00);
1420 writeGr (0x05, 0x00); 1416 writeGr(0x05, 0x00);
1421 writeGr (0x01, 0x00); 1417 writeGr(0x01, 0x00);
1422 writeGr (0x08, 0xFF); 1418 writeGr(0x08, 0xFF);
1423 1419
1424 while (numrects--) { 1420 while (numrects--) {
1425 left = rects->x & ~7; 1421 left = rects->x & ~7;
1426 width = (rects->w + 7) >> 3; 1422 width = (rects->w + 7) >> 3;
1427 height = rects->h; 1423 height = rects->h;
1434 phase = width; 1430 phase = width;
1435 width -= phase; 1431 width -= phase;
1436 } 1432 }
1437 1433
1438 while (height--) { 1434 while (height--) {
1439 writeSeq (0x02, 1 << 0); 1435 writeSeq(0x02, 1 << 0);
1440 dstPtr = dst; 1436 dstPtr = dst;
1441 srcPtr = src; 1437 srcPtr = src;
1442 i = width; 1438 i = width;
1443 j = phase; 1439 j = phase;
1444 while (j--) { 1440 while (j--) {
1471 << 4); 1467 << 4);
1472 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); 1468 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3);
1473 srcPtr += 2; 1469 srcPtr += 2;
1474 } 1470 }
1475 1471
1476 writeSeq (0x02, 1 << 1); 1472 writeSeq(0x02, 1 << 1);
1477 dstPtr = dst; 1473 dstPtr = dst;
1478 srcPtr = src; 1474 srcPtr = src;
1479 i = width; 1475 i = width;
1480 j = phase; 1476 j = phase;
1481 while (j--) { 1477 while (j--) {
1508 << 4); 1504 << 4);
1509 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); 1505 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2);
1510 srcPtr += 2; 1506 srcPtr += 2;
1511 } 1507 }
1512 1508
1513 writeSeq (0x02, 1 << 2); 1509 writeSeq(0x02, 1 << 2);
1514 dstPtr = dst; 1510 dstPtr = dst;
1515 srcPtr = src; 1511 srcPtr = src;
1516 i = width; 1512 i = width;
1517 j = phase; 1513 j = phase;
1518 while (j--) { 1514 while (j--) {
1545 << 4); 1541 << 4);
1546 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); 1542 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1);
1547 srcPtr += 2; 1543 srcPtr += 2;
1548 } 1544 }
1549 1545
1550 writeSeq (0x02, 1 << 3); 1546 writeSeq(0x02, 1 << 3);
1551 dstPtr = dst; 1547 dstPtr = dst;
1552 srcPtr = src; 1548 srcPtr = src;
1553 i = width; 1549 i = width;
1554 j = phase; 1550 j = phase;
1555 while (j--) { 1551 while (j--) {
1591 } 1587 }
1592 } 1588 }
1593 #endif /* VGA16_FBCON_SUPPORT */ 1589 #endif /* VGA16_FBCON_SUPPORT */
1594 1590
1595 void 1591 void
1596 FB_SavePaletteTo (_THIS, int palette_len, __u16 * area) 1592 FB_SavePaletteTo(_THIS, int palette_len, __u16 * area)
1597 { 1593 {
1598 struct fb_cmap cmap; 1594 struct fb_cmap cmap;
1599 1595
1600 cmap.start = 0; 1596 cmap.start = 0;
1601 cmap.len = palette_len; 1597 cmap.len = palette_len;
1602 cmap.red = &area[0 * palette_len]; 1598 cmap.red = &area[0 * palette_len];
1603 cmap.green = &area[1 * palette_len]; 1599 cmap.green = &area[1 * palette_len];
1604 cmap.blue = &area[2 * palette_len]; 1600 cmap.blue = &area[2 * palette_len];
1605 cmap.transp = NULL; 1601 cmap.transp = NULL;
1606 ioctl (console_fd, FBIOGETCMAP, &cmap); 1602 ioctl(console_fd, FBIOGETCMAP, &cmap);
1607 } 1603 }
1608 1604
1609 void 1605 void
1610 FB_RestorePaletteFrom (_THIS, int palette_len, __u16 * area) 1606 FB_RestorePaletteFrom(_THIS, int palette_len, __u16 * area)
1611 { 1607 {
1612 struct fb_cmap cmap; 1608 struct fb_cmap cmap;
1613 1609
1614 cmap.start = 0; 1610 cmap.start = 0;
1615 cmap.len = palette_len; 1611 cmap.len = palette_len;
1616 cmap.red = &area[0 * palette_len]; 1612 cmap.red = &area[0 * palette_len];
1617 cmap.green = &area[1 * palette_len]; 1613 cmap.green = &area[1 * palette_len];
1618 cmap.blue = &area[2 * palette_len]; 1614 cmap.blue = &area[2 * palette_len];
1619 cmap.transp = NULL; 1615 cmap.transp = NULL;
1620 ioctl (console_fd, FBIOPUTCMAP, &cmap); 1616 ioctl(console_fd, FBIOPUTCMAP, &cmap);
1621 } 1617 }
1622 1618
1623 static void 1619 static void
1624 FB_SavePalette (_THIS, struct fb_fix_screeninfo *finfo, 1620 FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,
1625 struct fb_var_screeninfo *vinfo) 1621 struct fb_var_screeninfo *vinfo)
1626 { 1622 {
1627 int i; 1623 int i;
1628 1624
1629 /* Save hardware palette, if needed */ 1625 /* Save hardware palette, if needed */
1630 if (finfo->visual == FB_VISUAL_PSEUDOCOLOR) { 1626 if (finfo->visual == FB_VISUAL_PSEUDOCOLOR) {
1631 saved_cmaplen = 1 << vinfo->bits_per_pixel; 1627 saved_cmaplen = 1 << vinfo->bits_per_pixel;
1632 saved_cmap = 1628 saved_cmap =
1633 (__u16 *) SDL_malloc (3 * saved_cmaplen * sizeof (*saved_cmap)); 1629 (__u16 *) SDL_malloc(3 * saved_cmaplen * sizeof(*saved_cmap));
1634 if (saved_cmap != NULL) { 1630 if (saved_cmap != NULL) {
1635 FB_SavePaletteTo (this, saved_cmaplen, saved_cmap); 1631 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
1636 } 1632 }
1637 } 1633 }
1638 1634
1639 /* Added support for FB_VISUAL_DIRECTCOLOR. 1635 /* Added support for FB_VISUAL_DIRECTCOLOR.
1640 With this mode pixel information is passed through the palette... 1636 With this mode pixel information is passed through the palette...
1649 __u16 new_entries[3 * 256]; 1645 __u16 new_entries[3 * 256];
1650 1646
1651 /* Save the colormap */ 1647 /* Save the colormap */
1652 saved_cmaplen = 256; 1648 saved_cmaplen = 256;
1653 saved_cmap = 1649 saved_cmap =
1654 (__u16 *) SDL_malloc (3 * saved_cmaplen * sizeof (*saved_cmap)); 1650 (__u16 *) SDL_malloc(3 * saved_cmaplen * sizeof(*saved_cmap));
1655 if (saved_cmap != NULL) { 1651 if (saved_cmap != NULL) {
1656 FB_SavePaletteTo (this, saved_cmaplen, saved_cmap); 1652 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap);
1657 } 1653 }
1658 1654
1659 /* Allocate new identity colormap */ 1655 /* Allocate new identity colormap */
1660 for (i = 0; i < 256; ++i) { 1656 for (i = 0; i < 256; ++i) {
1661 new_entries[(0 * 256) + i] = 1657 new_entries[(0 * 256) + i] =
1662 new_entries[(1 * 256) + i] = 1658 new_entries[(1 * 256) + i] =
1663 new_entries[(2 * 256) + i] = (i << 8) | i; 1659 new_entries[(2 * 256) + i] = (i << 8) | i;
1664 } 1660 }
1665 FB_RestorePaletteFrom (this, 256, new_entries); 1661 FB_RestorePaletteFrom(this, 256, new_entries);
1666 } 1662 }
1667 } 1663 }
1668 1664
1669 static void 1665 static void
1670 FB_RestorePalette (_THIS) 1666 FB_RestorePalette(_THIS)
1671 { 1667 {
1672 /* Restore the original palette */ 1668 /* Restore the original palette */
1673 if (saved_cmap) { 1669 if (saved_cmap) {
1674 FB_RestorePaletteFrom (this, saved_cmaplen, saved_cmap); 1670 FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap);
1675 SDL_free (saved_cmap); 1671 SDL_free(saved_cmap);
1676 saved_cmap = NULL; 1672 saved_cmap = NULL;
1677 } 1673 }
1678 } 1674 }
1679 1675
1680 static int 1676 static int
1681 FB_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 1677 FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1682 { 1678 {
1683 int i; 1679 int i;
1684 __u16 r[256]; 1680 __u16 r[256];
1685 __u16 g[256]; 1681 __u16 g[256];
1686 __u16 b[256]; 1682 __u16 b[256];
1697 cmap.red = r; 1693 cmap.red = r;
1698 cmap.green = g; 1694 cmap.green = g;
1699 cmap.blue = b; 1695 cmap.blue = b;
1700 cmap.transp = NULL; 1696 cmap.transp = NULL;
1701 1697
1702 if ((ioctl (console_fd, FBIOPUTCMAP, &cmap) < 0) || 1698 if ((ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) ||
1703 !(this->screen->flags & SDL_HWPALETTE)) { 1699 !(this->screen->flags & SDL_HWPALETTE)) {
1704 colors = this->screen->format->palette->colors; 1700 colors = this->screen->format->palette->colors;
1705 ncolors = this->screen->format->palette->ncolors; 1701 ncolors = this->screen->format->palette->ncolors;
1706 cmap.start = 0; 1702 cmap.start = 0;
1707 cmap.len = ncolors; 1703 cmap.len = ncolors;
1708 SDL_memset (r, 0, sizeof (r)); 1704 SDL_memset(r, 0, sizeof(r));
1709 SDL_memset (g, 0, sizeof (g)); 1705 SDL_memset(g, 0, sizeof(g));
1710 SDL_memset (b, 0, sizeof (b)); 1706 SDL_memset(b, 0, sizeof(b));
1711 if (ioctl (console_fd, FBIOGETCMAP, &cmap) == 0) { 1707 if (ioctl(console_fd, FBIOGETCMAP, &cmap) == 0) {
1712 for (i = ncolors - 1; i >= 0; --i) { 1708 for (i = ncolors - 1; i >= 0; --i) {
1713 colors[i].r = (r[i] >> 8); 1709 colors[i].r = (r[i] >> 8);
1714 colors[i].g = (g[i] >> 8); 1710 colors[i].g = (g[i] >> 8);
1715 colors[i].b = (b[i] >> 8); 1711 colors[i].b = (b[i] >> 8);
1716 } 1712 }
1722 1718
1723 /* Note: If we are terminated, this could be called in the middle of 1719 /* Note: If we are terminated, this could be called in the middle of
1724 another SDL video routine -- notably UpdateRects. 1720 another SDL video routine -- notably UpdateRects.
1725 */ 1721 */
1726 static void 1722 static void
1727 FB_VideoQuit (_THIS) 1723 FB_VideoQuit(_THIS)
1728 { 1724 {
1729 int i, j; 1725 int i, j;
1730 1726
1731 if (this->screen) { 1727 if (this->screen) {
1732 /* Clear screen and tell SDL not to free the pixels */ 1728 /* Clear screen and tell SDL not to free the pixels */
1733 if (this->screen->pixels && FB_InGraphicsMode (this)) { 1729 if (this->screen->pixels && FB_InGraphicsMode(this)) {
1734 #if defined(__powerpc__) || defined(__ia64__) /* SIGBUS when using SDL_memset() ?? */ 1730 #if defined(__powerpc__) || defined(__ia64__) /* SIGBUS when using SDL_memset() ?? */
1735 Uint8 *rowp = (Uint8 *) this->screen->pixels; 1731 Uint8 *rowp = (Uint8 *) this->screen->pixels;
1736 int left = this->screen->pitch * this->screen->h; 1732 int left = this->screen->pitch * this->screen->h;
1737 while (left--) { 1733 while (left--) {
1738 *rowp++ = 0; 1734 *rowp++ = 0;
1739 } 1735 }
1740 #else 1736 #else
1741 SDL_memset (this->screen->pixels, 0, 1737 SDL_memset(this->screen->pixels, 0,
1742 this->screen->h * this->screen->pitch); 1738 this->screen->h * this->screen->pitch);
1743 #endif 1739 #endif
1744 } 1740 }
1745 /* This test fails when using the VGA16 shadow memory */ 1741 /* This test fails when using the VGA16 shadow memory */
1746 if (((char *) this->screen->pixels >= mapped_mem) && 1742 if (((char *) this->screen->pixels >= mapped_mem) &&
1747 ((char *) this->screen->pixels < (mapped_mem + mapped_memlen))) { 1743 ((char *) this->screen->pixels < (mapped_mem + mapped_memlen))) {
1749 } 1745 }
1750 } 1746 }
1751 1747
1752 /* Clear the lock mutex */ 1748 /* Clear the lock mutex */
1753 if (hw_lock) { 1749 if (hw_lock) {
1754 SDL_DestroyMutex (hw_lock); 1750 SDL_DestroyMutex(hw_lock);
1755 hw_lock = NULL; 1751 hw_lock = NULL;
1756 } 1752 }
1757 1753
1758 /* Clean up defined video modes */ 1754 /* Clean up defined video modes */
1759 for (i = 0; i < NUM_MODELISTS; ++i) { 1755 for (i = 0; i < NUM_MODELISTS; ++i) {
1760 if (SDL_modelist[i] != NULL) { 1756 if (SDL_modelist[i] != NULL) {
1761 for (j = 0; SDL_modelist[i][j]; ++j) { 1757 for (j = 0; SDL_modelist[i][j]; ++j) {
1762 SDL_free (SDL_modelist[i][j]); 1758 SDL_free(SDL_modelist[i][j]);
1763 } 1759 }
1764 SDL_free (SDL_modelist[i]); 1760 SDL_free(SDL_modelist[i]);
1765 SDL_modelist[i] = NULL; 1761 SDL_modelist[i] = NULL;
1766 } 1762 }
1767 } 1763 }
1768 1764
1769 /* Clean up the memory bucket list */ 1765 /* Clean up the memory bucket list */
1770 FB_FreeHWSurfaces (this); 1766 FB_FreeHWSurfaces(this);
1771 1767
1772 /* Close console and input file descriptors */ 1768 /* Close console and input file descriptors */
1773 if (console_fd > 0) { 1769 if (console_fd > 0) {
1774 /* Unmap the video framebuffer and I/O registers */ 1770 /* Unmap the video framebuffer and I/O registers */
1775 if (mapped_mem) { 1771 if (mapped_mem) {
1776 munmap (mapped_mem, mapped_memlen); 1772 munmap(mapped_mem, mapped_memlen);
1777 mapped_mem = NULL; 1773 mapped_mem = NULL;
1778 } 1774 }
1779 if (mapped_io) { 1775 if (mapped_io) {
1780 munmap (mapped_io, mapped_iolen); 1776 munmap(mapped_io, mapped_iolen);
1781 mapped_io = NULL; 1777 mapped_io = NULL;
1782 } 1778 }
1783 1779
1784 /* Restore the original video mode and palette */ 1780 /* Restore the original video mode and palette */
1785 if (FB_InGraphicsMode (this)) { 1781 if (FB_InGraphicsMode(this)) {
1786 FB_RestorePalette (this); 1782 FB_RestorePalette(this);
1787 ioctl (console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); 1783 ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo);
1788 } 1784 }
1789 1785
1790 /* We're all done with the framebuffer */ 1786 /* We're all done with the framebuffer */
1791 close (console_fd); 1787 close(console_fd);
1792 console_fd = -1; 1788 console_fd = -1;
1793 } 1789 }
1794 FB_CloseMouse (this); 1790 FB_CloseMouse(this);
1795 FB_CloseKeyboard (this); 1791 FB_CloseKeyboard(this);
1796 } 1792 }
1797 1793
1798 /* vi: set ts=4 sw=4 expandtab: */ 1794 /* vi: set ts=4 sw=4 expandtab: */