IBNOS
Macros | Enumerations | Functions
Console

Macros

#define MAKE_COLOR(foreground, background)   (((foreground) & 15) | (background) << 4)
 
#define MAKE_RAW_CHAR(color, chr)   ((((uint32_t)(chr)) & 0xFF) | (((uint32_t)(color)) & 0xFF) << 8)
 
#define RAW_CHAR_COLOR(raw)   (((raw) >> 8) & 0xFF)
 
#define RAW_CHAR_CHR(raw)   ((raw) & 0xFF)
 
#define BG_COLOR(color)   ((color >> 4) & 15)
 
#define FG_COLOR(color)   (color & 15)
 
#define CONSOLE_WIDTH(size)   (size & 0xFFFF)
 
#define CONSOLE_HEIGHT(size)   ((size >> 16) & 0xFFFF)
 
#define CONSOLE_POSX(pos)   (pos & 0xFFFF)
 
#define CONSOLE_POSY(pos)   ((pos >> 16) & 0xFFFF)
 

Enumerations

enum  VGA_COLOR {
  COLOR_BLACK = 0, COLOR_BLUE = 1, COLOR_GREEN = 2, COLOR_CYAN = 3,
  COLOR_RED = 4, COLOR_MAGENTA = 5, COLOR_BROWN = 6, COLOR_LIGHT_GREY = 7,
  COLOR_DARK_GREY = 8, COLOR_LIGHT_BLUE = 9, COLOR_LIGHT_GREEN = 10, COLOR_LIGHT_CYAN = 11,
  COLOR_LIGHT_RED = 12, COLOR_LIGHT_MAGENTA = 13, COLOR_LIGHT_BROWN = 14, COLOR_WHITE = 15
}
 
enum  CONSOLE_FLAGS { CONFLAGS_ECHO = 1, CONFLAGS_HWCURSOR = 2, CONFLAGS_HWCURSOR_AUTO = 4, CONFLAGS_RAW_MODE = 8 }
 

Functions

void consoleInit ()
 Initializes the console. More...
 
void consoleClear ()
 Clear the screen contents. More...
 
void consoleSetColor (uint8_t color)
 Set the text and background color of the console. More...
 
uint8_t consoleGetColor ()
 Get current color. More...
 
uint8_t consoleGetColorForeground ()
 Get current foreground color. More...
 
uint8_t consoleGetColorBackground ()
 Get current background color. More...
 
void consolePutChar (char chr)
 Write a character on the console. More...
 
void consoleEchoChar (char chr)
 Echo keyboard input on the console. More...
 
void consolePutCharRaw (uint16_t chr)
 Write a raw character and color on the console. More...
 
void consoleWriteString (const char *str)
 Write a C string to the console. More...
 
void consoleWriteStringLen (const char *str, size_t len)
 Write a string with a fixed size to the console. More...
 
void consoleWriteRawLen (const uint16_t *data, size_t count)
 Write raw data with a fixed size to the console. More...
 
void consoleWriteStringMax (const char *str, size_t len)
 Write a nullterminated string or a maximum of len characters. More...
 
void consoleWriteHex32 (uint32_t value)
 Write a 32 bit integer as hex value on the console. More...
 
void consoleWriteInt32 (uint32_t value)
 Write a 32 bit integer as decimal value on the console. More...
 
void consoleWriteHex16 (uint16_t value)
 Write a 16 bit integer as hex value on the console. More...
 
bool consoleSetCursorPos (uint8_t x, uint8_t y)
 Set the position of the text cursor. More...
 
uint32_t consoleGetCursorPos ()
 Get packed position of the text cursor. More...
 
uint32_t consoleGetCursorPosX ()
 Get X position of the text cursor. More...
 
uint32_t consoleGetCursorPosY ()
 Get Y position of the text cursor. More...
 
void consoleScrollUp ()
 Scroll the console up one line. More...
 
uint32_t consoleGetSize ()
 Returns the packed size of the console. More...
 
uint8_t consoleGetHeight ()
 Returns the height (text rows) of the console. More...
 
uint8_t consoleGetWidth ()
 Returns the width (text cols) of the console. More...
 
