簡體   English   中英

OSDEV:我如何使用 vesa 模式?

[英]OSDEV: How do i use vesa mode?

嗨,我正在嘗試在我的操作系統中使用 vesa 模式,我正在使用本教程:在保護模式下繪圖

我得到了要切換的分辨率,但我不知道如何繪制像素。

這是我的代碼:

內核文件

bits    32
section .text
align 4

dd 0x1BADB002
dd 0x04
dd -(0x1BADB002 + 0x04)

dd 0 ; skip some flags
dd 0
dd 0
dd 0
dd 0

dd 0 ; sets it to graphical mode
dd 800 ; sets the width
dd 600 ; sets the height
dd 32 ; sets the bits per pixel

push ebx
global start
extern kmain
start:
    cli
    call kmain
    hlt

內核文件

#include "include/types.h"
kmain(){

}

先感謝您

首先,您是否使用 grub 和 multiboot 來加載您的內核? 如果是這樣,那么 VESA 信息(連同視頻內存地址(也稱為線性幀緩沖區地址)將被復制到多重引導頭結構中,您可以在“kernel.c”文件中訪問該結構。幀緩沖區地址被存儲在索引 22 處的結構內。如果您想要有關 multiboot 及其結構的完整規范,您可以在此處查看它們: https : //www.gnu.org/software/grub/manual/multiboot/multiboot.html

否則,您可以在“kernel.c”文件中執行此操作:

void kmain(unsigned int* MultiBootHeaderStruct)
{
    //color code macros:
    #define red   0xFF0000
    #define green 0x00FF00
    #define blue  0x0000FF

    /*store the framebuffer address inside a new pointer
      the framebuffer is located at MultiBootHeaderStruct[22]*/
    unsigned int* framebuffer = (unsigned int*)MultiBootHeaderStruct[22];

    /*now to place a pixel at a specific screen position(screen index starts at 
      the top left of the screen which is at index 0), write a color value
      to the framebuffer pointer with a specified index*/
    
    //Sample Code:
    framebuffer[0] = red; //writes a red pixel(0xFF0000) at screen index 0
    framebuffer[1] = green; //writes a green pixel(0x00FF00) at screen index 1
    framebuffer[2] = blue; //writes a blue pixel(0x0000FF) at screen index 2
    /*this code should plot 3 pixels at the very top left of the screen
      one red, one green and one blue. If you want a specific color you can
      use the link I will provide at the bottom.*/

    
    //Sample code to fil the entire screen blue:
    int totalPixels = 480000; //800x600 = 480000 pixels total
    
    //loop through each pixel and write a blue color value to it
    for (int i = 0; i < totalPixels; i++)
    {
        framebuffer[i] = blue; //0x0000FF is the blue color value
    }
}

一個有用的顏色代碼生成器: https : //html-color-codes.info/注意。 不要使用放置在您生成的顏色前面的“#”主題標簽,只使用它后面的值並將顏色值放在代碼中的“0x”之后,這意味着 #FF0000 應該放在您的代碼中: 0xFF0000

我希望這有幫助。 我也與 VESA 斗爭過,我想幫助任何也在與它斗爭的人。 如果你想直接聯系我尋求幫助,你可以在不和諧中添加我,我可以盡我所能提供幫助。 我的用戶名和標簽是:Yeon#7984

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM