Subversion Repositories Kolibri OS

Rev

Rev 714 | Rev 731 | 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.         lfs     si, [es:vi.VideoModePtr]
  176.  
  177.         mov     bx,modes_table
  178. ;save no vesa mode of work 320x200, EGA/CGA 256 梥⮢ and 640x480, VGA 16 梥⮢
  179.         mov     word [es:bx],640
  180.         mov     word [es:bx+2],480
  181.         mov     word [es:bx+6],0x13
  182.        
  183.         mov     word [es:bx+10],640
  184.         mov     word [es:bx+12],480
  185.         mov     word [es:bx+16],0x12
  186.         add     bx,20
  187.   .next_mode:
  188.         mov     cx,word [fs:si] ; mode number
  189.         cmp     cx,-1
  190.         je      .modes_ok.2
  191.  
  192.         mov     ax,0x4F01
  193.         mov     di,mi
  194.         int     0x10
  195.  
  196.         or      ah,ah
  197.         jnz     .modes_ok.2;vesa_info.exit
  198.  
  199.         test    [es:mi.ModeAttributes],00000001b   ;videomode support ?
  200.         jz      @f
  201.         test    [es:mi.ModeAttributes],00010000b   ;picture ?
  202.         jz      @f
  203.         test    [es:mi.ModeAttributes],10000000b   ;LFB ?
  204.         jz      @f
  205.  
  206. ;        cmp     [es:mi.BitsPerPixel], 24
  207. ;        jb      @f
  208.  
  209.         cmp     [es:mi.BitsPerPixel],16
  210.         jne     .l0
  211.         cmp     [es:mi.GreenMaskSize],5
  212.         jne     .l0
  213.         mov     [es:mi.BitsPerPixel],15
  214.  
  215.  
  216.   .l0:
  217.         cmp     [es:mi.XRes],640
  218.         jb      @f
  219.         cmp     [es:mi.YRes],480
  220.         jb      @f
  221. ;        cmp     [es:mi.BitsPerPixel],8
  222. ;        jb      @f
  223.  
  224.         mov     ax,[es:mi.XRes]
  225.         mov     [es:bx+0],ax               ; +0[2] : resolution X
  226.         mov     ax,[es:mi.YRes]
  227.         mov     [es:bx+2],ax               ; +2[2] : resolution Y
  228.         mov     ax,[es:mi.ModeAttributes]
  229.         mov     [es:bx+4],ax               ; +4[2] : attributes
  230.  
  231.         cmp     [s_vesa.ver],'2'
  232.         jb      .lp1
  233.  
  234.         or      cx,0x4000  ; use LFB
  235.   .lp1: mov     [es:bx+6],cx               ; +6 : mode number
  236.         movzx   ax,byte [es:mi.BitsPerPixel]
  237.         mov     word [es:bx+8],ax               ; +8 : bits per pixel
  238.         add     bx,size_of_step
  239.  
  240.     @@:
  241.         add     si,2
  242.         jmp     .next_mode
  243.  
  244.   .modes_ok.2:
  245.  
  246.         mov     word[es:bx],-1  ;end video table
  247.         mov     word[end_cursor],bx     ;save end cursor position
  248. ;;;;;;;;;;;;;;;;;;
  249. ;Sort array
  250. ;        mov     si,modes_table
  251. ;.new_mode:
  252. ;        mov     ax,word [es:si]
  253. ;        cmp     ax,-1
  254. ;        je      .exxit
  255. ;        add     ax,word [es:si+2]
  256. ;        add     ax,word [es:si+8]
  257. ;        mov     bp,si
  258. ;.again:
  259. ;        add     bp,12
  260. ;        mov     bx,word [es:bp]
  261. ;        cmp     bx,-1
  262. ;        je      .exit
  263. ;        add     bx,word [es:bp+2]
  264. ;        add     bx,word [es:bp+8]
  265. ;        
  266. ;        cmp     ax,bx
  267. ;        ja      .loops
  268. ;        jmp     .again
  269. ;.loops:
  270. ;        push    dword [es:si]
  271. ;        push    dword [es:si+4]
  272. ;        push    dword [es:si+8]
  273. ;        push    dword [es:bp]
  274. ;        push    dword [es:bp+4]
  275. ;        push    dword [es:bp+8]
  276. ;
  277. ;        pop     dword [es:si+8]
  278. ;        pop     dword [es:si+4]
  279. ;        pop     dword [es:si]
  280. ;        pop     dword [es:bp+8]
  281. ;        pop     dword [es:bp+4]
  282. ;        pop     dword [es:bp]
  283. ;        jmp     .new_mode
  284. ;
  285. ;.exit:  add     si,12
  286. ;        jmp     .new_mode
  287. ;.exxit:
  288.         popad
  289.         ret
  290.  
  291. ;-----------------------------------------------------------------------------
  292.  
  293. draw_current_vmode:
  294.         push    0
  295.         pop     es
  296.  
  297.         mov     si,word [cursor_pos]
  298.  
  299.         cmp     word [es:si+6],0x12
  300.         je      .no_vesa_0x12
  301.  
  302.         cmp     word [es:si+6],0x13
  303.         je      .no_vesa_0x13
  304.  
  305.         mov     di,loader_block_error
  306.         movzx   eax,word[es:si+0]
  307.         mov     ecx,10
  308.         call    int2strnz
  309.         mov     byte[es:di],'x'
  310.         inc     di
  311.         movzx   eax,word[es:si+2]
  312.         call    int2strnz
  313.         mov     byte[es:di],'x'
  314.         inc     di
  315.         movzx   eax,word[es:si+8]
  316.         call    int2strnz
  317.         mov     dword[es:di],0x00000d0a
  318.         mov     si,loader_block_error
  319.         push    ds
  320.         push    es
  321.         pop     ds
  322.         call    printplain
  323.         pop     ds
  324.         ret
  325. .no_vesa_0x13:
  326.         mov     si,mode0
  327.         jmp     .print
  328. .no_vesa_0x12:
  329.         mov     si,mode9
  330. .print:
  331.         call    printplain
  332.         ret        
  333. ;-----------------------------------------------------------------------------
  334. check_first_parm:
  335.         mov     ax,word [preboot_graph]
  336.         test    ax,ax
  337.         jnz      .no_zero        ;if no zero
  338. .zerro:
  339. ;        mov     ax,modes_table
  340. ;        mov     word [cursor_pos],ax
  341. ;        mov     word [home_cursor],ax
  342. ;        mov     word [preboot_graph],ax
  343. ;SET default video of mode first probe will fined a move of work 1024x768@32
  344.  
  345.         mov     ax,1024
  346.         mov     bx,768
  347.         mov     si,modes_table
  348.         call    .loops
  349.         test    ax,ax
  350.         jz     .ok_found_mode
  351.         mov     ax,800
  352.         mov     bx,600
  353.         mov     si,modes_table
  354.         call    .loops
  355.         test    ax,ax
  356.         jz     .ok_found_mode
  357.         mov     ax,640
  358.         mov     bx,480
  359.         mov     si,modes_table
  360.         call    .loops
  361.         test    ax,ax
  362.         jz     .ok_found_mode
  363.  
  364.         mov     si,modes_table
  365.  
  366.  
  367. .ok_found_mode:
  368.         mov     word [home_cursor],si
  369. ;        mov     word [cursor_pos],si
  370.         mov     word [preboot_graph],si
  371.         mov     ax,si
  372.  
  373. .no_zero:
  374.         cmp     ax,modes_table
  375.         jb      .zerro           ;check on correct if bellow
  376.         cmp     ax,word [end_cursor]
  377.         ja      .zerro           ;check on correct if anymore
  378.  
  379.         mov     ecx,long_v_table
  380.  
  381. .loop:  add     ax,size_of_step
  382.         cmp     ax,word [end_cursor]
  383.         jae     .next_step
  384.         loop    .loop
  385. .next_step:
  386.         sub     ax,size_of_step*long_v_table
  387.         cmp     ax,modes_table
  388.         jb      .zerro
  389.  
  390.         mov     word[home_cursor],ax
  391.         push    word [preboot_graph]
  392.         pop     word [cursor_pos]
  393.         ret
  394. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  395. .loops:
  396.         cmp     ax,word [es:si]
  397.         jne     .next
  398.         cmp     bx,word [es:si+2]
  399.         jne     .next
  400.         cmp     word [es:si+8],32
  401.         je      .ok
  402.         cmp     word [es:si+8],24
  403.         je      .ok
  404. .next:  add     si,size_of_step
  405.         cmp     word [es:si],-1
  406.         je      .exit
  407.         jmp     .loops
  408. .ok:    xor     ax,ax        
  409. .exit:  ret
  410.  
  411.  
  412. ;-----------------------------------------------------------------------------
  413.  
  414. default_vmode:
  415.        
  416. ;-----------------------------------------------------------------------------
  417. draw_vmodes_table:
  418.         _setcursor 9, 2
  419.         mov     si,gr_mode
  420.         call    printplain
  421.  
  422.         mov     si,_st
  423.         call    printplain
  424.  
  425.         push    word [cursor_pos]
  426.         pop     ax
  427.         push    word [home_cursor]
  428.         pop     si
  429.         mov     cx,si
  430.  
  431.         cmp     ax,si
  432.         je      .ok
  433.         jb      .low
  434.  
  435.  
  436.         add     cx,size_of_step*long_v_table
  437.        
  438.         cmp     ax,cx
  439.         jb      .ok
  440.        
  441.         sub     cx,size_of_step*long_v_table
  442.         add     cx,size_of_step
  443.         cmp     cx,word[end_cursor]
  444.         jae     .ok
  445.         add     si,size_of_step
  446.         push    si
  447.         pop     word [home_cursor]
  448.         jmp     .ok
  449.  
  450.  
  451. .low:   sub     cx,size_of_step
  452.         cmp     cx,modes_table
  453.         jb      .ok
  454.         push    cx
  455.         push    cx
  456.         pop     word [home_cursor]
  457.         pop     si
  458.  
  459.  
  460. .ok:
  461.         mov     bp,long_v_table               ;show rows
  462. .@@_next_bit:
  463.         cmp     word [es:si+6],0x12
  464.         je      .show_0x12
  465.         cmp     word [es:si+6],0x13
  466.         je      .show_0x13
  467.  
  468.         movzx   eax,word[es:si]
  469.         cmp     ax,-1
  470.         je      .@@_end
  471.         mov     di,_rs+23          
  472.         mov     ecx,10
  473.         mov     bl,4
  474.         call    int2str
  475.         movzx   eax,word[es:si+2]
  476.         inc     di
  477.         mov     bl,4
  478.         call    int2str
  479.  
  480.         movzx   eax,word[es:si+8]
  481.         inc     di
  482.         mov     bl,2
  483.         call    int2str
  484. ;clear cursor
  485.         mov     word[ds:_r1+21],'  '
  486.         mov     word[ds:_r1+50],'  '
  487.  
  488.         mov     word[ds:_r2+21],'  '
  489.         mov     word[ds:_r2+45],'  '
  490.  
  491.         mov     word[ds:_rs+21],'  '
  492.         mov     word[ds:_rs+46],'  '
  493.  
  494.         cmp     si, word [cursor_pos]
  495.         jne     .next
  496. ;draw   cursor
  497.         mov     word[ds:_rs+21],'>>'
  498.         mov     word[ds:_rs+46],'<<'
  499.        
  500.  
  501.  
  502. .next:
  503.         push    si
  504.         mov     si,_rs
  505. .@@_sh:
  506.         call    printplain
  507.         pop     si
  508.         add     si,size_of_step
  509.  
  510.         dec     bp
  511.         jnz     .@@_next_bit
  512.  
  513. .@@_end:
  514.         mov     si,_bt
  515.         call    printplain
  516. ; show scroll
  517.         push    es
  518.         push    0xB800
  519.         pop     es
  520. ; arrows
  521.         mov     di, (11*80+53)*2
  522.         mov     al, 30
  523.         stosb
  524.         add     di, 80*2-1
  525.         mov     al, 32
  526.         mov     cx, 7
  527. @@:
  528.         stosb
  529.         add     di, 80*2-1
  530.         loop    @b
  531.         mov     al, 31
  532.         stosb
  533. ; calculate scroll size
  534.         mov     ax, [end_cursor]
  535.         sub     ax, modes_table
  536.         mov     bx, size_of_step
  537.         cwd
  538.         div     bx
  539.         mov     si, ax          ; si = size of list
  540.         mov     ax, [home_cursor]
  541.         sub     ax, modes_table
  542.         cwd
  543.         div     bx
  544.         mov     di, ax
  545.         mov     ax, 7*9
  546.         cwd
  547.         div     si
  548.         test    ax, ax
  549.         jnz     @f
  550.         inc     ax
  551. @@:
  552.         cmp     al, 7
  553.         jb      @f
  554.         mov     al, 7
  555. @@:
  556.         mov     cx, ax
  557. ; cx = scroll height
  558. ; calculate scroll pos
  559.         xor     bx, bx          ; initialize scroll pos
  560.         sub     al, 7+1
  561.         neg     al
  562.         sub     si, 9-1
  563.         jbe     .draw_scroll
  564.         mul     di
  565.         div     si
  566.         mov     bx, ax
  567. .draw_scroll:
  568.         mov     al, 0xDB
  569.         imul    di, bx, 80*2
  570.         add     di, (12*80+53)*2
  571. @@:
  572.         stosb
  573.         add     di, 80*2-1
  574.         loop    @b
  575.         pop     es
  576.         ret
  577. .show_0x13:
  578.         push    si
  579.  
  580.         cmp     si, word [cursor_pos]
  581.         jne     @f
  582.         mov     word[ds:_r1+21],'>>'
  583.         mov     word[ds:_r1+50],'<<'        
  584. @@:
  585.         mov     si,_r1
  586.         jmp     .@@_sh
  587. .show_0x12:
  588.         push    si
  589.         cmp     si, word [cursor_pos]
  590.         jne     @f
  591.  
  592.         mov     word[ds:_r2+21],'>>'
  593.         mov     word[ds:_r2+45],'<<'
  594. @@:
  595.         mov     si,_r2
  596.         jmp     .@@_sh
  597.  
  598. ;-----------------------------------------------------------------------------
  599. ;Clear arrea of current video page (0xb800)
  600. clear_vmodes_table:
  601.         pusha
  602.        ; draw frames
  603.         push    es
  604.         push    0xb800
  605.         pop     es
  606.         mov     di,1444
  607.         xor     ax,ax
  608.         mov     ah, 1*16+15
  609.         mov     cx,70
  610.         mov     bp,12
  611. .loop_start:
  612.         rep     stosw
  613.         mov     cx,70
  614.         add     di,20
  615.         dec     bp               ; 㬥­ìè¨âì DX,
  616.         jns        .loop_start      
  617.         pop     es
  618.         popa
  619.         ret
  620.  
  621. ;-----------------------------------------------------------------------------
  622.  
  623. set_vmode:
  624.         push    0 ;0;x1000
  625.         pop     es
  626.  
  627.         mov     si,word [preboot_graph]            ;[preboot_graph]
  628.         mov     cx,word [es:si+6]            ; number of mode
  629.        
  630.  
  631.         mov     ax,word [es:si+0]            ; resolution X
  632.         mov     bx,word [es:si+2]            ; resolution Y
  633.  
  634.  
  635.         mov     word [es:0x900A],ax              ; resolution X
  636.         mov     word [es:0x900C],bx              ; resolution Y
  637.         mov     word [es:0x9008],cx              ; number of mode
  638.  
  639.         cmp     cx,0x12
  640.         je      .mode0x12_0x13
  641.         cmp     cx,0x13
  642.         je      .mode0x12_0x13
  643.  
  644.  
  645.         cmp     byte [s_vesa.ver],'2'
  646.         jb      .vesa12
  647.  
  648. ;  VESA 2 and Vesa 3
  649.  
  650.         mov     ax,0x4f01
  651.         and     cx,0xfff
  652.         mov     di,mi;0xa000
  653.         int     0x10
  654.         ; LFB
  655.         mov     eax,[es:mi.PhysBasePtr];di+0x28]
  656.         mov     [es:0x9018],eax
  657.         ; ---- vbe voodoo
  658.         BytesPerLine equ 0x10
  659.         mov     ax, [es:di+BytesPerLine]
  660.         mov     [es:0x9001], ax
  661.         ; BPP
  662.         cmp     [es:mi.BitsPerPixel],16
  663.         jne     .l0
  664.         cmp     [es:mi.GreenMaskSize],5
  665.         jne     .l0
  666.         mov     [es:mi.BitsPerPixel],15
  667. .l0:
  668.         mov     al, byte [es:di+0x19]
  669.         mov     [es:0x9000], al
  670.         jmp     .exit
  671.  
  672. .mode0x12_0x13:
  673.         mov     byte [es:0x9000], 32
  674.         or      dword [es:0x9018], 0xFFFFFFFF; 0x800000
  675.  
  676.  
  677. ;  VESA 1.2 PM BANK SWITCH ADDRESS
  678.  
  679. .vesa12:
  680.  
  681.  
  682.         mov     ax,0x4f0A
  683.         xor     bx,bx
  684.         int     0x10
  685.         xor     eax,eax
  686.         xor     ebx,ebx
  687.         mov     ax,es
  688.         shl     eax,4
  689.         mov     bx,di
  690.         add     eax,ebx
  691.         movzx   ebx,word[es:di]
  692.         add     eax,ebx
  693.         push    0x0000
  694.         pop     es
  695.         mov     [es:0x9014],eax
  696.   .exit:
  697.         ret
  698.  
  699.  
  700. ;        mov     dword[es:0x9018],0x000A0000
  701. ;        ret
  702.  
  703. ;=============================================================================
  704. ;=============================================================================
  705. ;=============================================================================
  706.  
  707.