Subversion Repositories Kolibri OS

Rev

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