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