home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d023 / microemacs.lha / Ver30 / Tty / Intuition / tty.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-05-10  |  5.1 KB  |  266 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Amiga console device virtual terminal display
  4.  * Version:    31
  5.  * Last Edit:    19-Apr-86
  6.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  7.  *
  8.  * Drives the Amiga console device display.  The code is a combination
  9.  * of the Heath and ANSI terminal drivers.
  10.  */
  11. #include    "def.h"
  12.  
  13.  
  14. #define    BEL    0x07            /* BEL character.        */
  15. #define    ESC    0x1B            /* ESC character.        */
  16.  
  17. extern    int    ttrow;
  18. extern    int    ttcol;
  19. extern    int    tttop;
  20. extern    int    ttbot;
  21. extern    int    tthue;
  22.  
  23. int    tceeol    =    3;        /* Costs, ANSI display.        */
  24. int    tcinsl    =     17;
  25. int    tcdell    =    16;
  26.  
  27. /*
  28.  * Initialize the terminal when the editor
  29.  * gets started up. This is a no-op on the Amiga.
  30.  */
  31. ttinit()
  32. {
  33. }
  34.  
  35. /*
  36.  * Clean up the terminal, in anticipation of
  37.  * a return to the command interpreter. This is a no-op
  38.  * on the Amiga.
  39.  */
  40. tttidy()
  41. {
  42. }
  43.  
  44. /*
  45.  * Move the cursor to the specified
  46.  * origin 0 row and column position. Try to
  47.  * optimize out extra moves; redisplay may
  48.  * have left the cursor in the right
  49.  * location last time!
  50.  */
  51. ttmove(row, col)
  52. {
  53.     if (ttrow!=row || ttcol!=col) {
  54.         ttputc(ESC);
  55.         ttputc('[');
  56.         asciiparm(row+1);
  57.         ttputc(';');
  58.         asciiparm(col+1);
  59.         ttputc('H');
  60.         ttrow = row;
  61.         ttcol = col;
  62.     }
  63. }
  64.  
  65. /*
  66.  * Erase to end of line.
  67.  */
  68. tteeol()
  69. {
  70.     ttputc(ESC);
  71.     ttputc('[');
  72.     ttputc('K');
  73. }
  74.  
  75. /*
  76.  * Erase to end of page.
  77.  */
  78. tteeop()
  79. {
  80.     ttputc(ESC);
  81.     ttputc('[');
  82.     ttputc('J');
  83. }
  84.  
  85. /*
  86.  * Make a noise.
  87.  */
  88. ttbeep()
  89. {
  90.     ttputc(BEL);
  91.     ttflush();
  92. }
  93.  
  94. /*
  95.  * Convert a number to decimal
  96.  * ascii, and write it out. Used to
  97.  * deal with numeric arguments.
  98.  */
  99. asciiparm(n)
  100. register int    n;
  101. {
  102.     register int    q;
  103.  
  104.     q = n/10;
  105.     if (q != 0)
  106.         asciiparm(q);
  107.     ttputc((n%10) + '0');
  108. }
  109.  
  110. /*
  111.  * Insert a block of blank lines onto the
  112.  * screen, using a scrolling region that starts at row
  113.  * "row" and extends down to row "bot". Deal with the one
  114.  * line case, which is a little bit special, with special
  115.  * case code.
  116.  * Since we don't really have a scrolling region,
  117.  * delete the block of lines that would have been deleted if
  118.  * we'd had one, then insert blank lines to move the rest
  119.  * of the screen back to where it belongs.  This idea from
  120.  * the Heath driver.
  121.  */
  122. VOID ttinsl(row, bot, nchunk)
  123. {
  124.     if (row == bot) {            /* Funny case.        */
  125.         if (nchunk != 1)
  126.             abort();
  127.         ttmove(row, 0);
  128.         tteeol();
  129.         return;
  130.     } 
  131.     ttmove(1+bot-nchunk, 0);
  132.     if (nchunk > 0) {        /* Delete a chunk of lines    */
  133.         ttputc(ESC);        /* nchunk in size.  Rest of    */
  134.         ttputc('[');        /* screen moves up.        */
  135.         asciiparm(nchunk);
  136.         ttputc('M');
  137.     }
  138.     ttmove(row, 0);
  139.     if (nchunk > 0) {        /* Insert a chunk nchunk in size*/
  140.         ttputc(ESC);        /* before current line,    sliding    */
  141.         ttputc('[');        /* rest of screen down.        */
  142.         asciiparm(nchunk);
  143.         ttputc('L');
  144.     }
  145.     ttrow = row;            /* End up on current line    */
  146.     ttcol = 0;
  147. }
  148.  
  149. /*
  150.  * Delete a block of lines, with the uppermost
  151.  * line at row "row", in a screen slice that extends to
  152.  * row "bot". The "nchunk" is the number of lines that have
  153.  * to be deleted.  This is done by deleting nchunk lines at the
  154.  * appropriate spot, then inserting nchunk lines to make up for
  155.  * the empty space at the bottom of the virtual scrolling region.
  156.  */
  157. VOID ttdell(row, bot, nchunk)
  158. {
  159.     if (row == bot) {        /* One line special case    */
  160.         ttmove(row, 0);
  161.         tteeol();
  162.         return;
  163.     }
  164.     if (nchunk > 0) {
  165.         ttmove(row, 0);
  166.         ttputc(ESC);
  167.         ttputc('[');
  168.         asciiparm(nchunk);
  169.         ttputc('M');
  170.     }
  171.     ttmove(1+bot-nchunk,0);
  172.     if (nchunk > 0) {
  173.         ttputc(ESC);        /* For all lines in chunk    */
  174.         ttputc('[');        /* INS line before bottom    */
  175.         asciiparm(nchunk);    /* Bottom of window (and rest     */
  176.         ttputc('L');        /* of screen) moves down */
  177.     }
  178.     ttrow = HUGE;
  179.     ttcol = HUGE;
  180.     ttmove(bot-nchunk,0);
  181. }
  182.  
  183. /*
  184.  * No-op.
  185.  */
  186. ttwindow(top,bot)
  187. {
  188. }
  189.  
  190. /*
  191.  * No-op.
  192.  */
  193. ttnowindow()
  194. {
  195. }
  196.  
  197. /*
  198.  * Set the current writing color to the
  199.  * specified color. Watch for color changes that are
  200.  * not going to do anything (the color is already right)
  201.  * and don't send anything to the display.
  202.  */
  203. ttcolor(color)
  204. register int    color;
  205. {
  206.     if (color != tthue) {
  207.         if (color == CTEXT) {        /* Normal video.    */
  208.             ttputc(ESC);
  209.             ttputc('[');
  210.             ttputc('m');
  211.         } else if (color == CMODE) {    /* Reverse video.    */
  212.             ttputc(ESC);
  213.             ttputc('[');
  214.             ttputc('7');
  215.             ttputc('m');
  216.         }
  217.         tthue = color;            /* Save the color.    */
  218.     }
  219. }
  220.  
  221. /*
  222.  * This routine is called by the
  223.  * "refresh the screen" command to try and resize
  224.  * the display. The new size, which must be deadstopped
  225.  * to not exceed the NROW and NCOL limits, is stored
  226.  * back into "nrow" and "ncol". Display can always deal
  227.  * with a screen NROW by NCOL. Look in "window.c" to
  228.  * see how the caller deals with a change.
  229.  */
  230. #define    CSI    0x9B
  231.  
  232. extern    int    ttsize();        /* Defined by "ttyio.c"    */
  233.  
  234. ttresize()
  235. {
  236.     int newnrow, newncol;
  237.  
  238.     ttsize(&newnrow,&newncol);        /* ask tty how big it is */
  239.  
  240.     if (newnrow < 1)            /* check limits.     */
  241.         newnrow = 1;
  242.     else if (newnrow > NROW)
  243.         newnrow = NROW;
  244.     if (newncol < 1)
  245.         newncol = 1;
  246.     else if (newncol > NCOL)
  247.         newncol = NCOL;
  248.     nrow = newnrow;
  249.     ncol = newncol;
  250. }
  251.  
  252. /*
  253.  * Read an unsigned parameter from the console
  254.  */
  255. static readparm(delim)
  256. char delim;
  257. {
  258.     register int     parm;
  259.     register int    c;
  260.  
  261.     parm = 0;
  262.     while ((c=ttgetc()) >= '0' && c <= '9')
  263.         parm = 10 * parm + c - '0';
  264.     return (c == delim) ? parm : -1;
  265. }
  266.