-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgplot.c
108 lines (97 loc) · 1.95 KB
/
fgplot.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
/* Tek fast-graphics (405x) to plot converter - Bsy, 4/29/87 */
/* no plot library */
#define ALWAYS 0
#define TEK4014 0
#define outArr(arr) do { fwrite(arr, 1, sizeof arr, stdout); } while(0)
void erase(void) {
static unsigned char eraseTek[] = {
033, 014,
};
outArr(eraseTek);
}
void openpl(void) {
static unsigned char toTek[] = {
033, '[', '?', '3', '8', 'h', 037,
};
outArr(toTek);
erase();
}
void closepl(void) {
static unsigned char toVT[] = {
033, 3,
};
fflush(stdout);
/*
* xterm Tek emulator drops final graphics ops if we switched to VT100
* immediately
*/
usleep(1000);
outArr(toVT);
}
int hi_x = 0, lo_x = 0, hi_y = 0, lo_y = 0;
#if TEK4014
int lsb = 0;
#endif
void cont(int x, int y) {
int hx, lx, hy, ly;
#if TEK4014
int nlsb;
/* assume 4096 resolution, so 12 bits */
hx = ((x >> 7) & 0x1f) + 0x20;
lx = ((x >> 2) & 0x1f) + 0x40;
hy = ((y >> 7) & 0x1f) + 0x20;
ly = ((y >> 2) & 0x1f) + 0x60;
nlsb = (((y & 0x3) << 2) | (x & 0x3)) + 0x60;
#else
/* assume 1024 resolution, so 10 bits */
hx = ((x >> 5) & 0x1f) + 0x20;
lx = (x & 0x1f) + 0x40;
hy = ((y >> 5) & 0x1f) + 0x20;
ly = (y & 0x1f) + 0x60;
#endif
if (hy != hi_y || ALWAYS)
putchar(hy);
#if TEK4014
if (nlsb != lsb || ALWAYS)
putchar(nlsb);
#endif
if (ly != lo_y || hx != hi_x ||
#if TEK4014
nlsb != lsb ||
#endif
ALWAYS)
putchar(ly);
if (hx != hi_x || ALWAYS)
putchar(hx);
putchar(lx);
hi_x = hx;
lo_x = lx;
hi_y = hy;
lo_y = ly;
#if TEK4014
lsb = nlsb;
#endif
}
void move(int x, int y) {
putchar(035);
cont(x,y);
}
int main(void) {
char code[3];
int m,x,y;
openpl();
erase();
while (fread(code,1,3,stdin) == 3) {
m = code[0] & 0100;
x = ((code[0] & 070) << 4) | code[1];
y = ((code[0] & 007) << 7) | code[2];
if (m) {
move(x,y);
} else cont(x,y);
}
closepl();
exit(0);
}