Incomplete screen driver.
This commit is contained in:
parent
a9a0aa79ed
commit
21c97f509d
46
drivers/screen.c
Normal file
46
drivers/screen.c
Normal 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
13
drivers/screen.h
Normal 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);
|
Loading…
Reference in New Issue
Block a user