-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.c
129 lines (111 loc) · 2.28 KB
/
graphics.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
/* Graficke funkcie pre vdt52s */
/* */
#include "parita.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "vt52vnc.h"
#define ESC 0x1b
#define PAR(x) ((x) | (128-parity_table[(x) & 0x7f]))
#define HIGH_Y(n) (PAR(0x20|(n)))
#define LOW_Y(n) (PAR(0x60|(n)))
#define HIGH_X(n) (PAR(0x20|(n)))
#define LOW_X(n) (PAR(0x40|(n)))
unsigned long bytes_sent = 0;
void gflush( t_kanal *k )
{
write(1,k->outbuf,k->pos);
bytes_sent+=k->pos;
k->pos=0;
}
void gputc( t_kanal *k, char c )
{
k->outbuf[(k->pos)++]=c;
if( k->pos >=BUFLEN )
gflush(k);
}
#define gputcesc(k,c) {gputc((k),ESC);gputc((k),(c));}
void greset( t_kanal *k )
{
gputcesc(k,'0');
}
void gcls( t_kanal *k )
{
gputc(k,13);
gputc(k,10);
gputcesc(k,'E');
}
void gset_scaling( t_kanal *k, int xfactor, int yfactor )
{
gputc(k,0x1d);
gputc(k,ESC);
gputc(k,'s');
gputc(k,PAR(0x40|xfactor));
gputc(k,PAR(0x40|yfactor));
}
void gset_attrib( t_kanal *k, int attrib )
{
if( attrib&GA_OR )
gputcesc(k,0x12)
else if( attrib&GA_XOR )
gputcesc(k,0x13)
if( attrib&GA_DEL )
gputcesc(k,0x11)
if( attrib&GA_PATTERN )
gputcesc(k,0x14)
}
void gsetpos( t_kanal *k, int x, int y )
{
gputc(k,0x1d);
gputc(k,HIGH_Y((y>>5)));
gputc(k,LOW_Y((y&0x1f)));
gputc(k,HIGH_X((x>>5)));
gputc(k,LOW_X((x&0x1f)));
}
void gline( t_kanal *k ,int x1,int y1, int x2, int y2 )
{
gputc(k,0x1d);
gputc(k,HIGH_Y((y1>>5)));
gputc(k,LOW_Y((y1&0x1f)));
gputc(k,HIGH_X((x1>>5)));
gputc(k,LOW_X((x1&0x1f)));
gputc(k,HIGH_Y((y2>>5)));
gputc(k,LOW_Y((y2&0x1f)));
gputc(k,HIGH_X((x2>>5)));
gputc(k,LOW_X((x2&0x1f)));
}
void gdrawto( t_kanal *k ,int x,int y )
{
gputc(k,0x1d);
gputc(k,7);
gputc(k,HIGH_Y((y>>5)));
gputc(k,LOW_Y((y&0x1f)));
gputc(k,HIGH_X((x>>5)));
gputc(k,LOW_X((x&0x1f)));
}
void gplot( t_kanal *k ,int x,int y )
{
gputc(k,0x1d);
gputc(k,HIGH_Y((y>>5)));
gputc(k,LOW_Y((y&0x1f)));
gputc(k,HIGH_X((x>>5)));
gputc(k,LOW_X((x&0x1f)));
gputc(k,LOW_X((x&0x1f)));
}
void gpline( t_kanal *k , t_pos *pos, int num )
{ int i;
gputc(k,0x1d);
for(i=0;i<num;i++)
{ gputc(k,HIGH_Y(((pos[i].y)>>5)));
gputc(k,LOW_Y(((pos[i].y)&0x1f)));
gputc(k,HIGH_X(((pos[i].x)>>5)));
gputc(k,LOW_X(((pos[i].x)&0x1f)));
}
}
unsigned long get_stat(void)
{
unsigned long tmp = bytes_sent;
bytes_sent = 0;
return tmp;
}