Max OS 0.3
Loading...
Searching...
No Matches
vesaboot.cpp
Go to the documentation of this file.
1
10#include <gui/font/amiga_font.h>
11#include <common/logger.h>
12
13using namespace MaxOS;
14using namespace MaxOS::common;
15using namespace MaxOS::gui;
16using namespace MaxOS::memory;
17using namespace MaxOS::drivers;
18using namespace MaxOS::drivers::console;
19using namespace MaxOS::system;
20
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}
45
46VESABootConsole::~VESABootConsole() = default;
47
54 return s_graphics_context->width() / FONT_WIDTH; // 8 pixels per character
55}
56
63 return s_graphics_context->height() / FONT_HEIGHT;
64}
65
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}
138
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}
158
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}
178
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}
198
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}
221
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}
244
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}
282
283
296 uint16_t height,
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}
345
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}
356
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}
Defines the Amiga system font used in the GUI.
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
static Logger HEADER()
Gets active logger set to task level.
Definition logger.cpp:159
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
Definition colour.h:91
ConsoleColour to_console_colour() const
Converts the colour to a console colour.
Definition colour.cpp:261
Draws pixels to the screen, and handles drawing lines, rectangles and circles.
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Type height
The height of the rectangle.
Definition rectangle.h:27
Type width
The width of the rectangle.
Definition rectangle.h:26
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
void set_cursor(uint16_t x, uint16_t y)
Set the m_position of the cursor.
Definition console.cpp:510
virtual void scroll_up()
Scroll the entire console up by 1 line.
Definition console.cpp:142
common::ConsoleColour get_foreground_color(uint16_t x, uint16_t y) final
Gets the foreground color at the specified location.
Definition vesaboot.cpp:206
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 finish() const
Cleans up the boot console.
Definition vesaboot.cpp:349
char get_character(uint16_t x, uint16_t y) final
Gets the character at the specified location.
Definition vesaboot.cpp:186
void put_character(uint16_t x, uint16_t y, char) final
Places a character at the specified location.
Definition vesaboot.cpp:73
uint16_t width() final
Gets the width of the console.
Definition vesaboot.cpp:53
VESABootConsole(common::GraphicsContext *)
Constructs a new VESA Boot Console object, initializing the console area for text output.
Definition vesaboot.cpp:25
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
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
static void update_progress_bar(uint8_t percentage)
Updates the progress bar.
Definition vesaboot.cpp:362
uint16_t height() final
Gets the height of the console.
Definition vesaboot.cpp:62
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
static void * kmalloc(size_t size)
Allocates a block of memory in the KERNEL space.
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
const char *const ANSI_COLOURS[]
ANSI Colour Codes.
Definition colour.h:19
constexpr uint8_t FONT_HEIGHT
How many pixels tall the font is.
Definition font.h:20
constexpr uint8_t FONT_WIDTH
How many pixels wide the font is.
Definition font.h:21
Defines a Logger class for logging messages with different severity levels to multiple output streams...
#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 * memmove(void *destination, const void *source, uint64_t num)
Copies a block of memory from one location to another.
Definition memoryIO.cpp:235
void * memset(void *ptr, uint32_t value, uint64_t num)
Fills a block of memory with a specified value.
Definition memoryIO.cpp:215
bool strcmp(char const *str1, char const *str2)
Checks if one string pointer is equal to another string pointer.
Definition string.cpp:765
Defines the VESABootConsole driver for handling console output during boot using an VESA framebuffer.