2 #include "../port/lib.h"
7 #include "../port/error.h"
15 static Memimage *conscol;
16 static Memimage *back;
19 static Rectangle window;
33 vgascroll(VGAscr* scr)
39 h = scr->memdefont->height;
41 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
42 p = Pt(window.min.x, window.min.y+o);
43 memimagedraw(scr->gscreen, r, scr->gscreen, p, nil, p, S);
44 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
45 memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S);
51 vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr)
57 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
60 h = scr->memdefont->height;
63 if(curpos.y+h >= window.max.y){
68 vgascreenputc(scr, "\r", flushr);
73 curpos.x = window.min.x;
77 p = memsubfontwidth(scr->memdefont, " ");
79 if(curpos.x >= window.max.x-4*w)
80 vgascreenputc(scr, "\n", flushr);
82 pos = (curpos.x-window.min.x)/w;
85 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
86 memimagedraw(scr->gscreen, r, back, ZP, nil, ZP, S);
94 r = Rect(*xp, curpos.y, curpos.x, curpos.y+h);
95 memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S);
96 combinerect(flushr, r);
104 p = memsubfontwidth(scr->memdefont, buf);
107 if(curpos.x >= window.max.x-w)
108 vgascreenputc(scr, "\n", flushr);
111 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h);
112 memimagedraw(scr->gscreen, r, back, r.min, nil, ZP, S);
113 memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf);
114 combinerect(flushr, r);
120 vgascreenputs(char* s, int n)
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);
150 i = chartorune(&r, s);
160 vgascreenputc(scr, buf, &flushr);
162 flushmemscreen(flushr);
166 unlock(&vgascreenlock);
170 mkcolor(Memimage *screen, ulong color)
174 if(i = allocmemimage(Rect(0,0,1,1), screen->chan)){
176 i->clipr = screen->r;
177 memfillcolor(i, color);
183 vgascreenwin(VGAscr* scr)
192 h = scr->memdefont->height;
195 if(i = mkcolor(scr->gscreen, 0x444488FF)){
196 memimagedraw(scr->gscreen, r, i, ZP, nil, ZP, S);
200 window = insetrect(r, 20);
201 memimagedraw(scr->gscreen, window, conscol, ZP, memopaque, ZP, S);
202 window = insetrect(window, 4);
203 memimagedraw(scr->gscreen, window, back, ZP, memopaque, ZP, S);
205 if(i = mkcolor(scr->gscreen, 0xAAAAAAFF)){
206 memimagedraw(scr->gscreen, Rect(window.min.x, window.min.y,
207 window.max.x, window.min.y+h+5+6), i, ZP, nil, ZP, S);
210 window = insetrect(window, 5);
211 p = addpt(window.min, Pt(10, 0));
212 memimagestring(scr->gscreen, p, memblack, ZP, scr->memdefont, " Plan 9 Console ");
215 window = insetrect(window, 5);
217 window.max.y = window.min.y+(Dy(window)/h)*h;
224 screenputs = vgascreenputs;
228 * Supposedly this is the way to turn DPMS
229 * monitors off using just the VGA registers.
230 * Unfortunately, it seems to mess up the video mode
231 * on the cards I've tried.
234 vgablank(VGAscr*, int blank)
246 outs(Seqx, 0x0100); /* synchronous reset */
247 seq1 |= vgaxi(Seqx, 1) & ~0x20;
248 vgaxo(Seqx, 1, seq1);
249 crtc17 |= vgaxi(Crtx, 0x17) & ~0x80;
251 vgaxo(Crtx, 0x17, crtc17);
252 outs(Crtx, 0x0300); /* end synchronous reset */
256 addvgaseg(char *name, ulong pa, ulong size)
260 memset(&seg, 0, sizeof seg);
261 seg.attr = SG_PHYSICAL;