Subversion Repositories Kolibri OS

Rev

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

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