comparison src/video/riscos/SDL_riscostask.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
56 56
57 extern int mouseInWindow; /* Mouse is in WIMP window */ 57 extern int mouseInWindow; /* Mouse is in WIMP window */
58 58
59 /* Local function */ 59 /* Local function */
60 60
61 static int RISCOS_GetTaskName (char *task_name, size_t maxlen); 61 static int RISCOS_GetTaskName(char *task_name, size_t maxlen);
62 62
63 /* Uncomment next line to copy mode changes/restores to stderr */ 63 /* Uncomment next line to copy mode changes/restores to stderr */
64 /* #define DUMP_MODE */ 64 /* #define DUMP_MODE */
65 #ifdef DUMP_MODE 65 #ifdef DUMP_MODE
66 #include "stdio.h" 66 #include "stdio.h"
67 static void 67 static void
68 dump_mode () 68 dump_mode()
69 { 69 {
70 fprintf (stderr, "mode %d\n", stored_mode); 70 fprintf(stderr, "mode %d\n", stored_mode);
71 if (stored_mode < -1 || stored_mode >= 256) { 71 if (stored_mode < -1 || stored_mode >= 256) {
72 int blockSize = 0; 72 int blockSize = 0;
73 int *storeBlock = (int *) stored_mode; 73 int *storeBlock = (int *) stored_mode;
74 74
75 while (blockSize < 5 || storeBlock[blockSize] != -1) { 75 while (blockSize < 5 || storeBlock[blockSize] != -1) {
76 fprintf (stderr, " %d\n", storeBlock[blockSize++]); 76 fprintf(stderr, " %d\n", storeBlock[blockSize++]);
77 } 77 }
78 } 78 }
79 } 79 }
80 #endif 80 #endif
81 81
84 Initialise as RISC OS Wimp task 84 Initialise as RISC OS Wimp task
85 85
86 *******************************************************************/ 86 *******************************************************************/
87 87
88 int 88 int
89 RISCOS_InitTask () 89 RISCOS_InitTask()
90 { 90 {
91 char task_name[32]; 91 char task_name[32];
92 _kernel_swi_regs regs; 92 _kernel_swi_regs regs;
93 int messages[4]; 93 int messages[4];
94 94
95 if (RISCOS_GetTaskName (task_name, SDL_arraysize (task_name)) == 0) 95 if (RISCOS_GetTaskName(task_name, SDL_arraysize(task_name)) == 0)
96 return 0; 96 return 0;
97 97
98 messages[0] = 9; /* Palette changed */ 98 messages[0] = 9; /* Palette changed */
99 messages[1] = 0x400c1; /* Mode changed */ 99 messages[1] = 0x400c1; /* Mode changed */
100 messages[2] = 8; /* Pre quit */ 100 messages[2] = 8; /* Pre quit */
103 regs.r[0] = (unsigned int) 360; /* Minimum version 3.6 */ 103 regs.r[0] = (unsigned int) 360; /* Minimum version 3.6 */
104 regs.r[1] = (unsigned int) 0x4b534154; 104 regs.r[1] = (unsigned int) 0x4b534154;
105 regs.r[2] = (unsigned int) task_name; 105 regs.r[2] = (unsigned int) task_name;
106 regs.r[3] = (unsigned int) messages; 106 regs.r[3] = (unsigned int) messages;
107 107
108 if (_kernel_swi (Wimp_Initialise, &regs, &regs) == 0) { 108 if (_kernel_swi(Wimp_Initialise, &regs, &regs) == 0) {
109 wimp_version = regs.r[0]; 109 wimp_version = regs.r[0];
110 task_handle = regs.r[1]; 110 task_handle = regs.r[1];
111 return 1; 111 return 1;
112 } 112 }
113 #if !SDL_THREADS_DISABLED 113 #if !SDL_THREADS_DISABLED
114 main_thread = pthread_self (); 114 main_thread = pthread_self();
115 #endif 115 #endif
116 116
117 return 0; 117 return 0;
118 } 118 }
119 119
122 Close down application on exit. 122 Close down application on exit.
123 123
124 **********************************************************************/ 124 **********************************************************************/
125 125
126 void 126 void
127 RISCOS_ExitTask () 127 RISCOS_ExitTask()
128 { 128 {
129 _kernel_swi_regs regs; 129 _kernel_swi_regs regs;
130 130
131 if (stored_mode == -1) { 131 if (stored_mode == -1) {
132 /* Ensure cursor is put back to standard pointer shape if 132 /* Ensure cursor is put back to standard pointer shape if
133 we have been running in a window */ 133 we have been running in a window */
134 _kernel_osbyte (106, 1, 0); 134 _kernel_osbyte(106, 1, 0);
135 } 135 }
136 136
137 /* Ensure we end up back in the wimp */ 137 /* Ensure we end up back in the wimp */
138 RISCOS_RestoreWimpMode (); 138 RISCOS_RestoreWimpMode();
139 139
140 /* Neatly exit the task */ 140 /* Neatly exit the task */
141 regs.r[0] = task_handle; 141 regs.r[0] = task_handle;
142 regs.r[1] = (unsigned int) 0x4b534154; 142 regs.r[1] = (unsigned int) 0x4b534154;
143 _kernel_swi (Wimp_CloseDown, &regs, &regs); 143 _kernel_swi(Wimp_CloseDown, &regs, &regs);
144 task_handle = 0; 144 task_handle = 0;
145 } 145 }
146 146
147 /************************************************************************** 147 /**************************************************************************
148 148
176 1 Show close icon 176 1 Show close icon
177 177
178 ***************************************************************************/ 178 ***************************************************************************/
179 179
180 int 180 int
181 RISCOS_GetTaskName (char *task_name, size_t maxlen) 181 RISCOS_GetTaskName(char *task_name, size_t maxlen)
182 { 182 {
183 _kernel_swi_regs regs; 183 _kernel_swi_regs regs;
184 184
185 task_name[0] = 0; 185 task_name[0] = 0;
186 186
187 /* Figure out a sensible task name */ 187 /* Figure out a sensible task name */
188 if (_kernel_swi (OS_GetEnv, &regs, &regs) == 0) { 188 if (_kernel_swi(OS_GetEnv, &regs, &regs) == 0) {
189 char *command_line = (char *) regs.r[0]; 189 char *command_line = (char *) regs.r[0];
190 size_t len = SDL_strlen (command_line) + 1; 190 size_t len = SDL_strlen(command_line) + 1;
191 char *buffer = SDL_stack_alloc (char, len); 191 char *buffer = SDL_stack_alloc(char, len);
192 char *env_var; 192 char *env_var;
193 char *p; 193 char *p;
194 194
195 SDL_strlcpy (buffer, command_line, len); 195 SDL_strlcpy(buffer, command_line, len);
196 p = SDL_strchr (buffer, ' '); 196 p = SDL_strchr(buffer, ' ');
197 if (p) 197 if (p)
198 *p = 0; 198 *p = 0;
199 p = SDL_strrchr (buffer, '.'); 199 p = SDL_strrchr(buffer, '.');
200 if (p == 0) 200 if (p == 0)
201 p = buffer; 201 p = buffer;
202 if (stricmp (p + 1, "!RunImage") == 0) { 202 if (stricmp(p + 1, "!RunImage") == 0) {
203 *p = 0; 203 *p = 0;
204 p = SDL_strrchr (buffer, '.'); 204 p = SDL_strrchr(buffer, '.');
205 if (p == 0) 205 if (p == 0)
206 p = buffer; 206 p = buffer;
207 } 207 }
208 if (*p == '.') 208 if (*p == '.')
209 p++; 209 p++;
210 if (*p == '!') 210 if (*p == '!')
211 p++; /* Skip "!" at beginning of application directories */ 211 p++; /* Skip "!" at beginning of application directories */
212 212
213 if (*p == '<') { 213 if (*p == '<') {
214 // Probably in the form <appname$Dir> 214 // Probably in the form <appname$Dir>
215 char *q = SDL_strchr (p, '$'); 215 char *q = SDL_strchr(p, '$');
216 if (q == 0) 216 if (q == 0)
217 q = SDL_strchr (p, '>'); /* Use variable name if not */ 217 q = SDL_strchr(p, '>'); /* Use variable name if not */
218 if (q) 218 if (q)
219 *q = 0; 219 *q = 0;
220 p++; /* Move over the < */ 220 p++; /* Move over the < */
221 } 221 }
222 222
223 if (*p) { 223 if (*p) {
224 /* Read variables that effect the RISC OS SDL engine for this task */ 224 /* Read variables that effect the RISC OS SDL engine for this task */
225 len = SDL_strlen (p) + 18; /* 18 is larger than the biggest variable name */ 225 len = SDL_strlen(p) + 18; /* 18 is larger than the biggest variable name */
226 env_var = SDL_stack_alloc (char, len); 226 env_var = SDL_stack_alloc(char, len);
227 if (env_var) { 227 if (env_var) {
228 char *env_val; 228 char *env_val;
229 229
230 /* See if a variable of form SDL$<dirname>$TaskName exists */ 230 /* See if a variable of form SDL$<dirname>$TaskName exists */
231 231
232 SDL_strlcpy (env_var, "SDL$", len); 232 SDL_strlcpy(env_var, "SDL$", len);
233 SDL_strlcat (env_var, p, len); 233 SDL_strlcat(env_var, p, len);
234 SDL_strlcat (env_var, "$TaskName", len); 234 SDL_strlcat(env_var, "$TaskName", len);
235 235
236 env_val = SDL_getenv (env_var); 236 env_val = SDL_getenv(env_var);
237 if (env_val) 237 if (env_val)
238 SDL_strlcpy (task_name, env_val, maxlen); 238 SDL_strlcpy(task_name, env_val, maxlen);
239 239
240 SDL_strlcpy (env_var, "SDL$", len); 240 SDL_strlcpy(env_var, "SDL$", len);
241 SDL_strlcat (env_var, p, len); 241 SDL_strlcat(env_var, p, len);
242 SDL_strlcat (env_var, "$BackBuffer", len); 242 SDL_strlcat(env_var, "$BackBuffer", len);
243 243
244 env_val = SDL_getenv (env_var); 244 env_val = SDL_getenv(env_var);
245 if (env_val) 245 if (env_val)
246 riscos_backbuffer = atoi (env_val); 246 riscos_backbuffer = atoi(env_val);
247 247
248 SDL_strlcpy (env_var, "SDL$", len); 248 SDL_strlcpy(env_var, "SDL$", len);
249 SDL_strlcat (env_var, p, len); 249 SDL_strlcat(env_var, p, len);
250 SDL_strlcat (env_var, "$CloseAction", len); 250 SDL_strlcat(env_var, "$CloseAction", len);
251 251
252 env_val = SDL_getenv (env_var); 252 env_val = SDL_getenv(env_var);
253 if (env_val && SDL_strcmp (env_val, "0") == 0) 253 if (env_val && SDL_strcmp(env_val, "0") == 0)
254 riscos_closeaction = 0; 254 riscos_closeaction = 0;
255 255
256 SDL_stack_free (env_var); 256 SDL_stack_free(env_var);
257 } 257 }
258 258
259 if (!*task_name) 259 if (!*task_name)
260 SDL_strlcpy (task_name, p, maxlen); 260 SDL_strlcpy(task_name, p, maxlen);
261 } 261 }
262 262
263 SDL_stack_free (buffer); 263 SDL_stack_free(buffer);
264 } 264 }
265 265
266 if (task_name[0] == 0) 266 if (task_name[0] == 0)
267 SDL_strlcpy (task_name, "SDL Task", maxlen); 267 SDL_strlcpy(task_name, "SDL Task", maxlen);
268 268
269 return 1; 269 return 1;
270 } 270 }
271 271
272 /***************************************************************** 272 /*****************************************************************
274 Store the current desktop screen mode if we are in the desktop. 274 Store the current desktop screen mode if we are in the desktop.
275 275
276 ******************************************************************/ 276 ******************************************************************/
277 277
278 void 278 void
279 RISCOS_StoreWimpMode () 279 RISCOS_StoreWimpMode()
280 { 280 {
281 _kernel_swi_regs regs; 281 _kernel_swi_regs regs;
282 282
283 /* Don't store if in full screen mode */ 283 /* Don't store if in full screen mode */
284 if (stored_mode != -1) 284 if (stored_mode != -1)
285 return; 285 return;
286 286
287 regs.r[0] = 1; 287 regs.r[0] = 1;
288 _kernel_swi (OS_ScreenMode, &regs, &regs); 288 _kernel_swi(OS_ScreenMode, &regs, &regs);
289 if (regs.r[1] >= 0 && regs.r[1] < 256) 289 if (regs.r[1] >= 0 && regs.r[1] < 256)
290 stored_mode = regs.r[1]; 290 stored_mode = regs.r[1];
291 else { 291 else {
292 int blockSize = 0; 292 int blockSize = 0;
293 int *retBlock = (int *) regs.r[1]; 293 int *retBlock = (int *) regs.r[1];
295 int j; 295 int j;
296 296
297 while (blockSize < 5 || retBlock[blockSize] != -1) 297 while (blockSize < 5 || retBlock[blockSize] != -1)
298 blockSize++; 298 blockSize++;
299 blockSize++; 299 blockSize++;
300 storeBlock = (int *) SDL_malloc (blockSize * sizeof (int)); 300 storeBlock = (int *) SDL_malloc(blockSize * sizeof(int));
301 retBlock = (int *) regs.r[1]; 301 retBlock = (int *) regs.r[1];
302 for (j = 0; j < blockSize; j++) 302 for (j = 0; j < blockSize; j++)
303 storeBlock[j] = retBlock[j]; 303 storeBlock[j] = retBlock[j];
304 304
305 stored_mode = (int) storeBlock; 305 stored_mode = (int) storeBlock;
306 } 306 }
307 #if DUMP_MODE 307 #if DUMP_MODE
308 fprintf (stderr, "Stored "); 308 fprintf(stderr, "Stored ");
309 dump_mode (); 309 dump_mode();
310 #endif 310 #endif
311 } 311 }
312 312
313 /***************************************************************** 313 /*****************************************************************
314 314
315 Restore desktop screen mode if we are in full screen mode. 315 Restore desktop screen mode if we are in full screen mode.
316 316
317 *****************************************************************/ 317 *****************************************************************/
318 318
319 void 319 void
320 RISCOS_RestoreWimpMode () 320 RISCOS_RestoreWimpMode()
321 { 321 {
322 _kernel_swi_regs regs; 322 _kernel_swi_regs regs;
323 323
324 /* Only need to restore if we are in full screen mode */ 324 /* Only need to restore if we are in full screen mode */
325 if (stored_mode == -1) 325 if (stored_mode == -1)
326 return; 326 return;
327 327
328 #if DUMP_MODE 328 #if DUMP_MODE
329 fprintf (stderr, "Restored"); 329 fprintf(stderr, "Restored");
330 dump_mode (); 330 dump_mode();
331 #endif 331 #endif
332 332
333 regs.r[0] = stored_mode; 333 regs.r[0] = stored_mode;
334 _kernel_swi (Wimp_SetMode, &regs, &regs); 334 _kernel_swi(Wimp_SetMode, &regs, &regs);
335 if (stored_mode < 0 || stored_mode > 256) { 335 if (stored_mode < 0 || stored_mode > 256) {
336 SDL_free ((int *) stored_mode); 336 SDL_free((int *) stored_mode);
337 } 337 }
338 stored_mode = -1; 338 stored_mode = -1;
339 339
340 /* Flush keyboard buffer to dump the keystrokes we've already polled */ 340 /* Flush keyboard buffer to dump the keystrokes we've already polled */
341 regs.r[0] = 21; 341 regs.r[0] = 21;
342 regs.r[1] = 0; /* Keyboard buffer number */ 342 regs.r[1] = 0; /* Keyboard buffer number */
343 _kernel_swi (OS_Byte, &regs, &regs); 343 _kernel_swi(OS_Byte, &regs, &regs);
344 344
345 mouseInWindow = 0; 345 mouseInWindow = 0;
346 346
347 } 347 }
348 348
351 Get version of Wimp running when task was initialised. 351 Get version of Wimp running when task was initialised.
352 352
353 *********************************************************************/ 353 *********************************************************************/
354 354
355 int 355 int
356 RISCOS_GetWimpVersion () 356 RISCOS_GetWimpVersion()
357 { 357 {
358 return wimp_version; 358 return wimp_version;
359 } 359 }
360 360
361 int 361 int
362 RISCOS_GetTaskHandle () 362 RISCOS_GetTaskHandle()
363 { 363 {
364 return task_handle; 364 return task_handle;
365 } 365 }
366 366
367 /* vi: set ts=4 sw=4 expandtab: */ 367 /* vi: set ts=4 sw=4 expandtab: */