Changed structure of module screen
This commit is contained in:
parent
7ab1592f75
commit
bf9ced8721
|
@ -14,7 +14,7 @@
|
|||
#define CURSOR_LOW_BYTE_COMMAND 0x0F
|
||||
|
||||
/*
|
||||
* screen_move_cursor:
|
||||
* _screen_move_cursor:
|
||||
* Moves the cursor of the framebuffer to a give position calculated using
|
||||
* @x and @y coordinates.
|
||||
*
|
||||
|
@ -23,6 +23,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
void screen_move_cursor(uint8_t x, uint8_t y);
|
||||
void _screen_move_cursor(uint8_t x, uint8_t y);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#ifndef ISCREEN_H_
|
||||
#define ISCREEN_H_
|
||||
|
||||
/*
|
||||
* The starting address of the memory mapped I/O for the framebuffer.
|
||||
*
|
||||
*/
|
||||
/* Starting address of the memory mapped I/O for the framebuffer. */
|
||||
|
||||
#define FBUFFER_START_ADDR 0x000B8000
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef SCREEN_INTERNALS_H_
|
||||
#define SCREEN_INTERNALS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* State of the screen. */
|
||||
|
||||
uint16_t *fbuffer;
|
||||
|
||||
size_t screen_row;
|
||||
size_t screen_column;
|
||||
size_t screen_color;
|
||||
|
||||
/*
|
||||
* _screen_putchar_*:
|
||||
* Put character at a specified position or put character at the next position
|
||||
* available in framebuffer acording to state variables.
|
||||
*
|
||||
* @param c - Char to be displayed
|
||||
* @param color - Color attributes of @c
|
||||
* @param x - Vertical position
|
||||
* @param y - Horizontal position
|
||||
*
|
||||
*/
|
||||
|
||||
void _screen_putchar_at(char c, uint16_t color, size_t x, size_t y);
|
||||
void _screen_putchar(char c);
|
||||
|
||||
/*
|
||||
* _screen_scroll_up:
|
||||
* Deletes the last line of framebuffer and moves other lines up by one.
|
||||
*
|
||||
*/
|
||||
|
||||
void _screen_scroll_up(void);
|
||||
|
||||
#endif
|
|
@ -4,7 +4,7 @@
|
|||
#include "lib/vga.h"
|
||||
|
||||
/*
|
||||
* screen_move_cursor:
|
||||
* _screen_move_cursor:
|
||||
* -------------------
|
||||
*
|
||||
* Compute the screen index, @sindex, using the given coordinates and send
|
||||
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
void screen_move_cursor(uint8_t x, uint8_t y) {
|
||||
void _screen_move_cursor(uint8_t x, uint8_t y) {
|
||||
|
||||
uint16_t sindex = y * VGA_WIDTH + x;
|
||||
|
||||
|
|
|
@ -1,35 +1,15 @@
|
|||
#include "kernel/screen.h"
|
||||
|
||||
#include "framebuffer.h"
|
||||
#include "cursor.h"
|
||||
#include "screen_internals.h"
|
||||
|
||||
#include "lib/vga.h"
|
||||
#include "lib/memio.h"
|
||||
|
||||
/*
|
||||
* Variables that determine the state of the screen.
|
||||
*
|
||||
*/
|
||||
|
||||
static unsigned short *fbuffer;
|
||||
|
||||
static unsigned screen_row;
|
||||
static unsigned screen_column;
|
||||
static unsigned screen_color;
|
||||
|
||||
/*
|
||||
* Private functions used to implement the public ones.
|
||||
*
|
||||
*/
|
||||
|
||||
static void screen_putchar_at(char c, unsigned short color, unsigned x, unsigned y);
|
||||
static void screen_putchar(char c);
|
||||
|
||||
static void screen_scroll_up(void);
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* screen_init:
|
||||
* ------
|
||||
* ------------
|
||||
*
|
||||
* Initialize @screen_row and @screen_column.
|
||||
* Set the @screen color (at the moment the screen has preset colors).
|
||||
|
@ -43,12 +23,12 @@ void screen_init(void) {
|
|||
screen_column = 0;
|
||||
screen_color = vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLUE);
|
||||
|
||||
fbuffer = (unsigned short *) FBUFFER_START_ADDR;
|
||||
fbuffer = (uint16_t *) FBUFFER_START_ADDR;
|
||||
|
||||
for (unsigned y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (unsigned x = 0; x < VGA_WIDTH; x++) {
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
|
||||
const unsigned index = y * VGA_WIDTH + x;
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
fbuffer[index] = vga_entry(' ', screen_color);
|
||||
|
||||
}
|
||||
|
@ -69,79 +49,8 @@ size_t screen_write(char *buf, size_t len) {
|
|||
volatile size_t i = 0;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
screen_putchar(buf[i]);
|
||||
_screen_putchar(buf[i]);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* PRIVATE FUNCTIONS */
|
||||
|
||||
/*
|
||||
* screen_putchar_at:
|
||||
* ------------------
|
||||
*
|
||||
* Put the character @c of color @color in framebuffer at the index determined
|
||||
* by @x and @y coordinates.
|
||||
*
|
||||
*/
|
||||
|
||||
static void screen_putchar_at(char c, unsigned short color, unsigned x, unsigned y) {
|
||||
|
||||
const unsigned index = y * VGA_WIDTH + x;
|
||||
fbuffer[index] = vga_entry(c, color);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* screen_scroll_up:
|
||||
* -----------------
|
||||
*
|
||||
* Scroll the first 24 lines and delete the content of the last line.
|
||||
*
|
||||
*/
|
||||
|
||||
static void screen_scroll_up(void) {
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < VGA_WIDTH * VGA_HEIGHT - 80; i++)
|
||||
fbuffer[i] = fbuffer[i + 80];
|
||||
|
||||
for (i = 0; i < VGA_WIDTH; i++)
|
||||
fbuffer[(VGA_HEIGHT - 1) * VGA_WIDTH + 1] = vga_entry(' ', screen_color);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* screen_puchar:
|
||||
* --------------
|
||||
*
|
||||
* Wrapper function over screen_putchar_at. Puts the character in framebuffer and
|
||||
* has support for newline characters.
|
||||
*
|
||||
* Side efects:
|
||||
* scrolls up the screen whenever there is no more space
|
||||
* moves the cursor after each displayed characte
|
||||
*
|
||||
*/
|
||||
|
||||
static void screen_putchar(char c) {
|
||||
|
||||
if (screen_column == VGA_WIDTH || c == '\n') {
|
||||
|
||||
screen_column = 0;
|
||||
|
||||
if (screen_row == VGA_HEIGHT - 1)
|
||||
screen_scroll_up();
|
||||
else
|
||||
screen_row++;
|
||||
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
return;
|
||||
|
||||
screen_putchar_at(c, screen_color, screen_column++, screen_row);
|
||||
screen_move_cursor(screen_column, screen_row);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
#include "screen_internals.h"
|
||||
#include "cursor.h"
|
||||
|
||||
#include "lib/vga.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* _screen_putchar_at:
|
||||
* ------------------
|
||||
*
|
||||
* Put the character @c of color @color in framebuffer at the index determined
|
||||
* by @x and @y coordinates.
|
||||
*
|
||||
*/
|
||||
|
||||
void _screen_putchar_at(char c, uint16_t color, size_t x, size_t y) {
|
||||
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
fbuffer[index] = vga_entry(c, color);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* _screen_scroll_up:
|
||||
* -----------------
|
||||
*
|
||||
* Scroll the first 24 lines and delete the content of the last line.
|
||||
*
|
||||
*/
|
||||
|
||||
void _screen_scroll_up(void) {
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < VGA_WIDTH * VGA_HEIGHT - 80; i++)
|
||||
fbuffer[i] = fbuffer[i + 80];
|
||||
|
||||
for (i = 0; i < VGA_WIDTH; i++)
|
||||
fbuffer[(VGA_HEIGHT - 1) * VGA_WIDTH + 1] = vga_entry(' ', screen_color);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* _screen_putchar:
|
||||
* --------------
|
||||
*
|
||||
* Wrapper function over _screen_putchar_at. Puts the character in framebuffer and
|
||||
* has support for newline characters.
|
||||
*
|
||||
* Side efects:
|
||||
* scrolls up the screen whenever there is no more space
|
||||
* moves the cursor after each displayed characte
|
||||
*
|
||||
*/
|
||||
|
||||
void _screen_putchar(char c) {
|
||||
|
||||
if (screen_column == VGA_WIDTH || c == '\n') {
|
||||
|
||||
screen_column = 0;
|
||||
|
||||
if (screen_row == VGA_HEIGHT - 1)
|
||||
_screen_scroll_up();
|
||||
else
|
||||
screen_row++;
|
||||
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
return;
|
||||
|
||||
_screen_putchar_at(c, screen_color, screen_column++, screen_row);
|
||||
_screen_move_cursor(screen_column, screen_row);
|
||||
|
||||
}
|
Loading…
Reference in New Issue