diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-20 14:27:07 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-20 14:27:07 +0200 |
commit | af3ff7f8c80bb3953f261a602316f92ec662daa8 (patch) | |
tree | 6321339875d7bd3aa4d03ab0ae11b20f037459d2 /Source/Kernel/VTManager | |
parent | 82fec280c2ceba890ea794f5a5917877677fb984 (diff) | |
parent | 1eb942c8a34166e43f43c843f09bb48ba40b65b2 (diff) | |
download | Melon-af3ff7f8c80bb3953f261a602316f92ec662daa8.tar.gz Melon-af3ff7f8c80bb3953f261a602316f92ec662daa8.zip |
Merge branch 'advt'
Conflicts:
Source/Kernel/Melon.ke
Source/Kernel/VTManager/SimpleVT.class.cpp
Source/Kernel/VTManager/VirtualTerminal.proto.h
Diffstat (limited to 'Source/Kernel/VTManager')
-rw-r--r-- | Source/Kernel/VTManager/ScrollableVT.class.cpp | 94 | ||||
-rw-r--r-- | Source/Kernel/VTManager/ScrollableVT.class.h | 24 | ||||
-rw-r--r-- | Source/Kernel/VTManager/SimpleVT.class.cpp (renamed from Source/Kernel/VTManager/VirtualTerminal.class.cpp) | 97 | ||||
-rw-r--r-- | Source/Kernel/VTManager/SimpleVT.class.h | 42 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VT.ns.cpp | 6 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VT.ns.h | 6 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp (renamed from Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp) | 2 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal.proto.cpp | 74 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal.proto.h (renamed from Source/Kernel/VTManager/VirtualTerminal.class.h) | 39 |
9 files changed, 271 insertions, 113 deletions
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 <VTManager/VT.ns.h> +#include <DeviceManager/Disp.ns.h> + +#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 <VTManager/SimpleVT.class.h> + +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/VirtualTerminal.class.cpp b/Source/Kernel/VTManager/SimpleVT.class.cpp index 8555bf0..9639d50 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.cpp +++ b/Source/Kernel/VTManager/SimpleVT.class.cpp @@ -1,10 +1,10 @@ -#include "VirtualTerminal.class.h" -#include <DeviceManager/Disp.ns.h> +#include "SimpleVT.class.h" #include <VTManager/VT.ns.h> +#include <DeviceManager/Disp.ns.h> #define BUFCHR(l, c) m_buff[((l) * m_cols) + (c)] -VirtualTerminal::VirtualTerminal(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) : m_kbdMutex(false) { +SimpleVT::SimpleVT(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) : VirtualTerminal() { m_buff = new vtchr[rows * cols]; m_rows = rows; m_cols = cols; @@ -16,12 +16,12 @@ VirtualTerminal::VirtualTerminal(u32int rows, u32int cols, u8int fgcolor, u8int m_csrlin = 0; } -VirtualTerminal::~VirtualTerminal() { +SimpleVT::~SimpleVT() { if (m_mapped) VT::unmap(this); delete [] m_buff; } -void VirtualTerminal::setColor(u8int fgcolor, u8int bgcolor) { +void SimpleVT::setColor(u8int fgcolor, u8int bgcolor) { if (bgcolor == 0xFF) { m_color = (m_color & 0xF0) | fgcolor; } else { @@ -29,7 +29,7 @@ void VirtualTerminal::setColor(u8int fgcolor, u8int bgcolor) { } } -void VirtualTerminal::putChar(u32int row, u32int col, WChar c) { +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; @@ -38,7 +38,7 @@ void VirtualTerminal::putChar(u32int row, u32int col, WChar c) { Disp::putChar(row + m_maprow, col + m_mapcol, BUFCHR(row, col).c, m_color); } -void VirtualTerminal::clear() { +void SimpleVT::clear() { for (u32int i = 0; i < m_rows * m_cols; i++) { m_buff[i].c = ' '; m_buff[i].color = m_color; @@ -46,7 +46,7 @@ void VirtualTerminal::clear() { if (m_mapped) redraw(); } -void VirtualTerminal::map(s32int row, s32int col) { +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; @@ -54,12 +54,12 @@ void VirtualTerminal::map(s32int row, s32int col) { VT::map(this); } -void VirtualTerminal::unmap() { +void SimpleVT::unmap() { m_mapped = false; VT::unmap(this); } -void VirtualTerminal::redraw() { +void SimpleVT::redraw() { if (!m_mapped) return; for (u32int r = 0; r < m_rows; r++) { for (u32int c = 0; c < m_cols; c++) { @@ -68,7 +68,7 @@ void VirtualTerminal::redraw() { } } -void VirtualTerminal::scroll() { +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); @@ -81,29 +81,29 @@ void VirtualTerminal::scroll() { if (m_mapped) redraw(); } -void VirtualTerminal::updateCursor() { +void SimpleVT::updateCursor() { Disp::moveCursor(m_csrlin + m_maprow, m_csrcol + m_mapcol); } -void VirtualTerminal::moveCursor(u32int row, u32int col) { +void SimpleVT::moveCursor(u32int row, u32int col) { m_csrlin = row; m_csrcol = col; updateCursor(); } -void VirtualTerminal::setCursorLine(u32int line) { +void SimpleVT::setCursorLine(u32int line) { m_csrlin = line; updateCursor(); } -void VirtualTerminal::setCursorCol(u32int col) { +void SimpleVT::setCursorCol(u32int col) { m_csrcol = col; updateCursor(); } // Display functionn -void VirtualTerminal::put(WChar c, bool updatecsr) { +void SimpleVT::put(WChar c, bool updatecsr) { if (c.value == '\b') { if (m_csrcol > 0) m_csrcol--; putChar(m_csrlin, m_csrcol, ' '); @@ -129,68 +129,7 @@ void VirtualTerminal::put(WChar c, bool updatecsr) { 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) { +void SimpleVT::hexDump(u8int *ptr, u32int sz, bool addnl) { 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"); - } + 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 <VTManager/VirtualTerminal.proto.h> + +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<VirtualTerminal*> mappedVTs; +Vector<SimpleVT*> 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 <Core/common.wtf.h> -#include <VTManager/VirtualTerminal.class.h> +#include <VTManager/SimpleVT.class.h> 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.proto.cpp index 7c784fe..1797554 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp @@ -1,4 +1,4 @@ -#include "VirtualTerminal.class.h" +#include "VirtualTerminal.proto.h" #include <TaskManager/Task.ns.h> using namespace Kbd; 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 <DeviceManager/Disp.ns.h> +#include <VTManager/VT.ns.h> + +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.class.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h index 690ee2a..bd38d89 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.h +++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h @@ -13,44 +13,29 @@ struct vtchr { }; class VirtualTerminal { - private: - vtchr* m_buff; - u32int m_rows, m_cols; - u8int m_color; - - u32int m_maprow, m_mapcol; - bool m_mapped; - - u32int m_csrlin, m_csrcol; - + protected: Mutex m_kbdMutex, m_kbdbuffMutex; Vector<Kbd::keypress_t> 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(); + VirtualTerminal(); + virtual ~VirtualTerminal(); - void map(s32int row = -1, s32int col = -1); - void unmap(); - void redraw(); - void scroll(); //Scrolls 1 line + virtual void setColor(u8int fgcolor, u8int bgcolor = 0xFF) {} //For a pipe/file VT, this will do nothing. + virtual bool isBoxed() = 0; - void updateCursor(); - void moveCursor(u32int row, u32int col); - void setCursorLine(u32int line); - void setCursorCol(u32int col); + 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 - void put(WChar c, bool updatecsr = true); + 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); - void hexDump(u8int* ptr, u32int sz); + 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; } @@ -58,7 +43,7 @@ class VirtualTerminal { 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 + 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); }; |