【问题标题】:OSDEV: How do i use vesa mode?OSDEV:我如何使用 vesa 模式?
【发布时间】:2020-06-21 23:25:10
【问题描述】:

您好,我正在尝试在我的操作系统中使用 vesa 模式,我正在使用本教程: Drawing In Protected Mode

我可以切换分辨率,但我不知道如何绘制像素。

这是我的代码:

kernel.asm

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

kernel.c

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

}

提前谢谢你

【问题讨论】:

  • 如何定义指向显存的指针?什么是对 putpixel 不起作用的示例调用?这不是minimal reproducible example
  • 多一点代码输入会很有帮助。

标签: c user-interface graphics osdev vesa


【解决方案1】:

首先,您是否使用 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

【讨论】:

    猜你喜欢
    • 2022-01-02
    • 2015-08-25
    • 2018-11-05
    • 2018-11-22
    • 2019-08-11
    • 2020-02-08
    • 2014-12-01
    • 2018-01-21
    • 2023-02-16
    相关资源
    最近更新 更多