home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURSES.LZH / CURSESIO.C < prev    next >
C/C++ Source or Header  |  1980-01-01  |  7KB  |  212 lines

  1. /****************************************************************/
  2. /* Low-level I/O functions of the PCcurses package, 'C' version    */
  3. /*                                */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version    */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,    */
  8. /* and therefore consider myself free make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* BUT: this particular module was written by            */
  12. /*    Steve Creps (creps@silver.bacs.indiana.edu)        */
  13. /* It provides 'C' versions of the low-level I/O functions    */
  14. /* that are also available in assembler in cursesio.asm.    */
  15. /* B. Larsson took the liberty of modifying its style slightly    */
  16. /* when incorporating it into PCcurses v.1.2.            */
  17. /****************************************************************/
  18. /* 1.0:    Original, S. Creps:                880827    */
  19. /* 1.2:    Style clean-up, rcsid[] string for maintenance:    881002    */
  20. /* 1.3:    MSC -W3, Turbo'C' -w -w-pro checkes:        881005    */
  21. /****************************************************************/
  22.  
  23. #include <curses.h>
  24. #include <curspriv.h>
  25. #include <dos.h>
  26.  
  27. char _curses_curseio_rcsid[] = "@(#)cursesio.c v1.3 - 881005";
  28.  
  29. static union REGS regs;
  30.  
  31. /****************************************************************/
  32. /* _Cursescattr() writes char 'chr' with attributes 'attr' to    */
  33. /* the current cursor location.                    */
  34. /****************************************************************/
  35.  
  36. void _cursescattr(chr, attr)
  37.   char    chr;
  38.   char    attr;
  39.   {
  40.   regs.h.ah = 0x09;
  41.   regs.h.al = (unsigned char)chr;
  42.   regs.h.bh = 0x00;
  43.   regs.h.bl = (unsigned char)attr;
  44.   regs.x.cx = 0x01;
  45.   int86(0x10, ®s, ®s);
  46.   } /* _cursescattr */
  47.  
  48. /****************************************************************/
  49. /* _Cursescursor() sets the cursor position in video page 0.    */
  50. /* 'row' and 'column' are the cursor address. If 'row' is set    */
  51. /*  to 25, no cursor at    all is displayed.            */
  52. /****************************************************************/
  53.  
  54. void _cursescursor(row, column)
  55.   int    row;
  56.   int    column;
  57.   {
  58.   regs.h.ah = 0x02;
  59.   regs.h.bh = 0x00;
  60.   regs.h.dh = (unsigned char)row;
  61.   regs.h.dl = (unsigned char)column;
  62.   int86(0x10, ®s, ®s);
  63.   }/* _cursescursor */
  64.  
  65. /****************************************************************/
  66. /* _Cursesgcols() returns the current number of columns on the    */
  67. /* screen.                            */
  68. /****************************************************************/
  69.  
  70. int _cursesgcols()
  71.   {
  72.   regs.h.ah = 0x0f;
  73.   int86(0x10, ®s, ®s);
  74.   return (int)regs.h.ah;
  75.   } /* _cursesgcols */
  76.  
  77. /****************************************************************/
  78. /* _Cursesputc() outputs character 'chr' to screen in tty    */
  79. /* fashion. If a colour mode is active, the character is writ-    */
  80. /* ten with colour 'colour'.                    */
  81. /****************************************************************/
  82.  
  83. void _cursesputc(chr, color)
  84.   char    chr;
  85.   char    color;
  86.   {
  87.   regs.h.ah = 0x0e;
  88.   regs.h.al = (unsigned char)chr;
  89.   regs.h.bh = 0x00;
  90.   regs.h.bl = (unsigned char)color;
  91.   int86(0x10, ®s, ®s);
  92.   } /* _cursesputc */
  93.  
  94. /****************************************************************/
  95. /* _Cursesscroll() scrolls a window in the current page up or    */
  96. /*  down. Urow, lcol, lrow,rcol are the window coordinates.    */
  97. /* Lines is the number of lines to scroll. If 0, clears the    */
  98. /* window, if < 0 scrolls down, > 0 scrolls up. Blanks areas    */
  99. /* that are left, and sets character attributes to attr. If in    */
  100. /* a colour graphics mode, fills them with the colour 'attr'    */
  101. /* instead.                            */
  102. /****************************************************************/
  103.  
  104. void _cursesscroll(urow, lcol, lrow, rcol, lines, attr)
  105.   int    urow;
  106.   int    lcol;
  107.   int    lrow;
  108.   int    rcol;
  109.   int    lines;
  110.   char attr;
  111.   {
  112.   if (lines >= 0)
  113.     {
  114.     regs.h.ah = 0x06;
  115.     regs.h.al = (unsigned char)lines;
  116.     } /* if */
  117.   else
  118.     {
  119.     regs.h.ah = 0x07;
  120.     regs.h.al = (unsigned char)(-lines);
  121.     } /* else */
  122.   regs.h.bh = (unsigned char)attr;
  123.   regs.h.ch = (unsigned char)urow;
  124.   regs.h.cl = (unsigned char)lcol;
  125.   regs.h.dh = (unsigned char)lrow;
  126.   regs.h.dl = (unsigned char)rcol;
  127.   int86(0x10, ®s, ®s);
  128.   } /* _cursesscroll */
  129.  
  130. /****************************************************************/
  131. /* _Cursesgcmode() returns the current cursor type. Bits 8-15    */
  132. /* of the return value is the start scan row, and bits 0-7 is    */
  133. /* the end scan row.                        */
  134. /****************************************************************/
  135.  
  136. int _cursesgcmode()
  137.   {
  138.   regs.h.ah = 0x03;
  139.   regs.h.bh = 0x00;
  140.   int86(0x10, ®s, ®s);
  141.   return (int)regs.x.cx;
  142.   } /* _cursesgcmode */
  143.  
  144. /****************************************************************/
  145. /* _Cursescmode() sets the cursor type to begin in scan line    */
  146. /* startrow and end in scan line endrow. Both values should be    */
  147. /* 0-31.                            */
  148. /****************************************************************/
  149.  
  150. void _cursescmode(startrow, endrow)
  151.   int    startrow;
  152.   int    endrow;
  153.   {
  154.   regs.h.ah = 0x01;
  155.   regs.h.ch = (unsigned char)startrow;
  156.   regs.h.cl = (unsigned char)endrow;
  157.   int86(0x10, ®s, ®s);
  158.   } /* _cursescmode */
  159.  
  160. /****************************************************************/
  161. /* _Curseskey() returns the next key code struck at the key-    */
  162. /* board. If the low 8 bits are 0, the upper bits contain the    */
  163. /* extended character code. If bit 0-7 are non-zero, the upper    */
  164. /* bits = 0.                            */
  165. /****************************************************************/
  166.  
  167. int _curseskey()
  168.   {
  169.   regs.h.ah = 0x00;
  170.   int86(0x16, ®s, ®s);
  171.   if (regs.h.al != 0)
  172.     return (int)(regs.x.ax & 0x00ff);
  173.   return (int)regs.x.ax;
  174.   } /* _curseskey */
  175.  
  176. /****************************************************************/
  177. /* _Curseskeytst() returns 1 if a keyboard character is avail-    */
  178. /* able, 0 otherwise.                        */
  179. /****************************************************************/
  180.  
  181. bool _curseskeytst()
  182.   {
  183.   regs.h.ah = 0x01;
  184.   int86(0x16, ®s, ®s);
  185.   return ((bool)((regs.x.cflag & 0x40) ? 1 : 0));
  186.   } /*_curseskeytst */
  187.  
  188. /****************************************************************/
  189. /* _Cursesgcb() returns 1 if MSDOS BREAK CHECK is on, else 0.    */
  190. /****************************************************************/
  191.  
  192. int _cursesgcb()
  193.   {
  194.   regs.h.ah = 0x33;
  195.   regs.h.al = 0x00;
  196.   int86(0x21, ®s, ®s);
  197.   return (int)regs.h.dl;
  198.   } /* _cursesgcb */
  199.  
  200. /****************************************************************/
  201. /* _Cursesscb() sets MSDOS BREAK CHECK according to 'setting'.    */
  202. /****************************************************************/
  203.  
  204. void _cursesscb(setting)
  205.   int setting;
  206.   {
  207.   regs.h.ah = 0x33;
  208.   regs.h.al = 0x00;
  209.   regs.h.dl = (unsigned char)(setting ? 1 : 0);
  210.   int86(0x21, ®s, ®s);
  211.   } /* _cursesscb */
  212.