home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * gr_handl.c - Graphics handler routines.
- *
- * Purpose: This file contains the primitive graphics routines
- * used for the IBM PC.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <dos.h>
- #include "blackstr.h"
- #include "sc_head.h"
- #include "gr_head.h"
- #include "gr_defs.h"
-
-
- /********
- *
- * gr_init(mode,fcolr,bcolr,palette) - set up graphics terminal
- *
- **/
-
- void gr_init(int mode, int fcolr, int bcolr, char *palette)
- {
- if (mode)
- sc_smod_(mode);
- else
- mode = sc_gmod_();
-
- switch(mode){
- case GR320:
- case EGA_D:
- grcols_ = 320;
- grrows_ = 200;
- break;
- case GR640:
- case EGA_E:
- grcols_ = 640;
- grrows_ = 200;
- break;
- case EGA_10:
- case EGA_F:
- grcols_ = 640;
- grrows_ = 350;
- break;
- }
-
- if (palette || !grfpal_)
- gr_palette(palette); /* set the graphics palette */
- if(bcolr)
- gr_bcolor(bcolr);
- if (fcolr)
- gr_pen(NUL,fcolr);
-
- grx_=gry_=gr_minx_=gr_miny_=0;
- gr_windo(0,0,grcols_-1,grrows_-1);
- scolst_ = srowst_ = 0;
- scolen_ = sc_cols_-1;
- srowen_ = sc_rows_-1;
- sc_windo(scolst_,srowst_,scolen_,srowen_); /* full screen */
- sc_setcur(0,0); /* home cursor */
- scrollf_=wrapf_= TRUE; /* set wrap & scroll on */
- nlexpf_ = TRUE; /* \n expansion on */
- }
-
-
- /********
- *
- * gr_palette(palette) - set graphics palette
- *
- **/
-
- void gr_palette(char *palette)
- {
- union REGS inregs,outregs;
- struct SREGS segregs;
-
- if( (sc_adp_&CGA_ADP) || ((sc_adp_&EGA_ADP) && (sc_mode_<7))) {
- /* check for EGA */
-
- if(!palette)
- palette = gr_cgap0_;
- inregs.h.bl = palette[16]; /* for CGA, palette is 0 or 1 only */
- inregs.h.bh = 1;
- inregs.h.ah = 11;
- int86(IVIDEO,&inregs,&outregs);
- }
- else if(sc_adp_&EGA_ADP) {
-
- if(!palette)
- palette = gr_egap_;
- segread(&segregs);
- inregs.h.al = 2; /* set all palette and overscan */
- inregs.x.dx = sy_doff(palette);
- inregs.h.ah = 16; /* set palette command */
- inregs.x.bx = 0;
- segregs.es = sy_dseg(palette);
- int86x(IVIDEO,&inregs,&outregs,&segregs);
- }
- grfpal_ = palette;
- }
-
-
- /********
- *
- * gr_bcolor(bcolr) - set background color
- *
- **/
-
- void gr_bcolor(char bcolr)
- {
- union REGS inregs,outregs;
-
- grbcolr_ = bcolr;
- if( (sc_adp_&CGA_ADP) || ((sc_adp_&EGA_ADP) && (sc_mode_<7)) ) {
- /* check for EGA */
- inregs.h.ah = 0xb; /* set color palette CGA */
- inregs.h.bh = 0; /* set background color */
- inregs.h.bl = grbcolr_;
- }
- else if (sc_adp_&EGA_ADP) {
- inregs.h.ah = 0x10; /* set color palette */
- inregs.h.al = 0; /* set background */
- inregs.h.bh = grbcolr_;
- inregs.h.bl = 0; /* enable intensity */
- }
- int86(IVIDEO,&inregs,&outregs);
- sc_color(grfcolr_,bcolr); /* set text color attribute */
- }
-
-
- /********
- *
- * gr_color(fcolr,bcolr) - set foreground & background color palette
- *
- **/
-
- void gr_color(char fcolr, char bcolr)
- {
- gr_pen(0,fcolr);
- gr_bcolor(bcolr);
- }
-
-
- /********
- *
- * gr_pen(xorf,color) - set graphics pen
- *
- **/
-
- void gr_pen(int xorf, int color)
- {
- grfcolr_ = color;
- if ((sc_adp_&EGA_ADP) && (sc_mode_>7))
- grfcol_ = color; /* in EGA modes write using the value */
- else
- grfcol_=grfpal_[color]; /* in CGA modes write using the index */
-
- (!xorf)? (grxorf_=0):(grxorf_=0x80);
- sc_color(color,grbcolr_); /* set text to correct color */
- }
-
-
- /********
- *
- * gr_pos(x,y) - set graphics pen to x,y
- *
- **/
-
- void gr_pos(int x, int y)
- {
- gr_clip(&x,&y);
- grx_ = x;
- gry_ = y;
- }
-
-
- /********
- *
- * gr_setpt(x,y) - set point at x,y
- *
- **/
-
- void gr_setpt(int x, int y)
- {
- gr_clip(&x,&y);
- gr_pt_(x,y);
- grx_ =x, gry_ = y;
- }
-
-
- /********
- *
- * gr_xorp(x,y) - xor point at x,y
- *
- **/
-
- void gr_xorp(int x, int y)
- {
- int oxorf;
-
- oxorf = grxorf_;
- grxorf_=TRUE;
- gr_setpt(x,y);
- grxorf_= oxorf;
- }
-
-
- /********
- *
- * gr_getpt(x,y) - get color of point at x,y
- *
- **/
-
- int gr_getpt(int x, int y)
- {
- gr_clip(&x,&y);
- return(gr_gpt_(x,y));
- }
-
-
- /********
- *
- * gr_putpt(x,y,color) - put color at point x,y
- *
- **/
-
- void gr_putpt(int x, int y, char color)
- {
- gr_pen(NUL,color);
- gr_setpt(x,y);
- }
-
-
- /********
- *
- * gr_getwin() - get graphics windo
- *
- **/
-
- char *gr_getwin(int x1, int y1, int x2, int y2)
- {
- extern char *malloc();
- char *ptr; /* pointer to windo buffer */
-
- gr_wpush(); /* save current windo */
- gr_windo(x1,y1,x2,y2); /* set current windo */
- ptr = malloc((x2-(--x1))*(y2-(--y1))); /* buffer size for windo */
- gr_gwin_(ptr);
- gr_wpop(); /* restore previous windo */
- return(ptr);
- }
-
-
- /********
- *
- * gr_putwin(buff,x1,y1,x2,y2) - put graphics windo
- *
- **/
-
- void gr_putwin(char *buff, int x1, int y1, int x2, int y2)
- {
- gr_wpush(); /* save current windo */
- gr_windo(x1,y1,x2,y2);
- gr_pwin_(buff); /* put buffer to windo */
- gr_wpop(); /* restore previous windo */
- }
-
-
- /********
- *
- * gr_clip(x,y) - clip a point
- *
- **/
-
- void gr_clip(int *x, int *y)
- {
- *x = min(*x,gr_maxx_);
- *x = max(*x,gr_minx_);
- *y = min(*y,gr_maxy_);
- *y = max(*y,gr_miny_);
- }
-
-
- /********
- *
- * gr_line (x1,y1,x2,y2) - line from x1,y1 to x2,y2
- *
- **/
-
- void gr_line(int x1, int y1,int x2,int y2)
- {
- gr_clip(&x1,&y1);
- gr_clip(&x2,&y2);
- gr_ln_(x1,y1,x2,y2);
- grx_ = x2, gry_ = y2; /* update pen position*/
- }
-
-
- /********
- *
- * gr_lineto(x,y) - line to x,y from current location
- *
- **/
-
- void gr_lineto(int x, int y)
- {
- gr_clip(&x,&y);
- gr_ln_(grx_,gry_,x,y);
- grx_ = x, gry_ = y; /* update pen position*/
- }
-
-
-