summaryrefslogtreecommitdiff
path: root/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
blob: 9b0b86266572dcbb1339f9f66ca5a090ca0edfd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "VirtualTerminal.proto.h"
#include <DeviceManager/Disp.ns.h>
#include <VTManager/VT.ns.h>
#include <TaskManager/Task.ns.h>

#include <VirtualTerminal.iface.h>

call_t VirtualTerminal::m_callTable[] = {
	CALL1(VTIF_WRITEHEX, &VirtualTerminal::writeHexSC),
	CALL2(VTIF_WRITEDEC, &VirtualTerminal::writeDecSC),
	CALL1(VTIF_WRITE, &VirtualTerminal::writeSC),
	CALL1(VTIF_PUT, &VirtualTerminal::putSC),
	CALL0(VTIF_READLINE, &VirtualTerminal::readLineSC),
	CALL1(VTIF_SETCOLOR, &VirtualTerminal::setColorSC),
	CALL1(VTIF_SETCSRLINE, &VirtualTerminal::setCursorLineSC),
	CALL1(VTIF_SETCSRCOL, &VirtualTerminal::setCursorColSC),
	CALL0(VTIF_ISBOXED, &VirtualTerminal::isBoxedSC),
	CALL0(0, 0)
};

u32int VirtualTerminal::scall(u8int wat, u32int a, u32int b, u32int c, u32int d) {
	if (wat == VTIF_SGETPRVT) return Task::currProcess()->getVirtualTerminal()->resId();
	return (u32int) - 1;
}

VirtualTerminal::VirtualTerminal() : 
	Ressource(VTIF_OBJTYPE, m_callTable), m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() {
}

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");
	}
}