annotate src/timer/riscos/SDL_systimer.c @ 1095:f10892fa2e48

XBIOS in interrupt not usable under MiNT
author Patrice Mandin <patmandin@gmail.com>
date Wed, 20 Jul 2005 17:39:10 +0000
parents 974ba6ae0fa3
children c9b51268668f
rev   line source
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
769
b8d311d90021 Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents: 630
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@devolution.com
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id$";
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include <stdio.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include <time.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include <sys/time.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <unistd.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #include <string.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include <errno.h>
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "SDL_error.h"
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_timer.h"
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_timer_c.h"
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
39 #ifdef DISABLE_THREADS
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 /* Timer start/reset time */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 static Uint32 timerStart;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 /* Timer running function */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 void RISCOS_CheckTimer();
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
44 #else
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
45 #include <pthread.h>
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
46 extern Uint32 riscos_main_thread;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
47 extern int riscos_using_threads;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
48 extern Uint32 SDL_ThreadID();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
49 extern Uint32 SDL_EventThreadID(void);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
50 #endif
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
51
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 extern void RISCOS_BackgroundTasks(void);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 /* The first ticks value of the application */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 clock_t start;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 void SDL_StartTicks(void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* Set first ticks value */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 start = clock();
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 Uint32 SDL_GetTicks (void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 clock_t ticks;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 ticks=clock()-start;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #if CLOCKS_PER_SEC == 1000
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 return(ticks);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 #elif CLOCKS_PER_SEC == 100
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 return (ticks * 10);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 #else
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 return ticks*(1000/CLOCKS_PER_SEC);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #endif
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 void SDL_Delay (Uint32 ms)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 Uint32 now,then,elapsed;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
90 #ifndef DISABLE_THREADS
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
91 int is_event_thread;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
92 if (riscos_using_threads)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
93 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
94 is_event_thread = 0;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
95 if (SDL_EventThreadID())
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
96 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
97 if (SDL_EventThreadID() == SDL_ThreadID()) is_event_thread = 1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
98 } else if (SDL_ThreadID() == riscos_main_thread) is_event_thread = 1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
99 } else is_event_thread = 1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
100 #endif
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
101
1035
974ba6ae0fa3 Date: Wed, 26 Jan 2005 13:37:09 GMT
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
102 /*TODO: Next version of Unixlib may allow us to use usleep here */
974ba6ae0fa3 Date: Wed, 26 Jan 2005 13:37:09 GMT
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
103 /* for non event threads */
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 /* Set the timeout interval - Linux only needs to do this once */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 then = SDL_GetTicks();
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 do {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 /* Do background tasks required while sleeping as we are not multithreaded */
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
110 #ifdef DISABLE_THREADS
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 RISCOS_BackgroundTasks();
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
112 #else
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
113 /* For threaded build only run background tasks in event thread */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
114 if (is_event_thread) RISCOS_BackgroundTasks();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
115 #endif
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
116
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 /* Calculate the time interval left (in case of interrupt) */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 now = SDL_GetTicks();
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 elapsed = (now-then);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 then = now;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if ( elapsed >= ms ) {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 break;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 ms -= elapsed;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
125 #ifndef DISABLE_THREADS
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
126 /* Need to yield to let other threads have a go */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
127 if (riscos_using_threads) pthread_yield();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
128 #endif
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 } while ( 1 );
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
133 #ifdef DISABLE_THREADS
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
134
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
135 /* Non-threaded version of timer */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
136
630
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 int SDL_SYS_TimerInit(void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 return(0);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 void SDL_SYS_TimerQuit(void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 SDL_SetTimer(0, NULL);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 int SDL_SYS_StartTimer(void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 timerStart = SDL_GetTicks();
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 return(0);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 void SDL_SYS_StopTimer(void)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 /* Don't need to do anything as we use SDL_timer_running
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 to detect if we need to check the timer */
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 void RISCOS_CheckTimer()
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval)
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 Uint32 ms;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 ms = SDL_alarm_callback(SDL_alarm_interval);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 if ( ms != SDL_alarm_interval )
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 if ( ms )
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 SDL_alarm_interval = ROUND_RESOLUTION(ms);
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 } else
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 {
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 SDL_alarm_interval = 0;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 SDL_timer_running = 0;
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 if (SDL_alarm_interval) timerStart = SDL_GetTicks();
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
550bccdf04bd Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
182
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
183 #else
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
184
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
185 /* Threaded version of timer - based on code for linux */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
186
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
187 #include "SDL_thread.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
188
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
189 /* Data to handle a single periodic alarm */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
190 static int timer_alive = 0;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
191 static SDL_Thread *timer = NULL;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
192
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
193 static int RunTimer(void *unused)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
194 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
195 while ( timer_alive ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
196 if ( SDL_timer_running ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
197 SDL_ThreadedTimerCheck();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
198 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
199 SDL_Delay(1);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
200 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
201 return(0);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
202 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
203
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
204 /* This is only called if the event thread is not running */
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
205 int SDL_SYS_TimerInit(void)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
206 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
207 timer_alive = 1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
208 timer = SDL_CreateThread(RunTimer, NULL);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
209 if ( timer == NULL )
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
210 return(-1);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
211 return(SDL_SetTimerThreaded(1));
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
212 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
213
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
214 void SDL_SYS_TimerQuit(void)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
215 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
216 timer_alive = 0;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
217 if ( timer ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
218 SDL_WaitThread(timer, NULL);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
219 timer = NULL;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
220 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
221 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
222
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
223 int SDL_SYS_StartTimer(void)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
224 {
1035
974ba6ae0fa3 Date: Wed, 26 Jan 2005 13:37:09 GMT
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
225 SDL_SetError("Internal logic error: RISC OS uses threaded timer");
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
226 return(-1);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
227 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
228
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
229 void SDL_SYS_StopTimer(void)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
230 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
231 return;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
232 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
233
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
234 #endif /* DISABLE_THREADS */