6 #include "screen.hpp"
\r
7 #include "vgalib.hpp"
\r
10 GraphicsAPI::GraphicsAPI(int xr, int yr, int vxr, int vyr, int clrs)
\r
18 libID = "Generic Graphics";
\r
29 font = (unsigned char *)MK_FP(segm, offs);
\r
30 fontHeight = fontWidth = 8;
\r
33 void GraphicsAPI::hLine(int x, int y, int l)
\r
39 void GraphicsAPI::vLine(int x, int y, int l)
\r
46 * Generic line drawing routine, using Bresenham's algorithm.
\r
47 * Taken from Richard Wilton: "PC & PS/2 Video Systems" p. 166-7
\r
50 void GraphicsAPI::line(int x1, int y1, int x2, int y2)
\r
55 vLine(x1, y1, y2-y1+1);
\r
61 hLine(x1, y1, x2-x1+1);
\r
63 int dx = absolute(x2-x1);
\r
64 int dy = absolute(y2-y1);
\r
75 int d = 2 * dy - dx;
\r
76 int aincr = 2 * (dy - dx);
\r
104 int aincr = 2 * (dx - dy);
\r
105 int bincr = 2 * dx;
\r
123 void GraphicsAPI::rectangle(int x1, int y1, int x2, int y2)
\r
127 hLine(x1, y1, x2-x1);
\r
128 hLine(x1, y2, x2-x1);
\r
129 vLine(x1, y1, y2-y1);
\r
130 vLine(x2, y1, y2-y1);
\r
133 void GraphicsAPI::bar(int x1, int y1, int x2, int y2)
\r
135 int width = x2-x1+1;
\r
136 for (int y = y1; y < y2; ++y)
\r
137 hLine(x1, y, width);
\r
140 void GraphicsAPI::wipe()
\r
142 bar(0, 0, vxres, vyres);
\r
145 void GraphicsAPI::putChar(int x, int y, int ch)
\r
147 unsigned char *fptr = font + fontHeight*ch;
\r
148 for (int j=0; j<fontHeight; ++j, ++fptr)
\r
151 for (int i=0; i<fontWidth; ++i)
\r
155 putPixel(x+i, y+j, color);
\r
161 void GraphicsAPI::putText(int x, int y, char *txt)
\r
166 x -= fontWidth * strlen(txt) / 2;
\r
169 x -= fontWidth * strlen(txt);
\r
175 y -= fontHeight / 2;
\r
184 putChar(x, y, *(txt++));
\r
189 void GraphicsAPI::setTextJustify(HJustify h, VJustify v)
\r
200 unsigned char *VGAGraphicsAPI::videoBuf =
\r
201 (unsigned char *)MK_FP(0xa000,0);
\r
203 VGAGraphicsAPI::VGAGraphicsAPI(int xr, int yr, int vxr, int xb, int clrs)
\r
204 : GraphicsAPI(xr, yr, vxr, 65536L/xb, clrs), xbytes(xb)
\r
206 libID = "VGA Graphics";
\r
208 int t = inp(0x3cf);
\r
209 outpw(0x3ce, 0x05 | (t & 0xfc) << 8); // write mode 0
\r
210 outpw(0x3c4, 0x0f02); // enable all planes
\r
214 void VGAGraphicsAPI::syncWithRefresh()
\r
216 while (inp(0x3da)&0x8);
\r
217 while (!(inp(0x3da)&0x8));
\r
220 unsigned VGAGraphicsAPI::getOffset(int x, int y)
\r
222 return y * xbytes + x/(vxres/xbytes);
\r
225 void VGAGraphicsAPI::setBase(int x=0, int y=0)
\r
227 unsigned offset = getOffset(x,y);
\r
230 outp(0x3c0, getPelPan(x));
\r
231 outpw(0x3d4, 0x0c | (offset & 0xff00));
\r
232 outpw(0x3d4, 0x0d | (offset & 0x00ff)<<8);
\r
241 Planar16::Planar16(int xr, int yr, int vxr)
\r
242 : VGAGraphicsAPI(xr, yr, vxr, vxr>>3, 16)
\r
244 libID = "4-plane 16-color mode";
\r
245 outpw(0x3ce, 0x0f01); // enable set/reset
\r
248 void Planar16::putPixel(int x, int y, int c)
\r
250 outpw(0x3ce, 0x00 | (c<<8)); // set/reset to select color
\r
251 outpw(0x3ce, 0x08 | 0x8000>>(x&7)); // bit mask to select bit
\r
252 unsigned char *pos = graphScr+y*xbytes+(x>>3);
\r
256 int Planar16::getPixel(int x, int y)
\r
258 return videoBuf[y*xbytes+x];
\r
261 void Planar16::hLine(int x, int y, int l)
\r
263 outpw(0x3ce, 0x00 | (color<<8)); // set/reset to select color
\r
264 unsigned char *pos = graphScr+y*xbytes+(x>>3);
\r
269 mask = 0x00ff >> shift;
\r
272 mask &= 0xff << -l;
\r
273 outpw(0x3ce, 0x08 | mask << 8); // bit mask to select first bits
\r
279 outpw(0x3ce, 0xff08); // bit mask to select 8 bits
\r
280 memset(pos, 0, l>>3);
\r
286 mask = 0xff00 << (8-l);
\r
287 outpw(0x3ce, 0x08 | mask); // bit mask to select last bits
\r
292 int Planar16::getPelPan(int x)
\r
301 Chained256::Chained256(int xr, int yr, int vxr)
\r
302 : VGAGraphicsAPI(xr, yr, vxr, vxr, 256)
\r
304 libID = "Chained 256-color mode";
\r
307 void Chained256::putPixel(int x, int y, int c)
\r
309 videoBuf[y*xbytes+x] = c;
\r
312 int Chained256::getPixel(int x, int y)
\r
314 return videoBuf[y*xbytes+x];
\r
317 void Chained256::hLine(int x, int y, int l)
\r
319 memset(graphScr+y*xbytes+x, color, l);
\r
322 unsigned Chained256::getOffset(int x, int y)
\r
324 return (y * xbytes + x/(vxres/xbytes)) >> 2;
\r
327 int Chained256::getPelPan(int x)
\r
337 Unchained256::Unchained256(int xr, int yr, int vxr)
\r
338 : VGAGraphicsAPI(xr, yr, vxr, vxr>>2, 256)
\r
340 libID = "Unchained 256-color mode";
\r
343 void Unchained256::putPixel(int x, int y, int c)
\r
345 outpw(0x3c4, 0x02 | 0x0100<<(x&3));
\r
346 videoBuf[y*xbytes+(x>>2)] = c;
\r
349 int Unchained256::getPixel(int x, int y)
\r
351 return videoBuf[y*xbytes+x];
\r
354 void Unchained256::hLine(int x, int y, int l)
\r
356 unsigned char *pos = graphScr+y*xbytes+(x>>2);
\r
361 mask = 0x000f << shift & 0x000f;
\r
364 mask &= 0x0f >> -l;
\r
365 outpw(0x3c4, 0x02 | mask << 8); // write enable first pixels
\r
370 outpw(0x3c4, 0x0f02); // write enable 4 pixels
\r
371 memset(pos, color, l>>2);
\r
377 mask = 0x0f00 >> (4-l) & 0x0f00;
\r
378 outpw(0x3c4, 0x02 | mask); // write enable last pixels
\r
383 int Unchained256::getPelPan(int x)
\r