src/video/svga/SDL_svgavideo.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Oct 2001 19:49:02 +0000
changeset 205 13161d3d349d
parent 67 3647c809813d
child 226 bb72c418a1f9
permissions -rw-r--r--
Added double-buffering support for SVGAlib (thanks Kutak!)
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@67
    35
#include <sys/types.h>
slouken@67
    36
#include <sys/ioctl.h>
slouken@67
    37
#include <fcntl.h>
slouken@0
    38
slouken@0
    39
#if defined(linux)
slouken@0
    40
#include <linux/vt.h>
slouken@0
    41
#elif defined(__FreeBSD__)
slouken@0
    42
#include <sys/consio.h>
slouken@0
    43
#else
slouken@0
    44
#error You must choose your operating system here
slouken@0
    45
#endif
slouken@0
    46
#include <vga.h>
slouken@0
    47
#include <vgamouse.h>
slouken@0
    48
#include <vgakeyboard.h>
slouken@0
    49
slouken@0
    50
#include "SDL.h"
slouken@0
    51
#include "SDL_error.h"
slouken@0
    52
#include "SDL_video.h"
slouken@0
    53
#include "SDL_mouse.h"
slouken@0
    54
#include "SDL_sysvideo.h"
slouken@0
    55
#include "SDL_pixels_c.h"
slouken@0
    56
#include "SDL_events_c.h"
slouken@0
    57
#include "SDL_svgavideo.h"
slouken@0
    58
#include "SDL_svgaevents_c.h"
slouken@0
    59
#include "SDL_svgamouse_c.h"
slouken@0
    60
slouken@0
    61
slouken@0
    62
/* Initialization/Query functions */
slouken@0
    63
static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
slouken@0
    64
static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
slouken@0
    65
static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
slouken@0
    66
static int SVGA_SetColors(_THIS, int firstcolor, int ncolors,
slouken@0
    67
			  SDL_Color *colors);
slouken@0
    68
static void SVGA_VideoQuit(_THIS);
slouken@0
    69
slouken@0
    70
/* Hardware surface functions */
slouken@0
    71
static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    72
static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    73
static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    74
static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    75
static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface);
slouken@0
    76
slouken@0
    77
/* SVGAlib driver bootstrap functions */
slouken@0
    78
slouken@0
    79
static int SVGA_Available(void)
slouken@0
    80
{
slouken@0
    81
	/* Check to see if we are root and stdin is a virtual console */
slouken@0
    82
	int console;
slouken@67
    83
	
slouken@67
    84
	/* SVGALib 1.9.x+ doesn't require root (via /dev/svga) */
slouken@67
    85
	int svgalib2 = -1;
slouken@0
    86
slouken@67
    87
	/* See if we are connected to a virtual terminal */
slouken@0
    88
	console = STDIN_FILENO;
slouken@0
    89
	if ( console >= 0 ) {
slouken@0
    90
		struct stat sb;
slouken@0
    91
		struct vt_mode dummy;
slouken@0
    92
slouken@0
    93
		if ( (fstat(console, &sb) < 0) ||
slouken@0
    94
		     (ioctl(console, VT_GETMODE, &dummy) < 0) ) {
slouken@0
    95
			console = -1;
slouken@0
    96
		}
slouken@0
    97
	}
slouken@67
    98
slouken@67
    99
	/* See if SVGAlib 2.0 is available */
slouken@67
   100
	svgalib2 = open("/dev/svga", O_RDONLY);
slouken@67
   101
	if (svgalib2 != -1) {
slouken@67
   102
		close(svgalib2);
slouken@67
   103
	}
slouken@67
   104
slouken@67
   105
	return(((svgalib2 != -1) || (geteuid() == 0)) && (console >= 0));
slouken@0
   106
}
slouken@0
   107
slouken@0
   108
static void SVGA_DeleteDevice(SDL_VideoDevice *device)
slouken@0
   109
{
slouken@0
   110
	free(device->hidden);
slouken@0
   111
	free(device);
slouken@0
   112
}
slouken@0
   113
slouken@0
   114
