2 * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
4 * Copyright (c) 2000 Victor Larionov, Victor Rogachev <rogach@sut.ru>
7 * Screen Driver using BGI for DOS TURBOC
9 * This driver requires the following BGI entry points:
10 * initgraph, closegraph,
12 * setcolor, line, setfillstyle, bar
14 * All graphics drawing primitives are based on top of these functions.
16 * This file also contains the generalized low-level font/text
17 * drawing routines, which will be split out into another file.
18 * Both fixed and proportional fonts are supported.
26 /* specific bgi driver entry points*/
27 static PSD BGI_open(PSD psd);
28 static void BGI_close(PSD psd);
29 static void BGI_getscreeninfo(PSD psd,PMWSCREENINFO psi);
30 static void BGI_setpalette(PSD psd,int first,int count,MWPALENTRY *pal);
31 static void BGI_drawpixel(PSD psd,MWCOORD x, MWCOORD y, MWPIXELVAL c);
32 static MWPIXELVAL BGI_readpixel(PSD psd,MWCOORD x, MWCOORD y);
33 static void BGI_drawhline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c);
34 static void BGI_drawvline(PSD psd,MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c);
35 static void BGI_fillrect(PSD psd,MWCOORD x1,MWCOORD y1,MWCOORD x2,MWCOORD y2,MWPIXELVAL c);
36 static void BGI_blit(PSD dstpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,MWCOORD h,
37 PSD srcpsd,MWCOORD srcx,MWCOORD srcy,long op);
38 static PSD BGI_allocatememgc(PSD psd);
40 SCREENDEVICE scrdev = {
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
54 NULL, /* DrawArea subdriver*/
55 NULL, /* SetIOPermissions*/
62 extern int gr_mode; /* temp kluge*/
63 static struct linesettingstype lineinfo;
64 static struct palettetype bgi_pal;
72 registerbgidriver(EGAVGA_driver);
73 initgraph(&gd,&gm,"");
75 getlinesettings(&lineinfo);
77 psd->xres = psd->xvirtres = getmaxx()+1;
78 psd->yres = psd->yvirtres = getmaxy()+1;
79 psd->linelen = lineinfo.thickness;
81 psd->bpp = 4; /* FIXME?? */
82 psd->ncolors = getmaxcolor() + 1;
83 psd->flags = PSF_SCREEN;
84 psd->addr = 0; /* FIXME */
86 /* note: must change psd->pixtype here for truecolor systems*/
87 psd->pixtype = MWPF_PALETTE;
98 BGI_getscreeninfo(PSD psd,PMWSCREENINFO psi)
100 psi->rows = psd->yvirtres;
101 psi->cols = psd->xvirtres;
102 psi->planes = psd->planes;
104 psi->ncolors = psd->ncolors;
105 psi->pixtype = psd->pixtype;
106 psi->fonts = NUMBER_FONTS;
108 if(scrdev.yvirtres > 480) {
110 psi->xdpcm = 33; /* assumes screen width of 24 cm*/
111 psi->ydpcm = 33; /* assumes screen height of 18 cm*/
112 } else if(scrdev.yvirtres > 350) {
114 psi->xdpcm = 27; /* assumes screen width of 24 cm*/
115 psi->ydpcm = 27; /* assumes screen height of 18 cm*/
118 psi->xdpcm = 27; /* assumes screen width of 24 cm*/
119 psi->ydpcm = 19; /* assumes screen height of 18 cm*/
124 BGI_setpalette(PSD psd,int first,int count,MWPALENTRY *pal)
126 /* std 16 color palette assumed*/
130 BGI_drawpixel(PSD psd,MWCOORD x, MWCOORD y, MWPIXELVAL c)
133 case MWMODE_COPY: break;
134 case MWMODE_XOR: c ^= getpixel(x, y); break;
135 case MWMODE_OR: c |= getpixel(x, y); break;
136 case MWMODE_AND: c &= getpixel(x, y); break;
142 BGI_readpixel(PSD psd,MWCOORD x, MWCOORD y)
144 return getpixel(x, y);
148 BGI_drawhline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
161 setwritemode(COPY_PUT);
164 setwritemode(XOR_PUT);
167 for(x = x1; x <= x2; x++)
168 putpixel(x, y, c | getpixel(x, y));
171 for(x = x1; x <= x2; x++)
172 putpixel(x, y, c & getpixel(x, y));
179 BGI_drawvline(PSD psd,MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
192 setwritemode(COPY_PUT);
195 setwritemode(XOR_PUT);
198 for(y = y1; y <= y2; y++)
199 putpixel(x, y, c | getpixel(x, y));
202 for(y = y1; y <= y2; y++)
203 putpixel(x, y, c & getpixel(x, y));
210 BGI_fillrect(PSD psd,MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2,
233 for(x = x1; x <= x2; x++)
234 for(y = y1; y <= y2; y++)
235 putpixel(x, y, c ^ getpixel(x, y));
239 for(x = x1; x <= x2; x++)
240 for(y = y1; y <= y2; y++)
241 putpixel(x, y, c | getpixel(x, y));
245 for(x = x1; x <= x2; x++)
246 for(y = y1; y <= y2; y++)
247 putpixel(x, y, c & getpixel(x, y));
256 BGI_blit(PSD dstpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,MWCOORD h,
257 PSD srcpsd,MWCOORD srcx,MWCOORD srcy,long op)
262 /* allocate a memory screen device*/
264 BGI_allocatememgc(PSD psd)
266 /* if driver doesn't have blit, fail*/