/* * scr_gfx.bgi: * IBM PC graphics handling via BGI * (a first attempt at using BGI routines ...) * * Copyright (c) 1989 University of Toronto. All rights reserved. * Anyone may use or copy this software, except that it may not be * sold for profit, that this copyright notice remain intact, and that * credit is given where it is due. The University of Toronto and the * author make no warranty and accept no liability for this software. */ static char GFXid[] = "$Header: /homes/ugw/pkern/src/cterm/RCS/scr_gfx.bgi,v 1.1 89/07/24 12:45:17 pkern Exp $"; /* #define BGI_DIR "C:\\" /* */ /* #define BGI_DIR "" /* */ #define BGI_DIR "c:\\tc\\bgi" /* */ /* video mode parameters */ unsigned int txt_mode=0x07, txt_addr=0xb000; unsigned int avm_mode=0, avm_addr=0; unsigned int gfx_mode=0, gfx_addr=0; unsigned int gfx_xres=2, gfx_yres=2, gfx_numclr=2; int gfx_driver = DETECT; static int o_gclr = -1; static uchar o_gtyp = 0; init_gfx() { extern uchar interlace, gcolour; extern int gmax_x, gmax_y, gmax_clr; if (!interlace) { if (gfx_addr && gfx_driver > 0) restorecrtmode(); } else if (g_type != o_gtyp || !gfx_addr) { extern char *program; char bgipath[MAXPATH]; o_gtyp = g_type; gfx_driver = (g_type) ? g_type : DETECT; strcpy(bgipath, BGI_DIR); if (*program) { int len; char drv[MAXDRIVE], dir[MAXDIR]; char file[MAXFILE], ext[MAXEXT]; fnsplit(program, drv, dir, file, ext); fnmerge(bgipath, drv, dir, "", ""); len = strlen(bgipath); if (len > 2 && (bgipath[len-1] == '/' || bgipath[len-1] == '\\') && bgipath[len-2] != ':') /* drop trailing '/' (or '\') */ bgipath[len-1] = '\0'; } initgraph(&gfx_driver, &gfx_mode, bgipath); if (graphresult() != grOk) { gfx_driver = (g_type) ? g_type : DETECT; strcpy(bgipath, BGI_DIR); initgraph(&gfx_driver, &gfx_mode, bgipath); } if (graphresult() == grOk) { gfx_xres = getmaxx() + 1; gfx_yres = getmaxy() + 1; gfx_numclr = getpalettesize(); gfx_addr = gfx_mode + 1; } } else if (gfx_driver > 0) setgraphmode(gfx_mode); gmax_x = gfx_xres; gmax_y = gfx_yres; gmax_clr = gfx_numclr; if (interlace) { if (o_gclr < 0) o_gclr = gmax_clr-1; gcolour = o_gclr; } } /* gfx_erase -- clear the graphics screen */ gfx_erase() { if (gfx_driver > 0) cleardevice(); } gfx_colour(n) uchar n; { return(o_gclr = n % gfx_numclr); } /* gpeek -- get a pixel's colour */ gpeek(x, y) int x, y; { if (gfx_addr) return(getpixel(x, y)); } /* boink -- light a pixel */ boink(x,y,c) int x, y; uchar c; { if (gfx_addr) putpixel(x, y, c); } /* * hline -- only does horizontal lines (union regulations :-) * (called from bline(), should be optimized for speed). */ hline(x,y,n,c) int x; register int y,n; uchar c; { register int i; if (n < 0) { n = -n; x -= n; if (x < 0) { n += x; x = 0; } } /* needs optimizing! */ for (i=x; i < x+n; i++) boink(i, y, c); } /* * vline -- vertical lines only * (again, called from bline(), should be optimized for speed). */ vline(x,y,n,c) int y; register int x,n; uchar c; { register int i; if (n < 0) { n = -n; y -= n; if (y < 0) { n += y; y = 0; } } /* needs optimizing! */ for (i=y; i < y+n; i++) boink(x, i, c); } /* * xrun -- optimize search for runs to colour c in x direction * (called from dofill(), should be quicker that gpeek()-ing each pixel) */ xrun(x, y, c, dir) int x, y, dir; uchar c; { uchar cx; extern int gmax_x; while (0 <= x && x < gmax_x) { cx = gpeek(x, y); /* needs optimizing! */ if (c == cx) break; x += dir; } if (c == cx) x -= dir; if (x < 0) return(0); if (x >= gmax_x) return(gmax_x-1); return(x); }