首先,您是否使用 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 上苦苦挣扎,我想帮助那些也在苦苦挣扎的人。如果你想直接联系我寻求帮助,你可以在 discord 上加我,我可以尽我所能提供帮助。我的用户名和标签是:Yeon#7984