src/video/svga/SDL_svgavideo.c
author Sam Lantinga <slouken@lokigames.com>
Thu, 26 Apr 2001 16:45:43 +0000
changeset 0 74212992fb08
child 1 cf2af46e9e2a
permissions -rw-r--r--
Initial revision
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@0
    20
    slouken@devolution.com
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* SVGAlib based SDL video driver implementation.
slouken@0
    29
*/
slouken@0
    30
slouken@0
    31
#include <stdlib.h>
slouken@0
    32
#include <stdio.h>
slouken@0
    33
#include <unistd.h>
slouken@0
    34
#include <sys/stat.h>
slouken@0
    35
slouken@0
    36
#if defined(linux)
slouken@0
    37
#include <linux/vt.h>
slouken@0
    38
#elif defined(__FreeBSD__)
slouken@0
    39
#include <sys/consio.h>
slouken@0
    40
#else
slouken@0
    41
#error You must choose your operating system here
slouken@0
    42
#endif
slouken@0
    43
#include <vga.h>
slouken@0
    44
#include <vgamouse.h>
slouken@0
    45
#include <vgakeyboard.h>
slouken@0
    46
slouken@0
    47
#include "SDL.h"
slouken@0
    48
#include "SDL_error.h"
slouken@0
    49
#include "SDL_video.h"
slouken@0
    50
#include "SDL_mouse.h"
slouken@0
    51
#include "SDL_sysvideo.h"
slouken@0
    52
#include "SDL_pixels_c.h"
slouken@0
    53
#include "SDL_events_c.h"
slouken@0
    54
#include "SDL_svgavideo.h"
slouken@0
    55
#include "SDL_svgaevents_c.h"
slouken@0
    56
#include "SDL_svgamouse_c.h"
slouken@0
    57
slouken@0
    58
slouken@0
    59
/* Initialization/Query functions */
slouken@0
    60
static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
slouken@0
    61
static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
slouken@0
    62
static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
slouken@0
    63
static int SVGA_SetColors(_THIS, int firstcolor, int ncolors,
slouken@0
    64
			  SDL_Color *colors);
slouken@0
    65
static void SVGA_VideoQuit(_THIS);
slouken@0
    66
slouken@0
    67
/* Hardware surface functions */
slouken@0
    68
static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    69
static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    70
static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    71
static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    72
static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    73
slouken@0
    74
/* SVGAlib driver bootstrap functions */
slouken@0
    75
slouken@0
    76
static int SVGA_Available(void)
slouken@0
    77
{
slouken@0
    78
	/* Check to see if we are root and stdin is a virtual console */
slouken@0
    79
	int console;
slouken@0
    80
slouken@0
    81
	console = STDIN_FILENO;
slouken@0
    82
	if ( console >= 0 ) {
slouken@0
    83
		struct stat sb;
slouken@0
    84
		struct vt_mode dummy;
slouken@0
    85
slouken@0
    86
		if ( (fstat(console, &sb) < 0) ||
slouken@0
    87
		     (ioctl(console, VT_GETMODE, &dummy) < 0) ) {
slouken@0
    88
			console = -1;
slouken@0
    89
		}
slouken@0
    90
	}
slouken@0
    91
	return((geteuid() == 0) && (console >= 0));
slouken@0
    92
}
slouken@0
    93
slouken@0
    94
static void SVGA_DeleteDevice(SDL_VideoDevice *device)
slouken@0
    95
{
slouken@0
    96
	free(device->hidden);
slouken@0
    97
	free(device);
slouken@0
    98
}
slouken@0
    99
slouken@0
   100
