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

Driver for the VESA Console during boot, handles the printing of characters and strings to the screen using VESA protocol. More...

#include <vesaboot.h>

Inheritance diagram for MaxOS::drivers::console::VESABootConsole:
MaxOS::drivers::Driver MaxOS::drivers::console::Console

Public Member Functions

 VESABootConsole (common::GraphicsContext *)
 Constructs a new VESA Boot Console object, initializing the console area for text output.
 
uint16_t width () final
 Gets the width of the console.
 
uint16_t height () final
 Gets the height of the console.
 
void finish () const
 Cleans up the boot console.
 
void put_character (uint16_t x, uint16_t y, char) final
 Places a character at the specified location.
 
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.
 
void scroll_up (uint16_t left, uint16_t top, uint16_t width, uint16_t height, common::ConsoleColour foreground, common::ConsoleColour background, char fill) final
 Scrolls the console up by 1 line.
 
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 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.
 

Static Public Member Functions

static void print_logo (bool is_panic=false)
 Prints the logo to the center of the screen.
 
static void update_progress_bar (uint8_t percentage)
 Updates the progress bar.
 

Public Attributes

ConsoleStreamcout
 The boot console output stream.
 

Detailed Description

Driver for the VESA Console during boot, handles the printing of characters and strings to the screen using VESA protocol.

Definition at line 30 of file vesaboot.h.

Constructor & Destructor Documentation

◆ VESABootConsole()

VESABootConsole::VESABootConsole ( common::GraphicsContext graphics_context)
explicit

Constructs a new VESA Boot Console object, initializing the console area for text output.

Parameters
graphics_contextThe graphics context to use for rendering

Definition at line 25 of file vesaboot.cpp.

26 : m_font((uint8_t*) AMIGA_FONT) {
27
28 // Set up
29 Logger::INFO() << "Setting up VESA console\n";
30 s_graphics_context = graphics_context;
31 m_video_memory_meta = (uint16_t*) MemoryManager::kmalloc(width() * height() * sizeof(uint16_t));
32
33 // Prepare the console
35 print_logo();
36 m_console_area = new ConsoleArea(this, 0, 0, width() / 2 - 25, height(), ConsoleColour::DarkGrey, ConsoleColour::Black);
37 cout = new ConsoleStream(m_console_area);
38
39 // Only log to the screen when debugging
40#ifndef NDEBUG
41 Logger::active_logger()->add_log_writer(cout);
42 Logger::INFO() << "Console Stream set up \n";
43#endif
44}
static Logger * active_logger()
Gets the active logger (to be used to modify the logger)
Definition logger.cpp:228
static Logger INFO()
Gets active logger set to info level.
Definition logger.cpp:171
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
A console that is a subsection of another console, limited by a width and height.
Definition console.h:59
A stream that can be used to write to a console.
Definition console.h:91
uint16_t width() final
Gets the width of the console.
Definition vesaboot.cpp:53
static void print_logo(bool is_panic=false)
Prints the logo to the center of the screen.
Definition vesaboot.cpp:250
ConsoleStream * cout
The boot console output stream.
Definition vesaboot.h:51
uint16_t height() final
Gets the height of the console.
Definition vesaboot.cpp:62
static void * kmalloc(size_t size)
Allocates a block of memory in the KERNEL space.

References MaxOS::Logger::active_logger(), MaxOS::drivers::console::Console::clear(), cout, height(), MaxOS::Logger::INFO(), MaxOS::memory::MemoryManager::kmalloc(), print_logo(), and width().

Member Function Documentation

◆ finish()

void VESABootConsole::finish ( ) const

Cleans up the boot console.

Definition at line 349 of file vesaboot.cpp.

349 {
350
351 // Done
352 Logger::HEADER() << "MaxOS Kernel Successfully Booted\n" << ANSI_COLOURS[ANSIColour::Reset];
353 cout->set_cursor(0, 0);
354 Logger::active_logger()->disable_log_writer(cout);
355}
static Logger HEADER()
Gets active logger set to task level.
Definition logger.cpp:159
void set_cursor(uint16_t x, uint16_t y)
Set the m_position of the cursor.
Definition console.cpp:510
const char *const ANSI_COLOURS[]
ANSI Colour Codes.
Definition colour.h:19

References MaxOS::Logger::active_logger(), MaxOS::common::ANSI_COLOURS, cout, MaxOS::Logger::HEADER(), and MaxOS::drivers::console::ConsoleStream::set_cursor().

Referenced by kernel_main().

◆ get_background_color()

ConsoleColour VESABootConsole::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 229 of file vesaboot.cpp.

