Subversion Repositories Kolibri OS

Rev

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. DRIVER_CODE_START:
  17.  
  18. ;-----------------------------------------------------------------------------
  19.  
  20. include 'normal.inc'
  21. include 'clipping.asm'
  22.  
  23. ;-----------------------------------------------------------------------------
  24.  
  25. struct graph_funcs
  26.  draw_line        dd ?
  27.  disable_mouse    dd ?
  28.  draw_pointer     dd ?
  29.  draw_mouse_under dd ?
  30.  drawbar          dd ?
  31.  putpixel         dd ?
  32.  getpixel         dd ?
  33.  sys_putimage     dd ?
  34.  drawbackground   dd ?
  35.  calculatescreen  dd ?
  36.  setscreen        dd ?
  37. ends
  38.  
  39. SF graph_funcs
  40.  
  41. call_cnt dd 0
  42. viewport RECT
  43.  
  44. set_bank dd set_bank1
  45. setbnk   dd set_bank0,set_bank1,set_s3_bank,set_bank3
  46.  
  47. virtual at esi
  48.   rr RECT
  49. end virtual
  50.  
  51. virtual at 0x00010008
  52.   GF graph_funcs
  53. end virtual
  54.  
  55. ;-----------------------------------------------------------------------------
  56.  
  57. CLIP_RECTS = 0x00720000 ; 0x00780000
  58. bg_address = 0x300000
  59.  
  60. ;label bg_bytes_per_scanline dword at 0x600000-16;0x460000-16
  61. ;label bg_type   dword at 0x600000-12;0x460000-12
  62. ;label bg_width  dword at 0x600000-8;0x460000-8
  63. ;label bg_height dword at 0x600000-4;0x460000-4
  64.  
  65. label bg_bytes_per_scanline dword at 0x460000-16
  66. label bg_type   dword at 0x460000-12
  67. label bg_width  dword at 0x460000-8
  68. label bg_height dword at 0x460000-4
  69.  
  70. label lfb_address dword at 0x0000FE80
  71. label mouse_invisible dword at 0x0000F204
  72.  
  73. label screen_width dword at 0x0000FE00
  74. label screen_height dword at 0x0000FE04
  75. label bytes_per_scanline dword at 0x0000FE08
  76.  
  77. BGT_TILE    = 1
  78. BGT_STRETCH = 2
  79.  
  80. ;-----------------------------------------------------------------------------
  81.  
  82. CRTC_INDX       equ     3D4h
  83.  
  84. func vm_mike_init
  85. begin
  86. ;       jif     dword[mdrvm],e,0,.exit
  87.         mov     eax,[0x00010004]
  88.         jif     eax,e,'ENUE',.exit
  89.         jif     [call_cnt],a,0,.exit.2
  90.         add     eax, 0x00010000
  91.         mov     [systlb],eax
  92.  
  93. ;       SHFLOW  'System funcs table offset: 0x%x',eax
  94.  
  95. ;--------------------------------------
  96.  
  97.         mov     esi,0x00010008
  98.         mov     edi,SF
  99.         mov     ecx,sizeof.graph_funcs/4
  100.         cld
  101.         rep     movsd
  102.  
  103. ;       push    dword[0x00003000]
  104. ;       mov     dword[0x00003000],1
  105. ;       call    [SF.disable_mouse]
  106. ;       pop     dword[0x00003000]
  107.  
  108.         mov     [viewport.left],0
  109.         mov     [viewport.top],0
  110.         m2m     [viewport.right],[0x0000FE00]
  111.         m2m     [viewport.bottom],[0x0000FE04]
  112.  
  113.         movzx   eax,byte[0xE035]
  114.         cmp     byte[0xE034],'2'
  115.         jb      @f
  116.         mov     al,0
  117.     @@: mov     eax,[setbnk+eax*4]
  118.         mov     [set_bank],eax
  119.  
  120.         mov     al,[0xFBF1]
  121.         cmp     al,32
  122.         jne     @f
  123.  
  124. ;       SHFLOW  'Driver initialized in 32-bit mode'
  125.  
  126.         mov     [GF.draw_line],vm_mike_draw_line.32
  127. ;;      mov     [GF.disable_mouse],vm_mike_disable_mouse.32
  128. ;;      mov     [GF.draw_pointer],vm_mike_draw_pointer.32
  129.         mov     [GF.drawbar],vm_mike_draw_rect.32
  130.         mov     [GF.putpixel],vm_mike_put_pixel.32
  131.         mov     [GF.getpixel],vm_mike_get_pixel.32
  132.         mov     [GF.sys_putimage],vm_mike_put_image.32
  133.         mov     [GF.drawbackground],vm_mike_draw_bg.32
  134.  
  135.         jmp     .exit.2
  136.  
  137.     @@: cmp     al,24
  138.         jne     @f
  139.  
  140. ;       SHFLOW  'Driver initialized in 24-bit mode'
  141.  
  142.         mov     [GF.draw_line],vm_mike_draw_line.24
  143. ;       mov     [GF.disable_mouse],vm_mike_disable_mouse.24
  144. ;       mov     [GF.draw_pointer],vm_mike_draw_pointer.24
  145.         mov     [GF.drawbar],vm_mike_draw_rect.24
  146.         mov     [GF.putpixel],vm_mike_put_pixel.24
  147.         mov     [GF.getpixel],vm_mike_get_pixel.24
  148.         mov     [GF.sys_putimage],vm_mike_put_image.24
  149.         mov     [GF.drawbackground],vm_mike_draw_bg.24
  150.  
  151.         jmp     .exit.2
  152.  
  153.     @@: cmp     al,16
  154.         jne     @f
  155.  
  156. ;       SHFLOW  'Driver initialized in 16-bit mode'
  157.  
  158.         mov     [GF.draw_line],vm_mike_draw_line.16
  159. ;       mov     [GF.disable_mouse],vm_mike_disable_mouse.16
  160. ;       mov     [GF.draw_pointer],vm_mike_draw_pointer.16
  161.         mov     [GF.drawbar],vm_mike_draw_rect.16
  162.         mov     [GF.putpixel],vm_mike_put_pixel.16
  163.         mov     [GF.getpixel],vm_mike_get_pixel.16
  164.         mov     [GF.sys_putimage],vm_mike_put_image.16
  165.         mov     [GF.drawbackground],vm_mike_draw_bg.16
  166.  
  167.         jmp     .exit.2
  168.  
  169.     @@: cmp     al,15
  170.         jne     @f
  171.  
  172. ;       SHFLOW  'Driver initialized in 15-bit mode'
  173.  
  174.         mov     [GF.draw_line],vm_mike_draw_line.15
  175. ;       mov     [GF.disable_mouse],vm_mike_disable_mouse.15
  176. ;       mov     [GF.draw_pointer],vm_mike_draw_pointer.15
  177.         mov     [GF.drawbar],vm_mike_draw_rect.15
  178.         mov     [GF.putpixel],vm_mike_put_pixel.15
  179.         mov     [GF.getpixel],vm_mike_get_pixel.15
  180.         mov     [GF.sys_putimage],vm_mike_put_image.15
  181.         mov     [GF.drawbackground],vm_mike_draw_bg.15
  182.  
  183.         jmp     .exit.2
  184.  
  185.     @@: cmp     al,8
  186.         jne     @f
  187.  
  188. ;       SHFLOW  'Driver initialized in 8-bit mode'
  189.  
  190.         call    setup_palette_8
  191.  
  192.         mov     [GF.draw_line],vm_mike_draw_line.08
  193. ;       mov     [GF.disable_mouse],vm_mike_disable_mouse.08
  194. ;       mov     [GF.draw_pointer],vm_mike_draw_pointer.08
  195.         mov     [GF.drawbar],vm_mike_draw_rect.08
  196.         mov     [GF.putpixel],vm_mike_put_pixel.08
  197.         mov     [GF.getpixel],vm_mike_get_pixel.08
  198.         mov     [GF.sys_putimage],vm_mike_put_image.08
  199.         mov     [GF.drawbackground],vm_mike_draw_bg.08
  200.  
  201.         jmp     .exit.2
  202.  
  203.     @@: cmp     al,4
  204.         jne     .exit
  205.  
  206. ;       SHFLOW  'Driver initialized in 4-bit mode'
  207.  
  208.         mov     [GF.draw_line],vm_mike_draw_line.04
  209. ;       mov     [GF.disable_mouse],vm_mike_disable_mouse.04
  210. ;       mov     [GF.draw_pointer],vm_mike_draw_pointer.04
  211.         mov     [GF.drawbar],vm_mike_draw_rect.04
  212.         mov     [GF.putpixel],vm_mike_put_pixel.04
  213.         mov     [GF.getpixel],vm_mike_get_pixel.04
  214.         mov     [GF.sys_putimage],vm_mike_put_image.04
  215.         mov     [GF.drawbackground],vm_mike_draw_bg.04
  216.  
  217. ;--------------------------------------
  218.  
  219.   .exit.2:
  220.  
  221.         mov     [GF.calculatescreen],vm_mike_calculatescreen
  222.         mov     [GF.setscreen],vm_mike_setscreen
  223.  
  224.         inc     [call_cnt]
  225.         xor     eax,eax
  226.   .exit.3:
  227.         retn
  228.   .exit:
  229.         xor     eax,eax
  230.         dec     eax
  231.         retn
  232. endf
  233.  
  234. func vm_mike_calculatescreen
  235. begin
  236. ;       call    [SF.calculatescreen]
  237.   .direct:
  238.         pushad
  239.         cli
  240.         movzx   ecx,word[0x00003004]    ; number of processes
  241.         lea     edi,[CLIP_RECTS+ecx*4+4]
  242.         push    dword[0x00003000]
  243.         xor     eax,eax
  244.   .next_window:
  245.         inc     eax
  246.         push    ecx ebx eax edi
  247.         mov     [0x00003000],ax
  248.         call    calc_clipping_rects
  249.         pop     edi eax ebx
  250.         mov     [CLIP_RECTS+eax*4],edi
  251.         mov     [edi],ecx
  252.         add     edi,4
  253.         shl     ecx,2
  254.         rep     movsd
  255.         pop     ecx
  256.         loop    .next_window
  257.         pop     dword[0x00003000]
  258.         sti
  259.         popad
  260.         ret
  261. endf
  262.  
  263. func vm_mike_setscreen
  264. begin
  265. ;       call    [SF.setscreen]
  266.         call    vm_mike_calculatescreen.direct
  267.         ret
  268. endf
  269.  
  270. func vm_mike_uninit
  271. begin
  272. ;       jif     dword[mdrvm],e,0,.exit
  273.         jif     [call_cnt],nz,,.exit.2,dec
  274.         mov     esi,SF
  275.         mov     edi,GF
  276.         mov     ecx,sizeof.graph_funcs/4
  277.         rep     movsd
  278.   .exit.2:
  279.         xor     eax,eax
  280.         retn
  281.   .exit:
  282.         xor     eax,eax
  283.         dec     eax
  284.         retn
  285. endf
  286.  
  287. ;-----------------------------------------------------------------------------
  288.  
  289. include 'norm_04.inc'
  290. include 'norm_08.inc'
  291. include 'norm_15.inc'
  292. include 'norm_16.inc'
  293. include 'norm_24.inc'
  294. include 'norm_32.inc'
  295.  
  296. ;-----------------------------------------------------------------------------
  297.  
  298. func is_intersect_rc
  299. begin
  300.         jif     ecx,l,[tr.left],.exit
  301.         jif     edx,l,[tr.top],.exit
  302.         jif     ebx,ge,[tr.bottom],.exit
  303.         jif     eax,ge,[tr.right],.exit
  304.         clc
  305.         ret
  306.     .exit:
  307.         stc
  308.         ret
  309. endf
  310.  
  311. func is_intersect_hln
  312. begin
  313.         jif     edx,l,[tr.left],.exit
  314.         jif     eax,l,[tr.top],.exit
  315.         jif     eax,ge,[tr.bottom],.exit
  316.         jif     ebx,ge,[tr.right],.exit
  317.         clc
  318.         ret
  319.     .exit:
  320.         stc
  321.         ret
  322. endf
  323.  
  324. func is_intersect_vln
  325. begin
  326.         jif     eax,l,[tr.left],.exit
  327.         jif     edx,l,[tr.top],.exit
  328.         jif     ebx,ge,[tr.bottom],.exit
  329.         jif     eax,ge,[tr.right],.exit
  330.         clc
  331.         ret
  332.     .exit:
  333.         stc
  334.         ret
  335. endf
  336.  
  337. func is_intersect_pt
  338. begin
  339.         jif     eax,l,[tr.left],.exit
  340.         jif     ebx,l,[tr.top],.exit
  341.         jif     ebx,ge,[tr.bottom],.exit
  342.         jif     eax,ge,[tr.right],.exit
  343.         clc
  344.         ret
  345.     .exit:
  346.         stc
  347.         ret
  348. endf
  349.  
  350. func get_cursor_rect
  351. begin
  352.         push    eax
  353.         movsx   eax,word[0x0000FB0A]
  354.         mov     [tr.left],eax
  355.         add     eax,31
  356.         mov     [tr.right],eax
  357.         movsx   eax,word[0x0000FB0C]
  358.         mov     [tr.top],eax
  359.         add     eax,31
  360.         mov     [tr.bottom],eax
  361.         pop     eax
  362.         ret
  363. endf
  364.  
  365. ;-----------------------------------------------------------------------------
  366.  
  367. gamma_4_0 = 0x00
  368. gamma_4_1 = 0x1F
  369. gamma_4_2 = 0x2F
  370. gamma_4_3 = 0x3F
  371.  
  372. align 16
  373. palette_8_64  rb 256*3
  374. palette_8_256 rb 256*3
  375.  
  376. rept 4 red:0
  377. {
  378. \rept 4 green:0
  379. \{
  380. \\rept 4 blue:0
  381. \\{
  382.    index = ((red shl 4) or (green shl 2) or blue)*3
  383.    store gamma_4_  #red   at palette_8_64+index+0
  384.    store gamma_4_ \#green at palette_8_64+index+1
  385.    store gamma_4_\\#blue  at palette_8_64+index+2
  386.    store gamma_4_  #red  *4+red   at palette_8_256+index+0
  387.    store gamma_4_ \#green*4+green at palette_8_256+index+1
  388.    store gamma_4_\\#blue *4+blue  at palette_8_256+index+2
  389. \\}
  390. \}
  391. }
  392.  
  393. ;rept 64 clr1:0
  394. ;{
  395. ; index = clr1*3+64*3
  396. ; clr2 = clr*4+(clr shr 4)
  397. ; store clr1 at palette_8_64 +index
  398. ; store clr2 at palette_8_256+index
  399. ; index = index + 64*3 + 1
  400. ; store clr1 at palette_8_64 +index
  401. ; store clr2 at palette_8_256+index
  402. ; index = index + 64*3 + 1
  403. ; store clr1 at palette_8_64 +index
  404. ; store clr2 at palette_8_256+index
  405. ;}
  406.  
  407. func setup_palette_8
  408. begin
  409.         mov     edx,0x03C8
  410.         xor     al,al
  411.         out     dx,al
  412.         mov     ecx,256*3
  413.         mov     edx,0x03C9
  414.         mov     esi,palette_8_64
  415.         cld
  416.         rep     outsb
  417.         ret
  418. endf
  419.  
  420. ;-----------------------------------------------------------------------------
  421.  
  422. func set_bank0
  423. begin
  424.         mov     ebp,[esp+4*1]
  425.         ret
  426. endf
  427.  
  428.  
  429. ; i810/i815
  430. ; by Protopopius
  431. func set_bank1
  432. begin
  433.         cli
  434.         push    eax edx
  435.         mov     eax,[esp+4*3]
  436.         mov     ebp,eax
  437.         shr     eax,16
  438.         sub     al,0x0A
  439.         cmp     al,[0xfff2]
  440.         je      .exit
  441.         mov     [0xfff2],al
  442.  
  443.         mov     dx,3CEh
  444.         mov     ah,al           ; Save value for later use
  445.         mov     al,10h          ; Index GR10 (Address Mapping)
  446.         out     dx,al           ; Select GR10
  447.         inc     dl
  448.         mov     al,3            ; Set bits 0 and 1 (Enable linear page mapping)
  449.         out     dx,al           ; Write value
  450.         dec     dl
  451.         mov     al,11h          ; Index GR11 (Page Selector)
  452.         out     dx,al           ; Select GR11
  453.         inc     dl
  454.  
  455.         mov     al,ah           ; Write address
  456.         out     dx,al           ; Write the value
  457.  
  458.   .exit:
  459.         and     ebp,0x0000FFFF
  460.         add     ebp,0x000A0000
  461.         pop     edx eax
  462.         sti
  463.         ret
  464. endf
  465.  
  466.  
  467. ; S3
  468. ; by kmeaw
  469. func set_bank2
  470. begin
  471.         cli
  472.         push    eax edx ecx
  473.         mov     eax,[esp+4*4]
  474.         mov     ebp,eax
  475.         shr     eax,16
  476.         sub     al,0x0A
  477.         cmp     al,[0xfff2]
  478.         je      .exit
  479.         mov     [0xfff2],al
  480.  
  481.         mov     cl,al
  482.         mov     dx,0x3D4
  483.         mov     al,0x38
  484.         out     dx,al
  485.         inc     dx
  486.         mov     al,0x48
  487.         out     dx,al
  488.         dec     dx
  489.         mov     al,0x31
  490.         out     dx,al
  491.         inc     dx
  492.         in      al,dx
  493.         dec     dx
  494.         mov     ah,al
  495.         mov     al,0x31
  496.         out     dx,ax
  497.         mov     al,ah
  498.         or      al,9
  499.         inc     dx
  500.         out     dx,al
  501.         dec     dx
  502.         mov     al,0x35
  503.         out     dx,al
  504.         inc     dx
  505.         in      al,dx
  506.         dec     dx
  507.         and     al,0xF0
  508.         mov     ch,cl
  509.         and     ch,0x0F
  510.         or      ch,al
  511.         mov     al,0x35
  512.         out     dx,al
  513.         inc     dx
  514.         mov     al,ch
  515.         out     dx,ax
  516.         dec     dx
  517.         mov     al,0x51
  518.         out     dx,al
  519.         inc     dx
  520.         in      al,dx
  521.         dec     dx
  522.         and     al,0xF3
  523.         shr     cl,2
  524.         and     cl,0x0C
  525.         or      cl,al
  526.         mov     al,0x51
  527.         out     dx,al
  528.         inc     dx
  529.         mov     al,cl
  530.         out     dx,al
  531.         dec     dx
  532.         mov     al,0x38
  533.         out     dx,al
  534.         inc     dx
  535.         xor     al,al
  536.         out     dx,al
  537.  
  538.   .exit:
  539.         and     ebp,0x0000FFFF
  540.         add     ebp,0x000A0000
  541.         pop     ecx edx eax
  542.         sti
  543.         ret
  544. endf
  545.  
  546.  
  547. ; from http://my.execpc.com/CE/AC/geezer/os/slfb.asm
  548. func set_s3_bank
  549. begin
  550.         cli
  551.         push    eax edx
  552.         mov     eax,[esp+4*3]
  553.         mov     ebp,eax
  554.         shr     eax,16
  555.         sub     al,0x0A
  556.         cmp     al,[0xfff2]
  557.         je      .exit
  558.         mov     [0xfff2],al
  559.  
  560.         mov ah,al
  561. ; grrrr...mode-set locked the S3 registers, so unlock them again
  562. ; xxx - do this after mode-set
  563.         mov dx,CRTC_INDX
  564.         mov al,38h
  565.         out dx,al
  566.         inc edx
  567.         mov al,48h
  568.         out dx,al
  569.         dec edx
  570.         mov al,39h
  571.         out dx,al
  572.         inc edx
  573.         mov al,0A5h
  574.         out dx,al
  575. ; now: do the bank-switch
  576.         mov dx,CRTC_INDX
  577.         mov al,35h
  578.         out dx,al
  579.         inc edx
  580.         in al,dx
  581.         and al,0F0h
  582.         or al,ah
  583.         out dx,al
  584.  
  585.   .exit:
  586.         and     ebp,0x0000FFFF
  587.         add     ebp,0x000A0000
  588.         pop     edx eax
  589.         sti
  590.         ret
  591. endf
  592.  
  593.  
  594. func set_bank3
  595. begin
  596.         cli
  597.         push    eax edx
  598.         mov     eax,[esp+4*3]
  599.         mov     ebp,eax
  600.         shr     eax,16
  601.         sub     al,0x0A
  602.         cmp     al,[0xfff2]
  603.         je      .exit
  604.         mov     [0xfff2],al
  605.  
  606.         mov     ah,al
  607.         mov     dx,0x03D4
  608.         mov     al,0x39
  609.         out     dx,al
  610.         inc     dl
  611.         mov     al,0xA5
  612.         out     dx,al
  613.         dec     dl
  614.         mov     al,6Ah
  615.         out     dx,al
  616.         inc     dl
  617.         mov     al,ah
  618.         out     dx,al
  619.         dec     dl
  620.         mov     al,0x39
  621.         out     dx,al
  622.         inc     dl
  623.         mov     al,0x5A
  624.         out     dx,al
  625.         dec     dl
  626.  
  627.   .exit:
  628.         and     ebp,0x0000FFFF
  629.         add     ebp,0x000A0000
  630.         pop     edx eax
  631.         sti
  632.         ret
  633. endf
  634.  
  635. ;-----------------------------------------------------------------------------
  636.  
  637. DRIVER_CODE_END:
  638.  
  639. diff10 'driver code size',DRIVER_CODE_START,DRIVER_CODE_END
  640.  
  641. ;-----------------------------------------------------------------------------
  642. ;///// END ///////////////////////////////////////////////////////////////////
  643. ;-----------------------------------------------------------------------------