static SDL_VideoDevice *SVGA_CreateDevice(int devindex)
slouken@0
   101
{
slouken@0
   102
	SDL_VideoDevice *device;
slouken@0
   103
slouken@0
   104
	/* Initialize all variables that we clean on shutdown */
slouken@0
   105
	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
slouken@0
   106
	if ( device ) {
slouken@0
   107
		memset(device, 0, (sizeof *device));
slouken@0
   108
		device->hidden = (struct SDL_PrivateVideoData *)
slouken@0
   109
				malloc((sizeof *device->hidden));
slouken@0
   110
	}
slouken@0
   111
	if ( (device == NULL) || (device->hidden == NULL) ) {
slouken@0
   112
		SDL_OutOfMemory();
slouken@0
   113
		if ( device ) {
slouken@0
   114
			free(device);
slouken@0
   115
		}
slouken@0
   116
		return(0);
slouken@0
   117
	}
slouken@0
   118
	memset(device->hidden, 0, (sizeof *device->hidden));
slouken@0
   119
slouken@0
   120
	/* Set the function pointers */
slouken@0
   121
	device->VideoInit = SVGA_VideoInit;
slouken@0
   122
	device->ListModes = SVGA_ListModes;
slouken@0
   123
	device->SetVideoMode = SVGA_SetVideoMode;
slouken@0
   124
	device->SetColors = SVGA_SetColors;
slouken@0
   125
	device->UpdateRects = NULL;
slouken@0
   126
	device->VideoQuit = SVGA_VideoQuit;
slouken@0
   127
	device->AllocHWSurface = SVGA_AllocHWSurface;
slouken@0
   128
	device->CheckHWBlit = NULL;
slouken@0
   129
	device->FillHWRect = NULL;
slouken@0
   130
	device->SetHWColorKey = NULL;
slouken@0
   131
	device->SetHWAlpha = NULL;
slouken@0
   132
	device->LockHWSurface = SVGA_LockHWSurface;
slouken@0
   133
	device->UnlockHWSurface = SVGA_UnlockHWSurface;
slouken@0
   134
	device->FlipHWSurface = NULL;
slouken@0
   135
	device->FreeHWSurface = SVGA_FreeHWSurface;
slouken@0
   136
	device->SetCaption = NULL;
slouken@0
   137
	device->SetIcon = NULL;
slouken@0
   138
	device->IconifyWindow = NULL;
slouken@0
   139
	device->GrabInput = NULL;
slouken@0
   140
	device->GetWMInfo = NULL;
slouken@0
   141
	device->InitOSKeymap = SVGA_InitOSKeymap;
slouken@0
   142
	device->PumpEvents = SVGA_PumpEvents;
slouken@0
   143
slouken@0
   144
	device->free = SVGA_DeleteDevice;
slouken@0
   145
slouken@0
   146
	return device;
slouken@0
   147
}
slouken@0
   148
slouken@0
   149
VideoBootStrap SVGALIB_bootstrap = {
slouken@0
   150
	"svgalib", "SVGAlib",
slouken@0
   151
	SVGA_Available, SVGA_CreateDevice
slouken@0
   152
};
slouken@0
   153
slouken@0
   154
static int SVGA_AddMode(_THIS, int mode, int actually_add, int force)
slouken@0
   155
{
slouken@0
   156
	vga_modeinfo *modeinfo;
slouken@0
   157
slouken@0
   158
	modeinfo = vga_getmodeinfo(mode);
slouken@0
   159
	if ( force || ( modeinfo->flags & CAPABLE_LINEAR ) ) {
slouken@0
   160
		int i, j;
slouken@0
   161
slouken@0
   162
		i = modeinfo->bytesperpixel-1;
slouken@0
   163
		if ( actually_add ) {
slouken@0
   164
			SDL_Rect saved_rect[2];
slouken@0
   165
			int      saved_mode[2];
slouken@0
   166
			int b;
slouken@0
   167
slouken@0
   168
			/* Add the mode, sorted largest to smallest */
slouken@0
   169
			b = 0;
slouken@0
   170
			j = 0;
slouken@0
   171
			while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
slouken@0
   172
			        (SDL_modelist[i][j]->h > modeinfo->height) ) {
slouken@0
   173
				++j;
slouken@0
   174
			}
slouken@0
   175
			/* Skip modes that are already in our list */
slouken@0
   176
			if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
slouken@0
   177
			     (SDL_modelist[i][j]->h == modeinfo->height) ) {
slouken@0
   178
				return(0);
slouken@0
   179
			}
slouken@0
   180
			/* Insert the new mode */
slouken@0
   181
			saved_rect[b] = *SDL_modelist[i][j];
slouken@0
   182
			saved_mode[b] = SDL_vgamode[i][j];
slouken@0
   183
			SDL_modelist[i][j]->w = modeinfo->width;
slouken@0
   184
			SDL_modelist[i][j]->h = modeinfo->height;
slouken@0
   185
			SDL_vgamode[i][j] = mode;
slouken@0
   186
			/* Everybody scoot down! */
slouken@0
   187
			if ( saved_rect[b].w && saved_rect[b].h ) {
slouken@0
   188
			    for ( ++j; SDL_modelist[i][j]->w; ++j ) {
slouken@0
   189
				saved_rect[!b] = *SDL_modelist[i][j];
slouken@0
   190
				saved_mode[!b] = SDL_vgamode[i][j];
slouken@0
   191
				*SDL_modelist[i][j] = saved_rect[b];
slouken@0
   192
				SDL_vgamode[i][j] = saved_mode[b];
slouken@0
   193
				b = !b;
slouken@0
   194
			    }
slouken@0
   195
			    *SDL_modelist[i][j] = saved_rect[b];
slouken@0
   196
			    SDL_vgamode[i][j] = saved_mode[b];
slouken@0
   197
			}
slouken@0
   198
		} else {
slouken@0
   199
			++SDL_nummodes[i];
slouken@0
   200
		}
