From 2893e75ad15a9a96debaa09f5b98b4664ce5005e Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:30:14 +0200 Subject: [PATCH] fix: conway, words --- docs/USERS.md | 8 +- src/drivers/serial.c | 2 +- src/kernel/kmain.c | 11 +-- src/libc/string.c | 12 +++ src/libc/string.h | 1 + src/programs/conway.c | 5 +- src/programs/conway.h | 4 +- src/programs/words.c | 171 ++++++++++++++++++++++++++++++++++++++++-- 8 files changed, 196 insertions(+), 18 deletions(-) diff --git a/docs/USERS.md b/docs/USERS.md index 1185b0c..0d503b8 100644 --- a/docs/USERS.md +++ b/docs/USERS.md @@ -43,7 +43,11 @@ Triggers a kernel panic by trying to divide four by zero. #### `words` -Prints ten random words using an arbitrary dictionary that you can expand in `src/programs/words.c`. +Prints random words using an arbitrary dictionary that you can expand in `src/programs/words.c`. + +Options: +- `` will default amount of words to 10 +- `` will set the amount of words to that number #### `primes` @@ -78,7 +82,7 @@ The classic echo command, that outputs your input. Outputs information about the current system (CPU and RAM). Options: -- `nothing` will show basic info about the CPUid and lower/upper memory. +- `` will show basic info about the CPUid and lower/upper memory. - `-v` will output the CPUID, lower/upper memory, and the memory map. #### `conway` diff --git a/src/drivers/serial.c b/src/drivers/serial.c index a9d369f..ffb6cc6 100644 --- a/src/drivers/serial.c +++ b/src/drivers/serial.c @@ -282,5 +282,5 @@ void serial_printf(int errlevel, const char* fmt, ...) } fmt++; } - serial_puts("\n"); + serial_puts("\r\n"); } diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index 14248bc..8aff6c6 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -31,11 +31,11 @@ void kmain(multiboot2_info *mb_info) tags += ((tag_size + 7) & ~7); } - serial_printf(3, "Framebuffer Address: 0x%x\r", fb_info->framebuffer_addr); - serial_printf(3, "Framebuffer Width: %u\r\n", fb_info->framebuffer_width); - serial_printf(3, "Framebuffer Height: %u\r\n", fb_info->framebuffer_height); - serial_printf(3, "Framebuffer Pitch: %u\r\n", fb_info->framebuffer_pitch); - serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp); + serial_printf(3, "Framebuffer Address: 0x%x", fb_info->framebuffer_addr); + serial_printf(3, "Framebuffer Width: %u", fb_info->framebuffer_width); + serial_printf(3, "Framebuffer Height: %u", fb_info->framebuffer_height); + serial_printf(3, "Framebuffer Pitch: %u", fb_info->framebuffer_pitch); + serial_printf(3, "Framebuffer BPP: %u", fb_info->framebuffer_bpp); if (fb_info) { framebuffer = (uint32_t *)(uintptr_t) fb_info->framebuffer_addr; @@ -47,6 +47,7 @@ void kmain(multiboot2_info *mb_info) //8x16 font, not padded VGA_WIDTH = width/8; VGA_HEIGHT = height/16; + serial_printf(3, "VGA_WIDTH=%d, VGA_HEIGHT=%d", VGA_WIDTH, VGA_HEIGHT); scanline = width * (bpp/8); } diff --git a/src/libc/string.c b/src/libc/string.c index 681298d..6f079b3 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -74,3 +74,15 @@ char* strtok(char* str, const char* delimiter) return token_start; } + +int atoi(char* str) +{ + int result = 0; + + for (int i=0; str[i] != '\0'; i++) + { + result = result*10 + str[i] - '0'; + } + + return result; +} diff --git a/src/libc/string.h b/src/libc/string.h index b3fc1ce..130c2b6 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -9,5 +9,6 @@ int strlen(const char* str); int strcmp(const char* str1, const char* str2); char* strtok(char* str, const char* delimiter); +int atoi(char* str); #endif diff --git a/src/programs/conway.c b/src/programs/conway.c index 61e4c4a..70e26bc 100644 --- a/src/programs/conway.c +++ b/src/programs/conway.c @@ -13,14 +13,13 @@ void print_grid(const unsigned char grid[X][Y]) { + clear(); for (int i=0; i