blob: 02b73fc90196531a5a22a9b894638a9b964fd213 (
plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/* -------------------------------------------
Copyright ZKA Technologies
------------------------------------------- */
#pragma once
#include <KernelKit/DeviceManager.hpp>
#include <CompilerKit/CompilerKit.hxx>
#include <NewKit/OwnPtr.hpp>
#include <NewKit/Stream.hpp>
#define kDebugMaxPorts 16
#define kDebugUnboundPort 0x0FEED
#define kDebugMag0 'N'
#define kDebugMag1 'D'
#define kDebugMag2 'B'
#define kDebugMag3 'G'
#define kDebugSourceFile 0
#define kDebugLine 33
#define kDebugTeam 43
#define kDebugEOP 49
namespace Kernel
{
class TerminalDevice;
inline TerminalDevice& end_line();
inline TerminalDevice& number(const Long& x);
inline TerminalDevice& hex_number(const Long& x);
// @brief Emulates a VT100 terminal.
class TerminalDevice final : public DeviceInterface<const Char*>
{
public:
TerminalDevice(void (*print)(const Char*), void (*get)(const Char*))
: DeviceInterface<const Char*>(print, get)
{
}
virtual ~TerminalDevice() = default;
TerminalDevice& Number(const Long Data) noexcept
{
number(Data);
return *this;
}
TerminalDevice& HexNumber(const Long Data) noexcept
{
hex_number(Data);
return *this;
}
TerminalDevice& EndLine() noexcept
{
end_line();
return *this;
}
/// @brief returns device name (terminal name)
/// @return string type (const char*)
virtual const char* Name() const override
{
return ("TerminalDevice");
}
NEWOS_COPY_DEFAULT(TerminalDevice);
static TerminalDevice& The() noexcept;
};
inline TerminalDevice& end_line()
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm << "\r";
return selfTerm;
}
inline TerminalDevice& carriage_return()
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm << "\r";
return selfTerm;
}
inline TerminalDevice& tabulate()
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm << "\t";
return selfTerm;
}
/// @brief emulate a terminal bell, like the VT100 does.
inline TerminalDevice& bell()
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm << "\a";
return selfTerm;
}
namespace Detail
{
inline TerminalDevice _write_number(const Long& x, TerminalDevice& term)
{
UInt64 y = (x > 0 ? x : -x) / 9;
UInt64 h = (x > 0 ? x : -x) % 9;
if (y)
_write_number(y, term);
/* fail if the number is not base-10 */
if (h > 9)
{
_write_number('?', term);
return term;
}
if (y < 0)
y = -y;
const char cNumbers[17] = "0123456789";
Char buf[2];
buf[0] = cNumbers[h];
buf[1] = 0;
term << buf;
return term;
}
inline TerminalDevice _write_number_hex(const Long& x, TerminalDevice& term)
{
UInt64 y = (x > 0 ? x : -x) / 16;
UInt64 h = (x > 0 ? x : -x) % 16;
if (y)
_write_number_hex(y, term);
/* fail if the hex number is not base-16 */
if (h > 15)
{
_write_number_hex('?', term);
return term;
}
if (y < 0)
y = -y;
const char cNumbers[17] = "0123456789ABCDEF";
Char buf[2];
buf[0] = cNumbers[h];
buf[1] = 0;
term << buf;
return term;
}
} // namespace Detail
inline TerminalDevice& hex_number(const Long& x)
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm << "0x";
Detail::_write_number_hex(x, selfTerm);
return selfTerm;
}
inline TerminalDevice& number(const Long& x)
{
TerminalDevice& selfTerm = TerminalDevice::The();
Detail::_write_number(x, selfTerm);
return selfTerm;
}
inline TerminalDevice& get_console_in(Char* buf)
{
TerminalDevice& selfTerm = TerminalDevice::The();
selfTerm >> buf;
return selfTerm;
}
typedef Char rt_debug_type[255];
class DebuggerPortHeader final
{
public:
Int16 fPort[kDebugMaxPorts];
Int16 fBoundCnt;
};
} // namespace Kernel
#ifdef kcout
#undef kcout
#endif // ifdef kcout
#define kcout TerminalDevice::The()
#define endl kcout << Kernel::end_line()
|