Subversion Repositories Kolibri OS

Rev

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