static SDL_VideoDevice *SVGA_CreateDevice(int devindex)
slouken@0
   115
{
slouken@0
   116
	SDL_VideoDevice *device;
slouken@0
   117
slouken@0
   118
	/* Initialize all variables that we clean on shutdown */
slouken@0
   119
	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
slouken@0
   120
	if ( device ) {
slouken@0
   121
		memset(device, 0, (sizeof *device));
slouken@0
   122
		device->hidden = (struct SDL_PrivateVideoData *)
slouken@0
   123
				malloc((sizeof *device->hidden));
slouken@0
   124
	}
slouken@0
   125
	if ( (device == NULL) || (device->hidden == NULL) ) {
slouken@0
   126
		SDL_OutOfMemory();
slouken@0
   127
		if ( device ) {
slouken@0
   128
			free(device);
slouken@0
   129
		}
slouken@0
   130
		return(0);
slouken@0
   131
	}
slouken@0
   132
	memset(device->hidden, 0, (sizeof *device->hidden));
slouken@0
   133
slouken@0
   134
	/* Set the function pointers */
slouken@0
   135
	device->VideoInit = SVGA_VideoInit;
slouken@0
   136
	device->ListModes = SVGA_ListModes;
slouken@0
   137
	device->SetVideoMode = SVGA_SetVideoMode;
slouken@0
   138
	device->SetColors = SVGA_SetColors;
slouken@0
   139
	device->UpdateRects = NULL;
slouken@0
   140
	device->VideoQuit = SVGA_VideoQuit;
slouken@0
   141
	device->AllocHWSurface = SVGA_AllocHWSurface;
slouken@0
   142
	device->CheckHWBlit = NULL;
slouken@0
   143
	device->FillHWRect = NULL;
slouken@0
   144
	device->SetHWColorKey = NULL;
slouken@0
   145
	device->SetHWAlpha = NULL;
slouken@0
   146
	device->LockHWSurface = SVGA_LockHWSurface;
slouken@0
   147
	device->UnlockHWSurface = SVGA_UnlockHWSurface;
slouken@205
   148
	device->FlipHWSurface = SVGA_FlipHWSurface;
slouken@0
   149
	device->FreeHWSurface = SVGA_FreeHWSurface;
slouken@0
   150
	device->SetCaption = NULL;
slouken@0
   151
	device->SetIcon = NULL;
slouken@0
   152
	device->IconifyWindow = NULL;
slouken@0
   153
	device->GrabInput = NULL;
slouken@0
   154
	device->GetWMInfo = NULL;
slouken@0
   155
	device->InitOSKeymap = SVGA_InitOSKeymap;
slouken@0
   156
	device->PumpEvents = SVGA_PumpEvents;
slouken@0
   157
slouken@0
   158
	device->free = SVGA_DeleteDevice;
slouken@0
   159
slouken@0
   160
	return device;
slouken@0
   161
}
slouken@0
   162
slouken@0
   163
VideoBootStrap SVGALIB_bootstrap = {
slouken@0
   164
	"svgalib", "SVGAlib",
slouken@0
   165
	SVGA_Available, SVGA_CreateDevice
slouken@0
   166
};
slouken@0
   167
slouken@0
   168
