Use new C2P routine + corrections for iconification window
authorPatrice Mandin <patmandin@gmail.com>
Wed, 12 Nov 2003 18:49:29 +0000
changeset 736028e03e273c8
parent 735 abec2a842d11
child 737 7e4347dd2f9c
Use new C2P routine + corrections for iconification window
src/video/gem/SDL_gemevents.c
src/video/gem/SDL_gemmouse.c
src/video/gem/SDL_gemvideo.c
src/video/gem/SDL_gemvideo.h
src/video/gem/SDL_gemwm.c
     1.1 --- a/src/video/gem/SDL_gemevents.c	Wed Nov 12 18:46:48 2003 +0000
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Wed Nov 12 18:49:29 2003 +0000
     1.3 @@ -219,6 +219,11 @@
     1.4  				/* Send an internal deactivate event */
     1.5  				SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
     1.6  			}
     1.7 +			/* Update window title */
     1.8 +			if (GEM_refresh_name && GEM_icon_name) {
     1.9 +				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
    1.10 +				GEM_refresh_name = SDL_FALSE;
    1.11 +			}
    1.12  			break;
    1.13  		case WM_UNICONIFY:
    1.14  			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
    1.15 @@ -227,6 +232,10 @@
    1.16  				/* Send an internal activate event */
    1.17  				SDL_PrivateAppActive(1, SDL_APPACTIVE);
    1.18  			}
    1.19 +			if (GEM_refresh_name && GEM_title_name) {
    1.20 +				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
    1.21 +				GEM_refresh_name = SDL_FALSE;
    1.22 +			}
    1.23  			break;
    1.24  		case WM_SIZED:
    1.25  			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
     2.1 --- a/src/video/gem/SDL_gemmouse.c	Wed Nov 12 18:46:48 2003 +0000
     2.2 +++ b/src/video/gem/SDL_gemmouse.c	Wed Nov 12 18:49:29 2003 +0000
     2.3 @@ -43,6 +43,8 @@
     2.4  
     2.5  /* Defines */
     2.6  
     2.7 +/*#define DEBUG_VIDEO_GEM 1*/
     2.8 +
     2.9  #define MAXCURWIDTH 16
    2.10  #define MAXCURHEIGHT 16
    2.11  
    2.12 @@ -102,36 +104,46 @@
    2.13  	new_mform->mf_fg = 0;
    2.14  	new_mform->mf_bg = 1;
    2.15  
    2.16 -	for (i=0;i<MAXCURHEIGHT;i++)
    2.17 -	{
    2.18 +	for (i=0;i<MAXCURHEIGHT;i++) {
    2.19  		new_mform->mf_mask[i]=0;
    2.20  		new_mform->mf_data[i]=0;
    2.21  	}
    2.22  
    2.23  	if (w<=8) {
    2.24 -		for (i=0;i<h;i++)
    2.25 -		{
    2.26 +		for (i=0;i<h;i++) {
    2.27  			new_mform->mf_mask[i]= mask[i]<<8;
    2.28  			new_mform->mf_data[i]= data[i]<<8;
    2.29  		}
    2.30  	} else {
    2.31 -		for (i=0;i<h;i++)
    2.32 -		{
    2.33 +		for (i=0;i<h;i++) {
    2.34  			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
    2.35  			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
    2.36  		}
    2.37  	}
    2.38  
    2.39 +#ifdef DEBUG_VIDEO_GEM
    2.40 +	for (i=0; i<h ;i++) {
    2.41 +		printf("sdl:video:gem: cursor, line %d = 0x%04x\n", i, new_mform->mf_mask[i]);
    2.42 +	}
    2.43 +
    2.44 +	printf("sdl:video:gem: CreateWMCursor(): done\n");
    2.45 +#endif
    2.46 +
    2.47  	return cursor;
    2.48  }
    2.49  
    2.50  int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
    2.51  {
    2.52 +/*
    2.53  	if (cursor == NULL) {
    2.54  		graf_mouse(M_OFF, NULL);
    2.55  	} else if (cursor->mform_p) {
    2.56  		graf_mouse(USER_DEF, cursor->mform_p);
    2.57  	}
    2.58 +*/
    2.59 +#ifdef DEBUG_VIDEO_GEM
    2.60 +	printf("sdl:video:gem: ShowWMCursor(0x%08x)\n", (long) cursor);
    2.61 +#endif
    2.62  
    2.63  	return 1;
    2.64  }
     3.1 --- a/src/video/gem/SDL_gemvideo.c	Wed Nov 12 18:46:48 2003 +0000
     3.2 +++ b/src/video/gem/SDL_gemvideo.c	Wed Nov 12 18:49:29 2003 +0000
     3.3 @@ -26,13 +26,12 @@
     3.4  #endif
     3.5  
     3.6  /*
     3.7 - * GEM SDL video driver implementation
     3.8 - * inspired from the Dummy SDL driver
     3.9 - * 
    3.10 - * Patrice Mandin
    3.11 - * and work from
    3.12 - * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
    3.13 - */
    3.14 +	GEM video driver
    3.15 +
    3.16 +	Patrice Mandin
    3.17 +	and work from
    3.18 +	Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
    3.19 +*/
    3.20  
    3.21  #include <stdio.h>
    3.22  #include <stdlib.h>
    3.23 @@ -54,7 +53,6 @@
    3.24  #include "SDL_cursor_c.h"
    3.25  
    3.26  #include "SDL_ataric2p_s.h"
    3.27 -#include "SDL_ataric2p060_c.h"
    3.28  #include "SDL_atarieddi_s.h"
    3.29  #include "SDL_atarimxalloc_c.h"
    3.30  #include "SDL_gemvideo.h"
    3.31 @@ -65,6 +63,8 @@
    3.32  
    3.33  /* Defines */
    3.34  
    3.35 +/*#define DEBUG_VIDEO_GEM	1*/
    3.36 +
    3.37  #define GEM_VID_DRIVER_NAME "gem"
    3.38  
    3.39  /* Variables */
    3.40 @@ -97,6 +97,7 @@
    3.41  /* Internal functions */
    3.42  static void GEM_FreeBuffers(_THIS);
    3.43  static void GEM_ClearScreen(_THIS);
    3.44 +static void GEM_ClearRect(_THIS, short *rect);
    3.45  static void GEM_LockScreen(_THIS);
    3.46  static void GEM_UnlockScreen(_THIS);
    3.47  static void refresh_window(_THIS, int winhandle, short *rect);
    3.48 @@ -139,8 +140,6 @@
    3.49  	}
    3.50  	memset(device->hidden, 0, (sizeof *device->hidden));
    3.51  
    3.52 -	atari_test_cpu060_present();
    3.53 -
    3.54  	/* Set the function pointers */
    3.55  	device->VideoInit = GEM_VideoInit;
    3.56  	device->ListModes = GEM_ListModes;
    3.57 @@ -157,7 +156,7 @@
    3.58  
    3.59  	/* Window manager */
    3.60  	device->SetCaption = GEM_SetCaption;
    3.61 -	device->SetIcon = NULL /*GEM_SetIcon*/;
    3.62 +	device->SetIcon = GEM_SetIcon;
    3.63  	device->IconifyWindow = GEM_IconifyWindow;
    3.64  	device->GrabInput = GEM_GrabInput;
    3.65  
    3.66 @@ -218,48 +217,26 @@
    3.67  				if (work_out[14] & (1<<7)) {
    3.68  					/* Little endian */
    3.69  					if (work_out[14] & (1<<1)) {
    3.70 -						/* Falcon */
    3.71 -						VDI_alphamask = 1 << 13;
    3.72 -						VDI_redmask = 31 << 3;
    3.73 -						VDI_greenmask = (3 << 14) | 7;
    3.74 -						VDI_bluemask = 31 << 8;
    3.75 +						VDI_FBMASK(1<<13, 31<<3, (3<<14)|7, 31<<8);
    3.76  					} else {
    3.77 -						/* Others */
    3.78 -						VDI_alphamask = 1 << 7;
    3.79 -						VDI_redmask = 31 << 2;
    3.80 -						VDI_greenmask = (7 << 13) | 3;
    3.81 -						VDI_bluemask = 31 << 8;
    3.82 +						VDI_FBMASK(1<<7, 31<<2, (7<<13)|3, 31<<8);
    3.83  					}
    3.84  				} else {
    3.85  					/* Big endian */
    3.86  					if (work_out[14] & (1<<1)) {
    3.87 -						/* Falcon */
    3.88 -						VDI_alphamask = 1 << 5;
    3.89 -						VDI_redmask = 31 << 11;
    3.90 -						VDI_greenmask = 31 << 6;
    3.91 -						VDI_bluemask = 31;
    3.92 +						VDI_FBMASK(1<<5, 31<<11, 31<<6, 31);
    3.93  					} else {
    3.94 -						/* Others */
    3.95 -						VDI_alphamask = 1 << 15;
    3.96 -						VDI_redmask = 31 << 10;
    3.97 -						VDI_greenmask = 31 << 5;
    3.98 -						VDI_bluemask = 31;
    3.99 +						VDI_FBMASK(1<<15, 31<<10, 31<<5, 31);
   3.100  					}
   3.101  				}
   3.102  				break;
   3.103  			case 65536UL:
   3.104  				if (work_out[14] & (1<<7)) {
   3.105  					/* Little endian */
   3.106 -					VDI_alphamask = 0;
   3.107 -					VDI_redmask = 31 << 3;
   3.108 -					VDI_greenmask = (7 << 13) | 7;
   3.109 -					VDI_bluemask = 31 << 8;
   3.110 +					VDI_FBMASK(0, 31<<3, (7<<13)|7, 31<<8);
   3.111  				} else {
   3.112  					/* Big endian */
   3.113 -					VDI_alphamask = 0;
   3.114 -					VDI_redmask = 31 << 11;
   3.115 -					VDI_greenmask = 63 << 5;
   3.116 -					VDI_bluemask = 31;
   3.117 +					VDI_FBMASK(0, 31<<11, 63<<5, 31);
   3.118  				}
   3.119  				break;
   3.120  			case 16777216UL:
   3.121 @@ -267,32 +244,20 @@
   3.122  					/* Little endian */
   3.123  					switch(num_bits) {
   3.124  						case 24:
   3.125 -							VDI_alphamask = 0;
   3.126 -							VDI_redmask = 255;
   3.127 -							VDI_greenmask = 255 << 8;
   3.128 -							VDI_bluemask = 255 << 16;
   3.129 +							VDI_FBMASK(0, 255, 255<<8, 255<<16);
   3.130  							break;
   3.131  						case 32:
   3.132 -							VDI_alphamask = 255;
   3.133 -							VDI_redmask = 255 << 8;
   3.134 -							VDI_greenmask = 255 << 16;
   3.135 -							VDI_bluemask = 255 << 24;
   3.136 +							VDI_FBMASK(255, 255<<8, 255<<16, 255<<24);
   3.137  							break;
   3.138  					}
   3.139  				} else {
   3.140  					/* Big endian */
   3.141  					switch(num_bits) {
   3.142  						case 24:
   3.143 -							VDI_alphamask = 0;
   3.144 -							VDI_redmask = 255 << 16;
   3.145 -							VDI_greenmask = 255 << 8;
   3.146 -							VDI_bluemask = 255;
   3.147 +							VDI_FBMASK(0, 255<<16, 255<<8, 255);
   3.148  							break;
   3.149  						case 32:
   3.150 -							VDI_alphamask = 255 << 24;
   3.151 -							VDI_redmask = 255 << 16;
   3.152 -							VDI_greenmask = 255 << 8;
   3.153 -							VDI_bluemask = 255;
   3.154 +							VDI_FBMASK(255<<24, 255<<16, 255<<8, 255);
   3.155  							break;
   3.156  					}
   3.157  				}
   3.158 @@ -371,13 +336,31 @@
   3.159  	}
   3.160  
   3.161  	/* Read version and features */
   3.162 -	GEM_version = aes_params.global[0];
   3.163 -	if (GEM_version >= 0x0400) {
   3.164 -		short ap_gout[4];
   3.165 +	GEM_version = aes_global[0];
   3.166 +	if (GEM_version >= 0x0410) {
   3.167 +		short ap_gout[4], errorcode;
   3.168  		
   3.169 +#ifdef DEBUG_VIDEO_GEM
   3.170 +		printf("sdl:video:gem: AES %02x.%02x\n", (GEM_version>>8) & 0xff, GEM_version & 0xff);
   3.171 +#endif
   3.172 +
   3.173  		GEM_wfeatures=0;
   3.174 -		if (appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3])==0) {
   3.175 +		errorcode=appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3]);
   3.176 +#ifdef DEBUG_VIDEO_GEM
   3.177 +		printf("sdl:video:gem: appl_getinfo() returned 0x%04x\n", errorcode);
   3.178 +#endif
   3.179 +
   3.180 +		if (errorcode==0) {
   3.181  			GEM_wfeatures=ap_gout[0];			
   3.182 +
   3.183 +#ifdef DEBUG_VIDEO_GEM
   3.184 +			printf("sdl:video:gem: AES wind_*() modes: 0x%04x\n", GEM_wfeatures);
   3.185 +			printf("sdl:video:gem: AES window behaviours: 0x%04x\n", ap_gout[3]);
   3.186 +		} else {
   3.187 +			printf("sdl:video:gem: apgout[]={0x%04x,0x%04x,0x%04x,0x%04x}\n",
   3.188 +				ap_gout[0], ap_gout[1], ap_gout[1], ap_gout[3]
   3.189 +			);
   3.190 +#endif
   3.191  		}
   3.192  	}	
   3.193  
   3.194 @@ -469,7 +452,10 @@
   3.195  	VDI_ReadExtInfo(this, work_out);
   3.196  	if (VDI_screen == NULL) {
   3.197  		VDI_pitch = VDI_w * VDI_pixelsize;
   3.198 -		VDI_format = VDI_FORMAT_UNKNOWN;
   3.199 +		VDI_format = VDI_FORMAT_PACK;
   3.200 +		if (VDI_bpp <= 8) {
   3.201 +			VDI_format = VDI_FORMAT_INTER;
   3.202 +		}
   3.203  		VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
   3.204  	}
   3.205  
   3.206 @@ -480,14 +466,6 @@
   3.207  	this->info.hw_available = 0;
   3.208  	this->info.video_mem = 0;
   3.209  
   3.210 -	/*	TC, screen : no shadow (direct)
   3.211 -     *  8P, screen: no shadow (direct)
   3.212 -     *  8I, screen: shadow, c2p (shadow -> c2p)
   3.213 -	 *  TC, no screen: shadow (vro_cpyfm)
   3.214 -	 *  8P, no screen: shadow (vro_cpyfm)
   3.215 -	 *  8I/U, no screen: shadow, shadow_c2p, c2p (shadow -> c2p -> vro_cpyfm)
   3.216 -	 */
   3.217 -
   3.218  	/* Determine the screen depth */
   3.219  	/* we change this during the SDL_SetVideoMode implementation... */
   3.220  	vformat->BitsPerPixel = VDI_bpp;
   3.221 @@ -496,13 +474,16 @@
   3.222  	graf_mouse(ARROW, NULL);
   3.223  
   3.224  	/* Init chunky to planar routine */
   3.225 -	Atari_C2pInit = Atari_C2pInit8;
   3.226 -	if (atari_cpu060_avail) {
   3.227 -		Atari_C2pConvert = Atari_C2pConvert8_060;
   3.228 -	} else {
   3.229 -		Atari_C2pConvert = Atari_C2pConvert8;
   3.230 -	}
   3.231 -	Atari_C2pInit();
   3.232 +	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
   3.233 +
   3.234 +	/* Setup VDI fill functions */
   3.235 +	vsf_color(VDI_handle,0);
   3.236 +	vsf_interior(VDI_handle,1);
   3.237 +	vsf_perimeter(VDI_handle,0);
   3.238 +
   3.239 +#ifdef DEBUG_VIDEO_GEM
   3.240 +	printf("sdl:video:gem: VideoInit(): done\n");
   3.241 +#endif
   3.242  
   3.243  	/* We're done! */
   3.244  	return(0);
   3.245 @@ -520,9 +501,14 @@
   3.246  static void GEM_FreeBuffers(_THIS)
   3.247  {
   3.248  	/* Release buffer */
   3.249 -	if ( GEM_buffer ) {
   3.250 -		free( GEM_buffer );
   3.251 -		GEM_buffer=NULL;
   3.252 +	if ( GEM_buffer2 ) {
   3.253 +		free( GEM_buffer2 );
   3.254 +		GEM_buffer2=NULL;
   3.255 +	}
   3.256 +
   3.257 +	if ( GEM_buffer1 ) {
   3.258 +		free( GEM_buffer1 );
   3.259 +		GEM_buffer1=NULL;
   3.260  	}
   3.261  
   3.262  	/* Destroy window */
   3.263 @@ -533,26 +519,31 @@
   3.264  	}
   3.265  }
   3.266  
   3.267 +static void GEM_ClearRect(_THIS, short *rect)
   3.268 +{
   3.269 +	short oldrgb[3], rgb[3]={0,0,0};
   3.270 +
   3.271 +	vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
   3.272 +	vs_color(VDI_handle, vdi_index[0], rgb);
   3.273 +
   3.274 +	vsf_color(VDI_handle,0);
   3.275 +	vsf_interior(VDI_handle,1);
   3.276 +	vsf_perimeter(VDI_handle,0);
   3.277 +	v_bar(VDI_handle, rect);
   3.278 +
   3.279 +	vs_color(VDI_handle, vdi_index[0], oldrgb);
   3.280 +}
   3.281 +
   3.282  static void GEM_ClearScreen(_THIS)
   3.283  {
   3.284 -	short rgb[3]={0,0,0};
   3.285 -	short oldrgb[3];
   3.286  	short pxy[4];
   3.287  
   3.288  	v_hide_c(VDI_handle);
   3.289  
   3.290 -	vq_color(VDI_handle, vdi_index[0], 0, oldrgb);
   3.291 -	vs_color(VDI_handle, vdi_index[0], rgb);
   3.292 -
   3.293  	pxy[0] = pxy[1] = 0;
   3.294  	pxy[2] = VDI_w - 1;
   3.295  	pxy[3] = VDI_h - 1;
   3.296 -	vsf_color(VDI_handle,0);
   3.297 -	vsf_interior(VDI_handle,1);
   3.298 -	vsf_perimeter(VDI_handle,0);
   3.299 -	v_bar(VDI_handle,pxy);
   3.300 -
   3.301 -	vs_color(VDI_handle, vdi_index[0], oldrgb);
   3.302 +	GEM_ClearRect(this, pxy);
   3.303  
   3.304  	v_show_c(VDI_handle, 1);
   3.305  }
   3.306 @@ -588,7 +579,7 @@
   3.307  {
   3.308  	int maxwidth, maxheight;
   3.309  	Uint32 modeflags, screensize;
   3.310 -	SDL_bool use_shadow;
   3.311 +	SDL_bool use_shadow1, use_shadow2;
   3.312  
   3.313  	GEM_FreeBuffers(this);
   3.314  
   3.315 @@ -613,38 +604,48 @@
   3.316  		return(NULL);
   3.317  	}
   3.318  
   3.319 -	/*--- Allocate shadow buffer if needed ---*/
   3.320 -	use_shadow=SDL_FALSE;
   3.321 -	if (flags & SDL_FULLSCREEN) {
   3.322 -		if (!VDI_screen) {
   3.323 -			/* No access to real framebuffer, use shadow surface */
   3.324 -			use_shadow=SDL_TRUE;
   3.325 -		} else {
   3.326 -			if (VDI_format==VDI_FORMAT_INTER) {
   3.327 -				/* Real framebuffer, interleaved bitplanes,
   3.328 -				  use shadow surface */
   3.329 -				use_shadow=SDL_TRUE;
   3.330 -			} else if (flags & SDL_DOUBLEBUF) {
   3.331 -				/* Real framebuffer, double-buffered,
   3.332 -				  use shadow surface */
   3.333 -				use_shadow=SDL_TRUE;
   3.334 -				modeflags |= SDL_DOUBLEBUF;
   3.335 -			}
   3.336 +	screensize = width * height * VDI_pixelsize;
   3.337 +
   3.338 +	/*--- Allocate shadow buffers if needed, and conversion operations ---*/
   3.339 +	GEM_bufops=0;
   3.340 +	use_shadow1=use_shadow2=SDL_FALSE;
   3.341 +	if (VDI_screen && (flags & SDL_FULLSCREEN)) {
   3.342 +		if (VDI_format==VDI_FORMAT_INTER) {
   3.343 +			use_shadow1=SDL_TRUE;
   3.344 +			GEM_bufops = B2S_C2P_1TOS;
   3.345  		}
   3.346  	} else {
   3.347 -		/* Windowed mode, always with shadow surface */
   3.348 -		use_shadow=SDL_TRUE;
   3.349 +		use_shadow1=SDL_TRUE;
   3.350 +		if (VDI_format==VDI_FORMAT_PACK) {
   3.351 +			GEM_bufops = B2S_VROCPYFM_1TOS;
   3.352 +		} else {
   3.353 +			use_shadow2=SDL_TRUE;
   3.354 +			GEM_bufops = B2S_C2P_1TO2|B2S_VROCPYFM_2TOS;
   3.355 +		}
   3.356  	}
   3.357  
   3.358 -	if (use_shadow) {
   3.359 -		screensize = width * height * VDI_pixelsize;
   3.360 -
   3.361 -		GEM_buffer = Atari_SysMalloc(screensize, MX_PREFTTRAM);
   3.362 -		if (GEM_buffer==NULL) {
   3.363 +	if (use_shadow1) {
   3.364 +		GEM_buffer1 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
   3.365 +		if (GEM_buffer1==NULL) {
   3.366  			fprintf(stderr,"Unable to allocate shadow buffer\n");
   3.367  			return NULL;
   3.368  		}
   3.369 -		memset(GEM_buffer, 0, screensize);
   3.370 +		memset(GEM_buffer1, 0, screensize);
   3.371 +#ifdef DEBUG_VIDEO_GEM
   3.372 +		printf("sdl:video:gem: setvideomode(): allocated buffer 1\n");
   3.373 +#endif
   3.374 +	}
   3.375 +
   3.376 +	if (use_shadow2) {
   3.377 +		GEM_buffer2 = Atari_SysMalloc(screensize, MX_PREFTTRAM);
   3.378 +		if (GEM_buffer2==NULL) {
   3.379 +			fprintf(stderr,"Unable to allocate shadow buffer\n");
   3.380 +			return NULL;
   3.381 +		}
   3.382 +		memset(GEM_buffer2, 0, screensize);
   3.383 +#ifdef DEBUG_VIDEO_GEM
   3.384 +		printf("sdl:video:gem: setvideomode(): allocated buffer 2\n");
   3.385 +#endif
   3.386  	}
   3.387  
   3.388  	/*--- Initialize screen ---*/
   3.389 @@ -659,7 +660,7 @@
   3.390  		GEM_ClearScreen(this);
   3.391  
   3.392  		modeflags |= SDL_FULLSCREEN;
   3.393 -		if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow) {
   3.394 +		if (VDI_screen && (VDI_format==VDI_FORMAT_PACK) && !use_shadow1) {
   3.395  			modeflags |= SDL_HWSURFACE;
   3.396  		} else {
   3.397  			modeflags |= SDL_SWSURFACE;
   3.398 @@ -704,8 +705,13 @@
   3.399  			return NULL;
   3.400  		}
   3.401  
   3.402 +#ifdef DEBUG_VIDEO_GEM
   3.403 +		printf("sdl:video:gem: handle=%d\n", GEM_handle);
   3.404 +#endif
   3.405 +
   3.406  		/* Setup window name */
   3.407  		wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
   3.408 +		GEM_refresh_name = SDL_FALSE;
   3.409  	
   3.410  		/* Open the window */
   3.411  		wind_open(GEM_handle,x2,y2,w2,h2);
   3.412 @@ -717,8 +723,8 @@
   3.413  	current->flags = modeflags;
   3.414  	current->w = width;
   3.415  	current->h = height;
   3.416 -	if (use_shadow) {
   3.417 -		current->pixels = GEM_buffer;
   3.418 +	if (use_shadow1) {
   3.419 +		current->pixels = GEM_buffer1;
   3.420  		current->pitch = width * (VDI_bpp >> 3);
   3.421  	} else {
   3.422  		current->pixels = VDI_screen;
   3.423 @@ -733,7 +739,6 @@
   3.424  	return(current);
   3.425  }
   3.426  
   3.427 -/* We don't actually allow hardware surfaces other than the main one */
   3.428  static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
   3.429  {
   3.430  	return -1;
   3.431 @@ -743,7 +748,6 @@
   3.432  	return;
   3.433  }
   3.434  
   3.435 -/* We need to wait for vertical retrace on page flipped displays */
   3.436  static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
   3.437  {
   3.438  	return(0);
   3.439 @@ -757,93 +761,96 @@
   3.440  static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
   3.441  {
   3.442  	SDL_Surface *surface;
   3.443 -	MFDB mfdb_src;
   3.444 -	short blitcoords[8];
   3.445  	int i;
   3.446  
   3.447  	surface = this->screen;
   3.448  
   3.449 -	if (VDI_screen) {
   3.450 -		if (VDI_format==VDI_FORMAT_INTER) {
   3.451 -			void *destscr;
   3.452 +	if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
   3.453 +		void *destscr;
   3.454 +		int destpitch;
   3.455 +
   3.456 +		if (GEM_bufops & B2S_C2P_1TOS) {
   3.457  			int destx;
   3.458 -			
   3.459 +
   3.460  			destscr = VDI_screen;
   3.461  			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
   3.462  			destx = (VDI_w - surface->w) >> 1;
   3.463  			destx &= ~15;
   3.464  			destscr += destx;
   3.465 +			destpitch = VDI_pitch;
   3.466 +		} else {
   3.467 +			destscr = GEM_buffer2;
   3.468 +			destpitch = surface->pitch;
   3.469 +		}
   3.470  
   3.471 -			for (i=0;i<numrects;i++) {
   3.472 -				void *source,*destination;
   3.473 -				int x1,x2;
   3.474 +		for (i=0;i<numrects;i++) {
   3.475 +			void *source,*destination;
   3.476 +			int x1,x2;
   3.477  
   3.478 -				x1 = rects[i].x & ~15;
   3.479 -				x2 = rects[i].x+rects[i].w;
   3.480 -				if (x2 & 15) {
   3.481 -					x2 = (x2 | 15) +1;
   3.482 -				}
   3.483 -
   3.484 -				source = surface->pixels;
   3.485 -				source += surface->pitch * rects[i].y;
   3.486 -				source += x1;
   3.487 -
   3.488 -				destination = destscr;
   3.489 -				destination += VDI_pitch * rects[i].y;
   3.490 -				destination += x1;
   3.491 -
   3.492 -				/* Convert chunky to planar screen */
   3.493 -				Atari_C2pConvert(
   3.494 -					source,
   3.495 -					destination,
   3.496 -					x2-x1,
   3.497 -					rects[i].h,
   3.498 -					SDL_FALSE,
   3.499 -					surface->pitch,
   3.500 -					VDI_pitch
   3.501 -				);
   3.502 -
   3.503 +			x1 = rects[i].x & ~15;
   3.504 +			x2 = rects[i].x+rects[i].w;
   3.505 +			if (x2 & 15) {
   3.506 +				x2 = (x2 | 15) +1;
   3.507  			}
   3.508  
   3.509 -			return;
   3.510 -		}
   3.511 +			source = surface->pixels;
   3.512 +			source += surface->pitch * rects[i].y;
   3.513 +			source += x1;
   3.514  
   3.515 -		if (!(surface->flags & SDL_DOUBLEBUF)) {
   3.516 -			return;
   3.517 +			destination = destscr;
   3.518 +			destination += destpitch * rects[i].y;
   3.519 +			destination += x1;
   3.520 +
   3.521 +			SDL_Atari_C2pConvert(
   3.522 +				source, destination,
   3.523 +				x2-x1, rects[i].h,
   3.524 +				SDL_FALSE,
   3.525 +				surface->pitch, destpitch
   3.526 +			);
   3.527  		}
   3.528  	}
   3.529  
   3.530 -	mfdb_src.fd_addr=surface->pixels;
   3.531 -	mfdb_src.fd_w=surface->w;
   3.532 -	mfdb_src.fd_h=surface->h;
   3.533 -	mfdb_src.fd_wdwidth=(surface->w) >> 4;
   3.534 -	mfdb_src.fd_stand=0;
   3.535 -	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.536 -	mfdb_src.fd_r1=0;
   3.537 -	mfdb_src.fd_r2=0;
   3.538 -	mfdb_src.fd_r3=0;
   3.539 +	if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
   3.540 +		MFDB mfdb_src;
   3.541 +		short blitcoords[8];
   3.542  
   3.543 -	for ( i=0; i<numrects; ++i ) {
   3.544 -		blitcoords[0] = rects[i].x;
   3.545 -		blitcoords[1] = rects[i].y;
   3.546 -		blitcoords[2] = blitcoords[0] + rects[i].w - 1;
   3.547 -		blitcoords[3] = blitcoords[1] + rects[i].h - 1;
   3.548 +		mfdb_src.fd_addr=surface->pixels;
   3.549 +		mfdb_src.fd_w=surface->w;
   3.550 +		mfdb_src.fd_h=surface->h;
   3.551 +		mfdb_src.fd_wdwidth=(surface->w) >> 4;
   3.552 +		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.553 +		mfdb_src.fd_stand=
   3.554 +			mfdb_src.fd_r1=
   3.555 +			mfdb_src.fd_r2=
   3.556 +			mfdb_src.fd_r3= 0;
   3.557 +		if (GEM_bufops & B2S_VROCPYFM_2TOS) {
   3.558 +			mfdb_src.fd_addr=GEM_buffer2;
   3.559 +		}
   3.560  
   3.561 -		blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
   3.562 -		blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
   3.563 -		blitcoords[6] = blitcoords[4] + rects[i].w - 1;
   3.564 -		blitcoords[7] = blitcoords[5] + rects[i].h - 1;
   3.565 +		for ( i=0; i<numrects; ++i ) {
   3.566 +			blitcoords[0] = rects[i].x;
   3.567 +			blitcoords[1] = rects[i].y;
   3.568 +			blitcoords[2] = blitcoords[0] + rects[i].w - 1;
   3.569 +			blitcoords[3] = blitcoords[1] + rects[i].h - 1;
   3.570  
   3.571 -		vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   3.572 +			blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
   3.573 +			blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
   3.574 +			blitcoords[6] = blitcoords[4] + rects[i].w - 1;
   3.575 +			blitcoords[7] = blitcoords[5] + rects[i].h - 1;
   3.576 +
   3.577 +			vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   3.578 +		}
   3.579  	}
   3.580  }
   3.581  
   3.582  static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
   3.583  {
   3.584 -	short pxy[8], wind_pxy[8];
   3.585 +	short pxy[4], wind_pxy[4];
   3.586  	int i;
   3.587  
   3.588 -	wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
   3.589 +	if (wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
   3.590 +		return;
   3.591 +	}
   3.592  
   3.593  	for ( i=0; i<numrects; ++i ) {
   3.594  		pxy[0] = wind_pxy[0] + rects[i].x;
   3.595 @@ -870,60 +877,62 @@
   3.596  
   3.597  static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
   3.598  {
   3.599 -	MFDB mfdb_src;
   3.600 -	short blitcoords[8];
   3.601 +	if (GEM_bufops & (B2S_C2P_1TO2|B2S_C2P_1TOS)) {
   3.602 +		void *destscr;
   3.603 +		int destpitch;
   3.604  
   3.605 -	if (VDI_screen) {
   3.606 -		if (VDI_format==VDI_FORMAT_INTER) {
   3.607 -			void *destscr;
   3.608 +		if (GEM_bufops & B2S_C2P_1TOS) {
   3.609  			int destx;
   3.610 -			
   3.611 -			/* Center on destination screen */
   3.612 +
   3.613  			destscr = VDI_screen;
   3.614  			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
   3.615  			destx = (VDI_w - surface->w) >> 1;
   3.616  			destx &= ~15;
   3.617  			destscr += destx;
   3.618 -
   3.619 -			/* Convert chunky to planar screen */
   3.620 -			Atari_C2pConvert(
   3.621 -				surface->pixels,
   3.622 -				destscr,
   3.623 -				surface->w,
   3.624 -				surface->h,
   3.625 -				SDL_FALSE,
   3.626 -				surface->pitch,
   3.627 -				VDI_pitch
   3.628 -			);
   3.629 -
   3.630 -			return(0);
   3.631 +			destpitch = VDI_pitch;
   3.632 +		} else {
   3.633 +			destscr = GEM_buffer2;
   3.634 +			destpitch = surface->pitch;
   3.635  		}
   3.636  
   3.637 -		if (!(surface->flags & SDL_DOUBLEBUF)) {
   3.638 -			return(0);
   3.639 +		SDL_Atari_C2pConvert(
   3.640 +			surface->pixels, destscr,
   3.641 +			surface->w, surface->h,
   3.642 +			SDL_FALSE,
   3.643 +			surface->pitch, destpitch
   3.644 +		);
   3.645 +	}
   3.646 +
   3.647 +	if (GEM_bufops & (B2S_VROCPYFM_1TOS|B2S_VROCPYFM_2TOS)) {
   3.648 +		MFDB mfdb_src;
   3.649 +		short blitcoords[8];
   3.650 +
   3.651 +		mfdb_src.fd_w=surface->w;
   3.652 +		mfdb_src.fd_h=surface->h;
   3.653 +		mfdb_src.fd_wdwidth=(surface->w) >> 4;
   3.654 +		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.655 +		mfdb_src.fd_stand=
   3.656 +			mfdb_src.fd_r1=
   3.657 +			mfdb_src.fd_r2=
   3.658 +			mfdb_src.fd_r3= 0;
   3.659 +		if (GEM_bufops & B2S_VROCPYFM_1TOS) {
   3.660 +			mfdb_src.fd_addr=surface->pixels;
   3.661 +		} else {
   3.662 +			mfdb_src.fd_addr=GEM_buffer2;
   3.663  		}
   3.664 +
   3.665 +		blitcoords[0] = 0;
   3.666 +		blitcoords[1] = 0;
   3.667 +		blitcoords[2] = surface->w - 1;
   3.668 +		blitcoords[3] = surface->h - 1;
   3.669 +
   3.670 +		blitcoords[4] = (VDI_w - surface->w) >> 1;
   3.671 +		blitcoords[5] = (VDI_h - surface->h) >> 1;
   3.672 +		blitcoords[6] = blitcoords[4] + surface->w - 1;
   3.673 +		blitcoords[7] = blitcoords[5] + surface->h - 1;
   3.674 +
   3.675 +		vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   3.676  	}
   3.677 -	
   3.678 -	mfdb_src.fd_addr=surface->pixels;
   3.679 -	mfdb_src.fd_w=surface->w;
   3.680 -	mfdb_src.fd_h=surface->h;
   3.681 -	mfdb_src.fd_wdwidth=(surface->w) >> 4;
   3.682 -	mfdb_src.fd_stand=0;
   3.683 -	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.684 -	mfdb_src.fd_r1=0;
   3.685 -	mfdb_src.fd_r2=0;
   3.686 -	mfdb_src.fd_r3=0;
   3.687 -
   3.688 -	blitcoords[0] = 0;
   3.689 -	blitcoords[1] = 0;
   3.690 -	blitcoords[2] = surface->w - 1;
   3.691 -	blitcoords[3] = surface->h - 1;
   3.692 -	blitcoords[4] = (VDI_w - surface->w) >> 1;
   3.693 -	blitcoords[5] = (VDI_h - surface->h) >> 1;
   3.694 -	blitcoords[6] = blitcoords[4] + surface->w - 1;
   3.695 -	blitcoords[7] = blitcoords[5] + surface->h - 1;
   3.696 -
   3.697 -	vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
   3.698  
   3.699  	return(0);
   3.700  }
   3.701 @@ -954,6 +963,10 @@
   3.702  	int i;
   3.703  	SDL_Surface *surface;
   3.704  
   3.705 +#ifdef DEBUG_VIDEO_GEM
   3.706 +	printf("sdl:video:gem: setcolors()\n");
   3.707 +#endif
   3.708 +
   3.709  	/* Do not change palette in True Colour */
   3.710  	surface = this->screen;
   3.711  	if (surface->format->BitsPerPixel > 8) {
   3.712 @@ -1044,76 +1057,193 @@
   3.713  	v_hide_c(VDI_handle);
   3.714  
   3.715  	/* Browse the rectangle list to redraw */
   3.716 -	wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
   3.717 +	if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
   3.718  
   3.719 -	while (todo[2] && todo[3]) {
   3.720 +		while (todo[2] && todo[3]) {
   3.721  
   3.722 -		if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
   3.723 -			todo[2] += todo[0]-1;
   3.724 -			todo[3] += todo[1]-1;
   3.725 -			refresh_window(this, winhandle, todo);
   3.726 +			if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
   3.727 +				todo[2] += todo[0]-1;
   3.728 +				todo[3] += todo[1]-1;
   3.729 +				refresh_window(this, winhandle, todo);
   3.730 +			}
   3.731 +
   3.732 +			if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
   3.733 +				break;
   3.734 +			}
   3.735  		}
   3.736  
   3.737 -		wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
   3.738  	}
   3.739  
   3.740  	/* Update finished */
   3.741  	wind_update(END_UPDATE);
   3.742  
   3.743  	v_show_c(VDI_handle,1);
   3.744 +
   3.745 +#if DEBUG_VIDEO_GEM
   3.746 +	fflush(stdout);
   3.747 +#endif
   3.748  }
   3.749  
   3.750  static void refresh_window(_THIS, int winhandle, short *rect)
   3.751  {
   3.752 -	MFDB	mfdb_src;
   3.753 -	short	pxy[8], wind_pxy[8];
   3.754 +	MFDB mfdb_src;
   3.755 +	short pxy[8],wind_pxy[8];
   3.756 +	SDL_Surface *surface;
   3.757  	int iconified;
   3.758 -	SDL_Surface *surface;
   3.759 -
   3.760 -	surface=this->screen;
   3.761  
   3.762  	/* Is window iconified ? */
   3.763  	iconified = 0;
   3.764 -	if (GEM_wfeatures & (1<<WF_ICONIFY)) {
   3.765 -		wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
   3.766 -		iconified = pxy[0];
   3.767 +/*	if (GEM_wfeatures & (1<<WF_ICONIFY))*/ {
   3.768 +		if (wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])!=0) {
   3.769 +			iconified = wind_pxy[0];
   3.770 +		}
   3.771  	}
   3.772  
   3.773 -	wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
   3.774 -
   3.775 -	if (iconified) {
   3.776 -		/* Refresh icon */
   3.777 -		mfdb_src.fd_addr=surface->pixels;	/* Should be icon image */
   3.778 -		mfdb_src.fd_w=surface->w;
   3.779 -		mfdb_src.fd_h=surface->h;
   3.780 -		mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
   3.781 -	  	mfdb_src.fd_stand=0;
   3.782 -  		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.783 -		mfdb_src.fd_r1=0;
   3.784 -  		mfdb_src.fd_r2=0;
   3.785 -	  	mfdb_src.fd_r3=0;
   3.786 -	} else {
   3.787 -		/* Refresh window */
   3.788 -		mfdb_src.fd_addr=surface->pixels;
   3.789 -		mfdb_src.fd_w=surface->w;
   3.790 -		mfdb_src.fd_h=surface->h;
   3.791 -		mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
   3.792 -	  	mfdb_src.fd_stand=0;
   3.793 -  		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.794 -		mfdb_src.fd_r1=0;
   3.795 -  		mfdb_src.fd_r2=0;
   3.796 -	  	mfdb_src.fd_r3=0;
   3.797 +	if (wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3])==0) {
   3.798 +		return;
   3.799  	}
   3.800  
   3.801 -	pxy[0] = rect[0] - wind_pxy[0];
   3.802 -	pxy[1] = rect[1] - wind_pxy[1];
   3.803 - 	pxy[2] = pxy[0] + rect[2] - rect[0];   
   3.804 - 	pxy[3] = pxy[1] + rect[3] - rect[1];  
   3.805 +	if (iconified && GEM_icon) {
   3.806 +		short icon_rect[4], dst_rect[4];
   3.807 +		
   3.808 +		surface = GEM_icon;
   3.809  
   3.810 -	pxy[4] = rect[0];
   3.811 -	pxy[5] = rect[1];
   3.812 -	pxy[6] = rect[2];  
   3.813 -	pxy[7] = rect[3];
   3.814 +		GEM_ClearRect(this, rect);
   3.815 +
   3.816 +		/* Calculate centered icon(x,y,w,h) relative to window */
   3.817 +		icon_rect[0] = (wind_pxy[2]-surface->w)>>1;
   3.818 +		icon_rect[1] = (wind_pxy[3]-surface->h)>>1;
   3.819 +		icon_rect[2] = surface->w;
   3.820 +		icon_rect[3] = surface->h;
   3.821 +
   3.822 +		/* Calculate redraw rectangle(x,y,w,h) relative to window */
   3.823 +		dst_rect[0] = rect[0]-wind_pxy[0];
   3.824 +		dst_rect[1] = rect[1]-wind_pxy[1];
   3.825 +		dst_rect[2] = rect[2]-rect[0]+1;
   3.826 +		dst_rect[3] = rect[3]-rect[1]+1;
   3.827 +
   3.828 +		/* Does the icon rectangle must be redrawn ? */
   3.829 +		if (!rc_intersect((GRECT *)icon_rect, (GRECT *)dst_rect)) {
   3.830 +			return;
   3.831 +		}
   3.832 +
   3.833 +#ifdef DEBUG_VIDEO_GEM
   3.834 +		printf("sdl:video:gem:  clip(0,0,%d,%d) to (%d,%d,%d,%d)\n",
   3.835 +			surface->w-1,surface->h-1, dst_rect[0],dst_rect[1],dst_rect[2],dst_rect[3]);
   3.836 +		printf("sdl:video:gem:  icon(%d,%d,%d,%d)\n",
   3.837 +			icon_rect[0], icon_rect[1], icon_rect[2], icon_rect[3]);
   3.838 +		printf("sdl:video:gem: refresh_window(): draw icon\n");
   3.839 +#endif
   3.840 +
   3.841 +		/* Calculate icon(x1,y1,x2,y2) relative to screen */
   3.842 +		icon_rect[0] += wind_pxy[0];
   3.843 +		icon_rect[1] += wind_pxy[1];
   3.844 +		icon_rect[2] += icon_rect[0]-1;
   3.845 +		icon_rect[3] += icon_rect[1]-1;
   3.846 +
   3.847 +		/* Calculate intersection rectangle to redraw */
   3.848 +		pxy[0]=0;
   3.849 +		pxy[1]=0;
   3.850 + 		pxy[2]=surface->w - 1;
   3.851 +	 	pxy[3]=surface->h - 1;
   3.852 +		pxy[4]=rect[0];
   3.853 +		pxy[5]=rect[1];
   3.854 +		pxy[6]=rect[2];
   3.855 +		pxy[7]=rect[3];
   3.856 +
   3.857 +		if (icon_rect[0]>rect[0]) {
   3.858 +			pxy[4]=icon_rect[0];
   3.859 +		} else if (icon_rect[0]<rect[0]) {
   3.860 +			pxy[0]=rect[0]-icon_rect[0];
   3.861 +		}
   3.862 +
   3.863 +		if (icon_rect[1]>rect[1]) {
   3.864 +			pxy[5]=icon_rect[1];
   3.865 +		} else if (icon_rect[1]<rect[1]) {
   3.866 +			pxy[1]=rect[1]-icon_rect[1];
   3.867 +		}
   3.868 +
   3.869 +		if (icon_rect[2]>rect[2]) {
   3.870 +			pxy[2]=rect[2]-icon_rect[0];
   3.871 +			pxy[6]=rect[2];
   3.872 +		} else if (icon_rect[2]<rect[2]) {
   3.873 +			pxy[2]=icon_rect[2]-rect[0];
   3.874 +			pxy[6]=icon_rect[2];
   3.875 +		}
   3.876 +
   3.877 +		if (icon_rect[3]>rect[3]) {
   3.878 +			pxy[3]=rect[3]-icon_rect[1];
   3.879 +			pxy[7]=rect[3];
   3.880 +		} else if (icon_rect[3]<rect[3]) {
   3.881 +			pxy[3]=icon_rect[3]-rect[1];
   3.882 +			pxy[7]=icon_rect[3];
   3.883 +		}
   3.884 +
   3.885 +	} else {
   3.886 +		surface = this->screen;
   3.887 +
   3.888 +#ifdef DEBUG_VIDEO_GEM
   3.889 +		printf("sdl:video:gem: refresh_window(): draw frame buffer\n");
   3.890 +#endif
   3.891 +
   3.892 +		/* Redraw all window content */
   3.893 +		pxy[0] = rect[0]-wind_pxy[0];
   3.894 +		pxy[1] = rect[1]-wind_pxy[1];
   3.895 +	 	pxy[2] = rect[2]-wind_pxy[0];   
   3.896 +	 	pxy[3] = rect[3]-wind_pxy[1];  
   3.897 +
   3.898 +		pxy[4] = rect[0];
   3.899 +		pxy[5] = rect[1];
   3.900 +		pxy[6] = rect[2];  
   3.901 +		pxy[7] = rect[3];
   3.902 +	}
   3.903 +
   3.904 +	if (GEM_bufops & B2S_C2P_1TO2) {
   3.905 +		void *src, *dest;
   3.906 +		int x1,x2;
   3.907 +
   3.908 +		x1 = (rect[0]-wind_pxy[0]) & ~15;
   3.909 +		x2 = rect[2]-wind_pxy[0];
   3.910 +		if (x2 & 15) {
   3.911 +			x2 = (x2 | 15) +1;
   3.912 +		}
   3.913 +
   3.914 +		src = surface->pixels;
   3.915 +		src += surface->pitch * (rect[1]-wind_pxy[1]);
   3.916 +		src += x1;
   3.917 +
   3.918 +		dest = GEM_buffer2;
   3.919 +		dest += surface->pitch * (rect[1]-wind_pxy[1]);
   3.920 +		dest += x1;
   3.921 +
   3.922 +		SDL_Atari_C2pConvert(
   3.923 +			src, dest,
   3.924 +			x2-x1, rect[3]-rect[1]+1,
   3.925 +			SDL_FALSE,
   3.926 +			surface->pitch, surface->pitch
   3.927 +		);
   3.928 +	}
   3.929 +
   3.930 +	mfdb_src.fd_addr=surface->pixels;
   3.931 +	mfdb_src.fd_w=surface->w;
   3.932 +	mfdb_src.fd_h=surface->h;
   3.933 +  	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
   3.934 +	mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
   3.935 +	mfdb_src.fd_stand=
   3.936 +		mfdb_src.fd_r1=
   3.937 +  		mfdb_src.fd_r2=
   3.938 +	  	mfdb_src.fd_r3= 0;
   3.939 +
   3.940 +	if (GEM_bufops & B2S_VROCPYFM_2TOS) {
   3.941 +		mfdb_src.fd_addr=GEM_buffer2;
   3.942 +	}
   3.943 +
   3.944 +#ifdef DEBUG_VIDEO_GEM
   3.945 +	printf("sdl:video:gem: redraw (%d,%d,%d,%d) to (%d,%d,%d,%d)\n",
   3.946 +		pxy[0],pxy[1],pxy[2],pxy[3],
   3.947 +		pxy[4],pxy[5],pxy[6],pxy[7]
   3.948 +	);
   3.949 +#endif
   3.950  
   3.951  	vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
   3.952  }
     4.1 --- a/src/video/gem/SDL_gemvideo.h	Wed Nov 12 18:46:48 2003 +0000
     4.2 +++ b/src/video/gem/SDL_gemvideo.h	Wed Nov 12 18:49:29 2003 +0000
     4.3 @@ -39,37 +39,49 @@
     4.4  
     4.5  /* Private display data */
     4.6  
     4.7 +#define B2S_C2P_1TO2		(1<<0)	/* C2P convert buffer 1 to buffer 2 */
     4.8 +#define B2S_C2P_1TOS		(1<<1)	/* C2P convert buffer 1 to screen */
     4.9 +#define B2S_VROCPYFM_1TOS	(1<<2)	/* vro_cpyfm() buffer 1 to screen */
    4.10 +#define B2S_VROCPYFM_2TOS	(1<<3)	/* vro_cpyfm() buffer 2 to screen */
    4.11 +
    4.12  #define SDL_NUMMODES	1		/* Fullscreen */
    4.13  
    4.14  struct SDL_PrivateVideoData {
    4.15 +	Uint16	buf2scr_ops;		/* Operations to get buffer to screen */
    4.16 +    void *buffer1;				/* Our shadow buffers */
    4.17 +	void *buffer2;
    4.18 +
    4.19  	/* VDI infos */
    4.20  	short vdi_handle;			/* VDI handle */
    4.21  	short full_w, full_h;		/* Fullscreen size */
    4.22 -    int bpp;					/* Colour depth */
    4.23 -	int pixelsize;				/* Bytes per pixel */
    4.24 -	Uint16 old_numcolors;		/* Number of colors in saved palette */
    4.25 -	Uint16 old_palette[256][3];	/* Saved current palette */
    4.26 +    short bpp;					/* Colour depth */
    4.27 +	short pixelsize;			/* Bytes per pixel */
    4.28 +	short old_numcolors;		/* Number of colors in saved palette */
    4.29  	Uint16 pitch;				/* Line length */
    4.30 -	int format;					/* Screen format */
    4.31 +	Uint16 format;				/* Screen format */
    4.32  	void *screen;				/* Screen address */
    4.33  	Uint32 red, green, blue, alpha;	/* Screen components */
    4.34  	Uint32 screensize;
    4.35 +	short	blit_coords[8];		/* Coordinates for bitblt */
    4.36  	MFDB	src_mfdb, dst_mfdb;	/* VDI MFDB for bitblt */
    4.37 -	short	blit_coords[8];		/* Coordinates for bitblt */
    4.38 +	Uint16 old_palette[256][3];	/* Saved current palette */
    4.39 +
    4.40  	/* GEM infos */
    4.41  	short desk_x, desk_y;		/* Desktop properties */
    4.42  	short desk_w, desk_h;
    4.43  	short win_handle;			/* Our window handle */
    4.44 -    void *buffer;				/* Our shadow buffer */
    4.45  	int window_type;			/* Window type */
    4.46  	const char *title_name;		/* Window title */
    4.47  	const char *icon_name;		/* Icon title */
    4.48  	short version;				/* AES version */
    4.49  	short wfeatures;			/* AES window features */
    4.50 +	SDL_bool refresh_name;		/* Change window title ? */
    4.51  	SDL_bool window_fulled;		/* Window maximized ? */
    4.52  	SDL_bool mouse_relative;	/* Report relative mouse movement */
    4.53  	SDL_bool locked;			/* AES locked for fullscreen ? */
    4.54 +	short message[8];			/* To self-send an AES message */
    4.55  	SDL_Rect *SDL_modelist[SDL_NUMMODES+1];	/* Mode list */
    4.56 +	SDL_Surface *icon;			/* The icon */
    4.57  };
    4.58  
    4.59  /* Hidden structure -> variables names */
    4.60 @@ -97,15 +109,66 @@
    4.61  #define GEM_desk_w			(this->hidden->desk_w)
    4.62  #define GEM_desk_h			(this->hidden->desk_h)
    4.63  #define GEM_handle			(this->hidden->win_handle)
    4.64 -#define GEM_buffer			(this->hidden->buffer)
    4.65  #define GEM_win_type		(this->hidden->window_type)
    4.66  #define GEM_title_name		(this->hidden->title_name)
    4.67  #define GEM_icon_name		(this->hidden->icon_name)
    4.68 +#define GEM_refresh_name	(this->hidden->refresh_name)
    4.69  #define GEM_version			(this->hidden->version)
    4.70  #define GEM_wfeatures		(this->hidden->wfeatures)
    4.71  #define GEM_win_fulled		(this->hidden->window_fulled)
    4.72  #define GEM_mouse_relative	(this->hidden->mouse_relative)
    4.73  #define GEM_locked			(this->hidden->locked)
    4.74 +#define GEM_message			(this->hidden->message)
    4.75  #define SDL_modelist		(this->hidden->SDL_modelist)
    4.76 +#define GEM_icon			(this->hidden->icon)
    4.77 +
    4.78 +#define GEM_buffer1			(this->hidden->buffer1)
    4.79 +#define GEM_buffer2			(this->hidden->buffer2)
    4.80 +#define GEM_bufops			(this->hidden->buf2scr_ops)
    4.81 +
    4.82 +#define VDI_FBMASK(amask, rmask, gmask, bmask) \
    4.83 +	VDI_alphamask = (amask); \
    4.84 +	VDI_redmask = (rmask); \
    4.85 +	VDI_greenmask = (gmask); \
    4.86 +	VDI_bluemask = (bmask);
    4.87 +
    4.88 +/*
    4.89 +	Possible buffer to screen operations:
    4.90 +
    4.91 +	TC: 8 (chunky),15,16,24,32 bpp
    4.92 +	8I: 8 bpp planes
    4.93 +	FB: screen framebuffer address available
    4.94 +	FS: fullscreen
    4.95 +
    4.96 +	TC, FB, FS:
    4.97 +		- draw to screen
    4.98 +	8I, FB, FS:
    4.99 +		- draw to buffer 1
   4.100 +		- C2P from buffer 1 to screen
   4.101 +
   4.102 +	TC, !FB, FS:
   4.103 +		- draw to buffer 1
   4.104 +		- vro_cpyfm() from buffer 1 to screen
   4.105 +	8I, !FB, FS:
   4.106 +		- draw to buffer 1
   4.107 +		- C2P from buffer 1 to buffer 2
   4.108 +		- vro_cpyfm() from buffer 2 to screen
   4.109 +
   4.110 +	TC, FB, !FS:
   4.111 +		- draw to buffer 1
   4.112 +		- vro_cpyfm() from buffer 1 to screen
   4.113 +	8I, FB, !FS:
   4.114 +		- draw to buffer 1
   4.115 +		- C2P from buffer 1 to buffer 2
   4.116 +		- vro_cpyfm() from buffer 2 to screen
   4.117 +
   4.118 +	TC, !FB, !FS:
   4.119 +		- draw to buffer 1
   4.120 +		- vro_cpyfm() from buffer 1 to screen
   4.121 +	8I, !FB, !FS:
   4.122 +		- draw to buffer 1
   4.123 +		- C2P from buffer 1 to buffer 2
   4.124 +		- vro_cpyfm() from buffer 2 to screen
   4.125 +*/
   4.126  
   4.127  #endif /* _SDL_gemvideo_h */
     5.1 --- a/src/video/gem/SDL_gemwm.c	Wed Nov 12 18:46:48 2003 +0000
     5.2 +++ b/src/video/gem/SDL_gemwm.c	Wed Nov 12 18:49:29 2003 +0000
     5.3 @@ -26,11 +26,11 @@
     5.4  #endif
     5.5  
     5.6  /*
     5.7 - *	GEM SDL video driver implementation
     5.8 - *	Window manager functions
     5.9 - * 
    5.10 - *	Patrice Mandin
    5.11 - */
    5.12 +	GEM SDL video driver
    5.13 +	Window manager functions
    5.14 +
    5.15 +	Patrice Mandin
    5.16 +*/
    5.17  
    5.18  /* Mint includes */
    5.19  #include <gem.h>
    5.20 @@ -39,6 +39,8 @@
    5.21  
    5.22  /* Defines */
    5.23  
    5.24 +#define DEBUG_VIDEO_GEM 0
    5.25 +
    5.26  #define ICONWIDTH 64
    5.27  #define ICONHEIGHT 64
    5.28  
    5.29 @@ -46,65 +48,77 @@
    5.30  
    5.31  void GEM_SetCaption(_THIS, const char *title, const char *icon)
    5.32  {
    5.33 -	short parm[4];
    5.34 -	const char *new_name;
    5.35 -
    5.36 -	new_name = NULL;
    5.37 -
    5.38 -	if (title)
    5.39 +	if (title) {
    5.40  		GEM_title_name = title;
    5.41 -
    5.42 -	if (icon)
    5.43 -		GEM_icon_name = icon;
    5.44 -
    5.45 -	/* Is window iconified ? */
    5.46 -	parm[0]=0;
    5.47 -	if (GEM_wfeatures & (1<<WF_ICONIFY))
    5.48 -		wind_get(GEM_handle, WF_ICONIFY, &parm[0], &parm[1], &parm[2], &parm[3]);
    5.49 -
    5.50 -	if (parm[0]==0) {
    5.51 -		/* Change window name */
    5.52 -		if (title)
    5.53 -			new_name = title;
    5.54 -	} else {
    5.55 -		/* Change icon name */
    5.56 -		if (icon)
    5.57 -			new_name = icon;
    5.58 +		GEM_refresh_name = SDL_TRUE;
    5.59  	}
    5.60  
    5.61 -	parm[0]= ((unsigned long) new_name)>>16;
    5.62 -	parm[1]= ((unsigned long) new_name) & 65535;
    5.63 -
    5.64 -	if (new_name) {
    5.65 -		wind_set(GEM_handle, WF_NAME, parm[0], parm[1], 0, 0);
    5.66 +	if (icon) {
    5.67 +		GEM_icon_name = icon;
    5.68 +		GEM_refresh_name = SDL_TRUE;
    5.69  	}
    5.70  }
    5.71  
    5.72  void GEM_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
    5.73  {
    5.74 -	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0)
    5.75 +	SDL_Surface *sicon;
    5.76 +	SDL_Rect bounds;
    5.77 +
    5.78 +#ifdef DEBUG_VIDEO_GEM
    5.79 +	printf("sdl:video:gem: SetIcon(0x%08x)\n", (long) icon);
    5.80 +#endif
    5.81 +
    5.82 +#if 0
    5.83 +	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0) {
    5.84 +#ifdef DEBUG_VIDEO_GEM
    5.85 +		printf("sdl:video:gem: AES can not iconify windows\n");
    5.86 +#endif
    5.87  		return;
    5.88 +	}
    5.89 +#endif
    5.90  
    5.91 -	/* Todo */
    5.92 +	if (icon == NULL) {
    5.93 +		return;
    5.94 +	}
    5.95 +	
    5.96 +	/* Convert icon to the screen format */
    5.97 +	sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
    5.98 +		VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, 0);
    5.99 +	if ( sicon == NULL ) {
   5.100 +		return;
   5.101 +	}
   5.102 +
   5.103 +	bounds.x = 0;
   5.104 +	bounds.y = 0;
   5.105 +	bounds.w = icon->w;
   5.106 +	bounds.h = icon->h;
   5.107 +	if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 ) {
   5.108 +		SDL_FreeSurface(sicon);
   5.109 +		return;
   5.110 +	}
   5.111 +
   5.112 +	GEM_icon = sicon;
   5.113 +
   5.114 +#ifdef DEBUG_VIDEO_GEM
   5.115 +	printf("sdl:video:gem: SetIcon(): done\n");
   5.116 +#endif
   5.117  }
   5.118  
   5.119  int GEM_IconifyWindow(_THIS)
   5.120  {
   5.121 -	short message[8];
   5.122 -	
   5.123  	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0)
   5.124  		return 0;
   5.125  
   5.126 -	message[0] = WM_ICONIFY;
   5.127 -	message[1] = gl_apid;
   5.128 -	message[2] = 0;
   5.129 -	message[3] = GEM_handle;
   5.130 -	message[4] = 0;
   5.131 -	message[5] = GEM_desk_h-ICONHEIGHT;
   5.132 -	message[6] = ICONWIDTH;
   5.133 -	message[7] = ICONHEIGHT;
   5.134 +	GEM_message[0] = WM_ICONIFY;
   5.135 +	GEM_message[1] = gl_apid;
   5.136 +	GEM_message[2] = 0;
   5.137 +	GEM_message[3] = GEM_handle;
   5.138 +	GEM_message[4] = 0;
   5.139 +	GEM_message[5] = GEM_desk_h-ICONHEIGHT;
   5.140 +	GEM_message[6] = ICONWIDTH;
   5.141 +	GEM_message[7] = ICONHEIGHT;
   5.142  
   5.143 -	appl_write(gl_apid, sizeof(message), message);
   5.144 +	appl_write(gl_apid, sizeof(GEM_message), GEM_message);
   5.145  
   5.146  	return 1;
   5.147  }