home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / beav1402.zip / ttyio.c < prev    next >
Text File  |  1993-04-16  |  4KB  |  253 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. int  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. #ifdef    FP_SEG    /* this is for MSC 5.1 */
  67.     segs.es = FP_SEG (ptr);
  68. #else    /* this is for MSC 6.0 or 7.0 */
  69.     segs.es = _FP_SEG (ptr);
  70. #endif
  71.     
  72.     int86x (0x10, &inregs, &outregs, &segs);    /* get number of rows */
  73.  
  74.     /* if that failed then use the default */
  75.     if ((outregs.h.al != 0x1b) || (data[0x22] == 0))
  76.         return;
  77.     nrow = data[0x22];
  78.  
  79.     /* get current attributes */
  80.     inregs.h.ah = 0x8;
  81.     inregs.h.al = 0;
  82.     inregs.h.bh = 0;
  83.  
  84.     int86 (0x10, &inregs, &outregs);
  85.     attr = outregs.h.ah & 0x7f;    /* don't want blink */
  86.  
  87.     }
  88. }
  89. void
  90. ttclose ()
  91. {
  92. }
  93. void
  94. ttflush ()
  95. {
  96. }
  97.  
  98. /*
  99. * Write character.
  100. */
  101. int
  102. ttputc (c)
  103.     int c;
  104. {
  105.     bdos (6, c, 0);
  106.     return c;
  107. }
  108.  
  109. void
  110. putline (row, startcol, stringsize, string)
  111.     int row, startcol, stringsize;
  112.     char *string;
  113. {
  114.     extern int tthue;
  115.     unsigned short *screen;
  116.     int x, attribute;
  117.     char c_row, c_col, i;
  118.     union REGS regs;
  119.  
  120.     if (ibm_pc)
  121.     {
  122.     c_row = row - 1;
  123.     c_col = startcol - 1;
  124.     for (i = 0; i < stringsize; i++)
  125.     {
  126.         regs.h.ah = 2;
  127.         regs.h.dh = c_row;
  128.         regs.h.dl = c_col;
  129.         regs.h.bh = 0;
  130.         int86 (0x10, ®s, ®s);    /* set cursor position */
  131.  
  132.         if (tthue == CTEXT)
  133.         regs.h.bl = attr;
  134.         if (tthue == CMODE)
  135.         regs.h.bl = ((0x70 & attr) >> 4) | ((0x07 & attr) << 4);
  136.         regs.h.ah = 9;
  137.         regs.h.bh = 0;
  138.         regs.h.al = string[i];
  139.         regs.x.cx = 1;
  140.         int86 (0x10, ®s, ®s);    /* set cursor position */
  141.         c_col++;
  142.     }
  143.     }
  144.     else if (wang_pc)
  145.     {
  146.     if (tthue == CTEXT)
  147.         attribute = 0x00;
  148.     else
  149.         attribute = 0x02;
  150.  
  151.     x = stringsize;
  152.     screen = (unsigned short *) WANG_CHARACTER_SCREEN;
  153.     screen += ((row - 1) * 80) + startcol - 1;
  154.     outp (SCREEN_PORT, 01);
  155.     while (x--)
  156.     {
  157.         *screen = (*string++ << 8) | attribute;
  158.         screen++;
  159.     }
  160.     outp (SCREEN_PORT, 00);
  161.     }
  162. }
  163.  
  164. /*
  165. *   return with a TRUE if key was struck.
  166. */
  167. int
  168. ttkeyready ()
  169. {
  170.     int cnt;
  171.  
  172.     if (last_key != 0)
  173.     return (1);
  174.  
  175.     last_key = bdos (6, 0xff, 0);
  176.     last_key &= 0xff;
  177.     if (last_key == 0)
  178.     return (0);
  179.     else
  180.     return (1);
  181. }
  182.  
  183. /*
  184. * Read character.
  185. */
  186. int
  187. ttgetc ()
  188. {
  189.     int c;
  190.     if (last_key != 0)
  191.     {
  192.     c = last_key;
  193.     last_key = 0;
  194.     return (c);
  195.     }
  196.     ttcooked ();
  197.     c = (bdos (7, 0, 0) & 0xFF);
  198.     ttraw ();
  199.     return (c);
  200. }
  201.  
  202. /* disable nasty cntrl-c during disk io!
  203. */
  204. void
  205. ttraw ()
  206. {
  207.     union REGS inregs, outregs;
  208.  
  209.     inregs.h.al = 1;
  210.     inregs.h.ah = 0x33;
  211.     inregs.h.dl = 0;
  212.     intdos (&inregs, &outregs);
  213.     /*
  214.   cntrlcoff();
  215.   */
  216. }
  217.  
  218. /* re enable cntrl-c for keyboard
  219. */
  220. void
  221. ttcooked ()
  222. {
  223.     union REGS inregs, outregs;
  224.  
  225.     inregs.h.al = 1;
  226.     inregs.h.ah = 0x33;
  227.     intdos (&inregs, &outregs);
  228.     inregs.h.dl = 1;
  229.     /*
  230.   cntrlcon();
  231.   */
  232. }
  233.  
  234. /* switch physical monitors
  235. */
  236. static char str[] =
  237. {
  238.     0x1b, '/', 1, 's'
  239. };
  240.  
  241. void
  242. set_crt_type ()
  243. {
  244.     char active_screen;
  245.  
  246.     active_screen = getscreenstate ();
  247.     slot = active_screen & 0x0f;
  248.     scr_type = (active_screen & 0x70) >> 4;
  249.     video_port = 0x1010 | (slot << 8);
  250. }
  251.  
  252. #endif
  253.