예제 #1
0
/* Write a set of len byte values to MaxiLife token (-1 in case of error, 0 otherwise). */
int maxi_write_token_loop(struct i2c_client *client, u16 token, u8 len,
			  u8 * values)
{
	u8 lowToken, highToken, bCounter;
	int error;

	lowToken = LOW(token);
	highToken = HIGH(token);

	/* Set mailbox status register to idle state. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS,
				      MAXI_STAT_IDLE);
	if (error < 0)
		return error;

	/* Check for mailbox idle state. */
	error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS);
	if (error != MAXI_STAT_IDLE)
		return -1;

	for (bCounter = 0; (bCounter < len && bCounter < 32); bCounter++) {
		error =
		    i2c_smbus_write_byte_data(client,
					      (u8) (MAXI_REG_MBX_DATA +
						    bCounter),
					      values[bCounter]);
		if (error < 0)
			return error;
	}

	/* Write the most significant byte of the token we want to read. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H,
				      highToken);
	if (error < 0)
		return error;

	/* Write the least significant byte of the token we want to read. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L,
				      lowToken);
	if (error < 0)
		return error;

	/* Write the write token opcode to the mailbox. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD,
				      MAXI_CMD_WRITE);
	if (error < 0)
		return error;

	/* Check for transaction completion */
	do {
		error =
		    i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS);
	} while (error == MAXI_STAT_BUSY);
	if (error != MAXI_STAT_OK)
		return -1;

	/* set mailbox status to idle to complete transaction. */
	return i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS,
					 MAXI_STAT_IDLE);
}
예제 #2
0
static FT_Byte*
TA_hints_recorder_handle_segments(FT_Byte* bufp,
                                  TA_AxisHints axis,
                                  TA_Edge edge,
                                  FT_UInt* wraps)
{
  TA_Segment segments = axis->segments;
  TA_Segment seg;
  FT_UInt seg_idx;
  FT_UInt num_segs = 0;
  FT_UInt* wrap;


  seg_idx = edge->first - segments;

  /* we store everything as 16bit numbers */
  *(bufp++) = HIGH(seg_idx);
  *(bufp++) = LOW(seg_idx);

  /* wrap-around segments are stored as two segments */
  if (edge->first->first > edge->first->last)
    num_segs++;

  seg = edge->first->edge_next;
  while (seg != edge->first)
  {
    num_segs++;

    if (seg->first > seg->last)
      num_segs++;

    seg = seg->edge_next;
  }

  *(bufp++) = HIGH(num_segs);
  *(bufp++) = LOW(num_segs);

  if (edge->first->first > edge->first->last)
  {
    /* emit second part of wrap-around segment; */
    /* the bytecode positions such segments after `normal' ones */
    wrap = wraps;
    for (;;)
    {
      if (seg_idx == *wrap)
        break;
      wrap++;
    }

    *(bufp++) = HIGH(axis->num_segments + (wrap - wraps));
    *(bufp++) = LOW(axis->num_segments + (wrap - wraps));
  }

  seg = edge->first->edge_next;
  while (seg != edge->first)
  {
    seg_idx = seg - segments;

    *(bufp++) = HIGH(seg_idx);
    *(bufp++) = LOW(seg_idx);

    if (seg->first > seg->last)
    {
      wrap = wraps;
      for (;;)
      {
        if (seg_idx == *wrap)
          break;
        wrap++;
      }

      *(bufp++) = HIGH(axis->num_segments + (wrap - wraps));
      *(bufp++) = LOW(axis->num_segments + (wrap - wraps));
    }

    seg = seg->edge_next;
  }

  return bufp;
}
예제 #3
0
파일: ptmeffect.c 프로젝트: codefoco/dumb
void _dumb_it_ptm_convert_effect(int effect, int value, IT_ENTRY *entry) {
    if (effect >= PTM_N_EFFECTS)
        return;

    /* Linearisation of the effect number... */
    if (effect == PTM_E) {
        effect = PTM_EBASE + HIGH(value);
        value = LOW(value);
    }

    /* convert effect */
    entry->mask |= IT_ENTRY_EFFECT;
    switch (effect) {

    case PTM_APPREGIO:
        effect = IT_ARPEGGIO;
        break;
    case PTM_PORTAMENTO_UP:
        effect = IT_PORTAMENTO_UP;
        break;
    case PTM_PORTAMENTO_DOWN:
        effect = IT_PORTAMENTO_DOWN;
        break;
    case PTM_TONE_PORTAMENTO:
        effect = IT_TONE_PORTAMENTO;
        break;
    case PTM_VIBRATO:
        effect = IT_VIBRATO;
        break;
    case PTM_VOLSLIDE_TONEPORTA:
        effect = IT_VOLSLIDE_TONEPORTA;
        break;
    case PTM_VOLSLIDE_VIBRATO:
        effect = IT_VOLSLIDE_VIBRATO;
        break;
    case PTM_TREMOLO:
        effect = IT_TREMOLO;
        break;
    case PTM_SAMPLE_OFFSET:
        effect = IT_SET_SAMPLE_OFFSET;
        break;
    case PTM_VOLUME_SLIDE:
        effect = IT_VOLUME_SLIDE;
        break;
    case PTM_POSITION_JUMP:
        effect = IT_JUMP_TO_ORDER;
        break;
    case PTM_SET_CHANNEL_VOLUME:
        effect = IT_SET_CHANNEL_VOLUME;
        break;
    case PTM_PATTERN_BREAK:
        effect = IT_BREAK_TO_ROW;
        break;
    case PTM_SET_GLOBAL_VOLUME:
        effect = IT_SET_GLOBAL_VOLUME;
        break;
    case PTM_RETRIGGER:
        effect = IT_RETRIGGER_NOTE;
        break;
    case PTM_FINE_VIBRATO:
        effect = IT_FINE_VIBRATO;
        break;

    /* TODO properly */
    case PTM_NOTE_SLIDE_UP:
        effect = IT_PTM_NOTE_SLIDE_UP;
        break;
    case PTM_NOTE_SLIDE_DOWN:
        effect = IT_PTM_NOTE_SLIDE_DOWN;
        break;
    case PTM_NOTE_SLIDE_UP_RETRIG:
        effect = IT_PTM_NOTE_SLIDE_UP_RETRIG;
        break;
    case PTM_NOTE_SLIDE_DOWN_RETRIG:
        effect = IT_PTM_NOTE_SLIDE_DOWN_RETRIG;
        break;

    case PTM_SET_TEMPO_BPM:
        effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
        break;

    case PTM_EBASE + PTM_E_SET_FINETUNE:
        effect = SBASE + IT_S_FINETUNE;
        break; /** TODO */
    case PTM_EBASE + PTM_E_SET_LOOP:
        effect = SBASE + IT_S_PATTERN_LOOP;
        break;
    case PTM_EBASE + PTM_E_NOTE_CUT:
        effect = SBASE + IT_S_DELAYED_NOTE_CUT;
        break;
    case PTM_EBASE + PTM_E_NOTE_DELAY:
        effect = SBASE + IT_S_NOTE_DELAY;
        break;
    case PTM_EBASE + PTM_E_PATTERN_DELAY:
        effect = SBASE + IT_S_PATTERN_DELAY;
        break;
    case PTM_EBASE + PTM_E_SET_PANNING:
        effect = SBASE + IT_S_SET_PAN;
        break;

    case PTM_EBASE + PTM_E_FINE_VOLSLIDE_UP:
        effect = IT_VOLUME_SLIDE;
        value = EFFECT_VALUE(value, 0xF);
        break;

    case PTM_EBASE + PTM_E_FINE_VOLSLIDE_DOWN:
        effect = IT_VOLUME_SLIDE;
        value = EFFECT_VALUE(0xF, value);
        break;

    case PTM_EBASE + PTM_E_FINE_PORTA_UP:
        effect = IT_PORTAMENTO_UP;
        value = EFFECT_VALUE(0xF, value);
        break;

    case PTM_EBASE + PTM_E_FINE_PORTA_DOWN:
        effect = IT_PORTAMENTO_DOWN;
        value = EFFECT_VALUE(0xF, value);
        break;

    case PTM_EBASE + PTM_E_RETRIG_NOTE:
        effect = IT_XM_RETRIGGER_NOTE;
        value = EFFECT_VALUE(0, value);
        break;

    case PTM_EBASE + PTM_E_SET_VIBRATO_CONTROL:
        effect = SBASE + IT_S_SET_VIBRATO_WAVEFORM;
        value &= ~4; /** TODO: value&4 -> don't retrig wave */
        break;

    case PTM_EBASE + PTM_E_SET_TREMOLO_CONTROL:
        effect = SBASE + IT_S_SET_TREMOLO_WAVEFORM;
        value &= ~4; /** TODO: value&4 -> don't retrig wave */
        break;

    default:
        /* user effect (often used in demos for synchronisation) */
        entry->mask &= ~IT_ENTRY_EFFECT;
    }

    /* Inverse linearisation... */
    if (effect >= SBASE && effect < SBASE + 16) {
        value = EFFECT_VALUE(effect - SBASE, value);
        effect = IT_S;
    }

    entry->effect = effect;
    entry->effectvalue = value;
}
예제 #4
0
/* Read the byte value for a MaxiLife token (-1 in case of error, value otherwise */
int maxi_read_token(struct i2c_client *client, u16 token)
{
	u8 lowToken, highToken;
	int error, value;

	lowToken = LOW(token);
	highToken = HIGH(token);

	/* Set mailbox status register to idle state. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS,
				      MAXI_STAT_IDLE);
	if (error < 0)
		return error;

	/* Check for mailbox idle state. */
	error = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS);
	if (error != MAXI_STAT_IDLE)
		return -1;

	/* Write the most significant byte of the token we want to read. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_H,
				      highToken);
	if (error < 0)
		return error;

	/* Write the least significant byte of the token we want to read. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_TOKEN_L,
				      lowToken);
	if (error < 0)
		return error;

	/* Write the read token opcode to the mailbox. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_CMD,
				      MAXI_CMD_READ);
	if (error < 0)
		return error;

	/* Check for transaction completion */
	do {
		error =
		    i2c_smbus_read_byte_data(client, MAXI_REG_MBX_STATUS);
	} while (error == MAXI_STAT_BUSY);
	if (error != MAXI_STAT_OK)
		return -1;

	/* Read the value of the token. */
	value = i2c_smbus_read_byte_data(client, MAXI_REG_MBX_DATA);
	if (value == -1)
		return -1;

	/* set mailbox status to idle to complete transaction. */
	error =
	    i2c_smbus_write_byte_data(client, MAXI_REG_MBX_STATUS,
				      MAXI_STAT_IDLE);
	if (error < 0)
		return error;

	return value;
}
예제 #5
0
파일: rlserial.cpp 프로젝트: 376473984/pvb
int rlSerial::openDevice(const char *devicename, int speed, int block, int rtscts, int bits, int stopbits, int parity)
{
#ifdef RLUNIX
  struct termios buf;

  if(fd != -1) return -1;
  fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY);
  if(fd < 0) { return -1; }

  //signal(SIGINT, sighandler);

  if(tcgetattr(fd, &save_termios) < 0) { return -1; }
  buf = save_termios;
  buf.c_cflag = speed | CLOCAL | CREAD;
  if(rtscts   == 1)  buf.c_cflag |= CRTSCTS;
  if(bits     == 7)  buf.c_cflag |= CS7;
  else               buf.c_cflag |= CS8;
  if(stopbits == 2)  buf.c_cflag |= CSTOPB;
  if(parity == rlSerial::ODD)  buf.c_cflag |= (PARENB | PARODD);
  if(parity == rlSerial::EVEN) buf.c_cflag |= PARENB;
  buf.c_lflag = IEXTEN; //ICANON;
  buf.c_oflag     = OPOST;
  buf.c_cc[VMIN]  = 1;
  buf.c_cc[VTIME] = 0;
