home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nforx.zip / CINT86.C next >
C/C++ Source or Header  |  1993-07-15  |  4KB  |  195 lines

  1. /*
  2.  * File......: CINT86.C
  3.  * Author....: Ted Means
  4.  * Date......: $Date:   15 Jul 1993 22:38:34  $
  5.  * Revision..: $Revision:   1.0  $
  6.  * Log file..: $Logfile:   C:/nanfor/src/exo/sav/cint86.c_v  $
  7.  * 
  8.  * This function is an original work by Ted Means and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   C:/nanfor/src/exo/sav/cint86.c_v  $
  15.  * 
  16.  *    Rev 1.0   15 Jul 1993 22:38:34   GLENN
  17.  * Initial revision.
  18.  * 
  19.  *
  20.  */
  21.  
  22. /* Librarian's note:
  23.  *
  24.  * This source code is for a special version of ft_int86(), compatible
  25.  * with the ExoSpace (tm) DOS Extender from SofDesign, International.
  26.  * It is ExoSpace-specific and is maintained separately from the real
  27.  * mode version.
  28.  *
  29.  * The documentation can be found in the real-mode CINT86.C as
  30.  * distributed with the regular Nanforum Toolkit.
  31.  *
  32.  */ 
  33.   
  34.  
  35. #include "EXTEND.H"
  36.  
  37. typedef unsigned int UINT;
  38. typedef unsigned char BYTE;
  39.  
  40. typedef union
  41. {
  42.    void far * Address;
  43.    struct
  44.    {
  45.       UINT Offset;
  46.       UINT Segment;
  47.    } Pointer;
  48. } FARPTR;
  49.  
  50. typedef struct
  51. {
  52.     UINT BX;
  53.     UINT CX;
  54.     UINT DX;
  55.     UINT AX;
  56. } WORDREGS;
  57.  
  58. typedef struct
  59. {
  60.     BYTE BL, BH;
  61.     BYTE CL, CH;
  62.     BYTE DL, DH;
  63.     BYTE AL, AH;
  64. } BYTEREGS;
  65.  
  66. typedef union
  67. {
  68.     WORDREGS w;
  69.     BYTEREGS b;
  70. } REGS;
  71.  
  72. typedef union
  73. {
  74.    UINT registers[ 10 ];
  75.    struct
  76.    {
  77.       UINT DS;
  78.       UINT ES;
  79.       UINT DI;
  80.       UINT SI;
  81.       UINT BP;
  82.       UINT SP;
  83.       REGS regs;
  84.    } CPURegs;
  85. } REGISTERS;
  86.  
  87. void _bcopy( void far * pDest, void far * pSrc, UINT nBytes );
  88.  
  89. UINT ExoRMInterrupt( UINT nInt, REGISTERS far * inregs, REGISTERS far * outregs );
  90.  
  91. FARPTR _xalloclow( UINT nSize );
  92.  
  93. void _xfreelow( FARPTR * pPma );
  94.  
  95. FARPTR ExoRealPtr( FARPTR pPma );
  96.  
  97.  
  98. //                      AX BX CX DX SI DI BP
  99. static int regOff[] = {  9, 6, 8, 7, 3, 2, 4 };
  100.  
  101. CLIPPER FT_Int86( void )
  102. {
  103.    auto REGISTERS regs;
  104.  
  105.    auto FARPTR dsPtr;            // Pointers to incoming params
  106.    auto FARPTR esPtr;
  107.  
  108.    auto FARPTR dsPma;            // Protected mode addresses
  109.    auto FARPTR esPma;
  110.  
  111.    auto FARPTR dsRma;            // Real mode addresses
  112.    auto FARPTR esRma;
  113.  
  114.    auto UINT nLenDS;
  115.    auto UINT nLenES;
  116.    auto UINT n;
  117.  
  118.    dsPma.Address = NULL;   dsRma.Address = NULL;
  119.    esPma.Address = NULL;   esRma.Address = NULL;
  120.  
  121.    if ( ( PCOUNT == 2 ) && ISNUM( 1 ) && ISARRAY( 2 ) )
  122.    {
  123.       if ( _parinfa( 2, 8 ) & CHARACTER )
  124.       {
  125.          nLenDS = _parclen( 2, 8 );
  126.          
  127.          _storclen( NULL, nLenDS, 2, 8 ); dsPtr.Address = _parc( 2, 8 );
  128.  
  129.          dsPma = _xalloclow( nLenDS );
  130.  
  131.          _bcopy( dsPma.Address, dsPtr.Address, nLenDS );
  132.  
  133.          dsRma = ExoRealPtr( dsPma ); regs.CPURegs.DS = dsRma.Pointer.Segment;
  134.       }
  135.       else
  136.          regs.CPURegs.DS = _parni( 2, 8 );
  137.  
  138.       if ( _parinfa( 2, 9 ) & CHARACTER )
  139.       {
  140.          nLenES = _parclen( 2, 9 );
  141.          
  142.          _storclen( NULL, nLenES, 2, 9 ); esPtr.Address = _parc( 2, 9 );
  143.  
  144.          esPma = _xalloclow( nLenES );
  145.  
  146.          _bcopy( esPma.Address, esPtr.Address, nLenES );
  147.  
  148.          esRma = ExoRealPtr( esPma ); regs.CPURegs.ES = esRma.Pointer.Segment;
  149.       }
  150.       else
  151.          regs.CPURegs.ES = _parni( 2, 9 );
  152.  
  153.       for ( n = 1; n <= 7; n++ )
  154.       {
  155.          if ( _parinfa( 2, n ) & LOGICAL )
  156.             if ( _parl( 2, n ) )
  157.                regs.registers[ regOff[ n - 1 ] ] = dsRma.Pointer.Offset;
  158.             else
  159.                regs.registers[ regOff[ n - 1 ] ] = esRma.Pointer.Offset;
  160.          else
  161.             regs.registers[ regOff[ n - 1 ] ] = _parni( 2, n );
  162.       }
  163.  
  164.       _storni( ExoRMInterrupt( _parni( 1 ), ®s, ®s ), 2, 10 );
  165.  
  166.       for ( n = 1; n <= 7; n++ )
  167.          _storni( regs.registers[ regOff[ n - 1 ] ], 2, n );
  168.  
  169.       if ( dsPma.Address == NULL )
  170.          _storni( regs.CPURegs.DS, 2, 8 );
  171.       else
  172.       {
  173.          _bcopy( dsPtr.Address, dsPma.Address, nLenDS );
  174.  
  175.          _xfreelow( dsPma.Address );
  176.       }
  177.  
  178.       if ( esPma.Address == NULL )
  179.          _storni( regs.CPURegs.ES, 2, 9 );
  180.       else
  181.       {
  182.          _bcopy( esPtr.Address, esPma.Address, nLenES );
  183.  
  184.          _xfreelow( esPma.Address );
  185.       }
  186.  
  187.       _retl( TRUE );
  188.    }
  189.    else
  190.       _retl( FALSE );
  191.  
  192.    return;
  193. }
  194.  
  195.