home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / FILE / BEAV132S.ZIP / TTY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-08  |  4.7 KB  |  274 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. #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 UNIX 
  45.     tcapopen();
  46. #endif
  47. }
  48.  
  49. /*
  50. * Clean up the terminal, in anticipation of
  51. * a return to the command interpreter.
  52. */
  53. void    tttidy ()
  54. {
  55. #ifdef MSDOS
  56.     ttcooked ();
  57. #endif
  58. }
  59.  
  60. /*
  61. * Move the cursor to the specified
  62. * origin 0 row and column position. Try to
  63. * optimize out extra moves; redisplay may
  64. * have left the cursor in the right
  65. * location last time!
  66. */
  67. void    ttmove (row, col)
  68. {
  69. #ifdef MSDOS
  70.     union   REGS    regs;
  71.  
  72.     /* Move in both axes */
  73.     if (ibm_pc)
  74.     {
  75.         regs.h.ah = 2;
  76.         regs.h.dh = (char)row;
  77.         regs.h.dl = (char)col;
  78.         regs.h.bh = 0;
  79.         int86 (0x10, ®s, ®s); /* set cursor position */
  80.     }
  81.     else
  82. #endif
  83. #ifdef UNIX
  84.         tcapmove(row, col);
  85. #endif
  86. #ifdef ANSI
  87.     {
  88.         ttputc (ESC);
  89.         ttputc ('[');
  90.         asciiparm (row + 1);
  91.         ttputc (';');
  92.         asciiparm (col + 1);
  93.         ttputc ('H');
  94.     }
  95. #endif
  96.     ttrow = row;
  97.     ttcol = col;
  98. }
  99.  
  100. /*
  101. * Erase to end of line.
  102. */
  103. void    tteeol ()
  104. {
  105.     char    col, row, i;
  106. #ifdef MSDOS
  107.     union   REGS    regs;
  108.  
  109.     if (ibm_pc)
  110.     {
  111.         regs.h.ah = 3;
  112.         regs.h.bh = 0;
  113.         int86 (0x10, ®s, ®s); /* get cursor position */
  114.         col = regs.h.dl;
  115.         row = regs.h.dh;
  116.         for (i = col ; i < (NCOL - 1); i++)
  117.         {
  118.             regs.h.ah = 0x0e;
  119.             regs.h.bl = 0;
  120.             regs.h.bh = 0;
  121.             regs.h.al = ' ';
  122.             int86 (0x10, ®s, ®s); /* set cursor position */
  123.         }
  124.         /* put cursor back to original position */
  125.         regs.h.ah = 2;
  126.         regs.h.bh = 0;
  127.         regs.h.dl = col;
  128.         regs.h.dh = row;
  129.         int86 (0x10, ®s, ®s); /* get cursor position */
  130.     }
  131.     else
  132. #endif
  133. #ifdef ANSI
  134.         {
  135.             ttputc (ESC);
  136.             ttputc ('[');
  137. #ifdef MSDOS
  138.             if (ibm_pc)
  139.                 ttputc ('0');    /* this is necessary in IBM PC's */
  140. #endif
  141.             ttputc ('K');
  142.         }
  143. #endif
  144. #ifdef UNIX
  145.     tcapeeol();
  146. #endif
  147. }
  148.  
  149. /*
  150. * Erase to end of page.
  151. * only ever used when cursor is at 0,0, so IBM screen erase
  152. * is same as eop
  153. */
  154. void    tteeop ()
  155. {
  156. #ifdef MSDOS
  157.     union   REGS    regs;
  158.     char    i, j;
  159.  
  160.     if (ibm_pc)
  161.     {
  162.         for (j = 0 ; j < nrow; j++)
  163.         {
  164.             for (i = 0 ; i < NCOL; i++)
  165.             {
  166.                 regs.h.ah = 0x0e;
  167.                 regs.h.bl = 0;
  168.                 regs.h.bh = 0;
  169.                 regs.h.al = ' ';
  170.                 int86 (0x10, ®s, ®s); /* set cursor position */
  171.             }
  172.         }
  173.     }
  174.     else
  175. #endif
  176. #ifdef    ANSI
  177.         {
  178.             ttcolor (CTEXT);
  179.             ttputc (ESC);
  180.             ttputc ('[');
  181. #ifdef MSDOS
  182.             if (ibm_pc)
  183.                 ttputc ('0');
  184.             else
  185. #endif
  186.                 ttputc ('2');
  187.             ttputc ('J');
  188.         }
  189. #endif
  190. #ifdef UNIX
  191.     tcapeeop();
  192. #endif
  193. }
  194.  
  195. /*
  196. * Make a noise.
  197. */
  198. void    ttbeep ()
  199. {
  200.     ttputc (BEL);
  201.     ttflush ();
  202. }
  203.  
  204. /*
  205. * Convert a number to decimal
  206. * ascii, and write it out. Used to
  207. * deal with numeric arguments.
  208. */
  209. void    asciiparm (n)
  210. register int    n;
  211. {
  212.     register int    q;
  213.  
  214.     q = n / 10;
  215.     if (q != 0)
  216.         asciiparm (q);
  217.     ttputc ((n % 10) + '0');
  218. }
  219.  
  220. /*
  221. * Switch to full screen scroll. This is
  222. * used by "spawn.c" just before is suspends the
  223. * editor, and by "display.c" when it is getting ready
  224. * to exit.  This is a no-op.
  225. */
  226. void    ttnowindow (){
  227. }
  228.  
  229. /*
  230. * Set the current writing color to the
  231. * specified color. Watch for color changes that are
  232. * not going to do anything (the color is already right)
  233. * and don't send anything to the display.
  234. */
  235. void    ttcolor (color)
  236. register int    color;
  237. {
  238. #ifdef MSDOS
  239.     if (mem_map)
  240.     {
  241.         tthue = color;          /* Save the color.      */
  242.         return;
  243.     }
  244. #endif
  245. #ifdef UNIX
  246.     if (color == CTEXT)
  247.         tcaprev (FALSE);
  248.     else    
  249.         tcaprev (TRUE);
  250.     tthue = color;          /* Save the color.      */
  251. #endif
  252. #ifdef ANSI
  253.     if (color != tthue)
  254.     {
  255.         if (color == CTEXT)
  256.         {                   /* Normal video.        */
  257.             ttputc (ESC);
  258.             ttputc ('[');
  259.             ttputc ('0');
  260.             ttputc ('m');
  261.         }
  262.         else
  263.             if (color == CMODE)
  264.             {               /* Reverse video.       */
  265.                 ttputc (ESC);
  266.                 ttputc ('[');
  267.                 ttputc ('7');
  268.                 ttputc ('m');
  269.             }
  270.         tthue = color;          /* Save the color.      */
  271.     }
  272. #endif
  273. }
  274.