annotate src/video/svga/SDL_svgavideo.c @ 1743:70a4d819e95e

Future proof C++ code
author Sam Lantinga <slouken@libsdl.org>
date Fri, 28 Apr 2006 05:43:58 +0000
parents 011b633fa0c9
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
13 Lesser General Public License for more details.
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 226
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
22 #include "SDL_config.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 /* SVGAlib based SDL video driver implementation.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <sys/stat.h>
67
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
29 #include <sys/types.h>
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
30 #include <sys/ioctl.h>
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
31 #include <fcntl.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
33 #if defined(__LINUX__)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <linux/vt.h>
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
35 #elif defined(__FREEBSD__)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include <sys/consio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #error You must choose your operating system here
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #include <vga.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include <vgamouse.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include <vgakeyboard.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #include "SDL_video.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #include "SDL_mouse.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
46 #include "../SDL_sysvideo.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
47 #include "../SDL_pixels_c.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
48 #include "../../events/SDL_events_c.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 #include "SDL_svgavideo.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 #include "SDL_svgaevents_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 #include "SDL_svgamouse_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 /* Initialization/Query functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 static int SVGA_SetColors(_THIS, int firstcolor, int ncolors,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 SDL_Color *colors);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 static void SVGA_VideoQuit(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 /* Hardware surface functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 /* SVGAlib driver bootstrap functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 static int SVGA_Available(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 /* Check to see if we are root and stdin is a virtual console */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 int console;
67
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
74
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
75 /* SVGALib 1.9.x+ doesn't require root (via /dev/svga) */
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
76 int svgalib2 = -1;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77
67
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
78 /* See if we are connected to a virtual terminal */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 console = STDIN_FILENO;
226
bb72c418a1f9 Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents: 205
diff changeset
80 #if 0 /* This is no longer needed, SVGAlib can switch consoles for us */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 if ( console >= 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 struct stat sb;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 struct vt_mode dummy;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 if ( (fstat(console, &sb) < 0) ||
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 (ioctl(console, VT_GETMODE, &dummy) < 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 console = -1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 }
226
bb72c418a1f9 Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents: 205
diff changeset
90 #endif /* 0 */
67
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
91
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
92 /* See if SVGAlib 2.0 is available */
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
93 svgalib2 = open("/dev/svga", O_RDONLY);
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
94 if (svgalib2 != -1) {
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
95 close(svgalib2);
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
96 }
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
97
3647c809813d Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents: 1
diff changeset
98 return(((svgalib2 != -1) || (geteuid() == 0)) && (console >= 0));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 static void SVGA_DeleteDevice(SDL_VideoDevice *device)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
103 SDL_free(device->hidden);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
104 SDL_free(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 static SDL_VideoDevice *SVGA_CreateDevice(int devindex)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 SDL_VideoDevice *device;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
110
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
111 /* Initialize all variables that we clean on shutdown */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
112 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113 if ( device ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
114 SDL_memset(device, 0, (sizeof *device));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 device->hidden = (struct SDL_PrivateVideoData *)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
116 SDL_malloc((sizeof *device->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 if ( (device == NULL) || (device->hidden == NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120 if ( device ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
121 SDL_free(device);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
123 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
125 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 /* Set the function pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 device->VideoInit = SVGA_VideoInit;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 device->ListModes = SVGA_ListModes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 device->SetVideoMode = SVGA_SetVideoMode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 device->SetColors = SVGA_SetColors;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 device->UpdateRects = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 device->VideoQuit = SVGA_VideoQuit;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134 device->AllocHWSurface = SVGA_AllocHWSurface;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 device->CheckHWBlit = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 device->FillHWRect = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 device->SetHWColorKey = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 device->SetHWAlpha = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 device->LockHWSurface = SVGA_LockHWSurface;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 device->UnlockHWSurface = SVGA_UnlockHWSurface;
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
141 device->FlipHWSurface = SVGA_FlipHWSurface;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142 device->FreeHWSurface = SVGA_FreeHWSurface;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 device->SetCaption = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 device->SetIcon = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 device->IconifyWindow = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 device->GrabInput = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 device->GetWMInfo = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 device->InitOSKeymap = SVGA_InitOSKeymap;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 device->PumpEvents = SVGA_PumpEvents;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 device->free = SVGA_DeleteDevice;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153 return device;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 VideoBootStrap SVGALIB_bootstrap = {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 "svgalib", "SVGAlib",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 SVGA_Available, SVGA_CreateDevice
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
161 static int SVGA_AddMode(_THIS, int mode, int actually_add)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162 {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
163 int i, j;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 vga_modeinfo *modeinfo;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 modeinfo = vga_getmodeinfo(mode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
167
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
168 i = modeinfo->bytesperpixel-1;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
169 if ( i < 0 ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
170 return 0;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
171 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
172 if ( actually_add ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
173 SDL_Rect saved_rect[2];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
174 int saved_mode[2];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
175 int b;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
177 /* Add the mode, sorted largest to smallest */
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
178 b = 0;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
179 j = 0;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
180 while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
181 (SDL_modelist[i][j]->h > modeinfo->height) ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
182 ++j;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
183 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
184 /* Skip modes that are already in our list */
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
185 if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
186 (SDL_modelist[i][j]->h == modeinfo->height) ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
187 return(0);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 }
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
189 /* Insert the new mode */
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
190 saved_rect[b] = *SDL_modelist[i][j];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
191 saved_mode[b] = SDL_vgamode[i][j];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
192 SDL_modelist[i][j]->w = modeinfo->width;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
193 SDL_modelist[i][j]->h = modeinfo->height;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
194 SDL_vgamode[i][j] = mode;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
195 /* Everybody scoot down! */
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
196 if ( saved_rect[b].w && saved_rect[b].h ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
197 for ( ++j; SDL_modelist[i][j]->w; ++j ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
198 saved_rect[!b] = *SDL_modelist[i][j];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
199 saved_mode[!b] = SDL_vgamode[i][j];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
200 *SDL_modelist[i][j] = saved_rect[b];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
201 SDL_vgamode[i][j] = saved_mode[b];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
202 b = !b;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
203 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
204 *SDL_modelist[i][j] = saved_rect[b];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
205 SDL_vgamode[i][j] = saved_mode[b];
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
206 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
207 } else {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
208 ++SDL_nummodes[i];
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 }
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
210 return(1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
212
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
213 static void SVGA_UpdateVideoInfo(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 vga_modeinfo *modeinfo;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
216
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 this->info.wm_available = 0;
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
218 this->info.hw_available = (banked ? 0 : 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 modeinfo = vga_getmodeinfo(vga_getcurrentmode());
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
220 this->info.video_mem = modeinfo->memory;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
221 /* FIXME: Add hardware accelerated blit information */
226
bb72c418a1f9 Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents: 205
diff changeset
222 #ifdef SVGALIB_DEBUG
bb72c418a1f9 Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents: 205
diff changeset
223 printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not ");
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 #endif
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
227 int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
228 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 int keyboard;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 int i, j;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 int mode, total_modes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 /* Initialize all variables that we clean on shutdown */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 for ( i=0; i<NUM_MODELISTS; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 SDL_nummodes[i] = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
236 SDL_modelist[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
237 SDL_vgamode[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
238 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
239
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240 /* Initialize the library */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
241 vga_disabledriverreport();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
242 if ( vga_init() < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 SDL_SetError("Unable to initialize SVGAlib");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
244 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
245 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
246 vga_setmode(TEXT);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
248 /* Enable mouse and keyboard support */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 vga_setmousesupport(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 keyboard = keyboard_init_return_fd();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 if ( keyboard < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 SDL_SetError("Unable to initialize keyboard");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
255 if ( SVGA_initkeymaps(keyboard) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
256 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
257 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
258 keyboard_seteventhandler(SVGA_keyboardcallback);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259
1545
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
260 /* Determine the current screen size */
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
261 this->info.current_w = 0;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
262 this->info.current_h = 0;
8d9bb0cf2c2a Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
263
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 /* Determine the screen depth (use default 8-bit depth) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 vformat->BitsPerPixel = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
267 /* Enumerate the available fullscreen modes */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268 total_modes = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
269 for ( mode=vga_lastmodenumber(); mode; --mode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
270 if ( vga_hasmode(mode) ) {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
271 if ( SVGA_AddMode(this, mode, 0) ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
272 ++total_modes;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275 }
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
276 if ( SVGA_AddMode(this, G320x200x256, 0) ) ++total_modes;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 if ( total_modes == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
278 SDL_SetError("No linear video modes available");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
279 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
280 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 for ( i=0; i<NUM_MODELISTS; ++i ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
282 SDL_vgamode[i] = (int *)SDL_malloc(SDL_nummodes[i]*sizeof(int));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283 if ( SDL_vgamode[i] == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287 SDL_modelist[i] = (SDL_Rect **)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
288 SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
289 if ( SDL_modelist[i] == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
290 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
291 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
292 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293 for ( j=0; j<SDL_nummodes[i]; ++j ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
294 SDL_modelist[i][j]=(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
295 if ( SDL_modelist[i][j] == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
296 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
299 SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 SDL_modelist[i][j] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 for ( mode=vga_lastmodenumber(); mode; --mode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 if ( vga_hasmode(mode) ) {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
305 SVGA_AddMode(this, mode, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 }
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
308 SVGA_AddMode(this, G320x200x256, 1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 /* Free extra (duplicated) modes */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 for ( i=0; i<NUM_MODELISTS; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 j = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314 j++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 while ( SDL_modelist[i][j] ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
317 SDL_free(SDL_modelist[i][j]);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 SDL_modelist[i][j] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 j++;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 /* Fill in our hardware acceleration capabilities */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 SVGA_UpdateVideoInfo(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 /* We're done! */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 /* Various screen update functions available */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
339 SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
340 int width, int height, int bpp, Uint32 flags)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
341 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342 int mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 int vgamode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 vga_modeinfo *modeinfo;
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
345 int screenpage_len;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
347 /* Free old pixels if we were in banked mode */
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
348 if ( banked && current->pixels ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
349 free(current->pixels);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
350 current->pixels = NULL;
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
351 }
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
352
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 /* Try to set the requested linear video mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 bpp = (bpp+7)/8-1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 if ( (SDL_modelist[bpp][mode]->w == width) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 (SDL_modelist[bpp][mode]->h == height) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 if ( SDL_modelist[bpp][mode] == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 SDL_SetError("Couldn't find requested mode in list");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 }
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
365 vgamode = SDL_vgamode[bpp][mode];
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
366 vga_setmode(vgamode);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 vga_setpage(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
369 if ( (vga_setlinearaddressing() < 0) && (vgamode != G320x200x256) ) {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
370 banked = 1;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
371 } else {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
372 banked = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 }
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
374
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 /* Update hardware acceleration info */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 SVGA_UpdateVideoInfo(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 /* Allocate the new pixel format for the screen */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 bpp = (bpp+1)*8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 if ( (bpp == 16) && (modeinfo->colors == 32768) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 bpp = 15;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
385 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 return(NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 /* Set up the new mode framebuffer */
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
390 current->flags = SDL_FULLSCREEN;
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
391 if ( !banked ) {
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
392 current->flags |= SDL_HWSURFACE;
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
393 }
1
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
394 if ( bpp == 8 ) {
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
395 /* FIXME: What about DirectColor? */
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
396 current->flags |= SDL_HWPALETTE;
cf2af46e9e2a Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents: 0
diff changeset
397 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 current->w = width;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 current->h = height;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 current->pitch = modeinfo->linewidth;
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
401 if ( banked ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
402 current->pixels = SDL_malloc(current->h * current->pitch);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
403 if ( !current->pixels ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
404 SDL_OutOfMemory();
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
405 return(NULL);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
406 }
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
407 } else {
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
408 current->pixels = vga_getgraphmem();
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
409 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
411 /* set double-buffering */
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
412 if ( (flags & SDL_DOUBLEBUF) && !banked )
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
413 {
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
414 /* length of one screen page in bytes */
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
415 screenpage_len=current->h*modeinfo->linewidth;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
416
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
417 /* if start address should be aligned */
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
418 if ( modeinfo->linewidth_unit )
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
419 {
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
420 if ( screenpage_len % modeinfo->linewidth_unit )
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
421 {
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
422 screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit );
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
423 }
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
424 }
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
425
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
426 /* if we heve enough videomemory = ak je dost videopamete */
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
427 if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) )
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
428 {
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
429 current->flags |= SDL_DOUBLEBUF;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
430 flip_page = 0;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
431 flip_offset[0] = 0;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
432 flip_offset[1] = screenpage_len;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
433 flip_address[0] = vga_getgraphmem();
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
434 flip_address[1] = flip_address[0]+screenpage_len;
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
435 SVGA_FlipHWSurface(this,current);
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
436 }
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
437 }
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
438
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439 /* Set the blit function */
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
440 if ( banked ) {
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
441 this->UpdateRects = SVGA_BankedUpdate;
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
442 } else {
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
443 this->UpdateRects = SVGA_DirectUpdate;
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
444 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 /* Set up the mouse handler again (buggy SVGAlib 1.40) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 mouse_seteventhandler(SVGA_mousecallback);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 /* We're done */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 return(current);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 /* We don't actually allow hardware surfaces other than the main one */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 /* We need to wait for vertical retrace on page flipped displays */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 {
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
466 /* The waiting is done in SVGA_FlipHWSurface() */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
469 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
471 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
473
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475 {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
476 if ( !banked ) {
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
477 vga_setdisplaystart(flip_offset[flip_page]);
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
478 flip_page=!flip_page;
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
479 surface->pixels=flip_address[flip_page];
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
480 vga_waitretrace();
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
481 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
486 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
490 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491 {
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
492 int i, j;
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
493 SDL_Rect *rect;
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
494 int page, vp;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
495 int x, y, w, h;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
496 unsigned char *src;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
497 unsigned char *dst;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
498 int bpp = this->screen->format->BytesPerPixel;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
499 int pitch = this->screen->pitch;
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
500
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
501 dst = vga_getgraphmem();
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
502 for ( i=0; i < numrects; ++i ) {
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
503 rect = &rects[i];
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
504 x = rect->x;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
505 y = rect->y;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
506 w = rect->w * bpp;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
507 h = rect->h;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
508
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
509 vp = y * pitch + x * bpp;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
510 src = (unsigned char *)this->screen->pixels + vp;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
511 page = vp >> 16;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
512 vp &= 0xffff;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
513 vga_setpage(page);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
514 for (j = 0; j < h; j++) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
515 if (vp + w > 0x10000) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
516 if (vp >= 0x10000) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
517 page++;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
518 vga_setpage(page);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
519 vp &= 0xffff;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
520 } else {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
521 SDL_memcpy(dst + vp, src, 0x10000 - vp);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
522 page++;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
523 vga_setpage(page);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
524 SDL_memcpy(dst, src + 0x10000 - vp,
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
525 (vp + w) & 0xffff);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
526 vp = (vp + pitch) & 0xffff;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
527 src += pitch;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
528 continue;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
529 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
530 }
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
531 SDL_memcpy(dst + vp, src, w);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
532 src += pitch;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
533 vp += pitch;
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
534 }
1554
0ca607a5d173 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1545
diff changeset
535 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538 int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 for(i = 0; i < ncolors; i++) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 vga_setpalette(firstcolor + i,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 colors[i].r>>2,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 colors[i].g>>2,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 colors[i].b>>2);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 return(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 /* Note: If we are terminated, this could be called in the middle of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 another SDL video routine -- notably UpdateRects.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 void SVGA_VideoQuit(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 int i, j;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558 /* Reset the console video mode */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
559 if ( this->screen && (this->screen->w && this->screen->h) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
560 vga_setmode(TEXT);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
561 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
562 keyboard_close();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
563
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
564 /* Free video mode lists */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
565 for ( i=0; i<NUM_MODELISTS; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
566 if ( SDL_modelist[i] != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
567 for ( j=0; SDL_modelist[i][j]; ++j )
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
568 SDL_free(SDL_modelist[i][j]);
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
569 SDL_free(SDL_modelist[i]);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
570 SDL_modelist[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 if ( SDL_vgamode[i] != NULL ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
573 SDL_free(SDL_vgamode[i]);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
574 SDL_vgamode[i] = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
575 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
576 }
1556
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
577 if ( this->screen ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
578 if ( banked && this->screen->pixels ) {
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
579 SDL_free(this->screen->pixels);
011b633fa0c9 Fixed bug #84
Sam Lantinga <slouken@libsdl.org>
parents: 1554
diff changeset
580 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
581 this->screen->pixels = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
582 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
583 }
205
13161d3d349d Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents: 67
diff changeset
584