home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURS13_2.ZIP / CURSESIO.C < prev    next >
Text File  |  1989-12-11  |  10KB  |  324 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. #ifdef OS2
  28. #define INCL_SUB
  29. #define INCL_DOS
  30. #include <os2.h>
  31. #endif
  32.  
  33. char _curses_curseio_rcsid[] = "@(#)cursesio.c v1.3 - 881005";
  34.  
  35. static union REGS regs;
  36.  
  37. /****************************************************************/
  38. /* _Cursescattr() writes char 'chr' with attributes 'attr' to   */
  39. /* the current cursor location.                                 */
  40. /****************************************************************/
  41.  
  42. void _cursescattr(chr, attr)
  43.   char  chr;
  44.   char  attr;
  45.   {
  46. #ifdef OS2
  47.   USHORT x, y;
  48.   UCHAR buf[2];
  49.   
  50.   buf[0]=chr; buf[1]=attr;
  51.   VioGetCurPos(&y, &x, (HVIO)0);
  52.   VioWrtCellStr(buf, 2, y, x, 0);
  53. #else
  54.   regs.h.ah = 0x09;
  55.   regs.h.al = (unsigned char)chr;
  56.   regs.h.bh = 0x00;
  57.   regs.h.bl = (unsigned char)attr;
  58.   regs.x.cx = 0x01;
  59.   int86(0x10, ®s, ®s);
  60. #endif
  61.   } /* _cursescattr */
  62.  
  63. /****************************************************************/
  64. /* _Cursescursor() sets the cursor position in video page 0.    */
  65. /* 'row' and 'column' are the cursor address. If 'row' is set   */
  66. /*  to 25, no cursor at all is displayed.                       */
  67. /****************************************************************/
  68.  
  69. void _cursescursor(row, column)
  70.   int   row;
  71.   int   column;
  72.   {
  73. #ifdef OS2
  74.   VioSetCurPos(row, column, 0);
  75. #else
  76.   regs.h.ah = 0x02;
  77.   regs.h.bh = 0x00;
  78.   regs.h.dh = (unsigned char)row;
  79.   regs.h.dl = (unsigned char)column;
  80.   int86(0x10, ®s, ®s);
  81. #endif
  82.   }/* _cursescursor */
  83.  
  84. /****************************************************************/
  85. /* _Cursesgcols() returns the current number of columns on the  */
  86. /* screen.                                                      */
  87. /****************************************************************/
  88.  
  89. int _cursesgcols()
  90.   {
  91. #ifdef OS2
  92. VIOMODEINFO modeinfo;
  93.  
  94.   VioGetMode((PVIOMODEINFO)&modeinfo,0);
  95.   if (modeinfo.col == 0) return 80;
  96.   return modeinfo.col;
  97. #else
  98.   regs.h.ah = 0x0f;
  99.   int86(0x10, ®s, ®s);
  100.   return (int)regs.h.ah;
  101. #endif
  102.   } /* _cursesgcols */
  103.  
  104. /****************************************************************/
  105. /* _Cursesputc() outputs character 'chr' to screen in tty       */
  106. /* fashion. If a colour mode is active, the character is writ-  */
  107. /* ten with colour 'colour'.                                    */
  108. /****************************************************************/
  109.  
  110. void _cursesputc(chr, color)
  111.   char  chr;
  112.   char  color;
  113.   {
  114. #ifdef OS2
  115.   USHORT x, y;
  116.  
  117.   VioGetCurPos(&y, &x, (HVIO)0);
  118.   VioWrtNAttr(&color,1,y,x,0);
  119.   VioWrtTTy(&chr,1,0);
  120. #else
  121.   regs.h.ah = 0x0e;
  122.   regs.h.al = (unsigned char)chr;
  123.   regs.h.bh = 0x00;
  124.   regs.h.bl = (unsigned char)color;
  125.   int86(0x10, ®s, ®s);
  126. #endif
  127.   } /* _cursesputc */
  128.  
  129. /****************************************************************/
  130. /* _Cursesscroll() scrolls a window in the current page up or   */
  131. /*  down. Urow, lcol, lrow,rcol are the window coordinates.     */
  132. /* Lines is the number of lines to scroll. If 0, clears the     */
  133. /* window, if < 0 scrolls down, > 0 scrolls up. Blanks areas    */
  134. /* that are left, and sets character attributes to attr. If in  */
  135. /* a colour graphics mode, fills them with the colour 'attr'    */
  136. /* instead.                                                     */
  137. /****************************************************************/
  138.  
  139. void _cursesscroll(urow, lcol, lrow, rcol, lines, attr)
  140.   int   urow;
  141.   int   lcol;
  142.   int   lrow;
  143.   int   rcol;
  144.   int   lines;
  145.   char  attr;
  146.   {
  147. #ifdef OS2
  148.   char  buf[2];
  149.  
  150.   buf[0]=' '; buf[1]=attr;
  151.   if(lines == 0)    /* Clear window */
  152.      {
  153.      lines=-1;
  154.      VioScrollDn(urow,lcol,lrow,rcol,lines,buf,0);
  155.      }
  156.   else if (lines < 0) 
  157.      {
  158.      VioScrollDn(urow,lcol,lrow,rcol,-lines,buf,0);
  159.      }
  160.   else
  161.      {
  162.      VioScrollUp(urow,lcol,lrow,rcol,lines,buf,0);
  163.      }
  164. #else
  165.   if (lines >= 0)
  166.     {
  167.     regs.h.ah = 0x06;
  168.     regs.h.al = (unsigned char)lines;
  169.     } /* if */
  170.   else
  171.     {
  172.     regs.h.ah = 0x07;
  173.     regs.h.al = (unsigned char)(-lines);
  174.     } /* else */
  175.   regs.h.bh = (unsigned char)attr;
  176.   regs.h.ch = (unsigned char)urow;
  177.   regs.h.cl = (unsigned char)lcol;
  178.   regs.h.dh = (unsigned char)lrow;
  179.   regs.h.dl = (unsigned char)rcol;
  180.   int86(0x10, ®s, ®s);
  181. #endif
  182.   } /* _cursesscroll */
  183.  
  184. /****************************************************************/
  185. /* _Cursesgcmode() returns the current cursor type. Bits 8-15   */
  186. /* of the return value is the start scan row, and bits 0-7 is   */
  187. /* the end scan row.                                            */
  188. /****************************************************************/
  189.  
  190. int _cursesgcmode()
  191.   {
  192. #ifdef OS2
  193. VIOCURSORINFO curinfo;
  194.  
  195.   VioGetCurType(&curinfo,0);
  196.   return ((curinfo.yStart & 0xFF)*256+(curinfo.cEnd & 0xFF));
  197. #else
  198.   regs.h.ah = 0x03;
  199.   regs.h.bh = 0x00;
  200.   int86(0x10, ®s, ®s);
  201.   return (int)regs.x.cx;
  202. #endif
  203.   } /* _cursesgcmode */
  204.  
  205. /****************************************************************/
  206. /* _Cursescmode() sets the cursor type to begin in scan line    */
  207. /* startrow and end in scan line endrow. Both values should be  */
  208. /* 0-31.                                                        */
  209. /****************************************************************/
  210.  
  211. void _cursescmode(startrow, endrow)
  212.   int   startrow;
  213.   int   endrow;
  214.   {
  215. #ifdef OS2
  216. VIOCURSORINFO curinfo;
  217.  
  218.   curinfo.yStart=startrow;
  219.   curinfo.cEnd=endrow;
  220.   curinfo.cx=0;
  221.   curinfo.attr=0;
  222.   VioSetCurType(&curinfo,0);
  223. #else
  224.   regs.h.ah = 0x01;
  225.   regs.h.ch = (unsigned char)startrow;
  226.   regs.h.cl = (unsigned char)endrow;
  227.   int86(0x10, ®s, ®s);
  228. #endif
  229.   } /* _cursescmode */
  230.  
  231. /****************************************************************/
  232. /* _Curseskey() returns the next key code struck at the key-    */
  233. /* board. If the low 8 bits are 0, the upper bits contain the   */
  234. /* extended character code. If bit 0-7 are non-zero, the upper  */
  235. /* bits = 0.                                                    */
  236. /****************************************************************/
  237.  
  238. int _curseskey()
  239.   {
  240. #ifdef OS2
  241. KBDKEYINFO keyinfo;
  242.   KbdCharIn(&keyinfo,0,0);
  243.   if (keyinfo.chChar != 0)
  244.      return((int)keyinfo.chChar & 0xFF);
  245.   return((int)keyinfo.chScan<<8);
  246. #else
  247.   regs.h.ah = 0x00;
  248.   int86(0x16, ®s, ®s);
  249.   if (regs.h.al != 0)
  250.     return (int)(regs.x.ax & 0x00ff);
  251.   return (int)regs.x.ax;
  252. #endif
  253.   } /* _curseskey */
  254.  
  255. /****************************************************************/
  256. /* _Curseskeytst() returns 1 if a keyboard character is avail-  */
  257. /* able, 0 otherwise.                                           */
  258. /****************************************************************/
  259.  
  260. bool _curseskeytst()
  261.   {
  262. #ifdef OS2
  263.   if (kbhit())
  264.      return 1;
  265.   else
  266.      return 0;
  267. #else
  268.   regs.h.ah = 0x01;
  269.   int86(0x16, ®s, ®s);
  270.   return ((bool)((regs.x.cflag & 0x40) ? 1 : 0));
  271. #endif
  272.   } /*_curseskeytst */
  273.  
  274. /****************************************************************/
  275. /* _Cursesgcb() returns 1 if MSDOS BREAK CHECK is on, else 0.   */
  276. /****************************************************************/
  277. #ifdef OS2
  278. static int signal_enab=1;
  279. void FAR null_hand()
  280. {
  281. }
  282. #endif
  283.  
  284. int _cursesgcb()
  285.   {
  286. #ifdef OS2
  287.   return signal_enab;
  288. #else
  289.   regs.h.ah = 0x33;
  290.   regs.h.al = 0x00;
  291.   int86(0x21, ®s, ®s);
  292.   return (int)regs.h.dl;
  293. #endif
  294.   } /* _cursesgcb */
  295.  
  296. /****************************************************************/
  297. /* _Cursesscb() sets MSDOS BREAK CHECK according to 'setting'.  */
  298. /****************************************************************/
  299.  
  300. void _cursesscb(setting)
  301.   int setting;
  302.   {
  303. #ifdef OS2
  304. static PFNSIGHANDLER old_hand;
  305. static USHORT old_action;
  306.  
  307.   if((setting == 0)&&(signal_enab == 1))
  308.      {
  309.      DosSetSigHandler((PFNSIGHANDLER)null_hand,(PFNSIGHANDLER *)&old_hand,&old_action,1,1);
  310.      signal_enab = 0;
  311.      }
  312.   else if ((setting == 1)&&(signal_enab == 0))
  313.      {
  314.      DosSetSigHandler((PFNSIGHANDLER)old_hand,NULL,NULL,old_action,1);
  315.      signal_enab = 1;
  316.      }
  317. #else
  318.   regs.h.ah = 0x33;
  319.   regs.h.al = 0x00;
  320.   regs.h.dl = (unsigned char)(setting ? 1 : 0);
  321.   int86(0x21, ®s, ®s);
  322. #endif
  323.   } /* _cursesscb */
  324.