Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::drivers::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::drivers::console::TextModeConsole:
MaxOS::drivers::Driver MaxOS::drivers::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::drivers::Driver
virtual void activate ()
 Activate the driver.
 
virtual void deactivate ()
 Deactivate the driver.
 
virtual void initialise ()
 Initialise the driver.
 
virtual uint32_t reset ()
 Reset the driver.
 
virtual string vendor_name ()
 Get who created the device.
 
virtual string device_name ()
 Get the device name of the driver.
 
- Public Member Functions inherited from MaxOS::drivers::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 s, 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 23 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::drivers::console::Console.

Definition at line 145 of file textmode.cpp.

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

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::drivers::console::Console.

Definition at line 105 of file textmode.cpp.

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

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::drivers::console::Console.

Definition at line 125 of file textmode.cpp.

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

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::drivers::console::Console.

Definition at line 34 of file textmode.cpp.

34 {
35 return 25;
36}

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::drivers::console::Console.

Definition at line 45 of file textmode.cpp.

45 {
46
47 // Check bounds
48 if (x >= width() || y >= height())
49 return;
50
51 // Calculate the offset
52 int offset = (y * width() + x);
53
54 // Set the character at the offset, mask away the colour information
55 m_video_memory[offset] = (m_video_memory[offset] & 0xFF00) | (uint16_t) c;
56}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22

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::drivers::console::Console.

Definition at line 85 of file textmode.cpp.

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

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::drivers::console::Console.

Definition at line 65 of file textmode.cpp.

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

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::drivers::console::Console.

Definition at line 25 of file textmode.cpp.

25 {
26 return 80;
27}

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: