Subversion Repositories Kolibri OS

Rev

Rev 1505 | 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. $Revision: 1508 $
  9.  
  10. struc VBE_VGAInfo {
  11.   .VESASignature          dd ?    ; char
  12.   .VESAVersion            dw ?    ; short
  13.   .OemStringPtr           dd ?    ; char *
  14.   .Capabilities           dd ?    ; ulong
  15.   .VideoModePtr           dd ?    ; ulong
  16.   .TotalMemory            dw ?    ; short
  17.   ; VBE 2.0+
  18.   .OemSoftwareRev         db ?    ; short
  19.   .OemVendorNamePtr       dw ?    ; char *
  20.   .OemProductNamePtr      dw ?    ; char *
  21.   .OemProductRevPtr       dw ?    ; char *
  22.   .reserved               rb 222  ; char
  23.   .OemData                rb 256  ; char
  24. }
  25.  
  26. struc VBE_ModeInfo {
  27.   .ModeAttributes         dw ?    ; short
  28.   .WinAAttributes         db ?    ; char
  29.   .WinBAttributes         db ?    ; char
  30.   .WinGranularity         dw ?    ; short
  31.   .WinSize                dw ?    ; short
  32.   .WinASegment            dw ?    ; ushort
  33.   .WinBSegment            dw ?    ; ushort
  34.   .WinFuncPtr             dd ?    ; void *
  35.   .BytesPerScanLine       dw ?    ; short
  36.   .XRes                   dw ?    ; short
  37.   .YRes                   dw ?    ; short
  38.   .XCharSize              db ?    ; char
  39.   .YCharSize              db ?    ; char
  40.   .NumberOfPlanes         db ?    ; char
  41.   .BitsPerPixel           db ?    ; char
  42.   .NumberOfBanks          db ?    ; char
  43.   .MemoryModel            db ?    ; char
  44.   .BankSize               db ?    ; char
  45.   .NumberOfImagePages     db ?    ; char
  46.   .res1                   db ?    ; char
  47.   .RedMaskSize            db ?    ; char
  48.   .RedFieldPosition       db ?    ; char
  49.   .GreenMaskSize          db ?    ; char
  50.   .GreenFieldPosition     db ?    ; char
  51.   .BlueMaskSize           db ?    ; char
  52.   .BlueFieldPosition      db ?    ; char
  53.   .RsvedMaskSize          db ?    ; char
  54.   .RsvedFieldPosition     db ?    ; char
  55.   .DirectColorModeInfo    db ?    ; char ; MISSED IN THIS TUTORIAL!! SEE ABOVE
  56.   ; VBE 2.0+
  57.   .PhysBasePtr            dd ?    ; ulong
  58.   .OffScreenMemOffset     dd ?    ; ulong
  59.   .OffScreenMemSize       dw ?    ; short
  60.   ; VBE 3.0+
  61.   .LinbytesPerScanLine    dw ?    ; short
  62.   .BankNumberOfImagePages db ?    ; char
  63.   .LinNumberOfImagePages  db ?    ; char
  64.   .LinRedMaskSize         db ?    ; char
  65.   .LinRedFieldPosition    db ?    ; char
  66.   .LingreenMaskSize       db ?    ; char
  67.   .LinGreenFieldPosition  db ?    ; char
  68.   .LinBlueMaskSize        db ?    ; char
  69.   .LinBlueFieldPosition   db ?    ; char
  70.   .LinRsvdMaskSize        db ?    ; char
  71.   .LinRsvdFieldPosition   db ?    ; char
  72.   .MaxPixelClock          dd ?    ; ulong
  73.   .res2                   rb 190  ; char
  74. }
  75.  
  76. virtual at $A000
  77.   vi VBE_VGAInfo
  78.   mi VBE_ModeInfo
  79. modes_table:
  80. end virtual
  81. cursor_pos  dw 0         ;âðåìåííîå õðàíåíèå êóðñîðà.
  82. home_cursor dw 0    ;current shows rows a table
  83. end_cursor  dw 0     ;end of position current shows rows a table
  84. scroll_start dw 0    ;start position of scroll bar
  85. scroll_end  dw 0     ;end position of scroll bar
  86. long_v_table equ 9   ;long of visible video table
  87. size_of_step equ 10
  88. scroll_area_size equ (long_v_table-2)
  89. int2str:
  90.         dec     bl
  91.         jz      @f
  92.         xor     edx,edx
  93.         div     ecx
  94.         push    edx
  95.         call    int2str
  96.         pop     eax
  97.     @@: or      al,0x30
  98.         mov     [ds:di],al
  99.         inc     di
  100.         ret
  101.  
  102. int2strnz:
  103.         cmp     eax,ecx
  104.         jb      @f
  105.         xor     edx,edx
  106.         div     ecx
  107.         push    edx
  108.         call    int2strnz
  109.         pop     eax
  110.     @@: or      al,0x30
  111.         mov     [es:di],al
  112.         inc     di
  113.         ret
  114.  
  115. ;-------------------------------------------------------
  116. ;Write message about incorrect v_mode and write message about jmp on swith v_mode
  117. v_mode_error:
  118.         _setcursor 19,2
  119.         mov     si, fatalsel
  120.         call    printplain
  121.         _setcursor 20,2
  122.         mov     si,pres_key
  123.         call    printplain
  124.         xor     eax,eax
  125.         int     16h
  126.         jmp     cfgmanager.d
  127. ;-------------------------------------------------------
  128. ;
  129.  
  130.  
  131.  
  132. ;-------------------------------------------------------
  133. print_vesa_info:
  134.         _setcursor 5,2
  135.  
  136.         mov     [es:vi.VESASignature],'VBE2'
  137.         mov     ax,0x4F00
  138.         mov     di,vi      ;0xa000
  139.         int     0x10
  140.         or      ah,ah
  141.         jz      @f
  142.         mov     [es:vi.VESASignature],'VESA'
  143.         mov     ax,$4F00
  144.         mov     di,vi
  145.         int     0x10
  146.         or      ah,ah
  147.         jnz     .exit
  148.   @@:
  149.         cmp     [es:vi.VESASignature],'VESA'
  150.         jne     .exit
  151.         cmp     [es:vi.VESAVersion],0x0100
  152.         jb      .exit
  153.         jmp     .vesaok2
  154.  
  155.   .exit:
  156.         mov     si,novesa
  157.         call    printplain
  158.         ret
  159.  
  160.   .vesaok2:
  161.         mov     ax,[es:vi.VESAVersion]
  162.         add     ax,'00'
  163.  
  164.         mov     [s_vesa.ver], ah
  165.         mov     [s_vesa.ver+2], al
  166.         mov     si,s_vesa
  167.         call    printplain
  168.  
  169.         _setcursor 4,2
  170.         mov     si,word[es:vi.OemStringPtr]
  171.         mov     di,si
  172.  
  173.         push    ds
  174.         mov     ds,word[es:vi.OemStringPtr+2]
  175.         call    printplain
  176.         pop     ds
  177.  
  178.         ret
  179. ;-----------------------------------------------------------------------------
  180.  
  181. calc_vmodes_table:
  182.         pushad
  183.  
  184. ;        push    0
  185. ;        pop     es
  186.  
  187.         lfs     si, [es:vi.VideoModePtr]
  188.  
  189.         mov     bx,modes_table
  190. ;save no vesa mode of work 320x200, EGA/CGA 256 colors and 640x480, VGA 16 cols
  191. ;        mov     word [es:bx],640
  192. ;        mov     word [es:bx+2],480
  193. ;        mov     word [es:bx+6],0x13
  194.        
  195. ;        mov     word [es:bx+10],640
  196. ;        mov     word [es:bx+12],480
  197. ;        mov     word [es:bx+16],0x12
  198. ;        add     bx,20
  199.   .next_mode:
  200.         mov     cx,word [fs:si] ; mode number
  201.         cmp     cx,-1
  202.         je      .modes_ok.2
  203.  
  204.         mov     ax,0x4F01
  205.         mov     di,mi
  206.         int     0x10
  207.  
  208.         or      ah,ah
  209.         jnz     .modes_ok.2;vesa_info.exit
  210.  
  211.         test    [es:mi.ModeAttributes],00000001b   ;videomode support ?
  212.         jz      @f
  213.         test    [es:mi.ModeAttributes],00010000b   ;picture ?
  214.         jz      @f
  215.         test    [es:mi.ModeAttributes],10000000b   ;LFB ?
  216.         jz      @f
  217.  
  218.         cmp     [es:mi.BitsPerPixel], 32        ;to show only 32 bpp videomodes
  219.         jb      @f
  220.  
  221. .l0:
  222.         cmp     [es:mi.XRes],800        ; only 800x600 and higher
  223.         jb      @f
  224.  
  225.         mov     ax,[es:mi.XRes]
  226.         mov     [es:bx+0],ax               ; +0[2] : resolution X
  227.         mov     ax,[es:mi.YRes]
  228.         mov     [es:bx+2],ax               ; +2[2] : resolution Y
  229.         mov     ax,[es:mi.ModeAttributes]
  230.         mov     [es:bx+4],ax               ; +4[2] : attributes
  231.  
  232.         cmp     [s_vesa.ver],'2'
  233.         jb      .lp1
  234.  
  235.         or      cx,0x4000  ; use LFB
  236. .lp1:   mov     [es:bx+6],cx               ; +6 : mode number
  237.         movzx   ax,byte [es:mi.BitsPerPixel]
  238.         mov     word [es:bx+8],ax               ; +8 : bits per pixel
  239.         add     bx,size_of_step                 ; size of record
  240.  
  241.     @@:
  242.         add     si,2
  243.         jmp     .next_mode
  244.  
  245.   .modes_ok.2:
  246.  
  247.         mov     word[es:bx],-1  ;end video table
  248.         mov     word[end_cursor],bx     ;save end cursor position
  249.         popad
  250.         ret
  251.  
  252. ;-----------------------------------------------------------------------------
  253.  
  254. draw_current_vmode:
  255.         push    0
  256.         pop     es
  257.  
  258.         mov     si,word [cursor_pos]
  259.  
  260.         cmp     word [es:si+6],0x12
  261.         je      .no_vesa_0x12
  262.  
  263.         cmp     word [es:si+6],0x13
  264.         je      .no_vesa_0x13
  265.  
  266.         mov     di,loader_block_error
  267.         movzx   eax,word[es:si+0]
  268.         mov     ecx,10
  269.         call    int2strnz
  270.         mov     byte[es:di],'x'
  271.         inc     di
  272.         movzx   eax,word[es:si+2]
  273.         call    int2strnz
  274.         mov     byte[es:di],'x'
  275.         inc     di
  276.         movzx   eax,word[es:si+8]
  277.         call    int2strnz
  278.         mov     dword[es:di],0x00000d0a
  279.         mov     si,loader_block_error
  280.         push    ds
  281.         push    es
  282.         pop     ds
  283.         call    printplain
  284.         pop     ds
  285.         ret
  286. .no_vesa_0x13:
  287.         mov     si,mode0
  288.         jmp     .print
  289. .no_vesa_0x12:
  290.         mov     si,mode9
  291. .print:
  292.         call    printplain
  293.         ret        
  294. ;-----------------------------------------------------------------------------
  295. check_first_parm:
  296.         mov     si,word [preboot_graph]
  297.         test    si,si
  298.         jnz      .no_zero        ;if no zero
  299. .zerro:
  300. ;        mov     ax,modes_table
  301. ;        mov     word [cursor_pos],ax
  302. ;        mov     word [home_cursor],ax
  303. ;        mov     word [preboot_graph],ax
  304. ;SET default video of mode first probe will fined a move of work 1024x768@32
  305.  
  306.         mov     ax,1024
  307.         mov     bx,768
  308.         mov     si,modes_table
  309.         call    .loops
  310.         test    ax,ax
  311.         jz     .ok_found_mode
  312.         mov     ax,800
  313.         mov     bx,600
  314.         mov     si,modes_table
  315.         call    .loops
  316.         test    ax,ax
  317.         jz     .ok_found_mode
  318.  
  319.         mov     si,modes_table
  320.         jmp     .ok_found_mode
  321.  
  322. .no_zero:
  323.         mov     bp,word [number_vm]
  324.         cmp     bp,word [es:si+6]
  325.         jz      .ok_found_mode
  326.         mov     ax,word [x_save]
  327.         mov     bx,word [y_save]
  328.         mov     si,modes_table
  329.         call    .loops
  330.         test    ax,ax
  331.         jz     .ok_found_mode
  332.  
  333.         mov    si,modes_table
  334. ;        cmp     ax,modes_table
  335. ;        jb      .zerro           ;check on correct if bellow
  336. ;        cmp     ax,word [end_cursor]
  337. ;        ja      .zerro           ;check on correct if anymore
  338.  
  339. .ok_found_mode:
  340.         mov     word [home_cursor],si
  341. ;        mov     word [cursor_pos],si
  342.         mov     word [preboot_graph],si
  343.         mov     ax,si
  344.  
  345.         mov     ecx,long_v_table
  346.  
  347. .loop:  add     ax,size_of_step
  348.         cmp     ax,word [end_cursor]
  349.         jae     .next_step
  350.         loop    .loop
  351. .next_step:
  352.         sub     ax,size_of_step*long_v_table
  353.         cmp     ax,modes_table
  354.         jae     @f
  355.         mov     ax,modes_table
  356. @@:
  357.  
  358.         mov     word [home_cursor],ax
  359.         mov     si,[preboot_graph]
  360.         mov     word [cursor_pos],si
  361.  
  362.         push    word [es:si]
  363.         pop     word [x_save]
  364.         push    word [es:si+2]
  365.         pop     word [y_save]
  366.         push    word [es:si+6]
  367.         pop     word [number_vm]
  368.  
  369.         ret
  370. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  371. .loops:
  372.         cmp     ax,word [es:si]
  373.         jne     .next
  374.         cmp     bx,word [es:si+2]
  375.         jne     .next
  376.         cmp     word [es:si+8],32
  377.         je      .ok
  378.         cmp     word [es:si+8],24
  379.         je      .ok
  380. .next:  add     si,size_of_step
  381.         cmp     word [es:si],-1
  382.         je      .exit
  383.         jmp     .loops
  384. .ok:    xor     ax,ax        
  385.         ret
  386. .exit:  or      ax,-1
  387.         ret
  388.  
  389.  
  390. ;-----------------------------------------------------------------------------
  391.  
  392. ;default_vmode:
  393.        
  394. ;-----------------------------------------------------------------------------
  395. draw_vmodes_table:
  396.         _setcursor 9, 2
  397.         mov     si,gr_mode
  398.         call    printplain
  399.  
  400.         mov     si,_st
  401.         call    printplain
  402.  
  403.         push    word [cursor_pos]
  404.         pop     ax
  405.         push    word [home_cursor]
  406.         pop     si
  407.         mov     cx,si
  408.  
  409.         cmp     ax,si
  410.         je      .ok
  411.         jb      .low
  412.  
  413.  
  414.         add     cx,size_of_step*long_v_table
  415.        
  416.         cmp     ax,cx
  417.         jb      .ok
  418.        
  419.         sub     cx,size_of_step*long_v_table
  420.         add     cx,size_of_step
  421.         cmp     cx,word[end_cursor]
  422.         jae     .ok
  423.         add     si,size_of_step
  424.         push    si
  425.         pop     word [home_cursor]
  426.         jmp     .ok
  427.  
  428.  
  429. .low:   sub     cx,size_of_step
  430.         cmp     cx,modes_table
  431.         jb      .ok
  432.         push    cx
  433.         push    cx
  434.         pop     word [home_cursor]
  435.         pop     si
  436.  
  437.  
  438. .ok:
  439. ; calculate scroll position
  440.         push    si
  441.         mov     ax, [end_cursor]
  442.         sub     ax, modes_table
  443.         mov     bx, size_of_step
  444.         cwd
  445.         div     bx
  446.         mov     si, ax          ; si = size of list
  447.         mov     ax, [home_cursor]
  448.         sub     ax, modes_table
  449.         cwd
  450.         div     bx
  451.         mov     di, ax
  452.         mov     ax, scroll_area_size*long_v_table
  453.         cwd
  454.         div     si
  455.         test    ax, ax
  456.         jnz     @f
  457.         inc     ax
  458. @@:
  459.         cmp     al, scroll_area_size
  460.         jb      @f
  461.         mov     al, scroll_area_size
  462. @@:
  463.         mov     cx, ax
  464. ; cx = scroll height
  465. ; calculate scroll pos
  466.         xor     bx, bx          ; initialize scroll pos
  467.         sub     al, scroll_area_size+1
  468.         neg     al
  469.         sub     si, long_v_table-1
  470.         jbe     @f
  471.         mul     di
  472.         div     si
  473.         mov     bx, ax
  474. @@:
  475.         inc     bx
  476.         imul    ax, bx, size_of_step
  477.         add     ax, [home_cursor]
  478.         mov     [scroll_start], ax
  479.         imul    cx, size_of_step
  480.         add     ax, cx
  481.         mov     [scroll_end], ax
  482.         pop     si
  483.         mov     bp,long_v_table               ;show rows
  484. .@@_next_bit:
  485. ;clear cursor
  486.         mov     ax,'  '
  487.         mov     word[ds:_r1+21],ax
  488.         mov     word[ds:_r1+50],ax
  489.  
  490.         mov     word[ds:_r2+21],ax
  491.         mov     word[ds:_r2+45],ax
  492.  
  493.         mov     word[ds:_rs+21],ax
  494.         mov     word[ds:_rs+46],ax
  495. ; draw string
  496.         cmp     word [es:si+6],0x12
  497.         je      .show_0x12
  498.         cmp     word [es:si+6],0x13
  499.         je      .show_0x13
  500.  
  501.         movzx   eax,word[es:si]
  502.         cmp     ax,-1
  503.         je      .@@_end
  504.         mov     di,_rs+23          
  505.         mov     ecx,10
  506.         mov     bl,4
  507.         call    int2str
  508.         movzx   eax,word[es:si+2]
  509.         inc     di
  510.         mov     bl,4
  511.         call    int2str
  512.  
  513.         movzx   eax,word[es:si+8]
  514.         inc     di
  515.         mov     bl,2
  516.         call    int2str
  517.  
  518.         cmp     si, word [cursor_pos]
  519.         jne     .next
  520. ;draw   cursor
  521.         mov     word[ds:_rs+21],'>>'
  522.         mov     word[ds:_rs+46],'<<'
  523.        
  524.  
  525.  
  526. .next:
  527.         push    si
  528.         mov     si,_rs
  529. .@@_sh:
  530. ; add to the string pseudographics for scrollbar
  531.         pop     bx
  532.         push    bx
  533.         mov     byte [si+53], ' '
  534.         cmp     bx, [scroll_start]
  535.         jb      @f
  536.         cmp     bx, [scroll_end]
  537.         jae     @f
  538.         mov     byte [si+53], 0xDB ; filled bar
  539. @@:
  540.         push    bx
  541.         add     bx, size_of_step
  542.         cmp     bx, [end_cursor]
  543.         jnz     @f
  544.         mov     byte [si+53], 31 ; 'down arrow' symbol
  545. @@:
  546.         sub     bx, [home_cursor]
  547.         cmp     bx, size_of_step*long_v_table
  548.         jnz     @f
  549.         mov     byte [si+53], 31 ; 'down arrow' symbol
  550. @@:
  551.         pop     bx
  552.         cmp     bx, [home_cursor]
  553.         jnz     @f
  554.         mov     byte [si+53], 30 ; 'up arrow' symbol
  555. @@:
  556.         call    printplain
  557.         pop     si
  558.         add     si,size_of_step
  559.  
  560.         dec     bp
  561.         jnz     .@@_next_bit
  562.  
  563. .@@_end:
  564.         mov     si,_bt
  565.         call    printplain
  566.         ret
  567. .show_0x13:
  568.         push    si
  569.  
  570.         cmp     si, word [cursor_pos]
  571.         jne     @f
  572.         mov     word[ds:_r1+21],'>>'
  573.         mov     word[ds:_r1+50],'<<'        
  574. @@:
  575.         mov     si,_r1
  576.         jmp     .@@_sh
  577. .show_0x12:
  578.         push    si
  579.         cmp     si, word [cursor_pos]
  580.         jne     @f
  581.  
  582.         mov     word[ds:_r2+21],'>>'
  583.         mov     word[ds:_r2+45],'<<'
  584. @@:
  585.         mov     si,_r2
  586.         jmp     .@@_sh
  587.  
  588. ;-----------------------------------------------------------------------------
  589. ;Clear arrea of current video page (0xb800)
  590. clear_vmodes_table:
  591.         pusha
  592.        ; draw frames
  593.         push    es
  594.         push    0xb800
  595.         pop     es
  596.         mov     di,1444
  597.         xor     ax,ax
  598.         mov     ah, 1*16+15
  599.         mov     cx,70
  600.         mov     bp,12
  601. .loop_start:
  602.         rep     stosw
  603.         mov     cx,70
  604.         add     di,20
  605.         dec     bp
  606.         jns             .loop_start      
  607.         pop     es
  608.         popa
  609.         ret
  610.  
  611. ;-----------------------------------------------------------------------------
  612.  
  613. set_vmode:
  614.         push    0 ;0;x1000
  615.         pop     es
  616.  
  617.         mov     si,word [preboot_graph]            ;[preboot_graph]
  618.         mov     cx,word [es:si+6]            ; number of mode
  619.        
  620.  
  621.         mov     ax,word [es:si+0]            ; resolution X
  622.         mov     bx,word [es:si+2]            ; resolution Y
  623.  
  624.  
  625.         mov     word [es:0x900A],ax              ; resolution X
  626.         mov     word [es:0x900C],bx              ; resolution Y
  627.         mov     word [es:0x9008],cx              ; number of mode
  628.  
  629. ;        cmp     cx,0x12
  630. ;        je      .mode0x12_0x13
  631. ;        cmp     cx,0x13
  632. ;        je      .mode0x12_0x13
  633.  
  634.  
  635. ;        cmp     byte [s_vesa.ver],'2'
  636. ;        jb      .vesa12
  637.  
  638. ;  VESA 2 and Vesa 3
  639.  
  640.         mov     ax,0x4f01
  641.         and     cx,0xfff
  642.         mov     di,mi;0xa000
  643.         int     0x10
  644.         ; LFB
  645.         mov     eax,[es:mi.PhysBasePtr];di+0x28]
  646.         mov     [es:0x9018],eax
  647.         ; ---- vbe voodoo
  648.         BytesPerLine equ 0x10
  649.         mov     ax, [es:di+BytesPerLine]
  650.         mov     [es:0x9001], ax
  651.         ; BPP
  652. ;        cmp     [es:mi.BitsPerPixel],16
  653. ;        jne     .l0
  654. ;        cmp     [es:mi.GreenMaskSize],5
  655. ;        jne     .l0
  656. ;        mov     [es:mi.BitsPerPixel],15
  657. .l0:
  658.         mov     al, byte [es:di+0x19]
  659.         mov     [es:0x9000], al
  660.         jmp     .exit
  661.  
  662. ;.mode0x12_0x13:
  663. ;        mov     byte [es:0x9000], 32
  664. ;        or      dword [es:0x9018], 0xFFFFFFFF; 0x800000
  665.  
  666.  
  667. ;  VESA 1.2 PM BANK SWITCH ADDRESS
  668.  
  669. ;.vesa12:
  670.  
  671.  
  672. ;        mov     ax,0x4f0A
  673. ;        xor     bx,bx
  674. ;        int     0x10
  675. ;        xor     eax,eax
  676. ;        xor     ebx,ebx
  677. ;        mov     ax,es
  678. ;        shl     eax,4
  679. ;        mov     bx,di
  680. ;        add     eax,ebx
  681. ;        movzx   ebx,word[es:di]
  682. ;        add     eax,ebx
  683. ;        push    0x0000
  684. ;        pop     es
  685. ;        mov     [es:0x9014],eax
  686.   .exit:
  687.         ret
  688.  
  689.  
  690. ;=============================================================================
  691.  
  692.