viernes, 21 de abril de 2017

Encrypt/Decrypt module for SuperPro (Clipper)


/*****************************************************************************
*
*       Encrypt/Decrypt module for SuperPro (Clipper)
*
*
(C) Copyright 1986-1994 Rainbow Technologies, Inc. All rights reserved.
*
*****************************************************************************/

/*============================ V a r i a b l e s ===========================*/
static unsigned char      far  *CodePtr; /* Ptr. to byte to encrypt/decrypt */
static unsigned short int far  *wordPtr; /* Points to a word                */
static unsigned short int       tXseed;  /* Temp for encrypt/decrypt seed   */
static unsigned short int       tCount;  /* Temp for Xcount                 */
static unsigned short int       tMod;    /* Seed's adjustment value         */
static unsigned char            tSwap;   /* Temp for swapping bytes         */
/*==========================================================================*/

/****************************************************************************/
/* This subroutine sets up the variable tCount to contain the # of bytes of */
/* the SuperPro driver that are to be encrypted. This is done as follows:   */
/*   If Xcount is not 0, then tCount is just a copy of Xcount.              */
/*   If Xcount is 0, tCount is the number of bytes between Xstart and the   */
/*   last byte of the driver including both of those bytes.                 */
/****************************************************************************/
void DoMacroCore(unsigned int startX, unsigned int countX)
{
  wordPtr = ((unsigned short int far *)SUPERPRO) - 2;
                   /* Point 2 words (4 bytes) before the SuperPro entry     */
                   /* point. This word is used to decrypt the next word     */
                   /* in order to get the length of the SuperPro driver.    */

  tCount = *wordPtr;    /* Use this value to decrypt the SuperPro length.   */
  wordPtr++;            /* Advance 1 word (to the SuperPro length).         */
  tCount ^= *wordPtr;   /* tCount is now the length of the SuperPro driver  */

  if (countX == 0)
  {                     /* If 0, get the number of bytes from startX to     */
    tCount -= startX;   /* the end of the SuperPro driver (inclusive).      */
                        /* Note: we do not need to add 1 to this result     */
                        /* because tCount is 1-based and startX is 0-based. */
  }
  else
  {
    tCount = countX;    /* Not 0, so tCount gets what the user gave us      */
  }
}


