changeset 281:c5010ab8ba35

Added initial support for Atari (thanks Patrice!)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 17 Feb 2002 19:54:28 +0000
parents 0ddcea45d829
children b42d80e73896
files CREDITS Makefile.am README README.MiNT configure.in docs.html src/timer/Makefile.am src/timer/mint/SDL_systimer.c src/timer/mint/SDL_vbltimer.S src/timer/mint/SDL_vbltimer_s.h src/video/Makefile.am src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/ataricommon/Makefile.am src/video/ataricommon/SDL_ataric2p.S src/video/ataricommon/SDL_ataric2p060.c src/video/ataricommon/SDL_ataric2p060_c.h src/video/ataricommon/SDL_ataric2p_s.h src/video/ataricommon/SDL_atarieddi.S src/video/ataricommon/SDL_atarieddi_s.h src/video/ataricommon/SDL_atarievents.c src/video/ataricommon/SDL_atarievents_c.h src/video/ataricommon/SDL_atarikeys.h src/video/ataricommon/SDL_atarimxalloc.c src/video/ataricommon/SDL_atarimxalloc_c.h src/video/ataricommon/SDL_biosevents.c src/video/ataricommon/SDL_biosevents_c.h src/video/ataricommon/SDL_gemdosevents.c src/video/ataricommon/SDL_gemdosevents_c.h src/video/ataricommon/SDL_ikbdevents.c src/video/ataricommon/SDL_ikbdevents_c.h src/video/ataricommon/SDL_ikbdinterrupt.S src/video/ataricommon/SDL_ikbdinterrupt_s.h src/video/ataricommon/SDL_xbiosmouseevents.c src/video/ataricommon/SDL_xbiosmouseevents_c.h src/video/ataricommon/SDL_xbiosmouseinterrupt.S src/video/ataricommon/SDL_xbiosmouseinterrupt_s.h src/video/gem/Makefile.am src/video/gem/SDL_gemevents.c src/video/gem/SDL_gemevents_c.h src/video/gem/SDL_gemmouse.c src/video/gem/SDL_gemmouse_c.h src/video/gem/SDL_gemvideo.c src/video/gem/SDL_gemvideo.h src/video/gem/SDL_gemwm.c src/video/gem/SDL_gemwm_c.h src/video/xbios/Makefile.am src/video/xbios/SDL_xbios.c src/video/xbios/SDL_xbios.h
diffstat 49 files changed, 5991 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CREDITS	Thu Feb 14 21:26:42 2002 +0000
+++ b/CREDITS	Sun Feb 17 19:54:28 2002 +0000
@@ -19,11 +19,13 @@
 
 * Patrick Trainor and Jim Boucher, for the QNX Neutrino port
 
-* Hannu Viitala for the EPOC port
+* Carsten Griwodz for the AIX port
 
 * Gabriele Greco, for the Amiga port
 
-* Carsten Griwodz for the AIX port
+* Patrice Mandin, for the Atari port
+
+* Hannu Viitala for the EPOC port
 
 * Peter Valchev for nagging me about the OpenBSD port until I got it right. :)
 
--- a/Makefile.am	Thu Feb 14 21:26:42 2002 +0000
+++ b/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -28,6 +28,7 @@
 	README.Epoc	\
 	README.MacOS	\
 	README.MacOSX	\
+	README.MiNT	\
 	README.NanoX	\
 	README.OpenBSD	\
 	README.QNX	\
--- a/README	Thu Feb 14 21:26:42 2002 +0000
+++ b/README	Sun Feb 17 19:54:28 2002 +0000
@@ -17,8 +17,8 @@
 
 The current version supports Linux, Windows, BeOS, MacOS, MacOS X,
 FreeBSD, BSD/OS, Solaris, and IRIX.  The code contains support for
-Windows CE, OpenBSD, NetBSD, AIX, OSF/Tru64, and QNX, but these are
-not yet officially supported.
+Atari, Windows CE, OpenBSD, NetBSD, AIX, OSF/Tru64, and QNX, but these
+are not yet officially supported.
 
 This library is distributed under GNU LGPL version 2, which can be
 found in the file  "COPYING".  This license allows you to use SDL
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.MiNT	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,80 @@
+
+==============================================================================
+Using the Simple DirectMedia Layer on Atari
+==============================================================================
+
+==============================================================================
+I.  Building the Simple DirectMedia Layer libraries:
+    (This step isn't necessary if you have the SDL binary distribution)
+
+  Do the classic configure, with --disable-shared --enable-static and:
+
+    Tos version (should run everywhere):
+      --disable-audio --disable-threads
+    Tos does not support threads, so can not support audio, maybe in a future
+    version audio support will be added via interrupts.
+
+    MiNT version (maybe Magic, only for multitasking OS):
+      --disable-pthreads --enable-pth
+    Mint and Magic may supports threads, so audio can be used with current
+    devices, like Sun audio, or disk-writing support. Like Tos, interrupt
+    audio without threads is more suited for Atari machines.
+
+  Then you can make ; make install it.
+
+==============================================================================
+II. Building the Simple DirectMedia Layer test programs:
+
+  Do the classic configure, then make.
+
+  Run them !
+
+==============================================================================
+III.  Enjoy! :)
+
+  If you have a project you'd like me to know about, or want to ask questions,
+  go ahead and join the SDL developer's mailing list by sending e-mail to:
+
+	sdl-request@libsdl.org
+
+  and put "subscribe" into the subject of the message. Or alternatively you
+  can use the web interface:
+
+	http://www.libsdl.org/mailman/listinfo/sdl
+  
+==============================================================================
+IV.  What is supported:
+
+Keyboard (GEMDOS, BIOS, Ikbd)
+Mouse (XBIOS, GEM, Ikbd)
+Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
+Timer (VBL vector)
+
+- What is missing:
+Audio support (TOS)
+CDROM support (Metados, /dev/cdrom)
+Joystick and joypad support (Hardware)
+Threads support (TOS)
+
+- Driver combinations:
+Video	Kbd	Mouse	Timer
+xbios	ikbd	ikbd	vbl
+xbios	gemdos	xbios	vbl
+xbios	bios	xbios	vbl
+gem	gem	gem	vbl
+
+==============================================================================
+V.  Environment variables:
+
+SDL_ATARI_EVENTSDRIVER
+	Set to 'ikbd' to force IKBD 6301 keyboard driver
+	Set to 'gemdos' to force gemdos keyboard driver
+	Set to 'bios' to force bios keyboard driver
+
+SDL_VIDEODRIVER:
+	Set to 'xbios' to force xbios video driver
+	Set to 'gem' to force gem video driver
+
+-- 
+Patrice Mandin <pmandin@caramail.com>
+http://www.multimania.com/pmandin
--- a/configure.in	Thu Feb 14 21:26:42 2002 +0000
+++ b/configure.in	Sun Feb 17 19:54:28 2002 +0000
@@ -909,6 +909,49 @@
     fi
 }
 
+dnl Set up the Atari Xbios driver
+CheckAtariXbiosVideo()
+{
+    AC_ARG_ENABLE(xbios,
+[  --enable-video-xbios    use Atari Xbios video driver [default=yes]],
+                  , enable_video_xbios=yes)
+    video_xbios=no
+    if test x$enable_video = xyes -a x$enable_video_xbios = xyes; then
+        video_xbios=yes
+        CFLAGS="$CFLAGS -DENABLE_XBIOS"
+        VIDEO_SUBDIRS="$VIDEO_SUBDIRS xbios"
+        VIDEO_DRIVERS="$VIDEO_DRIVERS xbios/libvideo_xbios.la"
+    fi
+}
+
+dnl Set up the Atari Gem driver
+CheckAtariGemVideo()
+{
+    AC_ARG_ENABLE(gem,
+[  --enable-video-gem      use Atari Gem video driver [default=yes]],
+                  , enable_video_gem=yes)
+    if test x$enable_video = xyes -a x$enable_video_gem = xyes; then
+        video_gem=no
+        AC_CHECK_HEADER(gem.h, have_gem_hdr=yes)
+        AC_CHECK_LIB(gem, appl_init, have_gem_lib=yes)
+        if test x$have_gem_hdr = xyes -a x$have_gem_lib = xyes; then
+            video_gem=yes
+            CFLAGS="$CFLAGS -DENABLE_GEM"
+            SYSTEM_LIBS="$SYSTEM_LIBS -lgem"
+            VIDEO_SUBDIRS="$VIDEO_SUBDIRS gem"
+            VIDEO_DRIVERS="$VIDEO_DRIVERS gem/libvideo_gem.la"
+        fi
+    fi
+}
+
+dnl Set up the Atari Bios keyboard driver
+CheckAtariBiosEvent()
+{
+    CFLAGS="$CFLAGS -I\$(top_srcdir)/src/video/ataricommon"
+    VIDEO_SUBDIRS="$VIDEO_SUBDIRS ataricommon"
+    VIDEO_DRIVERS="$VIDEO_DRIVERS ataricommon/libvideo_ataricommon.la"
+}
+
 dnl rcg04172001 Set up the Null video driver.
 CheckDummyVideo()
 {
@@ -2165,6 +2208,57 @@
         SDL_CFLAGS="$SDL_CFLAGS -F/System/Library/Frameworks/Carbon.framework -F/System/Library/Frameworks/Cocoa.framework"
         SDL_LIBS="-lSDLmain $SDL_LIBS -framework Carbon -framework Cocoa"
         ;;
+    *-*-mint*)
+        ARCH=mint
+        CheckDummyVideo
+        CheckDiskAudio
+        CheckAtariBiosEvent
+        CheckAtariXbiosVideo
+        CheckAtariGemVideo
+        CheckPTH
+        # Set up files for the main() stub
+        COPY_ARCH_SRC(src/main, linux, SDL_main.c)
+        # Set up files for the audio library
+        if test x$enable_audio = xyes; then
+            AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun"
+            AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
+        fi
+        # Set up files for the joystick library
+        # (No joystick support yet)
+        if test x$enable_joystick = xyes; then
+            JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS dummy"
+            JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS dummy/libjoystick_dummy.la"
+        fi
+        # Set up files for the cdrom library
+        if test x$enable_cdrom = xyes; then
+            CDROM_SUBDIRS="$CDROM_SUBDIRS dummy"
+            CDROM_DRIVERS="$CDROM_DRIVERS dummy/libcdrom_dummy.la"
+        fi
+        # Set up files for the thread library
+        if test x$enable_threads = xyes; then
+            if test x$enable_pth = xyes; then
+                COPY_ARCH_SRC(src/thread, pth, SDL_systhread.c)
+                COPY_ARCH_SRC(src/thread, pth, SDL_systhread_c.h)
+            else
+                COPY_ARCH_SRC(src/thread, generic, SDL_systhread.c)
+                COPY_ARCH_SRC(src/thread, generic, SDL_systhread_c.h)
+            fi
+            COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex.c)
+            COPY_ARCH_SRC(src/thread, generic, SDL_sysmutex_c.h)
+            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
+            COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
+            COPY_ARCH_SRC(src/thread, generic, SDL_syscond.c)
+            COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
+        fi
+        # Set up files for the timer library
+        if test x$enable_timers = xyes; then
+            COPY_ARCH_SRC(src/timer, mint, SDL_systimer.c)
+            COPY_ARCH_SRC(src/timer, mint, SDL_vbltimer.S)
+            COPY_ARCH_SRC(src/timer, mint, SDL_vbltimer_s.h)
+        fi
+        # MiNT does not define "unix"
+        CFLAGS="$CFLAGS -Dunix"
+        ;;
     *)
         AC_MSG_ERROR(Unsupported target:  Please add to configure.in)
         ;;
@@ -2185,6 +2279,7 @@
 AM_CONDITIONAL(TARGET_MACOS, test $ARCH = macos)
 AM_CONDITIONAL(TARGET_MACOSX, test $ARCH = macosx)
 AM_CONDITIONAL(TARGET_QNX, test $ARCH = qnx)
+AM_CONDITIONAL(TARGET_MINT, test $ARCH = mint)
 
 # Set conditional variables for shared and static library selection.
 # These are not used in any Makefile.am but in sdl-config.in.
@@ -2318,10 +2413,14 @@
 src/video/photon/Makefile
 src/video/epoc/Makefile
 src/video/dummy/Makefile
+src/video/ataricommon/Makefile
+src/video/xbios/Makefile
+src/video/gem/Makefile
 src/events/Makefile
 src/joystick/Makefile
 src/joystick/amigaos/Makefile
 src/joystick/beos/Makefile
+src/joystick/bsd/Makefile
 src/joystick/darwin/Makefile
 src/joystick/dummy/Makefile
 src/joystick/linux/Makefile
--- a/docs.html	Thu Feb 14 21:26:42 2002 +0000
+++ b/docs.html	Sun Feb 17 19:54:28 2002 +0000
@@ -16,6 +16,7 @@
 Major changes since SDL 1.0.0:
 </H2>
 <UL>
+	<LI> 1.2.4: Added initial support for Atari (thanks Patrice!)
 	<LI> 1.2.4: Added support for joysticks on *BSD (thanks Wilbern!)
 	<LI> 1.2.4: Added a YUV overlay test program (thanks Jon!)
 	<LI> 1.2.4: Added support for building SDL for EPOC/SymbianOS 6.0
--- a/src/timer/Makefile.am	Thu Feb 14 21:26:42 2002 +0000
+++ b/src/timer/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -8,13 +8,18 @@
                $(srcdir)/epoc \
                $(srcdir)/linux \
                $(srcdir)/macos \
+               $(srcdir)/mint \
                $(srcdir)/win32
 
 # Include the architecture-independent sources
 COMMON_SRCS = SDL_timer.c SDL_timer_c.h SDL_systimer.h
 
 # Include the architecture-specific sources
+if TARGET_MINT
+ARCH_SRCS = SDL_systimer.c SDL_vbltimer.S SDL_vbltimer_s.h
+else
 ARCH_SRCS = SDL_systimer.c
+endif
 
 libtimer_la_SOURCES = $(COMMON_SRCS) $(ARCH_SRCS)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/timer/mint/SDL_systimer.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,149 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	TOS/MiNT timer driver
