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