comparison src/video/gem/SDL_gemvideo.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
74 }; 74 };
75 75
76 static const unsigned char empty_name[] = ""; 76 static const unsigned char empty_name[] = "";
77 77
78 /* Initialization/Query functions */ 78 /* Initialization/Query functions */
79 static int GEM_VideoInit (_THIS, SDL_PixelFormat * vformat); 79 static int GEM_VideoInit(_THIS, SDL_PixelFormat * vformat);
80 static SDL_Rect **GEM_ListModes (_THIS, SDL_PixelFormat * format, 80 static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat * format,
81 Uint32 flags); 81 Uint32 flags);
82 static SDL_Surface *GEM_SetVideoMode (_THIS, SDL_Surface * current, int width, 82 static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface * current, int width,
83 int height, int bpp, Uint32 flags); 83 int height, int bpp, Uint32 flags);
84 static int GEM_SetColors (_THIS, int firstcolor, int ncolors, 84 static int GEM_SetColors(_THIS, int firstcolor, int ncolors,
85 SDL_Color * colors); 85 SDL_Color * colors);
86 static void GEM_VideoQuit (_THIS); 86 static void GEM_VideoQuit(_THIS);
87 87
88 /* Hardware surface functions */ 88 /* Hardware surface functions */
89 static int GEM_AllocHWSurface (_THIS, SDL_Surface * surface); 89 static int GEM_AllocHWSurface(_THIS, SDL_Surface * surface);
90 static int GEM_LockHWSurface (_THIS, SDL_Surface * surface); 90 static int GEM_LockHWSurface(_THIS, SDL_Surface * surface);
91 static int GEM_FlipHWSurface (_THIS, SDL_Surface * surface); 91 static int GEM_FlipHWSurface(_THIS, SDL_Surface * surface);
92 static void GEM_UnlockHWSurface (_THIS, SDL_Surface * surface); 92 static void GEM_UnlockHWSurface(_THIS, SDL_Surface * surface);
93 static void GEM_FreeHWSurface (_THIS, SDL_Surface * surface); 93 static void GEM_FreeHWSurface(_THIS, SDL_Surface * surface);
94 static void GEM_UpdateRects (_THIS, int numrects, SDL_Rect * rects); 94 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
95 #if 0 95 #if 0
96 static int GEM_ToggleFullScreen (_THIS, int on); 96 static int GEM_ToggleFullScreen(_THIS, int on);
97 #endif 97 #endif
98 98
99 /* Internal functions */ 99 /* Internal functions */
100 static void GEM_FreeBuffers (_THIS); 100 static void GEM_FreeBuffers(_THIS);
101 static void GEM_ClearScreen (_THIS); 101 static void GEM_ClearScreen(_THIS);
102 static void GEM_ClearRect (_THIS, short *rect); 102 static void GEM_ClearRect(_THIS, short *rect);
103 static void GEM_SetNewPalette (_THIS, Uint16 newpal[256][3]); 103 static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]);
104 static void GEM_LockScreen (_THIS); 104 static void GEM_LockScreen(_THIS);
105 static void GEM_UnlockScreen (_THIS); 105 static void GEM_UnlockScreen(_THIS);
106 static void refresh_window (_THIS, int winhandle, short *rect); 106 static void refresh_window(_THIS, int winhandle, short *rect);
107 107
108 #if SDL_VIDEO_OPENGL 108 #if SDL_VIDEO_OPENGL
109 /* OpenGL functions */ 109 /* OpenGL functions */
110 static void GEM_GL_SwapBuffers (_THIS); 110 static void GEM_GL_SwapBuffers(_THIS);
111 #endif 111 #endif
112 112
113 /* GEM driver bootstrap functions */ 113 /* GEM driver bootstrap functions */
114 114
115 static int 115 static int
116 GEM_Available (void) 116 GEM_Available(void)
117 { 117 {
118 /* Test if AES available */ 118 /* Test if AES available */
119 if (appl_init () == -1) 119 if (appl_init() == -1)
120 return 0; 120 return 0;
121 121
122 appl_exit (); 122 appl_exit();
123 return 1; 123 return 1;
124 } 124 }
125 125
126 static void 126 static void
127 GEM_DeleteDevice (SDL_VideoDevice * device) 127 GEM_DeleteDevice(SDL_VideoDevice * device)
128 { 128 {
129 SDL_free (device->hidden); 129 SDL_free(device->hidden);
130 SDL_free (device); 130 SDL_free(device);
131 } 131 }
132 132
133 static SDL_VideoDevice * 133 static SDL_VideoDevice *
134 GEM_CreateDevice (int devindex) 134 GEM_CreateDevice(int devindex)
135 { 135 {
136 SDL_VideoDevice *device; 136 SDL_VideoDevice *device;
137 int vectors_mask; 137 int vectors_mask;
138 unsigned long dummy; 138 unsigned long dummy;
139 139
140 /* Initialize all variables that we clean on shutdown */ 140 /* Initialize all variables that we clean on shutdown */
141 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice)); 141 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
142 if (device) { 142 if (device) {
143 SDL_memset (device, 0, (sizeof *device)); 143 SDL_memset(device, 0, (sizeof *device));
144 device->hidden = (struct SDL_PrivateVideoData *) 144 device->hidden = (struct SDL_PrivateVideoData *)
145 SDL_malloc ((sizeof *device->hidden)); 145 SDL_malloc((sizeof *device->hidden));
146 device->gl_data = (struct SDL_PrivateGLData *) 146 device->gl_data = (struct SDL_PrivateGLData *)
147 SDL_malloc ((sizeof *device->gl_data)); 147 SDL_malloc((sizeof *device->gl_data));
148 } 148 }
149 if ((device == NULL) || (device->hidden == NULL)) { 149 if ((device == NULL) || (device->hidden == NULL)) {
150 SDL_OutOfMemory (); 150 SDL_OutOfMemory();
151 if (device) { 151 if (device) {
152 SDL_free (device); 152 SDL_free(device);
153 } 153 }
154 return (0); 154 return (0);
155 } 155 }
156 SDL_memset (device->hidden, 0, (sizeof *device->hidden)); 156 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
157 SDL_memset (device->gl_data, 0, sizeof (*device->gl_data)); 157 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
158 158
159 /* Set the function pointers */ 159 /* Set the function pointers */
160 device->VideoInit = GEM_VideoInit; 160 device->VideoInit = GEM_VideoInit;
161 device->ListModes = GEM_ListModes; 161 device->ListModes = GEM_ListModes;
162 device->SetVideoMode = GEM_SetVideoMode; 162 device->SetVideoMode = GEM_SetVideoMode;
195 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent; 195 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
196 device->GL_SwapBuffers = GEM_GL_SwapBuffers; 196 device->GL_SwapBuffers = GEM_GL_SwapBuffers;
197 #endif 197 #endif
198 198
199 device->hidden->use_dev_mouse = 199 device->hidden->use_dev_mouse =
200 (SDL_AtariDevMouse_Open () != 0) ? SDL_TRUE : SDL_FALSE; 200 (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
201 201
202 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 202 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
203 if (!(device->hidden->use_dev_mouse)) { 203 if (!(device->hidden->use_dev_mouse)) {
204 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */ 204 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
205 } 205 }
206 if (Getcookie (C_MiNT, &dummy) == C_FOUND) { 206 if (Getcookie(C_MiNT, &dummy) == C_FOUND) {
207 vectors_mask = 0; 207 vectors_mask = 0;
208 } 208 }
209 209
210 SDL_AtariXbios_InstallVectors (vectors_mask); 210 SDL_AtariXbios_InstallVectors(vectors_mask);
211 211
212 device->free = GEM_DeleteDevice; 212 device->free = GEM_DeleteDevice;
213 213
214 return device; 214 return device;
215 } 215 }
218 GEM_VID_DRIVER_NAME, "Atari GEM video driver", 218 GEM_VID_DRIVER_NAME, "Atari GEM video driver",
219 GEM_Available, GEM_CreateDevice 219 GEM_Available, GEM_CreateDevice
220 }; 220 };
221 221
222 static void 222 static void
223 VDI_ReadExtInfo (_THIS, short *work_out) 223 VDI_ReadExtInfo(_THIS, short *work_out)
224 { 224 {
225 unsigned long EdDI_version; 225 unsigned long EdDI_version;
226 unsigned long cookie_EdDI; 226 unsigned long cookie_EdDI;
227 Uint32 num_colours; 227 Uint32 num_colours;
228 Uint16 clut_type, num_bits; 228 Uint16 clut_type, num_bits;
229 229
230 /* Read EdDI informations */ 230 /* Read EdDI informations */
231 if (Getcookie (C_EdDI, &cookie_EdDI) == C_NOTFOUND) { 231 if (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
232 return; 232 return;
233 } 233 }
234 234
235 EdDI_version = Atari_get_EdDI_version ((void *) cookie_EdDI); 235 EdDI_version = Atari_get_EdDI_version((void *) cookie_EdDI);
236 236
237 vq_scrninfo (VDI_handle, work_out); 237 vq_scrninfo(VDI_handle, work_out);
238 238
239 VDI_format = work_out[0]; 239 VDI_format = work_out[0];
240 clut_type = work_out[1]; 240 clut_type = work_out[1];
241 num_bits = work_out[2]; 241 num_bits = work_out[2];
242 num_colours = *((Uint32 *) & work_out[3]); 242 num_colours = *((Uint32 *) & work_out[3]);
308 break; 308 break;
309 } 309 }
310 } 310 }
311 311
312 int 312 int
313 GEM_VideoInit (_THIS, SDL_PixelFormat * vformat) 313 GEM_VideoInit(_THIS, SDL_PixelFormat * vformat)
314 { 314 {
315 int i, menubar_size; 315 int i, menubar_size;
316 short work_in[12], work_out[272], dummy; 316 short work_in[12], work_out[272], dummy;
317 317
318 /* Open AES (Application Environment Services) */ 318 /* Open AES (Application Environment Services) */
319 if (appl_init () == -1) { 319 if (appl_init() == -1) {
320 fprintf (stderr, "Can not open AES\n"); 320 fprintf(stderr, "Can not open AES\n");
321 return 1; 321 return 1;
322 } 322 }
323 323
324 /* Read version and features */ 324 /* Read version and features */
325 GEM_version = aes_global[0]; 325 GEM_version = aes_global[0];
326 if (GEM_version >= 0x0410) { 326 if (GEM_version >= 0x0410) {
327 short ap_gout[4], errorcode; 327 short ap_gout[4], errorcode;
328 328
329 GEM_wfeatures = 0; 329 GEM_wfeatures = 0;
330 errorcode = 330 errorcode =
331 appl_getinfo (AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], 331 appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2],
332 &ap_gout[3]); 332 &ap_gout[3]);
333 333
334 if (errorcode == 0) { 334 if (errorcode == 0) {
335 GEM_wfeatures = ap_gout[0]; 335 GEM_wfeatures = ap_gout[0];
336 } 336 }
337 } 337 }
338 338
339 /* Ask VDI physical workstation handle opened by AES */ 339 /* Ask VDI physical workstation handle opened by AES */
340 VDI_handle = graf_handle (&dummy, &dummy, &dummy, &dummy); 340 VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
341 if (VDI_handle < 1) { 341 if (VDI_handle < 1) {
342 fprintf (stderr, "Wrong VDI handle %d returned by AES\n", VDI_handle); 342 fprintf(stderr, "Wrong VDI handle %d returned by AES\n", VDI_handle);
343 return 1; 343 return 1;
344 } 344 }
345 345
346 /* Open virtual VDI workstation */ 346 /* Open virtual VDI workstation */
347 work_in[0] = Getrez () + 2; 347 work_in[0] = Getrez() + 2;
348 for (i = 1; i < 10; i++) 348 for (i = 1; i < 10; i++)
349 work_in[i] = 1; 349 work_in[i] = 1;
350 work_in[10] = 2; 350 work_in[10] = 2;
351 351
352 v_opnvwk (work_in, &VDI_handle, work_out); 352 v_opnvwk(work_in, &VDI_handle, work_out);
353 if (VDI_handle == 0) { 353 if (VDI_handle == 0) {
354 fprintf (stderr, "Can not open VDI virtual workstation\n"); 354 fprintf(stderr, "Can not open VDI virtual workstation\n");
355 return 1; 355 return 1;
356 } 356 }
357 357
358 /* Read fullscreen size */ 358 /* Read fullscreen size */
359 VDI_w = work_out[0] + 1; 359 VDI_w = work_out[0] + 1;
361 361
362 /* Read desktop size and position */ 362 /* Read desktop size and position */
363 if (!wind_get 363 if (!wind_get
364 (DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, 364 (DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w,
365 &GEM_desk_h)) { 365 &GEM_desk_h)) {
366 fprintf (stderr, "Can not read desktop properties\n"); 366 fprintf(stderr, "Can not read desktop properties\n");
367 return 1; 367 return 1;
368 } 368 }
369 369
370 /* Read bit depth */ 370 /* Read bit depth */
371 vq_extnd (VDI_handle, 1, work_out); 371 vq_extnd(VDI_handle, 1, work_out);
372 VDI_bpp = work_out[4]; 372 VDI_bpp = work_out[4];
373 VDI_oldnumcolors = 0; 373 VDI_oldnumcolors = 0;
374 374
375 switch (VDI_bpp) { 375 switch (VDI_bpp) {
376 case 8: 376 case 8:
385 break; 385 break;
386 case 32: 386 case 32:
387 VDI_pixelsize = 4; 387 VDI_pixelsize = 4;
388 break; 388 break;
389 default: 389 default:
390 fprintf (stderr, "%d bits colour depth not supported\n", VDI_bpp); 390 fprintf(stderr, "%d bits colour depth not supported\n", VDI_bpp);
391 return 1; 391 return 1;
392 } 392 }
393 393
394 /* Setup hardware -> VDI palette mapping */ 394 /* Setup hardware -> VDI palette mapping */
395 for (i = 16; i < 255; i++) { 395 for (i = 16; i < 255; i++) {
405 } 405 }
406 406
407 for (i = 0; i < VDI_oldnumcolors; i++) { 407 for (i = 0; i < VDI_oldnumcolors; i++) {
408 short rgb[3]; 408 short rgb[3];
409 409
410 vq_color (VDI_handle, i, 0, rgb); 410 vq_color(VDI_handle, i, 0, rgb);
411 411
412 VDI_oldpalette[i][0] = rgb[0]; 412 VDI_oldpalette[i][0] = rgb[0];
413 VDI_oldpalette[i][1] = rgb[1]; 413 VDI_oldpalette[i][1] = rgb[1];
414 VDI_oldpalette[i][2] = rgb[2]; 414 VDI_oldpalette[i][2] = rgb[2];
415 } 415 }
416 VDI_setpalette = GEM_SetNewPalette; 416 VDI_setpalette = GEM_SetNewPalette;
417 SDL_memcpy (VDI_curpalette, VDI_oldpalette, sizeof (VDI_curpalette)); 417 SDL_memcpy(VDI_curpalette, VDI_oldpalette, sizeof(VDI_curpalette));
418 418
419 /* Setup screen info */ 419 /* Setup screen info */
420 GEM_title_name = empty_name; 420 GEM_title_name = empty_name;
421 GEM_icon_name = empty_name; 421 GEM_icon_name = empty_name;
422 422
428 428
429 VDI_screen = NULL; 429 VDI_screen = NULL;
430 VDI_pitch = VDI_w * VDI_pixelsize; 430 VDI_pitch = VDI_w * VDI_pixelsize;
431 VDI_format = ((VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK); 431 VDI_format = ((VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
432 VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0; 432 VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
433 VDI_ReadExtInfo (this, work_out); 433 VDI_ReadExtInfo(this, work_out);
434 434
435 #ifdef DEBUG_VIDEO_GEM 435 #ifdef DEBUG_VIDEO_GEM
436 printf ("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, 436 printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen,
437 VDI_pitch); 437 VDI_pitch);
438 printf ("sdl:video:gem: format=%d\n", VDI_format); 438 printf("sdl:video:gem: format=%d\n", VDI_format);
439 printf ("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", 439 printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
440 VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask); 440 VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask);
441 #endif 441 #endif
442 442
443 /* Setup destination mfdb */ 443 /* Setup destination mfdb */
444 VDI_dst_mfdb.fd_addr = NULL; 444 VDI_dst_mfdb.fd_addr = NULL;
445 445
450 /* Determine the screen depth */ 450 /* Determine the screen depth */
451 /* we change this during the SDL_SetVideoMode implementation... */ 451 /* we change this during the SDL_SetVideoMode implementation... */
452 vformat->BitsPerPixel = VDI_bpp; 452 vformat->BitsPerPixel = VDI_bpp;
453 453
454 /* Set mouse cursor to arrow */ 454 /* Set mouse cursor to arrow */
455 graf_mouse (ARROW, NULL); 455 graf_mouse(ARROW, NULL);
456 456
457 /* Init chunky to planar routine */ 457 /* Init chunky to planar routine */
458 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; 458 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
459 459
460 /* Setup VDI fill functions */ 460 /* Setup VDI fill functions */
461 vsf_color (VDI_handle, 0); 461 vsf_color(VDI_handle, 0);
462 vsf_interior (VDI_handle, 1); 462 vsf_interior(VDI_handle, 1);
463 vsf_perimeter (VDI_handle, 0); 463 vsf_perimeter(VDI_handle, 0);
464 464
465 /* Menu bar save buffer */ 465 /* Menu bar save buffer */
466 menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize; 466 menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize;
467 GEM_menubar = Atari_SysMalloc (menubar_size, MX_PREFTTRAM); 467 GEM_menubar = Atari_SysMalloc(menubar_size, MX_PREFTTRAM);
468 468
469 /* Fill video modes list */ 469 /* Fill video modes list */
470 SDL_modelist[0] = SDL_malloc (sizeof (SDL_Rect)); 470 SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect));
471 SDL_modelist[0]->x = 0; 471 SDL_modelist[0]->x = 0;
472 SDL_modelist[0]->y = 0; 472 SDL_modelist[0]->y = 0;
473 SDL_modelist[0]->w = VDI_w; 473 SDL_modelist[0]->w = VDI_w;
474 SDL_modelist[0]->h = VDI_h; 474 SDL_modelist[0]->h = VDI_h;
475 475
476 SDL_modelist[1] = NULL; 476 SDL_modelist[1] = NULL;
477 477
478 #if SDL_VIDEO_OPENGL 478 #if SDL_VIDEO_OPENGL
479 SDL_AtariGL_InitPointers (this); 479 SDL_AtariGL_InitPointers(this);
480 #endif 480 #endif
481 481
482 /* We're done! */ 482 /* We're done! */
483 return (0); 483 return (0);
484 } 484 }
485 485
486 SDL_Rect ** 486 SDL_Rect **
487 GEM_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags) 487 GEM_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
488 { 488 {
489 if (format->BitsPerPixel != VDI_bpp) { 489 if (format->BitsPerPixel != VDI_bpp) {
490 return ((SDL_Rect **) NULL); 490 return ((SDL_Rect **) NULL);
491 } 491 }
492 492
496 496
497 return ((SDL_Rect **) - 1); 497 return ((SDL_Rect **) - 1);
498 } 498 }
499 499
500 static void 500 static void
501 GEM_FreeBuffers (_THIS) 501 GEM_FreeBuffers(_THIS)
502 { 502 {
503 /* Release buffer */ 503 /* Release buffer */
504 if (GEM_buffer2) { 504 if (GEM_buffer2) {
505 Mfree (GEM_buffer2); 505 Mfree(GEM_buffer2);
506 GEM_buffer2 = NULL; 506 GEM_buffer2 = NULL;
507 } 507 }
508 508
509 if (GEM_buffer1) { 509 if (GEM_buffer1) {
510 Mfree (GEM_buffer1); 510 Mfree(GEM_buffer1);
511 GEM_buffer1 = NULL; 511 GEM_buffer1 = NULL;
512 } 512 }
513 } 513 }
514 514
515 static void 515 static void
516 GEM_ClearRect (_THIS, short *rect) 516 GEM_ClearRect(_THIS, short *rect)
517 { 517 {
518 short oldrgb[3], rgb[3] = { 0, 0, 0 }; 518 short oldrgb[3], rgb[3] = { 0, 0, 0 };
519 519
520 vq_color (VDI_handle, vdi_index[0], 0, oldrgb); 520 vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
521 vs_color (VDI_handle, vdi_index[0], rgb); 521 vs_color(VDI_handle, vdi_index[0], rgb);
522 522
523 vsf_color (VDI_handle, 0); 523 vsf_color(VDI_handle, 0);
524 vsf_interior (VDI_handle, 1); 524 vsf_interior(VDI_handle, 1);
525 vsf_perimeter (VDI_handle, 0); 525 vsf_perimeter(VDI_handle, 0);
526 v_bar (VDI_handle, rect); 526 v_bar(VDI_handle, rect);
527 527
528 vs_color (VDI_handle, vdi_index[0], oldrgb); 528 vs_color(VDI_handle, vdi_index[0], oldrgb);
529 } 529 }
530 530
531 static void 531 static void
532 GEM_ClearScreen (_THIS) 532 GEM_ClearScreen(_THIS)
533 { 533 {
534 short pxy[4]; 534 short pxy[4];
535 535
536 v_hide_c (VDI_handle); 536 v_hide_c(VDI_handle);
537 537
538 pxy[0] = pxy[1] = 0; 538 pxy[0] = pxy[1] = 0;
539 pxy[2] = VDI_w - 1; 539 pxy[2] = VDI_w - 1;
540 pxy[3] = VDI_h - 1; 540 pxy[3] = VDI_h - 1;
541 GEM_ClearRect (this, pxy); 541 GEM_ClearRect(this, pxy);
542 542
543 v_show_c (VDI_handle, 1); 543 v_show_c(VDI_handle, 1);
544 } 544 }
545 545
546 static void 546 static void
547 GEM_SetNewPalette (_THIS, Uint16 newpal[256][3]) 547 GEM_SetNewPalette(_THIS, Uint16 newpal[256][3])
548 { 548 {
549 int i; 549 int i;
550 short rgb[3]; 550 short rgb[3];
551 551
552 if (VDI_oldnumcolors == 0) 552 if (VDI_oldnumcolors == 0)
555 for (i = 0; i < VDI_oldnumcolors; i++) { 555 for (i = 0; i < VDI_oldnumcolors; i++) {
556 rgb[0] = newpal[i][0]; 556 rgb[0] = newpal[i][0];
557 rgb[1] = newpal[i][1]; 557 rgb[1] = newpal[i][1];
558 rgb[2] = newpal[i][2]; 558 rgb[2] = newpal[i][2];
559 559
560 vs_color (VDI_handle, i, rgb); 560 vs_color(VDI_handle, i, rgb);
561 } 561 }
562 } 562 }
563 563
564 static void 564 static void
565 GEM_LockScreen (_THIS) 565 GEM_LockScreen(_THIS)
566 { 566 {
567 if (!GEM_locked) { 567 if (!GEM_locked) {
568 /* Lock AES */ 568 /* Lock AES */
569 wind_update (BEG_UPDATE); 569 wind_update(BEG_UPDATE);
570 wind_update (BEG_MCTRL); 570 wind_update(BEG_MCTRL);
571 /* Reserve memory space, used to be sure of compatibility */ 571 /* Reserve memory space, used to be sure of compatibility */
572 form_dial (FMD_START, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h); 572 form_dial(FMD_START, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
573 573
574 /* Save menu bar */ 574 /* Save menu bar */
575 if (GEM_menubar) { 575 if (GEM_menubar) {
576 MFDB mfdb_src; 576 MFDB mfdb_src;
577 short blitcoords[8]; 577 short blitcoords[8];
587 blitcoords[0] = blitcoords[4] = 0; 587 blitcoords[0] = blitcoords[4] = 0;
588 blitcoords[1] = blitcoords[5] = 0; 588 blitcoords[1] = blitcoords[5] = 0;
589 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1; 589 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
590 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1; 590 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
591 591
592 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb, 592 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb,
593 &mfdb_src); 593 &mfdb_src);
594 } 594 }
595 595
596 GEM_locked = SDL_TRUE; 596 GEM_locked = SDL_TRUE;
597 } 597 }
598 } 598 }
599 599
600 static void 600 static void
601 GEM_UnlockScreen (_THIS) 601 GEM_UnlockScreen(_THIS)
602 { 602 {
603 if (GEM_locked) { 603 if (GEM_locked) {
604 /* Restore menu bar */ 604 /* Restore menu bar */
605 if (GEM_menubar) { 605 if (GEM_menubar) {
606 MFDB mfdb_src; 606 MFDB mfdb_src;
617 blitcoords[0] = blitcoords[4] = 0; 617 blitcoords[0] = blitcoords[4] = 0;
618 blitcoords[1] = blitcoords[5] = 0; 618 blitcoords[1] = blitcoords[5] = 0;
619 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1; 619 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
620 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1; 620 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
621 621
622 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src, 622 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src,
623 &VDI_dst_mfdb); 623 &VDI_dst_mfdb);
624 } 624 }
625 625
626 /* Restore screen memory, and send REDRAW to all apps */ 626 /* Restore screen memory, and send REDRAW to all apps */
627 form_dial (FMD_FINISH, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h); 627 form_dial(FMD_FINISH, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
628 /* Unlock AES */ 628 /* Unlock AES */
629 wind_update (END_MCTRL); 629 wind_update(END_MCTRL);
630 wind_update (END_UPDATE); 630 wind_update(END_UPDATE);
631 631
632 GEM_locked = SDL_FALSE; 632 GEM_locked = SDL_FALSE;
633 } 633 }
634 } 634 }
635 635
636 SDL_Surface * 636 SDL_Surface *
637 GEM_SetVideoMode (_THIS, SDL_Surface * current, 637 GEM_SetVideoMode(_THIS, SDL_Surface * current,
638 int width, int height, int bpp, Uint32 flags) 638 int width, int height, int bpp, Uint32 flags)
639 { 639 {
640 int maxwidth, maxheight; 640 int maxwidth, maxheight;
641 Uint32 modeflags, screensize; 641 Uint32 modeflags, screensize;
642 SDL_bool use_shadow1, use_shadow2; 642 SDL_bool use_shadow1, use_shadow2;
643 643
655 if ((width & 15) != 0) { 655 if ((width & 15) != 0) {
656 width = (width | 15) + 1; 656 width = (width | 15) + 1;
657 } 657 }
658 658
659 if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) { 659 if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
660 SDL_SetError ("Couldn't find requested mode in list"); 660 SDL_SetError("Couldn't find requested mode in list");
661 return (NULL); 661 return (NULL);
662 } 662 }
663 663
664 /*--- Allocate the new pixel format for the screen ---*/ 664 /*--- Allocate the new pixel format for the screen ---*/
665 if (!SDL_ReallocFormat 665 if (!SDL_ReallocFormat
666 (current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, 666 (current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask,
667 VDI_alphamask)) { 667 VDI_alphamask)) {
668 SDL_SetError 668 SDL_SetError("Couldn't allocate new pixel format for requested mode");
669 ("Couldn't allocate new pixel format for requested mode");
670 return (NULL); 669 return (NULL);
671 } 670 }
672 671
673 screensize = width * height * VDI_pixelsize; 672 screensize = width * height * VDI_pixelsize;
674 673
675 #ifdef DEBUG_VIDEO_GEM 674 #ifdef DEBUG_VIDEO_GEM
676 printf ("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height, 675 printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height,
677 bpp, screensize); 676 bpp, screensize);
678 #endif 677 #endif
679 678
680 /*--- Allocate shadow buffers if needed, and conversion operations ---*/ 679 /*--- Allocate shadow buffers if needed, and conversion operations ---*/
681 GEM_FreeBuffers (this); 680 GEM_FreeBuffers(this);
682 681
683 GEM_bufops = 0; 682 GEM_bufops = 0;
684 use_shadow1 = use_shadow2 = SDL_FALSE; 683 use_shadow1 = use_shadow2 = SDL_FALSE;
685 if (VDI_screen && (flags & SDL_FULLSCREEN)) { 684 if (VDI_screen && (flags & SDL_FULLSCREEN)) {
686 if (VDI_format == VDI_FORMAT_INTER) { 685 if (VDI_format == VDI_FORMAT_INTER) {
696 GEM_bufops = B2S_C2P_1TO2 | B2S_VROCPYFM_2TOS; 695 GEM_bufops = B2S_C2P_1TO2 | B2S_VROCPYFM_2TOS;
697 } 696 }
698 } 697 }
699 698
700 if (use_shadow1) { 699 if (use_shadow1) {
701 GEM_buffer1 = Atari_SysMalloc (screensize, MX_PREFTTRAM); 700 GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
702 if (GEM_buffer1 == NULL) { 701 if (GEM_buffer1 == NULL) {
703 SDL_SetError ("Can not allocate %d KB for frame buffer", 702 SDL_SetError("Can not allocate %d KB for frame buffer",
704 screensize >> 10); 703 screensize >> 10);
705 return NULL; 704 return NULL;
706 } 705 }
707 SDL_memset (GEM_buffer1, 0, screensize); 706 SDL_memset(GEM_buffer1, 0, screensize);
708 #ifdef DEBUG_VIDEO_GEM 707 #ifdef DEBUG_VIDEO_GEM
709 printf ("sdl:video:gem: setvideomode(): allocated buffer 1\n"); 708 printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
710 #endif 709 #endif
711 } 710 }
712 711
713 if (use_shadow2) { 712 if (use_shadow2) {
714 GEM_buffer2 = Atari_SysMalloc (screensize, MX_PREFTTRAM); 713 GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
715 if (GEM_buffer2 == NULL) { 714 if (GEM_buffer2 == NULL) {
716 SDL_SetError ("Can not allocate %d KB for shadow buffer", 715 SDL_SetError("Can not allocate %d KB for shadow buffer",
717 screensize >> 10); 716 screensize >> 10);
718 return NULL; 717 return NULL;
719 } 718 }
720 SDL_memset (GEM_buffer2, 0, screensize); 719 SDL_memset(GEM_buffer2, 0, screensize);
721 #ifdef DEBUG_VIDEO_GEM 720 #ifdef DEBUG_VIDEO_GEM
722 printf ("sdl:video:gem: setvideomode(): allocated buffer 2\n"); 721 printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
723 #endif 722 #endif
724 } 723 }
725 724
726 /*--- Initialize screen ---*/ 725 /*--- Initialize screen ---*/
727 modeflags = SDL_PREALLOC; 726 modeflags = SDL_PREALLOC;
728 if (VDI_bpp == 8) { 727 if (VDI_bpp == 8) {
729 modeflags |= SDL_HWPALETTE; 728 modeflags |= SDL_HWPALETTE;
730 } 729 }
731 730
732 if (flags & SDL_FULLSCREEN) { 731 if (flags & SDL_FULLSCREEN) {
733 GEM_LockScreen (this); 732 GEM_LockScreen(this);
734 733
735 GEM_ClearScreen (this); 734 GEM_ClearScreen(this);
736 735
737 modeflags |= SDL_FULLSCREEN; 736 modeflags |= SDL_FULLSCREEN;
738 if (VDI_screen && (VDI_format == VDI_FORMAT_PACK) && !use_shadow1) { 737 if (VDI_screen && (VDI_format == VDI_FORMAT_PACK) && !use_shadow1) {
739 modeflags |= SDL_HWSURFACE; 738 modeflags |= SDL_HWSURFACE;
740 } else { 739 } else {
744 GEM_fullscreen = SDL_TRUE; 743 GEM_fullscreen = SDL_TRUE;
745 } else { 744 } else {
746 int old_win_type; 745 int old_win_type;
747 short x2, y2, w2, h2; 746 short x2, y2, w2, h2;
748 747
749 GEM_UnlockScreen (this); 748 GEM_UnlockScreen(this);
750 749
751 /* Set window gadgets */ 750 /* Set window gadgets */
752 old_win_type = GEM_win_type; 751 old_win_type = GEM_win_type;
753 if (!(flags & SDL_NOFRAME)) { 752 if (!(flags & SDL_NOFRAME)) {
754 GEM_win_type = NAME | MOVER | CLOSER | SMALLER; 753 GEM_win_type = NAME | MOVER | CLOSER | SMALLER;
766 if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) { 765 if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
767 /* Calculate window size */ 766 /* Calculate window size */
768 if (!wind_calc 767 if (!wind_calc
769 (WC_BORDER, GEM_win_type, 0, 0, width, height, &x2, &y2, 768 (WC_BORDER, GEM_win_type, 0, 0, width, height, &x2, &y2,
770 &w2, &h2)) { 769 &w2, &h2)) {
771 GEM_FreeBuffers (this); 770 GEM_FreeBuffers(this);
772 SDL_SetError ("Can not calculate window attributes"); 771 SDL_SetError("Can not calculate window attributes");
773 return NULL; 772 return NULL;
774 } 773 }
775 774
776 /* Center window */ 775 /* Center window */
777 x2 = GEM_desk_x + ((GEM_desk_w - w2) >> 1); 776 x2 = GEM_desk_x + ((GEM_desk_w - w2) >> 1);
778 y2 = GEM_desk_y + ((GEM_desk_h - h2) >> 1); 777 y2 = GEM_desk_y + ((GEM_desk_h - h2) >> 1);
779 778
780 /* Destroy existing window */ 779 /* Destroy existing window */
781 if (GEM_handle >= 0) { 780 if (GEM_handle >= 0) {
782 wind_close (GEM_handle); 781 wind_close(GEM_handle);
783 wind_delete (GEM_handle); 782 wind_delete(GEM_handle);
784 } 783 }
785 784
786 /* Create window */ 785 /* Create window */
787 GEM_handle = wind_create (GEM_win_type, x2, y2, w2, h2); 786 GEM_handle = wind_create(GEM_win_type, x2, y2, w2, h2);
788 if (GEM_handle < 0) { 787 if (GEM_handle < 0) {
789 GEM_FreeBuffers (this); 788 GEM_FreeBuffers(this);
790 SDL_SetError ("Can not create window"); 789 SDL_SetError("Can not create window");
791 return NULL; 790 return NULL;
792 } 791 }
793 #ifdef DEBUG_VIDEO_GEM 792 #ifdef DEBUG_VIDEO_GEM
794 printf ("sdl:video:gem: handle=%d\n", GEM_handle); 793 printf("sdl:video:gem: handle=%d\n", GEM_handle);
795 #endif 794 #endif
796 795
797 /* Setup window name */ 796 /* Setup window name */
798 wind_set (GEM_handle, WF_NAME, 797 wind_set(GEM_handle, WF_NAME,
799 (short) (((unsigned long) GEM_title_name) >> 16), 798 (short) (((unsigned long) GEM_title_name) >> 16),
800 (short) (((unsigned long) GEM_title_name) & 0xffff), 799 (short) (((unsigned long) GEM_title_name) & 0xffff),
801 0, 0); 800 0, 0);
802 GEM_refresh_name = SDL_FALSE; 801 GEM_refresh_name = SDL_FALSE;
803 802
804 /* Open the window */ 803 /* Open the window */
805 wind_open (GEM_handle, x2, y2, w2, h2); 804 wind_open(GEM_handle, x2, y2, w2, h2);
806 } else { 805 } else {
807 /* Resize window if needed, to fit asked video mode */ 806 /* Resize window if needed, to fit asked video mode */
808 if (modeflags & SDL_RESIZABLE) { 807 if (modeflags & SDL_RESIZABLE) {
809 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2); 808 wind_get(GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
810 if ((w2 & 15) != 0) { 809 if ((w2 & 15) != 0) {
811 w2 = (w2 | 15) + 1; 810 w2 = (w2 | 15) + 1;
812 } 811 }
813 if ((w2 != width) || (h2 != height)) { 812 if ((w2 != width) || (h2 != height)) {
814 if (wind_calc 813 if (wind_calc
815 (WC_BORDER, GEM_win_type, x2, y2, width, 814 (WC_BORDER, GEM_win_type, x2, y2, width,
816 height, &x2, &y2, &w2, &h2)) { 815 height, &x2, &y2, &w2, &h2)) {
817 wind_set (GEM_handle, WF_CURRXYWH, x2, y2, w2, h2); 816 wind_set(GEM_handle, WF_CURRXYWH, x2, y2, w2, h2);
818 } 817 }
819 } 818 }
820 } 819 }
821 } 820 }
822 821
834 current->pitch = VDI_pitch; 833 current->pitch = VDI_pitch;
835 } 834 }
836 835
837 #if SDL_VIDEO_OPENGL 836 #if SDL_VIDEO_OPENGL
838 if (flags & SDL_INTERNALOPENGL) { 837 if (flags & SDL_INTERNALOPENGL) {
839 if (!SDL_AtariGL_Init (this, current)) { 838 if (!SDL_AtariGL_Init(this, current)) {
840 GEM_FreeBuffers (this); 839 GEM_FreeBuffers(this);
841 SDL_SetError ("Can not create OpenGL context"); 840 SDL_SetError("Can not create OpenGL context");
842 return NULL; 841 return NULL;
843 } 842 }
844 843
845 modeflags |= SDL_INTERNALOPENGL; 844 modeflags |= SDL_INTERNALOPENGL;
846 } 845 }
847 #endif 846 #endif
848 847
849 current->flags = modeflags; 848 current->flags = modeflags;
850 849
851 #ifdef DEBUG_VIDEO_GEM 850 #ifdef DEBUG_VIDEO_GEM
852 printf ("sdl:video:gem: surface: %dx%d\n", current->w, current->h); 851 printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
853 #endif 852 #endif
854 853
855 this->UpdateRects = GEM_UpdateRects; 854 this->UpdateRects = GEM_UpdateRects;
856 GEM_lock_redraw = SDL_FALSE; /* Enable redraw */ 855 GEM_lock_redraw = SDL_FALSE; /* Enable redraw */
857 856
858 /* We're done */ 857 /* We're done */
859 return (current); 858 return (current);
860 } 859 }
861 860
862 static int 861 static int
863 GEM_AllocHWSurface (_THIS, SDL_Surface * surface) 862 GEM_AllocHWSurface(_THIS, SDL_Surface * surface)
864 { 863 {
865 return -1; 864 return -1;
866 } 865 }
867 866
868 static void 867 static void
869 GEM_FreeHWSurface (_THIS, SDL_Surface * surface) 868 GEM_FreeHWSurface(_THIS, SDL_Surface * surface)
870 { 869 {
871 return; 870 return;
872 } 871 }
873 872
874 static int 873 static int
875 GEM_LockHWSurface (_THIS, SDL_Surface * surface) 874 GEM_LockHWSurface(_THIS, SDL_Surface * surface)
876 { 875 {
877 return (0); 876 return (0);
878 } 877 }
879 878
880 static void 879 static void
881 GEM_UnlockHWSurface (_THIS, SDL_Surface * surface) 880 GEM_UnlockHWSurface(_THIS, SDL_Surface * surface)
882 { 881 {
883 return; 882 return;
884 } 883 }
885 884
886 static void 885 static void
887 GEM_UpdateRectsFullscreen (_THIS, int numrects, SDL_Rect * rects) 886 GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect * rects)
888 { 887 {
889 SDL_Surface *surface; 888 SDL_Surface *surface;
890 int i, surf_width; 889 int i, surf_width;
891 890
892 surface = this->screen; 891 surface = this->screen;
924 923
925 destination = destscr; 924 destination = destscr;
926 destination += destpitch * rects[i].y; 925 destination += destpitch * rects[i].y;
927 destination += x1; 926 destination += x1;
928 927
929 SDL_Atari_C2pConvert (source, destination, 928 SDL_Atari_C2pConvert(source, destination,
930 x2 - x1, rects[i].h, 929 x2 - x1, rects[i].h,
931 SDL_FALSE, surface->pitch, destpitch); 930 SDL_FALSE, surface->pitch, destpitch);
932 } 931 }
933 } 932 }
934 933
935 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) { 934 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
936 MFDB mfdb_src; 935 MFDB mfdb_src;
951 blitcoords[0] = blitcoords[4] = rects[i].x; 950 blitcoords[0] = blitcoords[4] = rects[i].x;
952 blitcoords[1] = blitcoords[5] = rects[i].y; 951 blitcoords[1] = blitcoords[5] = rects[i].y;
953 blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1; 952 blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1;
954 blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1; 953 blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1;
955 954
956 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src, 955 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src,
957 &VDI_dst_mfdb); 956 &VDI_dst_mfdb);
958 } 957 }
959 } 958 }
960 } 959 }
961 960
962 static void 961 static void
963 GEM_UpdateRectsWindowed (_THIS, int numrects, SDL_Rect * rects) 962 GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect * rects)
964 { 963 {
965 short pxy[4], wind_pxy[4]; 964 short pxy[4], wind_pxy[4];
966 int i; 965 int i;
967 966
968 if (wind_get 967 if (wind_get
975 pxy[0] = wind_pxy[0] + rects[i].x; 974 pxy[0] = wind_pxy[0] + rects[i].x;
976 pxy[1] = wind_pxy[1] + rects[i].y; 975 pxy[1] = wind_pxy[1] + rects[i].y;
977 pxy[2] = rects[i].w; 976 pxy[2] = rects[i].w;
978 pxy[3] = rects[i].h; 977 pxy[3] = rects[i].h;
979 978
980 GEM_wind_redraw (this, GEM_handle, pxy); 979 GEM_wind_redraw(this, GEM_handle, pxy);
981 } 980 }
982 } 981 }
983 982
984 static void 983 static void
985 GEM_UpdateRects (_THIS, int numrects, SDL_Rect * rects) 984 GEM_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
986 { 985 {
987 SDL_Surface *surface; 986 SDL_Surface *surface;
988 987
989 if (GEM_lock_redraw) { 988 if (GEM_lock_redraw) {
990 return; 989 return;
991 } 990 }
992 991
993 surface = this->screen; 992 surface = this->screen;
994 993
995 if (surface->flags & SDL_FULLSCREEN) { 994 if (surface->flags & SDL_FULLSCREEN) {
996 GEM_UpdateRectsFullscreen (this, numrects, rects); 995 GEM_UpdateRectsFullscreen(this, numrects, rects);
997 } else { 996 } else {
998 GEM_UpdateRectsWindowed (this, numrects, rects); 997 GEM_UpdateRectsWindowed(this, numrects, rects);
999 } 998 }
1000 } 999 }
1001 1000
1002 static int 1001 static int
1003 GEM_FlipHWSurfaceFullscreen (_THIS, SDL_Surface * surface) 1002 GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface * surface)
1004 { 1003 {
1005 int surf_width; 1004 int surf_width;
1006 1005
1007 /* Need to be a multiple of 16 pixels */ 1006 /* Need to be a multiple of 16 pixels */
1008 surf_width = surface->w; 1007 surf_width = surface->w;
1020 } else { 1019 } else {
1021 destscr = GEM_buffer2; 1020 destscr = GEM_buffer2;
1022 destpitch = surface->pitch; 1021 destpitch = surface->pitch;
1023 } 1022 }
1024 1023
1025 SDL_Atari_C2pConvert (surface->pixels, destscr, 1024 SDL_Atari_C2pConvert(surface->pixels, destscr,
1026 surf_width, surface->h, 1025 surf_width, surface->h,
1027 SDL_FALSE, surface->pitch, destpitch); 1026 SDL_FALSE, surface->pitch, destpitch);
1028 } 1027 }
1029 1028
1030 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) { 1029 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
1031 MFDB mfdb_src; 1030 MFDB mfdb_src;
1032 short blitcoords[8]; 1031 short blitcoords[8];
1046 blitcoords[0] = blitcoords[4] = 0; 1045 blitcoords[0] = blitcoords[4] = 0;
1047 blitcoords[1] = blitcoords[5] = 0; 1046 blitcoords[1] = blitcoords[5] = 0;
1048 blitcoords[2] = blitcoords[6] = surface->w - 1; 1047 blitcoords[2] = blitcoords[6] = surface->w - 1;
1049 blitcoords[3] = blitcoords[7] = surface->h - 1; 1048 blitcoords[3] = blitcoords[7] = surface->h - 1;
1050 1049
1051 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb); 1050 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
1052 } 1051 }
1053 1052
1054 return (0); 1053 return (0);
1055 } 1054 }
1056 1055
1057 static int 1056 static int
1058 GEM_FlipHWSurfaceWindowed (_THIS, SDL_Surface * surface) 1057 GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface * surface)
1059 { 1058 {
1060 short pxy[8]; 1059 short pxy[8];
1061 1060
1062 /* Update the whole window */ 1061 /* Update the whole window */
1063 wind_get (GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]); 1062 wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
1064 1063
1065 GEM_wind_redraw (this, GEM_handle, pxy); 1064 GEM_wind_redraw(this, GEM_handle, pxy);
1066 1065
1067 return (0); 1066 return (0);
1068 } 1067 }
1069 1068
1070 static int 1069 static int
1071 GEM_FlipHWSurface (_THIS, SDL_Surface * surface) 1070 GEM_FlipHWSurface(_THIS, SDL_Surface * surface)
1072 { 1071 {
1073 if (GEM_lock_redraw) { 1072 if (GEM_lock_redraw) {
1074 return (0); 1073 return (0);
1075 } 1074 }
1076 1075
1077 if (surface->flags & SDL_FULLSCREEN) { 1076 if (surface->flags & SDL_FULLSCREEN) {
1078 return GEM_FlipHWSurfaceFullscreen (this, surface); 1077 return GEM_FlipHWSurfaceFullscreen(this, surface);
1079 } else { 1078 } else {
1080 return GEM_FlipHWSurfaceWindowed (this, surface); 1079 return GEM_FlipHWSurfaceWindowed(this, surface);
1081 } 1080 }
1082 } 1081 }
1083 1082
1084 static int 1083 static int
1085 GEM_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors) 1084 GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1086 { 1085 {
1087 int i; 1086 int i;
1088 SDL_Surface *surface; 1087 SDL_Surface *surface;
1089 1088
1090 #ifdef DEBUG_VIDEO_GEM 1089 #ifdef DEBUG_VIDEO_GEM
1091 printf ("sdl:video:gem: setcolors()\n"); 1090 printf("sdl:video:gem: setcolors()\n");
1092 #endif 1091 #endif
1093 1092
1094 /* Do not change palette in True Colour */ 1093 /* Do not change palette in True Colour */
1095 surface = this->screen; 1094 surface = this->screen;
1096 if (surface->format->BitsPerPixel > 8) { 1095 if (surface->format->BitsPerPixel > 8) {
1107 1106
1108 rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255; 1107 rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
1109 rgb[1] = VDI_curpalette[i][1] = (1000 * g) / 255; 1108 rgb[1] = VDI_curpalette[i][1] = (1000 * g) / 255;
1110 rgb[2] = VDI_curpalette[i][2] = (1000 * b) / 255; 1109 rgb[2] = VDI_curpalette[i][2] = (1000 * b) / 255;
1111 1110
1112 vs_color (VDI_handle, vdi_index[firstcolor + i], rgb); 1111 vs_color(VDI_handle, vdi_index[firstcolor + i], rgb);
1113 } 1112 }
1114 1113
1115 return (1); 1114 return (1);
1116 } 1115 }
1117 1116
1118 #if 0 1117 #if 0
1119 static int 1118 static int
1120 GEM_ToggleFullScreen (_THIS, int on) 1119 GEM_ToggleFullScreen(_THIS, int on)
1121 { 1120 {
1122 if (on) { 1121 if (on) {
1123 GEM_LockScreen (this); 1122 GEM_LockScreen(this);
1124 } else { 1123 } else {
1125 GEM_UnlockScreen (this); 1124 GEM_UnlockScreen(this);
1126 } 1125 }
1127 1126
1128 return (1); 1127 return (1);
1129 } 1128 }
1130 #endif 1129 #endif
1131 1130
1132 /* Note: If we are terminated, this could be called in the middle of 1131 /* Note: If we are terminated, this could be called in the middle of
1133 another SDL video routine -- notably UpdateRects. 1132 another SDL video routine -- notably UpdateRects.
1134 */ 1133 */
1135 void 1134 void
1136 GEM_VideoQuit (_THIS) 1135 GEM_VideoQuit(_THIS)
1137 { 1136 {
1138 SDL_AtariXbios_RestoreVectors (); 1137 SDL_AtariXbios_RestoreVectors();
1139 if (GEM_usedevmouse) { 1138 if (GEM_usedevmouse) {
1140 SDL_AtariDevMouse_Close (); 1139 SDL_AtariDevMouse_Close();
1141 } 1140 }
1142 1141
1143 GEM_FreeBuffers (this); 1142 GEM_FreeBuffers(this);
1144 1143
1145 #if SDL_VIDEO_OPENGL 1144 #if SDL_VIDEO_OPENGL
1146 if (gl_active) { 1145 if (gl_active) {
1147 SDL_AtariGL_Quit (this, SDL_TRUE); 1146 SDL_AtariGL_Quit(this, SDL_TRUE);
1148 } 1147 }
1149 #endif 1148 #endif
1150 1149
1151 /* Destroy window */ 1150 /* Destroy window */
1152 if (GEM_handle >= 0) { 1151 if (GEM_handle >= 0) {
1153 wind_close (GEM_handle); 1152 wind_close(GEM_handle);
1154 wind_delete (GEM_handle); 1153 wind_delete(GEM_handle);
1155 GEM_handle = -1; 1154 GEM_handle = -1;
1156 } 1155 }
1157 1156
1158 GEM_UnlockScreen (this); 1157 GEM_UnlockScreen(this);
1159 if (GEM_menubar) { 1158 if (GEM_menubar) {
1160 Mfree (GEM_menubar); 1159 Mfree(GEM_menubar);
1161 GEM_menubar = NULL; 1160 GEM_menubar = NULL;
1162 } 1161 }
1163 1162
1164 appl_exit (); 1163 appl_exit();
1165 1164
1166 GEM_SetNewPalette (this, VDI_oldpalette); 1165 GEM_SetNewPalette(this, VDI_oldpalette);
1167 1166
1168 /* Close VDI workstation */ 1167 /* Close VDI workstation */
1169 if (VDI_handle) { 1168 if (VDI_handle) {
1170 v_clsvwk (VDI_handle); 1169 v_clsvwk(VDI_handle);
1171 } 1170 }
1172 1171
1173 /* Free mode list */ 1172 /* Free mode list */
1174 if (SDL_modelist[0]) { 1173 if (SDL_modelist[0]) {
1175 SDL_free (SDL_modelist[0]); 1174 SDL_free(SDL_modelist[0]);
1176 SDL_modelist[0] = NULL; 1175 SDL_modelist[0] = NULL;
1177 } 1176 }
1178 1177
1179 this->screen->pixels = NULL; 1178 this->screen->pixels = NULL;
1180 } 1179 }
1181 1180
1182 void 1181 void
1183 GEM_wind_redraw (_THIS, int winhandle, short *inside) 1182 GEM_wind_redraw(_THIS, int winhandle, short *inside)
1184 { 1183 {
1185 short todo[4]; 1184 short todo[4];
1186 1185
1187 /* Tell AES we are going to update */ 1186 /* Tell AES we are going to update */
1188 wind_update (BEG_UPDATE); 1187 wind_update(BEG_UPDATE);
1189 1188
1190 v_hide_c (VDI_handle); 1189 v_hide_c(VDI_handle);
1191 1190
1192 /* Browse the rectangle list to redraw */ 1191 /* Browse the rectangle list to redraw */
1193 if (wind_get 1192 if (wind_get
1194 (winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], 1193 (winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2],
1195 &todo[3]) != 0) { 1194 &todo[3]) != 0) {
1196 1195
1197 while (todo[2] && todo[3]) { 1196 while (todo[2] && todo[3]) {
1198 1197
1199 if (rc_intersect ((GRECT *) inside, (GRECT *) todo)) { 1198 if (rc_intersect((GRECT *) inside, (GRECT *) todo)) {
1200 todo[2] += todo[0] - 1; 1199 todo[2] += todo[0] - 1;
1201 todo[3] += todo[1] - 1; 1200 todo[3] += todo[1] - 1;
1202 refresh_window (this, winhandle, todo); 1201 refresh_window(this, winhandle, todo);
1203 } 1202 }
1204 1203
1205 if (wind_get 1204 if (wind_get
1206 (winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], 1205 (winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2],
1207 &todo[3]) == 0) { 1206 &todo[3]) == 0) {
1210 } 1209 }
1211 1210
1212 } 1211 }
1213 1212
1214 /* Update finished */ 1213 /* Update finished */
1215 wind_update (END_UPDATE); 1214 wind_update(END_UPDATE);
1216 1215
1217 v_show_c (VDI_handle, 1); 1216 v_show_c(VDI_handle, 1);
1218 } 1217 }
1219 1218
1220 static void 1219 static void
1221 refresh_window (_THIS, int winhandle, short *rect) 1220 refresh_window(_THIS, int winhandle, short *rect)
1222 { 1221 {
1223 MFDB mfdb_src; 1222 MFDB mfdb_src;
1224 short pxy[8], wind_pxy[8]; 1223 short pxy[8], wind_pxy[8];
1225 SDL_Surface *surface; 1224 SDL_Surface *surface;
1226 int iconified; 1225 int iconified;
1246 short icon_rect[4], dst_rect[4]; 1245 short icon_rect[4], dst_rect[4];
1247 short iconx, icony; 1246 short iconx, icony;
1248 1247
1249 surface = GEM_icon; 1248 surface = GEM_icon;
1250 1249
1251 GEM_ClearRect (this, rect); 1250 GEM_ClearRect(this, rect);
1252 1251
1253 /* Calculate centered icon(x,y,w,h) relative to window */ 1252 /* Calculate centered icon(x,y,w,h) relative to window */
1254 iconx = (wind_pxy[2] - surface->w) >> 1; 1253 iconx = (wind_pxy[2] - surface->w) >> 1;
1255 icony = (wind_pxy[3] - surface->h) >> 1; 1254 icony = (wind_pxy[3] - surface->h) >> 1;
1256 1255
1264 dst_rect[1] = rect[1] - wind_pxy[1]; 1263 dst_rect[1] = rect[1] - wind_pxy[1];
1265 dst_rect[2] = rect[2] - rect[0] + 1; 1264 dst_rect[2] = rect[2] - rect[0] + 1;
1266 dst_rect[3] = rect[3] - rect[1] + 1; 1265 dst_rect[3] = rect[3] - rect[1] + 1;
1267 1266
1268 /* Does the icon rectangle must be redrawn ? */ 1267 /* Does the icon rectangle must be redrawn ? */
1269 if (!rc_intersect ((GRECT *) icon_rect, (GRECT *) dst_rect)) { 1268 if (!rc_intersect((GRECT *) icon_rect, (GRECT *) dst_rect)) {
1270 return; 1269 return;
1271 } 1270 }
1272 #if DEBUG_VIDEO_GEM 1271 #if DEBUG_VIDEO_GEM
1273 printf ("sdl:video:gem: clip(0,0,%d,%d) to (%d,%d,%d,%d)\n", 1272 printf("sdl:video:gem: clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
1274 surface->w - 1, surface->h - 1, dst_rect[0], dst_rect[1], 1273 surface->w - 1, surface->h - 1, dst_rect[0], dst_rect[1],
1275 dst_rect[2], dst_rect[3]); 1274 dst_rect[2], dst_rect[3]);
1276 printf ("sdl:video:gem: icon(%d,%d,%d,%d)\n", icon_rect[0], 1275 printf("sdl:video:gem: icon(%d,%d,%d,%d)\n", icon_rect[0],
1277 icon_rect[1], icon_rect[2], icon_rect[3]); 1276 icon_rect[1], icon_rect[2], icon_rect[3]);
1278 printf ("sdl:video:gem: refresh_window(): draw icon\n"); 1277 printf("sdl:video:gem: refresh_window(): draw icon\n");
1279 #endif 1278 #endif
1280 1279
1281 /* Calculate icon(x1,y1,x2,y2) relative to screen */ 1280 /* Calculate icon(x1,y1,x2,y2) relative to screen */
1282 icon_rect[0] += wind_pxy[0]; 1281 icon_rect[0] += wind_pxy[0];
1283 icon_rect[1] += wind_pxy[1]; 1282 icon_rect[1] += wind_pxy[1];
1284 icon_rect[2] += icon_rect[0] - 1; 1283 icon_rect[2] += icon_rect[0] - 1;
1285 icon_rect[3] += icon_rect[1] - 1; 1284 icon_rect[3] += icon_rect[1] - 1;
1286 1285
1287 /* Calculate intersection rectangle to redraw */ 1286 /* Calculate intersection rectangle to redraw */
1288 pxy[4] = pxy[0] = MAX (icon_rect[0], rect[0]); 1287 pxy[4] = pxy[0] = MAX(icon_rect[0], rect[0]);
1289 pxy[5] = pxy[1] = MAX (icon_rect[1], rect[1]); 1288 pxy[5] = pxy[1] = MAX(icon_rect[1], rect[1]);
1290 pxy[6] = pxy[2] = MIN (icon_rect[2], rect[2]); 1289 pxy[6] = pxy[2] = MIN(icon_rect[2], rect[2]);
1291 pxy[7] = pxy[3] = MIN (icon_rect[3], rect[3]); 1290 pxy[7] = pxy[3] = MIN(icon_rect[3], rect[3]);
1292 1291
1293 /* Calculate icon source image pos relative to window */ 1292 /* Calculate icon source image pos relative to window */
1294 pxy[0] -= wind_pxy[0] + iconx; 1293 pxy[0] -= wind_pxy[0] + iconx;
1295 pxy[1] -= wind_pxy[1] + icony; 1294 pxy[1] -= wind_pxy[1] + icony;
1296 pxy[2] -= wind_pxy[0] + iconx; 1295 pxy[2] -= wind_pxy[0] + iconx;
1298 1297
1299 } else { 1298 } else {
1300 surface = this->screen; 1299 surface = this->screen;
1301 1300
1302 #if DEBUG_VIDEO_GEM 1301 #if DEBUG_VIDEO_GEM
1303 printf ("sdl:video:gem: refresh_window(): draw frame buffer\n"); 1302 printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
1304 #endif 1303 #endif
1305 1304
1306 /* Redraw all window content */ 1305 /* Redraw all window content */
1307 pxy[0] = rect[0] - wind_pxy[0]; 1306 pxy[0] = rect[0] - wind_pxy[0];
1308 pxy[1] = rect[1] - wind_pxy[1]; 1307 pxy[1] = rect[1] - wind_pxy[1];
1331 1330
1332 dest = GEM_buffer2; 1331 dest = GEM_buffer2;
1333 dest += surface->pitch * (rect[1] - wind_pxy[1]); 1332 dest += surface->pitch * (rect[1] - wind_pxy[1]);
1334 dest += x1; 1333 dest += x1;
1335 1334
1336 SDL_Atari_C2pConvert (src, dest, 1335 SDL_Atari_C2pConvert(src, dest,
1337 x2 - x1, rect[3] - rect[1] + 1, 1336 x2 - x1, rect[3] - rect[1] + 1,
1338 SDL_FALSE, surface->pitch, surface->pitch); 1337 SDL_FALSE, surface->pitch, surface->pitch);
1339 } 1338 }
1340 1339
1341 mfdb_src.fd_addr = surface->pixels; 1340 mfdb_src.fd_addr = surface->pixels;
1342 { 1341 {
1343 int width; 1342 int width;
1356 1355
1357 if (GEM_bufops & B2S_VROCPYFM_2TOS) { 1356 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
1358 mfdb_src.fd_addr = GEM_buffer2; 1357 mfdb_src.fd_addr = GEM_buffer2;
1359 } 1358 }
1360 #if DEBUG_VIDEO_GEM 1359 #if DEBUG_VIDEO_GEM
1361 printf ("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n", 1360 printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
1362 surface->w, surface->h, 1361 surface->w, surface->h,
1363 pxy[0], pxy[1], pxy[2], pxy[3], pxy[4], pxy[5], pxy[6], pxy[7]); 1362 pxy[0], pxy[1], pxy[2], pxy[3], pxy[4], pxy[5], pxy[6], pxy[7]);
1364 #endif 1363 #endif
1365 1364
1366 vro_cpyfm (VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb); 1365 vro_cpyfm(VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
1367 } 1366 }
1368 1367
1369 #if SDL_VIDEO_OPENGL 1368 #if SDL_VIDEO_OPENGL
1370 1369
1371 static void 1370 static void
1372 GEM_GL_SwapBuffers (_THIS) 1371 GEM_GL_SwapBuffers(_THIS)
1373 { 1372 {
1374 SDL_AtariGL_SwapBuffers (this); 1373 SDL_AtariGL_SwapBuffers(this);
1375 GEM_FlipHWSurface (this, this->screen); 1374 GEM_FlipHWSurface(this, this->screen);
1376 } 1375 }
1377 1376
1378 #endif 1377 #endif
1379 /* vi: set ts=4 sw=4 expandtab: */ 1378 /* vi: set ts=4 sw=4 expandtab: */