Add: framebuffer color output functions

This commit is contained in:
xamidev
2024-07-15 19:07:22 +02:00
parent 124d88f7b7
commit 43808da332
7 changed files with 51 additions and 10 deletions

BIN
com1.out

Binary file not shown.

Binary file not shown.

Binary file not shown.

23
kmain.c
View File

@@ -7,25 +7,24 @@
int kmain(int retvalue) int kmain(int retvalue)
{ {
gdt_install();
idt_install();
isr_install();
// serial testing
init_serial(); init_serial();
log("serial connection established", 3); log("serial connection established", 3);
gdt_install();
log("initialized GDT entries", 2); log("initialized GDT entries", 2);
log("kernel started", 2); idt_install();
log("initialized IDT", 2); log("initialized IDT", 2);
isr_install();
log("initialized ISRs", 3); log("initialized ISRs", 3);
log("kernel started", 2);
clear(); clear();
// printf testing // printf testing
// TODO: Framebuffer upgrade: color output // TODO: Framebuffer upgrade: color output
// TODO: Serial printf to dump registers on kernel panic
// TODO: Fix scrolling bug (framebuffer driver)
int age = 34; int age = 34;
int problems = 124; int problems = 124;
@@ -41,10 +40,14 @@ int kmain(int retvalue)
printf("such hex %x %X\n", 0xcafe, 0xdeadbeef); printf("such hex %x %X\n", 0xcafe, 0xdeadbeef);
printf("such pointer %p\n", (void*)0xcafe1234); printf("such pointer %p\n", (void*)0xcafe1234);
for (int i=0; i<10; i++)
{
colorputs("hello colorful world!!\n", i);
}
// Div by zero exception // Div by zero exception
printf("Lalala, what a beautiful day! %d", 4/0); //printf("Lalala, what a beautiful day! %d", 4/0);
return retvalue; return retvalue;
} }

BIN
os.iso

Binary file not shown.

36
stdio.c
View File

@@ -102,6 +102,33 @@ void putc(char c)
move_cursor(VGA_X, VGA_Y); move_cursor(VGA_X, VGA_Y);
} }
void colorputc(char c, unsigned int color)
{
switch(c)
{
case '\n':
VGA_X = 0;
VGA_Y++;
break;
case '\r':
VGA_X = 0;
break;
default:
putchar(VGA_X, VGA_Y, c);
putcolor(VGA_X, VGA_Y, color);
VGA_X++;
break;
}
if (VGA_X >= VGA_WIDTH)
{
VGA_Y++;
VGA_X = 0;
}
if (VGA_Y >= VGA_HEIGHT) scroll(1);
move_cursor(VGA_X, VGA_Y);
}
void puts(const char* str) void puts(const char* str)
{ {
while (*str) while (*str)
@@ -111,6 +138,15 @@ void puts(const char* str)
} }
} }
void colorputs(const char* str, unsigned int color)
{
while (*str)
{
colorputc(*str, color);
str++;
}
}
void printf(const char* fmt, ...) void printf(const char* fmt, ...)
{ {
int* argp = (int*) &fmt; int* argp = (int*) &fmt;

View File

@@ -14,12 +14,14 @@
void move_cursor(int x, int y); void move_cursor(int x, int y);
void putchar(int x, int y, char c); void putchar(int x, int y, char c);
void puts(const char* str); void puts(const char* str);
void colorputs(const char* str, unsigned int color);
void clear(void); void clear(void);
void putcolor(int x, int y, unsigned int color); void putcolor(int x, int y, unsigned int color);
char getchar(int x, int y); char getchar(int x, int y);
unsigned int getcolor(int x, int y); unsigned int getcolor(int x, int y);
void scroll(int lines); void scroll(int lines);
void putc(char c); void putc(char c);
void colorputc(char c, unsigned int color);
#define PRINTF_STATE_START 0 #define PRINTF_STATE_START 0
#define PRINTF_STATE_LENGTH 1 #define PRINTF_STATE_LENGTH 1