home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2872 / ttyio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  3.5 KB  |  199 lines

  1. /*
  2. *
  3. *   MS-DOS terminal I/O.               TTYIO.C
  4. */
  5. #if MSDOS
  6. #include        "def.h"
  7.  
  8. void    ttopen ();
  9. void    ttclose (); /* stub */
  10. void    ttputc ();
  11. void    putline ();
  12. void    ttflush (); /* stub */
  13. int     ttkeyready ();
  14. int     ttgetc ();
  15. void    ttraw ();
  16. void    ttcooked ();
  17. int     set_crt_type ();
  18. #if RUNCHK  
  19. char    ERR_bd_pl[];
  20. #endif
  21. #include    "lintfunc.dec"
  22. #include    "dos.h"
  23.  
  24. int     slot;
  25. int     scr_type;
  26. #define SCREEN_PORT (video_port)
  27. static int  video_port =
  28. {0x1010
  29. };
  30.  
  31. extern  bool    wang_pc;
  32. extern  bool    ibm_pc;
  33. int     nrow;                   /* Terminal size, rows.         */
  34. int     ncol;                   /* Terminal size, columns.      */
  35. int     last_key;
  36.  
  37. /*
  38. * Initialization.
  39. * Almost no operation in MS-DOS.
  40. */
  41. void ttopen ()
  42. {
  43.     if (wang_pc && !ibm_pc)
  44.         set_crt_type ();
  45.     nrow = NROW;
  46.     ncol = NCOL;
  47. }
  48.  
  49. void ttclose ()
  50. {
  51. }
  52. /*
  53. * Write character.
  54. */
  55. void ttputc (c)
  56. {
  57.     bdos (6, c, 0);
  58. }
  59.  
  60. void putline (row, startcol, stringsize, string)
  61. int     row,
  62.         startcol,
  63.         stringsize;
  64. char   *string;
  65. {
  66.     extern int  tthue;
  67.     unsigned short *screen;
  68.     int     x,
  69.             attribute;
  70.     char    c_row, c_col, i;
  71.     union   REGS    regs;
  72.  
  73.     if (ibm_pc)
  74.         {
  75.         c_row = row - 1;
  76.         c_col = startcol - 1;
  77.         for (i = 0; i < stringsize; i++)
  78.             {
  79.             regs.h.ah = 2;
  80.             regs.h.dh = c_row;
  81.             regs.h.dl= c_col;
  82.             regs.h.bh = 0;
  83.             int86 (0x10, ®s, ®s); /* set cursor position */
  84.         
  85.             if (tthue == CTEXT)
  86.                 regs.h.bl = 0x07;
  87.             if (tthue == CMODE)
  88.                 regs.h.bl = 0x70;
  89.             regs.h.ah = 9;
  90.             regs.h.bh = 0;
  91.             regs.h.al = string[i];
  92.             regs.x.cx= 1;
  93.             int86 (0x10, ®s, ®s); /* set cursor position */
  94.             c_col++;
  95.             }
  96.         }
  97.     else if (wang_pc)
  98.         {
  99.         if (tthue == CTEXT)
  100.             attribute = 0x00;
  101.         else
  102.             attribute = 0x02;
  103.  
  104.         x = stringsize;
  105.         screen = (unsigned short *) WANG_CHARACTER_SCREEN;
  106.         screen += ((row - 1) * 80) + startcol - 1;
  107.         outp (SCREEN_PORT, 01);
  108.         while (x--)
  109.             {
  110.             *screen = (*string++ << 8) | attribute;
  111.             screen++;
  112.             }
  113.         outp (SCREEN_PORT, 00);
  114.         }
  115. }
  116.  
  117. /* 
  118. *   return with a TRUE if key was struck.
  119. */
  120. int     ttkeyready ()
  121. {
  122.     int    cnt;
  123.  
  124.     if (last_key != 0)
  125.         return (1);
  126.  
  127.     last_key = bdos (6, 0xff, 0);
  128.     last_key &= 0xff;
  129.     if (last_key == 0)
  130.         return (0);
  131.     else
  132.         return (1);
  133. }
  134.  
  135. /*
  136. * Read character.
  137. */
  138. int     ttgetc ()
  139. {
  140.     int     c;
  141.     if (last_key != 0)
  142.         {
  143.         c = last_key;
  144.         last_key = 0;
  145.         return (c);
  146.         }
  147.     ttcooked ();
  148.     c = (bdos (7, 0, 0) & 0xFF);
  149.     ttraw ();
  150.     return (c);
  151. }
  152.  
  153. /* disable nasty cntrl-c during disk io!
  154. */
  155. void ttraw ()
  156. {
  157.     union REGS inregs, outregs;
  158.  
  159.     inregs.h.al = 1;
  160.     inregs.h.ah = 0x33;
  161.     inregs.h.dl = 0;
  162.     intdos (&inregs, &outregs);
  163. /*
  164.     cntrlcoff();
  165. */
  166. }
  167.  
  168. /* re enable cntrl-c for keyboard 
  169. */
  170. void ttcooked ()
  171. {
  172.     union REGS inregs, outregs;
  173.  
  174.     inregs.h.al = 1;
  175.     inregs.h.ah = 0x33;
  176.     intdos (&inregs, &outregs);
  177.     inregs.h.dl = 1;
  178. /*
  179.     cntrlcon();
  180. */
  181. }
  182.  
  183. /* switch physical monitors
  184. */
  185. static char str[] =
  186. {0x1b, '/', 1, 's'
  187. };
  188.  
  189. int     set_crt_type ()
  190. {
  191.     char    active_screen;
  192.  
  193.     active_screen = getscreenstate ();
  194.     slot = active_screen & 0x0f;
  195.     scr_type = (active_screen & 0x70) >> 4;
  196.     video_port = 0x1010 | (slot << 8);
  197. }
  198. #endif
  199.