src/video/xbios/SDL_xbios.c
author Patrice Mandin
Sun, 08 Jan 2006 17:29:19 +0000
changeset 1239 cbdb2c156aca
parent 1238 1901fea5edac
child 1256 3cfb04f6e726
permissions -rw-r--r--
Rollback
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@281
     6
    modify it under the terms of the GNU Library General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@281
     8
    version 2 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@281
    13
    Library General Public License for more details.
slouken@281
    14
slouken@281
    15
    You should have received a copy of the GNU Library General Public
slouken@281
    16
    License along with this library; if not, write to the Free
slouken@281
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@281
    22
slouken@281
    23
#ifdef SAVE_RCSID
slouken@281
    24
static char rcsid =
slouken@281
    25
 "@(#) $Id$";
slouken@281
    26
#endif
slouken@281
    27
slouken@281
    28
/*
slouken@281
    29
 * Xbios SDL video driver
slouken@281
    30
 * 
slouken@281
    31
 * Patrice Mandin
slouken@281
    32
 */
slouken@281
    33
slouken@281
    34
#include <stdio.h>
slouken@281
    35
#include <stdlib.h>
slouken@281
    36
#include <string.h>
slouken@281
    37
#include <sys/stat.h>
slouken@281
    38
#include <unistd.h>
slouken@281
    39
slouken@281
    40
/* Mint includes */
slouken@557
    41
#include <mint/cookie.h>
slouken@281
    42
#include <mint/osbind.h>
slouken@281
    43
#include <mint/falcon.h>
slouken@281
    44
slouken@281
    45
#include "SDL.h"
slouken@281
    46
#include "SDL_error.h"
slouken@281
    47
#include "SDL_video.h"
slouken@281
    48
#include "SDL_mouse.h"
slouken@281
    49
#include "SDL_sysvideo.h"
slouken@281
    50
#include "SDL_pixels_c.h"
slouken@281
    51
#include "SDL_events_c.h"
slouken@281
    52
slouken@281
    53
#include "SDL_ataric2p_s.h"
slouken@281
    54
#include "SDL_atarievents_c.h"
slouken@281
    55
#include "SDL_atarimxalloc_c.h"
patmandin@989
    56
#include "SDL_atarigl_c.h"
slouken@281
    57
#include "SDL_xbios.h"
patmandin@1040
    58
#include "SDL_xbios_blowup.h"
patmandin@1061
    59
#include "SDL_xbios_centscreen.h"
patmandin@1040
    60
#include "SDL_xbios_sb3.h"
slouken@281
    61
slouken@281
    62
#define XBIOS_VID_DRIVER_NAME "xbios"
slouken@281
    63
patmandin@1042
    64
/* Debug print info */
patmandin@1043
    65
#if 0
patmandin@1042
    66
#define DEBUG_PRINT(what) \
patmandin@1042
    67
	{ \
patmandin@1042
    68
		printf what; \
patmandin@1042
    69
	}
patmandin@1043
    70
#define DEBUG_VIDEO_XBIOS 1
patmandin@1042
    71
#else
patmandin@1042
    72
#define DEBUG_PRINT(what)
patmandin@1042
    73
#undef DEBUG_VIDEO_XBIOS
patmandin@1042
    74
#endif
patmandin@735
    75
slouken@281
    76
/* Initialization/Query functions */
slouken@281
    77
static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
slouken@281
    78
static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
slouken@281
    79
static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
slouken@281
    80
static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
slouken@281
    81
static void XBIOS_VideoQuit(_THIS);
slouken@281
    82
slouken@281
    83
/* Hardware surface functions */
slouken@281
    84
static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface);
slouken@281
    85
static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@281
    86
static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface);
slouken@281
    87
static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@281
    88
static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
slouken@281
    89
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
slouken@281
    90
patmandin@978
    91
#ifdef HAVE_OPENGL
patmandin@978
    92
/* OpenGL functions */
patmandin@978
    93
static void XBIOS_GL_SwapBuffers(_THIS);
patmandin@978
    94
#endif
patmandin@978
    95
slouken@281
    96
/* To setup palette */
slouken@281
    97
slouken@281
    98
static unsigned short	TT_palette[256];
slouken@281
    99
static unsigned long	F30_palette[256];
slouken@281
   100
slouken@281
   101
/* Xbios driver bootstrap functions */
slouken@281
   102
slouken@281
   103
static int XBIOS_Available(void)
slouken@281
   104
{
patmandin@1040
   105
	unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn;
patmandin@797
   106
patmandin@797
   107
	/* Milan/Hades Atari clones do not have an Atari video chip */
patmandin@797
   108
	if ( (Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||
patmandin@797
   109
		(Getcookie(C_hade, &cookie_hade) == C_FOUND) ) {
patmandin@797
   110
		return 0;
patmandin@797
   111
	}
slouken@281
   112
slouken@281
   113
	/* Cookie _VDO present ? if not, assume ST machine */
slouken@281
   114
	if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
slouken@281
   115
		cookie_vdo = VDO_ST << 16;
slouken@281
   116
	}
slouken@281
   117
slouken@281
   118
	/* Test if we have a monochrome monitor plugged in */
slouken@281
   119
	switch( cookie_vdo >>16) {
slouken@281
   120
		case VDO_ST:
slouken@281
   121
		case VDO_STE:
slouken@281
   122
			if ( Getrez() == (ST_HIGH>>8) )
slouken@281
   123
				return 0;
slouken@281
   124
			break;
slouken@281
   125
		case VDO_TT:
slouken@281
   126
			if ( (EgetShift() & ES_MODE) == TT_HIGH)
slouken@281
   127
				return 0;
slouken@281
   128
			break;
slouken@281
   129
		case VDO_F30:
slouken@281
   130
			if ( Montype() == MONITOR_MONO)
slouken@281
   131
				return 0;
patmandin@1040
   132
			if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
patmandin@1040
   133
				if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) {
patmandin@1040
   134
					return 0;
patmandin@1040
   135
				}
patmandin@1040
   136
			}
