]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libsdl/contrib/src/timer/mint/SDL_vbltimer.S
update
[l4.git] / l4 / pkg / libsdl / contrib / src / timer / mint / SDL_vbltimer.S
1 /*
2     SDL - Simple DirectMedia Layer
3     Copyright (C) 1997-2012 Sam Lantinga
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19     Sam Lantinga
20     slouken@libsdl.org
21 */
22
23 /*
24  *      VBL queue routine
25  *
26  *      Patrice Mandin
27  */
28
29 #define _vbl_queue 0x456
30 #define _hz_200    0x4ba
31
32         .text
33
34         .globl  _SDL_AtariVblInstall
35         .globl  _SDL_AtariVblUninstall
36
37         .globl  _SDL_MintAudio_hasfpu
38
39 /*--- Save/restore FPU context ---*/
40
41 #if defined(__mcoldfire__)
42
43 #define SAVE_FPU_CONTEXT \
44         lea             sp@(-216),sp;   \
45         fsave           sp@;    \
46         fmovel          fpiar,sp@-;     \
47         lea             sp@(-64),sp;    \
48         fmovemd fp0-fp7,sp@
49
50 #define RESTORE_FPU_CONTEXT     \
51         fmovemd         sp@,fp0-fp7;    \
52         lea             sp@(64),sp;     \
53         fmovel          sp@+,fpiar;     \
54         frestore        sp@;    \
55         lea             sp@(216),sp
56
57 #else
58
59 #define SAVE_FPU_CONTEXT        \
60         .chip   68k/68881;      \
61         fsave   sp@-;   \
62         fmoveml fpcr/fpsr/fpiar,sp@-;   \
63         fmovemx fp0-fp7,sp@-;   \
64         .chip   68k
65
66 #define RESTORE_FPU_CONTEXT     \
67         .chip   68k/68881;      \
68         fmovemx sp@+,fp0-fp7;   \
69         fmoveml sp@+,fpcr/fpsr/fpiar;   \
70         frestore        sp@+;   \
71         .chip   68k
72
73 #endif
74
75 /*--- Vector installer ---*/
76
77 _SDL_AtariVblInstall:
78 #if defined(__mcoldfire__)
79         movel   sp@(4),d0
80         movel   d0,my_vector
81 #else
82         movel   sp@(4),my_vector
83 #endif
84
85         lea             _my_vbl,a0
86
87         clrw    vbl_mutex
88 #if defined(__mcoldfire__)
89         movel   _hz_200.w,d0
90         movel   d0, _SDL_Atari_hz200
91 #else
92         movel   _hz_200.w, _SDL_Atari_hz200
93 #endif
94
95         /* Stop interrupts */
96
97         movew   #0x2700,sr
98
99         /* Read vbl_queue pointer */
100         movel   _vbl_queue.w,a1
101
102         /* Search a free place */
103         moveq   #7,d0
104 bcl_search_place:
105         movel   (a1),d1
106         beqs    place_found
107         addql   #4,a1
108 #if defined(__mcoldfire__)
109         subql   #1,d0
110         bpls    bcl_search_place
111 #else
112         dbra    d0,bcl_search_place
113 #endif
114
115         /* Not found */
116         moveq   #1,d0
117         bras    exit_vbl_queue
118
119         /* Then install ourselves */
120 place_found:
121         movel   a0,(a1)
122         moveq   #0,d0   
123
124 exit_vbl_queue:
125         /* Restart interrupts */
126         movew   #0x2300,sr
127
128         rts
129
130 /*--- Vector uninstaller ---*/
131
132 _SDL_AtariVblUninstall:
133         movel   sp@(4),d0
134         cmpl    my_vector,d0
135         bnes    badvector
136         
137         movel   #_my_vbl,d0
138
139         /* Stop interrupts */
140
141         movew   #0x2700,sr
142
143         /* Read vbl_queue pointer */
144         movel   _vbl_queue.w,a1
145
146         /* Search where we are */
147         moveq   #7,d1
148 bcl2_search_place:
149         cmpl    (a1),d0
150         bnes    next_place
151         clrl    (a1)
152         moveq   #0,d1
153 next_place:
154         addql   #4,a1
155 #if defined(__mcoldfire__)
156         subql   #1,d1
157         bpls    bcl_search_place
158 #else
159         dbra    d1,bcl2_search_place
160 #endif
161
162         /* Restart interrupts */
163         movew   #0x2300,sr
164 badvector:
165         rts
166
167 /*--- Our vbl ---*/
168
169 _my_vbl:
170 #if defined(__mcoldfire__)
171         lea     sp@(-60),sp
172         moveml  d0-d7/a0-a6,sp@
173 #else
174         moveml  d0-d7/a0-a6,sp@-
175 #endif
176
177         /* Update _hz_200 */
178 #if defined(__mcoldfire__)
179         movel   _hz_200.w,d0
180         movel   d0, _SDL_Atari_hz200
181 #else
182         movel   _hz_200.w, _SDL_Atari_hz200
183 #endif
184
185         /* Verify if this is not already running */
186
187         tstw    vbl_mutex
188         bnes    vbl_end
189 #if defined(__mcoldfire__)
190         movew   vbl_mutex,d0
191         notl    d0
192         movew   d0,vbl_mutex
193 #else
194         notw    vbl_mutex
195 #endif
196
197         /* Save FPU if needed */
198         tstw    _SDL_MintAudio_hasfpu
199         beqs    SDL_AtariVbl_nofpu1
200         SAVE_FPU_CONTEXT
201 SDL_AtariVbl_nofpu1:
202
203         movel   my_vector,a0
204         jsr             a0@
205
206         /* Restore FPU if needed */
207         tstw    _SDL_MintAudio_hasfpu
208         beqs    SDL_AtariVbl_Xbios_nofpu2
209         RESTORE_FPU_CONTEXT
210 SDL_AtariVbl_Xbios_nofpu2:
211
212         clrw    vbl_mutex
213 vbl_end:
214 #if defined(__mcoldfire__)
215         moveml  sp@,d0-d7/a0-a6
216         lea     sp@(60),sp
217 #else
218         moveml  sp@+,d0-d7/a0-a6
219 #endif
220         rts
221
222         .data
223         .even
224         .comm   _SDL_Atari_hz200,4*1
225         .even
226         .comm   vbl_mutex,2*1
227         .even
228         .comm   my_vector,4*1