Subversion Repositories Kolibri OS

Rev

Rev 2453 | Rev 2458 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. 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. $Revision: 2455 $
  10.  
  11. ;==============================================================================
  12. ;///// public functions ///////////////////////////////////////////////////////
  13. ;==============================================================================
  14.  
  15. window.BORDER_SIZE = 5
  16.  
  17. macro FuncTable name, table_name, [label]
  18. {
  19.   common
  20.     align 4
  21.     \label name#.#table_name dword
  22.   forward
  23.     dd name#.#label
  24.   common
  25.     name#.sizeof.#table_name = $ - name#.#table_name
  26. }
  27.  
  28. uglobal
  29.   common_colours rd 32
  30.   draw_limits    RECT
  31. endg
  32.  
  33. align 4
  34. ;------------------------------------------------------------------------------
  35. syscall_draw_window: ;///// system function 0 /////////////////////////////////
  36. ;------------------------------------------------------------------------------
  37. ;? <description>
  38. ;------------------------------------------------------------------------------
  39.         mov     eax, edx
  40.         shr     eax, 24
  41.         and     al, 0x0f
  42.         cmp     al, 5
  43.         jae     .exit
  44.  
  45.         push    eax
  46.         call    window._.sys_set_window
  47.         pop     eax
  48.  
  49.         or      al, al
  50.         jnz     @f
  51.  
  52.         ; type I - original style
  53.         call    drawwindow_I
  54.         jmp     window._.draw_window_caption.2
  55. ;--------------------------------------
  56. align 4
  57. @@:
  58.         dec     al
  59.         jnz     @f
  60.  
  61.         ; type II - only reserve area, no draw
  62. ;        call    sys_window_mouse
  63. ;        call    [draw_pointer]
  64.         call    __sys_draw_pointer
  65.         jmp     .exit
  66. ;--------------------------------------
  67. align 4
  68. @@:
  69.         dec     al
  70.         jnz     @f
  71.  
  72.         ; type III  - new style
  73.         call    drawwindow_III
  74.         jmp     window._.draw_window_caption.2
  75.  
  76.         ; type IV & V - skinned window (resizable & not)
  77. ;--------------------------------------
  78. align 4
  79. @@:
  80.         mov     eax, [TASK_COUNT]
  81.         movzx   eax, word[WIN_POS + eax * 2]
  82.         cmp     eax, [CURRENT_TASK]
  83.         setz    al
  84.         movzx   eax, al
  85.         push    eax
  86.         call    drawwindow_IV
  87.         jmp     window._.draw_window_caption.2
  88. ;--------------------------------------
  89. align 4
  90. .exit:
  91.         ret
  92. ;------------------------------------------------------------------------------
  93. align 4
  94. ;------------------------------------------------------------------------------
  95. syscall_display_settings: ;///// system function 48 ///////////////////////////
  96. ;------------------------------------------------------------------------------
  97. ;; Redraw screen:
  98. ;< ebx = 0
  99. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  100. ;; Set button style:
  101. ;< ebx = 1
  102. ;< ecx = 0 (flat) or 1 (with gradient)
  103. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  104. ;; Set system color palette:
  105. ;< ebx = 2
  106. ;< ecx = pointer to color table
  107. ;< edx = size of color table
  108. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  109. ;; Get system color palette:
  110. ;< ebx = 3
  111. ;< ecx = pointer to color table buffer
  112. ;< edx = size of color table buffer
  113. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  114. ;; Get skinned caption height:
  115. ;< ebx = 4
  116. ;> eax = height in pixels
  117. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  118. ;; Get screen working area:
  119. ;< ebx = 5
  120. ;> eax = pack[16(left), 16(right)]
  121. ;> ebx = pack[16(top), 16(bottom)]
  122. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  123. ;; Set screen working area:
  124. ;< ebx = 6
  125. ;< ecx = pack[16(left), 16(right)]
  126. ;< edx = pack[16(top), 16(bottom)]
  127. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  128. ;; Get skin margins:
  129. ;< ebx = 7
  130. ;> eax = pack[16(left), 16(right)]
  131. ;> ebx = pack[16(top), 16(bottom)]
  132. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  133. ;; Set skin:
  134. ;< ebx = 8
  135. ;< ecx = pointer to FileInfoBlock struct
  136. ;> eax = FS error code
  137. ;------------------------------------------------------------------------------
  138.         cmp     ebx, .sizeof.ftable / 4
  139.         ja      @f
  140.         jmp     [.ftable + ebx * 4]
  141. ;--------------------------------------
  142. align 4
  143. @@:
  144.         ret
  145. ;------------------------------------------------------------------------------
  146. align 4
  147. syscall_display_settings.00:
  148.         xor     eax, eax
  149.         inc     ebx
  150.         cmp     [windowtypechanged], ebx
  151.         jne     .exit
  152.         mov     [windowtypechanged], eax
  153.  
  154.         jmp     syscall_display_settings._.redraw_whole_screen
  155. ;--------------------------------------
  156. align 4
  157. .exit:
  158.         ret
  159. ;------------------------------------------------------------------------------
  160. align 4
  161. syscall_display_settings.01:
  162.         and     ecx, 1
  163.         cmp     ecx, [buttontype]
  164.         je      .exit
  165.         mov     [buttontype], ecx
  166.         mov     [windowtypechanged], ebx
  167. ;--------------------------------------
  168. align 4
  169.   .exit:
  170.         ret
  171. ;------------------------------------------------------------------------------
  172. align 4
  173. syscall_display_settings.02:
  174.         dec     ebx
  175.         mov     esi, ecx
  176.         and     edx, 127
  177.         mov     edi, common_colours
  178.         mov     ecx, edx
  179.         rep movsb
  180.         mov     [windowtypechanged], ebx
  181.         ret
  182. ;------------------------------------------------------------------------------
  183. align 4
  184. syscall_display_settings.03:
  185.         mov     edi, ecx
  186.         and     edx, 127
  187.         mov     esi, common_colours
  188.         mov     ecx, edx
  189.         rep movsb
  190.         ret
  191. ;------------------------------------------------------------------------------
  192. align 4
  193. syscall_display_settings.04:
  194.         mov     eax, [_skinh]
  195.         mov     [esp + 32], eax
  196.         ret
  197. ;------------------------------------------------------------------------------
  198. align 4
  199. syscall_display_settings.05:
  200.         mov     eax, [screen_workarea.left - 2]
  201.         mov     ax, word[screen_workarea.right]
  202.         mov     [esp + 32], eax
  203.         mov     eax, [screen_workarea.top - 2]
  204.         mov     ax, word[screen_workarea.bottom]
  205.         mov     [esp + 20], eax
  206.         ret
  207. ;------------------------------------------------------------------------------
  208. align 4
  209. syscall_display_settings.06:
  210.         xor     esi, esi
  211.  
  212.         mov     edi, [Screen_Max_X]
  213.         mov     eax, ecx
  214.         movsx   ebx, ax
  215.         sar     eax, 16
  216.         cmp     eax, ebx
  217.         jge     .check_horizontal
  218.         inc     esi
  219.         or      eax, eax
  220.         jge     @f
  221.         xor     eax, eax
  222. ;--------------------------------------
  223. align 4
  224. @@:
  225.         mov     [screen_workarea.left], eax
  226.         cmp     ebx, edi
  227.         jle     @f
  228.         mov     ebx, edi
  229. ;--------------------------------------
  230. align 4
  231. @@:
  232.         mov     [screen_workarea.right], ebx
  233. ;--------------------------------------
  234. align 4
  235. .check_horizontal:
  236.         mov     edi, [Screen_Max_Y]
  237.         mov     eax, edx
  238.         movsx   ebx, ax
  239.         sar     eax, 16
  240.         cmp     eax, ebx
  241.         jge     .check_if_redraw_needed
  242.         inc     esi
  243.         or      eax, eax
  244.         jge     @f
  245.         xor     eax, eax
  246. ;--------------------------------------
  247. align 4
  248. @@:
  249.         mov     [screen_workarea.top], eax
  250.         cmp     ebx, edi
  251.         jle     @f
  252.         mov     ebx, edi
  253. ;--------------------------------------
  254. align 4
  255. @@:
  256.         mov     [screen_workarea.bottom], ebx
  257. ;--------------------------------------
  258. align 4
  259. .check_if_redraw_needed:
  260.         or      esi, esi
  261.         jz      .exit
  262.  
  263.         call    repos_windows
  264.         jmp     syscall_display_settings._.calculate_whole_screen
  265. ;--------------------------------------
  266. align 4
  267. .exit:
  268.         ret
  269. ;------------------------------------------------------------------------------
  270. align 4
  271. syscall_display_settings.07:
  272.         mov     eax, [_skinmargins + 0]
  273.         mov     [esp + 32], eax
  274.         mov     eax, [_skinmargins + 4]
  275.         mov     [esp + 20], eax
  276.         ret
  277. ;------------------------------------------------------------------------------
  278. align 4
  279. syscall_display_settings.08:
  280.         mov     ebx, ecx
  281.         call    read_skin_file
  282.         mov     [esp + 32], eax
  283.         test    eax, eax
  284.         jnz     .exit
  285.  
  286.         call    syscall_display_settings._.calculate_whole_screen
  287.         jmp     syscall_display_settings._.redraw_whole_screen
  288. ;--------------------------------------
  289. align 4
  290. .exit:
  291.         ret
  292. ;------------------------------------------------------------------------------
  293. align 4
  294. syscall_display_settings._.calculate_whole_screen:
  295.         xor     eax, eax
  296.         xor     ebx, ebx
  297.         mov     ecx, [Screen_Max_X]
  298.         mov     edx, [Screen_Max_Y]
  299.         jmp     calculatescreen
  300. ;------------------------------------------------------------------------------
  301. align 4
  302. syscall_display_settings._.redraw_whole_screen:
  303.         xor     eax, eax
  304.         mov     [draw_limits.left], eax
  305.         mov     [draw_limits.top], eax
  306.         mov     eax, [Screen_Max_X]
  307.         mov     [draw_limits.right], eax
  308.         mov     eax, [Screen_Max_Y]
  309.         mov     [draw_limits.bottom], eax
  310.         mov     eax, window_data
  311.         jmp     redrawscreen
  312. ;------------------------------------------------------------------------------
  313. align 4
  314. ;------------------------------------------------------------------------------
  315. syscall_set_window_shape: ;///// system function 50 ///////////////////////////
  316. ;------------------------------------------------------------------------------
  317. ;; Set window shape address:
  318. ;> ebx = 0
  319. ;> ecx = shape data address
  320. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  321. ;; Set window shape scale:
  322. ;> ebx = 1
  323. ;> ecx = scale power (resulting scale is 2^ebx)
  324. ;------------------------------------------------------------------------------
  325.         mov     edi, [current_slot]
  326.  
  327.         test    ebx, ebx
  328.         jne     .shape_scale
  329.         mov     [edi + APPDATA.wnd_shape], ecx
  330. ;--------------------------------------
  331. align 4
  332. .shape_scale:
  333.         dec     ebx
  334.         jnz     .exit
  335.         mov     [edi + APPDATA.wnd_shape_scale], ecx
  336. ;--------------------------------------
  337. align 4
  338. .exit:
  339.         ret
  340. ;------------------------------------------------------------------------------
  341. align 4
  342. ;------------------------------------------------------------------------------
  343. syscall_move_window: ;///// system function 67 ////////////////////////////////
  344. ;------------------------------------------------------------------------------
  345. ;? <description>
  346. ;------------------------------------------------------------------------------
  347.         mov     edi, [CURRENT_TASK]
  348.         shl     edi, 5
  349.         add     edi, window_data
  350.  
  351.         test    [edi + WDATA.fl_wdrawn], 1
  352.         jz      .exit
  353.  
  354.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  355.         jnz     .exit
  356.  
  357.         cmp     ebx, -1
  358.         jne     @f
  359.         mov     ebx, [edi + WDATA.box.left]
  360. ;--------------------------------------
  361. align 4
  362. @@:
  363.         cmp     ecx, -1
  364.         jne     @f
  365.         mov     ecx, [edi + WDATA.box.top]
  366. ;--------------------------------------
  367. align 4
  368. @@:
  369.         cmp     edx, -1
  370.         jne     @f
  371.         mov     edx, [edi + WDATA.box.width]
  372. ;--------------------------------------
  373. align 4
  374. @@:
  375.         cmp     esi, -1
  376.         jne     @f
  377.         mov     esi, [edi + WDATA.box.height]
  378. ;--------------------------------------
  379. align 4
  380. @@:
  381.         push    esi edx ecx ebx
  382.         mov     eax, esp
  383.         mov     bl, [edi + WDATA.fl_wstate]
  384.         call    window._.set_window_box
  385.         add     esp, sizeof.BOX
  386.  
  387.         ; NOTE: do we really need this? to be reworked
  388. ;       mov     byte[DONT_DRAW_MOUSE], 0 ; mouse pointer
  389. ;       mov     byte[MOUSE_BACKGROUND], 0 ; no mouse under
  390. ;       mov     byte[MOUSE_DOWN], 0 ; react to mouse up/down
  391.  
  392.         ; NOTE: do we really need this? to be reworked
  393. ;       call    [draw_pointer]
  394. ;--------------------------------------
  395. align 4
  396. .exit:
  397.         ret
  398. ;------------------------------------------------------------------------------
  399. align 4
  400. ;------------------------------------------------------------------------------
  401. syscall_window_settings: ;///// system function 71 /////////////////////////////
  402. ;------------------------------------------------------------------------------
  403. ;? <description>
  404. ;------------------------------------------------------------------------------
  405.         dec     ebx     ; subfunction #1 - set window caption
  406.         jnz     .exit_fail
  407.  
  408.         ; NOTE: only window owner thread can set its caption,
  409.         ;       so there's no parameter for PID/TID
  410.  
  411.         mov     edi, [CURRENT_TASK]
  412.         shl     edi, 5
  413.  
  414.         mov     [edi * 8 + SLOT_BASE + APPDATA.wnd_caption], ecx
  415.         or      [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  416.  
  417.         call    window._.draw_window_caption
  418.  
  419.         xor     eax, eax ; eax = 0 (success)
  420.         ret
  421.  
  422. ;  .get_window_caption:
  423. ;        dec     eax     ; subfunction #2 - get window caption
  424. ;        jnz     .exit_fail
  425.  
  426.         ; not implemented yet
  427. ;--------------------------------------
  428. align 4
  429. .exit_fail:
  430.         xor     eax, eax
  431.         inc     eax     ; eax = 1 (fail)
  432.         ret
  433. ;------------------------------------------------------------------------------
  434. align 4
  435. ;------------------------------------------------------------------------------
  436. set_window_defaults: ;/////////////////////////////////////////////////////////
  437. ;------------------------------------------------------------------------------
  438. ;? <description>
  439. ;------------------------------------------------------------------------------
  440.         mov     byte [window_data + 0x20 + WDATA.cl_titlebar + 3], 1 ; desktop is not movable
  441.         push    eax ecx
  442.         xor     eax, eax
  443.         mov     ecx, WIN_STACK
  444. ;--------------------------------------
  445. align 4
  446. @@:
  447.         inc     eax
  448.         add     ecx, 2
  449.         ; process no
  450.         mov     [ecx + 0x000], ax
  451.         ; positions in stack
  452.         mov     [ecx + 0x400], ax
  453.         cmp     ecx, WIN_POS - 2
  454.         jne     @b
  455.         pop     ecx eax
  456.         ret
  457. ;------------------------------------------------------------------------------
  458. align 4
  459. ;------------------------------------------------------------------------------
  460. calculatescreen: ;/////////////////////////////////////////////////////////////
  461. ;------------------------------------------------------------------------------
  462. ;? Scan all windows from bottom to top, calling `setscreen` for each one
  463. ;? intersecting given screen area
  464. ;------------------------------------------------------------------------------
  465. ;> eax = left
  466. ;> ebx = top
  467. ;> ecx = right
  468. ;> edx = bottom
  469. ;------------------------------------------------------------------------------
  470.         push    esi
  471.         pushfd
  472.         cli
  473.  
  474.         mov     esi, 1
  475.         call    window._.set_screen
  476.  
  477.         push    ebp
  478.  
  479.         mov     ebp, [TASK_COUNT]
  480.         cmp     ebp, 1
  481.         jbe     .exit
  482.  
  483.         push    edx ecx ebx eax
  484. ;--------------------------------------
  485. align 4
  486. .next_window:
  487.         movzx   edi, word[WIN_POS + esi * 2]
  488.         shl     edi, 5
  489.  
  490.         cmp     [CURRENT_TASK + edi + TASKDATA.state], TSTATE_FREE
  491.         je      .skip_window
  492.  
  493.         add     edi, window_data
  494.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  495.         jnz     .skip_window
  496.  
  497.         mov     eax, [edi + WDATA.box.left]
  498.         cmp     eax, [esp + RECT.right]
  499.         jg      .skip_window
  500.         mov     ebx, [edi + WDATA.box.top]
  501.         cmp     ebx, [esp + RECT.bottom]
  502.         jg      .skip_window
  503.         mov     ecx, [edi + WDATA.box.width]
  504.         add     ecx, eax
  505.         cmp     ecx, [esp + RECT.left]
  506.         jl      .skip_window
  507.         mov     edx, [edi + WDATA.box.height]
  508.         add     edx, ebx
  509.         cmp     edx, [esp + RECT.top]
  510.         jl      .skip_window
  511.  
  512.         cmp     eax, [esp + RECT.left]
  513.         jae     @f
  514.         mov     eax, [esp + RECT.left]
  515. ;--------------------------------------
  516. align 4
  517. @@:
  518.         cmp     ebx, [esp + RECT.top]
  519.         jae     @f
  520.         mov     ebx, [esp + RECT.top]
  521. ;--------------------------------------
  522. align 4
  523. @@:
  524.         cmp     ecx, [esp + RECT.right]
  525.         jbe     @f
  526.         mov     ecx, [esp + RECT.right]
  527. ;--------------------------------------
  528. align 4
  529. @@:
  530.         cmp     edx, [esp + RECT.bottom]
  531.         jbe     @f
  532.         mov     edx, [esp + RECT.bottom]
  533. ;--------------------------------------
  534. align 4
  535. @@:
  536.         push    esi
  537.         movzx   esi, word[WIN_POS + esi * 2]
  538.         call    window._.set_screen
  539.         pop     esi
  540. ;--------------------------------------
  541. align 4
  542. .skip_window:
  543.         inc     esi
  544.         dec     ebp
  545.         jnz     .next_window
  546.  
  547.         pop     eax ebx ecx edx
  548. ;--------------------------------------
  549. align 4
  550. .exit:
  551.         pop     ebp
  552.         inc     [_display.mask_seqno]
  553.         popfd
  554.         pop     esi
  555.         ret
  556. ;------------------------------------------------------------------------------
  557. align 4
  558. ;------------------------------------------------------------------------------
  559. repos_windows: ;///////////////////////////////////////////////////////////////
  560. ;------------------------------------------------------------------------------
  561. ;? <description>
  562. ;------------------------------------------------------------------------------
  563.         mov     ecx, [TASK_COUNT]
  564.         mov     edi, window_data + sizeof.WDATA * 2
  565.         call    force_redraw_background
  566.         dec     ecx
  567.         jle     .exit
  568. ;--------------------------------------
  569. align 4
  570. .next_window:
  571.         mov     [edi + WDATA.fl_redraw], 1
  572.         test    [edi + WDATA.fl_wstate], WSTATE_MAXIMIZED
  573.         jnz     .fix_maximized
  574.  
  575.         mov     eax, [edi + WDATA.box.left]
  576.         add     eax, [edi + WDATA.box.width]
  577.         mov     ebx, [Screen_Max_X]
  578.         cmp     eax, ebx
  579.         jle     .fix_vertical
  580.         mov     eax, [edi + WDATA.box.width]
  581.         sub     eax, ebx
  582.         jle     @f
  583.         mov     [edi + WDATA.box.width], ebx
  584. ;--------------------------------------
  585. align 4
  586. @@:
  587.         sub     ebx, [edi + WDATA.box.width]
  588.         mov     [edi + WDATA.box.left], ebx
  589. ;--------------------------------------
  590. align 4
  591. .fix_vertical:
  592.         mov     eax, [edi + WDATA.box.top]
  593.         add     eax, [edi + WDATA.box.height]
  594.         mov     ebx, [Screen_Max_Y]
  595.         cmp     eax, ebx
  596.         jle     .fix_client_box
  597.         mov     eax, [edi + WDATA.box.height]
  598.         sub     eax, ebx
  599.         jle     @f
  600.         mov     [edi + WDATA.box.height], ebx
  601. ;--------------------------------------
  602. align 4
  603. @@:
  604.         sub     ebx, [edi + WDATA.box.height]
  605.         mov     [edi + WDATA.box.top], ebx
  606. ;--------------------------------------
  607. align 4
  608. .fix_client_box:
  609.         call    window._.set_window_clientbox
  610.         add     edi, sizeof.WDATA
  611.         loop    .next_window
  612. ;--------------------------------------
  613. align 4
  614. .exit:
  615.         ret
  616. ;--------------------------------------
  617. align 4
  618. .fix_maximized:
  619.         mov     eax, [screen_workarea.left]
  620.         mov     [edi + WDATA.box.left], eax
  621.         sub     eax, [screen_workarea.right]
  622.         neg     eax
  623.         mov     [edi + WDATA.box.width], eax
  624.         mov     eax, [screen_workarea.top]
  625.         mov     [edi + WDATA.box.top], eax
  626.         test    [edi + WDATA.fl_wstate], WSTATE_ROLLEDUP
  627.         jnz     .fix_client_box
  628.         sub     eax, [screen_workarea.bottom]
  629.         neg     eax
  630.         mov     [edi + WDATA.box.height], eax
  631.         jmp     .fix_client_box
  632. ;------------------------------------------------------------------------------
  633. ;align 4
  634. ;------------------------------------------------------------------------------
  635. ;sys_window_mouse: ;////////////////////////////////////////////////////////////
  636. ;------------------------------------------------------------------------------
  637. ;? <description>
  638. ;------------------------------------------------------------------------------
  639.         ; NOTE: commented out since doesn't provide necessary functionality
  640.         ;       anyway, to be reworked
  641. ;       push    eax
  642. ;
  643. ;       mov     eax, [timer_ticks]
  644. ;       cmp     [new_window_starting], eax
  645. ;       jb      .exit
  646. ;
  647. ;       mov     byte[MOUSE_BACKGROUND], 0
  648. ;       mov     byte[DONT_DRAW_MOUSE], 0
  649. ;
  650. ;       mov     [new_window_starting], eax
  651. ;
  652. ; .exit:
  653. ;       pop     eax
  654. ;        ret
  655. ;------------------------------------------------------------------------------
  656. align 4
  657. ;------------------------------------------------------------------------------
  658. draw_rectangle: ;//////////////////////////////////////////////////////////////
  659. ;------------------------------------------------------------------------------
  660. ;> eax = pack[16(left), 16(right)]
  661. ;> ebx = pack[16(top), 16(bottom)]
  662. ;> esi = color
  663. ;       ?? RR GG BB    ; 0x01000000 negation
  664. ;                      ; 0x02000000 used for draw_rectangle without top line
  665. ;                      ;           for example drawwindow_III and drawwindow_IV
  666. ;------------------------------------------------------------------------------
  667.         push    eax ebx ecx edi
  668.  
  669.         xor     edi, edi
  670. ;--------------------------------------
  671. align 4
  672. .flags_set:
  673.         push    ebx
  674.  
  675.         ; set line color
  676.         mov     ecx, esi
  677.         ; draw top border
  678.         rol     ebx, 16
  679.         push    ebx
  680.         rol     ebx, 16
  681.         pop     bx
  682.         test    ecx, 1 shl 25
  683.         jnz     @f
  684.         sub     ecx, 1 shl 25
  685. ;        call    [draw_line]
  686.         call    __sys_draw_line
  687. ;--------------------------------------
  688. align 4
  689. @@:
  690.         ; draw bottom border
  691.         mov     ebx, [esp - 2]
  692.         pop     bx
  693. ;        call    [draw_line]
  694.         call    __sys_draw_line
  695.  
  696.         pop     ebx
  697.         add     ebx, 1 * 65536 - 1
  698.  
  699.         ; draw left border
  700.         rol     eax, 16
  701.         push    eax
  702.         rol     eax, 16
  703.         pop     ax
  704. ;        call    [draw_line]
  705.         call    __sys_draw_line
  706.  
  707.         ; draw right border
  708.         mov     eax, [esp - 2]
  709.         pop     ax
  710. ;        call    [draw_line]
  711.         call    __sys_draw_line
  712.  
  713.         pop     edi ecx ebx eax
  714.         ret
  715. ;--------------------------------------
  716. align 4
  717. .forced:
  718.         push    eax ebx ecx edi
  719.         xor     edi, edi
  720.         inc     edi
  721.         jmp     .flags_set
  722. ;------------------------------------------------------------------------------
  723. align 4
  724. ;------------------------------------------------------------------------------
  725. drawwindow_I_caption: ;////////////////////////////////////////////////////////
  726. ;------------------------------------------------------------------------------
  727. ;? <description>
  728. ;------------------------------------------------------------------------------
  729.         push    [edx + WDATA.cl_titlebar]
  730.         mov     esi, edx
  731.  
  732.         mov     edx, [esi + WDATA.box.top]
  733.         mov     eax, edx
  734.         lea     ebx, [edx + 21]
  735.         inc     edx
  736.         add     eax, [esi + WDATA.box.height]
  737.  
  738.         cmp     ebx, eax
  739.         jbe     @f
  740.         mov     ebx, eax
  741. ;--------------------------------------
  742. align 4
  743. @@:
  744.         push    ebx
  745.  
  746.         xor     edi, edi
  747. ;--------------------------------------
  748. align 4
  749. .next_line:
  750.         mov     ebx, edx
  751.         shl     ebx, 16
  752.         add     ebx, edx
  753.         mov     eax, [esi + WDATA.box.left]
  754.         inc     eax
  755.         shl     eax, 16
  756.         add     eax, [esi + WDATA.box.left]
  757.         add     eax, [esi + WDATA.box.width]
  758.         dec     eax
  759.         mov     ecx, [esi + WDATA.cl_titlebar]
  760.         test    ecx, 0x80000000
  761.         jz      @f
  762.         sub     ecx, 0x00040404
  763.         mov     [esi + WDATA.cl_titlebar], ecx
  764. ;--------------------------------------
  765. align 4
  766. @@:
  767.         and     ecx, 0x00ffffff
  768. ;        call    [draw_line]
  769.         call    __sys_draw_line
  770.         inc     edx
  771.         cmp     edx, [esp]
  772.         jb      .next_line
  773.  
  774.         add     esp, 4
  775.         pop     [esi + WDATA.cl_titlebar]
  776.         ret
  777. ;------------------------------------------------------------------------------
  778. align 4
  779. ;------------------------------------------------------------------------------
  780. drawwindow_I: ;////////////////////////////////////////////////////////////////
  781. ;------------------------------------------------------------------------------
  782. ;? <description>
  783. ;------------------------------------------------------------------------------
  784.         pushad
  785.  
  786.         ; window border
  787.  
  788.         mov     eax, [edx + WDATA.box.left - 2]
  789.         mov     ax, word[edx + WDATA.box.left]
  790.         add     ax, word[edx + WDATA.box.width]
  791.         mov     ebx, [edx + WDATA.box.top - 2]
  792.         mov     bx, word[edx + WDATA.box.top]
  793.         add     bx, word[edx + WDATA.box.height]
  794.  
  795.         mov     esi, [edx + WDATA.cl_frames]
  796.         call    draw_rectangle
  797.  
  798.         ; window caption
  799.  
  800.         call    drawwindow_I_caption
  801.  
  802.         ; window client area
  803.  
  804.         ; do we need to draw it?
  805.         mov     edi, [esi + WDATA.cl_workarea]
  806.         test    edi, 0x40000000
  807.         jnz     .exit
  808.  
  809.         ; does client area have a positive size on screen?
  810.         mov     edx, [esi + WDATA.box.top]
  811.         add     edx, 21 + 5
  812.         mov     ebx, [esi + WDATA.box.top]
  813.         add     ebx, [esi + WDATA.box.height]
  814.         cmp     edx, ebx
  815.         jg      .exit
  816.  
  817.         ; okay, let's draw it
  818.         mov     eax, 1
  819.         mov     ebx, 21
  820.         mov     ecx, [esi + WDATA.box.width]
  821.         mov     edx, [esi + WDATA.box.height]
  822. ;        call    [drawbar]
  823.         call    vesa20_drawbar
  824. ;--------------------------------------
  825. align 4
  826. .exit:
  827.         popad
  828.         ret
  829. ;------------------------------------------------------------------------------
  830. align 4
  831. ;------------------------------------------------------------------------------
  832. drawwindow_III_caption: ;/////////////////////////////////////////////////////
  833. ;------------------------------------------------------------------------------
  834. ;? <description>
  835. ;------------------------------------------------------------------------------
  836.         mov     ecx, [edx + WDATA.cl_titlebar]
  837.         push    ecx
  838.         mov     esi, edx
  839.         mov     edx, [esi + WDATA.box.top]
  840.         add     edx, 4
  841.         mov     ebx, [esi + WDATA.box.top]
  842.         add     ebx, 20
  843.         mov     eax, [esi + WDATA.box.top]
  844.         add     eax, [esi + WDATA.box.height]
  845.  
  846.         cmp     ebx, eax
  847.         jb      @f
  848.         mov     ebx, eax
  849. ;--------------------------------------
  850. align 4
  851. @@:
  852.         push    ebx
  853.  
  854.         xor     edi, edi
  855. ;--------------------------------------
  856. align 4
  857. .next_line:
  858.         mov     ebx, edx
  859.         shl     ebx, 16
  860.         add     ebx, edx
  861.         mov     eax, [esi + WDATA.box.left]
  862.         shl     eax, 16
  863.         add     eax, [esi + WDATA.box.left]
  864.         add     eax, [esi + WDATA.box.width]
  865.         add     eax, 4 * 65536 - 4
  866.         mov     ecx, [esi + WDATA.cl_titlebar]
  867.         test    ecx, 0x40000000
  868.         jz      @f
  869.         add     ecx, 0x00040404
  870. ;--------------------------------------
  871. align 4
  872. @@:
  873.         test    ecx, 0x80000000
  874.         jz      @f
  875.         sub     ecx, 0x00040404
  876. ;--------------------------------------
  877. align 4
  878. @@:
  879.         mov     [esi + WDATA.cl_titlebar], ecx
  880.         and     ecx, 0x00ffffff
  881. ;        call    [draw_line]
  882.         call    __sys_draw_line
  883.         inc     edx
  884.         cmp     edx, [esp]
  885.         jb      .next_line
  886.  
  887.         add     esp, 4
  888.         pop     [esi + WDATA.cl_titlebar]
  889.         ret
  890. ;------------------------------------------------------------------------------
  891. align 4
  892. ;------------------------------------------------------------------------------
  893. drawwindow_III: ;//////////////////////////////////////////////////////////////
  894. ;------------------------------------------------------------------------------
  895. ;? <description>
  896. ;------------------------------------------------------------------------------
  897.         pushad
  898.  
  899.         ; window border
  900.  
  901.         mov     eax, [edx + WDATA.box.left - 2]
  902.         mov     ax, word[edx + WDATA.box.left]
  903.         add     ax, word[edx + WDATA.box.width]
  904.         mov     ebx, [edx + WDATA.box.top - 2]
  905.         mov     bx, word[edx + WDATA.box.top]
  906.         add     bx, word[edx + WDATA.box.height]
  907.  
  908.         mov     esi, [edx + WDATA.cl_frames]
  909.         shr     esi, 1
  910.         and     esi, 0x007f7f7f
  911.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  912.         ror     ebx, 16
  913.         add     ebx, [_skinh]
  914.         sub     bx, 1
  915.         rol     ebx, 16
  916.         call    draw_rectangle
  917.  
  918.         push    esi
  919.         mov     ecx, 3
  920.         mov     esi, [edx + WDATA.cl_frames]
  921.         or      esi, 1 shl 25; 0x02000000 used for draw_rectangle without top line
  922. ;--------------------------------------
  923. align 4
  924. .next_frame:
  925.         add     eax, 1 * 65536 - 1
  926.         add     ebx, 0 * 65536 - 1
  927.         call    draw_rectangle
  928.         dec     ecx
  929.         jnz     .next_frame
  930.  
  931.         pop     esi
  932.         add     eax, 1 * 65536 - 1
  933.         add     ebx, 0 * 65536 - 1
  934.         call    draw_rectangle
  935.  
  936.         ; window caption
  937.  
  938.         call    drawwindow_III_caption
  939.  
  940.         ; window client area
  941.  
  942.         ; do we need to draw it?
  943.         mov     edi, [esi + WDATA.cl_workarea]
  944.         test    edi, 0x40000000
  945.         jnz     .exit
  946.  
  947.         ; does client area have a positive size on screen?
  948.         mov     edx, [esi + WDATA.box.top]
  949.         add     edx, 21 + 5
  950.         mov     ebx, [esi + WDATA.box.top]
  951.         add     ebx, [esi + WDATA.box.height]
  952.         cmp     edx, ebx
  953.         jg      .exit
  954.  
  955.         ; okay, let's draw it
  956.         mov     eax, 5
  957.         mov     ebx, 20
  958.         mov     ecx, [esi + WDATA.box.width]
  959.         mov     edx, [esi + WDATA.box.height]
  960.         sub     ecx, 4
  961.         sub     edx, 4
  962. ;        call    [drawbar]
  963.         call    vesa20_drawbar
  964. ;--------------------------------------
  965. align 4
  966. .exit:
  967.         popad
  968.         ret
  969. ;------------------------------------------------------------------------------
  970. align 4
  971. ;------------------------------------------------------------------------------
  972. waredraw: ;////////////////////////////////////////////////////////////////////
  973. ;------------------------------------------------------------------------------
  974. ;? Activate window, redrawing if necessary
  975. ;------------------------------------------------------------------------------
  976.         push    -1
  977.         mov     eax, [TASK_COUNT]
  978.         lea     eax, [WIN_POS + eax * 2]
  979.         cmp     eax, esi
  980.         pop     eax
  981.         je      .exit
  982.  
  983.         ; is it overlapped by another window now?
  984.         push    ecx
  985.         call    window._.check_window_draw
  986.         test    ecx, ecx
  987.         pop     ecx
  988.         jz      .do_not_draw
  989.  
  990.         ; yes it is, activate and update screen buffer
  991.         mov     byte[MOUSE_DOWN], 1
  992.         call    window._.window_activate
  993.  
  994.         pushad
  995.         mov     edi, [TASK_COUNT]
  996.         movzx   esi, word[WIN_POS + edi * 2]
  997.         shl     esi, 5
  998.         add     esi, window_data
  999.  
  1000.         mov     eax, [esi + WDATA.box.left]
  1001.         mov     ebx, [esi + WDATA.box.top]
  1002.         mov     ecx, [esi + WDATA.box.width]
  1003.         mov     edx, [esi + WDATA.box.height]
  1004.  
  1005.         add     ecx, eax
  1006.         add     edx, ebx
  1007.  
  1008.         mov     edi, [TASK_COUNT]
  1009.         movzx   esi, word[WIN_POS + edi * 2]
  1010.         call    window._.set_screen
  1011.         inc     [_display.mask_seqno]
  1012.         popad
  1013.  
  1014.         ; tell application to redraw itself
  1015.         mov     [edi + WDATA.fl_redraw], 1
  1016.         xor     eax, eax
  1017.         jmp     .exit
  1018. ;--------------------------------------
  1019. align 4
  1020. .do_not_draw:
  1021.         ; no it's not, just activate the window
  1022.         call    window._.window_activate
  1023.         xor     eax, eax
  1024.         mov     byte[MOUSE_BACKGROUND], al
  1025.         mov     byte[DONT_DRAW_MOUSE], al
  1026. ;--------------------------------------
  1027. align 4
  1028. .exit:
  1029.         mov     byte[MOUSE_DOWN], 0
  1030.         inc     eax
  1031.         ret
  1032. ;------------------------------------------------------------------------------
  1033. align 4
  1034. ;------------------------------------------------------------------------------
  1035. minimize_window: ;/////////////////////////////////////////////////////////////
  1036. ;------------------------------------------------------------------------------
  1037. ;> eax = window number on screen
  1038. ;------------------------------------------------------------------------------
  1039. ;# corrupts [dl*]
  1040. ;------------------------------------------------------------------------------
  1041.         push    edi
  1042.         pushfd
  1043.         cli
  1044.  
  1045.         ; is it already minimized?
  1046.         movzx   edi, word[WIN_POS + eax * 2]
  1047.         shl     edi, 5
  1048.         add     edi, window_data
  1049.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1050.         jnz     .exit
  1051.  
  1052.         push    eax ebx ecx edx esi
  1053.  
  1054.         ; no it's not, let's do that
  1055.         or      [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1056.         mov     eax, [edi + WDATA.box.left]
  1057.         mov     [draw_limits.left], eax
  1058.         mov     ecx, eax
  1059.         add     ecx, [edi + WDATA.box.width]
  1060.         mov     [draw_limits.right], ecx
  1061.         mov     ebx, [edi + WDATA.box.top]
  1062.         mov     [draw_limits.top], ebx
  1063.         mov     edx, ebx
  1064.         add     edx, [edi + WDATA.box.height]
  1065.         mov     [draw_limits.bottom], edx
  1066.         call    calculatescreen
  1067.         xor     esi, esi
  1068.         xor     eax, eax
  1069.         call    redrawscreen
  1070.  
  1071.         pop     esi edx ecx ebx eax
  1072. ;--------------------------------------
  1073. align 4
  1074. .exit:
  1075.         popfd
  1076.         pop     edi
  1077.         ret
  1078. ;------------------------------------------------------------------------------
  1079. align 4
  1080. ;------------------------------------------------------------------------------
  1081. restore_minimized_window: ;////////////////////////////////////////////////////
  1082. ;------------------------------------------------------------------------------
  1083. ;> eax = window number on screen
  1084. ;------------------------------------------------------------------------------
  1085. ;# corrupts [dl*]
  1086. ;------------------------------------------------------------------------------
  1087.         pushad
  1088.         pushfd
  1089.         cli
  1090.  
  1091.         ; is it already restored?
  1092.         movzx   esi, word[WIN_POS + eax * 2]
  1093.         mov     edi, esi
  1094.         shl     edi, 5
  1095.         add     edi, window_data
  1096.         test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  1097.         jz      .exit
  1098.  
  1099.         ; no it's not, let's do that
  1100.         mov     [edi + WDATA.fl_redraw], 1
  1101.         and     [edi + WDATA.fl_wstate], not WSTATE_MINIMIZED
  1102.         mov     ebp, window._.set_screen
  1103.         cmp     eax, [TASK_COUNT]
  1104.         jz      @f
  1105.         mov     ebp, calculatescreen
  1106. ;--------------------------------------
  1107. align 4
  1108. @@:
  1109.         mov     eax, [edi + WDATA.box.left]
  1110.         mov     ebx, [edi + WDATA.box.top]
  1111.         mov     ecx, [edi + WDATA.box.width]
  1112.         mov     edx, [edi + WDATA.box.height]
  1113.         add     ecx, eax
  1114.         add     edx, ebx
  1115.         call    ebp
  1116.         inc     [_display.mask_seqno]
  1117.         mov     byte[MOUSE_BACKGROUND], 0
  1118. ;--------------------------------------
  1119. align 4
  1120. .exit:
  1121.         popfd
  1122.         popad
  1123.         ret
  1124. ;------------------------------------------------------------------------------
  1125. align 4
  1126. ; TODO: remove this proc
  1127. ;------------------------------------------------------------------------------
  1128. window_check_events: ;/////////////////////////////////////////////////////////
  1129. ;------------------------------------------------------------------------------
  1130. ;? <description>
  1131. ;------------------------------------------------------------------------------
  1132.         ; do we have window minimize/restore request?
  1133.         cmp     [window_minimize], 0
  1134.         je      .exit
  1135.  
  1136.         ; okay, minimize or restore top-most window and exit
  1137.         mov     eax, [TASK_COUNT]
  1138.         mov     bl, 0
  1139.         xchg    [window_minimize], bl
  1140.         dec     bl
  1141.         jnz     @f
  1142.         call    minimize_window
  1143.         jmp     .exit
  1144. ;--------------------------------------
  1145. align 4
  1146. @@:
  1147.         call    restore_minimized_window
  1148. ;--------------------------------------
  1149. align 4
  1150. .exit:
  1151.         ret
  1152. ;------------------------------------------------------------------------------
  1153. align 4
  1154. ;------------------------------------------------------------------------------
  1155. sys_window_maximize_handler: ;/////////////////////////////////////////////////
  1156. ;------------------------------------------------------------------------------
  1157. ;? <description>
  1158. ;------------------------------------------------------------------------------
  1159. ;> esi = process slot
  1160. ;------------------------------------------------------------------------------
  1161.         mov     edi, esi
  1162.         shl     edi, 5
  1163.         add     edi, window_data
  1164.  
  1165.         ; can window change its height?
  1166.         ; only types 2 and 3 can be resized
  1167.         mov     dl, [edi + WDATA.fl_wstyle]
  1168.         test    dl, 2
  1169.         jz      .exit
  1170.  
  1171.         ; toggle normal/maximized window state
  1172.         mov     bl, [edi + WDATA.fl_wstate]
  1173.         xor     bl, WSTATE_MAXIMIZED
  1174.  
  1175.         ; calculate and set appropriate window bounds
  1176.         test    bl, WSTATE_MAXIMIZED
  1177.         jz      .restore_size
  1178.  
  1179.         mov     eax, [screen_workarea.left]
  1180.         mov     ecx, [screen_workarea.top]
  1181.         push    [screen_workarea.bottom] \
  1182.                 [screen_workarea.right] \
  1183.                 ecx \
  1184.                 eax
  1185.         sub     [esp + BOX.width], eax
  1186.         sub     [esp + BOX.height], ecx
  1187.         mov     eax, esp
  1188.         jmp     .set_box
  1189. ;--------------------------------------
  1190. align 4
  1191. .restore_size:
  1192.         mov     eax, esi
  1193.         shl     eax, 8
  1194.         add     eax, SLOT_BASE + APPDATA.saved_box
  1195.         push    [eax + BOX.height] \
  1196.                 [eax + BOX.width] \
  1197.                 [eax + BOX.top] \
  1198.                 [eax + BOX.left]
  1199.         mov     eax, esp
  1200. ;--------------------------------------
  1201. align 4
  1202. .set_box:
  1203.         test    bl, WSTATE_ROLLEDUP
  1204.         jz      @f
  1205.  
  1206.         xchg    eax, ecx
  1207.         call    window._.get_rolledup_height
  1208.         mov     [ecx + BOX.height], eax
  1209.         xchg    eax, ecx
  1210. ;--------------------------------------
  1211. align 4
  1212. @@:
  1213.         call    window._.set_window_box
  1214.         add     esp, sizeof.BOX
  1215. ;--------------------------------------
  1216. align 4
  1217. .exit:
  1218.         inc     [_display.mask_seqno]
  1219.         ret
  1220. ;------------------------------------------------------------------------------
  1221. align 4
  1222. ;------------------------------------------------------------------------------
  1223. sys_window_rollup_handler: ;///////////////////////////////////////////////////
  1224. ;------------------------------------------------------------------------------
  1225. ;? <description>
  1226. ;------------------------------------------------------------------------------
  1227. ;> esi = process slot
  1228. ;------------------------------------------------------------------------------
  1229.         mov     edx, esi
  1230.         shl     edx, 8
  1231.         add     edx, SLOT_BASE
  1232.  
  1233.         ; toggle normal/rolled up window state
  1234.         mov     bl, [edi + WDATA.fl_wstate]
  1235.         xor     bl, WSTATE_ROLLEDUP
  1236.  
  1237.         ; calculate and set appropriate window bounds
  1238.         test    bl, WSTATE_ROLLEDUP
  1239.         jz      .restore_size
  1240.  
  1241.         call    window._.get_rolledup_height
  1242.         push    eax \
  1243.                 [edi + WDATA.box.width] \
  1244.                 [edi + WDATA.box.top] \
  1245.                 [edi + WDATA.box.left]
  1246.         mov     eax, esp
  1247.         jmp     .set_box
  1248. ;--------------------------------------
  1249. align 4
  1250. .restore_size:
  1251.         test    bl, WSTATE_MAXIMIZED
  1252.         jnz     @f
  1253.         add     esp, -sizeof.BOX
  1254.         lea     eax, [edx + APPDATA.saved_box]
  1255.         jmp     .set_box
  1256. ;--------------------------------------
  1257. align 4
  1258. @@:
  1259.         mov     eax, [screen_workarea.top]
  1260.         push    [screen_workarea.bottom] \
  1261.                 [edi + WDATA.box.width] \
  1262.                 eax \
  1263.                 [edi + WDATA.box.left]
  1264.         sub     [esp + BOX.height], eax
  1265.         mov     eax, esp
  1266. ;--------------------------------------
  1267. align 4
  1268. .set_box:
  1269.         call    window._.set_window_box
  1270.         add     esp, sizeof.BOX
  1271.         ret
  1272. ;------------------------------------------------------------------------------
  1273. align 4
  1274. ;------------------------------------------------------------------------------
  1275. sys_window_start_moving_handler: ;/////////////////////////////////////////////
  1276. ;------------------------------------------------------------------------------
  1277. ;? <description>
  1278. ;------------------------------------------------------------------------------
  1279. ;> eax = old (original) window box
  1280. ;> esi = process slot
  1281. ;------------------------------------------------------------------------------
  1282.         mov     edi, eax
  1283.         call    window._.draw_negative_box
  1284.         ret
  1285. ;------------------------------------------------------------------------------
  1286. align 4
  1287. ;------------------------------------------------------------------------------
  1288. sys_window_end_moving_handler: ;///////////////////////////////////////////////
  1289. ;------------------------------------------------------------------------------
  1290. ;? <description>
  1291. ;------------------------------------------------------------------------------
  1292. ;> eax = old (original) window box
  1293. ;> ebx = new (final) window box
  1294. ;> esi = process slot
  1295. ;------------------------------------------------------------------------------
  1296.         mov     edi, ebx
  1297.         call    window._.end_moving__box
  1298.  
  1299.         mov     edi, esi
  1300.         shl     edi, 5
  1301.         add     edi, window_data
  1302.  
  1303.         mov     eax, ebx
  1304.         mov     bl, [edi + WDATA.fl_wstate]
  1305.         call    window._.set_window_box
  1306.         ret
  1307. ;------------------------------------------------------------------------------
  1308. align 4
  1309. ;------------------------------------------------------------------------------
  1310. sys_window_moving_handler: ;///////////////////////////////////////////////////
  1311. ;------------------------------------------------------------------------------
  1312. ;? <description>
  1313. ;------------------------------------------------------------------------------
  1314. ;> eax = old (from previous call) window box
  1315. ;> ebx = new (current) window box
  1316. ;> esi = process_slot
  1317. ;------------------------------------------------------------------------------
  1318.         mov     edi, eax
  1319.         call    window._.draw_negative_box
  1320.         mov     edi, ebx
  1321.         call    window._.draw_negative_box
  1322.         ret
  1323. ;==============================================================================
  1324. ;///// private functions //////////////////////////////////////////////////////
  1325. ;==============================================================================
  1326.  
  1327. iglobal
  1328.   FuncTable syscall_display_settings, ftable, \
  1329.     00, 01, 02, 03, 04, 05, 06, 07, 08
  1330.  
  1331.   align 4
  1332.   window_topleft dd \
  1333.     1, 21, \ ;type 0
  1334.     0,  0, \ ;type 1
  1335.     5, 20, \ ;type 2
  1336.     5,  ?, \ ;type 3 {set by skin}
  1337.     5,  ?    ;type 4 {set by skin}
  1338. endg
  1339.  
  1340. ;uglobal
  1341.   ; NOTE: commented out since doesn't provide necessary functionality anyway,
  1342.   ;       to be reworked
  1343. ; new_window_starting       dd ?
  1344. ;endg
  1345. ;------------------------------------------------------------------------------
  1346. align 4
  1347. ;------------------------------------------------------------------------------
  1348. window._.invalidate_screen: ;//////////////////////////////////////////////////
  1349. ;------------------------------------------------------------------------------
  1350. ;? <description>
  1351. ;------------------------------------------------------------------------------
  1352. ;> eax = old (original) window box
  1353. ;> ebx = new (final) window box
  1354. ;> edi = pointer to WDATA struct
  1355. ;------------------------------------------------------------------------------
  1356.         push    eax ebx
  1357.  
  1358.         ; TODO: do we really need `draw_limits`?
  1359.         ; Yes, they are used by background drawing code.
  1360.         mov     ecx, [eax + BOX.left]
  1361.         mov     edx, [ebx + BOX.left]
  1362.         cmp     ecx, edx
  1363.         jle     @f
  1364.         mov     ecx, edx
  1365. ;--------------------------------------
  1366. align 4
  1367. @@:
  1368.         mov     [draw_limits.left], ecx
  1369.         mov     ecx, [eax + BOX.left]
  1370.         add     ecx, [eax + BOX.width]
  1371.         add     edx, [ebx + BOX.width]
  1372.         cmp     ecx, edx
  1373.         jae     @f
  1374.         mov     ecx, edx
  1375. ;--------------------------------------
  1376. align 4
  1377. @@:
  1378.         mov     [draw_limits.right], ecx
  1379.         mov     ecx, [eax + BOX.top]
  1380.         mov     edx, [ebx + BOX.top]
  1381.         cmp     ecx, edx
  1382.         jle     @f
  1383.         mov     ecx, edx
  1384. ;--------------------------------------
  1385. align 4
  1386. @@:
  1387.         mov     [draw_limits.top], ecx
  1388.         mov     ecx, [eax + BOX.top]
  1389.         add     ecx, [eax + BOX.height]
  1390.         add     edx, [ebx + BOX.height]
  1391.         cmp     ecx, edx
  1392.         jae     @f
  1393.         mov     ecx, edx
  1394. ;--------------------------------------
  1395. align 4
  1396. @@:
  1397.         mov     [draw_limits.bottom], ecx
  1398.         ; recalculate screen buffer at old position
  1399.         push    ebx
  1400.         mov     edx, [eax + BOX.height]
  1401.         mov     ecx, [eax + BOX.width]
  1402.         mov     ebx, [eax + BOX.top]
  1403.         mov     eax, [eax + BOX.left]
  1404.         add     ecx, eax
  1405.         add     edx, ebx
  1406.         call    calculatescreen
  1407.         pop     eax
  1408.         ; recalculate screen buffer at new position
  1409.         mov     edx, [eax + BOX.height]
  1410.         mov     ecx, [eax + BOX.width]
  1411.         mov     ebx, [eax + BOX.top]
  1412.         mov     eax, [eax + BOX.left]
  1413.         add     ecx, eax
  1414.         add     edx, ebx
  1415.         call    calculatescreen
  1416.  
  1417.         mov     eax, edi
  1418.         call    redrawscreen
  1419.  
  1420.         ; tell window to redraw itself
  1421.         mov     [edi + WDATA.fl_redraw], 1
  1422.  
  1423.         pop     ebx eax
  1424.         ret
  1425. ;------------------------------------------------------------------------------
  1426. align 4
  1427. ;------------------------------------------------------------------------------
  1428. window._.set_window_box: ;/////////////////////////////////////////////////////
  1429. ;------------------------------------------------------------------------------
  1430. ;? <description>
  1431. ;------------------------------------------------------------------------------
  1432. ;> eax = pointer to BOX struct
  1433. ;> bl = new window state flags
  1434. ;> edi = pointer to WDATA struct
  1435. ;------------------------------------------------------------------------------
  1436.         push    eax ebx esi
  1437.  
  1438. ; don't do anything if the new box is identical to the old
  1439.         cmp     bl, [edi + WDATA.fl_wstate]
  1440.         jnz     @f
  1441.         mov     esi, eax
  1442.         push    edi
  1443. if WDATA.box
  1444.         add     edi, WDATA.box
  1445. end if
  1446.         mov     ecx, 4
  1447.         repz cmpsd
  1448.         pop     edi
  1449.         jz      .exit
  1450. ;--------------------------------------
  1451. align 4
  1452. @@:
  1453.         add     esp, -sizeof.BOX
  1454.         mov     ebx, esp
  1455. if WDATA.box
  1456.         lea     esi, [edi + WDATA.box]
  1457. else
  1458.         mov     esi, edi ; optimization for WDATA.box = 0
  1459. end if
  1460.         xchg    eax, esi
  1461.         mov     ecx, sizeof.BOX
  1462.         call    memmove
  1463.         xchg    eax, esi
  1464.         xchg    ebx, esi
  1465.         call    memmove
  1466.         mov     eax, ebx
  1467.         mov     ebx, esi
  1468.  
  1469.         call    window._.check_window_position
  1470.         call    window._.set_window_clientbox
  1471.         call    window._.invalidate_screen
  1472.  
  1473.         add     esp, sizeof.BOX
  1474.  
  1475.         mov     cl, [esp + 4]
  1476.         mov     ch, cl
  1477.         xchg    cl, [edi + WDATA.fl_wstate]
  1478.  
  1479.         or      cl, ch
  1480.         test    cl, WSTATE_MAXIMIZED
  1481.         jnz     .exit
  1482.  
  1483.         mov     eax, edi
  1484.         sub     eax, window_data
  1485.         shl     eax, 3
  1486.         add     eax, SLOT_BASE
  1487.  
  1488.         lea     ebx, [edi + WDATA.box]
  1489.         xchg    esp, ebx
  1490.  
  1491.         pop     [eax + APPDATA.saved_box.left] \
  1492.                 [eax + APPDATA.saved_box.top] \
  1493.                 [eax + APPDATA.saved_box.width] \
  1494.                 edx
  1495.  
  1496.         xchg    esp, ebx
  1497.  
  1498.         test    ch, WSTATE_ROLLEDUP
  1499.         jnz     .exit
  1500.  
  1501.         mov     [eax + APPDATA.saved_box.height], edx
  1502. ;--------------------------------------
  1503. align 4
  1504. .exit:
  1505.         pop     esi ebx eax
  1506.         ret
  1507. ;------------------------------------------------------------------------------
  1508. align 4
  1509. ;------------------------------------------------------------------------------
  1510. window._.set_window_clientbox: ;///////////////////////////////////////////////
  1511. ;------------------------------------------------------------------------------
  1512. ;? <description>
  1513. ;------------------------------------------------------------------------------
  1514. ;> edi = pointer to WDATA struct
  1515. ;------------------------------------------------------------------------------
  1516.         push    eax ecx edi
  1517.  
  1518.         mov     eax, [_skinh]
  1519.         mov     [window_topleft + 8 * 3 + 4], eax
  1520.         mov     [window_topleft + 8 * 4 + 4], eax
  1521.  
  1522.         mov     ecx, edi
  1523.         sub     edi, window_data
  1524.         shl     edi, 3
  1525.         test    [ecx + WDATA.fl_wstyle], WSTYLE_CLIENTRELATIVE
  1526.         jz      .whole_window
  1527.  
  1528.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1529.         and     eax, 0x0F
  1530.         mov     eax, [eax * 8 + window_topleft + 0]
  1531.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1532.         shl     eax, 1
  1533.         neg     eax
  1534.         add     eax, [ecx + WDATA.box.width]
  1535.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1536.  
  1537.         movzx   eax, [ecx + WDATA.fl_wstyle]
  1538.         and     eax, 0x0F
  1539.         push    [eax * 8 + window_topleft + 0]
  1540.         mov     eax, [eax * 8 + window_topleft + 4]
  1541.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1542.         neg     eax
  1543.         sub     eax, [esp]
  1544.         add     eax, [ecx + WDATA.box.height]
  1545.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1546.         add     esp, 4
  1547.         jmp     .exit
  1548. ;--------------------------------------
  1549. align 4
  1550. .whole_window:
  1551.         xor     eax, eax
  1552.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.left], eax
  1553.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.top], eax
  1554.         mov     eax, [ecx + WDATA.box.width]
  1555.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.width], eax
  1556.         mov     eax, [ecx + WDATA.box.height]
  1557.         mov     [edi + SLOT_BASE + APPDATA.wnd_clientbox.height], eax
  1558. ;--------------------------------------
  1559. align 4
  1560. .exit:
  1561.         pop     edi ecx eax
  1562.         ret
  1563. ;------------------------------------------------------------------------------
  1564. align 4
  1565. ;------------------------------------------------------------------------------
  1566. window._.sys_set_window: ;/////////////////////////////////////////////////////
  1567. ;------------------------------------------------------------------------------
  1568. ;? <description>
  1569. ;------------------------------------------------------------------------------
  1570. ;< edx = pointer to WDATA struct
  1571. ;------------------------------------------------------------------------------
  1572.         mov     eax, [CURRENT_TASK]
  1573.         shl     eax, 5
  1574.         add     eax, window_data
  1575.  
  1576.         ; save window colors
  1577.         mov     [eax + WDATA.cl_workarea], edx
  1578.         mov     [eax + WDATA.cl_titlebar], esi
  1579.         mov     [eax + WDATA.cl_frames], edi
  1580.  
  1581.         mov     edi, eax
  1582.  
  1583.         ; was it already defined before?
  1584.         test    [edi + WDATA.fl_wdrawn], 1
  1585.         jnz     .set_client_box
  1586.         or      [edi + WDATA.fl_wdrawn], 1
  1587.  
  1588.         ; NOTE: commented out since doesn't provide necessary functionality
  1589.         ;       anyway, to be reworked
  1590. ;       mov     eax, [timer_ticks] ; [0xfdf0]
  1591. ;       add     eax, 100
  1592. ;       mov     [new_window_starting], eax
  1593.  
  1594.         ; no it wasn't, performing initial window definition
  1595.         movzx   eax, bx
  1596.         mov     [edi + WDATA.box.width], eax
  1597.         movzx   eax, cx
  1598.         mov     [edi + WDATA.box.height], eax
  1599.         sar     ebx, 16
  1600.         sar     ecx, 16
  1601.         mov     [edi + WDATA.box.left], ebx
  1602.         mov     [edi + WDATA.box.top], ecx
  1603.  
  1604.         call    window._.check_window_position
  1605.  
  1606.         push    ecx edi
  1607.  
  1608.         mov     cl, [edi + WDATA.fl_wstyle]
  1609.         mov     eax, [edi + WDATA.cl_frames]
  1610.  
  1611.         sub     edi, window_data
  1612.         shl     edi, 3
  1613.         add     edi, SLOT_BASE
  1614.  
  1615.         and     cl, 0x0F
  1616.         cmp     cl, 3
  1617.         je      @f
  1618.         cmp     cl, 4
  1619.         je      @f
  1620.  
  1621.         xor     eax, eax
  1622. ;--------------------------------------
  1623. align 4
  1624. @@:
  1625.         mov     [edi + APPDATA.wnd_caption], eax
  1626.  
  1627.         mov     esi, [esp]
  1628.         add     edi, APPDATA.saved_box
  1629.         movsd
  1630.         movsd
  1631.         movsd
  1632.         movsd
  1633.  
  1634.         pop     edi ecx
  1635.  
  1636.         mov     esi, [CURRENT_TASK]
  1637.         movzx   esi, word[WIN_STACK + esi * 2]
  1638.         lea     esi, [WIN_POS + esi * 2]
  1639.         call    waredraw
  1640.  
  1641.         mov     eax, [edi + WDATA.box.left]
  1642.         mov     ebx, [edi + WDATA.box.top]
  1643.         mov     ecx, [edi + WDATA.box.width]
  1644.         mov     edx, [edi + WDATA.box.height]
  1645.         add     ecx, eax
  1646.         add     edx, ebx
  1647.         call    calculatescreen
  1648.  
  1649.         mov     byte[KEY_COUNT], 0           ; empty keyboard buffer
  1650.         mov     byte[BTN_COUNT], 0           ; empty button buffer
  1651. ;--------------------------------------
  1652. align 4
  1653. .set_client_box:
  1654.         ; update window client box coordinates
  1655.         call    window._.set_window_clientbox
  1656.  
  1657.         ; reset window redraw flag and exit
  1658.         mov     [edi + WDATA.fl_redraw], 0
  1659.         mov     edx, edi
  1660.         ret
  1661. ;------------------------------------------------------------------------------
  1662. align 4
  1663. ;------------------------------------------------------------------------------
  1664. window._.check_window_position: ;//////////////////////////////////////////////
  1665. ;------------------------------------------------------------------------------
  1666. ;? Check if window is inside screen area
  1667. ;------------------------------------------------------------------------------
  1668. ;> edi = pointer to WDATA
  1669. ;------------------------------------------------------------------------------
  1670.         push    eax ebx ecx edx esi
  1671.  
  1672.         mov     eax, [edi + WDATA.box.left]
  1673.         mov     ebx, [edi + WDATA.box.top]
  1674.         mov     ecx, [edi + WDATA.box.width]
  1675.         mov     edx, [edi + WDATA.box.height]
  1676.  
  1677.         mov     esi, [Screen_Max_X]
  1678.         cmp     ecx, esi
  1679.         ja      .fix_width_high
  1680. ;--------------------------------------
  1681. align 4
  1682. .check_left:
  1683.         or      eax, eax
  1684.         jl      .fix_left_low
  1685.         add     eax, ecx
  1686.         cmp     eax, esi
  1687.         jg      .fix_left_high
  1688. ;--------------------------------------
  1689. align 4
  1690. .check_height:
  1691.         mov     esi, [Screen_Max_Y]
  1692.         cmp     edx, esi
  1693.         ja      .fix_height_high
  1694. ;--------------------------------------
  1695. align 4
  1696. .check_top:
  1697.         or      ebx, ebx
  1698.         jl      .fix_top_low
  1699.         add     ebx, edx
  1700.         cmp     ebx, esi
  1701.         jg      .fix_top_high
  1702. ;--------------------------------------
  1703. align 4
  1704. .exit:
  1705.         pop     esi edx ecx ebx eax
  1706.         ret
  1707. ;--------------------------------------
  1708. align 4
  1709. .fix_width_high:
  1710.         mov     ecx, esi
  1711.         mov     [edi + WDATA.box.width], esi
  1712.         jmp     .check_left
  1713. ;--------------------------------------
  1714. align 4
  1715. .fix_left_low:
  1716.         xor     eax, eax
  1717.         mov     [edi + WDATA.box.left], eax
  1718.         jmp     .check_height
  1719. ;--------------------------------------
  1720. align 4
  1721. .fix_left_high:
  1722.         mov     eax, esi
  1723.         sub     eax, ecx
  1724.         mov     [edi + WDATA.box.left], eax
  1725.         jmp     .check_height
  1726. ;--------------------------------------
  1727. align 4
  1728. .fix_height_high:
  1729.         mov     edx, esi
  1730.         mov     [edi + WDATA.box.height], esi
  1731.         jmp     .check_top
  1732. ;--------------------------------------
  1733. align 4
  1734. .fix_top_low:
  1735.         xor     ebx, ebx
  1736.         mov     [edi + WDATA.box.top], ebx
  1737.         jmp     .exit
  1738. ;--------------------------------------
  1739. align 4
  1740. .fix_top_high:
  1741.         mov     ebx, esi
  1742.         sub     ebx, edx
  1743.         mov     [edi + WDATA.box.top], ebx
  1744.         jmp     .exit
  1745. ;------------------------------------------------------------------------------
  1746. align 4
  1747. ;------------------------------------------------------------------------------
  1748. window._.get_titlebar_height: ;////////////////////////////////////////////////
  1749. ;------------------------------------------------------------------------------
  1750. ;? <description>
  1751. ;------------------------------------------------------------------------------
  1752. ;> edi = pointer to WDATA
  1753. ;------------------------------------------------------------------------------
  1754.         mov     al, [edi + WDATA.fl_wstyle]
  1755.         and     al, 0x0f
  1756.         cmp     al, 0x03
  1757.         jne     @f
  1758.         mov     eax, [_skinh]
  1759.         ret
  1760. ;--------------------------------------
  1761. align 4
  1762. @@:
  1763.         mov     eax, 21
  1764.         ret
  1765. ;------------------------------------------------------------------------------
  1766. align 4
  1767. ;------------------------------------------------------------------------------
  1768. window._.get_rolledup_height: ;////////////////////////////////////////////////
  1769. ;------------------------------------------------------------------------------
  1770. ;? <description>
  1771. ;------------------------------------------------------------------------------
  1772. ;> edi = pointer to WDATA
  1773. ;------------------------------------------------------------------------------
  1774.         mov     al, [edi + WDATA.fl_wstyle]
  1775.         and     al, 0x0f
  1776.         cmp     al, 0x03
  1777.         jb      @f
  1778.         mov     eax, [_skinh]
  1779.         add     eax, 3
  1780.         ret
  1781. ;--------------------------------------
  1782. align 4
  1783. @@:
  1784.         or      al, al
  1785.         jnz     @f
  1786.         mov     eax, 21
  1787.         ret
  1788. ;--------------------------------------
  1789. align 4
  1790. @@:
  1791.         mov     eax, 21 + 2
  1792.         ret
  1793. ;------------------------------------------------------------------------------
  1794. align 4
  1795. ;------------------------------------------------------------------------------
  1796. window._.set_screen: ;/////////////////////////////////////////////////////////
  1797. ;------------------------------------------------------------------------------
  1798. ;? Reserve window area in screen buffer
  1799. ;------------------------------------------------------------------------------
  1800. ;> eax = left
  1801. ;> ebx = top
  1802. ;> ecx = right
  1803. ;> edx = bottom
  1804. ;> esi = process number
  1805. ;------------------------------------------------------------------------------
  1806. virtual at esp
  1807.   ff_x     dd ?
  1808.   ff_y     dd ?
  1809.   ff_width dd ?
  1810.   ff_xsz   dd ?
  1811.   ff_ysz   dd ?
  1812.   ff_scale dd ?
  1813. end virtual
  1814.  
  1815.         pushad
  1816.  
  1817.         cmp     esi, 1
  1818.         jz      .check_for_shaped_window
  1819.         mov     edi, esi
  1820.         shl     edi, 5
  1821.         cmp     [window_data + edi + WDATA.box.width], 0
  1822.         jnz     .check_for_shaped_window
  1823.         cmp     [window_data + edi + WDATA.box.height], 0
  1824.         jz      .exit
  1825. ;--------------------------------------
  1826. align 4
  1827. .check_for_shaped_window:
  1828.         mov     edi, esi
  1829.         shl     edi, 8
  1830.         add     edi, SLOT_BASE
  1831.         cmp     [edi + APPDATA.wnd_shape], 0
  1832.         jne     .shaped_window
  1833.  
  1834.         ; get x&y size
  1835.         sub     ecx, eax
  1836.         sub     edx, ebx
  1837.         inc     ecx
  1838.         inc     edx
  1839.  
  1840.         ; get WinMap start
  1841.         push    esi
  1842. ;        mov     edi, [Screen_Max_X]
  1843. ;        inc     edi
  1844. ;        mov     esi, edi
  1845.         mov     esi, [Screen_Max_X]
  1846.         inc     esi
  1847. ;        imul    edi, ebx
  1848.         mov     edi, [d_width_calc_area + ebx*4]
  1849.  
  1850.         add     edi, eax
  1851.         add     edi, [_WinMapAddress]
  1852.         pop     eax
  1853.         mov     ah, al
  1854.         push    ax
  1855.         shl     eax, 16
  1856.         pop     ax
  1857. ;--------------------------------------
  1858. align 4
  1859. .next_line:
  1860.         push    ecx
  1861.         shr     ecx, 2
  1862.         rep stosd
  1863.         mov     ecx, [esp]
  1864.         and     ecx, 3
  1865.         rep stosb
  1866.         pop     ecx
  1867.         add     edi, esi
  1868.         sub     edi, ecx
  1869.         dec     edx
  1870.         jnz     .next_line
  1871.  
  1872.         jmp     .exit
  1873. ;--------------------------------------
  1874. align 4
  1875. .shaped_window:
  1876.         ;  for (y=0; y <= x_size; y++)
  1877.         ;      for (x=0; x <= x_size; x++)
  1878.         ;          if (shape[coord(x,y,scale)]==1)
  1879.         ;             set_pixel(x, y, process_number);
  1880.  
  1881.         sub     ecx, eax
  1882.         sub     edx, ebx
  1883.         inc     ecx
  1884.         inc     edx
  1885.  
  1886.         push    [edi + APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  1887.  
  1888.         ; get WinMap start  -> ebp
  1889.         push    eax
  1890. ;        mov     eax, [Screen_Max_X] ; screen_sx
  1891. ;        inc     eax
  1892. ;        imul    eax, ebx
  1893.         mov     eax, [d_width_calc_area + ebx*4]
  1894.  
  1895.         add     eax, [esp]
  1896.         add     eax, [_WinMapAddress]
  1897.         mov     ebp, eax
  1898.  
  1899.         mov     edi, [edi + APPDATA.wnd_shape]
  1900.         pop     eax
  1901.  
  1902.         ; eax = x_start
  1903.         ; ebx = y_start
  1904.         ; ecx = x_size
  1905.         ; edx = y_size
  1906.         ; esi = process_number
  1907.         ; edi = &shape
  1908.         ;       [scale]
  1909.         push    edx ecx ; for loop - x,y size
  1910.  
  1911.         mov     ecx, esi
  1912.         shl     ecx, 5
  1913.         mov     edx, [window_data + ecx + WDATA.box.top]
  1914.         push    [window_data + ecx + WDATA.box.width]           ; for loop - width
  1915.         mov     ecx, [window_data + ecx + WDATA.box.left]
  1916.         sub     ebx, edx
  1917.         sub     eax, ecx
  1918.         push    ebx eax ; for loop - x,y
  1919.  
  1920.         add     [ff_xsz], eax
  1921.         add     [ff_ysz], ebx
  1922.  
  1923.         mov     ebx, [ff_y]
  1924. ;--------------------------------------
  1925. align 4
  1926. .ff_new_y:
  1927.         mov     edx, [ff_x]
  1928. ;--------------------------------------
  1929. align 4
  1930. .ff_new_x:
  1931.         ; -- body --
  1932.         mov     ecx, [ff_scale]
  1933.         mov     eax, [ff_width]
  1934.         inc     eax
  1935.         shr     eax, cl
  1936.         push    ebx edx
  1937.         shr     ebx, cl
  1938.         shr     edx, cl
  1939.         imul    eax, ebx
  1940.         add     eax, edx
  1941.         pop     edx ebx
  1942.         add     eax, edi
  1943.         call    .read_byte
  1944.         test    al, al
  1945.         jz      @f
  1946.         mov     eax, esi
  1947.         mov     [ebp], al
  1948.         ; -- end body --
  1949. ;--------------------------------------
  1950. align 4
  1951. @@:
  1952.         inc     ebp
  1953.         inc     edx
  1954.         cmp     edx, [ff_xsz]
  1955.         jb      .ff_new_x
  1956.  
  1957.         sub     ebp, [ff_xsz]
  1958.         add     ebp, [ff_x]
  1959.         add     ebp, [Screen_Max_X]  ; screen.x
  1960.         inc     ebp
  1961.         inc     ebx
  1962.         cmp     ebx, [ff_ysz]
  1963.         jb      .ff_new_y
  1964.  
  1965.         add     esp, 24
  1966. ;--------------------------------------
  1967. align 4
  1968. .exit:
  1969.         popad
  1970.         inc     [_display.mask_seqno]
  1971.         ret
  1972. ;--------------------------------------
  1973. align 4
  1974. .read_byte:
  1975.         ; eax - address
  1976.         ; esi - slot
  1977.         push    eax ecx edx esi
  1978.         xchg    eax, esi
  1979.         lea     ecx, [esp + 12]
  1980.         mov     edx, 1
  1981.         call    read_process_memory
  1982.         pop     esi edx ecx eax
  1983.         ret
  1984. ;------------------------------------------------------------------------------
  1985. align 4
  1986. ;------------------------------------------------------------------------------
  1987. window._.window_activate: ;////////////////////////////////////////////////////
  1988. ;------------------------------------------------------------------------------
  1989. ;? Activate window
  1990. ;------------------------------------------------------------------------------
  1991. ;> esi = pointer to WIN_POS+ window data
  1992. ;------------------------------------------------------------------------------
  1993.         push    eax ebx
  1994.  
  1995.         ; if type of current active window is 3 or 4, it must be redrawn
  1996.         mov     ebx, [TASK_COUNT]
  1997.        
  1998. ;       DEBUGF  1, "K : TASK_COUNT (0x%x)\n", ebx
  1999.        
  2000.         movzx   ebx, word[WIN_POS + ebx * 2]
  2001.         shl     ebx, 5
  2002.         add     eax, window_data
  2003.         mov     al, [window_data + ebx + WDATA.fl_wstyle]
  2004.         and     al, 0x0f
  2005.         cmp     al, 0x03
  2006.         je      .set_window_redraw_flag
  2007.         cmp     al, 0x04
  2008.         jne     .move_others_down
  2009. ;--------------------------------------
  2010. align 4
  2011. .set_window_redraw_flag:
  2012.         mov     [window_data + ebx + WDATA.fl_redraw], 1
  2013. ;--------------------------------------
  2014. align 4
  2015. .move_others_down:
  2016.         ; ax <- process no
  2017.         movzx   ebx, word[esi]
  2018.         ; ax <- position in window stack
  2019.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2020.  
  2021.         ; drop others
  2022.         xor     eax, eax
  2023. ;--------------------------------------
  2024. align 4
  2025. .next_stack_window:
  2026.         cmp     eax, [TASK_COUNT]
  2027.         jae     .move_self_up
  2028.         inc     eax
  2029.        
  2030. ;       push    ebx
  2031. ;       xor     ebx,ebx
  2032. ;       mov     bx,[WIN_STACK + eax * 2]
  2033. ;       DEBUGF  1, "K : DEC WIN_STACK (0x%x)\n",ebx
  2034. ;       pop     ebx
  2035.        
  2036.         cmp     [WIN_STACK + eax * 2], bx
  2037.         jbe     .next_stack_window
  2038.         dec     word[WIN_STACK + eax * 2]
  2039.         jmp     .next_stack_window
  2040. ;--------------------------------------
  2041. align 4
  2042. .move_self_up:
  2043.         movzx   ebx, word[esi]
  2044.         ; number of processes
  2045.         mov     ax, [TASK_COUNT]
  2046.         ; this is the last (and the upper)
  2047.         mov     [WIN_STACK + ebx * 2], ax
  2048.  
  2049.         ; update on screen - window stack
  2050.         xor     eax, eax
  2051. ;--------------------------------------
  2052. align 4
  2053. .next_window_pos:
  2054.         cmp     eax, [TASK_COUNT]
  2055.         jae     .reset_vars
  2056.         inc     eax
  2057.         movzx   ebx, word[WIN_STACK + eax * 2]
  2058.         mov     [WIN_POS + ebx * 2], ax
  2059.         jmp     .next_window_pos
  2060. ;--------------------------------------
  2061. align 4
  2062. .reset_vars:
  2063.         mov     byte[KEY_COUNT], 0
  2064.         mov     byte[BTN_COUNT], 0
  2065.         mov     word[MOUSE_SCROLL_H], 0
  2066.         mov     word[MOUSE_SCROLL_V], 0
  2067.  
  2068.         pop     ebx eax
  2069.         ret
  2070. ;------------------------------------------------------------------------------
  2071. window._.window_deactivate: ;////////////////////////////////////////////////////
  2072. ;------------------------------------------------------------------------------
  2073. ;? Deactivate window
  2074. ;------------------------------------------------------------------------------
  2075. ;> esi = pointer to WIN_POS+ window data
  2076. ;------------------------------------------------------------------------------
  2077.         push    eax ebx
  2078. ;--------------------------------------
  2079. align 4
  2080. .move_others_up:
  2081.         ; ax <- process no
  2082.         movzx   ebx, word[esi]
  2083.         ; ax <- position in window stack
  2084.         movzx   ebx, word[WIN_STACK + ebx * 2]
  2085.         ; up others
  2086.         xor     eax, eax
  2087. ;--------------------------------------
  2088. align 4
  2089. .next_stack_window:
  2090.         cmp     eax, [TASK_COUNT]
  2091.         jae     .move_self_down
  2092.         inc     eax
  2093.         cmp     [WIN_STACK + eax * 2], bx
  2094.         jae     .next_stack_window
  2095.         inc     word[WIN_STACK + eax * 2]
  2096.         jmp     .next_stack_window
  2097. ;--------------------------------------
  2098. align 4
  2099. .move_self_down:
  2100.         movzx   ebx, word[esi]
  2101.         ; this is the last (and the low)
  2102.         mov     [WIN_STACK + ebx * 2], word 1
  2103.         ; update on screen - window stack
  2104.         xor     eax, eax
  2105. ;--------------------------------------
  2106. align 4
  2107. .next_window_pos:
  2108.         cmp     eax, [TASK_COUNT]
  2109.         jae     .reset_vars
  2110.         inc     eax
  2111.         movzx   ebx, word[WIN_STACK + eax * 2]
  2112.         mov     [WIN_POS + ebx * 2], ax
  2113.         jmp     .next_window_pos
  2114. ;--------------------------------------
  2115. align 4
  2116. .reset_vars:
  2117.         mov     byte[KEY_COUNT], 0
  2118.         mov     byte[BTN_COUNT], 0
  2119.         mov     word[MOUSE_SCROLL_H], 0
  2120.         mov     word[MOUSE_SCROLL_V], 0
  2121.         pop     ebx eax
  2122.         ret
  2123. ;------------------------------------------------------------------------------
  2124. align 4
  2125. ;------------------------------------------------------------------------------
  2126. window._.check_window_draw: ;//////////////////////////////////////////////////
  2127. ;------------------------------------------------------------------------------
  2128. ;? Check if window is necessary to draw
  2129. ;------------------------------------------------------------------------------
  2130. ;> edi = pointer to WDATA
  2131. ;------------------------------------------------------------------------------
  2132.         mov     cl, [edi + WDATA.fl_wstyle]
  2133.         and     cl, 0x0f
  2134.         cmp     cl, 3
  2135.         je      .exit.redraw      ; window type 3
  2136.         cmp     cl, 4
  2137.         je      .exit.redraw      ; window type 4
  2138.  
  2139.         push    eax ebx edx esi
  2140.  
  2141.         mov     eax, edi
  2142.         sub     eax, window_data
  2143.         shr     eax, 5
  2144.  
  2145.         movzx   eax, word[WIN_STACK + eax * 2]  ; get value of the curr process
  2146.         lea     esi, [WIN_POS + eax * 2]        ; get address of this process at 0xC400
  2147. ;--------------------------------------
  2148. align 4
  2149. .next_window:
  2150.         add     esi, 2
  2151.  
  2152.         mov     eax, [TASK_COUNT]
  2153.         lea     eax, word[WIN_POS + eax * 2] ; number of the upper window
  2154.  
  2155.         cmp     esi, eax
  2156.         ja      .exit.no_redraw
  2157.  
  2158.         movzx   edx, word[esi]
  2159.         shl     edx, 5
  2160.         cmp     [CURRENT_TASK + edx + TASKDATA.state], TSTATE_FREE
  2161.         je      .next_window
  2162.  
  2163.         mov     eax, [edi + WDATA.box.top]
  2164.         mov     ebx, [edi + WDATA.box.height]
  2165.         add     ebx, eax
  2166.  
  2167.         mov     ecx, [window_data + edx + WDATA.box.top]
  2168.         cmp     ecx, ebx
  2169.         jge     .next_window
  2170.         add     ecx, [window_data + edx + WDATA.box.height]
  2171.         cmp     eax, ecx
  2172.         jge     .next_window
  2173.  
  2174.         mov     eax, [edi + WDATA.box.left]
  2175.         mov     ebx, [edi + WDATA.box.width]
  2176.         add     ebx, eax
  2177.  
  2178.         mov     ecx, [window_data + edx + WDATA.box.left]
  2179.         cmp     ecx, ebx
  2180.         jge     .next_window
  2181.         add     ecx, [window_data + edx + WDATA.box.width]
  2182.         cmp     eax, ecx
  2183.         jge     .next_window
  2184.  
  2185.         pop     esi edx ebx eax
  2186. ;--------------------------------------
  2187. align 4
  2188. .exit.redraw:
  2189.         xor     ecx, ecx
  2190.         inc     ecx
  2191.         ret
  2192. ;--------------------------------------
  2193. align 4
  2194. .exit.no_redraw:
  2195.         pop     esi edx ebx eax
  2196.         xor     ecx, ecx
  2197.         ret
  2198. ;------------------------------------------------------------------------------
  2199. align 4
  2200. ;------------------------------------------------------------------------------
  2201. window._.draw_window_caption: ;////////////////////////////////////////////////
  2202. ;------------------------------------------------------------------------------
  2203. ;? <description>
  2204. ;------------------------------------------------------------------------------
  2205.         xor     eax, eax
  2206.         mov     edx, [TASK_COUNT]
  2207.         movzx   edx, word[WIN_POS + edx * 2]
  2208.         cmp     edx, [CURRENT_TASK]
  2209.         jne     @f
  2210.         inc     eax
  2211. ;--------------------------------------
  2212. align 4
  2213. @@:
  2214.         mov     edx, [CURRENT_TASK]
  2215.         shl     edx, 5
  2216.         add     edx, window_data
  2217.         movzx   ebx, [edx + WDATA.fl_wstyle]
  2218.         and     bl, 0x0F
  2219.         cmp     bl, 3
  2220.         je      .draw_caption_style_3
  2221.         cmp     bl, 4
  2222.         je      .draw_caption_style_3
  2223.  
  2224.         jmp     .not_style_3
  2225. ;--------------------------------------
  2226. align 4
  2227. .draw_caption_style_3:
  2228.         push    edx
  2229.         call    drawwindow_IV_caption
  2230.         add     esp, 4
  2231.         jmp     .2
  2232. ;--------------------------------------
  2233. align 4
  2234. .not_style_3:
  2235.         cmp     bl, 2
  2236.         jne     .not_style_2
  2237.  
  2238.         call    drawwindow_III_caption
  2239.         jmp     .2
  2240. ;--------------------------------------
  2241. align 4
  2242. .not_style_2:
  2243.         cmp     bl, 0
  2244.         jne     .2
  2245.  
  2246.         call    drawwindow_I_caption
  2247. ;--------------------------------------
  2248. align 4
  2249. .2:
  2250.         mov     edi, [CURRENT_TASK]
  2251.         shl     edi, 5
  2252.         test    [edi + window_data + WDATA.fl_wstyle], WSTYLE_HASCAPTION
  2253.         jz      .exit
  2254.         mov     edx, [edi * 8 + SLOT_BASE + APPDATA.wnd_caption]
  2255.         or      edx, edx
  2256.         jz      .exit
  2257.  
  2258.         movzx   eax, [edi + window_data + WDATA.fl_wstyle]
  2259.         and     al, 0x0F
  2260.         cmp     al, 3
  2261.         je      .skinned
  2262.         cmp     al, 4
  2263.         je      .skinned
  2264.  
  2265.         jmp     .not_skinned
  2266. ;--------------------------------------
  2267. align 4
  2268. .skinned:
  2269.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2270.         mov     bp, word[edi + window_data + WDATA.box.top]
  2271.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2272.         sub     ax, [_skinmargins.left]
  2273.         sub     ax, [_skinmargins.right]
  2274.         push    edx
  2275.         cwde
  2276.         cdq
  2277.         mov     ebx, 6
  2278.         idiv    ebx
  2279.         pop     edx
  2280.         or      eax, eax
  2281.         js      .exit
  2282.  
  2283.         mov     esi, eax
  2284.         mov     ebx, dword[_skinmargins.left - 2]
  2285.         mov     bx, word[_skinh]
  2286.         sub     bx, [_skinmargins.bottom]
  2287.         sub     bx, [_skinmargins.top]
  2288.         sar     bx, 1
  2289.         adc     bx, 0
  2290.         add     bx, [_skinmargins.top]
  2291.         add     bx, -3
  2292.         add     ebx, ebp
  2293.         jmp     .dodraw
  2294. ;--------------------------------------
  2295. align 4
  2296. .not_skinned:
  2297.         cmp     al, 1
  2298.         je      .exit
  2299.  
  2300.         mov     ebp, [edi + window_data + WDATA.box.left - 2]
  2301.         mov     bp, word[edi + window_data + WDATA.box.top]
  2302.         movzx   eax, word[edi + window_data + WDATA.box.width]
  2303.         sub     eax, 16
  2304.         push    edx
  2305.         cwde
  2306.         cdq
  2307.         mov     ebx, 6
  2308.         idiv    ebx
  2309.         pop     edx
  2310.         or      eax, eax
  2311.         js      .exit
  2312.  
  2313.         mov     esi, eax
  2314.         mov     ebx, 0x00080007
  2315.         add     ebx, ebp
  2316. ;--------------------------------------
  2317. align 4
  2318. .dodraw:
  2319.         mov     ecx, [common_colours + 16]
  2320.         or      ecx, 0x80000000
  2321.         xor     edi, edi
  2322.         call    dtext_asciiz_esi
  2323. ;--------------------------------------
  2324. align 4
  2325. .exit:
  2326. ;        call    [draw_pointer]
  2327.         call    __sys_draw_pointer
  2328.         ret
  2329. ;------------------------------------------------------------------------------
  2330. align 4
  2331. ;------------------------------------------------------------------------------
  2332. window._.draw_negative_box: ;//////////////////////////////////////////////////
  2333. ;------------------------------------------------------------------------------
  2334. ;? Draw negative box
  2335. ;------------------------------------------------------------------------------
  2336. ;> edi = pointer to BOX struct
  2337. ;------------------------------------------------------------------------------
  2338.         push    eax ebx esi
  2339.         mov     esi, 0x01000000
  2340. ;--------------------------------------
  2341. align 4
  2342. .1:
  2343.         mov     eax, [edi + BOX.left - 2]
  2344.         mov     ax, word[edi + BOX.left]
  2345.         add     ax, word[edi + BOX.width]
  2346.         mov     ebx, [edi + BOX.top - 2]
  2347.         mov     bx, word[edi + BOX.top]
  2348.         add     bx, word[edi + BOX.height]
  2349.         call    draw_rectangle.forced
  2350.         pop     esi ebx eax
  2351.         ret
  2352. ;------------------------------------------------------------------------------
  2353. align 4
  2354. ;------------------------------------------------------------------------------
  2355. window._.end_moving__box: ;//////////////////////////////////////////////////
  2356. ;------------------------------------------------------------------------------
  2357. ;? Draw positive box
  2358. ;------------------------------------------------------------------------------
  2359. ;> edi = pointer to BOX struct
  2360. ;------------------------------------------------------------------------------
  2361.         push    eax ebx esi
  2362.         xor     esi, esi
  2363.         jmp     window._.draw_negative_box.1
  2364. ;------------------------------------------------------------------------------
  2365. align 4
  2366. ;------------------------------------------------------------------------------
  2367. window._.get_rect: ;/////////////////////////////////////////////////////
  2368. ;------------------------------------------------------------------------------
  2369. ;? <description>  void __fastcall get_window_rect(struct RECT* rc);
  2370. ;------------------------------------------------------------------------------
  2371. ;> ecx = pointer to RECT
  2372. ;------------------------------------------------------------------------------
  2373.         mov     eax, [TASK_BASE]
  2374.  
  2375.         mov     edx, [eax-twdw + WDATA.box.left]
  2376.         mov     [ecx+RECT.left], edx
  2377.  
  2378.         add     edx, [eax-twdw + WDATA.box.width]
  2379.         mov     [ecx+RECT.right], edx
  2380.  
  2381.         mov     edx, [eax-twdw + WDATA.box.top]
  2382.         mov     [ecx+RECT.top], edx
  2383.  
  2384.         add     edx, [eax-twdw + WDATA.box.height]
  2385.         mov     [ecx+RECT.bottom], edx
  2386.         ret
  2387. ;------------------------------------------------------------------------------
  2388.