home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / NFSRC305.ZIP / C / PEEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-01  |  2.4 KB  |  90 lines

  1. /*
  2.  * File......: PEEK.C
  3.  * Author....: Ted Means
  4.  * CIS ID....: 73067,3332
  5.  *
  6.  * This function is an original work by Ted Means and is placed in the
  7.  * public domain.
  8.  *
  9.  * Modification history:
  10.  * ---------------------
  11.  *
  12.  *    Rev 1.3   07 Feb 1994 20:11:50   GLENN
  13.  * Ted re-wrote to make it CPMI compliant.
  14.  *
  15.  *    Rev 1.2   15 Aug 1991 23:08:18   GLENN
  16.  * Forest Belt proofread/edited/cleaned up doc
  17.  *
  18.  *    Rev 1.1   14 Jun 1991 19:53:46   GLENN
  19.  * Minor edit to file header
  20.  *
  21.  *    Rev 1.0   01 Apr 1991 01:02:52   GLENN
  22.  * Nanforum Toolkit
  23.  *
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_PEEK()
  31.  *  $CATEGORY$
  32.  *     DOS/BIOS
  33.  *  $ONELINER$
  34.  *     Retrieve a byte from a specified memory location.
  35.  *  $SYNTAX$
  36.  *     FT_PEEK( <nSegment>, <nOffset> ) -> nValue
  37.  *  $ARGUMENTS$
  38.  *     <nSegment> is the segment of the desired memory address.
  39.  *
  40.  *     <nOffset>  is the offset of the desired memory address.
  41.  *  $RETURNS$
  42.  *     <nValue> will be a value from 0 to 255 if all parameters were valid and
  43.  *              the function was able to retrieve the desired byte.
  44.  *     <nValue> will be -1 if invalid parameters were passed.
  45.  *  $DESCRIPTION$
  46.  *     Use this function if you have a need to examine a specific memory
  47.  *     location.  The function will return the byte at the specified
  48.  *     address as a numeric value.  If you need this value as a character,
  49.  *     use the Chr() function to convert it.
  50.  *
  51.  *     This function was written for version 5.1 of MicroSoft C.  You may
  52.  *     have to modify the source code to use another compiler.
  53.  *  $EXAMPLES$
  54.  *     local nVMode := FT_PEEK( 0, 1097 )  // Get the current video mode
  55.  *  $END$
  56.  */
  57.  
  58. #include <EXTEND.API>
  59. #include <CPMI.H>
  60.  
  61. #define FP_SEG( fp ) ( *( ( unsigned int * ) &( fp ) + 1 ) )
  62. #define FP_OFF( fp ) ( *( ( unsigned int * ) &( fp ) ) )
  63.  
  64. CLIPPER FT_Peek( void )
  65. {
  66.    auto unsigned int ProtMode = cpmiIsProtected();
  67.    auto unsigned char * bytePtr;
  68.  
  69.    if ( ( PCOUNT >= 2 ) && ( ISNUM( 1 ) ) && ( ISNUM( 2 ) ) )
  70.    {
  71.       FP_SEG( bytePtr ) = _parni( 1 );
  72.       FP_OFF( bytePtr ) = _parni( 2 );
  73.  
  74.       if ( ProtMode )
  75.       {
  76.          FP_SEG( bytePtr ) = cpmiProtectedPtr( bytePtr, 1 );
  77.          FP_OFF( bytePtr ) = 0;
  78.  
  79.          if ( FP_SEG( bytePtr ) == 0 ) goto Bogus;
  80.       }
  81.  
  82.       _retni( ( int ) *bytePtr );
  83.  
  84.       if ( ProtMode ) cpmiFreeSelector( FP_SEG( bytePtr ) );
  85.    }
  86.    else
  87.       Bogus: _retni( -1 );
  88.  
  89.    return;
  90. }