comparison src/video/wscons/SDL_wsconsvideo.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 56f952883795
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
38 #include "SDL_wsconsvideo.h" 38 #include "SDL_wsconsvideo.h"
39 #include "SDL_wsconsevents_c.h" 39 #include "SDL_wsconsevents_c.h"
40 #include "SDL_wsconsmouse_c.h" 40 #include "SDL_wsconsmouse_c.h"
41 41
42 #define WSCONSVID_DRIVER_NAME "wscons" 42 #define WSCONSVID_DRIVER_NAME "wscons"
43 enum { 43 enum
44 WSCONS_ROTATE_NONE = 0, 44 {
45 WSCONS_ROTATE_CCW = 90, 45 WSCONS_ROTATE_NONE = 0,
46 WSCONS_ROTATE_UD = 180, 46 WSCONS_ROTATE_CCW = 90,
47 WSCONS_ROTATE_CW = 270 47 WSCONS_ROTATE_UD = 180,
48 WSCONS_ROTATE_CW = 270
48 }; 49 };
49 50
50 #define min(a,b) ((a)<(b)?(a):(b)) 51 #define min(a,b) ((a)<(b)?(a):(b))
51 52
52 /* Initialization/Query functions */ 53 /* Initialization/Query functions */
53 static int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat); 54 static int WSCONS_VideoInit (_THIS, SDL_PixelFormat * vformat);
54 static SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 55 static SDL_Rect **WSCONS_ListModes (_THIS, SDL_PixelFormat * format,
55 static SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 56 Uint32 flags);
56 static int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 57 static SDL_Surface *WSCONS_SetVideoMode (_THIS, SDL_Surface * current,
57 static void WSCONS_VideoQuit(_THIS); 58 int width, int height, int bpp,
59 Uint32 flags);
60 static int WSCONS_SetColors (_THIS, int firstcolor, int ncolors,
61 SDL_Color * colors);
62 static void WSCONS_VideoQuit (_THIS);
58 63
59 /* Hardware surface functions */ 64 /* Hardware surface functions */
60 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface); 65 static int WSCONS_AllocHWSurface (_THIS, SDL_Surface * surface);
61 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface); 66 static int WSCONS_LockHWSurface (_THIS, SDL_Surface * surface);
62 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface); 67 static void WSCONS_UnlockHWSurface (_THIS, SDL_Surface * surface);
63 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface); 68 static void WSCONS_FreeHWSurface (_THIS, SDL_Surface * surface);
64 69
65 /* etc. */ 70 /* etc. */
66 static WSCONS_bitBlit WSCONS_blit16; 71 static WSCONS_bitBlit WSCONS_blit16;
67 static WSCONS_bitBlit WSCONS_blit16blocked; 72 static WSCONS_bitBlit WSCONS_blit16blocked;
68 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 73 static void WSCONS_UpdateRects (_THIS, int numrects, SDL_Rect * rects);
69 74
70 void WSCONS_ReportError(char *fmt, ...) 75 void
71 { 76 WSCONS_ReportError (char *fmt, ...)
72 char message[200]; 77 {
73 va_list vaArgs; 78 char message[200];
74 79 va_list vaArgs;
75 message[199] = '\0'; 80
76 81 message[199] = '\0';
77 va_start(vaArgs, fmt); 82
78 vsnprintf(message, 199, fmt, vaArgs); 83 va_start (vaArgs, fmt);
79 va_end(vaArgs); 84 vsnprintf (message, 199, fmt, vaArgs);
80 85 va_end (vaArgs);
81 SDL_SetError(message); 86
82 fprintf(stderr, "WSCONS error: %s\n", message); 87 SDL_SetError (message);
88 fprintf (stderr, "WSCONS error: %s\n", message);
83 } 89 }
84 90
85 /* WSCONS driver bootstrap functions */ 91 /* WSCONS driver bootstrap functions */
86 92
87 static int WSCONS_Available(void) 93 static int
88 { 94 WSCONS_Available (void)
89 return 1; 95 {
90 } 96 return 1;
91 97 }
92 static void WSCONS_DeleteDevice(SDL_VideoDevice *device) 98
93 { 99 static void
94 SDL_free(device->hidden); 100 WSCONS_DeleteDevice (SDL_VideoDevice * device)
95 SDL_free(device); 101 {
96 } 102 SDL_free (device->hidden);
97 103 SDL_free (device);
98 static SDL_VideoDevice *WSCONS_CreateDevice(int devindex) 104 }
99 { 105
100 SDL_VideoDevice *device; 106 static SDL_VideoDevice *
101 107 WSCONS_CreateDevice (int devindex)
102 /* Initialize all variables that we clean on shutdown */ 108 {
103 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 109 SDL_VideoDevice *device;
104 if (device == NULL) { 110
105 SDL_OutOfMemory(); 111 /* Initialize all variables that we clean on shutdown */
106 return 0; 112 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
107 } 113 if (device == NULL) {
108 SDL_memset(device, 0, (sizeof *device)); 114 SDL_OutOfMemory ();
109 device->hidden = 115 return 0;
110 (struct SDL_PrivateVideoData *)SDL_malloc((sizeof *device->hidden)); 116 }
111 if (device->hidden == NULL) { 117 SDL_memset (device, 0, (sizeof *device));
112 SDL_OutOfMemory(); 118 device->hidden =
113 SDL_free(device); 119 (struct SDL_PrivateVideoData *) SDL_malloc ((sizeof *device->hidden));
114 return(0); 120 if (device->hidden == NULL) {
115 } 121 SDL_OutOfMemory ();
116 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 122 SDL_free (device);
117 device->hidden->fd = -1; 123 return (0);
118 124 }
119 /* Set the function pointers */ 125 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
120 device->VideoInit = WSCONS_VideoInit; 126 device->hidden->fd = -1;
121 device->ListModes = WSCONS_ListModes; 127
122 device->SetVideoMode = WSCONS_SetVideoMode; 128 /* Set the function pointers */
123 device->SetColors = WSCONS_SetColors; 129 device->VideoInit = WSCONS_VideoInit;
124 device->UpdateRects = WSCONS_UpdateRects; 130 device->ListModes = WSCONS_ListModes;
125 device->VideoQuit = WSCONS_VideoQuit; 131 device->SetVideoMode = WSCONS_SetVideoMode;
126 device->AllocHWSurface = WSCONS_AllocHWSurface; 132 device->SetColors = WSCONS_SetColors;
127 device->LockHWSurface = WSCONS_LockHWSurface; 133 device->UpdateRects = WSCONS_UpdateRects;
128 device->UnlockHWSurface = WSCONS_UnlockHWSurface; 134 device->VideoQuit = WSCONS_VideoQuit;
129 device->FreeHWSurface = WSCONS_FreeHWSurface; 135 device->AllocHWSurface = WSCONS_AllocHWSurface;
130 device->InitOSKeymap = WSCONS_InitOSKeymap; 136 device->LockHWSurface = WSCONS_LockHWSurface;
131 device->PumpEvents = WSCONS_PumpEvents; 137 device->UnlockHWSurface = WSCONS_UnlockHWSurface;
132 device->free = WSCONS_DeleteDevice; 138 device->FreeHWSurface = WSCONS_FreeHWSurface;
133 139 device->InitOSKeymap = WSCONS_InitOSKeymap;
134 return device; 140 device->PumpEvents = WSCONS_PumpEvents;
141 device->free = WSCONS_DeleteDevice;
142
143 return device;
135 } 144 }
136 145
137 VideoBootStrap WSCONS_bootstrap = { 146 VideoBootStrap WSCONS_bootstrap = {
138 WSCONSVID_DRIVER_NAME, 147 WSCONSVID_DRIVER_NAME,
139 "SDL wscons video driver", 148 "SDL wscons video driver",
140 WSCONS_Available, 149 WSCONS_Available,
141 WSCONS_CreateDevice 150 WSCONS_CreateDevice
142 }; 151 };
143 152
144 #define WSCONSDEV_FORMAT "/dev/ttyC%01x" 153 #define WSCONSDEV_FORMAT "/dev/ttyC%01x"
145 154
146 int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat) 155 int
147 { 156 WSCONS_VideoInit (_THIS, SDL_PixelFormat * vformat)
148 char devnamebuf[30]; 157 {
149 char *devname; 158 char devnamebuf[30];
150 char *rotation; 159 char *devname;
151 int wstype; 160 char *rotation;
152 int wsmode = WSDISPLAYIO_MODE_DUMBFB; 161 int wstype;
153 size_t len, mapsize; 162 int wsmode = WSDISPLAYIO_MODE_DUMBFB;
154 int pagemask; 163 size_t len, mapsize;
155 int width, height; 164 int pagemask;
156 165 int width, height;
157 devname = SDL_getenv("SDL_WSCONSDEV"); 166
158 if (devname == NULL) { 167 devname = SDL_getenv ("SDL_WSCONSDEV");
159 int activeVT; 168 if (devname == NULL) {
160 if (ioctl(STDIN_FILENO, VT_GETACTIVE, &activeVT) == -1) { 169 int activeVT;
161 WSCONS_ReportError("Unable to determine active terminal: %s", 170 if (ioctl (STDIN_FILENO, VT_GETACTIVE, &activeVT) == -1) {
162 strerror(errno)); 171 WSCONS_ReportError ("Unable to determine active terminal: %s",
163 return -1; 172 strerror (errno));
164 } 173 return -1;
165 SDL_snprintf(devnamebuf, sizeof(devnamebuf), WSCONSDEV_FORMAT, activeVT - 1); 174 }
166 devname = devnamebuf; 175 SDL_snprintf (devnamebuf, sizeof (devnamebuf), WSCONSDEV_FORMAT,
167 } 176 activeVT - 1);
168 177 devname = devnamebuf;
169 private->fd = open(devname, O_RDWR | O_NONBLOCK, 0); 178 }
170 if (private->fd == -1) { 179
171 WSCONS_ReportError("open %s: %s", devname, strerror(errno)); 180 private->fd = open (devname, O_RDWR | O_NONBLOCK, 0);
172 return -1; 181 if (private->fd == -1) {
173 } 182 WSCONS_ReportError ("open %s: %s", devname, strerror (errno));
174 if (ioctl(private->fd, WSDISPLAYIO_GINFO, &private->info) == -1) { 183 return -1;
175 WSCONS_ReportError("ioctl WSDISPLAY_GINFO: %s", strerror(errno)); 184 }
176 return -1; 185 if (ioctl (private->fd, WSDISPLAYIO_GINFO, &private->info) == -1) {
177 } 186 WSCONS_ReportError ("ioctl WSDISPLAY_GINFO: %s", strerror (errno));
178 if (ioctl(private->fd, WSDISPLAYIO_GTYPE, &wstype) == -1) { 187 return -1;
179 WSCONS_ReportError("ioctl WSDISPLAY_GTYPE: %s", strerror(errno)); 188 }
180 return -1; 189 if (ioctl (private->fd, WSDISPLAYIO_GTYPE, &wstype) == -1) {
181 } 190 WSCONS_ReportError ("ioctl WSDISPLAY_GTYPE: %s", strerror (errno));
182 if (ioctl(private->fd, WSDISPLAYIO_LINEBYTES, &private->physlinebytes) == -1) { 191 return -1;
183 WSCONS_ReportError("ioctl WSDISPLAYIO_LINEBYTES: %s", strerror(errno)); 192 }
184 return -1; 193 if (ioctl (private->fd, WSDISPLAYIO_LINEBYTES, &private->physlinebytes) ==
185 } 194 -1) {
186 if (private->info.depth > 8) { 195 WSCONS_ReportError ("ioctl WSDISPLAYIO_LINEBYTES: %s",
187 if (wstype == WSDISPLAY_TYPE_SUN24 || 196 strerror (errno));
188 wstype == WSDISPLAY_TYPE_SUNCG12 || 197 return -1;
189 wstype == WSDISPLAY_TYPE_SUNCG14 || 198 }
190 wstype == WSDISPLAY_TYPE_SUNTCX || 199 if (private->info.depth > 8) {
191 wstype == WSDISPLAY_TYPE_SUNFFB) { 200 if (wstype == WSDISPLAY_TYPE_SUN24 ||
192 private->redMask = 0x0000ff; 201 wstype == WSDISPLAY_TYPE_SUNCG12 ||
193 private->greenMask = 0x00ff00; 202 wstype == WSDISPLAY_TYPE_SUNCG14 ||
194 private->blueMask = 0xff0000; 203 wstype == WSDISPLAY_TYPE_SUNTCX ||
204 wstype == WSDISPLAY_TYPE_SUNFFB) {
205 private->redMask = 0x0000ff;
206 private->greenMask = 0x00ff00;
207 private->blueMask = 0xff0000;
195 #ifdef WSDISPLAY_TYPE_PXALCD 208 #ifdef WSDISPLAY_TYPE_PXALCD
196 } else if (wstype == WSDISPLAY_TYPE_PXALCD) { 209 } else if (wstype == WSDISPLAY_TYPE_PXALCD) {
197 private->redMask = 0x1f << 11; 210 private->redMask = 0x1f << 11;
198 private->greenMask = 0x3f << 5; 211 private->greenMask = 0x3f << 5;
199 private->blueMask = 0x1f; 212 private->blueMask = 0x1f;
200 #endif 213 #endif
214 } else {
215 WSCONS_ReportError ("Unknown video hardware");
216 return -1;
217 }
201 } else { 218 } else {
202 WSCONS_ReportError("Unknown video hardware"); 219 WSCONS_ReportError ("Displays with 8 bpp or less are not supported");
203 return -1; 220 return -1;
204 } 221 }
205 } else { 222
206 WSCONS_ReportError("Displays with 8 bpp or less are not supported"); 223 private->rotate = WSCONS_ROTATE_NONE;
207 return -1; 224 rotation = SDL_getenv ("SDL_VIDEO_WSCONS_ROTATION");
208 } 225 if (rotation != NULL) {
209 226 if (SDL_strlen (rotation) == 0) {
210 private->rotate = WSCONS_ROTATE_NONE; 227 private->shadowFB = 0;
211 rotation = SDL_getenv("SDL_VIDEO_WSCONS_ROTATION"); 228 private->rotate = WSCONS_ROTATE_NONE;
212 if (rotation != NULL) { 229 printf ("Not rotating, no shadow\n");
213 if (SDL_strlen(rotation) == 0) { 230 } else if (!SDL_strcmp (rotation, "NONE")) {
214 private->shadowFB = 0; 231 private->shadowFB = 1;
215 private->rotate = WSCONS_ROTATE_NONE; 232 private->rotate = WSCONS_ROTATE_NONE;
216 printf("Not rotating, no shadow\n"); 233 printf ("Not rotating, but still using shadow\n");
217 } else if (!SDL_strcmp(rotation, "NONE")) { 234 } else if (!SDL_strcmp (rotation, "CW")) {
218 private->shadowFB = 1; 235 private->shadowFB = 1;
219 private->rotate = WSCONS_ROTATE_NONE; 236 private->rotate = WSCONS_ROTATE_CW;
220 printf("Not rotating, but still using shadow\n"); 237 printf ("Rotating screen clockwise\n");
221 } else if (!SDL_strcmp(rotation, "CW")) { 238 } else if (!SDL_strcmp (rotation, "CCW")) {
222 private->shadowFB = 1; 239 private->shadowFB = 1;
223 private->rotate = WSCONS_ROTATE_CW; 240 private->rotate = WSCONS_ROTATE_CCW;
224 printf("Rotating screen clockwise\n"); 241 printf ("Rotating screen counter clockwise\n");
225 } else if (!SDL_strcmp(rotation, "CCW")) { 242 } else if (!SDL_strcmp (rotation, "UD")) {
226 private->shadowFB = 1; 243 private->shadowFB = 1;
227 private->rotate = WSCONS_ROTATE_CCW; 244 private->rotate = WSCONS_ROTATE_UD;
228 printf("Rotating screen counter clockwise\n"); 245 printf ("Rotating screen upside down\n");
229 } else if (!SDL_strcmp(rotation, "UD")) { 246 } else {
230 private->shadowFB = 1; 247 WSCONS_ReportError ("\"%s\" is not a valid value for "
231 private->rotate = WSCONS_ROTATE_UD; 248 "SDL_VIDEO_WSCONS_ROTATION", rotation);
232 printf("Rotating screen upside down\n"); 249 return -1;
233 } else { 250 }
234 WSCONS_ReportError("\"%s\" is not a valid value for " 251 }
235 "SDL_VIDEO_WSCONS_ROTATION", rotation); 252
236 return -1; 253 switch (private->info.depth) {
237 }
238 }
239
240 switch (private->info.depth) {
241 case 1: 254 case 1:
242 case 4: 255 case 4:
243 case 8: 256 case 8:
244 len = private->physlinebytes * private->info.height; 257 len = private->physlinebytes * private->info.height;
245 break; 258 break;
246 case 16: 259 case 16:
247 if (private->physlinebytes == private->info.width) { 260 if (private->physlinebytes == private->info.width) {
248 len = private->info.width * private->info.height * sizeof(short); 261 len = private->info.width * private->info.height * sizeof (short);
249 } else { 262 } else {
250 len = private->physlinebytes * private->info.height; 263 len = private->physlinebytes * private->info.height;
251 } 264 }
252 if (private->rotate == WSCONS_ROTATE_NONE || 265 if (private->rotate == WSCONS_ROTATE_NONE ||
253 private->rotate == WSCONS_ROTATE_UD) { 266 private->rotate == WSCONS_ROTATE_UD) {
254 private->blitFunc = WSCONS_blit16; 267 private->blitFunc = WSCONS_blit16;
255 } else { 268 } else {
256 private->blitFunc = WSCONS_blit16blocked; 269 private->blitFunc = WSCONS_blit16blocked;
257 } 270 }
258 break; 271 break;
259 case 32: 272 case 32:
260 if (private->physlinebytes == private->info.width) { 273 if (private->physlinebytes == private->info.width) {
261 len = private->info.width * private->info.height * sizeof(int); 274 len = private->info.width * private->info.height * sizeof (int);
262 } else { 275 } else {
263 len = private->physlinebytes * private->info.height; 276 len = private->physlinebytes * private->info.height;
264 } 277 }
265 break; 278 break;
266 default: 279 default:
267 WSCONS_ReportError("unsupported depth %d", private->info.depth); 280 WSCONS_ReportError ("unsupported depth %d", private->info.depth);
268 return -1; 281 return -1;
269 } 282 }
270 283
271 if (private->shadowFB && private->blitFunc == NULL) { 284 if (private->shadowFB && private->blitFunc == NULL) {
272 WSCONS_ReportError("Using software buffer, but no blitter function is " 285 WSCONS_ReportError
273 "available for this %d bpp.", private->info.depth); 286 ("Using software buffer, but no blitter function is "
287 "available for this %d bpp.", private->info.depth);
288 return -1;
289 }
290
291 if (ioctl (private->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) {
292 WSCONS_ReportError ("ioctl SMODE");
293 return -1;
294 }
295
296 pagemask = getpagesize () - 1;
297 mapsize = ((int) len + pagemask) & ~pagemask;
298 private->physmem = (Uint8 *) mmap (NULL, mapsize,
299 PROT_READ | PROT_WRITE, MAP_SHARED,
300 private->fd, (off_t) 0);
301 if (private->physmem == (Uint8 *) MAP_FAILED) {
302 private->physmem = NULL;
303 WSCONS_ReportError ("mmap: %s", strerror (errno));
304 return -1;
305 }
306 private->fbmem_len = len;
307
308 if (private->rotate == WSCONS_ROTATE_CW ||
309 private->rotate == WSCONS_ROTATE_CCW) {
310 width = private->info.height;
311 height = private->info.width;
312 } else {
313 width = private->info.width;
314 height = private->info.height;
315 }
316
317 this->info.current_w = width;
318 this->info.current_h = height;
319
320 if (private->shadowFB) {
321 private->shadowmem = (Uint8 *) SDL_malloc (len);
322 if (private->shadowmem == NULL) {
323 WSCONS_ReportError ("No memory for shadow");
324 return -1;
325 }
326 private->fbstart = private->shadowmem;
327 private->fblinebytes = width * ((private->info.depth + 7) / 8);
328 } else {
329 private->fbstart = private->physmem;
330 private->fblinebytes = private->physlinebytes;
331 }
332
333 private->SDL_modelist[0] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
334 private->SDL_modelist[0]->w = width;
335 private->SDL_modelist[0]->h = height;
336
337 vformat->BitsPerPixel = private->info.depth;
338 vformat->BytesPerPixel = private->info.depth / 8;
339
340 if (WSCONS_InitKeyboard (this) == -1) {
341 return -1;
342 }
343
344 return 0;
345 }
346
347 SDL_Rect **
348 WSCONS_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
349 {
350 if (format->BitsPerPixel == private->info.depth) {
351 return private->SDL_modelist;
352 } else {
353 return NULL;
354 }
355 }
356
357 SDL_Surface *
358 WSCONS_SetVideoMode (_THIS, SDL_Surface * current,
359 int width, int height, int bpp, Uint32 flags)
360 {
361 if (width != private->SDL_modelist[0]->w ||
362 height != private->SDL_modelist[0]->h) {
363 WSCONS_ReportError ("Requested video mode %dx%d not supported.",
364 width, height);
365 return NULL;
366 }
367 if (bpp != private->info.depth) {
368 WSCONS_ReportError ("Requested video depth %d bpp not supported.",
369 bpp);
370 return NULL;
371 }
372
373 if (!SDL_ReallocFormat (current,
374 bpp,
375 private->redMask,
376 private->greenMask, private->blueMask, 0)) {
377 WSCONS_ReportError ("Couldn't allocate new pixel format");
378 return NULL;
379 }
380
381 current->flags &= SDL_FULLSCREEN;
382 if (private->shadowFB) {
383 current->flags |= SDL_SWSURFACE;
384 } else {
385 current->flags |= SDL_HWSURFACE;
386 }
387 current->w = width;
388 current->h = height;
389 current->pitch = private->fblinebytes;
390 current->pixels = private->fbstart;
391
392 SDL_memset (private->fbstart, 0, private->fbmem_len);
393
394 return current;
395 }
396
397 static int
398 WSCONS_AllocHWSurface (_THIS, SDL_Surface * surface)
399 {
274 return -1; 400 return -1;
275 } 401 }
276 402 static void
277 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) { 403 WSCONS_FreeHWSurface (_THIS, SDL_Surface * surface)
278 WSCONS_ReportError("ioctl SMODE"); 404 {
279 return -1; 405 }
280 } 406
281 407 static int
282 pagemask = getpagesize() - 1; 408 WSCONS_LockHWSurface (_THIS, SDL_Surface * surface)
283 mapsize = ((int)len + pagemask) & ~pagemask; 409 {
284 private->physmem = (Uint8 *)mmap(NULL, mapsize, 410 return 0;
285 PROT_READ | PROT_WRITE, MAP_SHARED, 411 }
286 private->fd, (off_t)0); 412
287 if (private->physmem == (Uint8 *)MAP_FAILED) { 413 static void
288 private->physmem = NULL; 414 WSCONS_UnlockHWSurface (_THIS, SDL_Surface * surface)
289 WSCONS_ReportError("mmap: %s", strerror(errno)); 415 {
290 return -1; 416 }
291 } 417
292 private->fbmem_len = len; 418 static void
293 419 WSCONS_blit16 (Uint8 * byte_src_pos,
294 if (private->rotate == WSCONS_ROTATE_CW || 420 int srcRightDelta,
295 private->rotate == WSCONS_ROTATE_CCW) { 421 int srcDownDelta,
296 width = private->info.height; 422 Uint8 * byte_dst_pos, int dst_linebytes, int width, int height)
297 height = private->info.width; 423 {
298 } else { 424 int w;
299 width = private->info.width; 425 Uint16 *src_pos = (Uint16 *) byte_src_pos;
300 height = private->info.height; 426 Uint16 *dst_pos = (Uint16 *) byte_dst_pos;
301 } 427
302 428 while (height) {
303 this->info.current_w = width; 429 Uint16 *src = src_pos;
304 this->info.current_h = height; 430 Uint16 *dst = dst_pos;
305 431 for (w = width; w != 0; w--) {
306 if (private->shadowFB) { 432 *dst = *src;
307 private->shadowmem = (Uint8 *)SDL_malloc(len); 433 src += srcRightDelta;
308 if (private->shadowmem == NULL) { 434 dst++;
309 WSCONS_ReportError("No memory for shadow"); 435 }
310 return -1; 436 dst_pos = (Uint16 *) ((Uint8 *) dst_pos + dst_linebytes);
311 } 437 src_pos += srcDownDelta;
312 private->fbstart = private->shadowmem; 438 height--;
313 private->fblinebytes = width * ((private->info.depth + 7) / 8); 439 }
314 } else {
315 private->fbstart = private->physmem;
316 private->fblinebytes = private->physlinebytes;
317 }
318
319 private->SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
320 private->SDL_modelist[0]->w = width;
321 private->SDL_modelist[0]->h = height;
322
323 vformat->BitsPerPixel = private->info.depth;
324 vformat->BytesPerPixel = private->info.depth / 8;
325
326 if (WSCONS_InitKeyboard(this) == -1) {
327 return -1;
328 }
329
330 return 0;
331 }
332
333 SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
334 {
335 if (format->BitsPerPixel == private->info.depth) {
336 return private->SDL_modelist;
337 } else {
338 return NULL;
339 }
340 }
341
342 SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current,
343 int width, int height, int bpp, Uint32 flags)
344 {
345 if (width != private->SDL_modelist[0]->w ||
346 height != private->SDL_modelist[0]->h) {
347 WSCONS_ReportError("Requested video mode %dx%d not supported.",
348 width, height);
349 return NULL;
350 }
351 if (bpp != private->info.depth) {
352 WSCONS_ReportError("Requested video depth %d bpp not supported.", bpp);
353 return NULL;
354 }
355
356 if (!SDL_ReallocFormat(current,
357 bpp,
358 private->redMask,
359 private->greenMask,
360 private->blueMask,
361 0)) {
362 WSCONS_ReportError("Couldn't allocate new pixel format");
363 return NULL;
364 }
365
366 current->flags &= SDL_FULLSCREEN;
367 if (private->shadowFB) {
368 current->flags |= SDL_SWSURFACE;
369 } else {
370 current->flags |= SDL_HWSURFACE;
371 }
372 current->w = width;
373 current->h = height;
374 current->pitch = private->fblinebytes;
375 current->pixels = private->fbstart;
376
377 SDL_memset(private->fbstart, 0, private->fbmem_len);
378
379 return current;
380 }
381
382 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface)
383 {
384 return -1;
385 }
386 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface)
387 {
388 }
389
390 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface)
391 {
392 return 0;
393 }
394
395 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface)
396 {
397 }
398
399 static void WSCONS_blit16(Uint8 *byte_src_pos,
400 int srcRightDelta,
401 int srcDownDelta,
402 Uint8 *byte_dst_pos,
403 int dst_linebytes,
404 int width,
405 int height)
406 {
407 int w;
408 Uint16 *src_pos = (Uint16 *)byte_src_pos;
409 Uint16 *dst_pos = (Uint16 *)byte_dst_pos;
410
411 while (height) {
412 Uint16 *src = src_pos;
413 Uint16 *dst = dst_pos;
414 for (w = width; w != 0; w--) {
415 *dst = *src;
416 src += srcRightDelta;
417 dst++;
418 }
419 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes);
420 src_pos += srcDownDelta;
421 height--;
422 }
423 } 440 }
424 441
425 #define BLOCKSIZE_W 32 442 #define BLOCKSIZE_W 32
426 #define BLOCKSIZE_H 32 443 #define BLOCKSIZE_H 32
427 444
428 static void WSCONS_blit16blocked(Uint8 *byte_src_pos, 445 static void
429 int srcRightDelta, 446 WSCONS_blit16blocked (Uint8 * byte_src_pos,
430 int srcDownDelta, 447 int srcRightDelta,
431 Uint8 *byte_dst_pos, 448 int srcDownDelta,
432 int dst_linebytes, 449 Uint8 * byte_dst_pos,
433 int width, 450 int dst_linebytes, int width, int height)
434 int height) 451 {
435 { 452 int w;
436 int w; 453 Uint16 *src_pos = (Uint16 *) byte_src_pos;
437 Uint16 *src_pos = (Uint16 *)byte_src_pos; 454 Uint16 *dst_pos = (Uint16 *) byte_dst_pos;
438 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; 455
439 456 while (height > 0) {
440 while (height > 0) { 457 Uint16 *src = src_pos;
441 Uint16 *src = src_pos; 458 Uint16 *dst = dst_pos;
442 Uint16 *dst = dst_pos; 459 for (w = width; w > 0; w -= BLOCKSIZE_W) {
443 for (w = width; w > 0; w -= BLOCKSIZE_W) { 460 WSCONS_blit16 ((Uint8 *) src,
444 WSCONS_blit16((Uint8 *)src, 461 srcRightDelta,
445 srcRightDelta, 462 srcDownDelta,
446 srcDownDelta, 463 (Uint8 *) dst,
447 (Uint8 *)dst, 464 dst_linebytes,
448 dst_linebytes, 465 min (w, BLOCKSIZE_W), min (height, BLOCKSIZE_H));
449 min(w, BLOCKSIZE_W), 466 src += srcRightDelta * BLOCKSIZE_W;
450 min(height, BLOCKSIZE_H)); 467 dst += BLOCKSIZE_W;
451 src += srcRightDelta * BLOCKSIZE_W; 468 }
452 dst += BLOCKSIZE_W; 469 dst_pos =
453 } 470 (Uint16 *) ((Uint8 *) dst_pos + dst_linebytes * BLOCKSIZE_H);
454 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes * BLOCKSIZE_H); 471 src_pos += srcDownDelta * BLOCKSIZE_H;
455 src_pos += srcDownDelta * BLOCKSIZE_H; 472 height -= BLOCKSIZE_H;
456 height -= BLOCKSIZE_H; 473 }
457 } 474 }
458 } 475
459 476 static void
460 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 477 WSCONS_UpdateRects (_THIS, int numrects, SDL_Rect * rects)
461 { 478 {
462 int width = private->SDL_modelist[0]->w; 479 int width = private->SDL_modelist[0]->w;
463 int height = private->SDL_modelist[0]->h; 480 int height = private->SDL_modelist[0]->h;
464 int bytesPerPixel = (private->info.depth + 7) / 8; 481 int bytesPerPixel = (private->info.depth + 7) / 8;
465 int i; 482 int i;
466 483
467 if (!private->shadowFB) { 484 if (!private->shadowFB) {
468 return; 485 return;
469 } 486 }
470 487
471 if (private->info.depth != 16) { 488 if (private->info.depth != 16) {
472 WSCONS_ReportError("Shadow copy only implemented for 16 bpp"); 489 WSCONS_ReportError ("Shadow copy only implemented for 16 bpp");
473 return; 490 return;
474 } 491 }
475 492
476 for (i = 0; i < numrects; i++) { 493 for (i = 0; i < numrects; i++) {
477 int x1, y1, x2, y2; 494 int x1, y1, x2, y2;
478 int scr_x1, scr_y1, scr_x2, scr_y2; 495 int scr_x1, scr_y1, scr_x2, scr_y2;
479 int sha_x1, sha_y1; 496 int sha_x1, sha_y1;
480 int shadowRightDelta; /* Address change when moving right in dest */ 497 int shadowRightDelta; /* Address change when moving right in dest */
481 int shadowDownDelta; /* Address change when moving down in dest */ 498 int shadowDownDelta; /* Address change when moving down in dest */
482 Uint8 *src_start; 499 Uint8 *src_start;
483 Uint8 *dst_start; 500 Uint8 *dst_start;
484 501
485 x1 = rects[i].x; 502 x1 = rects[i].x;
486 y1 = rects[i].y; 503 y1 = rects[i].y;
487 x2 = x1 + rects[i].w; 504 x2 = x1 + rects[i].w;
488 y2 = y1 + rects[i].h; 505 y2 = y1 + rects[i].h;
489 506
490 if (x1 < 0) { 507 if (x1 < 0) {
491 x1 = 0; 508 x1 = 0;
492 } else if (x1 > width) { 509 } else if (x1 > width) {
493 x1 = width; 510 x1 = width;
494 } 511 }
495 if (x2 < 0) { 512 if (x2 < 0) {
496 x2 = 0; 513 x2 = 0;
497 } else if (x2 > width) { 514 } else if (x2 > width) {
498 x2 = width; 515 x2 = width;
499 } 516 }
500 if (y1 < 0) { 517 if (y1 < 0) {
501 y1 = 0; 518 y1 = 0;
502 } else if (y1 > height) { 519 } else if (y1 > height) {
503 y1 = height; 520 y1 = height;
504 } 521 }
505 if (y2 < 0) { 522 if (y2 < 0) {
506 y2 = 0; 523 y2 = 0;
507 } else if (y2 > height) { 524 } else if (y2 > height) {
508 y2 = height; 525 y2 = height;
509 } 526 }
510 if (x2 <= x1 || y2 <= y1) { 527 if (x2 <= x1 || y2 <= y1) {
511 continue; 528 continue;
512 } 529 }
513 530
514 switch (private->rotate) { 531 switch (private->rotate) {
515 case WSCONS_ROTATE_NONE: 532 case WSCONS_ROTATE_NONE:
516 sha_x1 = scr_x1 = x1; 533 sha_x1 = scr_x1 = x1;
517 sha_y1 = scr_y1 = y1; 534 sha_y1 = scr_y1 = y1;
518 scr_x2 = x2; 535 scr_x2 = x2;
519 scr_y2 = y2; 536 scr_y2 = y2;
520 shadowRightDelta = 1; 537 shadowRightDelta = 1;
521 shadowDownDelta = width; 538 shadowDownDelta = width;
522 break; 539 break;
523 case WSCONS_ROTATE_CCW: 540 case WSCONS_ROTATE_CCW:
524 scr_x1 = y1; 541 scr_x1 = y1;
525 scr_y1 = width - x2; 542 scr_y1 = width - x2;
526 scr_x2 = y2; 543 scr_x2 = y2;
527 scr_y2 = width - x1; 544 scr_y2 = width - x1;
528 sha_x1 = x2 - 1; 545 sha_x1 = x2 - 1;
529 sha_y1 = y1; 546 sha_y1 = y1;
530 shadowRightDelta = width; 547 shadowRightDelta = width;
531 shadowDownDelta = -1; 548 shadowDownDelta = -1;
532 break; 549 break;
533 case WSCONS_ROTATE_UD: 550 case WSCONS_ROTATE_UD:
534 scr_x1 = width - x2; 551 scr_x1 = width - x2;
535 scr_y1 = height - y2; 552 scr_y1 = height - y2;
536 scr_x2 = width - x1; 553 scr_x2 = width - x1;
537 scr_y2 = height - y1; 554 scr_y2 = height - y1;
538 sha_x1 = x2 - 1; 555 sha_x1 = x2 - 1;
539 sha_y1 = y2 - 1; 556 sha_y1 = y2 - 1;
540 shadowRightDelta = -1; 557 shadowRightDelta = -1;
541 shadowDownDelta = -width; 558 shadowDownDelta = -width;
542 break; 559 break;
543 case WSCONS_ROTATE_CW: 560 case WSCONS_ROTATE_CW:
544 scr_x1 = height - y2; 561 scr_x1 = height - y2;
545 scr_y1 = x1; 562 scr_y1 = x1;
546 scr_x2 = height - y1; 563 scr_x2 = height - y1;
547 scr_y2 = x2; 564 scr_y2 = x2;
548 sha_x1 = x1; 565 sha_x1 = x1;
549 sha_y1 = y2 - 1; 566 sha_y1 = y2 - 1;
550 shadowRightDelta = -width; 567 shadowRightDelta = -width;
551 shadowDownDelta = 1; 568 shadowDownDelta = 1;
552 break; 569 break;
553 default: 570 default:
554 WSCONS_ReportError("Unknown rotation"); 571 WSCONS_ReportError ("Unknown rotation");
555 return; 572 return;
556 } 573 }
557 574
558 src_start = private->shadowmem + (sha_y1 * width + sha_x1) * bytesPerPixel; 575 src_start =
559 dst_start = private->physmem + scr_y1 * private->physlinebytes + 576 private->shadowmem + (sha_y1 * width + sha_x1) * bytesPerPixel;
560 scr_x1 * bytesPerPixel; 577 dst_start =
561 578 private->physmem + scr_y1 * private->physlinebytes +
562 private->blitFunc(src_start, 579 scr_x1 * bytesPerPixel;
563 shadowRightDelta, 580
564 shadowDownDelta, 581 private->blitFunc (src_start,
565 dst_start, 582 shadowRightDelta,
566 private->physlinebytes, 583 shadowDownDelta,
567 scr_x2 - scr_x1, 584 dst_start,
568 scr_y2 - scr_y1); 585 private->physlinebytes,
569 } 586 scr_x2 - scr_x1, scr_y2 - scr_y1);
570 } 587 }
571 588 }
572 int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 589
573 { 590 int
574 return 0; 591 WSCONS_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
592 {
593 return 0;
575 } 594 }
576 595
577 /* 596 /*
578 * Note: If we are terminated, this could be called in the middle of 597 * Note: If we are terminated, this could be called in the middle of
579 * another SDL video routine -- notably UpdateRects. 598 * another SDL video routine -- notably UpdateRects.
580 */ 599 */
581 void WSCONS_VideoQuit(_THIS) 600 void
582 { 601 WSCONS_VideoQuit (_THIS)
583 int mode = WSDISPLAYIO_MODE_EMUL; 602 {
584 603 int mode = WSDISPLAYIO_MODE_EMUL;
585 if (private->shadowmem != NULL) { 604
586 SDL_free(private->shadowmem); 605 if (private->shadowmem != NULL) {
587 private->shadowmem = NULL; 606 SDL_free (private->shadowmem);
588 } 607 private->shadowmem = NULL;
589 private->fbstart = NULL; 608 }
590 if (this->screen != NULL) { 609 private->fbstart = NULL;
591 this->screen->pixels = NULL; 610 if (this->screen != NULL) {
592 } 611 this->screen->pixels = NULL;
593 612 }
594 if (private->SDL_modelist[0] != NULL) { 613
595 SDL_free(private->SDL_modelist[0]); 614 if (private->SDL_modelist[0] != NULL) {
596 private->SDL_modelist[0] = NULL; 615 SDL_free (private->SDL_modelist[0]);
597 } 616 private->SDL_modelist[0] = NULL;
598 617 }
599 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &mode) == -1) { 618
600 WSCONS_ReportError("ioctl SMODE"); 619 if (ioctl (private->fd, WSDISPLAYIO_SMODE, &mode) == -1) {
601 } 620 WSCONS_ReportError ("ioctl SMODE");
602 621 }
603 WSCONS_ReleaseKeyboard(this); 622
604 623 WSCONS_ReleaseKeyboard (this);
605 if (private->fd != -1) { 624
606 close(private->fd); 625 if (private->fd != -1) {
607 private->fd = -1; 626 close (private->fd);
608 } 627 private->fd = -1;
609 } 628 }
629 }
630
631 /* vi: set ts=4 sw=4 expandtab: */