#ifndef PVMAC
  buf.c_line      = 0;
#endif
  buf.c_iflag     = IGNBRK | IGNPAR | IXANY;
  if(tcsetattr(fd, TCSAFLUSH, &buf) < 0) { return -1; }
  //if(tcsetattr(fd, TCSANOW, &buf) < 0) { return -1; }
  ttystate = RAW;
  ttysavefd = fd;
  if(block == 1) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
  tcflush(fd,TCIOFLUSH);
#endif

#ifdef __VMS
  // Please set com parameters at DCL level
  struct dsc$descriptor_s dsc;
  int status;

  dsc.dsc$w_length  = strlen(devicename);
  dsc.dsc$a_pointer = (char *) devicename;
  dsc.dsc$b_class   = DSC$K_CLASS_S;
  dsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  status = SYS$ASSIGN(&dsc,&vms_channel,0,0);
  if(status != SS$_NORMAL) return -1;
#endif

#ifdef RLWIN32
  DWORD ccsize;
  COMMCONFIG cc;
  int baudrate,ret;
  char devname[100];

  if(strlen(devicename) > 80) return -1;
  sprintf(devname,"\\\\.\\%s",devicename);        // Aenderung: allow more than 4 COM ports
  hdl = CreateFile(
                   devname,                       // devicename, // pointer to name of the file
                   GENERIC_READ | GENERIC_WRITE,  // access (read-write) mode
                   0,                             // share mode
                   0,                             // pointer to security attributes
                   OPEN_EXISTING,                 // how to create
                   0,                             // not overlapped I/O
                   0                              // handle to file with attributes to copy
                  );
  if(hdl == INVALID_HANDLE_VALUE)
  {
    printf("CreateFile(%s) failed\n",devicename);
    return -1;
  }

  baudrate = CBR_9600;
  if(speed == B50     ) baudrate = 50;
  if(speed == B75     ) baudrate = 75;
  if(speed == B110    ) baudrate = CBR_110;
  if(speed == B134    ) baudrate = 134;
  if(speed == B150    ) baudrate = 150;
  if(speed == B200    ) baudrate = 200;
  if(speed == B300    ) baudrate = CBR_300;
  if(speed == B600    ) baudrate = CBR_600;
  if(speed == B1200   ) baudrate = CBR_1200;
  if(speed == B1800   ) baudrate = 1800;
  if(speed == B2400   ) baudrate = CBR_2400;
  if(speed == B4800   ) baudrate = CBR_4800;
  if(speed == B9600   ) baudrate = CBR_9600;
  if(speed == B19200  ) baudrate = CBR_19200;
  if(speed == B38400  ) baudrate = CBR_38400;
  if(speed == B57600  ) baudrate = CBR_57600;
  if(speed == B115200 ) baudrate = CBR_115200;
  if(speed == B230400 ) baudrate = 230400;
  if(speed == B460800 ) baudrate = 460800;
  if(speed == B500000 ) baudrate = 500000;
  if(speed == B576000 ) baudrate = 576000;
  if(speed == B921600 ) baudrate = 921600;
  if(speed == B1000000) baudrate = 1000000;
  if(speed == B1152000) baudrate = 1152000;
  if(speed == B1500000) baudrate = 1500000;
  if(speed == B2000000) baudrate = 2000000;
  if(speed == B2500000) baudrate = 2500000;
  if(speed == B3000000) baudrate = 3000000;
  if(speed == B3500000) baudrate = 3500000;
  if(speed == B4000000) baudrate = 4000000;

  ccsize = sizeof(cc);
  GetCommConfig(hdl,&cc,&ccsize);
  //cc.dwSize            = sizeof(cc);  // size of structure
  //cc.wVersion          = 1;           // version of structure
  //cc.wReserved         = 0;           // reserved
  //  DCB   dcb;                      // device-control block
  cc.dcb.DCBlength     = sizeof(DCB); // sizeof(DCB)
  cc.dcb.BaudRate      = baudrate;    // current baud rate
  cc.dcb.fBinary       = 1;           // binary mode, no EOF check
  cc.dcb.fParity       = 1;           // enable parity checking
  cc.dcb.fOutxCtsFlow  = 0;           // CTS output flow control
  if(rtscts == 1) cc.dcb.fOutxCtsFlow = 1;
  cc.dcb.fOutxDsrFlow  = 0;           // DSR output flow control
  cc.dcb.fDtrControl   = DTR_CONTROL_DISABLE;  // DTR flow control type
  cc.dcb.fDsrSensitivity   = 0;       // DSR sensitivity
  cc.dcb.fTXContinueOnXoff = 1;       // XOFF continues Tx
  //cc.dcb.fOutX         = 0;           // XON/XOFF out flow control
  //cc.dcb.fInX          = 0;           // XON/XOFF in flow control
  //cc.dcb.fErrorChar    = 0;           // enable error replacement
  cc.dcb.fNull         = 0;           // enable null stripping
  cc.dcb.fRtsControl   = RTS_CONTROL_DISABLE;
  if(rtscts == 1)  cc.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;  // RTS flow control
  cc.dcb.fAbortOnError = 0;           // abort reads/writes on error
  //cc.dcb.fDummy2       = 0;           // reserved
  //cc.dcb.wReserved     = 0;           // not currently used
  //cc.dcb.XonLim        = 0;           // transmit XON threshold
  //cc.dcb.XoffLim       = 0;           // transmit XOFF threshold
  cc.dcb.ByteSize      = bits;        // number of bits/byte, 4-8
  cc.dcb.Parity        = 0;           // 0-4=no,odd,even,mark,space
  if(parity == rlSerial::ODD)    cc.dcb.Parity = 1;
  if(parity == rlSerial::EVEN)   cc.dcb.Parity = 2;
  cc.dcb.StopBits      = ONESTOPBIT;  // 0,1,2 = 1, 1.5, 2
  if(stopbits==2) cc.dcb.StopBits = TWOSTOPBITS;
  //cc.dcb.XonChar       = 0;           // Tx and Rx XON character
  //cc.dcb.XoffChar      = 0;           // Tx and Rx XOFF character
  //cc.dcb.ErrorChar     = 0;           // error replacement character
  //cc.dcb.EofChar       = 0;           // end of input character
  //cc.dcb.EvtChar       = 0;           // received event character
  //cc.dcb.wReserved1    = 0;           // reserved; do not use
  cc.dwProviderSubType = PST_RS232;   // type of provider-specific data
  //cc.dwProviderOffset  = 0;           // offset of provider-specific data
  //cc.dwProviderSize    = 0;           // size of provider-specific data
  //cc.wcProviderData[0] = 0;           // provider-specific data

  ret = SetCommConfig(hdl,&cc,sizeof(cc));
  if(ret == 0)
  {
    printf("SetCommConfig ret=%d devicename=%s LastError=%ld\n",ret,devicename,GetLastError());
    return -1;
  }
  if(block) return 0;
