美文网首页
3.【VGA分辨率】

3.【VGA分辨率】

作者: 月下蓑衣江湖夜雨 | 来源:发表于2021-01-04 20:20 被阅读0次

    1、分辨率的设置在boot的时候,使用int 10h中断可以设置
    2、所以需要一种方式,将boot中设置的信息,传递到后面的c程序(前面的例子是写死在程序里的)
    3、这次我们使用变量(结构体)来传递参数

    1、BOOTINFO定义

    // boot info:VGA图形系统相关参数
    typedef struct boot_info    {       /* 共 12 个字节 */
        char    cyls;               
        char    leds;               
        char    vmode;              
        char    reserve;                    
        short   scrnx;
        short   scrny;  
        char    *vram;              
    } __attribute__((packed)) BOOTINFO;
    

    2、boot中BOOTINFO赋值

    ; 在boot中给c传递BOOTINFO参数
    ; // boot info:VGA图形系统相关参数
    ; typedef struct boot_info  {       /* 共 12 个字节 */
    ;   char    cyls;               
    ;   char    leds;               
    ;   char    vmode;              
    ;   char    reserve;                    
    ;   short   scrnx;
    ;   short   scrny;  
    ;   char    *vram;              
    ; } __attribute__((packed)) BOOTINFO;
    
    ; 结构体的起始位置是0x0ff0
    CYLS   equ  0x0ff0
    LEDS   equ  0x0ff1
    VMODE  equ  0x0ff2
    SCRNX  equ  0x0ff4
    SCRNY  equ  0x0ff6
    VRAM   equ  0x0ff8
    ; 符号定义 ------------------------------------------------------------------------------------------------------------------------------------------------------
    ; 符号定义结束
    
      .......
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;设置VGA图形格式
      mov al, 0x13
      mov ah, 0x00
      int 0x10
      ; 记录画面模式
      mov  BYTE[VMODE], 8
      mov  WORD[SCRNX], 320
      mov  WORD[SCRNY], 200
      mov  DWORD[VRAM], 0x000a0000
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    

    3、c中读取

    // 绘制屏幕
    void init_screen(){
        BOOTINFO *binfo = (BOOTINFO *) 0x0ff0;                          // 在boot中写入
            
        init_palette();                                                 // 初始化调色板
        draw_ui(binfo->scrnx, binfo->scrny, binfo->vram);               // 绘制ui
        putfont8(binfo->vram, binfo->scrnx, 8, 8, COL8_FFFFFF, font_A); // 打印字符A
    }
    

    typedef struct boot_info {} BOOTINFO定义的好处就是BOOTINFO等价于struct boot_info;
    BOOTINFO *binfo = (BOOTINFO *) 0x0ff0;等价于struct boot_info *binfo = (struct boot_info *) 0x0ff0;

    提高分辨率

    我的电脑屏幕分辨率是1920*1080,先设置成1280*768吧。

    报错

    VirtualBox限制:https://blog.csdn.net/ztynet/article/details/53438982?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

    检查VBE是否存在

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 检查VBE版本
      ; 符号定义 ------------------------------------------------------------------------------------------------------------------------------------------------------
    BaseOfLoader            equ   09000h                  ; LOADER.BIN 被加载到的位置 ----  段地址
    OffsetOfLoader          equ   0100h                   ; LOADER.BIN 被加载到的位置 ----  偏移地址
    BeginSectorOfLoader     equ   2                       ; loader起始扇区放在2位置
    SectorNumsOfLoader      equ   15                      ; loader占用扇区数
    
    BaseOfKernelFile        equ   08000h                  ; KERNEL.BIN 被加载到的位置 ----  段地址
    OffsetOfKernelFile      equ   0h                      ; KERNEL.BIN 被加载到的位置 ----  偏移地址
    BeginSectorOfKernelFile equ   20                      ; KernelFile起始扇区放在2位置
    SectorNumsOfKernelFile  equ   15                      ; KernelFile占用扇区数
    ; 符号定义 ------------------------------------------------------------------------------------------------------------------------------------------------------
    ; 符号定义结束
    
      org 7c00h
      mov ax, cs
      mov ds, ax
      mov es, ax
      
      mov dh,0 
      mov dl,0
      call SetLn
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VBE检查-start
      ; 保存现场
      push ax
      push es
      push di
      
      mov ax, 0x9000
      mov es, ax
      mov di, 0
      mov ax, 0x4f00
      int 0x10
      
      ; 回复现场
      pop di
      pop es
      pop ax
      
      cmp ax, 0x004f
      jne scrn320                    ; 不相等即为不支持VBE
      
      mov ax, BootMsgSupportVBE
      mov cx, 18
      call DspStr
      jmp $
    
    scrn320:
      mov ax, BootMsgNotSupportVBE
      mov cx, 18
      call DspStr
      jmp $
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VBE检查-end
      ;mov ax, BootMsg1
      ;mov cx, 18
      ;call DspStr
      
      jmp $
    
    SetLn:
      mov ah,2 
      mov bh,0 
      ;mov dh,光标行号 
      ;mov dl,光标列号 
      int 10h 
      
      ret  
    
    DspStr:
      mov bp, ax
      mov ax, 01301h
      mov bx, 000ch
      mov dl, 0
      int 10h
    
      ret
      
    BootMsgNotSupportVBE:             db  "[not support VBE]!"
    BootMsgSupportVBE:                db  "[Support VBE]!!!!!"  
    
    times 510 - ($ - $$) db  0
    dw 0xaa55
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
    
    VirtualBox不支持VBE!!

    dd if=boot_reset.com of=D

    VGA-实用编程技术
    https://max.book118.com/html/2019/0107/5132014122002000.shtm

    相关文章

      网友评论

          本文标题:3.【VGA分辨率】

          本文链接:https://www.haomeiwen.com/subject/dktuoktx.html