229 {
230
231 if(CPU::panic_lock.is_locked())
232 return ConsoleColour::Red;
233
234 // If the coordinates are out of bounds, return
235 if(x >= width() || y >= height())
236 return ConsoleColour::Black;
237
238 // Calculate the offset
239 int offset = (y * width() + x);
240
241 // Return the background color at the offset, by masking the background color with the current background color (bits 12-15)
242 return (ConsoleColour) ((m_video_memory_meta[offset] & 0xF000) >> 12);
243}
static common::Spinlock panic_lock
Lock to prevent multiple panics at once.
Definition cpu.h:264
ConsoleColour
Enumeration of console colour codes.
Definition colour.h:67

References height(), MaxOS::system::CPU::panic_lock, and width().

Referenced by put_character(), and scroll_up().

◆ get_character()

char VESABootConsole::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 186 of file vesaboot.cpp.

186 {
187
188 // If the coordinates are out of bounds, return
189 if(x >= width() || y >= height())
190 return ' ';
191
192 // Calculate the offset
193 int offset = (y * width() + x);
194
195 // Return the character at the offset, by masking the character with the current character (last 8 bits)
196 return (char) (m_video_memory_meta[offset] & 0x00FF);
197}

References height(), and width().

◆ get_foreground_color()

ConsoleColour VESABootConsole::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 206 of file vesaboot.cpp.

206 {
207
208 if(CPU::panic_lock.is_locked())
209 return ConsoleColour::White;
210
211 // If the coordinates are out of bounds, return
212 if(x >= width() || y >= height())
213 return ConsoleColour::White;
214
215 // Calculate the offset
216 int offset = (y * width() + x);
217
218 // Return the foreground color at the offset, by masking the foreground color with the current foreground color (bits 8-11)
219 return (ConsoleColour) ((m_video_memory_meta[offset] & 0x0F00) >> 8);
220}

References height(), MaxOS::system::CPU::panic_lock, and width().

Referenced by put_character(), and scroll_up().

◆ height()

uint16_t VESABootConsole::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 62 of file vesaboot.cpp.

62 {
63 return s_graphics_context->height() / FONT_HEIGHT;
64}
Type height
The height of the rectangle.
Definition rectangle.h:27
constexpr uint8_t FONT_HEIGHT
How many pixels tall the font is.
Definition font.h:20

References MaxOS::gui::FONT_HEIGHT, and MaxOS::common::Rectangle< Type >::height.

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

◆ print_logo()

void VESABootConsole::print_logo ( bool  is_panic = false)
static

Prints the logo to the center of the screen.

Parameters
is_panicWhether to print the kernel panic logo or the normal logo

Definition at line 250 of file vesaboot.cpp.

250 {
251
252 // Load the logo
253 const char* logo = is_panic ? header_data_kp : header_data;
254
255 // Find the center of the screen
256 uint32_t screen_width = s_graphics_context->width();
257 uint32_t screen_height = s_graphics_context->height();
260
261 // Fill the screen with the logo colour
262 auto col = Colour(is_panic ? ConsoleColour::Red : ConsoleColour::Black);
263 memset(s_graphics_context->framebuffer_address(), s_graphics_context->colour_to_int(col), screen_width * screen_height * (s_graphics_context->color_depth() / 8));
264
265 // Draw the logo
266 for(uint32_t logo_y = 0; logo_y < LOGO_HEIGHT; ++logo_y) {
267 for(uint32_t logo_x = 0; logo_x < LOGO_WIDTH; ++logo_x) {
268
269 // Get the pixel from the logo
270 uint8_t pixel[3] = { 0 };
272
273 // Draw the pixel
274 s_graphics_context->put_pixel(center_x - LOGO_WIDTH / 2 + logo_x,
276 common::Colour(pixel[0], pixel[1], pixel[2]));
277 }
278 }
279
281}
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
Definition colour.h:91
Type width
The width of the rectangle.
Definition rectangle.h:26
static void update_progress_bar(uint8_t percentage)
Updates the progress bar.
Definition vesaboot.cpp:362
#define LOGO_HEADER_PIXEL(data, pixel)
Call this macro repeatedly. After each use, the pixel data can be extracted.
Definition logo.h:21
constexpr int LOGO_WIDTH
Width of the logo in pixels.
Definition logo.h:17
constexpr int LOGO_HEIGHT
Height of the logo in pixels.
Definition logo.h:18
void * memset(void *ptr, uint32_t value, uint64_t num)
Fills a block of memory with a specified value.
Definition memoryIO.cpp:215

References MaxOS::common::Rectangle< Type >::height, LOGO_HEADER_PIXEL, LOGO_HEIGHT, LOGO_WIDTH, memset(), update_progress_bar(), and MaxOS::common::Rectangle< Type >::width.

