Subversion Repositories Kolibri OS

Rev

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