首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OSDEV:我如何使用vesa模式?

OSDEV:我如何使用vesa模式?
EN

Stack Overflow用户
提问于 2020-03-10 03:44:56
回答 1查看 995关注 0票数 2

嗨,我试图在我的操作系统中使用vesa模式,我正在使用本教程:以保护方式绘制

我有分辨率切换,但我不知道如何画一个像素。

这是我的代码:

kernel.asm

代码语言:javascript
复制
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

代码语言:javascript
复制
#include "include/types.h"
kmain(){

}

先谢谢你

EN

回答 1

Stack Overflow用户

发布于 2020-11-10 03:12:27

首先,您是否使用grub和多重引导来加载内核?如果是这样的话,那么VESA信息(以及视频内存地址(也称为线性帧缓冲区地址)将被复制到您可以在"kernel.c“文件中访问的多引导头结构中。帧缓冲区地址存储在索引22处的结构中。如果您想要对multiboot及其结构的完整规范,您可以在这里查看它们:https://www.gnu.org/software/grub/manual/multiboot/multiboot.html

否则,您可以在"kernel.c“文件中这样做:

代码语言:javascript
复制
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”之后,这意味着# of 0000应该放在您的代码中,为: 0xFF0000。

希望这能帮上忙。我也和VESA做过斗争,我想帮助那些也在挣扎的人。如果你想直接联系我寻求帮助,你可以增加我的不和,我可以尽力帮助我。我的用户名和标签是: Yeon#7984

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60611275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档