/****************************************************************************/
/* Subroutine for Encrypting, by Xoring each byte with a seed.              */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int CryptX(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    *CodePtr ^= tXseed; /* Encrypt byte in SuperPro driver.                 */
    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Encrypting, by adding a seed to each byte.                */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int CryptA(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    *CodePtr += tXseed; /* Encrypt byte in SuperPro driver.                 */
    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Encrypting, by Rotating each byte left or right 1 bit.    */
/* The direction depends upon the current seed value.                       */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int CryptR(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    if ((tXseed & 1) == 0)
    {                   /* If tXseed is EVEN then rotate the bits right     */
      *CodePtr = (*CodePtr >> 1) | ((*CodePtr & 1) << 7);
    }
    else
    {                   /* If tXseed is ODD then rotate the bits left       */
      *CodePtr = (*CodePtr << 1) | ((*CodePtr & 0xEF) >> 7);
    }

    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Encrypting, by swapping byte pairs. This implies          */
/* that the range to encrypt must be an even number of bytes.               */
/* The seed is not currently used in this method (yet).                     */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int CryptS(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  if ((tCount & 1) != 0)         /* If count is odd . . .                   */
  {
    tCount -= 1;                 /* make count even                         */
  }

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    tSwap        = *CodePtr;     /* Copy 1st byte of byte pair              */
    *CodePtr     = *(CodePtr+1); /* Move 2nd byte of pair into 1st byte     */
    *(CodePtr+1) = tSwap;        /* Move 1st byte of pair into 2nd byte     */
    CodePtr     += 2;            /* Point to next byte pair.                */
    tXseed      += tMod;         /* Modify seed.                            */
    tCount      -= 2;            /* Decrement bytes left to be encrypted    */
  }
}


/****************************************************************************/
/* Subroutine for Decrypting, by Xoring each byte with a seed.              */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int DecryptX(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4) );

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    *CodePtr ^= tXseed; /* Encrypt byte in SuperPro driver.                 */
    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Decrypting, by Subtracting a seed from each byte.         */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int DecryptA(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    *CodePtr -= tXseed; /* Encrypt byte in SuperPro driver.                 */
    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Decrypting, by Rotating each byte left or right 1 bit.    */
/* The direction depends upon the current seed value.                       */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int DecryptR(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    if ((tXseed & 1) == 1)
    {                   /* If tXseed is ODD then rotate the bits right      */
      *CodePtr = (*CodePtr >> 1) | ((*CodePtr & 1) << 7);
    }
    else
    {                   /* If tXseed is EVEN then rotate the bits left      */
      *CodePtr = (*CodePtr << 1) | ((*CodePtr & 0xEF) >> 7);
    }

    CodePtr++;          /* Point to next byte.                              */
    tXseed += tMod;     /* Modify seed.                                     */
    tCount--;           /* Decrement bytes remaining to be encrypted        */
  }
}


/****************************************************************************/
/* Subroutine for Decrypting, by swapping byte pairs. This implies          */
/* that the range to decrypt must be an even number of bytes.               */
/* The seed is not currently used in this method (yet).                     */
/* None of the parameters are modified.                                     */
/****************************************************************************/
int DecryptS(unsigned int Xseed, unsigned int Xmod,
        unsigned int Xstart, unsigned int Xcount)
{
  DoMacroCore(_parni(3), _parni(4));

  tXseed = _parni(1);
  tMod   = _parni(2);

  if ((tCount & 1) != 0)         /* If count is odd . . .                   */
  {
    tCount -= 1;                 /* make count even                         */
  }

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(3);
                        /* Point at 1st byte in SuperPro driver to encrypt  */
  while (tCount > 0)
  {
    tSwap        = *CodePtr;     /* Copy 1st byte of byte pair              */
    *CodePtr     = *(CodePtr+1); /* Move 2nd byte of pair into 1st byte     */
    *(CodePtr+1) = tSwap;        /* Move 1st byte of pair into 2nd byte     */
    CodePtr     += 2;            /* Point to next byte pair.                */
    tXseed      += tMod;         /* Modify seed.                            */
    tCount      -= 2;            /* Decrement bytes left to be encrypted    */
  }
}


/****************************************************************************/
/* Subroutine to calculate a Long (32-bit) checksum over a given range.     */
/* The variable replaced by Xsum will be modified. Note that it is up to the*/
/* programmer to make sure this variable has the desired value before using */
/* this subr. (i.e. this subr. does not zero the variable replaced by Xsum  */
/* before using it!)                                                        */
/****************************************************************************/
int ChkSum(unsigned int Xstart, unsigned int Xcount, unsigned long Xsum)
{
  unsigned long sumX;

  sumX = 0;
  DoMacroCore(_parni(1), _parni(2));

  CodePtr = (unsigned char far *)(SUPERPRO) + _parni(1);
                        /* Point at 1st byte in SuperPro driver to checksum */
  while (tCount > 0)
  {
    sumX   += *CodePtr; /* Add byte of SuperPro driver to checksum value.   */
    CodePtr++;          /* Point to next byte.                              */
    tCount--;           /* Decrement bytes remaining to be checksummed      */
  }
  _retnl(sumX);         /* return the LONG checksum value to VB's Xsum var. */
}





*********************************************************************************
************************************************************************************
/****************************************************************************
 *            SuperPro (Clipper) Multiple Entry Points Module               *
    (C) Copyright 1986-1994 Rainbow Technologies, Inc. All rights reserved.
 ****************************************************************************
 * This module provides a method for performing SuperPro API commands so    *
 * so you do not have to deal with command packets.  It provides a function *
 * for each API command.                                                    *
 ****************************************************************************/

#include "superpro.h"           /* include of core driver definitions */
#include "extend.h"             /* for _retni, <others> */

APIPACKET ApiPacket;            /* API Command Packet */
UNITINFO  InitialUI ;

/****************************************************************************
 *
 *  Function: SPROINIT
 *  Purpose : To initialize the SuperPro Driver
 *
 *  Inputs      : NONE
 *  Outputs     : NONE
 *  Return Value: Status
 *
 *  Description : This routine does autotiming and checks for the valid port
 *                addresses based on the values passed in through the API
 *                packet's portAddrs field.
 ****************************************************************************/
int SPROINIT(void)
{
  int   error ;

  ApiPacket.functionCode = API_INITIALIZE;
  ApiPacket.intMode      = DEFAULT_INT_METHODS;
  ApiPacket.portAddrs[0] = 0;   /* DEFAULT_PORT_ADDRESS1; */
  ApiPacket.portAddrs[1] = 0;   /* DEFAULT_PORT_ADDRESS2; */
  ApiPacket.portAddrs[2] = 0;   /* DEFAULT_PORT_ADDRESS3; */
  ApiPacket.portAddrs[3] = 0;   /* DEFAULT_PORT_ADDRESS4; */
  ApiPacket.InitialPICMask1 = DEFAULT_PIC_MASK1;
  ApiPacket.InitialPICMask2 = DEFAULT_PIC_MASK2;
  error = SUPERPRO(&ApiPacket);
  InitialUI = ApiPacket.ui;
  _retni(error);
  return(error);
}


/****************************************************************************
 *
 *  Function: sproGetExtendedStatus
 *  Purpose : Return the Status (Word) from the previous SuperPro API Call.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *  Outputs     : Status word in function result
 *  Return Value: Status (Word)
 *
 **************************************************************************/
int SPROGXST(UNITINFO *unitinfo)
{
    int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
/*  if ... ApiPacket.ui = unitinfo;    */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }
  ApiPacket.functionCode  = API_GET_EXTENDED_STATUS;

  error = SUPERPRO(&ApiPacket);
/*    unitinfo = ApiPacket.ui;    */
  len = _parclen(1);
  if (len)
    _storclen(Aptr, len, 1);
  _retni(error);
  return(error);
}


