summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Kernel/Config.h3
-rw-r--r--Source/Kernel/Core/Sys.ns.cpp19
-rw-r--r--Source/Kernel/Core/Sys.ns.h1
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp15
-rw-r--r--Source/Kernel/DeviceManager/Kbd.ns.cpp2
-rw-r--r--Source/Kernel/Library/ByteArray.class.h2
-rw-r--r--Source/Kernel/Library/WChar.class.h4
-rw-r--r--Source/Kernel/Makefile6
-rw-r--r--Source/Kernel/MemoryManager/PhysMem.ns.cpp2
-rw-r--r--Source/Kernel/Ressources/Graphics/logo.text.cxd (renamed from Source/Kernel/Ressources/logo.cxd)0
-rw-r--r--Source/Kernel/Ressources/Keymaps/fr.cxd (renamed from Source/Kernel/Ressources/keymap-fr.wtf.cxd)10
-rw-r--r--Source/Kernel/Ressources/Texts/Info.txt (renamed from Source/Kernel/Ressources/Info.txt)0
-rw-r--r--Source/Kernel/Ressources/Texts/Welcome.txt (renamed from Source/Kernel/Ressources/Welcome.txt)0
-rw-r--r--Source/Kernel/SyscallManager/IDT.ns.cpp2
-rw-r--r--Source/Kernel/TaskManager/Process.class.h2
-rw-r--r--Source/Kernel/TaskManager/Task.ns.h2
-rw-r--r--Source/Kernel/VTManager/ScrollableVT.class.cpp94
-rw-r--r--Source/Kernel/VTManager/ScrollableVT.class.h24
-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.h42
-rw-r--r--Source/Kernel/VTManager/VT.ns.cpp6
-rw-r--r--Source/Kernel/VTManager/VT.ns.h6
-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.cpp74
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.h (renamed from Source/Kernel/VTManager/VirtualTerminal.class.h)39
25 files changed, 319 insertions, 135 deletions
diff --git a/Source/Kernel/Config.h b/Source/Kernel/Config.h
index 2767104..09c7a14 100644
--- a/Source/Kernel/Config.h
+++ b/Source/Kernel/Config.h
@@ -1,6 +1,9 @@
#ifndef DEF_MELON_KERNEL_CONFIG
#define DEF_MELON_KERNEL_CONFIG
+#define THIS_IS_MELON
+#undef THIS_IS_NOT_MELON
+
#define OPT_DEBUG
//Color scheme
diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp
index ab57589..081e7a5 100644
--- a/Source/Kernel/Core/Sys.ns.cpp
+++ b/Source/Kernel/Core/Sys.ns.cpp
@@ -1,9 +1,10 @@
//This automatically includes Sys.ns.h
#include <Core/common.wtf.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <Core/Log.ns.h>
+#include <VTManager/SimpleVT.class.h>
#include <SyscallManager/IDT.ns.h>
-#define DEBUGVT(x) VirtualTerminal *x = new VirtualTerminal(4, 56, 0, 15); x->map(); x->put('\n');
+#define DEBUGVT(x) SimpleVT *x = new SimpleVT(4, 56, 0, 15); x->map(); x->put('\n');
using namespace CMem;
@@ -81,7 +82,7 @@ void panic(char *message, char *file, u32int line) {
void panic(char *message, registers_t *regs, char *file, u32int line) {
asm volatile("cli");
- VirtualTerminal vt(20, 70, 7, 1);
+ SimpleVT vt(20, 70, 7, 1);
vt.map();
vt << "PANIC : " << message << "\n => in " << file << " at " << (s32int)line << "\n\n";
@@ -115,7 +116,19 @@ void panic_assert(char *file, u32int line, char *desc) {
}
void reboot() {
+ asm volatile("cli");
+ Log::close();
outb(0x64, 0xFE);
}
+void halt() {
+ asm volatile("cli");
+ Log::close();
+ String message("MELON SEZ : KTHXBYE, IOU CAN NAOW TURNZ OFF UR COMPUTER.");
+ SimpleVT vt(3, message.size() + 16, 6, 0);
+ vt.map();
+ vt << "\n\t" << message;
+ while (1) asm volatile("cli");
+}
+
}
diff --git a/Source/Kernel/Core/Sys.ns.h b/Source/Kernel/Core/Sys.ns.h
index a205892..6779585 100644
--- a/Source/Kernel/Core/Sys.ns.h
+++ b/Source/Kernel/Core/Sys.ns.h
@@ -31,6 +31,7 @@ namespace Sys {
void bochs_output(String message, char *file, u32int line);
void bochs_output_hex(u32int i);
void reboot();
+ void halt();
}
#endif
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index e3ef2fd..4c576b6 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -11,7 +11,7 @@
#include <DeviceManager/Dev.ns.h>
#include <DeviceManager/Kbd.ns.h>
#include <DeviceManager/Time.ns.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/ScrollableVT.class.h>
#include <MemoryManager/PhysMem.ns.h>
#include <MemoryManager/PageAlloc.ns.h>
#include <MemoryManager/GDT.ns.h>
@@ -27,8 +27,8 @@
#include <VFS/TextFile.class.h>
#include <Core/Log.ns.h>
-#include <Ressources/logo.cxd>
-#include <Ressources/keymap-fr.wtf.cxd>
+#include <Ressources/Graphics/logo.text.cxd>
+#include <Ressources/Keymaps/fr.cxd>
extern u32int end; //Placement address
@@ -65,7 +65,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
Disp::setDisplay(vgaout);
//Create a VT for handling the Melon bootup logo
- VirtualTerminal *melonLogoVT = new VirtualTerminal(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
+ SimpleVT *melonLogoVT = new SimpleVT(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
for (int i = 0; i < melonLogoLines; i++) {
for (int j = 0; j < melonLogoCols; j++) {
melonLogoVT->putChar(i, j, melonLogo[i][j]);
@@ -74,7 +74,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
melonLogoVT->map(1);
//Create a VT for logging what kernel does
- VirtualTerminal *kvt = new VirtualTerminal(15, 76, KVT_FGCOLOR, KVT_BGCOLOR);
+ SimpleVT *kvt = new ScrollableVT(15, 76, 100, KVT_FGCOLOR, KVT_BGCOLOR);
kvt->map(melonLogoLines + 2);
INFO(kvt); *kvt << "Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n";
@@ -116,7 +116,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
Log::log(KL_STATUS, "kmain : Registered textual VGA output");
Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver
- Kbd::setKeymap(keymapFR_normal, keymapFR_shift, keymapFR_caps, keymapFR_altgr, keymapFR_shiftaltgr); //Load keymap
+ Kbd::setKeymap(keymap_normal, keymap_shift, keymap_caps, keymap_altgr, keymap_shiftaltgr); //Load keymap
Kbd::setFocus(kvt); //Set focus to virtual terminal
Log::log(KL_STATUS, "kmain : Keyboard set up");
@@ -135,6 +135,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
*kvt << " - Command list for integrated kernel shell:\n";
*kvt << " - help shows this help screen\n";
*kvt << " - reboot reboots your computer\n";
+ *kvt << " - halt shuts down your computer\n";
*kvt << " - panic causes a kernel panic\n";
*kvt << " - devices shows all detected devices on your computer\n";
*kvt << " - free shows memory usage (physical frames and kernel heap)\n";
@@ -143,6 +144,8 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
*kvt << " - Commands you should know how to use : ls, cd, cat, pwd, rm, mkdir, wf\n";
} else if (tokens[0] == "reboot") {
Sys::reboot();
+ } else if (tokens[0] == "halt") {
+ Sys::halt();
} else if (tokens[0] == "panic") {
PANIC("This is what happens when you say 'panic'.");
} else if (tokens[0] == "ls") {
diff --git a/Source/Kernel/DeviceManager/Kbd.ns.cpp b/Source/Kernel/DeviceManager/Kbd.ns.cpp
index 95a97e3..fddf0dd 100644
--- a/Source/Kernel/DeviceManager/Kbd.ns.cpp
+++ b/Source/Kernel/DeviceManager/Kbd.ns.cpp
@@ -2,7 +2,7 @@
#include <DeviceManager/Dev.ns.h>
#include <Library/Vector.class.h>
#include <Devices/Keyboard/Keyboard.proto.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
namespace Kbd {
diff --git a/Source/Kernel/Library/ByteArray.class.h b/Source/Kernel/Library/ByteArray.class.h
index f5214b3..a6d594f 100644
--- a/Source/Kernel/Library/ByteArray.class.h
+++ b/Source/Kernel/Library/ByteArray.class.h
@@ -2,7 +2,7 @@
#define DEF_BYTEARRAY_CLASS_H
#include <Library/String.class.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
class ByteArray : public BasicString<u8int> {
public:
diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h
index ba94a23..e4da603 100644
--- a/Source/Kernel/Library/WChar.class.h
+++ b/Source/Kernel/Library/WChar.class.h
@@ -1,7 +1,11 @@
#ifndef DEF_UCHAR_CLASS_H
#define DEF_UCHAR_CLASS_H
+#include <Core/types.wtf.h>
+
+#ifndef THIS_IS_NOT_MELON
#include <Core/common.wtf.h>
+#endif
enum {
UE_UTF8,
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile
index e68d12b..7f6fa56 100644
--- a/Source/Kernel/Makefile
+++ b/Source/Kernel/Makefile
@@ -31,8 +31,10 @@ Objects = Core/loader.wtf.o \
TaskManager/Task.ns.o \
TaskManager/Task.wtf.o \
TaskManager/Mutex.class.o \
- VTManager/VirtualTerminal.class.o \
- VTManager/VirtualTerminal-kbd.class.o \
+ VTManager/VirtualTerminal.proto.o \
+ VTManager/SimpleVT.class.o \
+ VTManager/ScrollableVT.class.o \
+ VTManager/VirtualTerminal-kbd.proto.o \
VTManager/VT.ns.o \
Library/Bitset.class.o \
Library/String.class.o \
diff --git a/Source/Kernel/MemoryManager/PhysMem.ns.cpp b/Source/Kernel/MemoryManager/PhysMem.ns.cpp
index 08fa882..1794106 100644
--- a/Source/Kernel/MemoryManager/PhysMem.ns.cpp
+++ b/Source/Kernel/MemoryManager/PhysMem.ns.cpp
@@ -1,6 +1,6 @@
#include "PhysMem.ns.h"
#include <Library/Bitset.class.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
PageDirectory* kernelPageDirectory;
diff --git a/Source/Kernel/Ressources/logo.cxd b/Source/Kernel/Ressources/Graphics/logo.text.cxd
index 6cacdb1..6cacdb1 100644
--- a/Source/Kernel/Ressources/logo.cxd
+++ b/Source/Kernel/Ressources/Graphics/logo.text.cxd
diff --git a/Source/Kernel/Ressources/keymap-fr.wtf.cxd b/Source/Kernel/Ressources/Keymaps/fr.cxd
index f24c14d..8cfdf8c 100644
--- a/Source/Kernel/Ressources/keymap-fr.wtf.cxd
+++ b/Source/Kernel/Ressources/Keymaps/fr.cxd
@@ -1,6 +1,6 @@
//This file is precious !!! Very precious !!
-WChar keymapFR_normal[128] = {
+WChar keymap_normal[128] = {
/* 0x00 */ "", "", "&", "é", "\"", "'", "(", "-", "è", "_", "ç", "à", ")", "=", "", "",
/* 0x10 */ "a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "^", "$", "", "", "q", "s",
/* 0x20 */ "d", "f", "g", "h", "j", "k", "l", "m", "ù", "²", "", "*", "w", "x", "c", "v",
@@ -11,7 +11,7 @@ WChar keymapFR_normal[128] = {
/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
};
-WChar keymapFR_shift[128] = {
+WChar keymap_shift[128] = {
/* 0x00 */ "", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "°", "+", "", "",
/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "£", "", "", "Q", "S",
/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "%", "~", "", "µ", "W", "X", "C", "V",
@@ -22,7 +22,7 @@ WChar keymapFR_shift[128] = {
/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
};
-WChar keymapFR_caps[128] = {
+WChar keymap_caps[128] = {
/* 0x00 */ "", "", "&", "É", "\"", "'", "(", "-", "È", "_", "Ç", "À", ")", "=", "", "",
/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "$", "", "", "Q", "S",
/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "Ù", "²", "", "*", "W", "X", "C", "V",
@@ -33,7 +33,7 @@ WChar keymapFR_caps[128] = {
/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
};
-WChar keymapFR_altgr[128] = {
+WChar keymap_altgr[128] = {
/* 0x00 */ "", "", "¹", "~", "#", "{", "[", "|", "`", "\\", "^", "@", "]", "}", "", "",
/* 0x10 */ "æ", "«", "€", "¶", "ŧ", "←", "↓", "→", "ø", "þ", "¨", "¤", "", "", "@", "ß",
/* 0x20 */ "ð", "đ", "ŋ", "ħ", "j", "ĸ", "ł", "µ", "^", "¬", "", "`", "ł", "»", "¢", "“",
@@ -44,7 +44,7 @@ WChar keymapFR_altgr[128] = {
/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
};
-WChar keymapFR_shiftaltgr[128] = {
+WChar keymap_shiftaltgr[128] = {
/* 0x00 */ "", "", "¡", "⅛", "£", "$", "⅜", "⅝", "⅞", "™", "±", "°", "¿", "˛", "", "",
/* 0x10 */ "Æ", "<", "¢", "®", "Ŧ", "¥", "↑", "ı", "Ø", "Þ", "°", "¯", "", "", "Ω", "§",
/* 0x20 */ "Ð", "ª", "Ŋ", "Ħ", "J", "&", "Ł", "º", "ˇ", "¬", "", "˘", "Ł", ">", "©", "‘",
diff --git a/Source/Kernel/Ressources/Info.txt b/Source/Kernel/Ressources/Texts/Info.txt
index 1a57fc9..1a57fc9 100644
--- a/Source/Kernel/Ressources/Info.txt
+++ b/Source/Kernel/Ressources/Texts/Info.txt
diff --git a/Source/Kernel/Ressources/Welcome.txt b/Source/Kernel/Ressources/Texts/Welcome.txt
index 67bb8b2..67bb8b2 100644
--- a/Source/Kernel/Ressources/Welcome.txt
+++ b/Source/Kernel/Ressources/Texts/Welcome.txt
diff --git a/Source/Kernel/SyscallManager/IDT.ns.cpp b/Source/Kernel/SyscallManager/IDT.ns.cpp
index a27dfa9..4f41fb2 100644
--- a/Source/Kernel/SyscallManager/IDT.ns.cpp
+++ b/Source/Kernel/SyscallManager/IDT.ns.cpp
@@ -1,5 +1,5 @@
#include "IDT.ns.h"
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/SimpleVT.class.h>
#include <DeviceManager/Dev.ns.h>
#include <TaskManager/Task.ns.h>
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index 8b0a030..65a5d8b 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -4,7 +4,7 @@
#include <Library/String.class.h>
#include <Library/Vector.class.h>
#include <MemoryManager/PageDirectory.class.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
#define P_ZOMBIE 0
#define P_RUNNING 1
diff --git a/Source/Kernel/TaskManager/Task.ns.h b/Source/Kernel/TaskManager/Task.ns.h
index db7933c..634d103 100644
--- a/Source/Kernel/TaskManager/Task.ns.h
+++ b/Source/Kernel/TaskManager/Task.ns.h
@@ -2,7 +2,7 @@
#define DEF_TASK_NS_H
#include <TaskManager/Thread.class.h>
-#include <VTManager/VirtualTerminal.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
namespace Task {
extern Thread* currentThread;
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);
};