Referenced by MaxOS::system::CPU::prepare_for_panic(), and VESABootConsole().

◆ put_character()

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

Places a character at the specified location.

Parameters
xThe x coordinate
yThe y coordinate
cThe character to place

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 73 of file vesaboot.cpp.

73 {
74
75 // Parse any ansi codes
76 if(c == '\033') {
77
78 // Store the character
79 ansi_code_length = 0;
80 ansi_code[ansi_code_length++] = c;
81
82 // Do not draw the escape character
83 return;
84 }
85
86 if(ansi_code_length < 8) {
87
88 // Add the character to the ANSI code
89 ansi_code[ansi_code_length++] = c;
90
91 // If the ANSI code is complete
92 if(c == 'm') {
93 ansi_code[ansi_code_length] = '\0';
94 ansi_code_length = -1;
95
96 if(strcmp("\033[0m", ansi_code) != 0) {
97 m_foreground_color = ConsoleColour::Uninitialised;
98 m_background_color = ConsoleColour::Uninitialised;
99 return;
100 }
101
102 // Get the colour from the ANSI code
103 const Colour colour(ansi_code);
104
105 // Set the colour
106 bool foreground = ansi_code[4] == '3';
107 if(foreground)
108 m_foreground_color = colour.to_console_colour();
109 else
110 m_background_color = colour.to_console_colour();
111
112 }
113
114 // Do not draw the escape character
115 return;
116 }
117
118 // If the coordinates are out of bounds, return
119 if(x >= width() || y >= height())
120 return;
121
122 // Calculate the offset
123 int offset = (y * width() + x);
124
125 // Set the character at the offset, by masking the character with the current character (last 8 bits)
126 m_video_memory_meta[offset] = (m_video_memory_meta[offset] & 0xFF00) | (uint16_t) c;
127
128 // Convert the char into a string
129 char s[] = " ";
130 s[0] = c;
131
132 Colour foreground = m_foreground_color == ConsoleColour::Uninitialised ? Colour(get_foreground_color(x, y)) : Colour(m_foreground_color);
133 Colour background = m_background_color == ConsoleColour::Uninitialised ? Colour(get_background_color(x, y)) : Colour(m_background_color);
134
135 // Use the m_font to draw the character
136 m_font.draw_text(x * 8, y * FONT_HEIGHT, foreground, background, s_graphics_context, s);
137}
common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final
Gets the foreground color at the specified location.
Definition vesaboot.cpp:206
common::ConsoleColour get_background_color(uint16_t x, uint16_t y) final
Gets the background color at the specified location.
Definition vesaboot.cpp:229
virtual void draw_text(int32_t x, int32_t y, common::Colour foreground_colour, common::Colour background_colour, common::GraphicsContext *context, string text)
write the entire text to the screen
Definition font.cpp:41
bool strcmp(char const *str1, char const *str2)
Checks if one string pointer is equal to another string pointer.
Definition string.cpp:765

References MaxOS::gui::Font::draw_text(), MaxOS::gui::FONT_HEIGHT, get_background_color(), get_foreground_color(), height(), strcmp(), MaxOS::common::Colour::to_console_colour(), and width().

◆ scroll_up()

void VESABootConsole::scroll_up ( uint16_t  left,
uint16_t  top,
uint16_t  width,
uint16_t  height,
common::ConsoleColour  foreground,
common::ConsoleColour  background,
char  fill 
)
finalvirtual

Scrolls the console up by 1 line.

Parameters
leftThe left coordinate of the area to scroll
topThe top coordinate of the area to scroll
widthThe width of the area to scroll
heightThe height of the area to scroll
foregroundThe foreground color of the new line
backgroundThe background color of the new line
fillThe character to fill the new line with

Reimplemented from MaxOS::drivers::console::Console.

Definition at line 295 of file vesaboot.cpp.

