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)
179 *chan = gscreen->chan;
180 *width = gscreen->width;
183 return gscreen->data->bdata;
187 getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
193 setcolor(ulong p, ulong r, ulong g, ulong b)
200 blankscreen(int blank)
206 myscreenputs(char *s, int n)
213 /* don't deadlock trying to print in interrupt */
214 if(!canlock(&screenlock))
221 i = chartorune(&r, s);
247 orange = allocmemimage(Rect(0, 0, 1, 1), RGB16);
248 orange->flags |= Frepl;
249 orange->clipr = gscreen->r;
250 orange->data->bdata[0] = 0x40; /* magic: colour? */
251 orange->data->bdata[1] = 0xfd; /* magic: colour? */
253 w = memdefont->info[' '].width;
254 h = memdefont->height;
256 r = insetrect(gscreen->r, 4);
258 memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, S);
259 window = insetrect(r, 4);
260 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
262 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
263 window.max.x, window.min.y + h + 5 + 6), orange, ZP, nil, ZP, S);
264 freememimage(orange);
265 window = insetrect(window, 5);
267 greet = " Plan 9 Console ";
268 p = addpt(window.min, Pt(10, 0));
269 q = memsubfontwidth(memdefont, greet);
270 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
272 window.min.y += h + 6;
274 window.max.y = window.min.y + ((window.max.y - window.min.y) / h) * h;
285 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
286 p = Pt(window.min.x, window.min.y+o);
287 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
289 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
290 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
297 screenputc(char *buf)
304 static int xbuf[256];
306 if (xp < xbuf || xp >= &xbuf[nelem(xbuf)])
311 if (curpos.y + h >= window.max.y)
318 curpos.x = window.min.x;
321 p = memsubfontwidth(memdefont, " ");
323 if (curpos.x >= window.max.x - Tabstop * w)
326 pos = (curpos.x - window.min.x) / w;
327 pos = Tabstop - pos % Tabstop;
329 r = Rect(curpos.x, curpos.y, curpos.x + pos * w, curpos.y + h);
330 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
338 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
339 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
346 p = memsubfontwidth(memdefont, buf);
349 if (curpos.x >= window.max.x - w)
353 r = Rect(curpos.x, curpos.y, curpos.x + w, curpos.y + h);
354 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
355 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);