Max OS 0.3
Loading...
Searching...
No Matches
textmode.cpp
Go to the documentation of this file.
1
10
11using namespace MaxOS;
12using namespace MaxOS::common;
13using namespace MaxOS::drivers;
14using namespace MaxOS::drivers::console;
15
16TextModeConsole::TextModeConsole() = default;
17
18TextModeConsole::~TextModeConsole() = default;
19
26 return 80;
27}
28
35 return 25;
36}
37
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}
57
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}
77
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}
97
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}
117
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}
137
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}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
void put_character(uint16_t x, uint16_t y, char c) final
Places a character at the specified location if it is in bounds.
Definition textmode.cpp:45
common::ConsoleColour get_background_color(uint16_t x, uint16_t y) final
Gets the background color at the specified location.
Definition textmode.cpp:145
void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the background color at the specified location.
Definition textmode.cpp:85
common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final
Gets the foreground color at the specified location.
Definition textmode.cpp:125
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
void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the foreground color at the specified location.
Definition textmode.cpp:65
char get_character(uint16_t x, uint16_t y) final
Gets the character at the specified location.
Definition textmode.cpp:105
ConsoleColour
Enumeration of console colour codes.
Definition colour.h:67
Defines a TextModeConsole class for handling a console in text mode using VGA.