home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / term-dj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  4.4 KB  |  193 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * term-dj.c ---    Terminal driver for DOS and OS/2 with DJGPP,
  31.  *            there is almost nothing to do.
  32.  *
  33.  * Adapted from term-emx.c by Antonio Costa (acc@asterix.inescn.pt)
  34.  * Works in 25 and 50 lines text modes (at least).
  35.  *
  36.  * (duz 24Feb94)
  37.  * (acc 27Jul94)
  38.  */
  39.  
  40. #include "forth.h"
  41. #include "term.h"
  42.  
  43. #include <pc.h>
  44. #include <ctype.h>
  45.  
  46. Byte *
  47. rawkey_string [NO_OF_KEYS] =    /* what function keys send */
  48. {
  49.   "\377;", "\377<", "\377=", "\377>", "\377?",
  50.   "\377@", "\377A", "\377B", "\377C", "\377D",
  51.   "\377K", "\377M", "\377H", "\377P",
  52.   "\377G", "\377O", "\377Q", "\377I",
  53.   NULL,       "\377S", NULL,    "\377R",
  54.   NULL,    NULL,    NULL,    NULL,    /*"\r"*/
  55. };
  56.  
  57. int tty_interrupt_key (char ch)        { return 0; }
  58. void interactive_terminal (void)    {}
  59. void system_terminal (void)        {}
  60. void query_winsize (void)        {}
  61.  
  62. int
  63. prepare_terminal (void)
  64. {
  65.   setbuf (stdout, NULL);
  66.   cols = ScreenCols ();
  67.   rows = ScreenRows ();
  68.   return 1;
  69. }
  70.  
  71. int
  72. keypressed (void)
  73. {
  74.   return kbhit ();
  75. }
  76.  
  77. #undef getkey
  78.  
  79. static int nextkey = 0;
  80.  
  81. int newgetkey (void)
  82. {
  83.   int key;
  84.  
  85.   if (nextkey)
  86.     {
  87.       key = nextkey;
  88.       nextkey = 0;
  89.       return key;
  90.     }
  91.   key = getkey ();
  92.   if (key > 255)
  93.     {
  94.       nextkey = key & 255;
  95.       return 255;
  96.     }
  97.   return key;
  98. }
  99.  
  100. #define BLINK        0x0080
  101. #define INTENSITY    0x0008
  102. #define BW_NORMAL    0x0007
  103. #define BW_UNDERLINE 0x0004
  104. static int attribs = BW_NORMAL;
  105.  
  106. #if 1
  107. void
  108. c_putc (char c)
  109. {
  110.   int row, col;
  111.  
  112.   if (attribs == BW_NORMAL || iscntrl(c))
  113.     {
  114.       putchar (c);
  115.       return;
  116.     }
  117.   ScreenGetCursor (&row, &col);
  118.   ScreenPutChar (c, attribs, col, row);
  119.   ScreenSetCursor (row, col + 1);
  120. }
  121. void
  122. c_puts (const char *s)
  123.   int i;
  124.  
  125.   if (attribs == BW_NORMAL)
  126.     {
  127.       fputs (s, stdout);
  128.       return;
  129.     }
  130.   for (i = 0; s[i]; i++)
  131.     c_putc(s[i]);
  132. }
  133. #else
  134. void c_putc (char c)        { putchar (c); }
  135. void c_puts (const char *s)    { fputs (s, stdout); }
  136. #endif
  137.  
  138. void c_gotoxy (int x, int y)    { ScreenSetCursor (y, x); }
  139. void c_wherexy (int *x, int *y)    { ScreenGetCursor (y, x); }
  140.  
  141. static void
  142. addxy (int x, int y)
  143. {
  144.   int col, row;
  145.  
  146.   ScreenGetCursor (&row, &col);
  147.   ScreenSetCursor (row + y, col + x);
  148. }
  149.  
  150. void c_goleft (void)        { addxy (-1,  0); }
  151. void c_goright (void)        { addxy ( 1,  0); }
  152. void c_goup (void)        { addxy ( 0, -1); }
  153. void c_godown (void)        { addxy ( 0,  1); }
  154.  
  155. void c_clrscr (void)        { ScreenClear (); ScreenSetCursor (0, 0); }
  156. void c_home (void)        { ScreenSetCursor (0, 0); }
  157. void c_clreol (void)
  158. {
  159.   int i, col;
  160.  
  161.   ScreenGetCursor (&i, &col);
  162.   for (i = col; i < cols; i++)
  163.     putchar (' ');
  164. }
  165.  
  166. void
  167. c_clrdown (void)
  168. {
  169.   int i, row, col;
  170.  
  171.   ScreenGetCursor (&row, &col);
  172.   clreol ();
  173.   for (i = row + 1; i < rows; i++)
  174.     {
  175.       gotoxy (0, i);
  176.       clreol ();
  177.     }
  178.   gotoxy (col, row);
  179. }
  180.  
  181. void c_bell (void)        { putchar ('\a'); }
  182.  
  183. void c_standout_on (void)    { attribs |= INTENSITY; }
  184. void c_standout_off (void)    { attribs &= ~INTENSITY; }
  185. void c_bright (void)        { standout_on (); }
  186. void c_reverse (void)        { attribs = ((attribs & 0x0007) << 4) |
  187.                         (attribs & 0x0088); }
  188. void c_blinking (void)        { attribs |= BLINK; }
  189. void c_normal (void)        { attribs = BW_NORMAL; }
  190. void c_underline_on (void)    { attribs = (attribs&0x00F8) | BW_UNDERLINE; }
  191. void c_underline_off (void)    { attribs = BW_NORMAL; }
  192.