Max OS 0.3
Loading...
Searching...
No Matches
textmode.cpp
Go to the documentation of this file.
1
9#include <console/textmode.h>
10
11using namespace MaxOS;
12using namespace MaxOS::console;
13using namespace MaxOS::common;
14
15TextModeConsole::TextModeConsole() = default;
16
17TextModeConsole::~TextModeConsole() = default;
18
25 return 80;
26}
27
34 return 25;
35}
36
44void TextModeConsole::put_character(uint16_t x, uint16_t y, char c) {
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}
56
64void TextModeConsole::set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour foreground) {
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}
76
84void TextModeConsole::set_background_color(uint16_t x, uint16_t y, common::ConsoleColour background) {
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}
96
104char TextModeConsole::get_character(uint16_t x, uint16_t y) {
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}
116
124ConsoleColour TextModeConsole::get_foreground_color(uint16_t x, uint16_t y) {
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}
136
144ConsoleColour TextModeConsole::get_background_color(uint16_t x, uint16_t y) {
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}
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:44
common::ConsoleColour get_background_color(uint16_t x, uint16_t y) final
Gets the background color at the specified location.
Definition textmode.cpp:144
void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the background color at the specified location.
Definition textmode.cpp:84
common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final
Gets the foreground color at the specified location.
Definition textmode.cpp:124
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
void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the foreground color at the specified location.
Definition textmode.cpp:64
char get_character(uint16_t x, uint16_t y) final
Gets the character at the specified location.
Definition textmode.cpp:104
Defines a TextModeConsole class for handling a console in text mode using VGA.