src/video/riscos/SDL_riscosvideo.c
changeset 630 550bccdf04bd
child 687 91400ecf307d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/riscos/SDL_riscosvideo.c	Thu May 29 04:44:13 2003 +0000
     1.3 @@ -0,0 +1,312 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +/*
    1.27 +     File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
    1.28 +	 23 March 2003
    1.29 +
    1.30 +     Implements RISCOS display device management.
    1.31 +	 Routines for full screen and wimp modes are split
    1.32 +	 into other source files.
    1.33 +*/
    1.34 +
    1.35 +#include <stdio.h>
    1.36 +#include <stdlib.h>
    1.37 +#include <string.h>
    1.38 +
    1.39 +#include "SDL.h"
    1.40 +#include "SDL_syswm.h"
    1.41 +#include "SDL_error.h"
    1.42 +#include "SDL_video.h"
    1.43 +#include "SDL_mouse.h"
    1.44 +#include "SDL_sysvideo.h"
    1.45 +#include "SDL_pixels_c.h"
    1.46 +#include "SDL_events_c.h"
    1.47 +
    1.48 +#include "SDL_riscostask.h"
    1.49 +#include "SDL_riscosvideo.h"
    1.50 +#include "SDL_riscosevents_c.h"
    1.51 +#include "SDL_riscosmouse_c.h"
    1.52 +
    1.53 +#include "kernel.h"
    1.54 +#include "swis.h"
    1.55 +
    1.56 +#define RISCOSVID_DRIVER_NAME "riscos"
    1.57 +
    1.58 +/* Initialization/Query functions */
    1.59 +static int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
    1.60 +static void RISCOS_VideoQuit(_THIS);
    1.61 +
    1.62 +static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
    1.63 +static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    1.64 +
    1.65 +int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info);
    1.66 +
    1.67 +int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
    1.68 +/* Mouse checking */
    1.69 +void RISCOS_CheckMouseMode(_THIS);
    1.70 +extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
    1.71 +
    1.72 +/* Fullscreen mode functions */
    1.73 +extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
    1.74 +extern void FULLSCREEN_BuildModeList(_THIS);
    1.75 +extern void	FULLSCREEN_SetDeviceMode(_THIS);
    1.76 +extern int FULLSCREEN_ToggleFromWimp(_THIS);
    1.77 +
    1.78 +/* Wimp mode functions */
    1.79 +extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current,	int width, int height, int bpp, Uint32 flags);
    1.80 +extern void WIMP_DeleteWindow(_THIS);
    1.81 +extern int WIMP_ToggleFromFullScreen(_THIS);
    1.82 +
    1.83 +/* Hardware surface functions - common to WIMP and FULLSCREEN */
    1.84 +static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface);
    1.85 +static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface);
    1.86 +static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
    1.87 +static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface);
    1.88 +
    1.89 +/* RISCOS driver bootstrap functions */
    1.90 +
    1.91 +static int RISCOS_Available(void)
    1.92 +{
    1.93 +	return(1);
    1.94 +}
    1.95 +
    1.96 +static void RISCOS_DeleteDevice(SDL_VideoDevice *device)
    1.97 +{
    1.98 +	free(device->hidden);
    1.99 +	free(device);
   1.100 +}
   1.101 +
   1.102 +static SDL_VideoDevice *RISCOS_CreateDevice(int devindex)
   1.103 +{
   1.104 +	SDL_VideoDevice *device;
   1.105 +
   1.106 +	/* Initialize all variables that we clean on shutdown */
   1.107 +	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
   1.108 +	if ( device ) {
   1.109 +		memset(device, 0, (sizeof *device));
   1.110 +		device->hidden = (struct SDL_PrivateVideoData *)
   1.111 +				malloc((sizeof *device->hidden));
   1.112 +	}
   1.113 +	if ( (device == NULL) || (device->hidden == NULL) ) {
   1.114 +		SDL_OutOfMemory();
   1.115 +		if ( device ) {
   1.116 +			free(device);
   1.117 +		}
   1.118 +		return(0);
   1.119 +	}
   1.120 +	memset(device->hidden, 0, (sizeof *device->hidden));
   1.121 +
   1.122 +	/* Set the function pointers */
   1.123 +	device->VideoInit = RISCOS_VideoInit;
   1.124 +	device->VideoQuit = RISCOS_VideoQuit;
   1.125 +
   1.126 +	device->ListModes = RISCOS_ListModes;
   1.127 +	device->SetVideoMode = RISCOS_SetVideoMode;
   1.128 +	device->CreateYUVOverlay = NULL;
   1.129 +	device->AllocHWSurface = RISCOS_AllocHWSurface;
   1.130 +	device->CheckHWBlit = NULL;
   1.131 +	device->FillHWRect = NULL;
   1.132 +	device->SetHWColorKey = NULL;
   1.133 +	device->SetHWAlpha = NULL;
   1.134 +	device->LockHWSurface = RISCOS_LockHWSurface;
   1.135 +	device->UnlockHWSurface = RISCOS_UnlockHWSurface;
   1.136 +	device->FreeHWSurface = RISCOS_FreeHWSurface;
   1.137 +	
   1.138 +	device->FreeWMCursor = RISCOS_FreeWMCursor;
   1.139 +	device->CreateWMCursor = RISCOS_CreateWMCursor;
   1.140 +	device->CheckMouseMode = RISCOS_CheckMouseMode;
   1.141 +    device->GrabInput = RISCOS_GrabInput;
   1.142 +
   1.143 +	device->InitOSKeymap = RISCOS_InitOSKeymap;
   1.144 +
   1.145 +	device->GetWMInfo = RISCOS_GetWmInfo;
   1.146 +
   1.147 +	device->free = RISCOS_DeleteDevice;
   1.148 +
   1.149 +/* Can't get Toggle screen to work if program starts up in Full screen mode so
   1.150 +   disable it here and re-enable it when a wimp screen is chosen */
   1.151 +    device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/
   1.152 +
   1.153 +	/* Set other entries for fullscreen mode */
   1.154 +	FULLSCREEN_SetDeviceMode(device);
   1.155 +
   1.156 +/* Turn off unixlib file name translation - we hope people have initialised
   1.157 +   the video system before they try to read any files */
   1.158 +/*        __riscosify_control = __RISCOSIFY_NO_PROCESS;
   1.159 +*//* We may be able to eventually replace our processing of filenames with the correct flags above*/
   1.160 +
   1.161 +	return device;
   1.162 +}
   1.163 +
   1.164 +VideoBootStrap RISCOS_bootstrap = {
   1.165 +	RISCOSVID_DRIVER_NAME, "RISCOS video driver",
   1.166 +	RISCOS_Available, RISCOS_CreateDevice
   1.167 +};
   1.168 +
   1.169 +
   1.170 +int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
   1.171 +{
   1.172 +	_kernel_swi_regs regs;
   1.173 +
   1.174 +	if (RISCOS_InitTask() == 0)
   1.175 +	{
   1.176 +		SDL_SetError("Unable to start task");
   1.177 +		return 0;
   1.178 +	}
   1.179 +
   1.180 +	regs.r[0] = -1; /* Current mode */
   1.181 +	regs.r[1] = 9;  /* Log base 2 bpp */
   1.182 +
   1.183 +	_kernel_swi(OS_ReadVduVariables, &regs, &regs);
   1.184 +	vformat->BitsPerPixel = (1 << regs.r[0]);
   1.185 +
   1.186 +	/* Minimum bpp for SDL is 8 */
   1.187 +	if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8;
   1.188 +
   1.189 +
   1.190 +	switch (vformat->BitsPerPixel)
   1.191 +	{
   1.192 +		case 15:
   1.193 +		case 16:
   1.194 +			vformat->Bmask = 0x00007c00;
   1.195 +			vformat->Gmask = 0x000003e0;
   1.196 +			vformat->Rmask = 0x0000001f;
   1.197 +			vformat->BitsPerPixel = 15; /* SDL wants actual number of bits used */
   1.198 +			vformat->BytesPerPixel = 2;
   1.199 +			break;
   1.200 +
   1.201 +		case 24:
   1.202 +		case 32:
   1.203 +			vformat->Bmask = 0x00ff0000;
   1.204 +			vformat->Gmask = 0x0000ff00;
   1.205 +			vformat->Rmask = 0x000000ff;
   1.206 +			vformat->BytesPerPixel = 4;
   1.207 +			break;
   1.208 +
   1.209 +		default:
   1.210 +			vformat->Bmask = 0;
   1.211 +			vformat->Gmask = 0;
   1.212 +			vformat->Rmask = 0;
   1.213 +			vformat->BytesPerPixel = 1;			
   1.214 +			break;
   1.215 +	}
   1.216 +
   1.217 +	/* Fill in some window manager capabilities */
   1.218 +	this->info.wm_available = 1;
   1.219 +
   1.220 +	/* We're done! */
   1.221 +	return(0);
   1.222 +}
   1.223 +
   1.224 +/* Note:  If we are terminated, this could be called in the middle of
   1.225 +   another SDL video routine -- notably UpdateRects.
   1.226 +*/
   1.227 +void RISCOS_VideoQuit(_THIS)
   1.228 +{
   1.229 +	RISCOS_ExitTask();
   1.230 +
   1.231 +	if (this->hidden->alloc_bank) free(this->hidden->alloc_bank);
   1.232 +	this->hidden->alloc_bank = 0;
   1.233 +}
   1.234 +
   1.235 +
   1.236 +SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
   1.237 +{
   1.238 +	if (flags & SDL_FULLSCREEN)
   1.239 +	{
   1.240 +		/* Build mode list when first required. */
   1.241 +		if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this);
   1.242 +
   1.243 +		return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
   1.244 +	} else
   1.245 +		return (SDL_Rect **)-1;
   1.246 +}
   1.247 +
   1.248 +
   1.249 +/* Set up video mode */
   1.250 +SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
   1.251 +				int width, int height, int bpp, Uint32 flags)
   1.252 +{
   1.253 +	if (flags & SDL_FULLSCREEN)
   1.254 +	{
   1.255 +	    RISCOS_StoreWimpMode();
   1.256 +		/* Dump wimp window on switch to full screen */
   1.257 +  	    if (this->hidden->window_handle) WIMP_DeleteWindow(this);
   1.258 +
   1.259 +		return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
   1.260 +	} else
   1.261 +	{
   1.262 +	    RISCOS_RestoreWimpMode();
   1.263 +		return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
   1.264 +	}
   1.265 +}
   1.266 +
   1.267 +
   1.268 +/* We don't actually allow hardware surfaces other than the main one */
   1.269 +static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface)
   1.270 +{
   1.271 +	return(-1);
   1.272 +}
   1.273 +static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface)
   1.274 +{
   1.275 +	return;
   1.276 +}
   1.277 +
   1.278 +/* We need to wait for vertical retrace on page flipped displays */
   1.279 +static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface)
   1.280 +{
   1.281 +	return(0);
   1.282 +}
   1.283 +
   1.284 +static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
   1.285 +{
   1.286 +	return;
   1.287 +}
   1.288 +
   1.289 +
   1.290 +int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info)
   1.291 +{
   1.292 +	SDL_VERSION(&(info->version));
   1.293 +	info->wimpVersion = RISCOS_GetWimpVersion();
   1.294 +	info->taskHandle = RISCOS_GetTaskHandle();
   1.295 +	info->window = this->hidden->window_handle;
   1.296 +
   1.297 +	return 1;
   1.298 +}
   1.299 +/* Toggle full screen mode.
   1.300 +   Returns 1 if successful otherwise 0
   1.301 +*/
   1.302 +
   1.303 +int RISCOS_ToggleFullScreen(_THIS, int fullscreen)
   1.304 +{
   1.305 +    if (fullscreen)
   1.306 +    {
   1.307 +       return FULLSCREEN_ToggleFromWimp(this);
   1.308 +    } else
   1.309 +    {
   1.310 +       return WIMP_ToggleFromFullScreen(this);
   1.311 +    }
   1.312 +
   1.313 +   return 0;
   1.314 +}
   1.315 +