typedef struct {
          unsigned short int O, S;
        } OS, *OSPtr;

unsigned short int LoWord(long);
unsigned short int HiWord(long);

unsigned short int HiWord(long L)
// Return high-order word of L
{
  return ((unsigned short int) ((OSPtr)&L)->S);
}

unsigned short int LoWord(long L)
// Return low-order word of L
{
  return ((unsigned short int) ((OSPtr)&L)->O);
}

 /****************************************************************************
 * Function    : sproGetVersion
 *
 * Purpose     : Returns the driver's version number.
 *
 * Inputs      : thePacket  - pointer to a user allocated API packet.
 *               majVer     - is a pointer to where to store the major version.
 *               minVer     - is a pointer to where to store the minor version.
 *               rev        - is a pointer to where to store the revision.
 *               osDrvrType - is a pointer to where to store the os driver type.
 *
 * Outputs     : majVer     - is a pointer to where to store the major version.
 *               minVer     - is a pointer to where to store the minor version.
 *               rev        - is a pointer to where to store the revision.
 *               osDrvrType - is a pointer to where to store the os driver type.
 *
 * Return Value: Status
 *
 **************************************************************************/
int SPROGVER(UNITINFO *unitinfo,
                   unsigned char *majVer,
                   unsigned char *minVer,
                   unsigned char *rev,
                   unsigned char *osDrvrType )
{
    int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;
  unsigned char word;

  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
/*  if ... ApiPacket.ui = unitinfo;    */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }
  ApiPacket.functionCode  = API_GET_VERSION;
     error = SUPERPRO(&ApiPacket);

  if (!error) {
    word = LoWord(ApiPacket.longResult);
    _storni(word, 2);
    word = LoWord(ApiPacket.longResult) >> 8;
    _storni(word, 3);
    word = HiWord(ApiPacket.longResult);
    _storni(word, 4);
    word = HiWord(ApiPacket.longResult) >> 8;
    _storni(word, 5);
    }
  _retni(error);
  return(error);
}



/****************************************************************************
 *
 *  Function: SPROFIRST
 *  Purpose : Find a SuperPro with the specified developer ID and return a
 *            a unit handle.
 *
 *  Inputs      : developerID - your assigned 16 bit developer.
 *
 *  Outputs     : *unitInfo - ptr to a unit info handle structure.
 *
 *  Return Value: Status
 *
 **************************************************************************/
