Mercurial > sdl-ios-xcode
annotate src/video/wscons/SDL_wsconsvideo.c @ 1459:1e8582152d44
Date: Wed, 01 Mar 2006 10:14:31 +0000
From: "alan buckley"
Subject: Re: Updating SDL for RISC OS
I've attached a zip file with three diffs to get SDL to build on RISC OS.
configure.in.diff and makedeps.sh.diff have been modified so that they
can build the assembler file in video/riscos. You may want to double
check these as I don't know a lot about unix shell programming.
(I've tested them cross-compiling on cygwin).
sdlsysthread.diff is the changes required to SDL_systhread.c for RISC
OS. As you suspected with these changes in place you can delete the
RISC OS specific threading code in thread/riscos.
I've also renamed SDL_riscosASM.s to SDL_riscosASM.S, but I'm never
quite sure how to rename files in CVS, so if you could to this it would
be appreciated.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 02 Mar 2006 03:24:20 +0000 |
parents | d910939febfa |
children | 8d9bb0cf2c2a |
rev | line source |
---|---|
1187 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
1187 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
1187 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
1187 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
13 Lesser General Public License for more details. |
1187 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1187
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1187 | 18 |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1383
diff
changeset
|
22 #include "SDL_config.h" |
1187 | 23 |
24 #include <sys/time.h> | |
25 #include <sys/mman.h> | |
26 #include <sys/ioctl.h> | |
27 #include <dev/wscons/wsdisplay_usl_io.h> | |
28 #include <fcntl.h> | |
29 #include <unistd.h> | |
30 #include <errno.h> | |
31 | |
32 #include "SDL_video.h" | |
33 #include "SDL_mouse.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
34 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
35 #include "../SDL_pixels_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
36 #include "../../events/SDL_events_c.h" |
1187 | 37 |
38 #include "SDL_wsconsvideo.h" | |
39 #include "SDL_wsconsevents_c.h" | |
40 #include "SDL_wsconsmouse_c.h" | |
41 | |
42 #define WSCONSVID_DRIVER_NAME "wscons" | |
43 enum { | |
44 WSCONS_ROTATE_NONE = 0, | |
45 WSCONS_ROTATE_CCW = 90, | |
46 WSCONS_ROTATE_UD = 180, | |
47 WSCONS_ROTATE_CW = 270 | |
48 }; | |
49 | |
50 #define min(a,b) ((a)<(b)?(a):(b)) | |
51 | |
52 /* Initialization/Query functions */ | |
53 static int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
54 static SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
55 static SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
56 static int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
57 static void WSCONS_VideoQuit(_THIS); | |
58 | |
59 /* Hardware surface functions */ | |
60 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface); | |
61 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface); | |
62 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
63 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface); | |
64 | |
65 /* etc. */ | |
66 static WSCONS_bitBlit WSCONS_blit16; | |
67 static WSCONS_bitBlit WSCONS_blit16blocked; | |
68 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | |
69 | |
70 void WSCONS_ReportError(char *fmt, ...) | |
71 { | |
72 char message[200]; | |
73 | |
74 message[199] = '\0'; | |
75 | |
76 va_list vaArgs; | |
77 va_start(vaArgs, fmt); | |
78 vsnprintf(message, 199, fmt, vaArgs); | |
79 va_end(vaArgs); | |
80 | |
81 SDL_SetError(message); | |
82 fprintf(stderr, "WSCONS error: %s\n", message); | |
83 } | |
84 | |
85 /* WSCONS driver bootstrap functions */ | |
86 | |
87 static int WSCONS_Available(void) | |
88 { | |
89 return 1; | |
90 } | |
91 | |
92 static void WSCONS_DeleteDevice(SDL_VideoDevice *device) | |
93 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
94 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
95 SDL_free(device); |
1187 | 96 } |
97 | |
98 static SDL_VideoDevice *WSCONS_CreateDevice(int devindex) | |
99 { | |
100 SDL_VideoDevice *device; | |
101 | |
102 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
103 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
1187 | 104 if (device == NULL) { |
105 SDL_OutOfMemory(); | |
106 return 0; | |
107 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
108 SDL_memset(device, 0, (sizeof *device)); |
1187 | 109 device->hidden = |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
110 (struct SDL_PrivateVideoData *)SDL_malloc((sizeof *device->hidden)); |
1187 | 111 if (device->hidden == NULL) { |
112 SDL_OutOfMemory(); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
113 SDL_free(device); |
1187 | 114 return(0); |
115 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
116 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
1187 | 117 device->hidden->fd = -1; |
118 | |
119 /* Set the function pointers */ | |
120 device->VideoInit = WSCONS_VideoInit; | |
121 device->ListModes = WSCONS_ListModes; | |
122 device->SetVideoMode = WSCONS_SetVideoMode; | |
123 device->SetColors = WSCONS_SetColors; | |
124 device->UpdateRects = WSCONS_UpdateRects; | |
125 device->VideoQuit = WSCONS_VideoQuit; | |
126 device->AllocHWSurface = WSCONS_AllocHWSurface; | |
127 device->LockHWSurface = WSCONS_LockHWSurface; | |
128 device->UnlockHWSurface = WSCONS_UnlockHWSurface; | |
129 device->FreeHWSurface = WSCONS_FreeHWSurface; | |
130 device->InitOSKeymap = WSCONS_InitOSKeymap; | |
131 device->PumpEvents = WSCONS_PumpEvents; | |
132 device->free = WSCONS_DeleteDevice; | |
133 | |
134 return device; | |
135 } | |
136 | |
137 VideoBootStrap WSCONS_bootstrap = { | |
138 WSCONSVID_DRIVER_NAME, | |
139 "SDL wscons video driver", | |
140 WSCONS_Available, | |
141 WSCONS_CreateDevice | |
142 }; | |
143 | |
144 #define WSCONSDEV_FORMAT "/dev/ttyC%01x" | |
145 | |
146 int WSCONS_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
147 { | |
148 char devnamebuf[30]; | |
149 char *devname; | |
150 char *rotation; | |
151 int wstype; | |
152 int wsmode = WSDISPLAYIO_MODE_DUMBFB; | |
153 size_t len, mapsize; | |
154 int pagemask; | |
155 int width, height; | |
156 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
157 devname = SDL_getenv("SDL_WSCONSDEV"); |
1187 | 158 if (devname == NULL) { |
159 int activeVT; | |
160 if (ioctl(STDIN_FILENO, VT_GETACTIVE, &activeVT) == -1) { | |
161 WSCONS_ReportError("Unable to determine active terminal: %s", | |
162 strerror(errno)); | |
163 return -1; | |
164 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
165 SDL_snprintf(devnamebuf, sizeof(devnamebuf), WSCONSDEV_FORMAT, activeVT - 1); |
1187 | 166 devname = devnamebuf; |
167 } | |
168 | |
169 private->fd = open(devname, O_RDWR | O_NONBLOCK, 0); | |
170 if (private->fd == -1) { | |
171 WSCONS_ReportError("open %s: %s", devname, strerror(errno)); | |
172 return -1; | |
173 } | |
174 if (ioctl(private->fd, WSDISPLAYIO_GINFO, &private->info) == -1) { | |
175 WSCONS_ReportError("ioctl WSDISPLAY_GINFO: %s", strerror(errno)); | |
176 return -1; | |
177 } | |
178 if (ioctl(private->fd, WSDISPLAYIO_GTYPE, &wstype) == -1) { | |
179 WSCONS_ReportError("ioctl WSDISPLAY_GTYPE: %s", strerror(errno)); | |
180 return -1; | |
181 } | |
182 if (ioctl(private->fd, WSDISPLAYIO_LINEBYTES, &private->physlinebytes) == -1) { | |
183 WSCONS_ReportError("ioctl WSDISPLAYIO_LINEBYTES: %s", strerror(errno)); | |
184 return -1; | |
185 } | |
186 if (private->info.depth > 8) { | |
187 if (wstype == WSDISPLAY_TYPE_SUN24 || | |
188 wstype == WSDISPLAY_TYPE_SUNCG12 || | |
189 wstype == WSDISPLAY_TYPE_SUNCG14 || | |
190 wstype == WSDISPLAY_TYPE_SUNTCX || | |
191 wstype == WSDISPLAY_TYPE_SUNFFB) { | |
192 private->redMask = 0x0000ff; | |
193 private->greenMask = 0x00ff00; | |
194 private->blueMask = 0xff0000; | |
1383 | 195 #ifdef WSDISPLAY_TYPE_PXALCD |
1187 | 196 } else if (wstype == WSDISPLAY_TYPE_PXALCD) { |
197 private->redMask = 0x1f << 11; | |
198 private->greenMask = 0x3f << 5; | |
199 private->blueMask = 0x1f; | |
1383 | 200 #endif |
1187 | 201 } else { |
202 WSCONS_ReportError("Unknown video hardware"); | |
203 return -1; | |
204 } | |
205 } else { | |
206 WSCONS_ReportError("Displays with 8 bpp or less are not supported"); | |
207 return -1; | |
208 } | |
209 | |
210 private->rotate = WSCONS_ROTATE_NONE; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
211 rotation = SDL_getenv("SDL_VIDEO_WSCONS_ROTATION"); |
1187 | 212 if (rotation != NULL) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
213 if (SDL_strlen(rotation) == 0) { |
1187 | 214 private->shadowFB = 0; |
215 private->rotate = WSCONS_ROTATE_NONE; | |
216 printf("Not rotating, no shadow\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
217 } else if (!SDL_strcmp(rotation, "NONE")) { |
1187 | 218 private->shadowFB = 1; |
219 private->rotate = WSCONS_ROTATE_NONE; | |
220 printf("Not rotating, but still using shadow\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
221 } else if (!SDL_strcmp(rotation, "CW")) { |
1187 | 222 private->shadowFB = 1; |
223 private->rotate = WSCONS_ROTATE_CW; | |
224 printf("Rotating screen clockwise\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
225 } else if (!SDL_strcmp(rotation, "CCW")) { |
1187 | 226 private->shadowFB = 1; |
227 private->rotate = WSCONS_ROTATE_CCW; | |
228 printf("Rotating screen counter clockwise\n"); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
229 } else if (!SDL_strcmp(rotation, "UD")) { |
1187 | 230 private->shadowFB = 1; |
231 private->rotate = WSCONS_ROTATE_UD; | |
232 printf("Rotating screen upside down\n"); | |
233 } else { | |
234 WSCONS_ReportError("\"%s\" is not a valid value for " | |
235 "SDL_VIDEO_WSCONS_ROTATION", rotation); | |
236 return -1; | |
237 } | |
238 } | |
239 | |
240 switch (private->info.depth) { | |
241 case 1: | |
242 case 4: | |
243 case 8: | |
244 len = private->physlinebytes * private->info.height; | |
245 break; | |
246 case 16: | |
247 if (private->physlinebytes == private->info.width) { | |
248 len = private->info.width * private->info.height * sizeof(short); | |
249 } else { | |
250 len = private->physlinebytes * private->info.height; | |
251 } | |
252 if (private->rotate == WSCONS_ROTATE_NONE || | |
253 private->rotate == WSCONS_ROTATE_UD) { | |
254 private->blitFunc = WSCONS_blit16; | |
255 } else { | |
256 private->blitFunc = WSCONS_blit16blocked; | |
257 } | |
258 break; | |
259 case 32: | |
260 if (private->physlinebytes == private->info.width) { | |
261 len = private->info.width * private->info.height * sizeof(int); | |
262 } else { | |
263 len = private->physlinebytes * private->info.height; | |
264 } | |
265 break; | |
266 default: | |
267 WSCONS_ReportError("unsupported depth %d", private->info.depth); | |
268 return -1; | |
269 } | |
270 | |
271 if (private->shadowFB && private->blitFunc == NULL) { | |
272 WSCONS_ReportError("Using software buffer, but no blitter function is " | |
273 "available for this %d bpp.", private->info.depth); | |
274 return -1; | |
275 } | |
276 | |
277 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) { | |
278 WSCONS_ReportError("ioctl SMODE"); | |
279 return -1; | |
280 } | |
281 | |
282 pagemask = getpagesize() - 1; | |
283 mapsize = ((int)len + pagemask) & ~pagemask; | |
284 private->physmem = (Uint8 *)mmap(NULL, mapsize, | |
285 PROT_READ | PROT_WRITE, MAP_SHARED, | |
286 private->fd, (off_t)0); | |
287 if (private->physmem == (Uint8 *)MAP_FAILED) { | |
288 private->physmem = NULL; | |
289 WSCONS_ReportError("mmap: %s", strerror(errno)); | |
290 return -1; | |
291 } | |
292 private->fbmem_len = len; | |
293 | |
294 if (private->rotate == WSCONS_ROTATE_CW || | |
295 private->rotate == WSCONS_ROTATE_CCW) { | |
296 width = private->info.height; | |
297 height = private->info.width; | |
298 } else { | |
299 width = private->info.width; | |
300 height = private->info.height; | |
301 } | |
302 | |
303 if (private->shadowFB) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
304 private->shadowmem = (Uint8 *)SDL_malloc(len); |
1187 | 305 if (private->shadowmem == NULL) { |
306 WSCONS_ReportError("No memory for shadow"); | |
307 return -1; | |
308 } | |
309 private->fbstart = private->shadowmem; | |
310 private->fblinebytes = width * ((private->info.depth + 7) / 8); | |
311 } else { | |
312 private->fbstart = private->physmem; | |
313 private->fblinebytes = private->physlinebytes; | |
314 } | |
315 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
316 private->SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
1187 | 317 private->SDL_modelist[0]->w = width; |
318 private->SDL_modelist[0]->h = height; | |
319 | |
320 vformat->BitsPerPixel = private->info.depth; | |
321 vformat->BytesPerPixel = private->info.depth / 8; | |
322 | |
323 if (WSCONS_InitKeyboard(this) == -1) { | |
324 return -1; | |
325 } | |
326 | |
327 return 0; | |
328 } | |
329 | |
330 SDL_Rect **WSCONS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
331 { | |
332 if (format->BitsPerPixel == private->info.depth) { | |
333 return private->SDL_modelist; | |
334 } else { | |
335 return NULL; | |
336 } | |
337 } | |
338 | |
339 SDL_Surface *WSCONS_SetVideoMode(_THIS, SDL_Surface *current, | |
340 int width, int height, int bpp, Uint32 flags) | |
341 { | |
342 if (width != private->SDL_modelist[0]->w || | |
343 height != private->SDL_modelist[0]->h) { | |
344 WSCONS_ReportError("Requested video mode %dx%d not supported.", | |
345 width, height); | |
346 return NULL; | |
347 } | |
348 if (bpp != private->info.depth) { | |
349 WSCONS_ReportError("Requested video depth %d bpp not supported.", bpp); | |
350 return NULL; | |
351 } | |
352 | |
353 if (!SDL_ReallocFormat(current, | |
354 bpp, | |
355 private->redMask, | |
356 private->greenMask, | |
357 private->blueMask, | |
358 0)) { | |
359 WSCONS_ReportError("Couldn't allocate new pixel format"); | |
360 return NULL; | |
361 } | |
362 | |
363 current->flags &= SDL_FULLSCREEN; | |
364 if (private->shadowFB) { | |
365 current->flags |= SDL_SWSURFACE; | |
366 } else { | |
367 current->flags |= SDL_HWSURFACE; | |
368 } | |
369 current->w = width; | |
370 current->h = height; | |
371 current->pitch = private->fblinebytes; | |
372 current->pixels = private->fbstart; | |
373 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
374 SDL_memset(private->fbstart, 0, private->fbmem_len); |
1187 | 375 |
376 return current; | |
377 } | |
378 | |
379 static int WSCONS_AllocHWSurface(_THIS, SDL_Surface *surface) | |
380 { | |
381 return -1; | |
382 } | |
383 static void WSCONS_FreeHWSurface(_THIS, SDL_Surface *surface) | |
384 { | |
385 } | |
386 | |
387 static int WSCONS_LockHWSurface(_THIS, SDL_Surface *surface) | |
388 { | |
389 return 0; | |
390 } | |
391 | |
392 static void WSCONS_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
393 { | |
394 } | |
395 | |
396 static void WSCONS_blit16(Uint8 *byte_src_pos, | |
397 int srcRightDelta, | |
398 int srcDownDelta, | |
399 Uint8 *byte_dst_pos, | |
400 int dst_linebytes, | |
401 int width, | |
402 int height) | |
403 { | |
404 int w; | |
405 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
406 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
407 | |
408 while (height) { | |
409 Uint16 *src = src_pos; | |
410 Uint16 *dst = dst_pos; | |
411 for (w = width; w != 0; w--) { | |
412 *dst = *src; | |
413 src += srcRightDelta; | |
414 dst++; | |
415 } | |
416 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes); | |
417 src_pos += srcDownDelta; | |
418 height--; | |
419 } | |
420 } | |
421 | |
422 #define BLOCKSIZE_W 32 | |
423 #define BLOCKSIZE_H 32 | |
424 | |
425 static void WSCONS_blit16blocked(Uint8 *byte_src_pos, | |
426 int srcRightDelta, | |
427 int srcDownDelta, | |
428 Uint8 *byte_dst_pos, | |
429 int dst_linebytes, | |
430 int width, | |
431 int height) | |
432 { | |
433 int w; | |
434 Uint16 *src_pos = (Uint16 *)byte_src_pos; | |
435 Uint16 *dst_pos = (Uint16 *)byte_dst_pos; | |
436 | |
437 while (height > 0) { | |
438 Uint16 *src = src_pos; | |
439 Uint16 *dst = dst_pos; | |
440 for (w = width; w > 0; w -= BLOCKSIZE_W) { | |
441 WSCONS_blit16((Uint8 *)src, | |
442 srcRightDelta, | |
443 srcDownDelta, | |
444 (Uint8 *)dst, | |
445 dst_linebytes, | |
446 min(w, BLOCKSIZE_W), | |
447 min(height, BLOCKSIZE_H)); | |
448 src += srcRightDelta * BLOCKSIZE_W; | |
449 dst += BLOCKSIZE_W; | |
450 } | |
451 dst_pos = (Uint16 *)((Uint8 *)dst_pos + dst_linebytes * BLOCKSIZE_H); | |
452 src_pos += srcDownDelta * BLOCKSIZE_H; | |
453 height -= BLOCKSIZE_H; | |
454 } | |
455 } | |
456 | |
457 static void WSCONS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | |
458 { | |
459 int width = private->SDL_modelist[0]->w; | |
460 int height = private->SDL_modelist[0]->h; | |
461 int bytesPerPixel = (private->info.depth + 7) / 8; | |
462 int i; | |
463 | |
464 if (!private->shadowFB) { | |
465 return; | |
466 } | |
467 | |
468 if (private->info.depth != 16) { | |
469 WSCONS_ReportError("Shadow copy only implemented for 16 bpp"); | |
470 return; | |
471 } | |
472 | |
473 for (i = 0; i < numrects; i++) { | |
474 int x1, y1, x2, y2; | |
475 int scr_x1, scr_y1, scr_x2, scr_y2; | |
476 int sha_x1, sha_y1; | |
477 int shadowRightDelta; /* Address change when moving right in dest */ | |
478 int shadowDownDelta; /* Address change when moving down in dest */ | |
479 Uint8 *src_start; | |
480 Uint8 *dst_start; | |
481 | |
482 x1 = rects[i].x; | |
483 y1 = rects[i].y; | |
484 x2 = x1 + rects[i].w; | |
485 y2 = y1 + rects[i].h; | |
486 | |
487 if (x1 < 0) { | |
488 x1 = 0; | |
489 } else if (x1 > width) { | |
490 x1 = width; | |
491 } | |
492 if (x2 < 0) { | |
493 x2 = 0; | |
494 } else if (x2 > width) { | |
495 x2 = width; | |
496 } | |
497 if (y1 < 0) { | |
498 y1 = 0; | |
499 } else if (y1 > height) { | |
500 y1 = height; | |
501 } | |
502 if (y2 < 0) { | |
503 y2 = 0; | |
504 } else if (y2 > height) { | |
505 y2 = height; | |
506 } | |
507 if (x2 <= x1 || y2 <= y1) { | |
508 continue; | |
509 } | |
510 | |
511 switch (private->rotate) { | |
512 case WSCONS_ROTATE_NONE: | |
513 sha_x1 = scr_x1 = x1; | |
514 sha_y1 = scr_y1 = y1; | |
515 scr_x2 = x2; | |
516 scr_y2 = y2; | |
517 shadowRightDelta = 1; | |
518 shadowDownDelta = width; | |
519 break; | |
520 case WSCONS_ROTATE_CCW: | |
521 scr_x1 = y1; | |
522 scr_y1 = width - x2; | |
523 scr_x2 = y2; | |
524 scr_y2 = width - x1; | |
525 sha_x1 = x2 - 1; | |
526 sha_y1 = y1; | |
527 shadowRightDelta = width; | |
528 shadowDownDelta = -1; | |
529 break; | |
530 case WSCONS_ROTATE_UD: | |
531 scr_x1 = width - x2; | |
532 scr_y1 = height - y2; | |
533 scr_x2 = width - x1; | |
534 scr_y2 = height - y1; | |
535 sha_x1 = x2 - 1; | |
536 sha_y1 = y2 - 1; | |
537 shadowRightDelta = -1; | |
538 shadowDownDelta = -width; | |
539 break; | |
540 case WSCONS_ROTATE_CW: | |
541 scr_x1 = height - y2; | |
542 scr_y1 = x1; | |
543 scr_x2 = height - y1; | |
544 scr_y2 = x2; | |
545 sha_x1 = x1; | |
546 sha_y1 = y2 - 1; | |
547 shadowRightDelta = -width; | |
548 shadowDownDelta = 1; | |
549 break; | |
550 default: | |
551 WSCONS_ReportError("Unknown rotation"); | |
552 return; | |
553 } | |
554 | |
555 src_start = private->shadowmem + (sha_y1 * width + sha_x1) * bytesPerPixel; | |
556 dst_start = private->physmem + scr_y1 * private->physlinebytes + | |
557 scr_x1 * bytesPerPixel; | |
558 | |
559 private->blitFunc(src_start, | |
560 shadowRightDelta, | |
561 shadowDownDelta, | |
562 dst_start, | |
563 private->physlinebytes, | |
564 scr_x2 - scr_x1, | |
565 scr_y2 - scr_y1); | |
566 } | |
567 } | |
568 | |
569 int WSCONS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
570 { | |
571 return 0; | |
572 } | |
573 | |
574 /* | |
575 * Note: If we are terminated, this could be called in the middle of | |
576 * another SDL video routine -- notably UpdateRects. | |
577 */ | |
578 void WSCONS_VideoQuit(_THIS) | |
579 { | |
580 int mode = WSDISPLAYIO_MODE_EMUL; | |
581 | |
582 if (private->shadowmem != NULL) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
583 SDL_free(private->shadowmem); |
1187 | 584 private->shadowmem = NULL; |
585 } | |
586 private->fbstart = NULL; | |
587 if (this->screen != NULL) { | |
588 this->screen->pixels = NULL; | |
589 } | |
590 | |
591 if (private->SDL_modelist[0] != NULL) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
592 SDL_free(private->SDL_modelist[0]); |
1187 | 593 private->SDL_modelist[0] = NULL; |
594 } | |
595 | |
596 if (ioctl(private->fd, WSDISPLAYIO_SMODE, &mode) == -1) { | |
597 WSCONS_ReportError("ioctl SMODE"); | |
598 } | |
599 | |
600 WSCONS_ReleaseKeyboard(this); | |
601 | |
602 if (private->fd != -1) { | |
603 close(private->fd); | |
604 private->fd = -1; | |
605 } | |
606 } |