最近做UI,我采用了VESA0x118画面模式(1024*768分辨率,8:8:8 24位真彩),写了以下程序:
void putcolor(char* buf, int xsize, int color, int x, int y)
{
buf[(y * xsize + x) * 3 + 0] = (char)(color >> 16);
buf[(y * xsize + x) * 3 + 1] = (char)(color >> 8);
buf[(y * xsize + x) * 3 + 2] = (char)(color >> 0);
return;
}
void boxfill(char* buf, int xsize, int color, int xfrom, int yfrom, int xto, int yto)
{
int x, y;
for (x = xfrom; x <= xto; x++)
{
for (y = yfrom; y <= yto; y++)
{
putcolor(buf, xsize, color, x, y);
}
}
return;
}
void init_screen(char* buf, int xsize, int ysize)
{
static char startbtn[20][22] = {
"......................",
"......................",
"......................",
".........****.........",
".......********.......",
"......***....***......",
".....**........**.***.",
".....**........**...**",
"....**..........*..**.",
"....**...........***..",
".**.**........****....",
"**..**....****........",
".**...****.....**.....",
"..****.........**.....",
"......***....***......",
".......********.......",
".........****.........",
"......................",
"......................",
"......................",
};
static char searchbtn[18][20] = {
"....................",
"....................",
"...........****.....",
"..........*....*....",
".........*......*...",
".........*......*...",
".........*......*...",
".........*......*...",
"..........*....*....",
"........**.****.....",
".......**...........",
"......**............",
".....**.............",
"....**..............",
"...**...............",
"....................",
"....................",
"....................",
};
int x, y;
boxfill8(buf, xsize, 0x0000ff, 0, 0, xsize - 1, ysize - 1);
boxfill8(buf, xsize, 0x000084, 0, ysize - 30, xsize - 1, ysize - 1);
//boxfill8(buf, xsize, 0x000000, 0, y - 30, x - 1, y - 30);
boxfill8(buf, xsize, 0x848484, 40, ysize - 23, 40, ysize - 7);
boxfill8(buf, xsize, 0x000000, 50, ysize - 25, 300, ysize - 5);
boxfill8(buf, xsize, 0x0000ff, 51, ysize - 24, 299, ysize - 6);
for (x = 0; x < 20; x++)
{
for (y = 0; y < 22; y++)
{
if (startbtn[x][y] == '*')
{
putcolor(buf, xsize, 0xffffff, 9 + y, ysize - 25 + x);
}
else
{
putcolor(buf, xsize, 0x000084, 9 + y, ysize - 25 + x);
}
}
}
for (x = 0; x < 18; x++)
{
for (y = 0; y < 20; y++)
{
if (searchbtn[x][y] == '*')
{
putcolor(buf, xsize, 0x000000, 55 + y, ysize - 24 + x);
}
else
{
putcolor(buf, xsize, 0xffffff, 55 + y, ysize - 24 + x);
}
}
}
return;
}
putcolor用于画点,boxfill用于画方块,init_screen初始化屏幕,最终调用init_screen。
结果全乱了
我为此苦恼了一个月,有哪位兄长可以帮帮忙?
环境:QEMU虚拟机