comparison src/video/gem/SDL_gemvideo.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
67 #define MAX(a,b) (((a)>(b)) ? (a) : (b)) 67 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
68 68
69 /* Variables */ 69 /* Variables */
70 70
71 static unsigned char vdi_index[256] = { 71 static unsigned char vdi_index[256] = {
72 0, 2, 3, 6, 4, 7, 5, 8, 72 0, 2, 3, 6, 4, 7, 5, 8,
73 9, 10, 11, 14, 12, 15, 13, 255 73 9, 10, 11, 14, 12, 15, 13, 255
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, Uint32 flags); 80 static SDL_Rect **GEM_ListModes (_THIS, SDL_PixelFormat * format,
81 static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 81 Uint32 flags);
82 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 82 static SDL_Surface *GEM_SetVideoMode (_THIS, SDL_Surface * current, int width,
83 static void GEM_VideoQuit(_THIS); 83 int height, int bpp, Uint32 flags);
84 static int GEM_SetColors (_THIS, int firstcolor, int ncolors,
85 SDL_Color * colors);
86 static void GEM_VideoQuit (_THIS);
84 87
85 /* Hardware surface functions */ 88 /* Hardware surface functions */
86 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface); 89 static int GEM_AllocHWSurface (_THIS, SDL_Surface * surface);
87 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface); 90 static int GEM_LockHWSurface (_THIS, SDL_Surface * surface);
88 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface); 91 static int GEM_FlipHWSurface (_THIS, SDL_Surface * surface);
89 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface); 92 static void GEM_UnlockHWSurface (_THIS, SDL_Surface * surface);
90 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface); 93 static void GEM_FreeHWSurface (_THIS, SDL_Surface * surface);
91 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 94 static void GEM_UpdateRects (_THIS, int numrects, SDL_Rect * rects);
92 #if 0 95 #if 0
93 static int GEM_ToggleFullScreen(_THIS, int on); 96 static int GEM_ToggleFullScreen (_THIS, int on);
94 #endif 97 #endif
95 98
96 /* Internal functions */ 99 /* Internal functions */
97 static void GEM_FreeBuffers(_THIS); 100 static void GEM_FreeBuffers (_THIS);
98 static void GEM_ClearScreen(_THIS); 101 static void GEM_ClearScreen (_THIS);
99 static void GEM_ClearRect(_THIS, short *rect); 102 static void GEM_ClearRect (_THIS, short *rect);
100 static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]); 103 static void GEM_SetNewPalette (_THIS, Uint16 newpal[256][3]);
101 static void GEM_LockScreen(_THIS); 104 static void GEM_LockScreen (_THIS);
102 static void GEM_UnlockScreen(_THIS); 105 static void GEM_UnlockScreen (_THIS);
103 static void refresh_window(_THIS, int winhandle, short *rect); 106 static void refresh_window (_THIS, int winhandle, short *rect);
104 107
105 #if SDL_VIDEO_OPENGL 108 #if SDL_VIDEO_OPENGL
106 /* OpenGL functions */ 109 /* OpenGL functions */
107 static void GEM_GL_SwapBuffers(_THIS); 110 static void GEM_GL_SwapBuffers (_THIS);
108 #endif 111 #endif
109 112
110 /* GEM driver bootstrap functions */ 113 /* GEM driver bootstrap functions */
111 114
112 static int GEM_Available(void) 115 static int
113 { 116 GEM_Available (void)
114 /* Test if AES available */ 117 {
115 if (appl_init() == -1) 118 /* Test if AES available */
116 return 0; 119 if (appl_init () == -1)
117 120 return 0;
118 appl_exit(); 121
119 return 1; 122 appl_exit ();
120 } 123 return 1;
121 124 }
122 static void GEM_DeleteDevice(SDL_VideoDevice *device) 125
123 { 126 static void
124 SDL_free(device->hidden); 127 GEM_DeleteDevice (SDL_VideoDevice * device)
125 SDL_free(device); 128 {
126 } 129 SDL_free (device->hidden);
127 130 SDL_free (device);
128 static SDL_VideoDevice *GEM_CreateDevice(int devindex) 131 }
129 { 132
130 SDL_VideoDevice *device; 133 static SDL_VideoDevice *
131 int vectors_mask; 134 GEM_CreateDevice (int devindex)
132 unsigned long dummy; 135 {
133 136 SDL_VideoDevice *device;
134 /* Initialize all variables that we clean on shutdown */ 137 int vectors_mask;
135 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 138 unsigned long dummy;
136 if ( device ) { 139
137 SDL_memset(device, 0, (sizeof *device)); 140 /* Initialize all variables that we clean on shutdown */
138 device->hidden = (struct SDL_PrivateVideoData *) 141 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
139 SDL_malloc((sizeof *device->hidden)); 142 if (device) {
140 device->gl_data = (struct SDL_PrivateGLData *) 143 SDL_memset (device, 0, (sizeof *device));
141 SDL_malloc((sizeof *device->gl_data)); 144 device->hidden = (struct SDL_PrivateVideoData *)
142 } 145 SDL_malloc ((sizeof *device->hidden));
143 if ( (device == NULL) || (device->hidden == NULL) ) { 146 device->gl_data = (struct SDL_PrivateGLData *)
144 SDL_OutOfMemory(); 147 SDL_malloc ((sizeof *device->gl_data));
145 if ( device ) { 148 }
146 SDL_free(device); 149 if ((device == NULL) || (device->hidden == NULL)) {
147 } 150 SDL_OutOfMemory ();
148 return(0); 151 if (device) {
149 } 152 SDL_free (device);
150 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 153 }
151 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data)); 154 return (0);
152 155 }
153 /* Set the function pointers */ 156 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
154 device->VideoInit = GEM_VideoInit; 157 SDL_memset (device->gl_data, 0, sizeof (*device->gl_data));
155 device->ListModes = GEM_ListModes; 158
156 device->SetVideoMode = GEM_SetVideoMode; 159 /* Set the function pointers */
157 device->SetColors = GEM_SetColors; 160 device->VideoInit = GEM_VideoInit;
158 device->UpdateRects = NULL /*GEM_UpdateRects*/; 161 device->ListModes = GEM_ListModes;
159 device->VideoQuit = GEM_VideoQuit; 162 device->SetVideoMode = GEM_SetVideoMode;
160 device->AllocHWSurface = GEM_AllocHWSurface; 163 device->SetColors = GEM_SetColors;
161 device->LockHWSurface = GEM_LockHWSurface; 164 device->UpdateRects = NULL /*GEM_UpdateRects */ ;
162 device->UnlockHWSurface = GEM_UnlockHWSurface; 165 device->VideoQuit = GEM_VideoQuit;
163 device->FlipHWSurface = GEM_FlipHWSurface; 166 device->AllocHWSurface = GEM_AllocHWSurface;
164 device->FreeHWSurface = GEM_FreeHWSurface; 167 device->LockHWSurface = GEM_LockHWSurface;
165 device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/; 168 device->UnlockHWSurface = GEM_UnlockHWSurface;
166 169 device->FlipHWSurface = GEM_FlipHWSurface;
167 /* Window manager */ 170 device->FreeHWSurface = GEM_FreeHWSurface;
168 device->SetCaption = GEM_SetCaption; 171 device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen */ ;
169 device->SetIcon = GEM_SetIcon; 172
170 device->IconifyWindow = GEM_IconifyWindow; 173 /* Window manager */
171 device->GrabInput = GEM_GrabInput; 174 device->SetCaption = GEM_SetCaption;
172 175 device->SetIcon = GEM_SetIcon;
173 /* Events */ 176 device->IconifyWindow = GEM_IconifyWindow;
174 device->InitOSKeymap = GEM_InitOSKeymap; 177 device->GrabInput = GEM_GrabInput;
175 device->PumpEvents = GEM_PumpEvents; 178
176 179 /* Events */
177 /* Mouse */ 180 device->InitOSKeymap = GEM_InitOSKeymap;
178 device->FreeWMCursor = GEM_FreeWMCursor; 181 device->PumpEvents = GEM_PumpEvents;
179 device->CreateWMCursor = GEM_CreateWMCursor; 182
180 device->ShowWMCursor = GEM_ShowWMCursor; 183 /* Mouse */
181 device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/; 184 device->FreeWMCursor = GEM_FreeWMCursor;
182 device->CheckMouseMode = GEM_CheckMouseMode; 185 device->CreateWMCursor = GEM_CreateWMCursor;
186 device->ShowWMCursor = GEM_ShowWMCursor;
187 device->WarpWMCursor = NULL /*GEM_WarpWMCursor */ ;
188 device->CheckMouseMode = GEM_CheckMouseMode;
183 189
184 #if SDL_VIDEO_OPENGL 190 #if SDL_VIDEO_OPENGL
185 /* OpenGL functions */ 191 /* OpenGL functions */
186 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary; 192 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
187 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress; 193 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
188 device->GL_GetAttribute = SDL_AtariGL_GetAttribute; 194 device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
189 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent; 195 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
190 device->GL_SwapBuffers = GEM_GL_SwapBuffers; 196 device->GL_SwapBuffers = GEM_GL_SwapBuffers;
191 #endif 197 #endif
192 198
193 device->hidden->use_dev_mouse = 199 device->hidden->use_dev_mouse =
194 (SDL_AtariDevMouse_Open()!=0) ? SDL_TRUE : SDL_FALSE; 200 (SDL_AtariDevMouse_Open () != 0) ? SDL_TRUE : SDL_FALSE;
195 201
196 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */ 202 vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS; /* XBIOS joystick events */
197 if (!(device->hidden->use_dev_mouse)) { 203 if (!(device->hidden->use_dev_mouse)) {
198 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */ 204 vectors_mask |= ATARI_XBIOS_MOUSEEVENTS; /* XBIOS mouse events */
199 } 205 }
200 if (Getcookie(C_MiNT, &dummy)==C_FOUND) { 206 if (Getcookie (C_MiNT, &dummy) == C_FOUND) {
201 vectors_mask = 0; 207 vectors_mask = 0;
202 } 208 }
203 209
204 SDL_AtariXbios_InstallVectors(vectors_mask); 210 SDL_AtariXbios_InstallVectors (vectors_mask);
205 211
206 device->free = GEM_DeleteDevice; 212 device->free = GEM_DeleteDevice;
207 213
208 return device; 214 return device;
209 } 215 }
210 216
211 VideoBootStrap GEM_bootstrap = { 217 VideoBootStrap GEM_bootstrap = {
212 GEM_VID_DRIVER_NAME, "Atari GEM video driver", 218 GEM_VID_DRIVER_NAME, "Atari GEM video driver",
213 GEM_Available, GEM_CreateDevice 219 GEM_Available, GEM_CreateDevice
214 }; 220 };
215 221
216 static void VDI_ReadExtInfo(_THIS, short *work_out) 222 static void
217 { 223 VDI_ReadExtInfo (_THIS, short *work_out)
218 unsigned long EdDI_version; 224 {
219 unsigned long cookie_EdDI; 225 unsigned long EdDI_version;
220 Uint32 num_colours; 226 unsigned long cookie_EdDI;
221 Uint16 clut_type, num_bits; 227 Uint32 num_colours;
222 228 Uint16 clut_type, num_bits;
223 /* Read EdDI informations */ 229
224 if (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) { 230 /* Read EdDI informations */
225 return; 231 if (Getcookie (C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
226 } 232 return;
227 233 }
228 EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI); 234
229 235 EdDI_version = Atari_get_EdDI_version ((void *) cookie_EdDI);
230 vq_scrninfo(VDI_handle, work_out); 236
231 237 vq_scrninfo (VDI_handle, work_out);
232 VDI_format = work_out[0]; 238
233 clut_type = work_out[1]; 239 VDI_format = work_out[0];
234 num_bits = work_out[2]; 240 clut_type = work_out[1];
235 num_colours = *((Uint32 *) &work_out[3]); 241 num_bits = work_out[2];
236 242 num_colours = *((Uint32 *) & work_out[3]);
237 /* With EdDI>=1.1, we can have screen pitch, address and format 243
238 * so we can directly write to screen without using vro_cpyfm 244 /* With EdDI>=1.1, we can have screen pitch, address and format
239 */ 245 * so we can directly write to screen without using vro_cpyfm
240 if (EdDI_version >= EDDI_11) { 246 */
241 VDI_pitch = work_out[5]; 247 if (EdDI_version >= EDDI_11) {
242 VDI_screen = (void *) *((unsigned long *) &work_out[6]); 248 VDI_pitch = work_out[5];
243 } 249 VDI_screen = (void *) *((unsigned long *) &work_out[6]);
244 250 }
245 switch(clut_type) { 251
246 case VDI_CLUT_HARDWARE: 252 switch (clut_type) {
247 { 253 case VDI_CLUT_HARDWARE:
248 int i; 254 {
249 Uint16 *tmp_p; 255 int i;
250 256 Uint16 *tmp_p;
251 tmp_p = (Uint16 *)&work_out[16]; 257
252 258 tmp_p = (Uint16 *) & work_out[16];
253 for (i=0;i<256;i++) { 259
254 vdi_index[*tmp_p++] = i; 260 for (i = 0; i < 256; i++) {
255 } 261 vdi_index[*tmp_p++] = i;
256 } 262 }
257 break; 263 }
258 case VDI_CLUT_SOFTWARE: 264 break;
259 { 265 case VDI_CLUT_SOFTWARE:
260 int component; /* red, green, blue, alpha, overlay */ 266 {
261 int num_bit; 267 int component; /* red, green, blue, alpha, overlay */
262 unsigned short *tmp_p; 268 int num_bit;
263 269 unsigned short *tmp_p;
264 /* We can build masks with info here */ 270
265 tmp_p = (unsigned short *) &work_out[16]; 271 /* We can build masks with info here */
266 for (component=0;component<5;component++) { 272 tmp_p = (unsigned short *) &work_out[16];
267 for (num_bit=0;num_bit<16;num_bit++) { 273 for (component = 0; component < 5; component++) {
268 unsigned short valeur; 274 for (num_bit = 0; num_bit < 16; num_bit++) {
269 275 unsigned short valeur;
270 valeur = *tmp_p++; 276
271 277 valeur = *tmp_p++;
272 if (valeur == 0xffff) { 278
273 continue; 279 if (valeur == 0xffff) {
274 } 280 continue;
275 281 }
276 switch(component) { 282
277 case 0: 283 switch (component) {
278 VDI_redmask |= 1<< valeur; 284 case 0:
279 break; 285 VDI_redmask |= 1 << valeur;
280 case 1: 286 break;
281 VDI_greenmask |= 1<< valeur; 287 case 1:
282 break; 288 VDI_greenmask |= 1 << valeur;
283 case 2: 289 break;
284 VDI_bluemask |= 1<< valeur; 290 case 2:
285 break; 291 VDI_bluemask |= 1 << valeur;
286 case 3: 292 break;
287 VDI_alphamask |= 1<< valeur; 293 case 3:
288 break; 294 VDI_alphamask |= 1 << valeur;
289 } 295 break;
290 } 296 }
291 } 297 }
292 } 298 }
293 299 }
294 /* Remove lower green bits for Intel endian screen */ 300
295 if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) { 301 /* Remove lower green bits for Intel endian screen */
296 VDI_greenmask &= ~(7<<13); 302 if ((VDI_greenmask == ((7 << 13) | 3))
297 } 303 || (VDI_greenmask == ((7 << 13) | 7))) {
298 break; 304 VDI_greenmask &= ~(7 << 13);
299 case VDI_CLUT_NONE: 305 }
300 break; 306 break;
301 } 307 case VDI_CLUT_NONE:
302 } 308 break;
303 309 }
304 int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat) 310 }
305 { 311
306 int i, menubar_size; 312 int
307 short work_in[12], work_out[272], dummy; 313 GEM_VideoInit (_THIS, SDL_PixelFormat * vformat)
308 314 {
309 /* Open AES (Application Environment Services) */ 315 int i, menubar_size;
310 if (appl_init() == -1) { 316 short work_in[12], work_out[272], dummy;
311 fprintf(stderr,"Can not open AES\n"); 317
312 return 1; 318 /* Open AES (Application Environment Services) */
313 } 319 if (appl_init () == -1) {
314 320 fprintf (stderr, "Can not open AES\n");
315 /* Read version and features */ 321 return 1;
316 GEM_version = aes_global[0]; 322 }
317 if (GEM_version >= 0x0410) { 323
318 short ap_gout[4], errorcode; 324 /* Read version and features */
319 325 GEM_version = aes_global[0];
320 GEM_wfeatures=0; 326 if (GEM_version >= 0x0410) {
321 errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]); 327 short ap_gout[4], errorcode;
322 328
323 if (errorcode==0) { 329 GEM_wfeatures = 0;
324 GEM_wfeatures=ap_gout[0]; 330 errorcode =
325 } 331 appl_getinfo (AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2],
326 } 332 &ap_gout[3]);
327 333
328 /* Ask VDI physical workstation handle opened by AES */ 334 if (errorcode == 0) {
329 VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy); 335 GEM_wfeatures = ap_gout[0];
330 if (VDI_handle<1) { 336 }
331 fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle); 337 }
332 return 1; 338
333 } 339 /* Ask VDI physical workstation handle opened by AES */
334 340 VDI_handle = graf_handle (&dummy, &dummy, &dummy, &dummy);
335 /* Open virtual VDI workstation */ 341 if (VDI_handle < 1) {
336 work_in[0]=Getrez()+2; 342 fprintf (stderr, "Wrong VDI handle %d returned by AES\n", VDI_handle);
337 for(i = 1; i < 10; i++) 343 return 1;
338 work_in[i] = 1; 344 }
339 work_in[10] = 2; 345
340 346 /* Open virtual VDI workstation */
341 v_opnvwk(work_in, &VDI_handle, work_out); 347 work_in[0] = Getrez () + 2;
342 if (VDI_handle == 0) { 348 for (i = 1; i < 10; i++)
343 fprintf(stderr,"Can not open VDI virtual workstation\n"); 349 work_in[i] = 1;
344 return 1; 350 work_in[10] = 2;
345 } 351
346 352 v_opnvwk (work_in, &VDI_handle, work_out);
347 /* Read fullscreen size */ 353 if (VDI_handle == 0) {
348 VDI_w = work_out[0] + 1; 354 fprintf (stderr, "Can not open VDI virtual workstation\n");
349 VDI_h = work_out[1] + 1; 355 return 1;
350 356 }
351 /* Read desktop size and position */ 357
352 if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) { 358 /* Read fullscreen size */
353 fprintf(stderr,"Can not read desktop properties\n"); 359 VDI_w = work_out[0] + 1;
354 return 1; 360 VDI_h = work_out[1] + 1;
355 } 361
356 362 /* Read desktop size and position */
357 /* Read bit depth */ 363 if (!wind_get
358 vq_extnd(VDI_handle, 1, work_out); 364 (DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w,
359 VDI_bpp = work_out[4]; 365 &GEM_desk_h)) {
360 VDI_oldnumcolors=0; 366 fprintf (stderr, "Can not read desktop properties\n");
361 367 return 1;
362 switch(VDI_bpp) { 368 }
363 case 8: 369
364 VDI_pixelsize=1; 370 /* Read bit depth */
365 break; 371 vq_extnd (VDI_handle, 1, work_out);
366 case 15: 372 VDI_bpp = work_out[4];
367 case 16: 373 VDI_oldnumcolors = 0;
368 VDI_pixelsize=2; 374
369 break; 375 switch (VDI_bpp) {
370 case 24: 376 case 8:
371 VDI_pixelsize=3; 377 VDI_pixelsize = 1;
372 break; 378 break;
373 case 32: 379 case 15:
374 VDI_pixelsize=4; 380 case 16:
375 break; 381 VDI_pixelsize = 2;
376 default: 382 break;
377 fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp); 383 case 24:
378 return 1; 384 VDI_pixelsize = 3;
379 } 385 break;
380 386 case 32:
381 /* Setup hardware -> VDI palette mapping */ 387 VDI_pixelsize = 4;
382 for(i = 16; i < 255; i++) { 388 break;
383 vdi_index[i] = i; 389 default:
384 } 390 fprintf (stderr, "%d bits colour depth not supported\n", VDI_bpp);
385 vdi_index[255] = 1; 391 return 1;
386 392 }
387 /* Save current palette */ 393
388 if (VDI_bpp>8) { 394 /* Setup hardware -> VDI palette mapping */
389 VDI_oldnumcolors=1<<8; 395 for (i = 16; i < 255; i++) {
390 } else { 396 vdi_index[i] = i;
391 VDI_oldnumcolors=1<<VDI_bpp; 397 }
392 } 398 vdi_index[255] = 1;
393 399
394 for(i = 0; i < VDI_oldnumcolors; i++) { 400 /* Save current palette */
395 short rgb[3]; 401 if (VDI_bpp > 8) {
396 402 VDI_oldnumcolors = 1 << 8;
397 vq_color(VDI_handle, i, 0, rgb); 403 } else {
398 404 VDI_oldnumcolors = 1 << VDI_bpp;
399 VDI_oldpalette[i][0] = rgb[0]; 405 }
400 VDI_oldpalette[i][1] = rgb[1]; 406
401 VDI_oldpalette[i][2] = rgb[2]; 407 for (i = 0; i < VDI_oldnumcolors; i++) {
402 } 408 short rgb[3];
403 VDI_setpalette = GEM_SetNewPalette; 409
404 SDL_memcpy(VDI_curpalette,VDI_oldpalette,sizeof(VDI_curpalette)); 410 vq_color (VDI_handle, i, 0, rgb);
405 411
406 /* Setup screen info */ 412 VDI_oldpalette[i][0] = rgb[0];
407 GEM_title_name = empty_name; 413 VDI_oldpalette[i][1] = rgb[1];
408 GEM_icon_name = empty_name; 414 VDI_oldpalette[i][2] = rgb[2];
409 415 }
410 GEM_handle = -1; 416 VDI_setpalette = GEM_SetNewPalette;
411 GEM_locked = SDL_FALSE; 417 SDL_memcpy (VDI_curpalette, VDI_oldpalette, sizeof (VDI_curpalette));
412 GEM_win_fulled = SDL_FALSE; 418
413 GEM_fullscreen = SDL_FALSE; 419 /* Setup screen info */
414 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */ 420 GEM_title_name = empty_name;
415 421 GEM_icon_name = empty_name;
416 VDI_screen = NULL; 422
417 VDI_pitch = VDI_w * VDI_pixelsize; 423 GEM_handle = -1;
418 VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK); 424 GEM_locked = SDL_FALSE;
419 VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0; 425 GEM_win_fulled = SDL_FALSE;
420 VDI_ReadExtInfo(this, work_out); 426 GEM_fullscreen = SDL_FALSE;
427 GEM_lock_redraw = SDL_TRUE; /* Prevent redraw till buffers are setup */
428
429 VDI_screen = NULL;
430 VDI_pitch = VDI_w * VDI_pixelsize;
431 VDI_format = ((VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
432 VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
433 VDI_ReadExtInfo (this, work_out);
421 434
422 #ifdef DEBUG_VIDEO_GEM 435 #ifdef DEBUG_VIDEO_GEM
423 printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch); 436 printf ("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen,
424 printf("sdl:video:gem: format=%d\n", VDI_format); 437 VDI_pitch);
425 printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", 438 printf ("sdl:video:gem: format=%d\n", VDI_format);
426 VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask 439 printf ("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
427 ); 440 VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask);
428 #endif 441 #endif
429 442
430 /* Setup destination mfdb */ 443 /* Setup destination mfdb */
431 VDI_dst_mfdb.fd_addr = NULL; 444 VDI_dst_mfdb.fd_addr = NULL;
432 445
433 /* Determine the current screen size */ 446 /* Determine the current screen size */
434 this->info.current_w = VDI_w; 447 this->info.current_w = VDI_w;
435 this->info.current_h = VDI_h; 448 this->info.current_h = VDI_h;
436 449
437 /* Determine the screen depth */ 450 /* Determine the screen depth */
438 /* we change this during the SDL_SetVideoMode implementation... */ 451 /* we change this during the SDL_SetVideoMode implementation... */
439 vformat->BitsPerPixel = VDI_bpp; 452 vformat->BitsPerPixel = VDI_bpp;
440 453
441 /* Set mouse cursor to arrow */ 454 /* Set mouse cursor to arrow */
442 graf_mouse(ARROW, NULL); 455 graf_mouse (ARROW, NULL);
443 456
444 /* Init chunky to planar routine */ 457 /* Init chunky to planar routine */
445 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; 458 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
446 459
447 /* Setup VDI fill functions */ 460 /* Setup VDI fill functions */
448 vsf_color(VDI_handle,0); 461 vsf_color (VDI_handle, 0);
449 vsf_interior(VDI_handle,1); 462 vsf_interior (VDI_handle, 1);
450 vsf_perimeter(VDI_handle,0); 463 vsf_perimeter (VDI_handle, 0);
451 464
452 /* Menu bar save buffer */ 465 /* Menu bar save buffer */
453 menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize; 466 menubar_size = GEM_desk_w * GEM_desk_y * VDI_pixelsize;
454 GEM_menubar=Atari_SysMalloc(menubar_size,MX_PREFTTRAM); 467 GEM_menubar = Atari_SysMalloc (menubar_size, MX_PREFTTRAM);
455 468
456 /* Fill video modes list */ 469 /* Fill video modes list */
457 SDL_modelist[0] = SDL_malloc(sizeof(SDL_Rect)); 470 SDL_modelist[0] = SDL_malloc (sizeof (SDL_Rect));
458 SDL_modelist[0]->x = 0; 471 SDL_modelist[0]->x = 0;
459 SDL_modelist[0]->y = 0; 472 SDL_modelist[0]->y = 0;
460 SDL_modelist[0]->w = VDI_w; 473 SDL_modelist[0]->w = VDI_w;
461 SDL_modelist[0]->h = VDI_h; 474 SDL_modelist[0]->h = VDI_h;
462 475
463 SDL_modelist[1] = NULL; 476 SDL_modelist[1] = NULL;
464 477
465 #if SDL_VIDEO_OPENGL 478 #if SDL_VIDEO_OPENGL
466 SDL_AtariGL_InitPointers(this); 479 SDL_AtariGL_InitPointers (this);
467 #endif 480 #endif
468 481
469 /* We're done! */ 482 /* We're done! */
470 return(0); 483 return (0);
471 } 484 }
472 485
473 SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 486 SDL_Rect **
474 { 487 GEM_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
475 if (format->BitsPerPixel != VDI_bpp) { 488 {
476 return ((SDL_Rect **)NULL); 489 if (format->BitsPerPixel != VDI_bpp) {
477 } 490 return ((SDL_Rect **) NULL);
478 491 }
479 if (flags & SDL_FULLSCREEN) { 492
480 return (SDL_modelist); 493 if (flags & SDL_FULLSCREEN) {
481 } 494 return (SDL_modelist);
482 495 }
483 return((SDL_Rect **)-1); 496
484 } 497 return ((SDL_Rect **) - 1);
485 498 }
486 static void GEM_FreeBuffers(_THIS) 499
487 { 500 static void
488 /* Release buffer */ 501 GEM_FreeBuffers (_THIS)
489 if ( GEM_buffer2 ) { 502 {
490 Mfree( GEM_buffer2 ); 503 /* Release buffer */
491 GEM_buffer2=NULL; 504 if (GEM_buffer2) {
492 } 505 Mfree (GEM_buffer2);
493 506 GEM_buffer2 = NULL;
494 if ( GEM_buffer1 ) { 507 }
495 Mfree( GEM_buffer1 ); 508
496 GEM_buffer1=NULL; 509 if (GEM_buffer1) {
497 } 510 Mfree (GEM_buffer1);
498 } 511 GEM_buffer1 = NULL;
499 512 }
500 static void GEM_ClearRect(_THIS, short *rect) 513 }
501 { 514
502 short oldrgb[3], rgb[3]={0,0,0}; 515 static void
503 516 GEM_ClearRect (_THIS, short *rect)
504 vq_color(VDI_handle, vdi_index[0], 0, oldrgb); 517 {
505 vs_color(VDI_handle, vdi_index[0], rgb); 518 short oldrgb[3], rgb[3] = { 0, 0, 0 };
506 519
507 vsf_color(VDI_handle,0); 520 vq_color (VDI_handle, vdi_index[0], 0, oldrgb);
508 vsf_interior(VDI_handle,1); 521 vs_color (VDI_handle, vdi_index[0], rgb);
509 vsf_perimeter(VDI_handle,0); 522
510 v_bar(VDI_handle, rect); 523 vsf_color (VDI_handle, 0);
511 524 vsf_interior (VDI_handle, 1);
512 vs_color(VDI_handle, vdi_index[0], oldrgb); 525 vsf_perimeter (VDI_handle, 0);
513 } 526 v_bar (VDI_handle, rect);
514 527
515 static void GEM_ClearScreen(_THIS) 528 vs_color (VDI_handle, vdi_index[0], oldrgb);
516 { 529 }
517 short pxy[4]; 530
518 531 static void
519 v_hide_c(VDI_handle); 532 GEM_ClearScreen (_THIS)
520 533 {
521 pxy[0] = pxy[1] = 0; 534 short pxy[4];
522 pxy[2] = VDI_w - 1; 535
523 pxy[3] = VDI_h - 1; 536 v_hide_c (VDI_handle);
524 GEM_ClearRect(this, pxy); 537
525 538 pxy[0] = pxy[1] = 0;
526 v_show_c(VDI_handle, 1); 539 pxy[2] = VDI_w - 1;
527 } 540 pxy[3] = VDI_h - 1;
528 541 GEM_ClearRect (this, pxy);
529 static void GEM_SetNewPalette(_THIS, Uint16 newpal[256][3]) 542
530 { 543 v_show_c (VDI_handle, 1);
531 int i; 544 }
532 short rgb[3]; 545
533 546 static void
534 if (VDI_oldnumcolors==0) 547 GEM_SetNewPalette (_THIS, Uint16 newpal[256][3])
535 return; 548 {
536 549 int i;
537 for(i = 0; i < VDI_oldnumcolors; i++) { 550 short rgb[3];
538 rgb[0] = newpal[i][0]; 551
539 rgb[1] = newpal[i][1]; 552 if (VDI_oldnumcolors == 0)
540 rgb[2] = newpal[i][2]; 553 return;
541 554
542 vs_color(VDI_handle, i, rgb); 555 for (i = 0; i < VDI_oldnumcolors; i++) {
543 } 556 rgb[0] = newpal[i][0];
544 } 557 rgb[1] = newpal[i][1];
545 558 rgb[2] = newpal[i][2];
546 static void GEM_LockScreen(_THIS) 559
547 { 560 vs_color (VDI_handle, i, rgb);
548 if (!GEM_locked) { 561 }
549 /* Lock AES */ 562 }
550 wind_update(BEG_UPDATE); 563
551 wind_update(BEG_MCTRL); 564 static void
552 /* Reserve memory space, used to be sure of compatibility */ 565 GEM_LockScreen (_THIS)
553 form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h); 566 {
554 567 if (!GEM_locked) {
555 /* Save menu bar */ 568 /* Lock AES */
556 if (GEM_menubar) { 569 wind_update (BEG_UPDATE);
557 MFDB mfdb_src; 570 wind_update (BEG_MCTRL);
558 short blitcoords[8]; 571 /* Reserve memory space, used to be sure of compatibility */
559 572 form_dial (FMD_START, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
560 mfdb_src.fd_addr=GEM_menubar; 573
561 mfdb_src.fd_w=GEM_desk_w; 574 /* Save menu bar */
562 mfdb_src.fd_h=GEM_desk_y; 575 if (GEM_menubar) {
563 mfdb_src.fd_wdwidth=GEM_desk_w>>4; 576 MFDB mfdb_src;
564 mfdb_src.fd_nplanes=VDI_bpp; 577 short blitcoords[8];
565 mfdb_src.fd_stand= 578
566 mfdb_src.fd_r1= 579 mfdb_src.fd_addr = GEM_menubar;
567 mfdb_src.fd_r2= 580 mfdb_src.fd_w = GEM_desk_w;
568 mfdb_src.fd_r3= 0; 581 mfdb_src.fd_h = GEM_desk_y;
569 582 mfdb_src.fd_wdwidth = GEM_desk_w >> 4;
570 blitcoords[0] = blitcoords[4] = 0; 583 mfdb_src.fd_nplanes = VDI_bpp;
571 blitcoords[1] = blitcoords[5] = 0; 584 mfdb_src.fd_stand =
572 blitcoords[2] = blitcoords[6] = GEM_desk_w-1; 585 mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
573 blitcoords[3] = blitcoords[7] = GEM_desk_y-1; 586
574 587 blitcoords[0] = blitcoords[4] = 0;
575 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb, &mfdb_src); 588 blitcoords[1] = blitcoords[5] = 0;
576 } 589 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
577 590 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
578 GEM_locked=SDL_TRUE; 591
579 } 592 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &VDI_dst_mfdb,
580 } 593 &mfdb_src);
581 594 }
582 static void GEM_UnlockScreen(_THIS) 595
583 { 596 GEM_locked = SDL_TRUE;
584 if (GEM_locked) { 597 }
585 /* Restore menu bar */ 598 }
586 if (GEM_menubar) { 599
587 MFDB mfdb_src; 600 static void
588 short blitcoords[8]; 601 GEM_UnlockScreen (_THIS)
589 602 {
590 mfdb_src.fd_addr=GEM_menubar; 603 if (GEM_locked) {
591 mfdb_src.fd_w=GEM_desk_w; 604 /* Restore menu bar */
592 mfdb_src.fd_h=GEM_desk_y; 605 if (GEM_menubar) {
593 mfdb_src.fd_wdwidth=GEM_desk_w>>4; 606 MFDB mfdb_src;
594 mfdb_src.fd_nplanes=VDI_bpp; 607 short blitcoords[8];
595 mfdb_src.fd_stand= 608
596 mfdb_src.fd_r1= 609 mfdb_src.fd_addr = GEM_menubar;
597 mfdb_src.fd_r2= 610 mfdb_src.fd_w = GEM_desk_w;
598 mfdb_src.fd_r3= 0; 611 mfdb_src.fd_h = GEM_desk_y;
599 612 mfdb_src.fd_wdwidth = GEM_desk_w >> 4;
600 blitcoords[0] = blitcoords[4] = 0; 613 mfdb_src.fd_nplanes = VDI_bpp;
601 blitcoords[1] = blitcoords[5] = 0; 614 mfdb_src.fd_stand =
602 blitcoords[2] = blitcoords[6] = GEM_desk_w-1; 615 mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
603 blitcoords[3] = blitcoords[7] = GEM_desk_y-1; 616
604 617 blitcoords[0] = blitcoords[4] = 0;
605 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb); 618 blitcoords[1] = blitcoords[5] = 0;
606 } 619 blitcoords[2] = blitcoords[6] = GEM_desk_w - 1;
607 620 blitcoords[3] = blitcoords[7] = GEM_desk_y - 1;
608 /* Restore screen memory, and send REDRAW to all apps */ 621
609 form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h); 622 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src,
610 /* Unlock AES */ 623 &VDI_dst_mfdb);
611 wind_update(END_MCTRL); 624 }
612 wind_update(END_UPDATE); 625
613 626 /* Restore screen memory, and send REDRAW to all apps */
614 GEM_locked=SDL_FALSE; 627 form_dial (FMD_FINISH, 0, 0, 0, 0, 0, 0, VDI_w, VDI_h);
615 } 628 /* Unlock AES */
616 } 629 wind_update (END_MCTRL);
617 630 wind_update (END_UPDATE);
618 SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, 631
619 int width, int height, int bpp, Uint32 flags) 632 GEM_locked = SDL_FALSE;
620 { 633 }
621 int maxwidth, maxheight; 634 }
622 Uint32 modeflags, screensize; 635
623 SDL_bool use_shadow1, use_shadow2; 636 SDL_Surface *
624 637 GEM_SetVideoMode (_THIS, SDL_Surface * current,
625 /*--- Verify if asked mode can be used ---*/ 638 int width, int height, int bpp, Uint32 flags)
626 if (flags & SDL_FULLSCREEN) { 639 {
627 maxwidth=VDI_w; 640 int maxwidth, maxheight;
628 maxheight=VDI_h; 641 Uint32 modeflags, screensize;
629 } else { 642 SDL_bool use_shadow1, use_shadow2;
630 /* Windowed mode */ 643
631 maxwidth=GEM_desk_w; 644 /*--- Verify if asked mode can be used ---*/
632 maxheight=GEM_desk_h; 645 if (flags & SDL_FULLSCREEN) {
633 } 646 maxwidth = VDI_w;
634 647 maxheight = VDI_h;
635 /* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */ 648 } else {
636 if ((width & 15) != 0) { 649 /* Windowed mode */
637 width = (width | 15) +1; 650 maxwidth = GEM_desk_w;
638 } 651 maxheight = GEM_desk_h;
639 652 }
640 if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) { 653
641 SDL_SetError("Couldn't find requested mode in list"); 654 /* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
642 return(NULL); 655 if ((width & 15) != 0) {
643 } 656 width = (width | 15) + 1;
644 657 }
645 /*--- Allocate the new pixel format for the screen ---*/ 658
646 if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) { 659 if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
647 SDL_SetError("Couldn't allocate new pixel format for requested mode"); 660 SDL_SetError ("Couldn't find requested mode in list");
648 return(NULL); 661 return (NULL);
649 } 662 }
650 663
651 screensize = width * height * VDI_pixelsize; 664 /*--- Allocate the new pixel format for the screen ---*/
665 if (!SDL_ReallocFormat
666 (current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask,
667 VDI_alphamask)) {
668 SDL_SetError
669 ("Couldn't allocate new pixel format for requested mode");
670 return (NULL);
671 }
672
673 screensize = width * height * VDI_pixelsize;
652 674
653 #ifdef DEBUG_VIDEO_GEM 675 #ifdef DEBUG_VIDEO_GEM
654 printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height, bpp, screensize); 676 printf ("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height,
655 #endif 677 bpp, screensize);
656 678 #endif
657 /*--- Allocate shadow buffers if needed, and conversion operations ---*/ 679
658 GEM_FreeBuffers(this); 680 /*--- Allocate shadow buffers if needed, and conversion operations ---*/
659 681 GEM_FreeBuffers (this);
660 GEM_bufops=0; 682
661 use_shadow1=use_shadow2=SDL_FALSE; 683 GEM_bufops = 0;
662 if (VDI_screen && (flags & SDL_FULLSCREEN)) { 684 use_shadow1 = use_shadow2 = SDL_FALSE;
663 if (VDI_format==VDI_FORMAT_INTER) { 685 if (VDI_screen && (flags & SDL_FULLSCREEN)) {
664 use_shadow1=SDL_TRUE; 686 if (VDI_format == VDI_FORMAT_INTER) {
665 GEM_bufops = B2S_C2P_1TOS; 687 use_shadow1 = SDL_TRUE;
666 } 688 GEM_bufops = B2S_C2P_1TOS;
667 } else { 689 }
668 use_shadow1=SDL_TRUE; 690 } else {
669 if (VDI_format==VDI_FORMAT_PACK) { 691 use_shadow1 = SDL_TRUE;
670 GEM_bufops = B2S_VROCPYFM_1TOS; 692 if (VDI_format == VDI_FORMAT_PACK) {
671 } else { 693 GEM_bufops = B2S_VROCPYFM_1TOS;
672 use_shadow2=SDL_TRUE; 694 } else {
673 GEM_bufops = B2S_C2P_1TO2|B2S_VROCPYFM_2TOS; 695 use_shadow2 = SDL_TRUE;
674 } 696 GEM_bufops = B2S_C2P_1TO2 | B2S_VROCPYFM_2TOS;
675 } 697 }
676 698 }
677 if (use_shadow1) { 699
678 GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM); 700 if (use_shadow1) {
679 if (GEM_buffer1==NULL) { 701 GEM_buffer1 = Atari_SysMalloc (screensize, MX_PREFTTRAM);
680 SDL_SetError("Can not allocate %d KB for frame buffer", screensize>>10); 702 if (GEM_buffer1 == NULL) {
681 return NULL; 703 SDL_SetError ("Can not allocate %d KB for frame buffer",
682 } 704 screensize >> 10);
683 SDL_memset(GEM_buffer1, 0, screensize); 705 return NULL;
706 }
707 SDL_memset (GEM_buffer1, 0, screensize);
684 #ifdef DEBUG_VIDEO_GEM 708 #ifdef DEBUG_VIDEO_GEM
685 printf("sdl:video:gem: setvideomode(): allocated buffer 1\n"); 709 printf ("sdl:video:gem: setvideomode(): allocated buffer 1\n");
686 #endif 710 #endif
687 } 711 }
688 712
689 if (use_shadow2) { 713 if (use_shadow2) {
690 GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM); 714 GEM_buffer2 = Atari_SysMalloc (screensize, MX_PREFTTRAM);
691 if (GEM_buffer2==NULL) { 715 if (GEM_buffer2 == NULL) {
692 SDL_SetError("Can not allocate %d KB for shadow buffer", screensize>>10); 716 SDL_SetError ("Can not allocate %d KB for shadow buffer",
693 return NULL; 717 screensize >> 10);
694 } 718 return NULL;
695 SDL_memset(GEM_buffer2, 0, screensize); 719 }
720 SDL_memset (GEM_buffer2, 0, screensize);
696 #ifdef DEBUG_VIDEO_GEM 721 #ifdef DEBUG_VIDEO_GEM
697 printf("sdl:video:gem: setvideomode(): allocated buffer 2\n"); 722 printf ("sdl:video:gem: setvideomode(): allocated buffer 2\n");
698 #endif 723 #endif
699 } 724 }
700 725
701 /*--- Initialize screen ---*/ 726 /*--- Initialize screen ---*/
702 modeflags = SDL_PREALLOC; 727 modeflags = SDL_PREALLOC;
703 if (VDI_bpp == 8) { 728 if (VDI_bpp == 8) {
704 modeflags |= SDL_HWPALETTE; 729 modeflags |= SDL_HWPALETTE;
705 } 730 }
706 731
707 if (flags & SDL_FULLSCREEN) { 732 if (flags & SDL_FULLSCREEN) {
708 GEM_LockScreen(this); 733 GEM_LockScreen (this);
709 734
710 GEM_ClearScreen(this); 735 GEM_ClearScreen (this);
711 736
712 modeflags |= SDL_FULLSCREEN; 737 modeflags |= SDL_FULLSCREEN;
713 if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) { 738 if (VDI_screen && (VDI_format == VDI_FORMAT_PACK) && !use_shadow1) {
714 modeflags |= SDL_HWSURFACE; 739 modeflags |= SDL_HWSURFACE;
715 } else { 740 } else {
716 modeflags |= SDL_SWSURFACE; 741 modeflags |= SDL_SWSURFACE;
717 } 742 }
718 743
719 GEM_fullscreen = SDL_TRUE; 744 GEM_fullscreen = SDL_TRUE;
720 } else { 745 } else {
721 int old_win_type; 746 int old_win_type;
722 short x2,y2,w2,h2; 747 short x2, y2, w2, h2;
723 748
724 GEM_UnlockScreen(this); 749 GEM_UnlockScreen (this);
725 750
726 /* Set window gadgets */ 751 /* Set window gadgets */
727 old_win_type = GEM_win_type; 752 old_win_type = GEM_win_type;
728 if (!(flags & SDL_NOFRAME)) { 753 if (!(flags & SDL_NOFRAME)) {
729 GEM_win_type=NAME|MOVER|CLOSER|SMALLER; 754 GEM_win_type = NAME | MOVER | CLOSER | SMALLER;
730 if (flags & SDL_RESIZABLE) { 755 if (flags & SDL_RESIZABLE) {
731 GEM_win_type |= FULLER|SIZER; 756 GEM_win_type |= FULLER | SIZER;
732 modeflags |= SDL_RESIZABLE; 757 modeflags |= SDL_RESIZABLE;
733 } 758 }
734 } else { 759 } else {
735 GEM_win_type=0; 760 GEM_win_type = 0;
736 modeflags |= SDL_NOFRAME; 761 modeflags |= SDL_NOFRAME;
737 } 762 }
738 modeflags |= SDL_SWSURFACE; 763 modeflags |= SDL_SWSURFACE;
739 764
740 /* Recreate window ? only for different widget or non-created window */ 765 /* Recreate window ? only for different widget or non-created window */
741 if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) { 766 if ((old_win_type != GEM_win_type) || (GEM_handle < 0)) {
742 /* Calculate window size */ 767 /* Calculate window size */
743 if (!wind_calc(WC_BORDER, GEM_win_type, 0,0,width,height, &x2,&y2,&w2,&h2)) { 768 if (!wind_calc
744 GEM_FreeBuffers(this); 769 (WC_BORDER, GEM_win_type, 0, 0, width, height, &x2, &y2,
745 SDL_SetError("Can not calculate window attributes"); 770 &w2, &h2)) {
746 return NULL; 771 GEM_FreeBuffers (this);
747 } 772 SDL_SetError ("Can not calculate window attributes");
748 773 return NULL;
749 /* Center window */ 774 }
750 x2 = GEM_desk_x+((GEM_desk_w-w2)>>1); 775
751 y2 = GEM_desk_y+((GEM_desk_h-h2)>>1); 776 /* Center window */
752 777 x2 = GEM_desk_x + ((GEM_desk_w - w2) >> 1);
753 /* Destroy existing window */ 778 y2 = GEM_desk_y + ((GEM_desk_h - h2) >> 1);
754 if (GEM_handle >= 0) { 779
755 wind_close(GEM_handle); 780 /* Destroy existing window */
756 wind_delete(GEM_handle); 781 if (GEM_handle >= 0) {
757 } 782 wind_close (GEM_handle);
758 783 wind_delete (GEM_handle);
759 /* Create window */ 784 }
760 GEM_handle=wind_create(GEM_win_type, x2,y2,w2,h2); 785
761 if (GEM_handle<0) { 786 /* Create window */
762 GEM_FreeBuffers(this); 787 GEM_handle = wind_create (GEM_win_type, x2, y2, w2, h2);
763 SDL_SetError("Can not create window"); 788 if (GEM_handle < 0) {
764 return NULL; 789 GEM_FreeBuffers (this);
765 } 790 SDL_SetError ("Can not create window");
766 791 return NULL;
792 }
767 #ifdef DEBUG_VIDEO_GEM 793 #ifdef DEBUG_VIDEO_GEM
768 printf("sdl:video:gem: handle=%d\n", GEM_handle); 794 printf ("sdl:video:gem: handle=%d\n", GEM_handle);
769 #endif 795 #endif
770 796
771 /* Setup window name */ 797 /* Setup window name */
772 wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0); 798 wind_set (GEM_handle, WF_NAME,
773 GEM_refresh_name = SDL_FALSE; 799 (short) (((unsigned long) GEM_title_name) >> 16),
774 800 (short) (((unsigned long) GEM_title_name) & 0xffff),
775 /* Open the window */ 801 0, 0);
776 wind_open(GEM_handle,x2,y2,w2,h2); 802 GEM_refresh_name = SDL_FALSE;
777 } else { 803
778 /* Resize window if needed, to fit asked video mode */ 804 /* Open the window */
779 if (modeflags & SDL_RESIZABLE) { 805 wind_open (GEM_handle, x2, y2, w2, h2);
780 wind_get (GEM_handle, WF_WORKXYWH, &x2,&y2,&w2,&h2); 806 } else {
781 if ((w2&15)!=0) { 807 /* Resize window if needed, to fit asked video mode */
782 w2=(w2|15)+1; 808 if (modeflags & SDL_RESIZABLE) {
783 } 809 wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
784 if ((w2!=width) || (h2!=height)) { 810 if ((w2 & 15) != 0) {
785 if (wind_calc(WC_BORDER, GEM_win_type, x2,y2,width,height, &x2,&y2,&w2,&h2)) { 811 w2 = (w2 | 15) + 1;
786 wind_set (GEM_handle, WF_CURRXYWH, x2,y2,w2,h2); 812 }
787 } 813 if ((w2 != width) || (h2 != height)) {
788 } 814 if (wind_calc
789 } 815 (WC_BORDER, GEM_win_type, x2, y2, width,
790 } 816 height, &x2, &y2, &w2, &h2)) {
791 817 wind_set (GEM_handle, WF_CURRXYWH, x2, y2, w2, h2);
792 GEM_fullscreen = SDL_FALSE; 818 }
793 } 819 }
794 820 }
795 /* Set up the new mode framebuffer */ 821 }
796 current->w = width; 822
797 current->h = height; 823 GEM_fullscreen = SDL_FALSE;
798 if (use_shadow1) { 824 }
799 current->pixels = GEM_buffer1; 825
800 current->pitch = width * VDI_pixelsize; 826 /* Set up the new mode framebuffer */
801 } else { 827 current->w = width;
802 current->pixels = VDI_screen; 828 current->h = height;
803 current->pitch = VDI_pitch; 829 if (use_shadow1) {
804 } 830 current->pixels = GEM_buffer1;
831 current->pitch = width * VDI_pixelsize;
832 } else {
833 current->pixels = VDI_screen;
834 current->pitch = VDI_pitch;
835 }
805 836
806 #if SDL_VIDEO_OPENGL 837 #if SDL_VIDEO_OPENGL
807 if (flags & SDL_INTERNALOPENGL) { 838 if (flags & SDL_INTERNALOPENGL) {
808 if (!SDL_AtariGL_Init(this, current)) { 839 if (!SDL_AtariGL_Init (this, current)) {
809 GEM_FreeBuffers(this); 840 GEM_FreeBuffers (this);
810 SDL_SetError("Can not create OpenGL context"); 841 SDL_SetError ("Can not create OpenGL context");
811 return NULL; 842 return NULL;
812 } 843 }
813 844
814 modeflags |= SDL_INTERNALOPENGL; 845 modeflags |= SDL_INTERNALOPENGL;
815 } 846 }
816 #endif 847 #endif
817 848
818 current->flags = modeflags; 849 current->flags = modeflags;
819 850
820 #ifdef DEBUG_VIDEO_GEM 851 #ifdef DEBUG_VIDEO_GEM
821 printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h); 852 printf ("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
822 #endif 853 #endif
823 854
824 this->UpdateRects = GEM_UpdateRects; 855 this->UpdateRects = GEM_UpdateRects;
825 GEM_lock_redraw = SDL_FALSE; /* Enable redraw */ 856 GEM_lock_redraw = SDL_FALSE; /* Enable redraw */
826 857
827 /* We're done */ 858 /* We're done */
828 return(current); 859 return (current);
829 } 860 }
830 861
831 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface) 862 static int
832 { 863 GEM_AllocHWSurface (_THIS, SDL_Surface * surface)
833 return -1; 864 {
834 } 865 return -1;
835 866 }
836 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface) 867
837 { 868 static void
838 return; 869 GEM_FreeHWSurface (_THIS, SDL_Surface * surface)
839 } 870 {
840 871 return;
841 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface) 872 }
842 { 873
843 return(0); 874 static int
844 } 875 GEM_LockHWSurface (_THIS, SDL_Surface * surface)
845 876 {
846 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface) 877 return (0);
847 { 878 }
848 return; 879
849 } 880 static void
850 881 GEM_UnlockHWSurface (_THIS, SDL_Surface * surface)
851 static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects) 882 {
852 { 883 return;
853 SDL_Surface *surface; 884 }
854 int i, surf_width; 885
855 886 static void
856 surface = this->screen; 887 GEM_UpdateRectsFullscreen (_THIS, int numrects, SDL_Rect * rects)
857 /* Need to be a multiple of 16 pixels */ 888 {
858 surf_width=surface->w; 889 SDL_Surface *surface;
859 if ((surf_width & 15) != 0) { 890 int i, surf_width;
860 surf_width = (surf_width | 15) + 1; 891
861 } 892 surface = this->screen;
862 893 /* Need to be a multiple of 16 pixels */
863 if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) { 894 surf_width = surface->w;
864 void *destscr; 895 if ((surf_width & 15) != 0) {
865 int destpitch; 896 surf_width = (surf_width | 15) + 1;
866 897 }
867 if (GEM_bufops & B2S_C2P_1TOS) { 898
868 destscr = VDI_screen; 899 if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
869 destpitch = VDI_pitch; 900 void *destscr;
870 } else { 901 int destpitch;
871 destscr = GEM_buffer2; 902
872 destpitch = surface->pitch; 903 if (GEM_bufops & B2S_C2P_1TOS) {
873 } 904 destscr = VDI_screen;
874 905 destpitch = VDI_pitch;
875 for (i=0;i<numrects;i++) { 906 } else {
876 void *source,*destination; 907 destscr = GEM_buffer2;
877 int x1,x2; 908 destpitch = surface->pitch;
878 909 }
879 x1 = rects[i].x & ~15; 910
880 x2 = rects[i].x+rects[i].w; 911 for (i = 0; i < numrects; i++) {
881 if (x2 & 15) { 912 void *source, *destination;
882 x2 = (x2 | 15) +1; 913 int x1, x2;
883 } 914
884 915 x1 = rects[i].x & ~15;
885 source = surface->pixels; 916 x2 = rects[i].x + rects[i].w;
886 source += surface->pitch * rects[i].y; 917 if (x2 & 15) {
887 source += x1; 918 x2 = (x2 | 15) + 1;
888 919 }
889 destination = destscr; 920
890 destination += destpitch * rects[i].y; 921 source = surface->pixels;
891 destination += x1; 922 source += surface->pitch * rects[i].y;
892 923 source += x1;
893 SDL_Atari_C2pConvert( 924
894 source, destination, 925 destination = destscr;
895 x2-x1, rects[i].h, 926 destination += destpitch * rects[i].y;
896 SDL_FALSE, 927 destination += x1;
897 surface->pitch, destpitch 928
898 ); 929 SDL_Atari_C2pConvert (source, destination,
899 } 930 x2 - x1, rects[i].h,
900 } 931 SDL_FALSE, surface->pitch, destpitch);
901 932 }
902 if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) { 933 }
903 MFDB mfdb_src; 934
904 short blitcoords[8]; 935 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
905 936 MFDB mfdb_src;
906 mfdb_src.fd_addr=surface->pixels; 937 short blitcoords[8];
907 mfdb_src.fd_w=surf_width; 938
908 mfdb_src.fd_h=surface->h; 939 mfdb_src.fd_addr = surface->pixels;
909 mfdb_src.fd_wdwidth= (surface->pitch/VDI_pixelsize) >> 4; 940 mfdb_src.fd_w = surf_width;
910 mfdb_src.fd_nplanes=surface->format->BitsPerPixel; 941 mfdb_src.fd_h = surface->h;
911 mfdb_src.fd_stand= 942 mfdb_src.fd_wdwidth = (surface->pitch / VDI_pixelsize) >> 4;
912 mfdb_src.fd_r1= 943 mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
913 mfdb_src.fd_r2= 944 mfdb_src.fd_stand =
914 mfdb_src.fd_r3= 0; 945 mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
915 if (GEM_bufops & B2S_VROCPYFM_2TOS) { 946 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
916 mfdb_src.fd_addr=GEM_buffer2; 947 mfdb_src.fd_addr = GEM_buffer2;
917 } 948 }
918 949
919 for ( i=0; i<numrects; ++i ) { 950 for (i = 0; i < numrects; ++i) {
920 blitcoords[0] = blitcoords[4] = rects[i].x; 951 blitcoords[0] = blitcoords[4] = rects[i].x;
921 blitcoords[1] = blitcoords[5] = rects[i].y; 952 blitcoords[1] = blitcoords[5] = rects[i].y;
922 blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1; 953 blitcoords[2] = blitcoords[6] = rects[i].x + rects[i].w - 1;
923 blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1; 954 blitcoords[3] = blitcoords[7] = rects[i].y + rects[i].h - 1;
924 955
925 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb); 956 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src,
926 } 957 &VDI_dst_mfdb);
927 } 958 }
928 } 959 }
929 960 }
930 static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects) 961
931 { 962 static void
932 short pxy[4], wind_pxy[4]; 963 GEM_UpdateRectsWindowed (_THIS, int numrects, SDL_Rect * rects)
933 int i; 964 {
934 965 short pxy[4], wind_pxy[4];
935 if (wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) { 966 int i;
936 return; 967
937 } 968 if (wind_get
938 969 (GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
939 for ( i=0; i<numrects; ++i ) { 970 &wind_pxy[3]) == 0) {
940 pxy[0] = wind_pxy[0] + rects[i].x; 971 return;
941 pxy[1] = wind_pxy[1] + rects[i].y; 972 }
942 pxy[2] = rects[i].w; 973
943 pxy[3] = rects[i].h; 974 for (i = 0; i < numrects; ++i) {
944 975 pxy[0] = wind_pxy[0] + rects[i].x;
945 GEM_wind_redraw(this, GEM_handle, pxy); 976 pxy[1] = wind_pxy[1] + rects[i].y;
946 } 977 pxy[2] = rects[i].w;
947 } 978 pxy[3] = rects[i].h;
948 979
949 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 980 GEM_wind_redraw (this, GEM_handle, pxy);
950 { 981 }
951 SDL_Surface *surface; 982 }
952 983
953 if (GEM_lock_redraw) { 984 static void
954 return; 985 GEM_UpdateRects (_THIS, int numrects, SDL_Rect * rects)
955 } 986 {
956 987 SDL_Surface *surface;
957 surface = this->screen; 988
958 989 if (GEM_lock_redraw) {
959 if (surface->flags & SDL_FULLSCREEN) { 990 return;
960 GEM_UpdateRectsFullscreen(this, numrects, rects); 991 }
961 } else { 992
962 GEM_UpdateRectsWindowed(this, numrects, rects); 993 surface = this->screen;
963 } 994
964 } 995 if (surface->flags & SDL_FULLSCREEN) {
965 996 GEM_UpdateRectsFullscreen (this, numrects, rects);
966 static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface) 997 } else {
967 { 998 GEM_UpdateRectsWindowed (this, numrects, rects);
968 int surf_width; 999 }
969 1000 }
970 /* Need to be a multiple of 16 pixels */ 1001
971 surf_width=surface->w; 1002 static int
972 if ((surf_width & 15) != 0) { 1003 GEM_FlipHWSurfaceFullscreen (_THIS, SDL_Surface * surface)
973 surf_width = (surf_width | 15) + 1; 1004 {
974 } 1005 int surf_width;
975 1006
976 if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) { 1007 /* Need to be a multiple of 16 pixels */
977 void *destscr; 1008 surf_width = surface->w;
978 int destpitch; 1009 if ((surf_width & 15) != 0) {
979 1010 surf_width = (surf_width | 15) + 1;
980 if (GEM_bufops & B2S_C2P_1TOS) { 1011 }
981 destscr = VDI_screen; 1012
982 destpitch = VDI_pitch; 1013 if (GEM_bufops & (B2S_C2P_1TO2 | B2S_C2P_1TOS)) {
983 } else { 1014 void *destscr;
984 destscr = GEM_buffer2; 1015 int destpitch;
985 destpitch = surface->pitch; 1016
986 } 1017 if (GEM_bufops & B2S_C2P_1TOS) {
987 1018 destscr = VDI_screen;
988 SDL_Atari_C2pConvert( 1019 destpitch = VDI_pitch;
989 surface->pixels, destscr, 1020 } else {
990 surf_width, surface->h, 1021 destscr = GEM_buffer2;
991 SDL_FALSE, 1022 destpitch = surface->pitch;
992 surface->pitch, destpitch 1023 }
993 ); 1024
994 } 1025 SDL_Atari_C2pConvert (surface->pixels, destscr,
995 1026 surf_width, surface->h,
996 if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) { 1027 SDL_FALSE, surface->pitch, destpitch);
997 MFDB mfdb_src; 1028 }
998 short blitcoords[8]; 1029
999 1030 if (GEM_bufops & (B2S_VROCPYFM_1TOS | B2S_VROCPYFM_2TOS)) {
1000 mfdb_src.fd_w=surf_width; 1031 MFDB mfdb_src;
1001 mfdb_src.fd_h=surface->h; 1032 short blitcoords[8];
1002 mfdb_src.fd_wdwidth=mfdb_src.fd_w >> 4; 1033
1003 mfdb_src.fd_nplanes=surface->format->BitsPerPixel; 1034 mfdb_src.fd_w = surf_width;
1004 mfdb_src.fd_stand= 1035 mfdb_src.fd_h = surface->h;
1005 mfdb_src.fd_r1= 1036 mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
1006 mfdb_src.fd_r2= 1037 mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
1007 mfdb_src.fd_r3= 0; 1038 mfdb_src.fd_stand =
1008 if (GEM_bufops & B2S_VROCPYFM_1TOS) { 1039 mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
1009 mfdb_src.fd_addr=surface->pixels; 1040 if (GEM_bufops & B2S_VROCPYFM_1TOS) {
1010 } else { 1041 mfdb_src.fd_addr = surface->pixels;
1011 mfdb_src.fd_addr=GEM_buffer2; 1042 } else {
1012 } 1043 mfdb_src.fd_addr = GEM_buffer2;
1013 1044 }
1014 blitcoords[0] = blitcoords[4] = 0; 1045
1015 blitcoords[1] = blitcoords[5] = 0; 1046 blitcoords[0] = blitcoords[4] = 0;
1016 blitcoords[2] = blitcoords[6] = surface->w - 1; 1047 blitcoords[1] = blitcoords[5] = 0;
1017 blitcoords[3] = blitcoords[7] = surface->h - 1; 1048 blitcoords[2] = blitcoords[6] = surface->w - 1;
1018 1049 blitcoords[3] = blitcoords[7] = surface->h - 1;
1019 vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb); 1050
1020 } 1051 vro_cpyfm (VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
1021 1052 }
1022 return(0); 1053
1023 } 1054 return (0);
1024 1055 }
1025 static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface) 1056
1026 { 1057 static int
1027 short pxy[8]; 1058 GEM_FlipHWSurfaceWindowed (_THIS, SDL_Surface * surface)
1028 1059 {
1029 /* Update the whole window */ 1060 short pxy[8];
1030 wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]); 1061
1031 1062 /* Update the whole window */
1032 GEM_wind_redraw(this, GEM_handle, pxy); 1063 wind_get (GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
1033 1064
1034 return(0); 1065 GEM_wind_redraw (this, GEM_handle, pxy);
1035 } 1066
1036 1067 return (0);
1037 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface) 1068 }
1038 { 1069
1039 if (GEM_lock_redraw) { 1070 static int
1040 return(0); 1071 GEM_FlipHWSurface (_THIS, SDL_Surface * surface)
1041 } 1072 {
1042 1073 if (GEM_lock_redraw) {
1043 if (surface->flags & SDL_FULLSCREEN) { 1074 return (0);
1044 return GEM_FlipHWSurfaceFullscreen(this, surface); 1075 }
1045 } else { 1076
1046 return GEM_FlipHWSurfaceWindowed(this, surface); 1077 if (surface->flags & SDL_FULLSCREEN) {
1047 } 1078 return GEM_FlipHWSurfaceFullscreen (this, surface);
1048 } 1079 } else {
1049 1080 return GEM_FlipHWSurfaceWindowed (this, surface);
1050 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 1081 }
1051 { 1082 }
1052 int i; 1083
1053 SDL_Surface *surface; 1084 static int
1085 GEM_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1086 {
1087 int i;
1088 SDL_Surface *surface;
1054 1089
1055 #ifdef DEBUG_VIDEO_GEM 1090 #ifdef DEBUG_VIDEO_GEM
1056 printf("sdl:video:gem: setcolors()\n"); 1091 printf ("sdl:video:gem: setcolors()\n");
1057 #endif 1092 #endif
1058 1093
1059 /* Do not change palette in True Colour */ 1094 /* Do not change palette in True Colour */
1060 surface = this->screen; 1095 surface = this->screen;
1061 if (surface->format->BitsPerPixel > 8) { 1096 if (surface->format->BitsPerPixel > 8) {
1062 return 1; 1097 return 1;
1063 } 1098 }
1064 1099
1065 for(i = 0; i < ncolors; i++) 1100 for (i = 0; i < ncolors; i++) {
1066 { 1101 int r, g, b;
1067 int r, g, b; 1102 short rgb[3];
1068 short rgb[3]; 1103
1069 1104 r = colors[i].r;
1070 r = colors[i].r; 1105 g = colors[i].g;
1071 g = colors[i].g; 1106 b = colors[i].b;
1072 b = colors[i].b; 1107
1073 1108 rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255;
1074 rgb[0] = VDI_curpalette[i][0] = (1000 * r) / 255; 1109 rgb[1] = VDI_curpalette[i][1] = (1000 * g) / 255;
1075 rgb[1] = VDI_curpalette[i][1] =(1000 * g) / 255; 1110 rgb[2] = VDI_curpalette[i][2] = (1000 * b) / 255;
1076 rgb[2] = VDI_curpalette[i][2] =(1000 * b) / 255; 1111
1077 1112 vs_color (VDI_handle, vdi_index[firstcolor + i], rgb);
1078 vs_color(VDI_handle, vdi_index[firstcolor+i], rgb); 1113 }
1079 } 1114
1080 1115 return (1);
1081 return(1);
1082 } 1116 }
1083 1117
1084 #if 0 1118 #if 0
1085 static int GEM_ToggleFullScreen(_THIS, int on) 1119 static int
1086 { 1120 GEM_ToggleFullScreen (_THIS, int on)
1087 if (on) { 1121 {
1088 GEM_LockScreen(this); 1122 if (on) {
1089 } else { 1123 GEM_LockScreen (this);
1090 GEM_UnlockScreen(this); 1124 } else {
1091 } 1125 GEM_UnlockScreen (this);
1092 1126 }
1093 return(1); 1127
1128 return (1);
1094 } 1129 }
1095 #endif 1130 #endif
1096 1131
1097 /* Note: If we are terminated, this could be called in the middle of 1132 /* Note: If we are terminated, this could be called in the middle of
1098 another SDL video routine -- notably UpdateRects. 1133 another SDL video routine -- notably UpdateRects.
1099 */ 1134 */
1100 void GEM_VideoQuit(_THIS) 1135 void
1101 { 1136 GEM_VideoQuit (_THIS)
1102 SDL_AtariXbios_RestoreVectors(); 1137 {
1103 if (GEM_usedevmouse) { 1138 SDL_AtariXbios_RestoreVectors ();
1104 SDL_AtariDevMouse_Close(); 1139 if (GEM_usedevmouse) {
1105 } 1140 SDL_AtariDevMouse_Close ();
1106 1141 }
1107 GEM_FreeBuffers(this); 1142
1143 GEM_FreeBuffers (this);
1108 1144
1109 #if SDL_VIDEO_OPENGL 1145 #if SDL_VIDEO_OPENGL
1110 if (gl_active) { 1146 if (gl_active) {
1111 SDL_AtariGL_Quit(this, SDL_TRUE); 1147 SDL_AtariGL_Quit (this, SDL_TRUE);
1112 } 1148 }
1113 #endif 1149 #endif
1114 1150
1115 /* Destroy window */ 1151 /* Destroy window */
1116 if (GEM_handle>=0) { 1152 if (GEM_handle >= 0) {
1117 wind_close(GEM_handle); 1153 wind_close (GEM_handle);
1118 wind_delete(GEM_handle); 1154 wind_delete (GEM_handle);
1119 GEM_handle=-1; 1155 GEM_handle = -1;
1120 } 1156 }
1121 1157
1122 GEM_UnlockScreen(this); 1158 GEM_UnlockScreen (this);
1123 if (GEM_menubar) { 1159 if (GEM_menubar) {
1124 Mfree(GEM_menubar); 1160 Mfree (GEM_menubar);
1125 GEM_menubar=NULL; 1161 GEM_menubar = NULL;
1126 } 1162 }
1127 1163
1128 appl_exit(); 1164 appl_exit ();
1129 1165
1130 GEM_SetNewPalette(this, VDI_oldpalette); 1166 GEM_SetNewPalette (this, VDI_oldpalette);
1131 1167
1132 /* Close VDI workstation */ 1168 /* Close VDI workstation */
1133 if (VDI_handle) { 1169 if (VDI_handle) {
1134 v_clsvwk(VDI_handle); 1170 v_clsvwk (VDI_handle);
1135 } 1171 }
1136 1172
1137 /* Free mode list */ 1173 /* Free mode list */
1138 if (SDL_modelist[0]) { 1174 if (SDL_modelist[0]) {
1139 SDL_free(SDL_modelist[0]); 1175 SDL_free (SDL_modelist[0]);
1140 SDL_modelist[0]=NULL; 1176 SDL_modelist[0] = NULL;
1141 } 1177 }
1142 1178
1143 this->screen->pixels = NULL; 1179 this->screen->pixels = NULL;
1144 } 1180 }
1145 1181
1146 void GEM_wind_redraw(_THIS, int winhandle, short *inside) 1182 void
1147 { 1183 GEM_wind_redraw (_THIS, int winhandle, short *inside)
1148 short todo[4]; 1184 {
1149 1185 short todo[4];
1150 /* Tell AES we are going to update */ 1186
1151 wind_update(BEG_UPDATE); 1187 /* Tell AES we are going to update */
1152 1188 wind_update (BEG_UPDATE);
1153 v_hide_c(VDI_handle); 1189
1154 1190 v_hide_c (VDI_handle);
1155 /* Browse the rectangle list to redraw */ 1191
1156 if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) { 1192 /* Browse the rectangle list to redraw */
1157 1193 if (wind_get
1158 while (todo[2] && todo[3]) { 1194 (winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2],
1159 1195 &todo[3]) != 0) {
1160 if (rc_intersect((GRECT *)inside,(GRECT *)todo)) { 1196
1161 todo[2] += todo[0]-1; 1197 while (todo[2] && todo[3]) {
1162 todo[3] += todo[1]-1; 1198
1163 refresh_window(this, winhandle, todo); 1199 if (rc_intersect ((GRECT *) inside, (GRECT *) todo)) {
1164 } 1200 todo[2] += todo[0] - 1;
1165 1201 todo[3] += todo[1] - 1;
1166 if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) { 1202 refresh_window (this, winhandle, todo);
1167 break; 1203 }
1168 } 1204
1169 } 1205 if (wind_get
1170 1206 (winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2],
1171 } 1207 &todo[3]) == 0) {
1172 1208 break;
1173 /* Update finished */ 1209 }
1174 wind_update(END_UPDATE); 1210 }
1175 1211
1176 v_show_c(VDI_handle,1); 1212 }
1177 } 1213
1178 1214 /* Update finished */
1179 static void refresh_window(_THIS, int winhandle, short *rect) 1215 wind_update (END_UPDATE);
1180 { 1216
1181 MFDB mfdb_src; 1217 v_show_c (VDI_handle, 1);
1182 short pxy[8],wind_pxy[8]; 1218 }
1183 SDL_Surface *surface; 1219
1184 int iconified; 1220 static void
1185 1221 refresh_window (_THIS, int winhandle, short *rect)
1186 /* Is window iconified ? */ 1222 {
1187 iconified = 0; 1223 MFDB mfdb_src;
1188 /* if (GEM_wfeatures & (1<<WF_ICONIFY))*/ { 1224 short pxy[8], wind_pxy[8];
1189 if (wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])!=0) { 1225 SDL_Surface *surface;
1190 iconified = wind_pxy[0]; 1226 int iconified;
1191 } 1227
1192 } 1228 /* Is window iconified ? */
1193 1229 iconified = 0;
1194 if (wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) { 1230 /* if (GEM_wfeatures & (1<<WF_ICONIFY))*/
1195 return; 1231 {
1196 } 1232 if (wind_get
1197 1233 (winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
1198 if (iconified && GEM_icon) { 1234 &wind_pxy[3]) != 0) {
1199 short icon_rect[4], dst_rect[4]; 1235 iconified = wind_pxy[0];
1200 short iconx,icony; 1236 }
1201 1237 }
1202 surface = GEM_icon; 1238
1203 1239 if (wind_get
1204 GEM_ClearRect(this, rect); 1240 (winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2],
1205 1241 &wind_pxy[3]) == 0) {
1206 /* Calculate centered icon(x,y,w,h) relative to window */ 1242 return;
1207 iconx = (wind_pxy[2]-surface->w)>>1; 1243 }
1208 icony = (wind_pxy[3]-surface->h)>>1; 1244
1209 1245 if (iconified && GEM_icon) {
1210 icon_rect[0] = iconx; 1246 short icon_rect[4], dst_rect[4];
1211 icon_rect[1] = icony; 1247 short iconx, icony;
1212 icon_rect[2] = surface->w; 1248
1213 icon_rect[3] = surface->h; 1249 surface = GEM_icon;
1214 1250
1215 /* Calculate redraw rectangle(x,y,w,h) relative to window */ 1251 GEM_ClearRect (this, rect);
1216 dst_rect[0] = rect[0]-wind_pxy[0]; 1252
1217 dst_rect[1] = rect[1]-wind_pxy[1]; 1253 /* Calculate centered icon(x,y,w,h) relative to window */
1218 dst_rect[2] = rect[2]-rect[0]+1; 1254 iconx = (wind_pxy[2] - surface->w) >> 1;
1219 dst_rect[3] = rect[3]-rect[1]+1; 1255 icony = (wind_pxy[3] - surface->h) >> 1;
1220 1256
1221 /* Does the icon rectangle must be redrawn ? */ 1257 icon_rect[0] = iconx;
1222 if (!rc_intersect((GRECT *)icon_rect, (GRECT *)dst_rect)) { 1258 icon_rect[1] = icony;
1223 return; 1259 icon_rect[2] = surface->w;
1224 } 1260 icon_rect[3] = surface->h;
1225 1261
1262 /* Calculate redraw rectangle(x,y,w,h) relative to window */
1263 dst_rect[0] = rect[0] - wind_pxy[0];
1264 dst_rect[1] = rect[1] - wind_pxy[1];
1265 dst_rect[2] = rect[2] - rect[0] + 1;
1266 dst_rect[3] = rect[3] - rect[1] + 1;
1267
1268 /* Does the icon rectangle must be redrawn ? */
1269 if (!rc_intersect ((GRECT *) icon_rect, (GRECT *) dst_rect)) {
1270 return;
1271 }
1226 #if DEBUG_VIDEO_GEM 1272 #if DEBUG_VIDEO_GEM
1227 printf("sdl:video:gem: clip(0,0,%d,%d) to (%d,%d,%d,%d)\n", 1273 printf ("sdl:video:gem: clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
1228 surface->w-1,surface->h-1, dst_rect[0],dst_rect[1],dst_rect[2],dst_rect[3]); 1274 surface->w - 1, surface->h - 1, dst_rect[0], dst_rect[1],
1229 printf("sdl:video:gem: icon(%d,%d,%d,%d)\n", 1275 dst_rect[2], dst_rect[3]);
1230 icon_rect[0], icon_rect[1], icon_rect[2], icon_rect[3]); 1276 printf ("sdl:video:gem: icon(%d,%d,%d,%d)\n", icon_rect[0],
1231 printf("sdl:video:gem: refresh_window(): draw icon\n"); 1277 icon_rect[1], icon_rect[2], icon_rect[3]);
1232 #endif 1278 printf ("sdl:video:gem: refresh_window(): draw icon\n");
1233 1279 #endif
1234 /* Calculate icon(x1,y1,x2,y2) relative to screen */ 1280
1235 icon_rect[0] += wind_pxy[0]; 1281 /* Calculate icon(x1,y1,x2,y2) relative to screen */
1236 icon_rect[1] += wind_pxy[1]; 1282 icon_rect[0] += wind_pxy[0];
1237 icon_rect[2] += icon_rect[0]-1; 1283 icon_rect[1] += wind_pxy[1];
1238 icon_rect[3] += icon_rect[1]-1; 1284 icon_rect[2] += icon_rect[0] - 1;
1239 1285 icon_rect[3] += icon_rect[1] - 1;
1240 /* Calculate intersection rectangle to redraw */ 1286
1241 pxy[4]=pxy[0]=MAX(icon_rect[0],rect[0]); 1287 /* Calculate intersection rectangle to redraw */
1242 pxy[5]=pxy[1]=MAX(icon_rect[1],rect[1]); 1288 pxy[4] = pxy[0] = MAX (icon_rect[0], rect[0]);
1243 pxy[6]=pxy[2]=MIN(icon_rect[2],rect[2]); 1289 pxy[5] = pxy[1] = MAX (icon_rect[1], rect[1]);
1244 pxy[7]=pxy[3]=MIN(icon_rect[3],rect[3]); 1290 pxy[6] = pxy[2] = MIN (icon_rect[2], rect[2]);
1245 1291 pxy[7] = pxy[3] = MIN (icon_rect[3], rect[3]);
1246 /* Calculate icon source image pos relative to window */ 1292
1247 pxy[0] -= wind_pxy[0]+iconx; 1293 /* Calculate icon source image pos relative to window */
1248 pxy[1] -= wind_pxy[1]+icony; 1294 pxy[0] -= wind_pxy[0] + iconx;
1249 pxy[2] -= wind_pxy[0]+iconx; 1295 pxy[1] -= wind_pxy[1] + icony;
1250 pxy[3] -= wind_pxy[1]+icony; 1296 pxy[2] -= wind_pxy[0] + iconx;
1251 1297 pxy[3] -= wind_pxy[1] + icony;
1252 } else { 1298
1253 surface = this->screen; 1299 } else {
1300 surface = this->screen;
1254 1301
1255 #if DEBUG_VIDEO_GEM 1302 #if DEBUG_VIDEO_GEM
1256 printf("sdl:video:gem: refresh_window(): draw frame buffer\n"); 1303 printf ("sdl:video:gem: refresh_window(): draw frame buffer\n");
1257 #endif 1304 #endif
1258 1305
1259 /* Redraw all window content */ 1306 /* Redraw all window content */
1260 pxy[0] = rect[0]-wind_pxy[0]; 1307 pxy[0] = rect[0] - wind_pxy[0];
1261 pxy[1] = rect[1]-wind_pxy[1]; 1308 pxy[1] = rect[1] - wind_pxy[1];
1262 pxy[2] = rect[2]-wind_pxy[0]; 1309 pxy[2] = rect[2] - wind_pxy[0];
1263 pxy[3] = rect[3]-wind_pxy[1]; 1310 pxy[3] = rect[3] - wind_pxy[1];
1264 1311
1265 pxy[4] = rect[0]; 1312 pxy[4] = rect[0];
1266 pxy[5] = rect[1]; 1313 pxy[5] = rect[1];
1267 pxy[6] = rect[2]; 1314 pxy[6] = rect[2];
1268 pxy[7] = rect[3]; 1315 pxy[7] = rect[3];
1269 } 1316 }
1270 1317
1271 if (GEM_bufops & B2S_C2P_1TO2) { 1318 if (GEM_bufops & B2S_C2P_1TO2) {
1272 void *src, *dest; 1319 void *src, *dest;
1273 int x1,x2; 1320 int x1, x2;
1274 1321
1275 x1 = (rect[0]-wind_pxy[0]) & ~15; 1322 x1 = (rect[0] - wind_pxy[0]) & ~15;
1276 x2 = rect[2]-wind_pxy[0]; 1323 x2 = rect[2] - wind_pxy[0];
1277 if (x2 & 15) { 1324 if (x2 & 15) {
1278 x2 = (x2 | 15) +1; 1325 x2 = (x2 | 15) + 1;
1279 } 1326 }
1280 1327
1281 src = surface->pixels; 1328 src = surface->pixels;
1282 src += surface->pitch * (rect[1]-wind_pxy[1]); 1329 src += surface->pitch * (rect[1] - wind_pxy[1]);
1283 src += x1; 1330 src += x1;
1284 1331
1285 dest = GEM_buffer2; 1332 dest = GEM_buffer2;
1286 dest += surface->pitch * (rect[1]-wind_pxy[1]); 1333 dest += surface->pitch * (rect[1] - wind_pxy[1]);
1287 dest += x1; 1334 dest += x1;
1288 1335
1289 SDL_Atari_C2pConvert( 1336 SDL_Atari_C2pConvert (src, dest,
1290 src, dest, 1337 x2 - x1, rect[3] - rect[1] + 1,
1291 x2-x1, rect[3]-rect[1]+1, 1338 SDL_FALSE, surface->pitch, surface->pitch);
1292 SDL_FALSE, 1339 }
1293 surface->pitch, surface->pitch 1340
1294 ); 1341 mfdb_src.fd_addr = surface->pixels;
1295 } 1342 {
1296 1343 int width;
1297 mfdb_src.fd_addr=surface->pixels; 1344
1298 { 1345 /* Need to be a multiple of 16 pixels */
1299 int width; 1346 width = surface->w;
1300 1347 if ((width & 15) != 0) {
1301 /* Need to be a multiple of 16 pixels */ 1348 width = (width | 15) + 1;
1302 width=surface->w; 1349 }
1303 if ((width & 15) != 0) { 1350 mfdb_src.fd_w = width;
1304 width = (width | 15) + 1; 1351 }
1305 } 1352 mfdb_src.fd_h = surface->h;
1306 mfdb_src.fd_w=width; 1353 mfdb_src.fd_nplanes = surface->format->BitsPerPixel;
1307 } 1354 mfdb_src.fd_wdwidth = mfdb_src.fd_w >> 4;
1308 mfdb_src.fd_h=surface->h; 1355 mfdb_src.fd_stand = mfdb_src.fd_r1 = mfdb_src.fd_r2 = mfdb_src.fd_r3 = 0;
1309 mfdb_src.fd_nplanes=surface->format->BitsPerPixel; 1356
1310 mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4; 1357 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
1311 mfdb_src.fd_stand= 1358 mfdb_src.fd_addr = GEM_buffer2;
1312 mfdb_src.fd_r1= 1359 }
1313 mfdb_src.fd_r2=
1314 mfdb_src.fd_r3= 0;
1315
1316 if (GEM_bufops & B2S_VROCPYFM_2TOS) {
1317 mfdb_src.fd_addr=GEM_buffer2;
1318 }
1319
1320 #if DEBUG_VIDEO_GEM 1360 #if DEBUG_VIDEO_GEM
1321 printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n", 1361 printf ("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
1322 surface->w, surface->h, 1362 surface->w, surface->h,
1323 pxy[0],pxy[1],pxy[2],pxy[3], 1363 pxy[0], pxy[1], pxy[2], pxy[3], pxy[4], pxy[5], pxy[6], pxy[7]);
1324 pxy[4],pxy[5],pxy[6],pxy[7] 1364 #endif
1325 ); 1365
1326 #endif 1366 vro_cpyfm (VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
1327
1328 vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
1329 } 1367 }
1330 1368
1331 #if SDL_VIDEO_OPENGL 1369 #if SDL_VIDEO_OPENGL
1332 1370
1333 static void GEM_GL_SwapBuffers(_THIS) 1371 static void
1334 { 1372 GEM_GL_SwapBuffers (_THIS)
1335 SDL_AtariGL_SwapBuffers(this); 1373 {
1336 GEM_FlipHWSurface(this, this->screen); 1374 SDL_AtariGL_SwapBuffers (this);
1337 } 1375 GEM_FlipHWSurface (this, this->screen);
1338 1376 }
1339 #endif 1377
1378 #endif
1379 /* vi: set ts=4 sw=4 expandtab: */