2 #include "../port/lib.h"
7 #include "../port/error.h"
15 static Memimage *conscol;
16 static Memimage *back;
19 static Rectangle window;
32 vgascroll(VGAscr* scr)
38 h = scr->memdefont->height;
40 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
41 p = Pt(window.min.x, window.min.y+o);
42 memimagedraw(scr->gscreen, r, scr->gscreen, p, nil, p, S);
43 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
44 memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S);
50 vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr)
56 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
59 h = scr->memdefont->height;
62 if(curpos.y+h >= window.max.y){
67 vgascreenputc(scr, "\r", flushr);
72 curpos.x = window.min.x;
76 p = memsubfontwidth(scr->memdefont, " ");
78 if(curpos.x >= window.max.x-4*w)
79 vgascreenputc(scr, "\n", flushr);
81 pos = (curpos.x-window.min.x)/w;
84 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
85 memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S);
93 r = Rect(*xp, curpos.y, curpos.x, curpos.y+h);
94 memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S);
95 combinerect(flushr, r);
103 p = memsubfontwidth(scr->memdefont, buf);
106 if(curpos.x >= window.max.x-w)
107 vgascreenputc(scr, "\n", flushr);
110 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h);
111 memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S);
112 memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf);
113 combinerect(flushr, r);
119 vgascreenputs(char* s, int n)
121 static char rb[UTFmax+1];
132 * Don't deadlock trying to
133 * print in an interrupt.
135 if(!canlock(&vgascreenlock))
139 lock(&vgascreenlock);
142 * Be nice to hold this, but not going to deadlock
143 * waiting for it. Just try and see.
145 gotdraw = canqlock(&drawlock);
147 flushr = Rect(10000, 10000, -10000, -10000);
152 if(nrb >= UTFmax || fullrune(rb, nrb)){
154 vgascreenputc(scr, rb, &flushr);
158 flushmemscreen(flushr);
162 unlock(&vgascreenlock);
166 mkcolor(Memimage *screen, ulong color)
170 if(i = allocmemimage(Rect(0,0,1,1), screen->chan)){
172 i->clipr = screen->r;
173 memfillcolor(i, color);
179 vgascreenwin(VGAscr* scr)
188 h = scr->memdefont->height;
191 if(i = mkcolor(scr->gscreen, 0x0D686BFF)){
192 memimagedraw(scr->gscreen, r, i, ZP, nil, ZP, S);
196 window = insetrect(r, 20);
197 memimagedraw(scr->gscreen, window, conscol, ZP, memopaque, ZP, S);
198 window = insetrect(window, 4);
199 memimagedraw(scr->gscreen, window, back, ZP, memopaque, ZP, S);
201 if(i = mkcolor(scr->gscreen, 0xAAAAAAFF)){
202 memimagedraw(scr->gscreen, Rect(window.min.x, window.min.y,
203 window.max.x, window.min.y+h+5+6), i, ZP, nil, ZP, S);
206 window = insetrect(window, 5);
207 p = addpt(window.min, Pt(10, 0));
208 memimagestring(scr->gscreen, p, memblack, ZP, scr->memdefont, " Plan 9 Console ");
211 window = insetrect(window, 5);
213 window.max.y = window.min.y+(Dy(window)/h)*h;
220 screenputs = vgascreenputs;
224 * Supposedly this is the way to turn DPMS
225 * monitors off using just the VGA registers.
226 * Unfortunately, it seems to mess up the video mode
227 * on the cards I've tried.
230 vgablank(VGAscr*, int blank)
242 outs(Seqx, 0x0100); /* synchronous reset */
243 seq1 |= vgaxi(Seqx, 1) & ~0x20;
244 vgaxo(Seqx, 1, seq1);
245 crtc17 |= vgaxi(Crtx, 0x17) & ~0x80;
247 vgaxo(Crtx, 0x17, crtc17);
248 outs(Crtx, 0x0300); /* end synchronous reset */
252 addvgaseg(char *name, ulong pa, ulong size)
256 memset(&seg, 0, sizeof seg);
257 seg.attr = SG_PHYSICAL;