Updated vgaterminal.cpp to newer coding conventions.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-07-22 18:22:38 +02:00
parent d75a7145ef
commit 3907e14cb8
2 changed files with 515 additions and 533 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************** /*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix. This file is part of Sortix.
@ -14,13 +14,13 @@
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along with
with Sortix. If not, see <http://www.gnu.org/licenses/>. Sortix. If not, see <http://www.gnu.org/licenses/>.
vgaterminal.cpp vgaterminal.cpp
A terminal based on the VGA text mode buffer. A terminal based on a text mode buffer.
******************************************************************************/ *******************************************************************************/
#include <sortix/kernel/platform.h> #include <sortix/kernel/platform.h>
#include <sortix/kernel/log.h> #include <sortix/kernel/log.h>
@ -31,21 +31,20 @@
using namespace Maxsi; using namespace Maxsi;
namespace Sortix namespace Sortix {
{ namespace VGATerminal {
namespace VGATerminal
{ const unsigned width = 80;
const nat width = 80; const unsigned height = 25;
const nat height = 25; const uint16_t DEFAULT_COLOR = (COLOR8_LIGHT_GREY << 8) | (COLOR8_BLACK << 12);
const uint16_t defaultcolor = (COLOR8_LIGHT_GREY << 8) | (COLOR8_BLACK << 12);
uint16_t* const vga = (uint16_t* const) 0xB8000; uint16_t* const vga = (uint16_t* const) 0xB8000;
uint16_t vgaattr[width * height]; uint16_t vgaattr[width * height];
const uint16_t VGAATTR_CHAR = (1U<<0U); const uint16_t VGAATTR_CHAR = (1U<<0U);
nat line; unsigned line;
nat column; unsigned column;
uint16_t currentcolor; uint16_t currentcolor;
nat ansisavedposx; unsigned ansisavedposx;
nat ansisavedposy; unsigned ansisavedposy;
bool showcursor; bool showcursor;
enum enum
@ -58,14 +57,10 @@ namespace Sortix
void UpdateCursor() void UpdateCursor()
{ {
if ( showcursor ) if ( showcursor )
{
VGA::SetCursor(column, line); VGA::SetCursor(column, line);
}
else else
{
VGA::SetCursor(width, height-1); VGA::SetCursor(width, height-1);
} }
}
// Clear the screen, put the cursor at the top left corner, set default // Clear the screen, put the cursor at the top left corner, set default
// text color, and reset ANSI escape sequence state. // text color, and reset ANSI escape sequence state.
@ -78,14 +73,14 @@ namespace Sortix
ansisavedposx = 0; ansisavedposx = 0;
ansisavedposy = 0; ansisavedposy = 0;
currentcolor = defaultcolor; currentcolor = DEFAULT_COLOR;
for ( nat y = 0; y < height; y++ ) for ( nat y = 0; y < height; y++ )
{ {
for ( nat x = 0; x < width; x++ ) for ( nat x = 0; x < width; x++ )
{ {
unsigned index = y * width + x; unsigned index = y * width + x;
vga[index] = ' ' | defaultcolor; vga[index] = ' ' | DEFAULT_COLOR;
vgaattr[index] = 0; vgaattr[index] = 0;
} }
} }
@ -146,14 +141,10 @@ namespace Sortix
{ {
vgaattr[line * width + column] |= VGAATTR_CHAR; vgaattr[line * width + column] |= VGAATTR_CHAR;
if ( line < height - 1 ) if ( line < height - 1 )
{ line++;
line++; column = 0;
}
else else
{ ScrollUp();
ScrollUp(); column = 0; column = 0;
}
UpdateCursor(); UpdateCursor();
} }
@ -164,19 +155,6 @@ namespace Sortix
// display the text. // display the text.
size_t Print(void* /*user*/, const char* string, size_t stringlen) size_t Print(void* /*user*/, const char* string, size_t stringlen)
{ {
// Check for the bug where string contains the address 0x80000000
// which is not legal to print. It looks like we are trying to
// print a string from the stack that wasn't NUL-terminated. I
// tracked down the string value comes from LogTerminal, but it
// doesn't seem to originate from a write(2) call. Weird stuff.
addr_t straddr = (addr_t) string;
if ( straddr <= 0x80000000UL && 0x80000000UL <= straddr + stringlen )
{
PanicF("Trying to print bad string 0x%zx + 0x%zx bytes: this "
"is a known bug, but with an unknown cause.", straddr,
stringlen);
}
// Iterate over each character. // Iterate over each character.
size_t left = stringlen; size_t left = stringlen;
while ( (left--) > 0 ) while ( (left--) > 0 )
@ -282,8 +260,11 @@ namespace Sortix
void AnsiSetFont() void AnsiSetFont()
{ {
// Convert from the ANSI color scheme to the VGA color scheme. // Convert from the ANSI color scheme to the VGA color scheme.
nat conversion[8] = { COLOR8_BLACK, COLOR8_RED, COLOR8_GREEN, COLOR8_BROWN, const unsigned conversion[8] =
COLOR8_BLUE, COLOR8_MAGENTA, COLOR8_CYAN, COLOR8_LIGHT_GREY }; {
COLOR8_BLACK, COLOR8_RED, COLOR8_GREEN, COLOR8_BROWN,
COLOR8_BLUE, COLOR8_MAGENTA, COLOR8_CYAN, COLOR8_LIGHT_GREY,
};
for ( size_t i = 0; i < ansiusedparams; i++ ) for ( size_t i = 0; i < ansiusedparams; i++ )
{ {
@ -291,7 +272,7 @@ namespace Sortix
// Turn all attributes off. // Turn all attributes off.
if ( cmd == 0 ) if ( cmd == 0 )
{ {
currentcolor = defaultcolor; currentcolor = DEFAULT_COLOR;
} }
// Set text color. // Set text color.
else if ( 30 <= cmd && cmd <= 37 ) else if ( 30 <= cmd && cmd <= 37 )
@ -561,5 +542,6 @@ namespace Sortix
} }
} }
} }
}
} } // namespace VGATerminal
} // namespace Sortix

View File

@ -1,6 +1,6 @@
/****************************************************************************** /*******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
This file is part of Sortix. This file is part of Sortix.
@ -14,26 +14,26 @@
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. details.
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along with
with Sortix. If not, see <http://www.gnu.org/licenses/>. Sortix. If not, see <http://www.gnu.org/licenses/>.
vgaterminal.h vgaterminal.cpp
A terminal based on the VGA text mode buffer. A terminal based on a text mode buffer.
******************************************************************************/ *******************************************************************************/
#ifndef SORTIX_VGATERMINAL_H #ifndef SORTIX_VGATERMINAL_H
#define SORTIX_VGATERMINAL_H #define SORTIX_VGATERMINAL_H
namespace Sortix namespace Sortix {
{ namespace VGATerminal {
namespace VGATerminal
{
void Init(); void Init();
void Reset(); void Reset();
size_t Print(void* user, const char* string, size_t stringlen); size_t Print(void* user, const char* string, size_t stringlen);
}
} } // namespace VGATerminal
} // namespace Sortix
#endif #endif