home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-27 | 55.2 KB | 2,255 lines |
- Newsgroups: comp.sources.misc
- From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Subject: v27i005: sfs - Space Flight Simulator, Part05/21
- Message-ID: <1991Dec24.045305.29726@sparky.imd.sterling.com>
- X-Md4-Signature: 844e7682c929b5948638c8f26157ee7a
- Date: Tue, 24 Dec 1991 04:53:05 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
- Posting-number: Volume 27, Issue 5
- Archive-name: sfs/part05
- Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
-
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file io/gr/makefile.tam continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 5; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping io/gr/makefile.tam'
- else
- echo 'x - continuing file io/gr/makefile.tam'
- sed 's/^X//' << 'SHAR_EOF' >> '_shar_tmp_.tmp' &&
- M0T9,04=3/0D)+4\@+41$14)51PH*3T9)3$53/0D)9W)?=&5S="YO(&=R7W1A
- M;2YO(&=R7V1E9BYO"@IG<E]T97-T.@DD*$]&24Q%4RD*"0DD*$-#*2`D*$]&
- M24Q%4RD@:V)?-S,P,"YO(%P*"0DM;'1A;2`M;'1E<FUC87`@+6QM("UO(&=R
- M7W1E<W0*"F9O;G1T97-T.@EF;VYT=&5S="YO"@D))"A#0RD@9F]N='1E<W0N
- M;R`M;'1A;2`M;'1E<FUC87`@+6\@9F]N='1E<W0*"G%R9CH)"0H)"6-A="!G
- M<BYH(#YG<BYQ<F8*"0ER;6)O9'D@/&=R7W1A;2YC(#X^9W(N<7)F"@IK8CH*
- ="0EC8R`M3R`M8R`N+B]K8B]K8E\W,S`P+F,*"AIC
- `
- end
- SHAR_EOF
- echo 'File io/gr/makefile.tam is complete' &&
- echo 'uudecoding file io/gr/makefile.tam' &&
- uudecode < _shar_tmp_.tmp && rm -f _shar_tmp_.tmp &&
- chmod 0644 io/gr/makefile.tam ||
- echo 'restore of io/gr/makefile.tam failed'
- Wc_c="`wc -c < 'io/gr/makefile.tam'`"
- test 299 -eq "$Wc_c" ||
- echo 'io/gr/makefile.tam: original size 299, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb.h ==============
- if test ! -d 'io/kb'; then
- echo 'x - creating directory io/kb'
- mkdir 'io/kb'
- fi
- if test -f 'io/kb/kb.h' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb.h' &&
- /*************************************************************************
- X
- X kb.h Header file for keyboard (KB) subroutines
- X for Bywater Software.
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #define KB_ALT 0x500
- X
- #define KB_UP 0x201
- #define KB_DOWN 0x202
- #define KB_LEFT 0x203
- #define KB_RIGHT 0x204
- #define KB_P_UP 0x207
- #define KB_P_DOWN 0x208
- #define KB_HOME 0x209
- #define KB_END 0x20a
- #define KB_INSERT 0x211
- #define KB_DELETE 0x212
- X
- #define KB_FK0 0x220
- #define KB_FK1 0x221
- #define KB_FK2 0x222
- #define KB_FK3 0x223
- #define KB_FK4 0x224
- #define KB_FK5 0x225
- #define KB_FK6 0x226
- #define KB_FK7 0x227
- #define KB_FK8 0x228
- #define KB_FK9 0x229
- X
- SHAR_EOF
- chmod 0644 io/kb/kb.h ||
- echo 'restore of io/kb/kb.h failed'
- Wc_c="`wc -c < 'io/kb/kb.h'`"
- test 1891 -eq "$Wc_c" ||
- echo 'io/kb/kb.h: original size 1891, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_7300.c ==============
- if test -f 'io/kb/kb_7300.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_7300.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_7300.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_7300.c' &&
- /*************************************************************************
- X
- X kb_7300.c Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Implementation for AT&T Unix PC (7300)
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #define ATT_TAM TRUE
- #define ATT_MGR FALSE
- #define WRITE_OUTPUT FALSE
- X
- #include "stdio.h"
- #include "fcntl.h"
- #include "signal.h"
- #include "sys/stat.h"
- #include "termio.h"
- #include "bw.h"
- #include "kb.h"
- X
- #if ATT_TAM
- #include "tam.h"
- #define NO_KEY -1
- #else
- #define NO_KEY FALSE
- #endif
- X
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
- X
- #ifndef ESC
- #define ESC 0x1b
- #endif
- X
- #if ATT_TAM
- extern int w; /* window identifier */
- extern int tam_mready; /* is mouse ready with data ? */
- extern int tam_mx, tam_my; /* mouse position x, y */
- int tam_mb, tam_mr; /* button, reason for mouse */
- int tam_kready = FALSE;
- int kb_hold = 0;
- X
- #if WRITE_OUTPUT
- FILE *outfile;
- #endif
- X
- #else
- struct termio old_ttystruct;
- int kb_tty; /* fd for new terminal file */
- #endif
- X
- X
- #ifdef KB_TEST
- main()
- X {
- X register int s;
- X static char tbuf[ 3 ];
- X
- X kb_init();
- X
- X tbuf[ 0 ] = 0;
- X while ( tbuf[ 0 ] != 0x1b )
- X {
- #if ATT_TAM
- X s = wgetc( w );
- #else
- X s = read( kb_tty, tbuf, 1 );
- #endif
- X printf( "The read() function returned %d \n", s );
- X if ( s > 0 )
- X {
- X printf( "The key is <%c> \n", tbuf[ 0 ] );
- X }
- X }
- X
- X kb_deinit();
- X }
- #endif
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- #if ATT_TAM
- X
- X keypad( 0, 1 );
- X wndelay( w, 1 );
- X
- #if WRITE_OUTPUT
- X if ( ( outfile = fopen( "output", "w" ) ) == NULL )
- X {
- X bw_error( "Failed to open outfile <output> " );
- X }
- #endif
- #else
- X struct termio new_ttystruct;
- X
- X if ( ioctl( 0, TCGETA, &old_ttystruct ) < 0 )
- X {
- X bw_error( "Failed to get old tty parameters." );
- X }
- X
- X if ( ( kb_tty = open( "/dev/tty", O_NDELAY)) == -1 )
- X {
- X bw_error( "Failed to open /dev/tty" );
- X }
- #ifdef DEBUG
- X else
- X {
- X sprintf( bw_ebuf, "/dev/tty returns %d \n", kb_tty );
- X bw_debug( bw_ebuf );
- X }
- #endif
- X
- X if ( ioctl( kb_tty, TCGETA, &new_ttystruct ) < 0 )
- X {
- X bw_error( "Failed to get new tty parameters." );
- X }
- X
- X new_ttystruct.c_cc[4] = 0; /* minimum characters */
- X new_ttystruct.c_cc[5] = 0; /* maximum time */
- X new_ttystruct.c_iflag = 0;
- X new_ttystruct.c_lflag = ISIG;
- X new_ttystruct.c_cflag &= ~CSIZE;
- X new_ttystruct.c_cflag |= CS8;
- X new_ttystruct.c_cflag &= ~PARENB;
- X if ( ioctl( kb_tty, TCSETA, &new_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to set new tty parameters. \n" );
- X }
- X
- #endif
- X
- X }
- X
- X
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- #if ATT_TAM
- #else
- X if ( ioctl( 0, TCSETA, &old_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to restore old tty parameters. \n");
- X }
- #endif
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rxstat()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns 0 if no character is
- X available and 1 if a character is available.
- X
- **************************************************************************/
- X
- kb_rxstat()
- X {
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "kb_rxstat(): enter\n" );
- X fflush( outfile );
- #endif
- X
- X if ( tam_kready == FALSE )
- X {
- X att_rxstat();
- X }
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "kb_rxstat(): returns %d\n", tam_kready );
- X fflush( outfile );
- #endif
- X
- X return tam_kready;
- X }
- X
- att_rxstat()
- X {
- X int r;
- X register int s;
- #if ATT_TAM
- #else
- X static char tbuf[3];
- #endif
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "att_rxstat(): enter\n" );
- X fflush( outfile );
- #endif
- X
- X /* This should be the only point at which a character
- X is read */
- X
- #if ATT_TAM
- X s = wgetc( w );
- #else
- X s = read( kb_tty, tbuf, 1 );
- #endif
- X
- X /* if no character is available, return false */
- X
- X if ( s == NO_KEY )
- X {
- X return FALSE;
- X }
- X
- X /* we have now read a character */
- X
- #if ATT_TAM
- X kb_hold = s;
- #else
- X kb_hold = tbuf[ 0 ];
- #endif
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "att_rxstat(): read kb_hold 0x%02x\n", kb_hold );
- X fflush( outfile );
- #endif
- X
- X /* check to see if the available key indicates
- X an escape sequence of any sort */
- X
- X if ( kb_hold == ESC )
- X {
- X r = att_esc();
- X }
- X else if ( kb_hold > 127 )
- X {
- X r = att_seq( kb_hold );
- X }
- X else
- X {
- X r = kb_hold;
- X }
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "att_rxstat(): read r 0x%02x\n", r );
- X fflush( outfile );
- #endif
- X
- X /* now check to see if there is a key or mouse input
- X available */
- X
- X if ( r == 0 )
- X {
- X if ( ( tam_kready == TRUE ) || ( tam_mready == TRUE ))
- X {
- X return TRUE;
- X }
- X else
- X {
- X return FALSE;
- X }
- X }
- X
- X /* the available key is not 0; thus a character is available
- X as "r" */
- X
- X kb_hold = r;
- X tam_kready = TRUE;
- X return TRUE;
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rx()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate Simple Software KB conventions
- X designated for them.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_rx()
- X {
- #if WRITE_OUTPUT
- X int r;
- X
- X r = att_rx();
- X fprintf( outfile, "kb_rx(): 0x%02x\n", r );
- X fflush( outfile );
- X return r;
- #else
- X return att_rx();
- #endif
- X }
- X
- att_rx()
- X {
- X
- X while( tam_kready == FALSE )
- X {
- X att_rxstat();
- X }
- X
- X tam_kready = FALSE;
- X return kb_hold;
- X }
- X
- att_esc()
- X {
- X register int c;
- X static char sequence[ 3 ];
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "att_esc(): \n" );
- X fflush( outfile );
- #endif
- X
- X if ( kb_rxstat() == TRUE )
- X {
- X sequence[ 0 ] = kb_hold;
- X sequence[ 1 ] = 0;
- X tam_kready = 0;
- X }
- X else
- X {
- X return ESC;
- X }
- X
- X if ( kb_rxstat() == TRUE )
- X {
- X sequence[ 1 ] = kb_hold;
- X sequence[ 2 ] = 0;
- X tam_kready = FALSE;
- X }
- X
- X if ( strcmp( sequence, "[A" ) == 0 )
- X {
- X return KB_UP;
- X }
- X else if ( strcmp( sequence, "[B" ) == 0 )
- X {
- X return KB_DOWN;
- X }
- X else if ( strcmp( sequence, "[D" ) == 0 )
- X {
- X return KB_LEFT;
- X }
- X else if ( strcmp( sequence, "[C" ) == 0 )
- X {
- X return KB_RIGHT;
- X }
- X else if ( strcmp( sequence, "[?" ) == 0 )
- X {
- X tam_mready = TRUE;
- X wreadmouse( w, &tam_mx, &tam_my, &tam_mb, &tam_mr );
- X return 0;
- X }
- X else if ( strcmp( sequence, "Nh" ) == 0 )
- X {
- X return KB_P_DOWN;
- X }
- X else if ( strcmp( sequence, "Ng" ) == 0 )
- X {
- X return KB_P_UP;
- X }
- X else if ( strcmp( sequence, "Nf" ) == 0 )
- X {
- X return KB_DELETE;
- X }
- X else if ( strcmp( sequence, "Nj" ) == 0 )
- X {
- X return KB_INSERT;
- X }
- /*
- X else if ( strcmp( sequence, "Oc" ) == 0 )
- X {
- X return KB_HELP;
- X }
- X else if ( strcmp( sequence, "NK" ) == 0 )
- X {
- X return KB_W_LEFT;
- X }
- X else if ( strcmp( sequence, "NL" ) == 0 )
- X {
- X return KB_W_RIGHT;
- X }
- */
- X else if ( strcmp( sequence, "[H" ) == 0 )
- X {
- X return KB_HOME;
- X }
- X else if ( strcmp( sequence, "NM" ) == 0 )
- X {
- X return KB_HOME;
- X }
- X else if ( strcmp( sequence, "NN" ) == 0 )
- X {
- X return KB_END;
- X }
- X else if ( strcmp( sequence, "O" ) == 0 )
- X {
- X return KB_END;
- X }
- /*
- X else if ( strcmp( sequence, "Ne" ) == 0 )
- X {
- X return KB_D_WORD;
- X }
- X else if ( strcmp( sequence, "NE" ) == 0 )
- X {
- X return KB_D_LINE;
- X }
- X else if ( strcmp( sequence, "Ox" ) == 0 )
- X {
- X return KB_FIND;
- X }
- X else if ( strcmp( sequence, "Oy" ) == 0 )
- X {
- X return KB_REPLACE;
- X }
- X else if ( strcmp( sequence, "Ow" ) == 0 )
- X {
- X return KB_ABANDON;
- X }
- X else if ( strcmp( sequence, "Oo" ) == 0 )
- X {
- X return KB_SAVE;
- X }
- X else if ( strcmp( sequence, "Ok" ) == 0 )
- X {
- X return KB_QUIT;
- X }
- */
- X else
- X {
- X return 0;
- X }
- X }
- X
- att_seq( k )
- X int k;
- X {
- X char *map;
- X
- X map = kcodemap( k );
- X
- #if WRITE_OUTPUT
- X fprintf( outfile, "att_seq(): char 0x%02x, map <%s>\n", k, map + 1 );
- X fflush( outfile );
- #endif
- X
- X if ( strncmp( map + 1, "[A", 2 ) == 0 )
- X {
- X return KB_UP;
- X }
- X else if ( strncmp( map + 1, "[B", 2 ) == 0 )
- X {
- X return KB_DOWN;
- X }
- X else if ( strncmp( map + 1, "[D", 2 ) == 0 )
- X {
- X return KB_LEFT;
- X }
- X else if ( strncmp( map + 1, "[C", 2 ) == 0 )
- X {
- X return KB_RIGHT;
- X }
- X else if ( strncmp( map + 1, "[?", 2 ) == 0 )
- X {
- X tam_mready = TRUE;
- X wreadmouse( w, &tam_mx, &tam_my, &tam_mb, &tam_mr );
- X return 0;
- X }
- X else if ( strncmp( map + 1, "Nh", 2 ) == 0 )
- X {
- X return KB_P_DOWN;
- X }
- X else if ( strncmp( map + 1, "Ng", 2 ) == 0 )
- X {
- X return KB_P_UP;
- X }
- X else if ( strncmp( map + 1, "Nf", 2 ) == 0 )
- X {
- X return KB_DELETE;
- X }
- X else if ( strncmp( map + 1, "Nj", 2 ) == 0 )
- X {
- X return KB_INSERT;
- X }
- /*
- X else if ( strncmp( map + 1, "Oc", 2 ) == 0 )
- X {
- X return KB_HELP;
- X }
- X else if ( strncmp( map + 1, "NK", 2 ) == 0 )
- X {
- X return KB_W_LEFT;
- X }
- X else if ( strncmp( map + 1, "NL", 2 ) == 0 )
- X {
- X return KB_W_RIGHT;
- X }
- */
- X else if ( strncmp( map + 1, "[H", 2 ) == 0 )
- X {
- X return KB_HOME;
- X }
- X else if ( strncmp( map + 1, "NM", 2 ) == 0 )
- X {
- X return KB_HOME;
- X }
- X else if ( strncmp( map + 1, "NN", 2 ) == 0 )
- X {
- X return KB_END;
- X }
- X else if ( strncmp( map + 1, "O", 2 ) == 0 )
- X {
- X return KB_END;
- X }
- /*
- X else if ( strncmp( map + 1, "Ne", 2 ) == 0 )
- X {
- X return KB_D_WORD;
- X }
- X else if ( strncmp( map + 1, "NE", 2 ) == 0 )
- X {
- X return KB_D_LINE;
- X }
- X else if ( strncmp( map + 1, "Ox", 2 ) == 0 )
- X {
- X return KB_FIND;
- X }
- X else if ( strncmp( map + 1, "Oy", 2 ) == 0 )
- X {
- X return KB_REPLACE;
- X }
- X else if ( strncmp( map + 1, "Ow", 2 ) == 0 )
- X {
- X return KB_ABANDON;
- X }
- X else if ( strncmp( map + 1, "Oo", 2 ) == 0 )
- X {
- X return KB_SAVE;
- X }
- X else if ( strncmp( map + 1, "Ok", 2 ) == 0 )
- X {
- X return KB_QUIT;
- X }
- */
- X else
- X {
- X return 0;
- X }
- X }
- SHAR_EOF
- chmod 0644 io/kb/kb_7300.c ||
- echo 'restore of io/kb/kb_7300.c failed'
- Wc_c="`wc -c < 'io/kb/kb_7300.c'`"
- test 12842 -eq "$Wc_c" ||
- echo 'io/kb/kb_7300.c: original size 12842, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_cpm.c ==============
- if test -f 'io/kb/kb_cpm.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_cpm.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_cpm.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_cpm.c' &&
- /*************************************************************************
- X
- X kb_cpm.c Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Implementation for CP/M computers
- X (should work on all CP/M 2.2 machines).
- X utilizing the Eco-C (tm) compiler
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X WARNING: THIS IS AN OUTMODED FILE, unused in most
- X recent versions of this software, or not
- X yet updated and verified to latest revision
- X levels. Use at your own risk. It should not
- X be distributed publicly.
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "kb.h"
- X
- #ifndef CR
- #define CR 0x0d
- #define LF 0x0a
- #define ESC 0x1b
- #endif
- X
- #define DELBACK 0x08
- X
- int cpm_hold = 0;
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_cis()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns 0 if no character is
- X available and 1 if a character is available.
- X
- **************************************************************************/
- X
- kb_cis()
- X {
- X register int c;
- X if ( ( c = _bdos( 0x06, 0xff ) ) == 0 )
- X {
- X cpm_hold = 0;
- X return 0;
- X }
- X else
- X {
- X cpm_hold = c;
- X return 1;
- X }
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_ci()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate Simple Software KB conventions
- X designated for them.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_ci()
- X {
- X int c;
- X if ( cpm_hold != 0 )
- X {
- X c = cpm_hold;
- X cpm_hold = 0;
- X return c;
- X }
- X while ( ( c = _bdos( 0x06, 0xff )) == 0 )
- X ;
- X if ( ( c >= 0x20 ) && ( c < 0x7f ) )
- X {
- X return c;
- X }
- X else
- X {
- X switch ( c )
- X {
- X case 0x05:
- X return KB_UP;
- X break;
- X case 0x18:
- X return KB_DOWN;
- X break;
- X case 0x13:
- X return KB_LEFT;
- X break;
- X case 0x04:
- X return KB_RIGHT;
- X break;
- X case 0x12:
- X return KB_P_UP;
- X break;
- X case 0x03:
- X return KB_P_DOWN;
- X break;
- X case 0x16:
- X return KB_INSERT;
- X break;
- X case 0x07:
- X return KB_DELETE;
- X break;
- X case 0x01:
- X return KB_FK3;
- X break;
- X case 0x06:
- X return KB_FK4;
- X break;
- X case 0x19:
- X return KB_FK5;
- X break;
- X case 0x14:
- X return KB_FK6;
- X break;
- X case 0x0b:
- X case ESC:
- X return cpm_esc();
- X break;
- X case CR:
- X case LF:
- X case DELBACK:
- X return c;
- X break;
- X default:
- X return 0;
- X break;
- X }
- X }
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: cpm_esc()
- X
- X DESCRIPTION: This function handles escape sequences from the
- X keyboard. It calls the kb_emenu() function
- X (defined by the application program), accepts
- X a new command letter, then replace the menu
- X with kb_dmenu (the default menu defined by
- X the application program).
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the Simple Software
- X convention for a special key sequence (see
- X kb.h), or 0.
- X
- **************************************************************************/
- X
- cpm_esc()
- X {
- X register int c;
- X while ( ( c = _bdos( 0x06, 0xff ) ) == 0 )
- X ;
- X switch ( c )
- X {
- X case '1':
- X return KB_FK1;
- X break;
- X case '2':
- X return KB_FK2;
- X break;
- X case '3':
- X return KB_FK3;
- X break;
- X case '4':
- X return KB_FK4;
- X break;
- X case '5':
- X return KB_FK5;
- X break;
- X case '6':
- X return KB_FK6;
- X break;
- X case '7':
- X return KB_FK7;
- X break;
- X case '8':
- X case 'Q':
- X case 'q':
- X return KB_FK8;
- X break;
- X case '9':
- X case 'S':
- X case 's':
- X return KB_FK9;
- X break;
- X case '0':
- X case 'D':
- X case 'd':
- X return KB_FK10;
- X break;
- X default:
- X return 0;
- X break;
- X }
- X }
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_cpm.c ||
- echo 'restore of io/kb/kb_cpm.c failed'
- Wc_c="`wc -c < 'io/kb/kb_cpm.c'`"
- test 6035 -eq "$Wc_c" ||
- echo 'io/kb/kb_cpm.c: original size 6035, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_ibmpc.c ==============
- if test -f 'io/kb/kb_ibmpc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_ibmpc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_ibmpc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_ibmpc.c' &&
- /*************************************************************************
- X
- X kb_ibmpc.c Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Implementation for the IBM PC and Compatibles
- X utilizing BIOS keyboard routines.
- X
- X This implementation contains code specific
- X to the Microsoft Quick C (tm) compiler.
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "stdio.h"
- #include "kb.h"
- #include "bios.h"
- X
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
- X
- #ifndef CR
- #define CR 0x0d
- #endif
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rxstat()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns 0 if no character is
- X available and 1 if a character is available.
- X
- **************************************************************************/
- X
- kb_rxstat()
- X {
- X if ( _bios_keybrd( _KEYBRD_READY ) == 0 )
- X {
- X return FALSE;
- X }
- X else
- X {
- X return TRUE;
- X }
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rx()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate Simple Software KB conventions
- X designated for them.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_rx()
- X {
- X unsigned int ax;
- X unsigned char ah, al;
- X
- X while( kb_rxstat() == 0 )
- X {
- X }
- X
- X ax = _bios_keybrd( _KEYBRD_READ );
- X ah = ax / 256;
- X al = ax % 256;
- X
- X if ( al != 0 )
- X {
- X return al;
- X }
- X
- X else
- X {
- X switch( ah )
- X {
- X case 0x50:
- X return KB_DOWN;
- X break;
- X case 0x48:
- X return KB_UP;
- X break;
- X case 0x4b:
- X return KB_LEFT;
- X break;
- X case 0x4d:
- X return KB_RIGHT;
- X break;
- X case 0x49:
- X return KB_P_UP;
- X break;
- X case 0x51:
- X return KB_P_DOWN;
- X break;
- X case 0x53:
- X return KB_DELETE;
- X break;
- X case 0x52:
- X return KB_INSERT;
- X break;
- X case 0x4f:
- X return KB_END;
- X break;
- X case 0x47:
- X return KB_HOME;
- X break;
- X case 0x3b: /* FK 1 */
- X case 0x54:
- X return KB_FK1;
- X break;
- X case 0x3c: /* FK 2 */
- X case 0x55:
- X return KB_FK2;
- X break;
- X case 0x3d: /* FK 3 */
- X case 0x56:
- X return KB_FK3;
- X break;
- X case 0x3e: /* FK 4 */
- X case 0x57:
- X return KB_FK4;
- X break;
- X case 0x3f: /* FK 5 */
- X case 0x58:
- X return KB_FK5;
- X break;
- X case 0x40: /* FK 6 */
- X case 0x59:
- X return KB_FK6;
- X break;
- X case 0x41: /* FK 7 */
- X case 0x5a:
- X return KB_FK7;
- X break;
- X case 0x42: /* FK 8 */
- X case 0x5b:
- X return KB_FK8;
- X break;
- X case 0x43: /* FK 9 */
- X case 0x5c:
- X return KB_FK9;
- X break;
- X case 0x44: /* FK 10 */
- X case 0x5d:
- X return KB_FK0;
- X break;
- X case 0x10:
- X return KB_ALT + 'Q';
- X break;
- X case 0x11:
- X return KB_ALT + 'W';
- X break;
- X case 0x12:
- X return KB_ALT + 'E';
- X break;
- X case 0x13:
- X return KB_ALT + 'R';
- X break;
- X case 0x14:
- X return KB_ALT + 'T';
- X break;
- X case 0x15:
- X return KB_ALT + 'Y';
- X break;
- X case 0x16:
- X return KB_ALT + 'U';
- X break;
- X case 0x17:
- X return KB_ALT + 'I';
- X break;
- X case 0x18:
- X return KB_ALT + 'O';
- X break;
- X case 0x19:
- X return KB_ALT + 'P';
- X break;
- X case 0x1E:
- X return KB_ALT + 'A';
- X break;
- X case 0x1F:
- X return KB_ALT + 'S';
- X break;
- X case 0x20:
- X return KB_ALT + 'D';
- X break;
- X case 0x21:
- X return KB_ALT + 'F';
- X break;
- X case 0x22:
- X return KB_ALT + 'G';
- X break;
- X case 0x23:
- X return KB_ALT + 'H';
- X break;
- X case 0x24:
- X return KB_ALT + 'J';
- X break;
- X case 0x25:
- X return KB_ALT + 'K';
- X break;
- X case 0x26:
- X return KB_ALT + 'L';
- X break;
- X case 0x2C:
- X return KB_ALT + 'Z';
- X break;
- X case 0x2D:
- X return KB_ALT + 'X';
- X break;
- X case 0x2E:
- X return KB_ALT + 'C';
- X break;
- X case 0x2F:
- X return KB_ALT + 'V';
- X break;
- X case 0x30:
- X return KB_ALT + 'B';
- X break;
- X case 0x31:
- X return KB_ALT + 'N';
- X break;
- X case 0x32:
- X return KB_ALT + 'M';
- X break;
- X default:
- X return 0;
- X break;
- X }
- X }
- X }
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_ibmpc.c ||
- echo 'restore of io/kb/kb_ibmpc.c failed'
- Wc_c="`wc -c < 'io/kb/kb_ibmpc.c'`"
- test 6597 -eq "$Wc_c" ||
- echo 'io/kb/kb_ibmpc.c: original size 6597, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_spec.c ==============
- if test -f 'io/kb/kb_spec.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_spec.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_spec.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_spec.c' &&
- /*************************************************************************
- X
- X kb_spec.c Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Specification for developing new implementations.
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "kb.h"
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rxstat()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns FALSE if no character is
- X available and TRUE if a character is available.
- X
- **************************************************************************/
- X
- kb_rxstat()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rx()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate KB conventions designated for
- X them in "kb.h".
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_rx()
- X {
- X }
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_spec.c ||
- echo 'restore of io/kb/kb_spec.c failed'
- Wc_c="`wc -c < 'io/kb/kb_spec.c'`"
- test 3370 -eq "$Wc_c" ||
- echo 'io/kb/kb_spec.c: original size 3370, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_sysv.c ==============
- if test -f 'io/kb/kb_sysv.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_sysv.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_sysv.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_sysv.c' &&
- /*************************************************************************
- X
- X kb_sysv.c Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Implementation for Unix SYSTEM V
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "stdio.h"
- #include "fcntl.h"
- #include "signal.h"
- #include "sys/stat.h"
- #include "termio.h"
- X
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
- X
- struct termio old_ttystruct;
- int kb_tty; /* fd for new terminal file */
- X
- #ifdef KB_TEST
- main()
- X {
- X register int s;
- X static char tbuf[ 3 ];
- X
- X kb_init();
- X
- X tbuf[ 0 ] = 0;
- X while ( tbuf[ 0 ] != 0x1b )
- X {
- X s = read( kb_tty, tbuf, 1 );
- X printf( "The read() function returned %d \n", s );
- X if ( s > 0 )
- X {
- X printf( "The key is <%c> \n", tbuf[ 0 ] );
- X }
- X }
- X
- X kb_deinit();
- X }
- #endif
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- X struct termio new_ttystruct;
- X
- X if ( ioctl( 0, TCGETA, &old_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to get old tty parameters. \n" );
- X }
- X
- X if ( ( kb_tty = open( "/dev/tty", O_NDELAY)) == -1 )
- X {
- X fprintf( stderr, "Failed to open /dev/tty \n" );
- X }
- #ifdef DEBUG
- X else
- X {
- X fprintf( stderr, "/dev/tty returns %d \n", kb_tty );
- X }
- #endif
- X
- X if ( ioctl( kb_tty, TCGETA, &new_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to get new tty parameters. \n" );
- X }
- X
- X new_ttystruct.c_cc[4] = 0; /* minimum characters */
- X new_ttystruct.c_cc[5] = 0; /* maximum time */
- X new_ttystruct.c_iflag = 0;
- X new_ttystruct.c_lflag = ISIG;
- X new_ttystruct.c_cflag &= ~CSIZE;
- X new_ttystruct.c_cflag |= CS8;
- X new_ttystruct.c_cflag &= ~PARENB;
- X if ( ioctl( kb_tty, TCSETA, &new_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to set new tty parameters. \n" );
- X }
- X
- X }
- X
- X
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- X if ( ioctl( 0, TCSETA, &old_ttystruct ) < 0 )
- X {
- X fprintf( stderr, "Failed to restore old tty parameters. \n");
- X }
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rxstat()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns 0 if no character is
- X available and 1 if a character is available.
- X
- **************************************************************************/
- X
- int kb_available = 0;
- int kb_hold = 0;
- X
- kb_rxstat()
- X {
- X register int s;
- X static char tbuf[3];
- X
- X if ( kb_available == TRUE )
- X {
- X return TRUE;
- X }
- X else
- X {
- X s = read( kb_tty, tbuf, 1 );
- X if ( s == FALSE )
- X {
- X kb_available = FALSE;
- X return FALSE;
- X }
- X else
- X {
- X kb_hold = tbuf[ 0 ];
- X kb_available = TRUE;
- X return TRUE;
- X }
- X }
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rx()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate Simple Software KB conventions
- X designated for them.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_rx()
- X {
- X
- X while( kb_rxstat() == FALSE )
- X {
- X ;
- X }
- X
- X kb_available = FALSE;
- X return kb_hold;
- X }
- X
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_sysv.c ||
- echo 'restore of io/kb/kb_sysv.c failed'
- Wc_c="`wc -c < 'io/kb/kb_sysv.c'`"
- test 5260 -eq "$Wc_c" ||
- echo 'io/kb/kb_sysv.c: original size 5260, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_test.c ==============
- if test -f 'io/kb/kb_test.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_test.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_test.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_test.c' &&
- /*************************************************************************
- X
- X kb_test.c Test Keyboard (KB) Subroutines
- X for Bywater Software
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "stdio.h"
- #include "kb.h"
- X
- #define ESC 0x1b
- X
- main()
- X {
- X unsigned c;
- X kb_init();
- X
- X printf( "Test of KB functions. \n" );
- X printf( "Press ESCAPE to exit. \n" );
- X
- X c = 0;
- X while( c != ESC )
- X {
- X c = kb_rx();
- X switch ( c )
- X {
- X case KB_LEFT:
- X printf( "Key:\tLEFT \n" );
- X break;
- X case KB_RIGHT:
- X printf( "Key:\tRIGHT \n" );
- X break;
- X case KB_UP:
- X printf( "Key:\tUP \n" );
- X break;
- X case KB_DOWN:
- X printf( "Key:\tDOWN \n" );
- X break;
- X case KB_HOME:
- X printf( "Key:\tHOME \n" );
- X break;
- X case KB_END:
- X printf( "Key:\tEND \n" );
- X break;
- X case KB_P_UP:
- X printf( "Key:\tPAGE UP \n" );
- X break;
- X case KB_P_DOWN:
- X printf( "Key:\tPAGE DOWN \n" );
- X break;
- X case KB_INSERT:
- X printf( "Key:\tINSERT \n" );
- X break;
- X case KB_DELETE:
- X printf( "Key:\tDELETE \n" );
- X break;
- X case KB_FK0:
- X printf( "Key:\tFK 10 \n" );
- X break;
- X case KB_FK1:
- X printf( "Key:\tFK 1 \n" );
- X break;
- X case KB_FK2:
- X printf( "Key:\tFK 2 \n" );
- X break;
- X case KB_FK3:
- X printf( "Key:\tFK 3 \n" );
- X break;
- X case KB_FK4:
- X printf( "Key:\tFK 4 \n" );
- X break;
- X case KB_FK5:
- X printf( "Key:\tFK 5 \n" );
- X break;
- X case KB_FK6:
- X printf( "Key:\tFK 6 \n" );
- X break;
- X case KB_FK7:
- X printf( "Key:\tFK 7 \n" );
- X break;
- X case KB_FK8:
- X printf( "Key:\tFK 8 \n" );
- X break;
- X case KB_FK9:
- X printf( "Key:\tFK 9 \n" );
- X break;
- X default:
- X if ( ( c & KB_ALT ) == 0 )
- X {
- X printf( "Key:\t%c \n", c );
- X }
- X else
- X {
- X printf( "Key:\tALT-%c \n", ( c & 127 ));
- X }
- X break;
- X }
- X }
- X kb_deinit();
- X }
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_test.c ||
- echo 'restore of io/kb/kb_test.c failed'
- Wc_c="`wc -c < 'io/kb/kb_test.c'`"
- test 2861 -eq "$Wc_c" ||
- echo 'io/kb/kb_test.c: original size 2861, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/kb/kb_x.c ==============
- if test -f 'io/kb/kb_x.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/kb/kb_x.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/kb/kb_x.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/kb/kb_x.c' &&
- /*************************************************************************
- X
- X kb_x.c Keyboard (KB) Subroutines
- X for Bywater Software.
- X
- X Implementation for X Windows System
- X Depends on gr_x.c
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@hercules.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- **************************************************************************/
- X
- #include "stdio.h"
- #include "kb.h"
- X
- #ifndef TRUE
- #define TRUE 1
- #define FALSE 0
- #endif
- X
- #ifndef ESC
- #define ESC 0x1b
- #endif
- X
- extern int x_keybevent;
- extern int x_keypending;
- X
- /*************************************************************************
- X
- X FUNCTION: kb_init()
- X
- X DESCRIPTION: This function should perform any initialization
- X necessary for the keyboard system.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_init()
- X {
- X }
- X
- X
- /*************************************************************************
- X
- X FUNCTION: kb_deinit()
- X
- X DESCRIPTION: This function should perform any necessary
- X deinitialization, that is, return the keyboard
- X to its default state when a Simple Software
- X program is to be exited.
- X
- X INPUT: none.
- X
- X RETURNS: none.
- X
- **************************************************************************/
- X
- kb_deinit()
- X {
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rxstat()
- X
- X DESCRIPTION: This function determines whether a character is
- X ready from the console. The function is used
- X especially in telecommunications programs,
- X where it is necessary to poll the keyboard
- X without locking up the program waiting for a
- X response.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns 0 if no character is
- X available and 1 if a character is available.
- X
- **************************************************************************/
- X
- kb_rxstat()
- X {
- X if ( x_keybevent == TRUE )
- X {
- X return TRUE;
- X }
- X x_pollevent();
- X if ( x_keybevent == TRUE )
- X {
- X return TRUE;
- X }
- X return FALSE;
- X }
- X
- /*************************************************************************
- X
- X FUNCTION: kb_rx()
- X
- X DESCRIPTION: This function returns a single character from
- X the keyboard. If a character is not available
- X it waits. The function should be able to
- X recognize any special keys, and return the
- X appropriate Simple Software KB conventions
- X designated for them.
- X
- X INPUT: none.
- X
- X RETURNS: The function returns the ASCII code for the
- X key pressed, or the Simple Software KB convention
- X (see kb.h) for a function or other special key.
- X
- **************************************************************************/
- X
- kb_rx()
- X {
- X
- X while( x_keybevent == FALSE )
- X {
- X x_pollevent();
- X }
- X x_keybevent = FALSE;
- X return ( x_keypending );
- X
- X }
- X
- SHAR_EOF
- chmod 0644 io/kb/kb_x.c ||
- echo 'restore of io/kb/kb_x.c failed'
- Wc_c="`wc -c < 'io/kb/kb_x.c'`"
- test 3981 -eq "$Wc_c" ||
- echo 'io/kb/kb_x.c: original size 3981, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/tw/tw.h ==============
- if test ! -d 'io/tw'; then
- echo 'x - creating directory io/tw'
- mkdir 'io/tw'
- fi
- if test -f 'io/tw/tw.h' -a X"$1" != X"-c"; then
- echo 'x - skipping io/tw/tw.h (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/tw/tw.h (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/tw/tw.h' &&
- /****************************************************************
- X
- X tw.h Header for Graphics Text Window
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@teer3.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- struct tw_struct
- X {
- X int x1; /* left side in graphics coords */
- X int y1; /* bottom in graphics coords */
- X int x2; /* right side in graphics coords */
- X int y2; /* top in graphics coords */
- X int fxsize; /* font size graphics coords */
- X int fysize; /* font size graphics coords */
- X int lines; /* number of text lines */
- X int columns; /* number of text columns */
- X }
- X
- X
- extern struct tw_struct *tw_init();
- SHAR_EOF
- chmod 0644 io/tw/tw.h ||
- echo 'restore of io/tw/tw.h failed'
- Wc_c="`wc -c < 'io/tw/tw.h'`"
- test 1832 -eq "$Wc_c" ||
- echo 'io/tw/tw.h: original size 1832, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= io/tw/tw_ibmpc.c ==============
- if test -f 'io/tw/tw_ibmpc.c' -a X"$1" != X"-c"; then
- echo 'x - skipping io/tw/tw_ibmpc.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting io/tw/tw_ibmpc.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'io/tw/tw_ibmpc.c' &&
- /****************************************************************
- X
- X tw_ibmpc.c Graphics Text Window
- X for IBM PC (tm) and compatibles
- X utilizing Microsoft QuickC (tm)
- X
- X Copyright (c) 1991, Ted A. Campbell
- X
- X Bywater Software
- X P. O. Box 4023
- X Duke Station
- X Durham, NC 27706
- X
- X email: tcamp@teer3.acpub.duke.edu
- X
- X Copyright and Permissions Information:
- X
- X All U.S. and international copyrights are claimed by the
- X author. The author grants permission to use this code
- X and software based on it under the following conditions:
- X (a) in general, the code and software based upon it may be
- X used by individuals and by non-profit organizations; (b) it
- X may also be utilized by governmental agencies in any country,
- X with the exception of military agencies; (c) the code and/or
- X software based upon it may not be sold for a profit without
- X an explicit and specific permission from the author, except
- X that a minimal fee may be charged for media on which it is
- X copied, and for copying and handling; (d) the code must be
- X distributed in the form in which it has been released by the
- X author; and (e) the code and software based upon it may not
- X be used for illegal activities.
- X
- ****************************************************************/
- X
- #include "stdio.h"
- X
- #include "graph.h"
- X
- #ifdef __STDC__
- #include "malloc.h"
- #else
- extern char * malloc();
- #endif
- X
- #include "bw.h"
- #include "gr.h"
- #include "tw.h"
- X
- #define DEF_LINES 25
- #define DEF_COLUMNS 80
- X
- static struct tw_struct * cur_twstruct = NULL;
- X
- struct tw_struct *
- tw_init( rq_x1, rq_y2, rq_lines, rq_cols, min_x1, min_y1, max_x2, max_y2 )
- X int rq_x1; /* requested x1 (left, graphics) position */
- X int rq_y2; /* requested y2 (top, graphics) position */
- X int rq_lines; /* requested text lines */
- X int rq_cols; /* requested text columns */
- X int min_x1; /* leftmost allowable position */
- X int min_y1; /* bottommost allowable position */
- X int max_x2; /* rightmost allowable position */
- X int max_y2; /* topmost allowable position */
- X {
- X static struct videoconfig ibm_vc;
- X struct tw_struct *tw;
- X int x, y;
- X
- X /* get memory for tw_struct structure */
- X
- X if ( ( tw = (struct tw_struct *) malloc( sizeof( struct tw_struct ))) == NULL )
- X {
- X bw_error( "Failed to find memory for window." );
- X return NULL;
- X }
- X
- X /* determine current size of screen and then text fonts */
- X
- X _getvideoconfig( &ibm_vc );
- X tw->fxsize = ibm_vc.numxpixels / DEF_COLUMNS;
- X if ( ibm_vc.mode == _HERCMONO )
- X {
- X tw->fysize = ( ibm_vc.numypixels + 2 ) / DEF_LINES;
- SHAR_EOF
- true || echo 'restore of io/tw/tw_ibmpc.c failed'
- fi
- echo 'End of part 5'
- echo 'File io/tw/tw_ibmpc.c is continued in part 6'
- echo 6 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-