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