int SPROFIRST(unsigned int developerID, UNITINFO *unitinfo)
{
  int   error;
  unsigned int len;
  char  *Aptr = &ApiPacket.ui;

  ApiPacket.functionCode    = API_FIND_FIRST_UNIT;
  ApiPacket.memoryContents  = _parni(1);        /* developerID */
  ApiPacket.ui = InitialUI;

  error = SUPERPRO(&ApiPacket);

/*    if ... unitinfo = ApiPacket.ui;    */
  len = _parclen(2);
  if (len)
    _storclen(Aptr, len, 2);

  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPRONEXT
 *  Purpose : To find the next SuperPro unit with the same developer ID
 *            as the unit specified by the unitinfo parameter, and return
 *            a new unit handle.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *  Outputs     : *unitInfo - ptr to a new unit info handle structure.
 *  Return Value: Status
 *
 **************************************************************************/
int SPRONEXT(UNITINFO *unitinfo)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
/*  if ... ApiPacket.ui = unitinfo;    */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode = API_FIND_NEXT_UNIT;
  error = SUPERPRO(&ApiPacket);
/*    unitinfo = ApiPacket.ui;    */
  len = _parclen(1);
  if (len)
    _storclen(Aptr, len, 1);
  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPROREAD
 *  Purpose : To read the data in a readable SuperPro Cell
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 address - address 0-63 of the cell of interest.
 *  Outputs     : *data - ptr to 16 bit contents of the addressed cell.
 *  Return Value: Status
 *
 **************************************************************************/
int SPROREAD(UNITINFO *unitinfo, int address, unsigned int *data)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }
  ApiPacket.functionCode  = API_READ;
  ApiPacket.memoryAddress = _parni(2);
  error = SUPERPRO(&ApiPacket);
  if (!error)
    _storni(ApiPacket.memoryContents, 3);       /* data */
  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPROXREAD
 *  Purpose : To read the data in a readable SuperPro Cell
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 address - address 0-63 of the cell of interest.
 *  Outputs     : *data - ptr to 16 bit contents of the addressed cell.
 *                *accessCode - ptr to access code value (0-3) of the
 *                              addressed cell
 *  Return Value: Status
 *
 **************************************************************************/
int SPROXREAD(UNITINFO  *unitinfo,
int           address,
unsigned int  *data,
unsigned char *accessCode)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

  /* ApiPacket.ui = *unitinfo; */
  str = _parc(1);             /* ptr to unitinfo */
  len = _parclen(1);          /* len of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)       /* move unitinfo -> ApiPacket.ui */
      Aptr[i] = str[i]; }
  ApiPacket.functionCode  = API_EXTENDED_READ;
  ApiPacket.memoryAddress = _parni(2);  /* (addr) */
  error = SUPERPRO(&ApiPacket);
  if (!error)   {
    _storni(ApiPacket.memoryContents, 3); /* data */
    _storni(ApiPacket.accessCode, 4);     /* accesscode */
    }

  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPROWRITE
 *  Purpose : To write to a read/write Superpro Cell.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 writePassword - 16 bit write password
 *                 address    - address 0-63 of the cell to write to.
 *                 data       - the 16 bit value to write to the target cell.
 *                 accessCode - the Access code to write (0-3)
 *                           0 = Read/write
 *                           1 = Read only
 *                           2 = Counter
 *                           3 = Algo/Password
 *  Outputs     : NONE
 *  Return Value: Status
 *
 **************************************************************************/
int SPROWRITE(UNITINFO  *unitinfo,
 unsigned int  writePassword,
 int           address,
 unsigned int  data,
 unsigned char accessCode)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode     = API_WRITE;
  ApiPacket.writePassword    = _parni(2);       /* writePassword */
  ApiPacket.memoryAddress    = _parni(3);       /* address */
  ApiPacket.memoryContents   = _parni(4);       /* data */
  ApiPacket.accessCode       = _parni(5);       /* accesscode */
  error = SUPERPRO(&ApiPacket);
  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPROOVERW
 *  Purpose : To Overwrite any Overwriteable Superpro Cell (cells 5-63)
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 writePassword      - 16 bit write password
 *                 OverwritePassword1 - 16 bit Overwrite password 1
 *                 OverwritePassword2 - 16 bit Overwrite password 2
 *                 address    - address 0-63 of the cell to write to.
 *                 data       - the 16 bit value to write to the target cell.
 *                 accessCode - the Access code to write (0-3)
 *                           0 = Read/write
 *                           1 = Read only
 *                           2 = Counter
 *                           3 = Algo/Password
 *  Outputs     : NONE
 *  Return Value: Status
 *
 **************************************************************************/
