home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / utils / amd-udi / mondfe / io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-23  |  4.3 KB  |  164 lines

  1. static char _[] = "@(#)io.c    5.22 93/10/26 14:50:43, Srini, AMD.";
  2. /******************************************************************************
  3.  * Copyright 1991 Advanced Micro Devices, Inc.
  4.  *
  5.  * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
  6.  * specifically  grants the user the right to modify, use and distribute this
  7.  * software provided this notice is not removed or altered.  All other rights
  8.  * are reserved by AMD.
  9.  *
  10.  * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
  11.  * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
  12.  * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
  13.  * USE OF THIS SOFTWARE.
  14.  *
  15.  * So that all may benefit from your experience, please report  any  problems
  16.  * or  suggestions about this software to the 29K Technical Support Center at
  17.  * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
  18.  * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
  19.  *
  20.  * Advanced Micro Devices, Inc.
  21.  * 29K Support Products
  22.  * Mail Stop 573
  23.  * 5900 E. Ben White Blvd.
  24.  * Austin, TX 78741
  25.  * 800-292-9263
  26.  *****************************************************************************
  27.  *      Engineer: Srini Subramanian.
  28.  *****************************************************************************
  29.  * This file contains the I/O related routines.
  30.  *****************************************************************************
  31.  */
  32.  
  33. #include  <stdio.h>
  34. #include  <string.h>
  35. #ifdef    MSDOS
  36. #include  <conio.h>
  37. #else
  38. #include   <sys/ioctl.h>
  39. #endif
  40. #include  "main.h"
  41. #include  "miniint.h"
  42. #include  "error.h"
  43. #include  "monio.h"
  44.  
  45. /* Function declarations */
  46.  
  47. INT32    Mini_io_setup PARAMS((void));
  48. INT32    Mini_io_reset PARAMS((void));
  49. int    getkey PARAMS((void));
  50. INT32    Mini_poll_kbd PARAMS((char *cmd_buffer, int size, int mode));
  51. int    cmd_io PARAMS ((char *cmd_buffer, char c));
  52. int    channel0_io PARAMS ((char c));
  53.  
  54. INT32
  55. Mini_io_setup()
  56. {
  57.    setbuf(stdout, 0);    /* stdout unbuffered */
  58.    return(SUCCESS);
  59. }
  60.  
  61. INT32
  62. Mini_io_reset()
  63. {
  64. /* Nothing special for now */
  65.  return(SUCCESS);
  66. }
  67.  
  68. /*
  69. ** This function is used to perform all host I/O.  It
  70. ** calls the functions cmd_io() or hif_io() as appropriate
  71. ** Note that there are eight pobible I/O "modes".  These
  72. ** are all possible combination of:
  73. **
  74. **          - Host / Target I/O
  75. **          - HIF / non-HIF I/O
  76. **          - Command file / keyboard I/O
  77. **
  78. */
  79.  
  80. INT32
  81. Mini_poll_kbd(cmd_buffer, size, blockmode)
  82. char    *cmd_buffer;
  83. int    size;
  84. int    blockmode;
  85. {
  86. #ifdef    MSDOS
  87.    char        ch;
  88.    static int    indx=0;
  89.  
  90.    io_config.cmd_ready = FALSE;
  91.    if (blockmode) { /* BLOCK until a command is typed (line buffered) */
  92.      while (gets(cmd_buffer) == NULL); /* no characters in stdin */
  93.      io_config.cmd_ready = TRUE;
  94.    } else { /* NONBLOCk return immediately if there is no command pending */
  95.      if (kbhit()) {
  96.        ch = (unsigned char) getche();
  97.        *(cmd_buffer+indx) = ch;
  98.        indx=indx+1;
  99.        if (ch == (unsigned char) 13) { /* \r, insert \n */
  100.          putchar(10);    /* line feed */
  101.          *(cmd_buffer+indx) = '\0';
  102.              io_config.cmd_ready = TRUE;
  103.          indx=0;
  104.        } else if (ch == (unsigned char) 8) { /* backspace */
  105.      indx=indx-1;
  106.        } else if (ch == (unsigned char) 127) { /* delete */
  107.      indx=indx-1;
  108.        }
  109.      };
  110.    }
  111.    return(SUCCESS);
  112.  
  113. #else
  114.    int   c;
  115.    int   result;
  116.    char *temp_ptr;
  117.    int        tries;
  118.    int        i;
  119.  
  120.    result = 0;
  121.    io_config.cmd_ready = FALSE;
  122.  
  123.    if (blockmode)  {    /* block mode read */
  124.       i = 0;
  125. #ifdef __hpux
  126.       ioctl(fileno(stdin), FIOSNBIO, &i);    /* set blocking read */
  127. #else
  128.       ioctl(fileno(stdin), FIONBIO, &i);    /* set blocking read */
  129. #endif
  130.    } else    {    /* nonblocking read */
  131.            /* for now only read from stdin */
  132.       i = 1;
  133. #ifdef __hpux
  134.       ioctl(fileno(stdin), FIOSNBIO, &i);    /* set non blocking read */
  135. #else
  136.       ioctl(fileno(stdin), FIONBIO, &i);    /* set non blocking read */
  137. #endif
  138.    }
  139.  
  140.    /* Now read from stdin. */
  141.    result = read( 0, cmd_buffer, BUFSIZ );
  142.  
  143.    if (result < 0)
  144.    {
  145.    } else {
  146.       cmd_buffer[result] = '\0';
  147.       io_config.cmd_ready = TRUE;
  148.    }
  149.  
  150.    if (blockmode) {
  151.    } else {
  152.       i = 0;
  153. #ifdef __hpux
  154.       ioctl(fileno(stdin), FIOSNBIO, &i);   /* clear non-blocking read */
  155. #else
  156.       ioctl(fileno(stdin), FIONBIO, &i);   /* clear non-blocking read */
  157. #endif
  158.    }
  159.  
  160.    return(SUCCESS);
  161. #endif
  162. }
  163.  
  164.