home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / OS2 / BEAV132X.ZIP / TTY.C < prev    next >
C/C++ Source or Header  |  1992-01-06  |  5KB  |  289 lines

  1. /*
  2. *    Wang PC terminal display        TTY.C
  3. *
  4. */
  5. #include        "def.h"
  6.  
  7. void    ttinit ();
  8. void    tttidy ();
  9. void    ttmove ();
  10. void    tteeol ();
  11. void    tteeop ();
  12. void    ttbeep ();
  13. void    asciiparm ();
  14. void    ttnowindow ();    /* stub */
  15. void    ttcolor ();
  16. int    tcapopen ();
  17. int    tcapmove ();
  18.  
  19. #ifdef MSDOS
  20. #include    "dos.h"
  21. extern  bool    ibm_pc, mem_map;
  22. #endif
  23. #define BEL     0x07            /* BEL character.               */
  24. #define ESC     0x1B            /* ESC character.               */
  25.  
  26. extern int  ttrow;
  27. extern int  ttcol;
  28. extern int  tttop;
  29. extern int  ttbot;
  30. extern int  tthue;
  31.  
  32. int     tceeol = 3;             /* Costs.                       */
  33. int     rowb = NROW;
  34.  
  35. /*
  36. * Initialize the terminal when the editor
  37. * gets started up.
  38. */
  39. void    ttinit ()
  40. {
  41. #ifdef MSDOS
  42.     ttraw ();
  43. #endif
  44. #ifdef OS2
  45.     ttraw ();
  46. #endif
  47. #ifdef UNIX
  48.     tcapopen();
  49.     tcapinit(1);
  50.     tcapmove(0, 0);
  51.     tcapeeop();
  52. #endif
  53. }
  54.  
  55. /*
  56. * Clean up the terminal, in anticipation of
  57. * a return to the command interpreter.
  58. */
  59. void    tttidy ()
  60. {
  61. #ifdef MSDOS
  62.     ttcooked ();
  63. #endif
  64. #ifdef OS2
  65.     ttcooked ();
  66. #endif
  67. #ifdef UNIX
  68.     tcapinit(0);
  69.     tcapmove(0, 0);
  70.     tcapeeop();
  71. #endif
  72. }
  73.  
  74. /*
  75. * Move the cursor to the specified
  76. * origin 0 row and column position. Try to
  77. * optimize out extra moves; redisplay may
  78. * have left the cursor in the right
  79. * location last time!
  80. */
  81. void    ttmove (row, col)
  82. int row, col;
  83. {
  84. #ifdef MSDOS
  85.     union   REGS    regs;
  86.  
  87.     /* Move in both axes */
  88.     if (ibm_pc)
  89.     {
  90.         regs.h.ah = 2;
  91.         regs.h.dh = (char)row;
  92.         regs.h.dl = (char)col;
  93.         regs.h.bh = 0;
  94.         int86 (0x10, ®s, ®s); /* set cursor position */
  95.     }
  96.     else
  97. #endif
  98. #ifdef UNIX
  99.         tcapmove(row, col);
  100. #endif
  101. #ifdef ANSI
  102.     {
  103.         ttputc (ESC);
  104.         ttputc ('[');
  105.         asciiparm (row + 1);
  106.         ttputc (';');
  107.         asciiparm (col + 1);
  108.         ttputc ('H');
  109.     }
  110. #endif
  111.     ttrow = row;
  112.     ttcol = col;
  113. }
  114.  
  115. /*
  116. * Erase to end of line.
  117. */
  118. void    tteeol ()
  119. {
  120.     char    col, row, i;
  121. #ifdef MSDOS
  122.     union   REGS    regs;
  123.  
  124.     if (ibm_pc)
  125.     {
  126.         regs.h.ah = 3;
  127.         regs.h.bh = 0;
  128.         int86 (0x10, ®s, ®s); /* get cursor position */
  129.         col = regs.h.dl;
  130.         row = regs.h.dh;
  131.         for (i = col ; i < (NCOL - 1); i++)
  132.         {
  133.             regs.h.ah = 0x0e;
  134.             regs.h.bl = 0;
  135.             regs.h.bh = 0;
  136.             regs.h.al = ' ';
  137.             int86 (0x10, ®s, ®s); /* set cursor position */
  138.         }
  139.         /* put cursor back to original position */
  140.         regs.h.ah = 2;
  141.         regs.h.bh = 0;
  142.         regs.h.dl = col;
  143.         regs.h.dh = row;
  144.         int86 (0x10, ®s, ®s); /* get cursor position */
  145.     }
  146.     else
  147. #endif
  148. #ifdef ANSI
  149.         {
  150.             ttputc (ESC);
  151.             ttputc ('[');
  152. #ifdef MSDOS
  153.             if (ibm_pc)
  154.                 ttputc ('0');    /* this is necessary in IBM PC's */
  155. #endif
  156.             ttputc ('K');
  157.         }
  158. #endif
  159. #ifdef UNIX
  160.     tcapeeol();
  161. #endif
  162. }
  163.  
  164. /*
  165. * Erase to end of page.
  166. * only ever used when cursor is at 0,0, so IBM screen erase
  167. * is same as eop
  168. */
  169. void    tteeop ()
  170. {
  171. #ifdef MSDOS
  172.     union   REGS    regs;
  173.     char    i, j;
  174.  
  175.     if (ibm_pc)
  176.     {
  177.         for (j = 0 ; j < nrow; j++)
  178.         {
  179.             for (i = 0 ; i < NCOL; i++)
  180.             {
  181.                 regs.h.ah = 0x0e;
  182.                 regs.h.bl = 0;
  183.                 regs.h.bh = 0;
  184.                 regs.h.al = ' ';
  185.                 int86 (0x10, ®s, ®s); /* set cursor position */
  186.             }
  187.         }
  188.     }
  189.     else
  190. #endif
  191. #ifdef    ANSI
  192.         {
  193.             ttcolor (CTEXT);
  194.             ttputc (ESC);
  195.             ttputc ('[');
  196. #ifdef MSDOS
  197.             if (ibm_pc)
  198.                 ttputc ('0');
  199.             else
  200. #endif
  201.                 ttputc ('2');
  202.             ttputc ('J');
  203.         }
  204. #endif
  205. #ifdef UNIX
  206.     tcapeeop();
  207. #endif
  208. }
  209.  
  210. /*
  211. * Make a noise.
  212. */
  213. void    ttbeep ()
  214. {
  215.     ttputc (BEL);
  216.     ttflush ();
  217. }
  218.  
  219. /*
  220. * Convert a number to decimal
  221. * ascii, and write it out. Used to
  222. * deal with numeric arguments.
  223. */
  224. void    asciiparm (n)
  225. register int    n;
  226. {
  227.     register int    q;
  228.  
  229.     q = n / 10;
  230.     if (q != 0)
  231.         asciiparm (q);
  232.     ttputc ((n % 10) + '0');
  233. }
  234.  
  235. /*
  236. * Switch to full screen scroll. This is
  237. * used by "spawn.c" just before is suspends the
  238. * editor, and by "display.c" when it is getting ready
  239. * to exit.  This is a no-op.
  240. */
  241. void    ttnowindow (){
  242. }
  243.  
  244. /*
  245. * Set the current writing color to the
  246. * specified color. Watch for color changes that are
  247. * not going to do anything (the color is already right)
  248. * and don't send anything to the display.
  249. */
  250. void    ttcolor (color)
  251. register int    color;
  252. {
  253. #ifdef MSDOS
  254.     if (mem_map)
  255.     {
  256.         tthue = color;          /* Save the color.      */
  257.         return;
  258.     }
  259. #endif
  260. #ifdef UNIX
  261.     if (color == CTEXT)
  262.         tcaprev (FALSE);
  263.     else
  264.         tcaprev (TRUE);
  265.     tthue = color;          /* Save the color.      */
  266. #endif
  267. #ifdef ANSI
  268.     if (color != tthue)
  269.     {
  270.         if (color == CTEXT)
  271.         {                   /* Normal video.        */
  272.             ttputc (ESC);
  273.             ttputc ('[');
  274.             ttputc ('0');
  275.             ttputc ('m');
  276.         }
  277.         else
  278.             if (color == CMODE)
  279.             {               /* Reverse video.       */
  280.                 ttputc (ESC);
  281.                 ttputc ('[');
  282.                 ttputc ('7');
  283.                 ttputc ('m');
  284.             }
  285.         tthue = color;          /* Save the color.      */
  286.     }
  287. #endif
  288. }
  289.