Mercurial > sdl-ios-xcode
comparison src/video/svga/SDL_svgavideo.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 |
---|---|
49 #include "SDL_svgavideo.h" | 49 #include "SDL_svgavideo.h" |
50 #include "SDL_svgaevents_c.h" | 50 #include "SDL_svgaevents_c.h" |
51 #include "SDL_svgamouse_c.h" | 51 #include "SDL_svgamouse_c.h" |
52 | 52 |
53 /* Initialization/Query functions */ | 53 /* Initialization/Query functions */ |
54 static int SVGA_VideoInit (_THIS, SDL_PixelFormat * vformat); | 54 static int SVGA_VideoInit(_THIS, SDL_PixelFormat * vformat); |
55 static SDL_Rect **SVGA_ListModes (_THIS, SDL_PixelFormat * format, | 55 static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat * format, |
56 Uint32 flags); | 56 Uint32 flags); |
57 static SDL_Surface *SVGA_SetVideoMode (_THIS, SDL_Surface * current, | 57 static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface * current, |
58 int width, int height, int bpp, | 58 int width, int height, int bpp, |
59 Uint32 flags); | 59 Uint32 flags); |
60 static int SVGA_SetColors (_THIS, int firstcolor, int ncolors, | 60 static int SVGA_SetColors(_THIS, int firstcolor, int ncolors, |
61 SDL_Color * colors); | 61 SDL_Color * colors); |
62 static void SVGA_VideoQuit (_THIS); | 62 static void SVGA_VideoQuit(_THIS); |
63 | 63 |
64 /* Hardware surface functions */ | 64 /* Hardware surface functions */ |
65 static int SVGA_AllocHWSurface (_THIS, SDL_Surface * surface); | 65 static int SVGA_AllocHWSurface(_THIS, SDL_Surface * surface); |
66 static int SVGA_LockHWSurface (_THIS, SDL_Surface * surface); | 66 static int SVGA_LockHWSurface(_THIS, SDL_Surface * surface); |
67 static int SVGA_FlipHWSurface (_THIS, SDL_Surface * surface); | 67 static int SVGA_FlipHWSurface(_THIS, SDL_Surface * surface); |
68 static void SVGA_UnlockHWSurface (_THIS, SDL_Surface * surface); | 68 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface * surface); |
69 static void SVGA_FreeHWSurface (_THIS, SDL_Surface * surface); | 69 static void SVGA_FreeHWSurface(_THIS, SDL_Surface * surface); |
70 | 70 |
71 /* SVGAlib driver bootstrap functions */ | 71 /* SVGAlib driver bootstrap functions */ |
72 | 72 |
73 static int | 73 static int |
74 SVGA_Available (void) | 74 SVGA_Available(void) |
75 { | 75 { |
76 /* Check to see if we are root and stdin is a virtual console */ | 76 /* Check to see if we are root and stdin is a virtual console */ |
77 int console; | 77 int console; |
78 | 78 |
79 /* SVGALib 1.9.x+ doesn't require root (via /dev/svga) */ | 79 /* SVGALib 1.9.x+ doesn't require root (via /dev/svga) */ |
84 #if 0 /* This is no longer needed, SVGAlib can switch consoles for us */ | 84 #if 0 /* This is no longer needed, SVGAlib can switch consoles for us */ |
85 if (console >= 0) { | 85 if (console >= 0) { |
86 struct stat sb; | 86 struct stat sb; |
87 struct vt_mode dummy; | 87 struct vt_mode dummy; |
88 | 88 |
89 if ((fstat (console, &sb) < 0) || | 89 if ((fstat(console, &sb) < 0) || |
90 (ioctl (console, VT_GETMODE, &dummy) < 0)) { | 90 (ioctl(console, VT_GETMODE, &dummy) < 0)) { |
91 console = -1; | 91 console = -1; |
92 } | 92 } |
93 } | 93 } |
94 #endif /* 0 */ | 94 #endif /* 0 */ |
95 | 95 |
96 /* See if SVGAlib 2.0 is available */ | 96 /* See if SVGAlib 2.0 is available */ |
97 svgalib2 = open ("/dev/svga", O_RDONLY); | 97 svgalib2 = open("/dev/svga", O_RDONLY); |
98 if (svgalib2 != -1) { | 98 if (svgalib2 != -1) { |
99 close (svgalib2); | 99 close(svgalib2); |
100 } | 100 } |
101 | 101 |
102 return (((svgalib2 != -1) || (geteuid () == 0)) && (console >= 0)); | 102 return (((svgalib2 != -1) || (geteuid() == 0)) && (console >= 0)); |
103 } | 103 } |
104 | 104 |
105 static void | 105 static void |
106 SVGA_DeleteDevice (SDL_VideoDevice * device) | 106 SVGA_DeleteDevice(SDL_VideoDevice * device) |
107 { | 107 { |
108 SDL_free (device->hidden); | 108 SDL_free(device->hidden); |
109 SDL_free (device); | 109 SDL_free(device); |
110 } | 110 } |
111 | 111 |
112 static SDL_VideoDevice * | 112 static SDL_VideoDevice * |
113 SVGA_CreateDevice (int devindex) | 113 SVGA_CreateDevice(int devindex) |
114 { | 114 { |
115 SDL_VideoDevice *device; | 115 SDL_VideoDevice *device; |
116 | 116 |
117 /* Initialize all variables that we clean on shutdown */ | 117 /* Initialize all variables that we clean on shutdown */ |
118 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); | 118 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice)); |
119 if (device) { | 119 if (device) { |
120 SDL_memset (device, 0, (sizeof *device)); | 120 SDL_memset(device, 0, (sizeof *device)); |
121 device->hidden = (struct SDL_PrivateVideoData *) | 121 device->hidden = (struct SDL_PrivateVideoData *) |
122 SDL_malloc ((sizeof *device->hidden)); | 122 SDL_malloc((sizeof *device->hidden)); |
123 } | 123 } |
124 if ((device == NULL) || (device->hidden == NULL)) { | 124 if ((device == NULL) || (device->hidden == NULL)) { |
125 SDL_OutOfMemory (); | 125 SDL_OutOfMemory(); |
126 if (device) { | 126 if (device) { |
127 SDL_free (device); | 127 SDL_free(device); |
128 } | 128 } |
129 return (0); | 129 return (0); |
130 } | 130 } |
131 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); | 131 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
132 | 132 |
133 /* Set the function pointers */ | 133 /* Set the function pointers */ |
134 device->VideoInit = SVGA_VideoInit; | 134 device->VideoInit = SVGA_VideoInit; |
135 device->ListModes = SVGA_ListModes; | 135 device->ListModes = SVGA_ListModes; |
136 device->SetVideoMode = SVGA_SetVideoMode; | 136 device->SetVideoMode = SVGA_SetVideoMode; |
163 "svgalib", "SVGAlib", | 163 "svgalib", "SVGAlib", |
164 SVGA_Available, SVGA_CreateDevice | 164 SVGA_Available, SVGA_CreateDevice |
165 }; | 165 }; |
166 | 166 |
167 static int | 167 static int |
168 SVGA_AddMode (_THIS, int mode, int actually_add) | 168 SVGA_AddMode(_THIS, int mode, int actually_add) |
169 { | 169 { |
170 int i, j; | 170 int i, j; |
171 vga_modeinfo *modeinfo; | 171 vga_modeinfo *modeinfo; |
172 | 172 |
173 modeinfo = vga_getmodeinfo (mode); | 173 modeinfo = vga_getmodeinfo(mode); |
174 | 174 |
175 i = modeinfo->bytesperpixel - 1; | 175 i = modeinfo->bytesperpixel - 1; |
176 if (i < 0) { | 176 if (i < 0) { |
177 return 0; | 177 return 0; |
178 } | 178 } |
216 } | 216 } |
217 return (1); | 217 return (1); |
218 } | 218 } |
219 | 219 |
220 static void | 220 static void |
221 SVGA_UpdateVideoInfo (_THIS) | 221 SVGA_UpdateVideoInfo(_THIS) |
222 { | 222 { |
223 vga_modeinfo *modeinfo; | 223 vga_modeinfo *modeinfo; |
224 | 224 |
225 this->info.wm_available = 0; | 225 this->info.wm_available = 0; |
226 this->info.hw_available = (banked ? 0 : 1); | 226 this->info.hw_available = (banked ? 0 : 1); |
227 modeinfo = vga_getmodeinfo (vga_getcurrentmode ()); | 227 modeinfo = vga_getmodeinfo(vga_getcurrentmode()); |
228 this->info.video_mem = modeinfo->memory; | 228 this->info.video_mem = modeinfo->memory; |
229 /* FIXME: Add hardware accelerated blit information */ | 229 /* FIXME: Add hardware accelerated blit information */ |
230 #ifdef SVGALIB_DEBUG | 230 #ifdef SVGALIB_DEBUG |
231 printf ("Hardware accelerated blit: %savailable\n", | 231 printf("Hardware accelerated blit: %savailable\n", |
232 modeinfo->haveblit ? "" : "not "); | 232 modeinfo->haveblit ? "" : "not "); |
233 #endif | 233 #endif |
234 } | 234 } |
235 | 235 |
236 int | 236 int |
237 SVGA_VideoInit (_THIS, SDL_PixelFormat * vformat) | 237 SVGA_VideoInit(_THIS, SDL_PixelFormat * vformat) |
238 { | 238 { |
239 int keyboard; | 239 int keyboard; |
240 int i, j; | 240 int i, j; |
241 int mode, total_modes; | 241 int mode, total_modes; |
242 | 242 |
246 SDL_modelist[i] = NULL; | 246 SDL_modelist[i] = NULL; |
247 SDL_vgamode[i] = NULL; | 247 SDL_vgamode[i] = NULL; |
248 } | 248 } |
249 | 249 |
250 /* Initialize the library */ | 250 /* Initialize the library */ |
251 vga_disabledriverreport (); | 251 vga_disabledriverreport(); |
252 if (vga_init () < 0) { | 252 if (vga_init() < 0) { |
253 SDL_SetError ("Unable to initialize SVGAlib"); | 253 SDL_SetError("Unable to initialize SVGAlib"); |
254 return (-1); | 254 return (-1); |
255 } | 255 } |
256 vga_setmode (TEXT); | 256 vga_setmode(TEXT); |
257 | 257 |
258 /* Enable mouse and keyboard support */ | 258 /* Enable mouse and keyboard support */ |
259 vga_setmousesupport (1); | 259 vga_setmousesupport(1); |
260 keyboard = keyboard_init_return_fd (); | 260 keyboard = keyboard_init_return_fd(); |
261 if (keyboard < 0) { | 261 if (keyboard < 0) { |
262 SDL_SetError ("Unable to initialize keyboard"); | 262 SDL_SetError("Unable to initialize keyboard"); |
263 return (-1); | 263 return (-1); |
264 } | 264 } |
265 if (SVGA_initkeymaps (keyboard) < 0) { | 265 if (SVGA_initkeymaps(keyboard) < 0) { |
266 return (-1); | 266 return (-1); |
267 } | 267 } |
268 keyboard_seteventhandler (SVGA_keyboardcallback); | 268 keyboard_seteventhandler(SVGA_keyboardcallback); |
269 | 269 |
270 /* Determine the current screen size */ | 270 /* Determine the current screen size */ |
271 this->info.current_w = 0; | 271 this->info.current_w = 0; |
272 this->info.current_h = 0; | 272 this->info.current_h = 0; |
273 | 273 |
274 /* Determine the screen depth (use default 8-bit depth) */ | 274 /* Determine the screen depth (use default 8-bit depth) */ |
275 vformat->BitsPerPixel = 8; | 275 vformat->BitsPerPixel = 8; |
276 | 276 |
277 /* Enumerate the available fullscreen modes */ | 277 /* Enumerate the available fullscreen modes */ |
278 total_modes = 0; | 278 total_modes = 0; |
279 for (mode = vga_lastmodenumber (); mode; --mode) { | 279 for (mode = vga_lastmodenumber(); mode; --mode) { |
280 if (vga_hasmode (mode)) { | 280 if (vga_hasmode(mode)) { |
281 if (SVGA_AddMode (this, mode, 0)) { | 281 if (SVGA_AddMode(this, mode, 0)) { |
282 ++total_modes; | 282 ++total_modes; |
283 } | 283 } |
284 } | 284 } |
285 } | 285 } |
286 if (SVGA_AddMode (this, G320x200x256, 0)) | 286 if (SVGA_AddMode(this, G320x200x256, 0)) |
287 ++total_modes; | 287 ++total_modes; |
288 if (total_modes == 0) { | 288 if (total_modes == 0) { |
289 SDL_SetError ("No linear video modes available"); | 289 SDL_SetError("No linear video modes available"); |
290 return (-1); | 290 return (-1); |
291 } | 291 } |
292 for (i = 0; i < NUM_MODELISTS; ++i) { | 292 for (i = 0; i < NUM_MODELISTS; ++i) { |
293 SDL_vgamode[i] = (int *) SDL_malloc (SDL_nummodes[i] * sizeof (int)); | 293 SDL_vgamode[i] = (int *) SDL_malloc(SDL_nummodes[i] * sizeof(int)); |
294 if (SDL_vgamode[i] == NULL) { | 294 if (SDL_vgamode[i] == NULL) { |
295 SDL_OutOfMemory (); | 295 SDL_OutOfMemory(); |
296 return (-1); | 296 return (-1); |
297 } | 297 } |
298 SDL_modelist[i] = (SDL_Rect **) | 298 SDL_modelist[i] = (SDL_Rect **) |
299 SDL_malloc ((SDL_nummodes[i] + 1) * sizeof (SDL_Rect *)); | 299 SDL_malloc((SDL_nummodes[i] + 1) * sizeof(SDL_Rect *)); |
300 if (SDL_modelist[i] == NULL) { | 300 if (SDL_modelist[i] == NULL) { |
301 SDL_OutOfMemory (); | 301 SDL_OutOfMemory(); |
302 return (-1); | 302 return (-1); |
303 } | 303 } |
304 for (j = 0; j < SDL_nummodes[i]; ++j) { | 304 for (j = 0; j < SDL_nummodes[i]; ++j) { |
305 SDL_modelist[i][j] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect)); | 305 SDL_modelist[i][j] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); |
306 if (SDL_modelist[i][j] == NULL) { | 306 if (SDL_modelist[i][j] == NULL) { |
307 SDL_OutOfMemory (); | 307 SDL_OutOfMemory(); |
308 return (-1); | 308 return (-1); |
309 } | 309 } |
310 SDL_memset (SDL_modelist[i][j], 0, sizeof (SDL_Rect)); | 310 SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect)); |
311 } | 311 } |
312 SDL_modelist[i][j] = NULL; | 312 SDL_modelist[i][j] = NULL; |
313 } | 313 } |
314 for (mode = vga_lastmodenumber (); mode; --mode) { | 314 for (mode = vga_lastmodenumber(); mode; --mode) { |
315 if (vga_hasmode (mode)) { | 315 if (vga_hasmode(mode)) { |
316 SVGA_AddMode (this, mode, 1); | 316 SVGA_AddMode(this, mode, 1); |
317 } | 317 } |
318 } | 318 } |
319 SVGA_AddMode (this, G320x200x256, 1); | 319 SVGA_AddMode(this, G320x200x256, 1); |
320 | 320 |
321 /* Free extra (duplicated) modes */ | 321 /* Free extra (duplicated) modes */ |
322 for (i = 0; i < NUM_MODELISTS; ++i) { | 322 for (i = 0; i < NUM_MODELISTS; ++i) { |
323 j = 0; | 323 j = 0; |
324 while (SDL_modelist[i][j] && SDL_modelist[i][j]->w) { | 324 while (SDL_modelist[i][j] && SDL_modelist[i][j]->w) { |
325 j++; | 325 j++; |
326 } | 326 } |
327 while (SDL_modelist[i][j]) { | 327 while (SDL_modelist[i][j]) { |
328 SDL_free (SDL_modelist[i][j]); | 328 SDL_free(SDL_modelist[i][j]); |
329 SDL_modelist[i][j] = NULL; | 329 SDL_modelist[i][j] = NULL; |
330 j++; | 330 j++; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 /* Fill in our hardware acceleration capabilities */ | 334 /* Fill in our hardware acceleration capabilities */ |
335 SVGA_UpdateVideoInfo (this); | 335 SVGA_UpdateVideoInfo(this); |
336 | 336 |
337 /* We're done! */ | 337 /* We're done! */ |
338 return (0); | 338 return (0); |
339 } | 339 } |
340 | 340 |
341 SDL_Rect ** | 341 SDL_Rect ** |
342 SVGA_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) | 342 SVGA_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags) |
343 { | 343 { |
344 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); | 344 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]); |
345 } | 345 } |
346 | 346 |
347 /* Various screen update functions available */ | 347 /* Various screen update functions available */ |
348 static void SVGA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects); | 348 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects); |
349 static void SVGA_BankedUpdate (_THIS, int numrects, SDL_Rect * rects); | 349 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect * rects); |
350 | 350 |
351 SDL_Surface * | 351 SDL_Surface * |
352 SVGA_SetVideoMode (_THIS, SDL_Surface * current, | 352 SVGA_SetVideoMode(_THIS, SDL_Surface * current, |
353 int width, int height, int bpp, Uint32 flags) | 353 int width, int height, int bpp, Uint32 flags) |
354 { | 354 { |
355 int mode; | 355 int mode; |
356 int vgamode; | 356 int vgamode; |
357 vga_modeinfo *modeinfo; | 357 vga_modeinfo *modeinfo; |
358 int screenpage_len; | 358 int screenpage_len; |
359 | 359 |
360 /* Free old pixels if we were in banked mode */ | 360 /* Free old pixels if we were in banked mode */ |
361 if (banked && current->pixels) { | 361 if (banked && current->pixels) { |
362 free (current->pixels); | 362 free(current->pixels); |
363 current->pixels = NULL; | 363 current->pixels = NULL; |
364 } | 364 } |
365 | 365 |
366 /* Try to set the requested linear video mode */ | 366 /* Try to set the requested linear video mode */ |
367 bpp = (bpp + 7) / 8 - 1; | 367 bpp = (bpp + 7) / 8 - 1; |
370 (SDL_modelist[bpp][mode]->h == height)) { | 370 (SDL_modelist[bpp][mode]->h == height)) { |
371 break; | 371 break; |
372 } | 372 } |
373 } | 373 } |
374 if (SDL_modelist[bpp][mode] == NULL) { | 374 if (SDL_modelist[bpp][mode] == NULL) { |
375 SDL_SetError ("Couldn't find requested mode in list"); | 375 SDL_SetError("Couldn't find requested mode in list"); |
376 return (NULL); | 376 return (NULL); |
377 } | 377 } |
378 vgamode = SDL_vgamode[bpp][mode]; | 378 vgamode = SDL_vgamode[bpp][mode]; |
379 vga_setmode (vgamode); | 379 vga_setmode(vgamode); |
380 vga_setpage (0); | 380 vga_setpage(0); |
381 | 381 |
382 if ((vga_setlinearaddressing () < 0) && (vgamode != G320x200x256)) { | 382 if ((vga_setlinearaddressing() < 0) && (vgamode != G320x200x256)) { |
383 banked = 1; | 383 banked = 1; |
384 } else { | 384 } else { |
385 banked = 0; | 385 banked = 0; |
386 } | 386 } |
387 | 387 |
388 modeinfo = vga_getmodeinfo (SDL_vgamode[bpp][mode]); | 388 modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); |
389 | 389 |
390 /* Update hardware acceleration info */ | 390 /* Update hardware acceleration info */ |
391 SVGA_UpdateVideoInfo (this); | 391 SVGA_UpdateVideoInfo(this); |
392 | 392 |
393 /* Allocate the new pixel format for the screen */ | 393 /* Allocate the new pixel format for the screen */ |
394 bpp = (bpp + 1) * 8; | 394 bpp = (bpp + 1) * 8; |
395 if ((bpp == 16) && (modeinfo->colors == 32768)) { | 395 if ((bpp == 16) && (modeinfo->colors == 32768)) { |
396 bpp = 15; | 396 bpp = 15; |
397 } | 397 } |
398 if (!SDL_ReallocFormat (current, bpp, 0, 0, 0, 0)) { | 398 if (!SDL_ReallocFormat(current, bpp, 0, 0, 0, 0)) { |
399 return (NULL); | 399 return (NULL); |
400 } | 400 } |
401 | 401 |
402 /* Set up the new mode framebuffer */ | 402 /* Set up the new mode framebuffer */ |
403 current->flags = SDL_FULLSCREEN; | 403 current->flags = SDL_FULLSCREEN; |
410 } | 410 } |
411 current->w = width; | 411 current->w = width; |
412 current->h = height; | 412 current->h = height; |
413 current->pitch = modeinfo->linewidth; | 413 current->pitch = modeinfo->linewidth; |
414 if (banked) { | 414 if (banked) { |
415 current->pixels = SDL_malloc (current->h * current->pitch); | 415 current->pixels = SDL_malloc(current->h * current->pitch); |
416 if (!current->pixels) { | 416 if (!current->pixels) { |
417 SDL_OutOfMemory (); | 417 SDL_OutOfMemory(); |
418 return (NULL); | 418 return (NULL); |
419 } | 419 } |
420 } else { | 420 } else { |
421 current->pixels = vga_getgraphmem (); | 421 current->pixels = vga_getgraphmem(); |
422 } | 422 } |
423 | 423 |
424 /* set double-buffering */ | 424 /* set double-buffering */ |
425 if ((flags & SDL_DOUBLEBUF) && !banked) { | 425 if ((flags & SDL_DOUBLEBUF) && !banked) { |
426 /* length of one screen page in bytes */ | 426 /* length of one screen page in bytes */ |
439 if (modeinfo->memory > (screenpage_len * 2 / 1024)) { | 439 if (modeinfo->memory > (screenpage_len * 2 / 1024)) { |
440 current->flags |= SDL_DOUBLEBUF; | 440 current->flags |= SDL_DOUBLEBUF; |
441 flip_page = 0; | 441 flip_page = 0; |
442 flip_offset[0] = 0; | 442 flip_offset[0] = 0; |
443 flip_offset[1] = screenpage_len; | 443 flip_offset[1] = screenpage_len; |
444 flip_address[0] = vga_getgraphmem (); | 444 flip_address[0] = vga_getgraphmem(); |
445 flip_address[1] = flip_address[0] + screenpage_len; | 445 flip_address[1] = flip_address[0] + screenpage_len; |
446 SVGA_FlipHWSurface (this, current); | 446 SVGA_FlipHWSurface(this, current); |
447 } | 447 } |
448 } | 448 } |
449 | 449 |
450 /* Set the blit function */ | 450 /* Set the blit function */ |
451 if (banked) { | 451 if (banked) { |
453 } else { | 453 } else { |
454 this->UpdateRects = SVGA_DirectUpdate; | 454 this->UpdateRects = SVGA_DirectUpdate; |
455 } | 455 } |
456 | 456 |
457 /* Set up the mouse handler again (buggy SVGAlib 1.40) */ | 457 /* Set up the mouse handler again (buggy SVGAlib 1.40) */ |
458 mouse_seteventhandler (SVGA_mousecallback); | 458 mouse_seteventhandler(SVGA_mousecallback); |
459 | 459 |
460 /* We're done */ | 460 /* We're done */ |
461 return (current); | 461 return (current); |
462 } | 462 } |
463 | 463 |
464 /* We don't actually allow hardware surfaces other than the main one */ | 464 /* We don't actually allow hardware surfaces other than the main one */ |
465 static int | 465 static int |
466 SVGA_AllocHWSurface (_THIS, SDL_Surface * surface) | 466 SVGA_AllocHWSurface(_THIS, SDL_Surface * surface) |
467 { | 467 { |
468 return (-1); | 468 return (-1); |
469 } | 469 } |
470 static void | 470 static void |
471 SVGA_FreeHWSurface (_THIS, SDL_Surface * surface) | 471 SVGA_FreeHWSurface(_THIS, SDL_Surface * surface) |
472 { | 472 { |
473 return; | 473 return; |
474 } | 474 } |
475 | 475 |
476 /* We need to wait for vertical retrace on page flipped displays */ | 476 /* We need to wait for vertical retrace on page flipped displays */ |
477 static int | 477 static int |
478 SVGA_LockHWSurface (_THIS, SDL_Surface * surface) | 478 SVGA_LockHWSurface(_THIS, SDL_Surface * surface) |
479 { | 479 { |
480 /* The waiting is done in SVGA_FlipHWSurface() */ | 480 /* The waiting is done in SVGA_FlipHWSurface() */ |
481 return (0); | 481 return (0); |
482 } | 482 } |
483 static void | 483 static void |
484 SVGA_UnlockHWSurface (_THIS, SDL_Surface * surface) | 484 SVGA_UnlockHWSurface(_THIS, SDL_Surface * surface) |
485 { | 485 { |
486 return; | 486 return; |
487 } | 487 } |
488 | 488 |
489 static int | 489 static int |
490 SVGA_FlipHWSurface (_THIS, SDL_Surface * surface) | 490 SVGA_FlipHWSurface(_THIS, SDL_Surface * surface) |
491 { | 491 { |
492 if (!banked) { | 492 if (!banked) { |
493 vga_setdisplaystart (flip_offset[flip_page]); | 493 vga_setdisplaystart(flip_offset[flip_page]); |
494 flip_page = !flip_page; | 494 flip_page = !flip_page; |
495 surface->pixels = flip_address[flip_page]; | 495 surface->pixels = flip_address[flip_page]; |
496 vga_waitretrace (); | 496 vga_waitretrace(); |
497 } | 497 } |
498 return (0); | 498 return (0); |
499 } | 499 } |
500 | 500 |
501 static void | 501 static void |
502 SVGA_DirectUpdate (_THIS, int numrects, SDL_Rect * rects) | 502 SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects) |
503 { | 503 { |
504 return; | 504 return; |
505 } | 505 } |
506 | 506 |
507 static void | 507 static void |
508 SVGA_BankedUpdate (_THIS, int numrects, SDL_Rect * rects) | 508 SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect * rects) |
509 { | 509 { |
510 int i, j; | 510 int i, j; |
511 SDL_Rect *rect; | 511 SDL_Rect *rect; |
512 int page, vp; | 512 int page, vp; |
513 int x, y, w, h; | 513 int x, y, w, h; |
514 unsigned char *src; | 514 unsigned char *src; |
515 unsigned char *dst; | 515 unsigned char *dst; |
516 int bpp = this->screen->format->BytesPerPixel; | 516 int bpp = this->screen->format->BytesPerPixel; |
517 int pitch = this->screen->pitch; | 517 int pitch = this->screen->pitch; |
518 | 518 |
519 dst = vga_getgraphmem (); | 519 dst = vga_getgraphmem(); |
520 for (i = 0; i < numrects; ++i) { | 520 for (i = 0; i < numrects; ++i) { |
521 rect = &rects[i]; | 521 rect = &rects[i]; |
522 x = rect->x; | 522 x = rect->x; |
523 y = rect->y; | 523 y = rect->y; |
524 w = rect->w * bpp; | 524 w = rect->w * bpp; |
526 | 526 |
527 vp = y * pitch + x * bpp; | 527 vp = y * pitch + x * bpp; |
528 src = (unsigned char *) this->screen->pixels + vp; | 528 src = (unsigned char *) this->screen->pixels + vp; |
529 page = vp >> 16; | 529 page = vp >> 16; |
530 vp &= 0xffff; | 530 vp &= 0xffff; |
531 vga_setpage (page); | 531 vga_setpage(page); |
532 for (j = 0; j < h; j++) { | 532 for (j = 0; j < h; j++) { |
533 if (vp + w > 0x10000) { | 533 if (vp + w > 0x10000) { |
534 if (vp >= 0x10000) { | 534 if (vp >= 0x10000) { |
535 page++; | 535 page++; |
536 vga_setpage (page); | 536 vga_setpage(page); |
537 vp &= 0xffff; | 537 vp &= 0xffff; |
538 } else { | 538 } else { |
539 SDL_memcpy (dst + vp, src, 0x10000 - vp); | 539 SDL_memcpy(dst + vp, src, 0x10000 - vp); |
540 page++; | 540 page++; |
541 vga_setpage (page); | 541 vga_setpage(page); |
542 SDL_memcpy (dst, src + 0x10000 - vp, (vp + w) & 0xffff); | 542 SDL_memcpy(dst, src + 0x10000 - vp, (vp + w) & 0xffff); |
543 vp = (vp + pitch) & 0xffff; | 543 vp = (vp + pitch) & 0xffff; |
544 src += pitch; | 544 src += pitch; |
545 continue; | 545 continue; |
546 } | 546 } |
547 } | 547 } |
548 SDL_memcpy (dst + vp, src, w); | 548 SDL_memcpy(dst + vp, src, w); |
549 src += pitch; | 549 src += pitch; |
550 vp += pitch; | 550 vp += pitch; |
551 } | 551 } |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 int | 555 int |
556 SVGA_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) | 556 SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors) |
557 { | 557 { |
558 int i; | 558 int i; |
559 | 559 |
560 for (i = 0; i < ncolors; i++) { | 560 for (i = 0; i < ncolors; i++) { |
561 vga_setpalette (firstcolor + i, | 561 vga_setpalette(firstcolor + i, |
562 colors[i].r >> 2, colors[i].g >> 2, colors[i].b >> 2); | 562 colors[i].r >> 2, colors[i].g >> 2, colors[i].b >> 2); |
563 } | 563 } |
564 return (1); | 564 return (1); |
565 } | 565 } |
566 | 566 |
567 /* Note: If we are terminated, this could be called in the middle of | 567 /* Note: If we are terminated, this could be called in the middle of |
568 another SDL video routine -- notably UpdateRects. | 568 another SDL video routine -- notably UpdateRects. |
569 */ | 569 */ |
570 void | 570 void |
571 SVGA_VideoQuit (_THIS) | 571 SVGA_VideoQuit(_THIS) |
572 { | 572 { |
573 int i, j; | 573 int i, j; |
574 | 574 |
575 /* Reset the console video mode */ | 575 /* Reset the console video mode */ |
576 if (this->screen && (this->screen->w && this->screen->h)) { | 576 if (this->screen && (this->screen->w && this->screen->h)) { |
577 vga_setmode (TEXT); | 577 vga_setmode(TEXT); |
578 } | 578 } |
579 keyboard_close (); | 579 keyboard_close(); |
580 | 580 |
581 /* Free video mode lists */ | 581 /* Free video mode lists */ |
582 for (i = 0; i < NUM_MODELISTS; ++i) { | 582 for (i = 0; i < NUM_MODELISTS; ++i) { |
583 if (SDL_modelist[i] != NULL) { | 583 if (SDL_modelist[i] != NULL) { |
584 for (j = 0; SDL_modelist[i][j]; ++j) | 584 for (j = 0; SDL_modelist[i][j]; ++j) |
585 SDL_free (SDL_modelist[i][j]); | 585 SDL_free(SDL_modelist[i][j]); |
586 SDL_free (SDL_modelist[i]); | 586 SDL_free(SDL_modelist[i]); |
587 SDL_modelist[i] = NULL; | 587 SDL_modelist[i] = NULL; |
588 } | 588 } |
589 if (SDL_vgamode[i] != NULL) { | 589 if (SDL_vgamode[i] != NULL) { |
590 SDL_free (SDL_vgamode[i]); | 590 SDL_free(SDL_vgamode[i]); |
591 SDL_vgamode[i] = NULL; | 591 SDL_vgamode[i] = NULL; |
592 } | 592 } |
593 } | 593 } |
594 if (this->screen) { | 594 if (this->screen) { |
595 if (banked && this->screen->pixels) { | 595 if (banked && this->screen->pixels) { |
596 SDL_free (this->screen->pixels); | 596 SDL_free(this->screen->pixels); |
597 } | 597 } |
598 this->screen->pixels = NULL; | 598 this->screen->pixels = NULL; |
599 } | 599 } |
600 } | 600 } |
601 | 601 |