home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 332_01 / curses68.c < prev    next >
C/C++ Source or Header  |  1990-01-07  |  7KB  |  235 lines

  1. /****************************************************************/
  2. /* Low-level I/O functions of the PCcurses package, 'C' version    */
  3. /****************************************************************/
  4. /*     NOTE! NOTE! NOTE! NOTE! NOTE! NOTE! NOTE! NOTE!    */
  5. /* This version is for a 68000 stand-alone VT100 version    */
  6. /****************************************************************/
  7. /* This version of curses is based on ncurses, a curses version    */
  8. /* originally written by Pavel Curtis at Cornell University.    */
  9. /* I have made substantial changes to make it run on IBM PC's,    */
  10. /* and therefore consider myself free make it public domain.    */
  11. /*                Bjorn Larsson (bl@infovox.se)    */
  12. /****************************************************************/
  13. /* 1.4:  Functional:                    900114    */
  14. /****************************************************************/
  15.  
  16. #include <curses.h>
  17. #include <curspriv.h>
  18.  
  19. typedef struct
  20.   {
  21.   char *name;                /* Device/file name */
  22.   int (* inch)  ();            /* Address of input routine */
  23.   int (* outch) ();            /* Address of output routine */
  24.   int (* intst) ();            /* Address of input test routine */
  25.   int    id;
  26.   } _chan_desc;
  27.  
  28. static char _curses_curse68_rcsid[] = "@(#)curses68.c   v.1.4  - 900114";
  29.  
  30. extern    _chan_desc _chan_tab[];        /* This one may be accessed */
  31.  
  32. static    char    clearseq[] = "\033[2J\033[H";
  33. static    char    seqbuf[20];
  34.  
  35. static    char    isrev    = 0;
  36.  
  37. static    int    myrow = 1000;
  38. static    int    mycol = 1000;
  39.  
  40. /****************************************************************/
  41. /* _Cursescattr() writes char 'chr' with attributes 'attr' to    */
  42. /* the current cursor location.                    */
  43. /****************************************************************/
  44.  
  45. void _cursescattr(chr, attr)
  46.   char    chr;
  47.   char    attr;
  48.   {
  49.   if ((attr & 0x70) == 0x70)
  50.     {
  51.     if(!isrev)
  52.       {
  53.       (*_chan_tab[1].outch)(0x1b);
  54.       (*_chan_tab[1].outch)('[');
  55.       (*_chan_tab[1].outch)('7');
  56.       (*_chan_tab[1].outch)('m');
  57.       isrev = 1;
  58.       } /* if */
  59.     }
  60.   else
  61.     {
  62.     if (isrev)
  63.       {
  64.       (*_chan_tab[1].outch)(0x1b);
  65.       (*_chan_tab[1].outch)('[');
  66.       (*_chan_tab[1].outch)('0');
  67.       (*_chan_tab[1].outch)('m');
  68.       isrev = 0;
  69.       } /* if */
  70.     } /* else */
  71.   if ((_cursvar.cursrow < LINES-1) || (_cursvar.curscol < COLS-1))
  72.     {
  73.     (*_chan_tab[1].outch)(chr);
  74.     if (mycol++ >= 80)
  75.       {
  76.       mycol = 0;
  77.       myrow++;
  78.       } /* if */
  79.     } /* if */
  80.   } /* _cursescattr */    
  81.  
  82. /****************************************************************/
  83. /* _Cursescursor() sets the cursor position in video page 0.    */
  84. /* 'row' and 'column' are the cursor address. If 'row' is set    */
  85. /*  to 25, no cursor at    all is displayed.            */
  86. /****************************************************************/
  87.  
  88. void _cursescursor(row, column)
  89.   int    row;
  90.   int    column;
  91.   {
  92.   char    *p;
  93.   char    buf[15];
  94.  
  95.   if ((row == myrow) && (column == mycol))
  96.     return;
  97.   (*_chan_tab[1].outch)(0x1b);
  98.   sprintf(seqbuf,"\033[%d;%dH",row+1, column+1);
  99.   for (p = seqbuf; *p; p++)
  100.     (*_chan_tab[1].outch)(*p);
  101.   myrow = row;
  102.   mycol = column;
  103.   }/* _cursescursor */
  104.  
  105. /****************************************************************/
  106. /* _Cursesgcols() returns the current number of columns on the    */
  107. /* screen.                            */
  108. /****************************************************************/
  109.  
  110. int _cursesgcols()
  111.   {
  112.   return(80);
  113.   } /* _cursesgcols */
  114.  
  115. /****************************************************************/
  116. /* _Cursesputc() outputs character 'chr' to screen in tty    */
  117. /* fashion. If a colour mode is active, the character is writ-    */
  118. /* ten with colour 'colour'.                    */
  119. /****************************************************************/
  120.  
  121. void _cursesputc(chr, color)
  122.   char    chr;
  123.   char    color;
  124.   {
  125.   if (_cursvar.cursrow >= LINES-1)
  126.     return;
  127.   if (_cursvar.curscol >= COLS-1)
  128.     return;
  129.   (*_chan_tab[1].outch)(chr);
  130.   if (mycol++ >= 80)
  131.     {
  132.     mycol = 0;
  133.     myrow++;
  134.     } /* if */
  135.   } /* _cursesputc */
  136.  
  137. /****************************************************************/
  138. /* _Cursesscroll() scrolls a window in the current page up or    */
  139. /*  down. Urow, lcol, lrow,rcol are the window coordinates.    */
  140. /* Lines is the number of lines to scroll. If 0, clears the    */
  141. /* window, if < 0 scrolls down, > 0 scrolls up. Blanks areas    */
  142. /* that are left, and sets character attributes to attr. If in    */
  143. /* a colour graphics mode, fills them with the colour 'attr'    */
  144. /* instead.                            */
  145. /****************************************************************/
  146.  
  147. void _cursesscroll(urow, lcol, lrow, rcol, lines, attr)
  148.   int    urow;
  149.   int    lcol;
  150.   int    lrow;
  151.   int    rcol;
  152.   int    lines;
  153.   char attr;
  154.   {
  155.   char    *p;
  156.  
  157.   for (p = clearseq; *p; p++)
  158.     (*_chan_tab[1].outch)(*p);
  159.   } /* _cursesscroll */
  160.  
  161. /****************************************************************/
  162. /* _Cursesgcmode() returns the current cursor type. Bits 8-15    */
  163. /* of the return value is the start scan row, and bits 0-7 is    */
  164. /* the end scan row.                        */
  165. /****************************************************************/
  166.  
  167. int _cursesgcmode()
  168.   {
  169.   return(0x0f00);
  170.   } /* _cursesgcmode */
  171.  
  172. /****************************************************************/
  173. /* _Cursescmode() sets the cursor type to begin in scan line    */
  174. /* startrow and end in scan line endrow. Both values should be    */
  175. /* 0-31.                            */
  176. /****************************************************************/
  177.  
  178. void _cursescmode(startrow, endrow)
  179.   int    startrow;
  180.   int    endrow;
  181.   {
  182.   } /* _cursescmode */
  183.  
  184. /****************************************************************/
  185. /* _Curseskey() returns the next key code struck at the key-    */
  186. /* board. If the low 8 bits are 0, the upper bits contain the    */
  187. /* extended character code. If bit 0-7 are non-zero, the upper    */
  188. /* bits = 0.                            */
  189. /****************************************************************/
  190.  
  191. int _curseskey()
  192.   {
  193.   return ((*_chan_tab[1].inch)());
  194.   } /* _curseskey */
  195.  
  196. /****************************************************************/
  197. /* _Curseskeytst() returns 1 if a keyboard character is avail-    */
  198. /* able, 0 otherwise.                        */
  199. /****************************************************************/
  200.  
  201. char _curseskeytst()
  202.   {
  203.   return((*_chan_tab[1].intst)());
  204.   } /*_curseskeytst */
  205.  
  206. /****************************************************************/
  207. /* _Cursesgcb() returns 1 if MSDOS BREAK CHECK is on, else 0.    */
  208. /****************************************************************/
  209.  
  210. int _cursesgcb()
  211.   {
  212.   return(1);
  213.   } /* _cursesgcb */
  214.  
  215. /****************************************************************/
  216. /* _Cursesscb() sets MSDOS BREAK CHECK according to 'setting'.    */
  217. /****************************************************************/
  218.  
  219. void _cursesscb(setting)
  220.   int setting;
  221.   {
  222.   } /* _cursesscb */
  223.  
  224. #undef getch
  225.  
  226. /****************************************************************/
  227. /* Getch() read one character from the keyboard without any    */
  228. /* interpretation whatever.                    */
  229. /****************************************************************/
  230.  
  231. int    getch()
  232.   {
  233.   return ((*_chan_tab[1].inch)());
  234.   } /* getch */
  235.