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