comparison src/video/riscos/SDL_riscosvideo.c @ 630:550bccdf04bd

Added initial support for RISC OS (thanks Peter Naulls!)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 29 May 2003 04:44:13 +0000
parents
children 91400ecf307d
comparison
equal deleted inserted replaced
629:3fa401bb4bb5 630:550bccdf04bd
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 /*
24 File added by Alan Buckley (alan_baa@hotmail.com) for RISCOS compatability
25 23 March 2003
26
27 Implements RISCOS display device management.
28 Routines for full screen and wimp modes are split
29 into other source files.
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "SDL.h"
37 #include "SDL_syswm.h"
38 #include "SDL_error.h"
39 #include "SDL_video.h"
40 #include "SDL_mouse.h"
41 #include "SDL_sysvideo.h"
42 #include "SDL_pixels_c.h"
43 #include "SDL_events_c.h"
44
45 #include "SDL_riscostask.h"
46 #include "SDL_riscosvideo.h"
47 #include "SDL_riscosevents_c.h"
48 #include "SDL_riscosmouse_c.h"
49
50 #include "kernel.h"
51 #include "swis.h"
52
53 #define RISCOSVID_DRIVER_NAME "riscos"
54
55 /* Initialization/Query functions */
56 static int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
57 static void RISCOS_VideoQuit(_THIS);
58
59 static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
60 static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
61
62 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info);
63
64 int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
65 /* Mouse checking */
66 void RISCOS_CheckMouseMode(_THIS);
67 extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
68
69 /* Fullscreen mode functions */
70 extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
71 extern void FULLSCREEN_BuildModeList(_THIS);
72 extern void FULLSCREEN_SetDeviceMode(_THIS);
73 extern int FULLSCREEN_ToggleFromWimp(_THIS);
74
75 /* Wimp mode functions */
76 extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
77 extern void WIMP_DeleteWindow(_THIS);
78 extern int WIMP_ToggleFromFullScreen(_THIS);
79
80 /* Hardware surface functions - common to WIMP and FULLSCREEN */
81 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface);
82 static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface);
83 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
84 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface);
85
86 /* RISCOS driver bootstrap functions */
87
88 static int RISCOS_Available(void)
89 {
90 return(1);
91 }
92
93 static void RISCOS_DeleteDevice(SDL_VideoDevice *device)
94 {
95 free(device->hidden);
96 free(device);
97 }
98
99 static SDL_VideoDevice *RISCOS_CreateDevice(int devindex)
100 {
101 SDL_VideoDevice *device;
102
103 /* Initialize all variables that we clean on shutdown */
104 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
105 if ( device ) {
106 memset(device, 0, (sizeof *device));
107 device->hidden = (struct SDL_PrivateVideoData *)
108 malloc((sizeof *device->hidden));
109 }
110 if ( (device == NULL) || (device->hidden == NULL) ) {
111 SDL_OutOfMemory();
112 if ( device ) {
113 free(device);
114 }
115 return(0);
116 }
117 memset(device->hidden, 0, (sizeof *device->hidden));
118
119 /* Set the function pointers */
120 device->VideoInit = RISCOS_VideoInit;
121 device->VideoQuit = RISCOS_VideoQuit;
122
123 device->ListModes = RISCOS_ListModes;
124 device->SetVideoMode = RISCOS_SetVideoMode;
125 device->CreateYUVOverlay = NULL;
126 device->AllocHWSurface = RISCOS_AllocHWSurface;
127 device->CheckHWBlit = NULL;
128 device->FillHWRect = NULL;
129 device->SetHWColorKey = NULL;
130 device->SetHWAlpha = NULL;
131 device->LockHWSurface = RISCOS_LockHWSurface;
132 device->UnlockHWSurface = RISCOS_UnlockHWSurface;
133 device->FreeHWSurface = RISCOS_FreeHWSurface;
134
135 device->FreeWMCursor = RISCOS_FreeWMCursor;
136 device->CreateWMCursor = RISCOS_CreateWMCursor;
137 device->CheckMouseMode = RISCOS_CheckMouseMode;
138 device->GrabInput = RISCOS_GrabInput;
139
140 device->InitOSKeymap = RISCOS_InitOSKeymap;
141
142 device->GetWMInfo = RISCOS_GetWmInfo;
143
144 device->free = RISCOS_DeleteDevice;
145
146 /* Can't get Toggle screen to work if program starts up in Full screen mode so
147 disable it here and re-enable it when a wimp screen is chosen */
148 device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/
149
150 /* Set other entries for fullscreen mode */
151 FULLSCREEN_SetDeviceMode(device);
152
153 /* Turn off unixlib file name translation - we hope people have initialised
154 the video system before they try to read any files */
155 /* __riscosify_control = __RISCOSIFY_NO_PROCESS;
156 *//* We may be able to eventually replace our processing of filenames with the correct flags above*/
157
158 return device;
159 }
160
161 VideoBootStrap RISCOS_bootstrap = {
162 RISCOSVID_DRIVER_NAME, "RISCOS video driver",
163 RISCOS_Available, RISCOS_CreateDevice
164 };
165
166
167 int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
168 {
169 _kernel_swi_regs regs;
170
171 if (RISCOS_InitTask() == 0)
172 {
173 SDL_SetError("Unable to start task");
174 return 0;
175 }
176
177 regs.r[0] = -1; /* Current mode */
178 regs.r[1] = 9; /* Log base 2 bpp */
179
180 _kernel_swi(OS_ReadVduVariables, &regs, &regs);
181 vformat->BitsPerPixel = (1 << regs.r[0]);
182
183 /* Minimum bpp for SDL is 8 */
184 if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8;
185
186
187 switch (vformat->BitsPerPixel)
188 {
189 case 15:
190 case 16:
191 vformat->Bmask = 0x00007c00;
192 vformat->Gmask = 0x000003e0;
193 vformat->Rmask = 0x0000001f;
194 vformat->BitsPerPixel = 15; /* SDL wants actual number of bits used */
195 vformat->BytesPerPixel = 2;
196 break;
197
198 case 24:
199 case 32:
200 vformat->Bmask = 0x00ff0000;
201 vformat->Gmask = 0x0000ff00;
202 vformat->Rmask = 0x000000ff;
203 vformat->BytesPerPixel = 4;
204 break;
205
206 default:
207 vformat->Bmask = 0;
208 vformat->Gmask = 0;
209 vformat->Rmask = 0;
210 vformat->BytesPerPixel = 1;
211 break;
212 }
213
214 /* Fill in some window manager capabilities */
215 this->info.wm_available = 1;
216
217 /* We're done! */
218 return(0);
219 }
220
221 /* Note: If we are terminated, this could be called in the middle of
222 another SDL video routine -- notably UpdateRects.
223 */
224 void RISCOS_VideoQuit(_THIS)
225 {
226 RISCOS_ExitTask();
227
228 if (this->hidden->alloc_bank) free(this->hidden->alloc_bank);
229 this->hidden->alloc_bank = 0;
230 }
231
232
233 SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
234 {
235 if (flags & SDL_FULLSCREEN)
236 {
237 /* Build mode list when first required. */
238 if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this);
239
240 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
241 } else
242 return (SDL_Rect **)-1;
243 }
244
245
246 /* Set up video mode */
247 SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
248 int width, int height, int bpp, Uint32 flags)
249 {
250 if (flags & SDL_FULLSCREEN)
251 {
252 RISCOS_StoreWimpMode();
253 /* Dump wimp window on switch to full screen */
254 if (this->hidden->window_handle) WIMP_DeleteWindow(this);
255
256 return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
257 } else
258 {
259 RISCOS_RestoreWimpMode();
260 return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
261 }
262 }
263
264
265 /* We don't actually allow hardware surfaces other than the main one */
266 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface)
267 {
268 return(-1);
269 }
270 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface)
271 {
272 return;
273 }
274
275 /* We need to wait for vertical retrace on page flipped displays */
276 static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface)
277 {
278 return(0);
279 }
280
281 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
282 {
283 return;
284 }
285
286
287 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info)
288 {
289 SDL_VERSION(&(info->version));
290 info->wimpVersion = RISCOS_GetWimpVersion();
291 info->taskHandle = RISCOS_GetTaskHandle();
292 info->window = this->hidden->window_handle;
293
294 return 1;
295 }
296 /* Toggle full screen mode.
297 Returns 1 if successful otherwise 0
298 */
299
300 int RISCOS_ToggleFullScreen(_THIS, int fullscreen)
301 {
302 if (fullscreen)
303 {
304 return FULLSCREEN_ToggleFromWimp(this);
305 } else
306 {
307 return WIMP_ToggleFromFullScreen(this);
308 }
309
310 return 0;
311 }
312