Subversion Repositories Kolibri OS

Rev

Rev 837 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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