diff -ruN SDL-1.2.7.orig/configure.in SDL-1.2.7/configure.in
--- SDL-1.2.7.orig/configure.in	Sat Jan 29 22:23:01 2005
+++ SDL-1.2.7/configure.in	Sat Jan 29 22:27:50 2005
@@ -962,6 +962,32 @@
     fi
 }
 
+dnl Find the libcaca includes
+CheckCaca()
+{
+    AC_ARG_ENABLE(video-caca,
+[  --enable-video-caca     use libcaca video driver [default=no]],
+		    , enable_video_caca=no)
+    if test x$enable_video = xyes -a x$enable_video_caca = xyes; then
+	AC_MSG_CHECKING(for libcaca support)
+	video_caca=no
+	AC_TRY_COMPILE([
+	 #include <caca.h>
+	],[
+	],[
+	video_caca=yes
+	])
+	AC_MSG_RESULT($video_caca)
+	if test x$video_caca = xyes; then
+	    CFLAGS="$CFLAGS -DENABLE_CACA `caca-config --cflags`"
+	    SYSTEM_LIBS="$SYSTEM_LIBS `caca-config --plugin-libs`"
+	    
+	    VIDEO_SUBDIRS="$VIDEO_SUBDIRS caca"
+	    VIDEO_DRIVERS="$VIDEO_DRIVERS caca/libvideo_caca.la"
+	fi
+    fi
+}
+
 dnl Set up the Atari Xbios driver
 CheckAtariXbiosVideo()
 {
@@ -1999,6 +2025,7 @@
         CheckNAS
         CheckX11
         CheckAAlib
+	CheckCaca
         CheckOpenGL
         CheckPTHREAD
         CheckSIGACTION
@@ -2750,6 +2777,7 @@
 src/video/aalib/Makefile
 src/video/ataricommon/Makefile
 src/video/bwindow/Makefile
+src/video/caca/Makefile
 src/video/cybergfx/Makefile
 src/video/dc/Makefile
 src/video/dga/Makefile
diff -ruN SDL-1.2.7.orig/src/video/Makefile.am SDL-1.2.7/src/video/Makefile.am
--- SDL-1.2.7.orig/src/video/Makefile.am	Sat Jan 29 22:22:51 2005
+++ SDL-1.2.7/src/video/Makefile.am	Sat Jan 29 22:23:15 2005
@@ -5,7 +5,7 @@
 
 # Define which subdirectories need to be built
 SUBDIRS = @VIDEO_SUBDIRS@
-DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
+DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib caca \
                wincommon windib windx5 \
                maccommon macdsp macrom riscos quartz \
                bwindow ps2gs photon cybergfx epoc picogui \
diff -ruN SDL-1.2.7.orig/src/video/SDL_sysvideo.h SDL-1.2.7/src/video/SDL_sysvideo.h
--- SDL-1.2.7.orig/src/video/SDL_sysvideo.h	Sat Jan 29 22:22:51 2005
+++ SDL-1.2.7/src/video/SDL_sysvideo.h	Sat Jan 29 22:23:15 2005
@@ -359,6 +359,9 @@
 #ifdef ENABLE_AALIB
 extern VideoBootStrap AALIB_bootstrap;
 #endif
+#ifdef ENABLE_CACA
+extern VideoBootStrap Caca_bootstrap;
+#endif
 #ifdef ENABLE_WINDIB
 extern VideoBootStrap WINDIB_bootstrap;
 #endif
diff -ruN SDL-1.2.7.orig/src/video/SDL_video.c SDL-1.2.7/src/video/SDL_video.c
--- SDL-1.2.7.orig/src/video/SDL_video.c	Sat Jan 29 22:22:52 2005
+++ SDL-1.2.7/src/video/SDL_video.c	Sat Jan 29 22:23:15 2005
@@ -78,6 +78,9 @@
 #ifdef ENABLE_AALIB
 	&AALIB_bootstrap,
 #endif
+#ifdef ENABLE_CACA
+	&Caca_bootstrap,
+#endif
 #ifdef ENABLE_DIRECTX
 	&DIRECTX_bootstrap,
 #endif
diff -ruN SDL-1.2.7.orig/src/video/caca/Makefile.am SDL-1.2.7/src/video/caca/Makefile.am
--- SDL-1.2.7.orig/src/video/caca/Makefile.am	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/Makefile.am	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,13 @@
+
+## Makefile.am for SDL using the libcaca video driver
+
+noinst_LTLIBRARIES = libvideo_caca.la
+libvideo_caca_la_SOURCES = $(CACA_SRCS)
+
+# The SDL libcaca video driver sources
+CACA_SRCS = 			\
+	SDL_cacavideo.h		\
+	SDL_cacaevents.c	\
+	SDL_cacaevents_c.h	\
+	SDL_cacavideo.c
+
diff -ruN SDL-1.2.7.orig/src/video/caca/Makefile.in SDL-1.2.7/src/video/caca/Makefile.in
--- SDL-1.2.7.orig/src/video/caca/Makefile.in	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/Makefile.in	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,342 @@
+# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ../../..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+ARCH = @ARCH@
+ARTSCCONFIG = @ARTSCCONFIG@
+AS = @AS@
+ASFLAGS = @ASFLAGS@
+AUDIO_DRIVERS = @AUDIO_DRIVERS@
+AUDIO_SUBDIRS = @AUDIO_SUBDIRS@
+CC = @CC@
+CCAS = @CCAS@
+CCASFLAGS = @CCASFLAGS@
+CDROM_DRIVERS = @CDROM_DRIVERS@
+CDROM_SUBDIRS = @CDROM_SUBDIRS@
+CXX = @CXX@
+DIRECTFB_CFLAGS = @DIRECTFB_CFLAGS@
+DIRECTFB_LIBS = @DIRECTFB_LIBS@
+DLLTOOL = @DLLTOOL@
+ESD_CFLAGS = @ESD_CFLAGS@
+ESD_CONFIG = @ESD_CONFIG@
+ESD_LIBS = @ESD_LIBS@
+JOYSTICK_DRIVERS = @JOYSTICK_DRIVERS@
+JOYSTICK_SUBDIRS = @JOYSTICK_SUBDIRS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LT_AGE = @LT_AGE@
+LT_CURRENT = @LT_CURRENT@
+LT_RELEASE = @LT_RELEASE@
+LT_REVISION = @LT_REVISION@
+MAKEINFO = @MAKEINFO@
+NASM = @NASM@
+NASMFLAGS = @NASMFLAGS@
+OBJC = @OBJC@
+OBJCDEPMODE = @OBJCDEPMODE@
+OBJCFLAGS = @OBJCFLAGS@
+OBJDUMP = @OBJDUMP@
+PACKAGE = @PACKAGE@
+PKG_CONFIG = @PKG_CONFIG@
+PTH_CONFIG = @PTH_CONFIG@
+RANLIB = @RANLIB@
+SDL_BINARY_AGE = @SDL_BINARY_AGE@
+SDL_CFLAGS = @SDL_CFLAGS@
+SDL_EXTRADIRS = @SDL_EXTRADIRS@
+SDL_EXTRALIBS = @SDL_EXTRALIBS@
+SDL_INTERFACE_AGE = @SDL_INTERFACE_AGE@
+SDL_LIBS = @SDL_LIBS@
+SDL_MAJOR_VERSION = @SDL_MAJOR_VERSION@
+SDL_MICRO_VERSION = @SDL_MICRO_VERSION@
+SDL_MINOR_VERSION = @SDL_MINOR_VERSION@
+SDL_RLD_FLAGS = @SDL_RLD_FLAGS@
+SDL_VERSION = @SDL_VERSION@
+SHARED_SYSTEM_LIBS = @SHARED_SYSTEM_LIBS@
+STATIC_SYSTEM_LIBS = @STATIC_SYSTEM_LIBS@
+SYSTEM_LIBS = @SYSTEM_LIBS@
+VERSION = @VERSION@
+VIDEO_DRIVERS = @VIDEO_DRIVERS@
+VIDEO_SUBDIRS = @VIDEO_SUBDIRS@
+arts_lib = @arts_lib@
+esd_lib = @esd_lib@
+
+noinst_LTLIBRARIES = libvideo_caca.la
+libvideo_caca_la_SOURCES = $(CACA_SRCS)
+
+# The SDL libcaca video driver sources
+CACA_SRCS =  	SDL_cacavideo.h			SDL_cacaevents.c		SDL_cacaevents_c.h		SDL_cacavideo.c
+
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_CLEAN_FILES = 
+LTLIBRARIES =  $(noinst_LTLIBRARIES)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir) 
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+X_CFLAGS = @X_CFLAGS@
+X_LIBS = @X_LIBS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+libvideo_caca_la_LDFLAGS = 
+libvideo_caca_la_LIBADD = 
+libvideo_caca_la_OBJECTS =  SDL_cacaevents.lo SDL_cacavideo.lo
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+DIST_COMMON =  Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = gtar
+GZIP_ENV = --best
+SOURCES = $(libvideo_caca_la_SOURCES)
+OBJECTS = $(libvideo_caca_la_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .lo .o .s
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) 
+	cd $(top_srcdir) && $(AUTOMAKE) --foreign --include-deps src/video/caca/Makefile
+
+Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
+	cd $(top_builddir) \
+	  && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-noinstLTLIBRARIES:
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+
+distclean-noinstLTLIBRARIES:
+
+maintainer-clean-noinstLTLIBRARIES:
+
+.c.o:
+	$(COMPILE) -c $<
+
+.s.o:
+	$(COMPILE) -c $<
+
+.S.o:
+	$(COMPILE) -c $<
+
+mostlyclean-compile:
+	-rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+	-rm -f *.tab.c
+
+maintainer-clean-compile:
+
+.c.lo:
+	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+.s.lo:
+	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+.S.lo:
+	$(LIBTOOL) --mode=compile $(COMPILE) -c $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+distclean-libtool:
+
+maintainer-clean-libtool:
+
+libvideo_caca.la: $(libvideo_caca_la_OBJECTS) $(libvideo_caca_la_DEPENDENCIES)
+	$(LINK)  $(libvideo_caca_la_LDFLAGS) $(libvideo_caca_la_OBJECTS) $(libvideo_caca_la_LIBADD) $(LIBS)
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+	list='$(SOURCES) $(HEADERS)'; \
+	unique=`for i in $$list; do echo $$i; done | \
+	  awk '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	here=`pwd` && cd $(srcdir) \
+	  && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)'; \
+	unique=`for i in $$list; do echo $$i; done | \
+	  awk '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+	  || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags  $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+	-rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+subdir = src/video/caca
+
+distdir: $(DISTFILES)
+	@for file in $(DISTFILES); do \
+	  d=$(srcdir); \
+	  if test -d $$d/$$file; then \
+	    cp -pr $$d/$$file $(distdir)/$$file; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+	    || cp -p $$d/$$file $(distdir)/$$file || :; \
+	  fi; \
+	done
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am: all-am
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(LTLIBRARIES)
+all-redirect: all-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-rm -f Makefile $(CONFIG_CLEAN_FILES)
+	-rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am:  mostlyclean-noinstLTLIBRARIES mostlyclean-compile \
+		mostlyclean-libtool mostlyclean-tags \
+		mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am:  clean-noinstLTLIBRARIES clean-compile clean-libtool \
+		clean-tags clean-generic mostlyclean-am
+
+clean: clean-am
+
+distclean-am:  distclean-noinstLTLIBRARIES distclean-compile \
+		distclean-libtool distclean-tags distclean-generic \
+		clean-am
+	-rm -f libtool
+
+distclean: distclean-am
+
+maintainer-clean-am:  maintainer-clean-noinstLTLIBRARIES \
+		maintainer-clean-compile maintainer-clean-libtool \
+		maintainer-clean-tags maintainer-clean-generic \
+		distclean-am
+	@echo "This command is intended for maintainers to use;"
+	@echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-noinstLTLIBRARIES distclean-noinstLTLIBRARIES \
+clean-noinstLTLIBRARIES maintainer-clean-noinstLTLIBRARIES \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile mostlyclean-libtool distclean-libtool \
+clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
+distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
+dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
+install-exec install-data-am install-data install-am install \
+uninstall-am uninstall all-redirect all-am all installdirs \
+mostlyclean-generic distclean-generic clean-generic \
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff -ruN SDL-1.2.7.orig/src/video/caca/SDL_cacaevents.c SDL-1.2.7/src/video/caca/SDL_cacaevents.c
--- SDL-1.2.7.orig/src/video/caca/SDL_cacaevents.c	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/SDL_cacaevents.c	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,97 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+#ifdef SAVE_RCSID
+static char rcsid =
+ "@(#) $Id: patch-libsdl1.2-libcaca0.7.diff 324 2004-01-08 12:43:53Z sam $";
+#endif
+
+#include <stdio.h>
+
+#include <caca.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+#include "SDL_cacavideo.h"
+#include "SDL_cacaevents_c.h"
+
+void Caca_PumpEvents(_THIS)
+{
+	int posted = 0;
+	int event;
+	SDL_keysym keysym;
+
+	if( ! this->screen ) /* Wait till we got the screen initialised */
+	  return;
+
+	do {
+		posted = 0;
+
+		/* Get libcaca event */
+		SDL_mutexP(Caca_mutex);
+		event = caca_get_event(CACA_EVENT_ANY);
+		SDL_mutexV(Caca_mutex);
+
+		if ( event & (CACA_EVENT_KEY_PRESS | CACA_EVENT_KEY_RELEASE)) {
+			int key;
+			switch ( event & 0xffffff )
+			{
+				case CACA_KEY_LEFT: key = SDLK_LEFT; break;
+				case CACA_KEY_RIGHT: key = SDLK_RIGHT; break;
+				case CACA_KEY_UP: key = SDLK_UP; break;
+				case CACA_KEY_DOWN: key = SDLK_DOWN; break;
+				default: key = event & 0xff; break;
+			}
+			/* Key pressed */
+/*    			printf("Key pressed: %d (%c)\n", key, key); */
+			keysym.scancode = key;
+			keysym.sym = key;
+			keysym.mod = KMOD_NONE;
+			keysym.unicode = 0;
+			if ( SDL_TranslateUNICODE ) {
+				keysym.unicode = key;
+			}
+			posted += SDL_PrivateKeyboard((event & CACA_EVENT_KEY_PRESS) ? SDL_PRESSED : SDL_RELEASED, &keysym);
+		}
+		else if ( event & (CACA_EVENT_MOUSE_PRESS | CACA_EVENT_MOUSE_RELEASE) ) {
+			/* FIXME: we currently ignore the button type! */
+			int button = event & 0x00ffffff;
+			if ( button > 3 ) {
+				button = 1;
+			}
+			posted += SDL_PrivateMouseButton((event & CACA_EVENT_MOUSE_PRESS) ? SDL_PRESSED : SDL_RELEASED, button, 0, 0);
+		}
+		else if ( event & CACA_EVENT_MOUSE_MOTION ) {
+			int new_x = 0, new_y = 0;
+			new_x = ((event & 0x00fff000) >> 12) * Caca_w / caca_get_width();
+			new_y = ((event & 0x00000fff) >> 0) * Caca_h / caca_get_height();
+			posted += SDL_PrivateMouseMotion(0, 0, new_x, new_y);
+		}
+	} while ( posted );
+}
+
+void Caca_InitOSKeymap(_THIS)
+{
+    return;
+}
+
diff -ruN SDL-1.2.7.orig/src/video/caca/SDL_cacaevents_c.h SDL-1.2.7/src/video/caca/SDL_cacaevents_c.h
--- SDL-1.2.7.orig/src/video/caca/SDL_cacaevents_c.h	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/SDL_cacaevents_c.h	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,34 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+#ifdef SAVE_RCSID
+static char rcsid =
+ "@(#) $Id: patch-libsdl1.2-libcaca0.7.diff 324 2004-01-08 12:43:53Z sam $";
+#endif
+
+#include "SDL_cacavideo.h"
+
+/* Variables and functions exported by SDL_sysevents.c to other parts 
+   of the native video subsystem (SDL_sysvideo.c)
+*/
+extern void Caca_PumpEvents(_THIS);
+extern void Caca_InitOSKeymap(_THIS);
diff -ruN SDL-1.2.7.orig/src/video/caca/SDL_cacavideo.c SDL-1.2.7/src/video/caca/SDL_cacavideo.c
--- SDL-1.2.7.orig/src/video/caca/SDL_cacavideo.c	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/SDL_cacavideo.c	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,301 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 2003  Sam Hocevar
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Hocevar
+    sam@zoy.org
+*/
+
+#ifdef SAVE_RCSID
+static char rcsid =
+ "@(#) $Id: patch-libsdl1.2-libcaca0.7.diff 324 2004-01-08 12:43:53Z sam $";
+#endif
+
+/* libcaca based SDL video driver implementation.
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+
+#include "SDL.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "SDL_sysvideo.h"
+#include "SDL_pixels_c.h"
+#include "SDL_events_c.h"
+
+#include "SDL_cacavideo.h"
+#include "SDL_cacaevents_c.h"
+
+#include <caca.h>
+
+/* Initialization/Query functions */
+static int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat);
+static SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
+static SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
+static void Caca_VideoQuit(_THIS);
+
+/* Hardware surface functions */
+static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface);
+static int Caca_LockHWSurface(_THIS, SDL_Surface *surface);
+static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface);
+static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface);
+static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface);
+
+/* Cache the VideoDevice struct */
+static struct SDL_VideoDevice *local_this;
+
+/* libcaca driver bootstrap functions */
+
+static int Caca_Available(void)
+{
+	return 1; /* Always available ! */
+}
+
+static void Caca_DeleteDevice(SDL_VideoDevice *device)
+{
+	free(device->hidden);
+	free(device);
+}
+
+static SDL_VideoDevice *Caca_CreateDevice(int devindex)
+{
+	SDL_VideoDevice *device;
+
+	/* Initialize all variables that we clean on shutdown */
+	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+	if ( device ) {
+		memset(device, 0, (sizeof *device));
+		device->hidden = (struct SDL_PrivateVideoData *)
+				malloc((sizeof *device->hidden));
+	}
+	if ( (device == NULL) || (device->hidden == NULL) ) {
+		SDL_OutOfMemory();
+		if ( device ) {
+			free(device);
+		}
+		return(0);
+	}
+	memset(device->hidden, 0, (sizeof *device->hidden));
+
+	/* Set the function pointers */
+	device->VideoInit = Caca_VideoInit;
+	device->ListModes = Caca_ListModes;
+	device->SetVideoMode = Caca_SetVideoMode;
+	device->CreateYUVOverlay = NULL;
+	device->SetColors = NULL;
+	device->UpdateRects = NULL;
+	device->VideoQuit = Caca_VideoQuit;
+	device->AllocHWSurface = Caca_AllocHWSurface;
+	device->CheckHWBlit = NULL;
+	device->FillHWRect = NULL;
+	device->SetHWColorKey = NULL;
+	device->SetHWAlpha = NULL;
+	device->LockHWSurface = Caca_LockHWSurface;
+	device->UnlockHWSurface = Caca_UnlockHWSurface;
+	device->FlipHWSurface = NULL;
+	device->FreeHWSurface = Caca_FreeHWSurface;
+	device->SetCaption = NULL;
+	device->SetIcon = NULL;
+	device->IconifyWindow = NULL;
+	device->GrabInput = NULL;
+	device->GetWMInfo = NULL;
+	device->InitOSKeymap = Caca_InitOSKeymap;
+	device->PumpEvents = Caca_PumpEvents;
+
+	device->free = Caca_DeleteDevice;
+
+	return device;
+}
+
+VideoBootStrap Caca_bootstrap = {
+	"caca", "Color ASCII Art Library",
+	Caca_Available, Caca_CreateDevice
+};
+
+int Caca_VideoInit(_THIS, SDL_PixelFormat *vformat)
+{
+	int i;
+
+	/* Initialize all variables that we clean on shutdown */
+	for ( i=0; i<SDL_NUMMODES; ++i ) {
+		SDL_modelist[i] = malloc(sizeof(SDL_Rect));
+		SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
+	}
+	/* Modes sorted largest to smallest */
+	SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
+	SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
+	SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
+	SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
+	SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
+	SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
+	SDL_modelist[6] = NULL;
+
+	Caca_mutex = SDL_CreateMutex();
+
+	/* Initialize the library */
+	if ( caca_init() != 0 ) {
+		SDL_SetError("Unable to initialize libcaca");
+		return(-1);
+	}
+
+	/* Initialize private variables */
+	Caca_lastkey = 0;
+	Caca_bitmap = NULL;
+	Caca_buffer = NULL;
+
+	local_this = this;
+
+	/* Determine the screen depth (use default 8-bit depth) */
+	vformat->BitsPerPixel = 8;
+	vformat->BytesPerPixel = 1;
+
+	/* We're done! */
+	return(0);
+}
+
+SDL_Rect **Caca_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
+{
+     if(format->BitsPerPixel != 8)
+ 		return NULL;
+
+	 if ( flags & SDL_FULLSCREEN ) {
+		 return SDL_modelist;
+	 } else {
+		 return (SDL_Rect **) -1;
+	 }
+}
+
+/* Various screen update functions available */
+static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects);
+
+SDL_Surface *Caca_SetVideoMode(_THIS, SDL_Surface *current,
+				int width, int height, int bpp, Uint32 flags)
+{
+	if ( Caca_buffer ) {
+		free( Caca_buffer );
+		Caca_buffer = NULL;
+	}
+
+	if ( Caca_bitmap ) {
+		caca_free_bitmap( Caca_bitmap );
+		Caca_bitmap = NULL;
+	}
+
+	Caca_buffer = malloc(2 * ((width + 15) & ~15) * height);
+	if ( ! Caca_buffer ) {
+		SDL_SetError("Couldn't allocate buffer for requested mode");
+		return(NULL);
+	}
+
+	memset(Caca_buffer, 0, 2 * ((width + 15) & ~15) * height);
+
+	/* Allocate the new pixel format for the screen */
+	if ( ! SDL_ReallocFormat(current, 16, 0xf800, 0x07e0, 0x001f, 0) ) {
+		return(NULL);
+	}
+
+	/* Set up the new mode framebuffer */
+	current->flags = SDL_FULLSCREEN;
+	Caca_w = current->w = width;
+	Caca_h = current->h = height;
+	current->pitch = 2 * ((width + 15) & ~15);
+	current->pixels = Caca_buffer;
+
+	/* Create the libcaca bitmap */
+	Caca_bitmap = caca_create_bitmap( 16, width, height, current->pitch, 0xf800, 0x07e0, 0x001f, 0x0000 );
+	if ( ! Caca_bitmap ) {
+		SDL_SetError("Couldn't allocate libcaca bitmap");
+		return(NULL);
+	}
+
+	/* Set the blit function */
+	this->UpdateRects = Caca_DirectUpdate;
+
+	/* We're done */
+	return(current);
+}
+
+/* We don't actually allow hardware surfaces other than the main one */
+static int Caca_AllocHWSurface(_THIS, SDL_Surface *surface)
+{
+	return(-1);
+}
+static void Caca_FreeHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+/* We need to wait for vertical retrace on page flipped displays */
+static int Caca_LockHWSurface(_THIS, SDL_Surface *surface)
+{
+	/* TODO ? */
+	return(0);
+}
+static void Caca_UnlockHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+/* FIXME: How is this done with libcaca? */
+static int Caca_FlipHWSurface(_THIS, SDL_Surface *surface)
+{
+	SDL_mutexP(Caca_mutex);
+	caca_refresh();
+	SDL_mutexV(Caca_mutex);
+	return(0);
+}
+
+static void Caca_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
+{
+	SDL_mutexP(Caca_mutex);
+	caca_draw_bitmap( 0, 0, caca_get_width() - 1, caca_get_height() - 1,
+			  Caca_bitmap, Caca_buffer );
+	caca_refresh();
+	SDL_mutexV(Caca_mutex);
+	return;
+}
+
+/* Note:  If we are terminated, this could be called in the middle of
+   another SDL video routine -- notably UpdateRects.
+*/
+void Caca_VideoQuit(_THIS)
+{
+	int i;
+
+	/* Free video mode lists */
+	for ( i=0; i<SDL_NUMMODES; ++i ) {
+		if ( SDL_modelist[i] != NULL ) {
+			free(SDL_modelist[i]);
+			SDL_modelist[i] = NULL;
+		}
+	}
+
+	if ( Caca_bitmap ) {
+		caca_free_bitmap( Caca_bitmap );
+		Caca_bitmap = NULL;
+	}
+
+	caca_end();
+
+	SDL_DestroyMutex(Caca_mutex);
+}
diff -ruN SDL-1.2.7.orig/src/video/caca/SDL_cacavideo.h SDL-1.2.7/src/video/caca/SDL_cacavideo.h
--- SDL-1.2.7.orig/src/video/caca/SDL_cacavideo.h	Thu Jan  1 01:00:00 1970
+++ SDL-1.2.7/src/video/caca/SDL_cacavideo.h	Sat Jan 29 22:23:15 2005
@@ -0,0 +1,72 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 2003  Sam Hocevar
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Hocevar
+    sam@zoy.org
+*/
+
+#ifdef SAVE_RCSID
+static char rcsid =
+ "@(#) $Id: patch-libsdl1.2-libcaca0.7.diff 324 2004-01-08 12:43:53Z sam $";
+#endif
+
+#ifndef _SDL_cacavideo_h
+#define _SDL_cacavideo_h
+
+#include "SDL_mouse.h"
+#include "SDL_sysvideo.h"
+#include "SDL_mutex.h"
+
+#include <sys/time.h>
+#include <time.h>
+
+#include <caca.h>
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+#define SDL_NUMMODES 6
+
+/* Private display data */
+struct SDL_PrivateVideoData {
+	SDL_Rect *SDL_modelist[SDL_NUMMODES+1];
+	SDL_mutex *mutex;
+
+	struct caca_bitmap *bitmap;
+	void *buffer;
+	int w, h;
+
+	int lastkey;
+	struct timeval lasttime;
+};
+
+/* Old variable names */
+#define SDL_modelist		(this->hidden->SDL_modelist)
+#define Caca_palette		    (this->hidden->palette)
+#define Caca_bitmap		    (this->hidden->bitmap)
+#define Caca_buffer		    (this->hidden->buffer)
+
+#define Caca_w			    (this->hidden->w)
+#define Caca_h			    (this->hidden->h)
+
+#define Caca_lastkey		    (this->hidden->lastkey)
+#define Caca_lasttime		    (this->hidden->lasttime)
+
+#define Caca_mutex		    (this->hidden->mutex)
+
+#endif /* _SDL_cacavideo_h */