void consoleShowHardwareCursor (bool changed)
 Show / hide blinking hardware cursor. More...
 
void consoleSetHardwareCursor (uint8_t x, uint8_t y)
 Set the position of the hardware cursor. More...
 
uint32_t consoleGetHardwareCursor ()
 Get packed position of the hardware cursor. More...
 
void consoleSetFont ()
 Load a custom font supporting latin1 characters. More...
 
void consoleSetFlags (uint32_t newFlags)
 Set console flags. More...
 
uint32_t consoleGetFlags ()
 Get console flags. More...
 
void consoleSystemFailure (const char **lines, uint32_t numArgs, uint32_t *args, struct taskContext *context)
 Print a system failure message and halts the system. More...
 

Detailed Description

Macro Definition Documentation

◆ BG_COLOR

#define BG_COLOR (   color)    ((color >> 4) & 15)

Used to extract the background color from a packed color value

Definition at line 100 of file console.h.

◆ CONSOLE_HEIGHT

#define CONSOLE_HEIGHT (   size)    ((size >> 16) & 0xFFFF)

Used to extract the height from a packed size value

Definition at line 115 of file console.h.

◆ CONSOLE_POSX

#define CONSOLE_POSX (   pos)    (pos & 0xFFFF)

Used to extract the X position from a packed position value

Definition at line 120 of file console.h.

◆ CONSOLE_POSY

#define CONSOLE_POSY (   pos)    ((pos >> 16) & 0xFFFF)

Used to extract the Y position from a packed position value

Definition at line 125 of file console.h.

◆ CONSOLE_WIDTH

#define CONSOLE_WIDTH (   size)    (size & 0xFFFF)

Used to extract the width from a packed size value

Definition at line 110 of file console.h.

◆ FG_COLOR

#define FG_COLOR (   color)    (color & 15)

Used to extract the foreground color from a packed color value

Definition at line 105 of file console.h.

◆ MAKE_COLOR

#define MAKE_COLOR (   foreground,
  background 
)    (((foreground) & 15) | (background) << 4)

Combines two 4 bit colors codes into a single byte as required by the VGA card

Definition at line 78 of file console.h.

◆ MAKE_RAW_CHAR

#define MAKE_RAW_CHAR (   color,
  chr 
)    ((((uint32_t)(chr)) & 0xFF) | (((uint32_t)(color)) & 0xFF) << 8)

Combines a color and character code into a packed 16 bit raw character value

Definition at line 83 of file console.h.

◆ RAW_CHAR_CHR

#define RAW_CHAR_CHR (   raw)    ((raw) & 0xFF)

Extract the character code from a raw character

Definition at line 95 of file console.h.

◆ RAW_CHAR_COLOR

#define RAW_CHAR_COLOR (   raw)    (((raw) >> 8) & 0xFF)

Extract the color information from a raw character. Use BG_COLOR and FG_COLOR to extract the returned value into background and foreground color.

Definition at line 90 of file console.h.

Enumeration Type Documentation

◆ CONSOLE_FLAGS

Console flags (can be combined)

Enumerator
CONFLAGS_ECHO 

Show keyboard input

CONFLAGS_HWCURSOR 

Show hardware cursor

CONFLAGS_HWCURSOR_AUTO 

Automatically move hardware cursor

CONFLAGS_RAW_MODE 

Do not parse linebreaks or scroll up

Definition at line 66 of file console.h.

◆ VGA_COLOR

enum VGA_COLOR

Text mode colors codes

Enumerator
COLOR_BLACK 
COLOR_BLUE 
COLOR_GREEN 
COLOR_CYAN 
COLOR_RED 
COLOR_MAGENTA 
COLOR_BROWN 
COLOR_LIGHT_GREY 
COLOR_DARK_GREY 
COLOR_LIGHT_BLUE 
COLOR_LIGHT_GREEN 
COLOR_LIGHT_CYAN 
COLOR_LIGHT_RED 
COLOR_LIGHT_MAGENTA 
COLOR_LIGHT_BROWN 
COLOR_WHITE 

Definition at line 43 of file console.h.

Function Documentation

