Annotation of /trunk/libsdl/patches/libsdl-1.2.8-libcaca.patch
Parent Directory | Revision Log
Revision 144 -
(hide annotations)
(download)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 19410 byte(s)
Tue May 8 20:06:05 2007 UTC (17 years, 4 months ago) by niro
File size: 19410 byte(s)
-import
1 | niro | 144 | --- SDL/configure.in |
2 | +++ SDL/configure.in | ||
3 | @@ -1004,6 +1004,32 @@ CheckAAlib() | ||
4 | fi | ||
5 | } | ||
6 | |||
7 | +dnl Find the libcaca includes | ||
8 | +CheckCaca() | ||
9 | +{ | ||
10 | + AC_ARG_ENABLE(video-caca, | ||
11 | +[ --enable-video-caca use libcaca video driver [default=no]], | ||
12 | + , enable_video_caca=no) | ||
13 | + if test x$enable_video = xyes -a x$enable_video_caca = xyes; then | ||
14 | + AC_MSG_CHECKING(for libcaca support) | ||
15 | + video_caca=no | ||
16 | + AC_TRY_COMPILE([ | ||
17 | + #include <caca.h> | ||
18 | + ],[ | ||
19 | + ],[ | ||
20 | + video_caca=yes | ||
21 | + ]) | ||
22 | + AC_MSG_RESULT($video_caca) | ||
23 | + if test x$video_caca = xyes; then | ||
24 | + CFLAGS="$CFLAGS -DENABLE_CACA `caca-config --cflags`" | ||
25 | + SYSTEM_LIBS="$SYSTEM_LIBS `caca-config --plugin-libs`" | ||
26 | + | ||
27 | + VIDEO_SUBDIRS="$VIDEO_SUBDIRS caca" | ||
28 | + VIDEO_DRIVERS="$VIDEO_DRIVERS caca/libvideo_caca.la" | ||
29 | + fi | ||
30 | + fi | ||
31 | +} | ||
32 | + | ||
33 | dnl Set up the Atari Xbios driver | ||
34 | CheckAtariXbiosVideo() | ||
35 | { | ||
36 | @@ -1882,6 +1908,7 @@ case "$target" in | ||
37 | CheckGGI | ||
38 | CheckSVGA | ||
39 | CheckAAlib | ||
40 | + CheckCaca | ||
41 | CheckQtopia | ||
42 | CheckPicoGUI | ||
43 | CheckOpenGL | ||
44 | @@ -1962,6 +1989,7 @@ case "$target" in | ||
45 | CheckDGA | ||
46 | CheckSVGA | ||
47 | CheckAAlib | ||
48 | + CheckCaca | ||
49 | CheckOpenGL | ||
50 | CheckPTHREAD | ||
51 | CheckSIGACTION | ||
52 | @@ -2007,6 +2035,7 @@ case "$target" in | ||
53 | CheckDGA | ||
54 | CheckSVGA | ||
55 | CheckAAlib | ||
56 | + CheckCaca | ||
57 | CheckOpenGL | ||
58 | CheckPTHREAD | ||
59 | CheckSIGACTION | ||
60 | @@ -2044,6 +2073,7 @@ case "$target" in | ||
61 | CheckNAS | ||
62 | CheckX11 | ||
63 | CheckAAlib | ||
64 | + CheckCaca | ||
65 | CheckOpenGL | ||
66 | CheckPTHREAD | ||
67 | CheckSIGACTION | ||
68 | @@ -2085,6 +2115,7 @@ case "$target" in | ||
69 | CheckNAS | ||
70 | CheckX11 | ||
71 | CheckAAlib | ||
72 | + CheckCaca | ||
73 | CheckOpenGL | ||
74 | CheckPTHREAD | ||
75 | CheckSIGACTION | ||
76 | @@ -2127,6 +2158,7 @@ case "$target" in | ||
77 | CheckNAS | ||
78 | CheckX11 | ||
79 | CheckAAlib | ||
80 | + CheckCaca | ||
81 | CheckOpenGL | ||
82 | CheckPTHREAD | ||
83 | CheckSIGACTION | ||
84 | @@ -2169,6 +2201,7 @@ case "$target" in | ||
85 | CheckNAS | ||
86 | CheckX11 | ||
87 | CheckAAlib | ||
88 | + CheckCaca | ||
89 | CheckOpenGL | ||
90 | CheckPTHREAD | ||
91 | CheckSIGACTION | ||
92 | @@ -2208,6 +2241,7 @@ case "$target" in | ||
93 | CheckNAS | ||
94 | CheckX11 | ||
95 | CheckAAlib | ||
96 | + CheckCaca | ||
97 | CheckOpenGL | ||
98 | CheckPTHREAD | ||
99 | CheckSIGACTION | ||
100 | @@ -2259,6 +2293,7 @@ case "$target" in | ||
101 | CheckX11 | ||
102 | CheckGGI | ||
103 | CheckAAlib | ||
104 | + CheckCaca | ||
105 | CheckOpenGL | ||
106 | CheckPTHREAD | ||
107 | CheckSIGACTION | ||
108 | @@ -2299,6 +2334,7 @@ case "$target" in | ||
109 | CheckX11 | ||
110 | CheckGGI | ||
111 | CheckAAlib | ||
112 | + CheckCaca | ||
113 | CheckOpenGL | ||
114 | CheckPTHREAD | ||
115 | CheckSIGACTION | ||
116 | @@ -2336,6 +2372,7 @@ case "$target" in | ||
117 | CheckX11 | ||
118 | CheckGGI | ||
119 | CheckAAlib | ||
120 | + CheckCaca | ||
121 | CheckOpenGL | ||
122 | CheckPTHREAD | ||
123 | CheckSIGACTION | ||
124 | @@ -2869,6 +2906,7 @@ src/video/Makefile | ||
125 | src/video/aalib/Makefile | ||
126 | src/video/ataricommon/Makefile | ||
127 | src/video/bwindow/Makefile | ||
128 | +src/video/caca/Makefile | ||
129 | src/video/cybergfx/Makefile | ||
130 | src/video/dc/Makefile | ||
131 | src/video/dga/Makefile | ||
132 | --- SDL/src/video/Makefile.am | ||
133 | +++ SDL/src/video/Makefile.am | ||
134 | @@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libvideo.la | ||
135 | |||
136 | # Define which subdirectories need to be built | ||
137 | SUBDIRS = @VIDEO_SUBDIRS@ | ||
138 | -DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \ | ||
139 | +DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib caca \ | ||
140 | wincommon windib windx5 \ | ||
141 | maccommon macdsp macrom riscos quartz \ | ||
142 | bwindow ps2gs photon cybergfx epoc picogui \ | ||
143 | --- SDL/src/video/SDL_sysvideo.h | ||
144 | +++ SDL/src/video/SDL_sysvideo.h | ||
145 | @@ -359,6 +359,9 @@ extern VideoBootStrap SVGALIB_bootstrap; | ||
146 | #ifdef ENABLE_AALIB | ||
147 | extern VideoBootStrap AALIB_bootstrap; | ||
148 | #endif | ||
149 | +#ifdef ENABLE_CACA | ||
150 | +extern VideoBootStrap Caca_bootstrap; | ||
151 | +#endif | ||
152 | #ifdef ENABLE_WINDIB | ||
153 | extern VideoBootStrap WINDIB_bootstrap; | ||
154 | #endif | ||
155 | --- SDL/src/video/SDL_video.c | ||
156 | +++ SDL/src/video/SDL_video.c | ||
157 | @@ -78,6 +78,9 @@ static VideoBootStrap *bootstrap[] = { | ||
158 | #ifdef ENABLE_AALIB | ||
159 | &AALIB_bootstrap, | ||
160 | #endif | ||
161 | +#ifdef ENABLE_CACA | ||
162 | + &Caca_bootstrap, | ||
163 | +#endif | ||
164 | #ifdef ENABLE_DIRECTX | ||
165 | &DIRECTX_bootstrap, | ||
166 | #endif | ||
167 | --- SDL/src/video/caca/Makefile.am | ||
168 | +++ SDL/src/video/caca/Makefile.am | ||
169 | @@ -0,0 +1,13 @@ | ||
170 | + | ||
171 | +## Makefile.am for SDL using the libcaca video driver | ||
172 | + | ||
173 | +noinst_LTLIBRARIES = libvideo_caca.la | ||
174 | +libvideo_caca_la_SOURCES = $(CACA_SRCS) | ||
175 | + | ||
176 | +# The SDL libcaca video driver sources | ||
177 | +CACA_SRCS = \ | ||
178 | + SDL_cacavideo.h \ | ||
179 | + SDL_cacaevents.c \ | ||
180 | + SDL_cacaevents_c.h \ | ||
181 | + SDL_cacavideo.c | ||
182 | + | ||
183 | --- SDL/src/video/caca/SDL_cacaevents.c | ||
184 | +++ SDL/src/video/caca/SDL_cacaevents.c | ||
185 | @@ -0,0 +1,98 @@ | ||
186 | +/* | ||
187 | + SDL - Simple DirectMedia Layer | ||
188 | + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga | ||
189 | + | ||
190 | + This library is free software; you can redistribute it and/or | ||
191 | + modify it under the terms of the GNU Library General Public | ||
192 | + License as published by the Free Software Foundation; either | ||
193 | + version 2 of the License, or (at your option) any later version. | ||
194 | + | ||
195 | + This library is distributed in the hope that it will be useful, | ||
196 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
197 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
198 | + Library General Public License for more details. | ||
199 | + | ||
200 | + You should have received a copy of the GNU Library General Public | ||
201 | + License along with this library; if not, write to the Free | ||
202 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
203 | + | ||
204 | + Sam Lantinga | ||
205 | + slouken@libsdl.org | ||
206 | +*/ | ||
207 | + | ||
208 | +#ifdef SAVE_RCSID | ||
209 | +static char rcsid = | ||
210 | + "@(#) $Id: libsdl-1.2.8-libcaca.patch,v 1.1 2007-05-08 19:57:41 niro Exp $"; | ||
211 | +#endif | ||
212 | + | ||
213 | +#include <stdio.h> | ||
214 | + | ||
215 | +#include <caca.h> | ||
216 | + | ||
217 | +#include "SDL.h" | ||
218 | +#include "SDL_sysevents.h" | ||
219 | +#include "SDL_events_c.h" | ||
220 | +#include "SDL_cacavideo.h" | ||
221 | +#include "SDL_cacaevents_c.h" | ||
222 | + | ||
223 | +void Caca_PumpEvents(_THIS) | ||
224 | +{ | ||
225 | + int posted = 0; | ||
226 | + int event; | ||
227 | + SDL_keysym keysym; | ||
228 | + | ||
229 | + if( ! this->screen ) /* Wait till we got the screen initialised */ | ||
230 | + return; | ||
231 | + | ||
232 | + do { | ||
233 | + posted = 0; | ||
234 | + | ||
235 | + /* Get libcaca event */ | ||
236 | + SDL_mutexP(Caca_mutex); | ||
237 | + event = caca_get_event(CACA_EVENT_ANY); | ||
238 | + SDL_mutexV(Caca_mutex); | ||
239 | + | ||
240 | + if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) { | ||
241 | + int key; | ||
242 | + switch ( event & 0xffffff ) | ||
243 | + { | ||
244 | + case CACA_KEY_LEFT: key = SDLK_LEFT; break; | ||
245 | + case CACA_KEY_RIGHT: key = SDLK_RIGHT; break; | ||
246 | + case CACA_KEY_UP: key = SDLK_UP; break; | ||
247 | + case CACA_KEY_DOWN: key = SDLK_DOWN; break; | ||
248 | + default: key = event & 0xff; break; | ||
249 | + } | ||
250 | + /* Key pressed */ | ||
251 | +/* printf("Key pressed: %d (%c)\n", key, key); */ | ||
252 | + keysym.scancode = key; | ||
253 | + keysym.sym = key; | ||
254 | + keysym.mod = KMOD_NONE; | ||
255 | + keysym.unicode = 0; | ||
256 | + if ( SDL_TranslateUNICODE ) { | ||
257 | + keysym.unicode = key; | ||
258 | + } | ||
259 | + posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym); | ||
260 | + } | ||
261 | + else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) { | ||
262 | + /* FIXME: we currently ignore the button type! */ | ||
263 | + int button = event & 0x00ffffff; | ||
264 | + if ( button > 3 ) { | ||
265 | + button = 1; | ||
266 | + } | ||
267 | + posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0); | ||
268 | + } | ||
269 | + else if ( event & CACA_EVENT_MOUSE_MOTION ) { | ||
270 | + int new_x = 0, new_y = 0; | ||
271 | + new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width(); | ||
272 | + new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height(); | ||
273 | + posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y); | ||
274 | + } | ||
275 | + } while ( posted ); | ||
276 | +} | ||
277 | + | ||
278 | +void Caca_InitOSKeymap(_THIS) | ||
279 | +{ | ||
280 | + return; | ||
281 | +} | ||
282 | + | ||
283 | + | ||
284 | --- SDL/src/video/caca/SDL_cacaevents_c.h | ||
285 | +++ SDL/src/video/caca/SDL_cacaevents_c.h | ||
286 | @@ -0,0 +1,35 @@ | ||
287 | +/* | ||
288 | + SDL - Simple DirectMedia Layer | ||
289 | + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga | ||
290 | + | ||
291 | + This library is free software; you can redistribute it and/or | ||
292 | + modify it under the terms of the GNU Library General Public | ||
293 | + License as published by the Free Software Foundation; either | ||
294 | + version 2 of the License, or (at your option) any later version. | ||
295 | + | ||
296 | + This library is distributed in the hope that it will be useful, | ||
297 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
298 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
299 | + Library General Public License for more details. | ||
300 | + | ||
301 | + You should have received a copy of the GNU Library General Public | ||
302 | + License along with this library; if not, write to the Free | ||
303 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
304 | + | ||
305 | + Sam Lantinga | ||
306 | + slouken@libsdl.org | ||
307 | +*/ | ||
308 | + | ||
309 | +#ifdef SAVE_RCSID | ||
310 | +static char rcsid = | ||
311 | + "@(#) $Id: libsdl-1.2.8-libcaca.patch,v 1.1 2007-05-08 19:57:41 niro Exp $"; | ||
312 | +#endif | ||
313 | + | ||
314 | +#include "SDL_cacavideo.h" | ||
315 | + | ||
316 | +/* Variables and functions exported by SDL_sysevents.c to other parts. | ||
317 | + of the native video subsystem (SDL_sysvideo.c) | ||
318 | +*/ | ||
319 | +extern void Caca_PumpEvents(_THIS); | ||
320 | +extern void Caca_InitOSKeymap(_THIS); | ||
321 | + | ||
322 | --- SDL/src/video/caca/SDL_cacavideo.c | ||
323 | +++ SDL/src/video/caca/SDL_cacavideo.c | ||
324 | @@ -0,0 +1,301 @@ | ||
325 | +/* | ||
326 | + SDL - Simple DirectMedia Layer | ||
327 | + Copyright (C) 2003 Sam Hocevar | ||
328 | + | ||
329 | + This library is free software; you can redistribute it and/or | ||
330 | + modify it under the terms of the GNU Library General Public | ||
331 | + License as published by the Free Software Foundation; either | ||
332 | + version 2 of the License, or (at your option) any later version. | ||
333 | + | ||
334 | + This library is distributed in the hope that it will be useful, | ||
335 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
336 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
337 | + Library General Public License for more details. | ||
338 | + | ||
339 | + You should have received a copy of the GNU Library General Public | ||
340 | + License along with this library; if not, write to the Free | ||
341 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
342 | + | ||
343 | + Sam Hocevar | ||
344 | + sam@zoy.org | ||
345 | +*/ | ||
346 | + | ||
347 | +#ifdef SAVE_RCSID | ||
348 | +static char rcsid = | ||
349 | + "@(#) $Id: libsdl-1.2.8-libcaca.patch,v 1.1 2007-05-08 19:57:41 niro Exp $"; | ||
350 | +#endif | ||
351 | + | ||
352 | +/* libcaca based SDL video driver implementation. | ||
353 | +*/ | ||
354 | + | ||
355 | +#include <stdlib.h> | ||
356 | +#include <stdio.h> | ||
357 | +#include <string.h> | ||
358 | +#include <unistd.h> | ||
359 | +#include <sys/stat.h> | ||
360 | + | ||
361 | + | ||
362 | +#include "SDL.h" | ||
363 | +#include "SDL_error.h" | ||
364 | +#include "SDL_video.h" | ||
365 | +#include "SDL_mouse.h" | ||
366 | +#include "SDL_sysvideo.h" | ||
367 | +#include "SDL_pixels_c.h" | ||
368 | +#include "SDL_events_c.h" | ||
369 | + | ||
370 | +#include "SDL_cacavideo.h" | ||
371 | +#include "SDL_cacaevents_c.h" | ||
372 | + | ||
373 | +#include <caca.h> | ||
374 | + | ||
375 | +/* Initialization/Query functions */ | ||
376 | +static int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat); | ||
377 | +static SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | ||
378 | +static SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | ||
379 | +static void Caca_VideoQuit(_THIS); | ||
380 | + | ||
381 | +/* Hardware surface functions */ | ||
382 | +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface); | ||
383 | +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface); | ||
384 | +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface); | ||
385 | +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface); | ||
386 | +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface); | ||
387 | + | ||
388 | +/* Cache the VideoDevice struct */ | ||
389 | +static struct SDL_VideoDevice *local_this; | ||
390 | + | ||
391 | +/* libcaca driver bootstrap functions */ | ||
392 | + | ||
393 | +static int Caca_Available(void) | ||
394 | +{ | ||
395 | + return 1; /* Always available ! */ | ||
396 | +} | ||
397 | + | ||
398 | +static void Caca_DeleteDevice(SDL_VideoDevice *device) | ||
399 | +{ | ||
400 | + free(device->hidden); | ||
401 | + free(device); | ||
402 | +} | ||
403 | +static SDL_VideoDevice *Caca_CreateDevice(int devindex) | ||
404 | +{ | ||
405 | + SDL_VideoDevice *device; | ||
406 | + | ||
407 | + /* Initialize all variables that we clean on shutdown */ | ||
408 | + device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | ||
409 | + if ( device ) { | ||
410 | + memset(device, 0, (sizeof *device)); | ||
411 | + device->hidden = (struct SDL_PrivateVideoData *) | ||
412 | + malloc((sizeof *device->hidden)); | ||
413 | + } | ||
414 | + if ( (device == NULL) || (device->hidden == NULL) ) { | ||
415 | + SDL_OutOfMemory(); | ||
416 | + if ( device ) { | ||
417 | + free(device); | ||
418 | + } | ||
419 | + return(0); | ||
420 | + } | ||
421 | + memset(device->hidden, 0, (sizeof *device->hidden)); | ||
422 | + | ||
423 | + /* Set the function pointers */ | ||
424 | + device->VideoInit = Caca_VideoInit; | ||
425 | + device->ListModes = Caca_ListModes; | ||
426 | + device->SetVideoMode = Caca_SetVideoMode; | ||
427 | + device->CreateYUVOverlay = NULL; | ||
428 | + device->SetColors = NULL; | ||
429 | + device->UpdateRects = NULL; | ||
430 | + device->VideoQuit = Caca_VideoQuit; | ||
431 | + device->AllocHWSurface = Caca_AllocHWSurface; | ||
432 | + device->CheckHWBlit = NULL; | ||
433 | + device->FillHWRect = NULL; | ||
434 | + device->SetHWColorKey = NULL; | ||
435 | + device->SetHWAlpha = NULL; | ||
436 | + device->LockHWSurface = Caca_LockHWSurface; | ||
437 | + device->UnlockHWSurface = Caca_UnlockHWSurface; | ||
438 | + device->FlipHWSurface = NULL; | ||
439 | + device->FreeHWSurface = Caca_FreeHWSurface; | ||
440 | + device->SetCaption = NULL; | ||
441 | + device->SetIcon = NULL; | ||
442 | + device->IconifyWindow = NULL; | ||
443 | + device->GrabInput = NULL; | ||
444 | + device->GetWMInfo = NULL; | ||
445 | + device->InitOSKeymap = Caca_InitOSKeymap; | ||
446 | + device->PumpEvents = Caca_PumpEvents; | ||
447 | + | ||
448 | + device->free = Caca_DeleteDevice; | ||
449 | + | ||
450 | + return device; | ||
451 | +} | ||
452 | + | ||
453 | +VideoBootStrap Caca_bootstrap = { | ||
454 | + "caca", "Color ASCII Art Library", | ||
455 | + Caca_Available, Caca_CreateDevice | ||
456 | +}; | ||
457 | + | ||
458 | +int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat) | ||
459 | +{ | ||
460 | + int i; | ||
461 | + | ||
462 | + /* Initialize all variables that we clean on shutdown */ | ||
463 | + for ( i=0; i<SDL_NUMMODES; ++i ) { | ||
464 | + SDL_modelist[i] = malloc(sizeof(SDL_Rect)); | ||
465 | + SDL_modelist[i]->x = SDL_modelist[i]->y = 0; | ||
466 | + } | ||
467 | + /* Modes sorted largest to smallest */ | ||
468 | + SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768; | ||
469 | + SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600; | ||
470 | + SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480; | ||
471 | + SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400; | ||
472 | + SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240; | ||
473 | + SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200; | ||
474 | + SDL_modelist[6] = NULL; | ||
475 | + | ||
476 | + Caca_mutex = SDL_CreateMutex(); | ||
477 | + | ||
478 | + /* Initialize the library */ | ||
479 | + if ( caca_init() != 0 ) { | ||
480 | + SDL_SetError("Unable to initialize libcaca"); | ||
481 | + return(-1); | ||
482 | + } | ||
483 | + | ||
484 | + /* Initialize private variables */ | ||
485 | + Caca_lastkey = 0; | ||
486 | + Caca_bitmap = NULL; | ||
487 | + Caca_buffer = NULL; | ||
488 | + | ||
489 | + local_this = this; | ||
490 | + | ||
491 | + /* Determine the screen depth (use default 8-bit depth) */ | ||
492 | + vformat->BitsPerPixel = 8; | ||
493 | + vformat->BytesPerPixel = 1; | ||
494 | + | ||
495 | + /* We're done! */ | ||
496 | + return(0); | ||
497 | +} | ||
498 | + | ||
499 | +SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | ||
500 | +{ | ||
501 | + if(format->BitsPerPixel != 8) | ||
502 | + return NULL; | ||
503 | + | ||
504 | + if ( flags & SDL_FULLSCREEN ) { | ||
505 | + return SDL_modelist; | ||
506 | + } else { | ||
507 | + return (SDL_Rect **) -1; | ||
508 | + } | ||
509 | +} | ||
510 | + | ||
511 | +/* Various screen update functions available */ | ||
512 | +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | ||
513 | + | ||
514 | +SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, | ||
515 | + int width, int height, int bpp, Uint32 flags) | ||
516 | +{ | ||
517 | + if ( Caca_buffer ) { | ||
518 | + free( Caca_buffer ); | ||
519 | + Caca_buffer = NULL; | ||
520 | + } | ||
521 | + | ||
522 | + if ( Caca_bitmap ) { | ||
523 | + caca_free_bitmap( Caca_bitmap ); | ||
524 | + Caca_bitmap = NULL; | ||
525 | + } | ||
526 | + | ||
527 | + Caca_buffer = malloc(2 * ((width + 15) & ~15) * height); | ||
528 | + if ( ! Caca_buffer ) { | ||
529 | + SDL_SetError("Couldn't allocate buffer for requested mode"); | ||
530 | + return(NULL); | ||
531 | + } | ||
532 | + | ||
533 | + memset(Caca_buffer, 0, 2 * ((width + 15) & ~15) * height); | ||
534 | + | ||
535 | + /* Allocate the new pixel format for the screen */ | ||
536 | + if ( ! SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0) ) { | ||
537 | + return(NULL); | ||
538 | + } | ||
539 | + | ||
540 | + /* Set up the new mode framebuffer */ | ||
541 | + current->flags = SDL_FULLSCREEN; | ||
542 | + Caca_w = current->w = width; | ||
543 | + Caca_h = current->h = height; | ||
544 | + current->pitch = 2 * ((width + 15) & ~15); | ||
545 | + current->pixels = Caca_buffer; | ||
546 | + | ||
547 | + /* Create the libcaca bitmap */ | ||
548 | + Caca_bitmap = caca_create_bitmap( 16, width, height, current->pitch, 0xf800, 0x07e0, 0x001f, 0x0000 ); | ||
549 | + if ( ! Caca_bitmap ) { | ||
550 | + SDL_SetError("Couldn't allocate libcaca bitmap"); | ||
551 | + return(NULL); | ||
552 | + } | ||
553 | + | ||
554 | + /* Set the blit function */ | ||
555 | + this->UpdateRects = Caca_DirectUpdate; | ||
556 | + | ||
557 | + /* We're done */ | ||
558 | + return(current); | ||
559 | +} | ||
560 | + | ||
561 | +/* We don't actually allow hardware surfaces other than the main one */ | ||
562 | +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface) | ||
563 | +{ | ||
564 | + return(-1); | ||
565 | +} | ||
566 | +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface) | ||
567 | +{ | ||
568 | + return; | ||
569 | +} | ||
570 | + | ||
571 | +/* We need to wait for vertical retrace on page flipped displays */ | ||
572 | +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface) | ||
573 | +{ | ||
574 | + /* TODO ? */ | ||
575 | + return(0); | ||
576 | +} | ||
577 | +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface) | ||
578 | +{ | ||
579 | + return; | ||
580 | +} | ||
581 | + | ||
582 | +/* FIXME: How is this done with libcaca? */ | ||
583 | +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface) | ||
584 | +{ | ||
585 | + SDL_mutexP(Caca_mutex); | ||
586 | + caca_refresh(); | ||
587 | + SDL_mutexV(Caca_mutex); | ||
588 | + return(0); | ||
589 | +} | ||
590 | + | ||
591 | +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | ||
592 | +{ | ||
593 | + SDL_mutexP(Caca_mutex); | ||
594 | + caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1, | ||
595 | + Caca_bitmap, Caca_buffer ); | ||
596 | + caca_refresh(); | ||
597 | + SDL_mutexV(Caca_mutex); | ||
598 | + return; | ||
599 | +} | ||
600 | + | ||
601 | +/* Note: If we are terminated, this could be called in the middle of | ||
602 | + another SDL video routine -- notably UpdateRects. | ||
603 | +*/ | ||
604 | +void Caca_VideoQuit(_THIS) | ||
605 | +{ | ||
606 | + int i; | ||
607 | + | ||
608 | + /* Free video mode lists */ | ||
609 | + for ( i=0; i<SDL_NUMMODES; ++i ) { | ||
610 | + if ( SDL_modelist[i] != NULL ) { | ||
611 | + free(SDL_modelist[i]); | ||
612 | + SDL_modelist[i] = NULL; | ||
613 | + } | ||
614 | + } | ||
615 | + | ||
616 | + if ( Caca_bitmap ) { | ||
617 | + caca_free_bitmap( Caca_bitmap ); | ||
618 | + Caca_bitmap = NULL; | ||
619 | + } | ||
620 | + | ||
621 | + caca_end(); | ||
622 | + | ||
623 | + SDL_DestroyMutex(Caca_mutex); | ||
624 | +} | ||
625 | + | ||
626 | --- SDL/src/video/caca/SDL_cacavideo.h | ||
627 | +++ SDL/src/video/caca/SDL_cacavideo.h | ||
628 | @@ -0,0 +1,73 @@ | ||
629 | +/* | ||
630 | + SDL - Simple DirectMedia Layer | ||
631 | + Copyright (C) 2003 Sam Hocevar | ||
632 | + | ||
633 | + This library is free software; you can redistribute it and/or | ||
634 | + modify it under the terms of the GNU Library General Public | ||
635 | + License as published by the Free Software Foundation; either | ||
636 | + version 2 of the License, or (at your option) any later version. | ||
637 | + | ||
638 | + This library is distributed in the hope that it will be useful, | ||
639 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
640 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
641 | + Library General Public License for more details. | ||
642 | + | ||
643 | + You should have received a copy of the GNU Library General Public | ||
644 | + License along with this library; if not, write to the Free | ||
645 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
646 | + | ||
647 | + Sam Hocevar | ||
648 | + sam@zoy.org | ||
649 | +*/ | ||
650 | + | ||
651 | +#ifdef SAVE_RCSID | ||
652 | +static char rcsid = | ||
653 | + "@(#) $Id: libsdl-1.2.8-libcaca.patch,v 1.1 2007-05-08 19:57:41 niro Exp $"; | ||
654 | +#endif | ||
655 | + | ||
656 | +#ifndef _SDL_cacavideo_h | ||
657 | +#define _SDL_cacavideo_h | ||
658 | + | ||
659 | +#include "SDL_mouse.h" | ||
660 | +#include "SDL_sysvideo.h" | ||
661 | +#include "SDL_mutex.h" | ||
662 | + | ||
663 | +#include <sys/time.h> | ||
664 | +#include <time.h> | ||
665 | + | ||
666 | +#include <caca.h> | ||
667 | + | ||
668 | +/* Hidden "this" pointer for the video functions */ | ||
669 | +#define _THIS SDL_VideoDevice *this | ||
670 | + | ||
671 | +#define SDL_NUMMODES 6 | ||
672 | + | ||
673 | +/* Private display data */ | ||
674 | +struct SDL_PrivateVideoData { | ||
675 | + SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; | ||
676 | + SDL_mutex *mutex; | ||
677 | + | ||
678 | + struct caca_bitmap *bitmap; | ||
679 | + void *buffer; | ||
680 | + int w, h; | ||
681 | + | ||
682 | + int lastkey; | ||
683 | + struct timeval lasttime; | ||
684 | +}; | ||
685 | + | ||
686 | +/* Old variable names */ | ||
687 | +#define SDL_modelist (this->hidden->SDL_modelist) | ||
688 | +#define Caca_palette (this->hidden->palette) | ||
689 | +#define Caca_bitmap (this->hidden->bitmap) | ||
690 | +#define Caca_buffer (this->hidden->buffer) | ||
691 | + | ||
692 | +#define Caca_w (this->hidden->w) | ||
693 | +#define Caca_h (this->hidden->h) | ||
694 | + | ||
695 | +#define Caca_lastkey (this->hidden->lastkey) | ||
696 | +#define Caca_lasttime (this->hidden->lasttime) | ||
697 | + | ||
698 | +#define Caca_mutex (this->hidden->mutex) | ||
699 | + | ||
700 | +#endif /* _SDL_cacavideo_h */ | ||
701 | + |