static int SVGA_AddMode(_THIS, int mode, int actually_add, int force)
slouken@0
   169
{
slouken@0
   170
	vga_modeinfo *modeinfo;
slouken@0
   171
slouken@0
   172
	modeinfo = vga_getmodeinfo(mode);
slouken@0
   173
	if ( force || ( modeinfo->flags & CAPABLE_LINEAR ) ) {
slouken@0
   174
		int i, j;
slouken@0
   175
slouken@0
   176
		i = modeinfo->bytesperpixel-1;
slouken@0
   177
		if ( actually_add ) {
slouken@0
   178
			SDL_Rect saved_rect[2];
slouken@0
   179
			int      saved_mode[2];
slouken@0
   180
			int b;
slouken@0
   181
slouken@0
   182
			/* Add the mode, sorted largest to smallest */
slouken@0
   183
			b = 0;
slouken@0
   184
			j = 0;
slouken@0
   185
			while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
slouken@0
   186
			        (SDL_modelist[i][j]->h > modeinfo->height) ) {
slouken@0
   187
				++j;
slouken@0
   188
			}
slouken@0
   189
			/* Skip modes that are already in our list */
slouken@0
   190
			if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
slouken@0
   191
			     (SDL_modelist[i][j]->h == modeinfo->height) ) {
slouken@0
   192
				return(0);
slouken@0
   193
			}
slouken@0
   194
			/* Insert the new mode */
slouken@0
   195
			saved_rect[b] = *SDL_modelist[i][j];
slouken@0
   196
			saved_mode[b] = SDL_vgamode[i][j];
slouken@0
   197
			SDL_modelist[i][j]->w = modeinfo->width;
slouken@0
   198
			SDL_modelist[i][j]->h = modeinfo->height;
slouken@0
   199
			SDL_vgamode[i][j] = mode;
slouken@0
   200
			/* Everybody scoot down! */
slouken@0
   201
			if ( saved_rect[b].w && saved_rect[b].h ) {
slouken@0
   202
			    for ( ++j; SDL_modelist[i][j]->w; ++j ) {
slouken@0
   203
				saved_rect[!b] = *SDL_modelist[i][j];
slouken@0
   204
				saved_mode[!b] = SDL_vgamode[i][j];
slouken@0
   205
				*SDL_modelist[i][j] = saved_rect[b];
slouken@0
   206
				SDL_vgamode[i][j] = saved_mode[b];
slouken@0
   207
				b = !b;
slouken@0
   208
			    }
slouken@0
   209
			    *SDL_modelist[i][j] = saved_rect[b];
slouken@0
   210
			    SDL_vgamode[i][j] = saved_mode[b];
slouken@0
   211
			}
slouken@0
   212
		} else {
slouken@0
   213
			++SDL_nummodes[i];
slouken@0
   214
		}
slouken@0
   215
	}
slouken@0
   216
	return( force || ( modeinfo->flags & CAPABLE_LINEAR ) );
slouken@0
   217
}
slouken@0
   218
slouken@0
   219
static void SVGA_UpdateVideoInfo(_THIS)
slouken@0
   220
{
slouken@0
   221
	vga_modeinfo *modeinfo;
slouken@0
   222
slouken@0
   223
	this->info.wm_available = 0;
slouken@0
   224
	this->info.hw_available = 1;
slouken@0
   225
	modeinfo = vga_getmodeinfo(vga_getcurrentmode());
slouken@205
   226
	this->info.video_mem = modeinfo->memory;
slouken@0
   227
	/* FIXME: Add hardware accelerated blit information */
slouken@0
   228
#if 0
slouken@0
   229
printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not ");
slouken@0
   230
#endif
slouken@0
   231
}
slouken@0
   232
slouken@0
   233
int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
slouken@0
   234
{
slouken@0
   235
	int keyboard;
slouken@0
   236
	int i, j;
slouken@0
   237
	int mode, total_modes;
slouken@0
   238
slouken@0
   239
	/* Initialize all variables that we clean on shutdown */
slouken@0
   240
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   241
		SDL_nummodes[i] = 0;
slouken@0
   242
		SDL_modelist[i] = NULL;
slouken@0
   243
		SDL_vgamode[i] = NULL;
slouken@0
   244
	}
slouken@0
   245
slouken@0
   246
	/* Initialize the library */
slouken@0
   247
	vga_disabledriverreport();
slouken@0
   248
	if ( vga_init() < 0 ) {
slouken@0
   249
		SDL_SetError("Unable to initialize SVGAlib");
slouken@0
   250
		return(-1);
slouken@0
   251
	}
slouken@0
   252
	vga_setmode(TEXT);
slouken@0
   253
slouken@0
   254
	/* Enable mouse and keyboard support */
slouken@0
   255
	vga_setmousesupport(1);
slouken@0
   256
	keyboard = keyboard_init_return_fd();
slouken@0
   257
	if ( keyboard < 0 ) {
slouken@0
   258
		SDL_SetError("Unable to initialize keyboard");
slouken@0
   259
		return(-1);
slouken@0
   260
	}
