src/video/gem/SDL_gemvideo.c
author Patrice Mandin <patmandin@gmail.com>
Thu, 05 Aug 2004 19:50:06 +0000
changeset 924 6e81ce1372d1
parent 923 2748679027ff
child 925 15ff92ae7e1b
permissions -rw-r--r--
Too much backslash-n at end of line
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /*
    29 	GEM video driver
    30 
    31 	Patrice Mandin
    32 	and work from
    33 	Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
    34 */
    35 
    36 #include <stdio.h>
    37 #include <stdlib.h>
    38 #include <string.h>
    39 
    40 /* Mint includes */
    41 #include <gem.h>
    42 #include <gemx.h>
    43 #include <mint/osbind.h>
    44 #include <mint/cookie.h>
    45 
    46 #include "SDL.h"
    47 #include "SDL_error.h"
    48 #include "SDL_video.h"
    49 #include "SDL_mouse.h"
    50 #include "SDL_sysvideo.h"
    51 #include "SDL_pixels_c.h"
    52 #include "SDL_events_c.h"
    53 #include "SDL_cursor_c.h"
    54 
    55 #include "SDL_ataric2p_s.h"
    56 #include "SDL_atarieddi_s.h"
    57 #include "SDL_atarimxalloc_c.h"
    58 #include "SDL_gemvideo.h"
    59 #include "SDL_gemevents_c.h"
    60 #include "SDL_gemmouse_c.h"
    61 #include "SDL_gemwm_c.h"
    62 #include "SDL_xbiosevents_c.h"
    63 
    64 /* Defines */
    65 
    66 /* #define DEBUG_VIDEO_GEM	1 */
    67 
    68 #define GEM_VID_DRIVER_NAME "gem"
    69 
    70 #undef MIN
    71 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
    72 #undef MAX
    73 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
    74 
    75 /* Variables */
    76 
    77 static unsigned char vdi_index[256] = {
    78 	0,  2,  3,  6,  4,  7,  5,   8,
    79 	9, 10, 11, 14, 12, 15, 13, 255
    80 };
    81 
    82 static const unsigned char empty_name[]="";
    83 
    84 /* Initialization/Query functions */
    85 static int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat);
    86 static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
    87 static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    88 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
    89 static void GEM_VideoQuit(_THIS);
    90 
    91 /* Hardware surface functions */
    92 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface);
    93 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface);
    94 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface);
    95 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface);
    96 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface);
    97 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
    98 #if 0
    99 static int GEM_ToggleFullScreen(_THIS, int on);
   100 #endif
   101 
   102 /* Internal functions */
   103 static void GEM_FreeBuffers(_THIS);
   104 static void GEM_ClearScreen(_THIS);
   105 static void GEM_ClearRect(_THIS, short *rect);
   106 static void GEM_LockScreen(_THIS);
   107 static void GEM_UnlockScreen(_THIS);
   108 static void refresh_window(_THIS, int winhandle, short *rect);
   109 
   110 /* GEM driver bootstrap functions */
   111 
   112 static int GEM_Available(void)
   113 {
   114 	/* Test if AES available */
   115 	if (appl_init() == -1)
   116 		return 0;
   117 
   118 	appl_exit();
   119 	return 1;
   120 }
   121 
   122 static void GEM_DeleteDevice(SDL_VideoDevice *device)
   123 {
   124 	free(device->hidden);
   125 	free(device);
   126 }
   127 
   128 static SDL_VideoDevice *GEM_CreateDevice(int devindex)
   129 {
   130 	SDL_VideoDevice *device;
   131 
   132 	/* Initialize all variables that we clean on shutdown */
   133 	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
   134 	if ( device ) {
   135 		memset(device, 0, (sizeof *device));
   136 		device->hidden = (struct SDL_PrivateVideoData *)
   137 				malloc((sizeof *device->hidden));
   138 	}
   139 	if ( (device == NULL) || (device->hidden == NULL) ) {
   140 		SDL_OutOfMemory();
   141 		if ( device ) {
   142 			free(device);
   143 		}
   144 		return(0);
   145 	}
   146 	memset(device->hidden, 0, (sizeof *device->hidden));
   147 
   148 	/* Set the function pointers */
   149 	device->VideoInit = GEM_VideoInit;
   150 	device->ListModes = GEM_ListModes;
   151 	device->SetVideoMode = GEM_SetVideoMode;
   152 	device->SetColors = GEM_SetColors;
   153 	device->UpdateRects = NULL /*GEM_UpdateRects*/;
   154 	device->VideoQuit = GEM_VideoQuit;
   155 	device->AllocHWSurface = GEM_AllocHWSurface;
   156 	device->LockHWSurface = GEM_LockHWSurface;
   157 	device->UnlockHWSurface = GEM_UnlockHWSurface;
   158 	device->FlipHWSurface = GEM_FlipHWSurface;
   159 	device->FreeHWSurface = GEM_FreeHWSurface;
   160 	device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/;
   161 
   162 	/* Window manager */
   163 	device->SetCaption = GEM_SetCaption;
   164 	device->SetIcon = GEM_SetIcon;
   165 	device->IconifyWindow = GEM_IconifyWindow;
   166 	device->GrabInput = GEM_GrabInput;
   167 
   168 	/* Events */
   169 	device->InitOSKeymap = GEM_InitOSKeymap;
   170 	device->PumpEvents = GEM_PumpEvents;
   171 
   172 	/* Mouse */
   173 	device->FreeWMCursor = GEM_FreeWMCursor;
   174 	device->CreateWMCursor = GEM_CreateWMCursor;
   175 	device->ShowWMCursor = GEM_ShowWMCursor;
   176 	device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;
   177 	device->CheckMouseMode = GEM_CheckMouseMode;
   178 
   179 	/* Joystick + Mouse relative motion */
   180 	SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
   181 
   182 	device->free = GEM_DeleteDevice;
   183 
   184 	return device;
   185 }
   186 
   187 VideoBootStrap GEM_bootstrap = {
   188 	GEM_VID_DRIVER_NAME, "Atari GEM video driver",
   189 	GEM_Available, GEM_CreateDevice
   190 };
   191 
   192 static void VDI_ReadExtInfo(_THIS, short *work_out)
   193 {
   194 	unsigned long EdDI_version;
   195 	unsigned long cookie_EdDI;
   196 	Uint32 num_colours;
   197 	Uint16 clut_type, num_bits;
   198 
   199 	/* Read EdDI informations */
   200 	if  (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
   201 		return;
   202 	}
   203 	
   204 	EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI);
   205 
   206 	vq_scrninfo(VDI_handle, work_out);
   207 
   208 	VDI_format = work_out[0];
   209 	clut_type = work_out[1];
   210 	num_bits = work_out[2];
   211 	num_colours = *((Uint32 *) &work_out[3]);
   212 
   213 	/* With EdDI>=1.1, we can have screen pitch, address and format
   214 	 * so we can directly write to screen without using vro_cpyfm
   215 	 */
   216 	if (EdDI_version >= EDDI_11) {
   217 		VDI_pitch = work_out[5];
   218 		VDI_screen = (void *) *((unsigned long *) &work_out[6]);
   219 	}
   220 
   221 	switch(clut_type) {
   222 		case VDI_CLUT_HARDWARE:
   223 			{
   224 				int i;
   225 				Uint16 *tmp_p;
   226 
   227 				tmp_p = (Uint16 *)&work_out[16];
   228 
   229 				for (i=0;i<256;i++) {
   230 					vdi_index[*tmp_p++] = i;
   231 				}
   232 			}
   233 			break;
   234 		case VDI_CLUT_SOFTWARE:
   235 			{
   236 				int component; /* red, green, blue, alpha, overlay */
   237 				int num_bit;
   238 				unsigned short *tmp_p;
   239 
   240 				/* We can build masks with info here */
   241 				tmp_p = (unsigned short *) &work_out[16];
   242 				for (component=0;component<5;component++) {
   243 					for (num_bit=0;num_bit<16;num_bit++) {
   244 						unsigned short valeur;
   245 
   246 						valeur = *tmp_p++;
   247 
   248 						if (valeur == 0xffff) {
   249 							continue;
   250 						}
   251 
   252 						switch(component) {
   253 							case 0:
   254 								VDI_redmask |= 1<< valeur;
   255 								break;
   256 							case 1:
   257 								VDI_greenmask |= 1<< valeur;
   258 								break;
   259 							case 2:
   260 								VDI_bluemask |= 1<< valeur;
   261 								break;
   262 							case 3:
   263 								VDI_alphamask |= 1<< valeur;
   264 								break;
   265 						}
   266 					}
   267 				}
   268 			}
   269 
   270 			/* Remove lower green bits for Intel endian screen */
   271 			if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {
   272 				VDI_greenmask &= ~(7<<13);
   273 			}
   274 			break;
   275 		case VDI_CLUT_NONE:
   276 			break;
   277 	}
   278 }
   279 
   280 int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
   281 {
   282 	int i;
   283 	short work_in[12], work_out[272], dummy;
   284 
   285 	/* Open AES (Application Environment Services) */
   286 	if (appl_init() == -1) {
   287 		fprintf(stderr,"Can not open AES\n");
   288 		return 1;
   289 	}
   290 
   291 	/* Read version and features */
   292 	GEM_version = aes_global[0];
   293 	if (GEM_version >= 0x0410) {
   294 		short ap_gout[4], errorcode;
   295 		
   296 #ifdef DEBUG_VIDEO_GEM
   297 		printf("sdl:video:gem: AES %02x.%02x\n", (GEM_version>>8) & 0xff, GEM_version & 0xff);
   298 #endif
   299 
   300 		GEM_wfeatures=0;
   301 		errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
   302 #ifdef DEBUG_VIDEO_GEM
   303 		printf("sdl:video:gem: appl_getinfo() returned 0x%04x\n", errorcode);
   304 #endif
   305 
   306 		if (errorcode==0) {
   307 			GEM_wfeatures=ap_gout[0];			
   308 
   309 #ifdef DEBUG_VIDEO_GEM
   310 			printf("sdl:video:gem: AES wind_*() modes: 0x%04x\n", GEM_wfeatures);
   311 			printf("sdl:video:gem: AES window behaviours: 0x%04x\n", ap_gout[3]);
   312 		} else {
   313 			printf("sdl:video:gem: apgout[]={0x%04x,0x%04x,0x%04x,0x%04x}\n",
   314 				ap_gout[0], ap_gout[1], ap_gout[1], ap_gout[3]
   315 			);
   316 #endif
   317 		}
   318 	}	
   319 
   320 	/* Ask VDI physical workstation handle opened by AES */
   321 	VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
   322 	if (VDI_handle<1) {
   323 		fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle);
   324 		return 1;
   325 	}
   326 
   327 	/* Open virtual VDI workstation */
   328 	work_in[0]=Getrez()+2;
   329 	for(i = 1; i < 10; i++)
   330 		work_in[i] = 1;
   331 	work_in[10] = 2;
   332 
   333 	v_opnvwk(work_in, &VDI_handle, work_out);
   334 	if (VDI_handle == 0) {
   335 		fprintf(stderr,"Can not open VDI virtual workstation\n");
   336 		return 1;
   337 	}
   338 
   339 	/* Read fullscreen size */
   340 	VDI_w = work_out[0] + 1;
   341 	VDI_h = work_out[1] + 1;
   342 
   343 	/* Read desktop size and position */
   344 	if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) {
   345 		fprintf(stderr,"Can not read desktop properties\n");
   346 		return 1;
   347 	}
   348 
   349 	/* Read bit depth */
   350 	vq_extnd(VDI_handle, 1, work_out);
   351 	VDI_bpp = work_out[4];
   352 	VDI_oldnumcolors=0;
   353 
   354 	switch(VDI_bpp) {
   355 		case 8:
   356 			VDI_pixelsize=1;
   357 			break;
   358 		case 15:
   359 		case 16:
   360 			VDI_pixelsize=2;
   361 			break;
   362 		case 24:
   363 			VDI_pixelsize=3;
   364 			break;
   365 		case 32:
   366 			VDI_pixelsize=4;
   367 			break;
   368 		default:
   369 			fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp);
   370 			return 1;
   371 	}
   372 
   373 	/* Setup hardware -> VDI palette mapping */
   374 	for(i = 16; i < 255; i++) {
   375 		vdi_index[i] = i;
   376 	}
   377 	vdi_index[255] = 1;
   378 
   379 	/* Save current palette */
   380 	if (VDI_bpp>8) {
   381 		VDI_oldnumcolors=1<<8;
   382 	} else {
   383 		VDI_oldnumcolors=1<<VDI_bpp;
   384 	}
   385 	
   386 	for(i = 0; i < VDI_oldnumcolors; i++) {
   387 		short rgb[3];
   388 
   389 		vq_color(VDI_handle, i, 0, rgb);
   390 
   391 		VDI_oldpalette[i][0] = rgb[0];
   392 		VDI_oldpalette[i][1] = rgb[1];
   393 		VDI_oldpalette[i][2] = rgb[2];
   394 	}
   395 
   396 	/* Setup screen info */
   397 	GEM_title_name = empty_name;
   398 	GEM_icon_name = empty_name;
   399 
   400 	GEM_handle = -1;
   401 	GEM_locked = SDL_FALSE;
   402 	GEM_win_fulled = SDL_FALSE;
   403 
   404 	VDI_screen = NULL;
   405 	VDI_pitch = VDI_w * VDI_pixelsize;
   406 	VDI_format = ( (VDI_bpp <= 8) ? VDI_FORMAT_INTER : VDI_FORMAT_PACK);
   407 	VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
   408 	VDI_ReadExtInfo(this, work_out);
   409 
   410 #ifdef DEBUG_VIDEO_GEM
   411 	printf("sdl:video:gem: screen: address=0x%08x, pitch=%d\n", VDI_screen, VDI_pitch);
   412 	printf("sdl:video:gem: format=%d\n", VDI_format);
   413 	printf("sdl:video:gem: masks: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
   414 		VDI_alphamask, VDI_redmask, VDI_greenmask, VDI_bluemask
   415 	);
   416 #endif
   417 
   418 	/* Setup destination mfdb */
   419 	VDI_dst_mfdb.fd_addr = NULL;
   420 
   421 	/* Update hardware info */
   422 	this->info.hw_available = 0;
   423 	this->info.video_mem = 0;
   424 
   425 	/* Determine the screen depth */
   426 	/* we change this during the SDL_SetVideoMode implementation... */
   427 	vformat->BitsPerPixel = VDI_bpp;
   428 
   429 	/* Set mouse cursor to arrow */
   430 	graf_mouse(ARROW, NULL);
   431 
   432 	/* Init chunky to planar routine */
   433 	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
   434 
   435 	/* Setup VDI fill functions */
   436 	vsf_color(VDI_handle,0);
   437 	vsf_interior(VDI_handle,1);
   438 	vsf_perimeter(VDI_handle,0);
   439 
   440 	/* Fill video modes list */
   441 	SDL_modelist[0] = malloc(sizeof(SDL_Rect));
   442 	SDL_modelist[0]->x = 0;
   443 	SDL_modelist[0]->y = 0;
   444 	SDL_modelist[0]->w = VDI_w;
   445 	SDL_modelist[0]->h = VDI_h;
   446 
   447 	SDL_modelist[1] = NULL;
   448 
   449 #ifdef DEBUG_VIDEO_GEM
   450 	printf("sdl:video:gem: VideoInit(): done\n");
   451 #endif
   452 
   453 	/* We're done! */
   454 	return(0);
   455 }
   456 
   457 SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   458 {
   459 	if (format->BitsPerPixel != VDI_bpp) {
   460 		return ((SDL_Rect **)NULL);
   461 	}
   462 
   463 	if (flags & SDL_FULLSCREEN) {
   464 		return (SDL_modelist);
   465 	}
   466 
   467 	return((SDL_Rect **)-1);
   468 }
   469 
   470 static void GEM_FreeBuffers(_THIS)
   471 {
   472 	/* Release buffer */
   473 	if ( GEM_buffer2 ) {
   474 		free( GEM_buffer2 );
   475 		GEM_buffer2=NULL;
   476 	}
   477 
   478 	if ( GEM_buffer1 ) {
   479 		free( GEM_buffer1 );
   480 		GEM_buffer1=NULL;
   481 	}
   482 
   483 	/* Destroy window */
   484 	if (GEM_handle>=0) {
   485 		wind_close(GEM_handle);
   486 		wind_delete(GEM_handle);
   487 		GEM_handle=-1;
   488 	}
   489 }
   490 
   491 static void GEM_ClearRect(_THIS, short *rect)
   492 {
   493 	short oldrgb[3], rgb[3]={0,0,0};
   494 
   495 	vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
   496 	vs_color(VDI_handle, vdi_index[0], rgb);
   497 
   498 	vsf_color(VDI_handle,0);
   499 	vsf_interior(VDI_handle,1);
   500 	vsf_perimeter(VDI_handle,0);
   501 	v_bar(VDI_handle, rect);
   502 
   503 	vs_color(VDI_handle, vdi_index[0], oldrgb);
   504 }
   505 
   506 static void GEM_ClearScreen(_THIS)
   507 {
   508 	short pxy[4];
   509 
   510 	v_hide_c(VDI_handle);
   511 
   512 	pxy[0] = pxy[1] = 0;
   513 	pxy[2] = VDI_w - 1;
   514 	pxy[3] = VDI_h - 1;
   515 	GEM_ClearRect(this, pxy);
   516 
   517 	v_show_c(VDI_handle, 1);
   518 }
   519 
   520 static void GEM_LockScreen(_THIS)
   521 {
   522 	if (!GEM_locked) {
   523 		/* Lock AES */
   524 		wind_update(BEG_UPDATE);
   525 		wind_update(BEG_MCTRL);
   526 		/* Reserve memory space, used to be sure of compatibility */
   527 		form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
   528 
   529 		GEM_locked=SDL_TRUE;
   530 	}
   531 }
   532 
   533 static void GEM_UnlockScreen(_THIS)
   534 {
   535 	if (GEM_locked) {
   536 		/* Restore screen memory, and send REDRAW to all apps */
   537 		form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
   538 		/* Unlock AES */
   539 		wind_update(END_MCTRL);
   540 		wind_update(END_UPDATE);
   541 
   542 		GEM_locked=SDL_FALSE;
   543 	}
   544 }
   545 
   546 SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
   547 				int width, int height, int bpp, Uint32 flags)
   548 {
   549 	int maxwidth, maxheight;
   550 	Uint32 modeflags, screensize;
   551 	SDL_bool use_shadow1, use_shadow2;
   552 
   553 	GEM_FreeBuffers(this);
   554 
   555 	/*--- Verify if asked mode can be used ---*/
   556 	if (flags & SDL_FULLSCREEN) {
   557 		maxwidth=VDI_w;
   558 		maxheight=VDI_h;
   559 	} else {
   560 		/* Windowed mode */
   561 		maxwidth=GEM_desk_w;
   562 		maxheight=GEM_desk_h;
   563 	}
   564 
   565 	/* width must be multiple of 16, for vro_cpyfm() and c2p_convert() */
   566 	if ((width & 15) != 0) {
   567 		width = (width | 15) +1;
   568 	}
   569 
   570 	if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
   571 		SDL_SetError("Couldn't find requested mode in list");
   572 		return(NULL);
   573 	}
   574 
   575 	/*--- Allocate the new pixel format for the screen ---*/
   576 	if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) {
   577 		SDL_SetError("Couldn't allocate new pixel format for requested mode");
   578 		return(NULL);
   579 	}
   580 
   581 	screensize = width * height * VDI_pixelsize;
   582 
   583 #ifdef DEBUG_VIDEO_GEM
   584 	printf("sdl:video:gem: setvideomode(): %dx%dx%d = %d\n", width, height, bpp, screensize);
   585 #endif
   586 
   587 	/*--- Allocate shadow buffers if needed, and conversion operations ---*/
   588 	GEM_bufops=0;
   589 	use_shadow1=use_shadow2=SDL_FALSE;
   590 	if (VDI_screen && (flags & SDL_FULLSCREEN)) {
   591 		if (VDI_format==VDI_FORMAT_INTER) {
   592 			use_shadow1=SDL_TRUE;
   593 			GEM_bufops = B2S_C2P_1TOS;
   594 		}
   595 	} else {
   596 		use_shadow1=SDL_TRUE;
   597 		if (VDI_format==VDI_FORMAT_PACK) {
   598 			GEM_bufops = B2S_VROCPYFM_1TOS;
   599 		} else {
   600 			use_shadow2=SDL_TRUE;
   601 			GEM_bufops = B2S_C2P_1TO2|B2S_VROCPYFM_2TOS;
   602 		}
   603 	}
   604 
   605 	if (use_shadow1) {
   606 		GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
   607 		if (GEM_buffer1==NULL) {
   608 			SDL_SetError("Unable to allocate shadow buffer");
   609 			return NULL;
   610 		}
   611 		memset(GEM_buffer1, 0, screensize);
   612 #ifdef DEBUG_VIDEO_GEM
   613 		printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
   614 #endif
   615 	}
   616 
   617 	if (use_shadow2) {
   618 		GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
   619 		if (GEM_buffer2==NULL) {
   620 			SDL_SetError("Unable to allocate shadow buffer");
   621 			return NULL;
   622 		}
   623 		memset(GEM_buffer2, 0, screensize);
   624 #ifdef DEBUG_VIDEO_GEM
   625 		printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
   626 #endif
   627 	}
   628 
   629 	/*--- Initialize screen ---*/
   630 	modeflags = 0;
   631 	if (VDI_bpp == 8) {
   632 		modeflags |= SDL_HWPALETTE;
   633 	}
   634 
   635 	if (flags & SDL_FULLSCREEN) {
   636 		GEM_LockScreen(this);
   637 
   638 		GEM_ClearScreen(this);
   639 
   640 		modeflags |= SDL_FULLSCREEN;
   641 		if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) {
   642 			modeflags |= SDL_HWSURFACE;
   643 		} else {
   644 			modeflags |= SDL_SWSURFACE;
   645 		}
   646 	} else {
   647 		short x2,y2,w2,h2;
   648 
   649 		GEM_UnlockScreen(this);
   650 
   651 		/* Set window gadgets */
   652 		if (!(flags & SDL_NOFRAME)) {
   653 			GEM_win_type=NAME|MOVER|CLOSER|SMALLER;
   654 			if (flags & SDL_RESIZABLE) {
   655 				GEM_win_type |= FULLER|SIZER;
   656 				modeflags |= SDL_RESIZABLE;
   657 			}
   658 		} else {
   659 			GEM_win_type=0;
   660 			modeflags |= SDL_NOFRAME;
   661 		}
   662 
   663 		/* Calculate window size */
   664 		if (!wind_calc(WC_BORDER, GEM_win_type, 0,0,width,height, &x2,&y2,&w2,&h2)) {
   665 			GEM_FreeBuffers(this);
   666 			SDL_SetError("Can not calculate window attributes");
   667 			return NULL;
   668 		}
   669 
   670 		/* Center window */
   671 		x2 = GEM_desk_x+((GEM_desk_w-w2)>>1);
   672 		y2 = GEM_desk_y+((GEM_desk_h-h2)>>1);
   673 
   674 		/* Create window */
   675 		GEM_handle=wind_create(GEM_win_type, x2,y2,w2,h2);
   676 		if (GEM_handle<0) {
   677 			GEM_FreeBuffers(this);
   678 			SDL_SetError("Can not create window");
   679 			return NULL;
   680 		}
   681 
   682 #ifdef DEBUG_VIDEO_GEM
   683 		printf("sdl:video:gem: handle=%d\n", GEM_handle);
   684 #endif
   685 
   686 		/* Setup window name */
   687 		wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
   688 		GEM_refresh_name = SDL_FALSE;
   689 	
   690 		/* Open the window */
   691 		wind_open(GEM_handle,x2,y2,w2,h2);
   692 
   693 		modeflags |= SDL_SWSURFACE;
   694 	}
   695 
   696 	/* Set up the new mode framebuffer */
   697 	current->flags = modeflags;
   698 	current->w = width;
   699 	current->h = height;
   700 	if (use_shadow1) {
   701 		current->pixels = GEM_buffer1;
   702 		current->pitch = width * VDI_pixelsize;
   703 	} else {
   704 		current->pixels = VDI_screen;
   705 		current->pixels += VDI_pitch * ((VDI_h - height) >> 1);
   706 		current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1);
   707 		current->pitch = VDI_pitch;
   708 	}
   709 
   710 #ifdef DEBUG_VIDEO_GEM
   711 	printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
   712 #endif
   713 
   714 	this->UpdateRects = GEM_UpdateRects;
   715 
   716 	/* We're done */
   717 	return(current);
   718 }
   719 
   720 static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
   721 {
   722 	return -1;
   723 }
   724 
   725 static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface)
   726 {
   727 	return;
   728 }
   729 
   730 static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
   731 {
   732 	return(0);
   733 }
   734 
   735 static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface)
   736 {
   737 	return;
   738 }
   739 
   740 static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
   741 {
   742 	SDL_Surface *surface;
   743 	int i, surf_width;
   744 
   745 	surface = this->screen;
   746 	/* Need to be a multiple of 16 pixels */
   747 	surf_width=surface->w;
   748 	if ((surf_width & 15) != 0) {
   749 		surf_width = (surf_width | 15) + 1;
   750 	}
   751 
   752 	if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
   753 		void *destscr;
   754 		int destpitch;
   755 
   756 		if (GEM_bufops & B2S_C2P_1TOS) {
   757 			int destx;
   758 
   759 			destscr = VDI_screen;
   760 			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
   761 			destx = (VDI_w - surf_width) >> 1;
   762 			destx &= ~15;
   763 			destscr += destx;
   764 			destpitch = VDI_pitch;
   765 		} else {
   766 			destscr = GEM_buffer2;
   767 			destpitch = surface->pitch;
   768 		}
   769 
   770 		for (i=0;i<numrects;i++) {
   771 			void *source,*destination;
   772 			int x1,x2;
   773 
   774 			x1 = rects[i].x & ~15;
   775 			x2 = rects[i].x+rects[i].w;
   776 			if (x2 & 15) {
   777 				x2 = (x2 | 15) +1;
   778 			}
   779 
   780 			source = surface->pixels;
   781 			source += surface->pitch * rects[i].y;
   782 			source += x1;
   783 
   784 			destination = destscr;
   785 			destination += destpitch * rects[i].y;
   786 			destination += x1;
   787 
   788 			SDL_Atari_C2pConvert(
   789 				source, destination,
   790 				x2-x1, rects[i].h,
   791 				SDL_FALSE,
   792 				surface->pitch, destpitch
   793 			);
   794 		}
   795 	}
   796 
   797 	if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
   798 		MFDB mfdb_src;
   799 		short blitcoords[8];
   800 
   801 		mfdb_src.fd_addr=surface->pixels;
   802 		mfdb_src.fd_w=surf_width;
   803 		mfdb_src.fd_h=surface->h;
   804 		mfdb_src.fd_wdwidth=mfdb_src.fd_w >> 4;
   805 		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   806 		mfdb_src.fd_stand=
   807 			mfdb_src.fd_r1=
   808 			mfdb_src.fd_r2=
   809 			mfdb_src.fd_r3= 0;
   810 		if (GEM_bufops & B2S_VROCPYFM_2TOS) {
   811 			mfdb_src.fd_addr=GEM_buffer2;
   812 		}
   813 
   814 		for ( i=0; i<numrects; ++i ) {
   815 			blitcoords[0] = rects[i].x;
   816 			blitcoords[1] = rects[i].y;
   817 			blitcoords[2] = blitcoords[0] + rects[i].w - 1;
   818 			blitcoords[3] = blitcoords[1] + rects[i].h - 1;
   819 
   820 			blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
   821 			blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
   822 			blitcoords[6] = blitcoords[4] + rects[i].w - 1;
   823 			blitcoords[7] = blitcoords[5] + rects[i].h - 1;
   824 
   825 			vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   826 		}
   827 	}
   828 }
   829 
   830 static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
   831 {
   832 	short pxy[4], wind_pxy[4];
   833 	int i;
   834 
   835 	if (wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
   836 		return;
   837 	}
   838 
   839 	for ( i=0; i<numrects; ++i ) {
   840 		pxy[0] = wind_pxy[0] + rects[i].x;
   841 		pxy[1] = wind_pxy[1] + rects[i].y;
   842 		pxy[2] = rects[i].w;
   843 		pxy[3] = rects[i].h;
   844 
   845 		GEM_wind_redraw(this, GEM_handle, pxy);
   846 	}
   847 }
   848 
   849 static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
   850 {
   851 	SDL_Surface *surface;
   852 
   853 	surface = this->screen;
   854 
   855 	if (surface->flags & SDL_FULLSCREEN) {
   856 		GEM_UpdateRectsFullscreen(this, numrects, rects);
   857 	} else {
   858 		GEM_UpdateRectsWindowed(this, numrects, rects);
   859 	}
   860 }
   861 
   862 static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
   863 {
   864 	int surf_width;
   865 
   866 	/* Need to be a multiple of 16 pixels */
   867 	surf_width=surface->w;
   868 	if ((surf_width & 15) != 0) {
   869 		surf_width = (surf_width | 15) + 1;
   870 	}
   871 
   872 	if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
   873 		void *destscr;
   874 		int destpitch;
   875 
   876 		if (GEM_bufops & B2S_C2P_1TOS) {
   877 			int destx;
   878 
   879 			destscr = VDI_screen;
   880 			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
   881 			destx = (VDI_w - surf_width) >> 1;
   882 			destx &= ~15;
   883 			destscr += destx;
   884 			destpitch = VDI_pitch;
   885 		} else {
   886 			destscr = GEM_buffer2;
   887 			destpitch = surface->pitch;
   888 		}
   889 
   890 		SDL_Atari_C2pConvert(
   891 			surface->pixels, destscr,
   892 			surf_width, surface->h,
   893 			SDL_FALSE,
   894 			surface->pitch, destpitch
   895 		);
   896 	}
   897 
   898 	if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
   899 		MFDB mfdb_src;
   900 		short blitcoords[8];
   901 
   902 		mfdb_src.fd_w=surf_width;
   903 		mfdb_src.fd_h=surface->h;
   904 		mfdb_src.fd_wdwidth=mfdb_src.fd_w >> 4;
   905 		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   906 		mfdb_src.fd_stand=
   907 			mfdb_src.fd_r1=
   908 			mfdb_src.fd_r2=
   909 			mfdb_src.fd_r3= 0;
   910 		if (GEM_bufops & B2S_VROCPYFM_1TOS) {
   911 			mfdb_src.fd_addr=surface->pixels;
   912 		} else {
   913 			mfdb_src.fd_addr=GEM_buffer2;
   914 		}
   915 
   916 		blitcoords[0] = 0;
   917 		blitcoords[1] = 0;
   918 		blitcoords[2] = surface->w - 1;
   919 		blitcoords[3] = surface->h - 1;
   920 
   921 		blitcoords[4] = (VDI_w - surface->w) >> 1;
   922 		blitcoords[5] = (VDI_h - surface->h) >> 1;
   923 		blitcoords[6] = blitcoords[4] + surface->w - 1;
   924 		blitcoords[7] = blitcoords[5] + surface->h - 1;
   925 
   926 		vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   927 	}
   928 
   929 	return(0);
   930 }
   931 
   932 static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface)
   933 {
   934 	short	pxy[8];
   935 
   936 	/* Update the whole window */
   937 	wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
   938 
   939 	GEM_wind_redraw(this, GEM_handle, pxy);
   940 
   941 	return(0);
   942 }
   943 
   944 static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface)
   945 {
   946 	if (surface->flags & SDL_FULLSCREEN) {
   947 		return GEM_FlipHWSurfaceFullscreen(this, surface);
   948 	} else {
   949 		return GEM_FlipHWSurfaceWindowed(this, surface);
   950 	}
   951 }
   952 
   953 static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   954 {
   955 	int i;
   956 	SDL_Surface *surface;
   957 
   958 #ifdef DEBUG_VIDEO_GEM
   959 	printf("sdl:video:gem: setcolors()\n");
   960 #endif
   961 
   962 	/* Do not change palette in True Colour */
   963 	surface = this->screen;
   964 	if (surface->format->BitsPerPixel > 8) {
   965 		return 1;
   966 	}
   967 
   968 	for(i = 0; i < ncolors; i++)
   969 	{
   970 		int		r, g, b;
   971 		short	rgb[3];
   972 
   973 		r = colors[i].r;
   974 		g = colors[i].g;
   975 		b = colors[i].b;
   976 
   977 		rgb[0] = (1000 * r) / 255;
   978 		rgb[1] = (1000 * g) / 255;
   979 		rgb[2] = (1000 * b) / 255;
   980 
   981 		vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
   982 	}
   983 
   984 	return(1);
   985 }
   986 
   987 #if 0
   988 static int GEM_ToggleFullScreen(_THIS, int on)
   989 {
   990 	if (on) {
   991 		GEM_LockScreen(this);
   992 	} else {
   993 		GEM_UnlockScreen(this);
   994 	}
   995 
   996 	return(1);
   997 }
   998 #endif
   999 
  1000 /* Note:  If we are terminated, this could be called in the middle of
  1001    another SDL video routine -- notably UpdateRects.
  1002 */
  1003 void GEM_VideoQuit(_THIS)
  1004 {
  1005 	SDL_AtariXbios_RestoreVectors();
  1006 
  1007 	GEM_FreeBuffers(this);
  1008 
  1009 	GEM_UnlockScreen(this);
  1010 
  1011 	appl_exit();
  1012 
  1013 	/* Restore palette */
  1014 	if (VDI_oldnumcolors) {
  1015 		int i;
  1016 
  1017 		for(i = 0; i < VDI_oldnumcolors; i++) {
  1018 			short	rgb[3];
  1019 
  1020 			rgb[0] = VDI_oldpalette[i][0];
  1021 			rgb[1] = VDI_oldpalette[i][1];
  1022 			rgb[2] = VDI_oldpalette[i][2];
  1023 
  1024 			vs_color(VDI_handle, i, rgb);
  1025 		}
  1026 	}
  1027 
  1028 	/* Close VDI workstation */
  1029 	if (VDI_handle) {
  1030 		v_clsvwk(VDI_handle);
  1031 	}
  1032 
  1033 	/* Free mode list */
  1034 	if (SDL_modelist[0]) {
  1035 		free(SDL_modelist[0]);
  1036 		SDL_modelist[0]=NULL;
  1037 	}
  1038 
  1039 	this->screen->pixels = NULL;	
  1040 }
  1041 
  1042 void GEM_wind_redraw(_THIS, int winhandle, short *inside)
  1043 {
  1044 	short todo[4];
  1045 
  1046 	/* Tell AES we are going to update */
  1047 	wind_update(BEG_UPDATE);
  1048 
  1049 	v_hide_c(VDI_handle);
  1050 
  1051 	/* Browse the rectangle list to redraw */
  1052 	if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
  1053 
  1054 		while (todo[2] && todo[3]) {
  1055 
  1056 			if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
  1057 				todo[2] += todo[0]-1;
  1058 				todo[3] += todo[1]-1;
  1059 				refresh_window(this, winhandle, todo);
  1060 			}
  1061 
  1062 			if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
  1063 				break;
  1064 			}
  1065 		}
  1066 
  1067 	}
  1068 
  1069 	/* Update finished */
  1070 	wind_update(END_UPDATE);
  1071 
  1072 	v_show_c(VDI_handle,1);
  1073 }
  1074 
  1075 static void refresh_window(_THIS, int winhandle, short *rect)
  1076 {
  1077 	MFDB mfdb_src;
  1078 	short pxy[8],wind_pxy[8];
  1079 	SDL_Surface *surface;
  1080 	int iconified;
  1081 
  1082 	/* Is window iconified ? */
  1083 	iconified = 0;
  1084 /*	if (GEM_wfeatures & (1<<WF_ICONIFY))*/ {
  1085 		if (wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])!=0) {
  1086 			iconified = wind_pxy[0];
  1087 		}
  1088 	}
  1089 
  1090 	if (wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
  1091 		return;
  1092 	}
  1093 
  1094 	if (iconified && GEM_icon) {
  1095 		short icon_rect[4], dst_rect[4];
  1096 		short iconx,icony;
  1097 		
  1098 		surface = GEM_icon;
  1099 
  1100 		GEM_ClearRect(this, rect);
  1101 
  1102 		/* Calculate centered icon(x,y,w,h) relative to window */
  1103 		iconx = (wind_pxy[2]-surface->w)>>1;
  1104 		icony = (wind_pxy[3]-surface->h)>>1;
  1105 
  1106 		icon_rect[0] = iconx;
  1107 		icon_rect[1] = icony;
  1108 		icon_rect[2] = surface->w;
  1109 		icon_rect[3] = surface->h;
  1110 
  1111 		/* Calculate redraw rectangle(x,y,w,h) relative to window */
  1112 		dst_rect[0] = rect[0]-wind_pxy[0];
  1113 		dst_rect[1] = rect[1]-wind_pxy[1];
  1114 		dst_rect[2] = rect[2]-rect[0]+1;
  1115 		dst_rect[3] = rect[3]-rect[1]+1;
  1116 
  1117 		/* Does the icon rectangle must be redrawn ? */
  1118 		if (!rc_intersect((GRECT *)icon_rect, (GRECT *)dst_rect)) {
  1119 			return;
  1120 		}
  1121 
  1122 #if DEBUG_VIDEO_GEM
  1123 		printf("sdl:video:gem:  clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
  1124 			surface->w-1,surface->h-1, dst_rect[0],dst_rect[1],dst_rect[2],dst_rect[3]);
  1125 		printf("sdl:video:gem:  icon(%d,%d,%d,%d)\n",
  1126 			icon_rect[0], icon_rect[1], icon_rect[2], icon_rect[3]);
  1127 		printf("sdl:video:gem: refresh_window(): draw icon\n");
  1128 #endif
  1129 
  1130 		/* Calculate icon(x1,y1,x2,y2) relative to screen */
  1131 		icon_rect[0] += wind_pxy[0];
  1132 		icon_rect[1] += wind_pxy[1];
  1133 		icon_rect[2] += icon_rect[0]-1;
  1134 		icon_rect[3] += icon_rect[1]-1;
  1135 
  1136 		/* Calculate intersection rectangle to redraw */
  1137 		pxy[4]=pxy[0]=MAX(icon_rect[0],rect[0]);
  1138 		pxy[5]=pxy[1]=MAX(icon_rect[1],rect[1]);
  1139  		pxy[6]=pxy[2]=MIN(icon_rect[2],rect[2]);
  1140 	 	pxy[7]=pxy[3]=MIN(icon_rect[3],rect[3]);
  1141 
  1142 		/* Calculate icon source image pos relative to window */
  1143 		pxy[0] -= wind_pxy[0]+iconx;
  1144 		pxy[1] -= wind_pxy[1]+icony;
  1145 		pxy[2] -= wind_pxy[0]+iconx;
  1146 		pxy[3] -= wind_pxy[1]+icony;
  1147 
  1148 	} else {
  1149 		surface = this->screen;
  1150 
  1151 #if DEBUG_VIDEO_GEM
  1152 		printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
  1153 #endif
  1154 
  1155 		/* Redraw all window content */
  1156 		pxy[0] = rect[0]-wind_pxy[0];
  1157 		pxy[1] = rect[1]-wind_pxy[1];
  1158 	 	pxy[2] = rect[2]-wind_pxy[0];   
  1159 	 	pxy[3] = rect[3]-wind_pxy[1];  
  1160 
  1161 		pxy[4] = rect[0];
  1162 		pxy[5] = rect[1];
  1163 		pxy[6] = rect[2];  
  1164 		pxy[7] = rect[3];
  1165 	}
  1166 
  1167 	if (GEM_bufops & B2S_C2P_1TO2) {
  1168 		void *src, *dest;
  1169 		int x1,x2;
  1170 
  1171 		x1 = (rect[0]-wind_pxy[0]) & ~15;
  1172 		x2 = rect[2]-wind_pxy[0];
  1173 		if (x2 & 15) {
  1174 			x2 = (x2 | 15) +1;
  1175 		}
  1176 
  1177 		src = surface->pixels;
  1178 		src += surface->pitch * (rect[1]-wind_pxy[1]);
  1179 		src += x1;
  1180 
  1181 		dest = GEM_buffer2;
  1182 		dest += surface->pitch * (rect[1]-wind_pxy[1]);
  1183 		dest += x1;
  1184 
  1185 		SDL_Atari_C2pConvert(
  1186 			src, dest,
  1187 			x2-x1, rect[3]-rect[1]+1,
  1188 			SDL_FALSE,
  1189 			surface->pitch, surface->pitch
  1190 		);
  1191 	}
  1192 
  1193 	mfdb_src.fd_addr=surface->pixels;
  1194 	{
  1195 		int width;
  1196 
  1197 		/* Need to be a multiple of 16 pixels */
  1198 		width=surface->w;
  1199 		if ((width & 15) != 0) {
  1200 			width = (width | 15) + 1;
  1201 		}
  1202 		mfdb_src.fd_w=width;
  1203 	}
  1204 	mfdb_src.fd_h=surface->h;
  1205   	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
  1206 	mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
  1207 	mfdb_src.fd_stand=
  1208 		mfdb_src.fd_r1=
  1209   		mfdb_src.fd_r2=
  1210 	  	mfdb_src.fd_r3= 0;
  1211 
  1212 	if (GEM_bufops & B2S_VROCPYFM_2TOS) {
  1213 		mfdb_src.fd_addr=GEM_buffer2;
  1214 	}
  1215 
  1216 #if DEBUG_VIDEO_GEM
  1217 	printf("sdl:video:gem: redraw %dx%d: (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
  1218 		surface->w, surface->h,
  1219 		pxy[0],pxy[1],pxy[2],pxy[3],
  1220 		pxy[4],pxy[5],pxy[6],pxy[7]
  1221 	);
  1222 #endif
  1223 
  1224 	vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
  1225 }