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)
122 static char rb[UTFmax+1];
133 * Don't deadlock trying to
134 * print in an interrupt.
136 if(!canlock(&vgascreenlock))
140 lock(&vgascreenlock);
143 * Be nice to hold this, but not going to deadlock
144 * waiting for it. Just try and see.
146 gotdraw = canqlock(&drawlock);
148 flushr = Rect(10000, 10000, -10000, -10000);
153 if(nrb >= UTFmax || fullrune(rb, nrb)){
155 vgascreenputc(scr, rb, &flushr);
159 flushmemscreen(flushr);
163 unlock(&vgascreenlock);
167 mkcolor(Memimage *screen, ulong color)
171 if(i = allocmemimage(Rect(0,0,1,1), screen->chan)){
173 i->clipr = screen->r;
174 memfillcolor(i, color);
180 vgascreenwin(VGAscr* scr)
189 h = scr->memdefont->height;
192 if(i = mkcolor(scr->gscreen, 0x444488FF)){
193 memimagedraw(scr->gscreen, r, i, ZP, nil, ZP, S);
197 window = insetrect(r, 20);
198 memimagedraw(scr->gscreen, window, conscol, ZP, memopaque, ZP, S);
199 window = insetrect(window, 4);
200 memimagedraw(scr->gscreen, window, back, ZP, memopaque, ZP, S);
202 if(i = mkcolor(scr->gscreen, 0xAAAAAAFF)){
203 memimagedraw(scr->gscreen, Rect(window.min.x, window.min.y,
204 window.max.x, window.min.y+h+5+6), i, ZP, nil, ZP, S);
207 window = insetrect(window, 5);
208 p = addpt(window.min, Pt(10, 0));
209 memimagestring(scr->gscreen, p, memblack, ZP, scr->memdefont, " Plan 9 Console ");
212 window = insetrect(window, 5);
214 window.max.y = window.min.y+(Dy(window)/h)*h;
221 screenputs = vgascreenputs;
225 * Supposedly this is the way to turn DPMS
226 * monitors off using just the VGA registers.
227 * Unfortunately, it seems to mess up the video mode
228 * on the cards I've tried.
231 vgablank(VGAscr*, int blank)
243 outs(Seqx, 0x0100); /* synchronous reset */
244 seq1 |= vgaxi(Seqx, 1) & ~0x20;
245 vgaxo(Seqx, 1, seq1);
246 crtc17 |= vgaxi(Crtx, 0x17) & ~0x80;
248 vgaxo(Crtx, 0x17, crtc17);
249 outs(Crtx, 0x0300); /* end synchronous reset */
253 addvgaseg(char *name, ulong pa, ulong size)
257 memset(&seg, 0, sizeof seg);
258 seg.attr = SG_PHYSICAL;