slouken@0
   261
	if ( SVGA_initkeymaps(keyboard) < 0 ) {
slouken@0
   262
		return(-1);
slouken@0
   263
	}
slouken@0
   264
	keyboard_seteventhandler(SVGA_keyboardcallback);
slouken@0
   265
slouken@0
   266
	/* Determine the screen depth (use default 8-bit depth) */
slouken@0
   267
	vformat->BitsPerPixel = 8;
slouken@0
   268
slouken@0
   269
	/* Enumerate the available fullscreen modes */
slouken@0
   270
	total_modes = 0;
slouken@0
   271
	for ( mode=vga_lastmodenumber(); mode; --mode ) {
slouken@0
   272
		if ( vga_hasmode(mode) ) {
slouken@0
   273
			if ( SVGA_AddMode(this, mode, 0, 0) ) {
slouken@0
   274
				++total_modes;
slouken@0
   275
			}
slouken@0
   276
		}
slouken@0
   277
	}
slouken@0
   278
	if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes;
slouken@0
   279
	if ( total_modes == 0 ) {
slouken@0
   280
		SDL_SetError("No linear video modes available");
slouken@0
   281
		return(-1);
slouken@0
   282
	}
slouken@0
   283
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   284
		SDL_vgamode[i] = (int *)malloc(SDL_nummodes[i]*sizeof(int));
slouken@0
   285
		if ( SDL_vgamode[i] == NULL ) {
slouken@0
   286
			SDL_OutOfMemory();
slouken@0
   287
			return(-1);
slouken@0
   288
		}
slouken@0
   289
		SDL_modelist[i] = (SDL_Rect **)
slouken@0
   290
				malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
slouken@0
   291
		if ( SDL_modelist[i] == NULL ) {
slouken@0
   292
			SDL_OutOfMemory();
slouken@0
   293
			return(-1);
slouken@0
   294
		}
slouken@0
   295
		for ( j=0; j<SDL_nummodes[i]; ++j ) {
slouken@0
   296
			SDL_modelist[i][j]=(SDL_Rect *)malloc(sizeof(SDL_Rect));
slouken@0
   297
			if ( SDL_modelist[i][j] == NULL ) {
slouken@0
   298
				SDL_OutOfMemory();
slouken@0
   299
				return(-1);
slouken@0
   300
			}
slouken@0
   301
			memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
slouken@0
   302
		}
slouken@0
   303
		SDL_modelist[i][j] = NULL;
slouken@0
   304
	}
slouken@0
   305
	for ( mode=vga_lastmodenumber(); mode; --mode ) {
slouken@0
   306
		if ( vga_hasmode(mode) ) {
slouken@0
   307
			SVGA_AddMode(this, mode, 1, 0);
slouken@0
   308
		}
slouken@0
   309
	}
slouken@0
   310
	SVGA_AddMode(this, G320x200x256, 1, 1);
slouken@0
   311
slouken@0
   312
	/* Free extra (duplicated) modes */
slouken@0
   313
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   314
		j = 0;
slouken@0
   315
		while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) {
slouken@0
   316
			j++;
slouken@0
   317
		}
slouken@0
   318
		while ( SDL_modelist[i][j] ) {
slouken@0
   319
			free(SDL_modelist[i][j]);
slouken@0
   320
			SDL_modelist[i][j] = NULL;
slouken@0
   321
			j++;
slouken@0
   322
		}
slouken@0
   323
	}
slouken@0
   324
slouken@0
   325
	/* Fill in our hardware acceleration capabilities */
slouken@0
   326
	SVGA_UpdateVideoInfo(this);
slouken@0
   327
slouken@0
   328
	/* We're done! */
slouken@0
   329
	return(0);
slouken@0
   330
}
slouken@0
   331
slouken@0
   332
SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
slouken@0
   333
{
slouken@0
   334
	return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
slouken@0
   335
}
slouken@0
   336
slouken@0
   337
/* Various screen update functions available */
slouken@0
   338
static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
slouken@0
   339
static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects);
slouken@0
   340
slouken@0
   341
SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
   342
				int width, int height, int bpp, Uint32 flags)
