home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / CURSESIO.C < prev    next >
C/C++ Source or Header  |  1991-12-02  |  8KB  |  197 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(void) writes char 'chr' with attributes 'attr' to       */
  33. /* the current cursor location.                                 */
  34. /****************************************************************/
  35.  
  36. void _cursescattr(char chr, char attr)
  37.   {
  38.   regs.h.ah = 0x09;
  39.   regs.h.al = (unsigned char)chr;
  40.   regs.h.bh = 0x00;
  41.   regs.h.bl = (unsigned char)attr;
  42.   regs.x.cx = 0x01;
  43.   int86(0x10, ®s, ®s);
  44.   } /* _cursescattr */
  45.  
  46. /****************************************************************/
  47. /* _Cursescursor(void) sets the cursor position in video page 0.        */
  48. /* 'row' and 'column' are the cursor address. If 'row' is set   */
  49. /*  to 25, no cursor at all is displayed.                       */
  50. /****************************************************************/
  51.  
  52. void _cursescursor(int row, int column)
  53.   {
  54.   regs.h.ah = 0x02;
  55.   regs.h.bh = 0x00;
  56.   regs.h.dh = (unsigned char)row;
  57.   regs.h.dl = (unsigned char)column;
  58.   int86(0x10, ®s, ®s);
  59.   }/* _cursescursor */
  60.  
  61. /****************************************************************/
  62. /* _Cursesgcols(void) returns the current number of columns on the      */
  63. /* screen.                                                      */
  64. /****************************************************************/
  65.  
  66. int _cursesgcols(void)
  67.   {
  68.   regs.h.ah = 0x0f;
  69.   int86(0x10, ®s, ®s);
  70.   return (int)regs.h.ah;
  71.   } /* _cursesgcols */
  72.  
  73. /****************************************************************/
  74. /* _Cursesputc(void) outputs character 'chr' to screen in tty   */
  75. /* fashion. If a colour mode is active, the character is writ-  */
  76. /* ten with colour 'colour'.                                    */
  77. /****************************************************************/
  78.  
  79. void _cursesputc(char chr, char color)
  80.   {
  81.   regs.h.ah = 0x0e;
  82.   regs.h.al = (unsigned char)chr;
  83.   regs.h.bh = 0x00;
  84.   regs.h.bl = (unsigned char)color;
  85.   int86(0x10, ®s, ®s);
  86.   } /* _cursesputc */
  87.  
  88. /****************************************************************/
  89. /* _Cursesscroll(void) scrolls a window in the current page up or       */
  90. /*  down. Urow, lcol, lrow,rcol are the window coordinates.     */
  91. /* Lines is the number of lines to scroll. If 0, clears the     */
  92. /* window, if < 0 scrolls down, > 0 scrolls up. Blanks areas    */
  93. /* that are left, and sets character attributes to attr. If in  */
  94. /* a colour graphics mode, fills them with the colour 'attr'    */
  95. /* instead.                                                     */
  96. /****************************************************************/
  97.  
  98. void _cursesscroll(int urow, int lcol, int lrow, int rcol, int lines, char attr)
  99.   {
  100.   if (lines >= 0)
  101.     {
  102.     regs.h.ah = 0x06;
  103.     regs.h.al = (unsigned char)lines;
  104.     } /* if */
  105.   else
  106.     {
  107.     regs.h.ah = 0x07;
  108.     regs.h.al = (unsigned char)(-lines);
  109.     } /* else */
  110.   regs.h.bh = (unsigned char)attr;
  111.   regs.h.ch = (unsigned char)urow;
  112.   regs.h.cl = (unsigned char)lcol;
  113.   regs.h.dh = (unsigned char)lrow;
  114.   regs.h.dl = (unsigned char)rcol;
  115.   int86(0x10, ®s, ®s);
  116.   } /* _cursesscroll */
  117.  
  118. /****************************************************************/
  119. /* _Cursesgcmode(void) returns the current cursor type. Bits 8-15       */
  120. /* of the return value is the start scan row, and bits 0-7 is   */
  121. /* the end scan row.                                            */
  122. /****************************************************************/
  123.  
  124. int _cursesgcmode(void)
  125.   {
  126.   regs.h.ah = 0x03;
  127.   regs.h.bh = 0x00;
  128.   int86(0x10, ®s, ®s);
  129.   return (int)regs.x.cx;
  130.   } /* _cursesgcmode */
  131.  
  132. /****************************************************************/
  133. /* _Cursescmode(void) sets the cursor type to begin in scan line        */
  134. /* startrow and end in scan line endrow. Both values should be  */
  135. /* 0-31.                                                        */
  136. /****************************************************************/
  137.  
  138. void _cursescmode(int startrow, int endrow)
  139.   {
  140.   regs.h.ah = 0x01;
  141.   regs.h.ch = (unsigned char)startrow;
  142.   regs.h.cl = (unsigned char)endrow;
  143.   int86(0x10, ®s, ®s);
  144.   } /* _cursescmode */
  145.  
  146. /****************************************************************/
  147. /* _Curseskey(void) returns the next key code struck at the key-        */
  148. /* board. If the low 8 bits are 0, the upper bits contain the   */
  149. /* extended character code. If bit 0-7 are non-zero, the upper  */
  150. /* bits = 0.                                                    */
  151. /****************************************************************/
  152.  
  153. int _curseskey(void)
  154.   {
  155.   regs.h.ah = 0x00;
  156.   int86(0x16, ®s, ®s);
  157.   if (regs.h.al != 0)
  158.     return (int)(regs.x.ax & 0x00ff);
  159.   return (int)regs.x.ax;
  160.   } /* _curseskey */
  161.  
  162. /****************************************************************/
  163. /* _Curseskeytst(void) returns 1 if a keyboard character is avail-      */
  164. /* able, 0 otherwise.                                           */
  165. /****************************************************************/
  166.  
  167. bool _curseskeytst(void)
  168.   {
  169.   regs.h.ah = 0x01;
  170.   int86(0x16, ®s, ®s);
  171.   return ((bool)((regs.x.cflag & 0x40) ? 1 : 0));
  172.   } /*_curseskeytst */
  173.  
  174. /****************************************************************/
  175. /* _Cursesgcb(void) returns 1 if MSDOS BREAK CHECK is on, else 0.       */
  176. /****************************************************************/
  177.  
  178. int _cursesgcb(void)
  179.   {
  180.   regs.h.ah = 0x33;
  181.   regs.h.al = 0x00;
  182.   int86(0x21, ®s, ®s);
  183.   return (int)regs.h.dl;
  184.   } /* _cursesgcb */
  185.  
  186. /****************************************************************/
  187. /* _Cursesscb(void) sets MSDOS BREAK CHECK according to 'setting'.      */
  188. /****************************************************************/
  189.  
  190. void _cursesscb(int setting)
  191.   {
  192.   regs.h.ah = 0x33;
  193.   regs.h.al = 0x00;
  194.   regs.h.dl = (unsigned char)(setting ? 1 : 0);
  195.   int86(0x21, ®s, ®s);
  196.   } /* _cursesscb */
  197.