9#include <limine/limine.h>
22bool console_enabled =
false;
25 return console_enabled;
33 if (font_type == FONT_PSF1) {
41 for (uint32_t y = 0; y <
main_console.fb->height - height; y++) {
54 uint32_t *pixel_addr = (uint32_t *)(
59 for (
size_t y = 0; y < height; y++) {
60 uint32_t *dest = (uint32_t *)(
69 if (console_enabled)
return;
77 if (font_type == FONT_PSF1) {
78 main_console.font_psf1_info.magic[0] = *(_binary_font_psf_start);
79 main_console.font_psf1_info.magic[1] = *(_binary_font_psf_start + 1);
80 main_console.font_psf1_info.mode = *(_binary_font_psf_start + 2);
81 main_console.font_psf1_info.charsize = *(_binary_font_psf_start + 3);
86 main_console.font_psf2_info.magic = *(_binary_font_psf_start);
87 main_console.font_psf2_info.version = *(_binary_font_psf_start + 4);
88 main_console.font_psf2_info.headersize = *(_binary_font_psf_start + 8);
89 main_console.font_psf2_info.flags = *(_binary_font_psf_start + 12);
90 main_console.font_psf2_info.length = *(_binary_font_psf_start + 16);
91 main_console.font_psf2_info.charsize = *(_binary_font_psf_start + 20);
92 main_console.font_psf2_info.height = *(_binary_font_psf_start + 24);
93 main_console.font_psf2_info.width = *(_binary_font_psf_start + 28);
99 console_enabled =
true;
111void draw_char(
const char c,
const uint8_t col,
const uint8_t row) {
116 if (font_type == FONT_PSF1) {
117 glyph = (uint64_t) _binary_font_psf_start + 4 + c *
main_console.font_psf1_info.charsize;
121 glyph = (uint64_t) _binary_font_psf_start + 32 + c *
main_console.font_psf2_info.charsize;
126 const int px = col * width;
127 const int py = row * height;
129 const uint8_t bytes_per_row = (width + 7) / 8;
131 for (
int y = 0; y < height; y++) {
132 const uint8_t *glyph_row = (uint8_t *)(glyph + y * bytes_per_row);
134 for (
int x = 0; x < width; x++) {
135 const uint8_t row_bits = glyph_row[x / 8];
136 const uint8_t bit = (row_bits >> (7 - (x % 8))) & 1;
138 const unsigned int pixel_x = px + x;
139 const unsigned int pixel_y = py + y;
146 uint32_t *pixel_addr = (uint32_t *)(
172void fill32(uint32_t *dest, uint32_t value,
size_t count) {
173 for (
size_t i = 0; i < count; i++) {
225 char current = str[index];
227 if (current ==
'\0')
break;
247 uint64_t next = value;
260 const uint64_t MAX_LENGTH = index;
261 char chars[MAX_LENGTH];
267 if (index >= MAX_LENGTH)
271 chars[index] = ((next % 10) +
'0');
282 char str[MAX_LENGTH + 1];
284 for (
int i = index - 1; i >= 0; i--) {
285 str[MAX_LENGTH - i - 1] = chars[i];
288 str[MAX_LENGTH] =
'\0';
void fill32(uint32_t *dest, uint32_t value, size_t count)
Fills 32 bytes count times starting at dest with value.
void set_bg_color(struct rgb color)
Sets the background colour.
void console_putc(char c)
Arranges the cursor and prints characters.
struct rgb get_default_bg_color(void)
Gets the default bg colour.
void scroll_up(void)
Scrolls the whole console up.
bool get_console_status(void)
Returns the status of the console (initialized or uninitialized).
void console_puts(char *str)
Prints a non-formatted string.
struct rgb get_fg_color(void)
Gets the current fg colour.
struct rgb get_bg_color(void)
Gets the current bg colour.
void console_clear(void)
Clears the console (fills with bg color).
struct rgb get_default_fg_color(void)
Gets the default fg colour.
void set_fg_color(struct rgb color)
Sets the foreground colour.
void console_print_int(uint64_t value)
Prints an int to the console.
void console_init(void)
Initializes the console struct and fills all the properties.
struct console main_console
The main console info.
void draw_char(const char c, const uint8_t col, const uint8_t row)
Draws a character to the console.
Console utilities and configuration.
Utilities for memory and string operations.
void * memmove(void *dest, const void *src, size_t n)
Copies memory from one address to the other with possible overlap.
Console structure, holds all the information about the console.
Tools for testing different parts of the kernel.