comparison src/video/fbcon/SDL_fbvideo.c @ 1662:782fd950bd46 SDL-1.3

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