Import backup from 2005-05-12
This commit is contained in:
1 parent
14792ef954
commit
b0132c866e
35 files changed
+1637
-872
No files matched your search
@@ -0,0 +1,46 @@
|
||||
// misc_char.cpp
|
||||
// Miscellaneous character devices
|
||||
// Author: Josh Holtrop
|
||||
// Date: 05/11/05
|
||||
// Modified: 05/11/05
|
||||
|
||||
#define _HOS_CPP_ _HOS_CPP_
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "devices.h"
|
||||
#include "misc_char.h"
|
||||
#include "sys/io.h"
|
||||
|
||||
int MiscChar::char_read(minor_t minor)
|
||||
{
|
||||
switch (minor)
|
||||
{
|
||||
case MISC_CHAR_NULL:
|
||||
return DEV_EOF;
|
||||
case MISC_CHAR_ZERO:
|
||||
return 0;
|
||||
case MISC_CHAR_LP0:
|
||||
return DEV_INVALID_ACCESS;
|
||||
default:
|
||||
return DEV_INVALID_ACCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int MiscChar::char_write(minor_t minor, int c)
|
||||
{
|
||||
switch (minor)
|
||||
{
|
||||
case MISC_CHAR_NULL:
|
||||
return 0;
|
||||
case MISC_CHAR_ZERO:
|
||||
return 0;
|
||||
case MISC_CHAR_LP0:
|
||||
outportb(0x37a, 0xc);
|
||||
outportb(0x378, c);
|
||||
outportb(0x37a, 0x1);
|
||||
return 0;
|
||||
default:
|
||||
return DEV_INVALID_ACCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// misc_char.h
|
||||
// Miscellaneous character devices
|
||||
// Author: Josh Holtrop
|
||||
// Date: 05/11/05
|
||||
// Modified: 05/11/05
|
||||
|
||||
#ifndef __HOS_MISC_CHAR__
|
||||
#define __HOS_MISC_CHAR__ __HOS_MISC_CHAR__
|
||||
|
||||
#define MISC_CHAR_NULL 3
|
||||
#define MISC_CHAR_ZERO 5
|
||||
#define MISC_CHAR_LP0 10
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "devices.h"
|
||||
#include "misc_char.h"
|
||||
|
||||
#ifdef _HOS_CPP_
|
||||
|
||||
class MiscChar : public DeviceDriver
|
||||
{
|
||||
public:
|
||||
int char_read(minor_t minor);
|
||||
int char_write(minor_t minor, int c);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
// parallel.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 08/16/04
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "functions.h"
|
||||
#include "char/parallel.h"
|
||||
#include "fs/devices.h"
|
||||
#include "mm/vmm.h"
|
||||
|
||||
// initialization routine for vconsoles module
|
||||
int parallel_init(major_t major)
|
||||
{
|
||||
dev_driver_t *parallel_driver;
|
||||
if (( parallel_driver = New(dev_driver_t) ))
|
||||
{
|
||||
parallel_driver->char_write = parallel_char_write;
|
||||
devices_register_major('c', major, parallel_driver);
|
||||
// register parallel devices as /dev/lp0, etc...
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parallel_char_write(minor_t minor, int c)
|
||||
{
|
||||
if (minor == 0)
|
||||
{
|
||||
outportb(0x37a, 0xc);
|
||||
outportb(0x378, c);
|
||||
outportb(0x37a, 0x1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// parallel.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
|
||||
#ifndef __HOS_PARALLEL__
|
||||
#define __HOS_PARALLEL__ __HOS_PARALLEL__
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
int parallel_init(major_t major);
|
||||
int parallel_char_write(minor_t minor, int c);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,302 +0,0 @@
|
||||
// vconsole.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 08/16/04
|
||||
|
||||
#include "char/vconsole.h"
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "lang/lang.h"
|
||||
#include "display/display.h"
|
||||
#include "functions.h"
|
||||
|
||||
vconsole_t *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
|
||||
extern int display_activeConsole; // display subsystem active virtual console number
|
||||
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
|
||||
|
||||
void vconsole_put_char(minor_t id, int c);
|
||||
void vconsole_update_cursor(minor_t id, u16_t position);
|
||||
void vconsole_update_attribute(minor_t id);
|
||||
void vconsole_refresh(minor_t id);
|
||||
|
||||
// initialization routine for vconsoles module
|
||||
int vconsole_init(major_t major)
|
||||
{
|
||||
dev_driver_t *vconsole_driver;
|
||||
if (( vconsole_driver = New(dev_driver_t) ))
|
||||
{
|
||||
vconsole_driver->char_write = vconsole_char_write;
|
||||
devices_register_major('c', major, vconsole_driver);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// routine to create a new virtual console object
|
||||
minor_t vconsole_new(int width, int height)
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < VCONSOLE_MAX; i++)
|
||||
{
|
||||
if ( (!vconsoles[i]) && ( vconsoles[i] = New(vconsole_t) ) )
|
||||
{
|
||||
if (( vconsoles[i]->buffer = kmalloc(width * height * 2) ))
|
||||
{
|
||||
vconsoles[i]->width = width;
|
||||
vconsoles[i]->height = height;
|
||||
vconsoles[i]->attribute = vconsoles[i]->foreground = 0x07;
|
||||
memsetw(vconsoles[i]->buffer, 0x0720, width * height);
|
||||
// TODO: register the device as /dev/console%d
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
kfree(vconsoles[i]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// called by display subsystem to draw a virtual console to the screen
|
||||
int vconsole_draw(minor_t id)
|
||||
{
|
||||
if (vconsoles[id])
|
||||
return display_console_draw(id, vconsoles[id]->cursorPosition,
|
||||
vconsoles[id]->buffer, vconsoles[id]->width * vconsoles[id]->height);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// called by character device interface when a character is written to device w/ minor #id
|
||||
int vconsole_char_write(minor_t id, int c)
|
||||
{
|
||||
if (!vconsoles[id])
|
||||
return -1;
|
||||
int cursorY = vconsoles[id]->cursorPosition / vconsoles[id]->width;
|
||||
int cursorX = vconsoles[id]->cursorPosition % vconsoles[id]->width;
|
||||
int evalEscapePosition = 0;
|
||||
switch (vconsoles[id]->escapeLevel)
|
||||
{
|
||||
case 2:
|
||||
if (c >= '0' && c <= '9') // c is part of an escape value
|
||||
{
|
||||
vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] *= 10;
|
||||
vconsoles[id]->escapeValue[vconsoles[id]->escapePosition] += c - '0';
|
||||
return 0;
|
||||
}
|
||||
else if (c == ';')
|
||||
{
|
||||
if (vconsoles[id]->escapePosition < 7)
|
||||
vconsoles[id]->escapePosition++;
|
||||
return 0;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case 'A': // move cursor up n rows
|
||||
cursorY -= vconsoles[id]->escapeValue[0];
|
||||
if (cursorY < 0)
|
||||
cursorY = 0;
|
||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
||||
break;
|
||||
case 'B': // move cursor down n rows
|
||||
cursorY += vconsoles[id]->escapeValue[0];
|
||||
if (cursorY >= vconsoles[id]->height)
|
||||
cursorY = vconsoles[id]->height - 1;
|
||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
||||
break;
|
||||
case 'C': // move cursor left n columns
|
||||
cursorX -= vconsoles[id]->escapeValue[0];
|
||||
if (cursorX < 0)
|
||||
cursorX = 0;
|
||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
||||
break;
|
||||
case 'D': // move cursor right n columns
|
||||
cursorX += vconsoles[id]->escapeValue[0];
|
||||
if (cursorX >= vconsoles[id]->width)
|
||||
cursorX = vconsoles[id]->width - 1;
|
||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
||||
break;
|
||||
case 'H':
|
||||
case 'f': // move cursor to position (x,y) upper left is (1,1)
|
||||
cursorX = vconsoles[id]->escapeValue[0] - 1;
|
||||
cursorY = vconsoles[id]->escapeValue[1] - 1;
|
||||
if (cursorY < 0)
|
||||
cursorY = 0;
|
||||
if (cursorY >= vconsoles[id]->height)
|
||||
cursorY = vconsoles[id]->height - 1;
|
||||
if (cursorX < 0)
|
||||
cursorX = 0;
|
||||
if (cursorX >= vconsoles[id]->width)
|
||||
cursorX = vconsoles[id]->width - 1;
|
||||
vconsole_update_cursor(id, cursorY * vconsoles[id]->width + cursorX);
|
||||
break;
|
||||
case 'J': // clear screen, home cursor
|
||||
memsetw(vconsoles[id]->buffer, 0x0720, vconsoles[id]->width * vconsoles[id]->height);
|
||||
vconsole_draw(id);
|
||||
vconsole_update_cursor(id, 0);
|
||||
break;
|
||||
case 'K': // erase line from cursor position (including char. under cursor) to end of line
|
||||
memsetw(vconsoles[id]->buffer + vconsoles[id]->cursorPosition, 0x0720, vconsoles[id]->width - cursorX);
|
||||
vconsole_draw(id);
|
||||
break;
|
||||
case 's': // push cursor position on an internal stack
|
||||
if (vconsoles[id]->cursorStackPosition < 16)
|
||||
vconsoles[id]->cursorStack[vconsoles[id]->cursorStackPosition++] = vconsoles[id]->cursorPosition;
|
||||
break;
|
||||
case 'u': // pop cursor position from stack
|
||||
if (vconsoles[id]->cursorStackPosition > 0)
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorStack[--vconsoles[id]->cursorStackPosition]);
|
||||
break;
|
||||
case 'm': // set text attributes
|
||||
for (evalEscapePosition = 0; evalEscapePosition <= vconsoles[id]->escapePosition; evalEscapePosition++)
|
||||
{
|
||||
switch (vconsoles[id]->escapeValue[evalEscapePosition])
|
||||
{
|
||||
case 0:
|
||||
vconsoles[id]->foreground = 0x07;
|
||||
vconsoles[id]->background = 0x00;
|
||||
vconsoles[id]->concealed = 0;
|
||||
vconsoles[id]->reverse = 0;
|
||||
vconsoles[id]->blink = 0;
|
||||
vconsoles[id]->bold = 0;
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
case 1:
|
||||
vconsoles[id]->bold = 1;
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
case 5:
|
||||
vconsoles[id]->blink = 1;
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
case 7:
|
||||
vconsoles[id]->reverse = 1;
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
vconsoles[id]->foreground = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 30];
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
vconsoles[id]->background = ansi2vgaAttr[vconsoles[id]->escapeValue[evalEscapePosition] - 40];
|
||||
vconsole_update_attribute(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
vconsoles[id]->escapePosition = 0;
|
||||
break;
|
||||
}
|
||||
memsetd(vconsoles[id]->escapeValue, 0, 8);
|
||||
vconsoles[id]->escapePosition = 0;
|
||||
vconsoles[id]->escapeLevel = 0;
|
||||
return 0;
|
||||
case 1:
|
||||
if (c == '[')
|
||||
vconsoles[id]->escapeLevel = 2;
|
||||
break;
|
||||
vconsoles[id]->escapeLevel = 0;
|
||||
return 0; // invalid escape sequence
|
||||
default:
|
||||
if (c == '\e')
|
||||
{
|
||||
vconsoles[id]->escapeLevel = 1;
|
||||
return 0;
|
||||
}
|
||||
vconsole_put_char(id, c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// write the character to the virtual console
|
||||
void vconsole_put_char(minor_t id, int c)
|
||||
{
|
||||
if (!vconsoles[id]->concealed)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\t':
|
||||
if (vconsoles[id]->cursorPosition % 8)
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (8 - (vconsoles[id]->cursorPosition % 8)));
|
||||
else
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 8);
|
||||
break;
|
||||
case '\n':
|
||||
if (vconsoles[id]->cursorPosition % (vconsoles[id]->width))
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + (vconsoles[id]->width - (vconsoles[id]->cursorPosition % vconsoles[id]->width)));
|
||||
else
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + vconsoles[id]->width);
|
||||
break;
|
||||
default:
|
||||
vconsoles[id]->buffer[vconsoles[id]->cursorPosition] = c | (vconsoles[id]->attribute << 8);
|
||||
if (id == display_activeConsole)
|
||||
display_console_put_char(id, c | (vconsoles[id]->attribute << 8), vconsoles[id]->cursorPosition);
|
||||
vconsole_update_cursor(id, vconsoles[id]->cursorPosition + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vconsole_update_cursor(minor_t id, u16_t position)
|
||||
{
|
||||
vconsoles[id]->cursorPosition = position;
|
||||
if (position >= (vconsoles[id]->width * vconsoles[id]->height)) // time to scroll console
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < vconsoles[id]->cursorStackPosition; i++)
|
||||
{
|
||||
vconsoles[id]->cursorStack[i] -= vconsoles[id]->width;
|
||||
if (vconsoles[id]->cursorStack[i] < 0)
|
||||
vconsoles[id]->cursorStack[i] = 0;
|
||||
}
|
||||
vconsoles[id]->cursorPosition -= vconsoles[id]->width;
|
||||
memcpyw(vconsoles[id]->buffer, vconsoles[id]->buffer + vconsoles[id]->width, vconsoles[id]->width * (vconsoles[id]->height - 1));
|
||||
memsetw(vconsoles[id]->buffer + (vconsoles[id]->width * (vconsoles[id]->height - 1)), 0x0720, vconsoles[id]->width);
|
||||
if (display_activeConsole == id)
|
||||
{
|
||||
vconsole_draw(id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (display_activeConsole == id)
|
||||
display_console_update_cursor(id, position);
|
||||
}
|
||||
|
||||
void vconsole_update_attribute(minor_t id)
|
||||
{
|
||||
if (vconsoles[id]->reverse)
|
||||
{
|
||||
vconsoles[id]->attribute =
|
||||
vconsoles[id]->blink << 7 |
|
||||
vconsoles[id]->foreground << 4 |
|
||||
vconsoles[id]->bold << 3 |
|
||||
vconsoles[id]->background;
|
||||
}
|
||||
else
|
||||
{
|
||||
vconsoles[id]->attribute =
|
||||
vconsoles[id]->blink << 7 |
|
||||
vconsoles[id]->background << 4 |
|
||||
vconsoles[id]->bold << 3 |
|
||||
vconsoles[id]->foreground;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,258 @@
|
||||
// vconsole.cpp
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 05/11/05
|
||||
|
||||
#define _HOS_CPP_ _HOS_CPP_
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "hos_defines.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "lang/lang.h"
|
||||
#include "display/display.h"
|
||||
#include "functions.h"
|
||||
}
|
||||
|
||||
#include "devices.h"
|
||||
#include "char/vconsole.h"
|
||||
|
||||
VConsole *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
|
||||
extern int display_activeConsole; // display subsystem active virtual console number
|
||||
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
|
||||
|
||||
void vconsole_setup(int width, int height)
|
||||
{
|
||||
for (int i = 0; i < VCONSOLE_MAX; i++)
|
||||
vconsoles[i] = new VConsole(width, height);
|
||||
}
|
||||
|
||||
VConsoleDriver::~VConsoleDriver()
|
||||
{
|
||||
for (int i = 0; i < VCONSOLE_MAX; i++)
|
||||
if (vconsoles[i])
|
||||
delete vconsoles[i];
|
||||
}
|
||||
|
||||
int VConsoleDriver::char_write(minor_t minor, int c)
|
||||
{
|
||||
if (minor < 0 || minor >= VCONSOLE_MAX)
|
||||
return -1;
|
||||
if (!vconsoles[minor])
|
||||
return -2;
|
||||
return vconsoles[minor]->char_write(c);
|
||||
}
|
||||
|
||||
VConsole::VConsole(int width, int height)
|
||||
{
|
||||
myBuffer = new u16_t[width * height];
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
myAttribute = myForeground = 0x07;
|
||||
memsetw(myBuffer, 0x0720, width * height);
|
||||
myCursorPosition = 0;
|
||||
myCursorStackPosition = myEscapeLevel = myEscapePosition = myBackground =
|
||||
myBold = myReverse = myBlink = myConcealed = myActive = 0;
|
||||
|
||||
}
|
||||
|
||||
VConsole::~VConsole()
|
||||
{
|
||||
delete[] myBuffer;
|
||||
}
|
||||
|
||||
void VConsole::activate()
|
||||
{
|
||||
myActive = 1;
|
||||
}
|
||||
|
||||
void VConsole::deactivate()
|
||||
{
|
||||
myActive = 0;
|
||||
}
|
||||
|
||||
int VConsole::char_write(int c)
|
||||
{
|
||||
int cursorY = myCursorPosition / myWidth;
|
||||
int cursorX = myCursorPosition % myWidth;
|
||||
switch (myEscapeLevel)
|
||||
{
|
||||
case 2:
|
||||
if (c >= '0' && c <= '9') // c is part of an escape value
|
||||
{
|
||||
myEscapeValue[myEscapePosition] *= 10;
|
||||
myEscapeValue[myEscapePosition] += c - '0';
|
||||
return 0;
|
||||
}
|
||||
else if (c == ';')
|
||||
{
|
||||
if (myEscapePosition < 7)
|
||||
myEscapePosition++;
|
||||
return 0;
|
||||
}
|
||||
switch (c)
|
||||
{
|
||||
case 'A': // move cursor up n rows
|
||||
update_cursor_coord(cursorY - myEscapeValue[0], cursorX);
|
||||
break;
|
||||
case 'B': // move cursor down n rows
|
||||
update_cursor_coord(cursorY + myEscapeValue[0], cursorX);
|
||||
break;
|
||||
case 'C': // move cursor left n columns
|
||||
update_cursor_coord(cursorY, cursorX - myEscapeValue[0]);
|
||||
break;
|
||||
case 'D': // move cursor right n columns
|
||||
update_cursor_coord(cursorY, cursorX + myEscapeValue[0]);
|
||||
break;
|
||||
case 'H':
|
||||
case 'f': // move cursor to position (x,y) upper left is (1,1)
|
||||
update_cursor_coord(myEscapeValue[1] - 1, myEscapeValue[0] - 1);
|
||||
break;
|
||||
case 'J': // clear screen, home cursor
|
||||
memsetw(myBuffer, 0x0720, myWidth * myHeight);
|
||||
// vconsole_draw(id);
|
||||
update_cursor_coord(0, 0);
|
||||
break;
|
||||
case 'K': // erase line from cursor position (including char. under cursor) to end of line
|
||||
memsetw(myBuffer + myCursorPosition, 0x0720, myWidth - cursorX);
|
||||
// vconsole_draw(id);
|
||||
break;
|
||||
case 's': // push cursor position on an internal stack
|
||||
if (myCursorStackPosition < 16)
|
||||
myCursorStack[myCursorStackPosition++] = myCursorPosition;
|
||||
break;
|
||||
case 'u': // pop cursor position from stack
|
||||
if (myCursorStackPosition > 0)
|
||||
update_cursor(myCursorStack[--myCursorStackPosition]);
|
||||
break;
|
||||
case 'm': // set text attributes
|
||||
for (int evalEscapePosition = 0; evalEscapePosition <= myEscapePosition; evalEscapePosition++)
|
||||
{
|
||||
switch (myEscapeValue[evalEscapePosition])
|
||||
{
|
||||
case 0:
|
||||
myForeground = 0x07;
|
||||
myBackground = myConcealed = myReverse = myBlink = myBold = 0;
|
||||
update_attribute();
|
||||
break;
|
||||
case 1:
|
||||
myBold = 1;
|
||||
update_attribute();
|
||||
break;
|
||||
case 5:
|
||||
myBlink = 1;
|
||||
update_attribute();
|
||||
break;
|
||||
case 7:
|
||||
myReverse = 1;
|
||||
update_attribute();
|
||||
break;
|
||||
case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37:
|
||||
myForeground = ansi2vgaAttr[myEscapeValue[evalEscapePosition] - 30];
|
||||
update_attribute();
|
||||
break;
|
||||
case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47:
|
||||
myBackground = ansi2vgaAttr[myEscapeValue[evalEscapePosition] - 40];
|
||||
update_attribute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
myEscapePosition = 0;
|
||||
break;
|
||||
}
|
||||
memsetd(myEscapeValue, 0, 8);
|
||||
myEscapePosition = 0;
|
||||
myEscapeLevel = 0;
|
||||
return 0;
|
||||
case 1:
|
||||
if (c == '[')
|
||||
myEscapeLevel = 2;
|
||||
break;
|
||||
myEscapeLevel = 0;
|
||||
return 0; // invalid escape sequence
|
||||
default:
|
||||
if (c == '\e')
|
||||
{
|
||||
myEscapeLevel = 1;
|
||||
return 0;
|
||||
}
|
||||
put_char(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void VConsole::put_char(int c)
|
||||
{
|
||||
if (!myConcealed)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\t':
|
||||
if (myCursorPosition % 8)
|
||||
update_cursor(myCursorPosition + (8 - (myCursorPosition % 8)));
|
||||
else
|
||||
update_cursor(myCursorPosition + 8);
|
||||
break;
|
||||
case '\n':
|
||||
if (myCursorPosition % myWidth)
|
||||
update_cursor(myCursorPosition + (myWidth - (myCursorPosition % myWidth)));
|
||||
else
|
||||
update_cursor(myCursorPosition + myWidth);
|
||||
break;
|
||||
default:
|
||||
myBuffer[myCursorPosition] = c | (myAttribute << 8);
|
||||
// if (myActive)
|
||||
// display_console_put_char(c | (myAttribute << 8), myCursorPosition);
|
||||
update_cursor(myCursorPosition + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VConsole::update_cursor_coord(int y, int x)
|
||||
{
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
else if (y >= myHeight)
|
||||
y = myHeight - 1;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
else if (x >= myWidth)
|
||||
x = myWidth - 1;
|
||||
update_cursor(myWidth * y + x);
|
||||
}
|
||||
|
||||
void VConsole::update_cursor(u16_t position)
|
||||
{
|
||||
myCursorPosition = position;
|
||||
if (position >= (myWidth * myHeight)) // time to scroll console
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < myCursorStackPosition; i++)
|
||||
{
|
||||
myCursorStack[i] -= myWidth;
|
||||
if (myCursorStack[i] < 0)
|
||||
myCursorStack[i] = 0;
|
||||
}
|
||||
myCursorPosition -= myWidth;
|
||||
memcpyw(myBuffer, myBuffer + myWidth, myWidth * (myHeight - 1));
|
||||
memsetw(myBuffer + (myWidth * (myHeight - 1)), 0x0720, myWidth);
|
||||
// if (myActive)
|
||||
// {
|
||||
// vconsole_draw(id);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
// if (myActive)
|
||||
// display_console_update_cursor(id, position);
|
||||
}
|
||||
|
||||
void VConsole::update_attribute()
|
||||
{
|
||||
if (myReverse)
|
||||
myAttribute = myBlink << 7 | myForeground << 4 | myBold << 3 | myBackground;
|
||||
else
|
||||
myAttribute = myBlink << 7 | myBackground << 4 | myBold << 3 | myForeground;
|
||||
}
|
||||
|
||||
|
||||
+55
-25
@@ -1,42 +1,72 @@
|
||||
// vconsole.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 08/02/04
|
||||
// Modified: 08/07/04
|
||||
// Modified: 05/11/05
|
||||
|
||||
#ifndef __HOS_VCONSOLE__
|
||||
#define __HOS_VCONSOLE__ __HOS_VCONSOLE__
|
||||
|
||||
#define VCONSOLE_MAX 7
|
||||
|
||||
#ifdef _HOS_CPP_
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "fs/devices.h"
|
||||
|
||||
#define VCONSOLE_MAX 16
|
||||
void vconsole_setup(int width, int height);
|
||||
|
||||
typedef struct
|
||||
#ifdef _HOS_CPP_
|
||||
}
|
||||
|
||||
#include "devices.h"
|
||||
|
||||
class VConsoleDriver : public DeviceDriver
|
||||
{
|
||||
u16_t *buffer;
|
||||
u32_t escapeValue[8];
|
||||
u16_t cursorPosition;
|
||||
u16_t width;
|
||||
u16_t height;
|
||||
short cursorStack[16];
|
||||
public:
|
||||
~VConsoleDriver();
|
||||
int char_write(minor_t minor, int c);
|
||||
};
|
||||
|
||||
u8_t attribute;
|
||||
u8_t foreground;
|
||||
u8_t background;
|
||||
u8_t bold;
|
||||
u8_t reverse;
|
||||
u8_t blink;
|
||||
u8_t concealed;
|
||||
class VConsole
|
||||
{
|
||||
protected:
|
||||
u16_t *myBuffer;
|
||||
u16_t myWidth;
|
||||
u16_t myHeight;
|
||||
u16_t myCursorPosition;
|
||||
|
||||
u8_t cursorStackPosition;
|
||||
u8_t escapeLevel;
|
||||
u8_t escapePosition;
|
||||
} vconsole_t;
|
||||
short myCursorStack[16];
|
||||
u8_t myCursorStackPosition;
|
||||
|
||||
int vconsole_init(major_t major);
|
||||
minor_t vconsole_new(int width, int height);
|
||||
int vconsole_draw(minor_t id);
|
||||
int vconsole_char_write(minor_t id, int c);
|
||||
u32_t myEscapeValue[8];
|
||||
u8_t myEscapeLevel;
|
||||
u8_t myEscapePosition;
|
||||
|
||||
u8_t myAttribute;
|
||||
u8_t myForeground;
|
||||
u8_t myBackground;
|
||||
u8_t myBold;
|
||||
u8_t myReverse;
|
||||
u8_t myBlink;
|
||||
u8_t myConcealed;
|
||||
|
||||
u8_t myActive;
|
||||
|
||||
public:
|
||||
VConsole(int width, int height);
|
||||
~VConsole();
|
||||
int char_read();
|
||||
int char_write(int c);
|
||||
void put_char(int c);
|
||||
void update_cursor(u16_t position);
|
||||
void update_cursor_coord(int y, int x);
|
||||
void update_attribute();
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user