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