+ *	based on vbl vector
+ *
+ *	Patrice Mandin
+ */
+
+#include <stdio.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <mint/osbind.h>
+#include <sysvars.h>
+
+#include "SDL_error.h"
+#include "SDL_timer.h"
+#include "SDL_timer_c.h"
+#include "SDL_thread.h"
+
+#include "SDL_vbltimer_s.h"
+
+/* The first ticks value of the application */
+static Uint32 start;
+static SDL_bool supervisor;
+
+void SDL_StartTicks(void)
+{
+	void *oldpile;
+
+	/* Set first ticks value */
+	oldpile=(void *)Super(0);
+	start=*((volatile long *)_hz_200);
+	Super(oldpile);
+
+	start *= 5;	/* One _hz_200 tic is 5ms */
+}
+
+Uint32 SDL_GetTicks (void)
+{
+	Uint32 now;
+	void *oldpile;
+
+	/* Check if we are in supervisor mode 
+	   (this is the case when called from SDL_ThreadedTimerCheck,
+	   which is called from RunTimer, running in the vbl vector)
+	*/
+	if (!supervisor) {
+		oldpile=(void *)Super(0);
+	}
+
+	now=*((volatile long *)_hz_200);
+
+	if (!supervisor) {
+		Super(oldpile);
+	}
+
+	return((now*5)-start);
+}
+
+void SDL_Delay (Uint32 ms)
+{
+	Uint32 now;
+
+	now = SDL_GetTicks();
+	while ((SDL_GetTicks()-now)<ms){
+	}
+}
+
+/* Data to handle a single periodic alarm */
+static SDL_bool timer_installed=SDL_FALSE;
+
+static void RunTimer(void)
+{
+	supervisor=SDL_TRUE;
+	SDL_ThreadedTimerCheck();
+	supervisor=SDL_FALSE;
+}
+
+/* This is only called if the event thread is not running */
+int SDL_SYS_TimerInit(void)
+{
+	void *oldpile;
+
+	supervisor=SDL_FALSE;
+
+	/* Install RunTimer in vbl vector */
+	oldpile=(void *)Super(0);
+	timer_installed = !SDL_AtariVblInstall(RunTimer);
+	Super(oldpile);
+
+	if (!timer_installed) {
+		return(-1);
+	}
+	return(SDL_SetTimerThreaded(0));
+}
+
+void SDL_SYS_TimerQuit(void)
+{
+	void *oldpile;
+
+	if (timer_installed) {
+		/* Uninstall RunTimer vbl vector */
+		oldpile=(void *)Super(0);
+		SDL_AtariVblUninstall(RunTimer);
+		Super(oldpile);
+		timer_installed = SDL_FALSE;
+	}
+}
+
+int SDL_SYS_StartTimer(void)
+{
+	SDL_SetError("Internal logic error: MiNT uses vbl timer");
+	return(-1);
+}
+
+void SDL_SYS_StopTimer(void)
+{
+	return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/timer/mint/SDL_vbltimer.S	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,137 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	VBL queue routine
+ *
+ *	Patrice Mandin
+ */
+
+#define _vbl_queue 0x456
+
+	.text
+
+	.globl	_SDL_AtariVblInstall
+	.globl	_SDL_AtariVblUninstall
+
+/*--- Vector installer ---*/
+
+_SDL_AtariVblInstall:
+	movel	sp@(4),my_vector
+	lea		_my_vbl,a0
+
+	clrw	vbl_mutex
+
+	/* Stop interrupts */
+
+	movew	#0x2700,sr
+
+	/* Read vbl_queue pointer */
+	movel	_vbl_queue.w,a1
+
+	/* Search a free place */
+	moveq	#7,d0
+bcl_search_place:
+	movel	(a1),d1
+	beqs	place_found
+	addql	#4,a1
+	dbra	d0,bcl_search_place
+
+	/* Not found */
+	moveq	#1,d0
+	bras	exit_vbl_queue
+
+	/* Then install ourselves */
+place_found:
+	movel	a0,(a1)
+	moveq	#0,d0	
+
+exit_vbl_queue:
+	/* Restart interrupts */
+	movew	#0x2300,sr
+
+	rts
+
+/*--- Vector uninstaller ---*/
+
+_SDL_AtariVblUninstall:
+	movel	sp@(4),d0
+	cmpl	my_vector,d0
+	bnes	badvector
+	
+	movel	#_my_vbl,d0
+
+	/* Stop interrupts */
+
+	movew	#0x2700,sr
+
+	/* Read vbl_queue pointer */
+	movel	_vbl_queue.w,a1
+
+	/* Search where we are */
+	moveq	#7,d1
+bcl2_search_place:
+	cmpl	(a1),d0
+	bnes	next_place
+	clrl	(a1)
+	moveq	#0,d1
+next_place:
+	addql	#4,a1
+	dbra	d1,bcl2_search_place
+
+	/* Restart interrupts */
+	movew	#0x2300,sr
+badvector:
+	rts
+
+/*--- Our vbl ---*/
+
+	.text
+	.even
+	.ascii "XBRA"
+	.ascii "_SDL"
+_my_vbl:
+	/* Verify if this is not already running */
+
+	tstw	vbl_mutex
+	bnes	vbl_end
+	notw	vbl_mutex
+
+	moveml	d0-d7/a0-a6,sp@-
+	movel	my_vector,a0
+	jsr		a0@
+	moveml	sp@+,d0-d7/a0-a6
+
+	clrw	vbl_mutex
+vbl_end:
+	rts
+
+	.data
+	.even
+	.comm	vbl_mutex,2*1
+	.even
+	.comm	my_vector,4*1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/timer/mint/SDL_vbltimer_s.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,37 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	TOS/MiNT timer driver
+ *	based on vbl vector
+ *
+ *	Patrice Mandin
+ */
+
+/* Functions prototypes */
+extern int SDL_AtariVblInstall(void *newvector);
+extern void SDL_AtariVblUninstall(void *newvector);
--- a/src/video/Makefile.am	Thu Feb 14 21:26:42 2002 +0000
+++ b/src/video/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -8,7 +8,8 @@
 DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
                wincommon windib windx5 \
                maccommon macdsp macrom quartz \
-               bwindow ps2gs photon cybergfx epoc
+               bwindow ps2gs photon cybergfx epoc \
+               ataricommon xbios gem
 
 DRIVERS = @VIDEO_DRIVERS@
 
--- a/src/video/SDL_sysvideo.h	Thu Feb 14 21:26:42 2002 +0000
+++ b/src/video/SDL_sysvideo.h	Sun Feb 17 19:54:28 2002 +0000
@@ -392,6 +392,12 @@
 #ifdef ENABLE_DUMMYVIDEO
 extern VideoBootStrap DUMMY_bootstrap;
 #endif
+#ifdef ENABLE_XBIOS
+extern VideoBootStrap XBIOS_bootstrap;
+#endif
+#ifdef ENABLE_GEM
+extern VideoBootStrap GEM_bootstrap;
+#endif
 /* This is the current video device */
 extern SDL_VideoDevice *current_video;
 
--- a/src/video/SDL_video.c	Thu Feb 14 21:26:42 2002 +0000
+++ b/src/video/SDL_video.c	Sun Feb 17 19:54:28 2002 +0000
@@ -105,6 +105,12 @@
 #ifdef ENABLE_DUMMYVIDEO
 	&DUMMY_bootstrap,
 #endif
+#ifdef ENABLE_XBIOS
+	&XBIOS_bootstrap,
+#endif
+#ifdef ENABLE_GEM
+	&GEM_bootstrap,
+#endif
 	NULL
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,31 @@
+
+## Makefile.am for SDL using the Atari bios
+
+noinst_LTLIBRARIES = libvideo_ataricommon.la
+libvideo_ataricommon_la_SOURCES = $(ATARICOMMON_SRCS)
+
+# The SDL Atari bios driver sources
+ATARICOMMON_SRCS = 	\
+	SDL_ataric2p.S	\
+	SDL_ataric2p_s.h	\
+	SDL_ataric2p060.c	\
+	SDL_ataric2p060_c.h	\
+	SDL_atarieddi.S	\
+	SDL_atarieddi_s.h	\
+	SDL_atarievents.c	\
+	SDL_atarievents_c.h	\
+	SDL_atarikeys.h	\
+	SDL_atarimxalloc.c	\
+	SDL_atarimxalloc_c.h	\
+	SDL_biosevents.c	\
+	SDL_biosevents_c.h	\
+	SDL_gemdosevents.c	\
+	SDL_gemdosevents_c.h \
+	SDL_ikbdevents.c	\
+	SDL_ikbdevents_c.h \
+	SDL_ikbdinterrupt.S	\
+	SDL_ikbdinterrupt_s.h \
+	SDL_xbiosmouseevents.c \
+	SDL_xbiosmouseevents_c.h \
+	SDL_xbiosmouseinterrupt.S \
+	SDL_xbiosmouseinterrupt_s.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ataric2p.S	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,377 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Chunky to planar conversion routine
+ *	1 byte/pixel -> 4 or 8 bit planes
+ *
+ *	Patrice Mandin
+ *	Xavier Joubert
+ */
+
+/* ------------	Function pointers ------------ */
+
+	.globl	_Atari_C2pInit
+	.globl	_Atari_C2pConvert
+
+	.data
+
+	.even
+	.comm	_Atari_C2pInit,4
+	.comm	_Atari_C2pConvert,4
+
+/* ------------	Conversion Table C2P ------------ */
+
+	.globl	_Atari_table_c2p
+
+	.data
+
+	.comm	_Atari_table_c2p,2048
+
+/* ------------	Init table C2P, 8 bits ------------ */
+
+	.globl	_Atari_C2pInit8
+
+	.text
+_Atari_C2pInit8:
+	movel	d2,sp@-
+
+	lea	_Atari_table_c2p,a0
+	movew	#255,d0
+c2p_initbcl:
+#if defined (__M68020__)
+	lea	a0@(0,d0:w:8),a1
+#else
+	movew	d0,d2
+	lslw	#3,d2
+	lea	a0@(0,d2:w),a1
+#endif
+	moveq	#7,d1
+c2p_initbyte:
+	btst	d1,d0
+	sne	d2
+	negw	d2
+	moveb	d2,a1@(0,d1:w)
+
+	dbra	d1,c2p_initbyte
+
+	dbra	d0,c2p_initbcl
+
+	movel	sp@+,d2
+	rts
+
+/* ------------	Conversion C2P, 8 bits ------------ */
+
+	.globl	_Atari_C2pConvert8
+
+	.text
+_Atari_C2pConvert8:
+	movel	sp@(4),c2p_source
+	movel	sp@(8),c2p_dest
+	movel	sp@(12),c2p_width
+	movel	sp@(16),c2p_height
+	movel	sp@(20),c2p_dblligne
+	movel	sp@(24),c2p_srcpitch
+	movel	sp@(28),c2p_dstpitch
+
+	moveml	d2-d7/a2-a6,sp@-
+
+	movel	c2p_source,a0
+	movel	c2p_dest,a1
+	lea	_Atari_table_c2p,a2
+	movel	#0x000f0001,d3
+#if defined(__M68020__)
+	moveq	#0,d0
+#endif
+	
+	movel	c2p_height,d7
+	subql	#1,d7
+c2p8_bcly:
+	movel	a0,a4	| Save start address of source
+	movel	a1,a5	| Save start address of dest
+
+	| Conversion
+                 
+	movel	c2p_width,d6
+	lsrw	#4,d6
+	subql	#1,d6
+c2p8_bclx:
+	| Octets 0-7
+	
+	moveq	#0,d1
+	moveq	#0,d2
+	moveq	#7,d5
+c2p8_bcl07:
+#if defined(__M68020__)
+	moveb	a0@+,d0
+	lea	a2@(0,d0:w:8),a3
+#else
+	moveq	#0,d0
+	moveb	a0@+,d0
+	lslw	#3,d0
+	lea	a2@(0,d0:w),a3
+#endif
+	lsll	#1,d1
+	lsll	#1,d2
+	orl	a3@+,d1
+	orl	a3@,d2
+	dbra	d5,c2p8_bcl07
+
+	movepl	d1,a1@(0)
+	movepl	d2,a1@(8)
+	addw	d3,a1
+	swap	d3
+	
+	| Octets 8-15
+
+	moveq	#0,d1
+	moveq	#0,d2
+	moveq	#7,d5
+c2p8_bcl815:
+#if defined(__M68020__)
+	moveb	a0@+,d0
+	lea	a2@(0,d0:w:8),a3
+#else
+	moveq	#0,d0
+	moveb	a0@+,d0
+	lslw	#3,d0
+	lea	a2@(0,d0:w),a3
+#endif
+	lsll	#1,d1
+	lsll	#1,d2
+	orl	a3@+,d1
+	orl	a3@,d2
+	dbra	d5,c2p8_bcl815
+
+	movepl	d1,a1@(0)
+	movepl	d2,a1@(8)
+	addw	d3,a1
+	swap	d3
+
+	dbra	d6,c2p8_bclx
+
+	| Double line ?
+
+	tstl	c2p_dblligne
+	beq	c2p8_nodblligne
+
+	movel	a5,a6			| src line
+	movel	a5,a1			| dest line
+	addl	c2p_dstpitch,a1
+
+	movel	c2p_width,d6
+	lsrw	#2,d6
+	subql	#1,d6
+c2p8_copydbl:
+	movel	a6@+,a1@+
+	dbra	d6,c2p8_copydbl
+
+	addl	c2p_dstpitch,a5
+c2p8_nodblligne:
+
+	| Next line
+
+	movel	a4,a0		
+	addl	c2p_srcpitch,a0
+	movel	a5,a1
+	addl	c2p_dstpitch,a1
+
+	dbra	d7,c2p8_bcly
+
+	moveml	sp@+,d2-d7/a2-a6
+	rts
+
+/* ------------	Init table C2P, 4 bits ------------ */
+
+	.globl	_Atari_C2pInit4
+
+	.text
+_Atari_C2pInit4:
+	/* Nothing to do */
+	/* work is done in convert_c2p_pal */
+	rts
+
+/* ------------	Conversion C2P, 4 bits ------------ */
+
+	.globl	_Atari_C2pConvert4
+
+	.text
+_Atari_C2pConvert4:
+	movel	sp@(4),c2p_source
+	movel	sp@(8),c2p_dest
+	movel	sp@(12),c2p_width
+	movel	sp@(16),c2p_height
+	movel	sp@(20),c2p_dblligne
+	movel	sp@(24),c2p_srcpitch
+	movel	sp@(28),c2p_dstpitch
+
+	moveml	d2-d7/a2-a6,sp@-
+
+	movel	c2p_source,a0
+	movel	c2p_dest,a1
+	lea	_Atari_table_c2p,a2
+	movel	#0x00070001,d3
+#if defined(__M68020__)
+	moveq	#0,d0
+#endif
+	
+	movel	c2p_height,d7
+	subql	#1,d7
+c2p4_bcly:
+	movel	a0,a4	| Save start address of source
+	movel	a1,a5	| Save start address of dest
+
+	| Conversion
+                 			
+	movel	c2p_width,d6
+	lsrw	#4,d6
+	subql	#1,d6
+c2p4_bclx:
+	| Octets 0-7
+	
+	moveq	#0,d1
+	moveq	#7,d5
+c2p4_bcl07:
+#if defined(__M68020__)
+	moveb	a0@+,d0
+	lea	a2@(0,d0:w:4),a3
+#else
+	moveq	#0,d0
+	moveb	a0@+,d0
+	lslw	#2,d0
+	lea	a2@(0,d0:w),a3
+#endif
+	lsll	#1,d1
+	orl	a3@,d1
+	dbra	d5,c2p4_bcl07
+
+	movepl	d1,a1@(0)
+	addw	d3,a1
+	swap	d3
+	
+	| Octets 8-15
+
+	moveq	#0,d1
+	moveq	#7,d5
+c2p4_bcl815:
+#if defined(__M68020__)
+	moveb	a0@+,d0
+	lea	a2@(0,d0:w:4),a3
+#else
+	moveq	#0,d0
+	moveb	a0@+,d0
+	lslw	#2,d0
+	lea	a2@(0,d0:w),a3
+#endif
+	lsll	#1,d1
+	orl	a3@,d1
+	dbra	d5,c2p4_bcl815
+
+	movepl	d1,a1@(0)
+	addw	d3,a1
+	swap	d3
+
+	dbra	d6,c2p4_bclx
+
+	| Double line ?
+
+	tstl	c2p_dblligne
+	beq	c2p4_nodblligne
+
+	movel	a5,a6			| src line
+	movel	a5,a1			| dest line
+	addl	c2p_dstpitch,a1
+
+	movel	c2p_width,d6
+	lsrw	#3,d6
+	subql	#1,d6
+c2p4_copydbl:
+	movel	a6@+,a1@+
+	dbra	d6,c2p4_copydbl
+
+	addl	c2p_dstpitch,a5
+c2p4_nodblligne:
+
+	| Next line
+
+	movel	a4,a0		
+	addl	c2p_srcpitch,a0
+	movel	a5,a1
+	addl	c2p_dstpitch,a1
+
+	dbra	d7,c2p4_bcly
+
+	moveml	sp@+,d2-d7/a2-a6
+	rts
+
+* ------------	Conversion of a light palette in 4 bits ------------ */
+
+	.globl	_Atari_C2pConvert4_pal
+
+	.text
+_Atari_C2pConvert4_pal:
+	/* a0 is a 256-word light palette */
+	movel	sp@(4),a0
+
+	moveml	d2-d3,sp@-
+
+	lea	_Atari_table_c2p,a1
+	movew	#255,d3
+c2p_pal_initbcl:
+	movew	a0@+,d0
+	lsrw	#4,d0
+	and	#15,d0
+
+	moveq	#3,d1
+c2p_pal_initbyte:
+	btst	d1,d0
+	sne	d2
+	negw	d2
+	moveb	d2,a1@(0,d1:w)
+
+	dbra	d1,c2p_pal_initbyte
+
+	addql	#4,a1
+	dbra	d3,c2p_pal_initbcl
+
+	moveml	sp@+,d2-d3
+
+	rts
+
+/* ------------	Buffers ------------ */
+
+	.data
+
+	.even
+	.comm	c2p_source,4
+	.comm	c2p_dest,4
+	.comm	c2p_width,4
+	.comm	c2p_height,4
+	.comm	c2p_dblligne,4
+	.comm	c2p_srcpitch,4
+	.comm	c2p_dstpitch,4
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ataric2p060.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,203 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Chunky to planar conversion routine
+ *  for 68060 CPU, without movep instruction
+ *	1 byte/pixel -> 4 or 8 bit planes
+ *
+ *	Patrice Mandin
+ */
+
+#include <string.h>
+
+#include <sys/cookie.h>
+
+#include "SDL_ataric2p_s.h"
+
+/*--- Variables ---*/
+
+/* CPU is 060 ? */
+int atari_cpu060_avail;
+
+/*--- Functions ---*/
+
+void atari_test_cpu060_present(void)
+{
+	unsigned long cookie_cpu;
+
+	atari_cpu060_avail=0;
+
+	/* Cookie _CPU present ? */
+	if (Getcookie(C__CPU, &cookie_cpu) == C_FOUND) {
+		atari_cpu060_avail = (cookie_cpu == 60);
+	}
+}
+
+void Atari_C2pConvert8_060(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (8 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+)
+{
+	int x,y,z;
+	Uint8 *src_line, *dst_line;
+
+	for (y=0; y<height; y++) {
+		src_line = src;
+		dst_line = dest;
+
+		for (x=0; x<(width>>4); x++) {
+			Uint32 somme1, somme2;
+			Uint32 *convtable;
+
+			/* bytes 0-7 */
+			somme1 = somme2 = 0;
+			for (z=0; z<8 ;z++) {
+				convtable = (Uint32 *) &Atari_table_c2p[(*src_line++)<<3];
+				somme1 <<= 1;
+				somme2 <<= 1;
+				somme1 |= *convtable++;
+				somme2 |= *convtable;
+			}
+
+			*(dst_line+14) = somme2;	/* 000000FF */
+			*(dst_line+6) = somme1;		/* 000000FF */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+12) = somme2;	/* 0000FF00 */
+			*(dst_line+4) = somme1;		/* 0000FF00 */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+10) = somme2;	/* 00FF0000 */
+			*(dst_line+2) = somme1;		/* 00FF0000 */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+8) = somme2;		/* FF000000 */
+			*dst_line++ = somme1;		/* FF000000 */
+
+			/* bytes 8-15 */
+			somme1 = somme2 = 0;
+			for (z=0; z<8 ;z++) {
+				convtable = (Uint32 *) &Atari_table_c2p[(*src_line++)<<3];
+				somme1 <<= 1;
+				somme2 <<= 1;
+				somme1 |= *convtable++;
+				somme2 |= *convtable;
+			}
+
+			*(dst_line+14) = somme2;	/* 000000FF */
+			*(dst_line+6) = somme1;		/* 000000FF */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+12) = somme2;	/* 0000FF00 */
+			*(dst_line+4) = somme1;		/* 0000FF00 */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+10) = somme2;	/* 00FF0000 */
+			*(dst_line+2) = somme1;		/* 00FF0000 */
+			somme2 >>= 8;
+			somme1 >>= 8;
+			*(dst_line+8) = somme2;		/* FF000000 */
+			*dst_line = somme1;			/* FF000000 */
+
+			dst_line += 15;
+		}
+
+		if (dblligne) {
+			memcpy(dest+dstpitch, dest, width);
+			dest += dstpitch;
+		}
+
+		src += srcpitch;
+		dest += dstpitch;
+	}
+}
+
+void Atari_C2pConvert4_060(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (4 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+)
+{
+	int x,y,z;
+	Uint8 *src_line, *dst_line;
+
+	for (y=0;y<height;y++) {
+		src_line = src;
+		dst_line = dest;
+
+		for (x=0; x<(width>>4);x++) {
+			Uint32 somme;
+			Uint32 *convtable;
+
+			/* bytes 0-7 */
+			somme=0;
+			for (z=0; z<8 ; z++) {
+				convtable = (Uint32 *) &Atari_table_c2p[(*src_line++)<<2];
+				somme <<= 1;
+				somme |= *convtable;
+			}
+
+			*(dst_line+6) = somme; somme >>= 8;	/* 000000FF */
+			*(dst_line+4) = somme; somme >>= 8;	/* 0000FF00 */
+			*(dst_line+2) = somme; somme >>= 8;	/* 00FF0000 */
+			*dst_line++ = somme;				/* FF000000 */
+
+			/* bytes 8-15 */
+			somme = 0;
+			for (z=0; z<8 ;z++) {
+				convtable = (Uint32 *) &Atari_table_c2p[(*src_line++)<<2];
+				somme <<= 1;
+				somme |= *convtable;
+			}
+
+			*(dst_line+6) = somme; somme >>= 8;	/* 000000FF */
+			*(dst_line+4) = somme; somme >>= 8;	/* 0000FF00 */
+			*(dst_line+2) = somme; somme >>= 8;	/* 00FF0000 */
+			*dst_line = somme;					/* FF000000 */
+
+			dst_line += 7;
+		}
+
+		if (dblligne) {
+			memcpy(dest+dstpitch, dest, width>>1);
+			dest += dstpitch;
+		}
+
+		src += srcpitch;
+		dest += dstpitch;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ataric2p060_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,67 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Chunky to planar conversion routine
+ *  for 68060 CPU, without movep instruction
+ *	1 byte/pixel -> 4 or 8 bit planes
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_C2P060_H_
+#define _SDL_ATARI_C2P060_H_
+
+/*--- Variables ---*/
+
+extern int atari_cpu060_avail;
+
+/*--- Functions ---*/
+
+extern void atari_test_cpu060_present(void);
+
+extern void Atari_C2pConvert8_060(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (8 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+);
+
+extern void Atari_C2pConvert4_060(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (4 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+);
+
+#endif /* _SDL_ATARI_C2P060_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ataric2p_s.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,95 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#ifndef _ATARI_C2P_h
+#define _ATARI_C2P_h
+
+#include "SDL_types.h"
+
+/*--- Variables ---*/
+
+extern Uint8 Atari_table_c2p[2048];	/* Used by conversions routines */
+
+/*--- Functions pointers ---*/
+
+/* Initialize conversion table */
+
+extern void (*Atari_C2pInit)(void);
+
+/* Convert a chunky screen to bitplane screen */
+
+extern void (*Atari_C2pConvert)(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (4/8 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+);
+
+/*--- 8 bits functions ---*/
+
+/* Initialize conversion table */
+
+void Atari_C2pInit8(void);
+
+/* Convert a chunky screen to bitplane screen */
+
+void Atari_C2pConvert8(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (8 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+);
+
+/*--- 4 bits functions ---*/
+
+/* Initialize conversion table */
+
+void Atari_C2pInit4(void);
+
+/* Convert a chunky screen to bitplane screen */
+
+void Atari_C2pConvert4(
+	Uint8 *src,			/* Source screen (one byte=one pixel) */
+	Uint8 *dest,		/* Destination (4 bits planes) */
+	Uint32 width,		/* Dimensions of screen to convert */
+	Uint32 height,
+	Uint32 dblligne,	/* Double the lines when converting ? */
+	Uint32 srcpitch,	/* Length of one source line in bytes */
+	Uint32 dstpitch		/* Length of one destination line in bytes */
+);
+
+/* Conversion palette */
+
+void Atari_C2pConvert4_pal(Uint16 *lightpalette);
+
+#endif /* _ATARI_C2P_h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarieddi.S	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,47 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Read EdDI version
+ *
+ *	Patrice Mandin
+ */
+
+	.text
+
+	.globl	_Atari_get_EdDI_version
+
+/*--- Vector installer ---*/
+
+_Atari_get_EdDI_version:
+	movel	sp@(4),a0	/* Value of EdDI cookie */
+
+	/* Call EdDI function #0 */
+	clrw	d0
+	jsr	(a0)
+
+	rts
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarieddi_s.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,58 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#ifndef _SDL_Atari_eddi_s_h
+#define _SDL_Atari_eddi_s_h
+
+/*--- Defines ---*/
+
+/* EdDI versions */
+
+#define EDDI_10	(0x0100)
+#define EDDI_11 (0x0110)
+
+/* Screen format */
+
+enum {
+	VDI_FORMAT_UNKNOWN=-1,
+	VDI_FORMAT_INTER=0,	/* Interleaved bitplanes */
+	VDI_FORMAT_VDI=1,	/* VDI independent */
+	VDI_FORMAT_PACK=2	/* Packed pixels */
+};
+
+/* CLUT types */
+enum {
+	VDI_CLUT_NONE=0,	/* Monochrome mode */
+	VDI_CLUT_HARDWARE,	/* <256 colours mode */
+	VDI_CLUT_SOFTWARE	/* True colour mode */
+};
+
+/*--- Functions ---*/
+
+unsigned long Atari_get_EdDI_version(void *function_pointer);
+
+#endif /* _SDL_Atari_eddi_s_h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarievents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,126 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager
+ *
+ *	Patrice Mandin
+ *
+ *	This routines choose what the final event manager will be
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/cookie.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+
+#include "SDL_atarievents_c.h"
+#include "SDL_biosevents_c.h"
+#include "SDL_gemdosevents_c.h"
+#include "SDL_ikbdevents_c.h"
+
+enum {
+	MCH_ST=0,
+	MCH_STE,
+	MCH_TT,
+	MCH_F30
+};
+
+void (*Atari_ShutdownEvents)(void);
+
+static void Atari_InitializeEvents(_THIS)
+{
+	const char *envr;
+	unsigned long cookie_mch;
+
+	/* Test if we are on an Atari machine or not */
+	if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
+		cookie_mch = 0;
+	}
+	cookie_mch >>= 16;
+
+	/* Default is Ikbd, the faster except for clones */
+	switch(cookie_mch) {
+		case MCH_ST:
+		case MCH_STE:
+		case MCH_TT:
+		case MCH_F30:
+			this->InitOSKeymap=AtariIkbd_InitOSKeymap;
+			this->PumpEvents=AtariIkbd_PumpEvents;
+			Atari_ShutdownEvents=AtariIkbd_ShutdownEvents;
+			break;
+		default:
+			this->InitOSKeymap=AtariGemdos_InitOSKeymap;
+			this->PumpEvents=AtariGemdos_PumpEvents;
+			Atari_ShutdownEvents=AtariGemdos_ShutdownEvents;
+			break;
+	}
+
+	envr = getenv("SDL_ATARI_EVENTSDRIVER");
+
+ 	if (!envr) {
+		return;
+	}
+
+	if (strcmp(envr, "ikbd") == 0) {
+		this->InitOSKeymap=AtariIkbd_InitOSKeymap;
+		this->PumpEvents=AtariIkbd_PumpEvents;
+		Atari_ShutdownEvents=AtariIkbd_ShutdownEvents;
+	}
+
+	if (strcmp(envr, "gemdos") == 0) {
+		this->InitOSKeymap=AtariGemdos_InitOSKeymap;
+		this->PumpEvents=AtariGemdos_PumpEvents;
+		Atari_ShutdownEvents=AtariGemdos_ShutdownEvents;
+	}
+
+	if (strcmp(envr, "bios") == 0) {
+		this->InitOSKeymap=AtariBios_InitOSKeymap;
+		this->PumpEvents=AtariBios_PumpEvents;
+		Atari_ShutdownEvents=AtariBios_ShutdownEvents;
+	}
+}
+
+void Atari_InitOSKeymap(_THIS)
+{
+	Atari_InitializeEvents(this);
+
+	/* Call choosen routine */
+	this->InitOSKeymap(this);
+}
+
+void Atari_PumpEvents(_THIS)
+{
+	Atari_InitializeEvents(this);
+
+	/* Call choosen routine */
+	this->PumpEvents(this);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarievents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,47 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_EVENTS_H_
+#define _SDL_ATARI_EVENTS_H_
+
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+extern void (*Atari_ShutdownEvents)(void);
+
+extern void Atari_InitOSKeymap(_THIS);
+extern void Atari_PumpEvents(_THIS);
+
+#endif /* _SDL_ATARI_EVENTS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarikeys.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,145 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari Scancode definitions
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARIKEYS_H_
+#define _SDL_ATARIKEYS_H_ 
+
+/* --- Keyboard scancodes --- */
+/* taken from svgalib/vgakeyboard.h */
+
+#define SCANCODE_ESCAPE		0x01
+#define SCANCODE_1		0x02
+#define SCANCODE_2		0x03
+#define SCANCODE_3		0x04
+#define SCANCODE_4		0x05
+#define SCANCODE_5		0x06
+#define SCANCODE_6		0x07
+#define SCANCODE_7		0x08
+#define SCANCODE_8		0x09
+#define SCANCODE_9		0x0a
+#define SCANCODE_0		0x0b
+#define SCANCODE_MINUS		0x0c
+#define SCANCODE_EQUAL		0x0d
+#define SCANCODE_BACKSPACE	0x0e
+
+#define SCANCODE_TAB		0x0f
+#define SCANCODE_Q		0x10
+#define SCANCODE_W		0x11
+#define SCANCODE_E		0x12
+#define SCANCODE_R		0x13
+#define SCANCODE_T		0x14
+#define SCANCODE_Y		0x15
+#define SCANCODE_U		0x16
+#define SCANCODE_I		0x17
+#define SCANCODE_O		0x18
+#define SCANCODE_P		0x19
+#define SCANCODE_BRACKET_LEFT	0x1a
+#define SCANCODE_BRACKET_RIGHT	0x1b
+#define SCANCODE_ENTER		0x1c
+#define SCANCODE_DELETE		0x53
+
+#define SCANCODE_LEFTCONTROL	0x1d
+#define SCANCODE_A		0x1e
+#define SCANCODE_S		0x1f
+#define SCANCODE_D		0x20
+#define SCANCODE_F		0x21
+#define SCANCODE_G		0x22
+#define SCANCODE_H		0x23
+#define SCANCODE_J		0x24
+#define SCANCODE_K		0x25
+#define SCANCODE_L		0x26
+#define SCANCODE_SEMICOLON	0x27
+#define SCANCODE_APOSTROPHE	0x28
+#define SCANCODE_GRAVE		0x29
+
+#define SCANCODE_LEFTSHIFT	0x2a
+#define SCANCODE_BACKSLASH	0x2b
+#define SCANCODE_Z		0x2c
+#define SCANCODE_X		0x2d
+#define SCANCODE_C		0x2e
+#define SCANCODE_V		0x2f
+#define SCANCODE_B		0x30
+#define SCANCODE_N		0x31
+#define SCANCODE_M		0x32
+#define SCANCODE_COMMA		0x33
+#define SCANCODE_PERIOD		0x34
+#define SCANCODE_SLASH		0x35
+#define SCANCODE_RIGHTSHIFT	0x36
+
+#define SCANCODE_LEFTALT	0x38
+#define SCANCODE_SPACE		0x39
+#define SCANCODE_CAPSLOCK	0x3a
+
+/* Functions keys */
+#define SCANCODE_F1		0x3b
+#define SCANCODE_F2		0x3c
+#define SCANCODE_F3		0x3d
+#define SCANCODE_F4		0x3e
+#define SCANCODE_F5		0x3f
+#define SCANCODE_F6		0x40
+#define SCANCODE_F7		0x41
+#define SCANCODE_F8		0x42
+#define SCANCODE_F9		0x43
+#define SCANCODE_F10	0x44
+
+/* Numeric keypad */
+#define SCANCODE_KP0			0x70
+#define SCANCODE_KP1			0x6d
+#define SCANCODE_KP2			0x6e
+#define SCANCODE_KP3			0x6f
+#define SCANCODE_KP4			0x6a
+#define SCANCODE_KP5			0x6b
+#define SCANCODE_KP6			0x6c
+#define SCANCODE_KP7			0x67
+#define SCANCODE_KP8			0x68
+#define SCANCODE_KP9			0x69
+#define SCANCODE_KP_PERIOD		0x71
+#define SCANCODE_KP_DIVIDE		0x65
+#define SCANCODE_KP_MULTIPLY	0x66
+#define SCANCODE_KP_MINUS		0x4a
+#define SCANCODE_KP_PLUS		0x4e
+#define SCANCODE_KP_ENTER		0x72
+#define SCANCODE_KP_LEFTPAREN	0x63
+#define SCANCODE_KP_RIGHTPAREN	0x64
+
+/* Cursor keypad */
+#define SCANCODE_HELP		0x62
+#define SCANCODE_UNDO		0x61
+#define SCANCODE_INSERT		0x52
+#define SCANCODE_CLRHOME	0x47
+#define SCANCODE_UP			0x48
+#define SCANCODE_DOWN		0x50
+#define SCANCODE_RIGHT		0x4d
+#define SCANCODE_LEFT		0x4b
+
+#endif /* _SDL_ATARIKEYS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarimxalloc.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,56 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Memory allocation
+ *
+ *	Patrice Mandin
+ */
+
+#include <mint/osbind.h>
+
+#include "SDL_types.h"
+
+/*--- Variables ---*/
+
+static int atari_mxalloc_avail=-1;
+
+/*--- Functions ---*/
+
+void *Atari_SysMalloc(Uint32 size, Uint16 alloc_type)
+{
+	/* Test if Mxalloc() available */
+	if (atari_mxalloc_avail<0) {
+		atari_mxalloc_avail = ((Sversion()&0xFF)>=0x01) | (Sversion()>=0x1900);
+	}
+
+	if (atari_mxalloc_avail) {
+		return (void *) Mxalloc(size, alloc_type);
+	} else { \
+		return (void *) Malloc(size);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_atarimxalloc_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,49 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Memory allocation
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_MXALLOC_H_
+#define _SDL_ATARI_MXALLOC_H_
+
+/*--- Defines ---*/
+
+/* Mxalloc parameters */
+#define MX_STRAM 0
+#define MX_TTRAM 1
+#define MX_PREFSTRAM 2
+#define MX_PREFTTRAM 3
+
+/*--- Functions ---*/
+
+extern void *Atari_SysMalloc(Uint32 size, Uint16 alloc_type);
+
+#endif /* _SDL_ATARI_MXALLOC_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_biosevents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,187 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using BIOS
+ *
+ *	Patrice Mandin
+ */
+
+#include <string.h>
+
+/* Mint includes */
+#include <mint/osbind.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+
+#include "SDL_atarikeys.h"
+#include "SDL_xbiosmouseevents_c.h"
+
+/* To save state of keyboard */
+#define ATARIBIOS_MAXKEYS 128
+
+static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
+
+/* Special keys state */
+enum {
+	K_RSHIFT=0,
+	K_LSHIFT,
+	K_CTRL,
+	K_ALT,
+	K_CAPSLOCK,
+	K_CLRHOME,
+	K_INSERT
+};
+
+/* The translation tables from a console scancode to a SDL keysym */
+static SDLKey keymap[ATARIBIOS_MAXKEYS];
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
+static void UpdateSpecialKeys(int special_keys_state);
+
+void AtariBios_InitOSKeymap(_THIS)
+{
+	int i;
+
+	memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
+	memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
+
+	/* Initialize keymap */
+	for ( i=0; i<sizeof(keymap); i++ )
+		keymap[i] = SDLK_UNKNOWN;
+
+	/* Functions keys */
+	for ( i = 0; i<10; i++ )
+		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
+
+	/* Cursor keypad */
+	keymap[SCANCODE_HELP] = SDLK_HELP;
+	keymap[SCANCODE_UNDO] = SDLK_UNDO;
+	keymap[SCANCODE_INSERT] = SDLK_INSERT;
+	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
+	keymap[SCANCODE_UP] = SDLK_UP;
+	keymap[SCANCODE_DOWN] = SDLK_DOWN;
+	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
+	keymap[SCANCODE_LEFT] = SDLK_LEFT;
+
+	/* Special keys */
+	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
+	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
+	keymap[SCANCODE_TAB] = SDLK_TAB;
+	keymap[SCANCODE_ENTER] = SDLK_RETURN;
+	keymap[SCANCODE_DELETE] = SDLK_DELETE;
+	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
+	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
+	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
+	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
+	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+
+	AtariXbios_InstallMouseVector();
+}
+
+void AtariBios_PumpEvents(_THIS)
+{
+	int i;
+	SDL_keysym keysym;
+
+	/* Update pressed keys */
+	memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
+
+	while (Bconstat(_CON)) {
+		unsigned long key_pressed;
+		unsigned char asciicode, scancode;
+
+		key_pressed=Bconin(_CON);
+
+		asciicode = key_pressed;
+		scancode = key_pressed >> 16;
+
+		bios_currentkeyboard[scancode]=0xFF;
+		bios_currentascii[scancode]=asciicode;
+	}
+
+	/* Read special keys */
+	UpdateSpecialKeys(Kbshift(-1));
+
+	/* Now generate events */
+	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
+		/* Key pressed ? */
+		if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
+			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, bios_currentascii[i], &keysym));
+			
+		/* Key unpressed ? */
+		if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
+			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, 0, &keysym));
+	}
+
+	AtariXbios_PostMouseEvents(this);
+
+	/* Will be previous table */
+	memcpy(bios_previouskeyboard, bios_currentkeyboard, ATARIBIOS_MAXKEYS);
+}
+
+static void UpdateSpecialKeys(int special_keys_state)
+{
+#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
+	{	\
+		if (special_keys_state & (1<<(numbit))) { \
+			bios_currentkeyboard[scancode]=0xFF; \
+			bios_currentascii[scancode]=0; \
+		}	\
+	}
+
+	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
+	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
+	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
+	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
+	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
+}
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
+{
+	/* Set the keysym information */
+	keysym->scancode = scancode;
+
+	if (asciicode)
+		keysym->sym = asciicode;		
+	else
+		keysym->sym = keymap[scancode];
+
+	keysym->mod = KMOD_NONE;
+	keysym->unicode = 0;
+
+	return(keysym);
+}
+
+void AtariBios_ShutdownEvents(void)
+{
+	AtariXbios_RestoreMouseVector();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_biosevents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,46 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using BIOS
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_BIOSEVENTS_H_
+#define _SDL_ATARI_BIOSEVENTS_H_
+
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+extern void AtariBios_InitOSKeymap(_THIS);
+extern void AtariBios_PumpEvents(_THIS);
+extern void AtariBios_ShutdownEvents(void);
+
+#endif /* _SDL_ATARI_BIOSEVENTS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_gemdosevents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,192 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using Gemdos
+ *
+ *	Patrice Mandin
+ */
+
+#include <string.h>
+
+/* Mint includes */
+#include <mint/osbind.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+
+#include "SDL_atarikeys.h"
+#include "SDL_xbiosmouseevents_c.h"
+
+/* To save state of keyboard */
+#define ATARIBIOS_MAXKEYS 128
+
+static unsigned char gemdos_currentkeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char gemdos_previouskeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char gemdos_currentascii[ATARIBIOS_MAXKEYS];
+
+/* Special keys state */
+enum {
+	K_RSHIFT=0,
+	K_LSHIFT,
+	K_CTRL,
+	K_ALT,
+	K_CAPSLOCK,
+	K_CLRHOME,
+	K_INSERT
+};
+
+enum {
+	DEV_BUSY=0,
+	DEV_READY
+};
+
+/* The translation tables from a console scancode to a SDL keysym */
+static SDLKey keymap[ATARIBIOS_MAXKEYS];
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
+static void UpdateSpecialKeys(int special_keys_state);
+
+void AtariGemdos_InitOSKeymap(_THIS)
+{
+	int i;
+
+	memset(gemdos_currentkeyboard, 0, sizeof(gemdos_currentkeyboard));
+	memset(gemdos_previouskeyboard, 0, sizeof(gemdos_previouskeyboard));
+
+	/* Initialize keymap */
+	for ( i=0; i<sizeof(keymap); i++ )
+		keymap[i] = SDLK_UNKNOWN;
+
+	/* Functions keys */
+	for ( i = 0; i<10; i++ )
+		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
+
+	/* Cursor keypad */
+	keymap[SCANCODE_HELP] = SDLK_HELP;
+	keymap[SCANCODE_UNDO] = SDLK_UNDO;
+	keymap[SCANCODE_INSERT] = SDLK_INSERT;
+	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
+	keymap[SCANCODE_UP] = SDLK_UP;
+	keymap[SCANCODE_DOWN] = SDLK_DOWN;
+	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
+	keymap[SCANCODE_LEFT] = SDLK_LEFT;
+
+	/* Special keys */
+	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
+	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
+	keymap[SCANCODE_TAB] = SDLK_TAB;
+	keymap[SCANCODE_ENTER] = SDLK_RETURN;
+	keymap[SCANCODE_DELETE] = SDLK_DELETE;
+	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
+	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
+	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
+	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
+	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+
+	AtariXbios_InstallMouseVector();
+}
+
+void AtariGemdos_PumpEvents(_THIS)
+{
+	int i;
+	SDL_keysym keysym;
+
+	/* Update pressed keys */
+	memset(gemdos_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
+
+	while (Cconis()!=DEV_BUSY) {
+		unsigned long key_pressed;
+		unsigned char scancode, asciicode;
+
+		key_pressed=Cnecin();
+
+		asciicode = key_pressed;
+		scancode = key_pressed >> 16;
+
+		gemdos_currentkeyboard[scancode]=0xFF;
+		gemdos_currentascii[scancode]=asciicode;
+	}
+
+	/* Read special keys */
+	UpdateSpecialKeys(Kbshift(-1));
+
+	/* Now generate events */
+	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
+		/* Key pressed ? */
+		if (gemdos_currentkeyboard[i] && !gemdos_previouskeyboard[i])
+			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gemdos_currentascii[i], &keysym));
+			
+		/* Key unpressed ? */
+		if (gemdos_previouskeyboard[i] && !gemdos_currentkeyboard[i])
+			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, 0, &keysym));
+	}
+
+	AtariXbios_PostMouseEvents(this);
+
+	/* Will be previous table */
+	memcpy(gemdos_previouskeyboard, gemdos_currentkeyboard, ATARIBIOS_MAXKEYS);
+}
+
+static void UpdateSpecialKeys(int special_keys_state)
+{
+#define UPDATE_SPECIAL_KEYS(numbit,scancode) \
+	{	\
+		if (special_keys_state & (1<<(numbit))) { \
+			gemdos_currentkeyboard[scancode]=0xFF; \
+			gemdos_currentascii[scancode]=0; \
+		}	\
+	}
+
+	UPDATE_SPECIAL_KEYS(K_RSHIFT, SCANCODE_RIGHTSHIFT);
+	UPDATE_SPECIAL_KEYS(K_LSHIFT, SCANCODE_LEFTSHIFT);
+	UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
+	UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
+	UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
+}
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
+{
+	/* Set the keysym information */
+	keysym->scancode = scancode;
+
+	if (asciicode)
+		keysym->sym = asciicode;		
+	else
+		keysym->sym = keymap[scancode];
+
+	keysym->mod = KMOD_NONE;
+	keysym->unicode = 0;
+
+	return(keysym);
+}
+
+void AtariGemdos_ShutdownEvents(void)
+{
+	AtariXbios_RestoreMouseVector();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_gemdosevents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,46 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using Gemdos
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_GEMDOSEVENTS_H_
+#define _SDL_ATARI_GEMDOSEVENTS_H_
+
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+extern void AtariGemdos_InitOSKeymap(_THIS);
+extern void AtariGemdos_PumpEvents(_THIS);
+extern void AtariGemdos_ShutdownEvents(void);
+
+#endif /* _SDL_ATARI_GEMDOSEVENTS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ikbdevents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,241 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using hardware IKBD
+ *
+ *	Patrice Mandin
+ */
+
+#include <string.h>
+
+/* Mint includes */
+#include <mint/osbind.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+
+#include "SDL_atarikeys.h"
+#include "SDL_ikbdinterrupt_s.h"
+
+/* Special keys state */
+enum {
+	K_RSHIFT=0,
+	K_LSHIFT,
+	K_CTRL,
+	K_ALT,
+	K_CAPSLOCK,
+	K_CLRHOME,
+	K_INSERT
+};
+
+/* To save state of keyboard */
+#define ATARIBIOS_MAXKEYS 128
+
+static unsigned char ikbd_previouskeyboard[ATARIBIOS_MAXKEYS];
+static Uint16 atari_prevmouseb;	/* buttons */
+
+/* The translation tables from a console scancode to a SDL keysym */
+#define KT_NOCHANGE -1
+
+enum {
+	KT_UNSHIFT=0,
+	KT_SHIFT=1,
+	KT_CAPS=2
+};
+
+static int caps_state;
+_KEYTAB *curtables;
+static unsigned char *tab_unshift, *tab_shift, *tab_caps;
+static SDLKey keymap[ATARIBIOS_MAXKEYS];
+
+static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym);
+
+void AtariIkbd_InitOSKeymap(_THIS)
+{
+	int i;
+
+	memset(SDL_AtariIkbd_keyboard, 0, ATARIBIOS_MAXKEYS);
+	memset(ikbd_previouskeyboard, 0, ATARIBIOS_MAXKEYS);
+
+	/* Initialize keymap */
+	for ( i=0; i<sizeof(keymap); i++ )
+		keymap[i] = SDLK_UNKNOWN;
+
+	/* Functions keys */
+	for ( i = 0; i<10; i++ )
+		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
+
+	/* Cursor keypad */
+	keymap[SCANCODE_HELP] = SDLK_HELP;
+	keymap[SCANCODE_UNDO] = SDLK_UNDO;
+	keymap[SCANCODE_INSERT] = SDLK_INSERT;
+	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
+	keymap[SCANCODE_UP] = SDLK_UP;
+	keymap[SCANCODE_DOWN] = SDLK_DOWN;
+	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
+	keymap[SCANCODE_LEFT] = SDLK_LEFT;
+
+	/* Special keys */
+	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
+	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
+	keymap[SCANCODE_TAB] = SDLK_TAB;
+	keymap[SCANCODE_ENTER] = SDLK_RETURN;
+	keymap[SCANCODE_DELETE] = SDLK_DELETE;
+	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
+	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
+	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
+	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
+	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+
+	/* Read XBIOS tables for scancode -> ascii translation */
+	curtables=Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
+	tab_unshift=curtables->unshift;
+	tab_shift=curtables->shift;
+	tab_caps=curtables->caps;
+
+	/* Set Caps lock initial state */
+	caps_state=(Kbshift(-1) & (1<<K_CAPSLOCK));
+
+	/* Now install our handler */
+	SDL_AtariIkbd_mouseb = SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
+	atari_prevmouseb = 0;
+
+	Supexec(SDL_AtariIkbdInstall);
+}
+
+static int atari_GetButton(int button)
+{
+	switch(button)
+	{
+		case 0:
+			return SDL_BUTTON_RIGHT;
+			break;
+		case 1:
+		default:
+			return SDL_BUTTON_LEFT;
+			break;
+	}
+}
+
+void AtariIkbd_PumpEvents(_THIS)
+{
+	int i;
+	SDL_keysym keysym;
+	int specialkeys;
+
+	/*--- Send keyboard events ---*/
+
+	/* Update caps lock state */
+	if (SDL_AtariIkbd_keyboard[SCANCODE_CAPSLOCK] && !ikbd_previouskeyboard[SCANCODE_CAPSLOCK])
+		caps_state ^= 1;
+
+	/* Choose the translation table */
+	specialkeys=KT_UNSHIFT;
+	if (SDL_AtariIkbd_keyboard[SCANCODE_LEFTSHIFT] || SDL_AtariIkbd_keyboard[SCANCODE_RIGHTSHIFT])
+		specialkeys = KT_SHIFT;
+	if (caps_state)
+		specialkeys = KT_CAPS;
+
+	/* Now generate events */
+	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
+		/* Key pressed ? */
+		if (SDL_AtariIkbd_keyboard[i] && !ikbd_previouskeyboard[i])
+			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, specialkeys, &keysym));
+			
+		/* Key unpressed ? */
+		if (ikbd_previouskeyboard[i] && !SDL_AtariIkbd_keyboard[i])
+			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, specialkeys, &keysym));
+	}
+
+	/* Will be previous table */
+	memcpy(ikbd_previouskeyboard, SDL_AtariIkbd_keyboard, ATARIBIOS_MAXKEYS);
+
+	/*--- Send mouse events ---*/
+
+	/* Mouse motion ? */
+	if (SDL_AtariIkbd_mousex || SDL_AtariIkbd_mousey) {
+		SDL_PrivateMouseMotion(0, 1, SDL_AtariIkbd_mousex, SDL_AtariIkbd_mousey);
+		SDL_AtariIkbd_mousex = SDL_AtariIkbd_mousey = 0;
+	}
+
+	/* Mouse button ? */
+	if (SDL_AtariIkbd_mouseb != atari_prevmouseb) {
+		for (i=0;i<2;i++) {
+			int curbutton, prevbutton;
+
+			curbutton = SDL_AtariIkbd_mouseb & (1<<i);
+			prevbutton = atari_prevmouseb & (1<<i);
+
+			if (curbutton & !prevbutton) {
+				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
+			}
+			if (!curbutton & prevbutton) {
+				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
+			}
+		}
+		atari_prevmouseb = SDL_AtariIkbd_mouseb;
+	}
+}
+
+static SDL_keysym *TranslateKey(int scancode, int numkeytable, SDL_keysym *keysym)
+{
+	unsigned char asciicode;
+
+	/* Set the keysym information */
+	keysym->scancode = scancode;
+
+	asciicode=0;
+	switch(numkeytable) {
+		case KT_UNSHIFT:
+			asciicode=tab_unshift[scancode];
+			break;
+		case KT_SHIFT:
+			asciicode=tab_shift[scancode];
+			break;
+		case KT_CAPS:
+			asciicode=tab_caps[scancode];
+			break;
+	}
+
+	if (asciicode)
+		keysym->sym = asciicode;		
+	else
+		keysym->sym = keymap[scancode];
+
+	keysym->mod = KMOD_NONE;
+	keysym->unicode = 0;
+
+	return(keysym);
+}
+
+void AtariIkbd_ShutdownEvents(void)
+{
+	Supexec(SDL_AtariIkbdUninstall);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ikbdevents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,46 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Atari keyboard events manager, using hardware IKBD
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_ATARI_IKBDEVENTS_H_
+#define _SDL_ATARI_IKBDEVENTS_H_
+
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+extern void AtariIkbd_InitOSKeymap(_THIS);
+extern void AtariIkbd_PumpEvents(_THIS);
+extern void AtariIkbd_ShutdownEvents(void);
+
+#endif /* _SDL_ATARI_IKBDEVENTS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ikbdinterrupt.S	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,220 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	IKBD 6301 interrupt routine
+ *
+ *	Patrice Mandin
+ */
+
+	.text
+
+	.globl	_SDL_AtariIkbdInstall
+	.globl	_SDL_AtariIkbdUninstall
+
+	.globl	_SDL_AtariIkbd_keyboard
+	.globl	_SDL_AtariIkbd_mouseb
+	.globl	_SDL_AtariIkbd_mousex
+	.globl	_SDL_AtariIkbd_mousey
+	.globl	_SDL_AtariIkbd_joystick
+
+/*--- Install our IKBD vector ---*/
+
+_SDL_AtariIkbdInstall:
+	moveml	d0-d1/a0-a1,sp@-
+
+	| Init interrupts
+
+	movew	#0x2700,sr
+
+	| Save MFP registers used for keyboard
+
+	lea	0xfffffa00:w,a0
+	btst	#6,a0@(0x09)
+	sne	ikbd_ierb
+	btst	#6,a0@(0x15)
+	sne	ikbd_imrb
+
+	| Set our routine
+
+	movel	0x118:w,old_ikbd
+	movel	#ikbd,0x118:w
+	bset	#6,0xfffffa09:w	| IERB
+	bset	#6,0xfffffa15:w	| IMRB
+
+	moveb	#8,0xfffffc02:w
+
+	movew	#0x2300,sr
+
+	| Interrupts done
+
+	moveml	sp@+,d0-d1/a0-a1
+	rts
+
+/*--- Uninstall our IKBD vector ---*/
+
+_SDL_AtariIkbdUninstall:
+	movel	a0,sp@-
+
+	| Stop interrupt
+
+	movew	#0x2700,sr
+
+	| Restore previous MFP registers
+
+	lea	0xfffffa00:w,a0
+
+	bclr	#6,a0@(0x09)
+	tstb	ikbd_ierb
+	beq	ikbd_restoreierb
+	bset	#6,a0@(0x09)
+ikbd_restoreierb:
+
+	bclr	#6,a0@(0x15)
+	tstb	ikbd_imrb
+	beq	ikbd_restoreimrb
+	bset	#6,a0@(0x15)
+ikbd_restoreimrb:
+
+	movel	old_ikbd,0x118:w
+
+	| Clear keyboard buffer
+
+	lea	0xfffffc00:w,a0
+ikbd_videbuffer:
+	btst	#0,a0@
+	beq	ikbd_finbuffer
+	tstb	a0@(0x02)
+	bra	ikbd_videbuffer
+ikbd_finbuffer:
+
+	movew	#0x2300,sr
+
+	movel	sp@+,a0
+	rts
+
+	.data
+	.even
+	.comm	old_ikbd,4*1
+	.even
+	.comm	ikbd_ierb,4*1
+	.even
+	.comm	ikbd_imrb,4*1
+
+/*--- Our custom IKBD vector ---*/
+
+	.text
+	.even
+	.ascii	"XBRA"
+	.ascii	"_SDL"
+ikbd:
+	moveml	d0-d1/a0,sp@-
+	moveb	0xfffffc02:w,d0
+
+	| paquet joystick ?
+	
+	cmpb	#0xff,d0
+	beq	ikbd_yes_joystick
+
+	| paquet souris ?
+
+	cmpb	#0xf8,d0
+	bmi	ikbd_no_mouse
+	cmpb	#0xfc,d0
+	bpl	ikbd_no_mouse
+
+ikbd_yes_mouse:
+	andw	#3,d0
+	movew	d0,_SDL_AtariIkbd_mouseb
+
+	movel	#ikbd_mousex,0x118:w
+	bra	ikbd_endit
+
+ikbd_yes_joystick:
+	movel	#ikbd_joystick,0x118:w
+	bra	ikbd_endit
+
+ikbd_no_mouse:
+	moveb	d0,d1
+	lea	_SDL_AtariIkbd_keyboard,a0
+	andl	#0x7f,d1
+	tas	d0
+	spl	a0@(0,d1:w)
+ikbd_fin:
+
+	| Fin interruption
+
+ikbd_endit:
+	moveml	sp@+,d0-d1/a0
+	bclr	#6,0xfffffa11:w
+	rte
+
+ikbd_mousex:
+	movel	d0,sp@-
+
+	moveb	0xfffffc02:w,d0
+	extw	d0
+	addw	d0,_SDL_AtariIkbd_mousex
+
+	movel	sp@+,d0
+
+	movel	#ikbd_mousey,0x118:w
+	bclr	#6,0xfffffa11:w
+	rte
+
+ikbd_mousey:
+	movel	d0,sp@-
+
+	moveb	0xfffffc02:w,d0
+	extw	d0
+	addw	d0,_SDL_AtariIkbd_mousey
+
+	movel	sp@+,d0
+
+	movel	#ikbd,0x118:w
+	bclr	#6,0xfffffa11:w
+	rte
+
+ikbd_joystick:
+	moveb	0xfffffc02:w,_SDL_AtariIkbd_joystick+1
+
+	movel	#ikbd,0x118:w
+	bclr	#6,0xfffffa11:w
+	rte
+
+	.data
+	
+	.even
+	.comm	_SDL_AtariIkbd_keyboard,128
+	.even
+	.comm	_SDL_AtariIkbd_mousex,2*1
+	.even
+	.comm	_SDL_AtariIkbd_mousey,2*1
+	.even
+	.comm	_SDL_AtariIkbd_mouseb,2*1
+	.even
+	.comm	_SDL_AtariIkbd_joystick,2*1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_ikbdinterrupt_s.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,53 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Mouse vector
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_IKBDINTERRUPT_S_H_
+#define _SDL_IKBDINTERRUPT_S_H_
+
+#include <mint/osbind.h>
+
+#include "SDL_types.h"
+
+/* Variables */
+
+extern Uint8  SDL_AtariIkbd_keyboard[128];	/* Keyboard table */
+extern Uint16 SDL_AtariIkbd_mouseb;	/* buttons */
+extern Sint16 SDL_AtariIkbd_mousex;	/* X relative motion */
+extern Sint16 SDL_AtariIkbd_mousey;	/* Y relative motion */
+
+/* Functions */ 
+
+extern void SDL_AtariIkbdInstall(void);
+extern void SDL_AtariIkbdUninstall(void);
+
+#endif /* _SDL_IKBDINTERRUPT_S_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_xbiosmouseevents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,127 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	IKBD 6301 mouse vector
+ *
+ *	Patrice Mandin
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <mint/osbind.h>
+
+#include "SDL_events_c.h"
+#include "SDL_xbiosmouseinterrupt_s.h"
+
+static _KBDVECS *kbdvecs;		/* Pointer to access vectors */
+static _KBDVECS sys_kbdvecs;	/* Backup of system vectors */
+
+/* Variables */
+
+static Uint16 atari_prevmouseb;	/* buttons */
+
+void AtariXbios_InstallMouseVector(void)
+{
+	void *oldpile;
+
+	/* Read IKBD vectors base */
+	kbdvecs=Kbdvbase();
+
+	/* Go to supervisor mode */
+	oldpile=(void *)Super(0);
+
+	/* Backup system vectors */
+	memcpy(&sys_kbdvecs, kbdvecs, sizeof(_KBDVECS));
+
+	/* Install our vector */
+	SDL_AtariXbiosMouseInstall(kbdvecs,SDL_AtariXbiosMouseVector);
+
+	/* Back to user mode */
+	Super(oldpile);
+
+	/* Clear variables */
+	SDL_AtariXbios_mouseb = SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
+	atari_prevmouseb = 0;
+}
+
+void AtariXbios_RestoreMouseVector(void)
+{
+	void *oldpile;
+
+	/* Go to supervisor mode */
+	oldpile=(void *)Super(NULL);
+
+	/* Reinstall system vector */
+	SDL_AtariXbiosMouseInstall(kbdvecs,sys_kbdvecs.mousevec);
+
+	/* Back to user mode */
+	Super(oldpile);
+}
+
+static int atari_GetButton(int button)
+{
+	switch(button)
+	{
+		case 0:
+			return SDL_BUTTON_RIGHT;
+			break;
+		case 1:
+		default:
+			return SDL_BUTTON_LEFT;
+			break;
+	}
+}
+
+void AtariXbios_PostMouseEvents(_THIS)
+{
+	/* Mouse motion ? */
+	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
+		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
+		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
+	}
+	
+	/* Mouse button ? */
+	if (SDL_AtariXbios_mouseb != atari_prevmouseb) {
+		int i;
+
+		for (i=0;i<2;i++) {
+			int curbutton, prevbutton;
+
+			curbutton = SDL_AtariXbios_mouseb & (1<<i);
+			prevbutton = atari_prevmouseb & (1<<i);
+
+			if (curbutton & !prevbutton) {
+				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
+			}
+			if (!curbutton & prevbutton) {
+				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
+			}
+		}
+		atari_prevmouseb = SDL_AtariXbios_mouseb;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_xbiosmouseevents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,46 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	IKBD 6301 mouse vector
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_XBIOSMOUSEEVENTS_H_
+#define _SDL_XBIOSMOUSEEVENTS_H_
+
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+extern void AtariXbios_InstallMouseVector(void);
+extern void AtariXbios_RestoreMouseVector(void);
+extern void AtariXbios_PostMouseEvents(_THIS);
+
+#endif /* _SDL_XBIOSMOUSEEVENTS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_xbiosmouseinterrupt.S	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,109 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	IKBD 6301 mouse vector
+ *
+ *	Patrice Mandin
+ */
+
+	.text
+
+	.globl	_SDL_AtariXbiosMouseInstall
+	.globl	_SDL_AtariXbiosMouseVector
+
+	.globl	_SDL_AtariXbios_mouseb
+	.globl	_SDL_AtariXbios_mousex
+	.globl	_SDL_AtariXbios_mousey
+
+/*--- Vector installer ---*/
+
+_SDL_AtariXbiosMouseInstall:
+	movel	sp@(4),a0
+	movel	sp@(8),a1
+
+	/* Stop interrupts */
+
+	movew	#0x2700,sr
+
+	/* Save old vector */
+
+	movel	a0@(16),oldvector
+
+	/* Set our routine */
+
+	movel	a1,a0@(16)
+
+	/* Restart interrupts */
+
+	movew	#0x2300,sr
+
+	rts
+
+/*--- Our mouse vector ---*/
+
+	.text
+	.even
+	.ascii "XBRA"
+	.ascii "_SDL"
+_SDL_AtariXbiosMouseVector:
+	moveml	d0/a1,sp@-
+
+	/* Mouse buttons */
+	moveb	(a0),d0
+	andw	#3,d0
+	movew	d0,_SDL_AtariXbios_mouseb
+
+	/* X movement */
+	moveb	a0@(1),d0
+	extw	d0
+	addw	d0,_SDL_AtariXbios_mousex
+
+	/* Y movement */
+	moveb	a0@(2),d0
+	extw	d0
+	addw	d0,_SDL_AtariXbios_mousey
+
+	/* Jump through old vector */
+	movel	oldvector,a1
+	jsr	(a1)
+
+	moveml	sp@+,d0/a1
+	rts
+
+	.data
+	
+	.even
+	.comm	oldvector,4*1
+
+	.even
+	.comm	_SDL_AtariXbios_mousex,2*1
+	.even
+	.comm	_SDL_AtariXbios_mousey,2*1
+	.even
+	.comm	_SDL_AtariXbios_mouseb,2*1
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/ataricommon/SDL_xbiosmouseinterrupt_s.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,52 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	Mouse vector
+ *
+ *	Patrice Mandin
+ */
+
+#ifndef _SDL_XBIOSMOUSEEVENTS_S_H_
+#define _SDL_XBIOSMOUSEEVENTS_S_H_
+
+#include <mint/osbind.h>
+
+#include "SDL_types.h"
+
+/* Variables */
+
+extern Uint16 SDL_AtariXbios_mouseb;	/* buttons */
+extern Sint16 SDL_AtariXbios_mousex;	/* X relative motion */
+extern Sint16 SDL_AtariXbios_mousey;	/* Y relative motion */
+
+/* Functions */ 
+
+extern void SDL_AtariXbiosMouseInstall(_KBDVECS *kbdvecs,void *newvector);
+extern void SDL_AtariXbiosMouseVector(void *buf);
+
+#endif /* _SDL_XBIOSMOUSEEVENTS_S_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,16 @@
+
+## Makefile.am for SDL using the GEM video driver
+
+noinst_LTLIBRARIES = libvideo_gem.la
+libvideo_gem_la_SOURCES = $(GEM_SRCS)
+
+# The SDL GEM video driver sources
+GEM_SRCS = 	\
+	SDL_gemvideo.h	\
+	SDL_gemvideo.c	\
+	SDL_gemevents_c.h	\
+	SDL_gemevents.c \
+	SDL_gemmouse_c.h	\
+	SDL_gemmouse.c \
+	SDL_gemwm_c.h	\
+	SDL_gemwm.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemevents.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,322 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ * GEM SDL video driver implementation
+ * inspired from the Dummy SDL driver
+ * 
+ * Patrice Mandin
+ * and work from
+ * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
+ */
+
+#include <string.h>
+
+#include <gem.h>
+
+#include "SDL.h"
+#include "SDL_sysevents.h"
+#include "SDL_events_c.h"
+#include "SDL_gemvideo.h"
+#include "SDL_gemevents_c.h"
+#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
+
+/* Defines */
+
+#define ATARIBIOS_MAXKEYS 128
+
+/* Variables */
+
+static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
+static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
+
+static short prevmousex, prevmousey, prevmouseb;
+
+/* The translation tables from a console scancode to a SDL keysym */
+static SDLKey keymap[ATARIBIOS_MAXKEYS];
+
+/* Functions prototypes */
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
+static int do_messages(_THIS, short *message);
+static void do_keyboard(short kc, short ks);
+static void do_mouse(_THIS, short mx, short my, short mb);
+
+/* Functions */
+
+static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym)
+{
+	/* Set the keysym information */
+	keysym->scancode = scancode;
+
+	if (asciicode)
+		keysym->sym = asciicode;		
+	else
+		keysym->sym = keymap[scancode];
+
+	keysym->mod = KMOD_NONE;
+	keysym->unicode = 0;
+
+	return(keysym);
+}
+
+void GEM_InitOSKeymap(_THIS)
+{
+	int i;
+
+	memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
+	memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
+	memset(gem_currentascii, 0, sizeof(gem_currentascii));
+
+	/* Initialize keymap */
+	for ( i=0; i<sizeof(keymap); i++ )
+		keymap[i] = SDLK_UNKNOWN;
+
+	/* Functions keys */
+	for ( i = 0; i<10; i++ )
+		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
+
+	/* Cursor keypad */
+	keymap[SCANCODE_HELP] = SDLK_HELP;
+	keymap[SCANCODE_UNDO] = SDLK_UNDO;
+	keymap[SCANCODE_INSERT] = SDLK_INSERT;
+	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
+	keymap[SCANCODE_UP] = SDLK_UP;
+	keymap[SCANCODE_DOWN] = SDLK_DOWN;
+	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
+	keymap[SCANCODE_LEFT] = SDLK_LEFT;
+
+	/* Special keys */
+	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
+	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
+	keymap[SCANCODE_TAB] = SDLK_TAB;
+	keymap[SCANCODE_ENTER] = SDLK_RETURN;
+	keymap[SCANCODE_DELETE] = SDLK_DELETE;
+	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
+	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
+	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
+	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
+	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
+
+	/* Mouse init */
+	prevmousex = prevmousey = prevmouseb = 0;
+	GEM_mouse_relative = SDL_FALSE;
+}
+
+void GEM_PumpEvents(_THIS)
+{
+	short mx, my, mb, dummy;
+	int i;
+	SDL_keysym	keysym;
+
+	memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
+	
+	for (;;)
+	{
+		int quit, resultat;
+		short buffer[8], kc, ks;
+
+		quit = 0;
+
+		resultat = evnt_multi(
+			MU_MESAG|MU_TIMER|MU_KEYBD,
+			0,0,0,
+			0,0,0,0,0,
+			0,0,0,0,0,
+			buffer,
+			10,
+			&dummy,&dummy,&dummy,&ks,&kc,&dummy
+		);
+
+		/* Message event ? */
+		if (resultat & MU_MESAG)
+			quit = do_messages(this, buffer);
+
+		/* Keyboard event ? */
+		if (resultat & MU_KEYBD)
+			do_keyboard(kc,ks);
+		else
+			do_keyboard(0,0);
+
+		/* Timer event ? */
+		if ((resultat & MU_TIMER) || quit)
+			break;
+	}
+
+	/* Update mouse */
+	graf_mkstate(&mx, &my, &mb, &dummy);
+	do_mouse(this, mx, my, mb);
+
+	/* Now generates keyboard events */
+	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
+		/* Key pressed ? */
+		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
+			SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(i, gem_currentascii[i], &keysym));
+			
+		/* Key unpressed ? */
+		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
+			SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(i, 0, &keysym));
+	}
+
+	memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
+}
+
+static int do_messages(_THIS, short *message)
+{
+	int quit, posted;
+
+	quit=0;
+	switch (message[0]) {
+		case WM_CLOSED:
+		case AP_TERM:    
+			posted = SDL_PrivateQuit();
+			quit=1;
+			break;
+		case WM_MOVED:
+			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
+			break;
+		case WM_TOPPED:
+			wind_set(message[3],WF_TOP,message[4],0,0,0);
+			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
+			break;
+		case WM_REDRAW:
+			GEM_wind_redraw(this, message[3],&message[4]);
+			break;
+		case WM_ICONIFY:
+		case WM_ALLICONIFY:
+			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
+			/* If we're active, make ourselves inactive */
+			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
+				/* Send an internal deactivate event */
+				SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
+			}
+			break;
+		case WM_UNICONIFY:
+			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
+			/* If we're not active, make ourselves active */
+			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
+				/* Send an internal activate event */
+				SDL_PrivateAppActive(1, SDL_APPACTIVE);
+			}
+			break;
+		case WM_SIZED:
+			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
+			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
+			SDL_PrivateResize(message[6], message[7]);
+			break;
+		case WM_FULLED:
+			{
+				short x,y,w,h;
+
+				if (GEM_win_fulled) {
+					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
+					GEM_win_fulled = SDL_FALSE;
+				} else {
+					x = GEM_desk_x;
+					y = GEM_desk_y;
+					w = GEM_desk_w;
+					h = GEM_desk_h;
+					GEM_win_fulled = SDL_TRUE;
+				}
+				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
+				SDL_PrivateResize(w, h);
+			}
+			break;
+		case WM_BOTTOMED:
+		case WM_UNTOPPED:
+			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
+			break;
+	}
+	
+	return quit;
+}
+
+static void do_keyboard(short kc, short ks)
+{
+	int			scancode, asciicode;
+	short		dummy;
+
+	if (kc) {
+		scancode=(kc>>8) & 127;
+		asciicode=kc & 255;
+
+		gem_currentkeyboard[scancode]=0xFF;
+		gem_currentascii[scancode]=asciicode;
+	}
+
+	if (!ks)
+		graf_mkstate(&dummy, &dummy, &dummy, &ks);
+
+	/* Read special keys */
+	if (ks & K_RSHIFT)
+		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
+	if (ks & K_LSHIFT)
+		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
+	if (ks & K_CTRL)
+		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
+	if (ks & K_ALT)
+		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
+}
+
+static void do_mouse(_THIS, short mx, short my, short mb)
+{
+	/* Mouse motion ? */
+	if ((prevmousex!=mx) || (prevmousey!=my)) {
+		if (GEM_mouse_relative) {
+			short wind_pxy[8];
+
+			wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
+
+			SDL_PrivateMouseMotion(0, 1, mx-wind_pxy[0], my-wind_pxy[1]);
+		} else {
+			SDL_PrivateMouseMotion(0, 1, mx, my);
+		}
+		prevmousex = mx;
+		prevmousey = my;
+	}
+
+	/* Mouse button ? */
+	if (prevmouseb!=mb) {
+		int i;
+
+		for (i=0;i<3;i++) {
+			int curbutton, prevbutton;
+		
+			curbutton = mb & (1<<i);
+			prevbutton = prevmouseb & (1<<i);
+		
+			if (curbutton & !prevbutton) {
+				SDL_PrivateMouseButton(SDL_PRESSED, i, 0, 0);
+			}
+			if (!curbutton & prevbutton) {
+				SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
+			}
+		}
+		prevmouseb = mb;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemevents_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,37 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#include "SDL_gemvideo.h"
+
+/* Variables and functions exported by SDL_sysevents.c to other parts 
+   of the native video subsystem (SDL_sysvideo.c) */
+
+extern void GEM_InitOSKeymap(_THIS);
+extern void GEM_PumpEvents(_THIS);
+
+/* end of SDL_gemevents_c.h */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemmouse.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,158 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	GEM Mouse manager
+ *
+ *	Patrice Mandin
+ */
+
+#include <stdlib.h>
+
+#include <gem.h>
+
+#include "SDL_error.h"
+#include "SDL_mouse.h"
+#include "SDL_events_c.h"
+#include "SDL_cursor_c.h"
+#include "SDL_gemmouse_c.h"
+
+/* Defines */
+
+#define MAXCURWIDTH 16
+#define MAXCURHEIGHT 16
+
+/* The implementation dependent data for the window manager cursor */
+struct WMcursor {
+	MFORM *mform_p;
+};
+
+
+void GEM_FreeWMCursor(_THIS, WMcursor *cursor)
+{
+	if (cursor == NULL)
+		return;
+	
+	graf_mouse(ARROW, NULL);
+
+	if (cursor->mform_p != NULL)
+		free(cursor->mform_p);
+
+	free(cursor);
+}
+
+WMcursor *GEM_CreateWMCursor(_THIS,
+		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
+{
+	WMcursor *cursor;
+	MFORM *new_mform;
+	int i;
+
+	/* Check the size */
+	if ( (w > MAXCURWIDTH) || (h > MAXCURHEIGHT) ) {
+		SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
+							MAXCURWIDTH, MAXCURHEIGHT);
+		return(NULL);
+	}
+
+	/* Allocate the cursor memory */
+	cursor = (WMcursor *)malloc(sizeof(WMcursor));
+	if ( cursor == NULL ) {
+		SDL_OutOfMemory();
+		return(NULL);
+	}
+
+	/* Allocate mform */
+	new_mform = (MFORM *)malloc(sizeof(MFORM));		
+	if (new_mform == NULL) {
+		free(cursor);
+		SDL_OutOfMemory();
+		return(NULL);
+	}
+
+	cursor->mform_p = new_mform;
+
+	new_mform->mf_xhot = hot_x;
+	new_mform->mf_yhot = hot_y;
+	new_mform->mf_nplanes = 1;
+	new_mform->mf_fg = 0;
+	new_mform->mf_bg = 1;
+
+	for (i=0;i<MAXCURHEIGHT;i++)
+	{
+		new_mform->mf_mask[i]=0;
+		new_mform->mf_data[i]=0;
+	}
+
+	if (w<=8) {
+		for (i=0;i<h;i++)
+		{
+			new_mform->mf_mask[i]= mask[i]<<8;
+			new_mform->mf_data[i]= data[i]<<8;
+		}
+	} else {
+		for (i=0;i<h;i++)
+		{
+			new_mform->mf_mask[i]= mask[i<<1]<<8 | mask[(i<<1)+1];
+			new_mform->mf_data[i]= data[i<<1]<<8 | data[(i<<1)+1];
+		}
+	}
+
+	return cursor;
+}
+
+int GEM_ShowWMCursor(_THIS, WMcursor *cursor)
+{
+	if (cursor == NULL) {
+		graf_mouse(M_OFF, NULL);
+	} else if (cursor->mform_p) {
+		graf_mouse(USER_DEF, cursor->mform_p);
+	}
+
+	return 1;
+}
+
+void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
+{
+	EVNTREC	warpevent;
+	
+	warpevent.ap_event = APPEVNT_MOUSE; 
+	warpevent.ap_value = (y << 16) | x;
+
+	appl_tplay(&warpevent, 1, 1000);
+}
+
+void GEM_CheckMouseMode(_THIS)
+{
+	/* If the mouse is hidden and input is grabbed, we use relative mode */
+	if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
+		(this->input_grab != SDL_GRAB_OFF) ) {
+		GEM_mouse_relative = SDL_TRUE;
+	} else {
+		GEM_mouse_relative = SDL_FALSE;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemmouse_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,37 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#include "SDL_gemvideo.h"
+
+/* Functions to be exported */
+extern void GEM_FreeWMCursor(_THIS, WMcursor *cursor);
+extern WMcursor *GEM_CreateWMCursor(_THIS,
+		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
+extern int GEM_ShowWMCursor(_THIS, WMcursor *cursor);
+extern void GEM_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
+extern void GEM_CheckMouseModeNoLock(_THIS);
+extern void GEM_CheckMouseMode(_THIS);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemvideo.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,1064 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ * GEM SDL video driver implementation
+ * inspired from the Dummy SDL driver
+ * 
+ * Patrice Mandin
+ * and work from
+ * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Mint includes */
+#include <gem.h>
+#include <gemx.h>
+#include <mint/osbind.h>
+#include <sys/cookie.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_ataric2p_s.h"
+#include "SDL_ataric2p060_c.h"
+#include "SDL_atarieddi_s.h"
+#include "SDL_atarimxalloc_c.h"
+#include "SDL_gemvideo.h"
+#include "SDL_gemevents_c.h"
+#include "SDL_gemmouse_c.h"
+#include "SDL_gemwm_c.h"
+
+/* Defines */
+
+#define GEM_VID_DRIVER_NAME "gem"
+
+/* Variables */
+
+static unsigned char vdi_index[256] = {
+	0,  2,  3,  6,  4,  7,  5,   8,
+	9, 10, 11, 14, 12, 15, 13, 255
+};
+
+static const unsigned char empty_name[]="";
+
+/* Initialization/Query functions */
+static int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat);
+static SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
+static SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
+static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
+static void GEM_VideoQuit(_THIS);
+
+/* Hardware surface functions */
+static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface);
+static int GEM_LockHWSurface(_THIS, SDL_Surface *surface);
+static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface);
+static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface);
+static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface);
+static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
+#if 0
+static int GEM_ToggleFullScreen(_THIS, int on);
+#endif
+
+/* Internal functions */
+static void GEM_FreeBuffers(_THIS);
+static void refresh_window(_THIS, int winhandle, short *rect);
+
+/* GEM driver bootstrap functions */
+
+static int GEM_Available(void)
+{
+	short ap_id;
+	const char *envr = getenv("SDL_VIDEODRIVER");
+
+	/* Check if user asked a different video driver */
+	if ((envr) && (strcmp(envr, GEM_VID_DRIVER_NAME)!=0)) {
+		return 0;
+	}
+
+	/* Test if AES available */
+	ap_id = appl_init();
+	if (ap_id == -1)
+		return 0;
+
+	appl_exit();
+	return 1;
+}
+
+static void GEM_DeleteDevice(SDL_VideoDevice *device)
+{
+	free(device->hidden);
+	free(device);
+}
+
+static SDL_VideoDevice *GEM_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));
+
+	atari_test_cpu060_present();
+
+	/* Set the function pointers */
+	device->VideoInit = GEM_VideoInit;
+	device->ListModes = GEM_ListModes;
+	device->SetVideoMode = GEM_SetVideoMode;
+	device->SetColors = GEM_SetColors;
+	device->UpdateRects = NULL /*GEM_UpdateRects*/;
+	device->VideoQuit = GEM_VideoQuit;
+	device->AllocHWSurface = GEM_AllocHWSurface;
+	device->LockHWSurface = GEM_LockHWSurface;
+	device->UnlockHWSurface = GEM_UnlockHWSurface;
+	device->FlipHWSurface = GEM_FlipHWSurface;
+	device->FreeHWSurface = GEM_FreeHWSurface;
+	device->ToggleFullScreen = NULL /*GEM_ToggleFullScreen*/;
+
+	/* Window manager */
+	device->SetCaption = GEM_SetCaption;
+	device->SetIcon = NULL /*GEM_SetIcon*/;
+	device->IconifyWindow = GEM_IconifyWindow;
+	device->GrabInput = GEM_GrabInput;
+
+	/* Events */
+	device->InitOSKeymap = GEM_InitOSKeymap;
+	device->PumpEvents = GEM_PumpEvents;
+
+	/* Mouse */
+	device->FreeWMCursor = GEM_FreeWMCursor;
+	device->CreateWMCursor = GEM_CreateWMCursor;
+	device->ShowWMCursor = GEM_ShowWMCursor;
+	device->WarpWMCursor = GEM_WarpWMCursor;
+	device->CheckMouseMode = GEM_CheckMouseMode;
+
+	device->free = GEM_DeleteDevice;
+
+	return device;
+}
+
+VideoBootStrap GEM_bootstrap = {
+	GEM_VID_DRIVER_NAME, "Atari GEM video driver",
+	GEM_Available, GEM_CreateDevice
+};
+
+static void VDI_ReadExtInfo(_THIS, short *work_out)
+{
+	unsigned long EdDI_version;
+	unsigned long cookie_EdDI;
+	Uint32 num_colours;
+	Uint16 clut_type, num_bits;
+
+	/* Read EdDI informations */
+	if  (Getcookie(C_EdDI, &cookie_EdDI) == C_NOTFOUND) {
+		return;
+	}
+	
+	EdDI_version = Atari_get_EdDI_version( (void *)cookie_EdDI);
+
+	vq_scrninfo(VDI_handle, work_out);
+
+	VDI_format = work_out[0];
+	clut_type = work_out[1];
+	num_bits = work_out[2];
+	num_colours = *((Uint32 *) &work_out[3]);
+
+	/* With EdDI>=1.1, we can have screen pitch, address and format
+	 * so we can directly write to screen without using vro_cpyfm
+	 */
+	if (EdDI_version >= EDDI_11) {
+		VDI_pitch = work_out[5];
+		VDI_screen = (void *) *((unsigned long *) &work_out[6]);
+
+		switch(num_colours) {
+			case 32768UL:
+				if (work_out[14] & (1<<7)) {
+					/* Little endian */
+					if (work_out[14] & (1<<1)) {
+						/* Falcon */
+						VDI_alphamask = 1 << 13;
+						VDI_redmask = 31 << 3;
+						VDI_greenmask = (3 << 14) | 7;
+						VDI_bluemask = 31 << 8;
+					} else {
+						/* Others */
+						VDI_alphamask = 1 << 7;
+						VDI_redmask = 31 << 2;
+						VDI_greenmask = (7 << 13) | 3;
+						VDI_bluemask = 31 << 8;
+					}
+				} else {
+					/* Big endian */
+					if (work_out[14] & (1<<1)) {
+						/* Falcon */
+						VDI_alphamask = 1 << 5;
+						VDI_redmask = 31 << 11;
+						VDI_greenmask = 31 << 6;
+						VDI_bluemask = 31;
+					} else {
+						/* Others */
+						VDI_alphamask = 1 << 15;
+						VDI_redmask = 31 << 10;
+						VDI_greenmask = 31 << 5;
+						VDI_bluemask = 31;
+					}
+				}
+				break;
+			case 65536UL:
+				if (work_out[14] & (1<<7)) {
+					/* Little endian */
+					VDI_alphamask = 0;
+					VDI_redmask = 31 << 3;
+					VDI_greenmask = (7 << 13) | 7;
+					VDI_bluemask = 31 << 8;
+				} else {
+					/* Big endian */
+					VDI_alphamask = 0;
+					VDI_redmask = 31 << 11;
+					VDI_greenmask = 63 << 5;
+					VDI_bluemask = 31;
+				}
+				break;
+			case 16777216UL:
+				if (work_out[14] & (1<<7)) {
+					/* Little endian */
+					switch(num_bits) {
+						case 24:
+							VDI_alphamask = 0;
+							VDI_redmask = 255;
+							VDI_greenmask = 255 << 8;
+							VDI_bluemask = 255 << 16;
+							break;
+						case 32:
+							VDI_alphamask = 255;
+							VDI_redmask = 255 << 8;
+							VDI_greenmask = 255 << 16;
+							VDI_bluemask = 255 << 24;
+							break;
+					}
+				} else {
+					/* Big endian */
+					switch(num_bits) {
+						case 24:
+							VDI_alphamask = 0;
+							VDI_redmask = 255 << 16;
+							VDI_greenmask = 255 << 8;
+							VDI_bluemask = 255;
+							break;
+						case 32:
+							VDI_alphamask = 255 << 24;
+							VDI_redmask = 255 << 16;
+							VDI_greenmask = 255 << 8;
+							VDI_bluemask = 255;
+							break;
+					}
+				}
+				break;
+		}
+	}
+
+	switch(clut_type) {
+		case VDI_CLUT_HARDWARE:
+			{
+				int i;
+				Uint16 *tmp_p;
+
+				tmp_p = (Uint16 *)&work_out[16];
+
+				for (i=0;i<256;i++) {
+					vdi_index[i] = *tmp_p++;
+				}
+			}
+			break;
+		case VDI_CLUT_SOFTWARE:
+			if (EdDI_version < EDDI_11) {
+				int component; /* red, green, blue, alpha, overlay */
+				int num_bit;
+				unsigned short *tmp_p;
+
+				/* We can build masks with info here */
+				tmp_p = (unsigned short *) &work_out[16];
+				for (component=0;component<5;component++) {
+					for (num_bit=0;num_bit<16;num_bit++) {
+						unsigned short valeur;
+
+						valeur = *tmp_p++;
+
+						if (valeur == 0xffff) {
+							continue;
+						}
+
+						switch(component) {
+							case 0:
+								VDI_redmask |= 1<< valeur;
+								break;
+							case 1:
+								VDI_greenmask |= 1<< valeur;
+								break;
+							case 2:
+								VDI_bluemask |= 1<< valeur;
+								break;
+							case 3:
+								VDI_alphamask |= 1<< valeur;
+								break;
+						}
+					}
+				}
+
+				/* Remove lower green bits for Intel endian screen */
+				if ((VDI_greenmask == ((7<<13)|3)) || (VDI_greenmask == ((7<<13)|7))) {
+					VDI_greenmask &= ~(7<<13);
+				}
+			}
+			break;
+		case VDI_CLUT_NONE:
+			break;
+	}
+}
+
+int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
+{
+	int i;
+	short work_in[12], work_out[272], dummy;
+
+	/* Open AES (Application Environment Services) */
+	GEM_ap_id = appl_init();
+	if (GEM_ap_id == -1) {
+		fprintf(stderr,"Can not open AES\n");
+		return 1;
+	}
+
+	/* Read version and features */
+	GEM_version = aes_global[0];
+	if (GEM_version >= 0x0400) {
+		short ap_gout[4];
+		
+		GEM_wfeatures=0;
+		if (appl_getinfo(AES_WINDOW, &ap_gout[0], &ap_gout[1], &ap_gout[2], &ap_gout[3])==0) {
+			GEM_wfeatures=ap_gout[0];			
+		}
+	}	
+
+	/* Ask VDI physical workstation handle opened by AES */
+	VDI_handle = graf_handle(&dummy, &dummy, &dummy, &dummy);
+	if (VDI_handle<1) {
+		fprintf(stderr,"Wrong VDI handle %d returned by AES\n",VDI_handle);
+		return 1;
+	}
+
+	/* Open virtual VDI workstation */
+	work_in[0]=Getrez()+2;
+	for(i = 1; i < 10; i++)
+		work_in[i] = 1;
+	work_in[10] = 2;
+
+	v_opnvwk(work_in, &VDI_handle, work_out);
+	if (VDI_handle == 0) {
+		fprintf(stderr,"Can not open VDI virtual workstation\n");
+		return 1;
+	}
+
+	/* Read fullscreen size */
+	VDI_w = work_out[0] + 1;
+	VDI_h = work_out[1] + 1;
+
+	/* Read desktop size and position */
+	if (!wind_get(DESKTOP_HANDLE, WF_WORKXYWH, &GEM_desk_x, &GEM_desk_y, &GEM_desk_w, &GEM_desk_h)) {
+		fprintf(stderr,"Can not read desktop properties\n");
+		return 1;
+	}
+
+	/* Read bit depth */
+	vq_extnd(VDI_handle, 1, work_out);
+	VDI_bpp = work_out[4];
+	VDI_oldnumcolors=0;
+
+	switch(VDI_bpp) {
+		case 8:
+			VDI_pixelsize=1;
+			break;
+		case 15:
+		case 16:
+			VDI_pixelsize=2;
+			break;
+		case 24:
+			VDI_pixelsize=3;
+			break;
+		case 32:
+			VDI_pixelsize=4;
+			break;
+		default:
+			fprintf(stderr,"%d bits colour depth not supported\n",VDI_bpp);
+			return 1;
+	}
+
+	/* Setup hardware -> VDI palette mapping */
+	for(i = 16; i < 255; i++) {
+		vdi_index[i] = i;
+	}
+	vdi_index[255] = 1;
+
+	/* Save current palette */
+	if (VDI_bpp>8) {
+		VDI_oldnumcolors=1<<8;
+	} else {
+		VDI_oldnumcolors=1<<VDI_bpp;
+	}
+	
+	for(i = 0; i < VDI_oldnumcolors; i++) {
+		short rgb[3];
+
+		vq_color(VDI_handle, i, 0, rgb);
+
+		VDI_oldpalette[i][0] = rgb[0];
+		VDI_oldpalette[i][1] = rgb[1];
+		VDI_oldpalette[i][2] = rgb[2];
+	}
+
+	/* Setup screen info */
+	GEM_title_name = empty_name;
+	GEM_icon_name = empty_name;
+
+	GEM_handle = -1;
+	GEM_locked = SDL_FALSE;
+	GEM_win_fulled = SDL_FALSE;
+
+	VDI_screen = NULL;
+	VDI_ReadExtInfo(this, work_out);
+	if (VDI_screen == NULL) {
+		VDI_pitch = VDI_w * ((VDI_bpp)>>3);
+		VDI_format = VDI_FORMAT_UNKNOWN;
+		VDI_redmask = VDI_greenmask = VDI_bluemask = VDI_alphamask = 0;
+	}
+
+	/* Setup destination mfdb */
+	VDI_dst_mfdb.fd_addr = NULL;
+
+	/* Update hardware info */
+	this->info.hw_available = 0;
+	this->info.video_mem = 0;
+
+	/*	TC, screen : no shadow (direct)
+     *  8P, screen: no shadow (direct)
+     *  8I, screen: shadow, c2p (shadow -> c2p)
+	 *  TC, no screen: shadow (vro_cpyfm)
+	 *  8P, no screen: shadow (vro_cpyfm)
+	 *  8I/U, no screen: shadow, shadow_c2p, c2p (shadow -> c2p -> vro_cpyfm)
+	 */
+
+	/* Determine the screen depth */
+	/* we change this during the SDL_SetVideoMode implementation... */
+	vformat->BitsPerPixel = VDI_bpp;
+
+	/* Set mouse cursor to arrow */
+	graf_mouse(ARROW, NULL);
+
+	/* Init chunky to planar routine */
+	Atari_C2pInit = Atari_C2pInit8;
+	if (atari_cpu060_avail) {
+		Atari_C2pConvert = Atari_C2pConvert8_060;
+	} else {
+		Atari_C2pConvert = Atari_C2pConvert8;
+	}
+	Atari_C2pInit();
+
+	/* We're done! */
+	return(0);
+}
+
+SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
+{
+	if (format->BitsPerPixel == VDI_bpp) {
+		return((SDL_Rect **)-1);
+	} else {
+		return ((SDL_Rect **)NULL);
+	}
+}
+
+static void GEM_FreeBuffers(_THIS)
+{
+	/* Release buffer */
+	if ( GEM_buffer ) {
+		free( GEM_buffer );
+		GEM_buffer=NULL;
+	}
+
+	/* Destroy window */
+	if (GEM_handle>=0) {
+		wind_close(GEM_handle);
+		wind_delete(GEM_handle);
+		GEM_handle=-1;
+	}
+}
+
+SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
+				int width, int height, int bpp, Uint32 flags)
+{
+	int maxwidth, maxheight;
+	Uint32 modeflags, screensize;
+	SDL_bool use_shadow;
+
+	modeflags = SDL_HWPALETTE;
+	GEM_FreeBuffers(this);
+
+	/*--- Verify if asked mode can be used ---*/
+	if (flags & SDL_FULLSCREEN) {
+		maxwidth=VDI_w;
+		maxheight=VDI_h;
+	} else {
+		/* Windowed mode */
+		maxwidth=GEM_desk_w;
+		maxheight=GEM_desk_h;
+	}
+
+	if ((maxwidth < width) || (maxheight < height) || (VDI_bpp != bpp)) {
+		SDL_SetError("Couldn't find requested mode in list");
+		return(NULL);
+	}
+
+	/*--- Allocate the new pixel format for the screen ---*/
+	if ( ! SDL_ReallocFormat(current, VDI_bpp, VDI_redmask, VDI_greenmask, VDI_bluemask, VDI_alphamask) ) {
+		SDL_SetError("Couldn't allocate new pixel format for requested mode");
+		return(NULL);
+	}
+
+	/*--- Allocate shadow buffer if needed ---*/
+	use_shadow=SDL_FALSE;
+	if (flags & SDL_FULLSCREEN) {
+		if (!VDI_screen) {
+			use_shadow=SDL_TRUE;
+		} else if (VDI_format==VDI_FORMAT_INTER) {
+			use_shadow=SDL_TRUE;
+		}
+	} else {
+		use_shadow=SDL_TRUE;
+	}
+
+	if (use_shadow) {
+		screensize = width * height * VDI_pixelsize;
+
+		GEM_buffer = Atari_SysMalloc(screensize, MX_PREFTTRAM);
+		if (GEM_buffer==NULL) {
+			fprintf(stderr,"Unable to allocate shadow buffer\n");
+			return NULL;
+		}
+		memset(GEM_buffer, 0, screensize);
+	}
+
+	/*--- Initialize screen ---*/
+	if (flags & SDL_FULLSCREEN) {
+		short rgb[3]={0,0,0};
+		short pxy[4];
+
+		if (!GEM_locked) {
+			/* Reserve memory space, used to be sure of compatibility */
+			form_dial( FMD_START, 0,0,0,0, 0,0,VDI_w,VDI_h);
+			/* Lock AES */
+			while (!wind_update(BEG_UPDATE|BEG_MCTRL));
+
+			GEM_locked=SDL_TRUE;
+		}
+
+		/* Clear screen */
+		pxy[0] = pxy[1] = 0;
+		pxy[2] = VDI_w - 1;
+		pxy[3] = VDI_h - 1;
+		vs_color(VDI_handle, vdi_index[0], rgb);
+		vsf_color(VDI_handle,0);
+		vsf_interior(VDI_handle,1);
+		vsf_perimeter(VDI_handle,0);
+		v_bar(VDI_handle,pxy);
+
+		modeflags |= SDL_FULLSCREEN;
+		if (VDI_screen && (VDI_format==VDI_FORMAT_PACK)) {
+			modeflags |= SDL_HWSURFACE;
+		} else {
+			modeflags |= SDL_SWSURFACE;
+		}
+	} else {
+		int posx,posy;
+		short x2,y2,w2,h2;
+
+		if (GEM_locked) {
+			/* Restore screen memory, and send REDRAW to all apps */
+			form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
+			/* Unlock AES */
+			wind_update(END_UPDATE|END_MCTRL);
+			GEM_locked=SDL_FALSE;
+		}
+
+		/* Center our window */
+		posx = GEM_desk_x;
+		posy = GEM_desk_y;
+		if (width<GEM_desk_w)
+			posx += (GEM_desk_w - width) >> 1;
+		if (height<GEM_desk_h)
+			posy += (GEM_desk_h - height) >> 1;
+
+		/* Calculate our window size and position */
+		if (!(flags & SDL_NOFRAME)) {
+			GEM_win_type=NAME|MOVER|CLOSER|SMALLER;
+			if (flags & SDL_RESIZABLE) {
+				GEM_win_type |= FULLER|SIZER;
+				modeflags |= SDL_RESIZABLE;
+			}
+		} else {
+			GEM_win_type=0;
+			modeflags |= SDL_NOFRAME;
+		}
+
+		if (!wind_calc(0, GEM_win_type, posx, posy, width, height, &x2, &y2, &w2, &h2)) {
+			GEM_FreeBuffers(this);
+			fprintf(stderr,"Can not calculate window attributes\n");
+			return NULL;
+		}
+
+		/* Create window */
+		GEM_handle=wind_create(GEM_win_type, x2, y2, w2, h2);
+		if (GEM_handle<0) {
+			GEM_FreeBuffers(this);
+			fprintf(stderr,"Can not create window\n");
+			return NULL;
+		}
+
+		/* Setup window name */
+		wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
+	
+		/* Open the window */
+		wind_open(GEM_handle,x2,y2,w2,h2);
+
+		modeflags |= SDL_SWSURFACE;
+	}
+
+	/* Set up the new mode framebuffer */
+	current->flags = modeflags;
+	current->w = width;
+	current->h = height;
+	if (use_shadow) {
+		current->pixels = GEM_buffer;
+		current->pitch = width * (VDI_bpp >> 3);
+	} else {
+		current->pixels = VDI_screen;
+		current->pixels += VDI_pitch * ((VDI_h - height) >> 1);
+		current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1);
+		current->pitch = VDI_pitch;
+	}
+
+	this->UpdateRects = GEM_UpdateRects;
+
+	/* We're done */
+	return(current);
+}
+
+/* We don't actually allow hardware surfaces other than the main one */
+static int GEM_AllocHWSurface(_THIS, SDL_Surface *surface)
+{
+	return -1;
+}
+static void GEM_FreeHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+/* We need to wait for vertical retrace on page flipped displays */
+static int GEM_LockHWSurface(_THIS, SDL_Surface *surface)
+{
+	return(0);
+}
+
+static void GEM_UnlockHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+static void GEM_UpdateRectsFullscreen(_THIS, int numrects, SDL_Rect *rects)
+{
+	SDL_Surface *surface;
+
+	surface = this->screen;
+
+	if (VDI_screen) {
+		if (VDI_format==VDI_FORMAT_INTER) {
+			void *destscr;
+			int destx;
+			
+			destscr = VDI_screen;
+			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
+			destx = (VDI_w - surface->w) >> 1;
+			destx &= ~15;
+			destscr += VDI_pixelsize * destx;
+
+			/* Convert chunky to planar screen */
+			Atari_C2pConvert(
+				surface->pixels,
+				destscr,
+				surface->w,
+				surface->h,
+				SDL_FALSE,
+				surface->pitch,
+				VDI_pitch
+			);
+		}
+	} else {
+		MFDB mfdb_src;
+		short blitcoords[8];
+		int i;
+
+		mfdb_src.fd_addr=surface->pixels;
+		mfdb_src.fd_w=surface->w;
+		mfdb_src.fd_h=surface->h;
+		mfdb_src.fd_wdwidth=(surface->w) >> 4;
+		mfdb_src.fd_stand=0;
+	  	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
+		mfdb_src.fd_r1=0;
+		mfdb_src.fd_r2=0;
+		mfdb_src.fd_r3=0;
+
+		for ( i=0; i<numrects; ++i ) {
+			blitcoords[0] = rects[i].x;
+			blitcoords[1] = rects[i].y;
+			blitcoords[2] = blitcoords[0] + rects[i].w - 1;
+			blitcoords[3] = blitcoords[1] + rects[i].h - 1;
+
+			blitcoords[4] = rects[i].x + ((VDI_w - surface->w) >> 1);
+			blitcoords[5] = rects[i].y + ((VDI_h - surface->h) >> 1);
+			blitcoords[6] = blitcoords[4] + rects[i].w - 1;
+			blitcoords[7] = blitcoords[5] + rects[i].h - 1;
+
+			vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
+		}
+	}
+}
+
+static void GEM_UpdateRectsWindowed(_THIS, int numrects, SDL_Rect *rects)
+{
+	short pxy[8], wind_pxy[8];
+	int i;
+
+	wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
+
+	for ( i=0; i<numrects; ++i ) {
+		pxy[0] = wind_pxy[0] + rects[i].x;
+		pxy[1] = wind_pxy[1] + rects[i].y;
+		pxy[2] = rects[i].w;
+		pxy[3] = rects[i].h;
+
+		GEM_wind_redraw(this, GEM_handle, pxy);
+	}
+}
+
+static void GEM_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
+{
+	SDL_Surface *surface;
+
+	surface = this->screen;
+
+	if (surface->flags & SDL_FULLSCREEN) {
+		GEM_UpdateRectsFullscreen(this, numrects, rects);
+	} else {
+		GEM_UpdateRectsWindowed(this, numrects, rects);
+	}
+}
+
+static int GEM_FlipHWSurfaceFullscreen(_THIS, SDL_Surface *surface)
+{
+	if (VDI_screen) {
+		if (VDI_format==VDI_FORMAT_INTER) {
+			void *destscr;
+			int destx;
+			
+			/* Center on destination screen */
+			destscr = VDI_screen;
+			destscr += VDI_pitch * ((VDI_h - surface->h) >> 1);
+			destx = (VDI_w - surface->w) >> 1;
+			destx &= ~15;
+			destscr += VDI_pixelsize * destx;
+
+			/* Convert chunky to planar screen */
+			Atari_C2pConvert(
+				surface->pixels,
+				destscr,
+				surface->w,
+				surface->h,
+				SDL_FALSE,
+				surface->pitch,
+				VDI_pitch
+			);
+		}
+	} else {
+		MFDB mfdb_src;
+		short blitcoords[8];
+
+		mfdb_src.fd_addr=surface->pixels;
+		mfdb_src.fd_w=surface->w;
+		mfdb_src.fd_h=surface->h;
+		mfdb_src.fd_wdwidth=(surface->w) >> 4;
+		mfdb_src.fd_stand=0;
+	  	mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
+		mfdb_src.fd_r1=0;
+		mfdb_src.fd_r2=0;
+		mfdb_src.fd_r3=0;
+
+		blitcoords[0] = 0;
+		blitcoords[1] = 0;
+		blitcoords[2] = surface->w - 1;
+		blitcoords[3] = surface->h - 1;
+		blitcoords[4] = (VDI_w - surface->w) >> 1;
+		blitcoords[5] = (VDI_h - surface->h) >> 1;
+		blitcoords[6] = blitcoords[4] + surface->w - 1;
+		blitcoords[7] = blitcoords[5] + surface->h - 1;
+
+		vro_cpyfm(VDI_handle, S_ONLY, blitcoords, &mfdb_src, &VDI_dst_mfdb);
+	}
+
+	return(0);
+}
+
+static int GEM_FlipHWSurfaceWindowed(_THIS, SDL_Surface *surface)
+{
+	short	pxy[8];
+
+	/* Update the whole window */
+	wind_get(GEM_handle, WF_WORKXYWH, &pxy[0], &pxy[1], &pxy[2], &pxy[3]);
+
+	GEM_wind_redraw(this, GEM_handle, pxy);
+
+	return(0);
+}
+
+static int GEM_FlipHWSurface(_THIS, SDL_Surface *surface)
+{
+	if (surface->flags & SDL_FULLSCREEN) {
+		return GEM_FlipHWSurfaceFullscreen(this, surface);
+	} else {
+		return GEM_FlipHWSurfaceWindowed(this, surface);
+	}
+}
+
+static int GEM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
+{
+	int i;
+	SDL_Surface *surface;
+
+	/* Do not change palette in True Colour */
+	surface = this->screen;
+	if (surface->format->BitsPerPixel > 8) {
+		return 1;
+	}
+
+
+	for(i = 0; i < ncolors; i++)
+	{
+		int		r, g, b;
+		short	rgb[3];
+
+		r = colors[i].r;
+		g = colors[i].g;
+		b = colors[i].b;
+
+		rgb[0] = (1000 * r) / 255;
+		rgb[1] = (1000 * g) / 255;
+		rgb[2] = (1000 * b) / 255;
+
+		vs_color(VDI_handle, vdi_index[firstcolor+i], rgb);
+	}
+
+	return(1);
+}
+
+#if 0
+static int GEM_ToggleFullScreen(_THIS, int on)
+{
+	if (on) {
+		if (!GEM_locked) {
+			/* Lock AES */
+			while (!wind_update(BEG_UPDATE|BEG_MCTRL));
+			GEM_locked=SDL_TRUE;
+		}
+	} else {
+		if (GEM_locked) {
+			/* Unlock AES */
+			wind_update(END_UPDATE|END_MCTRL);
+			GEM_locked=SDL_FALSE;
+		}
+		/* Redraw all screen */
+	}
+
+	return(1);
+}
+#endif
+
+/* Note:  If we are terminated, this could be called in the middle of
+   another SDL video routine -- notably UpdateRects.
+*/
+void GEM_VideoQuit(_THIS)
+{
+	GEM_FreeBuffers(this);
+
+	if (GEM_locked) {
+		/* Restore screen memory, and send REDRAW to all apps */
+		form_dial( FMD_FINISH, 0,0,0,0, 0,0,VDI_w,VDI_h);
+		/* Unlock AES */
+		wind_update(END_UPDATE|END_MCTRL);
+		GEM_locked=SDL_FALSE;
+	}
+
+	/* Close AES application */
+	appl_exit();
+
+	/* Restore palette */
+	if (VDI_oldnumcolors) {
+		int i;
+
+		for(i = 0; i < VDI_oldnumcolors; i++) {
+			short	rgb[3];
+
+			rgb[0] = VDI_oldpalette[i][0];
+			rgb[1] = VDI_oldpalette[i][1];
+			rgb[2] = VDI_oldpalette[i][2];
+
+			vs_color(VDI_handle, i, rgb);
+		}
+	}
+
+	/* Close VDI workstation */
+	if (VDI_handle) {
+		v_clsvwk(VDI_handle);
+	}
+
+	/* Free mode list */
+	if (SDL_modelist[0]) {
+		free(SDL_modelist[0]);
+		SDL_modelist[0]=NULL;
+	}
+
+	this->screen->pixels = NULL;	
+}
+
+void GEM_wind_redraw(_THIS, int winhandle, short *inside)
+{
+	short todo[4];
+
+	/* Tell AES we are going to update */
+	while (!wind_update(BEG_UPDATE));
+
+	v_hide_c(VDI_handle);
+
+	/* Browse the rectangle list to redraw */
+	wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
+
+	while (todo[2] && todo[3]) {
+
+		if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
+			todo[2] += todo[0]-1;
+			todo[3] += todo[1]-1;
+			refresh_window(this, winhandle, todo);
+		}
+
+		wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3]);
+	}
+
+	/* Update finished */
+	wind_update(END_UPDATE);
+
+	v_show_c(VDI_handle,1);
+}
+
+static void refresh_window(_THIS, int winhandle, short *rect)
+{
+	MFDB	mfdb_src;
+	short	pxy[8], wind_pxy[8];
+	int iconified;
+	SDL_Surface *surface;
+
+	surface=this->screen;
+
+	/* Is window iconified ? */
+	iconified = 0;
+	if (GEM_wfeatures & (1<<WF_ICONIFY)) {
+		wind_get(winhandle, WF_ICONIFY, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
+		iconified = pxy[0];
+	}
+
+	wind_get(winhandle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
+
+	if (iconified) {
+		/* Refresh icon */
+		mfdb_src.fd_addr=surface->pixels;	/* Should be icon image */
+		mfdb_src.fd_w=surface->w;
+		mfdb_src.fd_h=surface->h;
+		mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
+	  	mfdb_src.fd_stand=0;
+  		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
+		mfdb_src.fd_r1=0;
+  		mfdb_src.fd_r2=0;
+	  	mfdb_src.fd_r3=0;
+	} else {
+		/* Refresh window */
+		mfdb_src.fd_addr=surface->pixels;
+		mfdb_src.fd_w=surface->w;
+		mfdb_src.fd_h=surface->h;
+		mfdb_src.fd_wdwidth=mfdb_src.fd_w>>4;
+	  	mfdb_src.fd_stand=0;
+  		mfdb_src.fd_nplanes=surface->format->BitsPerPixel;
+		mfdb_src.fd_r1=0;
+  		mfdb_src.fd_r2=0;
+	  	mfdb_src.fd_r3=0;
+	}
+
+	pxy[0] = rect[0] - wind_pxy[0];
+	pxy[1] = rect[1] - wind_pxy[1];
+ 	pxy[2] = pxy[0] + rect[2] - rect[0];   
+ 	pxy[3] = pxy[1] + rect[3] - rect[1];  
+
+	pxy[4] = rect[0];
+	pxy[5] = rect[1];
+	pxy[6] = rect[2];  
+	pxy[7] = rect[3];
+
+	vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemvideo.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,112 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#ifndef _SDL_gemvideo_h
+#define _SDL_gemvideo_h
+
+#include "SDL_sysvideo.h"
+#include "SDL_mutex.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+/* Functions prototypes */
+void GEM_wind_redraw(_THIS, int winhandle, short *inside);
+
+/* Private display data */
+
+#define SDL_NUMMODES	1		/* Fullscreen */
+
+struct SDL_PrivateVideoData {
+	/* VDI infos */
+	short vdi_handle;			/* VDI handle */
+	short full_w, full_h;		/* Fullscreen size */
+    int bpp;					/* Colour depth */
+	int pixelsize;				/* Bytes per pixel */
+	Uint16 old_numcolors;		/* Number of colors in saved palette */
+	Uint16 old_palette[256][3];	/* Saved current palette */
+	Uint16 pitch;				/* Line length */
+	int format;					/* Screen format */
+	void *screen;				/* Screen address */
+	Uint32 red, green, blue, alpha;	/* Screen components */
+	Uint32 screensize;
+	MFDB	src_mfdb, dst_mfdb;	/* VDI MFDB for bitblt */
+	short	blit_coords[8];		/* Coordinates for bitblt */
+	/* Gem infos */
+	short ap_id;				/* AES handle */
+	short desk_x, desk_y;		/* Desktop properties */
+	short desk_w, desk_h;
+	short win_handle;			/* Our window handle */
+    void *buffer;				/* Our shadow buffer */
+	int window_type;			/* Window type */
+	const char *title_name;		/* Window title */
+	const char *icon_name;		/* Icon title */
+	short version;				/* AES version */
+	short wfeatures;			/* AES window features */
+	SDL_bool window_fulled;		/* Window maximized ? */
+	SDL_bool mouse_relative;	/* Report relative mouse movement */
+	SDL_bool locked;			/* AES locked for fullscreen ? */
+	SDL_Rect *SDL_modelist[SDL_NUMMODES+1];	/* Mode list */
+};
+
+/* Hidden structure -> variables names */
+#define VDI_handle			(this->hidden->vdi_handle)
+#define VDI_w				(this->hidden->full_w)
+#define VDI_h				(this->hidden->full_h)
+#define VDI_bpp				(this->hidden->bpp)
+#define VDI_pixelsize		(this->hidden->pixelsize)
+#define VDI_oldnumcolors	(this->hidden->old_numcolors)
+#define VDI_oldpalette		(this->hidden->old_palette)
+#define VDI_pitch			(this->hidden->pitch)
+#define VDI_format			(this->hidden->format)
+#define VDI_screen			(this->hidden->screen)
+#define VDI_redmask			(this->hidden->red)
+#define VDI_greenmask		(this->hidden->green)
+#define VDI_bluemask		(this->hidden->blue)
+#define VDI_alphamask		(this->hidden->alpha)
+#define VDI_screensize		(this->hidden->screensize)
+#define VDI_src_mfdb		(this->hidden->src_mfdb)
+#define VDI_dst_mfdb		(this->hidden->dst_mfdb)
+#define VDI_blit_coords		(this->hidden->blit_coords)
+#define GEM_ap_id			(this->hidden->ap_id)
+#define GEM_desk_x			(this->hidden->desk_x)
+#define GEM_desk_y			(this->hidden->desk_y)
+#define GEM_desk_w			(this->hidden->desk_w)
+#define GEM_desk_h			(this->hidden->desk_h)
+#define GEM_handle			(this->hidden->win_handle)
+#define GEM_buffer			(this->hidden->buffer)
+#define GEM_win_type		(this->hidden->window_type)
+#define GEM_title_name		(this->hidden->title_name)
+#define GEM_icon_name		(this->hidden->icon_name)
+#define GEM_version			(this->hidden->version)
+#define GEM_wfeatures		(this->hidden->wfeatures)
+#define GEM_win_fulled		(this->hidden->window_fulled)
+#define GEM_mouse_relative	(this->hidden->mouse_relative)
+#define GEM_locked			(this->hidden->locked)
+#define SDL_modelist		(this->hidden->SDL_modelist)
+
+#endif /* _SDL_gemvideo_h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemwm.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,115 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	GEM SDL video driver implementation
+ *	Window manager functions
+ * 
+ *	Patrice Mandin
+ */
+
+/* Mint includes */
+#include <gem.h>
+
+#include "SDL_gemwm_c.h"
+
+/* Defines */
+
+#define ICONWIDTH 64
+#define ICONHEIGHT 64
+
+/* Functions */
+
+void GEM_SetCaption(_THIS, const char *title, const char *icon)
+{
+	short parm[4];
+	const char *new_name;
+
+	new_name = NULL;
+
+	if (title)
+		GEM_title_name = title;
+
+	if (icon)
+		GEM_icon_name = icon;
+
+	/* Is window iconified ? */
+	parm[0]=0;
+	if (GEM_wfeatures & (1<<WF_ICONIFY))
+		wind_get(GEM_handle, WF_ICONIFY, &parm[0], &parm[1], &parm[2], &parm[3]);
+
+	if (parm[0]==0) {
+		/* Change window name */
+		if (title)
+			new_name = title;
+	} else {
+		/* Change icon name */
+		if (icon)
+			new_name = icon;
+	}
+
+	parm[0]= ((unsigned long) new_name)>>16;
+	parm[1]= ((unsigned long) new_name) & 65535;
+
+	if (new_name) {
+		wind_set(GEM_handle, WF_NAME, parm[0], parm[1], 0, 0);
+	}
+}
+
+void GEM_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
+{
+	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0)
+		return;
+
+	/* Todo */
+}
+
+int GEM_IconifyWindow(_THIS)
+{
+	short message[8];
+	
+	if ((GEM_wfeatures & (1<<WF_ICONIFY))==0)
+		return 0;
+
+	message[0] = WM_ICONIFY;
+	message[1] = GEM_ap_id;
+	message[2] = 0;
+	message[3] = GEM_handle;
+	message[4] = 0;
+	message[5] = GEM_desk_h-ICONHEIGHT;
+	message[6] = ICONWIDTH;
+	message[7] = ICONHEIGHT;
+
+	appl_write(GEM_ap_id, sizeof(message), message);
+
+	return 1;
+}
+
+SDL_GrabMode GEM_GrabInput(_THIS, SDL_GrabMode mode)
+{
+	return mode;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/gem/SDL_gemwm_c.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,41 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ *	GEM SDL video driver implementation
+ *	Window manager functions
+ * 
+ *	Patrice Mandin
+ */
+
+#include "SDL_gemvideo.h"
+
+/* Functions prototypes */
+extern void GEM_SetCaption(_THIS, const char *title, const char *icon);
+extern void GEM_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask);
+extern int GEM_IconifyWindow(_THIS);
+extern SDL_GrabMode GEM_GrabInput(_THIS, SDL_GrabMode mode);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/xbios/Makefile.am	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,10 @@
+
+## Makefile.am for SDL using the XBIOS video driver
+
+noinst_LTLIBRARIES = libvideo_xbios.la
+libvideo_xbios_la_SOURCES = $(XBIOS_SRCS)
+
+# The SDL XBIOS video driver sources
+XBIOS_SRCS = 	\
+	SDL_xbios.c	\
+	SDL_xbios.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/xbios/SDL_xbios.c	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,757 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+/*
+ * Xbios SDL video driver
+ * 
+ * Patrice Mandin
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/* Mint includes */
+#include <sys/cookie.h>
+#include <mint/osbind.h>
+#include <mint/falcon.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_ataric2p_s.h"
+#include "SDL_ataric2p060_c.h"
+#include "SDL_atarievents_c.h"
+#include "SDL_atarimxalloc_c.h"
+#include "SDL_xbios.h"
+
+#define XBIOS_VID_DRIVER_NAME "xbios"
+
+/* Initialization/Query functions */
+static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
+static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
+static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
+static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
+static void XBIOS_VideoQuit(_THIS);
+
+/* Hardware surface functions */
+static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface);
+static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface);
+static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface);
+static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
+static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
+static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
+
+/* List of video modes */
+
+/* ST modes */
+static int xbiosnummodes_st=1;
+static xbiosmode_t xbiosmodelist_st[]={
+	{ST_LOW>>8,320,200,4,SDL_FALSE}
+};
+
+/* TT modes */
+static int xbiosnummodes_tt=2;
+static xbiosmode_t xbiosmodelist_tt[]={
+	{TT_LOW,320,480,8,SDL_FALSE},
+	{TT_LOW,320,240,8,SDL_TRUE}	/* Software double-lined mode */
+};
+
+/* Falcon RVB modes */
+static int xbiosnummodes_f30rvb=16;
+static xbiosmode_t xbiosmodelist_f30rvb[]={
+	{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
+	{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
+	{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
+	{BPS16|COL80,640,200,16,SDL_FALSE},
+	{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
+	{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
+	{BPS16|VERTFLAG,320,400,16,SDL_FALSE},
+	{BPS16,320,200,16,SDL_FALSE},
+
+	{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
+	{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
+	{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
+	{BPS8|COL80,640,200,8,SDL_FALSE},
+	{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
+	{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
+	{BPS8|VERTFLAG,320,400,8,SDL_FALSE},
+	{BPS8,320,200,8,SDL_FALSE}
+};
+
+/* Falcon VGA modes */
+static int xbiosnummodes_f30vga=6;
+static xbiosmode_t xbiosmodelist_f30vga[]={
+	{BPS16,320,480,16,SDL_FALSE},
+	{BPS16|VERTFLAG,320,240,16,SDL_FALSE},
+
+	{BPS8|COL80,640,480,8,SDL_FALSE},	
+	{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
+	{BPS8,320,480,8,SDL_FALSE},
+	{BPS8|VERTFLAG,320,240,8,SDL_FALSE}
+};
+
+/* To setup palette */
+
+static unsigned short	TT_palette[256];
+static unsigned long	F30_palette[256];
+
+/* Xbios driver bootstrap functions */
+
+static int XBIOS_Available(void)
+{
+	const char *envr = getenv("SDL_VIDEODRIVER");
+	unsigned long cookie_vdo;
+
+	/* Check if user asked a different video driver */
+	if ((envr) && (strcmp(envr, XBIOS_VID_DRIVER_NAME)!=0)) {
+		return 0;
+	}
+
+	/* Cookie _VDO present ? if not, assume ST machine */
+	if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
+		cookie_vdo = VDO_ST << 16;
+	}
+
+	/* Test if we have a monochrome monitor plugged in */
+	switch( cookie_vdo >>16) {
+		case VDO_ST:
+		case VDO_STE:
+			if ( Getrez() == (ST_HIGH>>8) )
+				return 0;
+			break;
+		case VDO_TT:
+			if ( (EgetShift() & ES_MODE) == TT_HIGH)
+				return 0;
+			break;
+		case VDO_F30:
+			if ( Montype() == MONITOR_MONO)
+				return 0;
+			break;
+		default:
+			return 0;
+	}
+
+	return 1;
+}
+
+static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
+{
+	free(device->hidden);
+	free(device);
+}
+
+static SDL_VideoDevice *XBIOS_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));
+
+	atari_test_cpu060_present();
+
+	/* Video functions */
+	device->VideoInit = XBIOS_VideoInit;
+	device->ListModes = XBIOS_ListModes;
+	device->SetVideoMode = XBIOS_SetVideoMode;
+	device->SetColors = XBIOS_SetColors;
+	device->UpdateRects = NULL;
+	device->VideoQuit = XBIOS_VideoQuit;
+	device->AllocHWSurface = XBIOS_AllocHWSurface;
+	device->LockHWSurface = XBIOS_LockHWSurface;
+	device->UnlockHWSurface = XBIOS_UnlockHWSurface;
+	device->FlipHWSurface = XBIOS_FlipHWSurface;
+	device->FreeHWSurface = XBIOS_FreeHWSurface;
+
+	/* Events */
+	device->InitOSKeymap = Atari_InitOSKeymap;
+	device->PumpEvents = Atari_PumpEvents;
+
+	device->free = XBIOS_DeleteDevice;
+
+	return device;
+}
+
+VideoBootStrap XBIOS_bootstrap = {
+	XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
+	XBIOS_Available, XBIOS_CreateDevice
+};
+
+static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
+{
+	int i,j8,j16;
+	xbiosmode_t *current_mode;
+
+	/* Initialize all variables that we clean on shutdown */
+	memset (SDL_modelist, 0, sizeof(SDL_modelist));
+
+	/* Cookie _VDO present ? if not, assume ST machine */
+	if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) {
+		XBIOS_cvdo = VDO_ST << 16;
+	}
+
+	/* Allocate memory for old palette */
+	XBIOS_oldpalette = (void *)malloc(256*sizeof(long));
+	if ( !XBIOS_oldpalette ) {
+		SDL_SetError("Unable to allocate memory for old palette\n");
+		return(-1);
+	}
+
+	/* Initialize video mode list */
+	/* and save current screen status (palette, screen address, video mode) */
+
+	switch (XBIOS_cvdo >>16) {
+		case VDO_ST:
+		case VDO_STE:
+			{
+				short *oldpalette;
+
+				XBIOS_nummodes=xbiosnummodes_st;
+				XBIOS_modelist=xbiosmodelist_st;
+			
+				XBIOS_oldvbase=Physbase();
+				XBIOS_oldvmode=Getrez();
+				switch(XBIOS_oldvmode << 8) {
+					case ST_LOW:
+						XBIOS_oldnumcol=16;
+						break;
+					case ST_MED:
+						XBIOS_oldnumcol=4;
+						break;
+					case ST_HIGH:
+						XBIOS_oldnumcol=2;
+						break;
+					default:
+						XBIOS_oldnumcol=0;
+						break;
+				}
+
+				oldpalette= (short *) XBIOS_oldpalette;
+				for (i=0;i<XBIOS_oldnumcol;i++) {
+					*oldpalette++=Setcolor(i,-1);
+				}
+
+				vformat->BitsPerPixel = 8;
+			}
+			break;
+		case VDO_TT:
+			XBIOS_nummodes=xbiosnummodes_tt;
+			XBIOS_modelist=xbiosmodelist_tt;
+
+			XBIOS_oldvbase=Logbase();
+			XBIOS_oldvmode=EgetShift();
+
+			switch(XBIOS_oldvmode & ES_MODE) {
+				case TT_LOW:
+					XBIOS_oldnumcol=256;
+					break;
+				case ST_LOW:
+				case TT_MED:
+					XBIOS_oldnumcol=16;
+					break;
+				case ST_MED:
+					XBIOS_oldnumcol=4;
+					break;
+				case ST_HIGH:
+				case TT_HIGH:
+					XBIOS_oldnumcol=2;
+					break;
+				default:
+					XBIOS_oldnumcol=0;
+					break;
+			}
+			if (XBIOS_oldnumcol) {
+				EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+			}
+
+			vformat->BitsPerPixel = 8;
+			break;
+		case VDO_F30:
+			switch (Montype())
+			{
+				case MONITOR_MONO:
+					/* Not usable */
+					break;
+				case MONITOR_RGB:
+				case MONITOR_TV:
+					XBIOS_nummodes = xbiosnummodes_f30rvb;
+					XBIOS_modelist = xbiosmodelist_f30rvb;
+					break;
+				case MONITOR_VGA:
+					XBIOS_nummodes = xbiosnummodes_f30vga;
+					XBIOS_modelist = xbiosmodelist_f30vga;
+					break;
+			}
+			XBIOS_oldvbase=Logbase();
+			XBIOS_oldvmode=Vsetmode(-1);
+
+			XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
+			if (XBIOS_oldnumcol > 256) {
+				XBIOS_oldnumcol = 0;
+			}
+			if (XBIOS_oldnumcol) {
+				VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+			}
+
+			vformat->BitsPerPixel = 16;
+
+			/* Keep vga/rvb, and pal/ntsc bits */
+			current_mode = XBIOS_modelist;
+			for (i=0;i<XBIOS_nummodes;i++) {
+				Uint16 newvmode;			
+
+				newvmode = current_mode->number;
+				newvmode &= ~(VGA|PAL);
+				newvmode |= XBIOS_oldvmode & (VGA|PAL);
+				current_mode->number = newvmode;
+				
+				current_mode++;
+			}
+
+			break;
+	}
+	
+	current_mode = XBIOS_modelist;
+	j8 = j16 = 0;
+	for (i=0;i<XBIOS_nummodes;i++) {
+		switch (current_mode->depth) {
+			case 4:
+			case 8:
+				SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect));
+				SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0;
+				SDL_modelist[0][j8]->w = current_mode->width;
+				SDL_modelist[0][j8]->h = current_mode->height;
+				XBIOS_videomodes[0][j8]=current_mode;
+				current_mode++;
+				j8++;
+				break;
+			case 16:
+				SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect));
+				SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0;
+				SDL_modelist[1][j16]->w = current_mode->width;
+				SDL_modelist[1][j16]->h = current_mode->height;
+				XBIOS_videomodes[1][j16]=current_mode;
+				current_mode++;
+				j16++;
+				break;
+		}		
+	}
+	SDL_modelist[0][j8] = NULL;
+	SDL_modelist[1][j16] = NULL;
+
+	XBIOS_screens[0]=NULL;
+	XBIOS_screens[1]=NULL;
+	XBIOS_shadowscreen=NULL;
+
+	/* Update hardware info */
+	this->info.hw_available = 1;
+	this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM);
+
+	/* Init chunky to planar routine */
+	Atari_C2pInit = Atari_C2pInit8;
+	if (atari_cpu060_avail) {
+		Atari_C2pConvert = Atari_C2pConvert8_060;
+	} else {
+		Atari_C2pConvert = Atari_C2pConvert8;
+	}
+	Atari_C2pInit();
+
+	/* We're done! */
+	return(0);
+}
+
+static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
+{
+	/* 8 bits -> list 0 */
+	/* 16 bits -> list 1 */
+	return(SDL_modelist[(format->BitsPerPixel)>>4]);
+}
+
+static void XBIOS_FreeBuffers(_THIS)
+{
+	int i;
+
+	for (i=0;i<2;i++) {
+		if (XBIOS_screensmem[i]!=NULL) {
+			Mfree(XBIOS_screensmem[i]);
+			XBIOS_screensmem[i]=NULL;
+		}
+	}
+
+	if (XBIOS_shadowscreen!=NULL) {
+		Mfree(XBIOS_shadowscreen);
+		XBIOS_shadowscreen=NULL;
+	}
+}
+
+static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
+				int width, int height, int bpp, Uint32 flags)
+{
+	int mode, new_depth;
+	int i;
+	xbiosmode_t *new_video_mode;
+	Uint32 new_screen_size;
+	Uint32 modeflags;
+
+	/* Free current buffers */
+	XBIOS_FreeBuffers(this);
+
+	/* Search if the mode exists (width, height, bpp) */
+	bpp >>= 4;
+	for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
+		if ( (SDL_modelist[bpp][mode]->w == width) &&
+		     (SDL_modelist[bpp][mode]->h == height) ) {
+
+			break;
+		}
+	}
+	if ( SDL_modelist[bpp][mode] == NULL ) {
+		SDL_SetError("Couldn't find requested mode in list");
+		return(NULL);
+	}
+
+	modeflags = (SDL_FULLSCREEN|SDL_HWPALETTE);
+
+	/* Allocate needed buffers: simple/double buffer and shadow surface */
+	new_video_mode = XBIOS_videomodes[bpp][mode];
+	new_depth = new_video_mode->depth;
+	if (new_depth == 4) {
+		Atari_C2pInit = Atari_C2pInit4;
+		if (atari_cpu060_avail) {
+			Atari_C2pConvert = Atari_C2pConvert4_060;
+		} else {
+			Atari_C2pConvert = Atari_C2pConvert4;
+		}
+		new_depth=8;
+		modeflags |= SDL_SWSURFACE;
+	} else if (new_depth == 8) {
+		Atari_C2pInit = Atari_C2pInit8;
+		if (atari_cpu060_avail) {
+			Atari_C2pConvert = Atari_C2pConvert8_060;
+		} else {
+			Atari_C2pConvert = Atari_C2pConvert8;
+		}
+		modeflags |= SDL_SWSURFACE;
+	} else {
+		modeflags |= SDL_HWSURFACE;
+	}
+
+	new_screen_size = width * height * ((new_depth)>>3);
+	new_screen_size += 256; /* To align on a 256 byte adress */	
+
+	if (new_depth == 8) {
+		XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
+
+		if (XBIOS_shadowscreen == NULL) {
+			SDL_SetError("XBIOS_SetVideoMode: Not enough memory for shadow surface");
+			return (NULL);
+		}
+	}
+
+	/* Output buffer needs to be twice in size for the software double-line mode */
+	XBIOS_doubleline = SDL_FALSE;
+	if (new_video_mode->doubleline) {
+		new_screen_size <<= 1;
+		XBIOS_doubleline = SDL_TRUE;
+	}
+
+	XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM);
+
+	if (XBIOS_screensmem[0]==NULL) {
+		XBIOS_FreeBuffers(this);
+		SDL_SetError("XBIOS_SetVideoMode: Not enough memory for video buffer");
+		return (NULL);
+	}
+
+	XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
+
+	/* Double buffer ? */
+	if (flags & SDL_DOUBLEBUF) {
+		XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM);
+
+		if (XBIOS_screensmem[1]==NULL) {
+			XBIOS_FreeBuffers(this);
+			SDL_SetError("XBIOS_SetVideoMode: Not enough memory for double buffer");
+			return (NULL);
+		}
+
+		XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL);
+		modeflags |= SDL_DOUBLEBUF;
+	}
+	
+	/* Allocate the new pixel format for the screen */
+	if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
+		XBIOS_FreeBuffers(this);
+		SDL_SetError("Couldn't allocate new pixel format for requested mode");
+		return(NULL);
+	}
+
+	current->flags = modeflags;
+	current->w = XBIOS_width = width;
+	current->h = XBIOS_height = height;
+	current->pitch = (width * new_depth)>>3;
+
+	/* this is for C2P conversion */
+	XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
+
+	if (new_depth == 8)
+		current->pixels = XBIOS_shadowscreen;
+	else
+		current->pixels = XBIOS_screens[0];
+
+	XBIOS_fbnum = 0;
+
+	/* Now set the video mode */
+	Setscreen(-1,XBIOS_screens[0],-1);
+
+	switch(XBIOS_cvdo >> 16) {
+		case VDO_ST:
+			Setscreen(-1,-1,new_video_mode->number);
+			/* Reset palette */
+			for (i=0;i<16;i++) {
+				int c;
+
+				c = ((i>>1)<<8) | ((i>>1)<<4) | (i>>1);
+				if ((i & 1) && (i<15))
+					c += (1<<4);
+				if (i==14)
+					c -= 1<<8;
+
+				TT_palette[i]= c;
+			}
+			Setpalette(TT_palette);
+			break;
+		case VDO_STE:
+			Setscreen(-1,-1,new_video_mode->number);
+			/* Reset palette */
+			for (i=0;i<16;i++)
+			{
+				int c;
+
+				c=((i&1)<<3)|((i>>1)&7);
+				TT_palette[i]=(c<<8)|(c<<4)|c;
+			}
+			Setpalette(TT_palette);
+			break;
+		case VDO_TT:
+			EsetShift(new_video_mode->number);
+			break;
+		case VDO_F30:
+			Vsetmode(new_video_mode->number);
+			break;
+	}
+
+	Vsync();
+
+	this->UpdateRects = XBIOS_UpdateRects;
+
+	return (current);
+}
+
+/* We don't actually allow hardware surfaces other than the main one */
+static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface)
+{
+	return(-1);
+}
+
+static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface)
+{
+	return(0);
+}
+
+static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
+{
+	return;
+}
+
+static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
+{
+	SDL_Surface *surface;
+	
+	surface = this->screen;
+
+	XBIOS_FlipHWSurface(this, surface);
+}
+
+static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
+{
+	if ((surface->format->BitsPerPixel) == 8) {
+		void *destscr;
+		int destx;
+			
+		/* Center on destination screen */
+		destscr = XBIOS_screens[XBIOS_fbnum];
+		destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
+		destx = (XBIOS_width - surface->w) >> 1;
+		destx &= ~15;
+		destscr += destx;
+
+		/* Convert chunky to planar screen */
+		Atari_C2pConvert(
+			surface->pixels,
+			destscr,
+			surface->w,
+			surface->h,
+			XBIOS_doubleline,
+			surface->pitch,
+			XBIOS_pitch
+		);
+	}
+
+	Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1);
+	Vsync();
+
+	if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
+		XBIOS_fbnum ^= 1;				
+	}
+
+	return(0);
+}
+
+static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
+{
+	int		i;
+	int		r,v,b;
+
+	switch( XBIOS_cvdo >> 16) {
+		case VDO_ST:
+		case VDO_STE:
+		 	for (i=0;i<ncolors;i++)
+			{
+				r = colors[i].r;	
+				v = colors[i].g;
+				b = colors[i].b;
+
+				TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100;
+			}
+			Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */
+			break;
+		case VDO_TT:
+			for(i = 0; i < ncolors; i++)
+			{
+				r = colors[i].r;	
+				v = colors[i].g;
+				b = colors[i].b;
+					
+				TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
+			}
+			EsetPalette(firstcolor,ncolors,TT_palette);
+			break;
+		case VDO_F30:
+			for(i = 0; i < ncolors; i++)
+			{
+				r = colors[i].r;	
+				v = colors[i].g;
+				b = colors[i].b;
+
+				F30_palette[i]=(r<<16)|(v<<8)|b;
+			}
+			VsetRGB(firstcolor,ncolors,F30_palette);
+			break;
+	}
+
+	return(1);
+}
+
+/* Note:  If we are terminated, this could be called in the middle of
+   another SDL video routine -- notably UpdateRects.
+*/
+static void XBIOS_VideoQuit(_THIS)
+{
+	int i,j;
+
+	Atari_ShutdownEvents();
+
+	/* Restore video mode and palette */
+	switch(XBIOS_cvdo >> 16) {
+		case VDO_ST:
+		case VDO_STE:
+			Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode);
+			if (XBIOS_oldnumcol) {
+				Setpalette(XBIOS_oldpalette);
+			}
+			break;
+		case VDO_TT:
+			Setscreen(-1,XBIOS_oldvbase,-1);
+			EsetShift(XBIOS_oldvmode);
+			if (XBIOS_oldnumcol) {
+				EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+			}
+			break;
+		case VDO_F30:
+			Setscreen(-1, XBIOS_oldvbase, -1);
+			Vsetmode(XBIOS_oldvmode);
+			if (XBIOS_oldnumcol) {
+				VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
+			}
+			break;
+	}
+	Vsync();
+
+	if (XBIOS_oldpalette) {
+		free(XBIOS_oldpalette);
+		XBIOS_oldpalette=NULL;
+	}
+	XBIOS_FreeBuffers(this);
+
+	/* Free mode list */
+	for (j=0;j<NUM_MODELISTS;j++) {
+		for (i=0;i<SDL_NUMMODES;i++) {
+			if (SDL_modelist[j][i]!=NULL) {
+				free(SDL_modelist[j][i]);
+				SDL_modelist[j][i]=NULL;
+			}
+		}
+	}
+
+	this->screen->pixels = NULL;	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/xbios/SDL_xbios.h	Sun Feb 17 19:54:28 2002 +0000
@@ -0,0 +1,127 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997, 1998, 1999, 2000, 2001  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$";
+#endif
+
+#ifndef _SDL_xbios_h
+#define _SDL_xbios_h
+
+#include "SDL_types.h"
+#include "SDL_sysvideo.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS	SDL_VideoDevice *this
+
+/* TT video modes:	2
+   Falcon RVB:		16 (could be *2 by adding PAL/NTSC modes)
+   Falcon VGA:		6
+   ST low:		1
+*/
+#define SDL_NUMMODES 16
+
+typedef struct
+{
+	Uint16 number;		/* Video mode number */
+	Uint16 width;		/* Size */	
+	Uint16 height;
+	Uint16 depth;		/* bits per plane */
+	SDL_bool doubleline;	/* Double the lines ? */
+} xbiosmode_t;
+
+/* Private display data */
+#define NUM_MODELISTS	2		/* 8 and 16 bits-per-pixel */
+
+struct SDL_PrivateVideoData {
+	long cookie_vdo;
+	int old_video_mode;				/* Old video mode before entering SDL */
+	void *old_video_base;			/* Old pointer to screen buffer */
+	void *old_palette;				/* Old palette */
+	Uint32 old_num_colors;			/* Nb of colors in saved palette */
+	int num_modes;					/* Number of xbios video modes */
+	xbiosmode_t	*mode_list;			/* List of xbios video modes */
+
+	void *screens[2];		/* Pointers to aligned screen buffer */
+	void *screensmem[2];	/* Pointers to screen buffer */
+	void *shadowscreen;		/* Shadow screen for c2p conversion */
+	int doubleline;			/* Double line mode ? */
+	int frame_number;		/* Number of frame for double buffer */
+	int pitch;				/* Destination line width for C2P */
+	int width, height;		/* Screen size for centered C2P */
+
+	SDL_Rect *SDL_modelist[NUM_MODELISTS][SDL_NUMMODES+1];
+	xbiosmode_t *videomodes[NUM_MODELISTS][SDL_NUMMODES+1];
+};
+
+/* _VDO cookie values */
+enum {
+	VDO_ST=0,
+	VDO_STE,
+	VDO_TT,
+	VDO_F30
+};
+
+/* Monitor types */
+enum {
+	MONITOR_MONO=0,
+	MONITOR_TV,
+	MONITOR_VGA,
+	MONITOR_RGB
+};
+
+/* EgetShift masks */
+#define ES_BANK		0x000f
+#define ES_MODE		0x0700
+#define ES_GRAY		0x1000
+#define ES_SMEAR	0x8000
+
+/* TT shifter modes */
+#define ST_LOW	0x0000
+#define ST_MED	0x0100
+#define ST_HIGH	0x0200
+#define TT_LOW	0x0700
+#define TT_MED	0x0300
+#define TT_HIGH	0x0600
+
+/* Hidden structure -> variables names */
+#define SDL_modelist		(this->hidden->SDL_modelist)
+#define XBIOS_mutex		    (this->hidden->mutex)
+#define XBIOS_cvdo		    (this->hidden->cookie_vdo)
+#define XBIOS_oldpalette	(this->hidden->old_palette)
+#define XBIOS_oldnumcol		(this->hidden->old_num_colors)
+#define XBIOS_oldvbase		(this->hidden->old_video_base)
+#define XBIOS_oldvmode		(this->hidden->old_video_mode)
+#define XBIOS_nummodes		(this->hidden->num_modes)
+#define XBIOS_modelist		(this->hidden->mode_list)
+#define XBIOS_screens		(this->hidden->screens)
+#define XBIOS_screensmem	(this->hidden->screensmem)
+#define XBIOS_shadowscreen	(this->hidden->shadowscreen)
+#define XBIOS_videomodes	(this->hidden->videomodes)
+#define XBIOS_doubleline	(this->hidden->doubleline)
+#define XBIOS_fbnum			(this->hidden->frame_number)
+#define XBIOS_pitch			(this->hidden->pitch)
+#define XBIOS_width			(this->hidden->width)
+#define XBIOS_height		(this->hidden->height)
+
+#endif /* _SDL_xbios_h */