19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Library General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Library General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Library General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 23 March 2003
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall     Implements RISC OS display device management.
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 Routines for full screen and wimp modes are split
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	 into other source files.
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_video.h"
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_mouse.h"
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_syswm.h"
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_sysvideo.h"
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../SDL_pixels_c.h"
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "../../events/SDL_events_c.h"
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscostask.h"
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosvideo.h"
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosevents_c.h"
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_riscosmouse_c.h"
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "kernel.h"
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "swis.h"
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define RISCOSVID_DRIVER_NAME "riscos"
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Initialization/Query functions */
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_VideoQuit(_THIS);
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info);
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint RISCOS_ToggleFullScreen(_THIS, int fullscreen);
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Mouse checking */
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_CheckMouseMode(_THIS);
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Fullscreen mode functions */
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void FULLSCREEN_BuildModeList(_THIS);
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void	FULLSCREEN_SetDeviceMode(_THIS);
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int FULLSCREEN_ToggleFromWimp(_THIS);
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Wimp mode functions */
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current,	int width, int height, int bpp, Uint32 flags);
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern void WIMP_DeleteWindow(_THIS);
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallextern int WIMP_ToggleFromFullScreen(_THIS);
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Hardware surface functions - common to WIMP and FULLSCREEN */
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface);
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface);
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface);
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* RISC OS driver bootstrap functions */
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_Available(void)
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(1);
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_DeleteDevice(SDL_VideoDevice *device)
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_free(device->hidden);
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_free(device);
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic SDL_VideoDevice *RISCOS_CreateDevice(int devindex)
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_VideoDevice *device;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Initialize all variables that we clean on shutdown */
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( device ) {
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_memset(device, 0, (sizeof *device));
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		device->hidden = (struct SDL_PrivateVideoData *)
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				SDL_malloc((sizeof *device->hidden));
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( (device == NULL) || (device->hidden == NULL) ) {
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_OutOfMemory();
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( device ) {
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_free(device);
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(0);
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_memset(device->hidden, 0, (sizeof *device->hidden));
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set the function pointers */
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->VideoInit = RISCOS_VideoInit;
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->VideoQuit = RISCOS_VideoQuit;
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->ListModes = RISCOS_ListModes;
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->SetVideoMode = RISCOS_SetVideoMode;
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->CreateYUVOverlay = NULL;
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->AllocHWSurface = RISCOS_AllocHWSurface;
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->CheckHWBlit = NULL;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->FillHWRect = NULL;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->SetHWColorKey = NULL;
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->SetHWAlpha = NULL;
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->LockHWSurface = RISCOS_LockHWSurface;
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->UnlockHWSurface = RISCOS_UnlockHWSurface;
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->FreeHWSurface = RISCOS_FreeHWSurface;
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->FreeWMCursor = RISCOS_FreeWMCursor;
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->CreateWMCursor = RISCOS_CreateWMCursor;
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->CheckMouseMode = RISCOS_CheckMouseMode;
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    device->GrabInput = RISCOS_GrabInput;
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->InitOSKeymap = RISCOS_InitOSKeymap;
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->GetWMInfo = RISCOS_GetWmInfo;
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->free = RISCOS_DeleteDevice;
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Can't get Toggle screen to work if program starts up in Full screen mode so
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   disable it here and re-enable it when a wimp screen is chosen */
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Set other entries for fullscreen mode */
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	FULLSCREEN_SetDeviceMode(device);
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Mouse pointer needs to use the WIMP ShowCursor version so
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   that it doesn't modify the pointer until the SDL Window is
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	   entered or the application goes full screen */
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	device->ShowWMCursor = WIMP_ShowWMCursor;
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return device;
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallVideoBootStrap RISCOS_bootstrap = {
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	RISCOSVID_DRIVER_NAME, "RISC OS video driver",
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	RISCOS_Available, RISCOS_CreateDevice
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall};
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_kernel_swi_regs regs;
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int vars[4], vals[3];
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (RISCOS_InitTask() == 0)
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_SetError("Unable to start task");
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return 0;
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	vars[0] = 9;  /* Log base 2 bpp */
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	vars[1] = 11; /* XWndLimit - num x pixels -1 */
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	vars[2] = 12; /* YWndLimit - num y pixels -1 */
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	vars[3] = -1; /* Terminate list */
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	regs.r[0] = (int)vars;
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	regs.r[1] = (int)vals;
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	_kernel_swi(OS_ReadVduVariables, &regs, &regs);
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	vformat->BitsPerPixel = (1 << vals[0]);
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Determine the current screen size */
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	this->info.current_w = vals[1] + 1;
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	this->info.current_h = vals[2] + 1;
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Minimum bpp for SDL is 8 */
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8;
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	switch (vformat->BitsPerPixel)
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 15:
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 16:
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Bmask = 0x00007c00;
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Gmask = 0x000003e0;
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Rmask = 0x0000001f;
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->BitsPerPixel = 16; /* SDL wants actual number of bits used */
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->BytesPerPixel = 2;
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 24:
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		case 32:
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Bmask = 0x00ff0000;
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Gmask = 0x0000ff00;
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Rmask = 0x000000ff;
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->BytesPerPixel = 4;
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		default:
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Bmask = 0;
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Gmask = 0;
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->Rmask = 0;
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			vformat->BytesPerPixel = 1;
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			break;
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Fill in some window manager capabilities */
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	this->info.wm_available = 1;
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* We're done! */
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Note:  If we are terminated, this could be called in the middle of
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   another SDL video routine -- notably UpdateRects.
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid RISCOS_VideoQuit(_THIS)
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	RISCOS_ExitTask();
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank);
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	this->hidden->alloc_bank = 0;
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (flags & SDL_FULLSCREEN)
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Build mode list when first required. */
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this);
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return (SDL_Rect **)-1;
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Set up video mode */
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				int width, int height, int bpp, Uint32 flags)
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if (flags & SDL_FULLSCREEN)
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    RISCOS_StoreWimpMode();
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Dump wimp window on switch to full screen */
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  	    if (this->hidden->window_handle) WIMP_DeleteWindow(this);
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	{
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	    RISCOS_RestoreWimpMode();
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* We don't actually allow hardware surfaces other than the main one */
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface)
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(-1);
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface)
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* We need to wait for vertical retrace on page flipped displays */
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface)
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return;
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info)
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_VERSION(&(info->version));
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info->wimpVersion = RISCOS_GetWimpVersion();
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info->taskHandle = RISCOS_GetTaskHandle();
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	info->window = this->hidden->window_handle;
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 1;
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Toggle full screen mode.
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   Returns 1 if successful otherwise 0
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint RISCOS_ToggleFullScreen(_THIS, int fullscreen)
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    if (fullscreen)
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       return FULLSCREEN_ToggleFromWimp(this);
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    } else
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    {
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall       return WIMP_ToggleFromFullScreen(this);
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall   return 0;
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
317