[Teton] Print out every character into the framebuffer as a test.
This commit is contained in:
parent
afdb024c36
commit
2df1f6c006
|
@ -1,15 +1,25 @@
|
||||||
#include "framebuffer/console.h"
|
#include "framebuffer/console.h"
|
||||||
|
|
||||||
|
#include <mammoth/debug.h>
|
||||||
|
|
||||||
void Console::WriteChar(char c) {
|
void Console::WriteChar(char c) {
|
||||||
|
if (c == '\n') {
|
||||||
|
CursorReturn();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t row = cursor_pos_ / cols();
|
uint64_t row = cursor_pos_ / cols();
|
||||||
|
if (row >= rows()) {
|
||||||
|
crash("Unimplemented console scroll.", glcr::UNIMPLEMENTED);
|
||||||
|
}
|
||||||
uint64_t fb_row = row * (psf_.height() + 1);
|
uint64_t fb_row = row * (psf_.height() + 1);
|
||||||
uint64_t col = cursor_pos_ % cols();
|
uint64_t col = cursor_pos_ % cols();
|
||||||
uint64_t fb_col = col * (psf_.width() + 1);
|
uint64_t fb_col = col * (psf_.width() + 1);
|
||||||
|
|
||||||
uint8_t* glyph = psf_.glyph(c);
|
uint8_t* glyph = psf_.glyph(c);
|
||||||
|
|
||||||
for (uint8_t r = fb_row; r < fb_row + psf_.height(); r++) {
|
for (uint32_t r = fb_row; r < fb_row + psf_.height(); r++) {
|
||||||
for (uint8_t c = fb_col; c < fb_col + psf_.width(); c++) {
|
for (uint32_t c = fb_col; c < fb_col + psf_.width(); c++) {
|
||||||
uint8_t glyph_offset = psf_.width() - (c - fb_col) - 1;
|
uint8_t glyph_offset = psf_.width() - (c - fb_col) - 1;
|
||||||
if ((glyph[r] & (1 << glyph_offset))) {
|
if ((glyph[r] & (1 << glyph_offset))) {
|
||||||
framebuf_.DrawPixel(r, c, 0xFFFFFFF);
|
framebuf_.DrawPixel(r, c, 0xFFFFFFF);
|
||||||
|
@ -21,8 +31,14 @@ void Console::WriteChar(char c) {
|
||||||
|
|
||||||
cursor_pos_++;
|
cursor_pos_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::WriteString(glcr::StringView str) {
|
void Console::WriteString(glcr::StringView str) {
|
||||||
for (uint64_t i = 0; i < str.size(); i++) {
|
for (uint64_t i = 0; i < str.size(); i++) {
|
||||||
WriteChar(str[i]);
|
WriteChar(str[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Console::CursorReturn() {
|
||||||
|
cursor_pos_ -= cursor_pos_ % cols();
|
||||||
|
cursor_pos_ += cols();
|
||||||
|
}
|
||||||
|
|
|
@ -20,4 +20,7 @@ class Console {
|
||||||
Framebuffer& framebuf_;
|
Framebuffer& framebuf_;
|
||||||
Psf& psf_;
|
Psf& psf_;
|
||||||
uint64_t cursor_pos_ = 0;
|
uint64_t cursor_pos_ = 0;
|
||||||
|
|
||||||
|
void CursorIncr();
|
||||||
|
void CursorReturn();
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,10 @@ uint64_t main(uint64_t init_port) {
|
||||||
psf.DumpHeader();
|
psf.DumpHeader();
|
||||||
|
|
||||||
Console console(fbuf, psf);
|
Console console(fbuf, psf);
|
||||||
console.WriteString("Hello World!");
|
console.WriteString("Hello World!\n");
|
||||||
|
for (uint8_t i = 0x20; i < 0x7E; i++) {
|
||||||
|
console.WriteChar(i);
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Write a line to the screen.
|
// 3. Write a line to the screen.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue