Added initial support for RISC OS (thanks Peter Naulls!)
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 May 2003 04:44:13 +0000
changeset 630550bccdf04bd
parent 629 3fa401bb4bb5
child 631 52864d66d168
Added initial support for RISC OS (thanks Peter Naulls!)
README
include/SDL_syswm.h
src/audio/Makefile.am
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/riscos/Makefile.am
src/audio/riscos/SDL_drenderer.c
src/audio/riscos/SDL_drenderer.h
src/joystick/Makefile.am
src/joystick/riscos/Makefile.am
src/joystick/riscos/SDL_sysjoystick.c
src/timer/Makefile.am
src/timer/riscos/SDL_systimer.c
src/video/Makefile.am
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/riscos/Makefile.am
src/video/riscos/SDL_riscosFullScreenVideo.c
src/video/riscos/SDL_riscosevents.c
src/video/riscos/SDL_riscosevents_c.h
src/video/riscos/SDL_riscosmouse.c
src/video/riscos/SDL_riscosmouse_c.h
src/video/riscos/SDL_riscossprite.c
src/video/riscos/SDL_riscostask.c
src/video/riscos/SDL_riscostask.h
src/video/riscos/SDL_riscosvideo.c
src/video/riscos/SDL_riscosvideo.h
src/video/riscos/SDL_wimppoll.c
src/video/riscos/SDL_wimpvideo.c
     1.1 --- a/README	Thu May 29 04:37:17 2003 +0000
     1.2 +++ b/README	Thu May 29 04:44:13 2003 +0000
     1.3 @@ -19,7 +19,7 @@
     1.4  The current version supports Linux, Windows, BeOS, MacOS, MacOS X,
     1.5  FreeBSD, OpenBSD, BSD/OS, Solaris, and IRIX.  The code contains support
     1.6  for Windows CE, AmigaOS, Dreamcast, Atari, QNX, NetBSD, AIX, OSF/Tru64,
     1.7 -and SymbianOS, but these are not officially supported.
     1.8 +RISC OS, and SymbianOS, but these are not officially supported.
     1.9  
    1.10  This library is distributed under GNU LGPL version 2, which can be
    1.11  found in the file  "COPYING".  This license allows you to use SDL
     2.1 --- a/include/SDL_syswm.h	Thu May 29 04:37:17 2003 +0000
     2.2 +++ b/include/SDL_syswm.h	Thu May 29 04:44:13 2003 +0000
     2.3 @@ -130,6 +130,23 @@
     2.4  	HGLRC hglrc;			/* The OpenGL context, if any */
     2.5  } SDL_SysWMinfo;
     2.6  
     2.7 +#elif defined(__riscos__)
     2.8 +
     2.9 +/* RISC OS custom event structure */
    2.10 +struct SDL_SysWMmsg {
    2.11 +	SDL_version version;
    2.12 +	int eventCode;		/* The window for the message */
    2.13 +	int pollBlock[64];
    2.14 +};
    2.15 +
    2.16 +/* The RISCOS custom window manager information structure */
    2.17 +typedef struct {
    2.18 +	SDL_version version;
    2.19 +	int wimpVersion;    /* Wimp version running under */
    2.20 +	int taskHandle;     /* The RISCOS task handle */
    2.21 +	int window;			/* The RISCOS display window */
    2.22 +} SDL_SysWMinfo;
    2.23 +
    2.24  #else
    2.25  
    2.26  /* The generic custom event structure */
     3.1 --- a/src/audio/Makefile.am	Thu May 29 04:37:17 2003 +0000
     3.2 +++ b/src/audio/Makefile.am	Thu May 29 04:44:13 2003 +0000
     3.3 @@ -6,7 +6,7 @@
     3.4  # Define which subdirectories need to be built
     3.5  SUBDIRS = @AUDIO_SUBDIRS@
     3.6  DIST_SUBDIRS = alsa arts baudio dma dmedia dsp esd macrom nas nto openbsd \
     3.7 -	paudio sun ums windib windx5 disk mint dc
     3.8 +	paudio riscos sun ums windib windx5 disk mint dc
     3.9  
    3.10  DRIVERS = @AUDIO_DRIVERS@
    3.11  
     4.1 --- a/src/audio/SDL_audio.c	Thu May 29 04:37:17 2003 +0000
     4.2 +++ b/src/audio/SDL_audio.c	Thu May 29 04:44:13 2003 +0000
     4.3 @@ -92,6 +92,9 @@
     4.4  #ifdef ENABLE_DC
     4.5  	&DCAUD_bootstrap,
     4.6  #endif
     4.7 +#ifdef DRENDERER_SUPPORT
     4.8 +	&DRENDERER_bootstrap,
     4.9 +#endif
    4.10  	NULL
    4.11  };
    4.12  SDL_AudioDevice *current_audio = NULL;
    4.13 @@ -381,7 +384,7 @@
    4.14  		return(-1);
    4.15  	}
    4.16  
    4.17 -#ifdef macintosh
    4.18 +#if defined(macintosh) || defined(__riscos__)
    4.19  	/* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
    4.20  #else
    4.21  #if defined(__MINT__) && !defined(ENABLE_THREADS)
     5.1 --- a/src/audio/SDL_sysaudio.h	Thu May 29 04:37:17 2003 +0000
     5.2 +++ b/src/audio/SDL_sysaudio.h	Thu May 29 04:44:13 2003 +0000
     5.3 @@ -156,6 +156,9 @@
     5.4  #ifdef ENABLE_DC
     5.5  extern AudioBootStrap DCAUD_bootstrap;
     5.6  #endif
     5.7 +#ifdef DRENDERER_SUPPORT
     5.8 +extern AudioBootStrap DRENDERER_bootstrap;
     5.9 +#endif
    5.10  
    5.11  /* This is the current audio device */
    5.12  extern SDL_AudioDevice *current_audio;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/audio/riscos/Makefile.am	Thu May 29 04:44:13 2003 +0000
     6.3 @@ -0,0 +1,9 @@
     6.4 +
     6.5 +## Makefile.am for SDL using the RISC OS audio system
     6.6 +
     6.7 +noinst_LTLIBRARIES = libaudio_riscos.la
     6.8 +libaudio_riscos_la_SOURCES = $(SRCS)
     6.9 +
    6.10 +# The SDL audio driver sources
    6.11 +SRCS =	SDL_drenderer.c	\
    6.12 +	SDL_drenderer.h
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/audio/riscos/SDL_drenderer.c	Thu May 29 04:44:13 2003 +0000
     7.3 @@ -0,0 +1,293 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Library General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Library General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Library General Public
    7.19 +    License along with this library; if not, write to the Free
    7.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@devolution.com
    7.24 +*/
    7.25 +
    7.26 +
    7.27 +#include <stdlib.h>
    7.28 +#include <stdio.h>
    7.29 +#include <memory.h>
    7.30 +
    7.31 +#include <kernel.h>
    7.32 +#include "swis.h"
    7.33 +
    7.34 +#include "SDL_endian.h"
    7.35 +#include "SDL_audio.h"
    7.36 +#include "SDL_audio_c.h"
    7.37 +#include "SDL_audiomem.h"
    7.38 +#include "SDL_sysaudio.h"
    7.39 +#include "SDL_drenderer.h"
    7.40 +
    7.41 +#define DigitalRenderer_Activate    0x4F700
    7.42 +#define DigitalRenderer_Deactivate	0x4F701
    7.43 +#define DigitalRenderer_ReadState	0x4F705
    7.44 +#define DigitalRenderer_NewSample	0x4F706
    7.45 +#define DigitalRenderer_NumBuffers	0x4F709
    7.46 +#define DigitalRenderer_StreamSamples  0x4F70A
    7.47 +#define DigitalRenderer_Stream16BitSamples	0x4F70B
    7.48 +#define DigitalRenderer_StreamStatistics	0x4F70C
    7.49 +#define DigitalRenderer_StreamFlags     0x4F70D
    7.50 +#define DigitalRenderer_Activate16		0x4F70F
    7.51 +#define DigitalRenderer_GetFrequency	0x4F710
    7.52 +
    7.53 +static int FillBuffer;
    7.54 +extern SDL_AudioDevice *current_audio;
    7.55 +
    7.56 +extern int riscos_audiobuffer; /* Override for audio buffer size */
    7.57 +
    7.58 +/* Audio driver functions */
    7.59 +
    7.60 +static void DRenderer_CloseAudio(_THIS);
    7.61 +static int DRenderer_OpenAudio(_THIS, SDL_AudioSpec *spec);
    7.62 +
    7.63 +/* Audio driver bootstrap functions */
    7.64 +
    7.65 +/* Define following to dump stats to stdout */
    7.66 +/* #define DUMP_AUDIO */
    7.67 +
    7.68 +
    7.69 +static int Audio_Available(void)
    7.70 +{
    7.71 +	_kernel_swi_regs regs;
    7.72 +	int available = 0;
    7.73 +
    7.74 +	/* Use call to set buffers to also check if Module is loaded */
    7.75 +	regs.r[0] = 0;
    7.76 +	if (_kernel_swi(DigitalRenderer_NumBuffers, &regs, &regs) == 0) available = 1;
    7.77 +
    7.78 +    return(available);
    7.79 +}
    7.80 +
    7.81 +static void Audio_DeleteDevice(SDL_AudioDevice *device)
    7.82 +{
    7.83 +    free(device->hidden);
    7.84 +    free(device);
    7.85 +}
    7.86 +
    7.87 +static SDL_AudioDevice *Audio_CreateDevice(int devindex)
    7.88 +{
    7.89 +    SDL_AudioDevice *this;
    7.90 +
    7.91 +    /* Initialize all variables that we clean on shutdown */
    7.92 +    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
    7.93 +    if ( this ) {
    7.94 +        memset(this, 0, (sizeof *this));
    7.95 +        this->hidden = (struct SDL_PrivateAudioData *)
    7.96 +                malloc((sizeof *this->hidden));
    7.97 +    }
    7.98 +    if ( (this == NULL) || (this->hidden == NULL) ) {
    7.99 +        SDL_OutOfMemory();
   7.100 +        if ( this ) {
   7.101 +            free(this);
   7.102 +        }
   7.103 +        return(0);
   7.104 +    }
   7.105 +    memset(this->hidden, 0, (sizeof *this->hidden));
   7.106 +
   7.107 +    /* Set the function pointers */
   7.108 +    this->OpenAudio   = DRenderer_OpenAudio;
   7.109 +    this->CloseAudio  = DRenderer_CloseAudio;
   7.110 +    this->free        = Audio_DeleteDevice;
   7.111 +
   7.112 +    return this;
   7.113 +}
   7.114 +
   7.115 +AudioBootStrap DRENDERER_bootstrap = {
   7.116 +	"drenderer", "RiscOS Digital Renderer Module",
   7.117 +	Audio_Available, Audio_CreateDevice
   7.118 +};
   7.119 +
   7.120 +/* Routine called to check and fill audio buffers if necessary */
   7.121 +static Uint8 *buffer = NULL;
   7.122 +
   7.123 +void DRenderer_FillBuffers()
   7.124 +{
   7.125 +	SDL_AudioDevice *audio = current_audio;
   7.126 +
   7.127 +   if ( !audio || ! audio->enabled )
   7.128 +   {
   7.129 +      return;
   7.130 +   }
   7.131 +
   7.132 +   if ( ! audio->paused )
   7.133 +   {
   7.134 +	   _kernel_swi_regs regs;
   7.135 +	   /* Check filled buffers count */
   7.136 +	   _kernel_swi(DigitalRenderer_StreamStatistics, &regs, &regs);
   7.137 +
   7.138 +#ifdef DUMP_AUDIO
   7.139 +    if (regs.r[0] <= FillBuffer)
   7.140 +    {
   7.141 +       printf("Buffers in use %d\n", regs.r[0]);
   7.142 +    }
   7.143 +#endif
   7.144 +
   7.145 +	   while (regs.r[0] <= FillBuffer && !audio->paused)
   7.146 +	   {
   7.147 +	     if ( audio->convert.needed )
   7.148 +		   {
   7.149 +		       int silence;
   7.150 +                       if ( audio->convert.src_format == AUDIO_U8 )
   7.151 +                       {
   7.152 +                       	 silence = 0x80;
   7.153 +                       } else {
   7.154 +                       	 silence = 0;
   7.155 +                       }
   7.156 +                       memset(audio->convert.buf, silence, audio->convert.len);
   7.157 +		       audio->spec.callback(audio->spec.userdata,
   7.158 +				   (Uint8 *)audio->convert.buf,audio->convert.len);
   7.159 +                       SDL_ConvertAudio(&audio->convert);
   7.160 +#if 0
   7.161 +			   if ( audio->convert.len_cvt != audio->spec.size ) {
   7.162 +				   /* Uh oh... probably crashes here; */
   7.163 +			   }
   7.164 +#endif
   7.165 +		       regs.r[0] = (int)audio->convert.buf;
   7.166 +		       regs.r[1] = audio->spec.samples * audio->spec.channels;
   7.167 +		       _kernel_swi(DigitalRenderer_Stream16BitSamples, &regs, &regs);
   7.168 +
   7.169 +		   } else
   7.170 +		   {
   7.171 +			/* Fill buffer with silence */
   7.172 +			memset (buffer, 0, audio->spec.size);
   7.173 +
   7.174 +			audio->spec.callback(audio->spec.userdata,
   7.175 +				   (Uint8 *)buffer, audio->spec.size);
   7.176 +
   7.177 +			regs.r[0] = (int)buffer;
   7.178 +			regs.r[1] = audio->spec.samples * audio->spec.channels;
   7.179 +			 _kernel_swi(DigitalRenderer_Stream16BitSamples, &regs, &regs);
   7.180 +		   }
   7.181 +  		   /* Check if we have enough buffers yet */
   7.182 +   		   _kernel_swi(DigitalRenderer_StreamStatistics, &regs, &regs);
   7.183 +	   }
   7.184 +
   7.185 +   }
   7.186 +}
   7.187 +
   7.188 +/* Size of DMA buffer to use */
   7.189 +#define DRENDERER_BUFFER_SIZE 512
   7.190 +
   7.191 +/* Number of centiseconds of sound to buffer.
   7.192 +   Hopefully more than the maximum time between calls to the
   7.193 +   FillBuffers routine above
   7.194 +*/
   7.195 +#define DRENDERER_CSEC_TO_BUFFER 10
   7.196 +
   7.197 +static int DRenderer_OpenAudio(_THIS, SDL_AudioSpec *spec)
   7.198 +{
   7.199 +	_kernel_swi_regs regs;
   7.200 +	int buffers_per_sample;
   7.201 +
   7.202 +#ifdef DUMP_AUDIO
   7.203 +    printf("Request format %d\n", spec->format);
   7.204 +    printf("Request freq   %d\n", spec->freq);
   7.205 +    printf("Samples        %d\n", spec->samples);
   7.206 +#endif
   7.207 +
   7.208 +	/* Only support signed 16bit format */
   7.209 +	spec->format = AUDIO_S16LSB;
   7.210 +
   7.211 +    if (spec->samples < DRENDERER_BUFFER_SIZE) spec->samples = DRENDERER_BUFFER_SIZE;
   7.212 +
   7.213 +    SDL_CalculateAudioSpec(spec);
   7.214 +
   7.215 +
   7.216 +	buffers_per_sample = spec->samples / DRENDERER_BUFFER_SIZE;
   7.217 +
   7.218 +	if ((spec->samples % DRENDERER_BUFFER_SIZE) != 0)
   7.219 +	{
   7.220 +		buffers_per_sample++;
   7.221 +		spec->samples = buffers_per_sample * DRENDERER_BUFFER_SIZE;
   7.222 +	}
   7.223 +
   7.224 +	/* Set number of buffers to use - the following should give enough
   7.225 +	   data between calls to the sound polling.
   7.226 +	*/
   7.227 +
   7.228 +    if (riscos_audiobuffer == 0)
   7.229 +    {
   7.230 +    	FillBuffer = (int)((double)DRENDERER_CSEC_TO_BUFFER / ((double)DRENDERER_BUFFER_SIZE * 100.0 / (double)spec->freq)) + 1;
   7.231 +    } else FillBuffer = riscos_audiobuffer/DRENDERER_BUFFER_SIZE - buffers_per_sample;
   7.232 +
   7.233 +	if (FillBuffer < buffers_per_sample) FillBuffer = buffers_per_sample;
   7.234 +	regs.r[0] = FillBuffer + buffers_per_sample;
   7.235 +
   7.236 +#ifdef DUMP_AUDIO
   7.237 +    printf("Buffers per sample %d\n", buffers_per_sample);
   7.238 +    printf("Fill buffer        %d\n", FillBuffer);
   7.239 +    printf("Time buffered (ms) %d\n",(int)((1000.0 * regs.r[0] * DRENDERER_BUFFER_SIZE)/(double)spec->freq));
   7.240 +#endif
   7.241 +
   7.242 +	if (_kernel_swi(DigitalRenderer_NumBuffers, &regs, &regs) != 0)
   7.243 +    {
   7.244 +       SDL_SetError("Can't set number of streaming sound buffers\n");
   7.245 +       return -1;
   7.246 +    }
   7.247 +
   7.248 +	/* Now initialise sound system */
   7.249 +	regs.r[0] = spec->channels;   /* Number of channels */
   7.250 +	regs.r[1] = DRENDERER_BUFFER_SIZE; /* Samples length */
   7.251 +	regs.r[2] = spec->freq; /* frequency */
   7.252 +	regs.r[3] = 1;   /* Restore previous handler on exit */
   7.253 +
   7.254 +	if (_kernel_swi(DigitalRenderer_Activate16, &regs, &regs) != 0)
   7.255 +	{
   7.256 +		SDL_SetError("Unable to activate digital renderer in 16 bit mode\n");
   7.257 +		return -1;
   7.258 +	}
   7.259 +
   7.260 +	if (_kernel_swi(DigitalRenderer_GetFrequency, &regs, &regs) == 0)
   7.261 +	{
   7.262 +		spec->freq = regs.r[0];
   7.263 +	}
   7.264 +
   7.265 +#ifdef DUMP_AUDIO
   7.266 +    printf("Got format %d\n", spec->format);
   7.267 +    printf("Frequency  %d\n", spec->freq);
   7.268 +    printf("Samples    %d\n", spec->samples);
   7.269 +#endif                 
   7.270 +
   7.271 +    /* Set to fill buffer with zero if we don't get data to it fast enough */
   7.272 +    regs.r[0] = 1;
   7.273 +    regs.r[1] = ~1;
   7.274 +    _kernel_swi(DigitalRenderer_StreamFlags, &regs, &regs);
   7.275 +
   7.276 +	buffer = (Uint8 *)malloc(sizeof(Uint8) * spec->size);
   7.277 +	if (buffer == NULL)
   7.278 +	{
   7.279 +		SDL_OutOfMemory();
   7.280 +		return -1;
   7.281 +	}
   7.282 +
   7.283 +   /* Hopefully returning 2 will show success, but not start up an audio thread */
   7.284 +   return 2;
   7.285 +}
   7.286 +
   7.287 +static void DRenderer_CloseAudio(_THIS)
   7.288 +{
   7.289 +	_kernel_swi_regs regs;
   7.290 +
   7.291 +	/* Close down the digital renderer */
   7.292 +	_kernel_swi(DigitalRenderer_Deactivate, &regs, &regs);
   7.293 +
   7.294 +	if (buffer != NULL) free(buffer);
   7.295 +}
   7.296 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/riscos/SDL_drenderer.h	Thu May 29 04:44:13 2003 +0000
     8.3 @@ -0,0 +1,36 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Library General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Library General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Library General Public
    8.19 +    License along with this library; if not, write to the Free
    8.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@devolution.com
    8.24 +*/
    8.25 +
    8.26 +
    8.27 +#ifndef _SDL_drenderer_h
    8.28 +#define _SDL_drenderer_h
    8.29 +
    8.30 +#include "SDL_sysaudio.h"
    8.31 +
    8.32 +/* Hidden "this" pointer for the video functions */
    8.33 +#define _THIS	SDL_AudioDevice *this
    8.34 +
    8.35 +struct SDL_PrivateAudioData {
    8.36 +	unsigned char *audio_buf;
    8.37 +};
    8.38 +
    8.39 +#endif /* _SDL_drenderer_h */
     9.1 --- a/src/joystick/Makefile.am	Thu May 29 04:37:17 2003 +0000
     9.2 +++ b/src/joystick/Makefile.am	Thu May 29 04:44:13 2003 +0000
     9.3 @@ -5,7 +5,7 @@
     9.4  
     9.5  # Define which subdirectories need to be built
     9.6  SUBDIRS = @JOYSTICK_SUBDIRS@
     9.7 -DIST_SUBDIRS = dummy amigaos beos bsd darwin dc linux macos mint win32
     9.8 +DIST_SUBDIRS = dummy amigaos beos bsd darwin dc linux macos mint riscos win32
     9.9  
    9.10  DRIVERS = @JOYSTICK_DRIVERS@
    9.11  
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/joystick/riscos/Makefile.am	Thu May 29 04:44:13 2003 +0000
    10.3 @@ -0,0 +1,8 @@
    10.4 +
    10.5 +## Makefile.am for the RISC OS joystick driver for SDL
    10.6 +
    10.7 +noinst_LTLIBRARIES = libjoystick_riscos.la
    10.8 +libjoystick_riscos_la_SOURCES = $(SRCS)
    10.9 +
   10.10 +# The SDL joystick driver sources
   10.11 +SRCS =  SDL_sysjoystick.c
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/joystick/riscos/SDL_sysjoystick.c	Thu May 29 04:44:13 2003 +0000
    11.3 @@ -0,0 +1,180 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Library General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Library General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Library General Public
   11.19 +    License along with this library; if not, write to the Free
   11.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@devolution.com
   11.24 +*/
   11.25 +
   11.26 +/*
   11.27 +   RISCOS - Joystick support by Alan Buckley (alan_baa@hotmail.com) - 10 April 2003
   11.28 +
   11.29 +   Note: Currently assumes joystick is present if joystick module is loaded
   11.30 +   and that there is one joystick with four buttons.
   11.31 +*/
   11.32 +
   11.33 +#ifdef SAVE_RCSID
   11.34 +static char rcsid =
   11.35 + "@(#) $Id$";
   11.36 +#endif
   11.37 +
   11.38 +/* This is the system specific header for the SDL joystick API */
   11.39 +
   11.40 +#include <stdio.h>		/* For the definition of NULL */
   11.41 +#include <stdlib.h>
   11.42 +
   11.43 +#include "SDL_error.h"
   11.44 +#include "SDL_joystick.h"
   11.45 +#include "SDL_sysjoystick.h"
   11.46 +#include "SDL_joystick_c.h"
   11.47 +
   11.48 +#include "kernel.h"
   11.49 +
   11.50 +#define JOYSTICK_READ 0x43F40
   11.51 +
   11.52 +struct joystick_hwdata 
   11.53 +{
   11.54 +	int joystate;
   11.55 +};
   11.56 +
   11.57 +
   11.58 +/* Function to scan the system for joysticks.
   11.59 + * This function should set SDL_numjoysticks to the number of available
   11.60 + * joysticks.  Joystick 0 should be the system default joystick.
   11.61 + * It should return number of joysticks, or -1 on an unrecoverable fatal error.
   11.62 + */
   11.63 +int SDL_SYS_JoystickInit(void)
   11.64 +{
   11.65 +	_kernel_swi_regs regs;
   11.66 +
   11.67 +	 /* Try to read joystick 0 */
   11.68 +	regs.r[0] = 0;
   11.69 +	if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL)
   11.70 +	{
   11.71 +		/* Switch works so assume we've got a joystick */
   11.72 +		return 1;
   11.73 +	}
   11.74 +	/* Switch fails so it looks like there's no joystick here */
   11.75 +
   11.76 +	return(0);
   11.77 +}
   11.78 +
   11.79 +/* Function to get the device-dependent name of a joystick */
   11.80 +const char *SDL_SYS_JoystickName(int index)
   11.81 +{
   11.82 +	if (index == 0)
   11.83 +	{
   11.84 +		return "RISCOS Joystick 0";
   11.85 +	}
   11.86 +
   11.87 +	SDL_SetError("No joystick available with that index");
   11.88 +	return(NULL);
   11.89 +}
   11.90 +
   11.91 +/* Function to open a joystick for use.
   11.92 +   The joystick to open is specified by the index field of the joystick.
   11.93 +   This should fill the nbuttons and naxes fields of the joystick structure.
   11.94 +   It returns 0, or -1 if there is an error.
   11.95 + */
   11.96 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
   11.97 +{
   11.98 +	_kernel_swi_regs regs;
   11.99 +
  11.100 +	if(!(joystick->hwdata=malloc(sizeof(struct joystick_hwdata))))
  11.101 +		return -1;
  11.102 +
  11.103 +	regs.r[0] = joystick->index;
  11.104 +
  11.105 +	/* Don't know how to get exact count of buttons so assume max of 4 for now */
  11.106 +	joystick->nbuttons=4;
  11.107 +
  11.108 +	joystick->nhats=0;
  11.109 +	joystick->nballs=0;
  11.110 +	joystick->naxes=2;
  11.111 +	joystick->hwdata->joystate=0;
  11.112 +
  11.113 +	return 0;
  11.114 +
  11.115 +}
  11.116 +
  11.117 +/* Function to update the state of a joystick - called as a device poll.
  11.118 + * This function shouldn't update the joystick structure directly,
  11.119 + * but instead should call SDL_PrivateJoystick*() to deliver events
  11.120 + * and update joystick device state.
  11.121 + */
  11.122 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
  11.123 +{
  11.124 +	_kernel_swi_regs regs;
  11.125 +	regs.r[0] = joystick->index;
  11.126 +
  11.127 +	if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL)
  11.128 +	{
  11.129 +		int newstate = regs.r[0];
  11.130 +		int oldstate = joystick->hwdata->joystate;
  11.131 +		if (newstate != oldstate)
  11.132 +		{
  11.133 +			if ((newstate & 0xFF) != (oldstate & 0xFF))
  11.134 +			{
  11.135 +				int y = regs.r[0] & 0xFF;
  11.136 +				/* Convert to signed values */
  11.137 +				if (y >= 128) y -= 256;
  11.138 +				SDL_PrivateJoystickAxis(joystick,1,-y * 256); /* Up and down opposite to result in SDL */
  11.139 +			}
  11.140 +			if ((newstate & 0xFF00) != (oldstate & 0xFF00))
  11.141 +			{
  11.142 +				int x = (regs.r[0] & 0xFF00) >> 8;
  11.143 +				if (x >= 128) x -= 256;
  11.144 +				SDL_PrivateJoystickAxis(joystick,0,x * 256);
  11.145 +			}
  11.146 +
  11.147 +			if ((newstate & 0xFF0000) != (oldstate & 0xFF0000))
  11.148 +			{
  11.149 +				int buttons = (regs.r[0] & 0xFF0000) >> 16;
  11.150 +				int oldbuttons = (oldstate & 0xFF0000) >> 16;
  11.151 +				int i;
  11.152 +				for (i = 0; i < joystick->nbuttons; i++)
  11.153 +				{
  11.154 +					if ((buttons & (1<<i)) != (oldbuttons & (1<<i)))
  11.155 +					{
  11.156 +						if (buttons & (1<<i)) SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
  11.157 +						else SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
  11.158 +					}
  11.159 +				}
  11.160 +			}
  11.161 +			joystick->hwdata->joystate = newstate;
  11.162 +		}		
  11.163 +	}
  11.164 +
  11.165 +	return;
  11.166 +}
  11.167 +
  11.168 +/* Function to close a joystick after use */
  11.169 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
  11.170 +{
  11.171 +	if(joystick->hwdata)
  11.172 +		free(joystick->hwdata);
  11.173 +	return;
  11.174 +}
  11.175 +
  11.176 +/* Function to perform any system-specific joystick related cleanup */
  11.177 +void SDL_SYS_JoystickQuit(void)
  11.178 +{
  11.179 +	SDL_numjoysticks=0;
  11.180 +
  11.181 +	return;
  11.182 +}
  11.183 +
    12.1 --- a/src/timer/Makefile.am	Thu May 29 04:37:17 2003 +0000
    12.2 +++ b/src/timer/Makefile.am	Thu May 29 04:44:13 2003 +0000
    12.3 @@ -10,6 +10,7 @@
    12.4                 $(srcdir)/linux \
    12.5                 $(srcdir)/macos \
    12.6                 $(srcdir)/mint \
    12.7 +               $(srcdir)/riscos \
    12.8                 $(srcdir)/win32
    12.9  
   12.10  # Include the architecture-independent sources
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/timer/riscos/SDL_systimer.c	Thu May 29 04:44:13 2003 +0000
    13.3 @@ -0,0 +1,146 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Library General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Library General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Library General Public
   13.19 +    License along with this library; if not, write to the Free
   13.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@devolution.com
   13.24 +*/
   13.25 +
   13.26 +#ifdef SAVE_RCSID
   13.27 +static char rcsid =
   13.28 + "@(#) $Id$";
   13.29 +#endif
   13.30 +
   13.31 +#include <stdio.h>
   13.32 +#include <time.h>
   13.33 +#include <sys/time.h>
   13.34 +#include <unistd.h>
   13.35 +#include <string.h>
   13.36 +#include <errno.h>
   13.37 +
   13.38 +#include "SDL_error.h"
   13.39 +#include "SDL_timer.h"
   13.40 +#include "SDL_timer_c.h"
   13.41 +
   13.42 +/* Timer start/reset time */
   13.43 +static Uint32 timerStart;
   13.44 +/* Timer running function */
   13.45 +void RISCOS_CheckTimer();
   13.46 +
   13.47 +extern void RISCOS_BackgroundTasks(void);
   13.48 +
   13.49 +/* The first ticks value of the application */
   13.50 +clock_t start;
   13.51 +
   13.52 +void SDL_StartTicks(void)
   13.53 +{
   13.54 +	/* Set first ticks value */
   13.55 +	start = clock();
   13.56 +}
   13.57 +
   13.58 +Uint32 SDL_GetTicks (void)
   13.59 +{
   13.60 +	clock_t ticks;
   13.61 +
   13.62 +	ticks=clock()-start;
   13.63 +
   13.64 +
   13.65 +#if CLOCKS_PER_SEC == 1000
   13.66 +
   13.67 +	return(ticks);
   13.68 +
   13.69 +#elif CLOCKS_PER_SEC == 100
   13.70 +
   13.71 +	return (ticks * 10);
   13.72 +
   13.73 +#else
   13.74 +
   13.75 +	return ticks*(1000/CLOCKS_PER_SEC);
   13.76 +
   13.77 +#endif
   13.78 +
   13.79 +}
   13.80 +
   13.81 +extern void DRenderer_FillBuffers();
   13.82 +
   13.83 +void SDL_Delay (Uint32 ms)
   13.84 +{
   13.85 +    Uint32 now,then,elapsed;
   13.86 +
   13.87 +	/* Set the timeout interval - Linux only needs to do this once */
   13.88 +	then = SDL_GetTicks();
   13.89 +
   13.90 +	do {
   13.91 +		/* Do background tasks required while sleeping as we are not multithreaded */
   13.92 +		RISCOS_BackgroundTasks();
   13.93 +		/* Calculate the time interval left (in case of interrupt) */
   13.94 +		now = SDL_GetTicks();
   13.95 +		elapsed = (now-then);
   13.96 +		then = now;
   13.97 +		if ( elapsed >= ms ) {
   13.98 +			break;
   13.99 +		}
  13.100 +		ms -= elapsed;
  13.101 +
  13.102 +	} while ( 1 );
  13.103 +}
  13.104 +
  13.105 +int SDL_SYS_TimerInit(void)
  13.106 +{
  13.107 +	return(0);
  13.108 +}
  13.109 +
  13.110 +void SDL_SYS_TimerQuit(void)
  13.111 +{
  13.112 +	SDL_SetTimer(0, NULL);
  13.113 +}
  13.114 +
  13.115 +int SDL_SYS_StartTimer(void)
  13.116 +{
  13.117 +	timerStart = SDL_GetTicks();
  13.118 +
  13.119 +	return(0);
  13.120 +}
  13.121 +
  13.122 +void SDL_SYS_StopTimer(void)
  13.123 +{
  13.124 +	/* Don't need to do anything as we use SDL_timer_running
  13.125 +	   to detect if we need to check the timer */
  13.126 +}
  13.127 +
  13.128 +
  13.129 +void RISCOS_CheckTimer()
  13.130 +{
  13.131 +	if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval)
  13.132 +	{
  13.133 +		Uint32 ms;
  13.134 +
  13.135 +		ms = SDL_alarm_callback(SDL_alarm_interval);
  13.136 +		if ( ms != SDL_alarm_interval )
  13.137 +		{
  13.138 +			if ( ms )
  13.139 +			{
  13.140 +				SDL_alarm_interval = ROUND_RESOLUTION(ms);
  13.141 +			} else
  13.142 +			{
  13.143 +				SDL_alarm_interval = 0;
  13.144 +				SDL_timer_running = 0;
  13.145 +			}
  13.146 +		}
  13.147 +		if (SDL_alarm_interval) timerStart = SDL_GetTicks();
  13.148 +	}
  13.149 +}
    14.1 --- a/src/video/Makefile.am	Thu May 29 04:37:17 2003 +0000
    14.2 +++ b/src/video/Makefile.am	Thu May 29 04:44:13 2003 +0000
    14.3 @@ -7,7 +7,7 @@
    14.4  SUBDIRS = @VIDEO_SUBDIRS@
    14.5  DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
    14.6                 wincommon windib windx5 \
    14.7 -               maccommon macdsp macrom quartz \
    14.8 +               maccommon macdsp macrom riscos quartz \
    14.9                 bwindow ps2gs photon cybergfx epoc picogui \
   14.10                 ataricommon xbios gem dc qtopia XFree86
   14.11  
    15.1 --- a/src/video/SDL_sysvideo.h	Thu May 29 04:37:17 2003 +0000
    15.2 +++ b/src/video/SDL_sysvideo.h	Thu May 29 04:44:13 2003 +0000
    15.3 @@ -409,6 +409,9 @@
    15.4  #ifdef ENABLE_DC
    15.5  extern VideoBootStrap DC_bootstrap;
    15.6  #endif
    15.7 +#ifdef ENABLE_RISCOS
    15.8 +extern VideoBootStrap RISCOS_bootstrap;
    15.9 +#endif
   15.10  /* This is the current video device */
   15.11  extern SDL_VideoDevice *current_video;
   15.12  
    16.1 --- a/src/video/SDL_video.c	Thu May 29 04:37:17 2003 +0000
    16.2 +++ b/src/video/SDL_video.c	Thu May 29 04:44:13 2003 +0000
    16.3 @@ -117,6 +117,9 @@
    16.4  #ifdef ENABLE_DC
    16.5  	&DC_bootstrap,
    16.6  #endif
    16.7 +#ifdef ENABLE_RISCOS
    16.8 +    &RISCOS_bootstrap,
    16.9 +#endif
   16.10  #ifdef ENABLE_DUMMYVIDEO
   16.11  	&DUMMY_bootstrap,
   16.12  #endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/video/riscos/Makefile.am	Thu May 29 04:44:13 2003 +0000
    17.3 @@ -0,0 +1,20 @@
    17.4 +
    17.5 +## Makefile.am for SDL using the RISC OS video driver
    17.6 +
    17.7 +noinst_LTLIBRARIES = libvideo_riscos.la
    17.8 +libvideo_riscos_la_SOURCES = $(CGX_SRCS)
    17.9 +
   17.10 +# The SDL RISC OS video driver sources
   17.11 +CGX_SRCS = 				\
   17.12 +	SDL_riscosevents.c		\
   17.13 +	SDL_riscosevents_c.h		\
   17.14 +	SDL_riscosFullScreenVideo.c	\
   17.15 +	SDL_riscosmouse.c		\
   17.16 +	SDL_riscosmouse_c.h		\
   17.17 +	SDL_riscossprite.c		\
   17.18 +	SDL_riscostask.c		\
   17.19 +	SDL_riscostask.h		\
   17.20 +	SDL_riscosvideo.c		\
   17.21 +	SDL_riscosvideo.h		\
   17.22 +	SDL_wimppoll.c			\
   17.23 +	SDL_wimpvideo.c
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/video/riscos/SDL_riscosFullScreenVideo.c	Thu May 29 04:44:13 2003 +0000
    18.3 @@ -0,0 +1,594 @@
    18.4 +/*
    18.5 +    SDL - Simple DirectMedia Layer
    18.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    18.7 +
    18.8 +    This library is free software; you can redistribute it and/or
    18.9 +    modify it under the terms of the GNU Library General Public
   18.10 +    License as published by the Free Software Foundation; either
   18.11 +    version 2 of the License, or (at your option) any later version.
   18.12 +
   18.13 +    This library is distributed in the hope that it will be useful,
   18.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.16 +    Library General Public License for more details.
   18.17 +
   18.18 +    You should have received a copy of the GNU Library General Public
   18.19 +    License along with this library; if not, write to the Free
   18.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.21 +
   18.22 +    Sam Lantinga
   18.23 +    slouken@devolution.com
   18.24 +*/
   18.25 +
   18.26 +/*
   18.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   18.28 +	 27 March 2003
   18.29 +
   18.30 +     Implements RISCOS full screen display.
   18.31 +*/
   18.32 +
   18.33 +#include <stdio.h>
   18.34 +#include <stdlib.h>
   18.35 +#include <string.h>
   18.36 +
   18.37 +#include "SDL.h"
   18.38 +#include "SDL_error.h"
   18.39 +#include "SDL_video.h"
   18.40 +#include "SDL_mouse.h"
   18.41 +#include "SDL_sysvideo.h"
   18.42 +#include "SDL_pixels_c.h"
   18.43 +#include "SDL_events_c.h"
   18.44 +
   18.45 +#include "SDL_riscostask.h"
   18.46 +#include "SDL_riscosvideo.h"
   18.47 +#include "SDL_riscosevents_c.h"
   18.48 +#include "SDL_riscosmouse_c.h"
   18.49 +
   18.50 +#include "kernel.h"
   18.51 +#include "swis.h"
   18.52 +#include "unixlib/os.h"
   18.53 +#include "unixlib/local.h"
   18.54 +
   18.55 +/* Private structures */
   18.56 +typedef struct tagScreenModeBlock
   18.57 +{
   18.58 +   int flags;  // mode selector flags, bit 0 = 1, bit 1-7 format specifier, 8-31 reserved
   18.59 +   int x_pixels;
   18.60 +   int y_pixels;
   18.61 +   int pixel_depth;  // 2^pixel_depth = bpp,i.e. 0 = 1, 1 = 2, 4 = 16, 5 = 32
   18.62 +   int frame_rate;   // -1 use first match
   18.63 +   int mode_vars[5]; // array of index, value pairs terminated by -1
   18.64 +} SCREENMODEBLOCK;
   18.65 +
   18.66 +
   18.67 +/* Helper functions */
   18.68 +void FULLSCREEN_SetDeviceMode(_THIS);
   18.69 +int FULLSCREEN_SetMode(int width, int height, int bpp);
   18.70 +void FULLSCREEN_SetupBanks(_THIS);
   18.71 +
   18.72 +/* SDL video device functions for fullscreen mode */
   18.73 +static int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   18.74 +static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface);
   18.75 +static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
   18.76 +void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon);
   18.77 +extern int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info);
   18.78 +
   18.79 +/* Local helper functions */
   18.80 +static int cmpmodes(const void *va, const void *vb);
   18.81 +static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h);
   18.82 +void FULLSCREEN_SetWriteBank(int bank);
   18.83 +void FULLSCREEN_SetDisplayBank(int bank);
   18.84 +static void FULLSCREEN_DisableEscape();
   18.85 +static void FULLSCREEN_EnableEscape();
   18.86 +void FULLSCREEN_BuildModeList(_THIS);
   18.87 +
   18.88 +/* Following variable is set up in riskosTask.c */
   18.89 +extern int riscos_backbuffer; /* Create a back buffer in system memory for full screen mode */
   18.90 +
   18.91 +
   18.92 +
   18.93 +SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current,
   18.94 +				int width, int height, int bpp, Uint32 flags)
   18.95 +{
   18.96 +   _kernel_swi_regs regs;
   18.97 +   Uint32 Rmask = 0;
   18.98 +   Uint32 Gmask = 0;
   18.99 +   Uint32 Bmask = 0;
  18.100 +   int create_back_buffer = riscos_backbuffer;
  18.101 +
  18.102 +   switch(bpp)
  18.103 +   {
  18.104 +	case 8:
  18.105 +		flags |= SDL_HWPALETTE;
  18.106 +		break;
  18.107 +
  18.108 +	case 15:
  18.109 +	case 16:
  18.110 +		Bmask = 0x00007c00;
  18.111 +		Gmask = 0x000003e0;
  18.112 +		Rmask = 0x0000001f;
  18.113 +		break;
  18.114 +
  18.115 +	case 32:
  18.116 +		Bmask = 0x00ff0000;
  18.117 +		Gmask = 0x0000ff00;
  18.118 +		Rmask = 0x000000ff;
  18.119 +		break;
  18.120 +
  18.121 +	default:
  18.122 +		SDL_SetError("Pixel depth not supported");
  18.123 +		return NULL;
  18.124 +		break;
  18.125 +   }
  18.126 +
  18.127 +   if (FULLSCREEN_SetMode(width, height, bpp) == 0)
  18.128 +   {
  18.129 +	   SDL_SetError("Couldn't set requested mode");
  18.130 +	   return (NULL);
  18.131 +   }
  18.132 +
  18.133 +/* 	printf("Setting mode %dx%d\n", width, height); */
  18.134 +
  18.135 +	/* Allocate the new pixel format for the screen */
  18.136 +	if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) {
  18.137 +	    RISCOS_RestoreWimpMode();
  18.138 +		SDL_SetError("Couldn't allocate new pixel format for requested mode");
  18.139 +		return(NULL);
  18.140 +	}
  18.141 +
  18.142 +	/* Set up the new mode framebuffer */
  18.143 +	current->w = width;
  18.144 +	this->hidden->height = current->h = height;
  18.145 +
  18.146 +   regs.r[0] = -1; /* -1 for current screen mode */
  18.147 +
  18.148 +   /* Get screen width in bytes */
  18.149 +   regs.r[1] = 6; // Screen Width in bytes
  18.150 +   _kernel_swi(OS_ReadModeVariable, &regs, &regs);
  18.151 +
  18.152 +   current->pitch = regs.r[2];
  18.153 +
  18.154 +   if (flags & SDL_DOUBLEBUF)
  18.155 +   {
  18.156 +	   regs.r[0] = 2; /* Screen area */
  18.157 +	   _kernel_swi(OS_ReadDynamicArea, &regs, &regs);
  18.158 +	   
  18.159 +	   /* Reg 1 has amount of memory currently used for display */
  18.160 +	   regs.r[0] = 2; /* Screen area */
  18.161 +	   regs.r[1] = (current->pitch * height * 2) - regs.r[1];
  18.162 +	   if (_kernel_swi(OS_ChangeDynamicArea, &regs, &regs) != NULL)
  18.163 +	   {
  18.164 +		   /* Can't allocate enough screen memory for double buffer */
  18.165 +		   flags &= ~SDL_DOUBLEBUF;
  18.166 +	   }
  18.167 +   }
  18.168 +   
  18.169 +  	current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC;
  18.170 +	
  18.171 +
  18.172 +	/* Need to set display banks here for double buffering */
  18.173 +	if (flags & SDL_DOUBLEBUF)
  18.174 +	{
  18.175 +	   FULLSCREEN_SetWriteBank(0);
  18.176 +	   FULLSCREEN_SetDisplayBank(1);
  18.177 +
  18.178 +         create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */
  18.179 +    }
  18.180 +
  18.181 +    FULLSCREEN_SetupBanks(this);
  18.182 +
  18.183 +    if (create_back_buffer)
  18.184 +    {
  18.185 +       /* If not double buffered we may need to create a memory
  18.186 +       ** back buffer to simulate processing on other OS's. 
  18.187 +         ** This is turned on by setting the enviromental variable
  18.188 +         ** SDL$<name>$BackBuffer to 1
  18.189 +         */    
  18.190 +       this->hidden->bank[0] = malloc(height * current->pitch);
  18.191 +       if (this->hidden->bank[0] == 0)
  18.192 +       {
  18.193 + 	       RISCOS_RestoreWimpMode();
  18.194 +           SDL_SetError("Couldnt allocate memory for back buffer");
  18.195 +           return (NULL);
  18.196 +       }
  18.197 +       /* Surface updated in programs is now a software surface */
  18.198 +       current->flags &= ~SDL_HWSURFACE;
  18.199 +    }
  18.200 +
  18.201 +	   /* Store address of allocated screen bank to be freed later */
  18.202 +	   if (this->hidden->alloc_bank) free(this->hidden->alloc_bank);
  18.203 +	   if (create_back_buffer)
  18.204 +	   {
  18.205 +		   this->hidden->alloc_bank = this->hidden->bank[0];
  18.206 +	   } else
  18.207 +		   this->hidden->alloc_bank = 0;
  18.208 +
  18.209 +       // Clear both banks to black
  18.210 +       memset(this->hidden->bank[0], 0, height * current->pitch);
  18.211 +	   memset(this->hidden->bank[1], 0, height * current->pitch);
  18.212 +
  18.213 + 	   this->hidden->current_bank = 0;
  18.214 +	   current->pixels = this->hidden->bank[0];
  18.215 +
  18.216 +	/* Reset device functions for the wimp */
  18.217 +	FULLSCREEN_SetDeviceMode(this);
  18.218 +
  18.219 +/*	FULLSCREEN_DisableEscape(); */
  18.220 +
  18.221 +	/* We're done */
  18.222 +	return(current);
  18.223 +}
  18.224 +
  18.225 +/* Reset any device functions that have been changed because we have run in WIMP mode */
  18.226 +void FULLSCREEN_SetDeviceMode(_THIS)
  18.227 +{
  18.228 +	if (this->SetColors == FULLSCREEN_SetColors) return; /* Already set up */
  18.229 +
  18.230 +	this->SetColors   = FULLSCREEN_SetColors;
  18.231 +	this->UpdateRects = FULLSCREEN_UpdateRects;
  18.232 +
  18.233 +	this->FlipHWSurface = FULLSCREEN_FlipHWSurface;
  18.234 +
  18.235 +	this->SetCaption = FULLSCREEN_SetWMCaption;
  18.236 +	this->SetIcon = NULL;
  18.237 +	this->IconifyWindow = NULL;
  18.238 +	
  18.239 +	this->ShowWMCursor = RISCOS_ShowWMCursor;
  18.240 +	this->WarpWMCursor = FULLSCREEN_WarpWMCursor;
  18.241 +
  18.242 +	this->PumpEvents = FULLSCREEN_PumpEvents;	
  18.243 +}
  18.244 +
  18.245 +/* Query for the list of available video modes */
  18.246 +void FULLSCREEN_BuildModeList(_THIS)
  18.247 +{
  18.248 +	_kernel_swi_regs regs;
  18.249 +	char *enumInfo = NULL;
  18.250 +	char *enum_ptr;
  18.251 +	int *blockInfo;
  18.252 +	int j;
  18.253 +	int num_modes;
  18.254 +
  18.255 +	/* Find out how much space we need */
  18.256 +	regs.r[0] = 2; /* Reason code */
  18.257 +	regs.r[2] = 0; /* Number of modes to skip */
  18.258 +	regs.r[6] = 0; /* pointer to block or 0 for count */
  18.259 +	regs.r[7] = 0; /* Size of block in bytes */
  18.260 +	_kernel_swi(OS_ScreenMode, &regs, &regs);
  18.261 +
  18.262 +    num_modes = -regs.r[2];
  18.263 +
  18.264 +	/* Video memory should be in r[5] */
  18.265 +	this->info.video_mem = regs.r[5]/1024;
  18.266 +
  18.267 +	enumInfo = (unsigned char *)malloc(-regs.r[7]);
  18.268 +	if (enumInfo == NULL)
  18.269 +	{
  18.270 +		SDL_OutOfMemory();
  18.271 +		return;
  18.272 +	}
  18.273 +	/* Read mode information into block */
  18.274 +	regs.r[2] = 0;
  18.275 +	regs.r[6] = (int)enumInfo;
  18.276 +	regs.r[7] = -regs.r[7];
  18.277 +	_kernel_swi(OS_ScreenMode, &regs, &regs);
  18.278 +
  18.279 +	enum_ptr = enumInfo;
  18.280 +
  18.281 +	for (j =0; j < num_modes;j++)
  18.282 +	{
  18.283 +		blockInfo = (int *)enum_ptr;
  18.284 +		if ((blockInfo[1] & 255) == 1) /* We understand this format */
  18.285 +		{
  18.286 +			switch(blockInfo[4])
  18.287 +			{
  18.288 +			case 3: /* 8 bits per pixel */
  18.289 +				FULLSCREEN_AddMode(this, 8, blockInfo[2], blockInfo[3]);
  18.290 +				break;
  18.291 +			case 4: /* 15 bits per pixel */
  18.292 +				FULLSCREEN_AddMode(this, 15, blockInfo[2], blockInfo[3]);
  18.293 +				break;
  18.294 +			case 5: /* 32 bits per pixel */
  18.295 +				FULLSCREEN_AddMode(this, 32, blockInfo[2], blockInfo[3]);
  18.296 +				break;
  18.297 +			}
  18.298 +		}
  18.299 +
  18.300 +		enum_ptr += blockInfo[0];
  18.301 +	}
  18.302 +
  18.303 +	free(enumInfo);
  18.304 +		
  18.305 +	/* Sort the mode lists */
  18.306 +	for ( j=0; j<NUM_MODELISTS; ++j ) {
  18.307 +		if ( SDL_nummodes[j] > 0 ) {
  18.308 +			qsort(SDL_modelist[j], SDL_nummodes[j], sizeof *SDL_modelist[j], cmpmodes);
  18.309 +		}
  18.310 +	}
  18.311 +}
  18.312 +
  18.313 +static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface)
  18.314 +{
  18.315 +   _kernel_swi_regs regs;
  18.316 +   regs.r[0] = 19;
  18.317 +   /* Wait for Vsync */
  18.318 +   _kernel_swi(OS_Byte, &regs, &regs);
  18.319 +
  18.320 +   FULLSCREEN_SetDisplayBank(this->hidden->current_bank);
  18.321 +   this->hidden->current_bank ^= 1;
  18.322 +   FULLSCREEN_SetWriteBank(this->hidden->current_bank);
  18.323 +   surface->pixels = this->hidden->bank[this->hidden->current_bank];
  18.324 +
  18.325 +	return(0);
  18.326 +}
  18.327 +
  18.328 +static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
  18.329 +{
  18.330 +   if (riscos_backbuffer && (this->screen->flags & SDL_DOUBLEBUF) == 0)
  18.331 +   {
  18.332 +      /* If not double buffered copy rectangles to main screen now */
  18.333 +      int j;
  18.334 +      char *to, *from;
  18.335 +      int pitch = this->screen->pitch;
  18.336 +      int row;
  18.337 +      int xmult = this->screen->format->BytesPerPixel;
  18.338 +      for (j = 0; j < numrects; j++)
  18.339 +      {
  18.340 +         from = this->hidden->bank[0] + rects->x * xmult + rects->y * pitch;
  18.341 +         to  = this->hidden->bank[1] + rects->x * xmult + rects->y * pitch;
  18.342 +         for (row = 0; row < rects->h; row++)
  18.343 +         {
  18.344 +             memcpy(to, from, rects->w * xmult);
  18.345 +             from += pitch;
  18.346 +             to += pitch;
  18.347 +         }
  18.348 +         rects++;
  18.349 +      }
  18.350 +   }
  18.351 +}
  18.352 +
  18.353 +int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  18.354 +{
  18.355 +	_kernel_swi_regs regs;
  18.356 +	int palette[256];
  18.357 +
  18.358 +	regs.r[0] = -1;
  18.359 +	regs.r[1] = -1;
  18.360 +	regs.r[2] = (int)palette;
  18.361 +	regs.r[3] = 1024;
  18.362 +	regs.r[4] = 0;
  18.363 +	_kernel_swi(ColourTrans_ReadPalette, &regs, &regs);
  18.364 +
  18.365 +	while(ncolors--)
  18.366 +	{
  18.367 +		palette[firstcolor] = ((colors->b) << 24) | ((colors->g) << 16) | ((colors->r) << 8);
  18.368 +		firstcolor++;
  18.369 +		colors++;
  18.370 +	}
  18.371 +
  18.372 +	regs.r[0] = -1;
  18.373 +	regs.r[1] = -1;
  18.374 +	regs.r[2] = (int)palette;
  18.375 +	regs.r[3] = 0;
  18.376 +	regs.r[4] = 0;
  18.377 +	_kernel_swi(ColourTrans_WritePalette, &regs, &regs);
  18.378 +
  18.379 +	return(1);
  18.380 +}
  18.381 +
  18.382 +
  18.383 +static int cmpmodes(const void *va, const void *vb)
  18.384 +{
  18.385 +    SDL_Rect *a = *(SDL_Rect **)va;
  18.386 +    SDL_Rect *b = *(SDL_Rect **)vb;
  18.387 +    if(a->w > b->w)
  18.388 +        return -1;
  18.389 +    return b->h - a->h;
  18.390 +}
  18.391 +
  18.392 +static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h)
  18.393 +{
  18.394 +	SDL_Rect *mode;
  18.395 +	int i, index;
  18.396 +	int next_mode;
  18.397 +
  18.398 +	/* Check to see if we already have this mode */
  18.399 +	if ( bpp < 8 ) {  /* Not supported */
  18.400 +		return(0);
  18.401 +	}
  18.402 +	index = ((bpp+7)/8)-1;
  18.403 +	for ( i=0; i<SDL_nummodes[index]; ++i ) {
  18.404 +		mode = SDL_modelist[index][i];
  18.405 +		if ( (mode->w == w) && (mode->h == h) ) {
  18.406 +			return(0);
  18.407 +		}
  18.408 +	}
  18.409 +
  18.410 +	/* Set up the new video mode rectangle */
  18.411 +	mode = (SDL_Rect *)malloc(sizeof *mode);
  18.412 +	if ( mode == NULL ) {
  18.413 +		SDL_OutOfMemory();
  18.414 +		return(-1);
  18.415 +	}
  18.416 +	mode->x = 0;
  18.417 +	mode->y = 0;
  18.418 +	mode->w = w;
  18.419 +	mode->h = h;
  18.420 +
  18.421 +	/* Allocate the new list of modes, and fill in the new mode */
  18.422 +	next_mode = SDL_nummodes[index];
  18.423 +	SDL_modelist[index] = (SDL_Rect **)
  18.424 +	       realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *));
  18.425 +	if ( SDL_modelist[index] == NULL ) {
  18.426 +		SDL_OutOfMemory();
  18.427 +		SDL_nummodes[index] = 0;
  18.428 +		free(mode);
  18.429 +		return(-1);
  18.430 +	}
  18.431 +	SDL_modelist[index][next_mode] = mode;
  18.432 +	SDL_modelist[index][next_mode+1] = NULL;
  18.433 +	SDL_nummodes[index]++;
  18.434 +
  18.435 +	return(0);
  18.436 +}
  18.437 +
  18.438 +void FULLSCREEN_SetWriteBank(int bank)
  18.439 +{
  18.440 +   _kernel_swi_regs regs;
  18.441 +   regs.r[0] = 112;
  18.442 +   regs.r[1] = bank+1;
  18.443 +   _kernel_swi(OS_Byte, &regs, &regs);
  18.444 +}
  18.445 +
  18.446 +void FULLSCREEN_SetDisplayBank(int bank)
  18.447 +{
  18.448 +   _kernel_swi_regs regs;
  18.449 +   regs.r[0] = 113;
  18.450 +   regs.r[1] = bank+1;
  18.451 +   _kernel_swi(OS_Byte, &regs, &regs);
  18.452 +}
  18.453 +
  18.454 +
  18.455 +/** Disable special escape key processing */
  18.456 +static void FULLSCREEN_DisableEscape()
  18.457 +{
  18.458 +   _kernel_swi_regs regs;
  18.459 +   regs.r[0] = 229;
  18.460 +   regs.r[1] = 1;
  18.461 +   regs.r[2] = 0;
  18.462 +   _kernel_swi(OS_Byte, &regs, &regs);
  18.463 +  
  18.464 +}
  18.465 +
  18.466 +/** Enable special escape key processing */
  18.467 +static void FULLSCREEN_EnableEscape()
  18.468 +{
  18.469 +   _kernel_swi_regs regs;
  18.470 +   regs.r[0] = 229;
  18.471 +   regs.r[1] = 0;
  18.472 +   regs.r[2] = 0;
  18.473 +   _kernel_swi(OS_Byte, &regs, &regs);
  18.474 +  
  18.475 +}
  18.476 +
  18.477 +/** Store caption in case this is called before we create a window */
  18.478 +void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon)
  18.479 +{
  18.480 +	strncpy(this->hidden->title, title, 255);
  18.481 +	this->hidden->title[255] = 0;
  18.482 +}
  18.483 +
  18.484 +/* Set screen mode
  18.485 +*
  18.486 +*  Returns 1 if mode is set ok, otherwise 0
  18.487 +*/
  18.488 +
  18.489 +int FULLSCREEN_SetMode(int width, int height, int bpp)
  18.490 +{
  18.491 +   SCREENMODEBLOCK smb;
  18.492 +   _kernel_swi_regs regs;
  18.493 +
  18.494 +   smb.flags = 1;
  18.495 +   smb.x_pixels = width;
  18.496 +   smb.y_pixels = height;
  18.497 +   smb.mode_vars[0] = -1;
  18.498 +
  18.499 +   switch(bpp)
  18.500 +   {
  18.501 +	case 8:
  18.502 +		smb.pixel_depth = 3;
  18.503 +		/* Note: Need to set ModeFlags to 128 and NColour variables to 255 get full 8 bit palette */
  18.504 +		smb.mode_vars[0] = 0; smb.mode_vars[1] = 128; /* Mode flags */
  18.505 +		smb.mode_vars[2] = 3; smb.mode_vars[3] = 255; /* NColour (number of colours -1) */
  18.506 +		smb.mode_vars[4] = -1; /* End of list */
  18.507 +		break;
  18.508 +
  18.509 +	case 15:
  18.510 +	case 16:
  18.511 +		smb.pixel_depth = 4;
  18.512 +		break;
  18.513 +
  18.514 +	case 32:
  18.515 +		smb.pixel_depth = 5;
  18.516 +		break;
  18.517 +
  18.518 +	default:
  18.519 +		SDL_SetError("Pixel depth not supported");
  18.520 +		return 0;
  18.521 +		break;
  18.522 +   }
  18.523 +   
  18.524 +   smb.frame_rate = -1;
  18.525 +
  18.526 +   regs.r[0] = 0;
  18.527 +   regs.r[1] = (int)&smb;
  18.528 +
  18.529 +   if (_kernel_swi(OS_ScreenMode, &regs, &regs) != 0)
  18.530 +   {
  18.531 +	   SDL_SetError("Couldn't set requested mode");
  18.532 +	   return 0;
  18.533 +   }
  18.534 +
  18.535 +    /* Turn cursor off*/
  18.536 +    _kernel_oswrch(23);_kernel_oswrch(1);_kernel_oswrch(0);
  18.537 +    _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0);
  18.538 +    _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0);
  18.539 +    _kernel_oswrch(0);_kernel_oswrch(0);
  18.540 +
  18.541 +   return 1;
  18.542 +}
  18.543 +
  18.544 +/* Get Start addresses for the screen banks */
  18.545 +void FULLSCREEN_SetupBanks(_THIS)
  18.546 +{
  18.547 +   _kernel_swi_regs regs;
  18.548 +   int block[5];
  18.549 +   block[0] = 148; /* Write screen start */
  18.550 +   block[1] = 149; /* Display screen start */
  18.551 +   block[2] = 4;  /* X eig factor */
  18.552 +   block[3] = 5;  /* Y eig factor */
  18.553 +   block[4] = -1;  /* End of list of variables to request */
  18.554 +
  18.555 +   regs.r[0] = (int)block;
  18.556 +   regs.r[1] = (int)block;
  18.557 +   _kernel_swi(OS_ReadVduVariables, &regs, &regs);
  18.558 +
  18.559 +   this->hidden->bank[0] = (void *)block[0];
  18.560 +   this->hidden->bank[1] = (void *)block[1];
  18.561 +   this->hidden->xeig = block[2];
  18.562 +   this->hidden->yeig = block[3];
  18.563 +}
  18.564 +
  18.565 +/* Toggle to full screen mode from the WIMP */
  18.566 +
  18.567 +int FULLSCREEN_ToggleFromWimp(_THIS)
  18.568 +{
  18.569 +   int width = this->screen->w;
  18.570 +   int height = this->screen->h;
  18.571 +   int bpp = this->screen->format->BitsPerPixel;
  18.572 +
  18.573 +   RISCOS_StoreWimpMode();
  18.574 +   if (FULLSCREEN_SetMode(width, height, bpp))
  18.575 +   {
  18.576 +       char *buffer = this->hidden->alloc_bank; /* This is start of sprite data */
  18.577 +       /* Support back buffer mode only */
  18.578 +       riscos_backbuffer = 1;
  18.579 +
  18.580 +       FULLSCREEN_SetupBanks(this);
  18.581 +
  18.582 +       this->hidden->bank[0] = buffer + 60; /* Start of sprite data */
  18.583 +       if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
  18.584 +
  18.585 +	   this->hidden->current_bank = 0;
  18.586 +	   this->screen->pixels = this->hidden->bank[0];
  18.587 +
  18.588 +       /* Copy back buffer to screen memory */
  18.589 +       memcpy(this->hidden->bank[1], this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel);
  18.590 +
  18.591 +       FULLSCREEN_SetDeviceMode(this);
  18.592 +       return 1;
  18.593 +   } else
  18.594 +      RISCOS_RestoreWimpMode();
  18.595 +
  18.596 +   return 0;
  18.597 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/video/riscos/SDL_riscosevents.c	Thu May 29 04:44:13 2003 +0000
    19.3 @@ -0,0 +1,458 @@
    19.4 +/*
    19.5 +    SDL - Simple DirectMedia Layer
    19.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    19.7 +
    19.8 +    This library is free software; you can redistribute it and/or
    19.9 +    modify it under the terms of the GNU Library General Public
   19.10 +    License as published by the Free Software Foundation; either
   19.11 +    version 2 of the License, or (at your option) any later version.
   19.12 +
   19.13 +    This library is distributed in the hope that it will be useful,
   19.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.16 +    Library General Public License for more details.
   19.17 +
   19.18 +    You should have received a copy of the GNU Library General Public
   19.19 +    License along with this library; if not, write to the Free
   19.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.21 +
   19.22 +    Sam Lantinga
   19.23 +    slouken@devolution.com
   19.24 +*/
   19.25 +
   19.26 +/*
   19.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   19.28 +	 27 March 2003
   19.29 +
   19.30 +     Implements keyboard setup, event pump and keyboard and mouse polling
   19.31 +*/
   19.32 +
   19.33 +
   19.34 +#include "SDL.h"
   19.35 +#include "SDL_sysevents.h"
   19.36 +#include "SDL_events_c.h"
   19.37 +#include "SDL_riscosvideo.h"
   19.38 +#include "SDL_riscosevents_c.h"
   19.39 +#include "SDL_timer_c.h"
   19.40 +#include "SDL_cursor_c.h"
   19.41 +
   19.42 +#include "memory.h"
   19.43 +#include "stdlib.h"
   19.44 +#include "ctype.h"
   19.45 +
   19.46 +#include "kernel.h"
   19.47 +#include "swis.h"
   19.48 +
   19.49 +/* The translation table from a RISCOS internal key numbers to a SDL keysym */
   19.50 +static SDLKey RO_keymap[SDLK_LAST];
   19.51 +
   19.52 +/* RISCOS Key codes */
   19.53 +#define ROKEY_SHIFT 0
   19.54 +#define ROKEY_CTRL  1
   19.55 +#define ROKEY_ALT   2
   19.56 +/* Left shift is first key we will check for */
   19.57 +#define ROKEY_LEFT_SHIFT 3
   19.58 +
   19.59 +/* Need to ignore mouse buttons as they are processed separately */
   19.60 +#define ROKEY_LEFT_MOUSE   9
   19.61 +#define ROKEY_CENTRE_MOUSE 10
   19.62 +#define ROKEY_RIGHT_MOUSE  11
   19.63 +
   19.64 +/* No key has been pressed return value*/
   19.65 +#define ROKEY_NONE 255
   19.66 +
   19.67 +/* Id of last key in keyboard */
   19.68 +#define ROKEY_LAST_KEY  124
   19.69 +
   19.70 +/* Size of array for all keys */
   19.71 +#define ROKEYBD_ARRAYSIZE 125
   19.72 +
   19.73 +static char RO_pressed[ROKEYBD_ARRAYSIZE];
   19.74 +
   19.75 +static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed);
   19.76 +
   19.77 +
   19.78 +void RISCOS_PollMouse(_THIS);
   19.79 +void RISCOS_PollKeyboard();
   19.80 +
   19.81 +void RISCOS_PollMouseHelper(_THIS, int fullscreen);
   19.82 +
   19.83 +extern void DRenderer_FillBuffers();
   19.84 +
   19.85 +/* Timer running function */
   19.86 +extern void RISCOS_CheckTimer();
   19.87 +
   19.88 +void FULLSCREEN_PumpEvents(_THIS)
   19.89 +{
   19.90 +    /* Current implementation requires keyboard and mouse polling */
   19.91 +	RISCOS_PollKeyboard();
   19.92 +	RISCOS_PollMouse(this);
   19.93 +	DRenderer_FillBuffers();
   19.94 +	if (SDL_timer_running) RISCOS_CheckTimer();
   19.95 +}
   19.96 +
   19.97 +
   19.98 +void RISCOS_InitOSKeymap(_THIS)
   19.99 +{
  19.100 +	int i;
  19.101 +
  19.102 +	/* Map the VK keysyms */
  19.103 +	for ( i=0; i<SDL_TABLESIZE(RO_keymap); ++i )
  19.104 +		RO_keymap[i] = SDLK_UNKNOWN;
  19.105 +
  19.106 +  RO_keymap[3] = SDLK_LSHIFT;
  19.107 +  RO_keymap[4] = SDLK_LCTRL;
  19.108 +  RO_keymap[5] = SDLK_LALT;
  19.109 +  RO_keymap[6] = SDLK_RSHIFT;
  19.110 +  RO_keymap[7] = SDLK_RCTRL;
  19.111 +  RO_keymap[8] = SDLK_RALT;
  19.112 +  RO_keymap[16] = SDLK_q;
  19.113 +  RO_keymap[17] = SDLK_3;
  19.114 +  RO_keymap[18] = SDLK_4;
  19.115 +  RO_keymap[19] = SDLK_5;
  19.116 +  RO_keymap[20] = SDLK_F4;
  19.117 +  RO_keymap[21] = SDLK_8;
  19.118 +  RO_keymap[22] = SDLK_F7;
  19.119 +  RO_keymap[23] = SDLK_MINUS,
  19.120 +  RO_keymap[25] = SDLK_LEFT;
  19.121 +  RO_keymap[26] = SDLK_KP6;
  19.122 +  RO_keymap[27] = SDLK_KP7;
  19.123 +  RO_keymap[28] = SDLK_F11;
  19.124 +  RO_keymap[29] = SDLK_F12;
  19.125 +  RO_keymap[30] = SDLK_F10;
  19.126 +  RO_keymap[31] = SDLK_SCROLLOCK;
  19.127 +  RO_keymap[32] = SDLK_PRINT;
  19.128 +  RO_keymap[33] = SDLK_w;
  19.129 +  RO_keymap[34] = SDLK_e;
  19.130 +  RO_keymap[35] = SDLK_t;
  19.131 +  RO_keymap[36] = SDLK_7;
  19.132 +  RO_keymap[37] = SDLK_i;
  19.133 +  RO_keymap[38] = SDLK_9;
  19.134 +  RO_keymap[39] = SDLK_0;
  19.135 +  RO_keymap[41] = SDLK_DOWN;
  19.136 +  RO_keymap[42] = SDLK_KP8;
  19.137 +  RO_keymap[43] = SDLK_KP9;
  19.138 +  RO_keymap[44] = SDLK_BREAK;
  19.139 +  RO_keymap[45] = SDLK_BACKQUOTE;
  19.140 +/*  RO_keymap[46] = SDLK_currency; TODO: Figure out if this has a value */
  19.141 +  RO_keymap[47] = SDLK_BACKSPACE;
  19.142 +  RO_keymap[48] = SDLK_1;
  19.143 +  RO_keymap[49] = SDLK_2;
  19.144 +  RO_keymap[50] = SDLK_d;
  19.145 +  RO_keymap[51] = SDLK_r;
  19.146 +  RO_keymap[52] = SDLK_6;
  19.147 +  RO_keymap[53] = SDLK_u;
  19.148 +  RO_keymap[54] = SDLK_o;
  19.149 +  RO_keymap[55] = SDLK_p;
  19.150 +  RO_keymap[56] = SDLK_LEFTPAREN;
  19.151 +  RO_keymap[57] = SDLK_UP;
  19.152 +  RO_keymap[58] = SDLK_KP_PLUS;
  19.153 +  RO_keymap[59] = SDLK_KP_MINUS;
  19.154 +  RO_keymap[60] = SDLK_KP_ENTER;
  19.155 +  RO_keymap[61] = SDLK_INSERT;
  19.156 +  RO_keymap[62] = SDLK_HOME;
  19.157 +  RO_keymap[63] = SDLK_PAGEUP;
  19.158 +  RO_keymap[64] = SDLK_CAPSLOCK;
  19.159 +  RO_keymap[65] = SDLK_a;
  19.160 +  RO_keymap[66] = SDLK_x;
  19.161 +  RO_keymap[67] = SDLK_f;
  19.162 +  RO_keymap[68] = SDLK_y;
  19.163 +  RO_keymap[69] = SDLK_j;
  19.164 +  RO_keymap[70] = SDLK_k;
  19.165 +  RO_keymap[72] = SDLK_SEMICOLON;
  19.166 +  RO_keymap[73] = SDLK_RETURN;
  19.167 +  RO_keymap[74] = SDLK_KP_DIVIDE;
  19.168 +  RO_keymap[76] = SDLK_KP_PERIOD;
  19.169 +  RO_keymap[77] = SDLK_NUMLOCK;
  19.170 +  RO_keymap[78] = SDLK_PAGEDOWN;
  19.171 +  RO_keymap[79] = SDLK_QUOTE;
  19.172 +  RO_keymap[81] = SDLK_s;
  19.173 +  RO_keymap[82] = SDLK_c;
  19.174 +  RO_keymap[83] = SDLK_g;
  19.175 +  RO_keymap[84] = SDLK_h;
  19.176 +  RO_keymap[85] = SDLK_n;
  19.177 +  RO_keymap[86] = SDLK_l;
  19.178 +  RO_keymap[87] = SDLK_SEMICOLON;
  19.179 +  RO_keymap[88] = SDLK_RIGHTPAREN;
  19.180 +  RO_keymap[89] = SDLK_DELETE;
  19.181 +  RO_keymap[90] = SDLK_KP_MINUS;
  19.182 +  RO_keymap[91] = SDLK_KP_MULTIPLY;
  19.183 +  RO_keymap[93] = SDLK_EQUALS;
  19.184 +  RO_keymap[94] = SDLK_BACKSLASH;
  19.185 +  RO_keymap[96] = SDLK_TAB;
  19.186 +  RO_keymap[97] = SDLK_z;
  19.187 +  RO_keymap[98] = SDLK_SPACE;
  19.188 +  RO_keymap[99] = SDLK_v;
  19.189 +  RO_keymap[100] = SDLK_b;
  19.190 +  RO_keymap[101] = SDLK_m;
  19.191 +  RO_keymap[102] = SDLK_COMMA;
  19.192 +  RO_keymap[103] = SDLK_PERIOD;
  19.193 +  RO_keymap[104] = SDLK_SLASH;
  19.194 +  RO_keymap[105] = SDLK_END;
  19.195 +  RO_keymap[106] = SDLK_KP0;
  19.196 +  RO_keymap[107] = SDLK_KP1;
  19.197 +  RO_keymap[108] = SDLK_KP3;
  19.198 +  RO_keymap[112] = SDLK_ESCAPE;
  19.199 +  RO_keymap[113] = SDLK_F1;
  19.200 +  RO_keymap[114] = SDLK_F2;
  19.201 +  RO_keymap[115] = SDLK_F3;
  19.202 +  RO_keymap[116] = SDLK_F5;
  19.203 +  RO_keymap[117] = SDLK_F6;
  19.204 +  RO_keymap[118] = SDLK_F8;
  19.205 +  RO_keymap[119] = SDLK_F9;
  19.206 +  RO_keymap[120] = SDLK_HASH;
  19.207 +  RO_keymap[121] = SDLK_RIGHT;
  19.208 +  RO_keymap[122] = SDLK_KP4;
  19.209 +  RO_keymap[123] = SDLK_KP5;
  19.210 +  RO_keymap[124] = SDLK_KP2;
  19.211 +
  19.212 +  memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE);
  19.213 +}
  19.214 +
  19.215 +
  19.216 +/* Variable for mouse relative processing */
  19.217 +int mouse_relative = 0;
  19.218 +
  19.219 +/* Check to see if we need to enter or leave mouse relative mode */
  19.220 +
  19.221 +void RISCOS_CheckMouseMode(_THIS)
  19.222 +{
  19.223 +    /* If the mouse is hidden and input is grabbed, we use relative mode */
  19.224 +    if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
  19.225 +        (this->input_grab != SDL_GRAB_OFF) ) {
  19.226 +            mouse_relative = 1;
  19.227 +     } else {
  19.228 +            mouse_relative = 0;
  19.229 +     }
  19.230 +}
  19.231 +
  19.232 +
  19.233 +void RISCOS_PollMouse(_THIS)
  19.234 +{
  19.235 +   RISCOS_PollMouseHelper(this, 1);
  19.236 +}
  19.237 +
  19.238 +extern int mouseInWindow;
  19.239 +
  19.240 +void WIMP_PollMouse(_THIS)
  19.241 +{
  19.242 +   /* Only poll when mouse is over the window */
  19.243 +   if (!mouseInWindow) return;
  19.244 +
  19.245 +   RISCOS_PollMouseHelper(this, 0);
  19.246 +}
  19.247 +
  19.248 +/* Static variables so only changes are reported */
  19.249 +static Sint16 last_x = -1, last_y = -1;
  19.250 +static int last_buttons = 0;
  19.251 +
  19.252 +/* Share routine between WIMP and FULLSCREEN for polling mouse and
  19.253 +   passing on events */
  19.254 +void RISCOS_PollMouseHelper(_THIS, int fullscreen)
  19.255 +{
  19.256 +    _kernel_swi_regs regs;
  19.257 +    static int starting = 1;
  19.258 +
  19.259 +    if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL)
  19.260 +    {
  19.261 +       Sint16 new_x = regs.r[0]; /* Initialy get as OS units */
  19.262 +       Sint16 new_y = regs.r[1];
  19.263 +
  19.264 +/* Discard mouse events until the let go of the mouse after starting */
  19.265 +       if (starting && regs.r[2] != 0) return;
  19.266 +       else starting = 0;
  19.267 +
  19.268 +       if (new_x != last_x || new_y != last_y || last_buttons != regs.r[2])
  19.269 +       {
  19.270 +          /* Something changed so generate appropriate events */
  19.271 +          int topLeftX, topLeftY;  /* Top left OS units */
  19.272 +          int x, y;                /* Mouse position in SDL pixels */
  19.273 +
  19.274 +          if (fullscreen)
  19.275 +          {
  19.276 +             topLeftX = 0;
  19.277 +             topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
  19.278 +          } else
  19.279 +          {
  19.280 +             int window_state[9];
  19.281 +
  19.282 +	         /* Get current window state */
  19.283 +		     window_state[0] = this->hidden->window_handle;
  19.284 +		     regs.r[1] = (unsigned int)window_state;
  19.285 +		     _kernel_swi(Wimp_GetWindowState, &regs, &regs);
  19.286 +
  19.287 +             topLeftX = window_state[1];
  19.288 +             topLeftY = window_state[4];
  19.289 +          }
  19.290 +
  19.291 +		  /* Convert co-ordinates to workspace */
  19.292 +		  x = new_x - topLeftX;
  19.293 +          y = topLeftY - new_y; /* Y goes from top of window/screen */
  19.294 +
  19.295 +	 	  /* Convert OS units to pixels */
  19.296 +	      x >>= this->hidden->xeig;
  19.297 +		  y >>= this->hidden->yeig;
  19.298 +
  19.299 +          if (last_x != new_x || last_y != new_y)
  19.300 +          {
  19.301 +             if (mouse_relative)
  19.302 +             {
  19.303 +                int centre_x = SDL_VideoSurface->w/2;
  19.304 +                int centre_y = SDL_VideoSurface->h/2;
  19.305 +
  19.306 +                if (centre_x != x || centre_y != y)
  19.307 +                {
  19.308 +                   if (SDL_VideoSurface) SDL_PrivateMouseMotion(0,1,x - centre_x, y - centre_y);
  19.309 +                   last_x = topLeftX + (centre_x << this->hidden->xeig);
  19.310 +                   last_y = topLeftY - (centre_y << this->hidden->yeig);
  19.311 +
  19.312 +                   /* Re-centre the mouse pointer, so we still get relative
  19.313 +                      movement when the mouse is at the edge of the window
  19.314 +                      or screen.
  19.315 +                   */
  19.316 +                   {
  19.317 +                      unsigned char block[5];
  19.318 +
  19.319 +                      block[0] = 3; /* OSWORD move pointer sub-reason code */
  19.320 +                      block[1] = last_x & 0xFF;
  19.321 +                      block[2] = (last_x >> 8) & 0xFF;
  19.322 +                      block[3] = last_y & 0xFF;
  19.323 +                      block[4] = (last_y >> 8) & 0xFF;
  19.324 +                       
  19.325 +                      regs.r[0] = 21; /* OSWORD pointer stuff code */
  19.326 +                      regs.r[1] = (int)block;
  19.327 +                      _kernel_swi(OS_Word, &regs, &regs);
  19.328 +               	   }
  19.329 +                }
  19.330 +             } else
  19.331 +             {
  19.332 +                last_x = new_x;
  19.333 +                last_y = new_y;
  19.334 +                SDL_PrivateMouseMotion(0,0,x,y);
  19.335 +             }
  19.336 +          }
  19.337 +
  19.338 +          if (last_buttons != regs.r[2])
  19.339 +          {
  19.340 +             int changed = last_buttons ^ regs.r[2];
  19.341 +             last_buttons = regs.r[2];
  19.342 +             if (changed & 4) SDL_PrivateMouseButton((last_buttons & 4) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, x, y);
  19.343 +             if (changed & 2) SDL_PrivateMouseButton((last_buttons & 2) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_MIDDLE, x, y);
  19.344 +             if (changed & 1) SDL_PrivateMouseButton((last_buttons & 1) ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT, x, y);
  19.345 +          }
  19.346 +       }
  19.347 +    }
  19.348 +}
  19.349 +
  19.350 +void RISCOS_PollKeyboard()
  19.351 +{
  19.352 +	int which_key = ROKEY_LEFT_SHIFT;
  19.353 +	int j;
  19.354 +	int min_key, max_key;
  19.355 +	SDL_keysym key;
  19.356 +
  19.357 +	/* Scan the keyboard to see what is pressed */
  19.358 +	while (which_key <= ROKEY_LAST_KEY)
  19.359 +	{
  19.360 +		which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
  19.361 +	    if (which_key != ROKEY_NONE)
  19.362 +		{
  19.363 +		    switch(which_key)
  19.364 +		    {
  19.365 +		    /* Skip over mouse keys */
  19.366 +		    case ROKEY_LEFT_MOUSE:
  19.367 +		    case ROKEY_CENTRE_MOUSE:
  19.368 +		    case ROKEY_RIGHT_MOUSE:
  19.369 +				which_key = ROKEY_RIGHT_MOUSE;
  19.370 +				break;
  19.371 +
  19.372 +            /* Ignore keys that cause 2 internal number to be generated */
  19.373 +			case 71: case 24: case 87: case 40:
  19.374 +			    break;
  19.375 +
  19.376 +			default:
  19.377 +				RO_pressed[which_key] += 2;
  19.378 +				break;
  19.379 +		    }
  19.380 +			which_key++;
  19.381 +		}
  19.382 +	}
  19.383 +
  19.384 +	/* Generate key released messages */
  19.385 +	min_key = ROKEY_LAST_KEY+1;
  19.386 +	max_key = ROKEY_LEFT_SHIFT;
  19.387 +
  19.388 +	for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++)
  19.389 +	{
  19.390 +		if (RO_pressed[j])
  19.391 +		{
  19.392 +			if (RO_pressed[j] == 1)
  19.393 +			{
  19.394 +				RO_pressed[j] = 0;
  19.395 +				SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j,&key,0));
  19.396 +			} else 
  19.397 +			{
  19.398 +				if (j < min_key) min_key = j;
  19.399 +				if (j > max_key) max_key = j;
  19.400 +			}
  19.401 +		}
  19.402 +	}
  19.403 +
  19.404 +	/* Generate key pressed messages */
  19.405 +	for (j = min_key; j <= max_key; j++)
  19.406 +	{
  19.407 +		if (RO_pressed[j])
  19.408 +		{
  19.409 +			if (RO_pressed[j] == 2)
  19.410 +			{
  19.411 +				SDL_PrivateKeyboard(SDL_PRESSED,TranslateKey(j,&key,1));
  19.412 +			}
  19.413 +			RO_pressed[j] = 1;
  19.414 +		}
  19.415 +	}
  19.416 +}
  19.417 +
  19.418 +static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed)
  19.419 +{
  19.420 +	/* Set the keysym information */
  19.421 +	keysym->scancode = (unsigned char) intkey;
  19.422 +	keysym->sym = RO_keymap[intkey];
  19.423 +	keysym->mod = KMOD_NONE;
  19.424 +	keysym->unicode = 0;
  19.425 +	if ( pressed && SDL_TranslateUNICODE )
  19.426 +	{
  19.427 +		int state;
  19.428 +		int ch;
  19.429 +
  19.430 +		state = (_kernel_osbyte(202, 0, 255) & 0xFF);
  19.431 +
  19.432 +		/*TODO: better key to char mapping */
  19.433 +
  19.434 +		ch = keysym->sym; /* This should handle most keys */
  19.435 +
  19.436 +        if (intkey < 9)
  19.437 +        {
  19.438 +           ch = 0;
  19.439 +
  19.440 +        } else if (state & 64) /* Control on */
  19.441 +		{
  19.442 +			ch = ch & 31;
  19.443 +
  19.444 +		} else if ((state & 16) == 0) /* Caps lock is on */
  19.445 +		{
  19.446 +			if ((state & 128) == 0) /* Shift Enable off */
  19.447 +			{
  19.448 +				ch = toupper(ch);
  19.449 +			}
  19.450 +		} else if (state & 8) /* Shift on */
  19.451 +		{
  19.452 +			ch = toupper(ch);
  19.453 +		}
  19.454 +				
  19.455 +		keysym->unicode = ch;
  19.456 +	}
  19.457 +	return(keysym);
  19.458 +}
  19.459 +
  19.460 +/* end of SDL_riscosevents.c ... */
  19.461 +
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/video/riscos/SDL_riscosevents_c.h	Thu May 29 04:44:13 2003 +0000
    20.3 @@ -0,0 +1,38 @@
    20.4 +/*
    20.5 +    SDL - Simple DirectMedia Layer
    20.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    20.7 +
    20.8 +    This library is free software; you can redistribute it and/or
    20.9 +    modify it under the terms of the GNU Library General Public
   20.10 +    License as published by the Free Software Foundation; either
   20.11 +    version 2 of the License, or (at your option) any later version.
   20.12 +
   20.13 +    This library is distributed in the hope that it will be useful,
   20.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 +    Library General Public License for more details.
   20.17 +
   20.18 +    You should have received a copy of the GNU Library General Public
   20.19 +    License along with this library; if not, write to the Free
   20.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   20.21 +
   20.22 +    Sam Lantinga
   20.23 +    slouken@devolution.com
   20.24 +*/
   20.25 +
   20.26 +#ifdef SAVE_RCSID
   20.27 +static char rcsid =
   20.28 + "@(#) $Id$";
   20.29 +#endif
   20.30 +
   20.31 +#include "SDL_riscosvideo.h"
   20.32 +
   20.33 +/* Variables and functions exported by SDL_sysevents.c to other parts 
   20.34 +   of the native video subsystem (SDL_sysvideo.c)
   20.35 +*/
   20.36 +extern void RISCOS_InitOSKeymap(_THIS);
   20.37 +extern void FULLSCREEN_PumpEvents(_THIS);
   20.38 +extern void WIMP_PumpEvents(_THIS);
   20.39 +
   20.40 +/* end of SDL_nullevents_c.h ... */
   20.41 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/video/riscos/SDL_riscosmouse.c	Thu May 29 04:44:13 2003 +0000
    21.3 @@ -0,0 +1,301 @@
    21.4 +/*
    21.5 +    SDL - Simple DirectMedia Layer
    21.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    21.7 +
    21.8 +    This library is free software; you can redistribute it and/or
    21.9 +    modify it under the terms of the GNU Library General Public
   21.10 +    License as published by the Free Software Foundation; either
   21.11 +    version 2 of the License, or (at your option) any later version.
   21.12 +
   21.13 +    This library is distributed in the hope that it will be useful,
   21.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21.16 +    Library General Public License for more details.
   21.17 +
   21.18 +    You should have received a copy of the GNU Library General Public
   21.19 +    License along with this library; if not, write to the Free
   21.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21.21 +
   21.22 +    Sam Lantinga
   21.23 +    slouken@devolution.com
   21.24 +*/
   21.25 +
   21.26 +/*
   21.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   21.28 +	 27 March 2003
   21.29 +
   21.30 +     Implements mouse cursor shape definitions and positioning
   21.31 +*/
   21.32 +
   21.33 +#include <stdio.h>
   21.34 +#include <stdlib.h>
   21.35 +
   21.36 +#include "SDL_error.h"
   21.37 +#include "SDL_mouse.h"
   21.38 +#include "SDL_events_c.h"
   21.39 +
   21.40 +#include "SDL_riscosmouse_c.h"
   21.41 +
   21.42 +#include "kernel.h"
   21.43 +#include "swis.h"
   21.44 +
   21.45 +static WMcursor *current_cursor = NULL;
   21.46 +
   21.47 +extern int mouseInWindow;
   21.48 +
   21.49 +void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor)
   21.50 +{
   21.51 +    free(cursor->data);
   21.52 +	free(cursor);
   21.53 +}
   21.54 +
   21.55 +WMcursor *RISCOS_CreateWMCursor(_THIS,
   21.56 +		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y)
   21.57 +{
   21.58 +	WMcursor *cursor;
   21.59 +	Uint8 *cursor_data;
   21.60 +	Uint8 *ptr;
   21.61 +	int i,j,k;
   21.62 +	int data_byte, mask_byte;
   21.63 +
   21.64 +	/* Check to make sure the cursor size is okay */
   21.65 +	if ( (w > 32) || (h > 32) ) {
   21.66 +		SDL_SetError("Only with width and height <= 32 pixels are allowed");
   21.67 +		return(NULL);
   21.68 +	}
   21.69 +
   21.70 +	/* Allocate the cursor */
   21.71 +	cursor = (WMcursor *)malloc(sizeof(*cursor));
   21.72 +	if ( cursor == NULL ) {
   21.73 +		SDL_SetError("Out of memory");
   21.74 +		return(NULL);
   21.75 +	}
   21.76 +
   21.77 +	/* Note: SDL says width must be a multiple of 8 */
   21.78 +	cursor_data = malloc(w/4 * h);
   21.79 +	if (cursor_data == NULL)
   21.80 +	{
   21.81 +		free(cursor);
   21.82 +		SDL_SetError("Out of memory");
   21.83 +		return(NULL);
   21.84 +	}
   21.85 +
   21.86 +	cursor->w = w;
   21.87 +	cursor->h = h;
   21.88 +	cursor->hot_x = hot_x;
   21.89 +	cursor->hot_y = hot_y;
   21.90 +	cursor->data = cursor_data;
   21.91 +
   21.92 +
   21.93 +/* Data / Mask Resulting pixel on screen 
   21.94 +   0 / 1 White 
   21.95 +   1 / 1 Black 
   21.96 +   0 / 0 Transparent 
   21.97 +   1 / 0 Inverted color if possible, black if not. 
   21.98 +*/
   21.99 +	ptr = cursor_data;
  21.100 +
  21.101 +	for ( i=0; i<h; ++i )
  21.102 +	{
  21.103 +		for (j = 0; j < w/8; ++j)
  21.104 +		{
  21.105 +			data_byte = *data;
  21.106 +			mask_byte = *mask;
  21.107 +			*ptr++ = 0; /* Sets whole byte transparent */
  21.108 +			*ptr = 0;
  21.109 +			for (k = 0; k < 8; k++)
  21.110 +			{
  21.111 +				(*ptr) <<= 2;
  21.112 +				if (data_byte & 1) *ptr |= 3; /* Black or inverted */
  21.113 +				else if(mask_byte & 1) *ptr |= 1; /* White */
  21.114 +				if ((k&3) == 3) ptr--;
  21.115 +				data_byte >>= 1;
  21.116 +				mask_byte >>= 1;
  21.117 +			}
  21.118 +
  21.119 +            ptr+=3;
  21.120 +		    data++;
  21.121 +		    mask++;
  21.122 +		}
  21.123 +	}
  21.124 +
  21.125 +	return(cursor);
  21.126 +}
  21.127 +
  21.128 +int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor)
  21.129 +{
  21.130 +	if (cursor == NULL)
  21.131 +	{
  21.132 +		_kernel_osbyte(106,0,0);
  21.133 +		current_cursor = NULL;
  21.134 +	} else
  21.135 +	{
  21.136 +		if (current_cursor == NULL)
  21.137 +		{
  21.138 +			/* First time set up the mouse colours */
  21.139 +			Uint8 block[5];
  21.140 +
  21.141 +			/* Set up colour 1 as white */
  21.142 +			block[0] = 1;   /* Colour to change 1 - 3 */
  21.143 +			block[1] = 25;  /* Set pointer colour */
  21.144 +			block[2] = 255; /* red component*/
  21.145 +			block[3] = 255; /* green component */
  21.146 +			block[4] = 255; /* blue component*/
  21.147 +			_kernel_osword(12, (int *)block);
  21.148 +		
  21.149 +			/* Set colour 3 to back */
  21.150 +			block[0] = 3;   /* Colour to change 1 - 3 */
  21.151 +			block[1] = 25;  /* Set pointer colour*/
  21.152 +			block[2] = 0; /* red component*/
  21.153 +			block[3] = 0; /* green component */
  21.154 +			block[4] = 0; /* blue component*/
  21.155 +			_kernel_osword(12, (int *)block);
  21.156 +		}
  21.157 +
  21.158 +		if (cursor != current_cursor)
  21.159 +		{
  21.160 +			Uint8 cursor_def[10];
  21.161 +
  21.162 +			cursor_def[0] = 0;
  21.163 +			cursor_def[1] = 2; /* Use shape number 2 */
  21.164 +			cursor_def[2] = cursor->w/4; /* Width in bytes */
  21.165 +			cursor_def[3] = cursor->h; /* Height (h) in pixels */
  21.166 +			cursor_def[4] = cursor->hot_x; /* ActiveX in pixels from left */
  21.167 +			cursor_def[5] = cursor->hot_y; /* ActiveY in pixels from top */
  21.168 +			cursor_def[6] = ((int)(cursor->data) & 0xFF);       /* Least significant byte of pointer to data */
  21.169 +			cursor_def[7] = ((int)(cursor->data) >> 8) & 0xFF;  /* ... */
  21.170 +			cursor_def[8] = ((int)(cursor->data) >> 16) & 0xFF; /* ... */
  21.171 +			cursor_def[9] = ((int)(cursor->data) >> 24) & 0xFF; /* Most significant byte of pointer to data */
  21.172 +
  21.173 +			if (_kernel_osword(21, (int *)cursor_def) == 0)
  21.174 +			{
  21.175 +				SDL_SetError("RISCOS couldn't create the cursor to show");
  21.176 +				return(0);
  21.177 +			}
  21.178 +			current_cursor = cursor;
  21.179 +		}
  21.180 +
  21.181 +		if ((this->screen->flags & SDL_FULLSCREEN) || mouseInWindow) _kernel_osbyte(106, 2, 0);
  21.182 +	}
  21.183 +	
  21.184 +	return(1);
  21.185 +}
  21.186 +
  21.187 +void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
  21.188 +{
  21.189 +	Uint8 move_block[5];
  21.190 +	int eig_block[3];
  21.191 +	_kernel_swi_regs regs;
  21.192 +	int os_x, os_y;
  21.193 +
  21.194 +	eig_block[0] = 4;  /* X eig factor */
  21.195 +	eig_block[1] = 5;  /* Y eig factor */
  21.196 +	eig_block[2] = -1;  /* End of list of variables to request */
  21.197 +
  21.198 +    regs.r[0] = (int)eig_block;
  21.199 +    regs.r[1] = (int)eig_block;
  21.200 +    _kernel_swi(OS_ReadVduVariables, &regs, &regs);
  21.201 +
  21.202 +	os_x = x << eig_block[0];
  21.203 +	os_y = y << eig_block[1];
  21.204 +
  21.205 +	move_block[0] = 3; /* Move cursor */
  21.206 +	move_block[1] = os_x & 0xFF;
  21.207 +	move_block[2] = (os_x >> 8) & 0xFF;
  21.208 +	move_block[3] = os_y & 0xFF;
  21.209 +	move_block[4] = (os_y >> 8) & 0xFF;
  21.210 +
  21.211 +	_kernel_osword(21, (int *)move_block);
  21.212 +	SDL_PrivateMouseMotion(0, 0, x, y);
  21.213 +}
  21.214 +
  21.215 +
  21.216 +/* Reshow cursor when mouse re-enters the window */
  21.217 +void WIMP_ReshowCursor(_THIS)
  21.218 +{
  21.219 +	WMcursor *cursor = current_cursor;
  21.220 +	current_cursor = NULL;
  21.221 +	RISCOS_ShowWMCursor(this, cursor);
  21.222 +}
  21.223 +
  21.224 +extern int mouseInWindow;
  21.225 +
  21.226 +void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
  21.227 +{
  21.228 +	_kernel_swi_regs regs;
  21.229 +	int window_state[9];
  21.230 +	char block[5];
  21.231 +	int osX, osY;
  21.232 +
  21.233 +	window_state[0] = this->hidden->window_handle;
  21.234 +	regs.r[1] = (unsigned int)window_state;
  21.235 +	_kernel_swi(Wimp_GetWindowState, &regs, &regs);
  21.236 +
  21.237 +	 osX = (x << this->hidden->xeig) + window_state[1];
  21.238 +	 osY = window_state[4] - (y << this->hidden->yeig);
  21.239 +
  21.240 +	block[0] = 3;
  21.241 +	block[1] = osX & 0xFF;
  21.242 +	block[2] = (osX >> 8) & 0xFF;
  21.243 +	block[3] = osY & 0xFF;
  21.244 +	block[4] = (osY >> 8) & 0xFF;
  21.245 +
  21.246 +	regs.r[0] = 21;
  21.247 +	regs.r[1] = (int)block;
  21.248 +	_kernel_swi(OS_Word, &regs, &regs);
  21.249 +	SDL_PrivateMouseMotion(0, 0, x, y);
  21.250 +}
  21.251 +
  21.252 +int WIMP_ShowWMCursor(_THIS, WMcursor *cursor)
  21.253 +{
  21.254 +	if (mouseInWindow) return RISCOS_ShowWMCursor(this, cursor);
  21.255 +	return 1;
  21.256 +}
  21.257 +
  21.258 +SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
  21.259 +{
  21.260 +   /* In fullscreen mode we don't need to do anything */
  21.261 +   if (mode < SDL_GRAB_FULLSCREEN)
  21.262 +   {
  21.263 +      _kernel_swi_regs regs;
  21.264 +      unsigned char block[9];
  21.265 +      block[0] = 1; /* Define mouse cursor bounding block */
  21.266 +
  21.267 +      if ( mode == SDL_GRAB_OFF )
  21.268 +      {
  21.269 +         /* Clip to whole screen */
  21.270 +
  21.271 +         int r = (this->hidden->screen_width << this->hidden->xeig) - 1;
  21.272 +         int t = (this->hidden->screen_height << this->hidden->yeig) - 1;
  21.273 +
  21.274 +	 block[1] = 0; block[2] = 0; /* Left*/
  21.275 +         block[3] = 0; block[4] = 0; /* Bottom */
  21.276 +         block[5] = r & 0xFF; block[6] = (r >> 8) & 0xFF; /* Right */
  21.277 +         block[7] = t & 0xFF; block[8] = (t >> 8) & 0xFF; /* Top */
  21.278 +      } else
  21.279 +      {
  21.280 +        /* Clip to window */
  21.281 +       	unsigned char window_state[36];
  21.282 +
  21.283 +	*((int *)window_state) = this->hidden->window_handle;
  21.284 +	regs.r[1] = (unsigned int)window_state;
  21.285 +	_kernel_swi(Wimp_GetWindowState, &regs, &regs);
  21.286 +
  21.287 +        block[1] = window_state[4];
  21.288 +        block[2] = window_state[5];
  21.289 +        block[3] = window_state[8];
  21.290 +        block[4] = window_state[9];
  21.291 +        block[5] = window_state[12];
  21.292 +        block[6] = window_state[13];
  21.293 +        block[7] = window_state[16];
  21.294 +        block[8] = window_state[17];
  21.295 +
  21.296 +      }
  21.297 +
  21.298 +      regs.r[0] = 21; /* OS word code */
  21.299 +      regs.r[1] = (int)block;
  21.300 +      _kernel_swi(OS_Word, &regs, &regs);
  21.301 +   }
  21.302 +
  21.303 +   return mode;
  21.304 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/video/riscos/SDL_riscosmouse_c.h	Thu May 29 04:44:13 2003 +0000
    22.3 @@ -0,0 +1,48 @@
    22.4 +/*
    22.5 +    SDL - Simple DirectMedia Layer
    22.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    22.7 +
    22.8 +    This library is free software; you can redistribute it and/or
    22.9 +    modify it under the terms of the GNU Library General Public
   22.10 +    License as published by the Free Software Foundation; either
   22.11 +    version 2 of the License, or (at your option) any later version.
   22.12 +
   22.13 +    This library is distributed in the hope that it will be useful,
   22.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   22.16 +    Library General Public License for more details.
   22.17 +
   22.18 +    You should have received a copy of the GNU Library General Public
   22.19 +    License along with this library; if not, write to the Free
   22.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22.21 +
   22.22 +    Sam Lantinga
   22.23 +    slouken@devolution.com
   22.24 +*/
   22.25 +
   22.26 +#ifdef SAVE_RCSID
   22.27 +static char rcsid =
   22.28 + "@(#) $Id$";
   22.29 +#endif
   22.30 +
   22.31 +#include "SDL_riscosvideo.h"
   22.32 +
   22.33 +/* The implementation dependent data for the window manager cursor */
   22.34 +struct WMcursor {
   22.35 +	int w;
   22.36 +	int h;
   22.37 +	int hot_x;
   22.38 +	int hot_y;
   22.39 +	Uint8 *data;
   22.40 +};
   22.41 +
   22.42 +/* Functions to be exported */
   22.43 +void RISCOS_FreeWMCursor(_THIS, WMcursor *cursor);
   22.44 +WMcursor *RISCOS_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
   22.45 +
   22.46 +int RISCOS_ShowWMCursor(_THIS, WMcursor *cursor);
   22.47 +void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
   22.48 +
   22.49 +int WIMP_ShowWMCursor(_THIS, WMcursor *cursor);
   22.50 +void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
   22.51 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/video/riscos/SDL_riscossprite.c	Thu May 29 04:44:13 2003 +0000
    23.3 @@ -0,0 +1,263 @@
    23.4 +/*
    23.5 +    SDL - Simple DirectMedia Layer
    23.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    23.7 +
    23.8 +    This library is free software; you can redistribute it and/or
    23.9 +    modify it under the terms of the GNU Library General Public
   23.10 +    License as published by the Free Software Foundation; either
   23.11 +    version 2 of the License, or (at your option) any later version.
   23.12 +
   23.13 +    This library is distributed in the hope that it will be useful,
   23.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   23.16 +    Library General Public License for more details.
   23.17 +
   23.18 +    You should have received a copy of the GNU Library General Public
   23.19 +    License along with this library; if not, write to the Free
   23.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.21 +
   23.22 +    Sam Lantinga
   23.23 +    slouken@devolution.com
   23.24 +*/
   23.25 +
   23.26 +/*
   23.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   23.28 +	 27 March 2003
   23.29 +
   23.30 +     Implements Sprite plotting code for wimp display.window
   23.31 +*/
   23.32 +
   23.33 +#include <stdlib.h>
   23.34 +#include "kernel.h"
   23.35 +#include "swis.h"
   23.36 +#include "SDL_riscosvideo.h"
   23.37 +
   23.38 +extern void WIMP_ReadModeInfo(_THIS);
   23.39 +
   23.40 +void WIMP_PaletteChanged(_THIS);
   23.41 +
   23.42 +
   23.43 +/* Create sprite buffer for screen */
   23.44 +
   23.45 +unsigned char *WIMP_CreateBuffer(int width, int height, int bpp)
   23.46 +{
   23.47 +	int size;
   23.48 +	char sprite_name[12] = "display";
   23.49 +	unsigned char *buffer;
   23.50 +	_kernel_swi_regs regs;
   23.51 +	int bytesPerPixel;
   23.52 +	int bytesPerRow;
   23.53 +	int offsetToSpriteData = 60;
   23.54 +
   23.55 +	switch(bpp)
   23.56 +	{
   23.57 +	case 32: bytesPerPixel = 4; break;
   23.58 +	case 16: bytesPerPixel = 2; break;
   23.59 +	case 8:
   23.60 +	    bytesPerPixel = 1;
   23.61 +	    offsetToSpriteData += 2048; /* Add in size of palette */
   23.62 +	    break;
   23.63 +	default:
   23.64 +		return NULL;
   23.65 +		break;
   23.66 +	}
   23.67 +
   23.68 +	bytesPerRow = bytesPerPixel * width;
   23.69 +
   23.70 +	if ((bytesPerRow & 3) != 0)
   23.71 +	{
   23.72 +		bytesPerRow += 4 - (bytesPerRow & 3);
   23.73 +	}
   23.74 +	size = bytesPerRow * height;
   23.75 +
   23.76 +	buffer = malloc( (size_t) size + offsetToSpriteData );
   23.77 +	if (!buffer) return NULL;
   23.78 +
   23.79 +   /* Initialise a sprite area */
   23.80 +
   23.81 +	*(unsigned int *)buffer		= size + offsetToSpriteData;
   23.82 +	*(unsigned int *)(buffer + 8)	= 16;
   23.83 +
   23.84 +	regs.r[0] = 256+9;
   23.85 +	regs.r[1] = (unsigned int)buffer;
   23.86 +   _kernel_swi(OS_SpriteOp, &regs, &regs);
   23.87 +
   23.88 +	regs.r[0] = 256+15;
   23.89 +	regs.r[1] = (unsigned int)buffer;
   23.90 +	regs.r[2] = (unsigned int)&sprite_name;
   23.91 +	regs.r[3] = 0; /* Palette flag: 0 = no palette */
   23.92 +	regs.r[4] = width;
   23.93 +	regs.r[5] = height;
   23.94 +	if (bpp == 8)
   23.95 +	{
   23.96 +		/* Use old style mode number */
   23.97 +		regs.r[6] = 28; /* 8bpp 90x90dpi */
   23.98 +	} else
   23.99 +	{
  23.100 +		regs.r[6] = (((bpp == 16) ? 5 : 6) << 27) /* Type 6 = 32bpp sprite, 5 = 16bpp sprite */
  23.101 +					| (90 << 14) /* Vertical dpi */
  23.102 +					| (90 << 1)  /* Horizontal dpi */
  23.103 +					| 1; /* Marker to distinguish between mode selectors and sprite modes */
  23.104 +	}
  23.105 +   if (_kernel_swi(OS_SpriteOp, &regs, &regs) == NULL)
  23.106 +   {
  23.107 +       if (bpp == 8)
  23.108 +       {
  23.109 +          /* Modify sprite to take into account 256 colour palette */
  23.110 +          int *sprite = (int *)(buffer + 16);
  23.111 +          /* Adjust sprite offsets */
  23.112 +          sprite[0] += 2048;
  23.113 +          sprite[8] += 2048;
  23.114 +          sprite[9] += 2048;
  23.115 +          /* Adjust sprite area next free pointer */
  23.116 +          (*(int *)(buffer+12)) += 2048;
  23.117 +
  23.118 +          /* Don't need to set up palette as SDL sets up the default
  23.119 +             256 colour palette */
  23.120 +/*          {
  23.121 +             int *pal = sprite + 11;
  23.122 +             unsigned int j;
  23.123 +             unsigned int entry;
  23.124 +             for (j = 0; j < 255; j++)
  23.125 +             {
  23.126 +                entry = (j << 24) | (j << 16) | (j << 8);
  23.127 +                *pal++ = entry;
  23.128 +                *pal++ = entry;
  23.129 +             }
  23.130 +          }
  23.131 +*/
  23.132 +       }
  23.133 +   } else
  23.134 +   {
  23.135 +      free(buffer);
  23.136 +      buffer = NULL;
  23.137 +   }
  23.138 +
  23.139 +   return buffer;
  23.140 +}
  23.141 +
  23.142 +
  23.143 +/* Setup translation buffers for the sprite plotting */
  23.144 +
  23.145 +void WIMP_SetupPlotInfo(_THIS)
  23.146 +{
  23.147 +   _kernel_swi_regs regs;
  23.148 +   int *sprite = ((int *)this->hidden->bank[1])+4;
  23.149 +
  23.150 +   regs.r[0] = (unsigned int)this->hidden->bank[1];
  23.151 +   regs.r[1] = (unsigned int)sprite;
  23.152 +   regs.r[2] = -1; /* Current mode */
  23.153 +   regs.r[3] = -1; /* Current palette */
  23.154 +   regs.r[4] = 0; /* Get size of buffer */
  23.155 +   regs.r[5] = 1|2|16; /* R1 - pointer to sprite and can use full palette words */
  23.156 +   regs.r[6] = 0;
  23.157 +   regs.r[7] = 0;
  23.158 +
  23.159 +   if (this->hidden->pixtrans) free(this->hidden->pixtrans);
  23.160 +   this->hidden->pixtrans = 0;
  23.161 +
  23.162 +   /* Get the size required for the buffer */
  23.163 +   _kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
  23.164 +   if (regs.r[4])
  23.165 +   {
  23.166 +      this->hidden->pixtrans = malloc(regs.r[4]);
  23.167 +    
  23.168 +      regs.r[4] = (unsigned int)this->hidden->pixtrans;
  23.169 +      /* Actually read the buffer */
  23.170 +      _kernel_swi(ColourTrans_GenerateTable, &regs, &regs);
  23.171 +   }
  23.172 +}
  23.173 +
  23.174 +/* Plot the sprite in the given context */
  23.175 +void WIMP_PlotSprite(_THIS, int x, int y)
  23.176 +{
  23.177 +   _kernel_swi_regs regs;
  23.178 +   _kernel_oserror *err;
  23.179 +
  23.180 +   regs.r[0] =  52 + 512;
  23.181 +   regs.r[1] = (unsigned int)this->hidden->bank[1];
  23.182 +   regs.r[2] = (unsigned int)this->hidden->bank[1]+16;
  23.183 +   regs.r[3] = x;
  23.184 +   regs.r[4] = y;
  23.185 +   regs.r[5] = 0|32; /* Overwrite screen and pixtrans contains wide colour entries */
  23.186 +   regs.r[6] = 0; /* No scale factors i.e. 1:1 */
  23.187 +   regs.r[7] = (int)this->hidden->pixtrans;
  23.188 +
  23.189 +   if ((err = _kernel_swi(OS_SpriteOp, &regs, &regs)) != 0)
  23.190 +   {
  23.191 +      int *p = (int *)this->hidden->pixtrans;
  23.192 +      printf("OS_SpriteOp failed \n%s\n",err->errmess);
  23.193 +      printf("pixtrans %d\n", (int)this->hidden->pixtrans);
  23.194 +      printf("%x %x %x\n", p[0], p[1], p[2]);
  23.195 +   }
  23.196 +}
  23.197 +
  23.198 +
  23.199 +/* Wimp mode has changes so update colour mapping and pixel sizes 
  23.200 +   of windows and the sprites they plot */
  23.201 +
  23.202 +void WIMP_ModeChanged(_THIS)
  23.203 +{
  23.204 +	int oldXeig = this->hidden->xeig;
  23.205 +	int oldYeig = this->hidden->yeig;
  23.206 +
  23.207 +	WIMP_ReadModeInfo(this);
  23.208 +
  23.209 +	if (oldXeig == this->hidden->xeig && oldYeig == this->hidden->yeig)
  23.210 +	{
  23.211 +		/* Only need to update the palette */
  23.212 +		WIMP_PaletteChanged(this);
  23.213 +	} else
  23.214 +	{
  23.215 +		_kernel_swi_regs regs;
  23.216 +		int window_state[9];
  23.217 +		int extent[4];
  23.218 +		int currWidth, currHeight;
  23.219 +		int newWidth, newHeight;
  23.220 +		
  23.221 +		/* Need to resize windows and update the palette */
  23.222 +		WIMP_SetupPlotInfo(this);
  23.223 +
  23.224 +
  23.225 +		window_state[0] = this->hidden->window_handle;
  23.226 +		regs.r[1] = (unsigned int)window_state;
  23.227 +		_kernel_swi(Wimp_GetWindowState, &regs, &regs);
  23.228 +						
  23.229 +		currWidth = window_state[3] - window_state[1];
  23.230 +		currHeight = window_state[4] - window_state[2];
  23.231 +		
  23.232 +		newWidth = (currWidth >> oldXeig) << this->hidden->xeig;
  23.233 +		newHeight = (currHeight >> oldYeig) << this->hidden->yeig;
  23.234 +		/* Need to avoid extent getting too small for visible part
  23.235 +		of window */
  23.236 +		extent[0] = 0;
  23.237 +		if (currHeight <= newHeight)
  23.238 +		{
  23.239 +			extent[1] = -newHeight;
  23.240 +		} else
  23.241 +		{
  23.242 +			extent[1] = -currHeight;
  23.243 +		}
  23.244 +		if (currWidth <= newWidth)
  23.245 +		{
  23.246 +			extent[2] = newWidth;
  23.247 +		} else
  23.248 +		{
  23.249 +			extent[2] = currWidth;
  23.250 +		}
  23.251 +		extent[3] = 0;
  23.252 +		
  23.253 +		regs.r[0] = this->hidden->window_handle;
  23.254 +		regs.r[1] = (int)extent;
  23.255 +		_kernel_swi(Wimp_SetExtent, &regs, &regs);
  23.256 +
  23.257 +		/*TODO: May need to set flag to resize window on next open */
  23.258 +	}
  23.259 +}
  23.260 +
  23.261 +/* Palette has changed so update palettes used for windows sprites */
  23.262 +
  23.263 +void WIMP_PaletteChanged(_THIS)
  23.264 +{
  23.265 +	WIMP_SetupPlotInfo(this);
  23.266 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/video/riscos/SDL_riscostask.c	Thu May 29 04:44:13 2003 +0000
    24.3 @@ -0,0 +1,356 @@
    24.4 +/*
    24.5 +    SDL - Simple DirectMedia Layer
    24.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    24.7 +
    24.8 +    This library is free software; you can redistribute it and/or
    24.9 +    modify it under the terms of the GNU Library General Public
   24.10 +    License as published by the Free Software Foundation; either
   24.11 +    version 2 of the License, or (at your option) any later version.
   24.12 +
   24.13 +    This library is distributed in the hope that it will be useful,
   24.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   24.16 +    Library General Public License for more details.
   24.17 +
   24.18 +    You should have received a copy of the GNU Library General Public
   24.19 +    License along with this library; if not, write to the Free
   24.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.21 +
   24.22 +    Sam Lantinga
   24.23 +    slouken@devolution.com
   24.24 +*/
   24.25 +
   24.26 +/*
   24.27 +    This file added by Alan Buckley (alan_baa@hotmail.com) to support RISCOS 
   24.28 +	26 March 2003
   24.29 +
   24.30 +	File includes routines for:
   24.31 +	  Setting up as a WIMP Task
   24.32 +	  Reading information about the current desktop
   24.33 +	  Storing information before a switch to full screen
   24.34 +	  Restoring desktop after switching to full screen
   24.35 +*/
   24.36 +
   24.37 +#include <stdlib.h>
   24.38 +#include <string.h>
   24.39 +
   24.40 +#include "kernel.h"
   24.41 +#include "swis.h"
   24.42 +
   24.43 +#include "SDL_riscostask.h"
   24.44 +
   24.45 +/* RISCOS variables */
   24.46 +
   24.47 +static int task_handle = 0;
   24.48 +static int wimp_version = 0;
   24.49 +
   24.50 +/* RISC OS variables to help compatability with certain programs */
   24.51 +int riscos_backbuffer = 0; /* Create a back buffer in system memory for full screen mode */
   24.52 +int riscos_closeaction = 1; /* Close icon action */
   24.53 +int riscos_audiobuffer = 0; /* Audio buffer size */
   24.54 +
   24.55 +static int stored_mode = -1; /* -1 when in desktop, mode number or pointer when full screen */
   24.56 +
   24.57 +extern int mouseInWindow; /* Mouse is in WIMP window */
   24.58 +
   24.59 +/* Local function */
   24.60 +
   24.61 +static int RISCOS_GetTaskName(char *task_name);
   24.62 +
   24.63 +/* Uncomment next line to copy mode changes/restores to stderr */
   24.64 +/* #define DUMP_MODE */
   24.65 +#ifdef DUMP_MODE
   24.66 +#include "stdio.h"
   24.67 +static void dump_mode()
   24.68 +{
   24.69 +    fprintf(stderr, "mode %d\n", stored_mode);
   24.70 +    if (stored_mode < -1 || stored_mode >= 256)
   24.71 +    {
   24.72 +        int blockSize = 0;
   24.73 +		int *storeBlock = (int *)stored_mode;
   24.74 +
   24.75 +        while(blockSize < 5 || storeBlock[blockSize] != -1)
   24.76 +        {
   24.77 +           fprintf(stderr, "   %d\n", storeBlock[blockSize++]);
   24.78 +        }
   24.79 +    }
   24.80 +}
   24.81 +#endif
   24.82 +
   24.83 +/******************************************************************
   24.84 +
   24.85 + Initialise as RISCOS Wimp task
   24.86 +
   24.87 +*******************************************************************/
   24.88 +
   24.89 +int RISCOS_InitTask()
   24.90 +{
   24.91 +   char task_name[32];
   24.92 +   _kernel_swi_regs regs;
   24.93 +   int messages[4];
   24.94 +
   24.95 +   if (RISCOS_GetTaskName(task_name) == 0) return 0;
   24.96 +
   24.97 +   messages[0] = 9;       /* Palette changed */
   24.98 +   messages[1] = 0x400c1; /* Mode changed */
   24.99 +   messages[2] = 8;       /* Pre quit */
  24.100 +   messages[2] = 0;
  24.101 +   
  24.102 +	regs.r[0] = (unsigned int)360; /* Minimum version 3.6 */
  24.103 +	regs.r[1] = (unsigned int)0x4b534154;
  24.104 +	regs.r[2] = (unsigned int)task_name;
  24.105 +	regs.r[3] = (unsigned int)messages;
  24.106 +
  24.107 +   if (_kernel_swi(Wimp_Initialise, &regs, &regs) == 0)
  24.108 +   {
  24.109 +	   wimp_version = regs.r[0];
  24.110 +	   task_handle = regs.r[1];
  24.111 +	   return 1;
  24.112 +   }
  24.113 +
  24.114 +   return 0;
  24.115 +}
  24.116 +
  24.117 +/*********************************************************************
  24.118 +
  24.119 +  Close down application on exit.
  24.120 +
  24.121 +**********************************************************************/
  24.122 +
  24.123 +void RISCOS_ExitTask()
  24.124 +{
  24.125 +	_kernel_swi_regs regs;
  24.126 +
  24.127 +    if (stored_mode == -1)
  24.128 +    {
  24.129 +       /* Ensure cursor is put back to standard pointer shape if
  24.130 +          we have been running in a window */
  24.131 +       _kernel_osbyte(106,1,0);
  24.132 +    }
  24.133 +
  24.134 +	/* Ensure we end up back in the wimp */
  24.135 +	RISCOS_RestoreWimpMode();
  24.136 +
  24.137 +	/* Neatly exit the task */
  24.138 +   	regs.r[0] = task_handle;
  24.139 +   	regs.r[1] = (unsigned int)0x4b534154;
  24.140 +   	_kernel_swi(Wimp_CloseDown, &regs, &regs);
  24.141 +	task_handle = 0;
  24.142 +}
  24.143 +
  24.144 +/**************************************************************************
  24.145 +
  24.146 +  Get the name of the task for the desktop.
  24.147 +
  24.148 +  Param:   task_name - name of task 32 characters.
  24.149 +
  24.150 +  Returns: 1 is successful, otherwise 0
  24.151 +
  24.152 +  Notes:   Works by getting using OS_GetEnv to get the command line
  24.153 +		   used to run the program and then parsing a name from it
  24.154 +		   as follows.
  24.155 +
  24.156 +		   1. Use name after final period if not !RunImage
  24.157 +		   2. If name is !RunImage then process item before the period
  24.158 +		      in front of !RunImage.
  24.159 +		   3. If directory name use that
  24.160 +		   4. if in form <XXX$Dir> use the XXX.
  24.161 +
  24.162 +		   Finally once this value has been retrieved use it unless
  24.163 +		   there is a variable set up in the form SDL$<name>$TaskName
  24.164 +		   in which case the value of this variable will be used.
  24.165 +
  24.166 +		   Now also gets other riscos configuration varibles
  24.167 +                SDL$<name>$BackBuffer - set to 1 to use a system memory backbuffer in fullscreen mode
  24.168 +						    so updates wait until a call to SDL_UpdateRects. (default 0)
  24.169 +						    This is required for programmes where they have assumed this is
  24.170 +						    always the case which is contrary to the documentation.
  24.171 +               SDL$<name>$CloseAction
  24.172 +                    0 Don't show close icon
  24.173 +                    1 Show close icon
  24.174 +
  24.175 +               SDL$<name>$AudioBuffer - set to number of samples to buffer
  24.176 +                    in advance. Will default to a minimum of 1024 or twice
  24.177 +                    amount requested by program whichever is largest.
  24.178 +                    If not specified default is amount for 10 csecs.
  24.179 +                    Time that will be pre-buffered can be calculated as
  24.180 +                    sample to buffer * 1000 / freq milliseconds.
  24.181 +                    
  24.182 +***************************************************************************/
  24.183 +
  24.184 +int RISCOS_GetTaskName(char *task_name)
  24.185 +{
  24.186 +	_kernel_swi_regs regs;
  24.187 +
  24.188 +   task_name[0] = 0;
  24.189 +
  24.190 +   /* Figure out a sensible task name */
  24.191 +   if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0)
  24.192 +   {
  24.193 +	   char *command_line = (char *)regs.r[0];
  24.194 +	   char *buffer = malloc(strlen(command_line)+1);
  24.195 +	   char *env_var;
  24.196 +	   char *p;
  24.197 +
  24.198 +	   strcpy(buffer, command_line);
  24.199 +	   p = strchr(buffer, ' ');
  24.200 +	   if (p) *p = 0;
  24.201 +	   p = strrchr(buffer, '.');
  24.202 +	   if (p == 0) p = buffer;
  24.203 +	   if (stricmp(p+1,"!RunImage") == 0)
  24.204 +	   {
  24.205 +		   *p = 0;
  24.206 +	   	   p = strrchr(buffer, '.');
  24.207 +		   if (p == 0) p = buffer;
  24.208 +	   }
  24.209 +	   if (*p == '.') p++;
  24.210 +	   if (*p == '!') p++; /* Skip "!" at beginning of application directories */
  24.211 +
  24.212 +       if (*p == '<')
  24.213 +       {
  24.214 +          // Probably in the form <appname$Dir>
  24.215 +          char *q = strchr(p, '$');
  24.216 +          if (q == 0) q = strchr(p,'>'); /* Use variable name if not */
  24.217 +          if (q) *q = 0;
  24.218 +          p++; /* Move over the < */
  24.219 +       }
  24.220 +
  24.221 +	   if (*p)
  24.222 +	   {
  24.223 +		   /* Read variables that effect the RISCOS SDL engine for this task */
  24.224 +		   env_var = malloc(strlen(p) + 18); /* 18 is larger than the biggest variable name */
  24.225 +		   if (env_var)
  24.226 +		   {
  24.227 +			   char *env_val;
  24.228 +
  24.229 +			   /* See if a variable of form SDL$<dirname>$TaskName exists */
  24.230 +
  24.231 +			   strcpy(env_var, "SDL$");
  24.232 +			   strcat(env_var, p);
  24.233 +			   strcat(env_var, "$TaskName");
  24.234 +
  24.235 +			   env_val = getenv(env_var);
  24.236 +			   if (env_val) strncpy(task_name, env_val, 31);
  24.237 +
  24.238 +			   strcpy(env_var, "SDL$");
  24.239 +			   strcat(env_var, p);
  24.240 +			   strcat(env_var, "$BackBuffer");
  24.241 +
  24.242 +			   env_val = getenv(env_var);
  24.243 +			   if (env_val && strcmp(env_val,"1") == 0) riscos_backbuffer = 1;
  24.244 +
  24.245 +			   strcpy(env_var, "SDL$");
  24.246 +			   strcat(env_var, p);
  24.247 +			   strcat(env_var, "$CloseAction");
  24.248 +
  24.249 +			   env_val = getenv(env_var);
  24.250 +			   if (env_val && strcmp(env_val,"0") == 0) riscos_closeaction = 0;
  24.251 +
  24.252 +			   strcpy(env_var, "SDL$");
  24.253 +			   strcat(env_var, p);
  24.254 +			   strcat(env_var, "$AudioBuffer");
  24.255 +
  24.256 +			   env_val = getenv(env_var);
  24.257 +			   riscos_audiobuffer = atoi(env_val);
  24.258 +
  24.259 +			   free(env_var);
  24.260 +		   }
  24.261 +		   
  24.262 +		   if (task_name[0] == 0) strncpy(task_name, p, 31);
  24.263 +		   task_name[31] = 0;
  24.264 +	   }
  24.265 +
  24.266 +	   free(buffer);
  24.267 +   }
  24.268 +
  24.269 +   if (task_name[0] == 0) strcpy(task_name, "SDL Task");
  24.270 +
  24.271 +   return 1;
  24.272 +}
  24.273 +
  24.274 +/*****************************************************************
  24.275 +
  24.276 +  Store the current desktop screen mode if we are in the desktop.
  24.277 +
  24.278 +******************************************************************/
  24.279 +
  24.280 +void RISCOS_StoreWimpMode()
  24.281 +{
  24.282 +     _kernel_swi_regs regs;
  24.283 +
  24.284 +	/* Don't store if in full screen mode */
  24.285 +	if (stored_mode != -1) return;
  24.286 +
  24.287 +    regs.r[0] = 1;
  24.288 +    _kernel_swi(OS_ScreenMode, &regs, &regs);
  24.289 +    if (regs.r[1] >= 0 && regs.r[1] < 256) stored_mode = regs.r[1];
  24.290 +    else
  24.291 +    {
  24.292 +        int blockSize = 0;
  24.293 +        int *retBlock = (int *)regs.r[1];
  24.294 +		int *storeBlock;
  24.295 +        int j;
  24.296 +
  24.297 +        while(blockSize < 5 || retBlock[blockSize] != -1) blockSize++;
  24.298 +        blockSize++;
  24.299 +        storeBlock = (int *)malloc(blockSize * sizeof(int));
  24.300 +        retBlock = (int *)regs.r[1];
  24.301 +        for ( j = 0; j < blockSize; j++)
  24.302 +           storeBlock[j] = retBlock[j];
  24.303 +
  24.304 +		stored_mode = (int)storeBlock;
  24.305 +     }
  24.306 +#if DUMP_MODE
  24.307 +    fprintf(stderr, "Stored "); dump_mode();
  24.308 +#endif
  24.309 +}
  24.310 +
  24.311 +/*****************************************************************
  24.312 +
  24.313 +  Restore desktop screen mode if we are in full screen mode.
  24.314 +
  24.315 +*****************************************************************/
  24.316 +
  24.317 +void RISCOS_RestoreWimpMode()
  24.318 +{
  24.319 +    _kernel_swi_regs regs;
  24.320 +
  24.321 +	/* Only need to restore if we are in full screen mode */
  24.322 +	if (stored_mode == -1) return;
  24.323 +
  24.324 +#if DUMP_MODE
  24.325 +   fprintf(stderr, "Restored"); dump_mode();
  24.326 +#endif
  24.327 +
  24.328 +    regs.r[0] = stored_mode;
  24.329 +    _kernel_swi(Wimp_SetMode, &regs, &regs);
  24.330 +    if (stored_mode < 0 || stored_mode > 256)
  24.331 +    {
  24.332 +       free((int *)stored_mode);
  24.333 +    }
  24.334 +    stored_mode = -1;
  24.335 +
  24.336 +    /* Flush keyboard buffer to dump the keystrokes we've already polled */
  24.337 +    regs.r[0] = 21;
  24.338 +    regs.r[1] = 0; /* Keyboard buffer number */
  24.339 +    _kernel_swi(OS_Byte, &regs, &regs);
  24.340 +
  24.341 +    mouseInWindow = 0;
  24.342 +
  24.343 +}
  24.344 +
  24.345 +/*********************************************************************
  24.346 +
  24.347 +  Get version of Wimp running when task was initialised.
  24.348 +
  24.349 +*********************************************************************/
  24.350 +
  24.351 +int RISCOS_GetWimpVersion()
  24.352 +{
  24.353 +	return wimp_version;
  24.354 +}
  24.355 +
  24.356 +int RISCOS_GetTaskHandle()
  24.357 +{
  24.358 +	return task_handle;
  24.359 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/video/riscos/SDL_riscostask.h	Thu May 29 04:44:13 2003 +0000
    25.3 @@ -0,0 +1,38 @@
    25.4 +/*
    25.5 +    SDL - Simple DirectMedia Layer
    25.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    25.7 +
    25.8 +    This library is free software; you can redistribute it and/or
    25.9 +    modify it under the terms of the GNU Library General Public
   25.10 +    License as published by the Free Software Foundation; either
   25.11 +    version 2 of the License, or (at your option) any later version.
   25.12 +
   25.13 +    This library is distributed in the hope that it will be useful,
   25.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   25.16 +    Library General Public License for more details.
   25.17 +
   25.18 +    You should have received a copy of the GNU Library General Public
   25.19 +    License along with this library; if not, write to the Free
   25.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.21 +
   25.22 +    Sam Lantinga
   25.23 +    slouken@devolution.com
   25.24 +*/
   25.25 +
   25.26 +/*
   25.27 +    This file added by Alan Buckley (alan_baa@hotmail.com) to support RISCOS 
   25.28 +	26 March 2003
   25.29 +*/
   25.30 +
   25.31 +/* Task initialisation/Clean up */
   25.32 +
   25.33 +extern int RISCOS_InitTask();
   25.34 +extern void RISCOS_ExitTask();
   25.35 +extern int RISCOS_GetWimpVersion();
   25.36 +extern int RISCOS_GetTaskHandle();
   25.37 +
   25.38 +
   25.39 +/* Wimp mode saveing/restoring */
   25.40 +extern void RISCOS_StoreWimpMode();
   25.41 +extern void RISCOS_RestoreWimpMode();
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/video/riscos/SDL_riscosvideo.c	Thu May 29 04:44:13 2003 +0000
    26.3 @@ -0,0 +1,312 @@
    26.4 +/*
    26.5 +    SDL - Simple DirectMedia Layer
    26.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    26.7 +
    26.8 +    This library is free software; you can redistribute it and/or
    26.9 +    modify it under the terms of the GNU Library General Public
   26.10 +    License as published by the Free Software Foundation; either
   26.11 +    version 2 of the License, or (at your option) any later version.
   26.12 +
   26.13 +    This library is distributed in the hope that it will be useful,
   26.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   26.16 +    Library General Public License for more details.
   26.17 +
   26.18 +    You should have received a copy of the GNU Library General Public
   26.19 +    License along with this library; if not, write to the Free
   26.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.21 +
   26.22 +    Sam Lantinga
   26.23 +    slouken@devolution.com
   26.24 +*/
   26.25 +
   26.26 +/*
   26.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   26.28 +	 23 March 2003
   26.29 +
   26.30 +     Implements RISCOS display device management.
   26.31 +	 Routines for full screen and wimp modes are split
   26.32 +	 into other source files.
   26.33 +*/
   26.34 +
   26.35 +#include <stdio.h>
   26.36 +#include <stdlib.h>
   26.37 +#include <string.h>
   26.38 +
   26.39 +#include "SDL.h"
   26.40 +#include "SDL_syswm.h"
   26.41 +#include "SDL_error.h"
   26.42 +#include "SDL_video.h"
   26.43 +#include "SDL_mouse.h"
   26.44 +#include "SDL_sysvideo.h"
   26.45 +#include "SDL_pixels_c.h"
   26.46 +#include "SDL_events_c.h"
   26.47 +
   26.48 +#include "SDL_riscostask.h"
   26.49 +#include "SDL_riscosvideo.h"
   26.50 +#include "SDL_riscosevents_c.h"
   26.51 +#include "SDL_riscosmouse_c.h"
   26.52 +
   26.53 +#include "kernel.h"
   26.54 +#include "swis.h"
   26.55 +
   26.56 +#define RISCOSVID_DRIVER_NAME "riscos"
   26.57 +
   26.58 +/* Initialization/Query functions */
   26.59 +static int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
   26.60 +static void RISCOS_VideoQuit(_THIS);
   26.61 +
   26.62 +static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   26.63 +static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   26.64 +
   26.65 +int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info);
   26.66 +
   26.67 +int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
   26.68 +/* Mouse checking */
   26.69 +void RISCOS_CheckMouseMode(_THIS);
   26.70 +extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
   26.71 +
   26.72 +/* Fullscreen mode functions */
   26.73 +extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   26.74 +extern void FULLSCREEN_BuildModeList(_THIS);
   26.75 +extern void	FULLSCREEN_SetDeviceMode(_THIS);
   26.76 +extern int FULLSCREEN_ToggleFromWimp(_THIS);
   26.77 +
   26.78 +/* Wimp mode functions */
   26.79 +extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current,	int width, int height, int bpp, Uint32 flags);
   26.80 +extern void WIMP_DeleteWindow(_THIS);
   26.81 +extern int WIMP_ToggleFromFullScreen(_THIS);
   26.82 +
   26.83 +/* Hardware surface functions - common to WIMP and FULLSCREEN */
   26.84 +static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface);
   26.85 +static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface);
   26.86 +static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
   26.87 +static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface);
   26.88 +
   26.89 +/* RISCOS driver bootstrap functions */
   26.90 +
   26.91 +static int RISCOS_Available(void)
   26.92 +{
   26.93 +	return(1);
   26.94 +}
   26.95 +
   26.96 +static void RISCOS_DeleteDevice(SDL_VideoDevice *device)
   26.97 +{
   26.98 +	free(device->hidden);
   26.99 +	free(device);
  26.100 +}
  26.101 +
  26.102 +static SDL_VideoDevice *RISCOS_CreateDevice(int devindex)
  26.103 +{
  26.104 +	SDL_VideoDevice *device;
  26.105 +
  26.106 +	/* Initialize all variables that we clean on shutdown */
  26.107 +	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
  26.108 +	if ( device ) {
  26.109 +		memset(device, 0, (sizeof *device));
  26.110 +		device->hidden = (struct SDL_PrivateVideoData *)
  26.111 +				malloc((sizeof *device->hidden));
  26.112 +	}
  26.113 +	if ( (device == NULL) || (device->hidden == NULL) ) {
  26.114 +		SDL_OutOfMemory();
  26.115 +		if ( device ) {
  26.116 +			free(device);
  26.117 +		}
  26.118 +		return(0);
  26.119 +	}
  26.120 +	memset(device->hidden, 0, (sizeof *device->hidden));
  26.121 +
  26.122 +	/* Set the function pointers */
  26.123 +	device->VideoInit = RISCOS_VideoInit;
  26.124 +	device->VideoQuit = RISCOS_VideoQuit;
  26.125 +
  26.126 +	device->ListModes = RISCOS_ListModes;
  26.127 +	device->SetVideoMode = RISCOS_SetVideoMode;
  26.128 +	device->CreateYUVOverlay = NULL;
  26.129 +	device->AllocHWSurface = RISCOS_AllocHWSurface;
  26.130 +	device->CheckHWBlit = NULL;
  26.131 +	device->FillHWRect = NULL;
  26.132 +	device->SetHWColorKey = NULL;
  26.133 +	device->SetHWAlpha = NULL;
  26.134 +	device->LockHWSurface = RISCOS_LockHWSurface;
  26.135 +	device->UnlockHWSurface = RISCOS_UnlockHWSurface;
  26.136 +	device->FreeHWSurface = RISCOS_FreeHWSurface;
  26.137 +	
  26.138 +	device->FreeWMCursor = RISCOS_FreeWMCursor;
  26.139 +	device->CreateWMCursor = RISCOS_CreateWMCursor;
  26.140 +	device->CheckMouseMode = RISCOS_CheckMouseMode;
  26.141 +    device->GrabInput = RISCOS_GrabInput;
  26.142 +
  26.143 +	device->InitOSKeymap = RISCOS_InitOSKeymap;
  26.144 +
  26.145 +	device->GetWMInfo = RISCOS_GetWmInfo;
  26.146 +
  26.147 +	device->free = RISCOS_DeleteDevice;
  26.148 +
  26.149 +/* Can't get Toggle screen to work if program starts up in Full screen mode so
  26.150 +   disable it here and re-enable it when a wimp screen is chosen */
  26.151 +    device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/
  26.152 +
  26.153 +	/* Set other entries for fullscreen mode */
  26.154 +	FULLSCREEN_SetDeviceMode(device);
  26.155 +
  26.156 +/* Turn off unixlib file name translation - we hope people have initialised
  26.157 +   the video system before they try to read any files */
  26.158 +/*        __riscosify_control = __RISCOSIFY_NO_PROCESS;
  26.159 +*//* We may be able to eventually replace our processing of filenames with the correct flags above*/
  26.160 +
  26.161 +	return device;
  26.162 +}
  26.163 +
  26.164 +VideoBootStrap RISCOS_bootstrap = {
  26.165 +	RISCOSVID_DRIVER_NAME, "RISCOS video driver",
  26.166 +	RISCOS_Available, RISCOS_CreateDevice
  26.167 +};
  26.168 +
  26.169 +
  26.170 +int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
  26.171 +{
  26.172 +	_kernel_swi_regs regs;
  26.173 +
  26.174 +	if (RISCOS_InitTask() == 0)
  26.175 +	{
  26.176 +		SDL_SetError("Unable to start task");
  26.177 +		return 0;
  26.178 +	}
  26.179 +
  26.180 +	regs.r[0] = -1; /* Current mode */
  26.181 +	regs.r[1] = 9;  /* Log base 2 bpp */
  26.182 +
  26.183 +	_kernel_swi(OS_ReadVduVariables, &regs, &regs);
  26.184 +	vformat->BitsPerPixel = (1 << regs.r[0]);
  26.185 +
  26.186 +	/* Minimum bpp for SDL is 8 */
  26.187 +	if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8;
  26.188 +
  26.189 +
  26.190 +	switch (vformat->BitsPerPixel)
  26.191 +	{
  26.192 +		case 15:
  26.193 +		case 16:
  26.194 +			vformat->Bmask = 0x00007c00;
  26.195 +			vformat->Gmask = 0x000003e0;
  26.196 +			vformat->Rmask = 0x0000001f;
  26.197 +			vformat->BitsPerPixel = 15; /* SDL wants actual number of bits used */
  26.198 +			vformat->BytesPerPixel = 2;
  26.199 +			break;
  26.200 +
  26.201 +		case 24:
  26.202 +		case 32:
  26.203 +			vformat->Bmask = 0x00ff0000;
  26.204 +			vformat->Gmask = 0x0000ff00;
  26.205 +			vformat->Rmask = 0x000000ff;
  26.206 +			vformat->BytesPerPixel = 4;
  26.207 +			break;
  26.208 +
  26.209 +		default:
  26.210 +			vformat->Bmask = 0;
  26.211 +			vformat->Gmask = 0;
  26.212 +			vformat->Rmask = 0;
  26.213 +			vformat->BytesPerPixel = 1;			
  26.214 +			break;
  26.215 +	}
  26.216 +
  26.217 +	/* Fill in some window manager capabilities */
  26.218 +	this->info.wm_available = 1;
  26.219 +
  26.220 +	/* We're done! */
  26.221 +	return(0);
  26.222 +}
  26.223 +
  26.224 +/* Note:  If we are terminated, this could be called in the middle of
  26.225 +   another SDL video routine -- notably UpdateRects.
  26.226 +*/
  26.227 +void RISCOS_VideoQuit(_THIS)
  26.228 +{
  26.229 +	RISCOS_ExitTask();
  26.230 +
  26.231 +	if (this->hidden->alloc_bank) free(this->hidden->alloc_bank);
  26.232 +	this->hidden->alloc_bank = 0;
  26.233 +}
  26.234 +
  26.235 +
  26.236 +SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
  26.237 +{
  26.238 +	if (flags & SDL_FULLSCREEN)
  26.239 +	{
  26.240 +		/* Build mode list when first required. */
  26.241 +		if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this);
  26.242 +
  26.243 +		return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
  26.244 +	} else
  26.245 +		return (SDL_Rect **)-1;
  26.246 +}
  26.247 +
  26.248 +
  26.249 +/* Set up video mode */
  26.250 +SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
  26.251 +				int width, int height, int bpp, Uint32 flags)
  26.252 +{
  26.253 +	if (flags & SDL_FULLSCREEN)
  26.254 +	{
  26.255 +	    RISCOS_StoreWimpMode();
  26.256 +		/* Dump wimp window on switch to full screen */
  26.257 +  	    if (this->hidden->window_handle) WIMP_DeleteWindow(this);
  26.258 +
  26.259 +		return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
  26.260 +	} else
  26.261 +	{
  26.262 +	    RISCOS_RestoreWimpMode();
  26.263 +		return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
  26.264 +	}
  26.265 +}
  26.266 +
  26.267 +
  26.268 +/* We don't actually allow hardware surfaces other than the main one */
  26.269 +static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface)
  26.270 +{
  26.271 +	return(-1);
  26.272 +}
  26.273 +static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface)
  26.274 +{
  26.275 +	return;
  26.276 +}
  26.277 +
  26.278 +/* We need to wait for vertical retrace on page flipped displays */
  26.279 +static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface)
  26.280 +{
  26.281 +	return(0);
  26.282 +}
  26.283 +
  26.284 +static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
  26.285 +{
  26.286 +	return;
  26.287 +}
  26.288 +
  26.289 +
  26.290 +int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info)
  26.291 +{
  26.292 +	SDL_VERSION(&(info->version));
  26.293 +	info->wimpVersion = RISCOS_GetWimpVersion();
  26.294 +	info->taskHandle = RISCOS_GetTaskHandle();
  26.295 +	info->window = this->hidden->window_handle;
  26.296 +
  26.297 +	return 1;
  26.298 +}
  26.299 +/* Toggle full screen mode.
  26.300 +   Returns 1 if successful otherwise 0
  26.301 +*/
  26.302 +
  26.303 +int RISCOS_ToggleFullScreen(_THIS, int fullscreen)
  26.304 +{
  26.305 +    if (fullscreen)
  26.306 +    {
  26.307 +       return FULLSCREEN_ToggleFromWimp(this);
  26.308 +    } else
  26.309 +    {
  26.310 +       return WIMP_ToggleFromFullScreen(this);
  26.311 +    }
  26.312 +
  26.313 +   return 0;
  26.314 +}
  26.315 +
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/video/riscos/SDL_riscosvideo.h	Thu May 29 04:44:13 2003 +0000
    27.3 @@ -0,0 +1,66 @@
    27.4 +/*
    27.5 +    SDL - Simple DirectMedia Layer
    27.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    27.7 +
    27.8 +    This library is free software; you can redistribute it and/or
    27.9 +    modify it under the terms of the GNU Library General Public
   27.10 +    License as published by the Free Software Foundation; either
   27.11 +    version 2 of the License, or (at your option) any later version.
   27.12 +
   27.13 +    This library is distributed in the hope that it will be useful,
   27.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27.16 +    Library General Public License for more details.
   27.17 +
   27.18 +    You should have received a copy of the GNU Library General Public
   27.19 +    License along with this library; if not, write to the Free
   27.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.21 +
   27.22 +    Sam Lantinga
   27.23 +    slouken@devolution.com
   27.24 +*/
   27.25 +
   27.26 +#ifdef SAVE_RCSID
   27.27 +static char rcsid =
   27.28 + "@(#) $Id$";
   27.29 +#endif
   27.30 +
   27.31 +#ifndef _SDL_riscosvideo_h
   27.32 +#define _SDL_riscosvideo_h
   27.33 +
   27.34 +#include "SDL_mouse.h"
   27.35 +#include "SDL_sysvideo.h"
   27.36 +#include "SDL_mutex.h"
   27.37 +
   27.38 +/* Hidden "this" pointer for the video functions */
   27.39 +#define _THIS	SDL_VideoDevice *this
   27.40 +
   27.41 +
   27.42 +/* Private display data */
   27.43 +
   27.44 +struct SDL_PrivateVideoData {
   27.45 +    unsigned char *bank[2];
   27.46 +    int current_bank;
   27.47 +	unsigned char *alloc_bank;
   27.48 +    int height;
   27.49 +    int xeig;
   27.50 +    int yeig;
   27.51 +	int screen_bpp;
   27.52 +	int screen_width;
   27.53 +	int screen_height;
   27.54 +	char *pixtrans;
   27.55 +
   27.56 +	/* Wimp variables */
   27.57 +	unsigned int window_handle;
   27.58 +	char title[256];
   27.59 +
   27.60 +#define NUM_MODELISTS	4		/* 8, 16, 24, and 32 bits-per-pixel */
   27.61 +    int SDL_nummodes[NUM_MODELISTS];
   27.62 +    SDL_Rect **SDL_modelist[NUM_MODELISTS];
   27.63 +};
   27.64 +
   27.65 +/* Old variable names */
   27.66 +#define SDL_nummodes		(this->hidden->SDL_nummodes)
   27.67 +#define SDL_modelist		(this->hidden->SDL_modelist)
   27.68 +
   27.69 +#endif /* _SDL_risosvideo_h */
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/video/riscos/SDL_wimppoll.c	Thu May 29 04:44:13 2003 +0000
    28.3 @@ -0,0 +1,309 @@
    28.4 +/*
    28.5 +    SDL - Simple DirectMedia Layer
    28.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    28.7 +
    28.8 +    This library is free software; you can redistribute it and/or
    28.9 +    modify it under the terms of the GNU Library General Public
   28.10 +    License as published by the Free Software Foundation; either
   28.11 +    version 2 of the License, or (at your option) any later version.
   28.12 +
   28.13 +    This library is distributed in the hope that it will be useful,
   28.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   28.16 +    Library General Public License for more details.
   28.17 +
   28.18 +    You should have received a copy of the GNU Library General Public
   28.19 +    License along with this library; if not, write to the Free
   28.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.21 +
   28.22 +    Sam Lantinga
   28.23 +    slouken@devolution.com
   28.24 +*/
   28.25 +
   28.26 +/*
   28.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   28.28 +	 27 March 2003
   28.29 +
   28.30 +     Implements Pumping of events and WIMP polling
   28.31 +*/
   28.32 +
   28.33 +#include "SDL.h"
   28.34 +#include "SDL_syswm.h"
   28.35 +#include "SDL_sysevents.h"
   28.36 +#include "SDL_events_c.h"
   28.37 +#include "SDL_riscosvideo.h"
   28.38 +#include "SDL_riscosevents_c.h"
   28.39 +#include "SDL_timer_c.h"
   28.40 +
   28.41 +#include "memory.h"
   28.42 +#include "stdlib.h"
   28.43 +#include "ctype.h"
   28.44 +
   28.45 +#include "kernel.h"
   28.46 +#include "swis.h"
   28.47 +#include "unixlib/os.h"
   28.48 +
   28.49 +/* Local functions */
   28.50 +void WIMP_Poll(_THIS, int waitTime);
   28.51 +void WIMP_SetFocus(int win);
   28.52 +
   28.53 +/* SDL_riscossprite functions */
   28.54 +void WIMP_PlotSprite(_THIS, int x, int y);
   28.55 +void WIMP_ModeChanged(_THIS);
   28.56 +void WIMP_PaletteChanged(_THIS);
   28.57 +
   28.58 +
   28.59 +extern void WIMP_PollMouse(_THIS);
   28.60 +extern void RISCOS_PollKeyboard();
   28.61 +
   28.62 +extern void DRenderer_FillBuffers();
   28.63 +
   28.64 +/* Timer running function */
   28.65 +extern void RISCOS_CheckTimer();
   28.66 +
   28.67 +/* Mouse cursor handling */
   28.68 +extern void WIMP_ReshowCursor(_THIS);
   28.69 +
   28.70 +int hasFocus = 0;
   28.71 +int mouseInWindow = 0;
   28.72 + 
   28.73 +/* Flag to ensure window is correct size after a mode change */
   28.74 +static int resizeOnOpen = 0;
   28.75 +
   28.76 +void WIMP_PumpEvents(_THIS)
   28.77 +{
   28.78 +	WIMP_Poll(this, 0);
   28.79 +	if (hasFocus) RISCOS_PollKeyboard();
   28.80 +	if (mouseInWindow) WIMP_PollMouse(this);
   28.81 +	DRenderer_FillBuffers();
   28.82 +	if (SDL_timer_running) RISCOS_CheckTimer();
   28.83 +}
   28.84 +
   28.85 +
   28.86 +void WIMP_Poll(_THIS, int waitTime)
   28.87 +{
   28.88 +	_kernel_swi_regs regs;
   28.89 +	int message[64];
   28.90 +	unsigned int code;
   28.91 +	int pollMask = 0;
   28.92 +	int doPoll = 1;
   28.93 +	int sysEvent;
   28.94 +	int sdlWindow = this->hidden->window_handle;
   28.95 +
   28.96 +    if (this->PumpEvents != WIMP_PumpEvents) return;
   28.97 +
   28.98 +    if (waitTime > 0)
   28.99 +    {
  28.100 +		_kernel_swi(OS_ReadMonotonicTime, &regs, &regs);
  28.101 +		waitTime += regs.r[0];
  28.102 +    }
  28.103 +
  28.104 +    while (doPoll)
  28.105 +    {
  28.106 +        if (waitTime <= 0)
  28.107 +        {
  28.108 +        	regs.r[0] = pollMask; /* Poll Mask */
  28.109 +        	 /* For no wait time mask out null event so we wait until something happens */
  28.110 +        	if (waitTime < 0) regs.r[0] |= 1;
  28.111 +        	regs.r[1] = (int)message;
  28.112 +        	_kernel_swi(Wimp_Poll, &regs, &regs);
  28.113 +        } else
  28.114 +        {
  28.115 +        	regs.r[0] = pollMask;
  28.116 +        	regs.r[1] = (int)message;
  28.117 +        	regs.r[2] = waitTime;
  28.118 +        	_kernel_swi(Wimp_PollIdle, &regs, &regs);
  28.119 +        }
  28.120 +
  28.121 +		/* Flag to specify if we post a SDL_SysWMEvent */
  28.122 +		sysEvent = 0;
  28.123 +        
  28.124 +        code = (unsigned int)regs.r[0];
  28.125 +
  28.126 +		switch(code)
  28.127 +		{
  28.128 +		case 0:  /* Null Event - drop out for standard processing*/
  28.129 +		   doPoll = 0;
  28.130 +		   break;
  28.131 +
  28.132 +		case 1:     /* Redraw window */
  28.133 +        	_kernel_swi(Wimp_RedrawWindow, &regs,&regs);
  28.134 +			if (message[0] == sdlWindow)
  28.135 +			{
  28.136 +        		while (regs.r[0])
  28.137 +        		{
  28.138 +        			WIMP_PlotSprite(this, message[1], message[2]);
  28.139 +        			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
  28.140 +        		}
  28.141 +			} else
  28.142 +			{
  28.143 +				/* TODO: Currently we just eat them - we may need to pass them on */
  28.144 +        		while (regs.r[0])
  28.145 +        		{
  28.146 +        			_kernel_swi(Wimp_GetRectangle, &regs, &regs);
  28.147 +        		}
  28.148 +			}
  28.149 +        	break;
  28.150 +        	
  28.151 +		case 2:		/* Open window */
  28.152 +		   if ( resizeOnOpen && message[0] == sdlWindow)
  28.153 +		   {
  28.154 +		      /* Ensure window is correct size */
  28.155 +		      resizeOnOpen = 0;
  28.156 +		      message[3] = message[1] + (this->screen->w << this->hidden->xeig);
  28.157 +		      message[4] = message[2] + (this->screen->h << this->hidden->yeig);       
  28.158 +		   }
  28.159 +        	_kernel_swi(Wimp_OpenWindow, &regs, &regs);
  28.160 +       	    break;
  28.161 +        	
  28.162 +		case 3:		/* Close window */
  28.163 +			if (message[0] == sdlWindow)
  28.164 +			{
  28.165 +				/* Documentation makes it looks as if the following line is correct:
  28.166 +				**    if (SDL_PrivateQuit() == 1) _kernel_swi(Wimp_CloseWindow, &regs, &regs);
  28.167 +				** However some programs don't process this message and so sit there invisibly
  28.168 +				** in the background so I just post the quit message and hope the application
  28.169 +				** does the correct thing.
  28.170 +				*/
  28.171 +				SDL_PrivateQuit();
  28.172 +			} else
  28.173 +				sysEvent = 1;
  28.174 +        	doPoll = 0;
  28.175 +        	break;
  28.176 +
  28.177 +		case 4: /* Pointer_Leaving_Window */
  28.178 +			if (message[0] == sdlWindow)
  28.179 +			{
  28.180 +				mouseInWindow = 0;
  28.181 +				//TODO: Lose buttons / dragging
  28.182 +				 /* Reset to default pointer */
  28.183 +   				 regs.r[0] = 106;
  28.184 +				 regs.r[1] = 1;
  28.185 +				 regs.r[2] = 0;
  28.186 +				 _kernel_swi(OS_Byte, &regs, &regs);
  28.187 +				 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
  28.188 +			} else
  28.189 +				sysEvent = 1;
  28.190 +			break;
  28.191 +
  28.192 +		case 5: /* Pointer_Entering_Window */
  28.193 +			if (message[0] == sdlWindow) 
  28.194 +			{
  28.195 +				mouseInWindow = 1;
  28.196 +				WIMP_ReshowCursor(this);
  28.197 +				SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
  28.198 +			} else sysEvent = 1;
  28.199 +			break;
  28.200 +
  28.201 +		case 6:		/* Mouse_Click */
  28.202 +			if (hasFocus == 0)
  28.203 +			{
  28.204 +			   /* First click gives focus if it's not a menu */
  28.205 +			   /* we only count non-menu clicks on a window that has the focus */
  28.206 +			   WIMP_SetFocus(message[3]);
  28.207 +			} else
  28.208 +				doPoll = 0; // So PollMouse gets a chance to pick it up
  28.209 +		   break;
  28.210 +
  28.211 +		case 7: /* User_Drag_Box - Used for mouse release */
  28.212 +			//TODO: May need to implement this in the future
  28.213 +			sysEvent = 1;
  28.214 +			break;
  28.215 +
  28.216 +		case 8: /* Keypressed */
  28.217 +			doPoll = 0; /* PollKeyboard should pick it up */
  28.218 +			if (message[0] != sdlWindow) sysEvent = 1;
  28.219 +			/*TODO: May want to always pass F12 etc to the wimp
  28.220 +			{
  28.221 +				regs.r[0] = message[6];
  28.222 +				_kernel_swi(Wimp_ProcessKey, &regs, &regs);
  28.223 +			}
  28.224 +			*/
  28.225 +			break;
  28.226 +
  28.227 +		case 11: /* Lose Caret */
  28.228 +			 hasFocus = 0;
  28.229 +			 if (message[0] == sdlWindow) SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
  28.230 +			 else sysEvent = 1;
  28.231 +			 break;
  28.232 +
  28.233 +		case 12: /* Gain Caret */
  28.234 +			 hasFocus = 1;
  28.235 +			 if (message[0] == sdlWindow) SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
  28.236 +			 else sysEvent = 1;
  28.237 +			 break;
  28.238 +        	
  28.239 +		case 17:
  28.240 +		case 18:
  28.241 +			sysEvent = 1; /* All messages are passed on */
  28.242 +
  28.243 +			switch(message[4])
  28.244 +			{
  28.245 +			case 0: /* Quit Event */
  28.246 +				/* No choice - have to quit */
  28.247 +			   SDL_Quit();
  28.248 +        	   exit(0);
  28.249 +			   break;
  28.250 +
  28.251 +			case 8: /* Pre Quit */
  28.252 +				SDL_PrivateQuit();
  28.253 +				break;
  28.254 +
  28.255 +			case 0x400c1: /* Mode change */
  28.256 +				WIMP_ModeChanged(this);
  28.257 +				resizeOnOpen = 1;
  28.258 +				break;
  28.259 +
  28.260 +			case 9:      /* Palette changed */
  28.261 +				WIMP_PaletteChanged(this);
  28.262 +				break;
  28.263 +			}
  28.264 +			break;
  28.265 +
  28.266 +		default:
  28.267 +			/* Pass unknown events on */
  28.268 +			sysEvent = 1;
  28.269 +			break;
  28.270 +		}
  28.271 +
  28.272 +		if (sysEvent)
  28.273 +		{
  28.274 +	        SDL_SysWMmsg wmmsg;
  28.275 +
  28.276 +			SDL_VERSION(&wmmsg.version);
  28.277 +			wmmsg.eventCode = code;
  28.278 +			memcpy(wmmsg.pollBlock, message, 64 * sizeof(int));
  28.279 +
  28.280 +			/* Fall out of polling loop if message is successfully posted */
  28.281 +			if (SDL_PrivateSysWMEvent(&wmmsg)) doPoll = 0;
  28.282 +		}
  28.283 +
  28.284 +    }
  28.285 +}
  28.286 +
  28.287 +/* Set focus to specified window */
  28.288 +void WIMP_SetFocus(int win)
  28.289 +{
  28.290 +	_kernel_swi_regs regs;
  28.291 +
  28.292 +	regs.r[0] = win;
  28.293 +	regs.r[1] = -1; /* Icon handle */
  28.294 +	regs.r[2] = 0;  /* X-offset we just put it at position 0 */
  28.295 +	regs.r[3] = 0;  /* Y-offset as above */
  28.296 +	regs.r[4] = 1 << 25; /* Caret is invisible */
  28.297 +	regs.r[5] = 0;  /* index into string */
  28.298 +
  28.299 +	_kernel_swi(Wimp_SetCaretPosition, &regs, &regs);
  28.300 +}
  28.301 +
  28.302 +/** Run background task while in a sleep command */
  28.303 +void RISCOS_BackgroundTasks(void)
  28.304 +{
  28.305 +	if (current_video && current_video->hidden->window_handle)
  28.306 +	{
  28.307 +		WIMP_Poll(current_video, 0);
  28.308 +	}
  28.309 +	/* Keep sound buffers running */
  28.310 +	DRenderer_FillBuffers();
  28.311 +	if (SDL_timer_running) RISCOS_CheckTimer();
  28.312 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/video/riscos/SDL_wimpvideo.c	Thu May 29 04:44:13 2003 +0000
    29.3 @@ -0,0 +1,492 @@
    29.4 +/*
    29.5 +    SDL - Simple DirectMedia Layer
    29.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
    29.7 +
    29.8 +    This library is free software; you can redistribute it and/or
    29.9 +    modify it under the terms of the GNU Library General Public
   29.10 +    License as published by the Free Software Foundation; either
   29.11 +    version 2 of the License, or (at your option) any later version.
   29.12 +
   29.13 +    This library is distributed in the hope that it will be useful,
   29.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   29.16 +    Library General Public License for more details.
   29.17 +
   29.18 +    You should have received a copy of the GNU Library General Public
   29.19 +    License along with this library; if not, write to the Free
   29.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.21 +
   29.22 +    Sam Lantinga
   29.23 +    slouken@devolution.com
   29.24 +*/
   29.25 +
   29.26 +/*
   29.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
   29.28 +	 27 March 2003
   29.29 +
   29.30 +     Implements RISCOS wimp display.
   29.31 +*/
   29.32 +
   29.33 +#include <stdio.h>
   29.34 +#include <stdlib.h>
   29.35 +#include <string.h>
   29.36 +
   29.37 +#include "SDL.h"
   29.38 +#include "SDL_error.h"
   29.39 +#include "SDL_video.h"
   29.40 +#include "SDL_mouse.h"
   29.41 +#include "SDL_sysvideo.h"
   29.42 +#include "SDL_pixels_c.h"
   29.43 +#include "SDL_events_c.h"
   29.44 +
   29.45 +#include "SDL_riscostask.h"
   29.46 +#include "SDL_riscosvideo.h"
   29.47 +#include "SDL_riscosevents_c.h"
   29.48 +#include "SDL_riscosmouse_c.h"
   29.49 +
   29.50 +#include "kernel.h"
   29.51 +#include "swis.h"
   29.52 +
   29.53 +/* Initialization/Query functions */
   29.54 +SDL_Rect **WIMP_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   29.55 +SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
   29.56 +int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
   29.57 +void WIMP_SetWMCaption(_THIS, const char *title, const char *icon);
   29.58 +
   29.59 +
   29.60 +extern unsigned char *WIMP_CreateBuffer(int width, int height, int bpp);
   29.61 +extern void WIMP_PumpEvents(_THIS);
   29.62 +extern void WIMP_PlotSprite(_THIS, int x, int y);
   29.63 +extern void WIMP_SetupPlotInfo(_THIS);
   29.64 +extern void WIMP_SetFocus(int win);
   29.65 +
   29.66 +/* etc. */
   29.67 +static void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
   29.68 +
   29.69 +/* RISC OS Wimp handling helpers */
   29.70 +void WIMP_ReadModeInfo(_THIS);
   29.71 +unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface);
   29.72 +void WIMP_SetDeviceMode(_THIS);
   29.73 +void WIMP_DeleteWindow(_THIS);
   29.74 +
   29.75 +/* FULLSCREEN function required for wimp/fullscreen toggling */
   29.76 +extern int FULLSCREEN_SetMode(int width, int height, int bpp);
   29.77 +
   29.78 +/* Currently need to set this up here as it only works if you
   29.79 +   start up in a Wimp mode */
   29.80 +extern int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
   29.81 +
   29.82 +extern int riscos_backbuffer;
   29.83 +extern int mouseInWindow;
   29.84 +extern int riscos_closeaction;
   29.85 +
   29.86 +
   29.87 +SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current,
   29.88 +				int width, int height, int bpp, Uint32 flags)
   29.89 +{
   29.90 +   Uint32 Rmask = 0;
   29.91 +   Uint32 Gmask = 0;
   29.92 +   Uint32 Bmask = 0;
   29.93 +   char *buffer = NULL;
   29.94 +   int bytesPerPixel = 1;
   29.95 +
   29.96 +   /* Don't support double buffering in Wimp mode */
   29.97 +   flags &= ~SDL_DOUBLEBUF;
   29.98 +   flags &= ~SDL_HWSURFACE;
   29.99 +
  29.100 +   switch(bpp)
  29.101 +   {
  29.102 +	case 8:
  29.103 +		/* Emulated palette using ColourTrans */
  29.104 +		flags |= SDL_HWPALETTE;
  29.105 +		break;
  29.106 +
  29.107 +	case 15:
  29.108 +	case 16:
  29.109 +		Bmask = 0x00007c00;
  29.110 +		Gmask = 0x000003e0;
  29.111 +		Rmask = 0x0000001f;
  29.112 +		bytesPerPixel = 2;
  29.113 +		break;
  29.114 +
  29.115 +	case 32:
  29.116 +		Bmask = 0x00ff0000;
  29.117 +		Gmask = 0x0000ff00;
  29.118 +		Rmask = 0x000000ff;
  29.119 +		bytesPerPixel = 4;
  29.120 +		break;
  29.121 +
  29.122 +	default:
  29.123 +		SDL_SetError("Pixel depth not supported");
  29.124 +		return NULL;
  29.125 +		break;
  29.126 +   }
  29.127 +
  29.128 +/* 	printf("Setting mode %dx%d\n", width, height);*/
  29.129 +
  29.130 +	/* Allocate the new pixel format for the screen */
  29.131 +	if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) {
  29.132 +		SDL_SetError("Couldn't allocate new pixel format for requested mode");
  29.133 +		return(NULL);
  29.134 +	}
  29.135 +
  29.136 +	/* Set up the new mode framebuffer */
  29.137 +	current->w = width;
  29.138 +	this->hidden->height = current->h = height;
  29.139 +
  29.140 +	if (bpp == 15) bpp = 16;
  29.141 +	buffer = WIMP_CreateBuffer(width, height, bpp);
  29.142 +	if (buffer == NULL)
  29.143 +	{
  29.144 +		SDL_SetError("Couldn't create sprite for video memory");
  29.145 +		return (NULL);
  29.146 +	}
  29.147 +
  29.148 +	this->hidden->bank[0] = buffer + 60; /* Start of sprite data */
  29.149 +	if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
  29.150 +
  29.151 +	this->hidden->bank[1] = buffer;      /* Start of buffer */
  29.152 +
  29.153 +	/* Remember sprite buffer so it can be freed later */
  29.154 +	if (this->hidden->alloc_bank) free(this->hidden->alloc_bank);
  29.155 +	this->hidden->alloc_bank = buffer;
  29.156 +
  29.157 +	current->pitch = width * bytesPerPixel;
  29.158 +	if ((current->pitch & 3))
  29.159 +	{
  29.160 +		/* Sprites are 32bit word aligned */
  29.161 +		current->pitch += (4 - (current->pitch & 3));
  29.162 +	}
  29.163 +
  29.164 +  	current->flags = flags | SDL_PREALLOC;
  29.165 +
  29.166 +	WIMP_ReadModeInfo(this);
  29.167 +	
  29.168 +    memset(this->hidden->bank[0], 0, height * current->pitch);
  29.169 +
  29.170 +	this->hidden->current_bank = 0;
  29.171 +	current->pixels = this->hidden->bank[0];
  29.172 +
  29.173 +
  29.174 +	if (WIMP_SetupWindow(this, current) == 0)
  29.175 +	{
  29.176 +		SDL_SetError("Unable to create window to display surface");
  29.177 +		return NULL;
  29.178 +	}
  29.179 +
  29.180 +	/* Reset device functions for the wimp */
  29.181 +	WIMP_SetDeviceMode(this);
  29.182 +
  29.183 +    /* Needs to set up plot info after window has been created */
  29.184 +    /* Not sure why, but plots don't work if I do it earlier */
  29.185 +    WIMP_SetupPlotInfo(this);
  29.186 +
  29.187 +	/* We're done */
  29.188 +	return(current);
  29.189 +}
  29.190 +
  29.191 +
  29.192 +void WIMP_ReadModeInfo(_THIS)
  29.193 +{
  29.194 +	_kernel_swi_regs regs;
  29.195 +	int vars[6];
  29.196 +	int vals[5];
  29.197 +
  29.198 +	vars[0] = 4;  /* XEig */
  29.199 +	vars[1] = 5;  /* YEig */
  29.200 +	vars[2] = 9;  /* Log base 2 bpp */
  29.201 +	vars[3] = 11; /* Screen Width - 1 */
  29.202 +	vars[4] = 12; /* Screen Depth - 1 */
  29.203 +	vars[5] = -1; /* Terminate list */
  29.204 +
  29.205 +	regs.r[0] = (int)vars;
  29.206 +	regs.r[1] = (int)vals;
  29.207 +	_kernel_swi(OS_ReadVduVariables, &regs, &regs);
  29.208 +	this->hidden->xeig = vals[0];
  29.209 +	this->hidden->yeig = vals[1];
  29.210 +	this->hidden->screen_bpp = 1 << vals[2];
  29.211 +	this->hidden->screen_width = vals[3] + 1;
  29.212 +	this->hidden->screen_height = vals[4] + 1;
  29.213 +}
  29.214 +
  29.215 +/* Set device function to call the correct versions for running
  29.216 +   in a wimp window */
  29.217 +
  29.218 +void WIMP_SetDeviceMode(_THIS)
  29.219 +{
  29.220 +	if (this->UpdateRects == WIMP_UpdateRects) return; /* Already set up */
  29.221 +
  29.222 +	this->SetColors   = WIMP_SetColors;
  29.223 +	this->UpdateRects = WIMP_UpdateRects;
  29.224 +
  29.225 +	this->FlipHWSurface = NULL;
  29.226 +
  29.227 +	this->SetCaption = WIMP_SetWMCaption;
  29.228 +	this->SetIcon = NULL;
  29.229 +	this->IconifyWindow = NULL;
  29.230 +	
  29.231 +	this->ShowWMCursor = WIMP_ShowWMCursor;
  29.232 +	this->WarpWMCursor = WIMP_WarpWMCursor;
  29.233 +
  29.234 +        this->ToggleFullScreen = RISCOS_ToggleFullScreen;
  29.235 +
  29.236 +	this->PumpEvents = WIMP_PumpEvents;	
  29.237 +}
  29.238 +
  29.239 +/* Setup the Window to display the surface */
  29.240 +unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface)
  29.241 +{
  29.242 +	_kernel_swi_regs regs;
  29.243 +	int window_data[23];
  29.244 +    int	*window_block = window_data+1;
  29.245 +	int x = (this->hidden->screen_width - surface->w) / 2;
  29.246 +	int y = (this->hidden->screen_height - surface->h) / 2;
  29.247 +	int xeig = this->hidden->xeig;
  29.248 +	int yeig = this->hidden->yeig;
  29.249 +
  29.250 +    mouseInWindow = 0;
  29.251 +    
  29.252 +	/* Always delete the window and recreate on a change */
  29.253 +	if (this->hidden->window_handle) WIMP_DeleteWindow(this);
  29.254 +
  29.255 +	/* Setup window co-ordinates */
  29.256 +   window_block[0] = x << xeig;
  29.257 +   window_block[1] = y << yeig;
  29.258 +   window_block[2] = window_block[0] + (surface->w << xeig);
  29.259 +   window_block[3] = window_block[1] + (surface->h << yeig);
  29.260 +
  29.261 +   
  29.262 +   window_block[4] = 0;				  /* Scroll offsets */
  29.263 +   window_block[5] = 0;
  29.264 +   window_block[6] = -1;			  /* Open on top of window stack */
  29.265 +
  29.266 +   window_block[7] = 0x85040042;      /* Window flags */
  29.267 +   if (riscos_closeaction != 0) window_block[7] |= 0x2000000;
  29.268 +
  29.269 +   /* TODO: Take into account surface->flags */
  29.270 +
  29.271 +   window_block[8] = 0xff070207;      /* Window colours */
  29.272 +   window_block[9] = 0x000c0103;
  29.273 +   window_block[10] = 0;                    /* Work area minimum */
  29.274 +   window_block[11] = -surface->h << yeig;
  29.275 +   window_block[12] = surface->w << xeig;   /* Work area maximum */
  29.276 +   window_block[13] = 0;
  29.277 +   window_block[14] = 0x2700013d;    /* Title icon flags */
  29.278 +   window_block[15] = 0x00003000;	 /* Work area flags - Mouse click down reported */
  29.279 +   window_block[16] = 1;             /* Sprite area control block pointer */
  29.280 +   window_block[17] = 0x00100010;	 /* Minimum window size (width & height) (16x16)*/
  29.281 +   window_block[18] = (int)this->hidden->title;    /* Title data */
  29.282 +   window_block[19] = -1;
  29.283 +   window_block[20] = 256;
  29.284 +   window_block[21] = 0;			 /* Number of icons */
  29.285 +
  29.286 +   regs.r[1] = (unsigned int)(window_block);
  29.287 +   
  29.288 +   /* Create the window */
  29.289 +   if (_kernel_swi(Wimp_CreateWindow, &regs, &regs) == NULL)
  29.290 +   {
  29.291 +	   this->hidden->window_handle = window_data[0] = regs.r[0];
  29.292 +
  29.293 +	   /* Show the window on the screen */
  29.294 +	   regs.r[1] = (unsigned int)window_data;
  29.295 +       if (_kernel_swi(Wimp_OpenWindow, &regs, &regs) == NULL)
  29.296 +       {
  29.297 +          WIMP_SetFocus(this->hidden->window_handle);
  29.298 +       } else
  29.299 +       {
  29.300 +		  WIMP_DeleteWindow(this);
  29.301 +	   }
  29.302 +   }
  29.303 +   
  29.304 +   return this->hidden->window_handle;
  29.305 +}
  29.306 +
  29.307 +/* Destroy the Window */
  29.308 +
  29.309 +void WIMP_DeleteWindow(_THIS)
  29.310 +{
  29.311 +	_kernel_swi_regs regs;
  29.312 +    regs.r[1] = (unsigned int)&(this->hidden->window_handle);
  29.313 +	_kernel_swi(Wimp_DeleteWindow, &regs, &regs);
  29.314 +	this->hidden->window_handle = 0;
  29.315 +}
  29.316 +
  29.317 +
  29.318 +void WIMP_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
  29.319 +{
  29.320 +	_kernel_swi_regs regs;
  29.321 +	int update_block[12];
  29.322 +	int xeig = this->hidden->xeig;
  29.323 +	int yeig = this->hidden->yeig;
  29.324 +	int j;
  29.325 +	update_block[0] = this->hidden->window_handle;
  29.326 +
  29.327 +	for (j = 0; j < numrects; j++)
  29.328 +	{
  29.329 +		update_block[1] = rects[j].x << xeig; /* Min X */
  29.330 +		update_block[4] = -(rects[j].y << yeig);
  29.331 +		update_block[3] = update_block[1] + (rects[j].w << xeig);
  29.332 +		update_block[2] = update_block[4] - (rects[j].h << yeig);
  29.333 +
  29.334 +		regs.r[1] = (int)update_block;
  29.335 +		/* Update window can fail if called before first poll */
  29.336 +		if (_kernel_swi(Wimp_UpdateWindow, &regs, &regs) == 0)
  29.337 +		{
  29.338 +			while (regs.r[0])
  29.339 +			{
  29.340 +				WIMP_PlotSprite(this, update_block[1], update_block[2]);
  29.341 +				_kernel_swi(Wimp_GetRectangle, &regs, &regs);
  29.342 +			}
  29.343 +		}
  29.344 +	}
  29.345 +}
  29.346 +
  29.347 +
  29.348 +int WIMP_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
  29.349 +{
  29.350 +   unsigned int *pal = (unsigned int *)(this->hidden->bank[1]+60);
  29.351 +   int j;
  29.352 +   SDL_Rect update;
  29.353 +
  29.354 +   pal += firstcolor*2;
  29.355 +   for (j = 0; j < ncolors; j++)
  29.356 +   {
  29.357 +      *pal = (((unsigned int)colors->r) << 8)
  29.358 +             + (((unsigned int)colors->g) << 16)
  29.359 +             + (((unsigned int)colors->b) << 24);
  29.360 +      pal[1] = *pal;
  29.361 +      pal += 2;
  29.362 +      colors++;
  29.363 +   }
  29.364 +
  29.365 +   WIMP_SetupPlotInfo(this);
  29.366 +
  29.367 +   /* Need to refresh the window */
  29.368 +   update.x = 0;
  29.369 +   update.y = 0;
  29.370 +   update.w = SDL_VideoSurface->w;
  29.371 +   update.h = SDL_VideoSurface->h;
  29.372 +   WIMP_UpdateRects(this, 1, &update);
  29.373 +      
  29.374 +	return 1;
  29.375 +}
  29.376 +
  29.377 +void WIMP_SetWMCaption(_THIS, const char *title, const char *icon)
  29.378 +{
  29.379 +	_kernel_swi_regs regs;
  29.380 +
  29.381 +	strncpy(this->hidden->title, title, 255);
  29.382 +	this->hidden->title[255] = 0;
  29.383 +
  29.384 +	if (RISCOS_GetWimpVersion() < 380)
  29.385 +	{
  29.386 +		int block[6];
  29.387 +
  29.388 +		regs.r[1] = (int)block;
  29.389 +		_kernel_swi(Wimp_GetCaretPosition, &regs, &regs);
  29.390 +		if (block[0] == (int)this->hidden->window_handle)
  29.391 +		{
  29.392 +			regs.r[0] = -1;
  29.393 +			_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
  29.394 +		} else
  29.395 +		{
  29.396 +			regs.r[0] = this->hidden->window_handle;
  29.397 +			regs.r[1] = -1;
  29.398 +			regs.r[2] = -1;
  29.399 +			regs.r[3] = -1;
  29.400 +			_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
  29.401 +		}
  29.402 +		regs.r[0] = block[0];
  29.403 +		regs.r[1] = block[1];
  29.404 +		regs.r[2] = block[2];
  29.405 +		regs.r[3] = block[3];
  29.406 +		regs.r[4] = block[4];
  29.407 +		regs.r[5] = block[5];
  29.408 +		_kernel_swi(Wimp_SetCaretPosition, &regs,&regs);
  29.409 +	} else
  29.410 +	{
  29.411 +		regs.r[0] = this->hidden->window_handle;
  29.412 +		regs.r[1] = 0x4b534154; /* "TASK" */
  29.413 +		regs.r[2] = 3; /* Redraw title */
  29.414 +		_kernel_swi(Wimp_ForceRedraw, &regs, &regs);
  29.415 +	}
  29.416 +}
  29.417 +
  29.418 +void WIMP_RefreshDesktop(_THIS)
  29.419 +{
  29.420 +   int width = this->hidden->screen_width << this->hidden->xeig;
  29.421 +   int height = this->hidden->screen_height << this->hidden->yeig;
  29.422 +   _kernel_swi_regs regs;
  29.423 +   regs.r[0] = -1; /* Whole screen */
  29.424 +   regs.r[1] = 0;
  29.425 +   regs.r[2] = 0;
  29.426 +   regs.r[3] = width;
  29.427 +   regs.r[4] = height;
  29.428 +   _kernel_swi(Wimp_ForceRedraw, &regs, &regs);
  29.429 +}
  29.430 +
  29.431 +/* Toggle to window from full screen */
  29.432 +int WIMP_ToggleFromFullScreen(_THIS)
  29.433 +{     
  29.434 +   int width = this->screen->w;
  29.435 +   int height = this->screen->h;
  29.436 +   int bpp = this->screen->format->BitsPerPixel;
  29.437 +   char *buffer = NULL;
  29.438 +   char *old_bank[2];
  29.439 +   char *old_alloc_bank;
  29.440 +
  29.441 +   /* Ensure flags are OK */
  29.442 +   this->screen->flags &= ~(SDL_DOUBLEBUF|SDL_HWSURFACE);
  29.443 +
  29.444 +   if (this->hidden->bank[0] == this->hidden->alloc_bank || riscos_backbuffer == 0)
  29.445 +   {
  29.446 +      /* Need to create a sprite for the screen and copy the data to it */
  29.447 +      char *data;
  29.448 +      buffer = WIMP_CreateBuffer(width, height, bpp);
  29.449 +      data = buffer + 60;         /* Start of sprite data */
  29.450 +      if (bpp == 8) data += 2048;  /* 8bpp sprite have palette first */
  29.451 +
  29.452 +      if (buffer == NULL) return 0;
  29.453 +      memcpy(data, this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel);
  29.454 +   }
  29.455 +   /* else We've switch to full screen before so we already have a sprite */
  29.456 +
  29.457 +   old_bank[0] = this->hidden->bank[0];
  29.458 +   old_bank[1] = this->hidden->bank[1];
  29.459 +   old_alloc_bank = this->hidden->alloc_bank;
  29.460 +
  29.461 +   if (buffer != NULL) this->hidden->alloc_bank = buffer;
  29.462 +
  29.463 +   this->hidden->bank[1] = this->hidden->alloc_bank;
  29.464 +   this->hidden->bank[0] = this->hidden->bank[1] + 60; /* Start of sprite data */
  29.465 +   if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */
  29.466 +
  29.467 +   this->hidden->current_bank = 0;
  29.468 +   this->screen->pixels = this->hidden->bank[0];
  29.469 +
  29.470 +   RISCOS_RestoreWimpMode();
  29.471 +   WIMP_ReadModeInfo(this);
  29.472 +   if (WIMP_SetupWindow(this, this->screen))
  29.473 +   {
  29.474 +      WIMP_SetDeviceMode(this);
  29.475 +      WIMP_SetupPlotInfo(this);
  29.476 +
  29.477 +      riscos_backbuffer = 1;
  29.478 +
  29.479 +      if (buffer && old_alloc_bank) free(old_alloc_bank);
  29.480 +
  29.481 +      return 1;
  29.482 +   } else
  29.483 +   {
  29.484 +      /* Drop back to full screen mode on failure */
  29.485 +      this->hidden->bank[0] = old_bank[0];
  29.486 +      this->hidden->bank[1] = old_bank[1];
  29.487 +      this->hidden->alloc_bank = old_alloc_bank;
  29.488 +      if (buffer) free(buffer);
  29.489 +      
  29.490 +      RISCOS_StoreWimpMode();
  29.491 +      FULLSCREEN_SetMode(width, height, bpp);
  29.492 +   }
  29.493 +
  29.494 +   return 0;
  29.495 +}