Rev 431 | Rev 473 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 431 | Rev 465 | ||
---|---|---|---|
1 | $Revision: 431 $ |
1 | $Revision: 465 $ |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; ;; |
3 | ;; ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
4 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
5 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
5 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
6 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;; Distributed under terms of the GNU General Public License ;; |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
8 | 8 | ||
9 | align 4 |
9 | align 4 |
10 | init_events: |
10 | init_events: |
11 | stdcall kernel_alloc, 512*EVENT_SIZE |
11 | stdcall kernel_alloc, 512*EVENT_SIZE |
12 | mov [events], eax |
12 | mov [events], eax |
13 | xor eax, eax |
13 | xor eax, eax |
14 | mov [event_uid], eax |
14 | mov [event_uid], eax |
15 | not eax |
15 | not eax |
16 | mov edi, event_map |
16 | mov edi, event_map |
17 | mov [event_start], edi |
17 | mov [event_start], edi |
18 | mov ecx, 64/4 |
18 | mov ecx, 64/4 |
19 | cld |
19 | cld |
20 | rep stosd |
20 | rep stosd |
21 | mov [event_end], edi |
21 | mov [event_end], edi |
22 | ret |
22 | ret |
23 | 23 | ||
24 | align 4 |
24 | align 4 |
25 | proc alloc_event |
25 | proc alloc_event |
26 | 26 | ||
27 | pushfd |
27 | pushfd |
28 | cli |
28 | cli |
29 | mov ebx, [event_start] |
29 | mov ebx, [event_start] |
30 | mov ecx, [event_end] |
30 | mov ecx, [event_end] |
31 | .l1: |
31 | .l1: |
32 | bsf eax,[ebx] |
32 | bsf eax,[ebx] |
33 | jnz .found |
33 | jnz .found |
34 | add ebx,4 |
34 | add ebx,4 |
35 | cmp ebx, ecx |
35 | cmp ebx, ecx |
36 | jb .l1 |
36 | jb .l1 |
37 | popfd |
37 | popfd |
38 | xor eax,eax |
38 | xor eax,eax |
39 | ret |
39 | ret |
40 | .found: |
40 | .found: |
41 | btr [ebx], eax |
41 | btr [ebx], eax |
42 | mov [event_start],ebx |
42 | mov [event_start],ebx |
43 | inc [event_uid] |
43 | inc [event_uid] |
44 | 44 | ||
45 | sub ebx, event_map |
45 | sub ebx, event_map |
46 | lea eax,[eax+ebx*8] |
46 | lea eax,[eax+ebx*8] |
47 | 47 | ||
48 | lea ebx, [eax+eax*4] |
48 | lea ebx, [eax+eax*4] |
49 | shl eax,5 |
49 | shl eax,5 |
50 | lea eax,[eax+ebx*4] ;eax*=52 (EVENT_SIZE) |
50 | lea eax,[eax+ebx*4] ;eax*=52 (EVENT_SIZE) |
51 | add eax, [events] |
51 | add eax, [events] |
52 | mov ebx, [event_uid] |
52 | mov ebx, [event_uid] |
53 | popfd |
53 | popfd |
54 | ret |
54 | ret |
55 | endp |
55 | endp |
56 | 56 | ||
57 | align 4 |
57 | align 4 |
58 | free_event: |
58 | free_event: |
59 | sub eax, [events] |
59 | sub eax, [events] |
60 | mov ecx, EVENT_SIZE |
60 | mov ecx, EVENT_SIZE |
61 | mov ebx, event_map |
61 | mov ebx, event_map |
62 | cdq |
62 | cdq |
63 | div ecx |
63 | div ecx |
64 | 64 | ||
65 | pushfd |
65 | pushfd |
66 | cli |
66 | cli |
67 | bts [ebx], eax |
67 | bts [ebx], eax |
68 | shr eax, 3 |
68 | shr eax, 3 |
69 | and eax, not 3 |
69 | and eax, not 3 |
70 | add eax, ebx |
70 | add eax, ebx |
71 | cmp [event_start], eax |
71 | cmp [event_start], eax |
72 | ja @f |
72 | ja @f |
73 | popfd |
73 | popfd |
74 | ret |
74 | ret |
75 | @@: |
75 | @@: |
76 | mov [event_start], eax |
76 | mov [event_start], eax |
77 | popfd |
77 | popfd |
78 | ret |
78 | ret |
79 | 79 | ||
80 | EVENT_WATCHED equ 0x10000000 |
80 | EVENT_WATCHED equ 0x10000000 |
81 | EVENT_SIGNALED equ 0x20000000 |
81 | EVENT_SIGNALED equ 0x20000000 |
82 | MANUAL_RESET equ 0x40000000 |
82 | MANUAL_RESET equ 0x40000000 |
83 | MANUAL_DESTROY equ 0x80000000 |
83 | MANUAL_DESTROY equ 0x80000000 |
84 | 84 | ||
85 | 85 | ||
86 | ; param |
86 | ; param |
87 | ; eax= event data |
87 | ; eax= event data |
88 | ; ebx= flags |
88 | ; ebx= flags |
89 | ; |
89 | ; |
90 | ; retval |
90 | ; retval |
91 | ; eax= event |
91 | ; eax= event |
92 | ; edx= id |
92 | ; edx= id |
93 | 93 | ||
94 | create_event: |
94 | create_event: |
95 | .flags equ esp+4 |
95 | .flags equ esp+4 |
96 | .data equ esp |
96 | .data equ esp |
97 | 97 | ||
98 | push ebx |
98 | push ebx |
99 | push eax |
99 | push eax |
100 | 100 | ||
101 | call alloc_event |
101 | call alloc_event |
102 | test eax, eax |
102 | test eax, eax |
103 | jz .fail |
103 | jz .fail |
104 | 104 | ||
105 | mov [eax+APPOBJ.magic], 'EVNT' |
105 | mov [eax+APPOBJ.magic], 'EVNT' |
106 | mov [eax+APPOBJ.destroy], destroy_event.internal |
106 | mov [eax+APPOBJ.destroy], destroy_event.internal |
107 | mov [eax+EVENT.id], ebx |
107 | mov [eax+EVENT.id], ebx |
108 | 108 | ||
109 | mov ebx, [CURRENT_TASK] |
109 | mov ebx, [CURRENT_TASK] |
110 | shl ebx, 5 |
110 | shl ebx, 5 |
111 | mov ebx, [CURRENT_TASK+ebx+4] |
111 | mov ebx, [CURRENT_TASK+ebx+4] |
112 | mov [eax+APPOBJ.pid], ebx |
112 | mov [eax+APPOBJ.pid], ebx |
113 | mov edx, [.flags] |
113 | mov edx, [.flags] |
114 | mov [eax+EVENT.state], edx |
114 | mov [eax+EVENT.state], edx |
115 | 115 | ||
116 | mov esi, [.data] |
116 | mov esi, [.data] |
117 | test esi, esi |
117 | test esi, esi |
118 | jz @F |
118 | jz @F |
119 | lea edi, [eax+EVENT.code] |
119 | lea edi, [eax+EVENT.code] |
120 | mov ecx, 6 |
120 | mov ecx, 6 |
121 | cld |
121 | cld |
122 | rep movsd |
122 | rep movsd |
123 | @@: |
123 | @@: |
124 | mov ecx, [CURRENT_TASK] |
124 | mov ecx, [current_slot] |
125 | shl ecx,8 |
- | |
126 | add ecx, SLOT_BASE+APP_OBJ_OFFSET |
125 | add ecx, APP_OBJ_OFFSET |
127 | 126 | ||
128 | pushfd |
127 | pushfd |
129 | cli |
128 | cli |
130 | mov edx, [ecx+APPOBJ.fd] |
129 | mov edx, [ecx+APPOBJ.fd] |
131 | mov [eax+APPOBJ.fd], edx |
130 | mov [eax+APPOBJ.fd], edx |
132 | mov [eax+APPOBJ.bk], ecx |
131 | mov [eax+APPOBJ.bk], ecx |
133 | mov [ecx+APPOBJ.fd], eax |
132 | mov [ecx+APPOBJ.fd], eax |
134 | mov [edx+APPOBJ.bk], eax |
133 | mov [edx+APPOBJ.bk], eax |
135 | popfd |
134 | popfd |
136 | mov edx, [eax+EVENT.id] |
135 | mov edx, [eax+EVENT.id] |
137 | .fail: |
136 | .fail: |
138 | add esp, 8 |
137 | add esp, 8 |
139 | ret |
138 | ret |
140 | 139 | ||
141 | restore .flags |
140 | restore .flags |
142 | restore .data |
141 | restore .data |
143 | 142 | ||
144 | ; param |
143 | ; param |
145 | ; eax= event |
144 | ; eax= event |
146 | ; ebx= id |
145 | ; ebx= id |
147 | 146 | ||
148 | destroy_event: |
147 | destroy_event: |
149 | 148 | ||
150 | cmp [eax+APPOBJ.magic], 'EVNT' |
149 | cmp [eax+APPOBJ.magic], 'EVNT' |
151 | jne .fail |
150 | jne .fail |
152 | cmp [eax+EVENT.id], ebx |
151 | cmp [eax+EVENT.id], ebx |
153 | jne .fail |
152 | jne .fail |
154 | .internal: |
153 | .internal: |
155 | mov ebx, [eax+APPOBJ.fd] |
154 | mov ebx, [eax+APPOBJ.fd] |
156 | mov ecx, [eax+APPOBJ.bk] |
155 | mov ecx, [eax+APPOBJ.bk] |
157 | mov [ebx+APPOBJ.bk], ecx |
156 | mov [ebx+APPOBJ.bk], ecx |
158 | mov [ecx+APPOBJ.fd], ebx |
157 | mov [ecx+APPOBJ.fd], ebx |
159 | .force: |
158 | .force: |
160 | xor edx, edx ;clear common header |
159 | xor edx, edx ;clear common header |
161 | mov [eax], edx |
160 | mov [eax], edx |
162 | mov [eax+4], edx |
161 | mov [eax+4], edx |
163 | mov [eax+8], edx |
162 | mov [eax+8], edx |
164 | mov [eax+12], edx |
163 | mov [eax+12], edx |
165 | mov [eax+16], edx |
164 | mov [eax+16], edx |
166 | 165 | ||
167 | call free_event ;release object memory |
166 | call free_event ;release object memory |
168 | .fail: |
167 | .fail: |
169 | ret |
168 | ret |
170 | 169 | ||
171 | align 4 |
170 | align 4 |
172 | proc send_event stdcall pid:dword, event:dword |
171 | proc send_event stdcall pid:dword, event:dword |
173 | locals |
172 | locals |
174 | slot dd ? |
173 | slot dd ? |
175 | endl |
174 | endl |
176 | 175 | ||
177 | mov eax, [pid] |
176 | mov eax, [pid] |
178 | call pid_to_slot |
177 | call pid_to_slot |
179 | test eax, eax |
178 | test eax, eax |
180 | jz .fail |
179 | jz .fail |
181 | 180 | ||
182 | shl eax, 8 |
181 | shl eax, 8 |
183 | cmp [SLOT_BASE+eax+APPDATA.ev_count], 32 |
182 | cmp [SLOT_BASE+eax+APPDATA.ev_count], 32 |
184 | ja .fail |
183 | ja .fail |
185 | 184 | ||
186 | mov [slot], eax |
185 | mov [slot], eax |
187 | 186 | ||
188 | call alloc_event |
187 | call alloc_event |
189 | test eax, eax |
188 | test eax, eax |
190 | jz .fail |
189 | jz .fail |
191 | 190 | ||
192 | lea edi, [eax+EVENT.code] |
191 | lea edi, [eax+EVENT.code] |
193 | mov ecx, 6 |
192 | mov ecx, 6 |
194 | mov esi, [event] |
193 | mov esi, [event] |
195 | cld |
194 | cld |
196 | rep movsd |
195 | rep movsd |
197 | 196 | ||
198 | mov ecx, [slot] |
197 | mov ecx, [slot] |
199 | add ecx, SLOT_BASE+APP_EV_OFFSET |
198 | add ecx, SLOT_BASE+APP_EV_OFFSET |
200 | 199 | ||
201 | mov [eax+APPOBJ.magic], 'EVNT' |
200 | mov [eax+APPOBJ.magic], 'EVNT' |
202 | mov [eax+APPOBJ.destroy], destroy_event |
201 | mov [eax+APPOBJ.destroy], destroy_event |
203 | mov ebx, [pid] |
202 | mov ebx, [pid] |
204 | mov [eax+APPOBJ.pid], ebx |
203 | mov [eax+APPOBJ.pid], ebx |
205 | mov [eax+EVENT.state], EVENT_SIGNALED |
204 | mov [eax+EVENT.state], EVENT_SIGNALED |
206 | 205 | ||
207 | pushfd |
206 | pushfd |
208 | cli ;insert event into |
207 | cli ;insert event into |
209 | mov edx, [ecx+APPOBJ.fd] ;events list |
208 | mov edx, [ecx+APPOBJ.fd] ;events list |
210 | mov [eax+APPOBJ.fd], edx ;and set events flag |
209 | mov [eax+APPOBJ.fd], edx ;and set events flag |
211 | mov [eax+APPOBJ.bk], ecx |
210 | mov [eax+APPOBJ.bk], ecx |
212 | mov [ecx+APPOBJ.fd], eax |
211 | mov [ecx+APPOBJ.fd], eax |
213 | mov [edx+APPOBJ.bk], eax |
212 | mov [edx+APPOBJ.bk], eax |
214 | inc [ecx+APPDATA.ev_count-APP_EV_OFFSET] |
213 | inc [ecx+APPDATA.ev_count-APP_EV_OFFSET] |
215 | or [ecx+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
214 | or [ecx+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
216 | popfd |
215 | popfd |
217 | .fail: |
216 | .fail: |
218 | ret |
217 | ret |
219 | endp |
218 | endp |
220 | 219 | ||
221 | ; timeout ignored |
220 | ; timeout ignored |
222 | 221 | ||
223 | align 4 |
222 | align 4 |
224 | proc get_event_ex stdcall, p_ev:dword, timeout:dword |
223 | proc get_event_ex stdcall, p_ev:dword, timeout:dword |
225 | 224 | ||
226 | .wait: |
225 | .wait: |
227 | mov edx,[CURRENT_TASK] |
226 | mov edx,[current_slot] |
228 | shl edx,8 |
- | |
229 | ; cmp [SLOT_BASE+edx+APPDATA.ev_count], 0 |
227 | ; cmp [SLOT_BASE+edx+APPDATA.ev_count], 0 |
230 | ; je .switch |
228 | ; je .switch |
231 | 229 | ||
232 | add edx, SLOT_BASE+APP_EV_OFFSET |
230 | add edx, APP_EV_OFFSET |
233 | 231 | ||
234 | mov eax, [edx+APPOBJ.fd] |
232 | mov eax, [edx+APPOBJ.fd] |
235 | cmp eax, edx |
233 | cmp eax, edx |
236 | je .switch |
234 | je .switch |
237 | 235 | ||
238 | lea esi, [eax+EVENT.code] |
236 | lea esi, [eax+EVENT.code] |
239 | mov edi, [p_ev] ;copy event data |
237 | mov edi, [p_ev] ;copy event data |
240 | mov ecx, 6 |
238 | mov ecx, 6 |
241 | cld |
239 | cld |
242 | rep movsd |
240 | rep movsd |
243 | 241 | ||
244 | and dword [edi-24], 0xFF00FFFF ;clear priority field |
242 | and dword [edi-24], 0xFF00FFFF ;clear priority field |
245 | ; |
243 | ; |
246 | test [eax+EVENT.state], MANUAL_RESET |
244 | test [eax+EVENT.state], MANUAL_RESET |
247 | jnz .done |
245 | jnz .done |
248 | 246 | ||
249 | pushfd |
247 | pushfd |
250 | cli ;remove event from events |
248 | cli ;remove event from events |
251 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
249 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
252 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
250 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
253 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
251 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
254 | mov [ecx+APPOBJ.fd], ebx |
252 | mov [ecx+APPOBJ.fd], ebx |
255 | 253 | ||
256 | and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
254 | and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
257 | 255 | ||
258 | dec [edx+APPDATA.ev_count-APP_EV_OFFSET] |
256 | dec [edx+APPDATA.ev_count-APP_EV_OFFSET] |
259 | jnz @F |
257 | jnz @F |
260 | and [edx+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED |
258 | and [edx+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED |
261 | @@: |
259 | @@: |
262 | popfd |
260 | popfd |
263 | 261 | ||
264 | test [eax+EVENT.state], MANUAL_DESTROY |
262 | test [eax+EVENT.state], MANUAL_DESTROY |
265 | jz .destroy |
263 | jz .destroy |
266 | 264 | ||
267 | add edx, (APP_OBJ_OFFSET-APP_EV_OFFSET) |
265 | add edx, (APP_OBJ_OFFSET-APP_EV_OFFSET) |
268 | 266 | ||
269 | pushfd |
267 | pushfd |
270 | cli |
268 | cli |
271 | mov ebx, [edx+APPOBJ.fd] ;insert event into |
269 | mov ebx, [edx+APPOBJ.fd] ;insert event into |
272 | mov [eax+APPOBJ.fd], ebx ;objects list |
270 | mov [eax+APPOBJ.fd], ebx ;objects list |
273 | mov [eax+APPOBJ.bk], edx |
271 | mov [eax+APPOBJ.bk], edx |
274 | mov [edx+APPOBJ.fd], eax |
272 | mov [edx+APPOBJ.fd], eax |
275 | mov [ebx+APPOBJ.bk], eax |
273 | mov [ebx+APPOBJ.bk], eax |
276 | popfd |
274 | popfd |
277 | .done: |
275 | .done: |
278 | ret |
276 | ret |
279 | 277 | ||
280 | .destroy: |
278 | .destroy: |
281 | call destroy_event.force |
279 | call destroy_event.force |
282 | ret |
280 | ret |
283 | .switch: |
281 | .switch: |
284 | mov eax, [TASK_BASE] |
282 | mov eax, [TASK_BASE] |
285 | mov [eax+TASKDATA.state], byte 5 |
283 | mov [eax+TASKDATA.state], byte 5 |
286 | call change_task |
284 | call change_task |
287 | jmp .wait |
285 | jmp .wait |
288 | endp |
286 | endp |
289 | 287 | ||
290 | ; param |
288 | ; param |
291 | ; eax= event |
289 | ; eax= event |
292 | ; ebx= id |
290 | ; ebx= id |
293 | 291 | ||
294 | align 4 |
292 | align 4 |
295 | wait_event: |
293 | wait_event: |
296 | .event equ esp |
294 | .event equ esp |
297 | push eax |
295 | push eax |
298 | .wait: |
296 | .wait: |
299 | cmp [eax+APPOBJ.magic], 'EVNT' |
297 | cmp [eax+APPOBJ.magic], 'EVNT' |
300 | jne .done |
298 | jne .done |
301 | cmp [eax+EVENT.id], ebx |
299 | cmp [eax+EVENT.id], ebx |
302 | jne .done |
300 | jne .done |
303 | 301 | ||
304 | test [eax+EVENT.state], EVENT_SIGNALED |
302 | test [eax+EVENT.state], EVENT_SIGNALED |
305 | jz .switch |
303 | jz .switch |
306 | 304 | ||
307 | test [eax+EVENT.state], MANUAL_RESET |
305 | test [eax+EVENT.state], MANUAL_RESET |
308 | jnz .done |
306 | jnz .done |
309 | 307 | ||
310 | mov edx,[CURRENT_TASK] |
- | |
311 | shl edx,8 |
- | |
312 | add edx, SLOT_BASE |
308 | mov edx,[current_slot] |
313 | 309 | ||
314 | pushfd |
310 | pushfd |
315 | cli ;remove event from events |
311 | cli ;remove event from events |
316 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
312 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
317 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
313 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
318 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
314 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
319 | mov [ecx+APPOBJ.fd], ebx |
315 | mov [ecx+APPOBJ.fd], ebx |
320 | dec [edx+APPDATA.ev_count] |
316 | dec [edx+APPDATA.ev_count] |
321 | jnz @F |
317 | jnz @F |
322 | and [edx+APPDATA.event_mask], not EVENT_EXTENDED |
318 | and [edx+APPDATA.event_mask], not EVENT_EXTENDED |
323 | @@: |
319 | @@: |
324 | and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
320 | and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
325 | popfd |
321 | popfd |
326 | 322 | ||
327 | test [eax+EVENT.state], MANUAL_DESTROY |
323 | test [eax+EVENT.state], MANUAL_DESTROY |
328 | jz .destroy |
324 | jz .destroy |
329 | 325 | ||
330 | add edx, APP_OBJ_OFFSET |
326 | add edx, APP_OBJ_OFFSET |
331 | 327 | ||
332 | pushfd |
328 | pushfd |
333 | cli |
329 | cli |
334 | mov ecx, [edx+APPOBJ.fd] ;insert event into |
330 | mov ecx, [edx+APPOBJ.fd] ;insert event into |
335 | mov [eax+APPOBJ.fd], ecx ;objects list |
331 | mov [eax+APPOBJ.fd], ecx ;objects list |
336 | mov [eax+APPOBJ.bk], edx |
332 | mov [eax+APPOBJ.bk], edx |
337 | mov [edx+APPOBJ.fd], eax |
333 | mov [edx+APPOBJ.fd], eax |
338 | mov [ecx+APPOBJ.bk], eax |
334 | mov [ecx+APPOBJ.bk], eax |
339 | popfd |
335 | popfd |
340 | .done: |
336 | .done: |
341 | add esp, 4 |
337 | add esp, 4 |
342 | ret |
338 | ret |
343 | .destroy: |
339 | .destroy: |
344 | call destroy_event.force |
340 | call destroy_event.force |
345 | add esp, 4 |
341 | add esp, 4 |
346 | ret |
342 | ret |
347 | .switch: |
343 | .switch: |
348 | or [eax+EVENT.state], EVENT_WATCHED |
344 | or [eax+EVENT.state], EVENT_WATCHED |
349 | mov eax, [TASK_BASE] |
345 | mov eax, [TASK_BASE] |
350 | mov [eax+TASKDATA.state], byte 5 |
346 | mov [eax+TASKDATA.state], byte 5 |
351 | call change_task |
347 | call change_task |
352 | mov eax, [.event] |
348 | mov eax, [.event] |
353 | jmp .wait |
349 | jmp .wait |
354 | restore .event |
350 | restore .event |
355 | 351 | ||
356 | ; param |
352 | ; param |
357 | ; eax= event |
353 | ; eax= event |
358 | ; ebx= id |
354 | ; ebx= id |
359 | ; ecx= flags |
355 | ; ecx= flags |
360 | ; edx= event data |
356 | ; edx= event data |
361 | 357 | ||
362 | raise_event: |
358 | raise_event: |
363 | .event equ esp |
359 | .event equ esp |
364 | push eax |
360 | push eax |
365 | 361 | ||
366 | cmp [eax+APPOBJ.magic], 'EVNT' |
362 | cmp [eax+APPOBJ.magic], 'EVNT' |
367 | jne .fail |
363 | jne .fail |
368 | cmp [eax+EVENT.id], ebx |
364 | cmp [eax+EVENT.id], ebx |
369 | jne .fail |
365 | jne .fail |
370 | 366 | ||
371 | mov eax, [eax+APPOBJ.pid] |
367 | mov eax, [eax+APPOBJ.pid] |
372 | call pid_to_slot |
368 | call pid_to_slot |
373 | test eax, eax |
369 | test eax, eax |
374 | jz .fail |
370 | jz .fail |
375 | 371 | ||
376 | mov esi, edx |
372 | mov esi, edx |
377 | test esi, esi |
373 | test esi, esi |
378 | mov edx, [.event] |
374 | mov edx, [.event] |
379 | jz @F |
375 | jz @F |
380 | 376 | ||
381 | push ecx |
377 | push ecx |
382 | lea edi, [edx+EVENT.code] |
378 | lea edi, [edx+EVENT.code] |
383 | mov ecx, 6 |
379 | mov ecx, 6 |
384 | cld |
380 | cld |
385 | rep movsd |
381 | rep movsd |
386 | pop ecx |
382 | pop ecx |
387 | @@: |
383 | @@: |
388 | test [edx+EVENT.state], EVENT_SIGNALED |
384 | test [edx+EVENT.state], EVENT_SIGNALED |
389 | jnz .done |
385 | jnz .done |
390 | 386 | ||
391 | test ecx, EVENT_WATCHED |
387 | test ecx, EVENT_WATCHED |
392 | jz @F |
388 | jz @F |
393 | test [edx+EVENT.state], EVENT_WATCHED |
389 | test [edx+EVENT.state], EVENT_WATCHED |
394 | jz .done |
390 | jz .done |
395 | @@: |
391 | @@: |
396 | shl eax, 8 |
392 | shl eax, 8 |
397 | add eax, SLOT_BASE+APP_EV_OFFSET |
393 | add eax, SLOT_BASE+APP_EV_OFFSET |
398 | 394 | ||
399 | pushfd |
395 | pushfd |
400 | cli |
396 | cli |
401 | mov ebx, [edx+APPOBJ.fd] |
397 | mov ebx, [edx+APPOBJ.fd] |
402 | mov ecx, [edx+APPOBJ.bk] |
398 | mov ecx, [edx+APPOBJ.bk] |
403 | mov [ebx+APPOBJ.bk], ecx |
399 | mov [ebx+APPOBJ.bk], ecx |
404 | mov [ecx+APPOBJ.fd], ebx |
400 | mov [ecx+APPOBJ.fd], ebx |
405 | 401 | ||
406 | mov ecx, [eax+APPOBJ.fd] |
402 | mov ecx, [eax+APPOBJ.fd] |
407 | mov [edx+APPOBJ.fd], ecx |
403 | mov [edx+APPOBJ.fd], ecx |
408 | mov [edx+APPOBJ.bk], eax |
404 | mov [edx+APPOBJ.bk], eax |
409 | mov [eax+APPOBJ.fd], edx |
405 | mov [eax+APPOBJ.fd], edx |
410 | mov [ecx+APPOBJ.bk], edx |
406 | mov [ecx+APPOBJ.bk], edx |
411 | or [edx+EVENT.state], EVENT_SIGNALED |
407 | or [edx+EVENT.state], EVENT_SIGNALED |
412 | 408 | ||
413 | inc [eax+APPDATA.ev_count-APP_EV_OFFSET] |
409 | inc [eax+APPDATA.ev_count-APP_EV_OFFSET] |
414 | or [eax+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
410 | or [eax+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
415 | popfd |
411 | popfd |
416 | .fail: |
412 | .fail: |
417 | .done: |
413 | .done: |
418 | add esp, 4 |
414 | add esp, 4 |
419 | ret |
415 | ret |
420 | restore .event |
416 | restore .event |
421 | 417 | ||
422 | ; param |
418 | ; param |
423 | ; eax= event |
419 | ; eax= event |
424 | ; ebx= id |
420 | ; ebx= id |
425 | align 4 |
421 | align 4 |
426 | clear_event: |
422 | clear_event: |
427 | .event equ esp |
423 | .event equ esp |
428 | push eax |
424 | push eax |
429 | 425 | ||
430 | cmp [eax+APPOBJ.magic], 'EVNT' |
426 | cmp [eax+APPOBJ.magic], 'EVNT' |
431 | jne .fail |
427 | jne .fail |
432 | cmp [eax+EVENT.id], ebx |
428 | cmp [eax+EVENT.id], ebx |
433 | jne .fail |
429 | jne .fail |
434 | 430 | ||
435 | mov eax, [eax+APPOBJ.pid] |
431 | mov eax, [eax+APPOBJ.pid] |
436 | call pid_to_slot |
432 | call pid_to_slot |
437 | test eax, eax |
433 | test eax, eax |
438 | jz .fail |
434 | jz .fail |
439 | 435 | ||
440 | shl eax, 8 |
436 | shl eax, 8 |
441 | add eax, SLOT_BASE+APP_EV_OFFSET |
437 | add eax, SLOT_BASE+APP_EV_OFFSET |
442 | mov edx, [.event] |
438 | mov edx, [.event] |
443 | pushfd |
439 | pushfd |
444 | cli ;remove event from events |
440 | cli ;remove event from events |
445 | mov ebx, [edx+APPOBJ.fd] ;list (reset event) |
441 | mov ebx, [edx+APPOBJ.fd] ;list (reset event) |
446 | mov ecx, [edx+APPOBJ.bk] ;and clear events flag |
442 | mov ecx, [edx+APPOBJ.bk] ;and clear events flag |
447 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
443 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
448 | mov [ecx+APPOBJ.fd], ebx |
444 | mov [ecx+APPOBJ.fd], ebx |
449 | 445 | ||
450 | and [edx+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
446 | and [edx+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
451 | 447 | ||
452 | dec [eax+APPDATA.ev_count-APP_EV_OFFSET] |
448 | dec [eax+APPDATA.ev_count-APP_EV_OFFSET] |
453 | jnz @F |
449 | jnz @F |
454 | and [eax+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED |
450 | and [eax+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED |
455 | @@: |
451 | @@: |
456 | add eax, (APP_OBJ_OFFSET-APP_EV_OFFSET) |
452 | add eax, (APP_OBJ_OFFSET-APP_EV_OFFSET) |
457 | 453 | ||
458 | mov ecx, [eax+APPOBJ.fd] ;insert event into |
454 | mov ecx, [eax+APPOBJ.fd] ;insert event into |
459 | mov [edx+APPOBJ.fd], ecx ;objects list |
455 | mov [edx+APPOBJ.fd], ecx ;objects list |
460 | mov [edx+APPOBJ.bk], eax |
456 | mov [edx+APPOBJ.bk], eax |
461 | mov [eax+APPOBJ.fd], edx |
457 | mov [eax+APPOBJ.fd], edx |
462 | mov [ecx+APPOBJ.bk], edx |
458 | mov [ecx+APPOBJ.bk], edx |
463 | popfd |
459 | popfd |
464 | .fail: |
460 | .fail: |
465 | .done: |
461 | .done: |
466 | add esp, 4 |
462 | add esp, 4 |
467 | ret |
463 | ret |
468 | restore .event |
464 | restore .event |
469 | 465 | ||
470 | sys_getevent: |
466 | sys_getevent: |
471 | 467 | ||
472 | call get_event_for_app |
468 | call get_event_for_app |
473 | mov [esp+36],eax |
469 | mov [esp+36],eax |
474 | ret |
470 | ret |
475 | 471 | ||
476 | 472 | ||
477 | align 4 |
473 | align 4 |
478 | sys_wait_event_timeout: |
474 | sys_wait_event_timeout: |
479 | 475 | ||
480 | mov ebx,[timer_ticks] |
476 | mov ebx,[timer_ticks] |
481 | add ebx,eax |
477 | add ebx,eax |
482 | cmp ebx,[timer_ticks] |
478 | cmp ebx,[timer_ticks] |
483 | jna .swfet2 |
479 | jna .swfet2 |
484 | .swfet1: |
480 | .swfet1: |
485 | call get_event_for_app |
481 | call get_event_for_app |
486 | test eax,eax |
482 | test eax,eax |
487 | jne .eventoccur_time |
483 | jne .eventoccur_time |
488 | call change_task |
484 | call change_task |
489 | cmp ebx,[timer_ticks] |
485 | cmp ebx,[timer_ticks] |
490 | jg .swfet1 |
486 | jg .swfet1 |
491 | .swfet2: |
487 | .swfet2: |
492 | xor eax,eax |
488 | xor eax,eax |
493 | .eventoccur_time: |
489 | .eventoccur_time: |
494 | mov [esp+36],eax |
490 | mov [esp+36],eax |
495 | ret |
491 | ret |
496 | 492 | ||
497 | 493 | ||
498 | align 4 |
494 | align 4 |
499 | 495 | ||
500 | sys_waitforevent: |
496 | sys_waitforevent: |
501 | 497 | ||
502 | call get_event_for_app |
498 | call get_event_for_app |
503 | test eax,eax |
499 | test eax,eax |
504 | jne eventoccur |
500 | jne eventoccur |
505 | newwait: |
501 | newwait: |
506 | 502 | ||
507 | mov eax, [TASK_BASE] |
503 | mov eax, [TASK_BASE] |
508 | mov [eax+TASKDATA.state], byte 5 |
504 | mov [eax+TASKDATA.state], byte 5 |
509 | call change_task |
505 | call change_task |
510 | 506 | ||
511 | mov eax, [event_sched] |
507 | mov eax, [event_sched] |
512 | 508 | ||
513 | eventoccur: |
509 | eventoccur: |
514 | mov [esp+36],eax |
510 | mov [esp+36],eax |
515 | ret |
511 | ret |
516 | 512 | ||
517 | get_event_for_app: |
513 | get_event_for_app: |
518 | 514 | ||
519 | pushad |
515 | pushad |
520 | 516 | ||
521 | mov edi,[TASK_BASE] ; WINDOW REDRAW |
517 | mov edi,[TASK_BASE] ; WINDOW REDRAW |
522 | test [edi+TASKDATA.event_mask],dword 1 |
518 | test [edi+TASKDATA.event_mask],dword 1 |
523 | jz no_eventoccur1 |
519 | jz no_eventoccur1 |
524 | ;mov edi,[TASK_BASE] |
520 | ;mov edi,[TASK_BASE] |
525 | cmp [edi-twdw+WDATA.fl_redraw],byte 0 |
521 | cmp [edi-twdw+WDATA.fl_redraw],byte 0 |
526 | je no_eventoccur1 |
522 | je no_eventoccur1 |
527 | popad |
523 | popad |
528 | mov eax,1 |
524 | mov eax,1 |
529 | ret |
525 | ret |
530 | no_eventoccur1: |
526 | no_eventoccur1: |
531 | 527 | ||
532 | ;mov edi,[TASK_BASE] ; KEY IN BUFFER |
528 | ;mov edi,[TASK_BASE] ; KEY IN BUFFER |
533 | test [edi+TASKDATA.event_mask],dword 2 |
529 | test [edi+TASKDATA.event_mask],dword 2 |
534 | jz no_eventoccur2 |
530 | jz no_eventoccur2 |
535 | mov ecx, [CURRENT_TASK] |
531 | mov ecx, [CURRENT_TASK] |
536 | movzx edx,word [WIN_STACK+ecx*2] |
532 | movzx edx,word [WIN_STACK+ecx*2] |
537 | mov eax, [TASK_COUNT] |
533 | mov eax, [TASK_COUNT] |
538 | cmp eax,edx |
534 | cmp eax,edx |
539 | jne no_eventoccur2x |
535 | jne no_eventoccur2x |
540 | cmp [KEY_COUNT],byte 0 |
536 | cmp [KEY_COUNT],byte 0 |
541 | je no_eventoccur2x |
537 | je no_eventoccur2x |
542 | eventoccur2: |
538 | eventoccur2: |
543 | popad |
539 | popad |
544 | mov eax,2 |
540 | mov eax,2 |
545 | ret |
541 | ret |
546 | no_eventoccur2x: |
542 | no_eventoccur2x: |
547 | mov eax, hotkey_buffer |
543 | mov eax, hotkey_buffer |
548 | @@: |
544 | @@: |
549 | cmp [eax], ecx |
545 | cmp [eax], ecx |
550 | jz eventoccur2 |
546 | jz eventoccur2 |
551 | add eax, 8 |
547 | add eax, 8 |
552 | cmp eax, hotkey_buffer+120*8 |
548 | cmp eax, hotkey_buffer+120*8 |
553 | jb @b |
549 | jb @b |
554 | no_eventoccur2: |
550 | no_eventoccur2: |
555 | 551 | ||
556 | ;mov edi,[TASK_BASE] ; BUTTON IN BUFFER |
552 | ;mov edi,[TASK_BASE] ; BUTTON IN BUFFER |
557 | test [edi+TASKDATA.event_mask],dword 4 |
553 | test [edi+TASKDATA.event_mask],dword 4 |
558 | jz no_eventoccur3 |
554 | jz no_eventoccur3 |
559 | cmp [BTN_COUNT],byte 0 |
555 | cmp [BTN_COUNT],byte 0 |
560 | je no_eventoccur3 |
556 | je no_eventoccur3 |
561 | mov ecx, [CURRENT_TASK] |
557 | mov ecx, [CURRENT_TASK] |
562 | movzx edx, word [WIN_STACK+ecx*2] |
558 | movzx edx, word [WIN_STACK+ecx*2] |
563 | mov eax, [TASK_COUNT] |
559 | mov eax, [TASK_COUNT] |
564 | cmp eax,edx |
560 | cmp eax,edx |
565 | jnz no_eventoccur3 |
561 | jnz no_eventoccur3 |
566 | popad |
562 | popad |
567 | mov eax,[BTN_BUFF] |
563 | mov eax,[BTN_BUFF] |
568 | cmp eax,65535 |
564 | cmp eax,65535 |
569 | je no_event_1 |
565 | je no_event_1 |
570 | mov eax,3 |
566 | mov eax,3 |
571 | ret |
567 | ret |
572 | 568 | ||
573 | no_event_1: |
569 | no_event_1: |
574 | mov [window_minimize],1 |
570 | mov [window_minimize],1 |
575 | mov [BTN_COUNT],byte 0 |
571 | mov [BTN_COUNT],byte 0 |
576 | xor eax, eax |
572 | xor eax, eax |
577 | ret |
573 | ret |
578 | 574 | ||
579 | no_eventoccur3: |
- | |
580 | 575 | no_eventoccur3: |
|
581 | 576 | ||
582 | ;mov edi,[TASK_BASE] ; mouse event |
577 | ;mov edi,[TASK_BASE] ; mouse event |
583 | test [edi+TASKDATA.event_mask],dword 00100000b |
578 | test [edi+TASKDATA.event_mask],dword 00100000b |
584 | jz no_mouse_event |
579 | jz no_mouse_event |
- | 580 | ||
585 | mov eax,[CURRENT_TASK] |
581 | mov eax, [CURRENT_TASK] |
586 | shl eax,8 |
582 | shl eax, 8 |
587 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 00100000b |
583 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 00100000b |
588 | jz no_mouse_event |
584 | jz no_mouse_event |
589 | and [eax+SLOT_BASE+APPDATA.event_mask],dword 0xffffffff-00100000b |
585 | and [eax+SLOT_BASE+APPDATA.event_mask],dword (not 00100000b) |
590 | popad |
586 | popad |
591 | mov eax,6 |
587 | mov eax,6 |
592 | ret |
588 | ret |
593 | no_mouse_event: |
589 | no_mouse_event: |
594 | - | ||
595 | 590 | ||
596 | ;mov edi,[TASK_BASE] ; DESKTOP BACKGROUND REDRAW |
591 | ;mov edi,[TASK_BASE] ; DESKTOP BACKGROUND REDRAW |
597 | test [edi+TASKDATA.event_mask],dword 16 |
592 | test [edi+TASKDATA.event_mask],dword 16 |
598 | jz no_eventoccur5 |
593 | jz no_eventoccur5 |
599 | cmp [REDRAW_BACKGROUND],byte 2 |
594 | cmp [REDRAW_BACKGROUND],byte 2 |
600 | jnz no_eventoccur5 |
595 | jnz no_eventoccur5 |
601 | popad |
596 | popad |
602 | mov eax,5 |
597 | mov eax,5 |
603 | ret |
598 | ret |
604 | no_eventoccur5: |
599 | no_eventoccur5: |
605 | 600 | ||
606 | ;mov edi,[TASK_BASE] ; IPC |
601 | ;mov edi,[TASK_BASE] ; IPC |
607 | test [edi+TASKDATA.event_mask],dword 01000000b |
602 | test [edi+TASKDATA.event_mask],dword 01000000b |
608 | jz no_ipc |
603 | jz no_ipc |
609 | mov eax,[CURRENT_TASK] |
604 | mov eax, [CURRENT_TASK] |
610 | shl eax,8 |
605 | shl eax, 8 |
611 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 01000000b |
606 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 01000000b |
612 | jz no_ipc |
607 | jz no_ipc |
613 | and [eax+SLOT_BASE+APPDATA.event_mask],dword 0xffffffff-01000000b |
608 | and [eax+SLOT_BASE+APPDATA.event_mask],dword 0xffffffff-01000000b |
614 | popad |
609 | popad |
615 | mov eax,7 |
610 | mov eax,7 |
616 | ret |
611 | ret |
617 | no_ipc: |
612 | no_ipc: |
618 | - | ||
619 | 613 | ||
620 | ;mov edi,[TASK_BASE] ; STACK |
614 | ;mov edi,[TASK_BASE] ; STACK |
621 | test [edi+TASKDATA.event_mask],dword 10000000b |
615 | test [edi+TASKDATA.event_mask],dword 10000000b |
622 | jz no_stack_event |
616 | jz no_stack_event |
623 | mov eax,[CURRENT_TASK] |
617 | mov eax, [CURRENT_TASK] |
624 | shl eax,8 |
618 | shl eax, 8 |
625 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 10000000b |
619 | test [eax+SLOT_BASE+APPDATA.event_mask],dword 10000000b |
626 | jz no_stack_event |
620 | jz no_stack_event |
627 | and [eax+SLOT_BASE+APPDATA.event_mask],dword 0xffffffff-10000000b |
621 | and [eax+SLOT_BASE+APPDATA.event_mask],dword 0xffffffff-10000000b |
628 | popad |
622 | popad |
629 | mov eax,8 |
623 | mov eax,8 |
630 | ret |
624 | ret |
631 | no_stack_event: |
625 | no_stack_event: |
632 | 626 | ||
633 | test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG |
627 | test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG |
634 | jz .test_IRQ |
628 | jz .test_IRQ |
635 | mov eax, [CURRENT_TASK] |
629 | mov eax, [CURRENT_TASK] |
636 | shl eax, 8 |
630 | shl eax, 8 |
637 | test byte [eax+SLOT_BASE+APPDATA.event_mask+1], byte 1 |
631 | test byte [eax+SLOT_BASE+APPDATA.event_mask+1], byte 1 |
638 | jz .test_IRQ |
632 | jz .test_IRQ |
639 | and byte [eax+SLOT_BASE+APPDATA.event_mask+1], not 1 |
633 | and byte [eax+SLOT_BASE+APPDATA.event_mask+1], not 1 |
640 | popad |
634 | popad |
641 | mov eax, 9 |
635 | mov eax, 9 |
642 | ret |
636 | ret |
643 | 637 | ||
644 | ;.test_ext: |
638 | ;.test_ext: |
645 | ; mov eax, [CURRENT_TASK] |
639 | ; mov eax, [CURRENT_TASK] |
646 | ; shl eax, 8 |
640 | ; shl eax, 8 |
647 | ; test dword [eax+SLOT_BASE+APPDATA.event_mask], EVENT_EXTENDED |
641 | ; test dword [eax+SLOT_BASE+APPDATA.event_mask], EVENT_EXTENDED |
648 | ; jz .test_IRQ |
642 | ; jz .test_IRQ |
649 | ; popad |
643 | ; popad |
650 | ; mov eax, 10 |
644 | ; mov eax, 10 |
651 | ; ret |
645 | ; ret |
652 | 646 | ||
653 | .test_IRQ: |
647 | .test_IRQ: |
654 | cmp dword [edi+TASKDATA.event_mask], 0xFFFF |
648 | cmp dword [edi+TASKDATA.event_mask], 0xFFFF |
655 | jbe no_events |
649 | jbe no_events |
656 | 650 | ||
657 | mov esi,IRQ_SAVE ; IRQ'S AND DATA |
651 | mov esi,IRQ_SAVE ; IRQ'S AND DATA |
658 | mov ebx,0x00010000 |
652 | mov ebx,0x00010000 |
659 | xor ecx, ecx |
653 | xor ecx, ecx |
660 | irq_event_test: |
654 | irq_event_test: |
661 | mov edi,[TASK_BASE] |
655 | mov edi,[TASK_BASE] |
662 | test [edi+TASKDATA.event_mask],ebx |
656 | test [edi+TASKDATA.event_mask],ebx |
663 | jz no_irq_event |
657 | jz no_irq_event |
664 | mov edi,ecx |
658 | mov edi,ecx |
665 | shl edi,2 |
659 | shl edi,2 |
666 | add edi,irq_owner |
660 | add edi,irq_owner |
667 | mov edx,[edi] |
661 | mov edx,[edi] |
668 | mov eax,[TASK_BASE] |
662 | mov eax,[TASK_BASE] |
669 | mov eax,[eax+TASKDATA.pid] |
663 | mov eax,[eax+TASKDATA.pid] |
670 | cmp edx,eax |
664 | cmp edx,eax |
671 | jne no_irq_event |
665 | jne no_irq_event |
672 | cmp [esi],dword 0 |
666 | cmp [esi],dword 0 |
673 | jz no_irq_event |
667 | jz no_irq_event |
674 | mov eax,ecx |
668 | mov eax,ecx |
675 | add eax,16 |
669 | add eax,16 |
676 | mov [esp+28],eax |
670 | mov [esp+28],eax |
677 | popad |
671 | popad |
678 | ret |
672 | ret |
679 | no_irq_event: |
673 | no_irq_event: |
680 | add esi,0x1000 |
674 | add esi,0x1000 |
681 | shl ebx,1 |
675 | shl ebx,1 |
682 | inc ecx |
676 | inc ecx |
683 | cmp ecx,16 |
677 | cmp ecx,16 |
684 | jb irq_event_test |
678 | jb irq_event_test |
685 | 679 | ||
686 | no_events: |
680 | no_events: |
687 | popad |
681 | popad |
688 | xor eax, eax |
682 | xor eax, eax |
689 | ret |
683 | ret |