OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
console.c File Reference
#include "console.h"
#include "font/font8x16.h"
#include "hal.h"
#include "color.h"
#include "string.h"
#include <ctype.h>

Data Structures

struct  cell
 A single cell in the console. More...
 

Macros

#define SCREEN_X   255
 Screen X resolution.
 
#define SCREEN_Y   255
 Screen Y resolution.
 

Functions

static void cdrawchar (char c, int row, int col, color_t color)
 Draws a character at a position, using the font specified in font8x16.h.
 
static void handle_cntrl_char (char c)
 Handles a control character.
 
void credrawchar (uint32_t row, uint32_t col)
 Redraws a character.
 
void crefresh (void)
 Refreshes the console's screen.
 
void cclear (color_t color)
 Clears the console's screen.
 
void cclearchar (uint32_t row, uint32_t col, color_t color)
 Clears a cell.
 
void cclearcurchar (color_t color)
 Clears the cell at the cursor's position.
 
void cprint (const char *str, color_t color)
 Prints a string to the console, without a newline.
 
void cmovecursor (int32_t rows, int32_t cols)
 Moves the cursor by an offset.
 
void cprintln (const char *str, color_t color)
 Prints a string to the console followed by a newline.
 
void cputchar (char c, color_t color)
 Prints a character at the cursor's position in the given color.
 
void cputint (int i, color_t color)
 Writes an integer in base 10 at the cursor's position in the given color.
 
void crcursor (void)
 Resets the cursor's position.
 
void csetcursor (uint32_t row, uint32_t col)
 Sets the cursor's position.
 
void csetrow (int32_t r)
 Sets the cursor's row.
 
void csetcol (int32_t c)
 Sets the cursor's column.
 
uint32_t cgetcol (void)
 Gets the cursor's column.
 
uint32_t cgetrow (void)
 Gets the cursor's row.
 

Variables

static struct cell screen_buffer [SCREEN_Y][SCREEN_X] = { 0 }
 The console's screen buffer.
 
static uint8_t row = 0
 
static uint8_t col = 0
 

Macro Definition Documentation

◆ SCREEN_X

#define SCREEN_X   255

Screen X resolution.

◆ SCREEN_Y

#define SCREEN_Y   255

Screen Y resolution.

Function Documentation

◆ cclear()

void cclear ( color_t  color)

Clears the console's screen.

Parameters
colorBackground color.

◆ cclearchar()

void cclearchar ( uint32_t  row,
uint32_t  col,
color_t  color 
)

Clears a cell.

Parameters
rowThe row.
colThe column.
colorBackground color.

◆ cclearcurchar()

void cclearcurchar ( color_t  color)

Clears the cell at the cursor's position.

Parameters
colorBackground color.

◆ cdrawchar()

static void cdrawchar ( char  c,
int  row,
int  col,
color_t  color 
)
static

Draws a character at a position, using the font specified in font8x16.h.

◆ cgetcol()

uint32_t cgetcol ( void  )

Gets the cursor's column.

Returns
Column.

◆ cgetrow()

uint32_t cgetrow ( void  )

Gets the cursor's row.

Returns
Row.

◆ cmovecursor()

void cmovecursor ( int32_t  rows,
int32_t  cols 
)

Moves the cursor by an offset.

Parameters
rowsNumber of rows.
colsNumber of columns.

◆ cprint()

void cprint ( const char *  str,
color_t  color 
)

Prints a string to the console, without a newline.

Parameters
strString to be printed. Must be null-terminated.
colorForeground color.

◆ cprintln()

void cprintln ( const char *  str,
color_t  color 
)

Prints a string to the console followed by a newline.

Parameters
strString to be printed. Must be null-terminated.
colorForeground color of the text.

◆ cputchar()

void cputchar ( char  c,
color_t  color 
)

Prints a character at the cursor's position in the given color.

Parameters
cCharacter to be written.
colorForeground color of the text.

◆ cputint()

void cputint ( int  i,
color_t  color 
)

Writes an integer in base 10 at the cursor's position in the given color.

Parameters
iInteger to be written.
colorForeground color of the text.

◆ crcursor()

void crcursor ( void  )

Resets the cursor's position.

◆ credrawchar()

void credrawchar ( uint32_t  row,
uint32_t  col 
)

Redraws a character.

Parameters
rowThe row.
colThe column.

◆ crefresh()

void crefresh ( void  )

Refreshes the console's screen.

◆ csetcol()

void csetcol ( int32_t  col)

Sets the cursor's column.

Parameters
colColumn

◆ csetcursor()

void csetcursor ( uint32_t  row,
uint32_t  col 
)

Sets the cursor's position.

Parameters
rowThe row.
colThe column.

◆ csetrow()

void csetrow ( int32_t  row)

Sets the cursor's row.

Parameters
rowRow.

◆ handle_cntrl_char()

static void handle_cntrl_char ( char  c)
static

Handles a control character.

Variable Documentation

◆ col

uint8_t col = 0
static

◆ row

uint8_t row = 0
static

◆ screen_buffer

struct cell screen_buffer[SCREEN_Y][SCREEN_X] = { 0 }
static

The console's screen buffer.

Note
When accessing, use screen_buffer[x][y].