slouken@0
   343
{
slouken@0
   344
	int mode;
slouken@0
   345
	int vgamode;
slouken@0
   346
	vga_modeinfo *modeinfo;
slouken@205
   347
	int screenpage_len;
slouken@0
   348
slouken@0
   349
	/* Try to set the requested linear video mode */
slouken@0
   350
	bpp = (bpp+7)/8-1;
slouken@0
   351
	for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
slouken@0
   352
		if ( (SDL_modelist[bpp][mode]->w == width) &&
slouken@0
   353
		     (SDL_modelist[bpp][mode]->h == height) ) {
slouken@0
   354
			break;
slouken@0
   355
		}
slouken@0
   356
	}
slouken@0
   357
	if ( SDL_modelist[bpp][mode] == NULL ) {
slouken@0
   358
		SDL_SetError("Couldn't find requested mode in list");
slouken@0
   359
		return(NULL);
slouken@0
   360
	}
slouken@0
   361
	vga_setmode(SDL_vgamode[bpp][mode]);
slouken@0
   362
	vga_setpage(0);
slouken@0
   363
slouken@0
   364
	vgamode=SDL_vgamode[bpp][mode];
slouken@0
   365
	if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) {
slouken@0
   366
		SDL_SetError("Unable to set linear addressing");
slouken@0
   367
		return(NULL);
slouken@0
   368
	}
slouken@0
   369
	modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]);
slouken@0
   370
slouken@0
   371
	/* Update hardware acceleration info */
slouken@0
   372
	SVGA_UpdateVideoInfo(this);
slouken@0
   373
slouken@0
   374
	/* Allocate the new pixel format for the screen */
slouken@0
   375
	bpp = (bpp+1)*8;
slouken@0
   376
	if ( (bpp == 16) && (modeinfo->colors == 32768) ) {
slouken@0
   377
		bpp = 15;
slouken@0
   378
	}
slouken@0
   379
	if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
slouken@0
   380
		return(NULL);
slouken@0
   381
	}
slouken@0
   382
slouken@0
   383
	/* Set up the new mode framebuffer */
slouken@0
   384
	current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
slouken@1
   385
	if ( bpp == 8 ) {
slouken@1
   386
		/* FIXME: What about DirectColor? */
slouken@1
   387
		current->flags |= SDL_HWPALETTE;
slouken@1
   388
	}
slouken@0
   389
	current->w = width;
slouken@0
   390
	current->h = height;
slouken@0
   391
	current->pitch = modeinfo->linewidth;
slouken@0
   392
	current->pixels = vga_getgraphmem();
slouken@0
   393
slouken@205
   394
	/* set double-buffering */
slouken@205
   395
	if ( flags & SDL_DOUBLEBUF )
slouken@205
   396
	{
slouken@205
   397
	    /* length of one screen page in bytes */
slouken@205
   398
	    screenpage_len=current->h*modeinfo->linewidth;
slouken@205
   399
slouken@205
   400
	    /* if start address should be aligned */
slouken@205
   401
	    if ( modeinfo->linewidth_unit )
slouken@205
   402
	    {
slouken@205
   403
		if ( screenpage_len % modeinfo->linewidth_unit )    
slouken@205
   404
		{
slouken@205
   405
		    screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit );
slouken@205
   406
		}
slouken@205
   407
	    }
slouken@205
   408
slouken@205
   409
	    /* if we heve enough videomemory =  ak je dost videopamete  */
slouken@205
   410
	    if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) )
slouken@205
   411
	    {
slouken@205
   412
		current->flags |= SDL_DOUBLEBUF;
slouken@205
   413
		flip_page = 0;
slouken@205
   414
		flip_offset[0] = 0;
slouken@205
   415
		flip_offset[1] = screenpage_len;
slouken@205
   416
		flip_address[0] = vga_getgraphmem();
slouken@205
   417
		flip_address[1] = flip_address[0]+screenpage_len;
slouken@205
   418
		SVGA_FlipHWSurface(this,current);
slouken@205
   419
	    }
slouken@205
   420
	} 
slouken@205
   421
slouken@0
   422
	/* Set the blit function */
slouken@0
   423
	this->UpdateRects = SVGA_DirectUpdate;
