Subversion Repositories Kolibri OS

Rev

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