6 #include "../port/lib.h"
27 { 0xFF, 0xFF, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0C,
28 0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04,
29 0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8C, 0x04,
30 0x92, 0x08, 0x91, 0x10, 0xA0, 0xA0, 0xC0, 0x40,
32 { 0x00, 0x00, 0x7F, 0xFE, 0x7F, 0xFC, 0x7F, 0xF0,
33 0x7F, 0xE0, 0x7F, 0xE0, 0x7F, 0xF0, 0x7F, 0xF8,
34 0x7F, 0xFC, 0x7F, 0xFE, 0x7F, 0xFC, 0x73, 0xF8,
35 0x61, 0xF0, 0x60, 0xE0, 0x40, 0x40, 0x00, 0x00,
41 static Memdata xgdata;
43 static Memimage xgscreen =
45 { 0, 0, Wid, Ht }, /* r */
46 { 0, 0, Wid, Ht }, /* clipr */
53 0, /* width in words of a single scan line */
58 static Memimage *conscol;
59 static Memimage *back;
60 static Memsubfont *memdefont;
62 static Lock screenlock;
66 static Rectangle window;
68 static void myscreenputs(char *s, int n);
69 static void screenputc(char *buf);
70 static void screenwin(void);
78 swcursordraw(mousexy());
93 /* called from devmouse */
95 setcursor(Cursor* curs)
101 hwdraw(Memdrawparam *par)
103 Memimage *dst, *src, *mask;
105 if((dst=par->dst) == nil || dst->data == nil)
107 if((src=par->src) == nil || src->data == nil)
109 if((mask=par->mask) == nil || mask->data == nil)
112 if(dst->data->bdata == xgdata.bdata)
113 swcursoravoid(par->r);
114 if(src->data->bdata == xgdata.bdata)
115 swcursoravoid(par->sr);
116 if(mask->data->bdata == xgdata.bdata)
117 swcursoravoid(par->mr);
127 int width, height, depth;
129 p = getconf("vgasize");
130 if(p == nil || getfields(p, f, nelem(f), 0, "x") != nelem(f) ||
131 (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 ||
132 (depth = atoi(f[2])) <= 0)
134 xgscreen.r.max = Pt(width, height);
135 xgscreen.depth = depth;
146 set = screensize() == 0;
147 fb = fbinit(set, &xgscreen.r.max.x, &xgscreen.r.max.y, &xgscreen.depth);
149 print("can't initialise %dx%dx%d framebuffer \n",
150 xgscreen.r.max.x, xgscreen.r.max.y, xgscreen.depth);
153 xgscreen.clipr = xgscreen.r;
154 switch(xgscreen.depth){
156 print("unsupported screen depth %d\n", xgscreen.depth);
169 memsetchan(&xgscreen, chan);
174 gscreen->width = wordsperline(gscreen->r, gscreen->depth);
177 memdefont = getmemdefont();
179 screenputs = myscreenputs;
184 flushmemscreen(Rectangle)
189 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
193 *chan = gscreen->chan;
194 *width = gscreen->width;
197 return gscreen->data->bdata;
201 getcolor(ulong p, ulong *pr, ulong *pg, ulong *pb)
207 setcolor(ulong p, ulong r, ulong g, ulong b)
214 blankscreen(int blank)
220 myscreenputs(char *s, int n)
227 /* don't deadlock trying to print in interrupt */
228 if(!canlock(&screenlock))
235 i = chartorune(&r, s);
261 orange = allocmemimage(Rect(0, 0, 1, 1), RGB16);
262 orange->flags |= Frepl;
263 orange->clipr = gscreen->r;
264 orange->data->bdata[0] = 0x40; /* magic: colour? */
265 orange->data->bdata[1] = 0xfd; /* magic: colour? */
267 w = memdefont->info[' '].width;
268 h = memdefont->height;
270 r = insetrect(gscreen->r, 4);
272 memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, S);
273 window = insetrect(r, 4);
274 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
276 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
277 window.max.x, window.min.y + h + 5 + 6), orange, ZP, nil, ZP, S);
278 freememimage(orange);
279 window = insetrect(window, 5);
281 greet = " Plan 9 Console ";
282 p = addpt(window.min, Pt(10, 0));
283 q = memsubfontwidth(memdefont, greet);
284 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
286 window.min.y += h + 6;
288 window.max.y = window.min.y + ((window.max.y - window.min.y) / h) * h;
299 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
300 p = Pt(window.min.x, window.min.y+o);
301 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
303 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
304 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);
311 screenputc(char *buf)
318 static int xbuf[256];
320 if (xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
325 if (curpos.y + h >= window.max.y)
332 curpos.x = window.min.x;
335 p = memsubfontwidth(memdefont, " ");
337 if (curpos.x >= window.max.x - Tabstop * w)
340 pos = (curpos.x - window.min.x) / w;
341 pos = Tabstop - pos % Tabstop;
343 r = Rect(curpos.x, curpos.y, curpos.x + pos * w, curpos.y + h);
344 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
352 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
353 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
360 p = memsubfontwidth(memdefont, buf);
363 if (curpos.x >= window.max.x - w)
367 r = Rect(curpos.x, curpos.y, curpos.x + w, curpos.y + h);
368 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
369 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);