slouken@0
   424
slouken@0
   425
	/* Set up the mouse handler again (buggy SVGAlib 1.40) */
slouken@0
   426
	mouse_seteventhandler(SVGA_mousecallback);
slouken@0
   427
slouken@0
   428
	/* We're done */
slouken@0
   429
	return(current);
slouken@0
   430
}
slouken@0
   431
slouken@0
   432
/* We don't actually allow hardware surfaces other than the main one */
slouken@0
   433
static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   434
{
slouken@0
   435
	return(-1);
slouken@0
   436
}
slouken@0
   437
static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   438
{
slouken@0
   439
	return;
slouken@0
   440
}
slouken@0
   441
slouken@0
   442
/* We need to wait for vertical retrace on page flipped displays */
slouken@0
   443
static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   444
{
slouken@205
   445
	/* The waiting is done in SVGA_FlipHWSurface() */
slouken@0
   446
	return(0);
slouken@0
   447
}
slouken@0
   448
static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   449
{
slouken@0
   450
	return;
slouken@0
   451
}
slouken@0
   452
slouken@0
   453
static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface)
slouken@0
   454
{
slouken@205
   455
	vga_setdisplaystart(flip_offset[flip_page]);
slouken@205
   456
	flip_page=!flip_page;
slouken@205
   457
	surface->pixels=flip_address[flip_page];
slouken@205
   458
	vga_waitretrace();
slouken@0
   459
	return(0);
slouken@0
   460
}
slouken@0
   461
slouken@0
   462
static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
slouken@0
   463
{
slouken@0
   464
	return;
slouken@0
   465
}
slouken@0
   466
slouken@0
   467
/* FIXME: Can this be used under SVGAlib? */
slouken@0
   468
static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects)
slouken@0
   469
{
slouken@0
   470
	return;
slouken@0
   471
}
slouken@0
   472
slouken@0
   473
int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@0
   474
{
slouken@0
   475
        int i;
slouken@0
   476
slouken@0
   477
	for(i = 0; i < ncolors; i++) {
slouken@0
   478
	        vga_setpalette(firstcolor + i,
slouken@0
   479
			       colors[i].r>>2,
slouken@0
   480
			       colors[i].g>>2,
slouken@0
   481
			       colors[i].b>>2);
slouken@0
   482
	}
slouken@0
   483
	return(1);
slouken@0
   484
}
slouken@0
   485
slouken@0
   486
/* Note:  If we are terminated, this could be called in the middle of
slouken@0
   487
   another SDL video routine -- notably UpdateRects.
slouken@0
   488
*/
slouken@0
   489
void SVGA_VideoQuit(_THIS)
slouken@0
   490
{
slouken@0
   491
	int i, j;
slouken@0
   492
slouken@0
   493
	/* Reset the console video mode */
slouken@0
   494
	if ( this->screen && (this->screen->w && this->screen->h) ) {
slouken@0
   495
		vga_setmode(TEXT);
slouken@0
   496
	}
slouken@0
   497
	keyboard_close();
slouken@0
   498
slouken@0
   499
	/* Free video mode lists */
slouken@0
   500
	for ( i=0; i<NUM_MODELISTS; ++i ) {
slouken@0
   501
		if ( SDL_modelist[i] != NULL ) {
slouken@0
   502
			for ( j=0; SDL_modelist[i][j]; ++j )
slouken@0
   503
				free(SDL_modelist[i][j]);
slouken@0
   504
			free(SDL_modelist[i]);
slouken@0
   505
			SDL_modelist[i] = NULL;
slouken@0
   506
		}
slouken@0
   507
		if ( SDL_vgamode[i] != NULL ) {
slouken@0
   508
			free(SDL_vgamode[i]);
slouken@0
   509
			SDL_vgamode[i] = NULL;
slouken@0
   510
		}
slouken@0
   511
	}
slouken@0
   512
	if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) {
slouken@0
   513
		/* Direct screen access, no memory buffer */
slouken@0
   514
		this->screen->pixels = NULL;
slouken@0
   515
	}
slouken@0
   516
}
slouken@205
   517