◆ consoleClear()

void consoleClear ( )

Clear the screen contents.

This function removes all text from the screen and sets the cursor to the top left corner.

Definition at line 90 of file console.c.

◆ consoleEchoChar()

void consoleEchoChar ( char  chr)

Echo keyboard input on the console.

This function is used internally by the keyboard driver to directly print the typed character onto the screen.

Parameters
chrEntered characters

Definition at line 193 of file console.c.

◆ consoleGetColor()

uint8_t consoleGetColor ( )

Get current color.

The returned value contains the background and foreground color. Use the BG_COLOR and FG_COLOR macro to get the individual values.

Returns
Foreground and background color

Definition at line 124 of file console.c.

◆ consoleGetColorBackground()

uint8_t consoleGetColorBackground ( )

Get current background color.

Returns
Background color

Definition at line 143 of file console.c.

◆ consoleGetColorForeground()

uint8_t consoleGetColorForeground ( )

Get current foreground color.

Returns
Foreground color

Definition at line 134 of file console.c.

◆ consoleGetCursorPos()

uint32_t consoleGetCursorPos ( )

Get packed position of the text cursor.

Use the CONSOLE_POSX and CONSOLE_POSY macro to extract the the X and Y position from this value.

Returns
Packed position containing the X and Y coordinate

Definition at line 388 of file console.c.

◆ consoleGetCursorPosX()

uint32_t consoleGetCursorPosX ( )

Get X position of the text cursor.

Returns
X coordinate

Definition at line 397 of file console.c.

◆ consoleGetCursorPosY()

uint32_t consoleGetCursorPosY ( )

Get Y position of the text cursor.

Returns
Y coordinate

Definition at line 406 of file console.c.

◆ consoleGetFlags()

uint32_t consoleGetFlags ( )

Get console flags.

Returns
Returns the current the active CONSOLE_FLAGS flags

Definition at line 564 of file console.c.

◆ consoleGetHardwareCursor()

uint32_t consoleGetHardwareCursor ( )

Get packed position of the hardware cursor.

Use the CONSOLE_POSX and CONSOLE_POSY macro to extract the the X and Y position from this value.

Returns
Packed position containing the X and Y coordinate

Definition at line 513 of file console.c.

◆ consoleGetHeight()

uint8_t consoleGetHeight ( )

Returns the height (text rows) of the console.

Returns
Height

Definition at line 434 of file console.c.

◆ consoleGetSize()

uint32_t consoleGetSize ( )

Returns the packed size of the console.

Use the CONSOLE_HEIGHT and CONSOLE_WIDTH macros to get the individual values.

Returns
Packed size

Definition at line 454 of file console.c.

◆ consoleGetWidth()

uint8_t consoleGetWidth ( )

Returns the width (text cols) of the console.

Returns
Width

Definition at line 443 of file console.c.

◆ consoleInit()

void consoleInit ( )

Initializes the console.

This function claims the memory area of the VGA graphic card to protect it from being treated as assignable memory. This function is called during the bootup of the operating system.

Definition at line 79 of file console.c.

◆ consolePutChar()

void consolePutChar ( char  chr)

Write a character on the console.

This functions writes a character on the terminal at the current cursor position. It will automatically insert line breaks if necessary (i.e. the end of the line is reached).

Parameters
chrThe character which should be printed

Definition at line 156 of file console.c.

◆ consolePutCharRaw()

void consolePutCharRaw ( uint16_t  chr)

Write a raw character and color on the console.

This functions writes a character and color on the terminal at the current cursor position. The character code and color is packed in a 16 bit value. Use the MAKE_RAW_CHAR macro to create such values.

Parameters
chrThe character which should be printed

Definition at line 208 of file console.c.

◆ consoleScrollUp()

void consoleScrollUp ( )

Scroll the console up one line.

This function scrolls the console up one line, so that every character is move to the previous line and the first line is discarded. The cursors are not modified.

Definition at line 417 of file console.c.

◆ consoleSetColor()

void consoleSetColor ( uint8_t  color)

Set the text and background color of the console.

This function alters the current color of the console and will affect all further write operations. The color will stay active till it is changed again.

