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