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ò)
檢查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