comparison src/video/riscos/SDL_riscostask.c @ 1895:c121d94672cb

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