Mercurial > hg > forks > pwpunix
annotate pwplib/decterm.c @ 61:0f616ade936a
Change char -> unsigned char pointer to fix a warning.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 09 Jul 2011 11:51:19 +0300 |
parents | 5d819ba6891c |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * PWPlib: VTxxx support, including VT220/320 charset customization | |
3 * | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 | |
9 #include "pwplib.h" | |
10 | |
11 #ifdef DRIVE_UNIX | |
12 #ifdef DRIVE_TTY_DEC | |
13 | |
14 #include "tty.h" | |
15 #include "convert.h" | |
16 | |
17 #define DECIMAL(x) \ | |
18 {int n=(x); if(n>=100){*d++='0'+(n/100);n%=100; \ | |
19 *d++='0'+(n/10);} \ | |
20 else \ | |
21 if(n>=10)*d++='0'+(n/10); \ | |
22 *d++='0'+(n%10);} | |
23 | |
24 /******************** vt2xx raster glyphs *************************/ | |
25 | |
26 /* move somewhere else */ | |
27 void tty_putch(int ch) | |
28 { | |
29 char c=ch; | |
30 write(pwp_tty.fd,&c,sizeof(char)); | |
31 } | |
32 | |
33 #ifdef DRIVE_TTY_VT2XX | |
34 void vt2xx_loadglyphs(char*src,int width,int height,int howmany) | |
35 { | |
36 if(pwp_tty.minor<300) | |
37 tty_write("\33P0;1;2{P",-1); | |
38 else | |
39 tty_write("\33P0;1;2;0;0;2{P",-1); | |
40 | |
41 for(;howmany;howmany--) | |
42 { | |
43 int x,y,i; | |
44 for(y=0;y<height;y+=6) | |
45 { | |
46 if(y)tty_putch('/'); | |
47 for(x=0;x<width;x++) | |
48 { | |
49 int sixel=0; | |
50 for(i=0;i<6;i++) | |
51 if(src[(i+y)*width+x])sixel|=(1<<i); | |
52 tty_putch('?'+sixel); | |
53 } | |
54 } | |
55 tty_putch(';'); | |
56 src+=width*height; | |
57 } | |
58 tty_write("\33\\",-1); | |
59 } | |
60 | |
61 /* | |
62 int vt2xx_genchars(char*o,int width,int height) | |
63 { | |
64 int u,d,x,y; | |
65 | |
66 for(u=0;u<8;u++) | |
67 for(d=0;d<8;d++) | |
68 { | |
69 if(u|d) | |
70 for(y=0;y<height;y++) | |
71 for(x=0;x<width;x++) | |
72 *o++= | |
73 rastmatrix[16*(y<=(height>>1)?u:d)+4*(y&3)+(x&3)]; | |
74 } | |
75 } | |
76 */ | |
77 #endif | |
78 | |
79 void tty_vt_prep_attr_40() | |
80 { | |
81 int y=0; | |
82 tty_write("\33[2J\33[H",-1); | |
83 for(;y<24;y++) | |
84 { | |
85 if(y)tty_putch('\n'); | |
86 tty_write("\33#6",3); | |
87 } | |
88 } | |
89 | |
90 #ifdef DRIVE_TTY_VT2XX | |
91 /* | |
92 int vt2xx_convcalc() | |
93 { | |
94 const char intens[16]= | |
95 { | |
96 0,1,6,7, 3,4,9,10, | |
97 1,2,9,10,5,6,13,15 | |
98 }; | |
99 | |
100 int up,dn; | |
101 for(dn=0;dn<256;dn++) | |
102 for(up=0;up<256;up++) | |
103 { | |
104 int dins=(intens[dn&15]+intens[(dn>>4)&15]*3); | |
105 int uins=(intens[up&15]+intens[(up>>4)&15]*3); | |
106 | |
107 if(dins<7 && uins<7 && (dins|uins)) | |
108 { | |
109 if(uins>dins)uins=7;else dins=7; | |
110 } | |
111 | |
112 dins/=7; | |
113 uins/=7; | |
114 | |
115 if(dins>7)dins=7; | |
116 if(uins>7)uins=7; | |
117 | |
118 pwpconv.rasthalve[BYTES2(up,dn)]= | |
119 BYTES2(32+(dins|(uins<<3)),0x10); | |
120 } | |
121 } | |
122 */ | |
123 #endif | |
124 | |
125 /**********************************************/ | |
126 | |
127 /* | |
128 &1: inverse | |
129 &8: bright | |
130 &16: charset: P vs B | |
131 */ | |
132 | |
61
0f616ade936a
Change char -> unsigned char pointer to fix a warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
133 int tty_vt_dump(u8 *s,unsigned char*p,int x,int y) |
0 | 134 { |
135 TEMPMALL(u8,tmp,pwplib.videobuf.width*pwplib.videobuf.height*16), | |
136 *d=tmp,skip=0,skipy=0; | |
137 | |
138 skipy=1; | |
139 | |
140 if(pwplib.frame&1) | |
141 { | |
142 p+=pwplib.videobuf.width*2; | |
143 s+=pwplib.videobuf.width*2; | |
144 } | |
145 | |
146 {int i=pwplib.frame&1; | |
147 for(;i<y;i+=2) | |
148 {int j=0; | |
149 | |
150 for(;j<x;j++) | |
151 { | |
152 if( (s[0]!=p[0]) || (s[1]!=p[1]) ) | |
153 { | |
154 int attch=s[1]^pwp_tty.att; | |
155 if(attch) | |
156 { | |
157 int a=s[1]; | |
158 d[0]=27;d[1]='[';d+=2; | |
159 if(attch&0x0f) | |
160 { | |
161 d[0]=27; | |
162 d[1]='['; | |
163 d+=2; | |
164 | |
165 if(!(a&0xf))*d++='0'; | |
166 else | |
167 { | |
168 int semic=0; | |
169 d+=2; | |
170 if(attch&8) | |
171 { | |
172 if(a&8)*d++='2'; | |
173 *d++='1'; | |
174 semic++; | |
175 } | |
176 if(attch&1) | |
177 { | |
178 if(semic)*d++=';'; | |
179 if(a&1)*d++='2'; | |
180 *d++='7'; | |
181 semic++; | |
182 } | |
183 } | |
184 *d++='m'; | |
185 } | |
186 if(attch&0xf0) | |
187 { | |
188 d[0]=27; | |
189 d[1]='('; | |
190 d[2]=(a&0x10)?'P':'B'; | |
191 d+=3; | |
192 } | |
193 pwp_tty.att=a; | |
194 } | |
195 | |
196 if(skip||skipy) | |
197 { | |
198 if(!skipy) | |
199 { | |
200 int realskip=1; | |
201 if(skip<4) | |
202 { | |
203 int i=0; | |
204 realskip=0; | |
205 for(;i<skip;i++) | |
206 if(s[-2*skip+2*i+1]!=pwp_tty.att) | |
207 {realskip++;break;} | |
208 } | |
209 if(realskip) | |
210 { | |
211 d[0]=27;d[1]='[';d+=2; | |
212 if(skip>1)DECIMAL(skip); | |
213 *d++='C'; | |
214 } | |
215 else | |
216 { | |
217 int i=0; | |
218 for(;i<skip;i++) | |
219 *d++=s[-2*skip+2*i]; | |
220 } | |
221 } | |
222 | |
223 else | |
224 { | |
225 d[0]=27;d[1]='[';d+=2; | |
226 DECIMAL(i+1); | |
227 *d++=';'; | |
228 DECIMAL(j+1); | |
229 *d++='H'; | |
230 } | |
231 skip=skipy=0; | |
232 } | |
233 | |
234 *d++=s[0]; | |
235 }else skip++; | |
236 s+=2;p+=2; | |
237 }skipy++; | |
238 | |
239 memcpy(p-pwplib.videobuf.width*2, | |
240 s-pwplib.videobuf.width*2, | |
241 pwplib.videobuf.width*2*sizeof(u8)); | |
242 | |
243 p+=pwplib.videobuf.width*2; | |
244 s+=pwplib.videobuf.width*2; | |
245 } | |
246 } | |
247 | |
248 /* ^^^ joo: pistä tuo luuppi omaan mökeltimeensä. yhdistä vt- ja | |
249 ansi-kamikset. */ | |
250 | |
251 memcpy(d,"\33[0m",4*sizeof(char)); /* nuo framen alkuun */ | |
252 pwp_tty.att=0;d+=4; | |
253 | |
56 | 254 tty_write((char *)tmp, d - tmp); |
0 | 255 TEMPFREE(tmp); |
256 return d-tmp; | |
257 } | |
258 | |
259 /* combine this with corresponding ansicon stuff */ | |
260 void tty_vt_dump_attr() | |
261 { | |
262 int lgt= | |
263 tty_vt_dump | |
264 (pwplib.videobuf.d,pwp_tty.prevbuf, | |
265 pwplib.videobuf.width, | |
266 pwplib.videobuf.height); | |
267 | |
268 pwplib.frame++; | |
269 | |
270 if(lgt<pwplib.set.framebytes) | |
271 { | |
272 lgt+=tty_vt_dump | |
273 (pwplib.videobuf.d,pwp_tty.prevbuf, | |
274 pwplib.videobuf.width, | |
275 pwplib.videobuf.height); | |
276 pwplib.frame++; | |
277 } | |
278 | |
279 if(lgt<pwplib.set.framebytes) | |
280 if(pwplib.setup[SETUP_BPS]) | |
281 { | |
282 int howmany=pwplib.setup[SETUP_BPS]/(72*2*3); | |
283 for(;howmany;howmany--) | |
284 { | |
285 tty_write("\33[H",3); | |
286 } | |
287 } | |
288 | |
289 if(pwplib.set.framedelay) | |
290 usleep(pwplib.set.framedelay*1000); | |
291 } | |
292 | |
293 /*** generic initstrings for vt100+/compatibles ****/ | |
294 | |
295 void tty_vt_restore() | |
296 { | |
297 if(pwp_tty.type==TTY_VT2XX)tty_write("\33(B",3); /* restore charset */ | |
298 tty_write( | |
299 "\33[0m" /* attributes off */ | |
300 "\33[?25h", /* cursor on */ | |
301 -1); | |
302 } | |
303 | |
304 void tty_vt_initstring() | |
305 { | |
17
c60e531d19cd
Some misc. cleanups and minor warning removals.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
306 pwplib_regdestr(tty_vt_restore); |
0 | 307 |
308 tty_write( | |
309 "\33[0;37;40m" /* attributes off, assert colors */ | |
310 "\33[?3l" /* 80-column mode */ | |
311 "\33[?5l" /* bright on dark */ | |
312 "\33[?25l" /* cursor off */ | |
313 "\33[2J" /* clear screen */ | |
314 "\33[H", /* home cursor */ | |
315 -1); | |
316 } | |
317 | |
318 /***************************************************/ | |
319 | |
320 void tty_vt1xx_init() | |
321 { | |
322 pwplib.dump_attr=tty_vt_dump_attr; | |
323 /* pwplib.prep_attr=tty_vt_prep_attr;*/ | |
324 | |
325 conv_init(9,3,2); | |
326 | |
327 tty_vt_initstring(); | |
328 } | |
329 | |
330 #ifdef DRIVE_TTY_VT2XX | |
331 void tty_vt2xx_init() | |
332 { | |
333 pwplib.dump_attr=tty_vt_dump_attr; | |
334 pwplib.prep_attr=tty_vt_prep_attr_40; | |
335 pwplib.videobuf.width>>=1; | |
336 | |
337 {int fw=8,fh=10; | |
338 switch((int)pwp_tty.minor) | |
339 { | |
340 case(420):fw=10;fh=16;break; /* 36 lines: fh=10, 48 lines: fh=8 */ | |
341 case(330):fw=10;fh=20;break; | |
342 case(320):fw=15;fh=12;break; | |
343 } | |
344 | |
345 conv_init(9,3,2); | |
346 | |
347 pwpwrite("* loading custom font\n"); | |
348 | |
349 { | |
350 TEMPMALL(char,tmp,fw*fh*64); | |
351 glyphgen_64rast(tmp,fw,fh); | |
352 vt2xx_loadglyphs(tmp,fw,fh,64); | |
353 TEMPFREE(tmp); | |
354 }} | |
355 | |
356 pwp_tty.maxframedata=500; | |
357 | |
358 tty_vt_initstring(); | |
359 } | |
360 #endif | |
361 | |
55 | 362 #endif /* DRIVE_TTY_DEC */ |
363 #endif /* DRIVE_UNIX */ |