home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / beav1402.zip / tty.c < prev    next >
Text File  |  1993-04-16  |  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. extern void tcapopen ();
  17. extern void tcapclose ();    /* DR */
  18. extern void tcapmove ();
  19.  
  20. #ifdef MSDOS
  21. #include    "dos.h"
  22. extern bool ibm_pc, mem_map;
  23. #endif
  24. #define BEL     0x07        /* BEL character.               */
  25. #define ESC     0x1B        /* ESC character.               */
  26.  
  27. extern int ttrow;
  28. extern int ttcol;
  29. extern int tttop;
  30. extern int ttbot;
  31. extern int tthue;
  32.  
  33. int tceeol = 3;            /* Costs.                       */
  34.  
  35. /*
  36. * Initialize the terminal when the editor
  37. * gets started up.
  38. */
  39. void
  40. ttinit ()
  41. {
  42. #ifdef MSDOS
  43.     ttraw ();
  44. #endif
  45. #ifdef OS2
  46.     ttraw ();
  47. #endif
  48. #ifdef UNIX
  49.     tcapopen ();
  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
  60. tttidy ()
  61. {
  62. #ifdef MSDOS
  63.     ttcooked ();
  64. #endif
  65. #ifdef OS2
  66.     ttcooked ();
  67. #endif
  68. #ifdef UNIX
  69.     tcapclose ();
  70. #endif
  71. }
  72.  
  73. /*
  74. * Move the cursor to the specified
  75. * origin 0 row and column position. Try to
  76. * optimize out extra moves; redisplay may
  77. * have left the cursor in the right
  78. * location last time!
  79. */
  80. void
  81. 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
  119. tteeol ()
  120. {
  121.     char col, row, i;
  122. #ifdef MSDOS
  123.     union REGS regs;
  124.  
  125.     if (ibm_pc)
  126.     {
  127.     regs.h.ah = 3;
  128.     regs.h.bh = 0;
  129.     int86 (0x10, ®s, ®s);    /* get cursor position */
  130.     col = regs.h.dl;
  131.     row = regs.h.dh;
  132.     for (i = col; i < (NCOL - 1); i++)
  133.     {
  134.         regs.h.ah = 0x0e;
  135.         regs.h.bl = 0;
  136.         regs.h.bh = 0;
  137.         regs.h.al = ' ';
  138.         int86 (0x10, ®s, ®s);    /* set cursor position */
  139.     }
  140.     /* put cursor back to original position */
  141.     regs.h.ah = 2;
  142.     regs.h.bh = 0;
  143.     regs.h.dl = col;
  144.     regs.h.dh = row;
  145.     int86 (0x10, ®s, ®s);    /* get cursor position */
  146.     }
  147.     else
  148. #endif
  149. #ifdef ANSI
  150.     {
  151.     ttputc (ESC);
  152.     ttputc ('[');
  153. #ifdef MSDOS
  154.     if (ibm_pc)
  155.         ttputc ('0');    /* this is necessary in IBM PC's */
  156. #endif
  157.     ttputc ('K');
  158.     }
  159. #endif
  160. #ifdef UNIX
  161.     tcapeeol ();
  162. #endif
  163. }
  164.  
  165. /*
  166. * Erase to end of page.
  167. * only ever used when cursor is at 0,0, so IBM screen erase
  168. * is same as eop
  169. */
  170. void
  171. tteeop ()
  172. {
  173. #ifdef MSDOS
  174.     union REGS regs;
  175.     char i, j;
  176.  
  177.     if (ibm_pc)
  178.     {
  179.     regs.h.ah = 6;
  180.     regs.h.al = 0;
  181.     regs.x.cx = 0;
  182.     regs.x.dx = (nrow << 8) | (NCOL - 1);
  183.     int86 (0x10, ®s, ®s);    /* scroll to clear screen */
  184.     }
  185.     else
  186. #endif
  187. #ifdef    ANSI
  188.     {
  189.     ttcolor (CTEXT);
  190.     ttputc (ESC);
  191.     ttputc ('[');
  192. #ifdef MSDOS
  193.     if (ibm_pc)
  194.         ttputc ('0');
  195.     else
  196. #endif
  197.         ttputc ('2');
  198.     ttputc ('J');
  199.     }
  200. #endif
  201. #ifdef UNIX
  202.     tcapeeop ();
  203. #endif
  204. }
  205.  
  206. /*
  207. * Make a noise.
  208. */
  209. void
  210. ttbeep ()
  211. {
  212.     ttputc (BEL);
  213.     ttflush ();
  214. }
  215.  
  216. /*
  217. * Convert a number to decimal
  218. * ascii, and write it out. Used to
  219. * deal with numeric arguments.
  220. */
  221. void
  222. asciiparm (n)
  223.     register int n;
  224. {
  225.     register int q;
  226.  
  227.     q = n / 10;
  228.     if (q != 0)
  229.     asciiparm (q);
  230.     ttputc ((n % 10) + '0');
  231. }
  232.  
  233. /*
  234. * Switch to full screen scroll. This is
  235. * used by "spawn.c" just before is suspends the
  236. * editor, and by "display.c" when it is getting ready
  237. * to exit.  This is a no-op.
  238. */
  239. void
  240. ttnowindow ()
  241. {
  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
  251. ttcolor (color)
  252.     register int color;
  253. {
  254. #ifdef MSDOS
  255.     if (mem_map)
  256.     {
  257.     tthue = color;        /* Save the color.      */
  258.     return;
  259.     }
  260. #endif
  261. #ifdef UNIX
  262.     if (color == CTEXT)
  263.     tcaprev (FALSE);
  264.     else
  265.     tcaprev (TRUE);
  266.     tthue = color;        /* Save the color.      */
  267. #endif
  268. #ifdef ANSI
  269.     if (color != tthue)
  270.     {
  271.     if (color == CTEXT)
  272.     {            /* Normal video.        */
  273.         ttputc (ESC);
  274.         ttputc ('[');
  275.         ttputc ('0');
  276.         ttputc ('m');
  277.     }
  278.     else 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.