From 1eb942c8a34166e43f43c843f09bb48ba40b65b2 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 20 Sep 2009 14:23:45 +0200 Subject: We now have scrollable virtual terminals ! --- Source/Kernel/VTManager/ScrollableVT.class.cpp | 94 ++++++++++ Source/Kernel/VTManager/ScrollableVT.class.h | 24 +++ Source/Kernel/VTManager/SimpleVT.class.cpp | 135 ++++++++++++++ Source/Kernel/VTManager/SimpleVT.class.h | 42 +++++ Source/Kernel/VTManager/VT.ns.cpp | 6 +- Source/Kernel/VTManager/VT.ns.h | 6 +- .../Kernel/VTManager/VirtualTerminal-kbd.class.cpp | 73 -------- .../Kernel/VTManager/VirtualTerminal-kbd.proto.cpp | 73 ++++++++ Source/Kernel/VTManager/VirtualTerminal.class.cpp | 196 --------------------- Source/Kernel/VTManager/VirtualTerminal.class.h | 67 ------- Source/Kernel/VTManager/VirtualTerminal.proto.cpp | 74 ++++++++ Source/Kernel/VTManager/VirtualTerminal.proto.h | 51 ++++++ 12 files changed, 499 insertions(+), 342 deletions(-) create mode 100644 Source/Kernel/VTManager/ScrollableVT.class.cpp create mode 100644 Source/Kernel/VTManager/ScrollableVT.class.h create mode 100644 Source/Kernel/VTManager/SimpleVT.class.cpp create mode 100644 Source/Kernel/VTManager/SimpleVT.class.h delete mode 100644 Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp create mode 100644 Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp delete mode 100644 Source/Kernel/VTManager/VirtualTerminal.class.cpp delete mode 100644 Source/Kernel/VTManager/VirtualTerminal.class.h create mode 100644 Source/Kernel/VTManager/VirtualTerminal.proto.cpp create mode 100644 Source/Kernel/VTManager/VirtualTerminal.proto.h (limited to 'Source/Kernel/VTManager') diff --git a/Source/Kernel/VTManager/ScrollableVT.class.cpp b/Source/Kernel/VTManager/ScrollableVT.class.cpp new file mode 100644 index 0000000..ca0075a --- /dev/null +++ b/Source/Kernel/VTManager/ScrollableVT.class.cpp @@ -0,0 +1,94 @@ +#include "ScrollableVT.class.h" +#include +#include + +#define BUFCHR(l, c) m_buff[((l) * m_cols) + (c)] + +ScrollableVT::ScrollableVT(u32int rows, u32int cols, u32int keepRows, u8int fgcolor, u8int bgcolor) : + SimpleVT(rows, cols, fgcolor, bgcolor) { + m_keeprows = keepRows; + m_linesup = 0; + m_lines = new vtchr* [keepRows]; + for (u32int i = 0; i < keepRows; i++) { + m_lines[i] = new vtchr [cols]; + for (u32int j = 0; j < cols; j++) { + m_lines[i][j].color = m_color; + m_lines[i][j].c = " "; + } + } +} + +ScrollableVT::~ScrollableVT() { + for (u32int i = 0; i < m_keeprows; i++) { + delete m_lines[i]; + } + delete m_lines; +} + +void ScrollableVT::putChar(u32int row, u32int col, WChar c) { + if (row >= m_rows or col >= m_cols) return; + vtchr* ch = &BUFCHR(row, col); + ch->c = c; + ch->color = m_color; + if (m_mapped) { + if (row + m_linesup < m_rows) + Disp::putChar(row + m_maprow + m_linesup, col + m_mapcol, BUFCHR(row, col).c, m_color); + } +} + +void ScrollableVT::updateCursor() { + if (m_csrlin + m_linesup < m_rows) + Disp::moveCursor(m_csrlin + m_maprow + m_linesup, m_csrcol + m_mapcol); +} + +void ScrollableVT::redraw() { + if (!m_mapped) return; + for (u32int r = 0; r < m_rows; r++) { + if (r >= m_linesup) { + for (u32int c = 0; c < m_cols; c++) { + Disp::putChar(r + m_maprow, c + m_mapcol, BUFCHR(r - m_linesup, c).c, BUFCHR(r - m_linesup, c).color); + } + } else { + for (u32int c = 0; c < m_cols; c++) { + register u32int l = m_keeprows - m_linesup + r; + Disp::putChar(r + m_maprow, c + m_mapcol, m_lines[l][c].c, m_lines[l][c].color); + } + } + } +} + +void ScrollableVT::scroll() { + for (u32int c = 0; c < m_cols; c++) { + m_lines[0][c] = BUFCHR(0, c); + } + vtchr* x = m_lines[0]; + for (u32int l = 1; l < m_keeprows; l++) { + m_lines[l - 1] = m_lines[l]; + } + m_lines[m_keeprows - 1] = x; + SimpleVT::scroll(); +} + +void ScrollableVT::keyPress(Kbd::keypress_t kp) { + if (kp.hascmd && kp.modifiers == STATUS_SHIFT) { + s32int nlup = m_linesup; + if (kp.command == KBDC_PGUP) { + nlup = m_linesup + (m_rows - 2); + } else if (kp.command == KBDC_PGDOWN) { + nlup = m_linesup - (m_rows - 2); + } else if (kp.command == KBDC_UP) { + nlup = m_linesup + 1; + } else if (kp.command == KBDC_DOWN) { + nlup = m_linesup - 1; + } else { + VirtualTerminal::keyPress(kp); + } + if (nlup < 0) nlup = 0; + m_linesup = nlup; + if (m_linesup > m_keeprows) m_linesup = m_keeprows; + redraw(); + updateCursor(); + } else { + VirtualTerminal::keyPress(kp); + } +} diff --git a/Source/Kernel/VTManager/ScrollableVT.class.h b/Source/Kernel/VTManager/ScrollableVT.class.h new file mode 100644 index 0000000..fbc2c4c --- /dev/null +++ b/Source/Kernel/VTManager/ScrollableVT.class.h @@ -0,0 +1,24 @@ +#ifndef DEF_SCROLLABLEVT_CLASS_H +#define DEF_SCROLLABLEVT_CLASS_H + +#include + +class ScrollableVT : public SimpleVT { + private: + vtchr **m_lines; + u32int m_keeprows; + u32int m_linesup; + + public: + ScrollableVT(u32int rows, u32int cols, u32int keepRows, u8int fgcolor = 7, u8int bgcolor = 0); + virtual ~ScrollableVT(); + + virtual void putChar(u32int row, u32int col, WChar c); + void updateCursor(); + void redraw(); + void scroll(); + + void keyPress(Kbd::keypress_t kp); +}; + +#endif diff --git a/Source/Kernel/VTManager/SimpleVT.class.cpp b/Source/Kernel/VTManager/SimpleVT.class.cpp new file mode 100644 index 0000000..9639d50 --- /dev/null +++ b/Source/Kernel/VTManager/SimpleVT.class.cpp @@ -0,0 +1,135 @@ +#include "SimpleVT.class.h" +#include +#include + +#define BUFCHR(l, c) m_buff[((l) * m_cols) + (c)] + +SimpleVT::SimpleVT(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) : VirtualTerminal() { + m_buff = new vtchr[rows * cols]; + m_rows = rows; + m_cols = cols; + m_mapped = false; + setColor(fgcolor, bgcolor); + clear(); + + m_csrcol = 0; + m_csrlin = 0; +} + +SimpleVT::~SimpleVT() { + if (m_mapped) VT::unmap(this); + delete [] m_buff; +} + +void SimpleVT::setColor(u8int fgcolor, u8int bgcolor) { + if (bgcolor == 0xFF) { + m_color = (m_color & 0xF0) | fgcolor; + } else { + m_color = (bgcolor << 4) | fgcolor; + } +} + +void SimpleVT::putChar(u32int row, u32int col, WChar c) { + if (row >= m_rows or col >= m_cols) return; + vtchr* ch = &BUFCHR(row, col); + ch->c = c; + ch->color = m_color; + if (m_mapped) + Disp::putChar(row + m_maprow, col + m_mapcol, BUFCHR(row, col).c, m_color); +} + +void SimpleVT::clear() { + for (u32int i = 0; i < m_rows * m_cols; i++) { + m_buff[i].c = ' '; + m_buff[i].color = m_color; + } + if (m_mapped) redraw(); +} + +void SimpleVT::map(s32int row, s32int col) { + m_maprow = (row == -1 ? (Disp::textRows() / 2) - (m_rows / 2) : row); + m_mapcol = (col == -1 ? (Disp::textCols() / 2) - (m_cols / 2) : col); + m_mapped = true; + redraw(); + VT::map(this); +} + +void SimpleVT::unmap() { + m_mapped = false; + VT::unmap(this); +} + +void SimpleVT::redraw() { + if (!m_mapped) return; + for (u32int r = 0; r < m_rows; r++) { + for (u32int c = 0; c < m_cols; c++) { + Disp::putChar(r + m_maprow, c + m_mapcol, BUFCHR(r, c).c, BUFCHR(r, c).color); + } + } +} + +void SimpleVT::scroll() { + for (u32int l = 0; l < m_rows - 1; l++) { + for (u32int c = 0; c < m_cols; c++) { + BUFCHR(l, c) = BUFCHR(l + 1, c); + } + } + for (u32int c = 0; c < m_cols; c++) { + BUFCHR(m_rows - 1, c).c = ' '; + BUFCHR(m_rows - 1, c).color = m_color; + } + if (m_mapped) redraw(); +} + +void SimpleVT::updateCursor() { + Disp::moveCursor(m_csrlin + m_maprow, m_csrcol + m_mapcol); +} + +void SimpleVT::moveCursor(u32int row, u32int col) { + m_csrlin = row; + m_csrcol = col; + updateCursor(); +} + +void SimpleVT::setCursorLine(u32int line) { + m_csrlin = line; + updateCursor(); +} + +void SimpleVT::setCursorCol(u32int col) { + m_csrcol = col; + updateCursor(); +} + + +// Display functionn +void SimpleVT::put(WChar c, bool updatecsr) { + if (c.value == '\b') { + if (m_csrcol > 0) m_csrcol--; + putChar(m_csrlin, m_csrcol, ' '); + } else if (c.value == '\t') { + m_csrcol = (m_csrcol + 8) &~(8 - 1); + } else if (c.value == '\r') { + m_csrcol = 0; + } else if (c.value == '\n') { + m_csrcol = 0; + m_csrlin++; + } else if (c.value >= ' ') { //Printable character + putChar(m_csrlin, m_csrcol, c); + m_csrcol++; + } + if (m_csrcol >= m_cols) { + m_csrcol = 0; + m_csrlin++; + } + while (m_csrlin >= m_rows) { + scroll(); + m_csrlin--; + } + if (updatecsr) updateCursor(); +} + +void SimpleVT::hexDump(u8int *ptr, u32int sz, bool addnl) { + if (m_cols < 76) return; //Not enough space + VirtualTerminal::hexDump(ptr, sz, (m_cols == 76)); +} diff --git a/Source/Kernel/VTManager/SimpleVT.class.h b/Source/Kernel/VTManager/SimpleVT.class.h new file mode 100644 index 0000000..6a50549 --- /dev/null +++ b/Source/Kernel/VTManager/SimpleVT.class.h @@ -0,0 +1,42 @@ +#ifndef DEF_SIMPLEVT_CLASS_H +#define DEF_SIMPLEVT_CLASS_H + +#include + +class SimpleVT : public VirtualTerminal { + protected: + vtchr* m_buff; + u32int m_rows, m_cols; + u8int m_color; + + u32int m_maprow, m_mapcol; + bool m_mapped; + + u32int m_csrlin, m_csrcol; + + public: + SimpleVT(u32int rows, u32int cols, u8int fgcolor = 7, u8int bgcolor = 0); + virtual ~SimpleVT(); + + virtual void putChar(u32int row, u32int col, WChar c); + void clear(); + void setColor(u8int fgcolor, u8int bgcolor = 0xFF); + bool isBoxed() { return true; } + + void map(s32int row = -1, s32int col = -1); + void unmap(); + virtual void redraw(); + virtual void scroll(); //Scrolls 1 line + + virtual void updateCursor(); + void moveCursor(u32int row, u32int col); + void setCursorLine(u32int line); + void setCursorCol(u32int col); + + void put(WChar c, bool updatecsr = true); + + virtual void hexDump(u8int* ptr, u32int sz, bool addnl = false); //Ignore parameter addnl +}; + +#endif + diff --git a/Source/Kernel/VTManager/VT.ns.cpp b/Source/Kernel/VTManager/VT.ns.cpp index 76aeb47..87586bc 100644 --- a/Source/Kernel/VTManager/VT.ns.cpp +++ b/Source/Kernel/VTManager/VT.ns.cpp @@ -4,14 +4,14 @@ namespace VT { -Vector mappedVTs; +Vector mappedVTs; -void map(VirtualTerminal* vt) { +void map(SimpleVT* vt) { unmap(vt); //Bad things might happen mappedVTs.push(vt); } -void unmap(VirtualTerminal* vt) { +void unmap(SimpleVT* vt) { for (u32int i = 0; i < mappedVTs.size(); i++) { if (mappedVTs[i] == vt) { mappedVTs[i] = mappedVTs.back(); diff --git a/Source/Kernel/VTManager/VT.ns.h b/Source/Kernel/VTManager/VT.ns.h index 9e6d3ba..55556b9 100644 --- a/Source/Kernel/VTManager/VT.ns.h +++ b/Source/Kernel/VTManager/VT.ns.h @@ -2,12 +2,12 @@ #define DEF_VT_NS_H #include -#include +#include namespace VT { //These should be called only from inside class VirtualTerminal - void map(VirtualTerminal* vt); - void unmap(VirtualTerminal* vt); + void map(SimpleVT* vt); + void unmap(SimpleVT* vt); void redrawScreen(); } diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp deleted file mode 100644 index 7c784fe..0000000 --- a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "VirtualTerminal.class.h" -#include - -using namespace Kbd; - -void VirtualTerminal::keyPress(keypress_t kp) { - m_kbdbuffMutex.waitLock(); - m_kbdbuff.push(kp); - if (!m_kbdMutex.locked()) { - if (kp.haschar && !kp.hascmd) { - put(kp.character); - } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_ENTER) { - put("\n"); - } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_TAB) { - put("\t"); - } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_BACKSPACE) { - put("\b"); - } - } - m_kbdbuffMutex.unlock(); -} - -keypress_t VirtualTerminal::getKeypress(bool show, bool block) { - m_kbdMutex.waitLock(); - - if (m_kbdbuff.empty() && !block) { - m_kbdMutex.unlock(); - return keypress_t(); - } - - while (m_kbdbuff.empty()) - Task::currentThread->sleep(10); - - m_kbdbuffMutex.waitLock(); - keypress_t ret = m_kbdbuff[0]; - - for (u32int i = 1; i < m_kbdbuff.size(); i++) { - m_kbdbuff[i - 1] = m_kbdbuff[i]; - } - m_kbdbuff.pop(); - m_kbdbuffMutex.unlock(); - - if (show) { - if (ret.haschar && !ret.hascmd) { - put(ret.character); - } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_ENTER) { - put("\n"); - } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_TAB) { - put("\t"); - } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_BACKSPACE) { - put("\b"); - } - } - - m_kbdMutex.unlock(); - return ret; -} - -String VirtualTerminal::readLine(bool show) { - String ret = ""; - keypress_t tmp = getKeypress(show); - while (!(tmp.hascmd && !tmp.haschar && tmp.command == KBDC_ENTER)) { - if (tmp.hascmd && !tmp.haschar && tmp.command == KBDC_BACKSPACE) { - if (!ret.empty()) ret = ret.substr(0, ret.size() - 1); - else put(" "); //Put a space so that cursor stays at same place - } else if (tmp.haschar && !tmp.hascmd) { - ret += tmp.character; - } - tmp = getKeypress(show); - } - if (!show) put("\n"); //Put a return if it hasn't been shown on getChar(); - return ret; -} diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp new file mode 100644 index 0000000..1797554 --- /dev/null +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp @@ -0,0 +1,73 @@ +#include "VirtualTerminal.proto.h" +#include + +using namespace Kbd; + +void VirtualTerminal::keyPress(keypress_t kp) { + m_kbdbuffMutex.waitLock(); + m_kbdbuff.push(kp); + if (!m_kbdMutex.locked()) { + if (kp.haschar && !kp.hascmd) { + put(kp.character); + } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_ENTER) { + put("\n"); + } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_TAB) { + put("\t"); + } else if (kp.hascmd && !kp.haschar && kp.command == KBDC_BACKSPACE) { + put("\b"); + } + } + m_kbdbuffMutex.unlock(); +} + +keypress_t VirtualTerminal::getKeypress(bool show, bool block) { + m_kbdMutex.waitLock(); + + if (m_kbdbuff.empty() && !block) { + m_kbdMutex.unlock(); + return keypress_t(); + } + + while (m_kbdbuff.empty()) + Task::currentThread->sleep(10); + + m_kbdbuffMutex.waitLock(); + keypress_t ret = m_kbdbuff[0]; + + for (u32int i = 1; i < m_kbdbuff.size(); i++) { + m_kbdbuff[i - 1] = m_kbdbuff[i]; + } + m_kbdbuff.pop(); + m_kbdbuffMutex.unlock(); + + if (show) { + if (ret.haschar && !ret.hascmd) { + put(ret.character); + } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_ENTER) { + put("\n"); + } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_TAB) { + put("\t"); + } else if (ret.hascmd && !ret.haschar && ret.command == KBDC_BACKSPACE) { + put("\b"); + } + } + + m_kbdMutex.unlock(); + return ret; +} + +String VirtualTerminal::readLine(bool show) { + String ret = ""; + keypress_t tmp = getKeypress(show); + while (!(tmp.hascmd && !tmp.haschar && tmp.command == KBDC_ENTER)) { + if (tmp.hascmd && !tmp.haschar && tmp.command == KBDC_BACKSPACE) { + if (!ret.empty()) ret = ret.substr(0, ret.size() - 1); + else put(" "); //Put a space so that cursor stays at same place + } else if (tmp.haschar && !tmp.hascmd) { + ret += tmp.character; + } + tmp = getKeypress(show); + } + if (!show) put("\n"); //Put a return if it hasn't been shown on getChar(); + return ret; +} diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.cpp b/Source/Kernel/VTManager/VirtualTerminal.class.cpp deleted file mode 100644 index 7ee360b..0000000 --- a/Source/Kernel/VTManager/VirtualTerminal.class.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "VirtualTerminal.class.h" -#include -#include - -#define BUFCHR(l, c) m_buff[((l) * m_cols) + (c)] - -VirtualTerminal::VirtualTerminal(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) : m_kbdMutex(false) { - m_buff = new chr[rows * cols]; - m_rows = rows; - m_cols = cols; - m_mapped = false; - setColor(fgcolor, bgcolor); - clear(); - - m_csrcol = 0; - m_csrlin = 0; -} - -VirtualTerminal::~VirtualTerminal() { - if (m_mapped) VT::unmap(this); - delete [] m_buff; -} - -void VirtualTerminal::setColor(u8int fgcolor, u8int bgcolor) { - if (bgcolor == 0xFF) { - m_color = (m_color & 0xF0) | fgcolor; - } else { - m_color = (bgcolor << 4) | fgcolor; - } -} - -void VirtualTerminal::putChar(u32int row, u32int col, WChar c) { - if (row >= m_rows or col >= m_cols) return; - chr* ch = &BUFCHR(row, col); - ch->c = c; - ch->color = m_color; - if (m_mapped) - Disp::putChar(row + m_maprow, col + m_mapcol, BUFCHR(row, col).c, m_color); -} - -void VirtualTerminal::clear() { - for (u32int i = 0; i < m_rows * m_cols; i++) { - m_buff[i].c = ' '; - m_buff[i].color = m_color; - } - if (m_mapped) redraw(); -} - -void VirtualTerminal::map(s32int row, s32int col) { - m_maprow = (row == -1 ? (Disp::textRows() / 2) - (m_rows / 2) : row); - m_mapcol = (col == -1 ? (Disp::textCols() / 2) - (m_cols / 2) : col); - m_mapped = true; - redraw(); - VT::map(this); -} - -void VirtualTerminal::unmap() { - m_mapped = false; - VT::unmap(this); -} - -void VirtualTerminal::redraw() { - if (!m_mapped) return; - for (u32int r = 0; r < m_rows; r++) { - for (u32int c = 0; c < m_cols; c++) { - Disp::putChar(r + m_maprow, c + m_mapcol, BUFCHR(r, c).c, BUFCHR(r, c).color); - } - } -} - -void VirtualTerminal::scroll() { - for (u32int l = 0; l < m_rows - 1; l++) { - for (u32int c = 0; c < m_cols; c++) { - BUFCHR(l, c) = BUFCHR(l + 1, c); - } - } - for (u32int c = 0; c < m_cols; c++) { - BUFCHR(m_rows - 1, c).c = ' '; - BUFCHR(m_rows - 1, c).color = m_color; - } - if (m_mapped) redraw(); -} - -void VirtualTerminal::updateCursor() { - Disp::moveCursor(m_csrlin + m_maprow, m_csrcol + m_mapcol); -} - -void VirtualTerminal::moveCursor(u32int row, u32int col) { - m_csrlin = row; - m_csrcol = col; - updateCursor(); -} - -void VirtualTerminal::setCursorLine(u32int line) { - m_csrlin = line; - updateCursor(); -} - -void VirtualTerminal::setCursorCol(u32int col) { - m_csrcol = col; - updateCursor(); -} - - -// Display functionn -void VirtualTerminal::put(WChar c, bool updatecsr) { - if (c.value == '\b') { - if (m_csrcol > 0) m_csrcol--; - putChar(m_csrlin, m_csrcol, ' '); - } else if (c.value == '\t') { - m_csrcol = (m_csrcol + 8) &~(8 - 1); - } else if (c.value == '\r') { - m_csrcol = 0; - } else if (c.value == '\n') { - m_csrcol = 0; - m_csrlin++; - } else if (c.value >= ' ') { //Printable character - putChar(m_csrlin, m_csrcol, c); - m_csrcol++; - } - if (m_csrcol >= m_cols) { - m_csrcol = 0; - m_csrlin++; - } - while (m_csrlin >= m_rows) { - scroll(); - m_csrlin--; - } - if (updatecsr) updateCursor(); -} - -void VirtualTerminal::write(const String& s, bool updatecsr) { - for (u32int i = 0; i < s.size(); i++) { - put(s[i], false); - } - if (updatecsr) updateCursor(); -} - -void VirtualTerminal::writeDec(s64int num, bool updatecsr) { - u64int i = num; - if (i == 0) { - put('0', false); - } else if (num < 0) { - put('-', false); - i = 0 - num; - } - char c[32]; - int n = 0; - while (i > 0) { - c[n] = '0' + (i % 10); - i /= 10; - n++; - } - while (n > 0) { - n--; - put(c[n], false); - } - if (updatecsr) updateCursor(); -} - -void VirtualTerminal::writeHex(u32int i, bool updatecsr) { - write("0x", false); - char hexdigits[] = "0123456789ABCDEF"; - for (u32int j = 0; j < 8; j++) { - put(hexdigits[(i & 0xF0000000) >> 28], false); - i = i << 4; - } - if (updatecsr) updateCursor(); -} - -void VirtualTerminal::hexDump(u8int *ptr, u32int sz) { - if (m_cols < 76) return; //Not enough space - write("HEX Dump, from "); writeHex((u32int)ptr); write("\n"); - char hexdigits[] = "0123456789ABCDEF"; - for (u32int i = 0; i < sz; i += 16) { - writeHex(i); - write(" "); - for (u32int j = 0; j < 16; j++) { - u8int b = ptr[i + j]; - if (j > 7) put(" "); - put(hexdigits[b >> 4]); - put(hexdigits[b & 0xF]); - if (j < 8) put(" "); - } - write(" "); - for (u32int j = 0; j < 16; j++) { - u8int b = ptr[i + j]; - if (b >= 0x20 && b < 128) { - put(WChar(b)); - } else { - put("."); - } - } - if (m_cols > 76) write("\n"); - } -} diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.h b/Source/Kernel/VTManager/VirtualTerminal.class.h deleted file mode 100644 index d8d7104..0000000 --- a/Source/Kernel/VTManager/VirtualTerminal.class.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef DEF_VIRTUALTERMINAL_CLASS_H -#define DEF_VIRTUALTERMINAL_CLASS_H - -#include -#include -#include -#include -#include - -struct chr { - u8int color; - WChar c; -}; - -class VirtualTerminal { - private: - chr* m_buff; - u32int m_rows, m_cols; - u8int m_color; - - u32int m_maprow, m_mapcol; - bool m_mapped; - - u32int m_csrlin, m_csrcol; - - Mutex m_kbdMutex, m_kbdbuffMutex; - Vector m_kbdbuff; //Key press events buffer - - public: - VirtualTerminal(u32int rows, u32int cols, u8int fgcolor = 7, u8int bgcolor = 0); - ~VirtualTerminal(); - - void setColor(u8int fgcolor, u8int bgcolor = 0xFF); - void putChar(u32int row, u32int col, WChar c); - void clear(); - - void map(s32int row = -1, s32int col = -1); - void unmap(); - void redraw(); - void scroll(); //Scrolls 1 line - - void updateCursor(); - void moveCursor(u32int row, u32int col); - void setCursorLine(u32int line); - void setCursorCol(u32int col); - - //Display functions - void put(WChar c, bool updatecsr = true); - void write(const String& s, bool updatecsr = true); - void writeDec(s64int num, bool updatecsr = true); - void writeHex(u32int i, bool updatecsr = true); - - void hexDump(u8int* ptr, u32int sz); - - inline VirtualTerminal& operator<<(const String& s) { write(s); return *this; } - //inline VirtualTerminal& operator<<(WChar c) { put(c); return *this; } - inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } - inline VirtualTerminal& operator<<(s64int i) { writeDec(i); return *this; } - inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } - - //Keyboard functions - void keyPress(Kbd::keypress_t kp); //Called by Kbd:: when a key is pressed - Kbd::keypress_t getKeypress(bool show = true, bool block = true); //Block : must we wait for a key to be pressed ? - String readLine(bool show = true); -}; - -#endif diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp new file mode 100644 index 0000000..7a9ffa8 --- /dev/null +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp @@ -0,0 +1,74 @@ +#include "VirtualTerminal.proto.h" +#include +#include + +VirtualTerminal::VirtualTerminal() : m_kbdMutex(false), m_kbdbuffMutex(false) { +} + +VirtualTerminal::~VirtualTerminal() { +} + +void VirtualTerminal::write(const String& s, bool updatecsr) { + for (u32int i = 0; i < s.size(); i++) { + put(s[i], false); + } + if (updatecsr) updateCursor(); +} + +void VirtualTerminal::writeDec(s64int num, bool updatecsr) { + u64int i = num; + if (i == 0) { + put('0', false); + } else if (num < 0) { + put('-', false); + i = 0 - num; + } + char c[32]; + int n = 0; + while (i > 0) { + c[n] = '0' + (i % 10); + i /= 10; + n++; + } + while (n > 0) { + n--; + put(c[n], false); + } + if (updatecsr) updateCursor(); +} + +void VirtualTerminal::writeHex(u32int i, bool updatecsr) { + write("0x", false); + char hexdigits[] = "0123456789ABCDEF"; + for (u32int j = 0; j < 8; j++) { + put(hexdigits[(i & 0xF0000000) >> 28], false); + i = i << 4; + } + if (updatecsr) updateCursor(); +} + +void VirtualTerminal::hexDump(u8int *ptr, u32int sz, bool addnl) { + write("HEX Dump, from "); writeHex((u32int)ptr); write("\n"); + char hexdigits[] = "0123456789ABCDEF"; + for (u32int i = 0; i < sz; i += 16) { + writeHex(i); + write(" "); + for (u32int j = 0; j < 16; j++) { + u8int b = ptr[i + j]; + if (j > 7) put(" "); + put(hexdigits[b >> 4]); + put(hexdigits[b & 0xF]); + if (j < 8) put(" "); + } + write(" "); + for (u32int j = 0; j < 16; j++) { + u8int b = ptr[i + j]; + if (b >= 0x20 && b < 128) { + put(WChar(b)); + } else { + put("."); + } + } + if (addnl) write("\n"); + } +} diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h new file mode 100644 index 0000000..bd38d89 --- /dev/null +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h @@ -0,0 +1,51 @@ +#ifndef DEF_VIRTUALTERMINAL_CLASS_H +#define DEF_VIRTUALTERMINAL_CLASS_H + +#include +#include +#include +#include +#include + +struct vtchr { + u8int color; + WChar c; +}; + +class VirtualTerminal { + protected: + Mutex m_kbdMutex, m_kbdbuffMutex; + Vector m_kbdbuff; //Key press events buffer + + public: + VirtualTerminal(); + virtual ~VirtualTerminal(); + + virtual void setColor(u8int fgcolor, u8int bgcolor = 0xFF) {} //For a pipe/file VT, this will do nothing. + virtual bool isBoxed() = 0; + + virtual void updateCursor() {} + virtual void moveCursor(u32int row, u32int col) {} //These are not implemented for pipe/file VTs + virtual void setCursorLine(u32int line) {} + virtual void setCursorCol(u32int col) {} //This one could be, and should be. It's used a lot for tabulating, etc. + + //Display functions + virtual void put(WChar c, bool updatecsr = true) = 0; + void write(const String& s, bool updatecsr = true); + void writeDec(s64int num, bool updatecsr = true); + void writeHex(u32int i, bool updatecsr = true); + + virtual void hexDump(u8int* ptr, u32int sz, bool addnl = true); //Always ignore parameter addnl + + inline VirtualTerminal& operator<<(const String& s) { write(s); return *this; } + inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } + inline VirtualTerminal& operator<<(s64int i) { writeDec(i); return *this; } + inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } + + //Keyboard functions + virtual void keyPress(Kbd::keypress_t kp); //Called by Kbd:: when a key is pressed, overloaded by ScrollableVT + Kbd::keypress_t getKeypress(bool show = true, bool block = true); //Block : must we wait for a key to be pressed ? + String readLine(bool show = true); +}; + +#endif -- cgit v1.2.3