3.【VGA分辨率】

1、分辨率的設(shè)置在boot的時(shí)候,使用int 10h中斷可以設(shè)置
2、所以需要一種方式,將boot中設(shè)置的信息,傳遞到后面的c程序(前面的例子是寫死在程序里的)
3、這次我們使用變量(結(jié)構(gòu)體)來(lái)傳遞參數(shù)

1、BOOTINFO定義

// boot info:VGA圖形系統(tǒng)相關(guān)參數(shù)
typedef struct boot_info    {       /* 共 12 個(gè)字節(jié) */
    char    cyls;               
    char    leds;               
    char    vmode;              
    char    reserve;                    
    short   scrnx;
    short   scrny;  
    char    *vram;              
} __attribute__((packed)) BOOTINFO;

2、boot中BOOTINFO賦值

; 在boot中給c傳遞BOOTINFO參數(shù)
; // boot info:VGA圖形系統(tǒng)相關(guān)參數(shù)
; typedef struct boot_info  {       /* 共 12 個(gè)字節(jié) */
;   char    cyls;               
;   char    leds;               
;   char    vmode;              
;   char    reserve;                    
;   short   scrnx;
;   short   scrny;  
;   char    *vram;              
; } __attribute__((packed)) BOOTINFO;

; 結(jié)構(gòu)體的起始位置是0x0ff0
CYLS   equ  0x0ff0
LEDS   equ  0x0ff1
VMODE  equ  0x0ff2
SCRNX  equ  0x0ff4
SCRNY  equ  0x0ff6
VRAM   equ  0x0ff8
; 符號(hào)定義 ------------------------------------------------------------------------------------------------------------------------------------------------------
; 符號(hào)定義結(jié)束

  .......
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;設(shè)置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();                                                 // 初始化調(diào)色板
    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等價(jià)于struct boot_info;
BOOTINFO *binfo = (BOOTINFO *) 0x0ff0;等價(jià)于struct boot_info *binfo = (struct boot_info *) 0x0ff0;

提高分辨率

我的電腦屏幕分辨率是1920*1080,先設(shè)置成1280*768吧。

報(bào)錯(cuò)

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版本
  ; 符號(hào)定義 ------------------------------------------------------------------------------------------------------------------------------------------------------
BaseOfLoader            equ   09000h                  ; LOADER.BIN 被加載到的位置 ----  段地址
OffsetOfLoader          equ   0100h                   ; LOADER.BIN 被加載到的位置 ----  偏移地址
BeginSectorOfLoader     equ   2                       ; loader起始扇區(qū)放在2位置
SectorNumsOfLoader      equ   15                      ; loader占用扇區(qū)數(shù)

BaseOfKernelFile        equ   08000h                  ; KERNEL.BIN 被加載到的位置 ----  段地址
OffsetOfKernelFile      equ   0h                      ; KERNEL.BIN 被加載到的位置 ----  偏移地址
BeginSectorOfKernelFile equ   20                      ; KernelFile起始扇區(qū)放在2位置
SectorNumsOfKernelFile  equ   15                      ; KernelFile占用扇區(qū)數(shù)
; 符號(hào)定義 ------------------------------------------------------------------------------------------------------------------------------------------------------
; 符號(hào)定義結(jié)束

  org 7c00h
  mov ax, cs
  mov ds, ax
  mov es, ax
  
  mov dh,0 
  mov dl,0
  call SetLn
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VBE檢查-start
  ; 保存現(xiàn)場(chǎng)
  push ax
  push es
  push di
  
  mov ax, 0x9000
  mov es, ax
  mov di, 0
  mov ax, 0x4f00
  int 0x10
  
  ; 回復(fù)現(xiàn)場(chǎng)
  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,光標(biāo)行號(hào) 
  ;mov dl,光標(biāo)列號(hào) 
  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-實(shí)用編程技術(shù)
https://max.book118.com/html/2019/0107/5132014122002000.shtm

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容