Subversion Repositories Kolibri OS

Rev

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

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