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