-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgr_con.c
More file actions
executable file
·447 lines (409 loc) · 7.65 KB
/
Copy pathgr_con.c
File metadata and controls
executable file
·447 lines (409 loc) · 7.65 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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* gr_con.c */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#ifdef GRX
#include <grdriver.h>
#include <grx20.h>
#include <grfontdv.h>
#endif
#ifndef WIN32
#include <signal.h>
#endif
#ifdef linux
#include <sys/ioctl.h>
#else /* linux */
#include <pc.h>
#include <dos.h>
#include <conio.h>
#endif /* linux */
#include "fk.h"
#ifdef linux
#define tk_put(s) fputs(s, stdout)
int _kbhit(void);
int _getch(void);
void kbd_init(void);
void kbd_restore(void);
void xw_clrb(int, int, int, int);
void xw_clrs(void);
void xw_flush(void);
void xw_init(void);
void xw_line(int, int, int, int, int);
void xw_close(void);
void xw_text(int, int, char *, int, int);
int xw_kbhit(void);
int xw_getch(void);
int xw_white(void);
int xw_pixel(int, int);
#endif /* linux */
extern int gr_mode;
extern int c0, c1, bx, by, bw, bh, cw, ch, xpix, ypix, ytop, ybot, ycmd;
extern int keyevent;
#ifdef linux
static int tek_cando_color = 0;
static int oldhiy = 0, oldloy = 0, oldhix = 0;
void
tk_draw(int x, int y, int do_gs, int c)
{
char buf[8], *bp;
char hiy, loy, hix, lox;
static int tkc = -1;
static int tek_color[] = {
'0', 'D', 'C', '5', 'B', '6', 'A', '8',
'9', '2', '3', '4', 'E', 'F', '7', '1',
};
if (c != tkc && tek_cando_color) {
buf[0] = '\033';
buf[1] = 'M';
buf[2] = 'L';
buf[3] = (c == c0) ? '0' : (c == c1) ? '1' : tek_color[c];
buf[4] = '\0';
tk_put(buf); /* set line color */
tkc = c;
}
hiy = ' ' + (y >> 5);
loy = '`' + (y & 31);
hix = ' ' + (x >> 5);
lox = '@' + (x & 31);
bp = buf;
if (do_gs == 0) {
*bp++ = '\035'; /* GS char. is used to enable graphics mode */
}
if (hiy != oldhiy)
*bp++ = hiy;
if (loy != oldloy || hiy != oldhiy || hix != oldhix)
*bp++ = loy;
if (hix != oldhix)
*bp++ = hix;
*bp++ = lox;
*bp = 0;
tk_put(buf);
oldhiy = hiy;
oldloy = loy;
oldhix = hix;
}
void
tk_clrb(int x1, int y1, int x2, int y2)
{
int y;
if (!tek_cando_color)
return;
if (y1 < y2) {
y = y1;
y1 = ypix - y2;
y2 = ypix - y;
} else {
y1 = ypix - y1;
y2 = ypix - y2;
}
x2--;
y2--;
for (y = y1; y <= y2; y++) {
tk_draw(x1, y, 0, c0);
tk_draw(x2, y, 1, c0);
if (y < y2) {
y++;
tk_draw(x2, y, 0, c0);
tk_draw(x1, y, 1, c0);
}
}
}
int
kbhit(void)
{
int c = 0;
if (gr_mode == 0) {
c = _kbhit();
} else if (gr_mode == 1) {
fflush(stdout);
ioctl(fileno(stdin), FIONREAD, &c);
} else if (gr_mode == 2) {
xw_flush();
c = xw_kbhit();
}
return (c);
}
int
getch(void)
{
int c = 0;
if (gr_mode == 0) {
c = _getch();
} else if (gr_mode == 1) {
fflush(stdout);
(void) read(fileno(stdin), &c, 1);
} else if (gr_mode == 2) {
c = xw_getch();
}
return (c);
}
#endif /* linux */
int
chk_event(void)
{
return (kbhit());
}
int
get_event(void)
{
int c = 0;
while (c == 0) {
if (kbhit()) {
c = getch();
if (c == 0 && gr_mode != 2) {
c = FN | getch();
} else if (c == 27 && kbhit()) {
c = getch();
if (c == ']') {
c = getch();
if (c == 'A') {
c = (FN | 72); /* Up Arrow */
} else if (c == 'B') {
c = (FN | 80); /* Down Arrow */
} else if (c == 'C') {
c = (FN | 77); /* Right Arrow */
} else if (c == 'D') {
c = (FN | 75); /* Left Arrow */
}
}
}
}
}
return (c);
}
void
flush_eventq(void)
{
while (chk_event())
get_event();
}
int
chk_escape(void)
{
if(chk_event())
{
if(get_event() == 27)
return 1;
}
return (0);
}
void
gr_cinit(void)
{
#ifndef WIN32
signal(SIGINT, SIG_IGN);
#endif
if (gr_mode == 0) {
#ifdef linux
kbd_init();
#endif /* linux */
#ifdef GRX
GrSetMode(GR_width_height_color_graphics, 640, 480, 16);
xpix = GrSizeX();
ypix = GrSizeY();
c0 = GrWhite();
c1 = GrBlack();
cw = 8;
ch = 14;
#else /* GRX */
fprintf(stderr, "No console graphics\n");
exit(1);
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 1) {
tk_put("\037"); /* switch to alpha mode */
c0 = 0;
c1 = 15;
xpix = 1024;
ypix = 768;
cw = 14;
ch = 24;
tek_cando_color = (strcmp(getenv("TERM"), "vt100") == 0);
} else if (gr_mode == 2) {
kbd_init();
xw_init();
#endif /* linux */
}
bx = 8 * cw;
by = ypix - 4 * ch;
bw = xpix - bx - 2 * cw;
bh = by - 4 * ch;
ytop = 3 * ch + ch / 2;
ybot = by + ch + ch / 2;
ycmd = ybot + ch;
}
void
gr_close(void)
{
if (gr_mode == 0) {
#ifdef GRX
GrSetMode(GR_default_text);
#endif /* GRX */
#ifdef linux
kbd_restore();
} else if (gr_mode == 1) {
tk_draw(0, 0, 0, c1); /* select forground color */
// tk_put("\033\f\0332\033\"0g");
tk_put("\033\f\0332\033\"0");
tk_put("\033[?38l"); /* put kermit in text mode */
fflush(stdout);
} else if (gr_mode == 2) {
xw_close();
kbd_restore();
#endif /* linux */
}
}
void
gr_clrb(int x1, int y1, int x2, int y2)
{
if (gr_mode == 0) {
#ifdef GRX
GrFilledBox(x1, y1, x2, y2, c0);
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 1) {
tk_clrb(x1, y1, x2, y2);
} else if (gr_mode == 2) {
xw_clrb(x1, y1, x2, y2);
#endif /* linux */
}
}
void
gr_text(int x, int y, char *s)
{
if (gr_mode == 0) {
#ifdef GRX
GrTextXY(x, y, s, c1, c0);
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 1) {
tk_draw(x, ypix - ch - y, 0, c0); /* move to (x,y) */
tk_put("\037"); /* switch to alpha mode */
tk_put(s);
} else if (gr_mode == 2) {
xw_text(x, y, s, c1, c0);
#endif /* linux */
}
}
int
gr_getpix(int x, int y)
{
if (gr_mode == 0) {
#ifdef GRX
return (GrPixel(x, y));
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 2) {
return (xw_pixel(x, y));
#endif /* linux */
}
return (0);
}
int
gr_white(void)
{
if (gr_mode == 0) {
#ifdef GRX
return (GrWhite());
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 2) {
return (xw_white());
#endif /* linux */
}
return (0);
}
void
gr_line(int x1, int y1, int x2, int y2, int c)
{
if (gr_mode == 0) {
#ifdef GRX
GrLine(x1, y1, x2, y2, c);
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 1) {
tk_draw(x1, ypix - y1, 0, c);
tk_draw(x2, ypix - y2, 1, c);
} else if (gr_mode == 2) {
xw_line(x1, y1, x2, y2, c);
#endif /* linux */
}
}
void
gr_clrs(void)
{
if (gr_mode == 0) {
#ifdef GRX
GrFilledBox(0, 0, xpix, ypix, c0);
#endif /* GRX */
#ifdef linux
} else if (gr_mode == 1) {
tk_put("\037"); /* switch to alpha mode */
tk_put("\033\f"); /* erase */
} else if (gr_mode == 2) {
xw_clrs();
#endif /* linux */
}
}
void
gr_beep(void)
{
#ifdef linux
tk_put("\007"); /* bell */
#else /* linux */
sound(1000);
sleep(1);
sound(0);
#endif /* linux */
}
void
gr_sleep(double s)
{
if (s < 1000)
usleep((int) (s * 1e6));
else
sleep((int) s);
}
void
gr_get_cwd(char *s, int n)
{
getcwd(s, n);
}
void
gr_set_cwd(char *s)
{
chdir(s);
}
int
gr_find(char *s, char *fn, int ix)
{
(void)ix;
(void)fn;
(void)s;
#ifdef MSDOS
int done;
static struct _find_t f;
if (ix == 0)
done = _dos_findfirst(s, _A_NORMAL, &f);
else
done = _dos_findnext(&f);
if (!done)
strcpy(fn, f.name);
return (!done);
#else /* MSDOS */
return (0);
#endif /* MSDOS */
}
int
gr_edit(char *fn)
{
(void)fn;
return (0);
}
void
gr_update(void)
{
}