Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. format MS COFF
  9.  
  10. include 'proc32.inc'
  11. include 'imports.inc'
  12.  
  13. DEBUG     equ 1
  14.  
  15. VID_ATI     equ 0x1002
  16.  
  17. LOAD_FROM_FILE  equ 0
  18. LOAD_FROM_MEM   equ 1
  19. LOAD_INDIRECT   equ 2
  20. LOAD_SYSTEM     equ 3
  21.  
  22. VIDEO_FREE      equ 2
  23.  
  24. struc BITMAPINFOHEADER {
  25.   .biSize          dd ? ; DWORD
  26.   .biWidth         dd ? ; LONG
  27.   .biHeight        dd ? ; LONG
  28.   .biPlanes        dw ? ; WORD
  29.   .biBitCount      dw ? ; WORD
  30.   .biCompression   dd ? ; DWORD
  31.   .biSizeImage     dd ? ; DWORD
  32.   .biXPelsPerMeter dd ? ; LONG
  33.   .biYPelsPerMeter dd ? ; LONG
  34.   .biClrUsed       dd ? ; DWORD
  35.   .biClrImportant  dd ? ; DWORD
  36. }
  37.  
  38. virtual at 0
  39.   BI BITMAPINFOHEADER
  40. end virtual
  41.  
  42. struc CURSOR
  43. {;common object header
  44.    .magic       dd ?   ;'CURS'
  45.    .destroy     dd ?   ;internal destructor
  46.    .fd          dd ?   ;next object in list
  47.    .bk          dd ?   ;prev object in list
  48.    .pid         dd ?   ;owner id
  49.  
  50.  ;cursor data
  51.    .base        dd ?   ;allocated memory
  52.    .hot_x       dd ?   ;hotspot coords
  53.    .hot_y       dd ?
  54. }
  55. virtual at 0
  56.   CURSOR CURSOR
  57. end virtual
  58.  
  59. CURSOR_SIZE     equ 32
  60.  
  61. R8500       equ 0x514C  ;R200
  62. R9000       equ 0x4966  ;RV250
  63. R9200       equ 0x5961  ;RV280
  64. R9500       equ 0x4144  ;R300
  65. R9500P      equ 0x4E45  ;R300
  66. R9550       equ 0x4153  ;RV350
  67. R9600       equ 0x4150  ;RV350
  68. R9600XT     equ 0x4152  ;RV360
  69. R9700P      equ 0x4E44  ;R300
  70. R9800       equ 0x4E49  ;R350
  71. R9800P      equ 0x4E48  ;R350
  72. R9800XT     equ 0x4E4A  ;R360
  73.  
  74. OS_BASE         equ 0x80000000
  75. SLOT_BASE       equ (OS_BASE+0x0080000)
  76.  
  77. PG_SW        equ 0x003
  78. PG_NOCACHE   equ 0x018
  79.  
  80. struc IOCTL
  81. {  .handle           dd ?
  82.    .io_code          dd ?
  83.    .input            dd ?
  84.    .inp_size         dd ?
  85.    .output           dd ?
  86.    .out_size         dd ?
  87. }
  88.  
  89. virtual at 0
  90.   IOCTL IOCTL
  91. end virtual
  92.  
  93. ;MMIO                   equ 0F9000000h
  94. RD_RB3D_CNTL            equ 1c3ch
  95.  
  96. RD_MEM_CNTL                equ 0140h
  97. RD_CRTC_GEN_CNTL           equ 0050h
  98. RD_CRTC_CUR_EN             equ 10000h
  99. RD_DISPLAY_BASE_ADDR       equ 023ch
  100. RD_DEFAULT_OFFSET          equ 16e0h
  101. CUR_HORZ_VERT_OFF          equ 0268h
  102. CUR_HORZ_VERT_POSN         equ 0264h
  103. CUR_OFFSET                 equ 0260h
  104. RD_RB3D_CNTL               equ 1c3ch
  105. RD_RBBM_STATUS             equ 0e40h
  106. RD_RBBM_FIFOCNT_MASK       equ 007fh
  107. RD_RBBM_ACTIVE             equ 80000000h
  108. RD_TIMEOUT                 equ 2000000
  109.  
  110. RD_DP_GUI_MASTER_CNTL      equ 0146ch
  111. RD_DP_BRUSH_BKGD_CLR       equ 01478h
  112. RD_DP_BRUSH_FRGD_CLR       equ 0147ch
  113. RD_DP_SRC_BKGD_CLR         equ 015dch
  114. RD_DP_SRC_FRGD_CLR         equ 015d8h
  115. RD_DP_CNTL                 equ 016c0h
  116. RD_DP_DATATYPE             equ 016c4h
  117. RD_DP_WRITE_MASK           equ 016cch
  118. RD_DP_SRC_SOURCE_MEMORY    equ (2 shl 24)
  119. RD_DP_SRC_SOURCE_HOST_DATA equ (3 shl 24)
  120. RD_DEFAULT_SC_BOTTOM_RIGHT equ 16e8h
  121. RD_GMC_BRUSH_SOLID_COLOR   equ (13 shl 4)
  122. RD_DEFAULT_SC_RIGHT_MAX    equ 1fffh
  123. RD_DEFAULT_SC_BOTTOM_MAX   equ 1fff0000h
  124. RD_GMC_DST_DATATYPE_SHIFT  equ 8
  125.  
  126. RD_ROP3_S                  equ 00cc0000h
  127. RD_ROP3_P                  equ 00f00000h
  128.  
  129. RD_RB2D_DSTCACHE_MODE      equ 03428h
  130. RD_RB2D_DSTCACHE_CTLSTAT   equ 0342ch
  131. RD_RB2D_DC_FLUSH_ALL       equ 000fh
  132. RD_RB2D_DC_BUSY            equ 80000000h
  133.  
  134. RD_GMC_BRUSH_SOLID_COLOR   equ 000000D0h
  135. RD_GMC_SRC_DATATYPE_COLOR  equ (3 shl 12)
  136. RD_GMC_CLR_CMP_CNTL_DIS    equ (1 shl 28)
  137. RD_GMC_WR_MSK_DIS          equ (1 shl 30)
  138.  
  139. cmdSolidFill               equ 73f036d0h
  140.  
  141. RD_DST_PITCH_OFFSET        equ 142ch
  142. RD_SRC_PITCH_OFFSET        equ 1428h
  143.  
  144. RD_DST_X_LEFT_TO_RIGHT     equ 1
  145. RD_DST_Y_TOP_TO_BOTTOM     equ 2
  146. RD_DST_Y_X                 equ 1438h
  147. RD_DST_WIDTH_HEIGHT        equ 1598h
  148. RD_DST_LINE_START          equ 1600h
  149. RD_DST_LINE_END            equ 1604h
  150. R300_MEM_NUM_CHANNELS_MASK equ 0003h
  151.  
  152. macro rdr op1, op2
  153. {
  154.      mov edi, [ati_io]
  155.      mov op1, [edi+op2]
  156. }
  157.  
  158. macro wrr dest, src
  159. {
  160.      mov edi, [ati_io]
  161.      mov dword [edi+dest], src
  162. }
  163.  
  164.  
  165. public START
  166. public service_proc
  167. public version
  168.  
  169. CURSOR_IMAGE_OFFSET  equ 0x00500000
  170.  
  171. DRV_ENTRY equ 1
  172. DRV_EXIT  equ -1
  173.  
  174. section '.flat' code readable align 16
  175.  
  176. proc START stdcall, state:dword
  177.  
  178.            cmp [state], 1
  179.            jne .exit
  180.  
  181.      if DEBUG
  182.            mov esi, msgInit
  183.            call SysMsgBoardStr
  184.      end if
  185.  
  186.            call detect_ati
  187.            test eax, eax
  188.            jz .fail
  189.  
  190.            call init_ati
  191.            test eax, eax
  192.            jz .fail
  193.  
  194.            or eax, -1
  195.            mov [cursor_map], eax
  196.            mov [cursor_map+4], eax
  197.            mov edx, cursor_map
  198.            mov [cursor_start], edx
  199.            add edx, 8
  200.            mov [cursor_end], edx
  201.  
  202.            stdcall RegService, sz_ati_srv, service_proc
  203.            test eax, eax
  204.            jz .fail
  205.            mov dword [SetHwCursor], drvCursorPos ;enable hardware cursor
  206.            mov dword [HwCursorRestore], drv_restore
  207.            mov dword [HwCursorCreate], ati_cursor
  208.            ret
  209. .fail:
  210.      if DEBUG
  211.            mov esi, msgFail
  212.            call SysMsgBoardStr
  213.      end if
  214.  
  215. .exit:
  216.            xor eax, eax
  217. ;           mov ebx, SetHwCursor
  218. ;           mov dword [ebx], eax    ;force disable hardware cursor
  219.            ret
  220. endp
  221.  
  222. handle     equ  IOCTL.handle
  223. io_code    equ  IOCTL.io_code
  224. input      equ  IOCTL.input
  225. inp_size   equ  IOCTL.inp_size
  226. output     equ  IOCTL.output
  227. out_size   equ  IOCTL.out_size
  228.  
  229. align 4
  230. proc service_proc stdcall, ioctl:dword
  231.  
  232.            mov edi, [ioctl]
  233.            mov ebx, [edi+io_code]
  234.            cmp ebx, VIDEO_FREE
  235.            jne .fail
  236.  
  237.            mov eax, [edi+input]
  238.            call video_free
  239. .fail:
  240.            or eax, -1
  241.            ret
  242. endp
  243.  
  244. restore   handle
  245. restore   io_code
  246. restore   input
  247. restore   inp_size
  248. restore   output
  249. restore   out_size
  250.  
  251. align 4
  252. proc detect_ati
  253.            locals
  254.              last_bus dd ?
  255.            endl
  256.  
  257.            xor eax, eax
  258.            mov [bus], eax
  259.            inc eax
  260.            call PciApi
  261.            cmp eax, -1
  262.            je .err
  263.  
  264.            mov [last_bus], eax
  265.  
  266. .next_bus:
  267.            and [devfn], 0
  268. .next_dev:
  269.            stdcall PciRead32, [bus], [devfn], dword 0
  270.            test eax, eax
  271.            jz .next
  272.            cmp eax, -1
  273.            je .next
  274.  
  275.            mov edi, devices
  276. @@:
  277.            mov ebx, [edi]
  278.            test ebx, ebx
  279.            jz .next
  280.  
  281.            cmp eax, ebx
  282.            je .found
  283.            add edi, 4
  284.            jmp @B
  285.  
  286. .next:
  287.            inc [devfn]
  288.            cmp [devfn], 256
  289.            jb  .next_dev
  290.            mov eax, [bus]
  291.            inc eax
  292.            mov [bus], eax
  293.            cmp eax, [last_bus]
  294.            jna .next_bus
  295.            xor eax, eax
  296.            ret
  297. .found:
  298.            xor eax, eax
  299.            inc eax
  300.            ret
  301. .err:
  302.            xor eax, eax
  303.            ret
  304. endp
  305.  
  306. align 4
  307. proc init_ati
  308.  
  309.            stdcall AllocKernelSpace, dword 0x10000
  310.            test eax, eax
  311.            jz .fail
  312.  
  313.            mov [ati_io], eax
  314.  
  315.            stdcall PciRead32, [bus], [devfn], dword 0x18
  316.            and eax, 0xFFFF0000
  317.            mov esi, eax
  318.  
  319.            mov edi, [ati_io]
  320.            mov edx, 16
  321. @@:
  322.            stdcall MapPage,edi,esi,PG_SW+PG_NOCACHE
  323.            add edi, 0x1000
  324.            add esi, 0x1000
  325.            dec edx
  326.            jnz @B
  327.  
  328.            mov edi, [ati_io]
  329.            mov dword [edi+RD_RB3D_CNTL], 0
  330.            call engRestore
  331.  
  332.            mov edi, [ati_io]
  333.            mov eax, [edi+0x50]
  334.            mov ebx,3
  335.            shl ebx,20
  336.            not ebx
  337.            and eax,ebx
  338.            mov ebx, 2
  339.            shl ebx,20
  340.            or eax, ebx
  341.            mov [edi+0x50], eax
  342.  
  343.            call drvShowCursor
  344.            xor eax, eax
  345.            inc eax
  346. .fail:
  347.            ret
  348. endp
  349.  
  350. align 4
  351. drv_restore:
  352.            ret 8
  353.  
  354. align 4
  355. drvShowCursor:
  356.            mov edi, [ati_io]
  357.  
  358.            mov eax, [edi+RD_CRTC_GEN_CNTL]
  359.            bts eax,16
  360.            mov [edi+RD_CRTC_GEN_CNTL], eax
  361.            ret
  362.  
  363. align 4
  364. proc drvCursorPos stdcall, hcursor:dword, x:dword, y:dword
  365.            pushfd
  366.            cli
  367.  
  368.            xor eax, eax
  369.            xor edx, edx
  370.            mov esi, [hcursor]
  371.            mov ebx, [x]
  372.            mov ecx, [y]
  373.  
  374.            sub ebx, [esi+CURSOR.hot_x]
  375.            jnc @F
  376.            neg ebx
  377.            mov eax, ebx
  378.            shl eax, 16
  379.            xor ebx, ebx
  380. @@:
  381.            sub ecx, [esi+CURSOR.hot_y]
  382.            jnc @F
  383.            neg ecx
  384.            mov ax, cx
  385.            mov edx, ecx
  386.            xor ecx, ecx
  387. @@:
  388.            or eax, 0x80000000
  389.            wrr CUR_HORZ_VERT_OFF, eax
  390.  
  391.            shl ebx, 16
  392.            mov bx, cx
  393.            or ebx, 0x80000000
  394.            wrr CUR_HORZ_VERT_POSN, ebx
  395.  
  396.            shl edx, 8
  397.            add edx, [esi+CURSOR.base]
  398.            sub edx, LFBAddress
  399.            wrr CUR_OFFSET, edx
  400.            popfd
  401.            ret
  402. endp
  403.  
  404. align 4
  405. proc video_alloc
  406.  
  407.            pushfd
  408.            cli
  409.            mov ebx, [cursor_start]
  410.            mov ecx, [cursor_end]
  411. .l1:
  412.            bsf eax,[ebx];
  413.            jnz .found
  414.            add ebx,4
  415.            cmp ebx, ecx
  416.            jb .l1
  417.            popfd
  418.            xor eax,eax
  419.            ret
  420. .found:
  421.            btr [ebx], eax
  422.            popfd
  423.  
  424.            mov [cursor_start],ebx
  425.            sub ebx, cursor_map
  426.            lea eax,[eax+ebx*8]
  427.  
  428.            shl eax,14
  429.            add eax, LFBAddress+CURSOR_IMAGE_OFFSET
  430.            ret
  431. endp
  432.  
  433. align 4
  434. video_free:
  435.            pushfd
  436.            cli
  437.            sub eax, LFBAddress+CURSOR_IMAGE_OFFSET
  438.            shr eax, 14
  439.            mov ebx, cursor_map
  440.            bts [ebx], eax
  441.            shr eax, 3
  442.            and eax, not 3
  443.            add eax, ebx
  444.            cmp [cursor_start], eax
  445.            ja @f
  446.            popfd
  447.            ret
  448. @@:
  449.            mov [cursor_start], eax
  450.            popfd
  451.            ret
  452.  
  453. ; param
  454. ;  eax= pid
  455. ;  ebx= src
  456. ;  ecx= flags
  457.  
  458. align 4
  459. ati_cursor:
  460. .src     equ esp
  461. .flags   equ esp+4
  462. .hcursor equ esp+8
  463.  
  464.            sub esp, 4          ;space for .hcursor
  465.            push ecx
  466.            push ebx
  467.  
  468.            mov ebx, eax
  469.            mov eax, CURSOR_SIZE
  470.            call CreateObject
  471.            test eax, eax
  472.            jz .fail
  473.  
  474.            mov [.hcursor],eax
  475.  
  476.            xor ebx, ebx
  477.            mov [eax+CURSOR.magic], 'CURS'
  478.            mov [eax+CURSOR.destroy], destroy_cursor
  479.            mov [eax+CURSOR.hot_x], ebx
  480.            mov [eax+CURSOR.hot_y], ebx
  481.  
  482.            call video_alloc
  483.            mov edi, [.hcursor]
  484.            mov [edi+CURSOR.base], eax
  485.  
  486.            mov esi, [.src]
  487.            mov ebx, [.flags]
  488.            cmp bx, LOAD_INDIRECT
  489.            je .indirect
  490.  
  491.            movzx ecx, word [esi+10]
  492.            movzx edx, word [esi+12]
  493.            mov [edi+CURSOR.hot_x], ecx
  494.            mov [edi+CURSOR.hot_y], edx
  495.  
  496.            stdcall ati_init_cursor, eax, esi
  497.            mov eax, [.hcursor]
  498. .fail:
  499.            add esp, 12
  500.            ret
  501. .indirect:
  502.            shr ebx, 16
  503.            movzx ecx, bh
  504.            movzx edx, bl
  505.            mov [edi+CURSOR.hot_x], ecx
  506.            mov [edi+CURSOR.hot_y], edx
  507.  
  508.            mov edi, eax
  509.            mov ebx, eax
  510.            mov ecx, 64*64
  511.            xor eax,eax
  512.            cld
  513.            rep stosd
  514.            mov edi, ebx
  515.  
  516.            mov esi, [.src]
  517.            mov ebx, 32
  518.            cld
  519. @@:
  520.            mov ecx, 32
  521.            rep movsd
  522.            add edi, 128
  523.            dec ebx
  524.            jnz @B
  525.            mov eax, [.hcursor]
  526.            add esp, 12
  527.            ret
  528.  
  529. align 4
  530. destroy_cursor:
  531.  
  532.            push eax
  533.            mov eax, [eax+CURSOR.base]
  534.            call video_free
  535.            pop eax
  536.  
  537.            call DestroyObject
  538.            ret
  539.  
  540. align 4
  541. proc ati_init_cursor stdcall, dst:dword, src:dword
  542.            locals
  543.              rBase    dd ?
  544.              pQuad    dd ?
  545.              pBits    dd ?
  546.              pAnd     dd ?
  547.              width    dd ?
  548.              height   dd ?
  549.              counter  dd ?
  550.            endl
  551.  
  552.            mov esi, [src]
  553.            add esi,[esi+18]
  554.            mov eax,esi
  555.  
  556.            cmp [esi+BI.biBitCount], 24
  557.            je .img_24
  558.            cmp [esi+BI.biBitCount], 8
  559.            je .img_8
  560.            cmp [esi+BI.biBitCount], 4
  561.            je .img_4
  562.  
  563. .img_2:
  564.            add eax, [esi]
  565.            mov [pQuad],eax
  566.            add eax,8
  567.            mov [pBits],eax
  568.            add eax, 128
  569.            mov [pAnd],eax
  570.            mov eax,[esi+4]
  571.            mov [width],eax
  572.            mov ebx,[esi+8]
  573.            shr ebx,1
  574.            mov [height],ebx
  575.  
  576.            mov edi, pCursor
  577.            add edi, 32*31*4
  578.            mov [rBase],edi
  579.  
  580.            mov esi,[pQuad]
  581. .l21:
  582.            mov ebx, [pBits]
  583.            mov ebx, [ebx]
  584.            bswap ebx
  585.            mov eax, [pAnd]
  586.            mov eax, [eax]
  587.            bswap eax
  588.            mov [counter], 32
  589. @@:
  590.            xor edx, edx
  591.            shl eax,1
  592.            setc dl
  593.            dec edx
  594.  
  595.            xor ecx, ecx
  596.            shl ebx,1
  597.            setc cl
  598.            mov ecx, [esi+ecx*4]
  599.            and ecx, edx
  600.            and edx, 0xFF000000
  601.            or edx, ecx
  602.            mov [edi], edx
  603.  
  604.            add edi, 4
  605.            dec [counter]
  606.            jnz @B
  607.  
  608.            add [pBits], 4
  609.            add [pAnd], 4
  610.            mov edi,[rBase]
  611.            sub edi,128
  612.            mov [rBase],edi
  613.            sub [height],1
  614.            jnz .l21
  615.            jmp .copy
  616. .img_4:
  617.            add eax, [esi]
  618.            mov [pQuad],eax
  619.            add eax,64
  620.            mov [pBits],eax
  621.            add eax, 0x200
  622.            mov [pAnd],eax
  623.            mov eax,[esi+4]
  624.            mov [width],eax
  625.            mov ebx,[esi+8]
  626.            shr ebx,1
  627.            mov [height],ebx
  628.  
  629.            mov edi, pCursor
  630.            add edi, 32*31*4
  631.            mov [rBase],edi
  632.  
  633.            mov esi,[pQuad]
  634.            mov ebx, [pBits]
  635. .l4:
  636.            mov eax, [pAnd]
  637.            mov eax, [eax]
  638.            bswap eax
  639.            mov [counter], 16
  640. @@:
  641.            xor edx, edx
  642.            shl eax,1
  643.            setc dl
  644.            dec edx
  645.  
  646.            movzx ecx, byte [ebx]
  647.            and cl, 0xF0
  648.            shr ecx, 2
  649.            mov ecx, [esi+ecx]
  650.            and ecx, edx
  651.            and edx, 0xFF000000
  652.            or edx, ecx
  653.            mov [edi], edx
  654.  
  655.            xor edx, edx
  656.            shl eax,1
  657.            setc dl
  658.            dec edx
  659.  
  660.            movzx ecx, byte [ebx]
  661.            and cl, 0x0F
  662.            mov ecx, [esi+ecx*4]
  663.            and ecx, edx
  664.            and edx, 0xFF000000
  665.            or edx, ecx
  666.            mov [edi+4], edx
  667.  
  668.            inc ebx
  669.            add edi, 8
  670.            dec [counter]
  671.            jnz @B
  672.  
  673.            add [pAnd], 4
  674.            mov edi,[rBase]
  675.            sub edi,128
  676.            mov [rBase],edi
  677.            sub [height],1
  678.            jnz .l4
  679.            jmp .copy
  680. .img_8:
  681.            add eax, [esi]
  682.            mov [pQuad],eax
  683.            add eax,1024
  684.            mov [pBits],eax
  685.            add eax, 1024
  686.            mov [pAnd],eax
  687.            mov eax,[esi+4]
  688.            mov [width],eax
  689.            mov ebx,[esi+8]
  690.            shr ebx,1
  691.            mov [height],ebx
  692.  
  693.            mov edi, pCursor
  694.            add edi, 32*31*4
  695.            mov [rBase],edi
  696.  
  697.            mov esi,[pQuad]
  698.            mov ebx, [pBits]
  699. .l81:
  700.            mov eax, [pAnd]
  701.            mov eax, [eax]
  702.            bswap eax
  703.            mov [counter], 32
  704. @@:
  705.            xor edx, edx
  706.            shl eax,1
  707.            setc dl
  708.            dec edx
  709.  
  710.            movzx ecx,  byte [ebx]
  711.            mov ecx, [esi+ecx*4]
  712.            and ecx, edx
  713.            and edx, 0xFF000000
  714.            or edx, ecx
  715.            mov [edi], edx
  716.  
  717.            inc ebx
  718.            add edi, 4
  719.            dec [counter]
  720.            jnz @B
  721.  
  722.            add [pAnd], 4
  723.            mov edi,[rBase]
  724.            sub edi,128
  725.            mov [rBase],edi
  726.            sub [height],1
  727.            jnz .l81
  728.            jmp .copy
  729. .img_24:
  730.            add eax, [esi]
  731.            mov [pQuad],eax
  732.            add eax, 0xC00
  733.            mov [pAnd],eax
  734.            mov eax,[esi+BI.biWidth]
  735.            mov [width],eax
  736.            mov ebx,[esi+BI.biHeight]
  737.            shr ebx,1
  738.            mov [height],ebx
  739.  
  740.            mov edi, pCursor
  741.            add edi, 32*31*4
  742.            mov [rBase],edi
  743.  
  744.            mov esi,[pAnd]
  745.            mov ebx, [pQuad]
  746. .row_24:
  747.            mov eax, [esi]
  748.            bswap eax
  749.            mov [counter], 32
  750. @@:
  751.            xor edx, edx
  752.            shl eax,1
  753.            setc dl
  754.            dec edx
  755.  
  756.            mov ecx, [ebx]
  757.            and ecx, 0x00FFFFFF
  758.            and ecx, edx
  759.            and edx, 0xFF000000
  760.            or edx, ecx
  761.            mov [edi], edx
  762.            add ebx, 3
  763.            add edi, 4
  764.            dec [counter]
  765.            jnz @B
  766.  
  767.            add esi, 4
  768.            mov edi,[rBase]
  769.            sub edi,128
  770.            mov [rBase],edi
  771.            sub [height],1
  772.            jnz .row_24
  773. .copy:
  774.            mov edi, [dst]
  775.            mov ecx, 64*64
  776.            xor eax,eax
  777.            rep stosd
  778.  
  779.            mov esi, pCursor
  780.            mov edi, [dst]
  781.            mov ebx, 32
  782.            cld
  783. @@:
  784.            mov ecx, 32
  785.            rep movsd
  786.            add edi, 128
  787.            dec ebx
  788.            jnz @B
  789.            ret
  790. endp
  791.  
  792. align 4
  793. proc engFlush
  794.  
  795.            mov edi, [ati_io]
  796.  
  797.            mov eax, [edi+RD_RB2D_DSTCACHE_CTLSTAT]
  798.            or eax,RD_RB2D_DC_FLUSH_ALL
  799.            mov [edi+RD_RB2D_DSTCACHE_CTLSTAT],eax
  800.  
  801.            mov ecx, RD_TIMEOUT
  802. @@:
  803.            mov eax,[edi+RD_RB2D_DSTCACHE_CTLSTAT]
  804.            and eax, RD_RB2D_DC_BUSY
  805.            jz .exit
  806.  
  807.            sub ecx,1
  808.            jnz @B
  809. .exit:
  810.            ret
  811. endp
  812.  
  813. align 4
  814. engWaitForFifo:
  815. cnt equ bp+8
  816.            push ebp
  817.            mov ebp, esp
  818.  
  819.            mov edi, [ati_io]
  820.  
  821.            mov ecx, RD_TIMEOUT
  822. @@:
  823.            mov eax, [edi+RD_RBBM_STATUS]
  824.            and eax, RD_RBBM_FIFOCNT_MASK
  825.            cmp eax, [ebp+8]
  826.            jae .exit
  827.  
  828.            sub ecx,1
  829.            jmp @B
  830.  
  831. .exit:
  832.            leave
  833.            ret 4
  834.  
  835. align 4
  836. proc engWaitForIdle
  837.  
  838.            push dword 64
  839.            call engWaitForFifo
  840.  
  841.            mov edi, [ati_io]
  842.            mov ecx ,RD_TIMEOUT
  843. @@:
  844.            mov eax, [edi+RD_RBBM_STATUS]
  845.            and eax,RD_RBBM_ACTIVE
  846.            jz .exit
  847.  
  848.            sub ecx,1
  849.            jnz @B
  850. .exit:
  851.            call engFlush
  852.            ret
  853. endp
  854.  
  855. align 4
  856. proc engRestore
  857.  
  858. ;             push dword 1
  859. ;             call engWaitForFifo
  860.  
  861. ;             mov dword  [MMIO+RD_RB2D_DSTCACHE_MODE], 0
  862.  
  863.            push dword 3
  864.            call engWaitForFifo
  865.  
  866.            mov edi, [ati_io]
  867.  
  868.            mov eax, [edi+RD_DISPLAY_BASE_ADDR]
  869.            shr eax, 10d
  870.            or eax,(64d shl 22d)
  871.            mov [edi+RD_DEFAULT_OFFSET],eax
  872.            mov [edi+RD_SRC_PITCH_OFFSET],eax
  873.            mov [edi+RD_DST_PITCH_OFFSET],eax
  874.  
  875.            push dword 1
  876.            call engWaitForFifo
  877.  
  878.            mov edi, [ati_io]
  879.            mov eax, [edi+RD_DP_DATATYPE]
  880.            btr eax, 29d
  881.            mov [edi+RD_DP_DATATYPE],eax
  882.  
  883.            push dword 1
  884.            call engWaitForFifo
  885.  
  886.            mov edi, [ati_io]
  887.            mov dword [edi+RD_DEFAULT_SC_BOTTOM_RIGHT],\
  888.                      (RD_DEFAULT_SC_RIGHT_MAX or RD_DEFAULT_SC_BOTTOM_MAX)
  889.  
  890.            push dword 1
  891.            call engWaitForFifo
  892.  
  893.            mov edi, [ati_io]
  894.            mov dword [edi+RD_DP_GUI_MASTER_CNTL],\
  895.                      (RD_GMC_BRUSH_SOLID_COLOR or \
  896.                       RD_GMC_SRC_DATATYPE_COLOR or \
  897.                      (6 shl RD_GMC_DST_DATATYPE_SHIFT) or \
  898.                       RD_GMC_CLR_CMP_CNTL_DIS or \
  899.                       RD_ROP3_P or \
  900.                       RD_GMC_WR_MSK_DIS)
  901.  
  902.  
  903.            push dword 7
  904.            call engWaitForFifo
  905.  
  906.            mov edi, [ati_io]
  907.  
  908.            mov dword [edi+RD_DST_LINE_START],0
  909.            mov dword [edi+RD_DST_LINE_END], 0
  910.            mov dword [edi+RD_DP_BRUSH_FRGD_CLR], 808000ffh
  911.            mov dword [edi+RD_DP_BRUSH_BKGD_CLR], 002020ffh
  912.            mov dword [edi+RD_DP_SRC_FRGD_CLR],   808000ffh
  913.            mov dword [edi+RD_DP_SRC_BKGD_CLR],   004000ffh
  914.            mov dword [edi+RD_DP_WRITE_MASK],0ffffffffh
  915.  
  916.            call engWaitForIdle
  917.  
  918.            ret
  919. endp
  920.  
  921. align 4
  922. engSetupSolidFill:
  923.            push ebp
  924.            mov ebp, esp
  925.  
  926.            push dword 3
  927.            call engWaitForFifo
  928.  
  929.            wrr RD_DP_GUI_MASTER_CNTL, cmdSolidFill
  930.  
  931.            mov eax, [ebp+8]
  932.            wrr RD_DP_BRUSH_FRGD_CLR,eax
  933.  
  934.            mov edi, [ati_io]
  935.            mov dword [edi+RD_DP_CNTL],(RD_DST_X_LEFT_TO_RIGHT or RD_DST_Y_TOP_TO_BOTTOM)
  936.            leave
  937.            ret 4
  938.  
  939.  
  940. align 4
  941. drvSolidFill:
  942. ;x:word,y:word,w:word,h:word,color:dword
  943.             push ebp
  944.             mov ebp, esp
  945. x equ ebp+8
  946. y equ ebp+12
  947. w equ ebp+16
  948. h equ ebp+20
  949. color equ ebp+24
  950.  
  951.            push dword [ebp+24]
  952.            call engSetupSolidFill
  953.  
  954.            push dword 2
  955.            call engWaitForFifo
  956.  
  957.            mov edi, [ati_io]
  958.  
  959.            mov eax, [y]
  960.            mov ebx, [x]
  961.            shl eax,16
  962.            or eax, ebx
  963.  
  964.            mov ecx,  [w]
  965.            mov edx,  [h]
  966.            shl ecx,16
  967.            or ecx, edx
  968.            mov [edi+RD_DST_Y_X], eax
  969.            mov [edi+RD_DST_WIDTH_HEIGHT], ecx
  970.            call engFlush
  971.            leave
  972.            ret 20
  973.  
  974. align 4
  975. devices dd (R8500   shl 16)+VID_ATI
  976.         dd (R9000   shl 16)+VID_ATI
  977.         dd (R9200   shl 16)+VID_ATI
  978.         dd (R9500   shl 16)+VID_ATI
  979.         dd (R9500P  shl 16)+VID_ATI
  980.         dd (R9550   shl 16)+VID_ATI
  981.         dd (R9600   shl 16)+VID_ATI
  982.         dd (R9600XT shl 16)+VID_ATI
  983.         dd (R9700P  shl 16)+VID_ATI
  984.         dd (R9800   shl 16)+VID_ATI
  985.         dd (R9800P  shl 16)+VID_ATI
  986.         dd (R9800XT shl 16)+VID_ATI
  987.         dd 0    ;terminator
  988.  
  989. version dd 0x00040004
  990.  
  991. sz_ati_srv   db 'HWCURSOR',0
  992.  
  993. msgInit      db 'detect hardware...',13,10,0
  994. msgPCI       db 'PCI accsess not supported',13,10,0
  995. msgFail      db 'device not found',13,10,0
  996. msg_neg      db 'neg ecx',13,10,0
  997. buff         db 8 dup(0)
  998.              db 13,10, 0
  999.  
  1000. section '.data' data readable writable align 16
  1001.  
  1002. pCursor  db 4096 dup(?)
  1003.  
  1004. cursor_map     rd 2
  1005. cursor_start   rd 1
  1006. cursor_end     rd 1
  1007.  
  1008. bus            dd ?
  1009. devfn          dd ?
  1010. ati_io         dd ?
  1011.  
  1012.  
  1013.  
  1014.