0
|
1 #include "config.h"
|
|
2 #ifdef DRIVE_UNIX
|
|
3 #ifdef DRIVE_TTY
|
|
4
|
|
5 #include <stdio.h>
|
|
6 #include <stdlib.h>
|
|
7 #include <unistd.h>
|
|
8 #include <fcntl.h>
|
|
9 #include <termios.h>
|
|
10
|
|
11 #include "pwplib.h"
|
57
|
12 #include "convert.h"
|
0
|
13 #include "tty.h"
|
|
14
|
|
15 #ifdef howmany
|
|
16 # undef howmany
|
|
17 #endif
|
|
18
|
|
19 #define DECIMAL(x) \
|
|
20 {int n=(x); if(n>=100){*d++='0'+(n/100);n%=100; \
|
|
21 *d++='0'+(n/10);} \
|
|
22 else \
|
|
23 if(n>=10)*d++='0'+(n/10); \
|
|
24 *d++='0'+(n%10);}
|
|
25
|
|
26 int tty_ansicol_dump(u8*s,u8*p,int x,int y)
|
|
27 {
|
|
28 TEMPMALL(u8,tmp,x*y*16),
|
|
29 *d=tmp,skip=0,skipy=0,att=0;
|
|
30
|
|
31 skipy=1;
|
|
32
|
|
33 memcpy(d,"\33[0;37;40m",10*sizeof(char));d+=10;
|
|
34 att=0x07;
|
|
35
|
|
36 if(pwplib.frame&1)
|
|
37 {
|
|
38 s+=pwplib.videobuf.width*2;
|
|
39 p+=pwplib.videobuf.width*2;
|
|
40 }
|
|
41
|
|
42 {int i=pwplib.frame&1;for(;i<y;i+=2)
|
|
43 {int j=0;
|
|
44
|
|
45 for(;j<x;j++)
|
|
46 {
|
|
47 if( (s[0]!=p[0]) || (s[1]!=p[1]) )
|
|
48 {
|
|
49 int attch=s[1]^att;
|
|
50 if(attch)
|
|
51 {
|
|
52 int a=s[1],semic=0;
|
|
53 d[0]=27;d[1]='[';d+=2;
|
|
54 if(attch&0x07)
|
|
55 {
|
|
56 d[0]='3';d[1]="04261537"[a&7];d+=2;semic=1;
|
|
57 }
|
|
58 if(attch&0x70)
|
|
59 {
|
|
60 if(semic)*d++=';';
|
|
61 d[0]='4';d[1]="04261537"[(a>>4)&7];d+=2;semic=1;
|
|
62 }
|
|
63 if(attch&0x80)
|
|
64 {
|
|
65 if(semic)*d++=';';
|
|
66 if(!(a&0x80))*d++='2';
|
|
67 *d++='5';semic=1;
|
|
68 }
|
|
69 if(attch&0x08)
|
|
70 {
|
|
71 if(semic)*d++=';';
|
|
72 if(!(a&0x08))*d++='2';
|
|
73 *d++='1';
|
|
74 }
|
|
75 *d++='m';
|
|
76 att=s[1];
|
|
77 }
|
|
78
|
|
79 if(skip||skipy)
|
|
80 {
|
|
81 if(!skipy)
|
|
82 {
|
|
83 int realskip=1;
|
|
84 if(skip<4)
|
|
85 {
|
|
86 int i=0;
|
|
87 realskip=0;
|
|
88 for(;i<skip;i++)
|
|
89 if(s[-2*skip+2*i+1]!=att)
|
|
90 {realskip++;break;}
|
|
91 }
|
|
92 if(realskip)
|
|
93 {
|
|
94 d[0]=27;d[1]='[';d+=2;
|
|
95 if(skip>1)DECIMAL(skip);
|
|
96 *d++='C';
|
|
97 }
|
|
98 else
|
|
99 {
|
|
100 int i=0;
|
|
101 for(;i<skip;i++)
|
|
102 *d++=s[-2*skip+2*i];
|
|
103 }
|
|
104 }
|
|
105
|
|
106 else
|
|
107 {
|
|
108 d[0]=27;d[1]='[';d+=2;
|
|
109 DECIMAL(i+1);
|
|
110 *d++=';';
|
|
111 DECIMAL(j+1);
|
|
112 *d++='H';
|
|
113 }
|
|
114 skip=skipy=0;
|
|
115 }
|
|
116
|
|
117 *d++=s[0];
|
|
118 }else skip++;
|
|
119 s+=2;p+=2;
|
|
120 }skipy++;
|
|
121
|
|
122 memcpy(p-pwplib.videobuf.width*2,
|
|
123 s-pwplib.videobuf.width*2,
|
|
124 pwplib.videobuf.width*2*sizeof(u8));
|
|
125
|
|
126 s+=pwplib.videobuf.width*2;
|
|
127 p+=pwplib.videobuf.width*2;
|
|
128 }
|
|
129 }
|
|
130
|
57
|
131 tty_write(tmp, d - tmp);
|
0
|
132
|
|
133 TEMPFREE(tmp);
|
|
134 return d-tmp;
|
|
135 }
|
|
136
|
|
137 /****************/
|
|
138
|
|
139 /* ..do a generic tty_dump_attr that calls pwp_tty.indump or something */
|
55
|
140 void tty_ansicol_dump_attr(void)
|
0
|
141 {
|
|
142 int lgt=
|
|
143 tty_ansicol_dump
|
|
144 (pwplib.videobuf.d,pwp_tty.prevbuf,
|
|
145 pwplib.videobuf.width,
|
|
146 pwplib.videobuf.height);
|
|
147
|
|
148 pwplib.frame++;
|
|
149
|
|
150 if(lgt<pwplib.set.framebytes)
|
|
151 {
|
|
152 lgt+=tty_ansicol_dump
|
|
153 (pwplib.videobuf.d,pwp_tty.prevbuf,
|
|
154 pwplib.videobuf.width,
|
|
155 pwplib.videobuf.height);
|
|
156 pwplib.frame++;
|
|
157 }
|
|
158
|
|
159 if(lgt<pwplib.set.framebytes)
|
|
160 if(pwplib.setup[SETUP_BPS])
|
|
161 {
|
|
162 int howmany=pwplib.setup[SETUP_BPS]/(72*2*3);
|
|
163 for(;howmany;howmany--)
|
|
164 {
|
|
165 tty_write("\33[H",3);
|
|
166 }
|
|
167 }
|
|
168
|
|
169 if(pwplib.set.framedelay)
|
|
170 usleep(pwplib.set.framedelay*1000);
|
|
171 }
|
|
172
|
55
|
173 void tty_ansicol_prep_attr(void)
|
0
|
174 {
|
|
175 tty_write("\33[37;40m[2J\33[H",-1);
|
|
176 }
|
|
177
|
55
|
178 void tty_ansicol_init(void)
|
0
|
179 {
|
|
180 pwplib.prep_attr=tty_ansicol_prep_attr;
|
|
181 pwplib.dump_attr=tty_ansicol_dump_attr;
|
|
182
|
|
183 conv_init(2,3,1);
|
|
184
|
|
185 tty_vt_initstring();
|
|
186 }
|
|
187
|
55
|
188 void tty_ansisys_init(void)
|
0
|
189 {
|
|
190 pwplib.prep_attr=tty_ansicol_prep_attr;
|
|
191 pwplib.dump_attr=tty_ansicol_dump_attr;
|
|
192
|
|
193 conv_init(2,0,0);
|
|
194
|
|
195 tty_vt_initstring();
|
|
196 }
|
|
197
|
|
198 #endif
|
|
199 #endif
|