Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::console::TextModeConsole Class Reference

Driver for the text mode console, handles the printing of characters and strings to the screen using VGA. More...

#include <textmode.h>

Inheritance diagram for MaxOS::console::TextModeConsole:
MaxOS::console::Console

Public Member Functions

uint16_t width () final
 Gets the width of the console.
 
uint16_t height () final
 Gets the height of the console.
 
void put_character (uint16_t x, uint16_t y, char c) final
 Places a character at the specified location if it is in bounds.
 
void set_foreground_color (uint16_t x, uint16_t y, common::ConsoleColour) final
 Sets the foreground color at the specified location.
 
void set_background_color (uint16_t x, uint16_t y, common::ConsoleColour) final
 Sets the background color at the specified location.
 
char get_character (uint16_t x, uint16_t y) final
 Gets the character at the specified location.
 
common::ConsoleColour get_foreground_color (uint16_t x, uint16_t y) final
 Gets the foreground color at the specified location.
 
common::ConsoleColour get_background_color (uint16_t x, uint16_t y) final
 Gets the background color at the specified location.
 
- Public Member Functions inherited from MaxOS::console::Console
virtual void put_character (uint16_t x, uint16_t y, char c, common::ConsoleColour foreground, common::ConsoleColour background)
 Put a character on the console with a given foreground and background color.
 
virtual void put_string (uint16_t x, uint16_t y, string string, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black)
 Put a string on the console.
 
virtual void scroll_up ()
 Scroll the entire console up by 1 line.
 
virtual void scroll_up (uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black, char fill=' ')
 Scroll an area of the console up by 1 line.
 
virtual void clear ()
 
virtual void clear (uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground=common::ConsoleColour::LightGrey, common::ConsoleColour background=common::ConsoleColour::Black, char fill=' ')
 Clear an area of the console.
 
virtual void invert_colors (uint16_t x, uint16_t y)
 Invert the colors of a character on the console.
 

Detailed Description

Driver for the text mode console, handles the printing of characters and strings to the screen using VGA.

Definition at line 22 of file textmode.h.

Member Function Documentation

◆ get_background_color()

ConsoleColour TextModeConsole::get_background_color ( uint16_t  x,
uint16_t  y 
)
finalvirtual

Gets the background color at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
Returns
The background color at the specified location or black if the coordinates are out of bounds

Reimplemented from MaxOS::console::Console.

Definition at line 144 of file textmode.cpp.

144 {
145
146 // Check bounds
147 if (x >= width() || y >= height())
148 return ConsoleColour::Black;
149
150 // Calculate the offset
151 int offset = (y * width() + x);
152
153 // Return the background color at the offset, by masking the background color with the current background color (bits 12-15)
154 return (ConsoleColour) ((m_video_memory[offset] & 0xF000) >> 12);
155}
uint16_t width() final
Gets the width of the console.
Definition textmode.cpp:24
uint16_t height() final
Gets the height of the console.
Definition textmode.cpp:33

References height(), and width().

◆ get_character()

char TextModeConsole::get_character ( uint16_t  x,
uint16_t  y 
)
finalvirtual

Gets the character at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
Returns
The character at the specified location or a space if the coordinates are out of bounds

Reimplemented from MaxOS::console::Console.

Definition at line 104 of file textmode.cpp.

104 {
105
106 // Check bounds
107 if (x >= width() || y >= height())
108 return ' ';
109
110 // Calculate the offset
111 int offset = (y * width() + x);
112
113 // Return the character at the offset, mask away the colour information
114 return (char) (m_video_memory[offset] & 0x00FF);
115}

References height(), and width().

◆ get_foreground_color()

ConsoleColour TextModeConsole::get_foreground_color ( uint16_t  x,
uint16_t  y 
)
finalvirtual

Gets the foreground color at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
Returns
The foreground color at the specified location or white if the coordinates are out of bounds

Reimplemented from MaxOS::console::Console.

Definition at line 124 of file textmode.cpp.

124 {
125
126 // Check bounds
127 if (x >= width() || y >= height())
128 return ConsoleColour::White;
129
130 // Calculate the offset
131 int offset = (y * width() + x);
132
133 // Return the foreground color at the offset, by masking the foreground color with the current foreground color (bits 8-11)
134 return (ConsoleColour) ((m_video_memory[offset] & 0x0F00) >> 8);
135}

References height(), and width().

◆ height()

uint16_t TextModeConsole::height ( )
finalvirtual

Gets the height of the console.

Returns
The height of the console in characters

Reimplemented from MaxOS::console::Console.

Definition at line 33 of file textmode.cpp.

33 {
34 return 25;
35}

Referenced by get_background_color(), get_character(), get_foreground_color(), put_character(), set_background_color(), and set_foreground_color().

◆ put_character()

void TextModeConsole::put_character ( uint16_t  x,
uint16_t  y,
char  c 
)
finalvirtual

Places a character at the specified location if it is in bounds.

Parameters
xThe x coordinate
yThe y coordinate
cThe character to place

Reimplemented from MaxOS::console::Console.

Definition at line 44 of file textmode.cpp.

44 {
45
46 // Check bounds
47 if (x >= width() || y >= height())
48 return;
49
50 // Calculate the offset
51 int offset = (y * width() + x);
52
53 // Set the character at the offset, mask away the colour information
54 m_video_memory[offset] = (m_video_memory[offset] & 0xFF00) | (uint16_t) c;
55}

References height(), and width().

◆ set_background_color()

void TextModeConsole::set_background_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  background 
)
finalvirtual

Sets the background color at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
backgroundThe background color

Reimplemented from MaxOS::console::Console.

Definition at line 84 of file textmode.cpp.

84 {
85
86 // Check bounds
87 if (x >= width() || y >= height())
88 return;
89
90 // Calculate the offset
91 int offset = (y * width() + x);
92
93 // Set the background color at the offset, mask to get the backgroun bits
94 m_video_memory[offset] = (m_video_memory[offset] & 0x0FFF) | ((uint16_t) background << 12);
95}

References height(), and width().

◆ set_foreground_color()

void TextModeConsole::set_foreground_color ( uint16_t  x,
uint16_t  y,
common::ConsoleColour  foreground 
)
finalvirtual

Sets the foreground color at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
foregroundThe foreground color

Reimplemented from MaxOS::console::Console.

Definition at line 64 of file textmode.cpp.

64 {
65
66 // Check bounds
67 if (x >= width() || y >= height())
68 return;
69
70 // Calculate the offset
71 int offset = (y * width() + x);
72
73 // Set the foreground color at the offset, mask to get the foreground bits
74 m_video_memory[offset] = (m_video_memory[offset] & 0xF0FF) | ((uint16_t) foreground << 8);
75}

References height(), and width().

◆ width()

uint16_t TextModeConsole::width ( )
finalvirtual

Gets the width of the console.

Returns
The width of the console in characters

Reimplemented from MaxOS::console::Console.

Definition at line 24 of file textmode.cpp.

24 {
25 return 80;
26}

Referenced by get_background_color(), get_character(), get_foreground_color(), put_character(), set_background_color(), and set_foreground_color().


The documentation for this class was generated from the following files: