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);
155 vgascreenputc(scr, buf, &flushr);
157 flushmemscreen(flushr);
161 unlock(&vgascreenlock);
165 mkcolor(Memimage *screen, ulong color)
169 if(i = allocmemimage(Rect(0,0,1,1), screen->chan)){
171 i->clipr = screen->r;
172 memfillcolor(i, color);
178 vgascreenwin(VGAscr* scr)
187 h = scr->memdefont->height;
190 if(i = mkcolor(scr->gscreen, 0x444488FF)){
191 memimagedraw(scr->gscreen, r, i, ZP, nil, ZP, S);
195 window = insetrect(r, 20);
196 memimagedraw(scr->gscreen, window, conscol, ZP, memopaque, ZP, S);
197 window = insetrect(window, 4);
198 memimagedraw(scr->gscreen, window, back, ZP, memopaque, ZP, S);
200 if(i = mkcolor(scr->gscreen, 0xAAAAAAFF)){
201 memimagedraw(scr->gscreen, Rect(window.min.x, window.min.y,
202 window.max.x, window.min.y+h+5+6), i, ZP, nil, ZP, S);
205 window = insetrect(window, 5);
206 p = addpt(window.min, Pt(10, 0));
207 memimagestring(scr->gscreen, p, memblack, ZP, scr->memdefont, " Plan 9 Console ");
210 window = insetrect(window, 5);
212 window.max.y = window.min.y+(Dy(window)/h)*h;
219 screenputs = vgascreenputs;
223 * Supposedly this is the way to turn DPMS
224 * monitors off using just the VGA registers.
225 * Unfortunately, it seems to mess up the video mode
226 * on the cards I've tried.
229 vgablank(VGAscr*, int blank)
241 outs(Seqx, 0x0100); /* synchronous reset */
242 seq1 |= vgaxi(Seqx, 1) & ~0x20;
243 vgaxo(Seqx, 1, seq1);
244 crtc17 |= vgaxi(Crtx, 0x17) & ~0x80;
246 vgaxo(Crtx, 0x17, crtc17);
247 outs(Crtx, 0x0300); /* end synchronous reset */
251 addvgaseg(char *name, ulong pa, ulong size)
255 memset(&seg, 0, sizeof seg);
256 seg.attr = SG_PHYSICAL;