From 7e2a7b441219e4eb33793ef42d8cb620e876f803 Mon Sep 17 00:00:00 2001 From: garritfra Date: Mon, 15 Jun 2020 19:56:20 +0200 Subject: [PATCH] Add std --- Makefile | 2 +- bochsrc.txt | 4 ++-- fb.c | 13 ++++++++++++- fb.h | 2 ++ kmain.c | 7 ++++--- std.c | 17 +++++++++++++++++ std.h | 10 ++++++++++ 7 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 std.c create mode 100644 std.h diff --git a/Makefile b/Makefile index 77d371a..cb390c2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -OBJECTS = io.o loader.o kmain.o fb.o serial.o +OBJECTS = io.o loader.o kmain.o fb.o serial.o std.o CC = gcc CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \ -nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c diff --git a/bochsrc.txt b/bochsrc.txt index c0f28c0..c975ff0 100644 --- a/bochsrc.txt +++ b/bochsrc.txt @@ -1,5 +1,5 @@ megs: 32 -display_library: sdl +display_library: x romimage: file=/usr/share/bochs/BIOS-bochs-latest vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest ata0-master: type=cdrom, path=os.iso, status=inserted @@ -7,4 +7,4 @@ boot: cdrom log: bochslog.txt clock: sync=realtime, time0=local cpu: count=1, ips=1000000 -com1: enabled=1, mode=file, dev=com1.out \ No newline at end of file +com1: enabled=1, mode=file, dev=com1.out diff --git a/fb.c b/fb.c index 75839f6..7863bfd 100644 --- a/fb.c +++ b/fb.c @@ -1,4 +1,3 @@ -#include "kmain.h" #include "fb.h" void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) { @@ -15,6 +14,9 @@ void fb_move_cursor(unsigned short pos) outb(FB_DATA_PORT, pos & 0x00FF); } +/* +* Write frame buffer to screen +*/ int fb_write(char *buf, unsigned int len) { for(int i = 0; i <= (int)len; i++) { @@ -24,6 +26,15 @@ int fb_write(char *buf, unsigned int len) { return 0; } +/** read_scan_code: + * Reads a scan code from the keyboard + * + * @return The scan code (NOT an ASCII character!) + */ +unsigned char read_scan_code(void) { + return inb(KBD_DATA_PORT); +} + void advance_cursor(void) { fb_move_cursor(get_cursor_position() + 1); } diff --git a/fb.h b/fb.h index 89d4145..94c81f3 100644 --- a/fb.h +++ b/fb.h @@ -28,6 +28,8 @@ #define VGA_COLOR_LIGHT_BROWN 14 #define VGA_COLOR_WHITE 15 +#define KBD_DATA_PORT 0x60 + int fb_write(char *buf, unsigned int len); diff --git a/kmain.c b/kmain.c index 5638d6e..9f53a1a 100644 --- a/kmain.c +++ b/kmain.c @@ -1,8 +1,9 @@ #include "kmain.h" -#include "fb.h" +#include "std.h" + int main() { - fb_write("Hello", 4); + printf("Hello"); return 0; -} \ No newline at end of file +} diff --git a/std.c b/std.c new file mode 100644 index 0000000..5fa04de --- /dev/null +++ b/std.c @@ -0,0 +1,17 @@ +#include "std.h" +#include "fb.h" + + +void printf(char *buf) { + fb_write(buf, strlen(buf)); +} + +void scanf(const char *format); + +unsigned int strlen(const char *str) { + const char *s; + + for (s = str; *s; ++s) + ; + return (s - str); +} \ No newline at end of file diff --git a/std.h b/std.h new file mode 100644 index 0000000..3115181 --- /dev/null +++ b/std.h @@ -0,0 +1,10 @@ +#ifndef INCLUDE_STD +#define INCLUDE_STD + +void printf(char *buf); + +void scanf(const char *format); + +unsigned int strlen(const char *buf); + +#endif \ No newline at end of file