Zurück Vorwärts

Radicon SCSCS
Mittlere Implementationsebene
Source Codes

kisl1.c - Funktion init_b



/*******************************************************************************
  procedure: init_b
  purpose:   load programm to monitor
  synopsis:  int CALLTYPE init_b ( pBuf, BufSize, rd, rs )
  input:     unsigned char * pBuf = buffer for data to transmit
             unsigned int BufSize = number of bytes to transmit
             int rd = data port address, (data register)
             int rs = control port address, that identifies controller (state
                 register)
  result:    0 = operation successful
             -1 = communication error
             -2 = controller reject connect
             -3 = buffer length bigger than maximum length
*******************************************************************************/

#ifdef DEBUG
int retspot_init;
#endif // def DEBUG

int CALLTYPE init_b ( pBuf, BufSize, rd, rs )

  unsigned char * pBuf;
  unsigned int BufSize;
  int rd, rs;

{

  /* local variables */
  register int i, j;
  int d;

#ifdef DEBUG
  retspot_set = retspot_beg = retspot_get = retspot_init = retspot_tr =
      retspot_rc = retspot_out = retspot_in = 0;
#endif // def DEBUG

  /* do nothing, if using FakeDevice */
  if (FakeDevice)
    return 0;

  /* fail with error code -3, if file is bigger than LNGPRG bytes */
  if (BufSize > LNGPRG)
  {
    {

#ifdef DEBUG
      retspot_init = 1;
#endif // def DEBUG

      return -3;
    }
  }

  /* retrieve current time */
  i = crnt_time();

  /* timeout after reset controller for TMOUT * 50 mseconds */
  while (1)
  {
    j = crnt_time();
    if (j - i < 0)
      i = j;
    if (j - i > TMOUT)
      break;
  }

#ifndef __WIN32__

  /* d = inp(rd); */
  _asm
  {
    sub ax, ax; // initialize ax
    mov dx, rd; // copy data out of rd in dx (16 Bit)
    /* get data from port stored in dx and write data to the lower Byte (8 Bit)
        of the accumulator */
    in  al, dx; 
    mov d, ax; // copy data out of ax (16 Bit) to d
  }

#endif // ndef __WIN32__

  /* stop controller */
  begwrk ( CF5, rd, rs );

  /* transmit message NCYCL cycles or until return value is 0 */
  for ( i = 0; i < NCYCL; i++ )
  {
    j = tr_message( CFF, rd, rs, pBuf, BufSize );
    if ( j == -2 )
    {

#ifdef DEBUG
      retspot_init = 2;
#endif // def DEBUG

      return -2;
    }
    if ( j == 0 )
      break;
  }

  /* if max number of cycles reached return error */
  if ( i == NCYCL )
  {

#ifdef DEBUG
    retspot_init = 3;
#endif // def DEBUG

    return -1;
  }

  /* ? */
  if ( d == MONIT )
  {
    i = in_byte( rd, rs, &d );
    if ( d == PROGR )
    {

#ifdef DEBUG
      retspot_init = 0;
#endif // def DEBUG

      return 0;
    }
  }

#ifdef DEBUG
  retspot_init = 0;
#endif // def DEBUG

  return 0;

}

Übersicht | Source Codes