提交 6ca8a7e6 编写于 作者: 指向BIOS的野指针's avatar 指向BIOS的野指针

add guilog:

known bug, error causes when output new line char
上级 a1b1fd8d
#ifndef __fonts_hh_
#define __fonts_hh_
namespace font
{
char consolas[256][16] = {
//带 ‘//' 的是基准线
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{
// space
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000, //
0b00000000,
0b00000000,
0b00000000,
0b00000000,
},
{
// !
0b00000000,
0b00000000,
0b00011000,
0b00011000,
0b00011000,
0b00011000,
0b00011000,
0b00011000,
0b00011000,
0b00011000,
0b00000000,
0b00011000, //
0b00011000,
0b00000000,
0b00000000,
0b00000000,
},
{
//"
0b00000000,
0b00110110,
0b00110110,
0b00110110,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000,
0b00000000, //
0b00000000,
0b00000000,
0b00000000,
0b00000000,
},
};
};
#endif
#include "guilog.hh"
#include "fonts.hh"
#include "update.hh"
#include "../dbg/logs.hh"
#include <unistd.h>
#include <thread>
namespace bwl
{
uint32_t *logbuffer;
uint64_t size[2];
void initGUILog(uint32_t *buffer, uint64_t width, uint64_t height)
extern __updating_signals __ud;
uint32_t *logbuffer; //缓冲区
uint64_t size[2]; //缓冲区大小
uint64_t cursor[2]; //光标位置
uint8_t cursor_move; //光标刷新标志
uint32_t color; //输出颜色
uint32_t bgcolor; //背景颜色
std::thread *cursor_flash; //光标刷新线程
#define buffer_at(buffer, x, y) ((uint32_t *)buffer)[x + y * size[0]]
void initGUILog(uint32_t *buffer, uint64_t width, uint64_t height, uint32_t __bgcolor)
{
bwl::log("initGUILog");
logbuffer = buffer; //初始化缓冲区
size[0] = width; //宽度
size[1] = height; //高度
cursor[0] = 0; //光标x
cursor[1] = 0; //光标y
bgcolor = __bgcolor; //背景颜色
color = 0x00ffffff; //文字颜色
cursor_move = true;
cursor_flash = new std::thread(cursorFlasher); //开启光标刷新线程
bwl::log("init succeeded");
putString("GUILog initialized!\n\"hello\"");
}
void clear()
{
for (int i = 0; i < size[0]; i++)
for (int j = 0; j < size[1]; j++)
{
buffer_at(logbuffer, i, j) = bgcolor;
}
//推送更新块
__updating_signals::bg ub;
ub.sig = true;
ub.pos[0] = -1;
__ud.bg_update_que.push(ub);
}
void cursorFlasher()
{
__updating_signals::bg ub;
bwl::log("flasher run");
while (1)
{
usleep(1000);
while (cursor_move)
{
bwl::log("flashing");
//绘制亮的光标
for (int i = 0; i < 8; i++)
{
buffer_at(logbuffer, cursor[0] * 8 + i, cursor[1] * 16 + 12) = 0x00ffffff;
buffer_at(logbuffer, cursor[0] * 8 + i, cursor[1] * 16 + 13) = 0x00ffffff;
}
//推送更新块
ub.sig = true;
ub.pos[0] = cursor[0] * 8;
ub.pos[1] = cursor[1] * 16;
ub.size[0] = 8;
ub.size[1] = 16;
__ud.bg_update_que.push(ub);
if (!cursor_move)
continue;
usleep(500000);
if (!cursor_move)
continue;
bwl::log("flashing");
//绘制暗的光标
for (int i = 0; i < 8; i++)
{
buffer_at(logbuffer, cursor[0] * 8 + i, cursor[1] * 16 + 12) = bgcolor;
buffer_at(logbuffer, cursor[0] * 8 + i, cursor[1] * 16 + 13) = bgcolor;
}
//推送更新块
ub.sig = true;
ub.pos[0] = cursor[0] * 8;
ub.pos[1] = cursor[1] * 16;
ub.size[0] = 8;
ub.size[1] = 16;
__ud.bg_update_que.push(ub);
if (!cursor_move)
continue;
usleep(500000);
}
}
}
void paintChar(uint64_t x, uint64_t y, char c)
{
bwl::log(std::string("drawing:") + c);
__updating_signals::bg ub;
char *character = font::consolas[c]; //获取对应字符的位图
//按照位图的01显示
for (int j = 0; j < 16; j++)
for (int i = 0; i < 8; i++)
{
if (character[j] & (1 << (7 - i)))
buffer_at(logbuffer, x + i, y + j) = color;
else
buffer_at(logbuffer, x + i, y + j) = bgcolor;
}
//推送更新块
ub.sig = true;
ub.pos[0] = x;
ub.pos[1] = y;
ub.size[0] = 8;
ub.size[1] = 16;
__ud.bg_update_que.push(ub);
}
void putChar(char c)
{
cursor_move = false; //停止光标线程刷新
if (c == '\n') //换行符检测
{
cursor[0] = 0;
cursor[1]++;
cursor_move = true;
return;
}
bwl::log(std::string("pos:") + std::to_string(cursor[0]) + "," + std::to_string(cursor[1]));
paintChar(cursor[0] * 8, cursor[1] * 16, c); //将字符绘制出来
cursor[0]++; //光标后移
if ((1 + cursor[0]) * 8 > size[0]) //检测行末
{
cursor[0] = 0;
cursor[1]++;
}
if ((1 + cursor[1]) * 16 > size[1]) //检测页尾
{
cursor[0] = 0;
cursor[1] = 0;
clear();
}
cursor_move = true; //继续光标刷新
}
void putString(const char *__str)
{
logbuffer = buffer;
size[0] = width;
size[1] = height;
int i = 0;
while (__str[i])
{
putChar(__str[i]);
i++;
}
}
};
......@@ -7,12 +7,45 @@ namespace bwl
{
/**
* @brief 初始化guilog模块
*
*
* @param buffer 缓冲区
* @param width 宽度
* @param height 高度
*/
void initGUILog(uint32_t *buffer, uint64_t width, uint64_t height);
void initGUILog(uint32_t *buffer, uint64_t width, uint64_t height, uint32_t __bgcolor);
/**
* @brief 清空屏幕
*
*/
void clear();
/**
* @brief 光标刷新
*
*/
void cursorFlasher();
/**
* @brief 设置出书颜色
*
* @param color 颜色
*/
void setColor(uint32_t color);
/**
* @brief 输出一个字符
*
* @param c
*/
void putChar(char c);
/**
* @brief 输出字符串
*
* @param __str
*/
void putString(const char *__str);
};
#endif
......@@ -39,7 +39,7 @@ int main(int argc, char **argv)
bwl::log("starting bad wayland server.");
start_bwl_server();
bwl::log("OK");
sleep(3);
sleep(7);
bwl::destoryDisplay();
bwl::bwl_exit(0);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册