我完全是个初学者。目前,我只是在osdevwiki之后实现了键盘和vga屏幕。现在我想像这样画出合适的像素
void drawPixel(int x, int y, int rgb)用独立的C语言编写。现在,在vga模式下,打印文本和颜色的地址是0xB8000。要在屏幕上绘制像素,我该怎么做?我一点头绪都没有。
发布于 2018-12-14 17:42:57
文本模式在这里讨论:
https://wiki.osdev.org/Text_mode
这里有一个在文本模式下写一个彩色字符的例子:
void WriteCharacter(unsigned char c, unsigned char forecolour, unsigned char backcolour, int x, int y)
{
uint16_t attrib = (backcolour << 4) | (forecolour & 0x0F);
volatile uint16_t * where;
where = (volatile uint16_t *)0xB8000 + (y * 80 + x) ;
*where = c | (attrib << 8);
}如果您想要在图形模式下写入RGB像素,则必须首先切换到不同的视频模式。
这在这里有解释:
https://wiki.osdev.org/Drawing_In_Protected_Mode
下面是该页面中关于如何在图形模式下绘制像素的代码:
/* only valid for 800x600x16M */
static void putpixel(unsigned char* screen, int x,int y, int color) {
unsigned where = x*3 + y*2400;
screen[where] = color & 255; // BLUE
screen[where + 1] = (color >> 8) & 255; // GREEN
screen[where + 2] = (color >> 16) & 255; // RED
}
/* only valid for 800x600x32bpp */
static void putpixel(unsigned char* screen, int x,int y, int color) {
unsigned where = x*4 + y*3200;
screen[where] = color & 255; // BLUE
screen[where + 1] = (color >> 8) & 255; // GREEN
screen[where + 2] = (color >> 16) & 255; // RED
}基本上,您需要将三个颜色值写入三个字节,从视频内存开始,然后将偏移量乘以坐标乘以一些值,以获得正确的行和列。
对于不同的视频模式,这些值是不同的。
请注意,即使视频存储器地址对于VGA/CGA/EGA模式也不同!
发布于 2018-12-14 18:31:15
我使用此方法从文本模式绘制像素。将字符设置为空格字符,并使用颜色作为像素的颜色。
char* video = (char*)0xb8000;
video [0] = 0x20; // space character
video [1] = 0x12; // color of the pixelhttps://stackoverflow.com/questions/53776878
复制相似问题