Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ;alpha version
  3.  
  4. format MS COFF
  5.  
  6.  
  7. include 'proc32.inc'
  8.  
  9. DEBUG     equ 0
  10.  
  11. VID_ATI     equ 0x1002
  12.  
  13. R8500       equ 0x514C  ;R200
  14. R9000       equ 0x4966  ;RV250
  15. R9200       equ 0x5961  ;RV280
  16. R9500       equ 0x4144  ;R300
  17. R9500P      equ 0x4E45  ;R300
  18. R9550       equ 0x4153  ;RV350
  19. R9600       equ 0x4150  ;RV350
  20. R9600XT     equ 0x4152  ;RV360
  21. R9700P      equ 0x4E44  ;R300
  22. R9800       equ 0x4E49  ;R350
  23. R9800P      equ 0x4E48  ;R350
  24. R9800XT     equ 0x4E4A  ;R360
  25.  
  26. OS_BASE         equ 0;  0x80400000
  27. new_app_base    equ 0x60400000;   0x01000000
  28. PROC_BASE       equ OS_BASE+0x0080000
  29.  
  30. PG_SW        equ 0x003
  31. PG_NOCACHE   equ 0x018
  32.  
  33. struc IOCTL
  34. {  .handle           dd ?
  35.    .io_code          dd ?
  36.    .input            dd ?
  37.    .inp_size         dd ?
  38.    .output           dd ?
  39.    .out_size         dd ?
  40. }
  41.  
  42. virtual at 0
  43.   IOCTL IOCTL
  44. end virtual
  45.  
  46. ;MMIO                  equ 0F9000000h
  47. RD_RB3D_CNTL          equ 1c3ch
  48.  
  49. RD_MEM_CNTL                equ 0140h
  50. RD_CRTC_GEN_CNTL           equ 0050h
  51. RD_CRTC_CUR_EN             equ 10000h
  52. RD_DISPLAY_BASE_ADDR       equ 023ch
  53. RD_DEFAULT_OFFSET          equ 16e0h
  54. CUR_HORZ_VERT_OFF          equ 0268h
  55. CUR_HORZ_VERT_POSN         equ 0264h
  56. CUR_OFFSET                 equ 0260h
  57. RD_RB3D_CNTL               equ 1c3ch
  58. RD_RBBM_STATUS             equ 0e40h
  59. RD_RBBM_FIFOCNT_MASK       equ 007fh
  60. RD_RBBM_ACTIVE             equ 80000000h
  61. RD_TIMEOUT                 equ 2000000
  62.  
  63. RD_DP_GUI_MASTER_CNTL      equ 0146ch
  64. RD_DP_BRUSH_BKGD_CLR       equ 01478h
  65. RD_DP_BRUSH_FRGD_CLR       equ 0147ch
  66. RD_DP_SRC_BKGD_CLR         equ 015dch
  67. RD_DP_SRC_FRGD_CLR         equ 015d8h
  68. RD_DP_CNTL                 equ 016c0h
  69. RD_DP_DATATYPE             equ 016c4h
  70. RD_DP_WRITE_MASK           equ 016cch
  71. RD_DP_SRC_SOURCE_MEMORY    equ (2 shl 24)
  72. RD_DP_SRC_SOURCE_HOST_DATA equ (3 shl 24)
  73. RD_DEFAULT_SC_BOTTOM_RIGHT equ 16e8h
  74. RD_GMC_BRUSH_SOLID_COLOR   equ (13 shl 4)
  75. RD_DEFAULT_SC_RIGHT_MAX    equ 1fffh
  76. RD_DEFAULT_SC_BOTTOM_MAX   equ 1fff0000h
  77. RD_GMC_DST_DATATYPE_SHIFT  equ 8
  78.  
  79. RD_ROP3_S                  equ 00cc0000h
  80. RD_ROP3_P                  equ 00f00000h
  81.  
  82. RD_RB2D_DSTCACHE_MODE      equ 03428h
  83. RD_RB2D_DSTCACHE_CTLSTAT   equ 0342ch
  84. RD_RB2D_DC_FLUSH_ALL       equ 000fh
  85. RD_RB2D_DC_BUSY            equ 80000000h
  86.  
  87. RD_GMC_BRUSH_SOLID_COLOR   equ 000000D0h
  88. RD_GMC_SRC_DATATYPE_COLOR  equ (3 shl 12)
  89. RD_GMC_CLR_CMP_CNTL_DIS    equ (1 shl 28)
  90. RD_GMC_WR_MSK_DIS          equ (1 shl 30)
  91.  
  92. cmdSolidFill               equ 73f036d0h
  93.  
  94. RD_DST_PITCH_OFFSET        equ 142ch
  95. RD_SRC_PITCH_OFFSET        equ 1428h
  96.  
  97. RD_DST_X_LEFT_TO_RIGHT     equ 1
  98. RD_DST_Y_TOP_TO_BOTTOM     equ 2
  99. RD_DST_Y_X                 equ 1438h
  100. RD_DST_WIDTH_HEIGHT        equ 1598h
  101. RD_DST_LINE_START          equ 1600h
  102. RD_DST_LINE_END            equ 1604h
  103. R300_MEM_NUM_CHANNELS_MASK equ 0003h
  104.  
  105. macro rdr op1, op2
  106. {
  107.      mov edi, [ati_io]
  108.      mov op1, [edi+op2]
  109. }
  110.  
  111. macro wrr dest, src
  112. {
  113.      mov edi, [ati_io]
  114.      mov dword [edi+dest], src
  115. }
  116.  
  117.  
  118. public START
  119. public service_proc
  120.  
  121. extrn SysMsgBoardStr
  122. extrn PciApi
  123. extrn PciRead32
  124. extrn AllocKernelSpace
  125. extrn MapPage
  126. extrn RegService
  127. extrn SetHwCursor
  128. extrn LFBAddress
  129. extrn LoadFile
  130.  
  131. CURSOR_IMAGE_OFFSET  equ 0x00500000
  132.  
  133. DRV_ENTRY equ 1
  134. DRV_EXIT  equ -1
  135.  
  136. section '.flat' code readable align 16
  137.  
  138. proc START stdcall, state:dword
  139.  
  140.            mov eax, [state]
  141.            cmp eax, 1
  142.            je .entry
  143.            jmp .exit
  144. .entry:
  145.      if DEBUG
  146.            mov esi, msgInit
  147.            call SysMsgBoardStr
  148.      end if
  149.  
  150.            call detect_ati
  151.            test eax, eax
  152.            jz .fail
  153.  
  154.            stdcall LoadFile, user_file
  155.            test eax, eax
  156.            jz @F
  157.            mov [user_arrow], eax
  158. @@:
  159.            stdcall ati_init_cursor, [user_arrow]
  160.  
  161.            call init_ati
  162.            test eax, eax
  163.            jz .fail
  164.  
  165.            stdcall RegService, sz_ati_srv, service_proc
  166.            test eax, eax
  167.            jz .fail
  168.            mov ebx, SetHwCursor
  169.            mov dword [ebx], drvCursorPos ;enable hardware cursor
  170.            ret
  171. .fail:
  172.      if DEBUG
  173.            mov esi, msgFail
  174.            call SysMsgBoardStr
  175.      end if
  176.  
  177. .exit:
  178.            xor eax, eax
  179.            mov ebx, SetHwCursor
  180.            mov dword [ebx], eax    ;force disable hardware cursor
  181.            ret
  182. endp
  183.  
  184. handle     equ  IOCTL.handle
  185. io_code    equ  IOCTL.io_code
  186. input      equ  IOCTL.input
  187. inp_size   equ  IOCTL.inp_size
  188. output     equ  IOCTL.output
  189. out_size   equ  IOCTL.out_size
  190.  
  191. align 4
  192. proc service_proc stdcall, ioctl:dword
  193.  
  194. ;           mov edi, [ioctl]
  195. ;           mov eax, [edi+io_code]
  196.  
  197.            xor eax, eax
  198.            ret
  199. endp
  200.  
  201. restore   handle
  202. restore   io_code
  203. restore   input
  204. restore   inp_size
  205. restore   output
  206. restore   out_size
  207.  
  208. align 4
  209. proc detect_ati
  210.            locals
  211.              last_bus dd ?
  212.            endl
  213.  
  214.            xor eax, eax
  215.            mov [bus], eax
  216.            inc eax
  217.            call PciApi
  218.            cmp eax, -1
  219.            je .err
  220.  
  221.            mov [last_bus], eax
  222.  
  223. .next_bus:
  224.            and [devfn], 0
  225. .next_dev:
  226.            stdcall PciRead32, [bus], [devfn], dword 0
  227.            test eax, eax
  228.            jz .next
  229.            cmp eax, -1
  230.            je .next
  231.  
  232.            mov edi, devices
  233. @@:
  234.            mov ebx, [edi]
  235.            test ebx, ebx
  236.            jz .next
  237.  
  238.            cmp eax, ebx
  239.            je .found
  240.            add edi, 4
  241.            jmp @B
  242.  
  243. .next:     inc [devfn]
  244.            cmp [devfn], 256
  245.            jb  .next_dev
  246.            mov eax, [bus]
  247.            inc eax
  248.            mov [bus], eax
  249.            cmp eax, [last_bus]
  250.            jna .next_bus
  251.            xor eax, eax
  252.            ret
  253. .found:
  254.            xor eax, eax
  255.            inc eax
  256.            ret
  257. .err:
  258.            xor eax, eax
  259.            ret
  260. endp
  261.  
  262. align 4
  263. proc init_ati
  264.  
  265.            stdcall AllocKernelSpace, dword 0x10000
  266.            test eax, eax
  267.            jz .fail
  268.  
  269.            mov [ati_io], eax
  270.  
  271.            stdcall PciRead32, [bus], [devfn], dword 0x18
  272.            and eax, 0xFFFF0000
  273.            mov esi, eax
  274.  
  275.            mov edi, [ati_io]
  276.            mov edx, 16
  277. @@:
  278.            stdcall MapPage,edi,esi,PG_SW+PG_NOCACHE
  279.            add edi, 0x1000
  280.            add esi, 0x1000
  281.            dec edx
  282.            jnz @B
  283.  
  284.            mov edi, [ati_io]
  285.            mov dword [edi+RD_RB3D_CNTL], 0
  286.            call engRestore
  287.  
  288.            mov edi, [ati_io]
  289.            mov eax, [edi+0x50]
  290.            mov ebx,3
  291.            shl ebx,20
  292.            not ebx
  293.            and eax,ebx
  294.            mov ebx, 2
  295.            shl ebx,20
  296.            or eax, ebx
  297.            mov [edi+0x50], eax
  298.  
  299.            pushd 0
  300.            pushd 0
  301.            call drvCursorPos
  302.            call drvShowCursor
  303.            xor eax, eax
  304.            inc eax
  305. .fail:
  306.            ret
  307. endp
  308.  
  309. align 4
  310. drvShowCursor:
  311.            mov edi, [ati_io]
  312.  
  313.            mov eax, [edi+RD_CRTC_GEN_CNTL]
  314.            bts eax,16
  315.            mov [edi+RD_CRTC_GEN_CNTL], eax
  316.            ret
  317.  
  318. align 4
  319. drvCursorPos:
  320.            push ebp
  321.            mov ebp, esp
  322.            mov eax, 80000000h
  323.            wrr CUR_HORZ_VERT_OFF, eax
  324.  
  325.            mov eax, [ebp+8]
  326.            shl eax, 16
  327.            or eax, [ebp+12]
  328.            or eax, 80000000h
  329.            wrr CUR_HORZ_VERT_POSN, eax
  330.  
  331.            mov eax, CURSOR_IMAGE_OFFSET
  332.            wrr CUR_OFFSET, eax
  333.            leave
  334.            ret 8
  335.  
  336. align 4
  337. proc ati_init_cursor stdcall, arrow:dword
  338.            locals
  339.              rBase    dd ?
  340.              pQuad    dd ?
  341.              pBits    dd ?
  342.              pAnd     dd ?
  343.              width    dd ?
  344.              height   dd ?
  345.              counter  dd ?
  346.            endl
  347.  
  348.            cld
  349.  
  350.            mov esi, [arrow]
  351.            add esi,[esi+18d]
  352.  
  353.            mov eax,esi
  354.            add eax, [esi]
  355.            mov [pQuad],eax
  356.            add eax,64
  357.            mov [pBits],eax
  358.            add eax, 0x200
  359.            mov [pAnd],eax
  360.            mov eax,[esi+4]
  361.            mov [width],eax
  362.            mov ebx,[esi+8]
  363.            shr ebx,1
  364.            mov [height],ebx
  365.  
  366.            mov edi, pCursor
  367.            add edi, 32*31*4
  368.            mov [rBase],edi
  369.  
  370.            mov esi,[pAnd]
  371.            mov ebx, [pBits]
  372. .l1:
  373.            mov eax, [esi]
  374.            bswap eax
  375.            mov [counter], 16
  376. @@:
  377.            xor edx, edx
  378.            shl eax,1
  379.            setc dl
  380.            dec edx
  381.  
  382.            mov ecx, [ebx]
  383.            and ecx, 0xF0
  384.            shr ecx, 2
  385.            add ecx, [pQuad]
  386.            mov ecx, [ecx]
  387.            and ecx, edx
  388.            and edx, 0xFF000000
  389.            or edx, ecx
  390.            mov [edi], edx
  391.  
  392.            xor edx, edx
  393.            shl eax,1
  394.            setc dl
  395.            dec edx
  396.  
  397.            mov ecx, [ebx]
  398.            and ecx, 0x0F
  399.            shl ecx, 2
  400.            add ecx, [pQuad]
  401.            mov ecx, [ecx]
  402.            and ecx, edx
  403.            and edx, 0xFF000000
  404.            or edx, ecx
  405.            mov [edi+4], edx
  406.  
  407.            inc ebx
  408.            add edi, 8
  409.            dec [counter]
  410.            jnz @B
  411.  
  412.            add esi, 4
  413.            mov edi,[rBase]
  414.            sub edi,128
  415.            mov [rBase],edi
  416.            sub [height],1
  417.            jnz .l1
  418.  
  419.            mov edi, LFBAddress
  420.            add edi, CURSOR_IMAGE_OFFSET
  421.            mov ecx, 64*64
  422.            xor eax,eax
  423.            rep stosd
  424.  
  425.            mov esi, pCursor
  426.            mov edi, LFBAddress
  427.            add edi, CURSOR_IMAGE_OFFSET
  428.            mov ebx, 32
  429. lc:
  430.            mov ecx, 32
  431. lb:
  432.            mov eax, [esi]
  433.            mov [edi], eax
  434.            add esi, 4
  435.            add edi, 4
  436.            sub ecx, 1
  437.            jnz lb
  438.  
  439.            add edi, 128
  440.            sub ebx, 1
  441.            jnz lc
  442.  
  443.            ret
  444. endp
  445.  
  446. align 4
  447. proc engFlush
  448.  
  449.            mov edi, [ati_io]
  450.  
  451.            mov eax, [edi+RD_RB2D_DSTCACHE_CTLSTAT]
  452.            or eax,RD_RB2D_DC_FLUSH_ALL
  453.            mov [edi+RD_RB2D_DSTCACHE_CTLSTAT],eax
  454.  
  455.            mov ecx, RD_TIMEOUT
  456. @@:
  457.            mov eax,[edi+RD_RB2D_DSTCACHE_CTLSTAT]
  458.            and eax, RD_RB2D_DC_BUSY
  459.            jz .exit
  460.  
  461.            sub ecx,1
  462.            jnz @B
  463. .exit:
  464.            ret
  465. endp
  466.  
  467. align 4
  468. engWaitForFifo:
  469. cnt equ bp+8
  470.            push ebp
  471.            mov ebp, esp
  472.  
  473.            mov edi, [ati_io]
  474.  
  475.            mov ecx, RD_TIMEOUT
  476. @@:
  477.            mov eax, [edi+RD_RBBM_STATUS]
  478.            and eax, RD_RBBM_FIFOCNT_MASK
  479.            cmp eax, [ebp+8]
  480.            jae .exit
  481.  
  482.            sub ecx,1
  483.            jmp @B
  484.  
  485. .exit:
  486.            leave
  487.            ret 4
  488.  
  489. align 4
  490. proc engWaitForIdle
  491.  
  492.                push dword 64
  493.                call engWaitForFifo
  494.  
  495.                mov edi, [ati_io]
  496.                mov ecx ,RD_TIMEOUT
  497. @@:
  498.                mov eax, [edi+RD_RBBM_STATUS]
  499.                and eax,RD_RBBM_ACTIVE
  500.                jz .exit
  501.  
  502.                sub ecx,1
  503.                jnz @B
  504. .exit:
  505.                call engFlush
  506.                ret
  507. endp
  508.  
  509. align 4
  510. proc engRestore
  511.  
  512. ;             push dword 1
  513. ;             call engWaitForFifo
  514.  
  515. ;             mov dword  [MMIO+RD_RB2D_DSTCACHE_MODE], 0
  516.  
  517.              push dword 3
  518.              call engWaitForFifo
  519.  
  520.            mov edi, [ati_io]
  521.  
  522.            mov eax, [edi+RD_DISPLAY_BASE_ADDR]
  523.            shr eax, 10d
  524.            or eax,(64d shl 22d)
  525.            mov [edi+RD_DEFAULT_OFFSET],eax
  526.            mov [edi+RD_SRC_PITCH_OFFSET],eax
  527.            mov [edi+RD_DST_PITCH_OFFSET],eax
  528.  
  529.            push dword 1
  530.            call engWaitForFifo
  531.  
  532.            mov edi, [ati_io]
  533.            mov eax, [edi+RD_DP_DATATYPE]
  534.            btr eax, 29d
  535.            mov [edi+RD_DP_DATATYPE],eax
  536.  
  537.            push dword 1
  538.            call engWaitForFifo
  539.  
  540.            mov edi, [ati_io]
  541.            mov dword [edi+RD_DEFAULT_SC_BOTTOM_RIGHT],\
  542.                      (RD_DEFAULT_SC_RIGHT_MAX or RD_DEFAULT_SC_BOTTOM_MAX)
  543.  
  544.            push dword 1
  545.            call engWaitForFifo
  546.  
  547.            mov edi, [ati_io]
  548.            mov dword [edi+RD_DP_GUI_MASTER_CNTL],\
  549.                      (RD_GMC_BRUSH_SOLID_COLOR or \
  550.                       RD_GMC_SRC_DATATYPE_COLOR or \
  551.                      (6 shl RD_GMC_DST_DATATYPE_SHIFT) or \
  552.                       RD_GMC_CLR_CMP_CNTL_DIS or \
  553.                       RD_ROP3_P or \
  554.                       RD_GMC_WR_MSK_DIS)
  555.  
  556.  
  557.            push dword 7
  558.            call engWaitForFifo
  559.  
  560.            mov edi, [ati_io]
  561.  
  562.            mov dword [edi+RD_DST_LINE_START],0
  563.            mov dword [edi+RD_DST_LINE_END], 0
  564.            mov dword [edi+RD_DP_BRUSH_FRGD_CLR], 808000ffh
  565.            mov dword [edi+RD_DP_BRUSH_BKGD_CLR], 002020ffh
  566.            mov dword [edi+RD_DP_SRC_FRGD_CLR],   808000ffh
  567.            mov dword [edi+RD_DP_SRC_BKGD_CLR],   004000ffh
  568.            mov dword [edi+RD_DP_WRITE_MASK],0ffffffffh
  569.  
  570.            call engWaitForIdle
  571.  
  572.            ret
  573. endp
  574.  
  575.  
  576. align 4
  577. engSetupSolidFill:
  578.            push ebp
  579.            mov ebp, esp
  580.  
  581.            push dword 3
  582.            call engWaitForFifo
  583.  
  584.            wrr RD_DP_GUI_MASTER_CNTL, cmdSolidFill
  585.  
  586.            mov eax, [ebp+8]
  587.            wrr RD_DP_BRUSH_FRGD_CLR,eax
  588.  
  589.            mov edi, [ati_io]
  590.            mov dword [edi+RD_DP_CNTL],(RD_DST_X_LEFT_TO_RIGHT or RD_DST_Y_TOP_TO_BOTTOM)
  591.            leave
  592.            ret 4
  593.  
  594.  
  595. align 4
  596. drvSolidFill:
  597. ;x:word,y:word,w:word,h:word,color:dword
  598.             push ebp
  599.             mov ebp, esp
  600. x equ ebp+8
  601. y equ ebp+12
  602. w equ ebp+16
  603. h equ ebp+20
  604. color equ ebp+24
  605.  
  606.             push dword [ebp+24]
  607.             call engSetupSolidFill
  608.  
  609.             push dword 2
  610.             call engWaitForFifo
  611.  
  612.             mov edi, [ati_io]
  613.  
  614.             mov eax, [y]
  615.             mov ebx, [x]
  616.             shl eax,16
  617.             or eax, ebx
  618.  
  619.             mov ecx,  [w]
  620.             mov edx,  [h]
  621.             shl ecx,16
  622.             or ecx, edx
  623.             mov [edi+RD_DST_Y_X], eax
  624.             mov [edi+RD_DST_WIDTH_HEIGHT], ecx
  625.             call engFlush
  626.             leave
  627.             ret 20
  628.  
  629. align 4
  630. devices dd (R8500   shl 16)+VID_ATI
  631.         dd (R9000   shl 16)+VID_ATI
  632.         dd (R9200   shl 16)+VID_ATI
  633.         dd (R9500   shl 16)+VID_ATI
  634.         dd (R9500P  shl 16)+VID_ATI
  635.         dd (R9550   shl 16)+VID_ATI
  636.         dd (R9600   shl 16)+VID_ATI
  637.         dd (R9600XT shl 16)+VID_ATI
  638.         dd (R9700P  shl 16)+VID_ATI
  639.         dd (R9800   shl 16)+VID_ATI
  640.         dd (R9800P  shl 16)+VID_ATI
  641.         dd (R9800XT shl 16)+VID_ATI
  642.         dd 0    ;terminator
  643.  
  644. ;szKernel     db 'KERNEL', 0
  645. sz_ati_srv   db 'ATI2D',0
  646. user_file    db '/rd/1/user.cur',0
  647.  
  648.  
  649. msgInit      db 'detect hardware...',13,10,0
  650. msgPCI       db 'PCI accsess not supported',13,10,0
  651. msgFail      db 'device not found',13,10,0
  652.  
  653. user_arrow   dd pArrow
  654.  
  655. align 16
  656. pArrow:
  657.   file 'arrow.cur'
  658.  
  659. section '.data' data readable writable align 16
  660.  
  661. pCursor  db 4096 dup(?)
  662.  
  663. bus        dd ?
  664. devfn      dd ?
  665. ati_io     dd ?
  666.  
  667.  
  668.  
  669.