comparison src/video/cybergfx/SDL_cgxvideo.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
41 #include "SDL_amigaevents_c.h" 41 #include "SDL_amigaevents_c.h"
42 #include "SDL_cgxmodes_c.h" 42 #include "SDL_cgxmodes_c.h"
43 #include "SDL_cgximage_c.h" 43 #include "SDL_cgximage_c.h"
44 44
45 /* Initialization/Query functions */ 45 /* Initialization/Query functions */
46 static int CGX_VideoInit (_THIS, SDL_PixelFormat * vformat); 46 static int CGX_VideoInit(_THIS, SDL_PixelFormat * vformat);
47 static SDL_Surface *CGX_SetVideoMode (_THIS, SDL_Surface * current, int width, 47 static SDL_Surface *CGX_SetVideoMode(_THIS, SDL_Surface * current, int width,
48 int height, int bpp, Uint32 flags); 48 int height, int bpp, Uint32 flags);
49 static int CGX_ToggleFullScreen (_THIS, int on); 49 static int CGX_ToggleFullScreen(_THIS, int on);
50 static void CGX_UpdateMouse (_THIS); 50 static void CGX_UpdateMouse(_THIS);
51 static int CGX_SetColors (_THIS, int firstcolor, int ncolors, 51 static int CGX_SetColors(_THIS, int firstcolor, int ncolors,
52 SDL_Color * colors); 52 SDL_Color * colors);
53 static void CGX_VideoQuit (_THIS); 53 static void CGX_VideoQuit(_THIS);
54 54
55 /* CGX driver bootstrap functions */ 55 /* CGX driver bootstrap functions */
56 56
57 struct Library *CyberGfxBase = NULL; 57 struct Library *CyberGfxBase = NULL;
58 struct IntuitionBase *IntuitionBase = NULL; 58 struct IntuitionBase *IntuitionBase = NULL;
59 struct GfxBase *GfxBase = NULL; 59 struct GfxBase *GfxBase = NULL;
60 60
61 int 61 int
62 CGX_SetGamma (_THIS, float red, float green, float blue) 62 CGX_SetGamma(_THIS, float red, float green, float blue)
63 { 63 {
64 SDL_SetError ("Gamma correction not supported"); 64 SDL_SetError("Gamma correction not supported");
65 return -1; 65 return -1;
66 } 66 }
67 67
68 int 68 int
69 CGX_GetGamma (_THIS, float red, float green, float blue) 69 CGX_GetGamma(_THIS, float red, float green, float blue)
70 { 70 {
71 SDL_SetError ("Gamma correction not supported"); 71 SDL_SetError("Gamma correction not supported");
72 return -1; 72 return -1;
73 } 73 }
74 74
75 int 75 int
76 CGX_SetGammaRamp (_THIS, Uint16 * ramp) 76 CGX_SetGammaRamp(_THIS, Uint16 * ramp)
77 { 77 {
78 #if 0 78 #if 0
79 Int i, ncolors; 79 Int i, ncolors;
80 XColor xcmap[256]; 80 XColor xcmap[256];
81 81
82 /* See if actually setting the gamma is supported */ 82 /* See if actually setting the gamma is supported */
83 if (SDL_Visual->class != DirectColor) { 83 if (SDL_Visual->class != DirectColor) {
84 SDL_SetError ("Gamma correction not supported on this visual"); 84 SDL_SetError("Gamma correction not supported on this visual");
85 return (-1); 85 return (-1);
86 } 86 }
87 87
88 /* Calculate the appropriate palette for the given gamma ramp */ 88 /* Calculate the appropriate palette for the given gamma ramp */
89 ncolors = SDL_Visual->map_entries; 89 ncolors = SDL_Visual->map_entries;
90 for (i = 0; i < ncolors; ++i) { 90 for (i = 0; i < ncolors; ++i) {
91 Uint8 c = (256 * i / ncolors); 91 Uint8 c = (256 * i / ncolors);
92 xcmap[i].pixel = SDL_MapRGB (this->screen->format, c, c, c); 92 xcmap[i].pixel = SDL_MapRGB(this->screen->format, c, c, c);
93 xcmap[i].red = ramp[0 * 256 + c]; 93 xcmap[i].red = ramp[0 * 256 + c];
94 xcmap[i].green = ramp[1 * 256 + c]; 94 xcmap[i].green = ramp[1 * 256 + c];
95 xcmap[i].blue = ramp[2 * 256 + c]; 95 xcmap[i].blue = ramp[2 * 256 + c];
96 xcmap[i].flags = (DoRed | DoGreen | DoBlue); 96 xcmap[i].flags = (DoRed | DoGreen | DoBlue);
97 } 97 }
98 XStoreColors (GFX_Display, SDL_XColorMap, xcmap, ncolors); 98 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
99 XSync (GFX_Display, False); 99 XSync(GFX_Display, False);
100 100
101 return (0); 101 return (0);
102 102
103 #else 103 #else
104 SDL_SetError ("Gamma correction not supported on this visual"); 104 SDL_SetError("Gamma correction not supported on this visual");
105 return (-1); 105 return (-1);
106 106
107 #endif 107 #endif
108 } 108 }
109 109
110 static void 110 static void
111 DestroyScreen (_THIS) 111 DestroyScreen(_THIS)
112 { 112 {
113 if (currently_fullscreen) { 113 if (currently_fullscreen) {
114 if (this->hidden->dbuffer) { 114 if (this->hidden->dbuffer) {
115 extern struct MsgPort *safeport, *dispport; 115 extern struct MsgPort *safeport, *dispport;
116 116
117 this->hidden->dbuffer = 0; 117 this->hidden->dbuffer = 0;
118 118
119 if (safeport) { 119 if (safeport) {
120 while (GetMsg (safeport) != NULL); 120 while (GetMsg(safeport) != NULL);
121 DeleteMsgPort (safeport); 121 DeleteMsgPort(safeport);
122 } 122 }
123 if (dispport) { 123 if (dispport) {
124 while (GetMsg (dispport) != NULL); 124 while (GetMsg(dispport) != NULL);
125 DeleteMsgPort (dispport); 125 DeleteMsgPort(dispport);
126 } 126 }
127 127
128 this->hidden->SB[0]->sb_DBufInfo->dbi_SafeMessage. 128 this->hidden->SB[0]->sb_DBufInfo->dbi_SafeMessage.
129 mn_ReplyPort = 129 mn_ReplyPort =
130 this->hidden->SB[0]->sb_DBufInfo->dbi_DispMessage. 130 this->hidden->SB[0]->sb_DBufInfo->dbi_DispMessage.
133 mn_ReplyPort = 133 mn_ReplyPort =
134 this->hidden->SB[1]->sb_DBufInfo->dbi_DispMessage. 134 this->hidden->SB[1]->sb_DBufInfo->dbi_DispMessage.
135 mn_ReplyPort = NULL; 135 mn_ReplyPort = NULL;
136 136
137 if (this->hidden->SB[1]) 137 if (this->hidden->SB[1])
138 FreeScreenBuffer (SDL_Display, this->hidden->SB[1]); 138 FreeScreenBuffer(SDL_Display, this->hidden->SB[1]);
139 if (this->hidden->SB[0]) 139 if (this->hidden->SB[0])
140 FreeScreenBuffer (SDL_Display, this->hidden->SB[0]); 140 FreeScreenBuffer(SDL_Display, this->hidden->SB[0]);
141 141
142 142
143 this->hidden->SB[0] = this->hidden->SB[1] = NULL; 143 this->hidden->SB[0] = this->hidden->SB[1] = NULL;
144 144
145 if (SDL_RastPort && SDL_RastPort != &SDL_Display->RastPort) 145 if (SDL_RastPort && SDL_RastPort != &SDL_Display->RastPort)
146 SDL_free (SDL_RastPort); 146 SDL_free(SDL_RastPort);
147 147
148 SDL_RastPort = NULL; 148 SDL_RastPort = NULL;
149 } 149 }
150 CloseScreen (GFX_Display); 150 CloseScreen(GFX_Display);
151 currently_fullscreen = 0; 151 currently_fullscreen = 0;
152 } else if (GFX_Display) 152 } else if (GFX_Display)
153 UnlockPubScreen (NULL, GFX_Display); 153 UnlockPubScreen(NULL, GFX_Display);
154 154
155 GFX_Display = NULL; 155 GFX_Display = NULL;
156 } 156 }
157 157
158 static int 158 static int
159 CGX_Available (void) 159 CGX_Available(void)
160 { 160 {
161 struct Library *l; 161 struct Library *l;
162 162
163 l = OpenLibrary ("cybergraphics.library", 0L); 163 l = OpenLibrary("cybergraphics.library", 0L);
164 164
165 if (l != NULL) { 165 if (l != NULL) {
166 D (bug ("CGX video device AVAILABLE\n")); 166 D(bug("CGX video device AVAILABLE\n"));
167 CloseLibrary (l); 167 CloseLibrary(l);
168 } 168 }
169 D ( 169 D(
170 else 170 else
171 bug ("**CGX video device UNAVAILABLE\n")); 171 bug("**CGX video device UNAVAILABLE\n"));
172 172
173 return (l != NULL); 173 return (l != NULL);
174 } 174 }
175 175
176 static void 176 static void
177 CGX_DeleteDevice (SDL_VideoDevice * device) 177 CGX_DeleteDevice(SDL_VideoDevice * device)
178 { 178 {
179 if (device) { 179 if (device) {
180 if (device->hidden) { 180 if (device->hidden) {
181 SDL_free (device->hidden); 181 SDL_free(device->hidden);
182 } 182 }
183 if (device->gl_data) { 183 if (device->gl_data) {
184 SDL_free (device->gl_data); 184 SDL_free(device->gl_data);
185 } 185 }
186 SDL_free (device); 186 SDL_free(device);
187 } 187 }
188 } 188 }
189 189
190 static SDL_VideoDevice * 190 static SDL_VideoDevice *
191 CGX_CreateDevice (int devindex) 191 CGX_CreateDevice(int devindex)
192 { 192 {
193 SDL_VideoDevice *device; 193 SDL_VideoDevice *device;
194 194
195 /* Initialize all variables that we clean on shutdown */ 195 /* Initialize all variables that we clean on shutdown */
196 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 196 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
197 if (device) { 197 if (device) {
198 SDL_memset (device, 0, (sizeof *device)); 198 SDL_memset(device, 0, (sizeof *device));
199 device->hidden = (struct SDL_PrivateVideoData *) 199 device->hidden = (struct SDL_PrivateVideoData *)
200 SDL_malloc ((sizeof *device->hidden)); 200 SDL_malloc((sizeof *device->hidden));
201 device->gl_data = (struct SDL_PrivateGLData *) 201 device->gl_data = (struct SDL_PrivateGLData *)
202 SDL_malloc ((sizeof *device->gl_data)); 202 SDL_malloc((sizeof *device->gl_data));
203 } 203 }
204 if ((device == NULL) || (device->hidden == NULL) || 204 if ((device == NULL) || (device->hidden == NULL) ||
205 (device->gl_data == NULL)) { 205 (device->gl_data == NULL)) {
206 D (bug ("Unable to create video device!\n")); 206 D(bug("Unable to create video device!\n"));
207 SDL_OutOfMemory (); 207 SDL_OutOfMemory();
208 CGX_DeleteDevice (device); 208 CGX_DeleteDevice(device);
209 return (0); 209 return (0);
210 } 210 }
211 SDL_memset (device->hidden, 0, sizeof (*device->hidden)); 211 SDL_memset(device->hidden, 0, sizeof(*device->hidden));
212 SDL_memset (device->gl_data, 0, sizeof (*device->gl_data)); 212 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
213 213
214 /* Set the driver flags */ 214 /* Set the driver flags */
215 device->handles_any_size = 1; 215 device->handles_any_size = 1;
216 216
217 /* Set the function pointers */ 217 /* Set the function pointers */
264 VideoBootStrap CGX_bootstrap = { 264 VideoBootStrap CGX_bootstrap = {
265 "CGX", "AmigaOS CyberGraphics", CGX_Available, CGX_CreateDevice 265 "CGX", "AmigaOS CyberGraphics", CGX_Available, CGX_CreateDevice
266 }; 266 };
267 267
268 Uint32 268 Uint32
269 MakeBitMask (_THIS, int type, int format, int *bpp) 269 MakeBitMask(_THIS, int type, int format, int *bpp)
270 { 270 {
271 D (if (type == 0) bug ("REAL pixel format: ")); 271 D(if (type == 0) bug("REAL pixel format: "));
272 272
273 if (this->hidden->depth == *bpp) { 273 if (this->hidden->depth == *bpp) {
274 274
275 switch (format) { 275 switch (format) {
276 case PIXFMT_LUT8: 276 case PIXFMT_LUT8:
277 D (if (type == 0) bug ("LUT8\n")); 277 D(if (type == 0) bug("LUT8\n"));
278 return 0; 278 return 0;
279 case PIXFMT_BGR15: 279 case PIXFMT_BGR15:
280 case PIXFMT_RGB15PC: 280 case PIXFMT_RGB15PC:
281 switch (type) { 281 switch (type) {
282 case 0: 282 case 0:
283 D (bug ("RGB15PC/BGR15\n")); 283 D(bug("RGB15PC/BGR15\n"));
284 return 31; 284 return 31;
285 case 1: 285 case 1:
286 return 992; 286 return 992;
287 case 2: 287 case 2:
288 return 31744; 288 return 31744;
289 } 289 }
290 case PIXFMT_RGB15: 290 case PIXFMT_RGB15:
291 case PIXFMT_BGR15PC: 291 case PIXFMT_BGR15PC:
292 switch (type) { 292 switch (type) {
293 case 0: 293 case 0:
294 D (bug ("RGB15/BGR15PC\n")); 294 D(bug("RGB15/BGR15PC\n"));
295 return 31744; 295 return 31744;
296 case 1: 296 case 1:
297 return 992; 297 return 992;
298 case 2: 298 case 2:
299 return 31; 299 return 31;
300 } 300 }
301 case PIXFMT_BGR16PC: 301 case PIXFMT_BGR16PC:
302 case PIXFMT_RGB16: 302 case PIXFMT_RGB16:
303 switch (type) { 303 switch (type) {
304 case 0: 304 case 0:
305 D (bug ("RGB16PC\n")); 305 D(bug("RGB16PC\n"));
306 return 63488; 306 return 63488;
307 case 1: 307 case 1:
308 return 2016; 308 return 2016;
309 case 2: 309 case 2:
310 return 31; 310 return 31;
311 } 311 }
312 case PIXFMT_BGR16: 312 case PIXFMT_BGR16:
313 case PIXFMT_RGB16PC: 313 case PIXFMT_RGB16PC:
314 switch (type) { 314 switch (type) {
315 case 0: 315 case 0:
316 D (bug ("RGB16PC/BGR16\n")); 316 D(bug("RGB16PC/BGR16\n"));
317 return 31; 317 return 31;
318 case 1: 318 case 1:
319 return 2016; 319 return 2016;
320 case 2: 320 case 2:
321 return 63488; 321 return 63488;
322 } 322 }
323 323
324 case PIXFMT_RGB24: 324 case PIXFMT_RGB24:
325 switch (type) { 325 switch (type) {
326 case 0: 326 case 0:
327 D (bug ("RGB24/BGR24\n")); 327 D(bug("RGB24/BGR24\n"));
328 return 0xff0000; 328 return 0xff0000;
329 case 1: 329 case 1:
330 return 0xff00; 330 return 0xff00;
331 case 2: 331 case 2:
332 return 0xff; 332 return 0xff;
333 } 333 }
334 case PIXFMT_BGR24: 334 case PIXFMT_BGR24:
335 switch (type) { 335 switch (type) {
336 case 0: 336 case 0:
337 D (bug ("BGR24\n")); 337 D(bug("BGR24\n"));
338 return 0xff; 338 return 0xff;
339 case 1: 339 case 1:
340 return 0xff00; 340 return 0xff00;
341 case 2: 341 case 2:
342 return 0xff0000; 342 return 0xff0000;
343 } 343 }
344 case PIXFMT_ARGB32: 344 case PIXFMT_ARGB32:
345 switch (type) { 345 switch (type) {
346 case 0: 346 case 0:
347 D (bug ("ARGB32\n")); 347 D(bug("ARGB32\n"));
348 return 0xff0000; 348 return 0xff0000;
349 case 1: 349 case 1:
350 return 0xff00; 350 return 0xff00;
351 case 2: 351 case 2:
352 return 0xff; 352 return 0xff;
353 } 353 }
354 case PIXFMT_BGRA32: 354 case PIXFMT_BGRA32:
355 switch (type) { 355 switch (type) {
356 case 0: 356 case 0:
357 D (bug ("BGRA32\n")); 357 D(bug("BGRA32\n"));
358 return 0xff00; 358 return 0xff00;
359 case 1: 359 case 1:
360 return 0xff0000; 360 return 0xff0000;
361 case 2: 361 case 2:
362 return 0xff000000; 362 return 0xff000000;
363 } 363 }
364 case PIXFMT_RGBA32: 364 case PIXFMT_RGBA32:
365 switch (type) { 365 switch (type) {
366 case 0: 366 case 0:
367 D (bug ("RGBA32\n")); 367 D(bug("RGBA32\n"));
368 return 0xff000000; 368 return 0xff000000;
369 case 1: 369 case 1:
370 return 0xff0000; 370 return 0xff0000;
371 case 2: 371 case 2:
372 return 0xff00; 372 return 0xff00;
373 } 373 }
374 default: 374 default:
375 D (bug ("Unknown pixel format! Default to 24bit\n")); 375 D(bug("Unknown pixel format! Default to 24bit\n"));
376 return (Uint32) (255 << (type * 8)); 376 return (Uint32) (255 << (type * 8));
377 } 377 }
378 } else { 378 } else {
379 D (if (type == 0) 379 D(if (type == 0)
380 bug ("DIFFERENT from screen.\nAllocated screen format: ")); 380 bug("DIFFERENT from screen.\nAllocated screen format: "));
381 381
382 switch (*bpp) { 382 switch (*bpp) {
383 case 32: 383 case 32:
384 D (if (type == 0) bug ("RGBA32\n")); 384 D(if (type == 0) bug("RGBA32\n"));
385 switch (type) { 385 switch (type) {
386 case 0: 386 case 0:
387 return 0xff000000; 387 return 0xff000000;
388 case 1: 388 case 1:
389 return 0xff0000; 389 return 0xff0000;
393 break; 393 break;
394 case 24: 394 case 24:
395 use_truecolor: 395 use_truecolor:
396 switch (type) { 396 switch (type) {
397 case 0: 397 case 0:
398 D (bug ("RGB24\n")); 398 D(bug("RGB24\n"));
399 return 0xff0000; 399 return 0xff0000;
400 case 1: 400 case 1:
401 return 0xff00; 401 return 0xff00;
402 case 2: 402 case 2:
403 return 0xff; 403 return 0xff;
404 } 404 }
405 case 16: 405 case 16:
406 case 15: 406 case 15:
407 D (if (type == 0) 407 D(if (type == 0)
408 bug ("Not supported, switching to 24bit!\n")); 408 bug("Not supported, switching to 24bit!\n"));
409 *bpp = 24; 409 *bpp = 24;
410 goto use_truecolor; 410 goto use_truecolor;
411 break; 411 break;
412 default: 412 default:
413 D (if (type == 0) bug ("This is a chunky display\n")); 413 D(if (type == 0) bug("This is a chunky display\n"));
414 // For chunky display mask is always 0; 414 // For chunky display mask is always 0;
415 return 0; 415 return 0;
416 } 416 }
417 } 417 }
418 return 0; 418 return 0;
419 } 419 }
420 420
421 static int 421 static int
422 CGX_VideoInit (_THIS, SDL_PixelFormat * vformat) 422 CGX_VideoInit(_THIS, SDL_PixelFormat * vformat)
423 { 423 {
424 int i; 424 int i;
425 struct Library *RTGBase; 425 struct Library *RTGBase;
426 426
427 D (bug ("VideoInit... Opening libraries\n")); 427 D(bug("VideoInit... Opening libraries\n"));
428 428
429 if (!IntuitionBase) { 429 if (!IntuitionBase) {
430 if (! 430 if (!
431 (IntuitionBase = 431 (IntuitionBase =
432 (struct IntuitionBase *) OpenLibrary ("intuition.library", 432 (struct IntuitionBase *) OpenLibrary("intuition.library",
433 39L))) { 433 39L))) {
434 SDL_SetError ("Couldn't open intuition V39+"); 434 SDL_SetError("Couldn't open intuition V39+");
435 return -1; 435 return -1;
436 } 436 }
437 } 437 }
438 438
439 if (!GfxBase) { 439 if (!GfxBase) {
440 if (! 440 if (!
441 (GfxBase = 441 (GfxBase =
442 (struct GfxBase *) OpenLibrary ("graphics.library", 39L))) { 442 (struct GfxBase *) OpenLibrary("graphics.library", 39L))) {
443 SDL_SetError ("Couldn't open graphics V39+"); 443 SDL_SetError("Couldn't open graphics V39+");
444 return -1; 444 return -1;
445 } 445 }
446 } 446 }
447 447
448 if (!CyberGfxBase) { 448 if (!CyberGfxBase) {
449 if (!(CyberGfxBase = OpenLibrary ("cybergraphics.library", 40L))) { 449 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library", 40L))) {
450 SDL_SetError ("Couldn't open cybergraphics."); 450 SDL_SetError("Couldn't open cybergraphics.");
451 return (-1); 451 return (-1);
452 } 452 }
453 } 453 }
454 454
455 if (RTGBase = OpenLibrary ("libs:picasso96/rtg.library", 0L)) { 455 if (RTGBase = OpenLibrary("libs:picasso96/rtg.library", 0L)) {
456 extern int use_picasso96; 456 extern int use_picasso96;
457 457
458 CloseLibrary (RTGBase); 458 CloseLibrary(RTGBase);
459 use_picasso96 = 1; 459 use_picasso96 = 1;
460 } 460 }
461 461
462 D (bug ("Library intialized, locking screen...\n")); 462 D(bug("Library intialized, locking screen...\n"));
463 463
464 SDL_Display = LockPubScreen (NULL); 464 SDL_Display = LockPubScreen(NULL);
465 465
466 if (SDL_Display == NULL) { 466 if (SDL_Display == NULL) {
467 D (bug ("Cannot lock display...\n")); 467 D(bug("Cannot lock display...\n"));
468 SDL_SetError ("Couldn't lock the display"); 468 SDL_SetError("Couldn't lock the display");
469 return (-1); 469 return (-1);
470 } 470 }
471 this->info.current_w = SDL_Display->Width; 471 this->info.current_w = SDL_Display->Width;
472 this->info.current_h = SDL_Display->Height; 472 this->info.current_h = SDL_Display->Height;
473 473
474 D (bug ("Checking if we are using a CGX native display...\n")); 474 D(bug("Checking if we are using a CGX native display...\n"));
475 475
476 if (!IsCyberModeID (GetVPModeID (&SDL_Display->ViewPort))) { 476 if (!IsCyberModeID(GetVPModeID(&SDL_Display->ViewPort))) {
477 Uint32 okid = 477 Uint32 okid =
478 BestCModeIDTags (CYBRBIDTG_NominalWidth, SDL_Display->Width, 478 BestCModeIDTags(CYBRBIDTG_NominalWidth, SDL_Display->Width,
479 CYBRBIDTG_NominalHeight, SDL_Display->Height, 479 CYBRBIDTG_NominalHeight, SDL_Display->Height,
480 CYBRBIDTG_Depth, 8, 480 CYBRBIDTG_Depth, 8,
481 TAG_DONE); 481 TAG_DONE);
482 482
483 D (bug ("Default visual is not CGX native!\n")); 483 D(bug("Default visual is not CGX native!\n"));
484 484
485 UnlockPubScreen (NULL, SDL_Display); 485 UnlockPubScreen(NULL, SDL_Display);
486 486
487 GFX_Display = NULL; 487 GFX_Display = NULL;
488 488
489 if (okid != INVALID_ID) { 489 if (okid != INVALID_ID) {
490 GFX_Display = OpenScreenTags (NULL, 490 GFX_Display = OpenScreenTags(NULL,
491 SA_Width, SDL_Display->Width, 491 SA_Width, SDL_Display->Width,
492 SA_Height, SDL_Display->Height, 492 SA_Height, SDL_Display->Height,
493 SA_Depth, 8, SA_Quiet, TRUE, 493 SA_Depth, 8, SA_Quiet, TRUE,
494 SA_ShowTitle, FALSE, 494 SA_ShowTitle, FALSE,
495 SA_DisplayID, okid, TAG_DONE); 495 SA_DisplayID, okid, TAG_DONE);
496 } 496 }
497 497
498 if (!GFX_Display) { 498 if (!GFX_Display) {
499 SDL_SetError ("Unable to open a suited CGX display"); 499 SDL_SetError("Unable to open a suited CGX display");
500 return -1; 500 return -1;
501 } else 501 } else
502 SDL_Display = GFX_Display; 502 SDL_Display = GFX_Display;
503 503
504 } else 504 } else
513 513
514 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { 514 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {
515 swap_pixels = 1; 515 swap_pixels = 1;
516 } 516 }
517 517
518 D (bug ("Before GetVideoModes....\n")); 518 D(bug("Before GetVideoModes....\n"));
519 519
520 /* Get the available video modes */ 520 /* Get the available video modes */
521 if (CGX_GetVideoModes (this) < 0) 521 if (CGX_GetVideoModes(this) < 0)
522 return -1; 522 return -1;
523 523
524 /* Determine the default screen depth: 524 /* Determine the default screen depth:
525 Use the default visual (or at least one with the same depth) */ 525 Use the default visual (or at least one with the same depth) */
526 526
527 for (i = 0; i < this->hidden->nvisuals; i++) 527 for (i = 0; i < this->hidden->nvisuals; i++)
528 if (this->hidden->visuals[i].depth == 528 if (this->hidden->visuals[i].depth ==
529 GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH)) 529 GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH))
530 break; 530 break;
531 if (i == this->hidden->nvisuals) { 531 if (i == this->hidden->nvisuals) {
532 /* default visual was useless, take the deepest one instead */ 532 /* default visual was useless, take the deepest one instead */
533 i = 0; 533 i = 0;
534 } 534 }
535 SDL_Visual = this->hidden->visuals[i].visual; 535 SDL_Visual = this->hidden->visuals[i].visual;
536 536
537 // SDL_XColorMap = SDL_DisplayColormap; 537 // SDL_XColorMap = SDL_DisplayColormap;
538 538
539 this->hidden->depth = this->hidden->visuals[i].depth; 539 this->hidden->depth = this->hidden->visuals[i].depth;
540 D (bug ("Init: Setting screen depth to: %ld\n", this->hidden->depth)); 540 D(bug("Init: Setting screen depth to: %ld\n", this->hidden->depth));
541 vformat->BitsPerPixel = this->hidden->visuals[i].depth; /* this->hidden->visuals[i].bpp; */ 541 vformat->BitsPerPixel = this->hidden->visuals[i].depth; /* this->hidden->visuals[i].bpp; */
542 542
543 { 543 {
544 int form; 544 int form;
545 APTR handle; 545 APTR handle;
546 struct DisplayInfo info; 546 struct DisplayInfo info;
547 547
548 if (!(handle = FindDisplayInfo (this->hidden->visuals[i].visual))) { 548 if (!(handle = FindDisplayInfo(this->hidden->visuals[i].visual))) {
549 D (bug ("Unable to get visual info...\n")); 549 D(bug("Unable to get visual info...\n"));
550 return -1; 550 return -1;
551 } 551 }
552 552
553 if (!GetDisplayInfoData 553 if (!GetDisplayInfoData
554 (handle, (char *) &info, sizeof (struct DisplayInfo), DTAG_DISP, 554 (handle, (char *) &info, sizeof(struct DisplayInfo), DTAG_DISP,
555 NULL)) { 555 NULL)) {
556 D (bug ("Unable to get visual info data...\n")); 556 D(bug("Unable to get visual info data...\n"));
557 return -1; 557 return -1;
558 } 558 }
559 559
560 form = GetCyberIDAttr (CYBRIDATTR_PIXFMT, SDL_Visual); 560 form = GetCyberIDAttr(CYBRIDATTR_PIXFMT, SDL_Visual);
561 561
562 // In this case I use makebitmask in a way that I'm sure I'll get PIXFMT pixel mask 562 // In this case I use makebitmask in a way that I'm sure I'll get PIXFMT pixel mask
563 563
564 if (vformat->BitsPerPixel > 8) { 564 if (vformat->BitsPerPixel > 8) {
565 vformat->Rmask = 565 vformat->Rmask = MakeBitMask(this, 0, form, &this->hidden->depth);
566 MakeBitMask (this, 0, form, &this->hidden->depth); 566 vformat->Gmask = MakeBitMask(this, 1, form, &this->hidden->depth);
567 vformat->Gmask = 567 vformat->Bmask = MakeBitMask(this, 2, form, &this->hidden->depth);
568 MakeBitMask (this, 1, form, &this->hidden->depth);
569 vformat->Bmask =
570 MakeBitMask (this, 2, form, &this->hidden->depth);
571 } 568 }
572 } 569 }
573 570
574 /* See if we have been passed a window to use */ 571 /* See if we have been passed a window to use */
575 /* SDL_windowid = SDL_getenv("SDL_WINDOWID"); */ 572 /* SDL_windowid = SDL_getenv("SDL_WINDOWID"); */
576 SDL_windowid = NULL; 573 SDL_windowid = NULL;
577 574
578 /* Create the blank cursor */ 575 /* Create the blank cursor */
579 SDL_BlankCursor = AllocMem (16, MEMF_CHIP | MEMF_CLEAR); 576 SDL_BlankCursor = AllocMem(16, MEMF_CHIP | MEMF_CLEAR);
580 577
581 /* Fill in some window manager capabilities */ 578 /* Fill in some window manager capabilities */
582 this->info.wm_available = 1; 579 this->info.wm_available = 1;
583 this->info.blit_hw = 1; 580 this->info.blit_hw = 1;
584 this->info.blit_hw_CC = 1; 581 this->info.blit_hw_CC = 1;
587 this->info.video_mem = 2000000; // Not always true but almost any Amiga card has this memory! 584 this->info.video_mem = 2000000; // Not always true but almost any Amiga card has this memory!
588 585
589 this->hidden->same_format = 0; 586 this->hidden->same_format = 0;
590 SDL_RastPort = &SDL_Display->RastPort; 587 SDL_RastPort = &SDL_Display->RastPort;
591 /* We're done! */ 588 /* We're done! */
592 D (bug ("End of CGX_VideoInit\n")); 589 D(bug("End of CGX_VideoInit\n"));
593 590
594 return (0); 591 return (0);
595 } 592 }
596 593
597 void 594 void
598 CGX_DestroyWindow (_THIS, SDL_Surface * screen) 595 CGX_DestroyWindow(_THIS, SDL_Surface * screen)
599 { 596 {
600 D (bug ("Destroy Window...\n")); 597 D(bug("Destroy Window...\n"));
601 598
602 if (!SDL_windowid) { 599 if (!SDL_windowid) {
603 /* Hide the managed window */ 600 /* Hide the managed window */
604 int was_fullscreen = 0; 601 int was_fullscreen = 0;
605 602
614 // CGX_LeaveFullScreen(this); tolto x crash 611 // CGX_LeaveFullScreen(this); tolto x crash
615 } 612 }
616 613
617 /* Destroy the output window */ 614 /* Destroy the output window */
618 if (SDL_Window) { 615 if (SDL_Window) {
619 CloseWindow (SDL_Window); 616 CloseWindow(SDL_Window);
620 SDL_Window = NULL; 617 SDL_Window = NULL;
621 } 618 }
622 619
623 /* Free the colormap entries */ 620 /* Free the colormap entries */
624 if (SDL_XPixels) { 621 if (SDL_XPixels) {
633 numcolors = 256; 630 numcolors = 256;
634 631
635 if (!was_fullscreen && this->hidden->depth == 8) { 632 if (!was_fullscreen && this->hidden->depth == 8) {
636 for (pixel = 0; pixel < numcolors; pixel++) { 633 for (pixel = 0; pixel < numcolors; pixel++) {
637 if (SDL_XPixels[pixel] >= 0) 634 if (SDL_XPixels[pixel] >= 0)
638 ReleasePen (GFX_Display->ViewPort. 635 ReleasePen(GFX_Display->ViewPort.
639 ColorMap, SDL_XPixels[pixel]); 636 ColorMap, SDL_XPixels[pixel]);
640 } 637 }
641 } 638 }
642 } 639 }
643 SDL_free (SDL_XPixels); 640 SDL_free(SDL_XPixels);
644 SDL_XPixels = NULL; 641 SDL_XPixels = NULL;
645 } 642 }
646 } 643 }
647 } 644 }
648 645
649 static void 646 static void
650 CGX_SetSizeHints (_THIS, int w, int h, Uint32 flags) 647 CGX_SetSizeHints(_THIS, int w, int h, Uint32 flags)
651 { 648 {
652 if (flags & SDL_RESIZABLE) { 649 if (flags & SDL_RESIZABLE) {
653 WindowLimits (SDL_Window, 32, 32, 4096, 4096); 650 WindowLimits(SDL_Window, 32, 32, 4096, 4096);
654 } else { 651 } else {
655 WindowLimits (SDL_Window, w, h, w, h); 652 WindowLimits(SDL_Window, w, h, w, h);
656 } 653 }
657 if (flags & SDL_FULLSCREEN) { 654 if (flags & SDL_FULLSCREEN) {
658 flags &= ~SDL_RESIZABLE; 655 flags &= ~SDL_RESIZABLE;
659 } else if (SDL_getenv ("SDL_VIDEO_CENTERED")) { 656 } else if (SDL_getenv("SDL_VIDEO_CENTERED")) {
660 int display_w, display_h; 657 int display_w, display_h;
661 658
662 display_w = SDL_Display->Width; 659 display_w = SDL_Display->Width;
663 display_h = SDL_Display->Height; 660 display_h = SDL_Display->Height;
664 ChangeWindowBox (SDL_Window, 661 ChangeWindowBox(SDL_Window,
665 (display_w - w - SDL_Window->BorderLeft - 662 (display_w - w - SDL_Window->BorderLeft -
666 SDL_Window->BorderRight) / 2, 663 SDL_Window->BorderRight) / 2,
667 (display_h - h - SDL_Window->BorderTop - 664 (display_h - h - SDL_Window->BorderTop -
668 SDL_Window->BorderBottom) / 2, 665 SDL_Window->BorderBottom) / 2,
669 w + SDL_Window->BorderLeft + 666 w + SDL_Window->BorderLeft +
670 SDL_Window->BorderRight, 667 SDL_Window->BorderRight,
671 h + SDL_Window->BorderTop + 668 h + SDL_Window->BorderTop + SDL_Window->BorderBottom);
672 SDL_Window->BorderBottom);
673 } 669 }
674 } 670 }
675 671
676 int 672 int
677 CGX_CreateWindow (_THIS, SDL_Surface * screen, 673 CGX_CreateWindow(_THIS, SDL_Surface * screen,
678 int w, int h, int bpp, Uint32 flags) 674 int w, int h, int bpp, Uint32 flags)
679 { 675 {
680 #if 0 676 #if 0
681 int i, depth; 677 int i, depth;
682 Uint32 vis; 678 Uint32 vis;
683 #endif 679 #endif
684 D (bug ("CGX_CreateWindow\n")); 680 D(bug("CGX_CreateWindow\n"));
685 681
686 /* If a window is already present, destroy it and start fresh */ 682 /* If a window is already present, destroy it and start fresh */
687 if (SDL_Window) { 683 if (SDL_Window) {
688 CGX_DestroyWindow (this, screen); 684 CGX_DestroyWindow(this, screen);
689 } 685 }
690 686
691 /* See if we have been given a window id */ 687 /* See if we have been given a window id */
692 if (SDL_windowid) { 688 if (SDL_windowid) {
693 SDL_Window = (struct Window *) atol (SDL_windowid); 689 SDL_Window = (struct Window *) atol(SDL_windowid);
694 } else { 690 } else {
695 SDL_Window = 0; 691 SDL_Window = 0;
696 } 692 }
697 693
698 /* find out which visual we are going to use */ 694 /* find out which visual we are going to use */
708 for (i = 0; i < this->hidden->nvisuals; i++) { 704 for (i = 0; i < this->hidden->nvisuals; i++) {
709 if (this->hidden->visuals[i].depth == bpp) /* era .depth */ 705 if (this->hidden->visuals[i].depth == bpp) /* era .depth */
710 break; 706 break;
711 } 707 }
712 if (i == this->hidden->nvisuals) { 708 if (i == this->hidden->nvisuals) {
713 SDL_SetError ("No matching visual for requested depth"); 709 SDL_SetError("No matching visual for requested depth");
714 return -1; /* should never happen */ 710 return -1; /* should never happen */
715 } 711 }
716 vis = this->hidden->visuals[i].visual; 712 vis = this->hidden->visuals[i].visual;
717 depth = this->hidden->visuals[i].depth; 713 depth = this->hidden->visuals[i].depth;
718 // } 714 // }
719 SDL_Visual = vis; 715 SDL_Visual = vis;
720 this->hidden->depth = depth; 716 this->hidden->depth = depth;
721 D (bug ("Setting screen depth to: %ld\n", this->hidden->depth)); 717 D(bug("Setting screen depth to: %ld\n", this->hidden->depth));
722 #endif 718 #endif
723 719
724 /* Allocate the new pixel format for this video mode */ 720 /* Allocate the new pixel format for this video mode */
725 { 721 {
726 Uint32 form; 722 Uint32 form;
727 APTR handle; 723 APTR handle;
728 struct DisplayInfo info; 724 struct DisplayInfo info;
729 725
730 if (!(handle = FindDisplayInfo (SDL_Visual))) 726 if (!(handle = FindDisplayInfo(SDL_Visual)))
731 return -1; 727 return -1;
732 728
733 if (!GetDisplayInfoData 729 if (!GetDisplayInfoData
734 (handle, (char *) &info, sizeof (struct DisplayInfo), DTAG_DISP, 730 (handle, (char *) &info, sizeof(struct DisplayInfo), DTAG_DISP,
735 NULL)) 731 NULL))
736 return -1; 732 return -1;
737 733
738 form = GetCyberIDAttr (CYBRIDATTR_PIXFMT, SDL_Visual); 734 form = GetCyberIDAttr(CYBRIDATTR_PIXFMT, SDL_Visual);
739 735
740 if (flags & SDL_HWSURFACE) { 736 if (flags & SDL_HWSURFACE) {
741 if (bpp != this->hidden->depth) { 737 if (bpp != this->hidden->depth) {
742 bpp = this->hidden->depth; 738 bpp = this->hidden->depth;
743 D (bug ("Accel forces bpp to be equal (%ld)\n", bpp)); 739 D(bug("Accel forces bpp to be equal (%ld)\n", bpp));
744 } 740 }
745 } 741 }
746 742
747 D (bug 743 D(bug
748 ("BEFORE screen allocation: bpp:%ld (real:%ld)\n", bpp, 744 ("BEFORE screen allocation: bpp:%ld (real:%ld)\n", bpp,
749 this->hidden->depth)); 745 this->hidden->depth));
750 746
751 /* With this call if needed I'll revert the wanted bpp to a bpp best suited for the display, actually occurs 747 /* With this call if needed I'll revert the wanted bpp to a bpp best suited for the display, actually occurs
752 only with requested format 15/16bit and display format != 15/16bit 748 only with requested format 15/16bit and display format != 15/16bit
753 */ 749 */
754 750
755 if (!SDL_ReallocFormat (screen, bpp, 751 if (!SDL_ReallocFormat(screen, bpp,
756 MakeBitMask (this, 0, form, &bpp), 752 MakeBitMask(this, 0, form, &bpp),
757 MakeBitMask (this, 1, form, &bpp), 753 MakeBitMask(this, 1, form, &bpp),
758 MakeBitMask (this, 2, form, &bpp), 0)) 754 MakeBitMask(this, 2, form, &bpp), 0))
759 return -1; 755 return -1;
760 756
761 D (bug 757 D(bug
762 ("AFTER screen allocation: bpp:%ld (real:%ld)\n", bpp, 758 ("AFTER screen allocation: bpp:%ld (real:%ld)\n", bpp,
763 this->hidden->depth)); 759 this->hidden->depth));
764 760
765 } 761 }
766 762
767 /* Create the appropriate colormap */ 763 /* Create the appropriate colormap */
768 /* 764 /*
769 if ( SDL_XColorMap != SDL_DisplayColormap ) { 765 if ( SDL_XColorMap != SDL_DisplayColormap ) {
770 XFreeColormap(SDL_Display, SDL_XColorMap); 766 XFreeColormap(SDL_Display, SDL_XColorMap);
771 } 767 }
772 */ 768 */
773 if (GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_PIXFMT) == 769 if (GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_PIXFMT) ==
774 PIXFMT_LUT8 || bpp == 8) { 770 PIXFMT_LUT8 || bpp == 8) {
775 int ncolors, i; 771 int ncolors, i;
776 D (bug ("XPixels palette allocation...\n")); 772 D(bug("XPixels palette allocation...\n"));
777 773
778 /* Allocate the pixel flags */ 774 /* Allocate the pixel flags */
779 775
780 if (bpp == 8) 776 if (bpp == 8)
781 ncolors = 256; 777 ncolors = 256;
782 else 778 else
783 ncolors = 1 << screen->format->BitsPerPixel; 779 ncolors = 1 << screen->format->BitsPerPixel;
784 780
785 SDL_XPixels = (Sint32 *) SDL_malloc (ncolors * sizeof (Sint32)); 781 SDL_XPixels = (Sint32 *) SDL_malloc(ncolors * sizeof(Sint32));
786 782
787 if (SDL_XPixels == NULL) { 783 if (SDL_XPixels == NULL) {
788 SDL_OutOfMemory (); 784 SDL_OutOfMemory();
789 return -1; 785 return -1;
790 } 786 }
791 787
792 788
793 for (i = 0; i < ncolors; i++) 789 for (i = 0; i < ncolors; i++)
805 801
806 /* Create (or use) the X11 display window */ 802 /* Create (or use) the X11 display window */
807 803
808 if (!SDL_windowid) { 804 if (!SDL_windowid) {
809 if (flags & SDL_FULLSCREEN) { 805 if (flags & SDL_FULLSCREEN) {
810 SDL_Window = OpenWindowTags (NULL, WA_Width, w, WA_Height, h, 806 SDL_Window = OpenWindowTags(NULL, WA_Width, w, WA_Height, h,
811 WA_Flags, 807 WA_Flags,
812 WFLG_ACTIVATE | WFLG_RMBTRAP | 808 WFLG_ACTIVATE | WFLG_RMBTRAP |
813 WFLG_BORDERLESS | WFLG_BACKDROP | 809 WFLG_BORDERLESS | WFLG_BACKDROP |
814 WFLG_REPORTMOUSE, WA_IDCMP, 810 WFLG_REPORTMOUSE, WA_IDCMP,
815 IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS 811 IDCMP_RAWKEY | IDCMP_MOUSEBUTTONS
816 | IDCMP_MOUSEMOVE, 812 | IDCMP_MOUSEMOVE,
817 WA_CustomScreen, 813 WA_CustomScreen,
818 (ULONG) SDL_Display, TAG_DONE); 814 (ULONG) SDL_Display, TAG_DONE);
819 815
820 D (bug 816 D(bug
821 ("Opening backdrop window %ldx%ld on display %lx!\n", w, h, 817 ("Opening backdrop window %ldx%ld on display %lx!\n", w, h,
822 SDL_Display)); 818 SDL_Display));
823 } else { 819 } else {
824 /* Create GimmeZeroZero window when OpenGL is used */ 820 /* Create GimmeZeroZero window when OpenGL is used */
825 unsigned long gzz = FALSE; 821 unsigned long gzz = FALSE;
826 if (flags & SDL_INTERNALOPENGL) { 822 if (flags & SDL_INTERNALOPENGL) {
827 gzz = TRUE; 823 gzz = TRUE;
828 } 824 }
829 825
830 SDL_Window = 826 SDL_Window =
831 OpenWindowTags (NULL, WA_InnerWidth, w, WA_InnerHeight, h, 827 OpenWindowTags(NULL, WA_InnerWidth, w, WA_InnerHeight, h,
832 WA_Flags, 828 WA_Flags,
833 WFLG_REPORTMOUSE | WFLG_ACTIVATE | 829 WFLG_REPORTMOUSE | WFLG_ACTIVATE |
834 WFLG_RMBTRAP | ((flags & SDL_NOFRAME) ? 0 830 WFLG_RMBTRAP | ((flags & SDL_NOFRAME) ? 0
835 : (WFLG_DEPTHGADGET | 831 : (WFLG_DEPTHGADGET |
836 WFLG_CLOSEGADGET | 832 WFLG_CLOSEGADGET |
837 WFLG_DRAGBAR | 833 WFLG_DRAGBAR |
838 ((flags & 834 ((flags &
839 SDL_RESIZABLE) ? 835 SDL_RESIZABLE) ?
840 WFLG_SIZEGADGET | 836 WFLG_SIZEGADGET |
841 WFLG_SIZEBBOTTOM : 837 WFLG_SIZEBBOTTOM :
842 0))), WA_IDCMP, 838 0))), WA_IDCMP,
843 IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | 839 IDCMP_RAWKEY | IDCMP_CLOSEWINDOW |
844 IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE | 840 IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE |
845 IDCMP_MOUSEMOVE, WA_PubScreen, 841 IDCMP_MOUSEMOVE, WA_PubScreen,
846 (ULONG) SDL_Display, WA_GimmeZeroZero, 842 (ULONG) SDL_Display, WA_GimmeZeroZero,
847 gzz, TAG_DONE); 843 gzz, TAG_DONE);
848 D (bug ("Opening WB window of size: %ldx%ld!\n", w, h)); 844 D(bug("Opening WB window of size: %ldx%ld!\n", w, h));
849 } 845 }
850 846
851 if (!SDL_Window) 847 if (!SDL_Window)
852 return -1; 848 return -1;
853 } 849 }
854 850
855 this->hidden->BytesPerPixel = 851 this->hidden->BytesPerPixel =
856 GetCyberMapAttr (SDL_Window->RPort->BitMap, CYBRMATTR_BPPIX); 852 GetCyberMapAttr(SDL_Window->RPort->BitMap, CYBRMATTR_BPPIX);
857 853
858 if (screen->flags & SDL_DOUBLEBUF) { 854 if (screen->flags & SDL_DOUBLEBUF) {
859 if (SDL_RastPort = SDL_malloc (sizeof (struct RastPort))) { 855 if (SDL_RastPort = SDL_malloc(sizeof(struct RastPort))) {
860 InitRastPort (SDL_RastPort); 856 InitRastPort(SDL_RastPort);
861 SDL_RastPort->BitMap = this->hidden->SB[1]->sb_BitMap; 857 SDL_RastPort->BitMap = this->hidden->SB[1]->sb_BitMap;
862 } else 858 } else
863 return -1; 859 return -1;
864 } else 860 } else
865 SDL_RastPort = SDL_Window->RPort; 861 SDL_RastPort = SDL_Window->RPort;
866 862
867 if (flags & SDL_HWSURFACE) 863 if (flags & SDL_HWSURFACE)
868 screen->flags |= SDL_HWSURFACE; 864 screen->flags |= SDL_HWSURFACE;
869 865
870 if (!SDL_windowid) { 866 if (!SDL_windowid) {
871 CGX_SetSizeHints (this, w, h, flags); 867 CGX_SetSizeHints(this, w, h, flags);
872 } 868 }
873 869
874 /* Set our colormaps when not setting a GL mode */ 870 /* Set our colormaps when not setting a GL mode */
875 /* 871 /*
876 if ( ! (flags & SDL_INTERNALOPENGL) ) { 872 if ( ! (flags & SDL_INTERNALOPENGL) ) {
888 screen->flags &= ~SDL_FULLSCREEN; 884 screen->flags &= ~SDL_FULLSCREEN;
889 } 885 }
890 } 886 }
891 screen->w = w; 887 screen->w = w;
892 screen->h = h; 888 screen->h = h;
893 screen->pitch = SDL_CalculatePitch (screen); 889 screen->pitch = SDL_CalculatePitch(screen);
894 CGX_ResizeImage (this, screen, flags); 890 CGX_ResizeImage(this, screen, flags);
895 891
896 /* Make OpenGL Context if needed */ 892 /* Make OpenGL Context if needed */
897 if (flags & SDL_INTERNALOPENGL) { 893 if (flags & SDL_INTERNALOPENGL) {
898 if (this->gl_data->gl_active == 0) { 894 if (this->gl_data->gl_active == 0) {
899 if (CGX_GL_Init (this) < 0) 895 if (CGX_GL_Init(this) < 0)
900 return -1; 896 return -1;
901 else 897 else
902 screen->flags |= SDL_INTERNALOPENGL; 898 screen->flags |= SDL_INTERNALOPENGL;
903 } else { 899 } else {
904 if (CGX_GL_Update (this) < 0) 900 if (CGX_GL_Update(this) < 0)
905 return -1; 901 return -1;
906 else 902 else
907 screen->flags |= SDL_INTERNALOPENGL; 903 screen->flags |= SDL_INTERNALOPENGL;
908 } 904 }
909 } 905 }
910 } 906 }
911 907
912 int 908 int
913 CGX_ResizeWindow (_THIS, SDL_Surface * screen, int w, int h, Uint32 flags) 909 CGX_ResizeWindow(_THIS, SDL_Surface * screen, int w, int h, Uint32 flags)
914 { 910 {
915 D (bug ("CGX_ResizeWindow\n")); 911 D(bug("CGX_ResizeWindow\n"));
916 912
917 if (!SDL_windowid) { 913 if (!SDL_windowid) {
918 /* Resize the window manager window */ 914 /* Resize the window manager window */
919 CGX_SetSizeHints (this, w, h, flags); 915 CGX_SetSizeHints(this, w, h, flags);
920 916
921 ChangeWindowBox (SDL_Window, SDL_Window->LeftEdge, 917 ChangeWindowBox(SDL_Window, SDL_Window->LeftEdge,
922 SDL_Window->TopEdge, 918 SDL_Window->TopEdge,
923 w + SDL_Window->BorderLeft + 919 w + SDL_Window->BorderLeft +
924 SDL_Window->BorderRight, 920 SDL_Window->BorderRight,
925 h + SDL_Window->BorderTop + 921 h + SDL_Window->BorderTop + SDL_Window->BorderBottom);
926 SDL_Window->BorderBottom);
927 922
928 screen->w = w; 923 screen->w = w;
929 screen->h = h; 924 screen->h = h;
930 screen->pitch = SDL_CalculatePitch (screen); 925 screen->pitch = SDL_CalculatePitch(screen);
931 CGX_ResizeImage (this, screen, flags); 926 CGX_ResizeImage(this, screen, flags);
932 } 927 }
933 return (0); 928 return (0);
934 } 929 }
935 930
936 static SDL_Surface * 931 static SDL_Surface *
937 CGX_SetVideoMode (_THIS, SDL_Surface * current, 932 CGX_SetVideoMode(_THIS, SDL_Surface * current,
938 int width, int height, int bpp, Uint32 flags) 933 int width, int height, int bpp, Uint32 flags)
939 { 934 {
940 Uint32 saved_flags; 935 Uint32 saved_flags;
941 int needcreate = 0; 936 int needcreate = 0;
942 937
943 D (bug ("CGX_SetVideoMode current:%lx\n", current)); 938 D(bug("CGX_SetVideoMode current:%lx\n", current));
944 939
945 /* Lock the event thread, in multi-threading environments */ 940 /* Lock the event thread, in multi-threading environments */
946 SDL_Lock_EventThread (); 941 SDL_Lock_EventThread();
947 942
948 // Check if the window needs to be closed or can be resized 943 // Check if the window needs to be closed or can be resized
949 944
950 if ((flags & SDL_FULLSCREEN) 945 if ((flags & SDL_FULLSCREEN)
951 || (current && current->flags & SDL_FULLSCREEN 946 || (current && current->flags & SDL_FULLSCREEN
955 // Check if we need to close an already existing videomode... 950 // Check if we need to close an already existing videomode...
956 951
957 if (current && current->flags & SDL_FULLSCREEN 952 if (current && current->flags & SDL_FULLSCREEN
958 && !(flags & SDL_FULLSCREEN)) { 953 && !(flags & SDL_FULLSCREEN)) {
959 unsigned long i; 954 unsigned long i;
960 D (bug ("Destroying image, window & screen!\n")); 955 D(bug("Destroying image, window & screen!\n"));
961 956
962 CGX_DestroyImage (this, current); 957 CGX_DestroyImage(this, current);
963 CGX_DestroyWindow (this, current); 958 CGX_DestroyWindow(this, current);
964 DestroyScreen (this); 959 DestroyScreen(this);
965 GFX_Display = SDL_Display = LockPubScreen (NULL); 960 GFX_Display = SDL_Display = LockPubScreen(NULL);
966 961
967 bpp = this->hidden->depth = 962 bpp = this->hidden->depth =
968 GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH); 963 GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
969 964
970 for (i = 0; i < this->hidden->nvisuals; i++) { 965 for (i = 0; i < this->hidden->nvisuals; i++) {
971 if (this->hidden->visuals[i].depth == bpp) /* era .depth */ 966 if (this->hidden->visuals[i].depth == bpp) /* era .depth */
972 break; 967 break;
973 } 968 }
974 if (i == this->hidden->nvisuals) { 969 if (i == this->hidden->nvisuals) {
975 SDL_SetError ("No matching visual for requested depth"); 970 SDL_SetError("No matching visual for requested depth");
976 return NULL; /* should never happen */ 971 return NULL; /* should never happen */
977 } 972 }
978 SDL_Visual = this->hidden->visuals[i].visual; 973 SDL_Visual = this->hidden->visuals[i].visual;
979 974
980 D (bug ("Setting screen depth to: %ld\n", this->hidden->depth)); 975 D(bug("Setting screen depth to: %ld\n", this->hidden->depth));
981 976
982 } 977 }
983 /* Check the combination of flags we were passed */ 978 /* Check the combination of flags we were passed */
984 if (flags & SDL_FULLSCREEN) { 979 if (flags & SDL_FULLSCREEN) {
985 int i; 980 int i;
989 flags &= ~SDL_FULLSCREEN; 984 flags &= ~SDL_FULLSCREEN;
990 } else if (current && current->flags & SDL_FULLSCREEN) { 985 } else if (current && current->flags & SDL_FULLSCREEN) {
991 if (current->w != width || 986 if (current->w != width ||
992 current->h != height || 987 current->h != height ||
993 (this->hidden && this->hidden->depth != bpp)) { 988 (this->hidden && this->hidden->depth != bpp)) {
994 D (bug ("Deleting previous window...\n")); 989 D(bug("Deleting previous window...\n"));
995 CGX_DestroyImage (this, current); 990 CGX_DestroyImage(this, current);
996 CGX_DestroyWindow (this, current); 991 CGX_DestroyWindow(this, current);
997 DestroyScreen (this); 992 DestroyScreen(this);
998 goto buildnewscreen; 993 goto buildnewscreen;
999 } 994 }
1000 } else 995 } else
1001 buildnewscreen: 996 buildnewscreen:
1002 { 997 {
1003 Uint32 okid = BestCModeIDTags (CYBRBIDTG_NominalWidth, width, 998 Uint32 okid = BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
1004 CYBRBIDTG_NominalHeight, 999 CYBRBIDTG_NominalHeight,
1005 height, 1000 height,
1006 CYBRBIDTG_Depth, bpp, 1001 CYBRBIDTG_Depth, bpp,
1007 TAG_DONE); 1002 TAG_DONE);
1008 1003
1009 GFX_Display = NULL; 1004 GFX_Display = NULL;
1010 1005
1011 D (bug ("Opening screen...\n")); 1006 D(bug("Opening screen...\n"));
1012 1007
1013 if (okid != INVALID_ID) 1008 if (okid != INVALID_ID)
1014 GFX_Display = OpenScreenTags (NULL, 1009 GFX_Display = OpenScreenTags(NULL,
1015 SA_Width, width, 1010 SA_Width, width,
1016 SA_Height, height, 1011 SA_Height, height,
1017 SA_Quiet, TRUE, 1012 SA_Quiet, TRUE,
1018 SA_ShowTitle, FALSE, 1013 SA_ShowTitle, FALSE,
1019 SA_Depth, bpp, SA_DisplayID, 1014 SA_Depth, bpp, SA_DisplayID,
1020 okid, TAG_DONE); 1015 okid, TAG_DONE);
1021 1016
1022 if (!GFX_Display) { 1017 if (!GFX_Display) {
1023 GFX_Display = SDL_Display; 1018 GFX_Display = SDL_Display;
1024 flags &= ~SDL_FULLSCREEN; 1019 flags &= ~SDL_FULLSCREEN;
1025 flags &= ~SDL_DOUBLEBUF; 1020 flags &= ~SDL_DOUBLEBUF;
1026 } else { 1021 } else {
1027 UnlockPubScreen (NULL, SDL_Display); 1022 UnlockPubScreen(NULL, SDL_Display);
1028 SDL_Display = GFX_Display; 1023 SDL_Display = GFX_Display;
1029 1024
1030 D (bug ("Screen opened.\n")); 1025 D(bug("Screen opened.\n"));
1031 1026
1032 if (flags & SDL_DOUBLEBUF) { 1027 if (flags & SDL_DOUBLEBUF) {
1033 int ok = 0; 1028 int ok = 0;
1034 D (bug ("Start of DBuffering allocations...\n")); 1029 D(bug("Start of DBuffering allocations...\n"));
1035 1030
1036 if (this->hidden->SB[0] = 1031 if (this->hidden->SB[0] =
1037 AllocScreenBuffer (SDL_Display, NULL, 1032 AllocScreenBuffer(SDL_Display, NULL,
1038 SB_SCREEN_BITMAP)) { 1033 SB_SCREEN_BITMAP)) {
1039 1034
1040 if (this->hidden->SB[1] = 1035 if (this->hidden->SB[1] =
1041 AllocScreenBuffer (SDL_Display, NULL, 0L)) { 1036 AllocScreenBuffer(SDL_Display, NULL, 0L)) {
1042 extern struct MsgPort *safeport, *dispport; 1037 extern struct MsgPort *safeport, *dispport;
1043 1038
1044 safeport = CreateMsgPort (); 1039 safeport = CreateMsgPort();
1045 dispport = CreateMsgPort (); 1040 dispport = CreateMsgPort();
1046 1041
1047 if (!safeport || !dispport) { 1042 if (!safeport || !dispport) {
1048 if (safeport) { 1043 if (safeport) {
1049 DeleteMsgPort (safeport); 1044 DeleteMsgPort(safeport);
1050 safeport = NULL; 1045 safeport = NULL;
1051 } 1046 }
1052 if (dispport) { 1047 if (dispport) {
1053 DeleteMsgPort (dispport); 1048 DeleteMsgPort(dispport);
1054 dispport = NULL; 1049 dispport = NULL;
1055 } 1050 }
1056 FreeScreenBuffer (SDL_Display, 1051 FreeScreenBuffer(SDL_Display,
1057 this->hidden->SB[0]); 1052 this->hidden->SB[0]);
1058 FreeScreenBuffer (SDL_Display, 1053 FreeScreenBuffer(SDL_Display,
1059 this->hidden->SB[1]); 1054 this->hidden->SB[1]);
1060 } else { 1055 } else {
1061 extern ULONG safe_sigbit, disp_sigbit; 1056 extern ULONG safe_sigbit, disp_sigbit;
1062 int i; 1057 int i;
1063 1058
1064 safe_sigbit = 1L << safeport->mp_SigBit; 1059 safe_sigbit = 1L << safeport->mp_SigBit;
1074 dbi_DispMessage. 1069 dbi_DispMessage.
1075 mn_ReplyPort = dispport; 1070 mn_ReplyPort = dispport;
1076 } 1071 }
1077 1072
1078 ok = 1; 1073 ok = 1;
1079 D (bug ("Dbuffering enabled!\n")); 1074 D(bug("Dbuffering enabled!\n"));
1080 this->hidden->dbuffer = 1; 1075 this->hidden->dbuffer = 1;
1081 current->flags |= SDL_DOUBLEBUF; 1076 current->flags |= SDL_DOUBLEBUF;
1082 } 1077 }
1083 } else { 1078 } else {
1084 FreeScreenBuffer (SDL_Display, 1079 FreeScreenBuffer(SDL_Display,
1085 this->hidden->SB[1]); 1080 this->hidden->SB[1]);
1086 this->hidden->SB[0] = NULL; 1081 this->hidden->SB[0] = NULL;
1087 } 1082 }
1088 } 1083 }
1089 1084
1090 if (!ok) 1085 if (!ok)
1096 (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH) == bpp) 1091 (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH) == bpp)
1097 this->hidden->same_format = 1; 1092 this->hidden->same_format = 1;
1098 } 1093 }
1099 1094
1100 bpp = this->hidden->depth = 1095 bpp = this->hidden->depth =
1101 GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH); 1096 GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
1102 D (bug ("Setting screen depth to: %ld\n", this->hidden->depth)); 1097 D(bug("Setting screen depth to: %ld\n", this->hidden->depth));
1103 1098
1104 for (i = 0; i < this->hidden->nvisuals; i++) 1099 for (i = 0; i < this->hidden->nvisuals; i++)
1105 if (this->hidden->visuals[i].depth == bpp) /* era .depth */ 1100 if (this->hidden->visuals[i].depth == bpp) /* era .depth */
1106 break; 1101 break;
1107 1102
1108 if (i == this->hidden->nvisuals) { 1103 if (i == this->hidden->nvisuals) {
1109 SDL_SetError ("No matching visual for requested depth"); 1104 SDL_SetError("No matching visual for requested depth");
1110 return NULL; /* should never happen */ 1105 return NULL; /* should never happen */
1111 } 1106 }
1112 SDL_Visual = this->hidden->visuals[i].visual; 1107 SDL_Visual = this->hidden->visuals[i].visual;
1113 1108
1114 } 1109 }
1117 saved_flags = current->flags; 1112 saved_flags = current->flags;
1118 1113
1119 if (SDL_Window 1114 if (SDL_Window
1120 && (saved_flags & SDL_INTERNALOPENGL) == (flags & SDL_INTERNALOPENGL) 1115 && (saved_flags & SDL_INTERNALOPENGL) == (flags & SDL_INTERNALOPENGL)
1121 && bpp == current->format->BitsPerPixel && !needcreate) { 1116 && bpp == current->format->BitsPerPixel && !needcreate) {
1122 if (CGX_ResizeWindow (this, current, width, height, flags) < 0) { 1117 if (CGX_ResizeWindow(this, current, width, height, flags) < 0) {
1123 current = NULL; 1118 current = NULL;
1124 goto done; 1119 goto done;
1125 } 1120 }
1126 } else { 1121 } else {
1127 if (CGX_CreateWindow (this, current, width, height, bpp, flags) < 0) { 1122 if (CGX_CreateWindow(this, current, width, height, bpp, flags) < 0) {
1128 current = NULL; 1123 current = NULL;
1129 goto done; 1124 goto done;
1130 } 1125 }
1131 } 1126 }
1132 1127
1135 if (((current->w != width) || (current->h != height)) || 1130 if (((current->w != width) || (current->h != height)) ||
1136 ((saved_flags & SDL_INTERNALOPENGL) != (flags & SDL_INTERNALOPENGL))) 1131 ((saved_flags & SDL_INTERNALOPENGL) != (flags & SDL_INTERNALOPENGL)))
1137 { 1132 {
1138 current->w = width; 1133 current->w = width;
1139 current->h = height; 1134 current->h = height;
1140 current->pitch = SDL_CalculatePitch (current); 1135 current->pitch = SDL_CalculatePitch(current);
1141 CGX_ResizeImage (this, current, flags); 1136 CGX_ResizeImage(this, current, flags);
1142 } 1137 }
1143 #endif 1138 #endif
1144 1139
1145 current->flags |= (flags & SDL_RESIZABLE); // Resizable only if the user asked it 1140 current->flags |= (flags & SDL_RESIZABLE); // Resizable only if the user asked it
1146 1141
1147 done: 1142 done:
1148 /* Release the event thread */ 1143 /* Release the event thread */
1149 SDL_Unlock_EventThread (); 1144 SDL_Unlock_EventThread();
1150 1145
1151 /* We're done! */ 1146 /* We're done! */
1152 return (current); 1147 return (current);
1153 } 1148 }
1154 1149
1155 static int 1150 static int
1156 CGX_ToggleFullScreen (_THIS, int on) 1151 CGX_ToggleFullScreen(_THIS, int on)
1157 { 1152 {
1158 Uint32 event_thread; 1153 Uint32 event_thread;
1159 1154
1160 /* Don't switch if we don't own the window */ 1155 /* Don't switch if we don't own the window */
1161 if (SDL_windowid) { 1156 if (SDL_windowid) {
1162 return (0); 1157 return (0);
1163 } 1158 }
1164 1159
1165 /* Don't lock if we are the event thread */ 1160 /* Don't lock if we are the event thread */
1166 event_thread = SDL_EventThreadID (); 1161 event_thread = SDL_EventThreadID();
1167 if (event_thread && (SDL_ThreadID () == event_thread)) { 1162 if (event_thread && (SDL_ThreadID() == event_thread)) {
1168 event_thread = 0; 1163 event_thread = 0;
1169 } 1164 }
1170 if (event_thread) { 1165 if (event_thread) {
1171 SDL_Lock_EventThread (); 1166 SDL_Lock_EventThread();
1172 } 1167 }
1173 if (on) { 1168 if (on) {
1174 this->screen->flags |= SDL_FULLSCREEN; 1169 this->screen->flags |= SDL_FULLSCREEN;
1175 CGX_EnterFullScreen (this); 1170 CGX_EnterFullScreen(this);
1176 } else { 1171 } else {
1177 this->screen->flags &= ~SDL_FULLSCREEN; 1172 this->screen->flags &= ~SDL_FULLSCREEN;
1178 CGX_LeaveFullScreen (this); 1173 CGX_LeaveFullScreen(this);
1179 } 1174 }
1180 1175
1181 CGX_RefreshDisplay (this); 1176 CGX_RefreshDisplay(this);
1182 if (event_thread) { 1177 if (event_thread) {
1183 SDL_Unlock_EventThread (); 1178 SDL_Unlock_EventThread();
1184 } 1179 }
1185 1180
1186 SDL_ResetKeyboard (); 1181 SDL_ResetKeyboard();
1187 1182
1188 return (1); 1183 return (1);
1189 } 1184 }
1190 1185
1191 static void 1186 static void
1192 SetSingleColor (Uint32 fmt, unsigned char r, unsigned char g, unsigned char b, 1187 SetSingleColor(Uint32 fmt, unsigned char r, unsigned char g, unsigned char b,
1193 unsigned char *c) 1188 unsigned char *c)
1194 { 1189 {
1195 switch (fmt) { 1190 switch (fmt) {
1196 case PIXFMT_BGR15: 1191 case PIXFMT_BGR15:
1197 case PIXFMT_RGB15PC: 1192 case PIXFMT_RGB15PC:
1198 { 1193 {
1251 c[2] = b; 1246 c[2] = b;
1252 c[3] = 0; 1247 c[3] = 0;
1253 break; 1248 break;
1254 1249
1255 default: 1250 default:
1256 D (bug ("Error, SetSingleColor with PIXFMT %ld!\n", fmt)); 1251 D(bug("Error, SetSingleColor with PIXFMT %ld!\n", fmt));
1257 } 1252 }
1258 } 1253 }
1259 1254
1260 /* Update the current mouse state and position */ 1255 /* Update the current mouse state and position */
1261 static void 1256 static void
1262 CGX_UpdateMouse (_THIS) 1257 CGX_UpdateMouse(_THIS)
1263 { 1258 {
1264 /* Lock the event thread, in multi-threading environments */ 1259 /* Lock the event thread, in multi-threading environments */
1265 SDL_Lock_EventThread (); 1260 SDL_Lock_EventThread();
1266 1261
1267 if (currently_fullscreen) { 1262 if (currently_fullscreen) {
1268 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 1263 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
1269 SDL_PrivateMouseMotion (0, 0, SDL_Display->MouseX, 1264 SDL_PrivateMouseMotion(0, 0, SDL_Display->MouseX,
1270 SDL_Display->MouseY); 1265 SDL_Display->MouseY);
1271 } else { 1266 } else {
1272 if (SDL_Display->MouseX >= 1267 if (SDL_Display->MouseX >=
1273 (SDL_Window->LeftEdge + SDL_Window->BorderLeft) 1268 (SDL_Window->LeftEdge + SDL_Window->BorderLeft)
1274 && SDL_Display->MouseX < 1269 && SDL_Display->MouseX <
1275 (SDL_Window->LeftEdge + SDL_Window->Width - 1270 (SDL_Window->LeftEdge + SDL_Window->Width -
1277 && SDL_Display->MouseY >= 1272 && SDL_Display->MouseY >=
1278 (SDL_Window->TopEdge + SDL_Window->BorderLeft) 1273 (SDL_Window->TopEdge + SDL_Window->BorderLeft)
1279 && SDL_Display->MouseY < 1274 && SDL_Display->MouseY <
1280 (SDL_Window->TopEdge + SDL_Window->Height - 1275 (SDL_Window->TopEdge + SDL_Window->Height -
1281 SDL_Window->BorderBottom)) { 1276 SDL_Window->BorderBottom)) {
1282 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 1277 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
1283 SDL_PrivateMouseMotion (0, 0, 1278 SDL_PrivateMouseMotion(0, 0,
1284 SDL_Display->MouseX - 1279 SDL_Display->MouseX -
1285 SDL_Window->LeftEdge - 1280 SDL_Window->LeftEdge -
1286 SDL_Window->BorderLeft, 1281 SDL_Window->BorderLeft,
1287 SDL_Display->MouseY - 1282 SDL_Display->MouseY -
1288 SDL_Window->TopEdge - 1283 SDL_Window->TopEdge -
1289 SDL_Window->BorderTop); 1284 SDL_Window->BorderTop);
1290 } else { 1285 } else {
1291 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 1286 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
1292 } 1287 }
1293 } 1288 }
1294 SDL_Unlock_EventThread (); 1289 SDL_Unlock_EventThread();
1295 } 1290 }
1296 1291
1297 static int 1292 static int
1298 CGX_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 1293 CGX_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1299 { 1294 {
1300 int i; 1295 int i;
1301 1296
1302 /* Check to make sure we have a colormap allocated */ 1297 /* Check to make sure we have a colormap allocated */
1303 1298
1314 xcmap[i * 3 + 1] = colors[i + firstcolor].r << 24; 1309 xcmap[i * 3 + 1] = colors[i + firstcolor].r << 24;
1315 xcmap[i * 3 + 2] = colors[i + firstcolor].g << 24; 1310 xcmap[i * 3 + 2] = colors[i + firstcolor].g << 24;
1316 xcmap[i * 3 + 3] = colors[i + firstcolor].b << 24; 1311 xcmap[i * 3 + 3] = colors[i + firstcolor].b << 24;
1317 } 1312 }
1318 xcmap[ncolors * 3 + 1] = 0; 1313 xcmap[ncolors * 3 + 1] = 0;
1319 LoadRGB32 (&GFX_Display->ViewPort, xcmap); 1314 LoadRGB32(&GFX_Display->ViewPort, xcmap);
1320 } else { 1315 } else {
1321 // XPixels are not needed on 8bit screen with hwpalette 1316 // XPixels are not needed on 8bit screen with hwpalette
1322 unsigned long pixel; 1317 unsigned long pixel;
1323 1318
1324 if (SDL_XPixels == NULL) { 1319 if (SDL_XPixels == NULL) {
1325 D (bug ("SetColors without colormap!")); 1320 D(bug("SetColors without colormap!"));
1326 return (0); 1321 return (0);
1327 } 1322 }
1328 1323
1329 if (this->hidden->depth == 8) { 1324 if (this->hidden->depth == 8) {
1330 // In this case I have to unalloc and realloc the full palette 1325 // In this case I have to unalloc and realloc the full palette
1331 D (bug ("Obtaining %ld colors on the screen\n", ncolors)); 1326 D(bug("Obtaining %ld colors on the screen\n", ncolors));
1332 1327
1333 /* Free existing allocated colors */ 1328 /* Free existing allocated colors */
1334 for (pixel = 0; 1329 for (pixel = 0;
1335 pixel < this->screen->format->palette->ncolors; ++pixel) { 1330 pixel < this->screen->format->palette->ncolors; ++pixel) {
1336 if (SDL_XPixels[pixel] >= 0) 1331 if (SDL_XPixels[pixel] >= 0)
1337 ReleasePen (GFX_Display->ViewPort.ColorMap, 1332 ReleasePen(GFX_Display->ViewPort.ColorMap,
1338 SDL_XPixels[pixel]); 1333 SDL_XPixels[pixel]);
1339 } 1334 }
1340 1335
1341 /* Try to allocate all the colors */ 1336 /* Try to allocate all the colors */
1342 for (i = 0; i < this->screen->format->palette->ncolors; ++i) { 1337 for (i = 0; i < this->screen->format->palette->ncolors; ++i) {
1343 SDL_XPixels[i] = 1338 SDL_XPixels[i] =
1344 ObtainBestPenA (GFX_Display->ViewPort.ColorMap, 1339 ObtainBestPenA(GFX_Display->ViewPort.ColorMap,
1345 colors[i].r << 24, 1340 colors[i].r << 24,
1346 colors[i].g << 24, 1341 colors[i].g << 24,
1347 colors[i].b << 24, NULL); 1342 colors[i].b << 24, NULL);
1348 } 1343 }
1349 } else { 1344 } else {
1350 #ifndef USE_CGX_WRITELUTPIXEL 1345 #ifndef USE_CGX_WRITELUTPIXEL
1351 Uint32 fmt; 1346 Uint32 fmt;
1352 D (bug ("Preparing a conversion pixel table...\n")); 1347 D(bug("Preparing a conversion pixel table...\n"));
1353 1348
1354 fmt = 1349 fmt =
1355 GetCyberMapAttr (SDL_Display->RastPort.BitMap, 1350 GetCyberMapAttr(SDL_Display->RastPort.BitMap,
1356 CYBRMATTR_PIXFMT); 1351 CYBRMATTR_PIXFMT);
1357 1352
1358 for (i = 0; i < ncolors; i++) { 1353 for (i = 0; i < ncolors; i++) {
1359 SetSingleColor (fmt, colors[firstcolor + i].r, 1354 SetSingleColor(fmt, colors[firstcolor + i].r,
1360 colors[firstcolor + i].g, 1355 colors[firstcolor + i].g,
1361 colors[firstcolor + i].b, (unsigned char *) 1356 colors[firstcolor + i].b, (unsigned char *)
1362 &SDL_XPixels[firstcolor + i]); 1357 &SDL_XPixels[firstcolor + i]);
1363 } 1358 }
1364 #else 1359 #else
1365 // D(bug("Executing XPixel(%lx) remapping: (from %ld, %ld colors) first: r%ld g%ld b%ld\n",SDL_XPixels,firstcolor,ncolors,colors[firstcolor].r,colors[firstcolor].g,colors[firstcolor].b)); 1360 // D(bug("Executing XPixel(%lx) remapping: (from %ld, %ld colors) first: r%ld g%ld b%ld\n",SDL_XPixels,firstcolor,ncolors,colors[firstcolor].r,colors[firstcolor].g,colors[firstcolor].b));
1366 for (i = 0; i < ncolors; i++) 1361 for (i = 0; i < ncolors; i++)
1367 SDL_XPixels[i + firstcolor] = 1362 SDL_XPixels[i + firstcolor] =
1379 1374
1380 /* Note: If we are terminated, this could be called in the middle of 1375 /* Note: If we are terminated, this could be called in the middle of
1381 another SDL video routine -- notably UpdateRects. 1376 another SDL video routine -- notably UpdateRects.
1382 */ 1377 */
1383 static void 1378 static void
1384 CGX_VideoQuit (_THIS) 1379 CGX_VideoQuit(_THIS)
1385 { 1380 {
1386 /* Shutdown everything that's still up */ 1381 /* Shutdown everything that's still up */
1387 /* The event thread should be done, so we can touch SDL_Display */ 1382 /* The event thread should be done, so we can touch SDL_Display */
1388 D (bug ("CGX_VideoQuit\n")); 1383 D(bug("CGX_VideoQuit\n"));
1389 1384
1390 if (SDL_Display != NULL) { 1385 if (SDL_Display != NULL) {
1391 /* Clean up OpenGL */ 1386 /* Clean up OpenGL */
1392 if (this->gl_data->gl_active == 1) { 1387 if (this->gl_data->gl_active == 1) {
1393 CGX_GL_Quit (this); 1388 CGX_GL_Quit(this);
1394 } 1389 }
1395 /* Start shutting down the windows */ 1390 /* Start shutting down the windows */
1396 D (bug ("Destroying image...\n")); 1391 D(bug("Destroying image...\n"));
1397 CGX_DestroyImage (this, this->screen); 1392 CGX_DestroyImage(this, this->screen);
1398 D (bug ("Destroying window...\n")); 1393 D(bug("Destroying window...\n"));
1399 CGX_DestroyWindow (this, this->screen); 1394 CGX_DestroyWindow(this, this->screen);
1400 // Otherwise SDL_VideoQuit will try to free it! 1395 // Otherwise SDL_VideoQuit will try to free it!
1401 SDL_VideoSurface = NULL; 1396 SDL_VideoSurface = NULL;
1402 1397
1403 CGX_FreeVideoModes (this); 1398 CGX_FreeVideoModes(this);
1404 1399
1405 /* Free that blank cursor */ 1400 /* Free that blank cursor */
1406 if (SDL_BlankCursor != NULL) { 1401 if (SDL_BlankCursor != NULL) {
1407 FreeMem (SDL_BlankCursor, 16); 1402 FreeMem(SDL_BlankCursor, 16);
1408 SDL_BlankCursor = NULL; 1403 SDL_BlankCursor = NULL;
1409 } 1404 }
1410 1405
1411 /* Close the X11 graphics connection */ 1406 /* Close the X11 graphics connection */
1412 this->hidden->same_format = 0; 1407 this->hidden->same_format = 0;
1413 1408
1414 D (bug ("Destroying screen...\n")); 1409 D(bug("Destroying screen...\n"));
1415 1410
1416 if (GFX_Display != NULL) 1411 if (GFX_Display != NULL)
1417 DestroyScreen (this); 1412 DestroyScreen(this);
1418 1413
1419 /* Close the X11 display connection */ 1414 /* Close the X11 display connection */
1420 SDL_Display = NULL; 1415 SDL_Display = NULL;
1421 1416
1422 /* Unload GL library after X11 shuts down */ 1417 /* Unload GL library after X11 shuts down */
1423 } 1418 }
1424 1419
1425 D (bug ("Closing libraries...\n")); 1420 D(bug("Closing libraries...\n"));
1426 1421
1427 if (CyberGfxBase) { 1422 if (CyberGfxBase) {
1428 CloseLibrary (CyberGfxBase); 1423 CloseLibrary(CyberGfxBase);
1429 CyberGfxBase = NULL; 1424 CyberGfxBase = NULL;
1430 } 1425 }
1431 1426
1432 if (IntuitionBase) { 1427 if (IntuitionBase) {
1433 CloseLibrary ((struct Library *) IntuitionBase); 1428 CloseLibrary((struct Library *) IntuitionBase);
1434 IntuitionBase = NULL; 1429 IntuitionBase = NULL;
1435 } 1430 }
1436 if (GfxBase) { 1431 if (GfxBase) {
1437 CloseLibrary ((struct Library *) GfxBase); 1432 CloseLibrary((struct Library *) GfxBase);
1438 GfxBase = NULL; 1433 GfxBase = NULL;
1439 } 1434 }
1440 1435
1441 if (this->screen && (this->screen->flags & SDL_HWSURFACE)) { 1436 if (this->screen && (this->screen->flags & SDL_HWSURFACE)) {
1442 /* Direct screen access, no memory buffer */ 1437 /* Direct screen access, no memory buffer */
1443 this->screen->pixels = NULL; 1438 this->screen->pixels = NULL;
1444 } 1439 }
1445 D (bug ("End of CGX_VideoQuit.\n")); 1440 D(bug("End of CGX_VideoQuit.\n"));
1446 1441
1447 } 1442 }
1448 1443
1449 /* vi: set ts=4 sw=4 expandtab: */ 1444 /* vi: set ts=4 sw=4 expandtab: */