slouken@0
   201
	}
slouken@0
   202
	return( force || ( modeinfo->flags & CAPABLE_LINEAR ) );
slouken@0
   203
}
slouken@0
   204
slouken@0
   205
static void SVGA_UpdateVideoInfo(_THIS)
slouken@0
   206
{
slouken@0
   207
	vga_modeinfo *modeinfo;
slouken@0
   208
slouken@0
   209
	this->info.wm_available = 0;
slouken@0
   210
	this->info.hw_available = 1;
slouken@0
   211
	modeinfo = vga_getmodeinfo(vga_getcurrentmode());
slouken@0
   212
	this->info.video_mem = (modeinfo->maxpixels/1024);
slouken@0
   213
	if ( modeinfo->bytesperpixel > 0 ) {
slouken@0
   214
		this->info.video_mem *= modeinfo->bytesperpixel;
slouken@0
   215
	}
slouken@0
   216
	/* FIXME: Add hardware accelerated blit information */
slouken@0
   217
#if 0
slouken@0
   218
printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not ");
slouken@0
   219
#endif
slouken@0
   220
}
slouken@0
   221
slouken@0
   222
int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
slouken@0
   223
{
slouken@0
   224
	int keyboard;
slouken@0
   225
	int i, j;
slouken@0
   226
	int mode, total_modes;
slouken@0
   227
slouken@0
   228
	/* Initialize all variables that we clean on shutdown */
slouken@0
   229
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   230
		SDL_nummodes[i] = 0;
slouken@0
   231
		SDL_modelist[i] = NULL;
slouken@0
   232
		SDL_vgamode[i] = NULL;
slouken@0
   233
	}
slouken@0
   234
slouken@0
   235
	/* Initialize the library */
slouken@0
   236
	vga_disabledriverreport();
slouken@0
   237
	if ( vga_init() < 0 ) {
slouken@0
   238
		SDL_SetError("Unable to initialize SVGAlib");
slouken@0
   239
		return(-1);
slouken@0
   240
	}
slouken@0
   241
	vga_setmode(TEXT);
slouken@0
   242
slouken@0
   243
	/* Enable mouse and keyboard support */
slouken@0
   244
	vga_setmousesupport(1);
slouken@0
   245
	keyboard = keyboard_init_return_fd();
slouken@0
   246
	if ( keyboard < 0 ) {
slouken@0
   247
		SDL_SetError("Unable to initialize keyboard");
slouken@0
   248
		return(-1);
slouken@0
   249
	}
slouken@0
   250
	if ( SVGA_initkeymaps(keyboard) < 0 ) {
slouken@0
   251
		return(-1);
slouken@0
   252
	}
slouken@0
   253
	keyboard_seteventhandler(SVGA_keyboardcallback);
slouken@0
   254
slouken@0
   255
	/* Determine the screen depth (use default 8-bit depth) */
slouken@0
   256
	vformat->BitsPerPixel = 8;
slouken@0
   257
slouken@0
   258
	/* Enumerate the available fullscreen modes */
slouken@0
   259
	total_modes = 0;
slouken@0
   260
	for ( mode=vga_lastmodenumber(); mode; --mode ) {
slouken@0
   261
		if ( vga_hasmode(mode) ) {
slouken@0
   262
			if ( SVGA_AddMode(this, mode, 0, 0) ) {
slouken@0
   263
				++total_modes;
slouken@0
   264
			}
slouken@0
   265
		}
slouken@0
   266
	}
slouken@0
   267
	if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes;
slouken@0
   268
	if ( total_modes == 0 ) {
slouken@0
   269
		SDL_SetError("No linear video modes available");
slouken@0
   270
		return(-1);
slouken@0
   271
	}
slouken@0
   272
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   273
		SDL_vgamode[i] = (int *)malloc(SDL_nummodes[i]*sizeof(int));
