Subversion Repositories Kolibri OS

Rev

Rev 117 | Rev 379 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                        ;;
  3. ;;  VGA.INC                                               ;;
  4. ;;                                                        ;;
  5. ;;  640x480 mode 0x12 VGA functions for MenuetOS          ;;
  6. ;;                                                        ;;
  7. ;;  Paul Butcher, paul.butcher@asa.co.uk                  ;;
  8. ;;                                                        ;;
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10.  
  11.  
  12.  
  13. paletteVGA:
  14.  
  15. ;16 colour palette
  16.        mov    dx,0x3c8
  17.        mov    al,0
  18.        out    dx,al
  19.  
  20.        mov    ecx,16
  21.        mov    dx,0x3c9
  22.        xor    eax,eax
  23.  
  24.      palvganew:
  25.  
  26.        mov al,0
  27.        test ah,4
  28.        jz palvgalbl1
  29.        add al,31
  30.        test ah,8
  31.        jz palvgalbl1
  32.        add al,32
  33.      palvgalbl1:
  34.        out dx,al  ; red 0,31 or 63
  35.        mov al,0
  36.        test ah,2
  37.        jz palvgalbl2
  38.        add al,31
  39.        test ah,8
  40.        jz palvgalbl2
  41.        add al,32
  42.      palvgalbl2:
  43.        out dx,al  ; blue 0,31 or 63
  44.        mov al,0
  45.        test ah,1
  46.        jz palvgalbl3
  47.        add al,31
  48.        test ah,8
  49.        jz palvgalbl3
  50.        add al,32
  51.      palvgalbl3:
  52.        out dx,al  ; green 0,31 or 63
  53.        add ah,1
  54.        loop palvganew
  55. ;       mov    dx, 3ceh
  56. ;       mov    ax, 0005h
  57. ;       out    dx, ax        
  58.        ret
  59.  
  60. palette320x200:
  61.  
  62.        mov   edx,0x3c8
  63.        xor   eax, eax
  64.        out   dx,al
  65.        mov   ecx,256
  66.        mov   edx,0x3c9
  67.        xor   eax,eax
  68.  
  69.      palnew:
  70.        mov   al,0
  71.        test  ah,64
  72.        jz    pallbl1
  73.        add   al,21
  74.      pallbl1:
  75.        test  ah,128
  76.        jz    pallbl2
  77.        add   al,42
  78.      pallbl2:
  79.        out   dx,al
  80.        mov   al,0
  81.        test  ah,8
  82.        jz    pallbl3
  83.        add   al,8
  84.      pallbl3:
  85.        test  ah,16
  86.        jz    pallbl4
  87.        add   al,15
  88.      pallbl4:
  89.        test  ah,32
  90.        jz    pallbl5
  91.        add   al,40
  92.      pallbl5:
  93.        out   dx,al
  94.        mov   al,0
  95.        test  ah,1
  96.        jz    pallbl6
  97.        add   al,8
  98.      pallbl6:
  99.        test  ah,2
  100.        jz    pallbl7
  101.        add   al,15
  102.      pallbl7:
  103.        test  ah,4
  104.        jz    pallbl8
  105.        add   al,40
  106.      pallbl8:
  107.        out   dx,al
  108.        add   ah,1
  109.        loop  palnew
  110.  
  111.        ret
  112.  
  113. uglobal
  114.   novesachecksum dd 0x0
  115.   EGA_counter    db  0
  116.   VGA_drawing_screen db 0
  117.   VGA_8_pixels:
  118.      rb 16
  119.   temp:
  120.      .cx dd 0
  121. endg
  122.  
  123. checkVga_N13:
  124.  
  125.         cmp    [0xfe0c],dword 0x13
  126.         jne   @f
  127.  
  128. ;      cnvl:
  129.         pushad
  130.         cmp   [EGA_counter],1
  131.         je   novesal
  132.         mov    ecx,[0xfb0a]
  133.         cmp    ecx,[novesachecksum]
  134.         jne    novesal
  135.         popad
  136.       @@:
  137.         ret
  138.  
  139.       novesal:
  140.         mov    [novesachecksum],ecx
  141.         mov    ecx,0
  142.         movzx  eax,word [0xfb0c]
  143.         cmp    eax,100
  144.         jge    m13l3
  145.         mov    eax,100
  146.       m13l3:
  147.         cmp    eax,480-100
  148.         jbe    m13l4
  149.         mov    eax,480-100
  150.       m13l4:
  151.         sub    eax,100
  152.         imul   eax,640*4
  153.         add    ecx,eax
  154.         movzx  eax,word [0xfb0a]
  155.         cmp    eax,160
  156.         jge    m13l1
  157.         mov    eax,160
  158.       m13l1:
  159.         cmp    eax,640-160
  160.         jbe    m13l2
  161.         mov    eax,640-160
  162.       m13l2:
  163.         sub    eax,160
  164.         shl    eax,2
  165.         add    ecx,eax
  166.         mov    esi,[0xfe80]
  167.         add    esi,ecx
  168.         mov    edi,0xa0000
  169.         mov    edx,200
  170.         mov    ecx,320
  171.         cld
  172.      m13pix:
  173.         lodsd
  174.         cmp    eax,0
  175.         je    .save_pixel
  176.         push   eax
  177.         mov    ebx,eax
  178.         and    eax,(128+64+32)      ; blue
  179.         shr    eax,5
  180.         and    ebx,(128+64+32)*256  ; green
  181.         shr    ebx,8+2
  182.         add    eax,ebx
  183.         pop    ebx
  184.         and    ebx,(128+64)*256*256 ; red
  185.         shr    ebx,8+8
  186.         add    eax,ebx
  187.      .save_pixel:
  188.         stosb
  189.         loop   m13pix
  190.         mov    ecx,320
  191.         add    esi,4*(640-320)
  192.         dec    edx
  193.         jnz    m13pix
  194.         mov    [EGA_counter],0
  195.         popad
  196.         ret
  197.  
  198. VGA_drawbackground:
  199. ; draw all  
  200.         cmp    [0xfe0c],dword 0x12
  201.         jne     .end
  202.         pushad
  203.         mov    esi,[0xfe80]
  204.         mov    edi,0xa0000
  205.         mov    ebx,640/32  ; 640*480/(8*4)
  206.         mov    edx,480
  207.      @@:
  208.         push   ebx edx esi edi
  209.         shl    edx,9          
  210.         lea    edx,[edx+edx*4]
  211.         add    esi,edx
  212.         shr    edx,5
  213.         add    edi,edx
  214.         call   VGA_draw_long_line
  215.         pop    edi esi edx ebx
  216.         dec    edx
  217.         jnz    @r
  218.         call   VGA_draw_long_line_1
  219.         popad
  220.     .end:
  221.         ret
  222.  
  223. VGA_draw_long_line:
  224.         mov    dx,3ceh
  225.         mov    ax,0ff08h
  226.         cli
  227.         out    dx, ax
  228.         mov    ax,0005h
  229.         out    dx, ax
  230.     m12pix:
  231.         call   VGA_draw_32_pixels
  232.         dec    ebx
  233.         jnz    m12pix
  234.         mov    dx,3c4h
  235.         mov    ax,0ff02h
  236.         out    dx,ax
  237.         mov    dx,3ceh
  238.         mov    ax,0205h
  239.         out    dx,ax
  240.         mov    dx,3ceh
  241.         mov    al,08h
  242.         out    dx,al
  243.         sti
  244.         ret
  245.  
  246. VGA_draw_32_pixels:
  247.         xor    eax,eax
  248.         mov    ebp,VGA_8_pixels
  249.         mov    [ebp],eax
  250.         mov    [ebp+4],eax
  251.         mov    [ebp+8],eax
  252.         mov    [ebp+12],eax
  253.         mov    ch,4
  254.     .main_loop:
  255.         mov    cl,8
  256.     .convert_pixels_to_VGA:
  257.         lodsd   ; eax = 24bit colour
  258.         cmp    eax,0
  259.         je     .end
  260.         rol    eax,8
  261.         mov    al,ch
  262.         ror    eax,8
  263.         mov    ch,1
  264.         dec    cl
  265.         shl    ch,cl
  266.         cmp    al,85
  267.         jbe     .p13green
  268.         or     [ebp],ch
  269.         cmp    al,170
  270.         jbe     .p13green
  271.         or     [ebp+12],ch
  272.     .p13green:
  273.         cmp    ah,85
  274.         jbe     .p13red
  275.         or     [ebp+4],ch
  276.         cmp    ah,170
  277.         jbe     .p13red
  278.         or     [ebp+12],ch
  279.     .p13red:
  280.         shr    eax,8
  281.         cmp    ah,85
  282.         jbe     .p13cont
  283.         or     [ebp+8],ch
  284.         cmp    ah,170
  285.         jbe     .p13cont
  286.         or     [ebp+12],ch
  287.     .p13cont:
  288.         ror    eax,8
  289.         mov    ch,ah
  290.         inc    cl
  291.     .end:
  292.         dec    cl
  293.         jnz    .convert_pixels_to_VGA
  294.         inc    ebp
  295.         dec    ch
  296.         jnz    .main_loop
  297.         push   esi
  298.         sub    ebp,4
  299.         mov    esi,ebp
  300.         mov    dx, 3c4h
  301.         mov    ah, 1h
  302.     @@:
  303.         mov    al, 02h
  304.         out    dx,ax
  305.         xchg   ax,bp
  306.         lodsd
  307.         mov    [edi],eax
  308.         xchg   ax,bp
  309.         shl    ah, 1
  310.         cmp    ah, 10h
  311.         jnz    @r
  312.         add    edi,4
  313.         pop    esi
  314.         ret
  315.  
  316. VGA_putpixel:
  317.  ; eax = x
  318.  ; ebx = y
  319.         mov     ecx,eax
  320.         mov     eax, [esp+32-8+4] ; color
  321.         shl        ebx,9          
  322.         lea        ebx,[ebx+ebx*4] ; óìíîæåíèå íà 5
  323.         lea     edx, [ebx+ecx*4]  ; + x*BytesPerPixel (Vesa2.0 32)
  324.         mov     edi,edx
  325.         add     edi, [0xfe80]     ; + LFB address
  326.         mov     [edi], eax        ; write to LFB for Vesa2.0
  327.         shr     edx,5             ; change BytesPerPixel to 1/8
  328.         mov     edi,edx
  329.         add     edi, 0x0a0000     ; address of pixel in VGA area
  330.         and     ecx,0x07          ; bit no. (modulo 8)
  331.         pushfd
  332.         ; edi = address, eax = 24bit colour, ecx = bit no. (modulo 8)
  333.         xor    edx,edx
  334.         cmp    eax,0
  335.         je     .p13cont
  336.         cmp    al,85
  337.         jbe    .p13green
  338.         or     dl,0x01
  339.         cmp    al,170
  340.         jbe    .p13green
  341.         or     dl,0x08
  342. .p13green:
  343.         cmp    ah,85
  344.         jbe    .p13red
  345.         or     dl,0x02
  346.         cmp    ah,170
  347.         jbe    .p13red
  348.         or     dl,0x08
  349. .p13red:
  350.         shr    eax,8
  351.         cmp    ah,85
  352.         jbe    .p13cont
  353.         or     dl,0x04
  354.         cmp    ah,170
  355.         jbe    .p13cont
  356.         or     dl,0x08
  357. .p13cont:
  358.         ror    edx,8
  359.         inc    cl
  360.         xor    eax,eax
  361.         inc    ah
  362.         shr    ax,cl
  363.         mov    dx,3cfh
  364.         cli
  365.         out    dx,al
  366.         mov    al,[edi]           ; dummy read
  367.         rol    edx,8
  368.         mov    [edi],dl
  369.         popfd
  370. ;.end:
  371.         ret
  372.        
  373. VGA__putimage:
  374. ; ecx = size [x|y]
  375. ; edx = coordinates [x|y]
  376.         cmp    [0xfe0c],dword 0x12
  377.         jne     @f
  378.          pushad
  379.          rol  edx,16
  380.          movzx eax,dx
  381.          rol  edx,16
  382.          movzx ebx,dx
  383.          movzx edx,cx
  384.          rol   ecx,16
  385.          movzx ecx,cx
  386.          call  VGA_draw_bar_1
  387.          popad
  388. @@:
  389.          ret
  390.  
  391. VGA_draw_bar:
  392. ; eax   cx
  393. ; ebx   cy
  394. ; ecx   xe
  395. ; edx   ye
  396.         cmp    [0xfe0c],dword 0x12
  397.         jne     @f
  398.          pushad
  399.          sub   ecx,eax
  400.          sub   edx,ebx
  401.          and   eax,0xffff
  402.          and   ebx,0xffff
  403.          and   ecx,0xffff
  404.          and   edx,0xffff
  405.          call  VGA_draw_bar_1
  406.          popad
  407. @@:
  408.          ret
  409.  
  410. VGA_draw_bar_1:
  411.         mov     [temp.cx],eax
  412.         mov     eax, [0x3010]
  413.         add     ebx, [eax-twdw + 4]
  414.         mov     eax, [eax-twdw + 0]
  415.         add     eax, [temp.cx]
  416.         and     eax,0xfff8
  417.         shl     ebx,9          
  418.         lea     ebx,[ebx+ebx*4] ; óìíîæåíèå íà 5
  419.         lea     ebx, [ebx+eax*4]  ; + x*BytesPerPixel (Vesa2.0 32)
  420.         mov     esi,ebx
  421.         add     esi, [0xfe80]     ; + LFB address
  422.         shr     ebx,5             ; change BytesPerPixel to 1/8
  423.         mov     edi,ebx
  424.         add     edi, 0x0a0000     ; address of pixel in VGA area
  425.         mov     ebx,ecx
  426.         shr     ebx,5
  427.         inc     ebx
  428. .main_loop:
  429.         call   VGA_draw_long_line_1
  430.         dec    edx
  431.         jnz    .main_loop
  432.         call   VGA_draw_long_line_1
  433.         ret
  434.  
  435. VGA_draw_long_line_1:
  436.         push   ebx edx esi edi
  437.         shl    edx,9          
  438.         lea    edx,[edx+edx*4]
  439.         add    esi,edx
  440.         shr    edx,5
  441.         add    edi,edx
  442.         call   VGA_draw_long_line
  443.         pop    edi esi edx ebx
  444.         ret
  445.  
  446.  
  447.