Subversion Repositories Kolibri OS

Rev

Rev 9949 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8.  
  9. WINDOW_MOVE_AND_RESIZE_FLAGS = \
  10.   mouse.WINDOW_RESIZE_N_FLAG + \
  11.   mouse.WINDOW_RESIZE_W_FLAG + \
  12.   mouse.WINDOW_RESIZE_S_FLAG + \
  13.   mouse.WINDOW_RESIZE_E_FLAG + \
  14.   mouse.WINDOW_MOVE_FLAG
  15.  
  16. uglobal
  17. align 4
  18.   event_start   dd ?
  19.   event_end     dd ?
  20.   event_uid     dd 0
  21. endg
  22. EV_SPACE   = 512
  23. FreeEvents = event_start-EVENT.fd    ; "virtual" event, only following field used:
  24.                                      ;  FreeEvents.fd=event_start and FreeEvents.bk=event_end
  25. ;-----------------------------------------------------------------------------
  26. align 4
  27. init_events:                                       ;; used from kernel.asm
  28.         stdcall kernel_alloc, EV_SPACE*sizeof.EVENT
  29.         or      eax, eax
  30.         jz      .fail
  31.       ; eax - current event, ebx - previous event below
  32.         mov     ecx, EV_SPACE        ; current - in allocated space
  33.         mov     ebx, FreeEvents      ; previous - list beginning
  34.         push    ebx                  ; it will be the end later
  35. ;--------------------------------------
  36. align 4
  37. @@:
  38.         mov     [ebx+EVENT.fd], eax
  39.         mov     [eax+EVENT.bk], ebx
  40.         mov     ebx, eax             ; previos <- current
  41.         add     eax, sizeof.EVENT    ; new current
  42.         loop    @b
  43.         pop     eax                  ; here it became the end
  44.         mov     [ebx+EVENT.fd], eax
  45.         mov     [eax+EVENT.bk], ebx
  46. ;--------------------------------------
  47. align 4
  48. .fail:
  49.         ret
  50. ;-----------------------------------------------------------------------------
  51. EVENT_WATCHED    = 0x10000000 ; bit 28
  52. EVENT_SIGNALED   = 0x20000000 ; bit 29
  53. MANUAL_RESET     = 0x40000000 ; bit 30
  54. MANUAL_DESTROY   = 0x80000000 ; bit 31
  55. ;-----------------------------------------------------------------------------
  56. align 4
  57. create_event:                                      ;; EXPORT use
  58. ;info:
  59. ;   Move EVENT from the FreeEvents list to the ObjList list of the current slot;
  60. ;   EVENT.state is set from ecx, EVENT.code indirectly from esi (if esi <> 0)
  61. ;param:
  62. ;   esi - event data
  63. ;   ecx - flags
  64. ;retval:
  65. ;   eax - event (=0 => fail)
  66. ;   edx - uid
  67. ;scratched: ebx,ecx,esi,edi
  68.         mov     ebx, [current_slot]
  69.         mov     edx, [ebx+APPDATA.tid]
  70.         add     ebx, APP_OBJ_OFFSET
  71.         pushfd
  72.         cli
  73. ;--------------------------------------
  74. align 4
  75. set_event:                                         ;; INTERNAL use !!! don't use for Call
  76. ;info:
  77. ;   We take a new event from FreeEvents, fill its fields from ecx, edx, esi
  78. ;   and add it to the list, which specified in ebx.
  79. ;   Return event (to eax), and it's uid (to edx)
  80. ;param:
  81. ;   ebx - start-chain "virtual" event for entry new event Right of him
  82. ;   ecx - flags      (copied to EVENT.state)
  83. ;   edx - pid        (copied to EVENT.pid)
  84. ;   esi - event data (copied to EVENT.code indirect, =0 => skip)
  85. ;retval:
  86. ;   eax - event (=0 => fail)
  87. ;   edx - uid
  88. ;scratched: ebx,ecx,esi,edi
  89.         mov     eax, FreeEvents
  90.         cmp     eax, [eax+EVENT.fd]
  91.         jne     @f  ; not empty ???
  92.         pushad
  93.         call    init_events
  94.         popad
  95.         jz      RemoveEventTo.break ; POPF+RET
  96. ;--------------------------------------
  97. align 4
  98. @@:
  99.         mov     eax, [eax+EVENT.fd]
  100.         mov     [eax+EVENT.magic], 'EVNT'
  101.         mov     [eax+EVENT.destroy], destroy_event.internal
  102.         mov     [eax+EVENT.state], ecx
  103.         mov     [eax+EVENT.pid], edx
  104.         inc     [event_uid]
  105.         mov     edx, [event_uid]
  106.         mov     [eax+EVENT.id], edx
  107.         or      esi, esi
  108.         jz      RemoveEventTo
  109.         lea     edi, [eax+EVENT.code]
  110.         mov     ecx, (sizeof.EVENT -EVENT.code)/4
  111.         cld
  112.         rep movsd
  113. ;--------------------------------------
  114. align 4
  115. RemoveEventTo:                                     ;; INTERNAL use !!! don't use for Call
  116. ;param:
  117. ;   eax - pointer to event, WHICH we will insert
  118. ;   ebx - pointer to event, AFTER which we will insert
  119. ;scratched: ebx,ecx
  120.         mov     ecx, eax             ; ecx=eax=Self,      ebx=NewLeft
  121.         xchg    ecx, [ebx+EVENT.fd]  ; NewLeft.fd=Self,   ecx=NewRight
  122.         cmp     eax, ecx             ; stop, I think...
  123.         je      .break               ; - am I not a fool?
  124.         mov     [ecx+EVENT.bk], eax  ; NewRight.bk=Self
  125.         xchg    ebx, [eax+EVENT.bk]  ; Self.bk=NewLeft,   ebx=OldLeft
  126.         xchg    ecx, [eax+EVENT.fd]  ; Self.fd=NewRight,  ecx=OldRight
  127.         mov     [ebx+EVENT.fd], ecx  ; OldLeft.fd=OldRight
  128.         mov     [ecx+EVENT.bk], ebx  ; OldRight.bk=OldLeft
  129. ;--------------------------------------
  130. align 4
  131. .break:
  132.         popfd
  133.         ret
  134. ;-----------------------------------------------------------------------------
  135. align 4
  136. NotDummyTest:                                      ;; INTERNAL use (not returned for fail !!!)
  137.         pop     edi
  138.         call    DummyTest ; not returned for fail !!!
  139.         mov     ebx, eax
  140.         mov     eax, [ebx+EVENT.pid]
  141.         push    edi
  142. ;--------------------------------------
  143. align 4
  144. .small: ; somehow ugly...
  145.         pop     edi
  146.         pushfd
  147.         cli
  148.         call    pid_to_slot ; saved all registers (eax - retval)
  149.         shl     eax, 8
  150.         jz      RemoveEventTo.break ; POPF+RET
  151.         jmp     edi ; normal return
  152. ;-----------------------------------------------------------------------------
  153. align 4
  154. raise_event:                                       ;; EXPORT use
  155. ;info:
  156. ;   Setting up EVENT.code data
  157. ;   If is has flag EVENT_SIGNALED activated - nothing else
  158. ;   Otherwise: activate this flag, except when the EVENT_WATCHED flag is present in edx
  159. ;   In this case EVENT_SIGNALED will activated only if EVENT_WATCHED presents in the event itself
  160. ;param:
  161. ;   eax - event
  162. ;   ebx - uid (for Dummy testing)
  163. ;   edx - flags
  164. ;   esi - event data (=0 => skip)
  165. ;scratched: ebx,ecx,esi,edi
  166.         call    NotDummyTest ; not returned for fail !!!
  167.         or      esi, esi
  168.         jz      @f
  169.         lea     edi, [ebx+EVENT.code]
  170.         mov     ecx, (sizeof.EVENT -EVENT.code)/4
  171.         cld
  172.         rep movsd
  173. ;--------------------------------------
  174. align 4
  175. @@:
  176.         test    byte[ebx+EVENT.state+3], EVENT_SIGNALED shr 24
  177.         jnz     RemoveEventTo.break  ; POPF+RET
  178.         bt      edx, 28 ;EVENT_WATCHED
  179.         jnc     @f
  180.         test    byte[ebx+EVENT.state+3], EVENT_WATCHED shr 24
  181.         jz      RemoveEventTo.break  ; POPF+RET
  182. ;--------------------------------------
  183. align 4
  184. @@:
  185.         or      byte[ebx+EVENT.state+3], EVENT_SIGNALED shr 24
  186.         add     eax, SLOT_BASE+APP_EV_OFFSET
  187.         xchg    eax, ebx
  188.         jmp     RemoveEventTo
  189. ;-----------------------------------------------------------------------------
  190. align 4
  191. clear_event:                                       ;; EXPORT use
  192. ;info:
  193. ;
  194. ;param:
  195. ;   eax - event
  196. ;   ebx - uid (for Dummy testing)
  197. ;scratched: ebx,ecx
  198.         call    NotDummyTest ; not returned for fail !!!
  199.         add     eax, SLOT_BASE+APP_OBJ_OFFSET
  200.         and     byte[ebx+EVENT.state+3], not((EVENT_SIGNALED+EVENT_WATCHED)shr 24)
  201.         xchg    eax, ebx
  202.         jmp     RemoveEventTo
  203. ;-----------------------------------------------------------------------------
  204. align 4
  205. send_event:                                        ;; EXPORT use
  206. ;info:
  207. ;   Creates a new EVENT (pulls from the FreeEvents list) in the EventList list
  208. ;   of target slot (eax=pid), with data from esi indirectly, and state=EVENT_SIGNALED
  209. ;param:
  210. ;   eax - slots pid, to sending new event
  211. ;   esi - pointer to sending data (in code field of new event)
  212. ;retval:
  213. ;   eax - event (=0 => fail)
  214. ;   edx - uid
  215. ;warning:
  216. ;   may be used as CDECL with such prefix...
  217. ;       mov     esi,[esp+8]
  218. ;       mov     eax,[esp+4]
  219. ;   but not as STDCALL :(
  220. ;scratched: ebx,ecx,esi,edi
  221.         mov     edx, eax
  222.         call    NotDummyTest.small ; not returned for fail !!!
  223.         lea     ebx, [eax+SLOT_BASE+APP_EV_OFFSET]
  224.         mov     ecx, EVENT_SIGNALED
  225.         jmp     set_event
  226. ;-----------------------------------------------------------------------------
  227. align 4
  228. DummyTest:                                         ;; INTERNAL use (not returned for fail !!!)
  229. ;param:
  230. ;   eax - event
  231. ;   ebx - uid (for Dummy testing)
  232.         cmp     [eax+EVENT.magic], 'EVNT'
  233.         jne     @f
  234.         cmp     [eax+EVENT.id], ebx
  235.         je      .ret
  236. ;--------------------------------------
  237. align 4
  238. @@:
  239.         pop     eax
  240.         xor     eax, eax
  241. ;--------------------------------------
  242. align 4
  243. .ret:
  244.         ret
  245. ;-----------------------------------------------------------------------------
  246. align 4
  247. Wait_events:
  248.         or      ebx, -1; infinite timeout
  249. ;--------------------------------------
  250. align 4
  251. Wait_events_ex:
  252. ;info:
  253. ;   Waiting for an "abstract" event by moving the slot to the 5th position.
  254. ;   Abstractness lies in the fact, that the fact of an event is determined by the APPDATA.wait_test function,
  255. ;   which is set by the client and can be actually anything.
  256. ;   This allows the shed to reliably determine the fact of the event, and not make "idle" switches,
  257. ;   intended for showdowns like "friend / foe" within the problem.
  258. ;param:
  259. ;   edx - wait_test, client testing function (code address)
  260. ;   ecx - wait_param, additional parameter, possibly needed for [wait_test]
  261. ;   ebx - wait_timeout
  262. ;retval:
  263. ;   eax - call result [wait_test] (=0 => timeout)
  264. ;scratched: esi
  265.         mov     esi, [current_slot]
  266.         mov     [esi+APPDATA.wait_param], ecx
  267.         pushad
  268.         mov     ebx, esi  ;now this is a question, what where to put..........
  269.         pushfd  ; this is a consequence of the general concept: let the test function have
  270.         cli     ; the right to hope to disable interrupts, as when called from shed
  271.         call    edx
  272.         popfd
  273.         mov     [esp+28], eax
  274.         popad
  275.         or      eax, eax
  276.         jnz     @f   ;RET
  277.         mov     [esi+APPDATA.wait_test], edx
  278.         mov     [esi+APPDATA.wait_timeout], ebx
  279.         mov     eax, [timer_ticks]
  280.         mov     [esi+APPDATA.wait_begin], eax
  281.         mov     [esi + APPDATA.state], TSTATE_WAITING
  282.         call    change_task
  283.         mov     eax, [esi+APPDATA.wait_param]
  284. ;--------------------------------------
  285. align 4
  286. @@:
  287.         ret
  288. ;-----------------------------------------------------------------------------
  289. align 4
  290. wait_event:                                        ;; EXPORT use
  291. ;info:
  292. ;   Waiting for the EVENT_SIGNALED flag in a very specific Event
  293. ;   (set, presumably, via raise_event)
  294. ;   When the MANUAL_RESET flag is active, nothing else
  295. ;   Otherwise: the flags EVENT_SIGNALED and EVENT_WATCHED for the received event are cleared,
  296. ;   and, if MANUAL_DESTROY is active, it moves to the ObjList list of the current slot,
  297. ;   and if not active, it is destroyed normally (destroy_event.internal)
  298. ;param:
  299. ;   eax - event
  300. ;   ebx - uid (for Dummy testing)
  301. ;scratched: ecx,edx,esi
  302.         call    DummyTest
  303.         mov     ecx, eax             ; wait_param
  304.         mov     edx, get_event_alone ; wait_test
  305.         call    Wait_events          ; timeout ignored
  306.         jmp     wait_finish
  307. ;-----------------------------------------------------------------------------
  308. align 4
  309. wait_event_timeout:
  310. ;param:
  311. ;   eax - event
  312. ;   ebx - uid (for Dummy testing)
  313. ;   ecx - timeout in timer ticks
  314. ;retval:
  315. ;   eax - EVENT handle or 0 if timeout
  316.         call    DummyTest
  317.         mov     ebx, ecx
  318.         mov     ecx, eax             ; wait_param
  319.         mov     edx, get_event_alone ; wait_test
  320.         call    Wait_events_ex
  321.         test    eax, eax
  322.         jnz     wait_finish
  323.         ret
  324. ;-----------------------------------------------------------------------------
  325. align 4
  326. get_event_ex:                                      ;; f68:14
  327. ;info:
  328. ;   Waiting for any event in the EventList of the current slot
  329. ;   Code event data - copied to application memory (indirectly by edi)
  330. ;   When the MANUAL_RESET flag is active, nothing else
  331. ;   Otherwise: the flags EVENT_SIGNALED and EVENT_WATCHED for the received event are cleared,
  332. ;   and, if MANUAL_DESTROY is active, it moves to the ObjList list of the current slot,
  333. ;   and if not active, it is destroyed normally (destroy_event.internal)
  334. ;param:
  335. ;   edi - address in the application code to copy data from EVENT.code
  336. ;retval:
  337. ;   eax - EVENT itself (we will call it a handle)
  338. ;scratched: ebx,ecx,edx,esi,edi
  339.         mov     edx, get_event_queue ; wait_test
  340.         call    Wait_events          ; timeout ignored
  341.         lea     esi, [eax+EVENT.code]
  342.         mov     ecx, (sizeof.EVENT-EVENT.code)/4
  343.         cld
  344.         rep movsd
  345.         mov     byte[edi-(sizeof.EVENT-EVENT.code)+2], cl;clear priority field
  346. ;--------------------------------------
  347. align 4
  348. wait_finish:
  349.         test    byte[eax+EVENT.state+3], MANUAL_RESET shr 24
  350.         jnz     get_event_queue.ret  ; RET
  351.         and     byte[eax+EVENT.state+3], not((EVENT_SIGNALED+EVENT_WATCHED)shr 24)
  352.         test    byte[eax+EVENT.state+3], MANUAL_DESTROY shr 24
  353.         jz      destroy_event.internal
  354.         mov     ebx, [current_slot]
  355.         add     ebx, APP_OBJ_OFFSET
  356.         pushfd
  357.         cli
  358.         jmp     RemoveEventTo
  359. ;-----------------------------------------------------------------------------
  360. align 4
  361. destroy_event:                                     ;; EXPORT use
  362. ;info:
  363. ;   Move EVENT to the FreeEvents list, clear the magic, destroy, pid, id fields
  364. ;param:
  365. ;   eax - event
  366. ;   ebx - uid (for Dummy testing)
  367. ;retval:
  368. ;   eax - address of EVENT object (=0 => fail)
  369. ;scratched: ebx,ecx
  370.         call    DummyTest ; not returned for fail !!!
  371. ;--------------------------------------
  372. align 4
  373. .internal:
  374.         xor     ecx, ecx  ; clear common header
  375.         pushfd
  376.         cli
  377.         mov     [eax+EVENT.magic], ecx
  378.         mov     [eax+EVENT.destroy], ecx
  379.         mov     [eax+EVENT.pid], ecx
  380.         mov     [eax+EVENT.id], ecx
  381.         mov     ebx, FreeEvents
  382.         jmp     RemoveEventTo
  383. ;-----------------------------------------------------------------------------
  384. align 4
  385. get_event_queue:
  386. ;info:
  387. ;   client testing function for get_event_ex
  388. ;warning:
  389. ;  -don't use [current_slot],[current_slot_idx] - it is not for your slot
  390. ;  -may be assumed, that interrupt are disabled
  391. ;  -it is not restriction for scratched registers
  392. ;param:
  393. ;   ebx - APPDATA address of testing slot
  394. ;retval:
  395. ;   eax - address of EVENT object (=0 => fail)
  396.         add     ebx, APP_EV_OFFSET
  397.         mov     eax, [ebx+APPOBJ.bk] ; we choose from the end, according to the FIFO principle
  398.         cmp     eax, ebx ; empty ???
  399.         je      get_event_alone.ret0
  400. ;--------------------------------------
  401. align 4
  402. .ret:
  403.         ret
  404. ;-----------------------------------------------------------------------------
  405. align 4
  406. get_event_alone:
  407. ;info:
  408. ;   client testing function for wait_event
  409. ;warning:
  410. ;  -don't use [current_slot],[current_slot_idx] - it is not for your slot
  411. ;  -may be assumed, that interrupt are disabled
  412. ;  -it is not restriction for scratched registers
  413. ;param:
  414. ;   ebx - APPDATA address of testing slot
  415. ;retval:
  416. ;   eax - address of EVENT object (=0 => fail)
  417.         mov     eax, [ebx+APPDATA.wait_param]
  418.         test    byte[eax+EVENT.state+3], EVENT_SIGNALED shr 24
  419.         jnz     .ret
  420.         or      byte[eax+EVENT.state+3], EVENT_WATCHED shr 24
  421. ;--------------------------------------
  422. align 4
  423. .ret0:
  424.         xor     eax, eax; NO event!!!
  425. ;--------------------------------------
  426. align 4
  427. .ret:
  428.         ret
  429. ;-----------------------------------------------------------------------------
  430. align 4
  431. sys_sendwindowmsg:                                 ;; f72
  432.         dec     ebx
  433.         jnz     .ret ;subfunction==1 ?
  434.         pushfd
  435.         cli
  436.         sub     ecx, 2
  437.         je      .sendkey
  438.         dec     ecx
  439.         jnz     .retf
  440. ;--------------------------------------
  441. align 4
  442. .sendbtn:
  443.         cmp     byte[BTN_COUNT], 1
  444.         jae     .result ;overflow
  445.         inc     byte[BTN_COUNT]
  446.         shl     edx, 8
  447.         mov     [BTN_BUFF], edx
  448.         jmp     .result
  449. ;--------------------------------------
  450. align 4
  451. .sendkey:
  452.         movzx   eax, byte[KEY_COUNT]
  453.         cmp     al, 120
  454.         jae     .result ;overflow
  455.         inc     byte[KEY_COUNT]
  456.         mov     [KEY_BUFF+eax], dl
  457. ; store empty scancode
  458.         add     eax, 120+2
  459.         mov     [KEY_BUFF+eax], byte 0
  460.         sub     eax, 120+2
  461. ;--------------------------------------
  462. align 4
  463. .result:
  464.         setae   byte[esp + SYSCALL_STACK.eax + 4] ;we consider that initially was: dword[esp+32+4]==72
  465. ;--------------------------------------
  466. align 4
  467. .retf:
  468.         popfd
  469. ;--------------------------------------
  470. align 4
  471. .ret:
  472.         ret
  473. ;-----------------------------------------------------------------------------
  474. align 4
  475. sys_getevent:                                      ;; f11
  476.         mov     ebx, [current_slot]  ;now this is a question, what where to put......
  477.         pushfd  ; this is a consequence of the general concept: let the test function have
  478.         cli     ; the right to hope to disable interrupts, as when called from shed
  479.         call    get_event_for_app
  480.         popfd
  481.         mov     [esp + SYSCALL_STACK.eax], eax
  482.         ret
  483. ;-----------------------------------------------------------------------------
  484. align 4
  485. sys_waitforevent:                                  ;; f10
  486.         or      ebx, -1; infinite timeout
  487. ;--------------------------------------
  488. align 4
  489. sys_wait_event_timeout:                            ;; f23
  490.         call    unprotect_from_terminate
  491.         mov     edx, get_event_for_app; wait_test
  492.         call    Wait_events_ex        ; ebx - timeout
  493.         mov     [esp + SYSCALL_STACK.eax], eax
  494.         call    protect_from_terminate
  495.         ret
  496. ;-----------------------------------------------------------------------------
  497. align 4
  498. get_event_for_app:                                 ;; used from f10,f11,f23
  499. ;info:
  500. ;   client testing function for applications (f10,f23)
  501. ;warning:
  502. ;  -don't use [current_slot],[current_slot_idx] - it is not for your slot
  503. ;  -may be assumed, that interrupt are disabled
  504. ;  -it is not restriction for scratched registers
  505. ;param:
  506. ;   ebx - APPDATA address of testing slot
  507. ;retval:
  508. ;   eax - event number (=0 => no events)
  509.         movzx   edi, bh               ; bh  is assumed as [current_slot_idx]
  510.         mov     ecx, [ebx+APPDATA.event_mask]
  511.         shl     edi, BSF sizeof.WDATA
  512.         add     edi, window_data
  513.         and     ecx, 0x7FFFFFFF
  514. ;--------------------------------------
  515. align 4
  516. .loop: ; until we run out all the bits of the mask
  517.         bsr     eax, ecx       ; find a non-zero bit of the mask (31 -> 0)
  518.         jz      .no_events     ; ran out all the bits of the mask but found nothing ???
  519.         btr     ecx, eax       ; clear the current checking bit of the mask
  520.        ; go to the handler of this (eax) bit
  521.         cmp     eax, 10
  522.         jae     .loop          ; eax=[10..31], ignored (event 11...32)
  523.  
  524.         cmp     eax, 3
  525.         je      .loop          ; eax=3, ignored (event 4)
  526.  
  527.         cmp     eax, 4
  528.         je      .FlagAutoReset  ; eax=4, retvals=eax+1 (event 5)
  529.  
  530.         cmp     eax, 5
  531.         je      .mouse_check  ; eax=5, retvals=eax+1 (event 6)
  532.  
  533.         ja      .FlagAutoReset ; eax=[6..9], retvals=eax+1 (event 7...10)
  534.  
  535.         cmp     eax, 1
  536.         jae     .BtKy          ; eax=[1,2],  retvals=eax+1 (event 2,3)
  537. ;--------------------------------------
  538. align 4
  539. .WndRedraw:                    ; eax=0, retval WndRedraw=1
  540.         cmp     [edi + WDATA.fl_redraw], al;al==0
  541.         jne     .result
  542.         jmp     .loop
  543. ;--------------------------------------
  544. align 4
  545. .no_events:
  546.         xor     eax, eax
  547.         ret
  548. ;--------------------------------------
  549. align 4
  550. .mouse_check:    ; Mouse 5+1=6
  551.         push    eax
  552.         mov     eax, [current_slot]
  553.         mov     eax, [eax + APPDATA.event_mask]
  554.         test    eax, EVM_MOUSE_FILTER ; bit 31: active/inactive filter f.40
  555.         jz      @f
  556.         pop     eax
  557.         jmp     .FlagAutoReset
  558. ;--------------------------------------
  559. align 4
  560. @@:
  561. ; If the window is captured and moved by the user, then no mouse events!!!
  562.         mov     al, [mouse.active_sys_window.action]
  563.         and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
  564.         test    al, al
  565.         pop     eax
  566.         jnz     .loop
  567. ;--------------------------------------
  568. align 4
  569. .FlagAutoReset: ; retvals: BgrRedraw=5, IPC=7, Stack=8, Debug=9
  570.         btr     [ebx+APPDATA.occurred_events], eax
  571.         jnc     .loop
  572. ;--------------------------------------
  573. align 4
  574. .result:      ; retval = eax+1
  575.         inc     eax
  576.         ret
  577. ;--------------------------------------
  578. align 4
  579. .BtKy:
  580.         movzx   edx, bh
  581.         movzx   edx, word[WIN_STACK+edx*2]
  582.         je      .Keys          ; eax=1, retval Keys=2
  583. ;--------------------------------------
  584. align 4
  585. .Buttons:                      ; eax=2, retval Buttons=3
  586.         cmp     byte[BTN_COUNT], 0
  587.         je      .loop          ; empty ???
  588.         cmp     edx, [thread_count]
  589.         jne     .loop          ; not Top ???
  590.         mov     edx, [BTN_BUFF]
  591.         shr     edx, 8
  592.         cmp     edx, 0xFFFF    ;-ID for Minimize-Button of Form
  593.         jne     .result
  594.         mov     [window_minimize], 1
  595.         call    wakeup_osloop
  596.         dec     byte[BTN_COUNT]
  597.         jmp     .loop
  598. ;--------------------------------------
  599. align 4
  600. .Keys:    ; eax==1
  601.         cmp     edx, [thread_count]
  602.         jne     @f             ; not Top ???
  603.         cmp     [KEY_COUNT], al; al==1
  604.         jae     .result        ; not empty ???
  605. ;--------------------------------------
  606. align 4
  607. @@:
  608.         mov     edx, hotkey_buffer
  609. ;--------------------------------------
  610. align 4
  611. @@:
  612.         cmp     [edx], bh      ; bh - slot for testing
  613.         je      .result
  614.         add     edx, 8
  615.         cmp     edx, hotkey_buffer+120*8
  616.         jb      @b
  617.         jmp     .loop
  618. ;end.
  619. ;-----------------------------------------------------------------------------
  620.