home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2872 / tty.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  6.8 KB  |  349 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. extern void tcapopen ();
  17. extern void tcapmove ();
  18.  
  19. #if     GOSLING
  20. void    ttinsl ();
  21. void    ttdell ();
  22. #endif
  23.  
  24. #include    "lintfunc.dec"
  25. #if MSDOS
  26. #include    "dos.h"
  27. extern  bool    ibm_pc, mem_map;
  28. #endif
  29. #define BEL     0x07            /* BEL character.               */
  30. #define ESC     0x1B            /* ESC character.               */
  31.  
  32. extern int  ttrow;
  33. extern int  ttcol;
  34. extern int  tttop;
  35. extern int  ttbot;
  36. extern int  tthue;
  37.  
  38. int     tceeol = 3;             /* Costs.                       */
  39. int     rowb = NROW;  
  40.  
  41. /*
  42. * Initialize the terminal when the editor
  43. * gets started up.
  44. */
  45. void    ttinit ()
  46. {
  47. #if MSDOS
  48.     ttraw ();
  49. #endif
  50. #if UNIX 
  51.     tcapopen();
  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. #if MSDOS
  62.     ttcooked ();
  63. #endif
  64. }
  65.  
  66. /*
  67. * Move the cursor to the specified
  68. * origin 0 row and column position. Try to
  69. * optimize out extra moves; redisplay may
  70. * have left the cursor in the right
  71. * location last time!
  72. */
  73. void    ttmove (row, col)
  74. {
  75. #if MSDOS
  76.     union   REGS    regs;
  77.  
  78. /* Move in both axes */
  79.     if (ibm_pc)
  80.         {
  81.         regs.h.ah = 2;
  82.         regs.h.dh = (char)row;
  83.         regs.h.dl = (char)col;
  84.         regs.h.bh = 0;
  85.         int86 (0x10, ®s, ®s); /* set cursor position */
  86.         }
  87.     else
  88. #endif
  89. #if UNIX
  90.     tcapmove(row, col);
  91. #endif
  92. #if ANSI
  93.         {
  94.         ttputc (ESC);
  95.         ttputc ('[');
  96.         asciiparm (row + 1);
  97.         ttputc (';');
  98.         asciiparm (col + 1);
  99.         ttputc ('H');
  100.         }
  101. #endif
  102.     ttrow = row;
  103.     ttcol = col;
  104. }
  105.  
  106. /*
  107. * Erase to end of line.
  108. */
  109. void    tteeol ()
  110. {
  111.     char    col, row, i;
  112. #if MSDOS
  113.     union   REGS    regs;
  114.  
  115.     if (ibm_pc)
  116.         {
  117.         regs.h.ah = 3;
  118.         regs.h.bh = 0;
  119.         int86 (0x10, ®s, ®s); /* get cursor position */
  120.         col = regs.h.dl;    
  121.         row = regs.h.dh;
  122.         for (i = col ; i < (NCOL - 1); i++)
  123.             {
  124.             regs.h.ah = 0x0e;
  125.             regs.h.bl = 0;
  126.             regs.h.bh = 0;
  127.             regs.h.al = ' ';
  128.             int86 (0x10, ®s, ®s); /* set cursor position */
  129.             }
  130.         /* put cursor back to original position */
  131.         regs.h.ah = 2;
  132.         regs.h.bh = 0;
  133.         regs.h.dl = col;    
  134.         regs.h.dh = row;
  135.         int86 (0x10, ®s, ®s); /* get cursor position */
  136.         }
  137.     else
  138. #endif
  139. #if ANSI
  140.         {
  141.         ttputc (ESC);
  142.         ttputc ('[');
  143. #if MSDOS
  144.         if (ibm_pc)
  145.            ttputc ('0');    /* this is necessary in IBM PC's */
  146. #endif
  147.         ttputc ('K');
  148.         }
  149. #endif
  150. #if UNIX
  151.     tcapeeol();
  152. #endif
  153.     }
  154.  
  155. /*
  156. * Erase to end of page.
  157. * only ever used when cursor is at 0,0, so IBM screen erase
  158. * is same as eop
  159. */
  160. void    tteeop ()
  161. {
  162. #if MSDOS
  163.     union   REGS    regs;
  164.     char    i, j;
  165.  
  166.     if (ibm_pc)
  167.         {
  168.         for (j = 0 ; j < nrow; j++)
  169.             {
  170.             for (i = 0 ; i < NCOL; i++)
  171.                 {
  172.                 regs.h.ah = 0x0e;
  173.                 regs.h.bl = 0;
  174.                 regs.h.bh = 0;
  175.                 regs.h.al = ' ';
  176.                 int86 (0x10, ®s, ®s); /* set cursor position */
  177.                 }
  178.             }
  179.         }
  180.     else
  181. #endif
  182. #if    ANSI
  183.         {
  184.         ttcolor (CTEXT);
  185.         ttputc (ESC);
  186.         ttputc ('[');
  187. #if MSDOS
  188.         if (ibm_pc)
  189.             ttputc ('0');
  190.         else
  191. #endif
  192.             ttputc ('2');
  193.         ttputc ('J');
  194.         }
  195. #endif
  196. #if UNIX
  197.     tcapeeop();
  198. #endif
  199. }
  200.  
  201. /*
  202. * Make a noise.
  203. */
  204. void    ttbeep ()
  205. {
  206.     ttputc (BEL);
  207.     ttflush ();
  208. }
  209.  
  210. /*
  211. * Convert a number to decimal
  212. * ascii, and write it out. Used to
  213. * deal with numeric arguments.
  214. */
  215. void    asciiparm (n)
  216. register int    n;
  217. {
  218.     register int    q;
  219.  
  220.     q = n / 10;
  221.     if (q != 0)
  222.         asciiparm (q);
  223.     ttputc ((n % 10) + '0');
  224. }
  225.  
  226. #if     GOSLING
  227. /*
  228. * Insert a block of blank lines onto the
  229. * screen, using a scrolling region that starts at row
  230. * "row" and extends down to row "bot".  Deal with the one
  231. * line case, which is a little bit special, with special
  232. * case code.
  233. */
  234. void    ttinsl (row, bot, nchunk)
  235. {
  236.     if (row == bot)
  237.         {
  238.     /* Funny case.          */
  239.         if (nchunk != 1)
  240.             abort ();
  241.         ttmove (row, 0);
  242.         tteeol ();
  243.         }
  244.     else
  245.         {
  246.     /* General case.        */
  247.         ttputc (ESC);
  248.         ttputc ('/');
  249.         asciiparm (row + 1);
  250.         ttputc (';');
  251.         asciiparm (bot + 1);
  252.         ttputc (';');
  253.         asciiparm (nchunk);
  254.         ttputc (';');
  255.         ttputc ('0');
  256.         ttputc ('S');
  257.         }
  258. }
  259.  
  260. /*
  261. * Delete a block of lines, with the uppermost
  262. * line at row "row", in a screen slice that extends to
  263. * row "bot". The "nchunk" is the number of lines that have
  264. * to be deleted.  Watch for the pathalogical 1 line case,
  265. * where the scroll region is *not* the way to do it.
  266. * The block delete is used by the slightly more
  267. * optimal display code.
  268. */
  269. void    ttdell (row, bot, nchunk)
  270. {
  271.     if (row == bot)
  272.         {
  273.     /* Funny case.          */
  274.         if (nchunk != 1)
  275.             abort ();
  276.         ttmove (row, 0);
  277.         tteeol ();
  278.         }
  279.     else
  280.         {
  281.     /* General case.        */
  282.         ttputc (ESC);
  283.         ttputc ('/');
  284.         asciiparm (row + 1);
  285.         ttputc (';');
  286.         asciiparm (bot + 1);
  287.         ttputc (';');
  288.         asciiparm (nchunk);
  289.         ttputc (';');
  290.         ttputc ('1');
  291.         ttputc ('S');
  292.         }
  293. }
  294. #endif
  295.  
  296. /*
  297. * Switch to full screen scroll. This is
  298. * used by "spawn.c" just before is suspends the
  299. * editor, and by "display.c" when it is getting ready
  300. * to exit.  This is a no-op.
  301. */
  302. void    ttnowindow (){}
  303.  
  304. /*
  305. * Set the current writing color to the
  306. * specified color. Watch for color changes that are
  307. * not going to do anything (the color is already right)
  308. * and don't send anything to the display.
  309. */
  310. void    ttcolor (color)
  311. register int    color;
  312. {
  313. #if MSDOS
  314.     if (mem_map)
  315.         {
  316.         tthue = color;          /* Save the color.      */
  317.         return;
  318.         }
  319. #endif
  320. #if UNIX
  321.     if (color == CTEXT)
  322.         tcaprev (FALSE);
  323.     else    
  324.         tcaprev (TRUE);
  325.     tthue = color;          /* Save the color.      */
  326. #endif
  327. #if ANSI
  328.     if (color != tthue)
  329.         {
  330.         if (color == CTEXT)
  331.             {                   /* Normal video.        */
  332.             ttputc (ESC);
  333.             ttputc ('[');
  334.             ttputc ('0');
  335.             ttputc ('m');
  336.             }
  337.         else
  338.             if (color == CMODE)
  339.                 {               /* Reverse video.       */
  340.                 ttputc (ESC);
  341.                 ttputc ('[');
  342.                 ttputc ('7');
  343.                 ttputc ('m');
  344.                 }
  345.         tthue = color;          /* Save the color.      */
  346.         }
  347. #endif
  348. }
  349.