From 21c97f509d0d61179b49238ffe82899d01b72261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sat, 24 Feb 2018 10:04:41 +0100 Subject: [PATCH] Incomplete screen driver. --- drivers/screen.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/screen.h | 13 +++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 drivers/screen.c create mode 100644 drivers/screen.h diff --git a/drivers/screen.c b/drivers/screen.c new file mode 100644 index 0000000..bbd07ef --- /dev/null +++ b/drivers/screen.c @@ -0,0 +1,46 @@ +#include "screen.h" + +#include "../kernel/ports.h" + +void print_char(char c, int col, int row, char attr_byte) { + unsigned char *vidmem = (unsigned char*) VIDEO_ADDRESS; + + if(!attr_byte) + attr_byte = WHITE_ON_BLACK; + + /* get the offset of the screen location specified */ + int offset; + /* + * if row & col are non-negative then they can be used + * as an offset + */ + if(col >= 0 && row >= 0) + { + offset = get_screen_offset(col, row); + } + /* otherwise use the cursor's current location */ + else + { + offset = get_cursor(); + } + + /* handle a newline */ + if(c == '\n') + { + int rows = offset / (2 * MAX_COLS); + offset = get_screen_offset(79,rows); + } + /* else set the character */ + else + { + vidmem[offset] = c; + vidmem[offset+1] = attr_byte; + } + + /* update the offset to the next cell */ + offset += 2; + /* set scrolling adjustment */ + offset = handle_scrolling(offset); + /* update the cursor position */ + set_cursor(offset); +} diff --git a/drivers/screen.h b/drivers/screen.h new file mode 100644 index 0000000..d07f2cb --- /dev/null +++ b/drivers/screen.h @@ -0,0 +1,13 @@ +#pragma once + +#define VIDEO_ADDRESS 0xb8000 +#define MAX_ROWS 25 +#define MAX_COLS 80 + +#define WHITE_ON_BLACK 0x0f + +#define REG_SCREEN_CTRL 0x3d4 +#define REG_SCREEN_DATA 0x3d5 + +void print_char(char c, int col, int row, char attr_byte); +int get_screen_offset(int col, int row);