slouken@0
   274
		if ( SDL_vgamode[i] == NULL ) {
slouken@0
   275
			SDL_OutOfMemory();
slouken@0
   276
			return(-1);
slouken@0
   277
		}
slouken@0
   278
		SDL_modelist[i] = (SDL_Rect **)
slouken@0
   279
				malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
slouken@0
   280
		if ( SDL_modelist[i] == NULL ) {
slouken@0
   281
			SDL_OutOfMemory();
slouken@0
   282
			return(-1);
slouken@0
   283
		}
slouken@0
   284
		for ( j=0; j<SDL_nummodes[i]; ++j ) {
slouken@0
   285
			SDL_modelist[i][j]=(SDL_Rect *)malloc(sizeof(SDL_Rect));
slouken@0
   286
			if ( SDL_modelist[i][j] == NULL ) {
slouken@0
   287
				SDL_OutOfMemory();
slouken@0
   288
				return(-1);
slouken@0
   289
			}
slouken@0
   290
			memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
slouken@0
   291
		}
slouken@0
   292
		SDL_modelist[i][j] = NULL;
slouken@0
   293
	}
slouken@0
   294
	for ( mode=vga_lastmodenumber(); mode; --mode ) {
slouken@0
   295
		if ( vga_hasmode(mode) ) {
slouken@0
   296
			SVGA_AddMode(this, mode, 1, 0);
slouken@0
   297
		}
slouken@0
   298
	}
slouken@0
   299
	SVGA_AddMode(this, G320x200x256, 1, 1);
slouken@0
   300
slouken@0
   301
	/* Free extra (duplicated) modes */
slouken@0
   302
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   303
		j = 0;
slouken@0
   304
		while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) {
slouken@0
   305
			j++;
slouken@0
   306
		}
slouken@0
   307
		while ( SDL_modelist[i][j] ) {
slouken@0
   308
			free(SDL_modelist[i][j]);
slouken@0
   309
			SDL_modelist[i][j] = NULL;
slouken@0
   310
			j++;
slouken@0
   311
		}
slouken@0
   312
	}
slouken@0
   313
slouken@0
   314
	/* Fill in our hardware acceleration capabilities */
slouken@0
   315
	SVGA_UpdateVideoInfo(this);
slouken@0
   316
slouken@0
   317
	/* We're done! */
slouken@0
   318
	return(0);
slouken@0
   319
}
slouken@0
   320
slouken@0
   321
SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
slouken@0
   322
{
slouken@0
   323
	return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
slouken@0
   324
}
slouken@0
   325
slouken@0
   326
/* Various screen update functions available */
slouken@0
   327
static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
slouken@0
   328
static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects);
slouken@0
   329
slouken@0
   330
SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
   331
				int width, int height, int bpp, Uint32 flags)
slouken@0
   332
{
slouken@0
   333
	int mode;
slouken@0
   334
	int vgamode;
slouken@0
   335
	vga_modeinfo *modeinfo;
slouken@0
   336
slouken@0
   337
	/* Try to set the requested linear video mode */
slouken@0
   338
	bpp = (bpp+7)/8-1;
slouken@0
   339
	for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
slouken@0
   340
		if ( (SDL_modelist[bpp][mode]->w == width) &&
slouken@0
   341
		     (SDL_modelist[bpp][mode]->h == height) ) {
slouken@0
   342
			break;
slouken@0
   343
		}
slouken@0
   344
	}
slouken@0
   345
	if ( SDL_modelist[bpp][mode] == NULL ) {
slouken@0
   346
		SDL_SetError("Couldn't find requested mode in list");
slouken@0
   347
		return(NULL);
slouken@0
   348
	}
slouken@0
   349
	vga_setmode(SDL_vgamode[bpp][mode]);
slouken@0
   350
	vga_setpage(0);
slouken@0
   351
slouken@0
   352
	vgamode=SDL_vgamode[bpp][mode];
slouken@0
   353
	if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) {
slouken@0
   354
		SDL_SetError("Unable to set linear addressing");
slouken@0
   355
		return(NULL);
slouken@0
   356
	}
slouken@0
   357
	modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]);
slouken@0
   358
slouken@0
   359
	/* Update hardware acceleration info */
slouken@0
   360
	SVGA_UpdateVideoInfo(this);
slouken@0
   361
slouken@0
   362
	/* Allocate the new pixel format for the screen */
slouken@0
   363
	bpp = (bpp+1)*8;
slouken@0
   364
	if ( (bpp == 16) && (modeinfo->colors == 32768) ) {
slouken@0
   365
		bpp = 15;
slouken@0
   366
	}
