1 --- tmview-01.03.orig/fb/writefb.c
2 +++ tmview-01.03/fb/writefb.c
5 /* framebuffer globals */
6 static uchar *thefb=NULL;
7 +static struct fb_var_screeninfo thefbvarinfo;
9 +static int thefbdepth;
12 -static int thefbbyteswidth;
13 +static int thefbstride;
14 static int thefbfd=-1;
15 static struct fb_cmap origpalette={0,0,NULL,NULL,NULL,NULL};
16 static unsigned short origreds[256];
17 static unsigned short origgreens[256];
18 static unsigned short origblues[256];
19 static unsigned short origtrans[256];
20 +static unsigned int newpalette[256];
22 /* terminal related stuff */
23 static struct termios origtermattr;
28 - if(origpalette.len!=0) {
29 + if(thefbdepth==1 && origpalette.len!=0) {
31 ioctl(thefbfd,FBIOPUTCMAP, &origpalette);
34 static volatile int pendingswitch=0;
36 void setpalette(void); /* foreward */
37 +void updateline(uchar *, uchar *, int);
39 static void vtrelease(int n){ /* switch away */
44 static void vtaquire(int n) { /* come back */
50 ioctl(thevtfd, VT_RELDISP, VT_ACKACQ);
51 if(offscreen!=NULL && thefb!=NULL) {
52 - memcpy(thefb,offscreen,thefblen);
62 + updateline(dst,src,vgaxdim);
65 pendingswitch=0; /* discard a pending request ... */
66 donotupdate=0; /* drawwings welcome again */
70 +void updateline(uchar *dst, uchar *src, int len) {
71 + switch(thefbdepth) {
73 + memcpy(dst,src,len);
77 + uint16_t*target=(uint16_t*)dst;
79 + *target++=newpalette[*src++];
84 + uint32_t*target=(uint32_t*)dst;
86 + *target++=newpalette[*src++];
92 void myupdate(int x1, int y1, int x2, int y2) {
99 - src=offscreen+thefbbyteswidth*y1+x1,
100 - dst=thefb+thefbbyteswidth*y1+x1;
101 + src=offscreen+vgaxdim*y1+x1,
102 + dst=thefb+thefbstride*y1+thefbdepth*x1;
105 - src+=thefbbyteswidth,
106 - dst+=thefbbyteswidth)
110 + updateline(dst,src,w);
112 updateinprogress=0; /* all drawings done so far */
113 if(pendingswitch){ /* aha: console switch requested while we were busy */
118 - if(0!=ioctl(thefbfd,FBIOPUTCMAP, &fbc))
119 - vgaerror("\nerror: writefb: setpalette\n");
120 + switch(thefbdepth) {
122 + if(0!=ioctl(thefbfd,FBIOPUTCMAP, &fbc)) {
123 + /*vgaerror("\nerror: writefb: setpalette\n")*/;
127 + newpalette[num] = (((int)r>>(16-thefbvarinfo.red.length))<<thefbvarinfo.red.offset)
128 + | (((int)g>>(16-thefbvarinfo.green.length))<<thefbvarinfo.green.offset)
129 + | (((int)b>>(16-thefbvarinfo.blue.length))<<thefbvarinfo.blue.offset);
134 void setpalette(void) {
138 struct fb_fix_screeninfo fixinfo;
139 - struct fb_var_screeninfo varinfo;
143 @@ -304,27 +350,34 @@
146 str=getenv("FRAMEBUFFER");
147 - if(str==NULL) str=THEFBDEV;/* is this a security problem? */
149 + thefbfd=open(str,O_RDWR); /* want write-only here */
151 + str=THEFBDEV; /* is this a security problem? */
152 + thefbfd=open(str,O_RDWR);
155 + thefbfd=open(str,O_RDWR);
159 - thefbfd=open(str,O_RDWR); /* want write-only here */
162 vgaerror("cannot open framebuffer device");
163 if(0!=ioctl(thefbfd,FBIOGET_FSCREENINFO, &fixinfo))
164 vgaerror("cannot get fixed info: its not a framebuffer?");
165 pfprot("(%s)",fixinfo.id);
166 - if(0!=ioctl(thefbfd,FBIOGET_VSCREENINFO, &varinfo))
167 + if(0!=ioctl(thefbfd,FBIOGET_VSCREENINFO, &thefbvarinfo))
168 vgaerror("cannot get var info");
169 - if(varinfo.xres!= varinfo.xres_virtual || varinfo.yres!= varinfo.yres_virtual)
170 - vgaerror("virtual res doesn't equal physical res");
171 - if(fixinfo.type!=FB_TYPE_PACKED_PIXELS || fixinfo.visual!= FB_VISUAL_PSEUDOCOLOR
172 - || varinfo.bits_per_pixel != 8)
173 - vgaerror("pseudocolor, packed-pixels, 8bpp required\n ... try fbset utility?");
174 - thefbxdim=varinfo.xres;
175 - thefbydim=varinfo.yres;
176 + if(fixinfo.type!=FB_TYPE_PACKED_PIXELS)
177 + vgaerror("packed-pixels required\n ... try fbset utility?");
178 + thefbdepth=(thefbvarinfo.bits_per_pixel+7) / 8;
181 + thefbxdim=thefbvarinfo.xres;
182 + thefbydim=thefbvarinfo.yres;
183 pfprot("(%dx%d)",thefbxdim,thefbydim);
184 - thefbbyteswidth=varinfo.xres;
185 - thefblen=((((long)thefbbyteswidth * (long)varinfo.yres * varinfo.bits_per_pixel+7)/8)
186 - + 0x0fffL) & ~0x0fffL;
187 + thefbstride=thefbvarinfo.xres_virtual * thefbdepth;
188 + thefblen=(((long)thefbstride * (long)thefbydim) + 0x0fffL) & ~0x0fffL;
189 if(thefblen>fixinfo.smem_len)
190 pfprot("warning: writefb: mapping more than there is?\n");
194 vgaerror("memory mapping of framebuffer failed");
196 - seteuid(getuid()); /* give back root permissions */
197 + setegid(getgid()); /* give back video group permissions */
199 - pfprot("(set euid %d uid %d)",geteuid(),getuid());
200 + pfprot("(set egid %d gid %d)",getegid(),getgid());
203 /* .. some basic tests, copied from below: under certain */
204 @@ -358,13 +411,13 @@
205 origpalette.green=origgreens;
206 origpalette.blue=origblues;
207 origpalette.transp=origtrans;
208 - if(0!=ioctl(thefbfd,FBIOGETCMAP, &origpalette)){
209 + if(thefbdepth==1 && 0!=ioctl(thefbfd,FBIOGETCMAP, &origpalette)){
211 - vgaerror("\nerror: writefb: readpalette\n");
212 + /*vgaerror("\nerror: writefb: readpalette\n");*/
215 /* accocaletmviews offscreenbuffer */
216 - allocmem(&offscreen,thefblen);
217 + allocmem(&offscreen,((long)thefbxdim * (long)thefbydim + 0x0fffL) & ~0x0fffL);
219 /* open mouse deveice */
222 vtno=ttystat.v_active;
223 sprintf(vtdevice,"/dev/tty%d",vtno);
224 thevtfd=open(vtdevice, O_RDWR | O_NDELAY);
226 + /* try the devfs name */
227 + sprintf(vtdevice,"/dev/vc/%d",vtno);
228 + thevtfd=open(vtdevice, O_RDWR | O_NDELAY);
230 + vgaerror("cannot open vt");
233 vgaerror("cannot open vt");
234 if(ioctl(thevtfd, VT_GETMODE, &vtmode)!=0)
236 vgaerror("cannot install vtswitch handles");
237 ioctl(thevtfd, KDSETMODE, KD_GRAPHICS);
239 + /* now that we switched to graphics mode, pan the display */
240 + thefbvarinfo.xoffset=0;
241 + thefbvarinfo.yoffset=0;
242 + ioctl(thefbfd,FBIOPUT_VSCREENINFO, &thefbvarinfo);
243 + /* don't check the return value; some buggy framebuffer */
244 + /* drivers will return an error while correctly panning */
245 + /* the display, we have no real choice. */
246 + thefbvarinfo.xoffset=0;
247 + thefbvarinfo.yoffset=0;
248 + ioctl(thefbfd,FBIOPAN_DISPLAY, &thefbvarinfo);
250 /* set the terminal to noblocking/noecho */
252 if(!isatty(STDIN_FILENO))
254 vgaydim=truevgaydim=thefbydim;
257 - #define PTDELTAV (thefbbyteswidth)
258 + #define PTDELTAV (vgaxdim)
259 ofscx1=0; ofscy1=0; ofscx2=vgaxdim-1; ofscy2=vgaydim-1;
262 @@ -452,17 +523,17 @@
266 - src+=thefbbyteswidth,
267 - dst+=thefbbyteswidth)
270 memmove(dst,src,vgaxdim-dx);
278 - src+=thefbbyteswidth,
279 - dst+=thefbbyteswidth)
282 memmove(dst,src,vgaxdim-dx);
285 @@ -473,22 +544,22 @@
289 - src=offscreen+thefbbyteswidth*(-dy),
290 + src=offscreen+vgaxdim*(-dy),
294 - src+=thefbbyteswidth,
295 - dst+=thefbbyteswidth)
298 memcpy(dst,src,vgaxdim);
303 - src=offscreen+thefbbyteswidth*(vgaydim-dy-1),
304 - dst=offscreen+thefbbyteswidth*(vgaydim-1);
305 + src=offscreen+vgaxdim*(vgaydim-dy-1),
306 + dst=offscreen+vgaxdim*(vgaydim-1);
309 - src-=thefbbyteswidth,
310 - dst-=thefbbyteswidth)
313 memcpy(dst,src,vgaxdim);
316 --- tmview-01.03.orig/fb/defsfb.h
317 +++ tmview-01.03/fb/defsfb.h
322 -/* the framebuffer devive to use */
323 +/* the framebuffer device to use */
324 #define THEFBDEV "/dev/fb0"
326 +#define THEOTHERFBDEV "/dev/fb/0"