/*
 * CopyRight 1995. Nicholas Poljakov all rights reserved.
 */
#include <malloc.h>
#include <stdio.h>
#include <alloc.h>
#include <dos.h>
#include <state1.h>

 allocate (lu_name,mode_name,tpn,return_control,security,
           sync_level,user_id,password,tp_id,p_convid,
           p_pip,p_rc)

 unsigned char lu_name[8];
 unsigned char mode_name[8];
 unsigned char tpn[64];
 unsigned char return_control;
 unsigned char security;
 unsigned char sync_level;
 unsigned char user_id[11];
 unsigned char password[10];
 unsigned char tp_id[8];
 unsigned long *p_convid;
 char *p_pip;
 struct rc {
  unsigned int prim;
  unsigned long sec; } *p_rc;

 {
  union REGS inregs,outregs;
  struct SREGS segregs;
  struct allocate *ptr;
       char _near *dp1;
       char _near *dp2;
  int l;

toup(lu_name);
toup(mode_name);

     l = sizeof(struct allocate);
     if ((ptr = (char *)calloc(1,l)) == NULL)
       {
        p_rc->prim = PORT_BUSY; /* нет доступной памяти */
        p_rc->sec = 0x00;
        return(0);
        }


     ptr->code=Allocate;
     ptr->e_cd=0x0000;

     copy(ptr->p_lu_name,lu_name,8);

     copy(ptr->mode_name,mode_name,8);

     memcpy(ptr->tp_id,tp_id,8);
     ptr->security = security;
     ptr->sync_level = sync_level;
     ptr->return_control = return_control;
     strcpy(ptr->tp_name,tpn);
     memcpy(ptr->password,password,10);
     memcpy(ptr->user_id,user_id,11);
     ptr->tp_lt = strlen(tpn);
     ptr->pip = p_pip;
/*
     inregs.x.dx = FP_OFF(ptr);
     segregs.ds = FP_SEG(ptr);
     inregs.x.ax = ptr->code;

         int86x(0x68,&inregs,&outregs,&segregs);
 */
     dp1 = FP_OFF( ptr );
     dp2 = FP_SEG( ptr );
     _asm
         {
            push  ds
            mov   dx, word ptr dp1[0]
            mov   ax, word ptr dp2[0]
            mov   ds, ax
            mov   ax, Allocate
            int   68h
            pop   ds
         }

  p_rc->prim = ptr->prim_rc;
  p_rc->sec = ptr->sec_rc;
  *p_convid = ptr -> conv_id;
   free(ptr);

  return(0);

 }
