-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal.cpp
More file actions
177 lines (127 loc) · 4.2 KB
/
terminal.cpp
File metadata and controls
177 lines (127 loc) · 4.2 KB
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
/***************************************************************************
* terminal.cpp
*
* Copyright 2008 Matthias v.d. Vlies
* matthias@mserver.nl
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*! \file terminal.cpp
* \brief Terminal Driver
*
* This file implements the Terminal class. The terminal class handles I/O to a virtual terminal.
*
*/
#include <config.h>
#include <errors.h>
#include <core/terminal.h>
Core::Terminal::Terminal(CharacterDevice* device) {
// assign local data
this->_device = device;
this->_type = device->getTerminalType();
if(this->_type == TERMINAL_TYPE_VIDEO) {
// set default terminal color
this->_color = MAKE_COLOR(TERMINAL_BLACK, TERMINAL_LIGHTGRAY, FALSE);
// get memory for the buffer
this->_buffer = new short[VIDEO_SIZE * 2];
this->_bufferSize = VIDEO_SIZE;
// "zero" the buffer
for(int n = 0; n < VIDEO_SIZE; n++) {
this->_buffer[n] = 0 | this->_color;
}
}
}
unsigned long Core::Terminal::put(int x, int y, char c) {
// check on which device to put it
if(this->_type == TERMINAL_TYPE_VIDEO) {
// copy into the buffer
this->_buffer[(y * 80 + x)] = c | this->_color;
return E_SUCCESS;
}
return E_INVALID_TERMINAL;
}
unsigned long Core::Terminal::put(int x, int y, char c, short color) {
// check on which device to put it
if(this->_type == TERMINAL_TYPE_VIDEO) {
// copy into the buffer
this->_buffer[(y * 80 + x)] = c | color;
return E_SUCCESS;
}
return E_INVALID_TERMINAL;
}
unsigned long Core::Terminal::setColor(short color) {
if(this->_type == TERMINAL_TYPE_VIDEO) {
this->_color = color;
return E_SUCCESS;
}
return E_INVALID_TERMINAL;
}
unsigned long Core::Terminal::write(const char* sequence) {
if(this->_type == TERMINAL_TYPE_VIDEO) {
// loop through the sequence (halt when string gets too big or ends)
for(int n = 0; n < VIDEO_SIZE && sequence[n] != 0; n++) {
// and copy
this->put(sequence[n]);
}
return E_SUCCESS;
}
return E_FAILURE;
}
void Core::Terminal::put(char c) {
// Handle a backspace, by moving the cursor back one space
if(c == 0x08)
{
if(this->_x != 0) {
this->_x--;
this->_buffer[this->_y * 80 + this->_x] = ' ';
}
}
// a tab
else if(c == 0x09) {
this->_x = this->_x + 8;
}
// Handles a 'Carriage Return', which simply brings the cursor back to the margin
else if(c == '\r') {
this->_x = 0;
}
// new line
else if(c == '\n') {
this->_x = 0;
this->_y++;
}
// normal char
else if(c >= ' ') {
this->_buffer[this->_y * 80 + this->_x] = c | this->_color;
this->_x++;
}
// end of line detection
if(this->_x >= 80) {
this->_x = 0;
this->_y++;
}
// Scroll the screen if needed
this->scroll();
}
void Core::Terminal::scroll() {
// TODO: fixme
}
unsigned long Core::Terminal::startResource() {
return E_SUCCESS;
}
const char* Core::Terminal::getResourceName() {
/*! \todo Terminal name */
return "Terminal";
}