/*
 * CopyRight 1995. Nicholas Poljakov all rights reserved.
 */
#include <malloc.h>
#include <dos.h>
#include <stdio.h>
#include <recimmed.h>
#include <state1.h>

 recimmed (tp_id,
           conv_id,fill,
           p_rc,
           length,max_length,
           p_rts,p_data,p_wr)
 unsigned char tp_id[8];
 unsigned long conv_id;
 unsigned char *p_data;
 unsigned int *length ;
 unsigned char *p_rts;
 unsigned char fill;
 unsigned char *p_wr;
 unsigned int max_length;

 struct   rc {
 unsigned   int   prim ;
 unsigned   long  sec  ; }  *p_rc;

         {
  union REGS inregs,outregs;
  struct SREGS segregs;
  struct recimmed *ptr;
  char *p;
       char _near *dp1;
       char _near *dp2;
  int i,l;

        l = sizeof(struct recimmed);
     if ((ptr = (char *)calloc(1,l)) == NULL)
       {
        p_rc->prim = PORT_BUSY; /* нет доступной памяти */
        p_rc->sec = 0x00;
        return(0);
        }

     ptr->code=Receive_immediate; /* code primitiv */
     ptr->e_cd=0x0000; /*  ex   */

     memcpy (ptr->tp_id,tp_id,8);

     ptr->conv_id=conv_id;
     ptr->fill = fill;
     ptr->maxlen=max_length;
     ptr->data_addr=p_data;
/*
     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, Receive_immediate
            int   68h
            pop   ds
         }


    *p_wr=ptr->what_received;
    *length=ptr->data_lt;
    *p_rts=ptr->rts;
     p_rc->prim =ptr->prim_rc;
     p_rc->sec  = ptr->sec_rc;
    p = ptr->data_addr;
    for (i=0;i<ptr->data_lt;i++)
       {
        *(p_data+i)=*(p+i);
       }
               free(ptr);
               return(0);
         }
