generated from PoCInnovation/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] psf font basic string implementation #2
- Loading branch information
1 parent
e1e3092
commit 2505bbd
Showing
12 changed files
with
262 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.o | ||
*.bin | ||
build/boot/grub/grub.cfg | ||
modos.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** ModOS | ||
** File description: | ||
** config.h | ||
*/ | ||
|
||
// TODO: implement config structure instead of macros so that it can be changed at runtime | ||
#ifndef CONFIG_H_ | ||
#define CONFIG_H_ | ||
#define TEXT_COLOR 0xffffff | ||
#define BACKGROUND_COLOR 0x111111 | ||
|
||
#endif /* !CONFIG_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
PORT=4444 | ||
HOST=localhost | ||
DELAY=1 | ||
|
||
while true; do | ||
clear | ||
echo "Connecting to QEMU serial port at $HOST:$PORT..." | ||
nc $HOST $PORT | ||
echo "Disconnected from QEMU serial port." | ||
echo "Reconnecting in $DELAY seconds..." | ||
sleep $DELAY | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,101 @@ | ||
#include "../include/font.h" | ||
#include "../include/kernel.h" | ||
#include "../include/pixel.h" | ||
#include "stddef.h" | ||
|
||
uint16_t *unicode; | ||
|
||
// NOTE: Optional unicode decoding | ||
// Needs calloc which we don't have right now. | ||
// | ||
// void psf_init() | ||
// { | ||
// uint16_t glyph = 0; | ||
// psf_font_t *font = (psf_font_t*)&font_start; | ||
// | ||
// if (font->flags) { | ||
// unicode = NULL; | ||
// return; | ||
// } | ||
// | ||
// char *s = (char *)( | ||
// (unsigned char*)&font_start + | ||
// font->headersize + | ||
// font->numglyph * font->bytesperglyph | ||
// ); | ||
// unicode = calloc(USHRT_MAX, 2); | ||
// while(s>_binary_zap_ext_light32_psf_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; | ||
// } | ||
// unicode[uc] = glyph; | ||
// s++; | ||
// } | ||
// } | ||
|
||
/** | ||
* @brief Unicode putchar | ||
* | ||
* @param c This is an int, not char as it's a unicode character | ||
* @param cx Horizontal position on screen, in characters not in pixels | ||
* @param cy Vertical position on screen, in characters not in pixels | ||
* @param fg ARGB foreground color | ||
* @param bg ARGB background color | ||
*/ | ||
void __os_putchar( | ||
unsigned short int c, | ||
int cx, int cy, | ||
uint32_t fg, uint32_t bg, | ||
psf_font_t *font, | ||
uint8_t *font_start) | ||
{ | ||
uint32_t bytesperline = (font->width + 7) / 8; | ||
|
||
if (unicode != NULL) { | ||
c = unicode[c]; | ||
} | ||
|
||
uint8_t *glyph = | ||
(uint8_t *)font_start + font->headersize + | ||
(c > 0 && c < font->numglyph ? c : 0) * font->bytesperglyph; | ||
uint32_t offset = (cy * font->height * framebuffer_pitch) + | ||
(cx * font->width * sizeof(argb_pixel_t)); | ||
|
||
for (uint32_t y = 0; y < font->height; y++) { | ||
uint32_t line = offset; | ||
uint8_t *glyph_row = glyph + y * bytesperline; | ||
uint32_t bits_left = font->width; | ||
|
||
for (uint32_t b = 0; b < bytesperline; b++) { | ||
uint8_t byte = glyph_row[b]; | ||
|
||
for (int bit = 7; bit >= 0 && bits_left > 0; bit--) { | ||
uint32_t color = (byte & (1 << bit)) ? fg : bg; | ||
|
||
*((argb_pixel_t *)(framebuffer + line)) = color; | ||
|
||
line += sizeof(argb_pixel_t); | ||
bits_left--; | ||
} | ||
} | ||
offset += framebuffer_pitch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,93 @@ | ||
#include "../include/string.h" | ||
#include "../include/kernel.h" | ||
|
||
void putchar(char c) { | ||
uint32_t cx, cy = 0; | ||
psf_font_t *font = (psf_font_t *)&_binary_zap_ext_light32_psf_start; | ||
|
||
void putchar(uint32_t unicode_char) | ||
{ | ||
if (unicode_char == '\n') { | ||
cx = 0; ++cy; | ||
return; | ||
} | ||
__os_putchar(unicode_char, cx, cy, TEXT_COLOR, BACKGROUND_COLOR, font, (uint8_t *)&_binary_zap_ext_light32_psf_start); | ||
if (++cx > (uint32_t)framebuffer_pitch / font->bytesperglyph) { | ||
cx = 0; ++cy; | ||
} | ||
} | ||
|
||
void put_uint(uint32_t value) | ||
{ | ||
char buffer[11]; | ||
int i = 10; | ||
buffer[i] = '\0'; | ||
|
||
if (value == 0) { | ||
putchar('0'); | ||
return; | ||
} | ||
|
||
while (value > 0 && i > 0) { | ||
buffer[--i] = '0' + (value % 10); | ||
value /= 10; | ||
} | ||
|
||
puts(&buffer[i]); | ||
} | ||
|
||
|
||
void put_uint_hex(uint32_t value) | ||
{ | ||
char buffer[9]; | ||
const char *hex_chars = "0123456789abcdef"; | ||
int i = 8; | ||
buffer[i] = '\0'; | ||
|
||
if (value == 0) { | ||
puts("0x0"); | ||
return; | ||
} | ||
|
||
while (value > 0 && i > 0) { | ||
buffer[--i] = hex_chars[value & 0xF]; | ||
value >>= 4; | ||
} | ||
|
||
puts("0x"); | ||
puts(&buffer[i]); | ||
} | ||
|
||
void printf(const char *format, ...) | ||
{ | ||
va_list params; va_start(params, format); | ||
for (uint32_t i = 0; format[i] != '\0'; ++i) { | ||
if (!(format[i] == '%')) { | ||
putchar(format[i]); | ||
continue; | ||
} | ||
switch (format[++i]) { | ||
case 'd': // idc for now | ||
case 'u': | ||
put_uint((uint32_t)va_arg(params, uint32_t)); | ||
break; | ||
case 'x': | ||
put_uint_hex((uint32_t)va_arg(params, uint32_t)); | ||
break; | ||
case 'c': | ||
putchar((uint8_t)va_arg(params, uint32_t)); | ||
break; | ||
case 's': | ||
puts((char *)va_arg(params, char *)); | ||
break; | ||
default: | ||
putchar(format[i]); | ||
break; | ||
} | ||
} | ||
va_end(params); | ||
} | ||
|
||
void puts(const char *str) | ||
{ | ||
for (uint32_t i = 0; str[i] != '\0'; ++i) putchar(str[i]); | ||
} |