Parameters
colorThe color to set, use the MAKE_COLOR() macro

Definition at line 113 of file console.c.

◆ consoleSetCursorPos()

bool consoleSetCursorPos ( uint8_t  x,
uint8_t  y 
)

Set the position of the text cursor.

Parameters
xX coordinate to set
yY coordinate to set
Returns
True if successful or false otherwise (coordinate out of range)

Definition at line 371 of file console.c.

◆ consoleSetFlags()

void consoleSetFlags ( uint32_t  flags)

Set console flags.

Parameters
flagsCombination of the CONSOLE_FLAGS values

Definition at line 554 of file console.c.

◆ consoleSetFont()

void consoleSetFont ( )

Load a custom font supporting latin1 characters.

This function loads a custom font (see vgafont.c) supporting latin1 encoding which is required to display some characters like the german ü, ä, ö or the € symbol.

Definition at line 526 of file console.c.

◆ consoleSetHardwareCursor()

void consoleSetHardwareCursor ( uint8_t  x,
uint8_t  y 
)

Set the position of the hardware cursor.

Parameters
xX coordinate
yY coordinate

Definition at line 498 of file console.c.

◆ consoleShowHardwareCursor()

void consoleShowHardwareCursor ( bool  changed)

Show / hide blinking hardware cursor.

Parameters
changedTrue if the cursor visibility changed

Definition at line 464 of file console.c.

◆ consoleSystemFailure()

void consoleSystemFailure ( const char **  lines,
uint32_t  numArgs,
uint32_t *  args,
struct taskContext context 
)

Print a system failure message and halts the system.

This function displays an error message, some optional hex values (for example the error code or offending function arguments), plus the current CPU context. The first line defines the header of the crash screen and all other lines will be shown as normal text.

Parameters
linesArray of string pointers, terminated with a NULL pointer
numArgsNumber of 32 bit integers to print
argsArray of 32 bit integers
contextThe CPU context which should be shown or NULL otherwise
char *msg[] = {" ERROR TITLE ", "First line", "Second line", NULL};
uint32_t arguments[] = {0, 1, 2};
consoleSystemFailure(msg, 3, arguments, NULL);

Definition at line 589 of file console.c.

◆ consoleWriteHex16()

void consoleWriteHex16 ( uint16_t  value)

Write a 16 bit integer as hex value on the console.

This function will convert a 16 bit value to a hex string and print it at the current cursor position.

Parameters
valueThe value to print

Definition at line 348 of file console.c.

◆ consoleWriteHex32()

void consoleWriteHex32 ( uint32_t  value)

Write a 32 bit integer as hex value on the console.

This function will convert a 32 bit value to a hex string and print it at the current cursor position.

Parameters
valueThe value to print

Definition at line 303 of file console.c.

◆ consoleWriteInt32()

void consoleWriteInt32 ( uint32_t  value)

Write a 32 bit integer as decimal value on the console.

This function will convert a 32 bit value to a decimal string and print it at the current cursor position.

Parameters
valueThe value to print

Definition at line 325 of file console.c.

◆ consoleWriteRawLen()

void consoleWriteRawLen ( const uint16_t *  data,
size_t  count 
)

Write raw data with a fixed size to the console.

Parameters
dataPointer to the data
countNumber of characters to write

Definition at line 269 of file console.c.

◆ consoleWriteString()

void consoleWriteString ( const char *  str)

Write a C string to the console.

Parameters
strPointer to the string

Definition at line 240 of file console.c.

◆ consoleWriteStringLen()

void consoleWriteStringLen ( const char *  str,
size_t  len 
)

Write a string with a fixed size to the console.

Parameters
strPointer to the string
lenNumber of bytes to write

Definition at line 254 of file console.c.

◆ consoleWriteStringMax()

void consoleWriteStringMax ( const char *  str,
size_t  len 
)

Write a nullterminated string or a maximum of len characters.

This function writes a string to the console, but will stop after either len character have been written or when it detects a NULL character inside of the string.

Parameters
strPointer to the string
lenMaximum number of bytes to print

Definition at line 287 of file console.c.