From 7613ba9de2a09e8b8396aa6a6edaf58a4740e1ad Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Fri, 22 May 2020 16:30:00 -0500 Subject: [PATCH] Implemented a simple draw_rect function into the video driver. --- build_numbers.c | 2 +- kernel/kmain.c | 9 +++++++++ kernel/screen.c | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/build_numbers.c b/build_numbers.c index a03c2d0..8382ced 100644 --- a/build_numbers.c +++ b/build_numbers.c @@ -1,3 +1,3 @@ #ifndef KERNEL_VERSION_NUMBER -#define KERNEL_VERSION_NUMBER "0.0.1-239" +#define KERNEL_VERSION_NUMBER "0.0.1-276" #endif diff --git a/kernel/kmain.c b/kernel/kmain.c index 954cd4f..c1a5654 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -5,6 +5,15 @@ void kmain() { clear_screen(); print_banner(); + //draw_rect(20, 5, 50, 7, 0x4, 0xF); + draw_rect(0, 5, 5, 13, 0xF, 0x4); + draw_rect(5, 8, 10, 10, 0x4, 0xF); + draw_rect(10, 5, 15, 13, 0x8, 0x6); + draw_rect(20, 5, 25, 7, 0xF, 0x1); + draw_rect(20, 8, 25, 13, 0x5, 0x3); + //draw_rect(20, 5, 50, 7, 0x4, 0xF); + //draw_rect(20, 5, 50, 7, 0x4, 0xF); + //draw_rect(20, 5, 50, 7, 0x4, 0xF); //draw_s("Hello, World!", 2, 9); //row = 2; ///column = 80; diff --git a/kernel/screen.c b/kernel/screen.c index 1a7079d..1511193 100644 --- a/kernel/screen.c +++ b/kernel/screen.c @@ -45,6 +45,20 @@ void print_banner(){ } } } +//index = (y_value * width_of_screen) + x_value; +void draw_rect(int start_x, int start_y, int end_x, int end_y, unsigned char fg, unsigned char bg){ + unsigned char y = end_y - start_y; + unsigned char x = end_x - start_x; + int attr = ((bg << 4) | (fg & 0x0F)); + unsigned short *buffer = (unsigned short*) 0x000B8000 + (start_y * 80) + start_x; + + for(unsigned char i = 0; i < y; i++){ + for(unsigned char j = 0; j < x; j++){ + unsigned short *where = (unsigned short*) buffer + (i * 80) + j; + *where = 0x23 | (attr << 8); + } + } +} void draw_s(char* string, unsigned char fg, unsigned char bg) {