mirror of
https://github.com/Leonmmcoset/cleonos.git
synced 2026-04-21 18:44:01 +00:00
初始化
This commit is contained in:
75
clks/drivers/video/font8x8.c
Normal file
75
clks/drivers/video/font8x8.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "font8x8.h"
|
||||
|
||||
#include <clks/types.h>
|
||||
|
||||
struct clks_glyph8x8 {
|
||||
char ch;
|
||||
u8 rows[8];
|
||||
};
|
||||
|
||||
static const struct clks_glyph8x8 clks_font_table[] = {
|
||||
{' ', {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
|
||||
{'[', {0x1E, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1E, 0x00}},
|
||||
{']', {0x78, 0x08, 0x08, 0x08, 0x08, 0x08, 0x78, 0x00}},
|
||||
{':', {0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00}},
|
||||
{'.', {0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00}},
|
||||
{'-', {0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00}},
|
||||
{'/', {0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00}},
|
||||
{'_', {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00}},
|
||||
{'?', {0x3C, 0x42, 0x02, 0x0C, 0x10, 0x00, 0x10, 0x00}},
|
||||
{'0', {0x3C, 0x42, 0x46, 0x4A, 0x52, 0x62, 0x3C, 0x00}},
|
||||
{'1', {0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00}},
|
||||
{'2', {0x3C, 0x42, 0x02, 0x0C, 0x30, 0x40, 0x7E, 0x00}},
|
||||
{'3', {0x3C, 0x42, 0x02, 0x1C, 0x02, 0x42, 0x3C, 0x00}},
|
||||
{'4', {0x0C, 0x14, 0x24, 0x44, 0x7E, 0x04, 0x04, 0x00}},
|
||||
{'5', {0x7E, 0x40, 0x7C, 0x02, 0x02, 0x42, 0x3C, 0x00}},
|
||||
{'6', {0x1C, 0x20, 0x40, 0x7C, 0x42, 0x42, 0x3C, 0x00}},
|
||||
{'7', {0x7E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x00}},
|
||||
{'8', {0x3C, 0x42, 0x42, 0x3C, 0x42, 0x42, 0x3C, 0x00}},
|
||||
{'9', {0x3C, 0x42, 0x42, 0x3E, 0x02, 0x04, 0x38, 0x00}},
|
||||
{'A', {0x18, 0x24, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x00}},
|
||||
{'B', {0x7C, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x7C, 0x00}},
|
||||
{'C', {0x3C, 0x42, 0x40, 0x40, 0x40, 0x42, 0x3C, 0x00}},
|
||||
{'D', {0x78, 0x44, 0x42, 0x42, 0x42, 0x44, 0x78, 0x00}},
|
||||
{'E', {0x7E, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x7E, 0x00}},
|
||||
{'F', {0x7E, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x00}},
|
||||
{'G', {0x3C, 0x42, 0x40, 0x4E, 0x42, 0x42, 0x3C, 0x00}},
|
||||
{'H', {0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x00}},
|
||||
{'I', {0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00}},
|
||||
{'J', {0x1E, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00}},
|
||||
{'K', {0x42, 0x44, 0x48, 0x70, 0x48, 0x44, 0x42, 0x00}},
|
||||
{'L', {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00}},
|
||||
{'M', {0x42, 0x66, 0x5A, 0x5A, 0x42, 0x42, 0x42, 0x00}},
|
||||
{'N', {0x42, 0x62, 0x52, 0x4A, 0x46, 0x42, 0x42, 0x00}},
|
||||
{'O', {0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00}},
|
||||
{'P', {0x7C, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x40, 0x00}},
|
||||
{'Q', {0x3C, 0x42, 0x42, 0x42, 0x4A, 0x44, 0x3A, 0x00}},
|
||||
{'R', {0x7C, 0x42, 0x42, 0x7C, 0x48, 0x44, 0x42, 0x00}},
|
||||
{'S', {0x3C, 0x42, 0x40, 0x3C, 0x02, 0x42, 0x3C, 0x00}},
|
||||
{'T', {0x7F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00}},
|
||||
{'U', {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00}},
|
||||
{'V', {0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00}},
|
||||
{'W', {0x42, 0x42, 0x42, 0x5A, 0x5A, 0x66, 0x42, 0x00}},
|
||||
{'X', {0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42, 0x00}},
|
||||
{'Y', {0x42, 0x42, 0x24, 0x18, 0x08, 0x08, 0x08, 0x00}},
|
||||
{'Z', {0x7E, 0x02, 0x04, 0x18, 0x20, 0x40, 0x7E, 0x00}},
|
||||
};
|
||||
|
||||
static const u8 clks_unknown[8] = {0x3C, 0x42, 0x02, 0x0C, 0x10, 0x00, 0x10, 0x00};
|
||||
|
||||
const u8 *clks_font8x8_get(char ch) {
|
||||
usize i;
|
||||
char upper = ch;
|
||||
|
||||
if (upper >= 'a' && upper <= 'z') {
|
||||
upper = (char)(upper - ('a' - 'A'));
|
||||
}
|
||||
|
||||
for (i = 0; i < (sizeof(clks_font_table) / sizeof(clks_font_table[0])); i++) {
|
||||
if (clks_font_table[i].ch == upper) {
|
||||
return clks_font_table[i].rows;
|
||||
}
|
||||
}
|
||||
|
||||
return clks_unknown;
|
||||
}
|
||||
8
clks/drivers/video/font8x8.h
Normal file
8
clks/drivers/video/font8x8.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef CLKS_FONT8X8_H
|
||||
#define CLKS_FONT8X8_H
|
||||
|
||||
#include <clks/types.h>
|
||||
|
||||
const u8 *clks_font8x8_get(char ch);
|
||||
|
||||
#endif
|
||||
95
clks/drivers/video/framebuffer.c
Normal file
95
clks/drivers/video/framebuffer.c
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <clks/framebuffer.h>
|
||||
#include <clks/string.h>
|
||||
#include <clks/types.h>
|
||||
|
||||
#include "font8x8.h"
|
||||
|
||||
struct clks_fb_state {
|
||||
volatile u8 *address;
|
||||
struct clks_framebuffer_info info;
|
||||
clks_bool ready;
|
||||
};
|
||||
|
||||
static struct clks_fb_state clks_fb = {
|
||||
.address = CLKS_NULL,
|
||||
.info = {0, 0, 0, 0},
|
||||
.ready = CLKS_FALSE,
|
||||
};
|
||||
|
||||
static void clks_fb_put_pixel(u32 x, u32 y, u32 rgb) {
|
||||
volatile u8 *row;
|
||||
volatile u32 *pixel;
|
||||
|
||||
if (clks_fb.ready == CLKS_FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x >= clks_fb.info.width || y >= clks_fb.info.height) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (clks_fb.info.bpp != 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
row = clks_fb.address + ((usize)y * (usize)clks_fb.info.pitch);
|
||||
pixel = (volatile u32 *)(row + ((usize)x * 4));
|
||||
*pixel = rgb;
|
||||
}
|
||||
|
||||
void clks_fb_init(const struct limine_framebuffer *fb) {
|
||||
if (fb == CLKS_NULL) {
|
||||
clks_fb.ready = CLKS_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
clks_fb.address = (volatile u8 *)fb->address;
|
||||
clks_fb.info.width = (u32)fb->width;
|
||||
clks_fb.info.height = (u32)fb->height;
|
||||
clks_fb.info.pitch = (u32)fb->pitch;
|
||||
clks_fb.info.bpp = fb->bpp;
|
||||
clks_fb.ready = CLKS_TRUE;
|
||||
}
|
||||
|
||||
clks_bool clks_fb_ready(void) {
|
||||
return clks_fb.ready;
|
||||
}
|
||||
|
||||
struct clks_framebuffer_info clks_fb_info(void) {
|
||||
return clks_fb.info;
|
||||
}
|
||||
|
||||
void clks_fb_clear(u32 rgb) {
|
||||
u32 x;
|
||||
u32 y;
|
||||
|
||||
if (clks_fb.ready == CLKS_FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < clks_fb.info.height; y++) {
|
||||
for (x = 0; x < clks_fb.info.width; x++) {
|
||||
clks_fb_put_pixel(x, y, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clks_fb_draw_char(u32 x, u32 y, char ch, u32 fg_rgb, u32 bg_rgb) {
|
||||
const u8 *glyph;
|
||||
u32 row;
|
||||
u32 col;
|
||||
|
||||
if (clks_fb.ready == CLKS_FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
glyph = clks_font8x8_get(ch);
|
||||
|
||||
for (row = 0; row < 8; row++) {
|
||||
for (col = 0; col < 8; col++) {
|
||||
u8 mask = (u8)(1U << (7U - col));
|
||||
u32 color = (glyph[row] & mask) != 0 ? fg_rgb : bg_rgb;
|
||||
clks_fb_put_pixel(x + col, y + row, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user