slouken@281
   137
			break;
slouken@281
   138
		default:
slouken@281
   139
			return 0;
slouken@281
   140
	}
slouken@281
   141
slouken@281
   142
	return 1;
slouken@281
   143
}
slouken@281
   144
slouken@281
   145
static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
slouken@281
   146
{
slouken@281
   147
	free(device->hidden);
slouken@281
   148
	free(device);
slouken@281
   149
}
slouken@281
   150
slouken@281
   151
static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
slouken@281
   152
{
slouken@281
   153
	SDL_VideoDevice *device;
slouken@281
   154
slouken@281
   155
	/* Initialize all variables that we clean on shutdown */
slouken@281
   156
	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
slouken@281
   157
	if ( device ) {
slouken@281
   158
		memset(device, 0, (sizeof *device));
slouken@281
   159
		device->hidden = (struct SDL_PrivateVideoData *)
slouken@281
   160
				malloc((sizeof *device->hidden));
patmandin@989
   161
		device->gl_data = (struct SDL_PrivateGLData *)
patmandin@989
   162
				malloc((sizeof *device->gl_data));
slouken@281
   163
	}
slouken@281
   164
	if ( (device == NULL) || (device->hidden == NULL) ) {
slouken@281
   165
		SDL_OutOfMemory();
slouken@281
   166
		if ( device ) {
slouken@281
   167
			free(device);
slouken@281
   168
		}
slouken@281
   169
		return(0);
slouken@281
   170
	}
slouken@281
   171
	memset(device->hidden, 0, (sizeof *device->hidden));
patmandin@989
   172
	memset(device->gl_data, 0, sizeof(*device->gl_data));
slouken@281
   173
slouken@281
   174
	/* Video functions */
slouken@281
   175
	device->VideoInit = XBIOS_VideoInit;
slouken@281
   176
	device->ListModes = XBIOS_ListModes;
slouken@281
   177
	device->SetVideoMode = XBIOS_SetVideoMode;
slouken@281
   178
	device->SetColors = XBIOS_SetColors;
slouken@281
   179
	device->UpdateRects = NULL;
slouken@281
   180
	device->VideoQuit = XBIOS_VideoQuit;
slouken@281
   181
	device->AllocHWSurface = XBIOS_AllocHWSurface;
slouken@281
   182
	device->LockHWSurface = XBIOS_LockHWSurface;
slouken@281
   183
	device->UnlockHWSurface = XBIOS_UnlockHWSurface;
slouken@281
   184
	device->FlipHWSurface = XBIOS_FlipHWSurface;
slouken@281
   185
	device->FreeHWSurface = XBIOS_FreeHWSurface;
slouken@281
   186
patmandin@978
   187
#ifdef HAVE_OPENGL
patmandin@978
   188
	/* OpenGL functions */
patmandin@989
   189
	device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
patmandin@989
   190
	device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
patmandin@989
   191
	device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
patmandin@989
   192
	device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
patmandin@978
   193
	device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
patmandin@978
   194
#endif
patmandin@978
   195
slouken@281
   196
	/* Events */
slouken@281
   197
	device->InitOSKeymap = Atari_InitOSKeymap;
slouken@281
   198
	device->PumpEvents = Atari_PumpEvents;
slouken@281
   199
slouken@281
   200
	device->free = XBIOS_DeleteDevice;
slouken@281
   201
slouken@281
   202
	return device;
slouken@281
   203
}
slouken@281
   204
slouken@281
   205
VideoBootStrap XBIOS_bootstrap = {
slouken@281
   206
	XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
slouken@281
   207
	XBIOS_Available, XBIOS_CreateDevice
slouken@281
   208
};
slouken@281
   209
patmandin@1042
   210
void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height,
patmandin@1042
   211
	Uint16 depth, SDL_bool flags)
patmandin@1042
   212
{
patmandin@1042
   213
	int i, curpos;
patmandin@1042
   214
	xbiosmode_t *current_mode;
patmandin@1042
   215
patmandin@1042
   216
	/* Check if mode already exists */
patmandin@1042
   217
	if (XBIOS_modelist) {
patmandin@1042
   218
		current_mode = XBIOS_modelist;
patmandin@1042
   219
		for (i=0;i<XBIOS_nummodes; i++, current_mode++) {
patmandin@1042
   220
			if (current_mode->width != width)
patmandin@1042
   221
				continue;
patmandin@1042
   222
			if (current_mode->height != height)
patmandin@1042
   223
				continue;
patmandin@1042
   224
			if (current_mode->depth != depth)
patmandin@1042
   225
				continue;
patmandin@1042
   226
			return;
patmandin@1042
   227
		}
patmandin@1042
   228
	}
patmandin@1042
   229
patmandin@1042
   230
	++XBIOS_nummodes;
patmandin@1042
   231
	XBIOS_modelist = (xbiosmode_t *) realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t));
patmandin@1042
   232
patmandin@1042
   233
	/* Keep the list sorted: bpp, width, height */
patmandin@1042
   234
	curpos=0;
patmandin@1042
   235
patmandin@1042
   236
	for(i=0; i<XBIOS_nummodes-1; i++) {
patmandin@1042
   237
		if (XBIOS_modelist[i].depth <= depth) {
patmandin@1042
   238
			if (XBIOS_modelist[i].width < width) {
patmandin@1042
   239
				break;
patmandin@1042
   240
			} else if (XBIOS_modelist[i].width == width) {
patmandin@1042
   241
				if (XBIOS_modelist[i].height <= height) {
patmandin@1042
   242
					break;
patmandin@1042
   243
				}
patmandin@1042
   244
			}
patmandin@1042
   245
		}
patmandin@1042
   246
		curpos++;
patmandin@1042
   247
	}
