-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.cpp
194 lines (151 loc) · 4.3 KB
/
console.cpp
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
#include "console.hpp"
void Console::SetCursorPosition(uint8_t x_pos , uint8_t y_pos)
{
*API_FUNCTION_ADDR = API_FN_CURSOR_POS ;
API_PARAMETERS_ADDR[0] = x_pos ;
API_PARAMETERS_ADDR[1] = y_pos ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
}
void Console::write (const unsigned char* buf, unsigned count) {
volatile unsigned char *cmd = (unsigned char *)0xFF00;
while (count--) {
while(*API_COMMAND_ADDR) {};
*API_FUNCTION_ADDR = API_FN_WRITE_CHAR;
API_PARAMETERS_ADDR[0] = *buf++;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
}
}
void Console::ClearScreen(){
// Clear Screen
*API_FUNCTION_ADDR = API_FN_CLEAR_SCREEN ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE;
while(*API_COMMAND_ADDR) {};
}
char Console::CheckKeyboardArray(){
// Check Console array
*API_FUNCTION_ADDR = API_FN_CHECK_STATUS ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
return(API_PARAMETERS_ADDR[0]);
}
// Get character from Console
char Console::inkey() {
while(*API_COMMAND_ADDR) {}
*API_FUNCTION_ADDR = API_FN_READ_CHAR ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ; // Group 2, Command 1
while(*API_COMMAND_ADDR) {}
return(API_PARAMETERS_ADDR[0]); // Return parameter
}
// Get character from Console
void Console::ReadLine(int line_read) {
API_PARAMETERS_ADDR[0] = line_read & 0xFF;
API_PARAMETERS_ADDR[1] = line_read >> 8;
while(*API_COMMAND_ADDR) {}
*API_FUNCTION_ADDR = API_FN_READ_LINE;
*API_COMMAND_ADDR = API_GROUP_CONSOLE;
while(*API_COMMAND_ADDR) {}
}
char Console::cgetc() {
char ch=0;
while(ch==0) {
ch=inkey();
}
return ch;
}
// Position cursor (API Group 2, Function 7)
void Console::gotoxy(uint8_t sx, uint8_t sy)
{
API_PARAMETERS_ADDR[0] = sx;
API_PARAMETERS_ADDR[1] = sy;
*API_FUNCTION_ADDR = API_FN_CURSOR_POS ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
}
// Put a character
void Console::cputc(char ch) {
while(*API_COMMAND_ADDR) {}
API_PARAMETERS_ADDR[0] = ch;
*API_FUNCTION_ADDR = API_FN_WRITE_CHAR_CURS ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
}
// Put a character at screen coord
void Console::cputcxy(int sx, int sy, char ch) {
gotoxy(sx,sy);
cputc(ch);
}
// Clear screen
void Console::clrscr() {
cputc(12);
gotoxy(0,0);
}
void Console::ClearKeyboardArray(){
// Clear Console array
while(CheckKeyboardArray()==0xff) {
cgetc();
}
}
uint8_t Console::KeyModifierStatus(uint8_t chr){
API_PARAMETERS_ADDR[0] = chr;
while(*API_COMMAND_ADDR) {}
*API_FUNCTION_ADDR = API_FN_KEY_STATUS;
*API_COMMAND_ADDR = API_GROUP_SYSTEM;
while(*API_COMMAND_ADDR) {}
return(API_PARAMETERS_ADDR[1]); // Return parameter
}
void Console::ReadString(char * str){
uint8_t i, key;
i=0;
while (1) {
key=cgetc();
if (key == 13) {
break; // Esce dal ciclo se viene premuto INVIO
} else if (key == 8 || key == 26) {
if (i>0) {
i--;
cputc(key);
}
} else {
// Aggiunge il carattere alla stringa di testo
i++;
cputc(key);
str[i] = key;
}
}
str[i+1]='\0'; //delimiter of string. Needed for API graphics
str[0]=i;
}
int Console::ReadNumber(char * str, int len){
uint8_t i, key;
int value, dec;
i=0;
value=0;
while (1) {
key=cgetc();
if (key == 13 || i > len) {
break; // Esce dal ciclo se viene premuto INVIO
} else if (key == 8 || key == 26) {
if (i>0) {
i--;
cputc(key);
}
} else if ((key>=48) && (key <= 57)){
// Aggiunge il carattere alla stringa di testo
i++;
cputc(key);
str[i] = key;
}
}
str[0]=i;
value = atoi(&str[1]);
return value;
}
key_with_Modifier Console::get_char_modifier(){
key_mod.chr = inkey();
key_mod.modifier =KeyModifierStatus(key_mod.chr);
return key_mod;
}
void Console::SetColorText(uint8_t colorText, uint8_t colorBackground){
API_PARAMETERS_ADDR[0] = colorText;
API_PARAMETERS_ADDR[1] = colorBackground;
*API_FUNCTION_ADDR = API_FN_SET_COLOR_TEXT ;
*API_COMMAND_ADDR = API_GROUP_CONSOLE ;
while(*API_COMMAND_ADDR) {}
}