Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
367 lines (282 loc) · 10.1 KB

SDL_riscostask.c

File metadata and controls

367 lines (282 loc) · 10.1 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 4, 2004
Jan 4, 2004
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
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
This file added by Alan Buckley (alan_baa@hotmail.com) to support RISC OS
26
27
28
29
30
31
32
33
34
35
36
37
26 March 2003
File includes routines for:
Setting up as a WIMP Task
Reading information about the current desktop
Storing information before a switch to full screen
Restoring desktop after switching to full screen
*/
#include "kernel.h"
#include "swis.h"
Feb 10, 2006
Feb 10, 2006
38
#include "SDL_stdinc.h"
39
40
#include "SDL_riscostask.h"
Feb 16, 2006
Feb 16, 2006
41
#if !SDL_THREADS_DISABLED
Sep 17, 2004
Sep 17, 2004
42
43
44
45
#include <pthread.h>
pthread_t main_thread;
#endif
Feb 12, 2005
Feb 12, 2005
46
/* RISC OS variables */
47
48
49
50
51
static int task_handle = 0;
static int wimp_version = 0;
/* RISC OS variables to help compatability with certain programs */
May 28, 2006
May 28, 2006
52
53
int riscos_backbuffer = 0; /* Create a back buffer in system memory for full screen mode */
int riscos_closeaction = 1; /* Close icon action */
May 28, 2006
May 28, 2006
55
static int stored_mode = -1; /* -1 when in desktop, mode number or pointer when full screen */
May 28, 2006
May 28, 2006
57
extern int mouseInWindow; /* Mouse is in WIMP window */
58
59
60
/* Local function */
May 29, 2006
May 29, 2006
61
static int RISCOS_GetTaskName(char *task_name, size_t maxlen);
62
63
64
65
66
/* Uncomment next line to copy mode changes/restores to stderr */
/* #define DUMP_MODE */
#ifdef DUMP_MODE
#include "stdio.h"
May 28, 2006
May 28, 2006
67
static void
May 29, 2006
May 29, 2006
68
dump_mode()
May 29, 2006
May 29, 2006
70
fprintf(stderr, "mode %d\n", stored_mode);
May 28, 2006
May 28, 2006
71
if (stored_mode < -1 || stored_mode >= 256) {
72
int blockSize = 0;
May 28, 2006
May 28, 2006
73
int *storeBlock = (int *) stored_mode;
May 28, 2006
May 28, 2006
75
while (blockSize < 5 || storeBlock[blockSize] != -1) {
May 29, 2006
May 29, 2006
76
fprintf(stderr, " %d\n", storeBlock[blockSize++]);
77
78
79
80
81
82
83
}
}
}
#endif
/******************************************************************
Feb 12, 2005
Feb 12, 2005
84
Initialise as RISC OS Wimp task
85
86
87
*******************************************************************/
May 28, 2006
May 28, 2006
88
int
May 29, 2006
May 29, 2006
89
RISCOS_InitTask()
May 28, 2006
May 28, 2006
91
92
93
94
char task_name[32];
_kernel_swi_regs regs;
int messages[4];
May 29, 2006
May 29, 2006
95
if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0)
May 28, 2006
May 28, 2006
96
97
98
99
100
101
102
103
104
105
106
return 0;
messages[0] = 9; /* Palette changed */
messages[1] = 0x400c1; /* Mode changed */
messages[2] = 8; /* Pre quit */
messages[2] = 0;
regs.r[0] = (unsigned int) 360; /* Minimum version 3.6 */
regs.r[1] = (unsigned int) 0x4b534154;
regs.r[2] = (unsigned int) task_name;
regs.r[3] = (unsigned int) messages;
May 29, 2006
May 29, 2006
108
if (_kernel_swi(Wimp_Initialise, &regs, &regs) == 0) {
May 28, 2006
May 28, 2006
109
110
111
112
wimp_version = regs.r[0];
task_handle = regs.r[1];
return 1;
}
Feb 16, 2006
Feb 16, 2006
113
#if !SDL_THREADS_DISABLED
May 29, 2006
May 29, 2006
114
main_thread = pthread_self();
Sep 17, 2004
Sep 17, 2004
115
116
#endif
May 28, 2006
May 28, 2006
117
return 0;
118
119
120
121
122
123
124
125
}
/*********************************************************************
Close down application on exit.
**********************************************************************/
May 28, 2006
May 28, 2006
126
void
May 29, 2006
May 29, 2006
127
RISCOS_ExitTask()
May 28, 2006
May 28, 2006
129
_kernel_swi_regs regs;
May 28, 2006
May 28, 2006
131
132
133
if (stored_mode == -1) {
/* Ensure cursor is put back to standard pointer shape if
we have been running in a window */
May 29, 2006
May 29, 2006
134
_kernel_osbyte(106, 1, 0);
May 28, 2006
May 28, 2006
137
/* Ensure we end up back in the wimp */
May 29, 2006
May 29, 2006
138
RISCOS_RestoreWimpMode();
May 28, 2006
May 28, 2006
140
141
142
/* Neatly exit the task */
regs.r[0] = task_handle;
regs.r[1] = (unsigned int) 0x4b534154;
May 29, 2006
May 29, 2006
143
_kernel_swi(Wimp_CloseDown, &regs, &regs);
May 28, 2006
May 28, 2006
144
task_handle = 0;
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
}
/**************************************************************************
Get the name of the task for the desktop.
Param: task_name - name of task 32 characters.
Returns: 1 is successful, otherwise 0
Notes: Works by getting using OS_GetEnv to get the command line
used to run the program and then parsing a name from it
as follows.
1. Use name after final period if not !RunImage
2. If name is !RunImage then process item before the period
in front of !RunImage.
3. If directory name use that
4. if in form <XXX$Dir> use the XXX.
Finally once this value has been retrieved use it unless
there is a variable set up in the form SDL$<name>$TaskName
in which case the value of this variable will be used.
Feb 12, 2005
Feb 12, 2005
169
Now also gets other RISC OS configuration varibles
170
171
172
173
174
175
176
177
178
179
SDL$<name>$BackBuffer - set to 1 to use a system memory backbuffer in fullscreen mode
so updates wait until a call to SDL_UpdateRects. (default 0)
This is required for programmes where they have assumed this is
always the case which is contrary to the documentation.
SDL$<name>$CloseAction
0 Don't show close icon
1 Show close icon
***************************************************************************/
May 28, 2006
May 28, 2006
180
int
May 29, 2006
May 29, 2006
181
RISCOS_GetTaskName(char *task_name, size_t maxlen)
May 28, 2006
May 28, 2006
183
184
185
186
187
_kernel_swi_regs regs;
task_name[0] = 0;
/* Figure out a sensible task name */
May 29, 2006
May 29, 2006
188
if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0) {
May 28, 2006
May 28, 2006
189
char *command_line = (char *) regs.r[0];
May 29, 2006
May 29, 2006
190
191
size_t len = SDL_strlen(command_line) + 1;
char *buffer = SDL_stack_alloc(char, len);
May 28, 2006
May 28, 2006
192
193
194
char *env_var;
char *p;
May 29, 2006
May 29, 2006
195
196
SDL_strlcpy(buffer, command_line, len);
p = SDL_strchr(buffer, ' ');
May 28, 2006
May 28, 2006
197
198
if (p)
*p = 0;
May 29, 2006
May 29, 2006
199
p = SDL_strrchr(buffer, '.');
May 28, 2006
May 28, 2006
200
201
if (p == 0)
p = buffer;
May 29, 2006
May 29, 2006
202
if (stricmp(p + 1, "!RunImage") == 0) {
May 28, 2006
May 28, 2006
203
*p = 0;
May 29, 2006
May 29, 2006
204
p = SDL_strrchr(buffer, '.');
May 28, 2006
May 28, 2006
205
206
207
208
209
210
211
212
213
214
if (p == 0)
p = buffer;
}
if (*p == '.')
p++;
if (*p == '!')
p++; /* Skip "!" at beginning of application directories */
if (*p == '<') {
// Probably in the form <appname$Dir>
May 29, 2006
May 29, 2006
215
char *q = SDL_strchr(p, '$');
May 28, 2006
May 28, 2006
216
if (q == 0)
May 29, 2006
May 29, 2006
217
q = SDL_strchr(p, '>'); /* Use variable name if not */
May 28, 2006
May 28, 2006
218
219
220
221
222
223
224
if (q)
*q = 0;
p++; /* Move over the < */
}
if (*p) {
/* Read variables that effect the RISC OS SDL engine for this task */
May 29, 2006
May 29, 2006
225
226
len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */
env_var = SDL_stack_alloc(char, len);
May 28, 2006
May 28, 2006
227
228
229
230
231
if (env_var) {
char *env_val;
/* See if a variable of form SDL$<dirname>$TaskName exists */
May 29, 2006
May 29, 2006
232
233
234
SDL_strlcpy(env_var, "SDL$", len);
SDL_strlcat(env_var, p, len);
SDL_strlcat(env_var, "$TaskName", len);
May 28, 2006
May 28, 2006
235
May 29, 2006
May 29, 2006
236
env_val = SDL_getenv(env_var);
May 28, 2006
May 28, 2006
237
if (env_val)
May 29, 2006
May 29, 2006
238
SDL_strlcpy(task_name, env_val, maxlen);
May 28, 2006
May 28, 2006
239
May 29, 2006
May 29, 2006
240
241
242
SDL_strlcpy(env_var, "SDL$", len);
SDL_strlcat(env_var, p, len);
SDL_strlcat(env_var, "$BackBuffer", len);
May 28, 2006
May 28, 2006
243
May 29, 2006
May 29, 2006
244
env_val = SDL_getenv(env_var);
May 28, 2006
May 28, 2006
245
if (env_val)
May 29, 2006
May 29, 2006
246
riscos_backbuffer = atoi(env_val);
May 28, 2006
May 28, 2006
247
May 29, 2006
May 29, 2006
248
249
250
SDL_strlcpy(env_var, "SDL$", len);
SDL_strlcat(env_var, p, len);
SDL_strlcat(env_var, "$CloseAction", len);
May 28, 2006
May 28, 2006
251
May 29, 2006
May 29, 2006
252
253
env_val = SDL_getenv(env_var);
if (env_val && SDL_strcmp(env_val, "0") == 0)
May 28, 2006
May 28, 2006
254
255
riscos_closeaction = 0;
May 29, 2006
May 29, 2006
256
SDL_stack_free(env_var);
May 28, 2006
May 28, 2006
257
258
259
}
if (!*task_name)
May 29, 2006
May 29, 2006
260
SDL_strlcpy(task_name, p, maxlen);
May 28, 2006
May 28, 2006
261
262
}
May 29, 2006
May 29, 2006
263
SDL_stack_free(buffer);
May 28, 2006
May 28, 2006
264
265
266
}
if (task_name[0] == 0)
May 29, 2006
May 29, 2006
267
SDL_strlcpy(task_name, "SDL Task", maxlen);
May 28, 2006
May 28, 2006
268
269
return 1;
270
271
272
273
274
275
276
277
}
/*****************************************************************
Store the current desktop screen mode if we are in the desktop.
******************************************************************/
May 28, 2006
May 28, 2006
278
void
May 29, 2006
May 29, 2006
279
RISCOS_StoreWimpMode()
May 28, 2006
May 28, 2006
281
_kernel_swi_regs regs;
May 28, 2006
May 28, 2006
283
284
285
/* Don't store if in full screen mode */
if (stored_mode != -1)
return;
286
287
regs.r[0] = 1;
May 29, 2006
May 29, 2006
288
_kernel_swi(OS_ScreenMode, &regs, &regs);
May 28, 2006
May 28, 2006
289
290
291
if (regs.r[1] >= 0 && regs.r[1] < 256)
stored_mode = regs.r[1];
else {
292
int blockSize = 0;
May 28, 2006
May 28, 2006
293
294
int *retBlock = (int *) regs.r[1];
int *storeBlock;
295
296
int j;
May 28, 2006
May 28, 2006
297
298
while (blockSize < 5 || retBlock[blockSize] != -1)
blockSize++;
299
blockSize++;
May 29, 2006
May 29, 2006
300
storeBlock = (int *) SDL_malloc(blockSize * sizeof(int));
May 28, 2006
May 28, 2006
301
302
303
retBlock = (int *) regs.r[1];
for (j = 0; j < blockSize; j++)
storeBlock[j] = retBlock[j];
May 28, 2006
May 28, 2006
305
306
stored_mode = (int) storeBlock;
}
307
#if DUMP_MODE
May 29, 2006
May 29, 2006
308
309
fprintf(stderr, "Stored ");
dump_mode();
310
311
312
313
314
315
316
317
318
#endif
}
/*****************************************************************
Restore desktop screen mode if we are in full screen mode.
*****************************************************************/
May 28, 2006
May 28, 2006
319
void
May 29, 2006
May 29, 2006
320
RISCOS_RestoreWimpMode()
321
322
323
{
_kernel_swi_regs regs;
May 28, 2006
May 28, 2006
324
325
326
/* Only need to restore if we are in full screen mode */
if (stored_mode == -1)
return;
327
328
#if DUMP_MODE
May 29, 2006
May 29, 2006
329
330
fprintf(stderr, "Restored");
dump_mode();
331
332
333
#endif
regs.r[0] = stored_mode;
May 29, 2006
May 29, 2006
334
_kernel_swi(Wimp_SetMode, &regs, &regs);
May 28, 2006
May 28, 2006
335
if (stored_mode < 0 || stored_mode > 256) {
May 29, 2006
May 29, 2006
336
SDL_free((int *) stored_mode);
337
338
339
340
341
}
stored_mode = -1;
/* Flush keyboard buffer to dump the keystrokes we've already polled */
regs.r[0] = 21;
May 28, 2006
May 28, 2006
342
regs.r[1] = 0; /* Keyboard buffer number */
May 29, 2006
May 29, 2006
343
_kernel_swi(OS_Byte, &regs, &regs);
344
345
346
347
348
349
350
351
352
353
354
mouseInWindow = 0;
}
/*********************************************************************
Get version of Wimp running when task was initialised.
*********************************************************************/
May 28, 2006
May 28, 2006
355
int
May 29, 2006
May 29, 2006
356
RISCOS_GetWimpVersion()
May 28, 2006
May 28, 2006
358
return wimp_version;
May 28, 2006
May 28, 2006
361
int
May 29, 2006
May 29, 2006
362
RISCOS_GetTaskHandle()
May 28, 2006
May 28, 2006
364
return task_handle;
May 28, 2006
May 28, 2006
366
367
/* vi: set ts=4 sw=4 expandtab: */