patmandin@1042
   248
patmandin@1042
   249
	/* Push remaining modes further */
patmandin@1042
   250
	for(i=XBIOS_nummodes-1; i>curpos; i--) {
patmandin@1042
   251
		memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t));
patmandin@1042
   252
	}
patmandin@1042
   253
patmandin@1042
   254
	XBIOS_modelist[curpos].number = modecode;
patmandin@1042
   255
	XBIOS_modelist[curpos].width = width;
patmandin@1042
   256
	XBIOS_modelist[curpos].height = height;
patmandin@1042
   257
	XBIOS_modelist[curpos].depth = depth;
patmandin@1042
   258
	XBIOS_modelist[curpos].doubleline = flags;
patmandin@1042
   259
}
patmandin@1042
   260
slouken@281
   261
static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
slouken@281
   262
{
slouken@281
   263
	int i,j8,j16;
slouken@281
   264
	xbiosmode_t *current_mode;
patmandin@1061
   265
	unsigned long cookie_blow, cookie_scpn, cookie_cnts;
slouken@281
   266
slouken@281
   267
	/* Initialize all variables that we clean on shutdown */
slouken@281
   268
	memset (SDL_modelist, 0, sizeof(SDL_modelist));
slouken@281
   269
slouken@281
   270
	/* Cookie _VDO present ? if not, assume ST machine */
slouken@281
   271
	if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) {
slouken@281
   272
		XBIOS_cvdo = VDO_ST << 16;
slouken@281
   273
	}
slouken@281
   274
slouken@281
   275
	/* Allocate memory for old palette */
slouken@281
   276
	XBIOS_oldpalette = (void *)malloc(256*sizeof(long));
slouken@281
   277
	if ( !XBIOS_oldpalette ) {
slouken@281
   278
		SDL_SetError("Unable to allocate memory for old palette\n");
slouken@281
   279
		return(-1);
slouken@281
   280
	}
slouken@281
   281
slouken@281
   282
	/* Initialize video mode list */
slouken@281
   283
	/* and save current screen status (palette, screen address, video mode) */
patmandin@1042
   284
	XBIOS_nummodes = 0;
patmandin@1042
   285
	XBIOS_modelist = NULL;
patmandin@1064
   286
	XBIOS_centscreen = SDL_FALSE;
slouken@281
   287
slouken@281
   288
	switch (XBIOS_cvdo >>16) {
slouken@281
   289
		case VDO_ST:
slouken@281
   290
		case VDO_STE:
slouken@281
   291
			{
slouken@281
   292
				short *oldpalette;
slouken@281
   293
patmandin@1042
   294
				SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE);
slouken@281
   295
			
slouken@281
   296
				XBIOS_oldvbase=Physbase();
slouken@281
   297
				XBIOS_oldvmode=Getrez();
slouken@281
   298
				switch(XBIOS_oldvmode << 8) {
slouken@281
   299
					case ST_LOW:
slouken@281
   300
						XBIOS_oldnumcol=16;
slouken@281
   301
						break;
slouken@281
   302
					case ST_MED:
slouken@281
   303
						XBIOS_oldnumcol=4;
slouken@281
   304
						break;
slouken@281
   305
					case ST_HIGH:
slouken@281
   306
						XBIOS_oldnumcol=2;
slouken@281
   307
						break;
slouken@281
   308
					default:
slouken@281
   309
						XBIOS_oldnumcol=0;
slouken@281
   310
						break;
slouken@281
   311
				}
slouken@281
   312
slouken@281
   313
				oldpalette= (short *) XBIOS_oldpalette;
slouken@281
   314
				for (i=0;i<XBIOS_oldnumcol;i++) {
slouken@281
   315
					*oldpalette++=Setcolor(i,-1);
slouken@281
   316
				}
slouken@281
   317
slouken@281
   318
				vformat->BitsPerPixel = 8;
slouken@281
   319
			}
slouken@281
   320
			break;
slouken@281
   321
		case VDO_TT:
patmandin@1042
   322
patmandin@1042
   323
			SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE);
patmandin@1042
   324
			/* Software double-lined mode */
patmandin@1042
   325
			SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE);
slouken@281
   326
slouken@281
   327
			XBIOS_oldvbase=Logbase();
slouken@281
   328
			XBIOS_oldvmode=EgetShift();
slouken@281
   329
slouken@281
   330
			switch(XBIOS_oldvmode & ES_MODE) {
slouken@281
   331
				case TT_LOW:
slouken@281
   332
					XBIOS_oldnumcol=256;
slouken@281
   333
					break;
slouken@281
   334
				case ST_LOW:
slouken@281
   335
				case TT_MED:
slouken@281
   336
					XBIOS_oldnumcol=16;
slouken@281
   337
					break;
slouken@281
   338
				case ST_MED:
slouken@281
   339
					XBIOS_oldnumcol=4;
slouken@281
   340
					break;
slouken@281
   341
				case ST_HIGH:
slouken@281
   342
				case TT_HIGH:
slouken@281
   343
					XBIOS_oldnumcol=2;
slouken@281
   344
					break;
slouken@281
   345
				default:
slouken@281
   346
					XBIOS_oldnumcol=0;
slouken@281
   347
					break;
slouken@281
   348
			}
slouken@281
   349
			if (XBIOS_oldnumcol) {
slouken@281
   350
				EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
slouken@281
   351
			}
slouken@281
   352
slouken@281
   353
			vformat->BitsPerPixel = 8;
