Updated vgaterminal.cpp to newer coding conventions.
This commit is contained in:
parent
d75a7145ef
commit
3907e14cb8
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -14,13 +14,13 @@
|
|||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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/log.h>
|
||||
|
@ -31,46 +31,41 @@
|
|||
|
||||
using namespace Maxsi;
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace VGATerminal
|
||||
{
|
||||
const nat width = 80;
|
||||
const nat height = 25;
|
||||
const uint16_t defaultcolor = (COLOR8_LIGHT_GREY << 8) | (COLOR8_BLACK << 12);
|
||||
uint16_t* const vga = (uint16_t* const) 0xB8000;
|
||||
uint16_t vgaattr[width * height];
|
||||
const uint16_t VGAATTR_CHAR = (1U<<0U);
|
||||
nat line;
|
||||
nat column;
|
||||
uint16_t currentcolor;
|
||||
nat ansisavedposx;
|
||||
nat ansisavedposy;
|
||||
bool showcursor;
|
||||
namespace Sortix {
|
||||
namespace VGATerminal {
|
||||
|
||||
enum
|
||||
{
|
||||
const unsigned width = 80;
|
||||
const unsigned height = 25;
|
||||
const uint16_t DEFAULT_COLOR = (COLOR8_LIGHT_GREY << 8) | (COLOR8_BLACK << 12);
|
||||
uint16_t* const vga = (uint16_t* const) 0xB8000;
|
||||
uint16_t vgaattr[width * height];
|
||||
const uint16_t VGAATTR_CHAR = (1U<<0U);
|
||||
unsigned line;
|
||||
unsigned column;
|
||||
uint16_t currentcolor;
|
||||
unsigned ansisavedposx;
|
||||
unsigned ansisavedposy;
|
||||
bool showcursor;
|
||||
|
||||
enum
|
||||
{
|
||||
NONE,
|
||||
CSI,
|
||||
COMMAND,
|
||||
} ansimode;
|
||||
} ansimode;
|
||||
|
||||
void UpdateCursor()
|
||||
{
|
||||
void UpdateCursor()
|
||||
{
|
||||
if ( showcursor )
|
||||
{
|
||||
VGA::SetCursor(column, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
VGA::SetCursor(width, height-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear the screen, put the cursor at the top left corner, set default
|
||||
// text color, and reset ANSI escape sequence state.
|
||||
void Reset()
|
||||
{
|
||||
// Clear the screen, put the cursor at the top left corner, set default
|
||||
// text color, and reset ANSI escape sequence state.
|
||||
void Reset()
|
||||
{
|
||||
ansimode = NONE;
|
||||
|
||||
line = 0;
|
||||
|
@ -78,14 +73,14 @@ namespace Sortix
|
|||
ansisavedposx = 0;
|
||||
ansisavedposy = 0;
|
||||
|
||||
currentcolor = defaultcolor;
|
||||
currentcolor = DEFAULT_COLOR;
|
||||
|
||||
for ( nat y = 0; y < height; y++ )
|
||||
{
|
||||
for ( nat x = 0; x < width; x++ )
|
||||
{
|
||||
unsigned index = y * width + x;
|
||||
vga[index] = ' ' | defaultcolor;
|
||||
vga[index] = ' ' | DEFAULT_COLOR;
|
||||
vgaattr[index] = 0;
|
||||
}
|
||||
}
|
||||
|
@ -93,17 +88,17 @@ namespace Sortix
|
|||
// Reset the VGA cursor.
|
||||
showcursor = true;
|
||||
UpdateCursor();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the terminal driver.
|
||||
void Init()
|
||||
{
|
||||
// Initialize the terminal driver.
|
||||
void Init()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
// Move every line one row up and leaves an empty line at the bottom.
|
||||
void ScrollUp()
|
||||
{
|
||||
// Move every line one row up and leaves an empty line at the bottom.
|
||||
void ScrollUp()
|
||||
{
|
||||
for ( nat y = 1; y < height; y++ )
|
||||
{
|
||||
size_t linesize = width * sizeof(uint16_t);
|
||||
|
@ -119,11 +114,11 @@ namespace Sortix
|
|||
vga[index] = ' ' | currentcolor;
|
||||
vgaattr[index] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move every line one row down and leaves an empty line at the top.
|
||||
void ScrollDown()
|
||||
{
|
||||
// Move every line one row down and leaves an empty line at the top.
|
||||
void ScrollDown()
|
||||
{
|
||||
for ( nat y = 1; y < height; y++ )
|
||||
{
|
||||
size_t linesize = width * sizeof(uint16_t);
|
||||
|
@ -139,44 +134,27 @@ namespace Sortix
|
|||
vga[index] = ' ' | currentcolor;
|
||||
vgaattr[index] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move to the next line. If at bottom, scroll one line up.
|
||||
void Newline()
|
||||
{
|
||||
// Move to the next line. If at bottom, scroll one line up.
|
||||
void Newline()
|
||||
{
|
||||
vgaattr[line * width + column] |= VGAATTR_CHAR;
|
||||
if ( line < height - 1 )
|
||||
{
|
||||
line++; column = 0;
|
||||
}
|
||||
line++;
|
||||
else
|
||||
{
|
||||
ScrollUp(); column = 0;
|
||||
}
|
||||
|
||||
ScrollUp();
|
||||
column = 0;
|
||||
UpdateCursor();
|
||||
}
|
||||
}
|
||||
|
||||
void ANSIReset();
|
||||
void ParseANSIEscape(char c);
|
||||
|
||||
// Print text to the vga framebuffer, simulating how a terminal would
|
||||
// display the text.
|
||||
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);
|
||||
}
|
||||
void ANSIReset();
|
||||
void ParseANSIEscape(char c);
|
||||
|
||||
// Print text to the vga framebuffer, simulating how a terminal would
|
||||
// display the text.
|
||||
size_t Print(void* /*user*/, const char* string, size_t stringlen)
|
||||
{
|
||||
// Iterate over each character.
|
||||
size_t left = stringlen;
|
||||
while ( (left--) > 0 )
|
||||
|
@ -253,20 +231,20 @@ namespace Sortix
|
|||
UpdateCursor();
|
||||
|
||||
return stringlen;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t ANSI_NUM_PARAMS = 16;
|
||||
nat ansiusedparams;
|
||||
nat ansiparams[ANSI_NUM_PARAMS];
|
||||
nat currentparamindex;
|
||||
bool paramundefined;
|
||||
bool ignoresequence;
|
||||
const size_t ANSI_NUM_PARAMS = 16;
|
||||
nat ansiusedparams;
|
||||
nat ansiparams[ANSI_NUM_PARAMS];
|
||||
nat currentparamindex;
|
||||
bool paramundefined;
|
||||
bool ignoresequence;
|
||||
|
||||
// TODO: The ANSI escape code is only partially implemented!
|
||||
// TODO: The ANSI escape code is only partially implemented!
|
||||
|
||||
// Begin an ANSI esacpe sequence.
|
||||
void ANSIReset()
|
||||
{
|
||||
// Begin an ANSI esacpe sequence.
|
||||
void ANSIReset()
|
||||
{
|
||||
if ( ansimode == NONE )
|
||||
{
|
||||
ansiusedparams = 0;
|
||||
|
@ -276,14 +254,17 @@ namespace Sortix
|
|||
ignoresequence = false;
|
||||
ansimode = CSI;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reads parameters and changes font properties accordingly.
|
||||
void AnsiSetFont()
|
||||
{
|
||||
// Reads parameters and changes font properties accordingly.
|
||||
void AnsiSetFont()
|
||||
{
|
||||
// Convert from the ANSI color scheme to the VGA color scheme.
|
||||
nat conversion[8] = { COLOR8_BLACK, COLOR8_RED, COLOR8_GREEN, COLOR8_BROWN,
|
||||
COLOR8_BLUE, COLOR8_MAGENTA, COLOR8_CYAN, COLOR8_LIGHT_GREY };
|
||||
const unsigned conversion[8] =
|
||||
{
|
||||
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++ )
|
||||
{
|
||||
|
@ -291,7 +272,7 @@ namespace Sortix
|
|||
// Turn all attributes off.
|
||||
if ( cmd == 0 )
|
||||
{
|
||||
currentcolor = defaultcolor;
|
||||
currentcolor = DEFAULT_COLOR;
|
||||
}
|
||||
// Set text color.
|
||||
else if ( 30 <= cmd && cmd <= 37 )
|
||||
|
@ -309,11 +290,11 @@ namespace Sortix
|
|||
}
|
||||
// TODO: There are many other things we don't support.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Executes an ASNI escape command based on given parameters.
|
||||
void RunANSICommand(char c)
|
||||
{
|
||||
// Executes an ASNI escape command based on given parameters.
|
||||
void RunANSICommand(char c)
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
// Cursor up
|
||||
|
@ -502,11 +483,11 @@ namespace Sortix
|
|||
}
|
||||
|
||||
ansimode = NONE;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse another char of an ASNI escape code.
|
||||
void ParseANSIEscape(char c)
|
||||
{
|
||||
// Parse another char of an ASNI escape code.
|
||||
void ParseANSIEscape(char c)
|
||||
{
|
||||
// Check the proper prefixes are used.
|
||||
if ( ansimode == CSI )
|
||||
{
|
||||
|
@ -560,6 +541,7 @@ namespace Sortix
|
|||
ansimode = NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace VGATerminal
|
||||
} // namespace Sortix
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/******************************************************************************
|
||||
/*******************************************************************************
|
||||
|
||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -14,26 +14,26 @@
|
|||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
vgaterminal.h
|
||||
A terminal based on the VGA text mode buffer.
|
||||
vgaterminal.cpp
|
||||
A terminal based on a text mode buffer.
|
||||
|
||||
******************************************************************************/
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_VGATERMINAL_H
|
||||
#define SORTIX_VGATERMINAL_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace VGATerminal
|
||||
{
|
||||
void Init();
|
||||
void Reset();
|
||||
size_t Print(void* user, const char* string, size_t stringlen);
|
||||
}
|
||||
}
|
||||
namespace Sortix {
|
||||
namespace VGATerminal {
|
||||
|
||||
void Init();
|
||||
void Reset();
|
||||
size_t Print(void* user, const char* string, size_t stringlen);
|
||||
|
||||
} // namespace VGATerminal
|
||||
} // namespace Sortix
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue