Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbvideo.c @ 1341:d02b552e5304
Configure dynamically generates SDL_config.h
I'm still wrestling with autoheader, but this should work for now...
Fixed lots of build problems with C library support disabled
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 12:11:33 +0000 |
parents | 604d73db6802 |
children | c71e05b4dc2e |
rev | line source |
---|---|
0 | 1 /* |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
6 modify it under the terms 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:
1217
diff
changeset
|
7 License as published by the Free Software Foundation; either |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
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:
1217
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:
1217
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:
1217
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
19 Sam Lantinga |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
20 slouken@libsdl.org |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1217
diff
changeset
|
21 */ |
0 | 22 |
23 /* Framebuffer console based SDL video driver implementation. | |
24 */ | |
25 | |
26 #include <stdio.h> | |
27 #include <fcntl.h> | |
28 #include <unistd.h> | |
29 #include <sys/ioctl.h> | |
30 #include <sys/mman.h> | |
31 #include <asm/page.h> /* For definition of PAGE_SIZE */ | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
32 #include <sys/io.h> /* For ioperm() */ |
0 | 33 |
34 #include "SDL.h" | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
35 #include "SDL_stdlib.h" |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
36 #include "SDL_string.h" |
0 | 37 #include "SDL_error.h" |
38 #include "SDL_video.h" | |
39 #include "SDL_mouse.h" | |
40 #include "SDL_sysvideo.h" | |
41 #include "SDL_pixels_c.h" | |
42 #include "SDL_events_c.h" | |
43 #include "SDL_fbvideo.h" | |
44 #include "SDL_fbmouse_c.h" | |
45 #include "SDL_fbevents_c.h" | |
46 #include "SDL_fb3dfx.h" | |
47 #include "SDL_fbmatrox.h" | |
133
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
48 #include "SDL_fbriva.h" |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
49 |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
50 /*#define FBCON_DEBUG*/ |
0 | 51 |
52 #if defined(i386) && defined(FB_TYPE_VGA_PLANES) | |
53 #define VGA16_FBCON_SUPPORT | |
54 #ifndef FB_AUX_VGA_PLANES_VGA4 | |
55 #define FB_AUX_VGA_PLANES_VGA4 0 | |
56 #endif | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
57 /* |
0 | 58 static inline void outb (unsigned char value, unsigned short port) |
59 { | |
60 __asm__ __volatile__ ("outb %b0,%w1"::"a" (value), "Nd" (port)); | |
61 } | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
62 */ |
0 | 63 #endif /* FB_TYPE_VGA_PLANES */ |
64 | |
65 /* A list of video resolutions that we query for (sorted largest to smallest) */ | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
6
diff
changeset
|
66 static const SDL_Rect checkres[] = { |
0 | 67 { 0, 0, 1600, 1200 }, /* 16 bpp: 0x11E, or 286 */ |
68 { 0, 0, 1408, 1056 }, /* 16 bpp: 0x19A, or 410 */ | |
69 { 0, 0, 1280, 1024 }, /* 16 bpp: 0x11A, or 282 */ | |
70 { 0, 0, 1152, 864 }, /* 16 bpp: 0x192, or 402 */ | |
71 { 0, 0, 1024, 768 }, /* 16 bpp: 0x117, or 279 */ | |
72 { 0, 0, 960, 720 }, /* 16 bpp: 0x18A, or 394 */ | |
73 { 0, 0, 800, 600 }, /* 16 bpp: 0x114, or 276 */ | |
74 { 0, 0, 768, 576 }, /* 16 bpp: 0x182, or 386 */ | |
330
5fed858d551c
Date: 03 Apr 2002 15:28:09 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
75 { 0, 0, 720, 576 }, /* PAL */ |
5fed858d551c
Date: 03 Apr 2002 15:28:09 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
76 { 0, 0, 720, 480 }, /* NTSC */ |
0 | 77 { 0, 0, 640, 480 }, /* 16 bpp: 0x111, or 273 */ |
78 { 0, 0, 640, 400 }, /* 8 bpp: 0x100, or 256 */ | |
79 { 0, 0, 512, 384 }, | |
80 { 0, 0, 320, 240 }, | |
81 { 0, 0, 320, 200 } | |
82 }; | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
6
diff
changeset
|
83 static const struct { |
0 | 84 int xres; |
85 int yres; | |
86 int pixclock; | |
87 int left; | |
88 int right; | |
89 int upper; | |
90 int lower; | |
91 int hslen; | |
92 int vslen; | |
93 int sync; | |
94 int vmode; | |
95 } vesa_timings[] = { | |
96 #ifdef USE_VESA_TIMINGS /* Only tested on Matrox Millenium I */ | |
97 { 640, 400, 39771, 48, 16, 39, 8, 96, 2, 2, 0 }, /* 70 Hz */ | |
98 { 640, 480, 39683, 48, 16, 33, 10, 96, 2, 0, 0 }, /* 60 Hz */ | |
99 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */ | |
100 { 800, 600, 24038, 144, 24, 28, 8, 112, 6, 0, 0 }, /* 60 Hz */ | |
101 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */ | |
102 { 1024, 768, 15386, 160, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
103 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
104 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */ | |
105 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */ | |
106 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */ | |
107 #else | |
108 /* You can generate these timings from your XF86Config file using | |
109 the 'modeline2fb' perl script included with the fbset package. | |
110 These timings were generated for Matrox Millenium I, 15" monitor. | |
111 */ | |
112 { 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0, 2 }, /* 70 Hz */ | |
113 { 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0, 2 }, /* 72 Hz */ | |
114 { 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0, 0 }, /* 78 Hz */ | |
115 { 640, 400, 31746, 96, 32, 41, 1, 64, 3, 2, 0 }, /* 85 Hz */ | |
116 { 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0, 0 }, /* 75 Hz */ | |
117 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */ | |
118 { 800, 600, 20000, 64, 56, 23, 37, 120, 6, 3, 0 }, /* 72 Hz */ | |
119 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */ | |
120 { 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0, 0 }, /* 70 Hz */ | |
121 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
122 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */ | |
123 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */ | |
124 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */ | |
125 #endif | |
126 }; | |
127 | |
128 /* Initialization/Query functions */ | |
129 static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
130 static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
131 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
132 #ifdef VGA16_FBCON_SUPPORT | |
133 static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
134 #endif | |
135 static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
136 static void FB_VideoQuit(_THIS); | |
137 | |
138 /* Hardware surface functions */ | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
139 static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size); |
0 | 140 static void FB_FreeHWSurfaces(_THIS); |
141 static int FB_AllocHWSurface(_THIS, SDL_Surface *surface); | |
142 static int FB_LockHWSurface(_THIS, SDL_Surface *surface); | |
143 static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
144 static void FB_FreeHWSurface(_THIS, SDL_Surface *surface); | |
145 static void FB_WaitVBL(_THIS); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
146 static void FB_WaitIdle(_THIS); |
0 | 147 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface); |
148 | |
149 /* Internal palette functions */ | |
150 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, | |
151 struct fb_var_screeninfo *vinfo); | |
152 static void FB_RestorePalette(_THIS); | |
153 | |
154 /* FB driver bootstrap functions */ | |
155 | |
156 static int FB_Available(void) | |
157 { | |
158 int console; | |
159 const char *SDL_fbdev; | |
160 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
161 SDL_fbdev = SDL_getenv("SDL_FBDEV"); |
0 | 162 if ( SDL_fbdev == NULL ) { |
163 SDL_fbdev = "/dev/fb0"; | |
164 } | |
165 console = open(SDL_fbdev, O_RDWR, 0); | |
166 if ( console >= 0 ) { | |
167 close(console); | |
168 } | |
169 return(console >= 0); | |
170 } | |
171 | |
172 static void FB_DeleteDevice(SDL_VideoDevice *device) | |
173 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
174 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
175 SDL_free(device); |
0 | 176 } |
177 | |
178 static SDL_VideoDevice *FB_CreateDevice(int devindex) | |
179 { | |
180 SDL_VideoDevice *this; | |
181 | |
182 /* 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
|
183 this = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 184 if ( this ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
185 SDL_memset(this, 0, (sizeof *this)); |
0 | 186 this->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
187 SDL_malloc((sizeof *this->hidden)); |
0 | 188 } |
189 if ( (this == NULL) || (this->hidden == NULL) ) { | |
190 SDL_OutOfMemory(); | |
191 if ( this ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
192 SDL_free(this); |
0 | 193 } |
194 return(0); | |
195 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
196 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
0 | 197 wait_vbl = FB_WaitVBL; |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
198 wait_idle = FB_WaitIdle; |
0 | 199 mouse_fd = -1; |
200 keyboard_fd = -1; | |
201 | |
202 /* Set the function pointers */ | |
203 this->VideoInit = FB_VideoInit; | |
204 this->ListModes = FB_ListModes; | |
205 this->SetVideoMode = FB_SetVideoMode; | |
206 this->SetColors = FB_SetColors; | |
207 this->UpdateRects = NULL; | |
208 this->VideoQuit = FB_VideoQuit; | |
209 this->AllocHWSurface = FB_AllocHWSurface; | |
210 this->CheckHWBlit = NULL; | |
211 this->FillHWRect = NULL; | |
212 this->SetHWColorKey = NULL; | |
213 this->SetHWAlpha = NULL; | |
214 this->LockHWSurface = FB_LockHWSurface; | |
215 this->UnlockHWSurface = FB_UnlockHWSurface; | |
216 this->FlipHWSurface = FB_FlipHWSurface; | |
217 this->FreeHWSurface = FB_FreeHWSurface; | |
218 this->SetCaption = NULL; | |
219 this->SetIcon = NULL; | |
220 this->IconifyWindow = NULL; | |
221 this->GrabInput = NULL; | |
222 this->GetWMInfo = NULL; | |
223 this->InitOSKeymap = FB_InitOSKeymap; | |
224 this->PumpEvents = FB_PumpEvents; | |
225 | |
226 this->free = FB_DeleteDevice; | |
227 | |
228 return this; | |
229 } | |
230 | |
231 VideoBootStrap FBCON_bootstrap = { | |
232 "fbcon", "Linux Framebuffer Console", | |
233 FB_Available, FB_CreateDevice | |
234 }; | |
235 | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
236 #define FB_MODES_DB "/etc/fb.modes" |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
237 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
238 static int read_fbmodes_line(FILE*f, char* line, int length) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
239 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
240 int blank; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
241 char* c; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
242 int i; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
243 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
244 blank=0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
245 /* find a relevant line */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
246 do |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
247 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
248 if (fgets(line,length,f)<=0) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
249 return 0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
250 c=line; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
251 while(((*c=='\t')||(*c==' '))&&(*c!=0)) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
252 c++; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
253 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
254 if ((*c=='\n')||(*c=='#')||(*c==0)) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
255 blank=1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
256 else |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
257 blank=0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
258 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
259 while(blank); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
260 /* remove whitespace at the begining of the string */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
261 i=0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
262 do |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
263 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
264 line[i]=c[i]; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
265 i++; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
266 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
267 while(c[i]!=0); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
268 return 1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
269 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
270 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
271 static int read_fbmodes_mode(FILE *f, struct fb_var_screeninfo *vinfo) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
272 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
273 char line[1024]; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
274 char option[256]; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
275 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
276 /* Find a "geometry" */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
277 do { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
278 if (read_fbmodes_line(f, line, sizeof(line))==0) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
279 return 0; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
280 if (SDL_strncmp(line,"geometry",8)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
281 break; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
282 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
283 while(1); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
284 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
285 SDL_sscanf(line, "geometry %d %d %d %d %d", &vinfo->xres, &vinfo->yres, |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
286 &vinfo->xres_virtual, &vinfo->yres_virtual, &vinfo->bits_per_pixel); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
287 if (read_fbmodes_line(f, line, sizeof(line))==0) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
288 return 0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
289 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
290 SDL_sscanf(line, "timings %d %d %d %d %d %d %d", &vinfo->pixclock, |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
291 &vinfo->left_margin, &vinfo->right_margin, &vinfo->upper_margin, |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
292 &vinfo->lower_margin, &vinfo->hsync_len, &vinfo->vsync_len); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
293 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
294 vinfo->sync=0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
295 vinfo->vmode=FB_VMODE_NONINTERLACED; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
296 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
297 /* Parse misc options */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
298 do { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
299 if (read_fbmodes_line(f, line, sizeof(line))==0) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
300 return 0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
301 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
302 if (SDL_strncmp(line,"hsync",5)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
303 SDL_sscanf(line,"hsync %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
304 if (SDL_strncmp(option,"high",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
305 vinfo->sync |= FB_SYNC_HOR_HIGH_ACT; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
306 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
307 else if (SDL_strncmp(line,"vsync",5)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
308 SDL_sscanf(line,"vsync %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
309 if (SDL_strncmp(option,"high",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
310 vinfo->sync |= FB_SYNC_VERT_HIGH_ACT; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
311 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
312 else if (SDL_strncmp(line,"csync",5)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
313 SDL_sscanf(line,"csync %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
314 if (SDL_strncmp(option,"high",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
315 vinfo->sync |= FB_SYNC_COMP_HIGH_ACT; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
316 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
317 else if (SDL_strncmp(line,"extsync",5)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
318 SDL_sscanf(line,"extsync %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
319 if (SDL_strncmp(option,"true",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
320 vinfo->sync |= FB_SYNC_EXT; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
321 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
322 else if (SDL_strncmp(line,"laced",5)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
323 SDL_sscanf(line,"laced %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
324 if (SDL_strncmp(option,"true",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
325 vinfo->vmode |= FB_VMODE_INTERLACED; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
326 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
327 else if (SDL_strncmp(line,"double",6)==0) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
328 SDL_sscanf(line,"double %s",option); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
329 if (SDL_strncmp(option,"true",4)==0) |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
330 vinfo->vmode |= FB_VMODE_DOUBLE; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
331 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
332 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
333 while(SDL_strncmp(line,"endmode",7)!=0); |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
334 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
335 return 1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
336 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
337 |
0 | 338 static int FB_CheckMode(_THIS, struct fb_var_screeninfo *vinfo, |
339 int index, unsigned int *w, unsigned int *h) | |
340 { | |
341 int mode_okay; | |
342 | |
343 mode_okay = 0; | |
344 vinfo->bits_per_pixel = (index+1)*8; | |
345 vinfo->xres = *w; | |
346 vinfo->xres_virtual = *w; | |
347 vinfo->yres = *h; | |
348 vinfo->yres_virtual = *h; | |
349 vinfo->activate = FB_ACTIVATE_TEST; | |
350 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0 ) { | |
351 #ifdef FBCON_DEBUG | |
352 fprintf(stderr, "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n", *w, *h, (index+1)*8, vinfo->xres, vinfo->yres, vinfo->bits_per_pixel); | |
353 #endif | |
354 if ( (((vinfo->bits_per_pixel+7)/8)-1) == index ) { | |
355 *w = vinfo->xres; | |
356 *h = vinfo->yres; | |
357 mode_okay = 1; | |
358 } | |
359 } | |
360 return mode_okay; | |
361 } | |
362 | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
363 static int FB_AddMode(_THIS, int index, unsigned int w, unsigned int h, int check_timings) |
0 | 364 { |
365 SDL_Rect *mode; | |
366 int i; | |
367 int next_mode; | |
368 | |
369 /* Check to see if we already have this mode */ | |
370 if ( SDL_nummodes[index] > 0 ) { | |
371 mode = SDL_modelist[index][SDL_nummodes[index]-1]; | |
372 if ( (mode->w == w) && (mode->h == h) ) { | |
373 #ifdef FBCON_DEBUG | |
374 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
375 #endif | |
376 return(0); | |
377 } | |
378 } | |
379 | |
380 /* Only allow a mode if we have a valid timing for it */ | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
381 if ( check_timings ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
382 int found_timing = 0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
383 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
384 if ( (w == vesa_timings[i].xres) && |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
385 (h == vesa_timings[i].yres) && vesa_timings[i].pixclock ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
386 found_timing = 1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
387 break; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
388 } |
0 | 389 } |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
390 if ( !found_timing ) { |
0 | 391 #ifdef FBCON_DEBUG |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
392 fprintf(stderr, "No valid timing line for mode %dx%d\n", w, h); |
0 | 393 #endif |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
394 return(0); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
395 } |
0 | 396 } |
397 | |
398 /* Set up the new video mode rectangle */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
399 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); |
0 | 400 if ( mode == NULL ) { |
401 SDL_OutOfMemory(); | |
402 return(-1); | |
403 } | |
404 mode->x = 0; | |
405 mode->y = 0; | |
406 mode->w = w; | |
407 mode->h = h; | |
408 #ifdef FBCON_DEBUG | |
409 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
410 #endif | |
411 | |
412 /* Allocate the new list of modes, and fill in the new mode */ | |
413 next_mode = SDL_nummodes[index]; | |
414 SDL_modelist[index] = (SDL_Rect **) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
415 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); |
0 | 416 if ( SDL_modelist[index] == NULL ) { |
417 SDL_OutOfMemory(); | |
418 SDL_nummodes[index] = 0; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
419 SDL_free(mode); |
0 | 420 return(-1); |
421 } | |
422 SDL_modelist[index][next_mode] = mode; | |
423 SDL_modelist[index][next_mode+1] = NULL; | |
424 SDL_nummodes[index]++; | |
425 | |
426 return(0); | |
427 } | |
428 | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
429 static int cmpmodes(const void *va, const void *vb) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
430 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
431 const SDL_Rect *a = *(const SDL_Rect**)va; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
432 const SDL_Rect *b = *(const SDL_Rect**)vb; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
433 if ( a->h == b->h ) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
434 return b->w - a->w; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
435 else |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
436 return b->h - a->h; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
437 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
438 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
439 static int FB_SortModes(_THIS) |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
440 { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
441 int i; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
442 for ( i=0; i<NUM_MODELISTS; ++i ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
443 if ( SDL_nummodes[i] > 0 ) { |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
444 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
445 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
446 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
447 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
448 |
0 | 449 static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) |
450 { | |
451 struct fb_fix_screeninfo finfo; | |
452 struct fb_var_screeninfo vinfo; | |
453 int i, j; | |
454 int current_index; | |
455 unsigned int current_w; | |
456 unsigned int current_h; | |
457 const char *SDL_fbdev; | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
458 FILE *modesdb; |
0 | 459 |
460 /* Initialize the library */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
461 SDL_fbdev = SDL_getenv("SDL_FBDEV"); |
0 | 462 if ( SDL_fbdev == NULL ) { |
463 SDL_fbdev = "/dev/fb0"; | |
464 } | |
465 console_fd = open(SDL_fbdev, O_RDWR, 0); | |
466 if ( console_fd < 0 ) { | |
467 SDL_SetError("Unable to open %s", SDL_fbdev); | |
468 return(-1); | |
469 } | |
470 | |
471 #ifndef DISABLE_THREADS | |
472 /* Create the hardware surface lock mutex */ | |
473 hw_lock = SDL_CreateMutex(); | |
474 if ( hw_lock == NULL ) { | |
475 SDL_SetError("Unable to create lock mutex"); | |
476 FB_VideoQuit(this); | |
477 return(-1); | |
478 } | |
479 #endif | |
480 | |
481 /* Get the type of video hardware */ | |
482 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
483 SDL_SetError("Couldn't get console hardware info"); | |
484 FB_VideoQuit(this); | |
485 return(-1); | |
486 } | |
487 switch (finfo.type) { | |
488 case FB_TYPE_PACKED_PIXELS: | |
489 /* Supported, no worries.. */ | |
490 break; | |
491 #ifdef VGA16_FBCON_SUPPORT | |
492 case FB_TYPE_VGA_PLANES: | |
493 /* VGA16 is supported, but that's it */ | |
494 if ( finfo.type_aux == FB_AUX_VGA_PLANES_VGA4 ) { | |
495 if ( ioperm(0x3b4, 0x3df - 0x3b4 + 1, 1) < 0 ) { | |
496 SDL_SetError("No I/O port permissions"); | |
497 FB_VideoQuit(this); | |
498 return(-1); | |
499 } | |
500 this->SetVideoMode = FB_SetVGA16Mode; | |
501 break; | |
502 } | |
503 /* Fall through to unsupported case */ | |
504 #endif /* VGA16_FBCON_SUPPORT */ | |
505 default: | |
506 SDL_SetError("Unsupported console hardware"); | |
507 FB_VideoQuit(this); | |
508 return(-1); | |
509 } | |
510 switch (finfo.visual) { | |
511 case FB_VISUAL_TRUECOLOR: | |
512 case FB_VISUAL_PSEUDOCOLOR: | |
513 case FB_VISUAL_STATIC_PSEUDOCOLOR: | |
514 case FB_VISUAL_DIRECTCOLOR: | |
515 break; | |
516 default: | |
517 SDL_SetError("Unsupported console hardware"); | |
518 FB_VideoQuit(this); | |
519 return(-1); | |
520 } | |
521 | |
522 /* Check if the user wants to disable hardware acceleration */ | |
523 { const char *fb_accel; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
524 fb_accel = SDL_getenv("SDL_FBACCEL"); |
0 | 525 if ( fb_accel ) { |
1341
d02b552e5304
Configure dynamically generates SDL_config.h
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
526 finfo.accel = SDL_atoi(fb_accel); |
0 | 527 } |
528 } | |
529 | |
530 /* Memory map the device, compensating for buggy PPC mmap() */ | |
531 mapped_offset = (((long)finfo.smem_start) - | |
532 (((long)finfo.smem_start)&~(PAGE_SIZE-1))); | |
533 mapped_memlen = finfo.smem_len+mapped_offset; | |
534 mapped_mem = mmap(NULL, mapped_memlen, | |
535 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0); | |
536 if ( mapped_mem == (char *)-1 ) { | |
537 SDL_SetError("Unable to memory map the video hardware"); | |
538 mapped_mem = NULL; | |
539 FB_VideoQuit(this); | |
540 return(-1); | |
541 } | |
542 | |
543 /* Determine the current screen depth */ | |
544 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
545 SDL_SetError("Couldn't get console pixel format"); | |
546 FB_VideoQuit(this); | |
547 return(-1); | |
548 } | |
549 vformat->BitsPerPixel = vinfo.bits_per_pixel; | |
550 if ( vformat->BitsPerPixel < 8 ) { | |
551 /* Assuming VGA16, we handle this via a shadow framebuffer */ | |
552 vformat->BitsPerPixel = 8; | |
553 } | |
554 for ( i=0; i<vinfo.red.length; ++i ) { | |
555 vformat->Rmask <<= 1; | |
556 vformat->Rmask |= (0x00000001<<vinfo.red.offset); | |
557 } | |
558 for ( i=0; i<vinfo.green.length; ++i ) { | |
559 vformat->Gmask <<= 1; | |
560 vformat->Gmask |= (0x00000001<<vinfo.green.offset); | |
561 } | |
562 for ( i=0; i<vinfo.blue.length; ++i ) { | |
563 vformat->Bmask <<= 1; | |
564 vformat->Bmask |= (0x00000001<<vinfo.blue.offset); | |
565 } | |
566 saved_vinfo = vinfo; | |
567 | |
568 /* Save hardware palette, if needed */ | |
569 FB_SavePalette(this, &finfo, &vinfo); | |
570 | |
571 /* If the I/O registers are available, memory map them so we | |
572 can take advantage of any supported hardware acceleration. | |
573 */ | |
574 vinfo.accel_flags = 0; /* Temporarily reserve registers */ | |
575 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo); | |
576 if ( finfo.accel && finfo.mmio_len ) { | |
577 mapped_iolen = finfo.mmio_len; | |
578 mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE, | |
579 MAP_SHARED, console_fd, mapped_memlen); | |
580 if ( mapped_io == (char *)-1 ) { | |
581 /* Hmm, failed to memory map I/O registers */ | |
582 mapped_io = NULL; | |
583 } | |
584 } | |
585 | |
586 /* Query for the list of available video modes */ | |
587 current_w = vinfo.xres; | |
588 current_h = vinfo.yres; | |
589 current_index = ((vinfo.bits_per_pixel+7)/8)-1; | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
590 modesdb = fopen(FB_MODES_DB, "r"); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
591 for ( i=0; i<NUM_MODELISTS; ++i ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
592 SDL_nummodes[i] = 0; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
593 SDL_modelist[i] = NULL; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
594 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
595 if ( SDL_getenv("SDL_FB_BROKEN_MODES") != NULL ) { |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
596 FB_AddMode(this, current_index, current_w, current_h, 0); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
597 } else if(modesdb) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
598 while ( read_fbmodes_mode(modesdb, &vinfo) ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
599 for ( i=0; i<NUM_MODELISTS; ++i ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
600 unsigned int w, h; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
601 |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
602 /* See if we are querying for the current mode */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
603 w = vinfo.xres; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
604 h = vinfo.yres; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
605 if ( i == current_index ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
606 if ( (current_w > w) || (current_h > h) ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
607 /* Only check once */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
608 FB_AddMode(this, i, current_w, current_h, 0); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
609 current_index = -1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
610 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
611 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
612 if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
613 FB_AddMode(this, i, w, h, 0); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
614 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
615 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
616 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
617 fclose(modesdb); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
618 FB_SortModes(this); |
941
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
619 } else { |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
620 for ( i=0; i<NUM_MODELISTS; ++i ) { |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
621 for ( j=0; j<(sizeof(checkres)/sizeof(checkres[0])); ++j ) { |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
622 unsigned int w, h; |
0 | 623 |
941
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
624 /* See if we are querying for the current mode */ |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
625 w = checkres[j].w; |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
626 h = checkres[j].h; |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
627 if ( i == current_index ) { |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
628 if ( (current_w > w) || (current_h > h) ) { |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
629 /* Only check once */ |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
630 FB_AddMode(this, i, current_w, current_h, 0); |
941
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
631 current_index = -1; |
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
632 } |
0 | 633 } |
941
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
634 if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) { |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
635 FB_AddMode(this, i, w, h, 1); |
941
5095c4a264aa
Date: Mon, 12 Jul 2004 14:17:47 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
636 } |
0 | 637 } |
638 } | |
639 } | |
640 | |
641 /* Fill in our hardware acceleration capabilities */ | |
642 this->info.wm_available = 0; | |
643 this->info.hw_available = 1; | |
644 this->info.video_mem = finfo.smem_len/1024; | |
645 if ( mapped_io ) { | |
646 switch (finfo.accel) { | |
647 case FB_ACCEL_MATROX_MGA2064W: | |
648 case FB_ACCEL_MATROX_MGA1064SG: | |
649 case FB_ACCEL_MATROX_MGA2164W: | |
650 case FB_ACCEL_MATROX_MGA2164W_AGP: | |
651 case FB_ACCEL_MATROX_MGAG100: | |
652 /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */ | |
653 case FB_ACCEL_MATROX_MGAG400: | |
654 #ifdef FBACCEL_DEBUG | |
655 printf("Matrox hardware accelerator!\n"); | |
656 #endif | |
657 FB_MatroxAccel(this, finfo.accel); | |
658 break; | |
659 case FB_ACCEL_3DFX_BANSHEE: | |
660 #ifdef FBACCEL_DEBUG | |
661 printf("3DFX hardware accelerator!\n"); | |
662 #endif | |
663 FB_3DfxAccel(this, finfo.accel); | |
664 break; | |
133
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
665 case FB_ACCEL_NV3: |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
666 case FB_ACCEL_NV4: |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
667 #ifdef FBACCEL_DEBUG |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
668 printf("NVidia hardware accelerator!\n"); |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
669 #endif |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
670 FB_RivaAccel(this, finfo.accel); |
5d4bafca35cd
Added support for hardware accelerated NVidia driver on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
106
diff
changeset
|
671 break; |
0 | 672 default: |
673 #ifdef FBACCEL_DEBUG | |
674 printf("Unknown hardware accelerator.\n"); | |
675 #endif | |
676 break; | |
677 } | |
678 } | |
679 | |
680 /* Enable mouse and keyboard support */ | |
681 if ( FB_OpenKeyboard(this) < 0 ) { | |
682 FB_VideoQuit(this); | |
683 return(-1); | |
684 } | |
685 if ( FB_OpenMouse(this) < 0 ) { | |
686 const char *sdl_nomouse; | |
687 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
688 sdl_nomouse = SDL_getenv("SDL_NOMOUSE"); |
0 | 689 if ( ! sdl_nomouse ) { |
690 SDL_SetError("Unable to open mouse"); | |
691 FB_VideoQuit(this); | |
692 return(-1); | |
693 } | |
694 } | |
695 | |
696 /* We're done! */ | |
697 return(0); | |
698 } | |
699 | |
700 static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
701 { | |
702 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
703 } | |
704 | |
705 /* Various screen update functions available */ | |
706 static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
707 #ifdef VGA16_FBCON_SUPPORT | |
708 static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects); | |
709 #endif | |
710 | |
711 #ifdef FBCON_DEBUG | |
712 static void print_vinfo(struct fb_var_screeninfo *vinfo) | |
713 { | |
714 fprintf(stderr, "Printing vinfo:\n"); | |
715 fprintf(stderr, "\txres: %d\n", vinfo->xres); | |
716 fprintf(stderr, "\tyres: %d\n", vinfo->yres); | |
717 fprintf(stderr, "\txres_virtual: %d\n", vinfo->xres_virtual); | |
718 fprintf(stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual); | |
719 fprintf(stderr, "\txoffset: %d\n", vinfo->xoffset); | |
720 fprintf(stderr, "\tyoffset: %d\n", vinfo->yoffset); | |
721 fprintf(stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel); | |
722 fprintf(stderr, "\tgrayscale: %d\n", vinfo->grayscale); | |
723 fprintf(stderr, "\tnonstd: %d\n", vinfo->nonstd); | |
724 fprintf(stderr, "\tactivate: %d\n", vinfo->activate); | |
725 fprintf(stderr, "\theight: %d\n", vinfo->height); | |
726 fprintf(stderr, "\twidth: %d\n", vinfo->width); | |
727 fprintf(stderr, "\taccel_flags: %d\n", vinfo->accel_flags); | |
728 fprintf(stderr, "\tpixclock: %d\n", vinfo->pixclock); | |
729 fprintf(stderr, "\tleft_margin: %d\n", vinfo->left_margin); | |
730 fprintf(stderr, "\tright_margin: %d\n", vinfo->right_margin); | |
731 fprintf(stderr, "\tupper_margin: %d\n", vinfo->upper_margin); | |
732 fprintf(stderr, "\tlower_margin: %d\n", vinfo->lower_margin); | |
733 fprintf(stderr, "\thsync_len: %d\n", vinfo->hsync_len); | |
734 fprintf(stderr, "\tvsync_len: %d\n", vinfo->vsync_len); | |
735 fprintf(stderr, "\tsync: %d\n", vinfo->sync); | |
736 fprintf(stderr, "\tvmode: %d\n", vinfo->vmode); | |
737 fprintf(stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset); | |
738 fprintf(stderr, "\tgreen: %d/%d\n", vinfo->green.length, vinfo->green.offset); | |
739 fprintf(stderr, "\tblue: %d/%d\n", vinfo->blue.length, vinfo->blue.offset); | |
740 fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length, vinfo->transp.offset); | |
741 } | |
742 static void print_finfo(struct fb_fix_screeninfo *finfo) | |
743 { | |
744 fprintf(stderr, "Printing finfo:\n"); | |
745 fprintf(stderr, "\tsmem_start = %p\n", (char *)finfo->smem_start); | |
746 fprintf(stderr, "\tsmem_len = %d\n", finfo->smem_len); | |
747 fprintf(stderr, "\ttype = %d\n", finfo->type); | |
748 fprintf(stderr, "\ttype_aux = %d\n", finfo->type_aux); | |
749 fprintf(stderr, "\tvisual = %d\n", finfo->visual); | |
750 fprintf(stderr, "\txpanstep = %d\n", finfo->xpanstep); | |
751 fprintf(stderr, "\typanstep = %d\n", finfo->ypanstep); | |
752 fprintf(stderr, "\tywrapstep = %d\n", finfo->ywrapstep); | |
753 fprintf(stderr, "\tline_length = %d\n", finfo->line_length); | |
754 fprintf(stderr, "\tmmio_start = %p\n", (char *)finfo->mmio_start); | |
755 fprintf(stderr, "\tmmio_len = %d\n", finfo->mmio_len); | |
756 fprintf(stderr, "\taccel = %d\n", finfo->accel); | |
757 } | |
758 #endif | |
759 | |
760 static int choose_fbmodes_mode(struct fb_var_screeninfo *vinfo) | |
761 { | |
762 int matched; | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
763 FILE *modesdb; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
764 struct fb_var_screeninfo cinfo; |
0 | 765 |
766 matched = 0; | |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
767 modesdb = fopen(FB_MODES_DB, "r"); |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
768 if ( modesdb ) { |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
769 /* Parse the mode definition file */ |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
770 while ( read_fbmodes_mode(modesdb, &cinfo) ) { |
1217
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
771 if ( (vinfo->xres == cinfo.xres && vinfo->yres == cinfo.yres) && |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
772 (!matched || (vinfo->bits_per_pixel == cinfo.bits_per_pixel)) ) { |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
773 vinfo->pixclock = cinfo.pixclock; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
774 vinfo->left_margin = cinfo.left_margin; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
775 vinfo->right_margin = cinfo.right_margin; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
776 vinfo->upper_margin = cinfo.upper_margin; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
777 vinfo->lower_margin = cinfo.lower_margin; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
778 vinfo->hsync_len = cinfo.hsync_len; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
779 vinfo->vsync_len = cinfo.vsync_len; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
780 if ( matched ) { |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
781 break; |
ae9981987c2f
Oops, actually use the timings in the modes db. :)
Sam Lantinga <slouken@libsdl.org>
parents:
1215
diff
changeset
|
782 } |
1215
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
783 matched = 1; |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
784 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
785 } |
d082d2d66ec8
Added support for parsing /etc/fb.modes, based on Stephane Marchesin's patch
Sam Lantinga <slouken@libsdl.org>
parents:
1036
diff
changeset
|
786 fclose(modesdb); |
0 | 787 } |
788 return(matched); | |
789 } | |
790 | |
791 static int choose_vesa_mode(struct fb_var_screeninfo *vinfo) | |
792 { | |
793 int matched; | |
794 int i; | |
795 | |
796 /* Check for VESA timings */ | |
797 matched = 0; | |
798 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) { | |
799 if ( (vinfo->xres == vesa_timings[i].xres) && | |
800 (vinfo->yres == vesa_timings[i].yres) ) { | |
801 #ifdef FBCON_DEBUG | |
802 fprintf(stderr, "Using VESA timings for %dx%d\n", | |
803 vinfo->xres, vinfo->yres); | |
804 #endif | |
805 if ( vesa_timings[i].pixclock ) { | |
806 vinfo->pixclock = vesa_timings[i].pixclock; | |
807 } | |
808 vinfo->left_margin = vesa_timings[i].left; | |
809 vinfo->right_margin = vesa_timings[i].right; | |
810 vinfo->upper_margin = vesa_timings[i].upper; | |
811 vinfo->lower_margin = vesa_timings[i].lower; | |
812 vinfo->hsync_len = vesa_timings[i].hslen; | |
813 vinfo->vsync_len = vesa_timings[i].vslen; | |
814 vinfo->sync = vesa_timings[i].sync; | |
815 vinfo->vmode = vesa_timings[i].vmode; | |
816 matched = 1; | |
817 break; | |
818 } | |
819 } | |
820 return(matched); | |
821 } | |
822 | |
823 #ifdef VGA16_FBCON_SUPPORT | |
824 static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current, | |
825 int width, int height, int bpp, Uint32 flags) | |
826 { | |
827 struct fb_fix_screeninfo finfo; | |
828 struct fb_var_screeninfo vinfo; | |
829 | |
830 /* Set the terminal into graphics mode */ | |
831 if ( FB_EnterGraphicsMode(this) < 0 ) { | |
832 return(NULL); | |
833 } | |
834 | |
835 /* Restore the original palette */ | |
836 FB_RestorePalette(this); | |
837 | |
838 /* Set the video mode and get the final screen format */ | |
839 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
840 SDL_SetError("Couldn't get console screen info"); | |
841 return(NULL); | |
842 } | |
843 cache_vinfo = vinfo; | |
844 #ifdef FBCON_DEBUG | |
845 fprintf(stderr, "Printing actual vinfo:\n"); | |
846 print_vinfo(&vinfo); | |
847 #endif | |
848 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | |
849 return(NULL); | |
850 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
851 current->format->palette->ncolors = 16; |
0 | 852 |
853 /* Get the fixed information about the console hardware. | |
854 This is necessary since finfo.line_length changes. | |
855 */ | |
856 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
857 SDL_SetError("Couldn't get console hardware info"); | |
858 return(NULL); | |
859 } | |
860 #ifdef FBCON_DEBUG | |
861 fprintf(stderr, "Printing actual finfo:\n"); | |
862 print_finfo(&finfo); | |
863 #endif | |
864 | |
865 /* Save hardware palette, if needed */ | |
866 FB_SavePalette(this, &finfo, &vinfo); | |
867 | |
868 /* Set up the new mode framebuffer */ | |
869 current->flags = SDL_FULLSCREEN; | |
870 current->w = vinfo.xres; | |
871 current->h = vinfo.yres; | |
872 current->pitch = current->w; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
873 current->pixels = SDL_malloc(current->h*current->pitch); |
0 | 874 |
875 /* Set the update rectangle function */ | |
876 this->UpdateRects = FB_VGA16Update; | |
877 | |
878 /* We're done */ | |
879 return(current); | |
880 } | |
881 #endif /* VGA16_FBCON_SUPPORT */ | |
882 | |
883 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current, | |
884 int width, int height, int bpp, Uint32 flags) | |
885 { | |
886 struct fb_fix_screeninfo finfo; | |
887 struct fb_var_screeninfo vinfo; | |
888 int i; | |
889 Uint32 Rmask; | |
890 Uint32 Gmask; | |
891 Uint32 Bmask; | |
892 char *surfaces_mem; | |
893 int surfaces_len; | |
894 | |
895 /* Set the terminal into graphics mode */ | |
896 if ( FB_EnterGraphicsMode(this) < 0 ) { | |
897 return(NULL); | |
898 } | |
899 | |
900 /* Restore the original palette */ | |
901 FB_RestorePalette(this); | |
902 | |
903 /* Set the video mode and get the final screen format */ | |
904 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
905 SDL_SetError("Couldn't get console screen info"); | |
906 return(NULL); | |
907 } | |
908 #ifdef FBCON_DEBUG | |
909 fprintf(stderr, "Printing original vinfo:\n"); | |
910 print_vinfo(&vinfo); | |
911 #endif | |
912 if ( (vinfo.xres != width) || (vinfo.yres != height) || | |
913 (vinfo.bits_per_pixel != bpp) || (flags & SDL_DOUBLEBUF) ) { | |
914 vinfo.activate = FB_ACTIVATE_NOW; | |
915 vinfo.accel_flags = 0; | |
916 vinfo.bits_per_pixel = bpp; | |
917 vinfo.xres = width; | |
918 vinfo.xres_virtual = width; | |
919 vinfo.yres = height; | |
920 if ( flags & SDL_DOUBLEBUF ) { | |
921 vinfo.yres_virtual = height*2; | |
922 } else { | |
923 vinfo.yres_virtual = height; | |
924 } | |
925 vinfo.xoffset = 0; | |
926 vinfo.yoffset = 0; | |
927 vinfo.red.length = vinfo.red.offset = 0; | |
928 vinfo.green.length = vinfo.green.offset = 0; | |
929 vinfo.blue.length = vinfo.blue.offset = 0; | |
930 vinfo.transp.length = vinfo.transp.offset = 0; | |
931 if ( ! choose_fbmodes_mode(&vinfo) ) { | |
932 choose_vesa_mode(&vinfo); | |
933 } | |
934 #ifdef FBCON_DEBUG | |
935 fprintf(stderr, "Printing wanted vinfo:\n"); | |
936 print_vinfo(&vinfo); | |
937 #endif | |
938 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { | |
939 vinfo.yres_virtual = height; | |
940 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { | |
941 SDL_SetError("Couldn't set console screen info"); | |
942 return(NULL); | |
943 } | |
944 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
945 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
946 int maxheight; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
947 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
948 /* Figure out how much video memory is available */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
949 if ( flags & SDL_DOUBLEBUF ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
950 maxheight = height*2; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
951 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
952 maxheight = height; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
953 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
954 if ( vinfo.yres_virtual > maxheight ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
955 vinfo.yres_virtual = maxheight; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
956 } |
0 | 957 } |
958 cache_vinfo = vinfo; | |
959 #ifdef FBCON_DEBUG | |
960 fprintf(stderr, "Printing actual vinfo:\n"); | |
961 print_vinfo(&vinfo); | |
962 #endif | |
963 Rmask = 0; | |
964 for ( i=0; i<vinfo.red.length; ++i ) { | |
965 Rmask <<= 1; | |
966 Rmask |= (0x00000001<<vinfo.red.offset); | |
967 } | |
968 Gmask = 0; | |
969 for ( i=0; i<vinfo.green.length; ++i ) { | |
970 Gmask <<= 1; | |
971 Gmask |= (0x00000001<<vinfo.green.offset); | |
972 } | |
973 Bmask = 0; | |
974 for ( i=0; i<vinfo.blue.length; ++i ) { | |
975 Bmask <<= 1; | |
976 Bmask |= (0x00000001<<vinfo.blue.offset); | |
977 } | |
978 if ( ! SDL_ReallocFormat(current, vinfo.bits_per_pixel, | |
979 Rmask, Gmask, Bmask, 0) ) { | |
980 return(NULL); | |
981 } | |
982 | |
983 /* Get the fixed information about the console hardware. | |
984 This is necessary since finfo.line_length changes. | |
985 */ | |
986 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
987 SDL_SetError("Couldn't get console hardware info"); | |
988 return(NULL); | |
989 } | |
990 | |
991 /* Save hardware palette, if needed */ | |
992 FB_SavePalette(this, &finfo, &vinfo); | |
993 | |
994 /* Set up the new mode framebuffer */ | |
995 current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); | |
996 current->w = vinfo.xres; | |
997 current->h = vinfo.yres; | |
998 current->pitch = finfo.line_length; | |
999 current->pixels = mapped_mem+mapped_offset; | |
1000 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1001 /* Set up the information for hardware surfaces */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1002 surfaces_mem = (char *)current->pixels + |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1003 vinfo.yres_virtual*current->pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1004 surfaces_len = (mapped_memlen-(surfaces_mem-mapped_mem)); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1005 FB_FreeHWSurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1006 FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1007 |
0 | 1008 /* Let the application know we have a hardware palette */ |
1009 switch (finfo.visual) { | |
1010 case FB_VISUAL_PSEUDOCOLOR: | |
1011 current->flags |= SDL_HWPALETTE; | |
1012 break; | |
1013 default: | |
1014 break; | |
1015 } | |
1016 | |
1017 /* Update for double-buffering, if we can */ | |
1018 if ( flags & SDL_DOUBLEBUF ) { | |
1019 if ( vinfo.yres_virtual == (height*2) ) { | |
1020 current->flags |= SDL_DOUBLEBUF; | |
1021 flip_page = 0; | |
1022 flip_address[0] = (char *)current->pixels; | |
1023 flip_address[1] = (char *)current->pixels+ | |
1024 current->h*current->pitch; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1025 this->screen = current; |
0 | 1026 FB_FlipHWSurface(this, current); |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1027 this->screen = NULL; |
0 | 1028 } |
1029 } | |
1030 | |
1031 /* Set the update rectangle function */ | |
1032 this->UpdateRects = FB_DirectUpdate; | |
1033 | |
1034 /* We're done */ | |
1035 return(current); | |
1036 } | |
1037 | |
1038 #ifdef FBCON_DEBUG | |
1039 void FB_DumpHWSurfaces(_THIS) | |
1040 { | |
1041 vidmem_bucket *bucket; | |
1042 | |
1043 printf("Memory left: %d (%d total)\n", surfaces_memleft, surfaces_memtotal); | |
1044 printf("\n"); | |
1045 printf(" Base Size\n"); | |
1046 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
1047 printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size, bucket->used ? "used" : "free"); | |
1048 if ( bucket->prev ) { | |
1049 if ( bucket->base != bucket->prev->base+bucket->prev->size ) { | |
1050 printf("Warning, corrupt bucket list! (prev)\n"); | |
1051 } | |
1052 } else { | |
1053 if ( bucket != &surfaces ) { | |
1054 printf("Warning, corrupt bucket list! (!prev)\n"); | |
1055 } | |
1056 } | |
1057 if ( bucket->next ) { | |
1058 if ( bucket->next->base != bucket->base+bucket->size ) { | |
1059 printf("Warning, corrupt bucket list! (next)\n"); | |
1060 } | |
1061 } | |
1062 } | |
1063 printf("\n"); | |
1064 } | |
1065 #endif | |
1066 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1067 static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size) |
0 | 1068 { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1069 vidmem_bucket *bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1070 |
0 | 1071 surfaces_memtotal = size; |
1072 surfaces_memleft = size; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1073 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1074 if ( surfaces_memleft > 0 ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1075 bucket = (vidmem_bucket *)SDL_malloc(sizeof(*bucket)); |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1076 if ( bucket == NULL ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1077 SDL_OutOfMemory(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1078 return(-1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1079 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1080 bucket->prev = &surfaces; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1081 bucket->used = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1082 bucket->dirty = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1083 bucket->base = base; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1084 bucket->size = size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1085 bucket->next = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1086 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1087 bucket = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1088 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1089 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1090 surfaces.prev = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1091 surfaces.used = 1; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1092 surfaces.dirty = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1093 surfaces.base = screen->pixels; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1094 surfaces.size = (unsigned int)((long)base - (long)surfaces.base); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1095 surfaces.next = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1096 screen->hwdata = (struct private_hwdata *)&surfaces; |
0 | 1097 return(0); |
1098 } | |
1099 static void FB_FreeHWSurfaces(_THIS) | |
1100 { | |
1101 vidmem_bucket *bucket, *freeable; | |
1102 | |
1103 bucket = surfaces.next; | |
1104 while ( bucket ) { | |
1105 freeable = bucket; | |
1106 bucket = bucket->next; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1107 SDL_free(freeable); |
0 | 1108 } |
1109 surfaces.next = NULL; | |
1110 } | |
1111 | |
1112 static int FB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
1113 { | |
1114 vidmem_bucket *bucket; | |
1115 int size; | |
1116 int extra; | |
1117 | |
1118 /* Temporarily, we only allow surfaces the same width as display. | |
1119 Some blitters require the pitch between two hardware surfaces | |
1120 to be the same. Others have interesting alignment restrictions. | |
1121 Until someone who knows these details looks at the code... | |
1122 */ | |
1123 if ( surface->pitch > SDL_VideoSurface->pitch ) { | |
1124 SDL_SetError("Surface requested wider than screen"); | |
1125 return(-1); | |
1126 } | |
1127 surface->pitch = SDL_VideoSurface->pitch; | |
1128 size = surface->h * surface->pitch; | |
1129 #ifdef FBCON_DEBUG | |
1130 fprintf(stderr, "Allocating bucket of %d bytes\n", size); | |
1131 #endif | |
1132 | |
1133 /* Quick check for available mem */ | |
1134 if ( size > surfaces_memleft ) { | |
1135 SDL_SetError("Not enough video memory"); | |
1136 return(-1); | |
1137 } | |
1138 | |
1139 /* Search for an empty bucket big enough */ | |
1140 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
1141 if ( ! bucket->used && (size <= bucket->size) ) { | |
1142 break; | |
1143 } | |
1144 } | |
1145 if ( bucket == NULL ) { | |
1146 SDL_SetError("Video memory too fragmented"); | |
1147 return(-1); | |
1148 } | |
1149 | |
1150 /* Create a new bucket for left-over memory */ | |
1151 extra = (bucket->size - size); | |
1152 if ( extra ) { | |
1153 vidmem_bucket *newbucket; | |
1154 | |
1155 #ifdef FBCON_DEBUG | |
1156 fprintf(stderr, "Adding new free bucket of %d bytes\n", extra); | |
1157 #endif | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1158 newbucket = (vidmem_bucket *)SDL_malloc(sizeof(*newbucket)); |
0 | 1159 if ( newbucket == NULL ) { |
1160 SDL_OutOfMemory(); | |
1161 return(-1); | |
1162 } | |
1163 newbucket->prev = bucket; | |
1164 newbucket->used = 0; | |
1165 newbucket->base = bucket->base+size; | |
1166 newbucket->size = extra; | |
1167 newbucket->next = bucket->next; | |
1168 if ( bucket->next ) { | |
1169 bucket->next->prev = newbucket; | |
1170 } | |
1171 bucket->next = newbucket; | |
1172 } | |
1173 | |
1174 /* Set the current bucket values and return it! */ | |
1175 bucket->used = 1; | |
1176 bucket->size = size; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1177 bucket->dirty = 0; |
0 | 1178 #ifdef FBCON_DEBUG |
1179 fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base); | |
1180 #endif | |
1181 surfaces_memleft -= size; | |
1182 surface->flags |= SDL_HWSURFACE; | |
1183 surface->pixels = bucket->base; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1184 surface->hwdata = (struct private_hwdata *)bucket; |
0 | 1185 return(0); |
1186 } | |
1187 static void FB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
1188 { | |
1189 vidmem_bucket *bucket, *freeable; | |
1190 | |
1191 /* Look for the bucket in the current list */ | |
1192 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1193 if ( bucket == (vidmem_bucket *)surface->hwdata ) { |
0 | 1194 break; |
1195 } | |
1196 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1197 if ( bucket && bucket->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1198 /* Add the memory back to the total */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1199 #ifdef DGA_DEBUG |
0 | 1200 printf("Freeing bucket of %d bytes\n", bucket->size); |
1201 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1202 surfaces_memleft += bucket->size; |
0 | 1203 |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1204 /* Can we merge the space with surrounding buckets? */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1205 bucket->used = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1206 if ( bucket->next && ! bucket->next->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1207 #ifdef DGA_DEBUG |
0 | 1208 printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size); |
1209 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1210 freeable = bucket->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1211 bucket->size += bucket->next->size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1212 bucket->next = bucket->next->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1213 if ( bucket->next ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1214 bucket->next->prev = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1215 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1216 SDL_free(freeable); |
0 | 1217 } |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1218 if ( bucket->prev && ! bucket->prev->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1219 #ifdef DGA_DEBUG |
0 | 1220 printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size); |
1221 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1222 freeable = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1223 bucket->prev->size += bucket->size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1224 bucket->prev->next = bucket->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1225 if ( bucket->next ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1226 bucket->next->prev = bucket->prev; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1227 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1228 SDL_free(freeable); |
0 | 1229 } |
1230 } | |
1231 surface->pixels = NULL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1232 surface->hwdata = NULL; |
0 | 1233 } |
1234 static int FB_LockHWSurface(_THIS, SDL_Surface *surface) | |
1235 { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1236 if ( surface == this->screen ) { |
0 | 1237 SDL_mutexP(hw_lock); |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1238 if ( FB_IsSurfaceBusy(surface) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1239 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1240 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1241 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1242 if ( FB_IsSurfaceBusy(surface) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1243 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1244 } |
0 | 1245 } |
1246 return(0); | |
1247 } | |
1248 static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
1249 { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1250 if ( surface == this->screen ) { |
0 | 1251 SDL_mutexV(hw_lock); |
1252 } | |
1253 } | |
1254 | |
1255 static void FB_WaitVBL(_THIS) | |
1256 { | |
1257 #ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */ | |
1258 ioctl(console_fd, FBIOWAITRETRACE, 0); | |
1259 #endif | |
1260 return; | |
1261 } | |
1262 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1263 static void FB_WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1264 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1265 return; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1266 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1267 |
0 | 1268 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface) |
1269 { | |
1270 /* Wait for vertical retrace and then flip display */ | |
1271 cache_vinfo.yoffset = flip_page*surface->h; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1272 if ( FB_IsSurfaceBusy(this->screen) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1273 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1274 } |
0 | 1275 wait_vbl(this); |
1276 if ( ioctl(console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0 ) { | |
1277 SDL_SetError("ioctl(FBIOPAN_DISPLAY) failed"); | |
1278 return(-1); | |
1279 } | |
1280 flip_page = !flip_page; | |
1281 | |
1282 surface->pixels = flip_address[flip_page]; | |
1283 return(0); | |
1284 } | |
1285 | |
1286 static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
1287 { | |
1288 /* The application is already updating the visible video memory */ | |
1289 return; | |
1290 } | |
1291 | |
1292 #ifdef VGA16_FBCON_SUPPORT | |
1293 /* Code adapted with thanks from the XFree86 VGA16 driver! :) */ | |
1294 #define writeGr(index, value) \ | |
1295 outb(index, 0x3CE); \ | |
1296 outb(value, 0x3CF); | |
1297 #define writeSeq(index, value) \ | |
1298 outb(index, 0x3C4); \ | |
1299 outb(value, 0x3C5); | |
1300 | |
1301 static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects) | |
1302 { | |
1303 SDL_Surface *screen; | |
1304 int width, height, FBPitch, left, i, j, SRCPitch, phase; | |
1305 register Uint32 m; | |
1306 Uint8 s1, s2, s3, s4; | |
1307 Uint32 *src, *srcPtr; | |
1308 Uint8 *dst, *dstPtr; | |
1309 | |
1310 screen = this->screen; | |
1311 FBPitch = screen->w >> 3; | |
1312 SRCPitch = screen->pitch >> 2; | |
1313 | |
1314 writeGr(0x03, 0x00); | |
1315 writeGr(0x05, 0x00); | |
1316 writeGr(0x01, 0x00); | |
1317 writeGr(0x08, 0xFF); | |
1318 | |
1319 while(numrects--) { | |
1320 left = rects->x & ~7; | |
1321 width = (rects->w + 7) >> 3; | |
1322 height = rects->h; | |
1323 src = (Uint32*)screen->pixels + (rects->y * SRCPitch) + (left >> 2); | |
1324 dst = (Uint8*)mapped_mem + (rects->y * FBPitch) + (left >> 3); | |
1325 | |
1326 if((phase = (long)dst & 3L)) { | |
1327 phase = 4 - phase; | |
1328 if(phase > width) phase = width; | |
1329 width -= phase; | |
1330 } | |
1331 | |
1332 while(height--) { | |
1333 writeSeq(0x02, 1 << 0); | |
1334 dstPtr = dst; | |
1335 srcPtr = src; | |
1336 i = width; | |
1337 j = phase; | |
1338 while(j--) { | |
1339 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1340 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1341 srcPtr += 2; | |
1342 } | |
1343 while(i >= 4) { | |
1344 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1345 s1 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1346 m = (srcPtr[3] & 0x01010101) | ((srcPtr[2] & 0x01010101) << 4); | |
1347 s2 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1348 m = (srcPtr[5] & 0x01010101) | ((srcPtr[4] & 0x01010101) << 4); | |
1349 s3 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1350 m = (srcPtr[7] & 0x01010101) | ((srcPtr[6] & 0x01010101) << 4); | |
1351 s4 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1352 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1353 srcPtr += 8; | |
1354 dstPtr += 4; | |
1355 i -= 4; | |
1356 } | |
1357 while(i--) { | |
1358 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1359 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1360 srcPtr += 2; | |
1361 } | |
1362 | |
1363 writeSeq(0x02, 1 << 1); | |
1364 dstPtr = dst; | |
1365 srcPtr = src; | |
1366 i = width; | |
1367 j = phase; | |
1368 while(j--) { | |
1369 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1370 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1371 srcPtr += 2; | |
1372 } | |
1373 while(i >= 4) { | |
1374 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1375 s1 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1376 m = (srcPtr[3] & 0x02020202) | ((srcPtr[2] & 0x02020202) << 4); | |
1377 s2 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1378 m = (srcPtr[5] & 0x02020202) | ((srcPtr[4] & 0x02020202) << 4); | |
1379 s3 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1380 m = (srcPtr[7] & 0x02020202) | ((srcPtr[6] & 0x02020202) << 4); | |
1381 s4 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1382 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1383 srcPtr += 8; | |
1384 dstPtr += 4; | |
1385 i -= 4; | |
1386 } | |
1387 while(i--) { | |
1388 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1389 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1390 srcPtr += 2; | |
1391 } | |
1392 | |
1393 writeSeq(0x02, 1 << 2); | |
1394 dstPtr = dst; | |
1395 srcPtr = src; | |
1396 i = width; | |
1397 j = phase; | |
1398 while(j--) { | |
1399 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1400 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1401 srcPtr += 2; | |
1402 } | |
1403 while(i >= 4) { | |
1404 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1405 s1 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1406 m = (srcPtr[3] & 0x04040404) | ((srcPtr[2] & 0x04040404) << 4); | |
1407 s2 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1408 m = (srcPtr[5] & 0x04040404) | ((srcPtr[4] & 0x04040404) << 4); | |
1409 s3 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1410 m = (srcPtr[7] & 0x04040404) | ((srcPtr[6] & 0x04040404) << 4); | |
1411 s4 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1412 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1413 srcPtr += 8; | |
1414 dstPtr += 4; | |
1415 i -= 4; | |
1416 } | |
1417 while(i--) { | |
1418 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1419 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1420 srcPtr += 2; | |
1421 } | |
1422 | |
1423 writeSeq(0x02, 1 << 3); | |
1424 dstPtr = dst; | |
1425 srcPtr = src; | |
1426 i = width; | |
1427 j = phase; | |
1428 while(j--) { | |
1429 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1430 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1431 srcPtr += 2; | |
1432 } | |
1433 while(i >= 4) { | |
1434 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1435 s1 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1436 m = (srcPtr[3] & 0x08080808) | ((srcPtr[2] & 0x08080808) << 4); | |
1437 s2 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1438 m = (srcPtr[5] & 0x08080808) | ((srcPtr[4] & 0x08080808) << 4); | |
1439 s3 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1440 m = (srcPtr[7] & 0x08080808) | ((srcPtr[6] & 0x08080808) << 4); | |
1441 s4 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1442 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1443 srcPtr += 8; | |
1444 dstPtr += 4; | |
1445 i -= 4; | |
1446 } | |
1447 while(i--) { | |
1448 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1449 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1450 srcPtr += 2; | |
1451 } | |
1452 | |
1453 dst += FBPitch; | |
1454 src += SRCPitch; | |
1455 } | |
1456 rects++; | |
1457 } | |
1458 } | |
1459 #endif /* VGA16_FBCON_SUPPORT */ | |
1460 | |
1461 void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area) | |
1462 { | |
1463 struct fb_cmap cmap; | |
1464 | |
1465 cmap.start = 0; | |
1466 cmap.len = palette_len; | |
1467 cmap.red = &area[0*palette_len]; | |
1468 cmap.green = &area[1*palette_len]; | |
1469 cmap.blue = &area[2*palette_len]; | |
1470 cmap.transp = NULL; | |
1471 ioctl(console_fd, FBIOGETCMAP, &cmap); | |
1472 } | |
1473 | |
1474 void FB_RestorePaletteFrom(_THIS, int palette_len, __u16 *area) | |
1475 { | |
1476 struct fb_cmap cmap; | |
1477 | |
1478 cmap.start = 0; | |
1479 cmap.len = palette_len; | |
1480 cmap.red = &area[0*palette_len]; | |
1481 cmap.green = &area[1*palette_len]; | |
1482 cmap.blue = &area[2*palette_len]; | |
1483 cmap.transp = NULL; | |
1484 ioctl(console_fd, FBIOPUTCMAP, &cmap); | |
1485 } | |
1486 | |
1487 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, | |
1488 struct fb_var_screeninfo *vinfo) | |
1489 { | |
1490 int i; | |
1491 | |
1492 /* Save hardware palette, if needed */ | |
1493 if ( finfo->visual == FB_VISUAL_PSEUDOCOLOR ) { | |
1494 saved_cmaplen = 1<<vinfo->bits_per_pixel; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1495 saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap)); |
0 | 1496 if ( saved_cmap != NULL ) { |
1497 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap); | |
1498 } | |
1499 } | |
1500 | |
1501 /* Added support for FB_VISUAL_DIRECTCOLOR. | |
1502 With this mode pixel information is passed through the palette... | |
1503 Neat fading and gamma correction effects can be had by simply | |
1504 fooling around with the palette instead of changing the pixel | |
1505 values themselves... Very neat! | |
1506 | |
1507 Adam Meyerowitz 1/19/2000 | |
1508 ameyerow@optonline.com | |
1509 */ | |
1510 if ( finfo->visual == FB_VISUAL_DIRECTCOLOR ) { | |
1511 __u16 new_entries[3*256]; | |
1512 | |
1513 /* Save the colormap */ | |
1514 saved_cmaplen = 256; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1515 saved_cmap=(__u16 *)SDL_malloc(3*saved_cmaplen*sizeof(*saved_cmap)); |
0 | 1516 if ( saved_cmap != NULL ) { |
1517 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap); | |
1518 } | |
1519 | |
1520 /* Allocate new identity colormap */ | |
1521 for ( i=0; i<256; ++i ) { | |
1522 new_entries[(0*256)+i] = | |
1523 new_entries[(1*256)+i] = | |
1524 new_entries[(2*256)+i] = (i<<8)|i; | |
1525 } | |
1526 FB_RestorePaletteFrom(this, 256, new_entries); | |
1527 } | |
1528 } | |
1529 | |
1530 static void FB_RestorePalette(_THIS) | |
1531 { | |
1532 /* Restore the original palette */ | |
1533 if ( saved_cmap ) { | |
1534 FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1535 SDL_free(saved_cmap); |
0 | 1536 saved_cmap = NULL; |
1537 } | |
1538 } | |
1539 | |
1540 static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
1541 { | |
1542 int i; | |
1543 __u16 r[256]; | |
1544 __u16 g[256]; | |
1545 __u16 b[256]; | |
1546 struct fb_cmap cmap; | |
1547 | |
1548 /* Set up the colormap */ | |
1549 for (i = 0; i < ncolors; i++) { | |
1550 r[i] = colors[i].r << 8; | |
1551 g[i] = colors[i].g << 8; | |
1552 b[i] = colors[i].b << 8; | |
1553 } | |
1554 cmap.start = firstcolor; | |
1555 cmap.len = ncolors; | |
1556 cmap.red = r; | |
1557 cmap.green = g; | |
1558 cmap.blue = b; | |
1559 cmap.transp = NULL; | |
1560 | |
1561 if( (ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) || | |
1562 !(this->screen->flags & SDL_HWPALETTE) ) { | |
1563 colors = this->screen->format->palette->colors; | |
1564 ncolors = this->screen->format->palette->ncolors; | |
1565 cmap.start = 0; | |
1566 cmap.len = ncolors; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1567 SDL_memset(r, 0, sizeof(r)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1568 SDL_memset(g, 0, sizeof(g)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1569 SDL_memset(b, 0, sizeof(b)); |
0 | 1570 if ( ioctl(console_fd, FBIOGETCMAP, &cmap) == 0 ) { |
1571 for ( i=ncolors-1; i>=0; --i ) { | |
1572 colors[i].r = (r[i]>>8); | |
1573 colors[i].g = (g[i]>>8); | |
1574 colors[i].b = (b[i]>>8); | |
1575 } | |
1576 } | |
1577 return(0); | |
1578 } | |
1579 return(1); | |
1580 } | |
1581 | |
1582 /* Note: If we are terminated, this could be called in the middle of | |
1583 another SDL video routine -- notably UpdateRects. | |
1584 */ | |
1585 static void FB_VideoQuit(_THIS) | |
1586 { | |
1587 int i, j; | |
1588 | |
1589 if ( this->screen ) { | |
1590 /* Clear screen and tell SDL not to free the pixels */ | |
1591 if ( this->screen->pixels && FB_InGraphicsMode(this) ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1592 #if defined(__powerpc__) || defined(__ia64__) /* SIGBUS when using SDL_memset() ?? */ |
0 | 1593 Uint8 *rowp = (Uint8 *)this->screen->pixels; |
1594 int left = this->screen->pitch*this->screen->h; | |
1595 while ( left-- ) { *rowp++ = 0; } | |
1596 #else | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1597 SDL_memset(this->screen->pixels,0,this->screen->h*this->screen->pitch); |
0 | 1598 #endif |
1599 } | |
1600 /* This test fails when using the VGA16 shadow memory */ | |
1601 if ( ((char *)this->screen->pixels >= mapped_mem) && | |
1602 ((char *)this->screen->pixels < (mapped_mem+mapped_memlen)) ) { | |
1603 this->screen->pixels = NULL; | |
1604 } | |
1605 } | |
1606 | |
1607 /* Clear the lock mutex */ | |
1608 if ( hw_lock ) { | |
1609 SDL_DestroyMutex(hw_lock); | |
1610 hw_lock = NULL; | |
1611 } | |
1612 | |
1613 /* Clean up defined video modes */ | |
1614 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
1615 if ( SDL_modelist[i] != NULL ) { | |
1616 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
|
1617 SDL_free(SDL_modelist[i][j]); |
0 | 1618 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
1619 SDL_free(SDL_modelist[i]); |
0 | 1620 SDL_modelist[i] = NULL; |
1621 } | |
1622 } | |
1623 | |
1624 /* Clean up the memory bucket list */ | |
1625 FB_FreeHWSurfaces(this); | |
1626 | |
1627 /* Close console and input file descriptors */ | |
1628 if ( console_fd > 0 ) { | |
1629 /* Unmap the video framebuffer and I/O registers */ | |
1630 if ( mapped_mem ) { | |
1631 munmap(mapped_mem, mapped_memlen); | |
1632 mapped_mem = NULL; | |
1633 } | |
1634 if ( mapped_io ) { | |
1635 munmap(mapped_io, mapped_iolen); | |
1636 mapped_io = NULL; | |
1637 } | |
1638 | |
1639 /* Restore the original video mode and palette */ | |
1640 if ( FB_InGraphicsMode(this) ) { | |
1641 FB_RestorePalette(this); | |
1642 ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); | |
1643 } | |
1644 | |
1645 /* We're all done with the framebuffer */ | |
1646 close(console_fd); | |
1647 console_fd = -1; | |
1648 } | |
1649 FB_CloseMouse(this); | |
1650 FB_CloseKeyboard(this); | |
1651 } |