slouken@281
   354
			break;
slouken@281
   355
		case VDO_F30:
slouken@281
   356
			switch (Montype())
slouken@281
   357
			{
slouken@281
   358
				case MONITOR_MONO:
slouken@281
   359
					/* Not usable */
slouken@281
   360
					break;
slouken@281
   361
				case MONITOR_RGB:
slouken@281
   362
				case MONITOR_TV:
patmandin@1042
   363
					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE);
patmandin@1042
   364
					SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE);
patmandin@1042
   365
					SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE);
patmandin@1042
   366
					SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE);
patmandin@1042
   367
					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE);
patmandin@1042
   368
					SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE);
patmandin@1042
   369
					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE);
patmandin@1042
   370
					SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE);
patmandin@1042
   371
					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE);
patmandin@1042
   372
					SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE);
patmandin@1042
   373
					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE);
patmandin@1042
   374
					SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE);
patmandin@1042
   375
					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE);
patmandin@1042
   376
					SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE);
patmandin@1042
   377
					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE);
patmandin@1042
   378
					SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE);
slouken@281
   379
					break;
slouken@281
   380
				case MONITOR_VGA:
patmandin@1042
   381
					SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE);
patmandin@1042
   382
					SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE);
patmandin@1042
   383
					SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE);
patmandin@1042
   384
					SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE);
patmandin@1042
   385
					SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE);
patmandin@1042
   386
					SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE);
slouken@281
   387
					break;
slouken@281
   388
			}
slouken@281
   389
			XBIOS_oldvbase=Logbase();
slouken@281
   390
			XBIOS_oldvmode=Vsetmode(-1);
slouken@281
   391
slouken@281
   392
			XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
slouken@281
   393
			if (XBIOS_oldnumcol > 256) {
slouken@281
   394
				XBIOS_oldnumcol = 0;
slouken@281
   395
			}
slouken@281
   396
			if (XBIOS_oldnumcol) {
slouken@281
   397
				VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
slouken@281
   398
			}
slouken@281
   399
slouken@281
   400
			vformat->BitsPerPixel = 16;
slouken@281
   401
slouken@281
   402
			/* Keep vga/rvb, and pal/ntsc bits */
slouken@281
   403
			current_mode = XBIOS_modelist;
slouken@281
   404
			for (i=0;i<XBIOS_nummodes;i++) {
slouken@281
   405
				Uint16 newvmode;			
slouken@281
   406
slouken@281
   407
				newvmode = current_mode->number;
slouken@281
   408
				newvmode &= ~(VGA|PAL);
slouken@281
   409
				newvmode |= XBIOS_oldvmode & (VGA|PAL);
slouken@281
   410
				current_mode->number = newvmode;
slouken@281
   411
				
slouken@281
   412
				current_mode++;
slouken@281
   413
			}
slouken@281
   414
patmandin@1064
   415
			/* Initialize BlowUp/SB3/Centscreen stuff if present */
patmandin@1040
   416
			if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
patmandin@1040
   417
				SDL_XBIOS_BlowupInit(this, (blow_cookie_t *)cookie_blow);
patmandin@1040
   418
			} else if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
patmandin@1040
   419
				SDL_XBIOS_SB3Init(this, (scpn_cookie_t *)cookie_scpn);
patmandin@1061
   420
			} else if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
patmandin@1064
   421
				XBIOS_oldvmode = SDL_XBIOS_CentscreenInit(this);
patmandin@1064
   422
				XBIOS_centscreen = SDL_TRUE;
patmandin@1040
   423
			}
patmandin@1064
   424
slouken@281
   425
			break;
slouken@281
   426
	}
patmandin@1042
   427
slouken@281
   428
	current_mode = XBIOS_modelist;
slouken@281
   429
	j8 = j16 = 0;
patmandin@1042
   430
	for (i=0; i<XBIOS_nummodes; i++, current_mode++) {
slouken@281
   431
		switch (current_mode->depth) {
slouken@281
   432
			case 4:
slouken@281
   433
			case 8:
slouken@281
   434
				SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect));
slouken@281
   435
				SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0;
slouken@281
   436
				SDL_modelist[0][j8]->w = current_mode->width;
slouken@281
   437
				SDL_modelist[0][j8]->h = current_mode->height;
slouken@281
   438
				XBIOS_videomodes[0][j8]=current_mode;
slouken@281
   439
				j8++;
slouken@281
   440
				break;
slouken@281
   441
			case 16:
slouken@281
   442
				SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect));
slouken@281
   443
				SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0;
slouken@281
   444
				SDL_modelist[1][j16]->w = current_mode->width;
slouken@281
   445
				SDL_modelist[1][j16]->h = current_mode->height;
slouken@281
   446
				XBIOS_videomodes[1][j16]=current_mode;
slouken@281
   447
				j16++;
slouken@281
   448
				break;
slouken@281
   449
		}		
slouken@281
   450
	}
slouken@281
   451
	SDL_modelist[0][j8] = NULL;
slouken@281
   452
	SDL_modelist[1][j16] = NULL;
slouken@281
   453
slouken@281
   454
	XBIOS_screens[0]=NULL;
slouken@281
   455
	XBIOS_screens[1]=NULL;
slouken@281
   456
	XBIOS_shadowscreen=NULL;
slouken@281
   457
slouken@281
   458
	/* Update hardware info */
slouken@281
   459
	this->info.hw_available = 1;
slouken@281
   460
	this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM);
slouken@281
   461
slouken@281
   462
	/* Init chunky to planar routine */
patmandin@735
   463
	SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
slouken@281
   464
patmandin@991
   465
#ifdef HAVE_OPENGL
patmandin@991
   466
	SDL_AtariGL_InitPointers(this);
