home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_02 / tipc.c < prev    next >
C/C++ Source or Header  |  1990-01-23  |  6KB  |  213 lines

  1. /*
  2.  * The routines in this file provide support for the TI-PC and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not a TI-PC driver
  5.  */
  6.  
  7. #define termdef 1                       /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include        "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     TIPC
  14.  
  15. #define NROW    25                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define MARGIN  8                       /* size of minimim margin and   */
  18. #define SCRSIZ  64                      /* scroll size for extended lines */
  19. #define NPAUSE  200                     /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define SPACE   32                      /* space character              */
  23. #define SCADD   0xDE000L                /* address of screen RAM        */
  24.  
  25. #define CHAR_ENABLE     0x08            /* TI attribute to show char    */
  26. #define TI_REVERSE      0x10            /* TI attribute to reverse char */
  27. #define BLACK   0+CHAR_ENABLE           /* TI attribute for Black       */
  28. #define BLUE    1+CHAR_ENABLE           /* TI attribute for Blue        */
  29. #define RED     2+CHAR_ENABLE           /* TI attribute for Red         */
  30. #define MAGENTA 3+CHAR_ENABLE           /* TI attribute for Magenta     */
  31. #define GREEN   4+CHAR_ENABLE           /* TI attribute for Green       */
  32. #define CYAN    5+CHAR_ENABLE           /* TI attribute for Cyan        */
  33. #define YELLOW  6+CHAR_ENABLE           /* TI attribute for Yellow      */
  34. #define WHITE   7+CHAR_ENABLE           /* TI attribute for White       */
  35.  
  36.  
  37. extern  int     ttopen();               /* Forward references.          */
  38. extern  int     ttgetc();
  39. extern  int     ttputc();
  40. extern  int     ttflush();
  41. extern  int     ttclose();
  42. extern  int     timove();
  43. extern  int     tieeol();
  44. extern  int     tieeop();
  45. extern  int     tibeep();
  46. extern  int     tiopen();
  47. extern  int     tirev();
  48. extern    int    ticres();
  49. extern  int     ticlose();
  50. extern  int     tiputc();
  51.  
  52. #if     COLOR
  53. extern  int     tifcol();
  54. extern  int     tibcol();
  55.  
  56. int     cfcolor = -1;           /* current forground color */
  57. int     cbcolor = -1;           /* current background color */
  58. int     ctrans[] =              /* ansi to ti color translation table */
  59.         {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
  60. #endif
  61.  
  62. /*
  63.  * Standard terminal interface dispatch table. Most of the fields point into
  64.  * "termio" code.
  65.  */
  66. TERM    term    = {
  67.     NROW-1,
  68.         NROW-1,
  69.         NCOL,
  70.         NCOL,
  71.         MARGIN,
  72.         SCRSIZ,
  73.         NPAUSE,
  74.         tiopen,
  75.         ticlose,
  76.         ttgetc,
  77.         tiputc,
  78.         ttflush,
  79.         timove,
  80.         tieeol,
  81.         tieeop,
  82.         tibeep,
  83.         tirev,
  84.         ticres
  85. #if     COLOR
  86.         , tifcol,
  87.         tibcol
  88. #endif
  89. };
  90.  
  91. extern union REGS rg;
  92.  
  93. #if     COLOR
  94. setatt( attr )
  95. int attr;
  96. {
  97.         rg.h.ah = 0x16;         /* set the forground character attribute */
  98.         rg.h.bl = attr;
  99.         int86( 0x49, &rg, &rg );
  100. }
  101.  
  102. tifcol(color)           /* set the current output color */
  103.  
  104. int color;      /* color to set */
  105.  
  106. {
  107.         cfcolor = ctrans[color];
  108.         setatt ( cfcolor );
  109. }
  110.  
  111. tibcol(color)           /* set the current background color */
  112.  
  113. int color;      /* color to set */
  114.  
  115. {
  116.         cbcolor = ctrans[color];
  117. }
  118. #endif
  119.  
  120. timove(row, col)
  121. {
  122.         rg.h.ah = 2;            /* set cursor position function code */
  123.         rg.h.dh = col;
  124.         rg.h.dl = row;
  125.         int86(0x49, &rg, &rg);
  126. }
  127.  
  128. tieeol()        /* erase to the end of the line */
  129.  
  130. {
  131.         int ccol;       /* current column cursor lives */
  132.         int crow;       /*         row  */
  133.  
  134.         /* find the current cursor position */
  135.         rg.h.ah = 3;            /* read cursor position function code */
  136.         int86(0x49, &rg, &rg);
  137.         ccol = rg.h.dh;         /* record current column */
  138.         crow = rg.h.dl;         /* and row */
  139.  
  140.         rg.h.ah = 0x09;         /* Write character at cursor position */
  141.         rg.h.al = ' ';          /* Space */
  142.         rg.h.bl = cfcolor;
  143.         rg.x.cx = NCOL-ccol;    /* Number of characters to write */
  144.         int86(0x49, &rg, &rg);
  145.  
  146. }
  147.  
  148. tiputc(ch)      /* put a character at the current position in the
  149.                    current colors */
  150.  
  151. int ch;
  152.  
  153. {
  154.         rg.h.ah = 0x0E;         /* write char to screen with current attrs */
  155.         rg.h.al = ch;
  156.         int86(0x49, &rg, &rg);
  157. }
  158.  
  159. tieeop()                        /* Actually a clear screen */
  160. {
  161.  
  162.         rg.h.ah = 0x13;         /* Clear Text Screen and Home Cursor */
  163.         int86(0x49, &rg, &rg);
  164. }
  165.  
  166. tirev(state)            /* change reverse video state */
  167.  
  168. int state;      /* TRUE = reverse, FALSE = normal */
  169.  
  170. {
  171.         setatt( state ? cbcolor : cfcolor  );
  172. }
  173.  
  174. ticres()    /* change screen resolution */
  175.  
  176. {
  177.     return(TRUE);
  178. }
  179.  
  180. spal()        /* change palette string */
  181.  
  182. {
  183.     /*    Does nothing here    */
  184. }
  185.  
  186. tibeep()
  187. {
  188.         bdos(6, BEL, 0);
  189. }
  190.  
  191. tiopen()
  192. {
  193.     strcpy(sres, "NORMAL");
  194.         revexist = TRUE;
  195.         ttopen();
  196. }
  197.  
  198. ticlose()
  199.  
  200. {
  201. #if     COLOR
  202.         tifcol(7);
  203.         tibcol(0);
  204. #endif
  205.         ttclose();
  206. }
  207. #else
  208. tihello()
  209. {
  210. }
  211. #endif
  212.  
  213.