298 {
299
300
301 // Get the framebuffer info
302 auto* framebuffer_address = (uint8_t*) s_graphics_context->framebuffer_address();
303 uint64_t framebuffer_width = s_graphics_context->width();
304 uint64_t framebuffer_bpp = s_graphics_context->color_depth(); // in bits per pixel
305 uint64_t bytes_per_pixel = framebuffer_bpp / 8;
306 uint64_t framebuffer_pitch = framebuffer_width * bytes_per_pixel;
307
309
310 // Region conversions
316
317 // Decide the colour of the pixel
320 uint32_t fill_value = s_graphics_context->colour_to_int(Colour(to_set_background));
321
322 // Scroll the region upward by one text line
324 uint8_t* src = framebuffer_address + (region_pixel_y + row + line_height) * framebuffer_pitch + region_pixel_left * bytes_per_pixel;
325 uint8_t* dest = framebuffer_address + (region_pixel_y + row) * framebuffer_pitch + region_pixel_left * bytes_per_pixel;
327 }
328
329 // Clear the last line of the region
331 for(uint16_t row = 0; row < line_height; row++) {
332 auto row_add = (uint32_t*) (framebuffer_address + (clear_start_y + row) * framebuffer_pitch + region_pixel_left * 4);
333 for(uint16_t col = 0; col < region_pixel_width; col++) {
335 }
336 }
337
338 //Update any per-pixel colour metadata
339 uint16_t text_row = top + height - 1;
340 for(uint16_t x = left; x < left + width; x++) {
343 }
344}
void set_foreground_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the foreground color at the specified location.
Definition vesaboot.cpp:146
void set_background_color(uint16_t x, uint16_t y, common::ConsoleColour) final
Sets the background color at the specified location.
Definition vesaboot.cpp:166
constexpr uint8_t FONT_WIDTH
How many pixels wide the font is.
Definition font.h:21
void * memmove(void *destination, const void *source, uint64_t num)
Copies a block of memory from one location to another.
Definition memoryIO.cpp:235

References MaxOS::gui::FONT_HEIGHT, MaxOS::gui::FONT_WIDTH, get_background_color(), get_foreground_color(), height(), memmove(), set_background_color(), set_foreground_color(), MaxOS::common::Rectangle< Type >::width, and width().

◆ set_background_color()

void VESABootConsole::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 166 of file vesaboot.cpp.

166 {
167
168 // If the coordinates are out of bounds, return
169 if(x >= width() || y >= height())
170 return;
171
172 // Calculate the offset
173 int offset = (y * width() + x);
174
175 // Set the background color at the offset, by masking the background color with the current background color (bits 12-15)
176 m_video_memory_meta[offset] = (m_video_memory_meta[offset] & 0x0FFF) | ((uint16_t) background << 12);
177}

References height(), and width().

Referenced by scroll_up().

◆ set_foreground_color()

void VESABootConsole::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 146 of file vesaboot.cpp.

146 {
147
148 // If the coordinates are out of bounds, return
149 if(x >= width() || y >= height())
150 return;
151
152 // Calculate the offset
153 int offset = (y * width() + x);
154
155 // Set the foreground color at the offset, by masking the foreground color with the current foreground color (bits 8-11)
156 m_video_memory_meta[offset] = (m_video_memory_meta[offset] & 0xF0FF) | ((uint16_t) foreground << 8);
157}

References height(), and width().

Referenced by scroll_up().

◆ update_progress_bar()

void VESABootConsole::update_progress_bar ( uint8_t  percentage)
static

Updates the progress bar.

Parameters
percentageThe percentage to update the progress bar to (0-100)

Definition at line 362 of file vesaboot.cpp.

362 {
363
364 // Check bounds
365 if(percentage > 100)
366 percentage = 100;
367
368 // Must have a valid graphics context
369 if(s_graphics_context == nullptr)
370 return;
371
375
376 // Find the center of the screen
377 uint32_t right_x = (s_graphics_context->width() / 2) - LOGO_WIDTH / 2;
378 uint32_t bottom_y = (s_graphics_context->height() / 2 - 80) - LOGO_HEIGHT / 2;
379
380 // Find the bounds
385
386 // Draw the progress bar
389
390 // Check if drawing border
391 bool is_border = (progress_y == start_y) || (progress_y == end_y - 1) ||
392 (progress_x == start_x) || (progress_x == end_x - 1);
393
394 // Only draw the border if it is the first time drawing it
396
397 // If it is not within the percentage, skip it
400 continue;
401
402 s_graphics_context->put_pixel(right_x + progress_x, bottom_y + progress_y, Colour(0xFF, 0xFF, 0xFF));
403
404 }
405 }
406}

References MaxOS::common::Rectangle< Type >::height, LOGO_HEIGHT, LOGO_WIDTH, and MaxOS::common::Rectangle< Type >::width.

Referenced by print_logo(), and MaxOS::Logger::set_log_level().

◆ width()

uint16_t VESABootConsole::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 53 of file vesaboot.cpp.

53 {
54 return s_graphics_context->width() / FONT_WIDTH; // 8 pixels per character
55}

References MaxOS::gui::FONT_WIDTH, and MaxOS::common::Rectangle< Type >::width.

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

Member Data Documentation

◆ cout

ConsoleStream* MaxOS::drivers::console::VESABootConsole::cout

The boot console output stream.

Definition at line 51 of file vesaboot.h.

Referenced by finish(), and VESABootConsole().


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