home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / editor / beav / ttyio.c < prev    next >
C/C++ Source or Header  |  1994-01-30  |  4KB  |  249 lines

  1. /*
  2. *
  3. *   MS-DOS terminal I/O.               TTYIO.C
  4. */
  5.  
  6. #include        "def.h"
  7. #ifdef    MSDOS
  8.  
  9.  
  10. void ttopen ();
  11. void ttclose ();        /* stub */
  12. void ttputc ();
  13. void putline ();
  14. void ttflush ();        /* stub */
  15. int ttkeyready ();
  16. int ttgetc ();
  17. void ttraw ();
  18. void ttcooked ();
  19. void set_crt_type ();
  20.  
  21. #include    "dos.h"
  22.  
  23. int slot;
  24. int scr_type;
  25. #define SCREEN_PORT (video_port)
  26. static int video_port =
  27. {
  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. uchar attr = 0x0f;        /* saved color attribute, default
  37.                  * white on black */
  38.  
  39. /*
  40. * Initialization.
  41. * for MS-DOS.
  42. */
  43. void
  44. ttopen ()
  45. {
  46.     uchar *ptr;
  47.     uchar data[64];
  48.  
  49.     if (wang_pc && !ibm_pc)
  50.     set_crt_type ();
  51.     nrow = NROW;
  52.     ncol = NCOL;
  53.     if (ibm_pc)
  54.     {
  55.     union REGS inregs, outregs;
  56.     struct SREGS segs;
  57.     int i;
  58.  
  59.     for (i = 0; i < 64; i++)
  60.         data[i] = 0;
  61.     ptr = data;
  62.     inregs.h.ah = 0x1b;
  63.     inregs.h.al = 0;
  64.     inregs.x.bx = 0;
  65.     inregs.x.di = (int) data;
  66.     segs.es = _FP_SEG (ptr);
  67.  
  68.     int86x (0x10, &inregs, &outregs, &segs);    /* get number of rows */
  69.  
  70.     /* if that failed then use the default */
  71.     if ((outregs.h.al != 0x1b) || (data[0x22] == 0))
  72.         return;
  73.     nrow = data[0x22];
  74.  
  75.     /* get current attributes */
  76.     inregs.h.ah = 0x8;
  77.     inregs.h.al = 0;
  78.     inregs.h.bh = 0;
  79.  
  80.     int86 (0x10, &inregs, &outregs);
  81.     attr = outregs.h.ah & 0x7f;    /* don't want blink */
  82.  
  83.     }
  84. }
  85. void
  86. ttclose ()
  87. {
  88. }
  89. void
  90. ttflush ()
  91. {
  92. }
  93.  
  94. /*
  95. * Write character.
  96. */
  97. int
  98. ttputc (c)
  99.     int c;
  100. {
  101.     bdos (6, c, 0);
  102.     return c;
  103. }
  104.  
  105. void
  106. putline (row, startcol, stringsize, string)
  107.     int row, startcol, stringsize;
  108.     char *string;
  109. {
  110.     extern int tthue;
  111.     unsigned short *screen;
  112.     int x, attribute;
  113.     char c_row, c_col, i;
  114.     union REGS regs;
  115.  
  116.     if (ibm_pc)
  117.     {
  118.     c_row = row - 1;
  119.     c_col = startcol - 1;
  120.     for (i = 0; i < stringsize; i++)
  121.     {
  122.         regs.h.ah = 2;
  123.         regs.h.dh = c_row;
  124.         regs.h.dl = c_col;
  125.         regs.h.bh = 0;
  126.         int86 (0x10, ®s, ®s);    /* set cursor position */
  127.  
  128.         if (tthue == CTEXT)
  129.         regs.h.bl = attr;
  130.         if (tthue == CMODE)
  131.         regs.h.bl = ((0x70 & attr) >> 4) | ((0x07 & attr) << 4);
  132.         regs.h.ah = 9;
  133.         regs.h.bh = 0;
  134.         regs.h.al = string[i];
  135.         regs.x.cx = 1;
  136.         int86 (0x10, ®s, ®s);    /* set cursor position */
  137.         c_col++;
  138.     }
  139.     }
  140.     else if (wang_pc)
  141.     {
  142.     if (tthue == CTEXT)
  143.         attribute = 0x00;
  144.     else
  145.         attribute = 0x02;
  146.  
  147.     x = stringsize;
  148.     screen = (unsigned short *) WANG_CHARACTER_SCREEN;
  149.     screen += ((row - 1) * 80) + startcol - 1;
  150.     outp (SCREEN_PORT, 01);
  151.     while (x--)
  152.     {
  153.         *screen = (*string++ << 8) | attribute;
  154.         screen++;
  155.     }
  156.     outp (SCREEN_PORT, 00);
  157.     }
  158. }
  159.  
  160. /*
  161. *   return with a TRUE if key was struck.
  162. */
  163. int
  164. ttkeyready ()
  165. {
  166.     int cnt;
  167.  
  168.     if (last_key != 0)
  169.     return (1);
  170.  
  171.     last_key = bdos (6, 0xff, 0);
  172.     last_key &= 0xff;
  173.     if (last_key == 0)
  174.     return (0);
  175.     else
  176.     return (1);
  177. }
  178.  
  179. /*
  180. * Read character.
  181. */
  182. int
  183. ttgetc ()
  184. {
  185.     int c;
  186.     if (last_key != 0)
  187.     {
  188.     c = last_key;
  189.     last_key = 0;
  190.     return (c);
  191.     }
  192.     ttcooked ();
  193.     c = (bdos (7, 0, 0) & 0xFF);
  194.     ttraw ();
  195.     return (c);
  196. }
  197.  
  198. /* disable nasty cntrl-c during disk io!
  199. */
  200. void
  201. ttraw ()
  202. {
  203.     union REGS inregs, outregs;
  204.  
  205.     inregs.h.al = 1;
  206.     inregs.h.ah = 0x33;
  207.     inregs.h.dl = 0;
  208.     intdos (&inregs, &outregs);
  209.     /*
  210.   cntrlcoff();
  211.   */
  212. }
  213.  
  214. /* re enable cntrl-c for keyboard
  215. */
  216. void
  217. ttcooked ()
  218. {
  219.     union REGS inregs, outregs;
  220.  
  221.     inregs.h.al = 1;
  222.     inregs.h.ah = 0x33;
  223.     intdos (&inregs, &outregs);
  224.     inregs.h.dl = 1;
  225.     /*
  226.   cntrlcon();
  227.   */
  228. }
  229.  
  230. /* switch physical monitors
  231. */
  232. static char str[] =
  233. {
  234.     0x1b, '/', 1, 's'
  235. };
  236.  
  237. void
  238. set_crt_type ()
  239. {
  240.     char active_screen;
  241.  
  242.     active_screen = getscreenstate ();
  243.     slot = active_screen & 0x0f;
  244.     scr_type = (active_screen & 0x70) >> 4;
  245.     video_port = 0x1010 | (slot << 8);
  246. }
  247.  
  248. #endif
  249.