Console can scroll now!
This commit is contained in:
parent
42ac9ebe86
commit
760884de78
3 changed files with 61 additions and 11 deletions
|
@ -38,9 +38,8 @@ Console::Console()
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Console::clear(Console::Color color)
|
Console::clear()
|
||||||
{
|
{
|
||||||
setColor(Color::LightGray, color);
|
|
||||||
for (size_t y = 0; y < Console::Height; y++) {
|
for (size_t y = 0; y < Console::Height; y++) {
|
||||||
for (size_t x = 0; x < Console::Width; x++) {
|
for (size_t x = 0; x < Console::Width; x++) {
|
||||||
putEntryAt(x, y, ' ', mColor);
|
putEntryAt(x, y, ' ', mColor);
|
||||||
|
@ -49,21 +48,31 @@ Console::clear(Console::Color color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Console::clear(Console::Color color)
|
||||||
|
{
|
||||||
|
setColor(Color::LightGray, color);
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Console::writeChar(char c)
|
Console::writeChar(char c)
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
mCursor.col = 0;
|
mCursor.col = 0;
|
||||||
if (++mCursor.row == Console::Height) {
|
if (++mCursor.row >= Console::Height) {
|
||||||
mCursor.row = 0;
|
scroll();
|
||||||
|
mCursor.row = Console::Height - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\t':
|
case '\t':
|
||||||
mCursor.col += 8;
|
mCursor.col += 8;
|
||||||
if (mCursor.col >= Console::Width) {
|
if (mCursor.col >= Console::Width) {
|
||||||
if (++mCursor.row == Console::Height) {
|
if (++mCursor.row >= Console::Height) {
|
||||||
mCursor.row = 0;
|
scroll();
|
||||||
|
mCursor.row = Console::Height - 1;
|
||||||
}
|
}
|
||||||
mCursor.col %= Console::Width;
|
mCursor.col %= Console::Width;
|
||||||
}
|
}
|
||||||
|
@ -72,8 +81,9 @@ Console::writeChar(char c)
|
||||||
putEntryAt(mCursor.col, mCursor.row, c, mColor);
|
putEntryAt(mCursor.col, mCursor.row, c, mColor);
|
||||||
if (++mCursor.col == Console::Width) {
|
if (++mCursor.col == Console::Width) {
|
||||||
mCursor.col = 0;
|
mCursor.col = 0;
|
||||||
if (++mCursor.row == Console::Height) {
|
if (++mCursor.row >= Console::Height) {
|
||||||
mCursor.row = 0;
|
scroll();
|
||||||
|
mCursor.row = Console::Height - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -111,4 +121,27 @@ Console::putEntryAt(size_t x,
|
||||||
mBase[index] = makeVGAEntry(c, color);
|
mBase[index] = makeVGAEntry(c, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Console::scroll(size_t lines)
|
||||||
|
{
|
||||||
|
if (lines == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines > Console::Height) {
|
||||||
|
clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t *dst = mBase;
|
||||||
|
uint16_t *src = mBase + lines * Console::Width;
|
||||||
|
uint16_t *const end = mBase + Console::Width * Console::Height;
|
||||||
|
while (src < end) {
|
||||||
|
*dst++ = *src++;
|
||||||
|
}
|
||||||
|
while (dst < end) {
|
||||||
|
*dst++ = makeVGAEntry(' ', mColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace kernel */
|
} /* namespace kernel */
|
||||||
|
|
|
@ -44,7 +44,8 @@ struct Console
|
||||||
Console();
|
Console();
|
||||||
|
|
||||||
/** Clear the console to the provided color. */
|
/** Clear the console to the provided color. */
|
||||||
void clear(Color color = Color::Black);
|
void clear();
|
||||||
|
void clear(Color color);
|
||||||
|
|
||||||
/** Write a character to the terminal at the current cursor position. */
|
/** Write a character to the terminal at the current cursor position. */
|
||||||
void writeChar(char c);
|
void writeChar(char c);
|
||||||
|
@ -60,6 +61,7 @@ private:
|
||||||
uint8_t mColor;
|
uint8_t mColor;
|
||||||
|
|
||||||
void putEntryAt(size_t x, size_t y, char c, uint8_t color);
|
void putEntryAt(size_t x, size_t y, char c, uint8_t color);
|
||||||
|
void scroll(size_t lines = 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace kernel */
|
} /* namespace kernel */
|
||||||
|
|
19
src/Main.cc
19
src/Main.cc
|
@ -18,8 +18,23 @@ kearly()
|
||||||
kernel::Console console;
|
kernel::Console console;
|
||||||
console.clear(kernel::Console::Color::Blue);
|
console.clear(kernel::Console::Color::Blue);
|
||||||
console.writeString("Hello world!\n");
|
console.writeString("Hello world!\n");
|
||||||
console.writeString("a\nb\nc\n");
|
|
||||||
console.writeString("abc\tdef\tghi\tjkl\tmno\n");
|
volatile int foo = 0;
|
||||||
|
int j = 0;
|
||||||
|
int i = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (j == 0) {
|
||||||
|
console.writeString("--- MARK ---\n");
|
||||||
|
}
|
||||||
|
console.writeChar('a' + i);
|
||||||
|
console.writeChar('\n');
|
||||||
|
i = (i + 1) % 26;
|
||||||
|
j = (j + 1) % 500;
|
||||||
|
|
||||||
|
for (uint32_t k = 0; k < (2u << 27) - 1; k++) {
|
||||||
|
foo /= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue