Change: font

This commit is contained in:
xamidev
2024-09-27 20:21:24 +02:00
parent 8a68cf3b30
commit 903188a543
6 changed files with 53 additions and 8 deletions

View File

@@ -7,9 +7,51 @@
#include "framebuffer.h"
#include "serial.h"
#include "../kernel/system.h"
#include "../kernel/kheap.h"
extern char* framebuffer;
void psf_init()
{
uint16_t glyph = 0;
PSF_font *font = (PSF_font*)&_binary_include_fonts_viscii10_8x16_psfu_start;
if (font->flags)
{
unicode = NULL;
return;
}
char* s = (char*)((unsigned char*)&_binary_include_fonts_viscii10_8x16_psfu_start + font->headersize + font->numglyph * font->bytesperglyph);
unicode = calloc(USHRT_MAX, 2);
while(s>_binary_include_fonts_viscii10_8x16_psfu_end){
uint16_t uc = (uint16_t)((unsigned char *)s[0]);
if(uc == 0xFF) {
glyph++;
s++;
continue;
} else if(uc & 128) {
/* UTF-8 to unicode */
if((uc & 32) == 0 ) {
uc = ((s[0] & 0x1F)<<6)+(s[1] & 0x3F);
s++;
} else
if((uc & 16) == 0 ) {
uc = ((((s[0] & 0xF)<<6)+(s[1] & 0x3F))<<6)+(s[2] & 0x3F);
s+=2;
} else
if((uc & 8) == 0 ) {
uc = ((((((s[0] & 0x7)<<6)+(s[1] & 0x3F))<<6)+(s[2] & 0x3F))<<6)+(s[3] & 0x3F);
s+=3;
} else
uc = 0;
}
/* save translation */
unicode[uc] = glyph;
s++;
}
}
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
{
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
@@ -18,13 +60,13 @@ void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
{
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyrExt_8x16_psf_start;
PSF_font *font = (PSF_font*)&_binary_include_fonts_viscii10_8x16_psfu_start;
int bytesperline=(font->width+7)/8;
if (unicode != NULL) {
c = unicode[c];
}
unsigned char* glyph = (unsigned char*)&_binary_include_fonts_UniCyrExt_8x16_psf_start + font->headersize + (c>0&&c<font->numglyph?c:0)*font->bytesperglyph;
unsigned char* glyph = (unsigned char*)&_binary_include_fonts_viscii10_8x16_psfu_start + font->headersize + (c>0&&c<font->numglyph?c:0)*font->bytesperglyph;
int offs =
(cy * font->height * scanline) +
@@ -54,7 +96,7 @@ void scroll()
{
serial_printf(3, "Scrolling...\r");
uint32_t bg_color = 0x00000000;
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyrExt_8x16_psf_start;
PSF_font *font = (PSF_font*)&_binary_include_fonts_viscii10_8x16_psfu_start;
int line_size = font->height * scanline;
int framebuffer_size = scanline * font->height * (1080/font->height);

View File

@@ -9,11 +9,13 @@
#include <stdint.h>
extern int scanline;
extern char _binary_include_fonts_UniCyrExt_8x16_psf_start;
uint16_t* unicode;
extern char _binary_include_fonts_viscii10_8x16_psfu_start;
extern char _binary_include_fonts_viscii10_8x16_psfu_end;
uint16_t* unicode;
#define PIXEL uint32_t
#define USHRT_MAX 10000
#define PSF1_FONT_MAGIC 0x0436
typedef struct {
@@ -38,5 +40,6 @@ typedef struct {
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
void scroll();
void psf_init();
#endif

View File

@@ -63,7 +63,7 @@ void kmain(multiboot2_info *mb_info)
serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch);
serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp);
}
psf_init();
printf("[kernel] multiboot2 info at 0x%x, size=%u\n", mb_info, mb_info->total_size);
printf("[kernel] framebuffer discovered at 0x%x\n", (unsigned int)fb_info->framebuffer_addr);
printf("[kernel] fb0: width=%u, height=%u, pitch=%u, bpp=%u\n", fb_info->framebuffer_width, fb_info->framebuffer_height, fb_info->framebuffer_pitch, fb_info->framebuffer_bpp);