patmandin@991
   467
#endif
patmandin@991
   468
slouken@281
   469
	/* We're done! */
slouken@281
   470
	return(0);
slouken@281
   471
}
slouken@281
   472
slouken@281
   473
static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
slouken@281
   474
{
slouken@281
   475
	/* 8 bits -> list 0 */
slouken@281
   476
	/* 16 bits -> list 1 */
patmandin@712
   477
	if ((format->BitsPerPixel != 8) && (format->BitsPerPixel !=16)) {
patmandin@711
   478
		return NULL;
patmandin@711
   479
	}
patmandin@711
   480
patmandin@712
   481
	return(SDL_modelist[(format->BitsPerPixel)>>4]);
slouken@281
   482
}
slouken@281
   483
slouken@281
   484
static void XBIOS_FreeBuffers(_THIS)
slouken@281
   485
{
slouken@281
   486
	int i;
slouken@281
   487
slouken@281
   488
	for (i=0;i<2;i++) {
slouken@281
   489
		if (XBIOS_screensmem[i]!=NULL) {
slouken@281
   490
			Mfree(XBIOS_screensmem[i]);
slouken@281
   491
			XBIOS_screensmem[i]=NULL;
slouken@281
   492
		}
slouken@281
   493
	}
slouken@281
   494
slouken@281
   495
	if (XBIOS_shadowscreen!=NULL) {
slouken@281
   496
		Mfree(XBIOS_shadowscreen);
slouken@281
   497
		XBIOS_shadowscreen=NULL;
slouken@281
   498
	}
slouken@281
   499
}
slouken@281
   500
slouken@281
   501
static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
slouken@281
   502
				int width, int height, int bpp, Uint32 flags)
slouken@281
   503
{
slouken@281
   504
	int mode, new_depth;
slouken@281
   505
	int i;
slouken@281
   506
	xbiosmode_t *new_video_mode;
slouken@281
   507
	Uint32 new_screen_size;
slouken@281
   508
	Uint32 modeflags;
slouken@281
   509
slouken@281
   510
	/* Free current buffers */
slouken@281
   511
	XBIOS_FreeBuffers(this);
slouken@281
   512
patmandin@801
   513
	/* Limit bpp */
patmandin@801
   514
	if (bpp>16) {
patmandin@801
   515
		bpp = 16;
patmandin@801
   516
	}
patmandin@801
   517
	bpp >>= 4;
patmandin@801
   518
slouken@281
   519
	/* Search if the mode exists (width, height, bpp) */
slouken@281
   520
	for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
slouken@281
   521
		if ( (SDL_modelist[bpp][mode]->w == width) &&
slouken@281
   522
		     (SDL_modelist[bpp][mode]->h == height) ) {
slouken@281
   523
slouken@281
   524
			break;
slouken@281
   525
		}
slouken@281
   526
	}
slouken@281
   527
	if ( SDL_modelist[bpp][mode] == NULL ) {
slouken@281
   528
		SDL_SetError("Couldn't find requested mode in list");
slouken@281
   529
		return(NULL);
slouken@281
   530
	}
slouken@281
   531
patmandin@1103
   532
	modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
slouken@281
   533
slouken@281
   534
	/* Allocate needed buffers: simple/double buffer and shadow surface */
slouken@281
   535
	new_video_mode = XBIOS_videomodes[bpp][mode];
slouken@281
   536
	new_depth = new_video_mode->depth;
slouken@281
   537
	if (new_depth == 4) {
patmandin@735
   538
		SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
slouken@281
   539
		new_depth=8;
patmandin@1085
   540
		modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
slouken@281
   541
	} else if (new_depth == 8) {
patmandin@735
   542
		SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
slouken@508
   543
		modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
slouken@281
   544
	} else {
slouken@281
   545
		modeflags |= SDL_HWSURFACE;
slouken@281
   546
	}
slouken@281
   547
slouken@281
   548
	new_screen_size = width * height * ((new_depth)>>3);
slouken@281
   549
	new_screen_size += 256; /* To align on a 256 byte adress */	
slouken@281
   550
slouken@281
   551
	if (new_depth == 8) {
slouken@281
   552
		XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
slouken@281
   553
slouken@281
   554
		if (XBIOS_shadowscreen == NULL) {
patmandin@1104
   555
			SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10);
slouken@281
   556
			return (NULL);
slouken@281
   557
		}
slouken@287
   558
		memset(XBIOS_shadowscreen, 0, new_screen_size);
slouken@281
   559
	}
slouken@281
   560
slouken@281
   561
	/* Output buffer needs to be twice in size for the software double-line mode */
slouken@281
   562
	XBIOS_doubleline = SDL_FALSE;
slouken@281
   563
	if (new_video_mode->doubleline) {
slouken@281
   564
		new_screen_size <<= 1;
slouken@281
   565
		XBIOS_doubleline = SDL_TRUE;
slouken@281
   566
	}
slouken@281
   567
slouken@281
   568
	XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM);
slouken@281
   569
slouken@281
   570
	if (XBIOS_screensmem[0]==NULL) {
slouken@281
   571
		XBIOS_FreeBuffers(this);
patmandin@1104
   572
		SDL_SetError("Can not allocate %d KB for frame buffer", new_screen_size>>10);
slouken@281
   573
		return (NULL);
slouken@281
   574
	}
slouken@287
   575
	memset(XBIOS_screensmem[0], 0, new_screen_size);
slouken@281
   576
slouken@281
   577
	XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
slouken@281
   578
patmandin@978
   579
#ifdef HAVE_OPENGL
patmandin@978
   580
	if (flags & SDL_OPENGL) {
patmandin@978
   581
		if (this->gl_config.double_buffer) {
patmandin@978
   582
			flags |= SDL_DOUBLEBUF;
patmandin@978
   583
		}
patmandin@978
   584
	}