slouken@0
   367
	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
slouken@0
   368
		return(NULL);
slouken@0
   369
	}
slouken@0
   370
slouken@0
   371
	/* Set up the new mode framebuffer */
slouken@0
   372
	current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
slouken@0
   373
	current->w = width;
slouken@0
   374
	current->h = height;
slouken@0
   375
	current->pitch = modeinfo->linewidth;
slouken@0
   376
	current->pixels = vga_getgraphmem();
slouken@0
   377
slouken@0
   378
	/* Set the blit function */
slouken@0
   379
	this->UpdateRects = SVGA_DirectUpdate;
slouken@0
   380
slouken@0
   381
	/* Set up the mouse handler again (buggy SVGAlib 1.40) */
slouken@0
   382
	mouse_seteventhandler(SVGA_mousecallback);
slouken@0
   383
slouken@0
   384
	/* We're done */
slouken@0
   385
	return(current);
slouken@0
   386
}
slouken@0
   387
slouken@0
   388
/* We don't actually allow hardware surfaces other than the main one */
slouken@0
   389
static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   390
{
slouken@0
   391
	return(-1);
slouken@0
   392
}
slouken@0
   393
static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   394
{
slouken@0
   395
	return;
slouken@0
   396
}
slouken@0
   397
slouken@0
   398
/* We need to wait for vertical retrace on page flipped displays */
slouken@0
   399
static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   400
{
slouken@0
   401
	if ( (surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
slouken@0
   402
		vga_waitretrace();
slouken@0
   403
	}
slouken@0
   404
	return(0);
slouken@0
   405
}
slouken@0
   406
static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   407
{
slouken@0
   408
	return;
slouken@0
   409
}
slouken@0
   410
slouken@0
   411
/* FIXME: How is this done with SVGAlib? */
slouken@0
   412
static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   413
{
slouken@0
   414
	return(0);
slouken@0
   415
}
slouken@0
   416
slouken@0
   417
static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
slouken@0
   418
{
slouken@0
   419
	return;
slouken@0
   420
}
slouken@0
   421
slouken@0
   422
/* FIXME: Can this be used under SVGAlib? */
slouken@0
   423
static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects)
slouken@0
   424
{
slouken@0
   425
	return;
slouken@0
   426
}
slouken@0
   427
slouken@0
   428
int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@0
   429
{
slouken@0
   430
        int i;
slouken@0
   431
slouken@0
   432
	for(i = 0; i < ncolors; i++) {
slouken@0
   433
	        vga_setpalette(firstcolor + i,
slouken@0
   434
			       colors[i].r>>2,
slouken@0
   435
			       colors[i].g>>2,
slouken@0
   436
			       colors[i].b>>2);
slouken@0
   437
	}
slouken@0
   438
	return(1);
slouken@0
   439
}
slouken@0
   440
slouken@0
   441
/* Note:  If we are terminated, this could be called in the middle of
slouken@0
   442
   another SDL video routine -- notably UpdateRects.
slouken@0
   443
*/
slouken@0
   444
void SVGA_VideoQuit(_THIS)
slouken@0
   445
{
slouken@0
   446
	int i, j;
slouken@0
   447
slouken@0
   448
	/* Reset the console video mode */
slouken@0
   449
	if ( this->screen && (this->screen->w && this->screen->h) ) {
slouken@0
   450
		vga_setmode(TEXT);
slouken@0
   451
	}
slouken@0
   452
	keyboard_close();
slouken@0
   453
slouken@0
   454
	/* Free video mode lists */
slouken@0
   455
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   456
		if ( SDL_modelist[i] != NULL ) {
slouken@0
   457
			for ( j=0; SDL_modelist[i][j]; ++j )
slouken@0
   458
				free(SDL_modelist[i][j]);
slouken@0
   459
			free(SDL_modelist[i]);
slouken@0
   460
			SDL_modelist[i] = NULL;
slouken@0
   461
		}
slouken@0
   462
		if ( SDL_vgamode[i] != NULL ) {
slouken@0
   463
			free(SDL_vgamode[i]);
slouken@0
   464
			SDL_vgamode[i] = NULL;
slouken@0
   465
		}
slouken@0
   466
	}
slouken@0
   467
	if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) {
slouken@0
   468
		/* Direct screen access, no memory buffer */
slouken@0
   469
		this->screen->pixels = NULL;
slouken@0
   470
	}
slouken@0
   471
}