-
Notifications
You must be signed in to change notification settings - Fork 0
/
dConsole.c
246 lines (211 loc) · 4.02 KB
/
dConsole.c
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <fxlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "dconsole.h"
#define LINE_ROW_MAX 8
#define LINE_COL_MAX 21
typedef unsigned int uint;
typedef unsigned char uchar;
char line_buf[LINE_ROW_MAX][LINE_COL_MAX+1];
int line_index = 0;
int line_x = 0;
int line_start = 0;
int line_count = 0;
void dAreaClear (int left,int top,int right,int bottom,int sel)
{
DISPBOX box;
box.left = left;box.top = top;box.right = right;box.bottom = bottom;
if (sel != 1)
Bdisp_AreaClr_VRAM (&box);
if (sel != 0){
Bdisp_DrawLineVRAM (box.left,box.top,box.right,box.top);
Bdisp_DrawLineVRAM (box.left,box.bottom,box.right,box.bottom);
Bdisp_DrawLineVRAM (box.left,box.top,box.left,box.bottom);
Bdisp_DrawLineVRAM (box.right,box.top,box.right,box.bottom);
}
}
uint WaitKey ()
{
uint key;GetKey(&key);return key;
}
char dGetKeyChar (uint key)
{
if (key>=KEY_CHAR_A && key<=KEY_CHAR_Z)
return key;
else if (key>=KEY_CHAR_0 && key<= KEY_CHAR_9)
return key;
return 0;
}
int dGetLineBox (char * s,int max,int width,int x,int y)
{
int pos = strlen(s);
int refresh = 1;
uint key;
char c;
while(1)
{
if (refresh)
{
dAreaClear(x,y,x+width*6+2,y+10,2);
if (pos<width-1)
{
PrintXY (x+1,y+2,(uchar*)s,0);
PrintXY (x+1+pos*6,y+2,(uchar*)"_",0);
}
else
{
PrintXY (x+1,y+2,(uchar*)(s+pos-width+1),0);
PrintXY (x+1+(width-1)*6,y+2,(uchar*)"_",0);
}
refresh = 0;
}
GetKey(&key);
if ((c=dGetKeyChar(key))!=0)
{
if (pos>=max) continue;
s[pos++] = c;s[pos] = '\0';
refresh = 1;
}
else
{
if (key==KEY_CTRL_DEL)
{
if (pos<=0) continue;
s[--pos] = '\0';
refresh = 1;
}
else if (key==KEY_CTRL_AC)
{
*s = 0;
pos = 0;
refresh = 1;
}
else if (key==KEY_CTRL_EXE) return 1;
else if (key==KEY_CTRL_EXIT) return 0;
}
}
}
int dGetLine (int max,char * s) // This function is depended on dConsole
// And this function is not allowed to abolish
{
int pos = strlen(s);
int refresh = 1;
int x,y,l,width;
uint key;
char c;
l = strlen (line_buf[line_index]);
if (l>=LINE_COL_MAX)
{
dConsolePut("\n");
l = 0;
}
else
dConsoleRedraw();
x = l + 1;
y = line_count;
width = LINE_COL_MAX - l;
while (1)
{
if (refresh)
{
int i;
for (i=x;i<=LINE_COL_MAX;++i)
{
locate(i,y);Print((uchar*)" ");
}
if (pos<width-1)
{
locate(x,y); Print((uchar*)s);
locate(x+pos,y); Print((uchar*)"_");
}
else
{
locate(x,y); Print((uchar*)s+pos-width+1);
locate(x+width-1,y); Print((uchar*)"_");
}
refresh = 0;
}
GetKey(&key);
if ((c=dGetKeyChar(key))!=0)
{
if (pos>=max) continue;
s[pos++] = c;s[pos] = '\0';
refresh = 1;
}
else
{
if (key==KEY_CTRL_DEL)
{
if (pos<=0) continue;
s[--pos] = '\0';
refresh = 1;
}
else if (key==KEY_CTRL_AC)
{
*s = 0;
pos = 0;
refresh = 1;
}
else if (key==KEY_CTRL_EXE) return 1;
}
}
return 0;
}
void dConsoleRedraw ()
{
int i,j;
Bdisp_AllClr_VRAM();
for(i=0,j=line_start;i<line_count;++i)
{
locate(1,i+1);Print((uchar*)line_buf[j]);
if (++j>=LINE_ROW_MAX) j = 0;
}
}
void dConsolePuts (const char * str)
{
dConsolePut(str);
dConsolePut("\n");
}
void dConsolePut(const char * str)
{
if (line_count == 0) line_count = 1;
for (;*str;++str)
{
if (*str != '\n')
line_buf[line_index][line_x++] = *str;
else
{
line_buf[line_index][line_x] = '\0';
line_x = LINE_COL_MAX;
}
if (line_x>=LINE_COL_MAX)
{
line_buf[line_index][line_x] = '\0';
line_x = 0;
if (line_count<LINE_ROW_MAX)
{
++line_count;
}
else
{
line_start++;
if (line_start>=LINE_ROW_MAX) line_start = 0;
}
line_index++;
if (line_index>=LINE_ROW_MAX) line_index = 0;
}
}
line_buf[line_index][line_x] = '\0';
dConsoleRedraw();
}
int dPrintf (const char * format,...)
{
char buf[256];
int length;
va_list arg_list;
va_start(arg_list,format);
length = vsprintf(buf,format,arg_list);
va_end(arg_list);
dConsolePut (buf);
return length;
}