Subversion Repositories Kolibri OS

Rev

Rev 384 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;-----------------------------------------------------------------------------
  2. ;///// PART OF ATi RADEON 9000 DRIVER ////////////////////////////////////////
  3. ;-----------------------------------------------------------------------------
  4. ; Copyright (c) 2004, mike.dld
  5. ; Using BeOS driver - Copyright (c) 2002, Thomas Kurschel
  6. ;-----------------------------------------------------------------------------
  7. ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  8. ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9. ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  10. ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  11. ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  12. ; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  13. ; DEALINGS IN THE SOFTWARE.
  14. ;-----------------------------------------------------------------------------
  15.  
  16. include 'clipping.inc'
  17.  
  18. struct RECT
  19.  left   dd ?
  20.  top    dd ?
  21.  right  dd ?
  22.  bottom dd ?
  23. ends
  24.  
  25. virtual at ebp
  26.  r RECT
  27. end virtual
  28.  
  29. virtual at edi
  30.  r2 RECT
  31. end virtual
  32.  
  33. SR = sizeof.RECT
  34.  
  35. macro movl val,reg {
  36.  mov reg,val
  37. }
  38.  
  39. EQUAL_LEFT   = 00000001b
  40. EQUAL_BOTTOM = 00000010b
  41. EQUAL_RIGHT  = 00000100b
  42. EQUAL_TOP    = 00001000b
  43.  
  44. func calc_clipping_rects
  45. begin
  46.         mov     [cnt],0
  47.         movzx   ebp,word[CURRENT_TASK]
  48.         shl     ebp,5
  49.  
  50.         cmp     ebp,0x20
  51.         jne     @f
  52.         mov     esi,viewport
  53.         mov     edi,rct
  54.         mov     ecx,sizeof.RECT/4
  55.         cld
  56.         rep     movsd
  57.         jmp     .lp1
  58.     @@:
  59.         movsx   eax,word[ebp+0x00]
  60.         mov     [rct.left],eax
  61.         mov     [rct.right],eax
  62.         movsx   eax,word[ebp+0x04]
  63.         mov     [rct.top],eax
  64.         mov     [rct.bottom],eax
  65.         movzx   eax,word[ebp+0x08]
  66.         inc     eax
  67.         add     [rct.right],eax
  68.         movzx   eax,word[ebp+0x0C]
  69.         inc     eax
  70.         add     [rct.bottom],eax
  71.   .lp1:
  72.         mov     esi,viewport
  73.         mov     edi,tr
  74.         mov     ecx,sizeof.RECT/4
  75.         cld
  76.         rep     movsd
  77.         mov     ebp,rct
  78.         call    intersect_rect ; (ebp,tr)->(x1:edx,y1:eax,x2:ebx,y2:ecx)+CF
  79.         jc      .exit
  80.         mov     [rct.left],edx
  81.         mov     [rct.top],eax
  82.         mov     [rct.right],ebx
  83.         mov     [rct.bottom],ecx
  84.         inc     [cnt]
  85. comment ^
  86.         movsx   eax,word[ebp+0x00]
  87.         mov     [rct.left],eax
  88.         mov     [rct.right],eax
  89.         movsx   eax,word[ebp+0x04]
  90.         mov     [rct.top],eax
  91.         mov     [rct.bottom],eax
  92.         movsx   eax,word[ebp+0x08]
  93.         inc     eax
  94.         add     [rct.right],eax
  95.         movsx   eax,word[ebp+0x0C]
  96.         inc     eax
  97.         add     [rct.bottom],eax
  98. ^
  99.         movzx   ecx,word[TASK_COUNT]    ; number of processes
  100.         jif     ecx,be,1,.exit
  101.  
  102. ; calculate clipping rectangles
  103.  
  104.         mov     esi,1
  105.   ; go forward through all windows
  106.     .next_window:
  107.         movzx   edi,word[CURRENT_TASK]  ; calling process number
  108.  
  109.         mov     ax,[WIN_STACK+esi*2]
  110.         jif     ax,be,[WIN_STACK+edi*2],.end_window.2
  111.  
  112.         mov     ebp,[cnt]
  113.         shl     ebp,4                   ; ebp *= SR
  114.         jz      .exit
  115.         lea     ebp,[rct+ebp-SR]
  116.  
  117.         push    esi ;ecx esi
  118.         shl     esi,5
  119.         lodsd
  120.         mov     [tr.left],eax
  121.         mov     [tr.right],eax
  122.         lodsd
  123.         mov     [tr.top],eax
  124.         mov     [tr.bottom],eax
  125.         lodsd
  126.         jif     eax,z,eax,.end_window,test
  127.         inc     eax
  128.         add     [tr.right],eax
  129.         lodsd
  130.         jif     eax,z,eax,.end_window,test
  131.         inc     eax
  132.         add     [tr.bottom],eax
  133.   ; go backward through all rectangles
  134.     .next_rect:
  135.  
  136. rc_top    equ eax
  137. rc_right  equ ebx
  138. rc_bottom equ ecx
  139. rc_left   equ edx
  140.  
  141.         call    intersect_rect ; (ebp,tr)->(x1:edx,y1:eax,x2:ebx,y2:ecx)+CF
  142.         jc      .is_finish
  143.         xor     edi,edi
  144.         jif     rc_top,ne,[r.top],@f
  145.         or      edi,EQUAL_TOP
  146.     @@: jif     rc_right,ne,[r.right],@f
  147.         or      edi,EQUAL_RIGHT
  148.     @@: jif     rc_bottom,ne,[r.bottom],@f
  149.         or      edi,EQUAL_BOTTOM
  150.     @@: jif     rc_left,ne,[r.left],@f
  151.         or      edi,EQUAL_LEFT
  152.     @@: jmp     [jtable_intersect+edi*4]
  153.  
  154.     .is_0000:
  155.         call    copy_current
  156.         mov     [r.left      ],rc_right
  157.         mov     [r2.right -SR],rc_left
  158.         mov     [r2.left     ],rc_left
  159.         mov     [r2.right    ],rc_right
  160.         mov     [r2.bottom   ],rc_top
  161.         mov     [r2.left  +SR],rc_left
  162.         mov     [r2.right +SR],rc_right
  163.         mov     [r2.top   +SR],rc_bottom
  164.         movl    [r.top       ],esi
  165.         mov     [r2.top      ],esi
  166.         movl    [r.bottom    ],esi
  167.         mov     [r2.bottom+SR],esi
  168.         add     [cnt],2
  169.         jmp     .is_finish
  170.     .is_0001:
  171.         call    copy_current
  172.         mov     [r.top       ],rc_bottom
  173.         mov     [r2.bottom-SR],rc_top
  174.         mov     [r2.left     ],rc_right
  175.         mov     [r2.top      ],rc_top
  176.         mov     [r2.bottom   ],rc_bottom
  177.         movl    [r.right     ],esi
  178.         mov     [r2.right    ],esi
  179.         inc     [cnt]
  180.         jmp     .is_finish
  181.     .is_0010:
  182.         call    copy_current
  183.         mov     [r.left      ],rc_right
  184.         mov     [r2.right -SR],rc_left
  185.         mov     [r2.left     ],rc_left
  186.         mov     [r2.right    ],rc_right
  187.         mov     [r2.bottom   ],rc_top
  188.         movl    [r.top       ],esi
  189.         mov     [r2.top      ],esi
  190.         inc     [cnt]
  191.         jmp     .is_finish
  192.     .is_0011:
  193.         call    copy_current
  194.         mov     [r.bottom    ],rc_top
  195.         mov     [r2.left  -SR],rc_right
  196.         mov     [r2.top   -SR],rc_top
  197.         jmp     .is_finish
  198.     .is_0100:
  199.         call    copy_current
  200.         mov     [r.top       ],rc_bottom
  201.         mov     [r2.bottom-SR],rc_top
  202.         mov     [r2.right    ],rc_left
  203.         mov     [r2.top      ],rc_top
  204.         mov     [r2.bottom   ],rc_bottom
  205.         movl    [r.left      ],esi
  206.         mov     [r2.left     ],esi
  207.         inc     [cnt]
  208.         jmp     .is_finish
  209.     .is_0101:
  210.         call    copy_current
  211.         mov     [r.top       ],rc_bottom
  212.         mov     [r2.bottom-SR],rc_top
  213.         jmp     .is_finish
  214.     .is_0110:
  215.         call    copy_current
  216.         mov     [r.bottom    ],rc_top
  217.         mov     [r2.right -SR],rc_left
  218.         mov     [r2.top   -SR],rc_top
  219.         jmp     .is_finish
  220.     .is_0111:
  221.         mov     [r.bottom    ],rc_top
  222.         jmp     .is_finish
  223.     .is_1000:
  224.         call    copy_current
  225.         mov     [r.left      ],rc_right
  226.         mov     [r2.right -SR],rc_left
  227.         mov     [r2.left     ],rc_left
  228.         mov     [r2.right    ],rc_right
  229.         mov     [r2.top      ],rc_bottom
  230.         movl    [r.bottom    ],esi
  231.         mov     [r2.bottom   ],esi
  232.         inc     [cnt]
  233.         jmp     .is_finish
  234.     .is_1001:
  235.         call    copy_current
  236.         mov     [r.top       ],rc_bottom
  237.         mov     [r2.left  -SR],rc_right
  238.         mov     [r2.bottom-SR],rc_bottom
  239.         jmp     .is_finish
  240.     .is_1010:
  241.         call    copy_current
  242.         mov     [r.left      ],rc_right
  243.         mov     [r2.right -SR],rc_left
  244.         jmp     .is_finish
  245.     .is_1011:
  246.         mov     [r.left      ],rc_right
  247.         jmp     .is_finish
  248.     .is_1100:
  249.         call    copy_current
  250.         mov     [r.top       ],rc_bottom
  251.         mov     [r2.right -SR],rc_left
  252.         mov     [r2.bottom-SR],rc_bottom
  253.         jmp     .is_finish
  254.     .is_1101:
  255.         mov     [r.top       ],rc_bottom
  256.         jmp     .is_finish
  257.     .is_1110:
  258.         mov     [r.right     ],rc_left
  259.         jmp     .is_finish
  260.     .is_1111:
  261.         call    delete_current
  262.     .is_finish:
  263.         sub     ebp,SR
  264.         jif     ebp,ae,rct,.next_rect
  265.     .end_window:
  266.         pop     esi; ecx
  267.     .end_window.2:
  268.         inc     esi
  269.         jif     esi,be,[TASK_COUNT],.next_window
  270. ;       dec     ecx
  271. ;       jnz     .next_window
  272.  
  273. ; combine some rectangles if possible
  274. ; with Result do begin
  275. ;  for i := cnt-1 downto 0 do if rct[i].Left >= 0 then
  276. ;   for j := cnt-1 downto 0 do if (j <> i) and (rct[j].Left >= 0) then
  277. ;    if (rct[i].Left = rct[j].Left) and (rct[i].Right = rct[j].Right) then begin
  278. ;    end else if (rct[i].Top = rct[j].Top) and (rct[i].Bottom = rct[j].Bottom) then begin
  279. ;     if (rct[i].Left = rct[j].Right) then begin
  280. ;      rct[i].Left := rct[j].Left;
  281. ;      rct[j].Left := -1;
  282. ;     end else if (rct[i].Right = rct[j].Left) then begin
  283. ;      rct[i].Right := rct[j].Right;
  284. ;      rct[j].Left := -1;
  285. ;     end;
  286. ;    end;
  287. ;  for i := cnt-1 downto 0 do if rct[i].Left < 0 then begin
  288. ;   for j := i to cnt-2 do
  289. ;    rct[j] := rct[j+1];
  290. ;   dec(cnt);
  291. ;  end;
  292. ; end;
  293.  
  294. .combine_rects:
  295.        mov     esi,[cnt]
  296.        shl     esi,4
  297.        add     esi,rct
  298.        lea     ebp,[esi-SR]
  299.        push    ebp
  300.   .next_rect1:
  301.        sub     esi,SR
  302.        jif     esi,b,rct,.exit.combine
  303.        jif     [esi+RECT.left],e,-1,.next_rect1
  304.        push    ebp
  305.   .next_rect2:
  306.        jif     ebp,e,esi,.next_rect2.ok
  307.        jif     [ebp+RECT.left],e,-1,.next_rect2.ok
  308.  
  309.        mov     eax,[ebp+RECT.left]
  310.        mov     ebx,[ebp+RECT.right]
  311.        mov     ecx,[ebp+RECT.top]
  312.        mov     edx,[ebp+RECT.bottom]
  313.        jif     eax,ne,[esi+RECT.left],.not_left_right
  314.        jif     ebx,ne,[esi+RECT.right],.not_left_right
  315.        jif     edx,ne,[esi+RECT.top],@f
  316.        mov     [esi+RECT.top],ecx
  317.        jmp     .next_rect2.mark
  318.     @@:        jif     ecx,ne,[esi+RECT.bottom],.next_rect2.ok
  319.        mov     [esi+RECT.bottom],edx
  320.        jmp     .next_rect2.mark
  321.   .not_left_right:
  322.        jif     ecx,ne,[esi+RECT.top],.next_rect2.ok
  323.        jif     edx,ne,[esi+RECT.bottom],.next_rect2.ok
  324.        jif     ebx,ne,[esi+RECT.left],@f
  325.        mov     [esi+RECT.left],eax
  326.        jmp     .next_rect2.mark
  327.     @@:        jif     eax,ne,[esi+RECT.right],.next_rect2.ok
  328.        mov     [esi+RECT.right],ebx
  329.   .next_rect2.mark:
  330.        or      [ebp+RECT.left],-1
  331.   .next_rect2.ok:
  332.        sub     ebp,SR
  333.        jif     ebp,ae,rct,.next_rect2
  334.        pop     ebp
  335.        jmp     .next_rect1
  336.   .exit.combine:
  337.  
  338.        pop     ebp
  339.   .next_rect3:
  340.        jif     [ebp+RECT.left],ne,-1,@f
  341.        call    delete_current
  342.     @@:        sub     ebp,SR
  343.        jif     ebp,ae,rct,.next_rect3
  344.  
  345. ; remove unnecessary rectangles
  346. ;  for i := Result.cnt-1 downto 0 do with Result do
  347. ;   if not IntersectRect(rc,rct[i],r2) then begin
  348. ;    for j := i to cnt-2 do
  349. ;     rct[j] := rct[j+1];
  350. ;    dec(cnt);
  351. ;   end;
  352.  
  353.     .exit:
  354.         mov     esi,rct
  355.         mov     ecx,[cnt]
  356.         ret
  357.  
  358. delete_current:
  359.         push    ecx
  360.         lea     esi,[ebp+SR]    ; esi = ebp+SR
  361.         mov     edi,ebp         ; edi = ebp
  362.         mov     ecx,[cnt]       ; ecx = cnt
  363.         shl     ecx,4           ; ecx *= SR
  364.         add     ecx,rct-SR      ; ecx += rct-SR
  365.         sub     ecx,ebp         ; ecx -= ebp
  366.         cld
  367.         rep     movsb
  368.         dec     [cnt]
  369.         pop     ecx
  370.         ret
  371.  
  372. copy_current:
  373.         push    ecx
  374.         mov     edi,[cnt]
  375.         shl     edi,4
  376.         lea     edi,[rct+edi]
  377.         mov     esi,ebp
  378.         mov     ecx,4
  379.         cld
  380.         rep     movsd
  381.         pop     ecx
  382.         inc     [cnt]
  383.         ret
  384.  
  385. intersect_rect: ; ebp,tr
  386.         mov     rc_top,[tr.top]
  387.         jif     rc_top,ge,[r.bottom],.exit
  388.         mov     rc_right,[tr.right]
  389.         jif     rc_right,le,[r.left],.exit
  390.         mov     rc_bottom,[tr.bottom]
  391.         jif     rc_bottom,le,[r.top],.exit
  392.         mov     rc_left,[tr.left]
  393.         jif     rc_left,ge,[r.right],.exit
  394.  
  395.         jif     rc_top,ge,[r.top],@f
  396.         mov     rc_top,[r.top]
  397.     @@: jif     rc_right,le,[r.right],@f
  398.         mov     rc_right,[r.right]
  399.     @@: jif     rc_bottom,le,[r.bottom],@f
  400.         mov     rc_bottom,[r.bottom]
  401.     @@: jif     rc_left,ge,[r.left],@f
  402.         mov     rc_left,[r.left]
  403.     @@: clc
  404.         ret
  405.     .exit:
  406.         stc
  407.         ret
  408.  
  409. endf
  410.  
  411. func FC
  412. begin
  413.   .x00:
  414.   .x01:
  415.   .x02:
  416.   .x04:
  417.   .x05:
  418.   .x06:
  419.   .x08:
  420.   .x09:
  421.   .x0A:
  422.   .x10:
  423.   .x11:
  424.   .x12:
  425.   .x14:
  426.   .x15:
  427.   .x16:
  428.   .x18:
  429.   .x19:
  430.   .x1A:
  431.   .x20:
  432.   .x21:
  433.   .x22:
  434.   .x24:
  435.   .x25:
  436.   .x26:
  437.   .x28:
  438.   .x29:
  439.   .x2A:
  440.   .x40:
  441.   .x41:
  442.   .x42:
  443.   .x44:
  444.   .x45:
  445.   .x46:
  446.   .x48:
  447.   .x49:
  448.   .x4A:
  449.   .x50:
  450.   .x51:
  451.   .x52:
  452.   .x54:
  453.   .x55:
  454.   .x56:
  455.   .x58:
  456.   .x59:
  457.   .x5A:
  458.   .x60:
  459.   .x61:
  460.   .x62:
  461.   .x64:
  462.   .x65:
  463.   .x66:
  464.   .x68:
  465.   .x69:
  466.   .x6A:
  467.   .x80:
  468.   .x81:
  469.   .x82:
  470.   .x84:
  471.   .x85:
  472.   .x86:
  473.   .x88:
  474.   .x89:
  475.   .x8A:
  476.   .x90:
  477.   .x91:
  478.   .x92:
  479.   .x94:
  480.   .x95:
  481.   .x96:
  482.   .x98:
  483.   .x99:
  484.   .x9A:
  485.   .xA0:
  486.   .xA1:
  487.   .xA2:
  488.   .xA4:
  489.   .xA5:
  490.   .xA6:
  491.   .xA8:
  492.   .xA9:
  493.   .xAA:
  494.         ret
  495.   .xXX:
  496.         ret
  497. endf
  498.  
  499. ;-----------------------------------------------------------------------------
  500. ;///// END ///////////////////////////////////////////////////////////////////
  501. ;-----------------------------------------------------------------------------