ALAN@NCSUVM.BITNET (08/06/85)
Here is an interface for MacIntalk for Aztec C.
Calls are just as defined in the MacIntalk documents.
Posted with permission by Alan Clegg, ALAN@NCSUVM.BITNET
for Michael Hecht
Please resopond to ALAN@NCSUVM.BITNET
Thanks...
-------------------------------------Cut Here----------------------------------
#define _DRIVER
#include <memory.h>
#include <pb.h>
#include <resource.h>
#include "speech.h"
#define NULL 0L
struct pbRec {
struct ParamBlkRec * ioLink;
short ioType;
short ioTrap;
Ptr ioCmdAddr;
ProcPtr ioCompletion;
short ioResult;
char * ioNamePtr;
short ioVRefNum;
union {
struct ioParam iop;
struct cntrlParam cp;
} u;
};
/*
* Internal format of the SpeechRecord structure
*/
struct iSpeechRecord {
struct pbRec pb; /* 50 bytes */
int junk0; /* 50 */
ProcPtr * rdrH0; /* 52 */
long junk4; /* 56 */
Str255 * ExcpFile; /* 60 */
int junk6; /* 64 */
ProcPtr * rdrHandle; /* 66 */
int DrvrRefNum; /* 70 */
int junk2; /* 72 */
int ExcpRefNum; /* 74 */
char junk1[24]; /* 76 */
};
typedef struct iSpeechRecord iSpeechRecord;
typedef iSpeechRecord * iSpeechPtr;
typedef iSpeechPtr * iSpeechHandle;
/* Driver Control Codes */
#define MODE_CODE 0
/* Code 1 for language maybe? */
#define RATE_CODE 2
#define SEX_CODE 3
#define PITCH_CODE 4
#define uTableBase ((long*)0x011c)
SpeechErr SpeechOn( ExcpsFile, ptheSpeech )
Str255 * ExcpsFile;
SpeechHandle * ptheSpeech;
{
static char * DrvrName = "\P.SPEECH";
static char * DrvrFile = "\PMacinTalk";
register iSpeechHandle theSpeech;
register iSpeechPtr isp;
register int refNum;
register Handle h;
register long * utp;
register int id;
register OSErr err;
* ptheSpeech = theSpeech
= NewHandle(( Size )( sizeof( iSpeechRecord )));
if( err = MemError())
return err;
HLock( theSpeech );
isp = *theSpeech;
setmem( isp, sizeof( iSpeechRecord ), 0 );
if(( refNum = OpenResFile( DrvrFile )) < 0 )
return ResError();
isp->ExcpRefNum = refNum;
SetResLoad( FALSE );
h = GetNamedResource( 'DRVR', DrvrName );
if( err = ResError())
return err;
SetResLoad( TRUE );
utp = uTableBase;
utp = &(utp[32]);
id = 32;
do {
--id;
if( id<= 18 )
return fullUnitT;
} while( *--utp );
isp->DrvrRefNum = -(id+1);
SetResInfo( h, id, NULL );
LoadResource( h );
/* err = ResError(); */
HLock( h );
isp->ExcpFile = ExcpsFile;
isp->pb.ioNamePtr = DrvrName;
isp->pb.ioVRefNum = 0;
isp->pb.u.iop.ioVersNum = 0;
isp->pb.u.iop.ioPermssn = 0;
isp->pb.u.iop.ioMisc = NULL;
PBOpen( isp, FALSE );
err = isp->pb.ioResult;
isp->rdrHandle = isp->rdrH0;
HUnlock( theSpeech );
return err;
}
void SpeechOff( theSpeech )
SpeechHandle theSpeech;
{
register iSpeechPtr isp;
register int excpRef;
HLock( theSpeech );
isp = *( iSpeechHandle )theSpeech;
PBClosei( isp );
if( excpRef = isp->ExcpRefNum )
CloseResFile( excpRef );
HUnlock( theSpeech );
DisposHandle( theSpeech );
}
void SpeechRate( theSpeech, theRate )
SpeechHandle theSpeech;
int theRate;
{
register iSpeechPtr isp;
HLock( theSpeech );
isp = *( iSpeechHandle )theSpeech;
isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
isp->pb.u.cp.csCode = RATE_CODE;
isp->pb.u.cp.csParam.conCtl.sg_flags = theRate;
PBCntli( isp );
HUnlock( theSpeech );
}
void SpeechPitch( theSpeech, thePitch, theMode )
SpeechHandle theSpeech;
int thePitch;
FOMode theMode;
{
register iSpeechPtr isp;
HLock( theSpeech );
isp = *( iSpeechHandle )theSpeech;
isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
isp->pb.u.cp.csCode = MODE_CODE;
isp->pb.u.cp.csParam.conCtl.sg_flags = theMode;
PBCntli( isp );
isp->pb.u.cp.csCode = PITCH_CODE;
isp->pb.u.cp.csParam.conCtl.sg_flags = thePitch;
PBCntli( isp );
HUnlock( theSpeech );
}
void SpeechSex( theSpeech, theSex )
SpeechHandle theSpeech;
Sex theSex;
{
register iSpeechPtr isp;
HLock( theSpeech );
isp = *( iSpeechHandle )theSpeech;
isp->pb.u.cp.csRefNum = isp->DrvrRefNum;
isp->pb.u.cp.csCode = SEX_CODE;
isp->pb.u.cp.csParam.conCtl.sg_flags = theSex;
PBCntli( isp );
HUnlock( theSpeech );
}
SpeechErr Reader( theSpeech, EnglishInput, InputLength, PhoneticOutput )
SpeechHandle theSpeech;
Ptr EnglishInput;
long InputLength;
Handle PhoneticOutput;
{
register iSpeechPtr isp;
register ProcPtr * rdr;
pascal SpeechErr DummyReader();
HLock( theSpeech );
isp = *( iSpeechHandle )theSpeech;
rdr = isp->rdrHandle;
HLock( rdr );
return DummyReader( EnglishInput, InputLength, PhoneticOutput, *rdr );
}
#asm
DummyRea_:
move.l 4(sp),a0 ; a0 <- RealReader
move.l (sp)+,(sp) ; RealReader spot <- ret address
jmp (a0) ; Branch to real reader
#endasm
SpeechErr MacinTalk( theSpeech, Phonemes )
SpeechHandle theSpeech;
Handle Phonemes;
{
register Size PhonemeSize;
register iSpeechPtr isp;
register OSErr err;
HLock( theSpeech );
PhonemeSize = GetHandleSIze( Phonemes );
isp = *( iSpeechHandle )theSpeech;
isp->pb.u.iop.ioRefNum = isp->DrvrRefNum;
isp->pb.u.iop.ioBuffer = Phonemes;
isp->pb.u.iop.ioReqCount = PhonemeSize;
err = PBWritei( isp );
HUnlock( theSpeech );
return err;
}
#asm
PBClosei_:
move.l 4(sp),a0 ; isp -> a0
dc.w $a201 ; _Close, Immed
rts
PBWritei_:
move.l 4(sp),a0 ; isp -> a0
dc.w $a203 ; _Write, Immed
rts
PBCntli_:
move.l 4(sp),a0 ; isp -> a0
dc.w $a204 ; _Control, Immed
rts
#endasm