Incomplete screen driver.

This commit is contained in:
Nicolás Ortega Froysa 2018-02-24 10:04:41 +01:00
parent a9a0aa79ed
commit 21c97f509d
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
2 changed files with 59 additions and 0 deletions

46
drivers/screen.c Normal file
View File

@ -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);
}

13
drivers/screen.h Normal file
View File

@ -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);