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