Subversion Repositories Kolibri OS

Rev

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

  1. get_titlebar_height: ; edi = window draw_data pointer
  2.         mov     al,[edi+WDATA.fl_wstyle]
  3.         and     al,0x0F
  4.         cmp     al,0x03
  5.         jne     @f
  6.         mov     eax,[_skinh]
  7.         ret
  8.     @@: mov     eax,21
  9.         ret
  10.  
  11. get_rolledup_height: ; edi = window draw_data pointer
  12.         mov     al,[edi+WDATA.fl_wstyle]
  13.         and     al,0x0F
  14.         cmp     al,0x03
  15.         jne     @f
  16.         mov     eax,[_skinh]
  17.         add     eax,3
  18.         ret
  19.     @@: or      al,al
  20.         jnz     @f
  21.         mov     eax,21
  22.         ret
  23.     @@: mov     eax,21+2
  24.         ret
  25.  
  26.  
  27. setwindowdefaults:
  28.         pushad
  29.  
  30.         xor   eax,eax
  31.         mov   ecx,0xc000
  32.        @@:
  33.         inc   eax
  34.         add   ecx,2
  35.         mov   [ecx+0x000],ax          ; process no
  36.         mov   [ecx+0x400],ax          ; positions in stack
  37.         cmp   ecx,0xc400-2            ; the more high, the more surface
  38.         jnz   @b
  39.  
  40.         popad
  41.         ret
  42.  
  43.  
  44.  
  45. ; eax = cx
  46. ; ebx = cy
  47. ; ecx = ex
  48. ; edx = ey
  49. ; èäåÿ: ïåðåáðàòü âñå îêíà, íà÷èíàÿ ñ ñàìîãî íèæíåãî,
  50. ;       è äëÿ ïîïàâøèõ â çàäàííóþ îáëàñòü
  51. ;       ÷àñòåé îêîí âûçâàòü setscreen
  52. align 4
  53. calculatescreen:
  54.         pushad
  55.         pushfd
  56.         cli
  57.  
  58.         push    edx ecx ebx eax
  59.  
  60.         mov     esi, 1
  61.         call    setscreen
  62.  
  63.         mov     ebp, [0x3004]        ; number of processes
  64.         cmp     ebp, 1
  65.         jbe     .finish
  66.         align 4
  67.       .new_wnd:
  68.         movzx   edi, word [0xC400 + esi * 2]
  69.         shl     edi, 5
  70.  
  71.         cmp     [0x3000+edi+TASKDATA.state], byte 9
  72.         je      .not_wnd
  73.  
  74.         add     edi, window_data
  75.         test    [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
  76.         jnz     .not_wnd
  77.  
  78.         mov     eax,[edi+WDATA.box.left]
  79.         cmp     eax, [esp+RECT.right]
  80.         ja      .out_of_bounds
  81.         mov     ebx,[edi+WDATA.box.top]
  82.         cmp     ebx, [esp+RECT.bottom]
  83.         ja      .out_of_bounds
  84.         mov     ecx,[edi+WDATA.box.width]
  85.         add     ecx, eax
  86.         cmp     ecx, [esp+RECT.left]
  87.         jb      .out_of_bounds
  88.         mov     edx,[edi+WDATA.box.height]
  89.         add     edx, ebx
  90.         cmp     edx, [esp+RECT.top]
  91.         jb      .out_of_bounds
  92.  
  93.     cmp     eax, [esp+RECT.left]
  94.         jae     @f
  95.         mov     eax, [esp+RECT.left]
  96.      @@:
  97.     cmp     ebx, [esp+RECT.top]
  98.         jae     @f
  99.         mov     ebx, [esp+RECT.top]
  100.      @@:
  101.     cmp     ecx, [esp+RECT.right]
  102.         jbe     @f
  103.         mov     ecx, [esp+RECT.right]
  104.      @@:
  105.     cmp     edx, [esp+RECT.bottom]
  106.         jbe     @f
  107.         mov     edx, [esp+RECT.bottom]
  108.      @@:
  109.  
  110.         push    esi
  111.         movzx   esi, word [0xC400 + esi * 2]
  112.         call    setscreen
  113.         pop     esi
  114.  
  115.       .not_wnd:
  116.       .out_of_bounds:
  117.         inc     esi
  118.         dec     ebp
  119.         jnz     .new_wnd
  120.       .finish:
  121.  
  122.     pop     eax ebx ecx edx
  123.  
  124.         popfd
  125.         popad
  126. ret
  127.  
  128.  
  129.  
  130. virtual at esp
  131.   ff_x     dd ?
  132.   ff_y     dd ?
  133.   ff_width dd ?
  134.   ff_xsz   dd ?
  135.   ff_ysz   dd ?
  136.   ff_scale dd ?
  137. end virtual
  138.  
  139. align 4
  140. ; ðåçåðâèðóåò ìåñòî ïîä îêíî çàäàííîãî ïðîöåññà
  141. setscreen:
  142. ;  eax  x start
  143. ;  ebx  y start
  144. ;  ecx  x end
  145. ;  edx  y end
  146. ;  esi  process number
  147. pushad
  148. ; \begin{diamond}[29.08.2006]
  149.         cmp     esi, 1
  150.         jz      @f
  151.         mov     edi, esi
  152.         shl     edi, 5
  153.         cmp     [edi+window_data+WDATA.box.width], 0
  154.         jnz     @f
  155.         cmp     [edi+window_data+WDATA.box.height], 0
  156.         jz      .ret
  157. @@:
  158. ; \end{diamond}[29.08.2006]
  159.         mov edi, esi ;;;word [esi*2+0xc400]
  160.         shl   edi, 8
  161.         add   edi, 0x80000  ; address of random shaped window area
  162.         cmp   [edi+APPDATA.wnd_shape], dword 0
  163.         jne   .free_form
  164.  
  165.         ; get x&y size
  166.         sub   ecx, eax
  167.         sub   edx, ebx
  168.         inc   ecx
  169.         inc   edx
  170.  
  171.         ; get WinMap start
  172.         mov   edi, [0xFE00] ; screen_sx
  173.         inc   edi
  174.         imul  edi, ebx
  175.         add   edi, eax
  176.         add   edi, WinMapAddress
  177.  
  178.   .new_y:
  179.         push  ecx ; sx
  180.         push  edx
  181.  
  182.         mov   edx, esi
  183.         align 4
  184.   .new_x:
  185.         mov   byte [edi], dl
  186.         inc   edi
  187.         dec   ecx
  188.         jnz   .new_x
  189.  
  190.         pop   edx
  191.         pop   ecx
  192.         add   edi, [0xFE00]
  193.         inc   edi
  194.         sub   edi, ecx
  195.         dec   edx
  196.         jnz   .new_y
  197. .ret:
  198.  popad
  199.  ret
  200.   .read_byte:
  201.    ;eax - address
  202.    ;esi - slot
  203.         push  eax
  204.         push  ebx
  205.         push  ecx
  206.         push  edx
  207.         mov   edx,eax
  208.         mov   eax,esi
  209.         lea   ebx,[esp+12]
  210.         mov   ecx,1
  211.         call  read_process_memory
  212.         pop   edx
  213.         pop   ecx
  214.         pop   ebx
  215.         pop   eax
  216.         ret  
  217.   .free_form:
  218.  
  219.         ;  for (y=0; y <= x_size; y++)
  220.         ;      for (x=0; x <= x_size; x++)
  221.         ;          if (shape[coord(x,y,scale)]==1)
  222.         ;             set_pixel(x, y, process_number);
  223.  
  224.         sub  ecx, eax
  225.         sub  edx, ebx
  226.         inc  ecx
  227.         inc  edx
  228.  
  229.         push  dword [edi+APPDATA.wnd_shape_scale]  ; push scale first -> for loop
  230.  
  231.         ; get WinMap start  -> ebp
  232.         push  eax
  233.         mov   eax, [0xFE00] ; screen_sx
  234.         inc   eax
  235.         imul  eax, ebx
  236.         add   eax, [esp]
  237.         add   eax, WinMapAddress
  238.         mov   ebp, eax
  239.  
  240.         mov   edi, [edi+APPDATA.wnd_shape]
  241.         pop   eax
  242.  
  243.         ; eax = x_start
  244.         ; ebx = y_start
  245.         ; ecx = x_size
  246.         ; edx = y_size
  247.         ; esi = process_number
  248.         ; edi = &shape
  249.         ;       [scale]
  250.         push edx ecx ; for loop - x,y size
  251.  
  252.         mov  ecx, esi
  253.         shl  ecx, 5
  254.         mov  edx, [window_data+ecx+WDATA.box.top]
  255.         push [window_data+ecx+WDATA.box.width]      ; for loop - width
  256.         mov  ecx, [window_data+ecx+WDATA.box.left]
  257.         sub  ebx, edx
  258.         sub  eax, ecx
  259.         push ebx eax ; for loop - x,y
  260.  
  261.         add  [ff_xsz], eax
  262.         add  [ff_ysz], ebx
  263.  
  264.         mov  ebx, [ff_y]
  265.  
  266.       .ff_new_y:
  267.         mov  edx, [ff_x]
  268.  
  269.       .ff_new_x:
  270.         ; -- body --
  271.         mov  ecx, [ff_scale]
  272.         mov  eax, [ff_width]
  273.         inc  eax
  274.         shr  eax, cl
  275.         push ebx edx
  276.         shr  ebx, cl
  277.         shr  edx, cl
  278.         imul eax, ebx
  279.         add  eax, edx
  280.         pop  edx ebx
  281.         add  eax, edi
  282.         call .read_byte
  283.         test al,al
  284.         jz   @f
  285.         mov  eax, esi
  286.         mov  [ebp], al
  287.        @@:
  288.         ; -- end body --
  289.         inc  ebp
  290.         inc  edx
  291.         cmp  edx, [ff_xsz]
  292.         jb   .ff_new_x
  293.         sub  ebp, [ff_xsz]
  294.         add  ebp, [ff_x]
  295.         add  ebp, [0xFE00]  ; screen.x
  296.         inc  ebp
  297.         inc  ebx
  298.         cmp  ebx, [ff_ysz]
  299.         jb   .ff_new_y
  300.  
  301.         add  esp, 24
  302. popad
  303. ret
  304.  
  305.  
  306. display_settings:
  307.  
  308. ;    eax = 0         ; DISPLAY redraw
  309. ;          ebx = 0   ; all
  310. ;
  311. ;    eax = 1         ; BUTTON type
  312. ;          ebx = 0   ; flat
  313. ;          ebx = 1   ; 3D
  314. ;    eax = 2         ; set WINDOW colours
  315. ;          ebx = pointer to table
  316. ;          ecx = number of bytes define
  317. ;    eax = 3         ; get WINDOW colours
  318. ;          ebx = pointer to table
  319. ;          ecx = number of bytes wanted
  320. ;    eax = 4         ; get skin height
  321. ;          input  : nothing
  322. ;          output : eax = skin height in pixel
  323. ;    eax = 5         ; get screen workarea
  324. ;          input  : nothing
  325. ;          output : eax = [left]*65536+[right]
  326. ;                   ebx = [top]*65536+[bottom]
  327. ;    eax = 6         ; set screen workarea
  328. ;          input  : ecx = [left]*65536+[right]
  329. ;                   edx = [top]*65536+[bottom]
  330. ;          output : nothing
  331. ;    eax = 7         ; get skin margins
  332. ;          input  : nothing
  333. ;          output : eax = [left]*65536+[right]
  334. ;                   ebx = [top]*65536+[bottom]
  335. ;    eax = 8         ; set window skin
  336. ;          input  : ecx = pointer to file info block
  337. ;          output : eax = FS error code
  338.  
  339.  
  340.      pushad
  341.  
  342.      test eax, eax      ; redraw display
  343.      jnz  dspl0
  344.      test ebx, ebx
  345.      jnz  dspl0
  346.      cmp  [windowtypechanged],dword 1
  347.      jne  dspl00
  348.      mov  [windowtypechanged],dword 0
  349.   redraw_screen_direct:
  350.      mov  [dlx],dword 0
  351.      mov  [dly],dword 0
  352.      mov  eax,[0xfe00]
  353.      mov  [dlxe],eax
  354.      mov  eax,[0xfe04]
  355.      mov  [dlye],eax
  356.      mov  eax,window_data
  357.      call redrawscreen
  358.    dspl00:
  359.      popad
  360.      ret
  361.    dspl0:
  362.  
  363.      cmp  eax,1       ; button type
  364.      jne  dspl1
  365.      and  ebx,1
  366.      cmp  ebx,[buttontype]
  367.      je   dspl9
  368.      mov  [buttontype],ebx
  369.      mov  [windowtypechanged],dword 1
  370.     dspl9:
  371.      popad
  372.      ret
  373.    dspl1:
  374.  
  375.      cmp  eax,2       ; set common window colours
  376.      jne  no_com_colours
  377.      mov  [windowtypechanged],dword 1
  378.      mov  esi,[0x3010]
  379.      add  esi,TASKDATA.mem_start
  380.      add  ebx,[esi]
  381.      mov  esi,ebx
  382.      mov  edi,common_colours
  383.      and  ecx,127
  384.      cld
  385.      rep  movsb
  386.      popad
  387.      ret
  388.    no_com_colours:
  389.  
  390.      cmp  eax,3       ; get common window colours
  391.      jne  no_get_com
  392.      mov  esi,[0x3010]
  393.      add  esi,TASKDATA.mem_start
  394.      add  ebx,[esi]
  395.      mov  edi,ebx
  396.      mov  esi,common_colours
  397.      and  ecx,127
  398.      cld
  399.      rep  movsb
  400.      popad
  401.      ret
  402.    no_get_com:
  403.  
  404.      cmp  eax,4       ; get skin height
  405.      jne  no_skin_height
  406.      popad
  407.      mov  eax,[_skinh]
  408.      mov  [esp+36],eax
  409.      ret
  410.    no_skin_height:
  411.  
  412.         cmp     eax,5       ; get screen workarea
  413.         jne     no_get_workarea
  414.         popad
  415.         mov     eax,[screen_workarea.left-2]
  416.         mov     ax,word[screen_workarea.right]
  417.         mov     [esp+36],eax
  418.         mov     eax,[screen_workarea.top-2]
  419.         mov     ax,word[screen_workarea.bottom]
  420.         mov     [esp+24],eax
  421.         ret
  422.    no_get_workarea:
  423.  
  424.         cmp     eax,6       ; set screen workarea
  425.         jne     no_set_workarea
  426.         movsx   eax,word[esp+16+2]
  427.         movsx   ebx,word[esp+16]
  428.         cmp     eax,ebx
  429.         jge     .lp1
  430.         or      eax,eax;[0xFE00]
  431.         jl      @f
  432.         mov     [screen_workarea.left],eax
  433.     @@: cmp     ebx,[0xFE00]
  434.         jg      .lp1
  435.         mov     [screen_workarea.right],ebx
  436.   .lp1: movsx   eax,word[esp+24+2]
  437.         movsx   ebx,word[esp+24]
  438.         cmp     eax,ebx
  439.         jge     .lp2
  440.         or      eax,eax;[0xFE04]
  441.         jl      @f
  442.         mov     [screen_workarea.top],eax
  443.     @@: cmp     ebx,[0xFE04]
  444.         jg      .lp2
  445.         mov     [screen_workarea.bottom],ebx
  446.   .lp2: call    repos_windows
  447.         mov     eax, 0
  448.         mov     ebx, 0
  449.         mov     ecx, [0xfe00]
  450.         mov     edx, [0xfe04]
  451.     call    calculatescreen
  452. ;    jmp    redraw_screen_direct
  453.     .exit:
  454.         popad
  455.         ret
  456.    no_set_workarea:
  457.  
  458.         cmp     eax,7       ; get skin margins
  459.         jne     no_get_skinmargins
  460.         popad
  461.         mov     eax,dword[_skinmargins+0]
  462.         mov     [esp+36],eax
  463.         mov     eax,dword[_skinmargins+4]
  464.         mov     [esp+24],eax
  465.         ret
  466.    no_get_skinmargins:
  467.  
  468.         cmp     eax,8       ; set window skin
  469.         jne     no_set_skin
  470.         mov     eax,ebx
  471.         mov     edi,[0x3010]
  472.         add     ebx,[edi+TASKDATA.mem_start]        ; abs start of info block
  473.         pushd   [ebx+0] [ebx+4] [ebx+8] [ebx+12]
  474.         mov     dword[ebx+0],0        ; read
  475.         mov     dword[ebx+4],0        ; from the beginning
  476.         mov     dword[ebx+8],64       ; 32 KBytes maximum
  477.         mov     ecx,skin_data+64*512
  478.         sub     ecx,[edi+0x10]
  479.         mov     dword[ebx+12],ecx     ; destination
  480.         push    eax
  481.         pushad
  482.         call    file_system
  483.         popad
  484.         pop    eax
  485.         popd    [ebx+12] [ebx+8] [ebx+4] [ebx+0]
  486.         cmp     eax,ERROR_SUCCESS
  487.         je      @f
  488.         cmp     eax,ERROR_END_OF_FILE
  489.         jne     .exit
  490.     @@: cmp     [skin_data+64*512+SKIN_HEADER.ident],'SKIN'
  491.         mov     eax,ERROR_UNKNOWN_FS
  492.         jne     .exit
  493.         mov     esi,skin_data+64*512
  494.         mov     edi,skin_data
  495.         mov     ecx,(64*512)/4
  496.         rep     movsd
  497.         call    parse_skin_data
  498.     pushad
  499.         mov     eax, 0
  500.         mov     ebx, 0
  501.         mov     ecx, [0xfe00]
  502.         mov     edx, [0xfe04]
  503.         call    calculatescreen
  504.     popad
  505.         mov     dword[esp+32+36],0
  506.         jmp     redraw_screen_direct
  507.   .exit:
  508.         mov     [esp+32+36],eax
  509.         popad
  510.         ret
  511.    no_set_skin:
  512.  
  513.      popad
  514.      ret
  515.  
  516.  
  517. repos_windows:
  518.         mov     ecx,[0x3004]
  519.         mov     edi,0x20*2
  520.     mov    byte[0x0000fff0],1
  521.         dec     ecx
  522.         jge    @f
  523.         ret
  524.     @@: mov     [edi+WDATA.fl_redraw],1
  525.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  526.         jz      .lp2
  527.         mov     eax,[screen_workarea.left]
  528.         mov     [edi+WDATA.box.left],eax
  529.         sub     eax,[screen_workarea.right]
  530.         neg     eax
  531.         mov     [edi+WDATA.box.width],eax
  532.         mov     eax,[screen_workarea.top]
  533.         mov     [edi+WDATA.box.top],eax
  534.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  535.         jnz     .lp1
  536.         sub     eax,[screen_workarea.bottom]
  537.         neg     eax
  538.         mov     [edi+WDATA.box.height],eax
  539.   .lp1:
  540.         call    set_window_clientbox
  541.         add     edi,0x20
  542.         loop    @b
  543.         ret
  544.   .lp2: mov     eax,[edi+WDATA.box.left]
  545.         add     eax,[edi+WDATA.box.width]
  546.     mov    ebx,[0x0000fe00]
  547. ;    inc    ebx
  548.     cmp    eax,ebx
  549.     jle    .lp4
  550.         mov     eax,[edi+WDATA.box.width]
  551.     sub    eax,ebx
  552.     jle    .lp3
  553.         mov     [edi+WDATA.box.width],ebx
  554.   .lp3: sub     ebx,[edi+WDATA.box.width]
  555.         mov     [esi+WDATA.box.left],ebx
  556.   .lp4: mov     eax,[edi+WDATA.box.top]
  557.         add     eax,[edi+WDATA.box.height]
  558.     mov    ebx,[0x0000fe04]
  559. ;    inc    ebx
  560.     cmp    eax,ebx
  561.     jle    .lp6
  562.         mov     eax,[edi+WDATA.box.height]
  563.     sub    eax,ebx
  564.     jle    .lp5
  565.         mov     [edi+WDATA.box.height],ebx
  566.   .lp5: sub     ebx,[edi+WDATA.box.height]
  567.         mov     [edi+WDATA.box.top],ebx
  568.   .lp6: jmp     .lp1
  569.  
  570. uglobal
  571.   common_colours:
  572.      times 128 db 0x0
  573. endg
  574.  
  575.  
  576.  
  577.  
  578. check_window_position:
  579.  
  580.     pushad                           ; window inside screen ?
  581.  
  582.     movzx eax,word [edi+WDATA.box.left]
  583.     movzx ebx,word [edi+WDATA.box.top]
  584.     movzx ecx,word [edi+WDATA.box.width]
  585.     movzx edx,word [edi+WDATA.box.height]
  586.  
  587.     mov   esi,ecx             ; check x pos
  588.     add   esi,eax
  589.     cmp   esi,[0xfe00]
  590.     jbe   x_pos_ok
  591.     mov   [edi+WDATA.box.left],dword 0
  592.     xor   eax, eax
  593.   x_pos_ok:
  594.  
  595.     mov   esi,edx             ; check y pos
  596.     add   esi,ebx
  597.     cmp   esi,[0xfe04]
  598.     jbe   y_pos_ok
  599.     mov   [edi+WDATA.box.top],dword 0
  600.     mov   ebx,0
  601.   y_pos_ok:
  602.  
  603.     mov   esi,ecx             ; check x size
  604.     add   esi,eax
  605.     cmp   esi,[0xfe00]
  606.     jbe   x_size_ok
  607.     mov   ecx,[0xfe00]
  608.     mov   [edi+WDATA.box.width],ecx
  609.   x_size_ok:
  610.  
  611.     mov   esi,edx             ; check y size
  612.     add   esi,ebx
  613.     cmp   esi,[0xfe04]
  614.     jbe   y_size_ok
  615.     mov   edx,[0xfe04]
  616.     mov   [edi+WDATA.box.height],edx
  617.   y_size_ok:
  618.  
  619.     popad
  620.  
  621.     ret
  622.  
  623.  
  624. uglobal
  625.   new_window_starting dd 0
  626. endg
  627.  
  628.  
  629. sys_window_mouse:
  630.  
  631.     push  eax
  632.  
  633.     mov   eax,[timer_ticks]
  634.     cmp   [new_window_starting],eax
  635.     jb    swml1
  636.  
  637.     mov   [0xfff4],byte 0  ; no mouse background
  638.     mov   [0xfff5],byte 0  ; draw mouse
  639.  
  640.     mov   [new_window_starting],eax
  641.  
  642.   swml1:
  643.  
  644.     pop   eax
  645.  
  646.     ret
  647.  
  648.  
  649.  
  650.  
  651. drawwindow_I_caption:
  652.  
  653.         mov   ecx,[edx+WDATA.cl_titlebar]   ; grab bar
  654.         push  ecx
  655.         mov   esi,edx
  656.         mov   edx,[esi+WDATA.box.top]
  657.         add   edx,1
  658.         mov   ebx,[esi+WDATA.box.top]
  659.         add   ebx,21
  660.         mov   eax,[esi+WDATA.box.top]
  661.         add   eax,[esi+WDATA.box.height]
  662.         cmp   ebx,eax
  663.         jb    .wdsizeok
  664.         mov   ebx,eax
  665.   .wdsizeok:
  666.         push  ebx
  667.   .drwi:
  668.         mov   ebx,edx
  669.         shl   ebx,16
  670.         add   ebx,edx
  671.         mov   eax,[esi+WDATA.box.left]
  672.         inc   eax
  673.         shl   eax,16
  674.         add   eax,[esi+WDATA.box.left]
  675.         add   eax,[esi+WDATA.box.width]
  676.         sub   eax,1
  677.         push  edx
  678.         mov   edx,0x80000000
  679.         mov   ecx,[esi+WDATA.cl_titlebar]
  680.         and   ecx,edx
  681.         cmp   ecx,edx
  682.         jnz   .nofa
  683.         mov   ecx,[esi+WDATA.cl_titlebar]
  684.         sub   ecx,0x00040404
  685.         mov   [esi+WDATA.cl_titlebar],ecx
  686.         and   ecx,0x00ffffff
  687.         jmp   .faj
  688.   .nofa:
  689.         mov   ecx,[esi+WDATA.cl_titlebar]
  690.         and   ecx,0x00ffffff
  691.   .faj:
  692.         pop   edx
  693.         mov   edi,0
  694.         call  [draw_line]
  695.         inc   edx
  696.         cmp   edx,[esp]
  697.         jb    .drwi
  698.         add   esp,4
  699.         pop   ecx
  700.         mov   [esi+WDATA.cl_titlebar],ecx
  701.  
  702.         ret
  703.  
  704.  
  705. drawwindow_I:
  706.  
  707.         pushad
  708.  
  709.         mov   esi,[edx+WDATA.cl_frames]   ; rectangle
  710.         mov   eax,[edx+WDATA.box.left]
  711.         shl   eax,16
  712.         add   eax,[edx+WDATA.box.left]
  713.         add   eax,[edx+WDATA.box.width]
  714.         mov   ebx,[edx+WDATA.box.top]
  715.         shl   ebx,16
  716.         add   ebx,[edx+WDATA.box.top]
  717.         add   ebx,[edx+WDATA.box.height]
  718.         call  draw_rectangle
  719.  
  720.         call    drawwindow_I_caption
  721.  
  722.         mov   edx,[esi+WDATA.box.top]      ; inside work area
  723.         add   edx,21+5
  724.         mov   ebx,[esi+WDATA.box.top]
  725.         add   ebx,[esi+WDATA.box.height]
  726.         cmp   edx,ebx
  727.         jg    noinside
  728.         mov   eax,1
  729.         mov   ebx,21
  730.         mov   ecx,[esi+WDATA.box.width]
  731.         mov   edx,[esi+WDATA.box.height]
  732.         mov   edi,[esi+WDATA.cl_workarea]
  733.         call  [drawbar]
  734.       noinside:
  735.  
  736.         popad
  737.  
  738.         ret
  739.  
  740.  
  741. draw_rectangle:
  742.  
  743. r_eax equ [esp+28]   ; x start
  744. r_ax  equ [esp+30]   ; x end
  745. r_ebx equ [esp+16]   ; y start
  746. r_bx  equ [esp+18]   ; y end
  747. ;esi                 ; color
  748.  
  749.         pushad
  750.  
  751.         mov   ecx,esi          ; yb,xb -> yb,xe
  752.         mov   eax, r_eax
  753.         rol   eax, 16
  754.         mov   ebx,r_ebx
  755.         shl   ebx,16
  756.         mov   bx,r_ebx
  757.         xor   edi, edi
  758.         call  [draw_line]
  759.  
  760.         mov   ebx,r_bx         ; ye,xb -> ye,xe
  761.         shl   ebx,16
  762.         mov   bx,r_bx
  763.         call  [draw_line]
  764.  
  765.         mov   ecx,esi          ; ya,xa -> ye,xa
  766.         mov   eax,r_eax
  767.         shl   eax,16
  768.         mov   ax,r_eax
  769.         mov   ebx,r_ebx
  770.         shl   ebx,16
  771.         mov   bx,r_bx
  772.         mov   edi,0
  773.         call  [draw_line]
  774.  
  775.         mov   eax,r_ax       ; ya,xe -> ye,xe
  776.         shl   eax,16
  777.         mov   ax,r_ax
  778.         call  [draw_line]
  779.  
  780.         popad
  781.         ret
  782.  
  783.  
  784. drawwindow_III_caption:
  785.  
  786.         mov   ecx,[edx+WDATA.cl_titlebar]                       ; GRAB BAR
  787.         push  ecx
  788.         mov   esi,edx
  789.         mov   edx,[esi+WDATA.box.top]
  790.         add   edx,4
  791.         mov   ebx,[esi+WDATA.box.top]
  792.         add   ebx,20
  793.         mov   eax,[esi+WDATA.box.top]
  794.         add   eax,[esi+WDATA.box.height]
  795.         cmp   ebx,eax
  796.         jb    .wdsizeok
  797.         mov   ebx,eax
  798.   .wdsizeok:
  799.         push  ebx
  800.   .drwi:
  801.         mov   ebx,edx
  802.         shl   ebx,16
  803.         add   ebx,edx
  804.         mov   eax,[esi+WDATA.box.left]
  805.         shl   eax,16
  806.         add   eax,[esi+WDATA.box.left]
  807.         add   eax,[esi+WDATA.box.width]
  808.         add   eax,4*65536-4
  809.         mov   ecx,[esi+WDATA.cl_titlebar]
  810.         test  ecx,0x40000000
  811.         jz    .nofa
  812.         add   ecx,0x040404
  813.   .nofa:
  814.         test  ecx,0x80000000
  815.         jz    .nofa2
  816.         sub   ecx,0x040404
  817.   .nofa2:
  818.         mov   [esi+WDATA.cl_titlebar],ecx
  819.         and   ecx,0xffffff
  820.         xor   edi, edi
  821.         call  [draw_line]
  822.         inc   edx
  823.         cmp   edx,[esp]
  824.         jb    .drwi
  825.         add   esp,4
  826.         pop   ecx
  827.         mov   [esi+WDATA.cl_titlebar],ecx
  828.  
  829.         ret
  830.  
  831.  
  832. drawwindow_III:
  833.  
  834.         pushad
  835.  
  836.         mov   edi,edx                              ; RECTANGLE
  837.         mov   eax,[edi+WDATA.box.left]
  838.         shl   eax,16
  839.     mov   ax, word [edi+WDATA.box.left]
  840.     add   ax, word [edi+WDATA.box.width]
  841.         mov   ebx,[edi+WDATA.box.top]
  842.         shl   ebx,16
  843.     mov   bx, word [edi+WDATA.box.top]
  844.     add   bx, word [edi+WDATA.box.height]
  845.         mov   esi,[edi+WDATA.cl_frames]
  846.         shr   esi,1
  847.         and   esi,0x007f7f7f
  848.         push  esi
  849.         call  draw_rectangle
  850.         mov   ecx,3
  851.       dw3l:
  852.         add   eax,1*65536-1
  853.         add   ebx,1*65536-1
  854.         mov   esi,[edi+WDATA.cl_frames]
  855.         call  draw_rectangle
  856.         dec   ecx
  857.         jnz   dw3l
  858.         pop   esi
  859.         add   eax,1*65536-1
  860.         add   ebx,1*65536-1
  861.         call  draw_rectangle
  862.  
  863.         call    drawwindow_III_caption
  864.  
  865.         mov   edx,[esi+WDATA.box.top]                       ; WORK AREA
  866.         add   edx,21+5
  867.         mov   ebx,[esi+WDATA.box.top]
  868.         add   ebx,[esi+WDATA.box.height]
  869.         cmp   edx,ebx
  870.         jg    noinside2
  871.         mov   eax,5
  872.         mov   ebx,20
  873.         mov   ecx,[esi+WDATA.box.width]
  874.         mov   edx,[esi+WDATA.box.height]
  875.         sub   ecx,4
  876.         sub   edx,4
  877.         mov   edi,[esi+WDATA.cl_workarea]
  878.         call  [drawbar]
  879.       noinside2:
  880.  
  881.         popad
  882.  
  883.         ret
  884.  
  885.  
  886.  
  887. ; activate window
  888. align 4
  889. windowactivate:
  890.  
  891.         ; esi = abs mem position in stack 0xC400+
  892.  
  893.         pushad
  894.  
  895.      ; if type of current active window is 3,
  896.      ; it must be redrawn
  897.         mov   eax, [0x3004]
  898.         movzx eax, word [0xC400 + eax*2]
  899.         shl   eax, 5
  900.         add   eax, window_data
  901.         mov   ebx, [eax + WDATA.cl_workarea]
  902.         and   ebx, 0x0f000000
  903.         cmp   ebx, 0x03000000
  904.         jne   @f
  905.         mov   [eax + WDATA.fl_redraw], byte 1
  906.      @@:
  907.  
  908.         push   esi
  909.       movzx   eax, word [esi] ; ax <- process no
  910.       movzx   eax, word [0xC000+eax*2] ; ax <- position in window stack
  911.  
  912.         xor   esi, esi        ; drop others
  913.       waloop:
  914.         cmp   esi, dword [0x3004]
  915.         jae   wacont
  916.         inc   esi
  917.         lea   edi, [0xC000 + esi*2]
  918.         mov   bx, [edi] ; position of the current process
  919.         cmp   bx, ax
  920.         jbe   @f
  921.         dec   bx       ; upper? => drop!
  922.         mov   [edi], bx
  923.       @@:
  924.         jmp   waloop
  925.       wacont:
  926.                             ; set to no 1
  927.         pop   esi           ;   esi = pointer at 0xC400
  928.  
  929.       movzx   eax, word [esi]
  930.         mov   bx, [0x3004]  ; number of processes
  931.         mov   [0xC000+eax*2], bx     ; this is the last (and the upper)
  932.  
  933.         ; update on screen -window stack
  934.         xor   esi, esi
  935.       waloop2:
  936.         mov   edi, [0x3004]
  937.         cmp   esi, edi
  938.         jae   wacont2
  939.         inc   esi
  940.         movzx ebx, word [esi*2 + 0xC000]
  941.         mov   [ebx*2 + 0xC400], si
  942.         jmp   waloop2
  943.       wacont2:
  944.         mov   [0xf400], byte 0           ; empty keyboard buffer
  945.         mov   [0xf500], byte 0           ; empty button buffer
  946.         popad
  947.         ret
  948.  
  949.  
  950. ; check if window is necessary to draw
  951.  
  952. checkwindowdraw:
  953.  
  954.         ; edi = position in window_data+
  955.  
  956.         mov   eax, [edi + WDATA.cl_workarea]
  957.         and   eax, 0x0f000000
  958.         cmp   eax, 0x03000000
  959.         je    .return_yes      ; window type 3
  960.  
  961.         mov   esi, edi
  962.         sub   esi, window_data
  963.         shr   esi, 5
  964.  
  965.         ; esi = process number
  966.  
  967.         movzx eax, word [0xC000 + esi * 2] ; get value of the curr process
  968.         lea   esi, [0xC400 + eax * 2]      ; get address of this process at 0xC400
  969.  
  970.         push  esi
  971.  
  972.       .new_check:
  973.  
  974.         pop   esi
  975.         add   esi, 2
  976.         push  esi
  977.  
  978.         mov   eax, [0x3004]
  979.         lea   eax, word [0xC400 + eax * 2] ; number of the upper window
  980.  
  981.         cmp   esi, eax
  982.         ja    .all_wnds_to_top
  983.  
  984.         movzx eax, word [esi]
  985.         shl   eax, 5
  986.         cmp   [0x3000 + eax + TASKDATA.state], byte 9
  987.         je    .new_check                    ; skip dead windows
  988.  
  989.         lea   esi, [eax+window_data]
  990.  
  991.         mov   ebx, [edi+WDATA.box.top]  ; y0
  992.         mov   edx, [edi+WDATA.box.height]
  993.         add   edx, ebx      ; y0e
  994.  
  995.         mov   ecx, [esi+WDATA.box.top]  ; y  ; y check
  996.         cmp   ecx, edx      
  997.         jae   .new_check     ; y < y0e
  998.         mov   eax, [esi+WDATA.box.height]
  999.         add   ecx, eax       ; ye
  1000.         cmp   ebx, ecx       ; y0 >= ye
  1001.         ja    .new_check
  1002.  
  1003.         mov   eax, [edi+WDATA.box.left]   ; x0
  1004.         mov   ecx, [edi+WDATA.box.width]
  1005.         add   ecx, eax       ; x0e
  1006.  
  1007.         mov   edx, [esi+WDATA.box.left]   ; x ; x check
  1008.         cmp   edx, ecx
  1009.         jae   .new_check     ; x < x0e
  1010.         mov   ecx, [esi+WDATA.box.width]
  1011.         add   edx, ecx
  1012.         cmp   eax, edx
  1013.         ja    .new_check
  1014.  
  1015.         pop   esi
  1016.   .return_yes:
  1017.         mov   ecx,1   ; overlap some window
  1018.         ret
  1019.  
  1020.   .all_wnds_to_top:
  1021.  
  1022.         pop   esi
  1023.  
  1024.         xor   ecx, ecx       ; passed all windows to top
  1025.         ret
  1026.  
  1027.  
  1028.  
  1029.  
  1030. waredraw:     ; if redraw necessary at activate
  1031.  
  1032.         pushad
  1033.  
  1034.         call  checkwindowdraw      ; draw window on activation ?
  1035.         test  ecx, ecx
  1036.         jz    .do_not_draw
  1037.  
  1038.         popad
  1039.         mov   [0xfb44], byte 1     ; do draw mouse
  1040.         call  windowactivate
  1041.  
  1042.         ; update screen info
  1043.         pushad
  1044.         mov   edi, [0x3004] ; the last process (number)
  1045.         movzx esi, word [0xC400 + edi * 2]
  1046.         shl   esi, 5
  1047.         add   esi, window_data
  1048.  
  1049.         ; coordinates of the upper window
  1050.     mov   eax, [esi + WDATA.box.left]   ; cx
  1051.     mov   ebx, [esi + WDATA.box.top]    ; cy
  1052.     mov   ecx, [esi + WDATA.box.width]  ; sx
  1053.     mov   edx, [esi + WDATA.box.height] ; sy
  1054.  
  1055.         add   ecx, eax       ; ecx = x_end
  1056.         add   edx, ebx       ; edx = y_end
  1057.  
  1058.         mov   edi, [0x3004]
  1059.         movzx esi, word [0xC400 + edi * 2]
  1060.         call  setscreen
  1061.         popad
  1062.  
  1063.     mov   [edi + WDATA.fl_redraw], 1  ; redraw flag for app
  1064.     mov   [0xfb44],byte 0             ; mouse down checks
  1065.  
  1066.         ret
  1067.  
  1068.      .do_not_draw:
  1069.  
  1070.         popad
  1071.  
  1072.         call  windowactivate
  1073.         mov   [0xfb44],byte 0  ; mouse down checks
  1074.         mov   [0xfff4],byte 0  ; no mouse background
  1075.         mov   [0xfff5],byte 0  ; draw mouse
  1076.         ret
  1077.  
  1078.  
  1079. ; eax = window number on screen
  1080. ; corrupts registers and [dl*]
  1081. minimize_window:
  1082.         movzx eax, word [0xC400+eax*2]
  1083.         shl   eax, 5
  1084.         add   eax, window_data
  1085.         test  [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
  1086.         jnz   .skip_redrawings
  1087.         pushfd
  1088.         cli
  1089.         or    [eax+WDATA.fl_wstate], WSTATE_MINIMIZED
  1090.         mov   edi, eax
  1091.         ;call  calculatescreen
  1092.         mov   eax, [edi+WDATA.box.left]
  1093.         mov   [dlx], eax
  1094.         mov   ecx, eax
  1095.         add   ecx, [edi+WDATA.box.width]
  1096.         mov   [dlxe], ecx
  1097.         mov   ebx, [edi+WDATA.box.top]
  1098.         mov   [dly], ebx
  1099.         mov   edx, ebx
  1100.         add   edx, [edi+WDATA.box.height]
  1101.         mov   [dlye], edx
  1102.         call  calculatescreen
  1103.         xor   esi, esi
  1104.         xor   eax, eax
  1105.         call  redrawscreen
  1106.         popfd
  1107. .skip_redrawings:
  1108.         ret
  1109.  
  1110. ; eax = window number on screen
  1111. ; corrupts registers and [dl*]
  1112. restore_minimized_window:
  1113.         pushfd
  1114.         cli
  1115.         movzx esi, word [0xC400+eax*2]
  1116.         mov   edi, esi
  1117.         shl   edi, 5
  1118.         add   edi, window_data
  1119.         test  [edi+WDATA.fl_wstate], WSTATE_MINIMIZED
  1120.         jz    .skip_redrawings
  1121.         mov   [edi+WDATA.fl_redraw], 1
  1122.         and   [edi+WDATA.fl_wstate], not WSTATE_MINIMIZED
  1123.         cmp   eax, [0x3004] ; the uppermost window
  1124.         jnz   .no_uppermost
  1125.         mov   eax, [edi+WDATA.box.left]
  1126.         mov   ebx, [edi+WDATA.box.top]
  1127.         mov   ecx, eax
  1128.         mov   edx, ebx
  1129.         add   ecx, [edi+WDATA.box.width]
  1130.         add   edx, [edi+WDATA.box.height]
  1131.         call  setscreen
  1132.         jmp   .done
  1133. .no_uppermost:
  1134.         mov   eax, [edi+WDATA.box.left]
  1135.         mov   ebx, [edi+WDATA.box.top]
  1136.         mov   ecx, eax
  1137.         mov   edx, ebx
  1138.         add   ecx, [edi+WDATA.box.width]
  1139.         add   edx, [edi+WDATA.box.height]
  1140.         call  calculatescreen
  1141. .done:
  1142.         mov   [0xfff4],byte 0 ; no mouse under
  1143. .skip_redrawings:
  1144.         popfd
  1145.         ret
  1146.  
  1147.  
  1148. iglobal
  1149.   window_moving   db 'K : Window - move/resize',13,10,0
  1150.   window_moved    db 'K : Window - done',13,10,0
  1151. endg
  1152.  
  1153. ; check window touch
  1154. align 4
  1155. checkwindows:
  1156.         pushad
  1157.  
  1158.         cmp   [window_minimize], 0
  1159.         je    .no_minimizing
  1160.         mov   eax, [0x3004]       ; the uppermost window
  1161.         mov   bl, 0
  1162.         xchg  [window_minimize], bl
  1163.         cmp   bl, 1
  1164.         jne   .restore
  1165.         call  minimize_window
  1166.         jmp   .continue
  1167.   .restore:
  1168.         call  restore_minimized_window
  1169.   .continue:
  1170.   .no_minimizing:
  1171.  
  1172.         cmp   [0xfb40],byte 0    ; mouse buttons pressed ?
  1173.         jne   .mouse_buttons_pressed
  1174.         popad
  1175.         ret
  1176.     .mouse_buttons_pressed:
  1177.  
  1178.         mov   esi,[0x3004]
  1179.         inc   esi
  1180.  
  1181.       cwloop:
  1182.         cmp   esi,2
  1183.         jb   .exit
  1184.  
  1185.         dec   esi
  1186.         movzx edi, word [0xC400 + esi * 2] ; ebx
  1187.         shl   edi, 5
  1188.         add   edi, window_data
  1189. ;        mov   edi, ebx
  1190.     mov   ecx, [edi + WDATA.box.left]
  1191.     mov   edx, [edi + WDATA.box.top]
  1192.  
  1193.         mov   eax,ecx
  1194.         mov   ebx,edx
  1195.         test    [edi+WDATA.fl_wstate],WSTATE_MINIMIZED
  1196.         jnz     cwloop
  1197.  
  1198.        movzx  eax, word [0xfb0a]
  1199.        movzx  ebx, word [0xfb0c]
  1200.        
  1201.         cmp   ecx, eax
  1202.         jae   cwloop
  1203.         cmp   edx, ebx
  1204.         jae   cwloop
  1205.     add   ecx, [edi + WDATA.box.width]
  1206.     add   edx, [edi + WDATA.box.height]
  1207.         cmp   eax, ecx
  1208.         jae   cwloop
  1209.         cmp   ebx, edx
  1210.         jae   cwloop
  1211.  
  1212.         pushad
  1213.         mov   eax, esi
  1214.         mov   ebx, [0x3004]
  1215.         cmp   eax, ebx      ; is this window active?
  1216.         jz    .move_resize_window
  1217.  
  1218.         ; eax = position in windowing stack
  1219.         ; redraw must ?
  1220.         lea   esi, [0xC400 + esi * 2]
  1221.         call  waredraw
  1222.         add   esp, 32
  1223.  
  1224.       .exit:
  1225.         popad
  1226.         ret
  1227.  
  1228.    .move_resize_window:    ; MOVE OR RESIZE WINDOW
  1229.         popad
  1230.  
  1231.         ; Check for user enabled fixed window
  1232.     mov   edx, [edi + WDATA.cl_titlebar]
  1233.         and   edx, 0x0f000000
  1234.         cmp   edx, 0x01000000
  1235.         jne   .window_move_enabled_for_user
  1236.         popad
  1237.         ret
  1238.       .window_move_enabled_for_user:
  1239.  
  1240.     test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1241.         jnz     .no_resize_2
  1242.  
  1243.         mov   [do_resize_from_corner],byte 0   ; resize for skinned window
  1244.     mov   edx, [edi + WDATA.cl_workarea]
  1245.         and   edx, 0x0f000000
  1246.         cmp   edx, 0x02000000
  1247.         jb    .no_resize_2 ; not type 2 wnd
  1248.  
  1249.     mov   edx, [edi + WDATA.box.top]
  1250.     add   edx, [edi + WDATA.box.height]
  1251.         sub   edx, 6       ; edx = y_end - 6
  1252.         cmp   ebx, edx     ; ebx = mouse_y
  1253.         jb    .no_resize_2
  1254.         mov   [do_resize_from_corner],byte 1
  1255.         jmp   .continue
  1256.       .no_resize_2:
  1257.  
  1258.         push    eax
  1259.         call    get_titlebar_height
  1260.     add     eax,[edi + WDATA.box.top]
  1261.         cmp     ebx,eax
  1262.         pop     eax
  1263.         jae     .exit
  1264.  
  1265.      .continue:
  1266.  
  1267.         push  esi
  1268.         mov   esi, window_moving
  1269.         call  sys_msg_board_str
  1270.         pop   esi
  1271.  
  1272.         mov   ecx, [timer_ticks]     ; double-click ?
  1273.         mov   edx, ecx
  1274.         sub   edx, [latest_window_touch]
  1275.         mov   [latest_window_touch], ecx
  1276.         mov   [latest_window_touch_delta], edx
  1277.  
  1278.         mov   cl, [0xfb40]     ; save for shade check
  1279.         mov   [do_resize], cl
  1280.      no_emulation_righ_button:
  1281.     mov   ecx, [edi + WDATA.box.left]
  1282.     mov   edx, [edi + WDATA.box.top]
  1283.  
  1284.         push  eax ecx edx
  1285.         mov   [dlx], ecx      ; save for drawlimits
  1286.         mov   [dly], edx
  1287.     mov   eax, [edi + WDATA.box.width]
  1288.         add   ecx, eax
  1289.     mov   eax, [edi + WDATA.box.height]
  1290.         add   edx, eax
  1291.         mov   [dlxe], ecx
  1292.         mov   [dlye], edx
  1293.         pop   edx ecx eax
  1294.  
  1295.         sub   eax, ecx
  1296.         sub   ebx, edx
  1297.  
  1298.         mov   esi, [0xfb0a]
  1299.         mov   [0xf300], esi
  1300.  
  1301.         pushad           ; wait for putimages to finish
  1302. ;        mov   eax,5
  1303. ;        call  delay_hs
  1304.     mov   eax,[edi + WDATA.box.left]
  1305.         mov   [npx],eax
  1306.     mov   eax,[edi + WDATA.box.top]
  1307.         mov   [npy],eax
  1308.         popad
  1309.  
  1310.         push eax                  ; save old coordinates
  1311.     mov   ax, word [edi + WDATA.box.left]
  1312.         mov   word [oldc+BOX.left],ax
  1313.     mov   ax, word [edi + WDATA.box.top]
  1314.         mov   word [oldc+BOX.top],ax
  1315.     mov   ax, word [edi + WDATA.box.width]
  1316.         mov   word [oldc+BOX.width],ax
  1317.         mov   word [npxe],ax
  1318.     mov   ax, word [edi + WDATA.box.height]
  1319.         mov   word [oldc+BOX.height],ax
  1320.         mov   word [npye],ax
  1321.         pop eax
  1322.  
  1323.         call  drawwindowframes
  1324.  
  1325.         mov   [reposition],0
  1326.         mov   [0xfb44],byte 1   ; no reaction to mouse up/down
  1327.  
  1328.         ; move window
  1329.  
  1330.       newchm:
  1331.  
  1332.         mov   [0xfff5],byte 1
  1333.  
  1334.         call  checkidle
  1335.  
  1336.         call  checkVga_N13
  1337.  
  1338.         mov   [0xfff4],byte 0
  1339.  
  1340.         call  [draw_pointer]
  1341.  
  1342.         pushad
  1343.         call   stack_handler
  1344.         popad
  1345.  
  1346.         mov   esi,[0xf300]
  1347.         cmp   esi,[0xfb0a]
  1348.         je    cwb
  1349.  
  1350.         mov   cx,[0xfb0a]
  1351.         mov   dx,[0xfb0c]
  1352.         sub   cx,ax
  1353.         sub   dx,bx
  1354.  
  1355.         push  ax
  1356.         push  bx
  1357.  
  1358.         call  drawwindowframes
  1359.  
  1360.         mov   ax,[0xfe00]
  1361.         mov   bx,[0xfe04]
  1362.  
  1363.         cmp   [do_resize_from_corner],1
  1364.         je    no_new_position
  1365.  
  1366.         mov   word [npx],word 0     ; x repos ?
  1367.         cmp   ax,cx
  1368.         jb    noreposx
  1369.         mov   [reposition],1
  1370.         sub   ax,word [npxe]
  1371.         mov   word [npx],ax
  1372.         cmp   ax,cx
  1373.         jb    noreposx
  1374.         mov   word [npx],cx
  1375.       noreposx:
  1376.  
  1377.         mov   word [npy],word 0     ; y repos ?
  1378.         cmp   bx,dx
  1379.         jb    noreposy
  1380.         mov   [reposition],1
  1381.         sub   bx,word [npye]
  1382.         mov   word [npy],bx
  1383.         cmp   bx,dx
  1384.         jb    noreposy
  1385.         mov   word [npy],dx
  1386.       noreposy:
  1387.  
  1388.       no_new_position:
  1389.  
  1390.         cmp   [do_resize_from_corner],0    ; resize from right corner
  1391.         je    norepos_size
  1392.         pushad
  1393.  
  1394.         mov   edx,edi
  1395.         sub   edx,window_data
  1396.         ;shr   edx,5
  1397.         ;shl   edx,8
  1398.         ;add   edx,0x80000                 ; process base at 0x80000+
  1399.     lea   edx, [0x80000 + edx*8]
  1400.  
  1401.         movzx eax,word [0xfb0a]
  1402.     cmp   eax,[edi + WDATA.box.left]
  1403.         jb    nnepx
  1404.     sub   eax,[edi + WDATA.box.left]
  1405.         cmp   eax,32 ; [edx+0x90+8]
  1406.         jge   nnepx2
  1407.         mov   eax,32 ; [edx+0x90+8]
  1408.       nnepx2:
  1409.         mov   [npxe],eax
  1410.       nnepx:
  1411.  
  1412.         call    get_rolledup_height
  1413.         mov     ebx,eax
  1414.         movzx eax,word [0xfb0c]
  1415.     cmp   eax,[edi + WDATA.box.top]
  1416.         jb    nnepy
  1417.     sub   eax,[edi + WDATA.box.top]
  1418.         cmp     eax,ebx ; [edx+0x90+12]
  1419.         jge     nnepy2
  1420.         mov     eax,ebx ; [edx+0x90+12]
  1421.       nnepy2:
  1422.         mov   [npye],eax
  1423.       nnepy:
  1424.  
  1425.         mov   [reposition],1
  1426.  
  1427.         popad
  1428.       norepos_size:
  1429.  
  1430.         pop   bx
  1431.         pop   ax
  1432.         call  drawwindowframes
  1433.  
  1434.         mov   esi,[0xfb0a]
  1435.         mov   [0xf300],esi
  1436.  
  1437.       cwb:
  1438.         cmp   [0xfb40],byte 0
  1439.         jne   newchm
  1440.                                      ; new position done
  1441.         mov     [0xfff5],byte 1
  1442.         mov     cl,0
  1443.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1444.         jnz     @f
  1445.         mov     cl,[reposition]
  1446.         call    drawwindowframes
  1447.  
  1448.         mov   eax,[npx]
  1449.     mov   [edi + WDATA.box.left],eax
  1450.         mov   eax,[npy]
  1451.     mov   [edi + WDATA.box.top],eax
  1452.         mov   eax,[npxe]
  1453.     mov   [edi + WDATA.box.width],eax
  1454.         mov   eax,[npye]
  1455.     mov   [edi + WDATA.box.height],eax
  1456.         call    set_window_clientbox
  1457.  
  1458.     @@: mov     [reposition],cl
  1459.  
  1460.         cmp   [reposition],1         ; save new position and size
  1461.         jne   no_bounds_save
  1462.         push  esi edi ecx
  1463.         mov   esi,edi
  1464.         mov   ecx,2
  1465.         test  [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP or WSTATE_MAXIMIZED
  1466.         jnz   @f
  1467.         add   ecx,2
  1468.     @@: sub   edi,window_data
  1469.         shr   edi,5
  1470.         shl   edi,8
  1471.         add   edi,0x80000+APPDATA.saved_box
  1472.         cld
  1473.         rep   movsd
  1474.         pop   ecx edi esi
  1475.       no_bounds_save:
  1476.  
  1477.         pushad                             ; WINDOW SHADE/FULLSCREEN
  1478.  
  1479.         cmp   [reposition],1
  1480.         je    no_window_sizing
  1481.         mov   edx,edi
  1482.         sub   edx,window_data
  1483.         shr   edx,5
  1484.         shl   edx,8
  1485.         add   edx,0x80000                 ; process base at 0x80000+
  1486.  
  1487.         cmp   [do_resize],2               ; window shade ?
  1488.         jne   no_window_shade
  1489.         mov   [reposition],1
  1490.  
  1491.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1492.         jnz     wnd_rolldown
  1493.   wnd_rollup:
  1494.         or      [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1495.         call    get_rolledup_height
  1496.         jmp     @f
  1497.   wnd_rolldown:
  1498.         and     [edi+WDATA.fl_wstate],not WSTATE_ROLLEDUP
  1499.     mov     eax,[edx + APPDATA.saved_box.height] ; 0x90+BOX.height
  1500.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1501.         jz      @f
  1502.         mov     eax,[screen_workarea.bottom]
  1503.         sub     eax,[screen_workarea.top]
  1504.     @@: mov     [edi+WDATA.box.height],eax
  1505.         call    set_window_clientbox
  1506.  
  1507.       no_window_shade:
  1508.  
  1509.         cmp   [do_resize],1               ; fullscreen/restore ?
  1510.         jne   no_fullscreen_restore
  1511.         cmp   [latest_window_touch_delta],dword 50
  1512.         jg    no_fullscreen_restore
  1513.         mov   [reposition],1
  1514.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1515.         jnz     restore_from_fullscreen
  1516.         or      [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1517.         mov     eax,[screen_workarea.left]
  1518.         mov     [edi+WDATA.box.left],eax
  1519.         sub     eax,[screen_workarea.right]
  1520.         neg     eax
  1521.         mov     [edi+WDATA.box.width],eax
  1522.         mov     eax,[screen_workarea.top]
  1523.         mov     [edi+WDATA.box.top],eax
  1524.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1525.         jnz     @f
  1526.         sub     eax,[screen_workarea.bottom]
  1527.         neg     eax
  1528.         mov     [edi+WDATA.box.height],eax
  1529.     @@:
  1530.         jmp     restore_from_fullscreen.clientbox
  1531.       restore_from_fullscreen:
  1532.         and     [edi+WDATA.fl_wstate],not WSTATE_MAXIMIZED
  1533.         push    [edi+WDATA.box.height]
  1534.         push  edi                         ; restore
  1535.         lea   esi, [edx + APPDATA.saved_box]
  1536.         mov   ecx,4
  1537.         cld
  1538.         rep   movsd
  1539.         pop   edi
  1540.         pop     eax
  1541.         test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
  1542.         jz      @f
  1543.         mov     [edi+WDATA.box.height],eax
  1544.     @@:
  1545.     .clientbox:
  1546.         call    set_window_clientbox
  1547.  
  1548.       no_fullscreen_restore:
  1549.  
  1550.         mov   eax,[edi+WDATA.box.top]                 ; check Y inside screen
  1551.         add   eax,[edi+WDATA.box.height]
  1552.         cmp   eax,[0xfe04]
  1553.         jbe   no_window_sizing
  1554.         mov   eax,[edi+WDATA.box.left]                 ; check X inside screen
  1555.         add   eax,[edi+WDATA.box.width]
  1556.         cmp   eax,[0xfe00]
  1557.         jbe   no_window_sizing
  1558.         mov   eax,[0xfe00]
  1559.         sub   eax,[edi+WDATA.box.width]
  1560.         mov   [edi+WDATA.box.left],eax
  1561.         mov   eax,[0xfe04]
  1562.         sub   eax,[edi+WDATA.box.height]
  1563.         mov   [edi+WDATA.box.top],eax
  1564.         call  set_window_clientbox
  1565.       no_window_sizing:
  1566.  
  1567.         popad
  1568.  
  1569.         cmp   [reposition],0
  1570.         je    retwm
  1571.  
  1572.         mov   [0xfff5],byte 1 ; no mouse
  1573.  
  1574.  
  1575.         push  eax ebx ecx edx
  1576.         mov   eax,[edi+WDATA.box.left]
  1577.         mov   ebx,[edi+WDATA.box.top]
  1578.         mov   ecx,[edi+WDATA.box.width]
  1579.         mov   edx,[edi+WDATA.box.height]
  1580.         add   ecx,eax
  1581.         add   edx,ebx
  1582.         call  calculatescreen
  1583.  
  1584.         mov   eax,[oldc+BOX.left]
  1585.         mov   ebx,[oldc+BOX.top]
  1586.         mov   ecx,[oldc+BOX.width]
  1587.         mov   edx,[oldc+BOX.height]
  1588.         add   ecx,eax
  1589.         add   edx,ebx
  1590.         call  calculatescreen
  1591.         pop   edx ecx ebx eax
  1592.  
  1593.         mov   eax,edi
  1594.         call  redrawscreen
  1595.  
  1596.  
  1597.         mov     [edi+WDATA.fl_redraw],1
  1598.  
  1599.         mov   ecx,100         ; wait to avoid mouse residuals
  1600.       waitre2:
  1601.         mov   [0xfff5],byte 1
  1602.         call  checkidle
  1603.         cmp     [edi+WDATA.fl_redraw],0
  1604.         jz    retwm
  1605.         loop  waitre2
  1606.  
  1607.       retwm:
  1608.  
  1609.         mov   [0xfff5],byte 0 ; mouse pointer
  1610.         mov   [0xfff4],byte 0 ; no mouse under
  1611.         mov   [0xfb44],byte 0 ; react to mouse up/down
  1612.  
  1613.         mov    esi,window_moved
  1614.         call   sys_msg_board_str
  1615.  
  1616.         popad
  1617.  
  1618.         ret
  1619.  
  1620.  
  1621. uglobal
  1622.   add_window_data            dd  0
  1623.   do_resize_from_corner      db  0x0
  1624.   reposition                 db  0x0
  1625.   latest_window_touch        dd  0x0
  1626.   latest_window_touch_delta  dd  0x0
  1627.  
  1628.   do_resize db 0x0
  1629.  
  1630.   oldc    dd 0x0,0x0,0x0,0x0
  1631.  
  1632.   dlx     dd 0x0
  1633.   dly     dd 0x0
  1634.   dlxe    dd 0x0
  1635.   dlye    dd 0x0
  1636.  
  1637.   npx     dd 0x0
  1638.   npy     dd 0x0
  1639.   npxe    dd 0x0
  1640.   npye    dd 0x0
  1641.  
  1642.   mpx     dd 0x0
  1643.   mpy     dd 0x0
  1644. endg
  1645.  
  1646.  
  1647. ; draw negative window frames
  1648. uglobal
  1649. moving_wnd dd ?
  1650. moving_wnd_redrawed db ?
  1651. endg
  1652.  
  1653. drawwindowframes:
  1654.         mov     [moving_wnd], edi
  1655.  
  1656.         test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
  1657.         jnz     .ret
  1658.         cmp     [edi+WDATA.fl_redraw], 0
  1659.         jz      @f
  1660.         xor     [moving_wnd_redrawed], 1
  1661.         jmp     .ret
  1662. @@:
  1663.         cmp     [moving_wnd_redrawed], 0
  1664.         jz      @f
  1665.         mov     [moving_wnd_redrawed], 0
  1666. .ret:
  1667.         ret
  1668. @@:
  1669.  
  1670.         pushad
  1671.  
  1672.         mov   eax,[npx]
  1673.         shl   eax,16
  1674.         add   eax,[npx]
  1675.         add   eax,[npxe]
  1676.         add   eax,65536*1-1
  1677.         mov   ebx,[npy]
  1678.         shl   ebx,16
  1679.         add   ebx,[npy]
  1680.         mov   ecx,0x01000000
  1681.         push  edi
  1682.         mov   edi,1
  1683.         call  [draw_line]
  1684.         pop   edi
  1685.  
  1686.         mov   eax,[npx]
  1687.         shl   eax,16
  1688.         add   eax,[npx]
  1689.         add   eax,[npxe]
  1690.         add   eax,65536*1-1
  1691.         mov   ebx,[npy]
  1692.         add   ebx,[npye]
  1693.         shl   ebx,16
  1694.         add   ebx,[npy]
  1695.         add   ebx,[npye]
  1696.         mov   ecx,0x01000000
  1697.         push  edi
  1698.         mov   edi,1
  1699.         call  [draw_line]
  1700.         pop   edi
  1701.  
  1702.         mov   eax,[npx]
  1703.         shl   eax,16
  1704.         add   eax,[npx]
  1705.         mov   ebx,[npy]
  1706.         shl   ebx,16
  1707.         add   ebx,[npy]
  1708.         add   ebx,[npye]
  1709.         mov   ecx,0x01000000
  1710.         push  edi
  1711.         mov   edi,1
  1712.         call  [draw_line]
  1713.         pop   edi
  1714.  
  1715.         mov   eax,[npx]
  1716.         add   eax,[npxe]
  1717.         shl   eax,16
  1718.         add   eax,[npx]
  1719.         add   eax,[npxe]
  1720.         mov   ebx,[npy]
  1721.         shl   ebx,16
  1722.         add   ebx,[npy]
  1723.         add   ebx,[npye]
  1724.         mov   ecx,0x01000000
  1725.         push  edi
  1726.         mov   edi,1
  1727.         call  [draw_line]
  1728.         mov   edi,[0x3000]
  1729.         shl   edi,5
  1730.         add   edi,window_data
  1731.         mov   [edi+WDATA.fl_wdrawn],byte 1
  1732.         pop   edi
  1733.  
  1734.         popad
  1735.         ret
  1736.  
  1737.  
  1738.  
  1739. random_shaped_window:
  1740.  
  1741. ;
  1742. ;  eax = 0    giving address of data area
  1743. ;      ebx    address
  1744. ;  eax = 1    shape area scale
  1745. ;      ebx    2^ebx scale
  1746.  
  1747.      test eax, eax
  1748.      jne  rsw_no_address
  1749.      mov  eax,[0x3000]
  1750.      shl  eax,8
  1751.  
  1752.      mov  [eax+0x80000+APPDATA.wnd_shape],ebx
  1753.    rsw_no_address:
  1754.  
  1755.      cmp  eax,1
  1756.      jne  rsw_no_scale
  1757.      mov  eax,[0x3000]
  1758.      shl  eax,8
  1759.      mov  byte [eax+0x80000+APPDATA.wnd_shape_scale], bl
  1760.    rsw_no_scale:
  1761.  
  1762.      ret
  1763.  
  1764.  
  1765.