6 #include "../port/lib.h"
27 static Memdata xgdata;
29 static Memimage xgscreen =
31 { 0, 0, Wid, Ht }, /* r */
32 { 0, 0, Wid, Ht }, /* clipr */
39 0, /* width in words of a single scan line */
44 static Memimage *conscol;
45 static Memimage *back;
46 static Memsubfont *memdefont;
48 static Lock screenlock;
52 static Rectangle window;
54 static void myscreenputs(char *s, int n);
55 static void screenputc(char *buf);
56 static void screenwin(void);
64 swcursordraw(mousexy());
79 /* called from devmouse */
81 setcursor(Cursor* curs)
87 hwdraw(Memdrawparam *par)
89 Memimage *dst, *src, *mask;
91 if((dst=par->dst) == nil || dst->data == nil)
93 if((src=par->src) == nil || src->data == nil)
95 if((mask=par->mask) == nil || mask->data == nil)
98 if(dst->data->bdata == xgdata.bdata)
99 swcursoravoid(par->r);
100 if(src->data->bdata == xgdata.bdata)
101 swcursoravoid(par->sr);
102 if(mask->data->bdata == xgdata.bdata)
103 swcursoravoid(par->mr);
113 int width, height, depth;
115 p = getconf("vgasize");
116 if(p == nil || getfields(p, f, nelem(f), 0, "x") != nelem(f) ||
117 (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 ||
118 (depth = atoi(f[2])) <= 0)
120 xgscreen.r.max = Pt(width, height);
121 xgscreen.depth = depth;
132 set = screensize() == 0;
133 fb = fbinit(set, &xgscreen.r.max.x, &xgscreen.r.max.y, &xgscreen.depth);
135 print("can't initialise %dx%dx%d framebuffer \n",
136 xgscreen.r.max.x, xgscreen.r.max.y, xgscreen.depth);
139 xgscreen.clipr = xgscreen.r;
140 switch(xgscreen.depth){
142 print("unsupported screen depth %d\n", xgscreen.depth);
155 memsetchan(&xgscreen, chan);
160 gscreen->width = wordsperline(gscreen->r, gscreen->depth);
163 memdefont = getmemdefont();
165 screenputs = myscreenputs;
170 flushmemscreen(Rectangle)
175 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
182 *chan = gscreen->chan;
183 *width = gscreen->width;
186 gscreen->data->ref++;
187 return gscreen->data;
191 getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
197 setcolor(ulong p, ulong r, ulong g, ulong b)
204 blankscreen(int blank)
210 myscreenputs(char *s, int n)
217 /* don't deadlock trying to print in interrupt */
218 if(!canlock(&screenlock))
225 i = chartorune(&r, s);
251 orange = allocmemimage(Rect(0, 0, 1, 1), RGB16);
252 orange->flags |= Frepl;
253 orange->clipr = gscreen->r;
254 orange->data->bdata[0] = 0x40; /* magic: colour? */
255 orange->data->bdata[1] = 0xfd; /* magic: colour? */
257 w = memdefont->info[' '].width;
258 h = memdefont->height;
260 r = insetrect(gscreen->r, 4);
262 memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, S);
263 window = insetrect(r, 4);
264 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
266 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
267 window.max.x, window.min.y + h + 5 + 6), orange, ZP, nil, ZP, S);
268 freememimage(orange);
269 window = insetrect(window, 5);
271 greet = " Plan 9 Console ";
272 p = addpt(window.min, Pt(10, 0));
273 q = memsubfontwidth(memdefont, greet);
274 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
276 window.min.y += h + 6;
278 window.max.y = window.min.y + ((window.max.y - window.min.y) / h) * h;
289 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
290 p = Pt(window.min.x, window.min.y+o);
291 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
293 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
294 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
301 screenputc(char *buf)
308 static int xbuf[256];
310 if (xp < xbuf || xp >= &xbuf[nelem(xbuf)])
315 if (curpos.y + h >= window.max.y)
322 curpos.x = window.min.x;
325 p = memsubfontwidth(memdefont, " ");
327 if (curpos.x >= window.max.x - Tabstop * w)
330 pos = (curpos.x - window.min.x) / w;
331 pos = Tabstop - pos % Tabstop;
333 r = Rect(curpos.x, curpos.y, curpos.x + pos * w, curpos.y + h);
334 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
342 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
343 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
350 p = memsubfontwidth(memdefont, buf);
353 if (curpos.x >= window.max.x - w)
357 r = Rect(curpos.x, curpos.y, curpos.x + w, curpos.y + h);
358 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
359 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);