1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/video/caca/SDL_cacaevents.c Sat Oct 10 10:17:51 2009 +0000
1.3 @@ -0,0 +1,101 @@
1.4 +/*
1.5 + SDL - Simple DirectMedia Layer
1.6 + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
1.7 +
1.8 + This library is free software; you can redistribute it and/or
1.9 + modify it under the terms of the GNU Library General Public
1.10 + License as published by the Free Software Foundation; either
1.11 + version 2 of the License, or (at your option) any later version.
1.12 +
1.13 + This library is distributed in the hope that it will be useful,
1.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.16 + Library General Public License for more details.
1.17 +
1.18 + You should have received a copy of the GNU Library General Public
1.19 + License along with this library; if not, write to the Free
1.20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.21 +
1.22 + Sam Lantinga
1.23 + slouken@libsdl.org
1.24 +*/
1.25 +
1.26 +#ifdef SAVE_RCSID
1.27 +static char rcsid =
1.28 + "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
1.29 +#endif
1.30 +
1.31 +#include <stdio.h>
1.32 +
1.33 +#include <caca.h>
1.34 +#ifdef CACA_API_VERSION_1
1.35 +#include <caca0.h>
1.36 +#endif
1.37 +
1.38 +#include "SDL.h"
1.39 +#include "../../events/SDL_sysevents.h"
1.40 +#include "../../events/SDL_events_c.h"
1.41 +#include "SDL_cacavideo.h"
1.42 +#include "SDL_cacaevents_c.h"
1.43 +
1.44 +void Caca_PumpEvents(_THIS)
1.45 +{
1.46 + int posted = 0;
1.47 + int event;
1.48 + SDL_keysym keysym;
1.49 +
1.50 + if( ! this->screen ) /* Wait till we got the screen initialised */
1.51 + return;
1.52 +
1.53 + do {
1.54 + posted = 0;
1.55 +
1.56 + /* Get libcaca event */
1.57 + SDL_mutexP(Caca_mutex);
1.58 + event = caca_get_event(CACA_EVENT_ANY);
1.59 + SDL_mutexV(Caca_mutex);
1.60 +
1.61 + if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) {
1.62 + int key;
1.63 + switch ( event & 0xffffff )
1.64 + {
1.65 + case CACA_KEY_LEFT: key = SDLK_LEFT; break;
1.66 + case CACA_KEY_RIGHT: key = SDLK_RIGHT; break;
1.67 + case CACA_KEY_UP: key = SDLK_UP; break;
1.68 + case CACA_KEY_DOWN: key = SDLK_DOWN; break;
1.69 + default: key = event & 0xff; break;
1.70 + }
1.71 + /* Key pressed */
1.72 +/* printf("Key pressed: %d (%c)\n", key, key); */
1.73 + keysym.scancode = key;
1.74 + keysym.sym = key;
1.75 + keysym.mod = KMOD_NONE;
1.76 + keysym.unicode = 0;
1.77 + if ( SDL_TranslateUNICODE ) {
1.78 + keysym.unicode = key;
1.79 + }
1.80 + posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym);
1.81 + }
1.82 + else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) {
1.83 + /* FIXME: we currently ignore the button type! */
1.84 + int button = event & 0x00ffffff;
1.85 + if ( button > 3 ) {
1.86 + button = 1;
1.87 + }
1.88 + posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0);
1.89 + }
1.90 + else if ( event & CACA_EVENT_MOUSE_MOTION ) {
1.91 + int new_x = 0, new_y = 0;
1.92 + new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width();
1.93 + new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height();
1.94 + posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y);
1.95 + }
1.96 + } while ( posted );
1.97 +}
1.98 +
1.99 +void Caca_InitOSKeymap(_THIS)
1.100 +{
1.101 + return;
1.102 +}
1.103 +
1.104 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/video/caca/SDL_cacaevents_c.h Sat Oct 10 10:17:51 2009 +0000
2.3 @@ -0,0 +1,35 @@
2.4 +/*
2.5 + SDL - Simple DirectMedia Layer
2.6 + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
2.7 +
2.8 + This library is free software; you can redistribute it and/or
2.9 + modify it under the terms of the GNU Library General Public
2.10 + License as published by the Free Software Foundation; either
2.11 + version 2 of the License, or (at your option) any later version.
2.12 +
2.13 + This library is distributed in the hope that it will be useful,
2.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2.16 + Library General Public License for more details.
2.17 +
2.18 + You should have received a copy of the GNU Library General Public
2.19 + License along with this library; if not, write to the Free
2.20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.21 +
2.22 + Sam Lantinga
2.23 + slouken@libsdl.org
2.24 +*/
2.25 +
2.26 +#ifdef SAVE_RCSID
2.27 +static char rcsid =
2.28 + "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
2.29 +#endif
2.30 +
2.31 +#include "SDL_cacavideo.h"
2.32 +
2.33 +/* Variables and functions exported by SDL_sysevents.c to other parts.
2.34 + of the native video subsystem (SDL_sysvideo.c)
2.35 +*/
2.36 +extern void Caca_PumpEvents(_THIS);
2.37 +extern void Caca_InitOSKeymap(_THIS);
2.38 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/video/caca/SDL_cacavideo.c Sat Oct 10 10:17:51 2009 +0000
3.3 @@ -0,0 +1,304 @@
3.4 +/*
3.5 + SDL - Simple DirectMedia Layer
3.6 + Copyright (C) 2003 Sam Hocevar
3.7 +
3.8 + This library is free software; you can redistribute it and/or
3.9 + modify it under the terms of the GNU Library General Public
3.10 + License as published by the Free Software Foundation; either
3.11 + version 2 of the License, or (at your option) any later version.
3.12 +
3.13 + This library is distributed in the hope that it will be useful,
3.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3.16 + Library General Public License for more details.
3.17 +
3.18 + You should have received a copy of the GNU Library General Public
3.19 + License along with this library; if not, write to the Free
3.20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3.21 +
3.22 + Sam Hocevar
3.23 + sam@zoy.org
3.24 +*/
3.25 +
3.26 +#ifdef SAVE_RCSID
3.27 +static char rcsid =
3.28 + "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
3.29 +#endif
3.30 +
3.31 +/* libcaca based SDL video driver implementation.
3.32 +*/
3.33 +
3.34 +#include <stdlib.h>
3.35 +#include <stdio.h>
3.36 +#include <string.h>
3.37 +#include <unistd.h>
3.38 +#include <sys/stat.h>
3.39 +
3.40 +
3.41 +#include "SDL.h"
3.42 +#include "SDL_error.h"
3.43 +#include "SDL_video.h"
3.44 +#include "SDL_mouse.h"
3.45 +#include "../SDL_sysvideo.h"
3.46 +#include "../SDL_pixels_c.h"
3.47 +#include "../../events/SDL_events_c.h"
3.48 +
3.49 +#include "SDL_cacavideo.h"
3.50 +#include "SDL_cacaevents_c.h"
3.51 +
3.52 +#include <caca.h>
3.53 +#ifdef CACA_API_VERSION_1
3.54 +#include <caca0.h>
3.55 +#endif
3.56 +
3.57 +/* Initialization/Query functions */
3.58 +static int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat);
3.59 +static SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
3.60 +static SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
3.61 +static void Caca_VideoQuit(_THIS);
3.62 +
3.63 +/* Hardware surface functions */
3.64 +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface);
3.65 +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface);
3.66 +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface);
3.67 +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface);
3.68 +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface);
3.69 +
3.70 +/* Cache the VideoDevice struct */
3.71 +static struct SDL_VideoDevice *local_this;
3.72 +
3.73 +/* libcaca driver bootstrap functions */
3.74 +
3.75 +static int Caca_Available(void)
3.76 +{
3.77 + return 1; /* Always available ! */
3.78 +}
3.79 +
3.80 +static void Caca_DeleteDevice(SDL_VideoDevice *device)
3.81 +{
3.82 + free(device->hidden);
3.83 + free(device);
3.84 +}
3.85 +static SDL_VideoDevice *Caca_CreateDevice(int devindex)
3.86 +{
3.87 + SDL_VideoDevice *device;
3.88 +
3.89 + /* Initialize all variables that we clean on shutdown */
3.90 + device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
3.91 + if ( device ) {
3.92 + memset(device, 0, (sizeof *device));
3.93 + device->hidden = (struct SDL_PrivateVideoData *)
3.94 + malloc((sizeof *device->hidden));
3.95 + }
3.96 + if ( (device == NULL) || (device->hidden == NULL) ) {
3.97 + SDL_OutOfMemory();
3.98 + if ( device ) {
3.99 + free(device);
3.100 + }
3.101 + return(0);
3.102 + }
3.103 + memset(device->hidden, 0, (sizeof *device->hidden));
3.104 +
3.105 + /* Set the function pointers */
3.106 + device->VideoInit = Caca_VideoInit;
3.107 + device->ListModes = Caca_ListModes;
3.108 + device->SetVideoMode = Caca_SetVideoMode;
3.109 + device->CreateYUVOverlay = NULL;
3.110 + device->SetColors = NULL;
3.111 + device->UpdateRects = NULL;
3.112 + device->VideoQuit = Caca_VideoQuit;
3.113 + device->AllocHWSurface = Caca_AllocHWSurface;
3.114 + device->CheckHWBlit = NULL;
3.115 + device->FillHWRect = NULL;
3.116 + device->SetHWColorKey = NULL;
3.117 + device->SetHWAlpha = NULL;
3.118 + device->LockHWSurface = Caca_LockHWSurface;
3.119 + device->UnlockHWSurface = Caca_UnlockHWSurface;
3.120 + device->FlipHWSurface = NULL;
3.121 + device->FreeHWSurface = Caca_FreeHWSurface;
3.122 + device->SetCaption = NULL;
3.123 + device->SetIcon = NULL;
3.124 + device->IconifyWindow = NULL;
3.125 + device->GrabInput = NULL;
3.126 + device->GetWMInfo = NULL;
3.127 + device->InitOSKeymap = Caca_InitOSKeymap;
3.128 + device->PumpEvents = Caca_PumpEvents;
3.129 +
3.130 + device->free = Caca_DeleteDevice;
3.131 +
3.132 + return device;
3.133 +}
3.134 +
3.135 +VideoBootStrap CACA_bootstrap = {
3.136 + "caca", "Color ASCII Art Library",
3.137 + Caca_Available, Caca_CreateDevice
3.138 +};
3.139 +
3.140 +int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat)
3.141 +{
3.142 + int i;
3.143 +
3.144 + /* Initialize all variables that we clean on shutdown */
3.145 + for ( i=0; i<SDL_NUMMODES; ++i ) {
3.146 + SDL_modelist[i] = malloc(sizeof(SDL_Rect));
3.147 + SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
3.148 + }
3.149 + /* Modes sorted largest to smallest */
3.150 + SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
3.151 + SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
3.152 + SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
3.153 + SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
3.154 + SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
3.155 + SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
3.156 + SDL_modelist[6] = NULL;
3.157 +
3.158 + Caca_mutex = SDL_CreateMutex();
3.159 +
3.160 + /* Initialize the library */
3.161 + if ( caca_init() != 0 ) {
3.162 + SDL_SetError("Unable to initialize libcaca");
3.163 + return(-1);
3.164 + }
3.165 +
3.166 + /* Initialize private variables */
3.167 + Caca_lastkey = 0;
3.168 + Caca_bitmap = NULL;
3.169 + Caca_buffer = NULL;
3.170 +
3.171 + local_this = this;
3.172 +
3.173 + /* Determine the screen depth (use default 8-bit depth) */
3.174 + vformat->BitsPerPixel = 8;
3.175 + vformat->BytesPerPixel = 1;
3.176 +
3.177 + /* We're done! */
3.178 + return(0);
3.179 +}
3.180 +
3.181 +SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
3.182 +{
3.183 + if(format->BitsPerPixel != 8)
3.184 + return NULL;
3.185 +
3.186 + if ( flags & SDL_FULLSCREEN ) {
3.187 + return SDL_modelist;
3.188 + } else {
3.189 + return (SDL_Rect **) -1;
3.190 + }
3.191 +}
3.192 +
3.193 +/* Various screen update functions available */
3.194 +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
3.195 +
3.196 +SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current,
3.197 + int width, int height, int bpp, Uint32 flags)
3.198 +{
3.199 + if ( Caca_buffer ) {
3.200 + free( Caca_buffer );
3.201 + Caca_buffer = NULL;
3.202 + }
3.203 +
3.204 + if ( Caca_bitmap ) {
3.205 + caca_free_bitmap( Caca_bitmap );
3.206 + Caca_bitmap = NULL;
3.207 + }
3.208 +
3.209 + Caca_buffer = malloc(2 * ((width + 15) & ~15) * height);
3.210 + if ( ! Caca_buffer ) {
3.211 + SDL_SetError("Couldn't allocate buffer for requested mode");
3.212 + return(NULL);
3.213 + }
3.214 +
3.215 + memset(Caca_buffer, 0, 2 * ((width + 15) & ~15) * height);
3.216 +
3.217 + /* Allocate the new pixel format for the screen */
3.218 + if ( ! SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0) ) {
3.219 + return(NULL);
3.220 + }
3.221 +
3.222 + /* Set up the new mode framebuffer */
3.223 + current->flags = SDL_FULLSCREEN;
3.224 + Caca_w = current->w = width;
3.225 + Caca_h = current->h = height;
3.226 + current->pitch = 2 * ((width + 15) & ~15);
3.227 + current->pixels = Caca_buffer;
3.228 +
3.229 + /* Create the libcaca bitmap */
3.230 + Caca_bitmap = caca_create_bitmap( 16, width, height, current->pitch, 0xf800, 0x07e0, 0x001f, 0x0000 );
3.231 + if ( ! Caca_bitmap ) {
3.232 + SDL_SetError("Couldn't allocate libcaca bitmap");
3.233 + return(NULL);
3.234 + }
3.235 +
3.236 + /* Set the blit function */
3.237 + this->UpdateRects = Caca_DirectUpdate;
3.238 +
3.239 + /* We're done */
3.240 + return(current);
3.241 +}
3.242 +
3.243 +/* We don't actually allow hardware surfaces other than the main one */
3.244 +static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface)
3.245 +{
3.246 + return(-1);
3.247 +}
3.248 +static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface)
3.249 +{
3.250 + return;
3.251 +}
3.252 +
3.253 +/* We need to wait for vertical retrace on page flipped displays */
3.254 +static int Caca_LockHWSurface(_THIS, SDL_Surface *surface)
3.255 +{
3.256 + /* TODO ? */
3.257 + return(0);
3.258 +}
3.259 +static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface)
3.260 +{
3.261 + return;
3.262 +}
3.263 +
3.264 +/* FIXME: How is this done with libcaca? */
3.265 +static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface)
3.266 +{
3.267 + SDL_mutexP(Caca_mutex);
3.268 + caca_refresh();
3.269 + SDL_mutexV(Caca_mutex);
3.270 + return(0);
3.271 +}
3.272 +
3.273 +static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
3.274 +{
3.275 + SDL_mutexP(Caca_mutex);
3.276 + caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1,
3.277 + Caca_bitmap, Caca_buffer );
3.278 + caca_refresh();
3.279 + SDL_mutexV(Caca_mutex);
3.280 + return;
3.281 +}
3.282 +
3.283 +/* Note: If we are terminated, this could be called in the middle of
3.284 + another SDL video routine -- notably UpdateRects.
3.285 +*/
3.286 +void Caca_VideoQuit(_THIS)
3.287 +{
3.288 + int i;
3.289 +
3.290 + /* Free video mode lists */
3.291 + for ( i=0; i<SDL_NUMMODES; ++i ) {
3.292 + if ( SDL_modelist[i] != NULL ) {
3.293 + free(SDL_modelist[i]);
3.294 + SDL_modelist[i] = NULL;
3.295 + }
3.296 + }
3.297 +
3.298 + if ( Caca_bitmap ) {
3.299 + caca_free_bitmap( Caca_bitmap );
3.300 + Caca_bitmap = NULL;
3.301 + }
3.302 +
3.303 + caca_end();
3.304 +
3.305 + SDL_DestroyMutex(Caca_mutex);
3.306 +}
3.307 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/video/caca/SDL_cacavideo.h Sat Oct 10 10:17:51 2009 +0000
4.3 @@ -0,0 +1,76 @@
4.4 +/*
4.5 + SDL - Simple DirectMedia Layer
4.6 + Copyright (C) 2003 Sam Hocevar
4.7 +
4.8 + This library is free software; you can redistribute it and/or
4.9 + modify it under the terms of the GNU Library General Public
4.10 + License as published by the Free Software Foundation; either
4.11 + version 2 of the License, or (at your option) any later version.
4.12 +
4.13 + This library is distributed in the hope that it will be useful,
4.14 + but WITHOUT ANY WARRANTY; without even the implied warranty of
4.15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4.16 + Library General Public License for more details.
4.17 +
4.18 + You should have received a copy of the GNU Library General Public
4.19 + License along with this library; if not, write to the Free
4.20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4.21 +
4.22 + Sam Hocevar
4.23 + sam@zoy.org
4.24 +*/
4.25 +
4.26 +#ifdef SAVE_RCSID
4.27 +static char rcsid =
4.28 + "@(#) $Id: libsdl-1.2.11-libcaca.patch,v 1.1 2006/09/18 16:06:06 mr_bones_ Exp $";
4.29 +#endif
4.30 +
4.31 +#ifndef _SDL_cacavideo_h
4.32 +#define _SDL_cacavideo_h
4.33 +
4.34 +#include "SDL_mouse.h"
4.35 +#include "../SDL_sysvideo.h"
4.36 +#include "SDL_mutex.h"
4.37 +
4.38 +#include <sys/time.h>
4.39 +#include <time.h>
4.40 +
4.41 +#include <caca.h>
4.42 +#ifdef CACA_API_VERSION_1
4.43 +#include <caca0.h>
4.44 +#endif
4.45 +
4.46 +/* Hidden "this" pointer for the video functions */
4.47 +#define _THIS SDL_VideoDevice *this
4.48 +
4.49 +#define SDL_NUMMODES 6
4.50 +
4.51 +/* Private display data */
4.52 +struct SDL_PrivateVideoData {
4.53 + SDL_Rect *SDL_modelist[SDL_NUMMODES+1];
4.54 + SDL_mutex *mutex;
4.55 +
4.56 + struct caca_bitmap *bitmap;
4.57 + void *buffer;
4.58 + int w, h;
4.59 +
4.60 + int lastkey;
4.61 + struct timeval lasttime;
4.62 +};
4.63 +
4.64 +/* Old variable names */
4.65 +#define SDL_modelist (this->hidden->SDL_modelist)
4.66 +#define Caca_palette (this->hidden->palette)
4.67 +#define Caca_bitmap (this->hidden->bitmap)
4.68 +#define Caca_buffer (this->hidden->buffer)
4.69 +
4.70 +#define Caca_w (this->hidden->w)
4.71 +#define Caca_h (this->hidden->h)
4.72 +
4.73 +#define Caca_lastkey (this->hidden->lastkey)
4.74 +#define Caca_lasttime (this->hidden->lasttime)
4.75 +
4.76 +#define Caca_mutex (this->hidden->mutex)
4.77 +
4.78 +#endif /* _SDL_cacavideo_h */
4.79 +