patmandin@978
   585
#endif
patmandin@978
   586
slouken@281
   587
	/* Double buffer ? */
slouken@281
   588
	if (flags & SDL_DOUBLEBUF) {
slouken@281
   589
		XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM);
slouken@281
   590
slouken@281
   591
		if (XBIOS_screensmem[1]==NULL) {
slouken@281
   592
			XBIOS_FreeBuffers(this);
patmandin@1104
   593
			SDL_SetError("Can not allocate %d KB for double buffer", new_screen_size>>10);
slouken@281
   594
			return (NULL);
slouken@281
   595
		}
slouken@287
   596
		memset(XBIOS_screensmem[1], 0, new_screen_size);
slouken@281
   597
slouken@281
   598
		XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL);
slouken@281
   599
		modeflags |= SDL_DOUBLEBUF;
slouken@281
   600
	}
slouken@281
   601
	
slouken@281
   602
	/* Allocate the new pixel format for the screen */
slouken@281
   603
	if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
slouken@281
   604
		XBIOS_FreeBuffers(this);
slouken@281
   605
		SDL_SetError("Couldn't allocate new pixel format for requested mode");
slouken@281
   606
		return(NULL);
slouken@281
   607
	}
slouken@281
   608
slouken@281
   609
	current->w = XBIOS_width = width;
slouken@281
   610
	current->h = XBIOS_height = height;
slouken@281
   611
	current->pitch = (width * new_depth)>>3;
slouken@281
   612
slouken@281
   613
	/* this is for C2P conversion */
slouken@281
   614
	XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
slouken@281
   615
slouken@281
   616
	if (new_depth == 8)
slouken@281
   617
		current->pixels = XBIOS_shadowscreen;
slouken@281
   618
	else
slouken@281
   619
		current->pixels = XBIOS_screens[0];
slouken@281
   620
slouken@281
   621
	XBIOS_fbnum = 0;
slouken@281
   622
patmandin@978
   623
#ifdef HAVE_OPENGL
patmandin@978
   624
	if (flags & SDL_OPENGL) {
patmandin@989
   625
		if (!SDL_AtariGL_Init(this, current)) {
patmandin@978
   626
			XBIOS_FreeBuffers(this);
patmandin@989
   627
			SDL_SetError("Can not create OpenGL context");
patmandin@989
   628
			return NULL;
patmandin@978
   629
		}
patmandin@978
   630
patmandin@978
   631
		modeflags |= SDL_OPENGL;
patmandin@978
   632
	}
patmandin@978
   633
#endif
patmandin@978
   634
patmandin@978
   635
	current->flags = modeflags;
patmandin@978
   636
slouken@281
   637
	/* Now set the video mode */
patmandin@735
   638
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   639
	Setscreen(-1,XBIOS_screens[0],-1);
patmandin@735
   640
#endif
slouken@281
   641
slouken@281
   642
	switch(XBIOS_cvdo >> 16) {
slouken@281
   643
		case VDO_ST:
patmandin@735
   644
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   645
			Setscreen(-1,-1,new_video_mode->number);
patmandin@735
   646
#endif
slouken@281
   647
			/* Reset palette */
slouken@281
   648
			for (i=0;i<16;i++) {
patmandin@1085
   649
				TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1);
slouken@281
   650
			}
patmandin@735
   651
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   652
			Setpalette(TT_palette);
patmandin@735
   653
#endif
slouken@281
   654
			break;
slouken@281
   655
		case VDO_STE:
patmandin@735
   656
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   657
			Setscreen(-1,-1,new_video_mode->number);
patmandin@735
   658
#endif
slouken@281
   659
			/* Reset palette */
slouken@281
   660
			for (i=0;i<16;i++)
slouken@281
   661
			{
slouken@281
   662
				int c;
slouken@281
   663
slouken@281
   664
				c=((i&1)<<3)|((i>>1)&7);
slouken@281
   665
				TT_palette[i]=(c<<8)|(c<<4)|c;
slouken@281
   666
			}
patmandin@735
   667
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   668
			Setpalette(TT_palette);
patmandin@735
   669
#endif
slouken@281
   670
			break;
slouken@281
   671
		case VDO_TT:
patmandin@735
   672
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   673
			EsetShift(new_video_mode->number);
patmandin@735
   674
#endif
slouken@281
   675
			break;
slouken@281
   676
		case VDO_F30:
patmandin@735
   677
#ifndef DEBUG_VIDEO_XBIOS
patmandin@1064
   678
			if (XBIOS_centscreen) {
patmandin@1064
   679
				SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth);
patmandin@1064
   680
			} else {
patmandin@1064
   681
				Vsetmode(new_video_mode->number);
patmandin@1064
   682
			}
patmandin@735
   683
#endif
patmandin@1094
   684
			/* Set hardware palette to black in True Colour */
patmandin@1094
   685
			if (new_depth == 16) {
patmandin@1094
   686
				memset(F30_palette, 0, sizeof(F30_palette));
patmandin@1094
   687
				VsetRGB(0,256,F30_palette);
patmandin@1094
   688
			}
slouken@281
   689
			break;
slouken@281
   690
	}
slouken@281
   691
slouken@281
   692
	Vsync();
slouken@281
   693
slouken@281
   694
	this->UpdateRects = XBIOS_UpdateRects;
slouken@281
   695
slouken@281
   696
	return (current);
slouken@281
   697
}
slouken@281
   698
slouken@281
   699
/* We don't actually allow hardware surfaces other than the main one */
slouken@281
   700
static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface)
slouken@281
   701
{
slouken@281
   702
	return(-1);
slouken@281
   703
}
slouken@281
   704
