Skip to content

Latest commit

 

History

History
342 lines (277 loc) · 9.15 KB

SDL_riscosvideo.c

File metadata and controls

342 lines (277 loc) · 9.15 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 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
Feb 1, 2006
Feb 1, 2006
20
slouken@libsdl.org
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Feb 12, 2005
Feb 12, 2005
25
File added by Alan Buckley (alan_baa@hotmail.com) for RISC OS compatability
26
27
23 March 2003
Feb 12, 2005
Feb 12, 2005
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"
Feb 10, 2006
Feb 10, 2006
35
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
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
51
52
53
54
55
56
57
58
59
60
61
62
#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 */
static int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
static void RISCOS_VideoQuit(_THIS);
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);
/* Hardware surface functions - common to WIMP and FULLSCREEN */
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);
Jun 18, 2019
Jun 18, 2019
63
64
65
66
67
#define MODE_350(type, xdpi, ydpi) \
(1 | (xdpi << 1) | (ydpi << 13) | (type << 27))
#define MODE_521(type, xeig, yeig, flags) \
(0x78000001 | (xeig << 4) | (yeig << 6) | (flags & 0xFF00) | (type << 20))
Jun 1, 2019
Jun 1, 2019
68
69
70
/* Table of known pixel formats */
const RISCOS_SDL_PixelFormat *RISCOS_SDL_PixelFormats = (const RISCOS_SDL_PixelFormat[]) {
/* 8bpp palettized */
Jun 18, 2019
Jun 18, 2019
71
{ { 255, 0x0080, 3, 28 }, 8, 0, 0, 0 },
Jun 1, 2019
Jun 1, 2019
72
/* 12bpp true colour */
Jun 18, 2019
Jun 18, 2019
73
74
{ { 4095, 0x0000, 4, MODE_521(16,1,1,0) }, 12, 0x0f, 0x0f<<4, 0x0f<<8 },
{ { 4095, 0x4000, 4, MODE_521(16,1,1,0x4000) }, 12, 0x0f<<8, 0x0f<<4, 0x0f },
Jun 1, 2019
Jun 1, 2019
75
/* 15bpp true colour */
Jun 18, 2019
Jun 18, 2019
76
77
{ { 65535, 0x0000, 4, MODE_350(5,90,90) }, 15, 0x1f, 0x1f<<5, 0x1f<<10 },
{ { 65535, 0x4000, 4, MODE_521(5,1,1,0x4000) }, 15, 0x1f<<10, 0x1f<<5, 0x1f },
Jun 1, 2019
Jun 1, 2019
78
/* 16bpp true colour */
Jun 18, 2019
Jun 18, 2019
79
80
{ { 65535, 0x0080, 4, MODE_350(10,90,90) }, 16, 0x1f, 0x3f<<5, 0x1f<<11 },
{ { 65535, 0x4080, 4, MODE_521(10,1,1,0x4000) }, 16, 0x1f<<11, 0x3f<<5, 0x1f },
Jun 1, 2019
Jun 1, 2019
81
/* 32bpp true colour */
Jun 18, 2019
Jun 18, 2019
82
83
{ { -1, 0x0000, 5, MODE_350(6,90,90) }, 32, 0xff, 0xff<<8, 0xff<<16 },
{ { -1, 0x4000, 5, MODE_521(6,1,1,0x4000) }, 32, 0xff<<16, 0xff<<8, 0xff },
Jun 1, 2019
Jun 1, 2019
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Terminator */
{ },
};
const RISCOS_SDL_PixelFormat *RISCOS_CurrentPixelFormat()
{
_kernel_swi_regs regs;
int vduvars[4];
const RISCOS_SDL_PixelFormat *fmt;
vduvars[0] = 3; /* NColour */
vduvars[1] = 0; /* ModeFlags */
vduvars[2] = 9; /* Log2BPP */
vduvars[3] = -1;
regs.r[0] = (int) vduvars;
regs.r[1] = (int) vduvars;
_kernel_swi(OS_ReadVduVariables, &regs, &regs);
vduvars[1] &= 0xf280; /* Mask out the bits we don't care about */
fmt = RISCOS_SDL_PixelFormats;
while (fmt->sdl_bpp)
{
if ((fmt->ro.ncolour == vduvars[0]) && (fmt->ro.modeflags == vduvars[1]) && (fmt->ro.log2bpp == vduvars[2]))
{
return fmt;
}
fmt++;
}
return NULL;
}
Feb 12, 2005
Feb 12, 2005
119
/* RISC OS driver bootstrap functions */
120
121
122
123
124
125
126
127
static int RISCOS_Available(void)
{
return(1);
}
static void RISCOS_DeleteDevice(SDL_VideoDevice *device)
{
Feb 7, 2006
Feb 7, 2006
128
129
SDL_free(device->hidden);
SDL_free(device);
130
131
132
133
134
135
136
}
static SDL_VideoDevice *RISCOS_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
137
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
138
if ( device ) {
Feb 7, 2006
Feb 7, 2006
139
SDL_memset(device, 0, (sizeof *device));
140
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
141
SDL_malloc((sizeof *device->hidden));
142
143
144
145
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
Feb 7, 2006
Feb 7, 2006
146
SDL_free(device);
147
148
149
}
return(0);
}
Feb 7, 2006
Feb 7, 2006
150
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* 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;
device->GrabInput = RISCOS_GrabInput;
device->InitOSKeymap = RISCOS_InitOSKeymap;
device->GetWMInfo = RISCOS_GetWmInfo;
device->free = RISCOS_DeleteDevice;
/* 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 */
device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/
/* Set other entries for fullscreen mode */
FULLSCREEN_SetDeviceMode(device);
Dec 23, 2005
Dec 23, 2005
186
187
188
189
190
/* 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;
191
192
193
194
return device;
}
VideoBootStrap RISCOS_bootstrap = {
Feb 12, 2005
Feb 12, 2005
195
RISCOSVID_DRIVER_NAME, "RISC OS video driver",
196
197
198
199
200
201
202
RISCOS_Available, RISCOS_CreateDevice
};
int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
_kernel_swi_regs regs;
Jun 1, 2019
Jun 1, 2019
203
204
205
int vars[3];
const RISCOS_SDL_PixelFormat *fmt;
SDL_PixelFormat *fmt2 = NULL;
206
207
208
209
210
211
if (RISCOS_InitTask() == 0)
{
return 0;
}
Jun 1, 2019
Jun 1, 2019
212
213
214
vars[0] = 11; /* XWndLimit - num x pixels -1 */
vars[1] = 12; /* YWndLimit - num y pixels -1 */
vars[2] = -1; /* Terminate list */
Mar 18, 2006
Mar 18, 2006
215
regs.r[0] = (int)vars;
Jun 1, 2019
Jun 1, 2019
216
regs.r[1] = (int)vars;
Mar 18, 2006
Mar 18, 2006
218
_kernel_swi(OS_ReadVduVariables, &regs, &regs);
Mar 15, 2006
Mar 15, 2006
220
/* Determine the current screen size */
Jun 1, 2019
Jun 1, 2019
221
222
this->info.current_w = vars[0] + 1;
this->info.current_h = vars[1] + 1;
Mar 15, 2006
Mar 15, 2006
223
Jun 1, 2019
Jun 1, 2019
224
225
226
227
228
229
230
231
232
233
234
fmt = RISCOS_CurrentPixelFormat();
if (fmt != NULL)
{
fmt2 = SDL_AllocFormat(fmt->sdl_bpp,fmt->rmask,fmt->gmask,fmt->bmask,0);
}
if (fmt2 != NULL)
{
*vformat = *fmt2;
SDL_free(fmt2);
}
else
Jun 1, 2019
Jun 1, 2019
236
237
238
239
240
241
/* Panic! */
vformat->BitsPerPixel = 8;
vformat->Bmask = 0;
vformat->Gmask = 0;
vformat->Rmask = 0;
vformat->BytesPerPixel = 1;
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
}
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
/* We're done! */
return(0);
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
void RISCOS_VideoQuit(_THIS)
{
RISCOS_ExitTask();
Feb 7, 2006
Feb 7, 2006
258
if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank);
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
this->hidden->alloc_bank = 0;
}
SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
if (flags & SDL_FULLSCREEN)
{
/* Build mode list when first required. */
if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this);
return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
} else
return (SDL_Rect **)-1;
}
/* Set up video mode */
SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
if (flags & SDL_FULLSCREEN)
{
RISCOS_StoreWimpMode();
/* Dump wimp window on switch to full screen */
if (this->hidden->window_handle) WIMP_DeleteWindow(this);
return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags);
} else
{
RISCOS_RestoreWimpMode();
return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
}
}
/* We don't actually allow hardware surfaces other than the main one */
static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
/* We need to wait for vertical retrace on page flipped displays */
static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info)
{
SDL_VERSION(&(info->version));
info->wimpVersion = RISCOS_GetWimpVersion();
info->taskHandle = RISCOS_GetTaskHandle();
info->window = this->hidden->window_handle;
return 1;
}
/* Toggle full screen mode.
Returns 1 if successful otherwise 0
*/
int RISCOS_ToggleFullScreen(_THIS, int fullscreen)
{
if (fullscreen)
{
return FULLSCREEN_ToggleFromWimp(this);
} else
{
return WIMP_ToggleFromFullScreen(this);
}
return 0;
}