#endif

#ifdef RM3
  RmEntryStruct    CatEntry;        /* Struktur der Deiviceinformationen              */
  int              iStatus;         /* Rckgabewert                                    */
  RmIOStatusStruct DrvSts;          /* Struktur der Rckgabewerte fr RmIO - Funktion   */
  RmBytParmStruct  PBlock;          /* Parameterstruktur fr RmIO - Funktion           */
  static UCD_BYT_PORT Ucd_byt_drv;  /* Struktur zum Setzen der UCD - Werte            */
  ushort           uTimeBd;         /* Timing - Wert der �ertragungsgeschwindigkeit   */
  uint             uMode;           /* Portsteuerungsparameter                        */
  unsigned char    cByte;           /* Byte - Parameter                               */
                                    /* Timing = 748800 / Baudrate;                    */
                                    /**************************************************/
  char byt_com[32];
                                    
  /* COM1=0x3F8 COM2=0x2F8 - Port Adresse           */
  if     (strcmp(devicename,"COM1") == 0)
  {
    strcpy(byt_com,"BYT_COM1");
    com = 0x3f8;
  }
  else if(strcmp(devicename,"COM2") == 0)
  {
    strcpy(byt_com,"BYT_COM2");
    com = 0x2f8;
  }
  else 
  {
    printf("Error: devicename=%s unknown\n",devicename);
    return -1;
  }  
  //printf("Open COM port - inside\n");

  /*
  * Device und Unit - Id auslesen
  */
  if( RmGetEntry( RM_WAIT, byt_com, &CatEntry ) != RM_OK ) /* RM_CONTINUE */
  {
    printf( "Error: %s device not found\n", byt_com);
    return -1;
  }

  device = (int) ((ushort) CatEntry.ide);
  unit   = (int) CatEntry.id;

  /*
  * Ger� reservieren
  */
  if( RmIO( BYT_RESERVE, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock ) < 0 )
  {
    printf( "Error: Unable to reserve %s device\n", byt_com);
    return -1;
  }

  /*
  * Baudrate ausrechnen
  */
  baudrate = 9600;
  if(speed == B50     ) baudrate = 50;
  if(speed == B75     ) baudrate = 75;
  if(speed == B110    ) baudrate = 110;
  if(speed == B134    ) baudrate = 134;
  if(speed == B150    ) baudrate = 150;
  if(speed == B200    ) baudrate = 200;
  if(speed == B300    ) baudrate = 300;
  if(speed == B600    ) baudrate = 600;
  if(speed == B1200   ) baudrate = 1200;
  if(speed == B1800   ) baudrate = 1800;
  if(speed == B2400   ) baudrate = 2400;
  if(speed == B4800   ) baudrate = 4800;
  if(speed == B9600   ) baudrate = 9600;
  if(speed == B19200  ) baudrate = 19200;
  if(speed == B38400  ) baudrate = 38400;
  if(speed == B57600  ) baudrate = 57600;
  if(speed == B115200 ) baudrate = 115200;
  if(speed == B230400 ) baudrate = 230400;
  if(speed == B460800 ) baudrate = 460800;
  if(speed == B500000 ) baudrate = 500000;
  if(speed == B576000 ) baudrate = 576000;
  if(speed == B921600 ) baudrate = 921600;
  if(speed == B1000000) baudrate = 1000000;
  if(speed == B1152000) baudrate = 1152000;
  if(speed == B1500000) baudrate = 1500000;
  if(speed == B2000000) baudrate = 2000000;
  if(speed == B2500000) baudrate = 2500000;
  if(speed == B3000000) baudrate = 3000000;
  if(speed == B3500000) baudrate = 3500000;
  if(speed == B4000000) baudrate = 4000000;
  uTimeBd = 748800 / baudrate;

  /*
  * Portsteuerungsparameter setzen
  */
  uMode = 0x1000 | DATA_8 | STOP_1 | NOPARITY;

  /*
  * UCD des seriellen Ports auslesen
  */
  PBlock.string = 0;
  PBlock.strlen = 0;
  PBlock.buffer = (char *)&Ucd_byt_drv;
  PBlock.timlen = sizeof(UCD_BYT_PORT);
  PBlock.status = 0;

  iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );

  /*
   * Modus �dern
   */
  Ucd_byt_drv.mobyte[5] |= (ushort) (uMode & 0xFFu);

  /*
   * Timeout setzen
   */
  Ucd_byt_drv.header.timout = timeout;

  /*
   * Werte zuweisen
   */
  PBlock.string = (char*) &Ucd_byt_drv;
  PBlock.strlen = sizeof(UCD_BYT_PORT);
  PBlock.buffer = 0;
  PBlock.timlen = 0;
  PBlock.status = 0;

  iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );

  /*
   * Register 0 und 1 zum Schreiben freigeben
   */
  cByte = inbyte( com + 0x03 );
  outbyte( com + 0x03, (unsigned char)(cByte | 0x80) );

  /*
   * Baudrate setzen
   */
  outbyte( com + 0x00, (ushort) LOW  (uTimeBd) );
  outbyte( com + 0x01, (ushort) HIGH (uTimeBd) );

  /*
   * Register 0 und 1 sperren
   */
  outbyte( com + 0x03, cByte );

  if( iStatus ) printf( "BYT_CREATE_NEW (set ucb): Error status = %X\n", iStatus );
