From 7bc439f3ada8d3bd19253f7709efb0daf940a593 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Tue, 1 Oct 2019 10:35:35 -0700 Subject: [PATCH] finally to a point where i can start building ddrivers for this framebuffer's output smh --- io.h => fb.h | 2 +- fb.s | 10 ++++++++++ framebuffer.c | 9 +++++---- framebuffer.h | 2 +- io.s | 7 ------- makefile | 2 +- stlio.c | 8 +++++++- stlio.h | 3 ++- tests.c | 5 +++-- tests.h | 1 + 10 files changed, 31 insertions(+), 18 deletions(-) rename io.h => fb.h (56%) create mode 100644 fb.s delete mode 100644 io.s diff --git a/io.h b/fb.h similarity index 56% rename from io.h rename to fb.h index c870683..51a83d7 100644 --- a/io.h +++ b/fb.h @@ -1,6 +1,6 @@ #ifndef INCLUDE_IO_H #define INCLUDE_IO_H -void out_buffer(unsigned short, unsigned char); +void fb_cursor_control(unsigned short, unsigned char); #endif /* INCLUDE_IO_H */ diff --git a/fb.s b/fb.s new file mode 100644 index 0000000..170085a --- /dev/null +++ b/fb.s @@ -0,0 +1,10 @@ +; Helpers for frame buffer which pretty much have to to be +; written in asm + +global fb_cursor_control + +fb_cursor_control: + mov al, [esp+8] + mov dx, [esp+4] + out dx, al + ret diff --git a/framebuffer.c b/framebuffer.c index a66a778..f0184c2 100644 --- a/framebuffer.c +++ b/framebuffer.c @@ -24,13 +24,14 @@ void clear_fb(void) { for(unsigned cell=0;cell> 8) & 0x00ff) ); - out_buffer(FB_CMD, FB_LOW_CMD); - out_buffer(FB_DATA, position & 0x00ff); + fb_cursor_control(FB_CMD, FB_HIGH_CMD); + fb_cursor_control(FB_DATA, ((position >> 8) & 0x00ff) ); + fb_cursor_control(FB_CMD, FB_LOW_CMD); + fb_cursor_control(FB_DATA, position & 0x00ff); } diff --git a/framebuffer.h b/framebuffer.h index bc0eece..748b8a9 100644 --- a/framebuffer.h +++ b/framebuffer.h @@ -1,5 +1,5 @@ #include "types.h" -#include "io.h" +#include "fb.h" #define COLUMNS 80 #define ROWS 25 diff --git a/io.s b/io.s deleted file mode 100644 index 8170dac..0000000 --- a/io.s +++ /dev/null @@ -1,7 +0,0 @@ -global out_buffer - -out_buffer: - mov al, [esp+8] - mov dx, [esp+4] - out dx, al - ret diff --git a/makefile b/makefile index ba88604..a090fa9 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ ASM=nasm LINK=ld ISO=genisoimage -OBJECTS=loader.o framebuffer.o io.o stlio.o tests.o +OBJECTS=loader.o framebuffer.o fb.o stlio.o tests.o AFLAGS=-f elf32 CFLAGS=-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles \ -nodefaultlibs -Wall -Wextra -Werror -c diff --git a/stlio.c b/stlio.c index 954557e..a50536d 100644 --- a/stlio.c +++ b/stlio.c @@ -1,6 +1,12 @@ #include "stlio.h" -u64 write(const s8* buffer, const u64 size) { +// We are assuming null-terminated strings here +u64 strlen(char* buffer) { + char* c; + for(c = buffer; *c != '\0'; c++); // LULW + return (u64)(c - buffer); +} +u64 write(const char* buffer, const u64 size) { u64 i; for(i = 0; i < size; i++) { write_cell_fb(buffer[i], Green, White); diff --git a/stlio.h b/stlio.h index dd16dcc..20d60ad 100644 --- a/stlio.h +++ b/stlio.h @@ -2,4 +2,5 @@ #include "framebuffer.h" // Frame buffer driver -u64 write(const s8*, const u64); +u64 strlen(char*); +u64 write(const char*, const u64); diff --git a/tests.c b/tests.c index ead6112..0d5faae 100644 --- a/tests.c +++ b/tests.c @@ -1,8 +1,9 @@ // Module for testing drivers and other things +#include "stlio.h" #include "tests.h" void test_write() { clear_fb(); - s8* msg1 = (s8*)"big yeet"; - write(msg1, sizeof(msg1)); + char* msg1 = "bigyeet"; + write(msg1, strlen(msg1)); } diff --git a/tests.h b/tests.h index 926dc57..b1ab1bc 100644 --- a/tests.h +++ b/tests.h @@ -1,3 +1,4 @@ #include "types.h" #include "stlio.h" + void test_write();