home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / GR_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-17  |  6.4 KB  |  317 lines

  1. /*********************
  2.  *
  3.  *  gr_handl.c - Graphics handler routines.
  4.  *
  5.  *  Purpose: This file contains the primitive graphics routines
  6.  *           used for the IBM PC.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <dos.h>
  14. #include "blackstr.h"
  15. #include "sc_head.h"
  16. #include "gr_head.h"
  17. #include "gr_defs.h"
  18.  
  19.  
  20. /********
  21.  *
  22.  *   gr_init(mode,fcolr,bcolr,palette) - set up graphics terminal
  23.  *
  24.  **/
  25.  
  26. void gr_init(int mode, int fcolr, int bcolr, char *palette)
  27. {
  28.     if (mode)
  29.     sc_smod_(mode);
  30.     else
  31.     mode = sc_gmod_();
  32.  
  33.     switch(mode){
  34.       case GR320:
  35.       case EGA_D:
  36.       grcols_ = 320;
  37.       grrows_ = 200;
  38.       break;
  39.       case GR640:
  40.       case EGA_E:
  41.       grcols_ = 640;
  42.       grrows_ = 200;
  43.       break;
  44.       case EGA_10:
  45.       case EGA_F:
  46.       grcols_ = 640;
  47.       grrows_ = 350;
  48.       break;
  49.       }
  50.  
  51.       if (palette || !grfpal_)
  52.       gr_palette(palette);  /* set the graphics palette */
  53.       if(bcolr)
  54.       gr_bcolor(bcolr);
  55.       if (fcolr)
  56.       gr_pen(NUL,fcolr);
  57.  
  58.       grx_=gry_=gr_minx_=gr_miny_=0;
  59.       gr_windo(0,0,grcols_-1,grrows_-1);
  60.       scolst_ = srowst_ = 0;
  61.       scolen_ = sc_cols_-1;
  62.       srowen_ = sc_rows_-1;
  63.       sc_windo(scolst_,srowst_,scolen_,srowen_);      /* full screen */
  64.       sc_setcur(0,0);                                                                         /* home cursor */
  65.       scrollf_=wrapf_= TRUE;  /* set wrap     & scroll on */
  66.       nlexpf_ = TRUE;         /* \n expansion on  */
  67. }
  68.  
  69.  
  70. /********
  71.  *
  72.  *   gr_palette(palette) - set graphics palette
  73.  *
  74.  **/
  75.  
  76. void gr_palette(char *palette)
  77. {
  78.     union REGS inregs,outregs;
  79.     struct SREGS segregs;
  80.  
  81.     if( (sc_adp_&CGA_ADP) || ((sc_adp_&EGA_ADP) && (sc_mode_<7))) {
  82.     /* check for EGA */
  83.  
  84.     if(!palette)
  85.         palette = gr_cgap0_;
  86.     inregs.h.bl = palette[16];       /* for CGA, palette is 0 or 1 only */
  87.     inregs.h.bh = 1;
  88.     inregs.h.ah = 11;
  89.        int86(IVIDEO,&inregs,&outregs);
  90.     }
  91.     else if(sc_adp_&EGA_ADP) {
  92.  
  93.     if(!palette)
  94.         palette = gr_egap_;
  95.     segread(&segregs);
  96.     inregs.h.al = 2;                /* set all palette and overscan */
  97.     inregs.x.dx = sy_doff(palette);
  98.     inregs.h.ah = 16;               /* set palette command */
  99.     inregs.x.bx = 0;
  100.     segregs.es = sy_dseg(palette);
  101.     int86x(IVIDEO,&inregs,&outregs,&segregs);
  102.     }
  103.     grfpal_ = palette;
  104. }
  105.  
  106.  
  107. /********
  108.  *
  109.  *   gr_bcolor(bcolr) - set background color
  110.  *
  111.  **/
  112.  
  113. void gr_bcolor(char bcolr)
  114. {
  115.     union REGS inregs,outregs;
  116.  
  117.     grbcolr_ = bcolr;
  118.     if( (sc_adp_&CGA_ADP) || ((sc_adp_&EGA_ADP) && (sc_mode_<7)) ) {
  119.     /* check for EGA */
  120.     inregs.h.ah = 0xb;              /* set color palette CGA         */
  121.     inregs.h.bh = 0;                /* set background color         */
  122.     inregs.h.bl = grbcolr_;
  123.     }
  124.     else if (sc_adp_&EGA_ADP) {
  125.     inregs.h.ah = 0x10;             /* set color palette             */
  126.     inregs.h.al = 0;                /* set background               */
  127.     inregs.h.bh = grbcolr_;
  128.     inregs.h.bl = 0;                /* enable intensity             */
  129.     }
  130.     int86(IVIDEO,&inregs,&outregs);
  131.     sc_color(grfcolr_,bcolr);           /* set text color attribute     */
  132. }
  133.  
  134.  
  135. /********
  136.  *
  137.  *   gr_color(fcolr,bcolr) - set foreground & background color palette
  138.  *
  139.  **/
  140.  
  141. void gr_color(char fcolr, char bcolr)
  142.     gr_pen(0,fcolr);
  143.     gr_bcolor(bcolr);
  144. }
  145.  
  146.  
  147. /********
  148.  *
  149.  *   gr_pen(xorf,color) - set graphics pen
  150.  *
  151.  **/
  152.  
  153. void gr_pen(int xorf, int color)
  154. {
  155.     grfcolr_ = color;
  156.     if ((sc_adp_&EGA_ADP) && (sc_mode_>7))
  157.     grfcol_ =  color;             /* in EGA modes write using the value */
  158.     else
  159.     grfcol_=grfpal_[color];       /* in CGA modes write using the index */
  160.  
  161.     (!xorf)? (grxorf_=0):(grxorf_=0x80);
  162.     sc_color(color,grbcolr_);         /* set text to correct color          */
  163. }
  164.  
  165.  
  166. /********
  167.  *
  168.  *   gr_pos(x,y) - set graphics pen to x,y
  169.  *
  170.  **/
  171.  
  172. void gr_pos(int x, int y)
  173. {
  174.     gr_clip(&x,&y);
  175.     grx_ = x;
  176.     gry_ = y;
  177. }
  178.  
  179.  
  180. /********
  181.  *
  182.  *   gr_setpt(x,y) - set point at x,y
  183.  *
  184.  **/
  185.  
  186. void gr_setpt(int x, int y)
  187. {
  188.     gr_clip(&x,&y);
  189.     gr_pt_(x,y);
  190.     grx_ =x, gry_ = y;
  191. }
  192.  
  193.  
  194. /********
  195.  *
  196.  *   gr_xorp(x,y) - xor point at x,y
  197.  *
  198.  **/
  199.  
  200. void gr_xorp(int x, int y)
  201. {
  202.     int oxorf;
  203.  
  204.     oxorf = grxorf_;
  205.     grxorf_=TRUE;
  206.     gr_setpt(x,y);
  207.     grxorf_= oxorf;
  208. }
  209.  
  210.  
  211. /********
  212.  *
  213.  *   gr_getpt(x,y) - get color of point at x,y
  214.  *
  215.  **/
  216.  
  217. int gr_getpt(int x, int y)
  218. {
  219.     gr_clip(&x,&y);
  220.     return(gr_gpt_(x,y));
  221. }
  222.  
  223.  
  224. /********
  225.  *
  226.  *   gr_putpt(x,y,color) - put color at point  x,y
  227.  *
  228.  **/
  229.  
  230. void gr_putpt(int x, int y, char color)
  231. {
  232.     gr_pen(NUL,color);
  233.     gr_setpt(x,y);
  234. }
  235.  
  236.  
  237. /********
  238.  *
  239.  *   gr_getwin() - get graphics windo
  240.  *
  241.  **/
  242.  
  243. char *gr_getwin(int x1, int y1, int x2, int y2)
  244. {
  245.     extern char *malloc();
  246.     char *ptr;                                                                                              /* pointer to windo buffer */
  247.  
  248.     gr_wpush();                                                                                     /* save current windo */
  249.     gr_windo(x1,y1,x2,y2);                   /* set current windo */
  250.     ptr = malloc((x2-(--x1))*(y2-(--y1)));   /* buffer size for windo */
  251.     gr_gwin_(ptr);
  252.     gr_wpop();                                                                                      /* restore previous windo */
  253.     return(ptr);
  254. }
  255.  
  256.  
  257. /********
  258.  *
  259.  *   gr_putwin(buff,x1,y1,x2,y2) - put graphics windo
  260.  *
  261.  **/
  262.  
  263. void gr_putwin(char *buff, int x1, int y1, int x2, int y2)
  264. {
  265.     gr_wpush();                 /* save current windo     */
  266.     gr_windo(x1,y1,x2,y2);
  267.     gr_pwin_(buff);             /* put buffer to windo    */
  268.     gr_wpop();                  /* restore previous windo */
  269. }
  270.  
  271.  
  272. /********
  273.  *
  274.  *   gr_clip(x,y) - clip a point
  275.  *
  276.  **/
  277.  
  278. void gr_clip(int *x, int *y)
  279. {
  280.     *x = min(*x,gr_maxx_);
  281.     *x = max(*x,gr_minx_);
  282.     *y = min(*y,gr_maxy_);
  283.     *y = max(*y,gr_miny_);
  284. }
  285.  
  286.  
  287. /********
  288.  *
  289.  *   gr_line (x1,y1,x2,y2) - line from x1,y1 to x2,y2
  290.  *
  291.  **/
  292.  
  293. void gr_line(int x1, int y1,int x2,int y2)
  294. {
  295.     gr_clip(&x1,&y1);
  296.     gr_clip(&x2,&y2);
  297.     gr_ln_(x1,y1,x2,y2);
  298.     grx_ = x2, gry_ = y2;   /* update pen position*/
  299. }
  300.  
  301.  
  302. /********
  303.  *
  304.  *   gr_lineto(x,y) - line to x,y from current location
  305.  *
  306.  **/
  307.  
  308. void gr_lineto(int x, int y)
  309. {
  310.     gr_clip(&x,&y);
  311.     gr_ln_(grx_,gry_,x,y);
  312.     grx_ = x, gry_ = y;     /* update pen position*/
  313. }
  314.  
  315.  
  316.