home *** CD-ROM | disk | FTP | other *** search
- /*
- * Wang PC terminal display TTY.C
- *
- */
- #include "def.h"
-
- void ttinit ();
- void tttidy ();
- void ttmove ();
- void tteeol ();
- void tteeop ();
- void ttbeep ();
- void asciiparm ();
- void ttnowindow (); /* stub */
- void ttcolor ();
- extern void tcapopen ();
- extern void tcapmove ();
-
- #if GOSLING
- void ttinsl ();
- void ttdell ();
- #endif
-
- #include "lintfunc.dec"
- #if MSDOS
- #include "dos.h"
- extern bool ibm_pc, mem_map;
- #endif
- #define BEL 0x07 /* BEL character. */
- #define ESC 0x1B /* ESC character. */
-
- extern int ttrow;
- extern int ttcol;
- extern int tttop;
- extern int ttbot;
- extern int tthue;
-
- int tceeol = 3; /* Costs. */
- int rowb = NROW;
-
- /*
- * Initialize the terminal when the editor
- * gets started up.
- */
- void ttinit ()
- {
- #if MSDOS
- ttraw ();
- #endif
- #if UNIX
- tcapopen();
- #endif
- }
-
- /*
- * Clean up the terminal, in anticipation of
- * a return to the command interpreter.
- */
- void tttidy ()
- {
- #if MSDOS
- ttcooked ();
- #endif
- }
-
- /*
- * Move the cursor to the specified
- * origin 0 row and column position. Try to
- * optimize out extra moves; redisplay may
- * have left the cursor in the right
- * location last time!
- */
- void ttmove (row, col)
- {
- #if MSDOS
- union REGS regs;
-
- /* Move in both axes */
- if (ibm_pc)
- {
- regs.h.ah = 2;
- regs.h.dh = (char)row;
- regs.h.dl = (char)col;
- regs.h.bh = 0;
- int86 (0x10, ®s, ®s); /* set cursor position */
- }
- else
- #endif
- #if UNIX
- tcapmove(row, col);
- #endif
- #if ANSI
- {
- ttputc (ESC);
- ttputc ('[');
- asciiparm (row + 1);
- ttputc (';');
- asciiparm (col + 1);
- ttputc ('H');
- }
- #endif
- ttrow = row;
- ttcol = col;
- }
-
- /*
- * Erase to end of line.
- */
- void tteeol ()
- {
- char col, row, i;
- #if MSDOS
- union REGS regs;
-
- if (ibm_pc)
- {
- regs.h.ah = 3;
- regs.h.bh = 0;
- int86 (0x10, ®s, ®s); /* get cursor position */
- col = regs.h.dl;
- row = regs.h.dh;
- for (i = col ; i < (NCOL - 1); i++)
- {
- regs.h.ah = 0x0e;
- regs.h.bl = 0;
- regs.h.bh = 0;
- regs.h.al = ' ';
- int86 (0x10, ®s, ®s); /* set cursor position */
- }
- /* put cursor back to original position */
- regs.h.ah = 2;
- regs.h.bh = 0;
- regs.h.dl = col;
- regs.h.dh = row;
- int86 (0x10, ®s, ®s); /* get cursor position */
- }
- else
- #endif
- #if ANSI
- {
- ttputc (ESC);
- ttputc ('[');
- #if MSDOS
- if (ibm_pc)
- ttputc ('0'); /* this is necessary in IBM PC's */
- #endif
- ttputc ('K');
- }
- #endif
- #if UNIX
- tcapeeol();
- #endif
- }
-
- /*
- * Erase to end of page.
- * only ever used when cursor is at 0,0, so IBM screen erase
- * is same as eop
- */
- void tteeop ()
- {
- #if MSDOS
- union REGS regs;
- char i, j;
-
- if (ibm_pc)
- {
- for (j = 0 ; j < nrow; j++)
- {
- for (i = 0 ; i < NCOL; i++)
- {
- regs.h.ah = 0x0e;
- regs.h.bl = 0;
- regs.h.bh = 0;
- regs.h.al = ' ';
- int86 (0x10, ®s, ®s); /* set cursor position */
- }
- }
- }
- else
- #endif
- #if ANSI
- {
- ttcolor (CTEXT);
- ttputc (ESC);
- ttputc ('[');
- #if MSDOS
- if (ibm_pc)
- ttputc ('0');
- else
- #endif
- ttputc ('2');
- ttputc ('J');
- }
- #endif
- #if UNIX
- tcapeeop();
- #endif
- }
-
- /*
- * Make a noise.
- */
- void ttbeep ()
- {
- ttputc (BEL);
- ttflush ();
- }
-
- /*
- * Convert a number to decimal
- * ascii, and write it out. Used to
- * deal with numeric arguments.
- */
- void asciiparm (n)
- register int n;
- {
- register int q;
-
- q = n / 10;
- if (q != 0)
- asciiparm (q);
- ttputc ((n % 10) + '0');
- }
-
- #if GOSLING
- /*
- * Insert a block of blank lines onto the
- * screen, using a scrolling region that starts at row
- * "row" and extends down to row "bot". Deal with the one
- * line case, which is a little bit special, with special
- * case code.
- */
- void ttinsl (row, bot, nchunk)
- {
- if (row == bot)
- {
- /* Funny case. */
- if (nchunk != 1)
- abort ();
- ttmove (row, 0);
- tteeol ();
- }
- else
- {
- /* General case. */
- ttputc (ESC);
- ttputc ('/');
- asciiparm (row + 1);
- ttputc (';');
- asciiparm (bot + 1);
- ttputc (';');
- asciiparm (nchunk);
- ttputc (';');
- ttputc ('0');
- ttputc ('S');
- }
- }
-
- /*
- * Delete a block of lines, with the uppermost
- * line at row "row", in a screen slice that extends to
- * row "bot". The "nchunk" is the number of lines that have
- * to be deleted. Watch for the pathalogical 1 line case,
- * where the scroll region is *not* the way to do it.
- * The block delete is used by the slightly more
- * optimal display code.
- */
- void ttdell (row, bot, nchunk)
- {
- if (row == bot)
- {
- /* Funny case. */
- if (nchunk != 1)
- abort ();
- ttmove (row, 0);
- tteeol ();
- }
- else
- {
- /* General case. */
- ttputc (ESC);
- ttputc ('/');
- asciiparm (row + 1);
- ttputc (';');
- asciiparm (bot + 1);
- ttputc (';');
- asciiparm (nchunk);
- ttputc (';');
- ttputc ('1');
- ttputc ('S');
- }
- }
- #endif
-
- /*
- * Switch to full screen scroll. This is
- * used by "spawn.c" just before is suspends the
- * editor, and by "display.c" when it is getting ready
- * to exit. This is a no-op.
- */
- void ttnowindow (){}
-
- /*
- * Set the current writing color to the
- * specified color. Watch for color changes that are
- * not going to do anything (the color is already right)
- * and don't send anything to the display.
- */
- void ttcolor (color)
- register int color;
- {
- #if MSDOS
- if (mem_map)
- {
- tthue = color; /* Save the color. */
- return;
- }
- #endif
- #if UNIX
- if (color == CTEXT)
- tcaprev (FALSE);
- else
- tcaprev (TRUE);
- tthue = color; /* Save the color. */
- #endif
- #if ANSI
- if (color != tthue)
- {
- if (color == CTEXT)
- { /* Normal video. */
- ttputc (ESC);
- ttputc ('[');
- ttputc ('0');
- ttputc ('m');
- }
- else
- if (color == CMODE)
- { /* Reverse video. */
- ttputc (ESC);
- ttputc ('[');
- ttputc ('7');
- ttputc ('m');
- }
- tthue = color; /* Save the color. */
- }
- #endif
- }
-