From ab775bd95826f5c2830aa0c41ccca1aa92d61158 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Fri, 14 Mar 2025 18:32:01 +0300 Subject: [PATCH] implemented basic keyboard input getting --- Makefile | 5 ++++- include/utils.h | 9 +++++++++ src/isr.c | 2 +- src/kernel.c | 21 ++++++++++++++++++--- src/screen.c | 36 ++++++++++++++++++++++++++---------- src/utils.c | 14 ++++++++++++++ 6 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 include/utils.h create mode 100644 src/utils.c diff --git a/Makefile b/Makefile index 71de756..6f800d6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Define the object files -OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o +OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o # Define the compiler and assembler CC = gcc @@ -36,6 +36,9 @@ bin/isr.o: src/isr.c bin/idt.o: src/idt.c $(CC) $(CFLAGS) -c $< -o $@ +bin/utils.o: src/utils.c + $(CC) $(CFLAGS) -c $< -o $@ + clean: rm -rf bin/ rm -f $(OUTPUT) diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..7a6cce3 --- /dev/null +++ b/include/utils.h @@ -0,0 +1,9 @@ +#ifndef UTILS_H +#define UTILS_H +#include "../include/types.h" + +uint8 inportb(uint16 _port); +void outportb(uint16 _port, uint8 _data); + +#endif + diff --git a/src/isr.c b/src/isr.c index 87b09be..2a56355 100644 --- a/src/isr.c +++ b/src/isr.c @@ -38,7 +38,7 @@ void isr_install() { idt_set_descriptor(31, (uint32)isr31, 0x8E); idt_set(); // Load with ASM - terminal_writestring("isr_install done"); + terminal_writestring("isr_install done\n"); } void isr0() diff --git a/src/kernel.c b/src/kernel.c index bcfd513..ae7e1b0 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,5 +1,6 @@ #include "../include/isr.h" #include "../include/screen.h" +#include "../include/utils.h" /* Check if the compiler thinks you are targeting the wrong operating system. */ /*#if defined(__linux__) @@ -15,8 +16,22 @@ void kmain() { terminal_initialize(); - terminal_writestring("KatauOS booting up"); + terminal_writestring("KatauOS booting up\n"); isr_install(); - terminal_writestring("Kernel init sequence completed"); - return; + terminal_writestring("Kernel init sequence completed\n"); + + while(1) + { + if(inportb(0x64) & 0x1) + { + unsigned char key = inportb(0x60); + if(key == 2) + terminal_writestring("1\n"); + else if(key == 4) + terminal_writestring("3\n"); + else + terminal_writestring("dunno what is it\n"); + } + } + } diff --git a/src/screen.c b/src/screen.c index bffea9c..ec648e8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -6,12 +6,12 @@ static size_t terminal_column; static uint8_t terminal_color; static uint16_t* terminal_buffer; -uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) +inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) { return fg | bg << 4; } -uint16_t vga_entry(unsigned char uc, uint8_t color) +inline uint16_t vga_entry(unsigned char uc, uint8_t color) { return (uint16_t) uc | (uint16_t) color << 8; } @@ -49,14 +49,32 @@ void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) terminal_buffer[index] = vga_entry(c, color); } -void terminal_putchar(char c) +void terminal_putchar(char c) { - terminal_putentryat(c, terminal_color, terminal_column, terminal_row); - if (++terminal_column == VGA_WIDTH) { + /*if(c == '\n') + { + terminal_column = 0; + terminal_row++; + }*/ + if(c != '\n') + terminal_putentryat(c, terminal_color, terminal_column, terminal_row); + + if (++terminal_column >= VGA_WIDTH){ terminal_column = 0; - if (++terminal_row == VGA_HEIGHT) - terminal_row = 0; - } + terminal_initialize(); + if (++terminal_row >= VGA_HEIGHT) + terminal_row = 0; + } + if(terminal_row >= VGA_HEIGHT){ + terminal_row = 0; + } + + if(c == '\n') + { + terminal_column = 0; + terminal_row++; + } + } void terminal_write(const char* data, size_t size) @@ -68,6 +86,4 @@ void terminal_write(const char* data, size_t size) void terminal_writestring(const char* data) { terminal_write(data, strlen(data)); - terminal_row++; - terminal_column = 0; } diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..9294b01 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,14 @@ +#include "../include/types.h" +#include "../include/utils.h" + +uint8 inportb(uint16 _port) +{ + uint8 rv; + __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port)); + return rv; +} + +void outportb(uint16 _port, uint8 _data) +{ + __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); +}