slouken@281
   705
static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface)
slouken@281
   706
{
slouken@281
   707
	return;
slouken@281
   708
}
slouken@281
   709
slouken@281
   710
static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface)
slouken@281
   711
{
slouken@281
   712
	return(0);
slouken@281
   713
}
slouken@281
   714
slouken@281
   715
static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
slouken@281
   716
{
slouken@281
   717
	return;
slouken@281
   718
}
slouken@281
   719
slouken@281
   720
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
slouken@281
   721
{
slouken@281
   722
	SDL_Surface *surface;
slouken@314
   723
slouken@281
   724
	surface = this->screen;
slouken@281
   725
slouken@314
   726
	if ((surface->format->BitsPerPixel) == 8) {
patmandin@1101
   727
		void *destscr;
patmandin@1101
   728
		int destx;
slouken@314
   729
		int i;
slouken@314
   730
patmandin@1101
   731
		/* Center on destination screen */
patmandin@1101
   732
		destscr = XBIOS_screens[XBIOS_fbnum];
patmandin@1101
   733
		destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
patmandin@1101
   734
		destx = (XBIOS_width - surface->w) >> 1;
patmandin@1101
   735
		destx &= ~15;
patmandin@1101
   736
		destscr += destx;
patmandin@1101
   737
slouken@314
   738
		for (i=0;i<numrects;i++) {
slouken@314
   739
			void *source,*destination;
slouken@314
   740
			int x1,x2;
slouken@314
   741
slouken@314
   742
			x1 = rects[i].x & ~15;
slouken@319
   743
			x2 = rects[i].x+rects[i].w;
slouken@319
   744
			if (x2 & 15) {
slouken@319
   745
				x2 = (x2 | 15) +1;
slouken@319
   746
			}
slouken@314
   747
slouken@314
   748
			source = surface->pixels;
slouken@314
   749
			source += surface->pitch * rects[i].y;
slouken@314
   750
			source += x1;
slouken@314
   751
patmandin@1101
   752
			destination = destscr;
slouken@314
   753
			destination += XBIOS_pitch * rects[i].y;
slouken@314
   754
			destination += x1;
slouken@314
   755
slouken@314
   756
			/* Convert chunky to planar screen */
patmandin@735
   757
			SDL_Atari_C2pConvert(
patmandin@1101
   758
				source,
patmandin@1101
   759
				destination,
patmandin@1101
   760
				x2-x1,
patmandin@1101
   761
				rects[i].h,
slouken@314
   762
				XBIOS_doubleline,
patmandin@1101
   763
				surface->pitch,
patmandin@1101
   764
				XBIOS_pitch
slouken@314
   765
			);
slouken@314
   766
		}
slouken@314
   767
	}
slouken@314
   768
patmandin@735
   769
#ifndef DEBUG_VIDEO_XBIOS
slouken@314
   770
	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
patmandin@735
   771
#endif
slouken@314
   772
	Vsync();
slouken@314
   773
slouken@314
   774
	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
slouken@314
   775
		XBIOS_fbnum ^= 1;
slouken@314
   776
		if ((surface->format->BitsPerPixel) > 8) {
slouken@314
   777
			surface->pixels=XBIOS_screens[XBIOS_fbnum];
slouken@314
   778
		}
slouken@314
   779
	}
slouken@281
   780
}
slouken@281
   781
slouken@281
   782
static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
slouken@281
   783
{
slouken@281
   784
	if ((surface->format->BitsPerPixel) == 8) {
patmandin@1101
   785
		void *destscr;
patmandin@1101
   786
		int destx;
patmandin@1101
   787
			
patmandin@1101
   788
		/* Center on destination screen */
patmandin@1101
   789
		destscr = XBIOS_screens[XBIOS_fbnum];
patmandin@1101
   790
		destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
patmandin@1101
   791
		destx = (XBIOS_width - surface->w) >> 1;
patmandin@1101
   792
		destx &= ~15;
patmandin@1101
   793
		destscr += destx;
patmandin@1101
   794
slouken@281
   795
		/* Convert chunky to planar screen */
patmandin@735
   796
		SDL_Atari_C2pConvert(
patmandin@1101
   797
			surface->pixels,
patmandin@1101
   798
			destscr,
patmandin@1101
   799
			surface->w,
patmandin@1101
   800
			surface->h,
slouken@281
   801
			XBIOS_doubleline,
patmandin@1101
   802
			surface->pitch,
patmandin@1101
   803
			XBIOS_pitch
slouken@281
   804
		);
slouken@281
   805
	}
slouken@281
   806
patmandin@735
   807
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   808
	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
patmandin@735
   809
#endif
slouken@281
   810
	Vsync();
slouken@281
   811
slouken@281
   812
	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
slouken@311
   813
		XBIOS_fbnum ^= 1;
slouken@311
   814
		if ((surface->format->BitsPerPixel) > 8) {
slouken@311
   815
			surface->pixels=XBIOS_screens[XBIOS_fbnum];
slouken@311
   816
		}
slouken@281
   817
	}
slouken@281
   818
slouken@281
   819
	return(0);
slouken@281
   820
}
slouken@281
   821
slouken@281
   822
