/****************************************/
/*  Talk module for English Clock v3.0  */
/*  ==================================  */
/*           Version 1.0                */
/*      Last revised: 23/08/95          */
/****************************************/

/* This module is totally seperate from the English clock main code
   and as such must be linked in as a module and link time.  For those
   in need of a high-level routine such as this, feel free to use it in
   your own programs, although you would have to be a bit sad to want
   this! */

#include <stdio.h>
#include <string.h>
#include <exec/types.h>
//#include <proto/exec.h>
#include <devices/narrator.h>
//#include <proto/dos.h>
//#include <proto/intuition.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <dos/dos.h>
#include <dos/dostags.h>


BOOL talk(char *text);

BOOL talk(char *text) {

   /**************************/
   /*          talk          */
   /*          ----          */
   /* One input, char *text  */
   /* ptr to string of       */
   /* phonetics.  Returns    */
   /* 1 success, 0 failure   */
   /**************************/

   struct MsgPort *VoiceMP;
   struct narrator_rb *VoiceIO;
   BYTE audio_chan[4];

   audio_chan[0]=3; audio_chan[1]=5; audio_chan[2]=10; audio_chan[3]=12;

   VoiceMP=CreateMsgPort();
   if(!VoiceMP) {
      DisplayBeep(NULL);
      return/*(0)*/;
   }

   VoiceIO=CreateIORequest(VoiceMP,sizeof(struct narrator_rb));
   if(!VoiceIO) {
      DisplayBeep(NULL);
      DeleteMsgPort(VoiceMP);
      return/*(0)*/;
   }

   VoiceIO->flags=NDF_NEWIORB;

   if(OpenDevice("narrator.device",0,(struct IORequest *)VoiceIO,NULL)) {
      //DisplayBeep(NULL);
      DeleteIORequest(VoiceIO);
      DeleteMsgPort(VoiceMP);
      return/*(0)*/;
   }

   VoiceIO->ch_masks=&audio_chan[0];
   VoiceIO->nm_masks=sizeof(audio_chan);
   VoiceIO->message.io_Command=CMD_WRITE;
   VoiceIO->message.io_Data=text;
   VoiceIO->message.io_Length=strlen(text);

   DoIO((struct IORequest *)VoiceIO);

   CloseDevice((struct IORequest *)VoiceIO);
   DeleteIORequest(VoiceIO);
   DeleteMsgPort(VoiceMP);

   //return(1);

}

