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