Mercurial > sdl-ios-xcode
annotate src/video/svga/SDL_svgavideo.c @ 4363:028d26915548 SDL-1.2
Added an untested code path for snd_pcm_wait()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 19 Oct 2009 05:59:07 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 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 /* Initialization/Query functions */ | |
54 static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
55 static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
56 static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
57 static int SVGA_SetColors(_THIS, int firstcolor, int ncolors, | |
58 SDL_Color *colors); | |
59 static void SVGA_VideoQuit(_THIS); | |
60 | |
61 /* Hardware surface functions */ | |
62 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface); | |
63 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface); | |
64 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface); | |
65 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
66 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface); | |
67 | |
68 /* SVGAlib driver bootstrap functions */ | |
69 | |
70 static int SVGA_Available(void) | |
71 { | |
72 /* Check to see if we are root and stdin is a virtual console */ | |
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 | 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 | 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 | 81 if ( console >= 0 ) { |
82 struct stat sb; | |
83 struct vt_mode dummy; | |
84 | |
85 if ( (fstat(console, &sb) < 0) || | |
86 (ioctl(console, VT_GETMODE, &dummy) < 0) ) { | |
87 console = -1; | |
88 } | |
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 | 99 } |
100 | |
101 static void SVGA_DeleteDevice(SDL_VideoDevice *device) | |
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 | 105 } |
106 | |
107 static SDL_VideoDevice *SVGA_CreateDevice(int devindex) | |
108 { | |
109 SDL_VideoDevice *device; | |
110 | |
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 | 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 | 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 | 117 } |
118 if ( (device == NULL) || (device->hidden == NULL) ) { | |
119 SDL_OutOfMemory(); | |
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 | 122 } |
123 return(0); | |
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 | 126 |
127 /* Set the function pointers */ | |
128 device->VideoInit = SVGA_VideoInit; | |
129 device->ListModes = SVGA_ListModes; | |
130 device->SetVideoMode = SVGA_SetVideoMode; | |
131 device->SetColors = SVGA_SetColors; | |
132 device->UpdateRects = NULL; | |
133 device->VideoQuit = SVGA_VideoQuit; | |
134 device->AllocHWSurface = SVGA_AllocHWSurface; | |
135 device->CheckHWBlit = NULL; | |
136 device->FillHWRect = NULL; | |
137 device->SetHWColorKey = NULL; | |
138 device->SetHWAlpha = NULL; | |
139 device->LockHWSurface = SVGA_LockHWSurface; | |
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 | 142 device->FreeHWSurface = SVGA_FreeHWSurface; |
143 device->SetCaption = NULL; | |
144 device->SetIcon = NULL; | |
145 device->IconifyWindow = NULL; | |
146 device->GrabInput = NULL; | |
147 device->GetWMInfo = NULL; | |
148 device->InitOSKeymap = SVGA_InitOSKeymap; | |
149 device->PumpEvents = SVGA_PumpEvents; | |
150 | |
151 device->free = SVGA_DeleteDevice; | |
152 | |
153 return device; | |
154 } | |
155 | |
156 VideoBootStrap SVGALIB_bootstrap = { | |
157 "svgalib", "SVGAlib", | |
158 SVGA_Available, SVGA_CreateDevice | |
159 }; | |
160 | |
1556 | 161 static int SVGA_AddMode(_THIS, int mode, int actually_add) |
0 | 162 { |
1556 | 163 int i, j; |
0 | 164 vga_modeinfo *modeinfo; |
165 | |
166 modeinfo = vga_getmodeinfo(mode); | |
167 | |
1556 | 168 i = modeinfo->bytesperpixel-1; |
169 if ( i < 0 ) { | |
170 return 0; | |
171 } | |
172 if ( actually_add ) { | |
173 SDL_Rect saved_rect[2]; | |
174 int saved_mode[2]; | |
175 int b; | |
0 | 176 |
1556 | 177 /* Add the mode, sorted largest to smallest */ |
178 b = 0; | |
179 j = 0; | |
180 while ( (SDL_modelist[i][j]->w > modeinfo->width) || | |
181 (SDL_modelist[i][j]->h > modeinfo->height) ) { | |
182 ++j; | |
183 } | |
184 /* Skip modes that are already in our list */ | |
185 if ( (SDL_modelist[i][j]->w == modeinfo->width) && | |
186 (SDL_modelist[i][j]->h == modeinfo->height) ) { | |
187 return(0); | |
0 | 188 } |
1556 | 189 /* Insert the new mode */ |
190 saved_rect[b] = *SDL_modelist[i][j]; | |
191 saved_mode[b] = SDL_vgamode[i][j]; | |
192 SDL_modelist[i][j]->w = modeinfo->width; | |
193 SDL_modelist[i][j]->h = modeinfo->height; | |
194 SDL_vgamode[i][j] = mode; | |
195 /* Everybody scoot down! */ | |
196 if ( saved_rect[b].w && saved_rect[b].h ) { | |
197 for ( ++j; SDL_modelist[i][j]->w; ++j ) { | |
198 saved_rect[!b] = *SDL_modelist[i][j]; | |
199 saved_mode[!b] = SDL_vgamode[i][j]; | |
200 *SDL_modelist[i][j] = saved_rect[b]; | |
201 SDL_vgamode[i][j] = saved_mode[b]; | |
202 b = !b; | |
203 } | |
204 *SDL_modelist[i][j] = saved_rect[b]; | |
205 SDL_vgamode[i][j] = saved_mode[b]; | |
206 } | |
207 } else { | |
208 ++SDL_nummodes[i]; | |
0 | 209 } |
1556 | 210 return(1); |
0 | 211 } |
212 | |
213 static void SVGA_UpdateVideoInfo(_THIS) | |
214 { | |
215 vga_modeinfo *modeinfo; | |
216 | |
217 this->info.wm_available = 0; | |
1556 | 218 this->info.hw_available = (banked ? 0 : 1); |
0 | 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) ) { | |
1556 | 271 if ( SVGA_AddMode(this, mode, 0) ) { |
0 | 272 ++total_modes; |
273 } | |
274 } | |
275 } | |
1556 | 276 if ( SVGA_AddMode(this, G320x200x256, 0) ) ++total_modes; |
0 | 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) ) { | |
1556 | 305 SVGA_AddMode(this, mode, 1); |
0 | 306 } |
307 } | |
1556 | 308 SVGA_AddMode(this, G320x200x256, 1); |
0 | 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 |
1556 | 347 /* Free old pixels if we were in banked mode */ |
348 if ( banked && current->pixels ) { | |
349 free(current->pixels); | |
350 current->pixels = NULL; | |
1554 | 351 } |
352 | |
0 | 353 /* Try to set the requested linear video mode */ |
354 bpp = (bpp+7)/8-1; | |
355 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { | |
356 if ( (SDL_modelist[bpp][mode]->w == width) && | |
357 (SDL_modelist[bpp][mode]->h == height) ) { | |
358 break; | |
359 } | |
360 } | |
361 if ( SDL_modelist[bpp][mode] == NULL ) { | |
362 SDL_SetError("Couldn't find requested mode in list"); | |
363 return(NULL); | |
364 } | |
1554 | 365 vgamode = SDL_vgamode[bpp][mode]; |
366 vga_setmode(vgamode); | |
0 | 367 vga_setpage(0); |
368 | |
1554 | 369 if ( (vga_setlinearaddressing() < 0) && (vgamode != G320x200x256) ) { |
1556 | 370 banked = 1; |
371 } else { | |
372 banked = 0; | |
0 | 373 } |
1554 | 374 |
0 | 375 modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); |
376 | |
377 /* Update hardware acceleration info */ | |
378 SVGA_UpdateVideoInfo(this); | |
379 | |
380 /* Allocate the new pixel format for the screen */ | |
381 bpp = (bpp+1)*8; | |
382 if ( (bpp == 16) && (modeinfo->colors == 32768) ) { | |
383 bpp = 15; | |
384 } | |
385 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | |
386 return(NULL); | |
387 } | |
388 | |
389 /* Set up the new mode framebuffer */ | |
1554 | 390 current->flags = SDL_FULLSCREEN; |
1556 | 391 if ( !banked ) { |
1554 | 392 current->flags |= SDL_HWSURFACE; |
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 | 398 current->w = width; |
399 current->h = height; | |
400 current->pitch = modeinfo->linewidth; | |
1556 | 401 if ( banked ) { |
402 current->pixels = SDL_malloc(current->h * current->pitch); | |
403 if ( !current->pixels ) { | |
404 SDL_OutOfMemory(); | |
405 return(NULL); | |
406 } | |
1554 | 407 } else { |
408 current->pixels = vga_getgraphmem(); | |
409 } | |
0 | 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 | 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 | 439 /* Set the blit function */ |
1556 | 440 if ( banked ) { |
1554 | 441 this->UpdateRects = SVGA_BankedUpdate; |
442 } else { | |
443 this->UpdateRects = SVGA_DirectUpdate; | |
444 } | |
0 | 445 |
446 /* Set up the mouse handler again (buggy SVGAlib 1.40) */ | |
447 mouse_seteventhandler(SVGA_mousecallback); | |
448 | |
449 /* We're done */ | |
450 return(current); | |
451 } | |
452 | |
453 /* We don't actually allow hardware surfaces other than the main one */ | |
454 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface) | |
455 { | |
456 return(-1); | |
457 } | |
458 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface) | |
459 { | |
460 return; | |
461 } | |
462 | |
463 /* We need to wait for vertical retrace on page flipped displays */ | |
464 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface) | |
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 | 467 return(0); |
468 } | |
469 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
470 { | |
471 return; | |
472 } | |
473 | |
474 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface) | |
475 { | |
1556 | 476 if ( !banked ) { |
1554 | 477 vga_setdisplaystart(flip_offset[flip_page]); |
478 flip_page=!flip_page; | |
479 surface->pixels=flip_address[flip_page]; | |
480 vga_waitretrace(); | |
481 } | |
0 | 482 return(0); |
483 } | |
484 | |
485 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
486 { | |
487 return; | |
488 } | |
489 | |
490 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects) | |
491 { | |
1556 | 492 int i, j; |
1554 | 493 SDL_Rect *rect; |
1556 | 494 int page, vp; |
495 int x, y, w, h; | |
496 unsigned char *src; | |
497 unsigned char *dst; | |
498 int bpp = this->screen->format->BytesPerPixel; | |
499 int pitch = this->screen->pitch; | |
1554 | 500 |
1556 | 501 dst = vga_getgraphmem(); |
1554 | 502 for ( i=0; i < numrects; ++i ) { |
503 rect = &rects[i]; | |
1556 | 504 x = rect->x; |
505 y = rect->y; | |
506 w = rect->w * bpp; | |
507 h = rect->h; | |
508 | |
509 vp = y * pitch + x * bpp; | |
510 src = (unsigned char *)this->screen->pixels + vp; | |
511 page = vp >> 16; | |
512 vp &= 0xffff; | |
513 vga_setpage(page); | |
514 for (j = 0; j < h; j++) { | |
515 if (vp + w > 0x10000) { | |
516 if (vp >= 0x10000) { | |
517 page++; | |
518 vga_setpage(page); | |
519 vp &= 0xffff; | |
520 } else { | |
521 SDL_memcpy(dst + vp, src, 0x10000 - vp); | |
522 page++; | |
523 vga_setpage(page); | |
524 SDL_memcpy(dst, src + 0x10000 - vp, | |
525 (vp + w) & 0xffff); | |
526 vp = (vp + pitch) & 0xffff; | |
527 src += pitch; | |
528 continue; | |
529 } | |
530 } | |
531 SDL_memcpy(dst + vp, src, w); | |
532 src += pitch; | |
533 vp += pitch; | |
534 } | |
1554 | 535 } |
0 | 536 } |
537 | |
538 int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
539 { | |
540 int i; | |
541 | |
542 for(i = 0; i < ncolors; i++) { | |
543 vga_setpalette(firstcolor + i, | |
544 colors[i].r>>2, | |
545 colors[i].g>>2, | |
546 colors[i].b>>2); | |
547 } | |
548 return(1); | |
549 } | |
550 | |
551 /* Note: If we are terminated, this could be called in the middle of | |
552 another SDL video routine -- notably UpdateRects. | |
553 */ | |
554 void SVGA_VideoQuit(_THIS) | |
555 { | |
556 int i, j; | |
557 | |
558 /* Reset the console video mode */ | |
559 if ( this->screen && (this->screen->w && this->screen->h) ) { | |
560 vga_setmode(TEXT); | |
561 } | |
562 keyboard_close(); | |
563 | |
564 /* Free video mode lists */ | |
565 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
566 if ( SDL_modelist[i] != NULL ) { | |
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 | 570 SDL_modelist[i] = NULL; |
571 } | |
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 | 574 SDL_vgamode[i] = NULL; |
575 } | |
576 } | |
1556 | 577 if ( this->screen ) { |
578 if ( banked && this->screen->pixels ) { | |
579 SDL_free(this->screen->pixels); | |
580 } | |
0 | 581 this->screen->pixels = NULL; |
582 } | |
583 } | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
584 |