static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@281
   823
{
slouken@281
   824
	int		i;
slouken@281
   825
	int		r,v,b;
slouken@281
   826
slouken@281
   827
	switch( XBIOS_cvdo >> 16) {
slouken@281
   828
		case VDO_ST:
slouken@281
   829
		case VDO_STE:
slouken@281
   830
		 	for (i=0;i<ncolors;i++)
slouken@281
   831
			{
slouken@281
   832
				r = colors[i].r;	
slouken@281
   833
				v = colors[i].g;
slouken@281
   834
				b = colors[i].b;
slouken@281
   835
slouken@281
   836
				TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100;
slouken@281
   837
			}
patmandin@735
   838
			SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
slouken@281
   839
			break;
slouken@281
   840
		case VDO_TT:
slouken@281
   841
			for(i = 0; i < ncolors; i++)
slouken@281
   842
			{
slouken@281
   843
				r = colors[i].r;	
slouken@281
   844
				v = colors[i].g;
slouken@281
   845
				b = colors[i].b;
slouken@281
   846
					
patmandin@1102
   847
				TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
slouken@281
   848
			}
patmandin@735
   849
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   850
			EsetPalette(firstcolor,ncolors,TT_palette);
patmandin@735
   851
#endif
slouken@281
   852
			break;
slouken@281
   853
		case VDO_F30:
slouken@281
   854
			for(i = 0; i < ncolors; i++)
slouken@281
   855
			{
slouken@281
   856
				r = colors[i].r;	
slouken@281
   857
				v = colors[i].g;
slouken@281
   858
				b = colors[i].b;
slouken@281
   859
patmandin@1102
   860
				F30_palette[i]=(r<<16)|(v<<8)|b;
slouken@281
   861
			}
patmandin@735
   862
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   863
			VsetRGB(firstcolor,ncolors,F30_palette);
patmandin@735
   864
#endif
slouken@281
   865
			break;
slouken@281
   866
	}
slouken@281
   867
slouken@281
   868
	return(1);
slouken@281
   869
}
slouken@281
   870
slouken@281
   871
/* Note:  If we are terminated, this could be called in the middle of
slouken@281
   872
   another SDL video routine -- notably UpdateRects.
slouken@281
   873
*/
slouken@281
   874
static void XBIOS_VideoQuit(_THIS)
slouken@281
   875
{
slouken@281
   876
	int i,j;
slouken@281
   877
slouken@281
   878
	Atari_ShutdownEvents();
slouken@281
   879
slouken@281
   880
	/* Restore video mode and palette */
patmandin@801
   881
#ifndef DEBUG_VIDEO_XBIOS
slouken@281
   882
	switch(XBIOS_cvdo >> 16) {
slouken@281
   883
		case VDO_ST:
slouken@281
   884
		case VDO_STE:
slouken@281
   885
			Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
slouken@281
   886
			if (XBIOS_oldnumcol) {
slouken@281
   887
				Setpalette(XBIOS_oldpalette);
slouken@281
   888
			}
slouken@281
   889
			break;
slouken@281
   890
		case VDO_TT:
slouken@281
   891
			Setscreen(-1,XBIOS_oldvbase,-1);
slouken@281
   892
			EsetShift(XBIOS_oldvmode);
slouken@281
   893
			if (XBIOS_oldnumcol) {
slouken@281
   894
				EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
slouken@281
   895
			}
slouken@281
   896
			break;
slouken@281
   897
		case VDO_F30:
slouken@281
   898
			Setscreen(-1, XBIOS_oldvbase, -1);
patmandin@1064
   899
			if (XBIOS_centscreen) {
patmandin@1064
   900
				SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode);
patmandin@1064
   901
			} else {
patmandin@1064
   902
				Vsetmode(XBIOS_oldvmode);
patmandin@1064
   903
			}
slouken@281
   904
			if (XBIOS_oldnumcol) {
slouken@281
   905
				VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
slouken@281
   906
			}
slouken@281
   907
			break;
slouken@281
   908
	}
slouken@281
   909
	Vsync();
patmandin@801
   910
#endif
slouken@281
   911
patmandin@992
   912
patmandin@992
   913
#ifdef HAVE_OPENGL
patmandin@992
   914
	if (gl_active) {
patmandin@992
   915
		SDL_AtariGL_Quit(this, SDL_TRUE);
patmandin@992
   916
	}
patmandin@992
   917
#endif
patmandin@992
   918
slouken@281
   919
	if (XBIOS_oldpalette) {
slouken@281
   920
		free(XBIOS_oldpalette);
slouken@281
   921
		XBIOS_oldpalette=NULL;
slouken@281
   922
	}
slouken@281
   923
	XBIOS_FreeBuffers(this);
slouken@281
   924
slouken@281
   925
	/* Free mode list */
slouken@281
   926
	for (j=0;j<NUM_MODELISTS;j++) {
slouken@281
   927
		for (i=0;i<SDL_NUMMODES;i++) {
slouken@281
   928
			if (SDL_modelist[j][i]!=NULL) {
slouken@281
   929
				free(SDL_modelist[j][i]);
slouken@281
   930
				SDL_modelist[j][i]=NULL;
slouken@281
   931
			}
slouken@281
   932
		}
slouken@281
   933
	}
slouken@281
   934
patmandin@1042
   935
	if (XBIOS_modelist) {
patmandin@1042
   936
		free(XBIOS_modelist);
patmandin@1042
   937
		XBIOS_nummodes=0;
patmandin@1042
   938
		XBIOS_modelist=NULL;
patmandin@1042
   939
	}
patmandin@1042
   940
slouken@281
   941
	this->screen->pixels = NULL;	
slouken@281
   942
}
patmandin@978
   943
patmandin@978
   944
#ifdef HAVE_OPENGL
patmandin@978
   945
patmandin@978
   946
static void XBIOS_GL_SwapBuffers(_THIS)
patmandin@978
   947
{
patmandin@993
   948
	SDL_AtariGL_SwapBuffers(this);
patmandin@993
   949
	XBIOS_FlipHWSurface(this, this->screen);
patmandin@993
   950
	SDL_AtariGL_MakeCurrent(this);
patmandin@978
   951
}
patmandin@978
   952
patmandin@978
   953
#endif