int SPROOVERW(UNITINFO  *unitinfo,
     unsigned int  writePassword,
     unsigned int  overwritePassword1,
     unsigned int  overwritePassword2,
     int           address,
     unsigned int  data,
     unsigned char accessCode)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode   = API_OVERWRITE;
  ApiPacket.writePassword  = _parni(2);         /* writePassword */
  ApiPacket.xtraPassword1  = _parni(3);         /* overwritePassword1 */
  ApiPacket.xtraPassword2  = _parni(4);         /* overwritePassword2 */
  ApiPacket.memoryAddress  = _parni(5);         /* address */
  ApiPacket.memoryContents = _parni(6);         /* data */
  ApiPacket.accessCode     = _parni(7);         /* accessCode */
  error = SUPERPRO(&ApiPacket);
  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPRODECR
 *  Purpose : This function decrements a specified cell.  If the cell
 *            decrements to 0 and there is an associated active algo
 *            descriptor, the algo descriptor is deactivated.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 writePassword      - 16 bit write password
 *                 address    - address 0-63 of the cell to decrement.
 *  Outputs     : NONE
 *  Return Value: Status
 *
 **************************************************************************/
int SPRODECR(UNITINFO  *unitinfo,
     unsigned int writePassword,
     int          address)
{
  int   error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode  = API_DECREMENT;
  ApiPacket.writePassword = _parni(2);          /* writePassword */
  ApiPacket.memoryAddress = _parni(3);          /* address */
  error = SUPERPRO(&ApiPacket);
  _retni(error);
  return(error);
}


 /****************************************************************************
 *
 *  Function: SPROACTIV
 *  Purpose : To activate an inactive algo descriptor.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 writePassword      - 16 bit write password
 *                 activatePassword1  - 16 bit activate password 1
 *                 activatePassword2  - 16 bit activate password 2
 *                 address    - address 0-63 of the cell to decrement.
 *  Outputs     : NONE
 *  Return Value: Status
 *
 **************************************************************************/
int SPROACTIV(UNITINFO   *unitinfo,
    unsigned int  writePassword,
    unsigned int activatePassword1,
    unsigned int activatePassword2,
    int           address)
{
  int error;
  char  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode  = API_ACTIVATE_ALGORITHM;
  ApiPacket.writePassword = _parni(2);          /* writePassword */
  ApiPacket.xtraPassword1 = _parni(3);          /* activatePassword1 */
  ApiPacket.xtraPassword2 = _parni(4);          /* activatePassword2 */
  ApiPacket.memoryAddress = _parni(5);          /* address */
  error = SUPERPRO(&ApiPacket);
  _retni(error);
  return(error);
}

 /****************************************************************************
 *
 *  Function: SPROQUERY
 *  Purpose : to scramble a bit stream through the superpro.
 *
 *  Inputs      : *unitInfo - ptr to the current unit info handle structure.
 *                 address    - address of the algo descriptor to use.
 *                 *queryData - ptr to input string
 *                 *response  - ptr to returned response string
 *                 *response32 - last 32 bits of response data
 *                 length - length of the input (and response) string.
 *  Outputs     : NONE
 *  Return Value: Status
 *
 **************************************************************************/
int SPROQUERY(UNITINFO  *unitinfo,
 int           address,
 void          *queryData,
 void          *response,
 unsigned long *response32,
 unsigned int  length)
{
  int error;
  char  *temp,  *str,   *Aptr = &ApiPacket.ui;
  unsigned int  len,    i;

/*  ApiPacket.ui = unitinfo;    */
  str = _parc(1);               /* address of unitinfo */
  len = _parclen(1);            /* length of unitinfo */
  if (len)              {
    for (i=0; i<len; i++)         /* move [unitinfo] -> ApiPacket.ui */
      Aptr[i] = str[i]; }

  ApiPacket.functionCode  = API_QUERY;
  ApiPacket.memoryAddress = _parni(2);          /* address */
  str = _parc(3);                       /* ptr to query string */
  len = _parni(6);                      /* LEN also = _parclen(3) */
  temp = _xgrab(len+1);                 /* allocate space for result string */
  temp[len] = '\0';                     /* only because P/U manual says to */

  ApiPacket.QueryIn       = str;        /* (unsigned long)queryData */
  ApiPacket.QueryOut      = temp;       /* (unsigned long)response */
  ApiPacket.dataLength    = len;        /* length */

  error = SUPERPRO(&ApiPacket);         /* call the driver */

  _storclen(temp, len, 4);              /* move result to Clipper variable */
  _xfree(temp);

  if (!error && !response)
    _stornl(ApiPacket.longResult, 5);   /* response32, if no response */

  _retni(error);
  return(error);
}


Blogger Widgets