#endif
  
  return 0;
}
void display_begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
    if (lines > 1) {
        _displayfunction |= LCD_2LINE;
    }
    _numlines = lines;
    _numcolumns = cols;
    _currline = 0;

    // for some 1 line displays you can select a 10 pixel high font
    if ((dotsize != 0) && (lines == 1)) {
        _displayfunction |= LCD_5x10DOTS;
    }

    // according to datasheet, we need at least 40ms after the input to the display rises above 2.7V
    _delay_us(50000);
    // Now we pull both RS and R/W low to begin display_commands
    LOW(_rs_pin);
    LOW(_enable_pin);

    //put the LCD into 4 bit mode
    if (! (_displayfunction & LCD_8BITMODE)) {
        // this is according to the hitachi HD44780 datasheet
        // figure 24, pg 46

        // we start in 8bit mode, try to set 4 bit mode
        display_write4bits(0x03);
        _delay_us(4500); // wait min 4.1ms

        // second try
        display_write4bits(0x03);
        _delay_us(4500); // wait min 4.1ms

        // third go!
        display_write4bits(0x03);
        _delay_us(150);

        // finally, set to 8-bit interface
        display_write4bits(0x02);
    } else {
        // this is according to the hitachi HD44780 datasheet
        // page 45 figure 23

        // Send function set display_command sequence
        display_command(LCD_FUNCTIONSET | _displayfunction);
        _delay_us(4500);  // wait more than 4.1ms

        // second try
        display_command(LCD_FUNCTIONSET | _displayfunction);
        _delay_us(150);

        // third go
        display_command(LCD_FUNCTIONSET | _displayfunction);
    }

    // finally, set # lines, font size, etc.
    display_command(LCD_FUNCTIONSET | _displayfunction);  

    // turn the display on with no cursor or blinking default
    _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
    display_show();

    // clear it off
    display_clear();

    // Initialize to default text direction (for romance languages)
    _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
    // set the entry mode
    display_command(LCD_ENTRYMODESET | _displaymode);

}
예제 #7
0
파일: xmeffect.c 프로젝트: katajakasa/dumb
/* Effects marked with 'special' are handled specifically in itrender.c */
void _dumb_it_xm_convert_effect(int effect, int value, IT_ENTRY *entry, int mod)
{
const int log = 0;

	if ((!effect && !value) || (effect >= XM_N_EFFECTS))
		return;

if (log) printf("%c%02X", (effect<10)?('0'+effect):('A'+effect-10), value);

	/* Linearisation of the effect number... */
	if (effect == XM_E) {
		effect = EBASE + HIGH(value);
		value = LOW(value);
	} else if (effect == XM_X) {
		effect = XBASE + HIGH(value);
		value = LOW(value);
	}

if (log) printf(" - %2d %02X", effect, value);

#if 0 // This should be handled in itrender.c!
	/* update effect memory */
	switch (xm_has_memory[effect]) {
		case 1:
			if (!value)
				value = memory[entry->channel][effect];
			else
				memory[entry->channel][effect] = value;
			break;

		case 2:
			if (!HIGH(value))
				SET_HIGH(value, HIGH(memory[entry->channel][effect]));
			else
				SET_HIGH(memory[entry->channel][effect], HIGH(value));

			if (!LOW(value))
				SET_LOW(value, LOW(memory[entry->channel][effect]));
			else
				SET_LOW(memory[entry->channel][effect], LOW(value));
			break;
	}
#endif

	/* convert effect */
	entry->mask |= IT_ENTRY_EFFECT;
	switch (effect) {

		case XM_APPREGIO:           effect = IT_ARPEGGIO;           break;
		case XM_VIBRATO:            effect = IT_VIBRATO;            break;
		case XM_TONE_PORTAMENTO:    effect = IT_TONE_PORTAMENTO;    break;
		case XM_TREMOLO:            effect = IT_TREMOLO;            break;
		case XM_SET_PANNING:        effect = IT_SET_PANNING;        break;
		case XM_SAMPLE_OFFSET:      effect = IT_SET_SAMPLE_OFFSET;  break;
		case XM_POSITION_JUMP:      effect = IT_JUMP_TO_ORDER;      break;
		case XM_MULTI_RETRIG:       effect = IT_RETRIGGER_NOTE;     break;
		case XM_TREMOR:             effect = IT_TREMOR;             break;
		case XM_PORTAMENTO_UP:      effect = IT_XM_PORTAMENTO_UP;   break;
		case XM_PORTAMENTO_DOWN:    effect = IT_XM_PORTAMENTO_DOWN; break;
		case XM_SET_CHANNEL_VOLUME: effect = IT_SET_CHANNEL_VOLUME; break; /* special */
		case XM_VOLSLIDE_TONEPORTA: effect = IT_VOLSLIDE_TONEPORTA; break; /* special */
		case XM_VOLSLIDE_VIBRATO:   effect = IT_VOLSLIDE_VIBRATO;   break; /* special */

		case XM_PATTERN_BREAK:
			effect = IT_BREAK_TO_ROW;
			value = BCD_TO_NORMAL(value);
			if (value > 63) value = 0; /* FT2, maybe ProTracker? */
			break;

		case XM_VOLUME_SLIDE: /* special */
			effect = IT_VOLUME_SLIDE;
			value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
			break;

		case XM_PANNING_SLIDE:
			effect = IT_PANNING_SLIDE;
			//value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
			value = HIGH(value) ? EFFECT_VALUE(0, HIGH(value)) : EFFECT_VALUE(LOW(value), 0);
			break;

		case XM_GLOBAL_VOLUME_SLIDE: /* special */
			effect = IT_GLOBAL_VOLUME_SLIDE;
			value = HIGH(value) ? EFFECT_VALUE(HIGH(value), 0) : EFFECT_VALUE(0, LOW(value));
			break;

		case XM_SET_TEMPO_BPM:
			if (mod) effect = (value <= 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
			else effect = (value < 0x20) ? (IT_SET_SPEED) : (IT_SET_SONG_TEMPO);
			break;

		case XM_SET_GLOBAL_VOLUME:
			effect = IT_SET_GLOBAL_VOLUME;
			value *= 2;
			if (value > 128) value = 128;
			break;

		case XM_KEY_OFF:
			effect = IT_XM_KEY_OFF;
			break;

		case XM_SET_ENVELOPE_POSITION:
			effect = IT_XM_SET_ENVELOPE_POSITION;
			break;

		case EBASE+XM_E_SET_FILTER:            effect = SBASE+IT_S_SET_FILTER;            break;
		case EBASE+XM_E_SET_GLISSANDO_CONTROL: effect = SBASE+IT_S_SET_GLISSANDO_CONTROL; break; /** TODO */
		case EBASE+XM_E_SET_FINETUNE:          effect = SBASE+IT_S_FINETUNE;              break;
		case EBASE+XM_E_SET_LOOP:              effect = SBASE+IT_S_PATTERN_LOOP;          break;
		case EBASE+XM_E_NOTE_CUT:              effect = SBASE+IT_S_DELAYED_NOTE_CUT;      break;
		case EBASE+XM_E_NOTE_DELAY:            effect = SBASE+IT_S_NOTE_DELAY;            break;
		case EBASE+XM_E_PATTERN_DELAY:         effect = SBASE+IT_S_PATTERN_DELAY;         break;
		case EBASE+XM_E_SET_PANNING:           effect = SBASE+IT_S_SET_PAN;               break;
		case EBASE+XM_E_FINE_VOLSLIDE_UP:      effect = IT_XM_FINE_VOLSLIDE_UP;           break;
		case EBASE+XM_E_FINE_VOLSLIDE_DOWN:    effect = IT_XM_FINE_VOLSLIDE_DOWN;         break;
		case EBASE+XM_E_SET_MIDI_MACRO:        effect = SBASE+IT_S_SET_MIDI_MACRO;        break;

		case EBASE + XM_E_FINE_PORTA_UP:
			effect = IT_PORTAMENTO_UP;
			value = EFFECT_VALUE(0xF, value);
			break;

		case EBASE + XM_E_FINE_PORTA_DOWN:
			effect = IT_PORTAMENTO_DOWN;
			value = EFFECT_VALUE(0xF, value);
			break;

		case EBASE + XM_E_RETRIG_NOTE:
			effect = IT_XM_RETRIGGER_NOTE;
			value = EFFECT_VALUE(0, value);
			break;

		case EBASE + XM_E_SET_VIBRATO_CONTROL:
			effect = SBASE+IT_S_SET_VIBRATO_WAVEFORM;
			value &= ~4;
			break;

		case EBASE + XM_E_SET_TREMOLO_CONTROL:
			effect = SBASE+IT_S_SET_TREMOLO_WAVEFORM;
			value &= ~4;
			break;

		case XBASE + XM_X_EXTRAFINE_PORTA_UP:
			effect = IT_PORTAMENTO_UP;
			value = EFFECT_VALUE(0xE, value);
			break;

		case XBASE + XM_X_EXTRAFINE_PORTA_DOWN:
			effect = IT_PORTAMENTO_DOWN;
			value = EFFECT_VALUE(0xE, value);
			break;

		default:
			/* user effect (often used in demos for synchronisation) */
			entry->mask &= ~IT_ENTRY_EFFECT;
	}

if (log) printf(" - %2d %02X", effect, value);

	/* Inverse linearisation... */
	if (effect >= SBASE && effect < SBASE+16) {
		value = EFFECT_VALUE(effect-SBASE, value);
		effect = IT_S;
	}

if (log) printf(" - %c%02X\n", 'A'+effect-1, value);

	entry->effect = effect;
	entry->effectvalue = value;
}
예제 #8
0
파일: taprep.c 프로젝트: MechanisM/entypo
static FT_Error
TA_table_build_prep(FT_Byte** prep,
                    FT_ULong* prep_len,
                    FONT* font)
{
  TA_LatinAxis vaxis;
  TA_LatinBlue blue_adjustment = NULL;
  FT_UInt i;

  FT_UInt buf_len = 0;
  FT_UInt len;
  FT_Byte* buf;
  FT_Byte* buf_p;


  if (font->loader->hints.metrics->clazz->script == TA_SCRIPT_NONE)
    vaxis = NULL;
  else
  {
    vaxis = &((TA_LatinMetrics)font->loader->hints.metrics)->axis[1];

    for (i = 0; i < vaxis->blue_count; i++)
    {
      if (vaxis->blues[i].flags & TA_LATIN_BLUE_ADJUSTMENT)
      {
        blue_adjustment = &vaxis->blues[i];
        break;
      }
    }
  }

  if (font->hinting_limit)
    buf_len += sizeof (PREP(hinting_limit_a))
               + 2
               + sizeof (PREP(hinting_limit_b));

  buf_len += sizeof (PREP(store_0x10000));

  if (blue_adjustment)
    buf_len += sizeof (PREP(align_top_a))
               + 1
               + sizeof (PREP(align_top_b))
               + (font->increase_x_height ? sizeof (PREP(align_top_c1))
                                          : sizeof (PREP(align_top_c2)))
               + sizeof (PREP(align_top_d))
               + sizeof (PREP(loop_cvt_a))
               + 2
               + sizeof (PREP(loop_cvt_b))
               + 2
               + sizeof (PREP(loop_cvt_c))
               + 2
               + sizeof (PREP(loop_cvt_d));

  buf_len += sizeof (PREP(compute_extra_light_a))
             + 1
             + sizeof (PREP(compute_extra_light_b));

  if (CVT_BLUES_SIZE(font))
    buf_len += sizeof (PREP(round_blues_a))
               + 2
               + sizeof (PREP(round_blues_b));

  buf_len += sizeof (PREP(set_dropout_mode));
  buf_len += sizeof (PREP(reset_component_counter));

  /* buffer length must be a multiple of four */
  len = (buf_len + 3) & ~3;
  buf = (FT_Byte*)malloc(len);
  if (!buf)
    return FT_Err_Out_Of_Memory;

  /* pad end of buffer with zeros */
  buf[len - 1] = 0x00;
  buf[len - 2] = 0x00;
  buf[len - 3] = 0x00;

  /* copy cvt program into buffer and fill in the missing variables */
  buf_p = buf;

  if (font->hinting_limit)
  {
    COPY_PREP(hinting_limit_a);
    *(buf_p++) = HIGH(font->hinting_limit);
    *(buf_p++) = LOW(font->hinting_limit);
    COPY_PREP(hinting_limit_b);
  }

  COPY_PREP(store_0x10000);

  if (blue_adjustment)
  {
    COPY_PREP(align_top_a);
    *(buf_p++) = (unsigned char)(CVT_BLUE_SHOOTS_OFFSET(font)
                                 + blue_adjustment - vaxis->blues);
    COPY_PREP(align_top_b);
    if (font->increase_x_height)
      COPY_PREP(align_top_c1);
    else
      COPY_PREP(align_top_c2);
    COPY_PREP(align_top_d);

    COPY_PREP(loop_cvt_a);
    *(buf_p++) = (unsigned char)CVT_VERT_WIDTHS_OFFSET(font);
    *(buf_p++) = (unsigned char)(CVT_VERT_WIDTHS_OFFSET(font)
                                 + CVT_VERT_WIDTHS_SIZE(font) - 1);
    COPY_PREP(loop_cvt_b);
    *(buf_p++) = (unsigned char)CVT_BLUE_REFS_OFFSET(font);
    *(buf_p++) = (unsigned char)(CVT_BLUE_REFS_OFFSET(font)
                                 + CVT_BLUES_SIZE(font) - 1);
    COPY_PREP(loop_cvt_c);
    *(buf_p++) = (unsigned char)CVT_BLUE_SHOOTS_OFFSET(font);
    *(buf_p++) = (unsigned char)(CVT_BLUE_SHOOTS_OFFSET(font)
                                 + CVT_BLUES_SIZE(font) - 1);
    COPY_PREP(loop_cvt_d);
  }

  COPY_PREP(compute_extra_light_a);
  *(buf_p++) = (unsigned char)CVT_VERT_STANDARD_WIDTH_OFFSET(font);
  COPY_PREP(compute_extra_light_b);

  if (CVT_BLUES_SIZE(font))
  {
    COPY_PREP(round_blues_a);
    *(buf_p++) = (unsigned char)CVT_BLUE_REFS_OFFSET(font);
    *(buf_p++) = (unsigned char)(CVT_BLUE_REFS_OFFSET(font)
                                 + CVT_BLUES_SIZE(font) - 1);
    COPY_PREP(round_blues_b);
  }

  COPY_PREP(set_dropout_mode);
  COPY_PREP(reset_component_counter);

  *prep = buf;
  *prep_len = buf_len;

  return FT_Err_Ok;
}
예제 #9
0
static FT_Error
TA_table_build_prep(FT_Byte** prep,
                    FT_ULong* prep_len,
                    SFNT* sfnt,
                    FONT* font)
{
  SFNT_Table* glyf_table = &font->tables[sfnt->glyf_idx];
  glyf_Data* data = (glyf_Data*)glyf_table->data;
  /* XXX: make this work for more than 256 styles */
  FT_Byte num_used_styles = (FT_Byte)data->num_used_styles;

  FT_Int i;

  FT_Byte* buf = NULL;
  FT_Byte* buf_new;
  FT_UInt buf_len;
  FT_UInt buf_new_len;

  FT_UInt len;
  FT_Byte* bufp = NULL;


  if (font->x_height_snapping_exceptions)
  {
    bufp = TA_sfnt_build_number_set(sfnt, &buf,
                                    font->x_height_snapping_exceptions);
    if (!bufp)
      return FT_Err_Out_Of_Memory;
  }

  buf_len = (FT_UInt)(bufp - buf);
  buf_new_len = buf_len;

  if (font->hinting_limit)
    buf_new_len += sizeof (PREP(hinting_limit_a))
                   + 2
                   + sizeof (PREP(hinting_limit_b));

  buf_new_len += sizeof (PREP(store_funits_to_pixels));

  if (font->x_height_snapping_exceptions)
    buf_new_len += sizeof (PREP(test_exception_a));

  buf_new_len += sizeof (PREP(align_top_a))
                 + (num_used_styles > 6 ? num_used_styles + 3
                                        : num_used_styles + 2)
                 + sizeof (PREP(align_top_b));
  buf_new_len += sizeof (PREP(loop_cvt_a))
                 + (num_used_styles > 3 ? 2 * num_used_styles + 3
                                        : 2 * num_used_styles + 2)
                 + sizeof (PREP(loop_cvt_b))
                 + (num_used_styles > 3 ? 2 * num_used_styles + 3
                                        : 2 * num_used_styles + 2)
                 + sizeof (PREP(loop_cvt_c));

  if (font->x_height_snapping_exceptions)
    buf_new_len += sizeof (PREP(test_exception_b));

  buf_new_len += sizeof (PREP(store_vwidth_data_a))
                 + 1
                 + sizeof (PREP(store_vwidth_data_b))
                 + (num_used_styles > 6 ? 2 * (num_used_styles + 1) + 2
                                        : 2 * (num_used_styles + 1) + 1)
                 + sizeof (PREP(store_vwidth_data_c))
                 + 1
                 + sizeof (PREP(store_vwidth_data_d))
                 + (num_used_styles > 6 ? 2 * (num_used_styles + 1) + 2
                                        : 2 * (num_used_styles + 1) + 1)
                 + sizeof (PREP(store_vwidth_data_e));
  buf_new_len += sizeof (PREP(set_smooth_or_strong_a))
                 + 1
                 + sizeof (PREP(set_smooth_or_strong_b))
                 + 1
                 + sizeof (PREP(set_smooth_or_strong_c))
                 + 1
                 + sizeof (PREP(set_smooth_or_strong_d));
  buf_new_len += (num_used_styles > 3 ? 2 * num_used_styles + 3
                                      : 2 * num_used_styles + 2)
                 + sizeof (PREP(round_blues));
  buf_new_len += sizeof (PREP(set_dropout_mode));
  buf_new_len += sizeof (PREP(reset_component_counter));
  if (font->control_data_head)
    buf_new_len += sizeof (PREP(adjust_delta_exceptions));
  buf_new_len += sizeof (PREP(set_default_cvs_values));

  /* buffer length must be a multiple of four */
  len = (buf_new_len + 3) & ~3U;
  buf_new = (FT_Byte*)realloc(buf, len);
  if (!buf_new)
  {
    free(buf);
    return FT_Err_Out_Of_Memory;
  }
  buf = buf_new;

  /* pad end of buffer with zeros */
  buf[len - 1] = 0x00;
  buf[len - 2] = 0x00;
  buf[len - 3] = 0x00;

  /* copy remaining cvt program into buffer */
  /* and fill in the missing variables */
  bufp = buf + buf_len;

  if (font->hinting_limit)
  {
    COPY_PREP(hinting_limit_a);
    *(bufp++) = HIGH(font->hinting_limit);
    *(bufp++) = LOW(font->hinting_limit);
    COPY_PREP(hinting_limit_b);
  }

  COPY_PREP(store_funits_to_pixels);

  if (font->x_height_snapping_exceptions)
    COPY_PREP(test_exception_a);

  COPY_PREP(align_top_a);
  if (num_used_styles > 6)
  {
    BCI(NPUSHB);
    BCI(num_used_styles + 2);
  }
  else
    BCI(PUSHB_1 - 1 + num_used_styles + 2);
  /* XXX: make this work for offsets > 255 */
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    *(bufp++) = CVT_X_HEIGHT_BLUE_OFFSET(i) >= 0xFFFFU
                  ? 0
                  : (unsigned char)CVT_X_HEIGHT_BLUE_OFFSET(i);
  }
  *(bufp++) = num_used_styles;
  COPY_PREP(align_top_b);

  COPY_PREP(loop_cvt_a);
  if (num_used_styles > 3)
  {
    BCI(NPUSHB);
    BCI(2 * num_used_styles + 2);
  }
  else
    BCI(PUSHB_1 - 1 + 2 * num_used_styles + 2);
  /* XXX: make this work for offsets > 255 */
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    /* don't loop over artificial blue zones */
    *(bufp++) = (unsigned char)CVT_VERT_STANDARD_WIDTH_OFFSET(i);
    *(bufp++) = (unsigned char)(
                  1
                  + CVT_VERT_WIDTHS_SIZE(i)
                  + (CVT_BLUES_SIZE(i) > 1 ? CVT_BLUES_SIZE(i) - 2 : 0));
  }
  *(bufp++) = num_used_styles;
  COPY_PREP(loop_cvt_b);
  if (num_used_styles > 3)
  {
    BCI(NPUSHB);
    BCI(2 * num_used_styles + 2);
  }
  else
    BCI(PUSHB_1 - 1 + 2 * num_used_styles + 2);
  /* XXX: make this work for offsets > 255 */
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    /* don't loop over artificial blue zones */
    *(bufp++) = (unsigned char)CVT_BLUE_SHOOTS_OFFSET(i);
    *(bufp++) = (unsigned char)(
                  CVT_BLUES_SIZE(i) > 1 ? CVT_BLUES_SIZE(i) - 2 : 0);
  }
  *(bufp++) = num_used_styles;
  COPY_PREP(loop_cvt_c);

  if (font->x_height_snapping_exceptions)
    COPY_PREP(test_exception_b);

  COPY_PREP(store_vwidth_data_a);
  *(bufp++) = (unsigned char)CVT_VWIDTH_OFFSET_DATA(0);
  COPY_PREP(store_vwidth_data_b);
  if (num_used_styles > 6)
  {
    BCI(NPUSHW);
    BCI(num_used_styles + 2);
  }
  else
    BCI(PUSHW_1 - 1 + num_used_styles + 2);
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    *(bufp++) = HIGH(CVT_VERT_WIDTHS_OFFSET(i) * 64);
    *(bufp++) = LOW(CVT_VERT_WIDTHS_OFFSET(i) * 64);
  }
  *(bufp++) = HIGH(num_used_styles);
  *(bufp++) = LOW(num_used_styles);
  COPY_PREP(store_vwidth_data_c);
  *(bufp++) = (unsigned char)CVT_VWIDTH_SIZE_DATA(0);
  COPY_PREP(store_vwidth_data_d);
  if (num_used_styles > 6)
  {
    BCI(NPUSHW);
    BCI(num_used_styles + 2);
  }
  else
    BCI(PUSHW_1 - 1 + num_used_styles + 2);
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    *(bufp++) = HIGH(CVT_VERT_WIDTHS_SIZE(i) * 64);
    *(bufp++) = LOW(CVT_VERT_WIDTHS_SIZE(i) * 64);
  }
  *(bufp++) = HIGH(num_used_styles);
  *(bufp++) = LOW(num_used_styles);
  COPY_PREP(store_vwidth_data_e);

  COPY_PREP(set_smooth_or_strong_a);
  *(bufp++) = font->gray_strong_stem_width ? 100 : 0;
  COPY_PREP(set_smooth_or_strong_b);
  *(bufp++) = font->gdi_cleartype_strong_stem_width ? 100 : 0;
  COPY_PREP(set_smooth_or_strong_c);
  *(bufp++) = font->dw_cleartype_strong_stem_width ? 100 : 0;
  COPY_PREP(set_smooth_or_strong_d);

  if (num_used_styles > 3)
  {
    BCI(NPUSHB);
    BCI(2 * num_used_styles + 2);
  }
  else
    BCI(PUSHB_1 - 1 + 2 * num_used_styles + 2);
  /* XXX: make this work for offsets > 255 */
  for (i = TA_STYLE_MAX - 1; i >= 0; i--)
  {
    if (data->style_ids[i] == 0xFFFFU)
      continue;

    *(bufp++) = (unsigned char)CVT_BLUE_REFS_OFFSET(i);
    *(bufp++) = (unsigned char)CVT_BLUES_SIZE(i);
  }
  *(bufp++) = num_used_styles;
  COPY_PREP(round_blues);

  COPY_PREP(set_dropout_mode);
  COPY_PREP(reset_component_counter);
  if (font->control_data_head)
    COPY_PREP(adjust_delta_exceptions);
  COPY_PREP(set_default_cvs_values);

  *prep = buf;
  *prep_len = buf_new_len;

  return FT_Err_Ok;
}
void test_filter_cases(){
  interval input,res,waited;
  db_number res_low, res_up, waited_low, waited_up;
  printf("When low>up... ");
  ASSIGN_LOW(input,3);
  ASSIGN_UP(input,2);
  ASSIGN_LOW(waited,0.0/0.0);
  ASSIGN_UP(waited,0.0/0.0);
  res=j_log(input);
  res_low.d=LOW(res);
  res_up.d=UP(res);
  waited_low.d=LOW(waited);
  waited_up.d=UP(waited);
  if (  (waited_low.i[LO]==res_low.i[LO])
     && (waited_low.i[HI]==res_low.i[HI])
     && (waited_up.i[LO]==res_up.i[LO])
     && (waited_up.i[HI]==res_up.i[HI]))
  {
    printf("OK\n");
  }
   else
  {
    printHexa("Waited low:",waited_low.d);
    printHexa("Waited up:",waited_up.d);
    printHexa("Given low:",res_low.d);
    printHexa("Given up:",res_up.d);
  }

  printf("When up<0... ");
  ASSIGN_LOW(input,3);
  ASSIGN_UP(input,-2);
  ASSIGN_LOW(waited,0.0/0.0);
  ASSIGN_UP(waited,0.0/0.0);
  res=j_log(input);
  res_low.d=LOW(res);
  res_up.d=UP(res);
  waited_low.d=LOW(waited);
  waited_up.d=UP(waited);
  if (  (waited_low.i[LO]==res_low.i[LO])
     && (waited_low.i[HI]==res_low.i[HI])
     && (waited_up.i[LO]==res_up.i[LO])
     && (waited_up.i[HI]==res_up.i[HI]))
  {
    printf("OK\n");
  }
   else
  {
    printHexa("Waited low:",waited_low.d);
    printHexa("Waited up:",waited_up.d);
    printHexa("Given low:",res_low.d);
    printHexa("Given up:",res_up.d);
  }

  printf("When low=1, up=1... ");
  ASSIGN_LOW(input,1.0);
  ASSIGN_UP(input,1.0);
  ASSIGN_LOW(waited,0.0);
  ASSIGN_UP(waited,0.0);
  res=j_log(input);
  res_low.d=LOW(res);
  res_up.d=UP(res);
  waited_low.d=LOW(waited);
  waited_up.d=UP(waited);
  if (  (waited_low.i[LO]==res_low.i[LO])
     && (waited_low.i[HI]==res_low.i[HI])
     && (waited_up.i[LO]==res_up.i[LO])
     && (waited_up.i[HI]==res_up.i[HI]))
  {
    printf("OK\n");
  }
   else
  {
    printHexa("Waited low:",waited_low.d);
    printHexa("Waited up:",waited_up.d);
    printHexa("Given low:",res_low.d);
    printHexa("Given up:",res_up.d);
  }
  printf("When low<0 and up>0... ");
  ASSIGN_LOW(input,-100.0);
  ASSIGN_UP(input,2);
  ASSIGN_LOW(waited,-1.0/0.0);
  ASSIGN_UP(waited,-1.0/0.0);
  res=j_log(input);
  res_low.d=LOW(res);
  res_up.d=UP(res);
  waited_low.d=LOW(waited);
  waited_up.d=UP(waited);
  if (  (waited_low.i[LO]==res_low.i[LO])
     && (waited_low.i[HI]==res_low.i[HI]))
   {
    printf("OK\n");
  }
   else
  {
    printHexa("Waited low:",waited_low.d);
    printHexa("Waited up:",waited_up.d);
    printHexa("Given low:",res_low.d);
    printHexa("Given up:",res_up.d);
  }

}
void test_all() {
  long long int 
    failures_libm=0,
#ifdef HAVE_MATHLIB_H
    failures_libultim=0,
#endif
#ifdef HAVE_LIBMCR_H
    failures_libmcr=0,
#endif
    failures_crlibm=0;
  long long int i;
  double worst_err, global_worst_err=-200;
  db_number global_worst_inpt, global_worst_inpt2;

  i=0; 
  while(1+1==2)
  {
    input.d = randfun();
    input2.d = randfun();
    if (input.d>input2.d)
    {
      double temp=input.d;
      input.d=input2.d;
      input2.d=temp;
    }
/*    db_number ia,ib;
    ia.i[HI]=0x31100afb;
    ia.i[LO]=0x198a95fe;
    ib.i[HI]=0x3d42897b;
    ib.i[LO]=0x84591a4e;
    input.d=ia.d; input2.d=ib.d;*/
    ASSIGN_LOW(input_i,input.d);
    ASSIGN_UP(input_i,input2.d);
   

    res_crlibm = testfun_crlibm_interval(input_i);
    res_crlibm_low.d=LOW(res_crlibm);
    res_crlibm_up.d=UP(res_crlibm);
    mpfr_set_d(mp_inpt, input.d, GMP_RNDN);
    testfun_mpfr(mp_res, mp_inpt, GMP_RNDD);
    res_mpfr_low.d = mpfr_get_d(mp_res, GMP_RNDD);
    mpfr_set_d(mp_inpt, input2.d, GMP_RNDN);
    testfun_mpfr(mp_res, mp_inpt, GMP_RNDU);
    res_mpfr_up.d = mpfr_get_d(mp_res, GMP_RNDU);
/*    printHexa("resul crlibm low:",res_crlibm_low.d);
    printHexa("resul crlibm up:",res_crlibm_up.d);
    printHexa("resul mpfr low:",res_mpfr_low.d);
    printHexa("resul mpfr up:",res_mpfr_up.d);*/
    

#if PRINT_NAN
    if(1){
#else
      if( ((res_mpfr_low.i[HI] & 0x7ff00000) != 0x7ff00000)
       && ((res_mpfr_up.i[HI] & 0x7ff00000) != 0x7ff00000) ) {
#endif
	if( (res_crlibm_low.i[LO] != res_mpfr_low.i[LO]) 
	    || (res_crlibm_low.i[HI] != res_mpfr_low.i[HI])
	    || (res_crlibm_up.i[LO] != res_mpfr_up.i[LO])
	    || (res_crlibm_up.i[HI] != res_mpfr_up.i[HI]) )
	    {
#if DETAILED_REPORT
	  printf("*** CRLIBM ERROR ***\n");
	  PRINT_INPUT_ERROR;
	  printf("crlibm gives    [%.50e,%.50e] \n         [(%08x %08x),(%08x %08x)] \n", 
		 res_crlibm_low.d, res_crlibm_up.d,
		 res_crlibm_low.i[HI], res_crlibm_low.i[LO],
		 res_crlibm_up.i[HI], res_crlibm_up.i[LO]);
	  printf("MPFR gives      [%.50e,%.50e] \n         [(%08x %08x),(%08x %08x)] \n\n", 
		 res_mpfr_low.d, 
		 res_mpfr_up.d,
		 res_mpfr_low.i[HI], 
		 res_mpfr_low.i[LO],
		 res_mpfr_up.i[HI],
		 res_mpfr_up.i[LO]
		 );
#endif
#if WORST_ERROR_REPORT
	  mpfr_set_d(mp_inpt, res_crlibm_low.d, GMP_RNDN);  
	  mpfr_sub(mp_inpt, mp_inpt, mp_res, GMP_RNDN);  
	  mpfr_div(mp_inpt, mp_inpt, mp_res, GMP_RNDN);
	  mpfr_abs(mp_inpt, mp_inpt, GMP_RNDN);
	  mpfr_log2(mp_inpt, mp_inpt, GMP_RNDN);
	  worst_err=mpfr_get_d(mp_inpt, GMP_RNDN);

	  if (worst_err>global_worst_err){
	    global_worst_err=worst_err;
	    global_worst_inpt.d  = input.d;
	    global_worst_inpt2.d = input2.d;
	  }
	  mpfr_set_d(mp_inpt, res_crlibm_up.d, GMP_RNDN);
	  mpfr_sub(mp_inpt, mp_inpt, mp_res, GMP_RNDN);
	  mpfr_div(mp_inpt, mp_inpt, mp_res, GMP_RNDN);
	  mpfr_abs(mp_inpt, mp_inpt, GMP_RNDN);
	  mpfr_log2(mp_inpt, mp_inpt, GMP_RNDN);
	  worst_err=mpfr_get_d(mp_inpt, GMP_RNDN);
	  
	  if (worst_err>global_worst_err){
	    global_worst_err=worst_err;
	    global_worst_inpt.d  = input.d;
            global_worst_inpt2.d = input2.d;
          }
	  printf("Worst crlibm relative error so far : 2^(%f)\n",global_worst_err);
	  printf(" for x =%.50e     (%08x %08x) \n", 
		 global_worst_inpt.d, 
		 global_worst_inpt.i[HI], 
		 global_worst_inpt.i[LO]);
#endif

	  failures_crlibm++;
	}
	
      }
      i++;
      if((i % 10000)==0) 
      {
	printf(" CRLIBM       : %lld failures out of %lld (ratio %e) \n",failures_crlibm, i,
	       ((double)failures_crlibm)/(double)i);
	printf("\n");
      }
  }
}




void usage(char *fct_name){
  /* fprintf (stderr, "\n%s: Soak-test for crlibm and other mathematical libraries \n", fct_name); */
  fprintf (stderr, "\nUsage: %s function seed \n", fct_name);
  fprintf (stderr, " function      : name of function to test \n");
  fprintf (stderr, " seed          : integer seed for the random number generator \n");
  exit (1);
}
예제 #12
0
/**
 * CT-BCS Eject ICC command
 *
 * @param ctx Reader context
 * @param lc Length of command
 * @param cmd Command
 * @param lr Length of response
 * @param rsp Response buffer
 * @return \ref OK, \ref ERR_CT
 */
int EjectICC(struct scr *ctx, unsigned int lc, unsigned char *cmd,
			 unsigned int *lr, unsigned char *rsp)
{
	int status;
	unsigned char save_timeout;
	unsigned char timeout;

	/* Reader has no display or other goodies, so check for correct P2 parameter */
	/* Unmask bit 3, because we can always keep the card in the slot               */

	if ((cmd[3] & 0xFB) != 0x00) {
		rsp[0] = HIGH(WRONG_PARAMETERS_P1_P2);
		rsp[1] = LOW(WRONG_PARAMETERS_P1_P2);
		*lr = 2;
		return OK;
	}

	if ((lc > 4) && (cmd[4] > 0)) {
		timeout = cmd[5];
	} else {
		timeout = 0;
	}

	save_timeout = timeout;

	status = PC_to_RDR_IccPowerOff(ctx);

	if (status < 0) {
		rsp[0] = HIGH(NOT_SUCCESSFUL);
		rsp[1] = LOW(NOT_SUCCESSFUL);
		*lr = 2;
		return ERR_CT;
	}

	ctx->CTModFunc = NULL;
	ctx->LenOfATR = 0;
	ctx->NumOfHB = 0;

	save_timeout *= 4;

	if (save_timeout > 0) {
		do {

			status = PC_to_RDR_GetSlotStatus(ctx);

			if (status < 0) {
				rsp[0] = HIGH(NOT_SUCCESSFUL);
				rsp[1] = LOW(NOT_SUCCESSFUL);
				*lr = 2;
				return ERR_CT;
			}

			if (status == ICC_PRESENT_AND_INACTIVE || status == NO_ICC_PRESENT) {
				break;
			}

			usleep(250000);

		} while (--save_timeout);

	} else { /* Command OK,no timeout specified   */
		rsp[0] = HIGH(SMARTCARD_SUCCESS);
		rsp[1] = LOW(SMARTCARD_SUCCESS);
		*lr = 2;
		return OK;
	}

	if (save_timeout) { /* Command OK, card removed          */
		rsp[0] = HIGH(SMARTCARD_SUCCESS);
		rsp[1] = LOW(SMARTCARD_SUCCESS);
		*lr = 2;
		return OK;
	}

	if ((!save_timeout) && (timeout > 0)) { /* warning: card not removed */
		rsp[0] = HIGH(W_NO_CARD_PRESENTED);
		rsp[1] = LOW(W_NO_CARD_PRESENTED);
		*lr = 2;
	}

	return OK;
}
예제 #13
0
void pscUpdateAll(PscValues *pscValues)
{
	psc0LockCompareValues();
	psc1LockCompareValues();
	psc2LockCompareValues();

#if (PSC0_FIFTY_PERCENT_MODE == 1)
	OCR0SBH = HIGH(pscValues->deadtime1);
	OCR0SBL = LOW (pscValues->deadtime1);
	OCR0RBH = HIGH(pscValues->ontime1);
	OCR0RBL = LOW (pscValues->ontime1);
#else
    OCR0SAH = HIGH(psc0Values->deadtime0);
    OCR0SAL = LOW (psc0Values->deadtime0);
    OCR0RAH = HIGH(psc0Values->ontime0);
    OCR0RAL = LOW (psc0Values->ontime0);
    OCR0SBH = HIGH(psc0Values->deadtime1);
    OCR0SBL = LOW (psc0Values->deadtime1);
    OCR0RBH = HIGH(psc0Values->ontime1);
    OCR0RBL = LOW (psc0Values->ontime1);
#endif

#if (PSC1_FIFTY_PERCENT_MODE == 1)
	OCR1SBH = HIGH(pscValues->deadtime1);
	OCR1SBL = LOW (pscValues->deadtime1);
	OCR1RBH = HIGH(pscValues->ontime1);
	OCR1RBL = LOW (pscValues->ontime1);
#else
    OCR1SAH = HIGH(psc1Values->deadtime0);
    OCR1SAL = LOW (psc1Values->deadtime0);
    OCR1RAH = HIGH(psc1Values->ontime0);
    OCR1RAL = LOW (psc1Values->ontime0);
    OCR1SBH = HIGH(psc1Values->deadtime1);
    OCR1SBL = LOW (psc1Values->deadtime1);
    OCR1RBH = HIGH(psc1Values->ontime1);
    OCR1RBL = LOW (psc1Values->ontime1);
#endif

#if (PSC2_FIFTY_PERCENT_MODE == 1)
	OCR2SBH = HIGH(pscValues->deadtime1);
	OCR2SBL = LOW (pscValues->deadtime1);
	OCR2RBH = HIGH(pscValues->ontime1);
	OCR2RBL = LOW (pscValues->ontime1);
#else
    OCR2SAH = HIGH(psc2Values->deadtime0);
    OCR2SAL = LOW (psc2Values->deadtime0);
    OCR2RAH = HIGH(psc2Values->ontime0);
    OCR2RAL = LOW (psc2Values->ontime0);
    OCR2SBH = HIGH(psc2Values->deadtime1);
    OCR2SBL = LOW (psc2Values->deadtime1);
    OCR2RBH = HIGH(psc2Values->ontime1);
    OCR2RBL = LOW (psc2Values->ontime1);
#endif

    psc0UpdateCompareValues();
    psc1UpdateCompareValues();
    psc2UpdateCompareValues();
}