voicegetreaddata.c 3.03 KB
/*---------------------------------------------------------------------
 	Copyright (C) 1997,1998 Nintendo.
 	
 	File		voicegetreaddata.c
 	Coded    by	Koji Mitsunari.	Oct  8, 1997.
 	Modified by	Koji Mitsunari.	Jun 22, 1998.
 	Comments	Voice Recognition System
   
 	$Id: voicegetreaddata.c,v 1.1.1.1 2002/05/02 03:28:44 blythe Exp $
   ---------------------------------------------------------------------*/
#include "osint.h"
#include "controller.h"
#include "siint.h"

s32
osVoiceGetReadData(OSVoiceHandle *hd, OSVoiceData *micdata) {
  s32		ret = 0, i;
  u8		stat;
  u8		temp[36];
  static u8	c;

  switch ( hd->__mode ) {
  case 1:
    if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
      return(ret);
    } else if (stat & VOICE_READ_READY) {
      return(CONT_ERR_NOT_READY);
    }
    if ((ret = __osVoiceContRead2(hd->__mq, hd->__channel,
				  VOICE_RW_ADDR, temp)) != 0){
      return(ret);
    }
    c = (temp[0] & 0x07);
    hd->cmd_status = c;
    if ( c != 0 && c != 7 ) {	/* finished execution ? */
      return(CONT_ERR_NOT_READY);
    }
  case 2:			/* getting data */
    hd->__mode = 2;
    if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0) {
      return(ret);
    }
    if (stat & VOICE_WRITE_READY) {
      return(CONT_ERR_VOICE_NO_RESPONSE);
    }

    ((u32 *)temp)[0]=0x600;
    ret = __osVoiceContWrite4(hd->__mq, hd->__channel, VOICE_RW_ADDR, temp);
    if (ret != 0 ) {
      return(ret);
    }
  case 3:
    hd->__mode = 3;
    if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
      return(ret);
    } else if (stat & VOICE_READ_READY) {
      return(CONT_ERR_VOICE_NO_RESPONSE);
    }
    
    ret = __osVoiceContRead36(hd->__mq, hd->__channel, VOICE_RW_ADDR, temp);
    if (ret != 0 ) {
      return(ret);
    }
    
    micdata->warning	= temp[4] + (temp[5]<<8);
#if 1
    micdata->answer_num = temp[6];
#else
    if (temp[6] == 0 ) {
      micdata->answer_num = 5;
    } else {
      micdata->answer_num = temp[6];
    }
#endif
    micdata->voice_level = temp[8] + (temp[9]<<8);
    micdata->voice_sn = temp[10] + (temp[11]<<8);
    micdata->voice_time = temp[12] + (temp[13]<<8);
    for ( i = 0 ; i < 5 ; i++ ) {
      micdata->answer[i] = temp[14+(i<<2)] + (temp[15+(i<<2)]<<8);
      micdata->distance[i] = temp[16+(i<<2)] + (temp[17+(i<<2)]<<8);
    }
    if (micdata->answer[0] == 0x7fff) {
      micdata->answer_num = 0;
    }

    hd->cmd_status = (temp[34] & 7);
    if (c == 0 || hd->cmd_status == 0) {
      break;
    }
  case 4:
    hd->__mode  = 4;
    if ((ret = __osVoiceGetStatus(hd->__mq, hd->__channel, &stat)) != 0 ) {
      return(ret);
    }
    if (stat & VOICE_READ_READY) {
      return(CONT_ERR_VOICE_NO_RESPONSE);
    }

    if ((ret = __osVoiceContRead2(hd->__mq, hd->__channel,
				  VOICE_RW_ADDR, temp)) != 0){
      return(ret);
    }
    hd->cmd_status = (temp[0] & 7);
    if ( (temp[0] & 0x07) != 0  ) {	/* finished execution */
      return(CONT_ERR_VOICE_NO_RESPONSE);
    }
    break;
  default:
    return(CONT_ERR_INVALID);
  }
  hd->__mode = 0;
  return(ret);
}