voicesetword.c 1.59 KB
/*---------------------------------------------------------------------
 	Copyright (C) 1997,1998 Nintendo.
 	
 	File		voicesetword.c
 	Coded    by	Koji Mitsunari.	Oct  6, 1997.
 	Modified by	Koji Mitsunari.	Jun 22, 1998.
 	Comments	Voice Recognition System
   
 	$Id: voicesetword.c,v 1.2 2003/03/25 20:42:04 blythe Exp $
   ---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"
#include "siint.h"

s32
osVoiceSetWord(OSVoiceHandle *hd, u8 *data) {
#ifdef BBPLAYER
    return CONT_ERR_DEVICE;
#else
  s32	j, k, ret;
  u8	stat;
  u8	buf[40];

  if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
    return(ret);
  } else if (stat & VOICE_WRITE_READY ) {
    return(CONT_ERR_VOICE_NO_RESPONSE);
  }
    
  for ( k = 0 ; data[k] ; k += 2); 	/* NULLޤǥݥ󥿰ư */

#ifdef	_DEBUG
  if (k >= 34) {
    return(CONT_ERR_VOICE_WORD);
  }
#endif    

  bzero(buf, 40);
    
  for ( j = 0 ; j < k ; j += 2 ) {
    buf[39 - k + j] = data[j];
    buf[39 - k + j-1] = data[j+1];
  }
  buf[39-j-5] = 3;
  if (k > 14) {
    ret = __osVoiceContWrite20(hd->__mq, hd->__channel, VOICE_RW_ADDR, buf);
    if (ret != 0 ) {
      return(ret);
    }
  }
  ret = __osVoiceContWrite20(hd->__mq, hd->__channel, VOICE_RW_ADDR,
			     &buf[20]);
  if (ret != 0 ) {
    return(ret);
  }
  ret = __osVoiceCheckResult(hd, &stat);

  if (ret != 0) {
    if (ret & 0x0100) {
      ret = CONT_ERR_VOICE_MEMORY;
    } else if (ret & 0x0200) {
      ret = CONT_ERR_VOICE_WORD;
    } else if (ret & 0xff00) {
      ret = CONT_ERR_INVALID;
    }
  }
  
  return(ret);
#endif
}