This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_riscosvideo.c
336 lines (271 loc) · 9.31 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2004 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
20
slouken@libsdl.org
21
*/
22
#include "SDL_config.h"
23
24
/*
25
File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
26
27
23 March 2003
28
Implements RISC OS display device management.
29
30
31
32
33
34
Routines for full screen and wimp modes are split
into other source files.
*/
#include "SDL_video.h"
#include "SDL_mouse.h"
35
#include "SDL_syswm.h"
36
37
38
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
39
40
41
42
43
44
45
46
47
48
49
50
#include "SDL_riscostask.h"
#include "SDL_riscosvideo.h"
#include "SDL_riscosevents_c.h"
#include "SDL_riscosmouse_c.h"
#include "kernel.h"
#include "swis.h"
#define RISCOSVID_DRIVER_NAME "riscos"
/* Initialization/Query functions */
51
52
static int RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat);
static void RISCOS_VideoQuit(_THIS);
53
54
55
56
57
58
static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp,
Uint32 flags);
59
60
int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info);
61
62
int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
63
/* Mouse checking */
64
65
void RISCOS_CheckMouseMode(_THIS);
extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
66
67
/* Fullscreen mode functions */
68
69
70
71
72
73
extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp,
Uint32 flags);
extern void FULLSCREEN_BuildModeList(_THIS);
extern void FULLSCREEN_SetDeviceMode(_THIS);
extern int FULLSCREEN_ToggleFromWimp(_THIS);
74
75
/* Wimp mode functions */
76
77
78
79
80
extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp,
Uint32 flags);
extern void WIMP_DeleteWindow(_THIS);
extern int WIMP_ToggleFromFullScreen(_THIS);
81
82
/* Hardware surface functions - common to WIMP and FULLSCREEN */
83
84
85
86
static int RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface);
static int RISCOS_LockHWSurface(_THIS, SDL_Surface * surface);
static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface);
static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface);
87
88
/* RISC OS driver bootstrap functions */
89
90
static int
91
RISCOS_Available(void)
92
{
93
return (1);
94
95
}
96
static void
97
RISCOS_DeleteDevice(SDL_VideoDevice * device)
98
{
99
100
SDL_free(device->hidden);
SDL_free(device);
101
102
}
103
static SDL_VideoDevice *
104
RISCOS_CreateDevice(int devindex)
105
{
106
107
108
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
109
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
110
if (device) {
111
SDL_memset(device, 0, (sizeof *device));
112
device->hidden = (struct SDL_PrivateVideoData *)
113
SDL_malloc((sizeof *device->hidden));
114
115
}
if ((device == NULL) || (device->hidden == NULL)) {
116
SDL_OutOfMemory();
117
if (device) {
118
SDL_free(device);
119
120
121
}
return (0);
}
122
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Set the function pointers */
device->VideoInit = RISCOS_VideoInit;
device->VideoQuit = RISCOS_VideoQuit;
device->ListModes = RISCOS_ListModes;
device->SetVideoMode = RISCOS_SetVideoMode;
device->CreateYUVOverlay = NULL;
device->AllocHWSurface = RISCOS_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = RISCOS_LockHWSurface;
device->UnlockHWSurface = RISCOS_UnlockHWSurface;
device->FreeHWSurface = RISCOS_FreeHWSurface;
device->FreeWMCursor = RISCOS_FreeWMCursor;
device->CreateWMCursor = RISCOS_CreateWMCursor;
device->CheckMouseMode = RISCOS_CheckMouseMode;
143
144
device->GrabInput = RISCOS_GrabInput;
145
device->InitOSKeymap = RISCOS_InitOSKeymap;
146
147
device->GetWMInfo = RISCOS_GetWmInfo;
148
149
device->free = RISCOS_DeleteDevice;
150
151
152
/* Can't get Toggle screen to work if program starts up in Full screen mode so
disable it here and re-enable it when a wimp screen is chosen */
153
device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen; */
154
155
/* Set other entries for fullscreen mode */
156
FULLSCREEN_SetDeviceMode(device);
157
158
159
160
161
/* Mouse pointer needs to use the WIMP ShowCursor version so
that it doesn't modify the pointer until the SDL Window is
entered or the application goes full screen */
device->ShowWMCursor = WIMP_ShowWMCursor;
162
163
return device;
164
165
166
}
VideoBootStrap RISCOS_bootstrap = {
167
168
RISCOSVID_DRIVER_NAME, "RISC OS video driver",
RISCOS_Available, RISCOS_CreateDevice
169
170
171
};
172
int
173
RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat)
174
{
175
176
177
_kernel_swi_regs regs;
int vars[4], vals[3];
178
179
if (RISCOS_InitTask() == 0) {
SDL_SetError("Unable to start task");
180
181
182
183
184
185
186
187
188
189
return 0;
}
vars[0] = 9; /* Log base 2 bpp */
vars[1] = 11; /* XWndLimit - num x pixels -1 */
vars[2] = 12; /* YWndLimit - num y pixels -1 */
vars[3] = -1; /* Terminate list */
regs.r[0] = (int) vars;
regs.r[1] = (int) vals;
190
_kernel_swi(OS_ReadVduVariables, ®s, ®s);
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
vformat->BitsPerPixel = (1 << vals[0]);
/* Determine the current screen size */
this->info.current_w = vals[1] + 1;
this->info.current_h = vals[2] + 1;
/* Minimum bpp for SDL is 8 */
if (vformat->BitsPerPixel < 8)
vformat->BitsPerPixel = 8;
switch (vformat->BitsPerPixel) {
case 15:
case 16:
vformat->Bmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Rmask = 0x0000001f;
vformat->BitsPerPixel = 16; /* SDL wants actual number of bits used */
vformat->BytesPerPixel = 2;
break;
case 24:
case 32:
vformat->Bmask = 0x00ff0000;
vformat->Gmask = 0x0000ff00;
vformat->Rmask = 0x000000ff;
vformat->BytesPerPixel = 4;
break;
default:
vformat->Bmask = 0;
vformat->Gmask = 0;
vformat->Rmask = 0;
vformat->BytesPerPixel = 1;
break;
}
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
/* We're done! */
return (0);
233
234
235
236
237
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
238
void
239
RISCOS_VideoQuit(_THIS)
240
{
241
RISCOS_ExitTask();
242
243
if (this->hidden->alloc_bank)
244
SDL_free(this->hidden->alloc_bank);
245
this->hidden->alloc_bank = 0;
246
247
248
}
249
SDL_Rect **
250
RISCOS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
251
{
252
253
254
if (flags & SDL_FULLSCREEN) {
/* Build mode list when first required. */
if (SDL_nummodes[0] == 0)
255
FULLSCREEN_BuildModeList(this);
256
257
258
259
return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
} else
return (SDL_Rect **) - 1;
260
261
262
263
}
/* Set up video mode */
264
SDL_Surface *
265
266
RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
267
{
268
if (flags & SDL_FULLSCREEN) {
269
RISCOS_StoreWimpMode();
270
271
/* Dump wimp window on switch to full screen */
if (this->hidden->window_handle)
272
WIMP_DeleteWindow(this);
273
274
275
return FULLSCREEN_SetVideoMode(this, current, width, height, bpp,
flags);
276
} else {
277
278
RISCOS_RestoreWimpMode();
return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
279
}
280
281
282
283
}
/* We don't actually allow hardware surfaces other than the main one */
284
static int
285
RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface)
286
{
287
return (-1);
288
}
289
static void
290
RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface)
291
{
292
return;
293
294
295
}
/* We need to wait for vertical retrace on page flipped displays */
296
static int
297
RISCOS_LockHWSurface(_THIS, SDL_Surface * surface)
298
{
299
return (0);
300
301
}
302
static void
303
RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface)
304
{
305
return;
306
307
308
}
309
int
310
RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info)
311
{
312
313
314
SDL_VERSION(&(info->version));
info->wimpVersion = RISCOS_GetWimpVersion();
info->taskHandle = RISCOS_GetTaskHandle();
315
info->window = this->hidden->window_handle;
316
317
return 1;
318
}
319
320
321
322
323
/* Toggle full screen mode.
Returns 1 if successful otherwise 0
*/
324
int
325
RISCOS_ToggleFullScreen(_THIS, int fullscreen)
326
{
327
if (fullscreen) {
328
return FULLSCREEN_ToggleFromWimp(this);
329
} else {
330
return WIMP_ToggleFromFullScreen(this);
331
332
}
333
return 0;
334
335
}
336
/* vi: set ts=4 sw=4 expandtab: */