From 6e7ff9d084001b673414a1dc2352c913c88b455b Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 29 May 2003 04:44:13 +0000 Subject: [PATCH] Added initial support for RISC OS (thanks Peter Naulls!) --- README | 2 +- include/SDL_syswm.h | 17 + src/audio/Makefile.am | 2 +- src/audio/SDL_audio.c | 5 +- src/audio/SDL_sysaudio.h | 3 + src/audio/riscos/Makefile.am | 9 + src/audio/riscos/SDL_drenderer.c | 293 +++++++++ src/audio/riscos/SDL_drenderer.h | 36 ++ src/joystick/Makefile.am | 2 +- src/joystick/riscos/Makefile.am | 8 + src/joystick/riscos/SDL_sysjoystick.c | 180 ++++++ src/timer/Makefile.am | 1 + src/timer/riscos/SDL_systimer.c | 146 +++++ src/video/Makefile.am | 2 +- src/video/SDL_sysvideo.h | 3 + src/video/SDL_video.c | 3 + src/video/riscos/Makefile.am | 20 + src/video/riscos/SDL_riscosFullScreenVideo.c | 594 +++++++++++++++++++ src/video/riscos/SDL_riscosevents.c | 458 ++++++++++++++ src/video/riscos/SDL_riscosevents_c.h | 38 ++ src/video/riscos/SDL_riscosmouse.c | 301 ++++++++++ src/video/riscos/SDL_riscosmouse_c.h | 48 ++ src/video/riscos/SDL_riscossprite.c | 263 ++++++++ src/video/riscos/SDL_riscostask.c | 356 +++++++++++ src/video/riscos/SDL_riscostask.h | 38 ++ src/video/riscos/SDL_riscosvideo.c | 312 ++++++++++ src/video/riscos/SDL_riscosvideo.h | 66 +++ src/video/riscos/SDL_wimppoll.c | 309 ++++++++++ src/video/riscos/SDL_wimpvideo.c | 492 +++++++++++++++ 29 files changed, 4002 insertions(+), 5 deletions(-) create mode 100644 src/audio/riscos/Makefile.am create mode 100644 src/audio/riscos/SDL_drenderer.c create mode 100644 src/audio/riscos/SDL_drenderer.h create mode 100644 src/joystick/riscos/Makefile.am create mode 100644 src/joystick/riscos/SDL_sysjoystick.c create mode 100644 src/timer/riscos/SDL_systimer.c create mode 100644 src/video/riscos/Makefile.am create mode 100644 src/video/riscos/SDL_riscosFullScreenVideo.c create mode 100644 src/video/riscos/SDL_riscosevents.c create mode 100644 src/video/riscos/SDL_riscosevents_c.h create mode 100644 src/video/riscos/SDL_riscosmouse.c create mode 100644 src/video/riscos/SDL_riscosmouse_c.h create mode 100644 src/video/riscos/SDL_riscossprite.c create mode 100644 src/video/riscos/SDL_riscostask.c create mode 100644 src/video/riscos/SDL_riscostask.h create mode 100644 src/video/riscos/SDL_riscosvideo.c create mode 100644 src/video/riscos/SDL_riscosvideo.h create mode 100644 src/video/riscos/SDL_wimppoll.c create mode 100644 src/video/riscos/SDL_wimpvideo.c diff --git a/README b/README index 591eb4bdd..d101cd77d 100644 --- a/README +++ b/README @@ -19,7 +19,7 @@ Objective C, Perl, PHP, Pike, Python, and Ruby. The current version supports Linux, Windows, BeOS, MacOS, MacOS X, FreeBSD, OpenBSD, BSD/OS, Solaris, and IRIX. The code contains support for Windows CE, AmigaOS, Dreamcast, Atari, QNX, NetBSD, AIX, OSF/Tru64, -and SymbianOS, but these are not officially supported. +RISC OS, and SymbianOS, but these are not officially supported. This library is distributed under GNU LGPL version 2, which can be found in the file "COPYING". This license allows you to use SDL diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index 805b28f71..f29f6d812 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -130,6 +130,23 @@ typedef struct { HGLRC hglrc; /* The OpenGL context, if any */ } SDL_SysWMinfo; +#elif defined(__riscos__) + +/* RISC OS custom event structure */ +struct SDL_SysWMmsg { + SDL_version version; + int eventCode; /* The window for the message */ + int pollBlock[64]; +}; + +/* The RISCOS custom window manager information structure */ +typedef struct { + SDL_version version; + int wimpVersion; /* Wimp version running under */ + int taskHandle; /* The RISCOS task handle */ + int window; /* The RISCOS display window */ +} SDL_SysWMinfo; + #else /* The generic custom event structure */ diff --git a/src/audio/Makefile.am b/src/audio/Makefile.am index a563cd919..d8aae3477 100644 --- a/src/audio/Makefile.am +++ b/src/audio/Makefile.am @@ -6,7 +6,7 @@ noinst_LTLIBRARIES = libaudio.la # Define which subdirectories need to be built SUBDIRS = @AUDIO_SUBDIRS@ DIST_SUBDIRS = alsa arts baudio dma dmedia dsp esd macrom nas nto openbsd \ - paudio sun ums windib windx5 disk mint dc + paudio riscos sun ums windib windx5 disk mint dc DRIVERS = @AUDIO_DRIVERS@ diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 97d00b7fb..ce066d6ec 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -91,6 +91,9 @@ static AudioBootStrap *bootstrap[] = { #endif #ifdef ENABLE_DC &DCAUD_bootstrap, +#endif +#ifdef DRENDERER_SUPPORT + &DRENDERER_bootstrap, #endif NULL }; @@ -381,7 +384,7 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) return(-1); } -#ifdef macintosh +#if defined(macintosh) || defined(__riscos__) /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */ #else #if defined(__MINT__) && !defined(ENABLE_THREADS) diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 3d1ad9e94..35e096d30 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -156,6 +156,9 @@ extern AudioBootStrap DISKAUD_bootstrap; #ifdef ENABLE_DC extern AudioBootStrap DCAUD_bootstrap; #endif +#ifdef DRENDERER_SUPPORT +extern AudioBootStrap DRENDERER_bootstrap; +#endif /* This is the current audio device */ extern SDL_AudioDevice *current_audio; diff --git a/src/audio/riscos/Makefile.am b/src/audio/riscos/Makefile.am new file mode 100644 index 000000000..1881e138d --- /dev/null +++ b/src/audio/riscos/Makefile.am @@ -0,0 +1,9 @@ + +## Makefile.am for SDL using the RISC OS audio system + +noinst_LTLIBRARIES = libaudio_riscos.la +libaudio_riscos_la_SOURCES = $(SRCS) + +# The SDL audio driver sources +SRCS = SDL_drenderer.c \ + SDL_drenderer.h diff --git a/src/audio/riscos/SDL_drenderer.c b/src/audio/riscos/SDL_drenderer.c new file mode 100644 index 000000000..d0ab5184d --- /dev/null +++ b/src/audio/riscos/SDL_drenderer.c @@ -0,0 +1,293 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + + +#include +#include +#include + +#include +#include "swis.h" + +#include "SDL_endian.h" +#include "SDL_audio.h" +#include "SDL_audio_c.h" +#include "SDL_audiomem.h" +#include "SDL_sysaudio.h" +#include "SDL_drenderer.h" + +#define DigitalRenderer_Activate 0x4F700 +#define DigitalRenderer_Deactivate 0x4F701 +#define DigitalRenderer_ReadState 0x4F705 +#define DigitalRenderer_NewSample 0x4F706 +#define DigitalRenderer_NumBuffers 0x4F709 +#define DigitalRenderer_StreamSamples 0x4F70A +#define DigitalRenderer_Stream16BitSamples 0x4F70B +#define DigitalRenderer_StreamStatistics 0x4F70C +#define DigitalRenderer_StreamFlags 0x4F70D +#define DigitalRenderer_Activate16 0x4F70F +#define DigitalRenderer_GetFrequency 0x4F710 + +static int FillBuffer; +extern SDL_AudioDevice *current_audio; + +extern int riscos_audiobuffer; /* Override for audio buffer size */ + +/* Audio driver functions */ + +static void DRenderer_CloseAudio(_THIS); +static int DRenderer_OpenAudio(_THIS, SDL_AudioSpec *spec); + +/* Audio driver bootstrap functions */ + +/* Define following to dump stats to stdout */ +/* #define DUMP_AUDIO */ + + +static int Audio_Available(void) +{ + _kernel_swi_regs regs; + int available = 0; + + /* Use call to set buffers to also check if Module is loaded */ + regs.r[0] = 0; + if (_kernel_swi(DigitalRenderer_NumBuffers, ®s, ®s) == 0) available = 1; + + return(available); +} + +static void Audio_DeleteDevice(SDL_AudioDevice *device) +{ + free(device->hidden); + free(device); +} + +static SDL_AudioDevice *Audio_CreateDevice(int devindex) +{ + SDL_AudioDevice *this; + + /* Initialize all variables that we clean on shutdown */ + this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); + if ( this ) { + memset(this, 0, (sizeof *this)); + this->hidden = (struct SDL_PrivateAudioData *) + malloc((sizeof *this->hidden)); + } + if ( (this == NULL) || (this->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( this ) { + free(this); + } + return(0); + } + memset(this->hidden, 0, (sizeof *this->hidden)); + + /* Set the function pointers */ + this->OpenAudio = DRenderer_OpenAudio; + this->CloseAudio = DRenderer_CloseAudio; + this->free = Audio_DeleteDevice; + + return this; +} + +AudioBootStrap DRENDERER_bootstrap = { + "drenderer", "RiscOS Digital Renderer Module", + Audio_Available, Audio_CreateDevice +}; + +/* Routine called to check and fill audio buffers if necessary */ +static Uint8 *buffer = NULL; + +void DRenderer_FillBuffers() +{ + SDL_AudioDevice *audio = current_audio; + + if ( !audio || ! audio->enabled ) + { + return; + } + + if ( ! audio->paused ) + { + _kernel_swi_regs regs; + /* Check filled buffers count */ + _kernel_swi(DigitalRenderer_StreamStatistics, ®s, ®s); + +#ifdef DUMP_AUDIO + if (regs.r[0] <= FillBuffer) + { + printf("Buffers in use %d\n", regs.r[0]); + } +#endif + + while (regs.r[0] <= FillBuffer && !audio->paused) + { + if ( audio->convert.needed ) + { + int silence; + if ( audio->convert.src_format == AUDIO_U8 ) + { + silence = 0x80; + } else { + silence = 0; + } + memset(audio->convert.buf, silence, audio->convert.len); + audio->spec.callback(audio->spec.userdata, + (Uint8 *)audio->convert.buf,audio->convert.len); + SDL_ConvertAudio(&audio->convert); +#if 0 + if ( audio->convert.len_cvt != audio->spec.size ) { + /* Uh oh... probably crashes here; */ + } +#endif + regs.r[0] = (int)audio->convert.buf; + regs.r[1] = audio->spec.samples * audio->spec.channels; + _kernel_swi(DigitalRenderer_Stream16BitSamples, ®s, ®s); + + } else + { + /* Fill buffer with silence */ + memset (buffer, 0, audio->spec.size); + + audio->spec.callback(audio->spec.userdata, + (Uint8 *)buffer, audio->spec.size); + + regs.r[0] = (int)buffer; + regs.r[1] = audio->spec.samples * audio->spec.channels; + _kernel_swi(DigitalRenderer_Stream16BitSamples, ®s, ®s); + } + /* Check if we have enough buffers yet */ + _kernel_swi(DigitalRenderer_StreamStatistics, ®s, ®s); + } + + } +} + +/* Size of DMA buffer to use */ +#define DRENDERER_BUFFER_SIZE 512 + +/* Number of centiseconds of sound to buffer. + Hopefully more than the maximum time between calls to the + FillBuffers routine above +*/ +#define DRENDERER_CSEC_TO_BUFFER 10 + +static int DRenderer_OpenAudio(_THIS, SDL_AudioSpec *spec) +{ + _kernel_swi_regs regs; + int buffers_per_sample; + +#ifdef DUMP_AUDIO + printf("Request format %d\n", spec->format); + printf("Request freq %d\n", spec->freq); + printf("Samples %d\n", spec->samples); +#endif + + /* Only support signed 16bit format */ + spec->format = AUDIO_S16LSB; + + if (spec->samples < DRENDERER_BUFFER_SIZE) spec->samples = DRENDERER_BUFFER_SIZE; + + SDL_CalculateAudioSpec(spec); + + + buffers_per_sample = spec->samples / DRENDERER_BUFFER_SIZE; + + if ((spec->samples % DRENDERER_BUFFER_SIZE) != 0) + { + buffers_per_sample++; + spec->samples = buffers_per_sample * DRENDERER_BUFFER_SIZE; + } + + /* Set number of buffers to use - the following should give enough + data between calls to the sound polling. + */ + + if (riscos_audiobuffer == 0) + { + FillBuffer = (int)((double)DRENDERER_CSEC_TO_BUFFER / ((double)DRENDERER_BUFFER_SIZE * 100.0 / (double)spec->freq)) + 1; + } else FillBuffer = riscos_audiobuffer/DRENDERER_BUFFER_SIZE - buffers_per_sample; + + if (FillBuffer < buffers_per_sample) FillBuffer = buffers_per_sample; + regs.r[0] = FillBuffer + buffers_per_sample; + +#ifdef DUMP_AUDIO + printf("Buffers per sample %d\n", buffers_per_sample); + printf("Fill buffer %d\n", FillBuffer); + printf("Time buffered (ms) %d\n",(int)((1000.0 * regs.r[0] * DRENDERER_BUFFER_SIZE)/(double)spec->freq)); +#endif + + if (_kernel_swi(DigitalRenderer_NumBuffers, ®s, ®s) != 0) + { + SDL_SetError("Can't set number of streaming sound buffers\n"); + return -1; + } + + /* Now initialise sound system */ + regs.r[0] = spec->channels; /* Number of channels */ + regs.r[1] = DRENDERER_BUFFER_SIZE; /* Samples length */ + regs.r[2] = spec->freq; /* frequency */ + regs.r[3] = 1; /* Restore previous handler on exit */ + + if (_kernel_swi(DigitalRenderer_Activate16, ®s, ®s) != 0) + { + SDL_SetError("Unable to activate digital renderer in 16 bit mode\n"); + return -1; + } + + if (_kernel_swi(DigitalRenderer_GetFrequency, ®s, ®s) == 0) + { + spec->freq = regs.r[0]; + } + +#ifdef DUMP_AUDIO + printf("Got format %d\n", spec->format); + printf("Frequency %d\n", spec->freq); + printf("Samples %d\n", spec->samples); +#endif + + /* Set to fill buffer with zero if we don't get data to it fast enough */ + regs.r[0] = 1; + regs.r[1] = ~1; + _kernel_swi(DigitalRenderer_StreamFlags, ®s, ®s); + + buffer = (Uint8 *)malloc(sizeof(Uint8) * spec->size); + if (buffer == NULL) + { + SDL_OutOfMemory(); + return -1; + } + + /* Hopefully returning 2 will show success, but not start up an audio thread */ + return 2; +} + +static void DRenderer_CloseAudio(_THIS) +{ + _kernel_swi_regs regs; + + /* Close down the digital renderer */ + _kernel_swi(DigitalRenderer_Deactivate, ®s, ®s); + + if (buffer != NULL) free(buffer); +} + diff --git a/src/audio/riscos/SDL_drenderer.h b/src/audio/riscos/SDL_drenderer.h new file mode 100644 index 000000000..c6e53840a --- /dev/null +++ b/src/audio/riscos/SDL_drenderer.h @@ -0,0 +1,36 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + + +#ifndef _SDL_drenderer_h +#define _SDL_drenderer_h + +#include "SDL_sysaudio.h" + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_AudioDevice *this + +struct SDL_PrivateAudioData { + unsigned char *audio_buf; +}; + +#endif /* _SDL_drenderer_h */ diff --git a/src/joystick/Makefile.am b/src/joystick/Makefile.am index 0e0decd6e..fa9015145 100644 --- a/src/joystick/Makefile.am +++ b/src/joystick/Makefile.am @@ -5,7 +5,7 @@ noinst_LTLIBRARIES = libjoystick.la # Define which subdirectories need to be built SUBDIRS = @JOYSTICK_SUBDIRS@ -DIST_SUBDIRS = dummy amigaos beos bsd darwin dc linux macos mint win32 +DIST_SUBDIRS = dummy amigaos beos bsd darwin dc linux macos mint riscos win32 DRIVERS = @JOYSTICK_DRIVERS@ diff --git a/src/joystick/riscos/Makefile.am b/src/joystick/riscos/Makefile.am new file mode 100644 index 000000000..ef5c85d51 --- /dev/null +++ b/src/joystick/riscos/Makefile.am @@ -0,0 +1,8 @@ + +## Makefile.am for the RISC OS joystick driver for SDL + +noinst_LTLIBRARIES = libjoystick_riscos.la +libjoystick_riscos_la_SOURCES = $(SRCS) + +# The SDL joystick driver sources +SRCS = SDL_sysjoystick.c diff --git a/src/joystick/riscos/SDL_sysjoystick.c b/src/joystick/riscos/SDL_sysjoystick.c new file mode 100644 index 000000000..644eec5d0 --- /dev/null +++ b/src/joystick/riscos/SDL_sysjoystick.c @@ -0,0 +1,180 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +/* + RISCOS - Joystick support by Alan Buckley (alan_baa@hotmail.com) - 10 April 2003 + + Note: Currently assumes joystick is present if joystick module is loaded + and that there is one joystick with four buttons. +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id$"; +#endif + +/* This is the system specific header for the SDL joystick API */ + +#include /* For the definition of NULL */ +#include + +#include "SDL_error.h" +#include "SDL_joystick.h" +#include "SDL_sysjoystick.h" +#include "SDL_joystick_c.h" + +#include "kernel.h" + +#define JOYSTICK_READ 0x43F40 + +struct joystick_hwdata +{ + int joystate; +}; + + +/* Function to scan the system for joysticks. + * This function should set SDL_numjoysticks to the number of available + * joysticks. Joystick 0 should be the system default joystick. + * It should return number of joysticks, or -1 on an unrecoverable fatal error. + */ +int SDL_SYS_JoystickInit(void) +{ + _kernel_swi_regs regs; + + /* Try to read joystick 0 */ + regs.r[0] = 0; + if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) + { + /* Switch works so assume we've got a joystick */ + return 1; + } + /* Switch fails so it looks like there's no joystick here */ + + return(0); +} + +/* Function to get the device-dependent name of a joystick */ +const char *SDL_SYS_JoystickName(int index) +{ + if (index == 0) + { + return "RISCOS Joystick 0"; + } + + SDL_SetError("No joystick available with that index"); + return(NULL); +} + +/* Function to open a joystick for use. + The joystick to open is specified by the index field of the joystick. + This should fill the nbuttons and naxes fields of the joystick structure. + It returns 0, or -1 if there is an error. + */ +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) +{ + _kernel_swi_regs regs; + + if(!(joystick->hwdata=malloc(sizeof(struct joystick_hwdata)))) + return -1; + + regs.r[0] = joystick->index; + + /* Don't know how to get exact count of buttons so assume max of 4 for now */ + joystick->nbuttons=4; + + joystick->nhats=0; + joystick->nballs=0; + joystick->naxes=2; + joystick->hwdata->joystate=0; + + return 0; + +} + +/* Function to update the state of a joystick - called as a device poll. + * This function shouldn't update the joystick structure directly, + * but instead should call SDL_PrivateJoystick*() to deliver events + * and update joystick device state. + */ +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) +{ + _kernel_swi_regs regs; + regs.r[0] = joystick->index; + + if (_kernel_swi(JOYSTICK_READ, ®s, ®s) == NULL) + { + int newstate = regs.r[0]; + int oldstate = joystick->hwdata->joystate; + if (newstate != oldstate) + { + if ((newstate & 0xFF) != (oldstate & 0xFF)) + { + int y = regs.r[0] & 0xFF; + /* Convert to signed values */ + if (y >= 128) y -= 256; + SDL_PrivateJoystickAxis(joystick,1,-y * 256); /* Up and down opposite to result in SDL */ + } + if ((newstate & 0xFF00) != (oldstate & 0xFF00)) + { + int x = (regs.r[0] & 0xFF00) >> 8; + if (x >= 128) x -= 256; + SDL_PrivateJoystickAxis(joystick,0,x * 256); + } + + if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) + { + int buttons = (regs.r[0] & 0xFF0000) >> 16; + int oldbuttons = (oldstate & 0xFF0000) >> 16; + int i; + for (i = 0; i < joystick->nbuttons; i++) + { + if ((buttons & (1<hwdata->joystate = newstate; + } + } + + return; +} + +/* Function to close a joystick after use */ +void SDL_SYS_JoystickClose(SDL_Joystick *joystick) +{ + if(joystick->hwdata) + free(joystick->hwdata); + return; +} + +/* Function to perform any system-specific joystick related cleanup */ +void SDL_SYS_JoystickQuit(void) +{ + SDL_numjoysticks=0; + + return; +} + diff --git a/src/timer/Makefile.am b/src/timer/Makefile.am index 01cab757a..c5a54f025 100644 --- a/src/timer/Makefile.am +++ b/src/timer/Makefile.am @@ -10,6 +10,7 @@ ARCH_SUBDIRS = $(srcdir)/amigaos \ $(srcdir)/linux \ $(srcdir)/macos \ $(srcdir)/mint \ + $(srcdir)/riscos \ $(srcdir)/win32 # Include the architecture-independent sources diff --git a/src/timer/riscos/SDL_systimer.c b/src/timer/riscos/SDL_systimer.c new file mode 100644 index 000000000..68673305a --- /dev/null +++ b/src/timer/riscos/SDL_systimer.c @@ -0,0 +1,146 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id$"; +#endif + +#include +#include +#include +#include +#include +#include + +#include "SDL_error.h" +#include "SDL_timer.h" +#include "SDL_timer_c.h" + +/* Timer start/reset time */ +static Uint32 timerStart; +/* Timer running function */ +void RISCOS_CheckTimer(); + +extern void RISCOS_BackgroundTasks(void); + +/* The first ticks value of the application */ +clock_t start; + +void SDL_StartTicks(void) +{ + /* Set first ticks value */ + start = clock(); +} + +Uint32 SDL_GetTicks (void) +{ + clock_t ticks; + + ticks=clock()-start; + + +#if CLOCKS_PER_SEC == 1000 + + return(ticks); + +#elif CLOCKS_PER_SEC == 100 + + return (ticks * 10); + +#else + + return ticks*(1000/CLOCKS_PER_SEC); + +#endif + +} + +extern void DRenderer_FillBuffers(); + +void SDL_Delay (Uint32 ms) +{ + Uint32 now,then,elapsed; + + /* Set the timeout interval - Linux only needs to do this once */ + then = SDL_GetTicks(); + + do { + /* Do background tasks required while sleeping as we are not multithreaded */ + RISCOS_BackgroundTasks(); + /* Calculate the time interval left (in case of interrupt) */ + now = SDL_GetTicks(); + elapsed = (now-then); + then = now; + if ( elapsed >= ms ) { + break; + } + ms -= elapsed; + + } while ( 1 ); +} + +int SDL_SYS_TimerInit(void) +{ + return(0); +} + +void SDL_SYS_TimerQuit(void) +{ + SDL_SetTimer(0, NULL); +} + +int SDL_SYS_StartTimer(void) +{ + timerStart = SDL_GetTicks(); + + return(0); +} + +void SDL_SYS_StopTimer(void) +{ + /* Don't need to do anything as we use SDL_timer_running + to detect if we need to check the timer */ +} + + +void RISCOS_CheckTimer() +{ + if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval) + { + Uint32 ms; + + ms = SDL_alarm_callback(SDL_alarm_interval); + if ( ms != SDL_alarm_interval ) + { + if ( ms ) + { + SDL_alarm_interval = ROUND_RESOLUTION(ms); + } else + { + SDL_alarm_interval = 0; + SDL_timer_running = 0; + } + } + if (SDL_alarm_interval) timerStart = SDL_GetTicks(); + } +} diff --git a/src/video/Makefile.am b/src/video/Makefile.am index 9908456d5..8472e82bc 100644 --- a/src/video/Makefile.am +++ b/src/video/Makefile.am @@ -7,7 +7,7 @@ noinst_LTLIBRARIES = libvideo.la SUBDIRS = @VIDEO_SUBDIRS@ DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \ wincommon windib windx5 \ - maccommon macdsp macrom quartz \ + maccommon macdsp macrom riscos quartz \ bwindow ps2gs photon cybergfx epoc picogui \ ataricommon xbios gem dc qtopia XFree86 diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 566341614..1fefd4a65 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -409,6 +409,9 @@ extern VideoBootStrap PG_bootstrap; #ifdef ENABLE_DC extern VideoBootStrap DC_bootstrap; #endif +#ifdef ENABLE_RISCOS +extern VideoBootStrap RISCOS_bootstrap; +#endif /* This is the current video device */ extern SDL_VideoDevice *current_video; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 82d601dfa..9d49c8fa0 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -117,6 +117,9 @@ static VideoBootStrap *bootstrap[] = { #ifdef ENABLE_DC &DC_bootstrap, #endif +#ifdef ENABLE_RISCOS + &RISCOS_bootstrap, +#endif #ifdef ENABLE_DUMMYVIDEO &DUMMY_bootstrap, #endif diff --git a/src/video/riscos/Makefile.am b/src/video/riscos/Makefile.am new file mode 100644 index 000000000..91c77fcf8 --- /dev/null +++ b/src/video/riscos/Makefile.am @@ -0,0 +1,20 @@ + +## Makefile.am for SDL using the RISC OS video driver + +noinst_LTLIBRARIES = libvideo_riscos.la +libvideo_riscos_la_SOURCES = $(CGX_SRCS) + +# The SDL RISC OS video driver sources +CGX_SRCS = \ + SDL_riscosevents.c \ + SDL_riscosevents_c.h \ + SDL_riscosFullScreenVideo.c \ + SDL_riscosmouse.c \ + SDL_riscosmouse_c.h \ + SDL_riscossprite.c \ + SDL_riscostask.c \ + SDL_riscostask.h \ + SDL_riscosvideo.c \ + SDL_riscosvideo.h \ + SDL_wimppoll.c \ + SDL_wimpvideo.c diff --git a/src/video/riscos/SDL_riscosFullScreenVideo.c b/src/video/riscos/SDL_riscosFullScreenVideo.c new file mode 100644 index 000000000..3d03abf57 --- /dev/null +++ b/src/video/riscos/SDL_riscosFullScreenVideo.c @@ -0,0 +1,594 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +/* + File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability + 27 March 2003 + + Implements RISCOS full screen display. +*/ + +#include +#include +#include + +#include "SDL.h" +#include "SDL_error.h" +#include "SDL_video.h" +#include "SDL_mouse.h" +#include "SDL_sysvideo.h" +#include "SDL_pixels_c.h" +#include "SDL_events_c.h" + +#include "SDL_riscostask.h" +#include "SDL_riscosvideo.h" +#include "SDL_riscosevents_c.h" +#include "SDL_riscosmouse_c.h" + +#include "kernel.h" +#include "swis.h" +#include "unixlib/os.h" +#include "unixlib/local.h" + +/* Private structures */ +typedef struct tagScreenModeBlock +{ + int flags; // mode selector flags, bit 0 = 1, bit 1-7 format specifier, 8-31 reserved + int x_pixels; + int y_pixels; + int pixel_depth; // 2^pixel_depth = bpp,i.e. 0 = 1, 1 = 2, 4 = 16, 5 = 32 + int frame_rate; // -1 use first match + int mode_vars[5]; // array of index, value pairs terminated by -1 +} SCREENMODEBLOCK; + + +/* Helper functions */ +void FULLSCREEN_SetDeviceMode(_THIS); +int FULLSCREEN_SetMode(int width, int height, int bpp); +void FULLSCREEN_SetupBanks(_THIS); + +/* SDL video device functions for fullscreen mode */ +static int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); +static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface); +static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects); +void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon); +extern int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info); + +/* Local helper functions */ +static int cmpmodes(const void *va, const void *vb); +static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h); +void FULLSCREEN_SetWriteBank(int bank); +void FULLSCREEN_SetDisplayBank(int bank); +static void FULLSCREEN_DisableEscape(); +static void FULLSCREEN_EnableEscape(); +void FULLSCREEN_BuildModeList(_THIS); + +/* Following variable is set up in riskosTask.c */ +extern int riscos_backbuffer; /* Create a back buffer in system memory for full screen mode */ + + + +SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +{ + _kernel_swi_regs regs; + Uint32 Rmask = 0; + Uint32 Gmask = 0; + Uint32 Bmask = 0; + int create_back_buffer = riscos_backbuffer; + + switch(bpp) + { + case 8: + flags |= SDL_HWPALETTE; + break; + + case 15: + case 16: + Bmask = 0x00007c00; + Gmask = 0x000003e0; + Rmask = 0x0000001f; + break; + + case 32: + Bmask = 0x00ff0000; + Gmask = 0x0000ff00; + Rmask = 0x000000ff; + break; + + default: + SDL_SetError("Pixel depth not supported"); + return NULL; + break; + } + + if (FULLSCREEN_SetMode(width, height, bpp) == 0) + { + SDL_SetError("Couldn't set requested mode"); + return (NULL); + } + +/* printf("Setting mode %dx%d\n", width, height); */ + + /* Allocate the new pixel format for the screen */ + if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { + RISCOS_RestoreWimpMode(); + SDL_SetError("Couldn't allocate new pixel format for requested mode"); + return(NULL); + } + + /* Set up the new mode framebuffer */ + current->w = width; + this->hidden->height = current->h = height; + + regs.r[0] = -1; /* -1 for current screen mode */ + + /* Get screen width in bytes */ + regs.r[1] = 6; // Screen Width in bytes + _kernel_swi(OS_ReadModeVariable, ®s, ®s); + + current->pitch = regs.r[2]; + + if (flags & SDL_DOUBLEBUF) + { + regs.r[0] = 2; /* Screen area */ + _kernel_swi(OS_ReadDynamicArea, ®s, ®s); + + /* Reg 1 has amount of memory currently used for display */ + regs.r[0] = 2; /* Screen area */ + regs.r[1] = (current->pitch * height * 2) - regs.r[1]; + if (_kernel_swi(OS_ChangeDynamicArea, ®s, ®s) != NULL) + { + /* Can't allocate enough screen memory for double buffer */ + flags &= ~SDL_DOUBLEBUF; + } + } + + current->flags = flags | SDL_FULLSCREEN | SDL_HWSURFACE | SDL_PREALLOC; + + + /* Need to set display banks here for double buffering */ + if (flags & SDL_DOUBLEBUF) + { + FULLSCREEN_SetWriteBank(0); + FULLSCREEN_SetDisplayBank(1); + + create_back_buffer = 0; /* Don't need a back buffer for a double buffered display */ + } + + FULLSCREEN_SetupBanks(this); + + if (create_back_buffer) + { + /* If not double buffered we may need to create a memory + ** back buffer to simulate processing on other OS's. + ** This is turned on by setting the enviromental variable + ** SDL$$BackBuffer to 1 + */ + this->hidden->bank[0] = malloc(height * current->pitch); + if (this->hidden->bank[0] == 0) + { + RISCOS_RestoreWimpMode(); + SDL_SetError("Couldnt allocate memory for back buffer"); + return (NULL); + } + /* Surface updated in programs is now a software surface */ + current->flags &= ~SDL_HWSURFACE; + } + + /* Store address of allocated screen bank to be freed later */ + if (this->hidden->alloc_bank) free(this->hidden->alloc_bank); + if (create_back_buffer) + { + this->hidden->alloc_bank = this->hidden->bank[0]; + } else + this->hidden->alloc_bank = 0; + + // Clear both banks to black + memset(this->hidden->bank[0], 0, height * current->pitch); + memset(this->hidden->bank[1], 0, height * current->pitch); + + this->hidden->current_bank = 0; + current->pixels = this->hidden->bank[0]; + + /* Reset device functions for the wimp */ + FULLSCREEN_SetDeviceMode(this); + +/* FULLSCREEN_DisableEscape(); */ + + /* We're done */ + return(current); +} + +/* Reset any device functions that have been changed because we have run in WIMP mode */ +void FULLSCREEN_SetDeviceMode(_THIS) +{ + if (this->SetColors == FULLSCREEN_SetColors) return; /* Already set up */ + + this->SetColors = FULLSCREEN_SetColors; + this->UpdateRects = FULLSCREEN_UpdateRects; + + this->FlipHWSurface = FULLSCREEN_FlipHWSurface; + + this->SetCaption = FULLSCREEN_SetWMCaption; + this->SetIcon = NULL; + this->IconifyWindow = NULL; + + this->ShowWMCursor = RISCOS_ShowWMCursor; + this->WarpWMCursor = FULLSCREEN_WarpWMCursor; + + this->PumpEvents = FULLSCREEN_PumpEvents; +} + +/* Query for the list of available video modes */ +void FULLSCREEN_BuildModeList(_THIS) +{ + _kernel_swi_regs regs; + char *enumInfo = NULL; + char *enum_ptr; + int *blockInfo; + int j; + int num_modes; + + /* Find out how much space we need */ + regs.r[0] = 2; /* Reason code */ + regs.r[2] = 0; /* Number of modes to skip */ + regs.r[6] = 0; /* pointer to block or 0 for count */ + regs.r[7] = 0; /* Size of block in bytes */ + _kernel_swi(OS_ScreenMode, ®s, ®s); + + num_modes = -regs.r[2]; + + /* Video memory should be in r[5] */ + this->info.video_mem = regs.r[5]/1024; + + enumInfo = (unsigned char *)malloc(-regs.r[7]); + if (enumInfo == NULL) + { + SDL_OutOfMemory(); + return; + } + /* Read mode information into block */ + regs.r[2] = 0; + regs.r[6] = (int)enumInfo; + regs.r[7] = -regs.r[7]; + _kernel_swi(OS_ScreenMode, ®s, ®s); + + enum_ptr = enumInfo; + + for (j =0; j < num_modes;j++) + { + blockInfo = (int *)enum_ptr; + if ((blockInfo[1] & 255) == 1) /* We understand this format */ + { + switch(blockInfo[4]) + { + case 3: /* 8 bits per pixel */ + FULLSCREEN_AddMode(this, 8, blockInfo[2], blockInfo[3]); + break; + case 4: /* 15 bits per pixel */ + FULLSCREEN_AddMode(this, 15, blockInfo[2], blockInfo[3]); + break; + case 5: /* 32 bits per pixel */ + FULLSCREEN_AddMode(this, 32, blockInfo[2], blockInfo[3]); + break; + } + } + + enum_ptr += blockInfo[0]; + } + + free(enumInfo); + + /* Sort the mode lists */ + for ( j=0; j 0 ) { + qsort(SDL_modelist[j], SDL_nummodes[j], sizeof *SDL_modelist[j], cmpmodes); + } + } +} + +static int FULLSCREEN_FlipHWSurface(_THIS, SDL_Surface *surface) +{ + _kernel_swi_regs regs; + regs.r[0] = 19; + /* Wait for Vsync */ + _kernel_swi(OS_Byte, ®s, ®s); + + FULLSCREEN_SetDisplayBank(this->hidden->current_bank); + this->hidden->current_bank ^= 1; + FULLSCREEN_SetWriteBank(this->hidden->current_bank); + surface->pixels = this->hidden->bank[this->hidden->current_bank]; + + return(0); +} + +static void FULLSCREEN_UpdateRects(_THIS, int numrects, SDL_Rect *rects) +{ + if (riscos_backbuffer && (this->screen->flags & SDL_DOUBLEBUF) == 0) + { + /* If not double buffered copy rectangles to main screen now */ + int j; + char *to, *from; + int pitch = this->screen->pitch; + int row; + int xmult = this->screen->format->BytesPerPixel; + for (j = 0; j < numrects; j++) + { + from = this->hidden->bank[0] + rects->x * xmult + rects->y * pitch; + to = this->hidden->bank[1] + rects->x * xmult + rects->y * pitch; + for (row = 0; row < rects->h; row++) + { + memcpy(to, from, rects->w * xmult); + from += pitch; + to += pitch; + } + rects++; + } + } +} + +int FULLSCREEN_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + _kernel_swi_regs regs; + int palette[256]; + + regs.r[0] = -1; + regs.r[1] = -1; + regs.r[2] = (int)palette; + regs.r[3] = 1024; + regs.r[4] = 0; + _kernel_swi(ColourTrans_ReadPalette, ®s, ®s); + + while(ncolors--) + { + palette[firstcolor] = ((colors->b) << 24) | ((colors->g) << 16) | ((colors->r) << 8); + firstcolor++; + colors++; + } + + regs.r[0] = -1; + regs.r[1] = -1; + regs.r[2] = (int)palette; + regs.r[3] = 0; + regs.r[4] = 0; + _kernel_swi(ColourTrans_WritePalette, ®s, ®s); + + return(1); +} + + +static int cmpmodes(const void *va, const void *vb) +{ + SDL_Rect *a = *(SDL_Rect **)va; + SDL_Rect *b = *(SDL_Rect **)vb; + if(a->w > b->w) + return -1; + return b->h - a->h; +} + +static int FULLSCREEN_AddMode(_THIS, int bpp, int w, int h) +{ + SDL_Rect *mode; + int i, index; + int next_mode; + + /* Check to see if we already have this mode */ + if ( bpp < 8 ) { /* Not supported */ + return(0); + } + index = ((bpp+7)/8)-1; + for ( i=0; iw == w) && (mode->h == h) ) { + return(0); + } + } + + /* Set up the new video mode rectangle */ + mode = (SDL_Rect *)malloc(sizeof *mode); + if ( mode == NULL ) { + SDL_OutOfMemory(); + return(-1); + } + mode->x = 0; + mode->y = 0; + mode->w = w; + mode->h = h; + + /* Allocate the new list of modes, and fill in the new mode */ + next_mode = SDL_nummodes[index]; + SDL_modelist[index] = (SDL_Rect **) + realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); + if ( SDL_modelist[index] == NULL ) { + SDL_OutOfMemory(); + SDL_nummodes[index] = 0; + free(mode); + return(-1); + } + SDL_modelist[index][next_mode] = mode; + SDL_modelist[index][next_mode+1] = NULL; + SDL_nummodes[index]++; + + return(0); +} + +void FULLSCREEN_SetWriteBank(int bank) +{ + _kernel_swi_regs regs; + regs.r[0] = 112; + regs.r[1] = bank+1; + _kernel_swi(OS_Byte, ®s, ®s); +} + +void FULLSCREEN_SetDisplayBank(int bank) +{ + _kernel_swi_regs regs; + regs.r[0] = 113; + regs.r[1] = bank+1; + _kernel_swi(OS_Byte, ®s, ®s); +} + + +/** Disable special escape key processing */ +static void FULLSCREEN_DisableEscape() +{ + _kernel_swi_regs regs; + regs.r[0] = 229; + regs.r[1] = 1; + regs.r[2] = 0; + _kernel_swi(OS_Byte, ®s, ®s); + +} + +/** Enable special escape key processing */ +static void FULLSCREEN_EnableEscape() +{ + _kernel_swi_regs regs; + regs.r[0] = 229; + regs.r[1] = 0; + regs.r[2] = 0; + _kernel_swi(OS_Byte, ®s, ®s); + +} + +/** Store caption in case this is called before we create a window */ +void FULLSCREEN_SetWMCaption(_THIS, const char *title, const char *icon) +{ + strncpy(this->hidden->title, title, 255); + this->hidden->title[255] = 0; +} + +/* Set screen mode +* +* Returns 1 if mode is set ok, otherwise 0 +*/ + +int FULLSCREEN_SetMode(int width, int height, int bpp) +{ + SCREENMODEBLOCK smb; + _kernel_swi_regs regs; + + smb.flags = 1; + smb.x_pixels = width; + smb.y_pixels = height; + smb.mode_vars[0] = -1; + + switch(bpp) + { + case 8: + smb.pixel_depth = 3; + /* Note: Need to set ModeFlags to 128 and NColour variables to 255 get full 8 bit palette */ + smb.mode_vars[0] = 0; smb.mode_vars[1] = 128; /* Mode flags */ + smb.mode_vars[2] = 3; smb.mode_vars[3] = 255; /* NColour (number of colours -1) */ + smb.mode_vars[4] = -1; /* End of list */ + break; + + case 15: + case 16: + smb.pixel_depth = 4; + break; + + case 32: + smb.pixel_depth = 5; + break; + + default: + SDL_SetError("Pixel depth not supported"); + return 0; + break; + } + + smb.frame_rate = -1; + + regs.r[0] = 0; + regs.r[1] = (int)&smb; + + if (_kernel_swi(OS_ScreenMode, ®s, ®s) != 0) + { + SDL_SetError("Couldn't set requested mode"); + return 0; + } + + /* Turn cursor off*/ + _kernel_oswrch(23);_kernel_oswrch(1);_kernel_oswrch(0); + _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0); + _kernel_oswrch(0);_kernel_oswrch(0);_kernel_oswrch(0); + _kernel_oswrch(0);_kernel_oswrch(0); + + return 1; +} + +/* Get Start addresses for the screen banks */ +void FULLSCREEN_SetupBanks(_THIS) +{ + _kernel_swi_regs regs; + int block[5]; + block[0] = 148; /* Write screen start */ + block[1] = 149; /* Display screen start */ + block[2] = 4; /* X eig factor */ + block[3] = 5; /* Y eig factor */ + block[4] = -1; /* End of list of variables to request */ + + regs.r[0] = (int)block; + regs.r[1] = (int)block; + _kernel_swi(OS_ReadVduVariables, ®s, ®s); + + this->hidden->bank[0] = (void *)block[0]; + this->hidden->bank[1] = (void *)block[1]; + this->hidden->xeig = block[2]; + this->hidden->yeig = block[3]; +} + +/* Toggle to full screen mode from the WIMP */ + +int FULLSCREEN_ToggleFromWimp(_THIS) +{ + int width = this->screen->w; + int height = this->screen->h; + int bpp = this->screen->format->BitsPerPixel; + + RISCOS_StoreWimpMode(); + if (FULLSCREEN_SetMode(width, height, bpp)) + { + char *buffer = this->hidden->alloc_bank; /* This is start of sprite data */ + /* Support back buffer mode only */ + riscos_backbuffer = 1; + + FULLSCREEN_SetupBanks(this); + + this->hidden->bank[0] = buffer + 60; /* Start of sprite data */ + if (bpp == 8) this->hidden->bank[0] += 2048; /* 8bpp sprite have palette first */ + + this->hidden->current_bank = 0; + this->screen->pixels = this->hidden->bank[0]; + + /* Copy back buffer to screen memory */ + memcpy(this->hidden->bank[1], this->hidden->bank[0], width * height * this->screen->format->BytesPerPixel); + + FULLSCREEN_SetDeviceMode(this); + return 1; + } else + RISCOS_RestoreWimpMode(); + + return 0; +} diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c new file mode 100644 index 000000000..598b6eb0e --- /dev/null +++ b/src/video/riscos/SDL_riscosevents.c @@ -0,0 +1,458 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Sam Lantinga + slouken@devolution.com +*/ + +/* + File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability + 27 March 2003 + + Implements keyboard setup, event pump and keyboard and mouse polling +*/ + + +#include "SDL.h" +#include "SDL_sysevents.h" +#include "SDL_events_c.h" +#include "SDL_riscosvideo.h" +#include "SDL_riscosevents_c.h" +#include "SDL_timer_c.h" +#include "SDL_cursor_c.h" + +#include "memory.h" +#include "stdlib.h" +#include "ctype.h" + +#include "kernel.h" +#include "swis.h" + +/* The translation table from a RISCOS internal key numbers to a SDL keysym */ +static SDLKey RO_keymap[SDLK_LAST]; + +/* RISCOS Key codes */ +#define ROKEY_SHIFT 0 +#define ROKEY_CTRL 1 +#define ROKEY_ALT 2 +/* Left shift is first key we will check for */ +#define ROKEY_LEFT_SHIFT 3 + +/* Need to ignore mouse buttons as they are processed separately */ +#define ROKEY_LEFT_MOUSE 9 +#define ROKEY_CENTRE_MOUSE 10 +#define ROKEY_RIGHT_MOUSE 11 + +/* No key has been pressed return value*/ +#define ROKEY_NONE 255 + +/* Id of last key in keyboard */ +#define ROKEY_LAST_KEY 124 + +/* Size of array for all keys */ +#define ROKEYBD_ARRAYSIZE 125 + +static char RO_pressed[ROKEYBD_ARRAYSIZE]; + +static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed); + + +void RISCOS_PollMouse(_THIS); +void RISCOS_PollKeyboard(); + +void RISCOS_PollMouseHelper(_THIS, int fullscreen); + +extern void DRenderer_FillBuffers(); + +/* Timer running function */ +extern void RISCOS_CheckTimer(); + +void FULLSCREEN_PumpEvents(_THIS) +{ + /* Current implementation requires keyboard and mouse polling */ + RISCOS_PollKeyboard(); + RISCOS_PollMouse(this); + DRenderer_FillBuffers(); + if (SDL_timer_running) RISCOS_CheckTimer(); +} + + +void RISCOS_InitOSKeymap(_THIS) +{ + int i; + + /* Map the VK keysyms */ + for ( i=0; i