Subversion Repositories Kolibri OS

Rev

Rev 731 | Rev 746 | 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.         jae     @f
  390.         mov     ax,modes_table
  391. @@:
  392.  
  393.         mov     word[home_cursor],ax
  394.         push    word [preboot_graph]
  395.         pop     word [cursor_pos]
  396.         ret
  397. ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  398. .loops:
  399.         cmp     ax,word [es:si]
  400.         jne     .next
  401.         cmp     bx,word [es:si+2]
  402.         jne     .next
  403.         cmp     word [es:si+8],32
  404.         je      .ok
  405.         cmp     word [es:si+8],24
  406.         je      .ok
  407. .next:  add     si,size_of_step
  408.         cmp     word [es:si],-1
  409.         je      .exit
  410.         jmp     .loops
  411. .ok:    xor     ax,ax        
  412. .exit:  ret
  413.  
  414.  
  415. ;-----------------------------------------------------------------------------
  416.  
  417. default_vmode:
  418.        
  419. ;-----------------------------------------------------------------------------
  420. draw_vmodes_table:
  421.         _setcursor 9, 2
  422.         mov     si,gr_mode
  423.         call    printplain
  424.  
  425.         mov     si,_st
  426.         call    printplain
  427.  
  428.         push    word [cursor_pos]
  429.         pop     ax
  430.         push    word [home_cursor]
  431.         pop     si
  432.         mov     cx,si
  433.  
  434.         cmp     ax,si
  435.         je      .ok
  436.         jb      .low
  437.  
  438.  
  439.         add     cx,size_of_step*long_v_table
  440.        
  441.         cmp     ax,cx
  442.         jb      .ok
  443.        
  444.         sub     cx,size_of_step*long_v_table
  445.         add     cx,size_of_step
  446.         cmp     cx,word[end_cursor]
  447.         jae     .ok
  448.         add     si,size_of_step
  449.         push    si
  450.         pop     word [home_cursor]
  451.         jmp     .ok
  452.  
  453.  
  454. .low:   sub     cx,size_of_step
  455.         cmp     cx,modes_table
  456.         jb      .ok
  457.         push    cx
  458.         push    cx
  459.         pop     word [home_cursor]
  460.         pop     si
  461.  
  462.  
  463. .ok:
  464.         mov     bp,long_v_table               ;show rows
  465. .@@_next_bit:
  466.         cmp     word [es:si+6],0x12
  467.         je      .show_0x12
  468.         cmp     word [es:si+6],0x13
  469.         je      .show_0x13
  470.  
  471.         movzx   eax,word[es:si]
  472.         cmp     ax,-1
  473.         je      .@@_end
  474.         mov     di,_rs+23          
  475.         mov     ecx,10
  476.         mov     bl,4
  477.         call    int2str
  478.         movzx   eax,word[es:si+2]
  479.         inc     di
  480.         mov     bl,4
  481.         call    int2str
  482.  
  483.         movzx   eax,word[es:si+8]
  484.         inc     di
  485.         mov     bl,2
  486.         call    int2str
  487. ;clear cursor
  488.         mov     word[ds:_r1+21],'  '
  489.         mov     word[ds:_r1+50],'  '
  490.  
  491.         mov     word[ds:_r2+21],'  '
  492.         mov     word[ds:_r2+45],'  '
  493.  
  494.         mov     word[ds:_rs+21],'  '
  495.         mov     word[ds:_rs+46],'  '
  496.  
  497.         cmp     si, word [cursor_pos]
  498.         jne     .next
  499. ;draw   cursor
  500.         mov     word[ds:_rs+21],'>>'
  501.         mov     word[ds:_rs+46],'<<'
  502.        
  503.  
  504.  
  505. .next:
  506.         push    si
  507.         mov     si,_rs
  508. .@@_sh:
  509.         call    printplain
  510.         pop     si
  511.         add     si,size_of_step
  512.  
  513.         dec     bp
  514.         jnz     .@@_next_bit
  515.  
  516. .@@_end:
  517.         mov     si,_bt
  518.         call    printplain
  519. ; show scroll
  520.         push    es
  521.         push    0xB800
  522.         pop     es
  523. ; arrows
  524.         mov     di, (11*80+53)*2
  525.         mov     al, 30
  526.         stosb
  527.         add     di, 80*2-1
  528.         mov     al, 32
  529.         mov     cx, scroll_area_size
  530. @@:
  531.         stosb
  532.         add     di, 80*2-1
  533.         loop    @b
  534.         mov     al, 31
  535.         stosb
  536. ; calculate scroll size
  537.         mov     ax, [end_cursor]
  538.         sub     ax, modes_table
  539.         mov     bx, size_of_step
  540.         cwd
  541.         div     bx
  542.         mov     si, ax          ; si = size of list
  543.         mov     ax, [home_cursor]
  544.         sub     ax, modes_table
  545.         cwd
  546.         div     bx
  547.         mov     di, ax
  548.         mov     ax, scroll_area_size*long_v_table
  549.         cwd
  550.         div     si
  551.         test    ax, ax
  552.         jnz     @f
  553.         inc     ax
  554. @@:
  555.         cmp     al, scroll_area_size
  556.         jb      @f
  557.         mov     al, scroll_area_size
  558. @@:
  559.         mov     cx, ax
  560. ; cx = scroll height
  561. ; calculate scroll pos
  562.         xor     bx, bx          ; initialize scroll pos
  563.         sub     al, scroll_area_size+1
  564.         neg     al
  565.         sub     si, long_v_table-1
  566.         jbe     .draw_scroll
  567.         mul     di
  568.         div     si
  569.         mov     bx, ax
  570. .draw_scroll:
  571.         mov     al, 0xDB
  572.         imul    di, bx, 80*2
  573.         add     di, (12*80+53)*2
  574. @@:
  575.         stosb
  576.         add     di, 80*2-1
  577.         loop    @b
  578.         pop     es
  579.         ret
  580. .show_0x13:
  581.         push    si
  582.  
  583.         cmp     si, word [cursor_pos]
  584.         jne     @f
  585.         mov     word[ds:_r1+21],'>>'
  586.         mov     word[ds:_r1+50],'<<'        
  587. @@:
  588.         mov     si,_r1
  589.         jmp     .@@_sh
  590. .show_0x12:
  591.         push    si
  592.         cmp     si, word [cursor_pos]
  593.         jne     @f
  594.  
  595.         mov     word[ds:_r2+21],'>>'
  596.         mov     word[ds:_r2+45],'<<'
  597. @@:
  598.         mov     si,_r2
  599.         jmp     .@@_sh
  600.  
  601. ;-----------------------------------------------------------------------------
  602. ;Clear arrea of current video page (0xb800)
  603. clear_vmodes_table:
  604.         pusha
  605.        ; draw frames
  606.         push    es
  607.         push    0xb800
  608.         pop     es
  609.         mov     di,1444
  610.         xor     ax,ax
  611.         mov     ah, 1*16+15
  612.         mov     cx,70
  613.         mov     bp,12
  614. .loop_start:
  615.         rep     stosw
  616.         mov     cx,70
  617.         add     di,20
  618.         dec     bp               ; 㬥­ìè¨âì DX,
  619.         jns        .loop_start      
  620.         pop     es
  621.         popa
  622.         ret
  623.  
  624. ;-----------------------------------------------------------------------------
  625.  
  626. set_vmode:
  627.         push    0 ;0;x1000
  628.         pop     es
  629.  
  630.         mov     si,word [preboot_graph]            ;[preboot_graph]
  631.         mov     cx,word [es:si+6]            ; number of mode
  632.        
  633.  
  634.         mov     ax,word [es:si+0]            ; resolution X
  635.         mov     bx,word [es:si+2]            ; resolution Y
  636.  
  637.  
  638.         mov     word [es:0x900A],ax              ; resolution X
  639.         mov     word [es:0x900C],bx              ; resolution Y
  640.         mov     word [es:0x9008],cx              ; number of mode
  641.  
  642.         cmp     cx,0x12
  643.         je      .mode0x12_0x13
  644.         cmp     cx,0x13
  645.         je      .mode0x12_0x13
  646.  
  647.  
  648.         cmp     byte [s_vesa.ver],'2'
  649.         jb      .vesa12
  650.  
  651. ;  VESA 2 and Vesa 3
  652.  
  653.         mov     ax,0x4f01
  654.         and     cx,0xfff
  655.         mov     di,mi;0xa000
  656.         int     0x10
  657.         ; LFB
  658.         mov     eax,[es:mi.PhysBasePtr];di+0x28]
  659.         mov     [es:0x9018],eax
  660.         ; ---- vbe voodoo
  661.         BytesPerLine equ 0x10
  662.         mov     ax, [es:di+BytesPerLine]
  663.         mov     [es:0x9001], ax
  664.         ; BPP
  665.         cmp     [es:mi.BitsPerPixel],16
  666.         jne     .l0
  667.         cmp     [es:mi.GreenMaskSize],5
  668.         jne     .l0
  669.         mov     [es:mi.BitsPerPixel],15
  670. .l0:
  671.         mov     al, byte [es:di+0x19]
  672.         mov     [es:0x9000], al
  673.         jmp     .exit
  674.  
  675. .mode0x12_0x13:
  676.         mov     byte [es:0x9000], 32
  677.         or      dword [es:0x9018], 0xFFFFFFFF; 0x800000
  678.  
  679.  
  680. ;  VESA 1.2 PM BANK SWITCH ADDRESS
  681.  
  682. .vesa12:
  683.  
  684.  
  685.         mov     ax,0x4f0A
  686.         xor     bx,bx
  687.         int     0x10
  688.         xor     eax,eax
  689.         xor     ebx,ebx
  690.         mov     ax,es
  691.         shl     eax,4
  692.         mov     bx,di
  693.         add     eax,ebx
  694.         movzx   ebx,word[es:di]
  695.         add     eax,ebx
  696.         push    0x0000
  697.         pop     es
  698.         mov     [es:0x9014],eax
  699.   .exit:
  700.         ret
  701.  
  702.  
  703. ;        mov     dword[es:0x9018],0x000A0000
  704. ;        ret
  705.  
  706. ;=============================================================================
  707. ;=============================================================================
  708. ;=============================================================================
  709.  
  710.