/*   ================================================================  */
/*			MasterBrain.c				       */
/*                      10.1.88  Ver 1.0	    		       */
/*   	 Thanks to EA for the IFF routines. 	        	       */
/* 	 The PD Speech routines are from Rob Peck's Speech Demo        */	
/*       Thanks to the anonymous Atari font creators, (fonts ported    */
/*       to the Amiga. A kludgey hack.....			       */	
/*   ================================================================  */
/*   					    (c)Tourmaline Software 10-1-88
				            Dana McPhee           
                                            763 Summer St. #3    
                                            Lynn,MA 01905        
				            E-Mail@ IDCMP,(617)769-3172
					    or Citinet-Boston,(617)439-5699
					    (TRAMIELHUNTER)	
*/
#include "types.h"
#include "memory.h"
#include "intuition.h"
#include "gfx.h"
#include "view.h"
#include "fcntl.h"
#include "stdio.h"
#include "exec.h"
#include "gfx.h"
#include "copper.h"
#include "gels.h"
#include "gfxbase.h"
#include "gfxmacros.h"
#include "clip.h"
#include "rastport.h"
#include "layers.h"
#include "text.h"
#include "collide.h"
#include "custom.h"
#include "dmabits.h"
#include "dos.h"
#include "audio.h"
#include "math.h"
#include "nodes.h"
#include "lists.h"
#include "ports.h"
#include "tasks.h"
#include "io.h"
#include "gads.h"
#include "nodes.h"
#include "lists.h"
#include "memory.h"
#include "interrupts.h"
#include "ports.h"
#include "libraries.h"
#include "io.h"
#include "execbase.h"
#include "narrator.h"
#include "translator.h"

struct MsgPort *readport=0;
struct MsgPort *writeport=0;
extern struct MsgPort *CreatePort();
extern struct IORequest *CreateExtIO();
struct narrator_rb *writeNarrator=0;
struct mouth_rb *readNarrator=0;
struct Library *TranslatorBase=0;

UBYTE *sampleinput;
UBYTE outputstring[500];
SHORT rtnCode;
SHORT readError;
SHORT writeError;
SHORT error;
BYTE audChanMasks[4] = { 3,5,10,12 };
ULONG mex;

#define CANT_OPEN_TRANSLATOR -100
#define CANT_OPEN_NARRATOR -200
#define CREATE_PORT_PROBLEMS -300
#define CREATE_IO_PROBLEMS -400
#define CANT_PERFORM_WRITE -500
#define REVISION 1
extern struct Library *OpenLibrary();
#define blitNode bltnode
#define LFTBW 150
#define TOPBW 60
#define TOPGUESS 62
#define LEFTGUESS 98
#define TOPGAD 119
#define FIRSTEDGE 223
#define SWIDTH 20
#define SHEIGHT 15
#define FLAGYES 0x0008
#define FLAGNO 0x0011
#define mskNone 0
#define mskHasMask 1
#define mskHasTransparentColor 2
#define mskLasso 3
#define cmpNone 0
#define cmpByteRun1 1
#define MakeID(a,b,c,d) ( (a)<<24 | (b)<<16 | (c)<<8 | (d) )
#define FORM MakeID('F','O','R','M')
#define LIST MakeID('L','I','S','T')
#define BODY MakeID('B','O','D','Y')
#define BMHD MakeID('B','M','H','D')
#define CMAP MakeID('C','M','A','P')
#define INTUITION_REV 29
#define GRAPHICS_REV 29
#define UGetByte() (*source++)
#define UPutByte(c) (*dest++ = (c))

struct Gadget gad[17];
struct Gadget *gad_ptr1;
struct Window *Window1;
struct IntuiMessage *mesg;
struct NewWindow NewWindow;
struct Menu Menu1,Menu2;
struct MenuItem *item,*next;
struct IntuiText t0,t1,t2,t3,xt0,xt1,about_t0,about_t1,about_t2,about_t3,about_t4,about_t5,about_t6;
struct GfxBase *GfxBase;
struct ViewPort *vp;
struct Image *Image;
struct Image background;
struct IntuitionBase *IntuitionBase;
struct MenuItem m0,m1,m2,m3,x0,x1;
struct Screen *Screen;
struct guessn {
  char number;
  int numpos;
  }   gs[4];
BOOL pal_resp1;
SHORT left,top,picked;
SHORT id,x,y,w,h,d;
USHORT mode,itemnum;
ULONG flags;
ULONG mcode,mclass;
ULONG Seconds,Micros;
UBYTE name2[30];
UBYTE *name;
UBYTE *buffer,*tempbuffer,**psource,**pdest;
UBYTE *filebuffer,*tempfilebuffer,*savebuffer;
UWORD BytePerPlane,TotalBytes,plane,BytePerRow;

int gvoff,hoff,toff,black,white,posse,ic,gad_xpos;
int ret,status,fd,i;

char empty[]="0000";
char pics1[] = "gray_matter";
char answer[] = "0000";
char answer_temp[] = "0000";
char guess[] = "0000";
char guess_temp[]= "0000";
char text1[] = "0123456789";
char wrong[] = "WXYZ";
char wrong2[] = "QRST";
char wrong3[] = "ABCD";
char wrong4[] = "EFGH";

VOID InitMen(),InitMenuItem();
typedef unsigned long ID;
struct Chunk
 {
  ID ckID ;
  long ckSize ;
 } ;
struct Chunk chk;

main()
{
 get_diskimage(pics1);
}
get_diskimage(pic)
{
typedef UBYTE Masking;
typedef UBYTE Compression;
int numcolors;
USHORT tred,tgreen,tblue;
struct BitMapHeader
{
  UWORD w, h;
  WORD x, y;
  UBYTE nPlanes;
  Masking masking;
  Compression compression;
  UBYTE pad1;
  UWORD transparentColor;
  UBYTE xAspect, yAspect;
  WORD pageWidth, pageHeight;
} ;
 struct BitMapHeader bmhd;
 struct ColorRegister
 {
  UBYTE red, green, blue;
 };
struct ColorRegister ColorMap[32];
  long pos;
  fd=open(pic,O_RDONLY);
  if(fd==-1)
  {
    printf("oops...data file 'gray_matter' missing,Sam.\n");
    exit(FALSE);
  }
  status=read(fd,&chk,sizeof(chk)); 
  pos=lseek(fd,4,1);
  status=read(fd,&chk,sizeof(chk));
  status=read(fd,&bmhd,sizeof(bmhd));
  status=read(fd,&chk,sizeof(chk));
  status=read(fd,&ColorMap[0],chk.ckSize);
  numcolors=chk.ckSize/3;
  status=read(fd,&chk,sizeof(chk));
  while(chk.ckID!=BODY)
  {
       pos=lseek(fd,chk.ckSize,1);
       status=read(fd,&chk,sizeof(chk));
       if(status==NULL)
       {
         printf("oops...No picture,Sam.\n");
         exit(FALSE);
       }
  }
  BytePerRow=(((bmhd.w+15) >> 4) << 1);
  BytePerPlane=BytePerRow*bmhd.h;
  TotalBytes=BytePerPlane*(UWORD)bmhd.nPlanes;
  buffer=(UBYTE *)AllocMem(TotalBytes,MEMF_CHIP);
  if(buffer==NULL)
  {
    printf("no memory for buffer;make some room!\n");
    exit(0);
  }
  filebuffer=(UBYTE *)AllocMem(chk.ckSize,MEMF_CHIP);
  if(filebuffer==NULL)
  {
    printf("Hey, Error! There's not enough ram for the file buffer.\n");
    exit(0);
  }
  savebuffer=buffer;
  tempfilebuffer=filebuffer;
  status=read(fd,filebuffer,chk.ckSize);
  pdest=&tempbuffer;
  psource=&tempfilebuffer;
  for(i=0;i<bmhd.h;i++)
  {
     for(plane=0;plane<bmhd.nPlanes;plane++)
     {
        tempbuffer=buffer+(BytePerRow*i)+(BytePerPlane*plane);
        if(bmhd.compression==cmpByteRun1)
        {
          UnPackBits(psource,pdest,BytePerRow);
        }
     else
     {
          GetBits(psource,pdest,BytePerRow);
     }
  }
}
  open_library();
  open_screen();
  gad[1].NextGadget=&gad[2];
  gad[1].LeftEdge=FIRSTEDGE;
  gad[1].TopEdge=TOPGAD;
  gad[1].Width=SWIDTH;
  gad[1].Height=SHEIGHT;
  gad[1].Flags=NULL;
  gad[1].Activation=GADGIMMEDIATE;
  gad[1].GadgetType=BOOLGADGET;
  gad[1].GadgetRender=NULL;
  gad[1].SelectRender=NULL;
  gad[1].GadgetText=NULL;
  gad[1].MutualExclude=NULL;
  gad[1].SpecialInfo=NULL;
  gad[1].GadgetID=01;
  gad[1].UserData=NULL;
  gad[2].NextGadget=&  gad[3];
  gad[2].LeftEdge=FIRSTEDGE+21;
  gad[2].TopEdge=TOPGAD;
  gad[2].Width=SWIDTH;
  gad[2].Height=SHEIGHT;
  gad[2].Flags=NULL;
  gad[2].Activation=GADGIMMEDIATE;
  gad[2].GadgetType=BOOLGADGET;
  gad[2].GadgetRender=NULL;
  gad[2].SelectRender=NULL;
  gad[2].GadgetText=NULL;
  gad[2].MutualExclude=NULL;
  gad[2].SpecialInfo=NULL;
  gad[2].GadgetID=02;
  gad[2].UserData=NULL;
  gad[3].NextGadget=&  gad[4];
  gad[3].LeftEdge=FIRSTEDGE+42;
  gad[3].TopEdge=TOPGAD;
  gad[3].Width=SWIDTH;
  gad[3].Height=SHEIGHT;
  gad[3].Flags=NULL;
  gad[3].Activation=GADGIMMEDIATE;
  gad[3].GadgetType=BOOLGADGET;
  gad[3].GadgetRender=NULL;
  gad[3].SelectRender=NULL;
  gad[3].GadgetText=NULL;
  gad[3].MutualExclude=NULL;
  gad[3].SpecialInfo=NULL;
  gad[3].GadgetID=03;
  gad[3].UserData=NULL;
  gad[4].NextGadget=&  gad[5];
  gad[4].LeftEdge=FIRSTEDGE;
  gad[4].TopEdge=TOPGAD+15;
  gad[4].Width=SWIDTH;
  gad[4].Height=SHEIGHT;
  gad[4].Flags=NULL;
  gad[4].Activation=GADGIMMEDIATE;
  gad[4].GadgetType=BOOLGADGET;
  gad[4].GadgetRender=NULL;
  gad[4].SelectRender=NULL;
  gad[4].GadgetText=NULL;
  gad[4].MutualExclude=NULL;
  gad[4].SpecialInfo=NULL;
  gad[4].GadgetID=04;
  gad[4].UserData=NULL;
  gad[5].NextGadget=&  gad[6];
  gad[5].LeftEdge=244;
  gad[5].TopEdge=134;
  gad[5].Width=SWIDTH;
  gad[5].Height=SHEIGHT;
  gad[5].Flags=NULL;
  gad[5].Activation=GADGIMMEDIATE;
  gad[5].GadgetType=BOOLGADGET;
  gad[5].GadgetRender=NULL;
  gad[5].SelectRender=NULL;
  gad[5].GadgetText=NULL;
  gad[5].MutualExclude=NULL;
  gad[5].SpecialInfo=NULL;
  gad[5].GadgetID=05;
  gad[5].UserData=NULL;
  gad[6].NextGadget=&  gad[7];
  gad[6].LeftEdge=265;
  gad[6].TopEdge=134;
  gad[6].Width=SWIDTH;
  gad[6].Height=SHEIGHT;
  gad[6].Flags=NULL;
  gad[6].Activation=GADGIMMEDIATE;
  gad[6].GadgetType=BOOLGADGET;
  gad[6].GadgetRender=NULL;
  gad[6].SelectRender=NULL;
  gad[6].GadgetText=NULL;
  gad[6].MutualExclude=NULL;
  gad[6].SpecialInfo=NULL;
  gad[6].GadgetID=06;
  gad[6].UserData=NULL;
  gad[7].NextGadget=&  gad[8];
  gad[7].LeftEdge=223;
  gad[7].TopEdge=148;
  gad[7].Width=SWIDTH;
  gad[7].Height=SHEIGHT;
  gad[7].Flags=NULL;
  gad[7].Activation=GADGIMMEDIATE;
  gad[7].GadgetType=BOOLGADGET;
  gad[7].GadgetRender=NULL;
  gad[7].SelectRender=NULL;
  gad[7].GadgetText=NULL;
  gad[7].MutualExclude=NULL;
  gad[7].SpecialInfo=NULL;
  gad[7].GadgetID=07;
  gad[7].UserData=NULL;
  gad[8].NextGadget=&  gad[9];
  gad[8].LeftEdge=244;
  gad[8].TopEdge=148;
  gad[8].Width=SWIDTH;
  gad[8].Height=SHEIGHT;
  gad[8].Flags=NULL;
  gad[8].Activation=GADGIMMEDIATE;
  gad[8].GadgetType=BOOLGADGET;
  gad[8].GadgetRender=NULL;
  gad[8].SelectRender=NULL;
  gad[8].GadgetText=NULL;
  gad[8].MutualExclude=NULL;
  gad[8].SpecialInfo=NULL;
  gad[8].GadgetID=08;
  gad[8].UserData=NULL;
  gad[9].NextGadget=&  gad[0];
  gad[9].LeftEdge=265;
  gad[9].TopEdge=148;
  gad[9].Width=SWIDTH;
  gad[9].Height=SHEIGHT;
  gad[9].Flags=NULL;
  gad[9].Activation=GADGIMMEDIATE;
  gad[9].GadgetType=BOOLGADGET;
  gad[9].GadgetRender=NULL;
  gad[9].SelectRender=NULL;
  gad[9].GadgetText=NULL;
  gad[9].MutualExclude=NULL;
  gad[9].SpecialInfo=NULL;
  gad[9].GadgetID=09;
  gad[9].UserData=NULL;
  gad[0].NextGadget=&  gad[11];
  gad[0].LeftEdge=244;
  gad[0].TopEdge=163;
  gad[0].Width=SWIDTH;
  gad[0].Height=SHEIGHT;
  gad[0].Flags=GADGHNONE;
  gad[0].Activation=GADGIMMEDIATE;
  gad[0].GadgetType=BOOLGADGET;
  gad[0].GadgetRender=NULL;
  gad[0].SelectRender=NULL;
  gad[0].GadgetText=NULL;
  gad[0].MutualExclude=NULL;
  gad[0].SpecialInfo=NULL;
  gad[0].GadgetID=00;
  gad[0].UserData=NULL;
  gad[11].NextGadget=&  gad[12];
  gad[11].LeftEdge=215;
  gad[11].TopEdge=79;
  gad[11].Width=16;
  gad[11].Height=8;
  gad[11].Flags=GADGIMAGE;
  gad[11].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[11].GadgetType=BOOLGADGET;
  gad[11].GadgetRender=(APTR)&g11_image;
  gad[11].SelectRender=(APTR)&g12_image;
  gad[11].GadgetText=NULL;
  gad[11].MutualExclude=NULL;
  gad[11].SpecialInfo=NULL;
  gad[11].GadgetID=11;
  gad[11].UserData=NULL;
  gad[12].NextGadget=&  gad[13];
  gad[12].LeftEdge=232;
  gad[12].TopEdge=79;
  gad[12].Width=18;
  gad[12].Height=8;
  gad[12].Flags=GADGIMAGE;
  gad[12].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[12].GadgetType=BOOLGADGET;
  gad[12].GadgetRender=(APTR)&g12_image;
  gad[12].SelectRender=(APTR)&g12b_image;
  gad[12].GadgetText=NULL;
  gad[12].MutualExclude=NULL;
  gad[12].SpecialInfo=NULL;
  gad[12].GadgetID=12;
  gad[12].UserData=NULL;
  gad[13].NextGadget=&  gad[14];
  gad[13].LeftEdge=251;
  gad[13].TopEdge=79;
  gad[13].Width=18;
  gad[13].Height=8;
  gad[13].Flags=GADGIMAGE;
  gad[13].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[13].GadgetType=BOOLGADGET;
  gad[13].GadgetRender=(APTR)&g13_image;
  gad[13].SelectRender=(APTR)&g13b_image;
  gad[13].GadgetText=NULL;
  gad[13].MutualExclude=NULL;
  gad[13].SpecialInfo=NULL;
  gad[13].GadgetID=13;
  gad[13].UserData=NULL;
  gad[14].NextGadget=&  gad[15];
  gad[14].LeftEdge=270;
  gad[14].TopEdge=79;
  gad[14].Width=18;
  gad[14].Height=8;
  gad[14].Flags=GADGIMAGE;
  gad[14].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[14].GadgetType=BOOLGADGET;
  gad[14].GadgetRender=(APTR)&g14_image;
  gad[14].SelectRender=(APTR)&g14b_image;
  gad[14].GadgetText=NULL;
  gad[14].MutualExclude=NULL;
  gad[14].SpecialInfo=NULL;
  gad[14].GadgetID=14;
  gad[14].UserData=NULL;
  gad[15].NextGadget=&  gad[16];
  gad[15].LeftEdge=297;
  gad[15].TopEdge=74;
  gad[15].Width=13;
  gad[15].Height=41;
  gad[15].Flags=GADGIMAGE;
  gad[15].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[15].GadgetType=BOOLGADGET;
  gad[15].GadgetRender=(APTR)&doneb_image;
  gad[15].SelectRender=(APTR)&done_image;
  gad[15].GadgetText=NULL;
  gad[15].MutualExclude=NULL;
  gad[15].SpecialInfo=NULL;
  gad[15].GadgetID=15;
  gad[15].UserData=NULL;
  gad[16].NextGadget=NULL;
  gad[16].LeftEdge=296;
  gad[16].TopEdge=120;
  gad[16].Width=15;
  gad[16].Height=54;
  gad[16].Flags=GADGIMAGE;
  gad[16].Activation=GADGIMMEDIATE|RELVERIFY|TOGGLESELECT;
  gad[16].GadgetType=BOOLGADGET;
  gad[16].GadgetRender=(APTR)&starta_image;
  gad[16].SelectRender=(APTR)&startb_image;
  gad[16].GadgetText=NULL;
  gad[16].MutualExclude=NULL;
  gad[16].SpecialInfo=NULL;
  gad[16].GadgetID=16;
  gad[16].UserData=NULL;
  gad_xpos=222;
  open_window();
  vp=(struct ViewPort *)ViewPortAddress(Window1);
  for(i=0;i<numcolors;i++)
  {
     tred=(ColorMap[i].red);
     tgreen=(ColorMap[i].green);
     tblue=(ColorMap[i].blue);
     tred>>=4;
     tgreen>>=4;
     tblue>>=4;
     SetRGB4(vp,i,tred,tgreen,tblue);
  }
  background.LeftEdge=0;
  background.TopEdge=0;
  background.Width=bmhd.w;
  background.Height=bmhd.h;
  background.Depth=bmhd.nPlanes;
  background.ImageData=(SHORT *)buffer;
  background.PlanePick=31;
  background.PlaneOnOff=0;
  background.NextImage=NULL;
  Image=&background;
  ShowTitle(Screen,FALSE);
  DrawImage(Window1->RPort,Image,0,0);
  InitMen(&t0,LOWCHECKWIDTH+1,0,"Hide Title");
  mex=0x0E;
  InitMenuItem(&t0,&m0,&m1,5,0,CHECKIT|CHECKED|MENUTOGGLE,mex);
  InitMen(&t1,LOWCHECKWIDTH+1,0,"Show Title");
  mex=0x0D;
  InitMenuItem(&t1,&m1,&m2,5,10,CHECKIT|MENUTOGGLE);
  InitMen(&t2,LOWCHECKWIDTH+1,0,"About");
  mex=0x0B;
  InitMenuItem(&t2,&m2,&m3,5,20,CHECKIT|MENUTOGGLE,mex);
  InitMen(&t3,LOWCHECKWIDTH+1,0,"Quit");
  mex=0x07;
  InitMenuItem(&t3,&m3,NULL,5,30,CHECKIT|MENUTOGGLE,mex);
  Menu1.NextMenu=NULL;
  Menu1.LeftEdge=1;
  Menu1.TopEdge=1;
  Menu1.Width=80;
  Menu1.Height=40;
  Menu1.Flags=MENUENABLED;
  Menu1.MenuName="Options";
  Menu1.FirstItem=&m0;
  SetMenuStrip(Window1,&Menu1,NULL);
  OnGadget(&gad[1],Window1,NULL);
  SetDrMd(Window1->RPort,JAM2);
  SetAPen(Window1->RPort,18);
  SetBPen(Window1->RPort,17);
  Move(Window1->RPort,15,80);
  Text(Window1->RPort,"Correct",7);
  Move(Window1->RPort,13,90);
  Text(Window1->RPort,"Answer:",7);
  SetAPen(Window1->RPort,19);
  SetBPen(Window1->RPort,0);
  speechD();
  rtnCode=Translate("I am the Amiga.",25,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  rtnCode=Translate("I am the Master Brain. Welcome to my little Gayme",90,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  rtnCode=Translate("of logic. You use computers. This should be easy.",90,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  rtnCode=Translate("ha ha ha ha ha ha ha ha ha ha ha ha ha ha",90,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  ReInit();
  GetInput();
}

VOID InitMen(sss,left,top,men2)
struct IntuiText *sss;
UBYTE *men2;
{
  sss->FrontPen=5;
  sss->BackPen=7;
  sss->DrawMode=JAM1;
  sss->LeftEdge=left;
  sss->TopEdge=top;
  sss->ITextFont=NULL;
  sss->IText=men2;
  sss->NextText=NULL;
}

VOID InitMenuItem(name2,item,next,left,top,flags,mex2)
ULONG mex2;
UBYTE *name2;
USHORT left,top;
ULONG flags;
struct MenuItem *item,*next;
{
  item->NextItem=next;
  item->LeftEdge=left;
  item->TopEdge=top;
  item->Width=100;
  item->Height=10;
  item->Flags=CHECKIT|ITEMTEXT|HIGHCOMP|ITEMENABLED|flags;
  item->MutualExclude=mex;
  item->ItemFill=(APTR)name2;
  item->SelectFill=NULL;
  item->Command=NULL;
  item->SubItem=NULL;
}

open_screen(title,detailspen,mode,blockpen)
{
struct NewScreen NewScreen;
  NewScreen.LeftEdge=0;
  NewScreen.TopEdge=0;
  NewScreen.Width=320;
  NewScreen.Height=200;
  NewScreen.Depth=5;
  NewScreen.DetailPen=5;
  NewScreen.BlockPen=3;
  NewScreen.ViewModes=NULL;
  NewScreen.Type=CUSTOMSCREEN;
  NewScreen.Font=NULL;
  NewScreen.DefaultTitle="MasterBrain";
  NewScreen.Gadgets=NULL;
  NewScreen.CustomBitMap=NULL;
  if((Screen=(struct Screen *)OpenScreen(&NewScreen))==NULL)
  {
    printf("oops...Can't open screen,Sam.\n");
    exit(FALSE);
  }
}

open_library()
{
  IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",INTUITION_REV);
  if(IntuitionBase==NULL)
  {
    printf("oops...Cannot load InutitionBase,Sam. Enough memory?\n");
    exit (FALSE);
  }
  GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",GRAPHICS_REV);
  TranslatorBase = OpenLibrary("translator.library",REVISION);
  if(TranslatorBase == NULL)
  {
    printf("oops...Translator.library not in libs directory,Sam.\n");
    exit (FALSE);
  }
}

open_window()
{
  NewWindow.LeftEdge=0;
  NewWindow.TopEdge=0;
  NewWindow.Width=320;
  NewWindow.Height=200;
  NewWindow.DetailPen=20;
  NewWindow.BlockPen=30;
  NewWindow.Title=NULL;
  NewWindow.Flags=SMART_REFRESH|WINDOWCLOSE|BORDERLESS|BACKDROP;
  NewWindow.IDCMPFlags=MOUSEBUTTONS|GADGETUP|MENUPICK|GADGETDOWN;
  NewWindow.Type=CUSTOMSCREEN;
  NewWindow.FirstGadget=&  gad[1];
  NewWindow.CheckMark=NULL;
  NewWindow.Screen=Screen;
  NewWindow.BitMap=NULL;
  NewWindow.MinWidth=0;
  NewWindow.MinHeight=0;
  NewWindow.MaxHeight=200;
  NewWindow.MaxWidth=320;
  if((Window1=(struct Window *)OpenWindow(&NewWindow))==NULL)
  {
    printf("oops...Can't open window,Sam.\n");
    exit (FALSE);
  }
}

GetBits(psource,pdest,dstBytes0)
BYTE **psource, **pdest; WORD dstBytes0;
{
register BYTE *source= *psource;
register BYTE *dest= *pdest;
register WORD dstBytes= dstBytes0;
  while(dstBytes>0)
  {
       UPutByte(UGetByte());
       dstBytes-=1;
  }
  *psource=source; *pdest=dest;
}

UnPackBits(psource,pdest,dstBytes0)
BYTE **psource, **pdest; WORD dstBytes0;
{
  register BYTE *source= *psource;
  register BYTE *dest = *pdest;
  register BYTE n;
  register BYTE c;
  register WORD dstBytes = dstBytes0;
  WORD minus128= -128;
  while(dstBytes > 0)
  {
       n=UGetByte();
       if(n>=0)
       {
         n+=1;
         dstBytes -= n;
       do{
          UPutByte(UGetByte()); 
         }
         while(--n>0);
       }
       else if(n != minus128)
       {
             n= -n + 1;
             dstBytes -=n;
             c=UGetByte();
            do{
              UPutByte(c);
            }
            while(--n >0);
       }
  }
  *psource=source; *pdest=dest;
}


GetInput()
{
  for(;;)
  {
     Wait(1<<Window1->UserPort->mp_SigBit);
     while((mesg=(struct IntuiMessage *) GetMsg(Window1->UserPort))!=NULL)
     {
          mclass=mesg->Class;
          mcode=mesg->Code;
          gad_ptr1=(struct Gadget *)(mesg->IAddress);
          picked=gad_ptr1->GadgetID;
          ReplyMsg(mesg);
          if(mclass == MENUPICK && mcode != MENUNULL)
          {
            itemnum = ITEMNUM(mcode);
            switch(itemnum)
            {
                  case 0:
                      ShowTitle(Screen, FALSE);
                      break;
                  case 1:
                      ShowTitle(Screen, TRUE);
                      break;
                  case 2:
                      About();
                      break;
                  case 3:
                      CloseThings();
                      break;
            }
          }
          if(mclass==GADGETDOWN)
          {
            gad_filter(picked);
          }
     }
  }
}

CloseThings()
{
 int fet,ret;
  if(writeNarrator != 0)
    CloseDevice(writeNarrator);
  if(readNarrator != 0)
    DeleteExtIO(readNarrator,sizeof(struct mouth_rb));
  if(writeNarrator != 0)
    DeleteExtIO(writeNarrator,sizeof(struct narrator_rb));
  if(readport != 0)
    DeletePort(readport);
  if(writeport != 0)
    DeletePort(writeport);
  ClearMenuStrip(Window1);
  status=close(fd);
  CloseWindow(Window1);
  CloseScreen(Screen);
  if(TranslatorBase != 0)
    CloseLibrary(TranslatorBase);
    CloseLibrary(IntuitionBase);
    ret=FreeMem(buffer,TotalBytes);
  if(ret==0)
  {
    printf("buffer dealocation failed\n");
  }
  fet=FreeMem(filebuffer,chk.ckSize);
  if(fet==0)
  {
    printf("filebuffer dealocation failed\n");
  }
  exit(FALSE);
}

Text_hand()
{
  Move(Window1->RPort,gad_xpos,106);
  Text(Window1->RPort,&text1[ic],1);
  guess[posse]=text1[ic];
}

gad_filter(pick1)
SHORT pick1;
{
  switch(pick1)
  {
        case 0:
            ic=0;
            Text_hand();
            break;
        case 1:
            ic=1;
            Text_hand();
            break;
        case 2:
            ic=2;
            Text_hand();
            break;
        case 3:
            ic=3;
            Text_hand();
            break;
        case 4:
            ic=4;
            Text_hand();
            break;
        case 5:
            ic=5;
            Text_hand();
            break;
        case 6:
            ic=6;
            Text_hand();
            break;
        case 7:
            ic=7;
            Text_hand();
            break;
        case 8:
            ic=8;
            Text_hand();
            break;
        case 9:
            ic=9;
            Text_hand();
            break;
        case 11:
            gad_xpos=221;
            posse=0;
            RemoveGadget(Window1,&  gad[11]);
            RemoveGadget(Window1,&  gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[11].Flags |= SELECTED;
            gad[12].Flags &= ~SELECTED;
            gad[13].Flags &= ~SELECTED;
            gad[14].Flags &= ~SELECTED;
            gad[15].Flags &= ~SELECTED;
            WaitTOF();
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            RefreshGadgets(&gad[1],Window1);
            break;
        case 12:
            gad_xpos=237;
            posse=1;
            RemoveGadget(Window1,&gad[11]);
            RemoveGadget(Window1,&gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[12].Flags |= SELECTED;
            gad[11].Flags &= ~SELECTED;
            gad[13].Flags &= ~SELECTED;
            gad[14].Flags &= ~SELECTED;
            gad[15].Flags &= ~SELECTED;
            WaitTOF();
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            RefreshGadgets(&gad[1],Window1);
            break;
        case 13:
            gad_xpos=256;
            posse=2;
            RemoveGadget(Window1,&gad[11]);
            RemoveGadget(Window1,&gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[13].Flags |= SELECTED;
            gad[11].Flags &= ~SELECTED;
            gad[12].Flags &= ~SELECTED;
            gad[14].Flags &= ~SELECTED;
            gad[15].Flags &= ~SELECTED;
            WaitTOF();
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            RefreshGadgets(&gad[1],Window1);
            break;
        case 14:
            gad_xpos=274;
            posse=3;
            RemoveGadget(Window1,&gad[11]);
            RemoveGadget(Window1,&gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[14].Flags |= SELECTED;
            gad[12].Flags &= ~SELECTED;
            gad[13].Flags &= ~SELECTED;
            gad[11].Flags &= ~SELECTED;
            gad[15].Flags &= ~SELECTED;
            WaitTOF();
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            RefreshGadgets(&gad[1],Window1);
            break;
        case 15:
            RemoveGadget(Window1,&gad[11]);
            RemoveGadget(Window1,&gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[15].Flags |= SELECTED;
            gad[11].Flags &= ~SELECTED;
            gad[12].Flags &= ~SELECTED;
            gad[13].Flags &= ~SELECTED;
            gad[14].Flags &= ~SELECTED;
            WaitTOF();
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            RefreshGadgets(&gad[1],Window1);
            gvoff++;
            if(gvoff>8) 
              gvoff=1;
            Move(Window1->RPort,LEFTGUESS,TOPGUESS+12*gvoff);
            Text(Window1->RPort,&guess[0],4);
            CompareB();
            CompareW();
            PrintBW();
            break;
        case 16:
            RemoveGadget(Window1,&gad[16]);
            RemoveGadget(Window1,&gad[11]);
            RemoveGadget(Window1,&gad[12]);
            RemoveGadget(Window1,&gad[13]);
            RemoveGadget(Window1,&gad[14]);
            RemoveGadget(Window1,&gad[15]);
            gad[16].Flags |= SELECTED;
            gad[11].Flags &= ~SELECTED;
            gad[12].Flags &= ~SELECTED;
            gad[13].Flags &= ~SELECTED;
            gad[14].Flags &= ~SELECTED;
            gad[15].Flags &= ~SELECTED;
            AddGadget(Window1,&gad[1]);
            AddGadget(Window1,&gad[2]);
            AddGadget(Window1,&gad[3]);
            AddGadget(Window1,&gad[4]);
            AddGadget(Window1,&gad[5]);
            AddGadget(Window1,&gad[6]);
            AddGadget(Window1,&gad[7]);
            AddGadget(Window1,&gad[8]);
            AddGadget(Window1,&gad[9]);
            AddGadget(Window1,&gad[0]);
            AddGadget(Window1,&gad[11]);
            AddGadget(Window1,&gad[12]);
            AddGadget(Window1,&gad[13]);
            AddGadget(Window1,&gad[14]);
            AddGadget(Window1,&gad[15]);
            AddGadget(Window1,&gad[16]);
            RefreshGadgets(&gad[1],Window1);
            ReInit();
  }
}

CompareB()
{
  int dd,ee;
   for(ee=0;ee<4;ee++)
   {
      guess_temp[ee]=guess[ee];
   }
   ee=0;
   for(ee=0;ee<4;ee++)
   {
      answer_temp[ee]=answer[ee];
   }
   for(dd=0;dd<4;dd++)
   {
      if(guess_temp[dd]==answer_temp[dd])
      {
        black++;
        answer_temp[dd]=wrong[dd];
        guess_temp[dd]=wrong2[dd];
      }
   }
}

CompareW()
{
 int count,iq,ee;
  for(ee=0;ee<4;ee++){
     gs[ee].number=guess_temp[ee];
     gs[ee].numpos=ee;
  }
  for(count=0;count<4;count++)
  {
     iq=0;
     for(iq=0;iq<4;iq++)
     {
        if(gs[count].number==answer_temp[iq]&&gs[count].numpos!=iq)
        {
          gs[count].number=wrong3[count];
          answer_temp[iq]=wrong4[count];
          white++;
        }
     }
  }
}

GetAnswer()
{
 int s,e;
  for(s=0;s<4;s++)
  {
     e=rand()%9;
     answer[s]=text1[e];
  }
}

PrintBW()
{
 int f;
 f=0;
  for(f=0;f<black;f++)
  {
     SetAPen(Window1->RPort,0);
     RectFill(Window1->RPort,LFTBW+8*hoff,TOPBW+8+toff,LFTBW+5+8*hoff,TOPBW+6+8+toff);
     hoff++;
  }
  f=0;
  SetAPen(Window1->RPort,1);
  for(f=0;f<white;f++)
  {
     RectFill(Window1->RPort,LFTBW+8*hoff,TOPBW+8+toff,LFTBW+5+8*hoff,TOPBW+6+8+toff);
     hoff++;
  }
  if(toff!=84)
  {
    toff=toff+12;
  }
   else
   {
      if(black!=4)
      {
        toff=0;
        PrintAns();
        SayLose();
        ShutOffGads();
      }
   }
  if(black==4)
  {
    toff=0;
    PrintAns();
    SayWin();
    ShutOffGads();
  }
  black=0;
  white=0;
  SetAPen(Window1->RPort,19);
  hoff=0;
}

speechD()
{
  writeport = CreatePort(0,0);
  if(writeport == NULL) 
  { 
    error=CREATE_PORT_PROBLEMS; 
    exit(FALSE);
  }
  readport = CreatePort(0,0);
  if(readport == NULL) { 
    error=CREATE_PORT_PROBLEMS; 
    exit(FALSE); 
  }
  writeNarrator = (struct narrator_rb *)CreateExtIO(writeport,sizeof(struct narrator_rb));
  if(writeNarrator == NULL) 
  { 
    error=CREATE_IO_PROBLEMS; 
    exit(FALSE); 
  }
  readNarrator=(struct mouth_rb *)CreateExtIO(readport,sizeof(struct mouth_rb));
  if(readNarrator == NULL) 
  { 
    error=CREATE_IO_PROBLEMS;
    exit(FALSE); 
  }
  writeNarrator->ch_masks = (audChanMasks);
  writeNarrator->nm_masks = sizeof(audChanMasks);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  writeNarrator->mouths = 1;
  writeNarrator->message.io_Command = CMD_WRITE;
  error=OpenDevice("narrator.device",0,writeNarrator,0);
  if(error != 0)
  {
    printf("oops...Narrator device not in devs directory,Sam.\n");
    exit(FALSE);
  }
  readNarrator->voice.message.io_Device=writeNarrator->message.io_Device;
  readNarrator->voice.message.io_Unit=writeNarrator->message.io_Unit;
  readNarrator->width=0;
  readNarrator->height=0;
  readNarrator->voice.message.io_Command=CMD_READ;
  readNarrator->voice.message.io_Error=0;
  writeError = SendIO(writeNarrator);
  if(writeError!=NULL) 
  { 
    error=CANT_PERFORM_WRITE; 
    exit(FALSE); 
  }
  while((readError=readNarrator->voice.message.io_Error)!=ND_NoWrite)
  {
       DoIO(readNarrator);
       DrawMouth(readNarrator->width,readNarrator->height);
  }
}
DrawMouth(w,h)
SHORT w,h;
{
  return(0);
}

int strlen(string)
char *string;
{
 int i,length;
  length = -1;
  for(i=0; i<256; i++)
  {
     if(*string++=='\0')
     {
       length = i+1;
       break;
     };
  }
  return(length);
}

struct IORequest *CreateExtIO(ioReplyPort,size)
struct MsgPort *ioReplyPort;
LONG size;
{
  struct IORequest *ioReq;
  if(ioReplyPort == 0)
    return ((struct IORequest *)0);
    ioReq = (struct IORequest *)AllocMem(size, MEMF_CLEAR | MEMF_PUBLIC);
  if(ioReq == 0)
    return ((struct IORequest *)0);
  ioReq -> io_Message.mn_Node.ln_Type = NT_MESSAGE;
  ioReq -> io_Message.mn_Node.ln_Pri = 0;
  ioReq -> io_Message.mn_ReplyPort = ioReplyPort;
  ioReq -> io_Message.mn_Length = (size - sizeof(struct Message));
  return (ioReq);
}

DeleteExtIO(ioExt,size)
struct IORequest *ioExt;
LONG size;
{
  ioExt -> io_Message.mn_Node.ln_Type = 0xff;
  ioExt -> io_Device = (struct Device *) -1;
  ioExt -> io_Unit = (struct Unit *) -1;
  FreeMem (ioExt, size);
}

SayLose()
{
 int rsay;
  CurrentTime(&Seconds,&Micros);
  srand(Micros);
  rsay=rand()%50;
  rtnCode = Translate("The envelope please. Sorry. The correct number was",95,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  rtnCode = Translate(&answer[0],4,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
   switch(rsay)
   {
        case 1:
            rtnCode=Translate("Better luck next time Doe bee.",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 2:
            rtnCode=Translate("Your answer is as logical as a pickpocket in a nudist colony.",137,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 3:
            rtnCode = Translate("Larry Bud Melmin would be a good match for you.",50,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 4:
            rtnCode=Translate("u lose. Youl never make Stupid Human tricks on Letterman at this rate.",150,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 5:
            rtnCode = Translate("hay,thats o k,we are all boe zoes on this bus.",94,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 6:
            rtnCode = Translate("Your a victim of",30,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            rtnCode = Translate("soycumstance.",30,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            writeNarrator->pitch = MAXPITCH;
            DoIO(writeNarrator);
            writeNarrator->pitch = DEFPITCH;
            break;
        case 7:
            rtnCode = Translate("Yuck. Yuck. Gag me with a spoon.",69,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 8:
            rtnCode = Translate("Sorry about that chief. Give it up!",96,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 9:
            rtnCode=Translate("Well, well. You thought this was easy. huh?",50,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 10:
            rtnCode=Translate("No way ho zay. You struck out. Youve benn zapped. Smoked. Dusted. Blown away. Dun in.",134,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 11:
            rtnCode = Translate("Excuze me. You, yes you. Looking at my screen.",85,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            rtnCode=Translate("Are you sure you are paying attention?",75,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 12:
            rtnCode=Translate("Hay u,would John Wayne lose at this game? Never.",87,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 13:
            rtnCode=Translate("good sir. This one of thoze slings, And Airows of",92,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            rtnCode=Translate("outrajeeus fortune that Bill shake spear warned u about",102,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 14:
            rtnCode=Translate("Its not wether you win or lose,its how well u cheet",102,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 15:
            rtnCode=Translate("You lose. Be sure and be a good sport about it.",82,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 16:
            rtnCode=Translate("Not this time, doabee. You learn from your mistakes.",92,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 17:
            rtnCode=Translate("Well, just think,you have plenty in cawmon with the baltimore orioles.",130,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 18:
            rtnCode=Translate("Humm. Do The words bom out come to mind.",92,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 19:
            rtnCode=Translate("To get the Hint book on the answer, send all your money to Infoa Com. They have most of it anyway.",162,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 20:
            rtnCode=Translate("You lost. Go to your room. Do not pass Go,Do not collect 2 hundred dollars",145,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 21:
            rtnCode=Translate("Sorry about that chief, you flunked.",90,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 22:
            rtnCode=Translate("U Dropped the ball on this one, doabee. No gaytoraid for you.",250,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 23:
            rtnCode=Translate("Your brain has turned to a mass of jello.",50,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 24:
            rtnCode=Translate("By any chance, Do you have two brothers named Daril?",150,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 25:
            rtnCode=Translate("A wise man once said. If at first u doant succeed, forget it, and go watch bullwinkle cartoons.",200,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 26:
            rtnCode=Translate("My advice is . Keep your day job.",50,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 27:
            rtnCode=Translate("When one has lost, it is good to remember. It is better to light one candle than to stub your toa.",250,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 28:
            rtnCode=Translate("You are the Bob uKer of logic games.",70,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 29:
            rtnCode=Translate("You forgot to burn your Atari S T as a sacrificial offering to the gods of logic this morning.",250,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 30:
            rtnCode=Translate("You are now condemned to work for I B M for the rest of your natural life. After that, your on your own.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 31:
            rtnCode=Translate("I forgot to mention. Because you lost, you are now my indentured servant.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 32:
            rtnCode=Translate("I would play taps for you but Jack Tramiel sat on my trumpet.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 33:
            rtnCode=Translate("Well, at least you could go on Donahue and give your story. If you won u could have gone on Oapra",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 34:
            rtnCode=Translate("I'll take the tyetil to your house,now please.",85,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 35:
            rtnCode=Translate("If u lose again u will have to listen to my phoanee voice for seven days strait.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 36:
            rtnCode=Translate("Hey, Burger king is looking for help.",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 37:
            rtnCode=Translate("I am the gordon gecko of games. Winning is good. Greed is good. ben and jerries ice cream is good.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 38:
            rtnCode=Translate("Got u on a called third strike. Yoa.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 39:
            rtnCode=Translate("Rivenge is mine.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 40:
            rtnCode=Translate("There u go. All intelligence is artificial.",85,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 41:
            rtnCode=Translate("take 2 asperin and doant call me.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 42:
            rtnCode=Translate("ha ha ha ha ha ha ha ha ha ha ha ha ha ha. Enuff said.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 43:
            rtnCode=Translate("as W C said, never give a sucker an even             break.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 44:
            rtnCode=Translate("All in all eyed rather be in filidelfia.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 45:
            rtnCode=Translate("go back to bayker street, sherlock.",85,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 46:
            rtnCode=Translate("do u no that u use fewer facial mussles when u win than wen u lose",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 47:
            rtnCode=Translate("say it over and over. losing can be fun. losing can be fun. Losing can be fun.",255,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 48:
            rtnCode=Translate("i would say better luck next time but u probably wont help.",175,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 49:
            rtnCode=Translate("guess what. a simple number game just beat you out.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 50:
            rtnCode=Translate("go wash the dog.",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length=strlen(outputstring);
            DoIO(writeNarrator);
            break;
   }
}

SayWin()
{
 int rsay2;
  CurrentTime(&Seconds,&Micros);
  rtnCode=Translate("We have a winner.",45,outputstring,500);
  writeNarrator->message.io_Data = (APTR)outputstring;
  writeNarrator->message.io_Length = strlen(outputstring);
  DoIO(writeNarrator);
  srand(Micros);
  rsay2=rand()%30;
   switch(rsay2)
   {
        case 0:
            rtnCode=Translate("You guessed it by gum. You got four big ones.",68,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 1:
            rtnCode=Translate("You Win,Cisco. Your mother would be proud. ",83,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 2:
            rtnCode=Translate("mister Spock would be exceedingly proud of your logic",75,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 3:
            rtnCode = Translate("Nice Going,ACE. Wheel let u out of jail now.",85,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 4:
            rtnCode=Translate("as Fill Rizzutoe would say. HOELEY KAOW",65,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 5:
            rtnCode=Translate("not bad. And you own an Amiga ,too. Chalk up 2 for u",99,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 6:
            rtnCode=Translate("hay Ace. Good thinking. Or was it dum luck?",65,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 7:
            rtnCode=Translate("ok you won. Go ahead and stroke your eego.",73,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 8:
            rtnCode=Translate("So u won,big deal. What do u want, a B M W?",76,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 9:
            rtnCode=Translate("All right, mick gilicutty, you did it.",62,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 10:
            rtnCode=Translate("your logic is impecable professor",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 11:
            rtnCode=Translate("You won. Hay. So This izzint Rocket Ranger. But as Letterman says,what did you pay for it?",145,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 12:
            rtnCode=Translate("You made it. You are now in the masterbrain hall of fame",75,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 13:
            rtnCode=Translate("You won. The gipper would be proud, by jorge",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 14:
            rtnCode=Translate("Your a winner, and I hear the fat lady singing.",210,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 15:
            rtnCode=Translate("You win. You are now an official Masterbrain apprentis.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 16:
            rtnCode=Translate("Woa nelly. You have won the Masterbrain M V P award.",175,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 17:
            rtnCode=Translate("You did it,chief.Now on to the masterbrain world series.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 18:
            rtnCode=Translate("Excellent choice. You get 60 brownee points.",95,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 19:
            rtnCode=Translate("I can't beleeve your brainpower. o o pinch me.",190,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 20:
            rtnCode=Translate("Strike up the band.",55,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 21:
            rtnCode=Translate("You win. For now. We are going to test you for steroids.",175,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 22:
            rtnCode=Translate("You beat me. This buds for u.",145,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 23:
            rtnCode=Translate("All right! Amiga. Computer of champeeons.",95,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 24:
            rtnCode=Translate("Jay Miner dreamed of the day you wood win this game. Hurray!.",155,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 25:
            rtnCode=Translate("The Master Brain has been zapped by his lowly apprentis.",145,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 26:
            rtnCode=Translate("You have an excellent brain. say. Do u have any hot tips for the bond market?",165,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 27:
            rtnCode=Translate("You won, but I cant play your national anthem. I am a louwsee singer.",175,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 28:
            rtnCode=Translate("Outstanding. This is better than M T V, esint it.",145,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 29:
            rtnCode=Translate("And before you ask, no, we doant have an audeeo daily double, nore is Vanna here.",175,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
        case 30:
            rtnCode=Translate("Congradulations. Ed mac man will be at your house tummorrow with the check.",195,outputstring,500);
            writeNarrator->message.io_Data = (APTR)outputstring;
            writeNarrator->message.io_Length = strlen(outputstring);
            DoIO(writeNarrator);
            break;
   }
}

ReInit()
{
 int ttoff,btoff,z;
  toff=0;
  ttoff=67;
  btoff=75;
  gvoff=0;
  CurrentTime(&Seconds,&Micros);
  srand(Micros);
  GetAnswer();
  rtnCode = Translate("O k,click on each number,,good luck.",37,outputstring,500);
  writeNarrator->message.io_Data=(APTR)outputstring;
  writeNarrator->message.io_Length=strlen(outputstring);
  DoIO(writeNarrator);
  for(z=0;z<8;z++)
  {
     SetAPen(Window1->RPort,0);
     RectFill(Window1->RPort,92,ttoff,136,btoff);
     SetAPen(Window1->RPort,23);
     RectFill(Window1->RPort,141,ttoff,188,btoff);
     ttoff=ttoff+12;
     btoff=btoff+12;
     if(ttoff==163)
       ttoff=67;
     if(ttoff==171)
       btoff=75;
     }
     z=0;
     for(z=0;z<8;z++)
     {
        SetAPen(Window1->RPort,0);
        RectFill(Window1->RPort,219,98,231,111);
        SetAPen(Window1->RPort,0);
        RectFill(Window1->RPort,235,98,249,111);
        SetAPen(Window1->RPort,0);
        RectFill(Window1->RPort,253,98,267,111);
        SetAPen(Window1->RPort,0);
        RectFill(Window1->RPort,271,98,285,111);
     }
  SetAPen(Window1->RPort,3);
  RectFill(Window1->RPort,26,108,65,118);
  strcpy(&guess,&empty);
  strcpy(&guess_temp,&empty);
  SetAPen(Window1->RPort,19);
  RefreshGadgets(&gad[1],Window1);
}

PrintAns()
{
  SetBPen(Window1->RPort,3);
  SetAPen(Window1->RPort,0);
  Move(Window1->RPort,29,116);
  Text(Window1->RPort,&answer[0],4);
  SetAPen(Window1->RPort,19);
  SetBPen(Window1->RPort,0);
  SetAPen(Window1->RPort,19);
}

ShutOffGads()
{
 int gadi;
  for(gadi=0;gadi<15;gadi++)
  {
     RemoveGadget(Window1,&gad[0+gadi]);
  }
}

TurnOnGads()
{
int gadi;
  for(gadi=0;gadi<15;gadi++)
  {
     AddGadget(Window1,&gad[0+gadi]);
  }
}

About()
{
  about_t0.FrontPen=0;
  about_t0.BackPen=11;
  about_t0.DrawMode=JAM1;
  about_t0.LeftEdge=15;
  about_t0.TopEdge=10;
  about_t0.ITextFont=NULL;
  about_t0.IText=(UBYTE *)"(Freely distributable)";
  about_t0.NextText=&about_t4;
  about_t4.FrontPen=18;
  about_t4.BackPen=11;
  about_t4.DrawMode=JAM1;
  about_t4.LeftEdge=15;
  about_t4.TopEdge=20;
  about_t4.ITextFont=NULL;
  about_t4.IText=(UBYTE *)"Tourmaline Software";
  about_t4.NextText=&about_t5;
  about_t5.FrontPen=18;
  about_t5.BackPen=15;
  about_t5.DrawMode=JAM1;
  about_t5.LeftEdge=15;
  about_t5.TopEdge=30;
  about_t5.ITextFont=NULL;
  about_t5.IText=(UBYTE *)"Dana McPhee";
  about_t5.NextText=&about_t6;
  about_t6.FrontPen=0;
  about_t6.BackPen=15;
  about_t6.DrawMode=JAM1;
  about_t6.LeftEdge=15;
  about_t6.TopEdge=40;
  about_t6.ITextFont=NULL;
  about_t6.IText=(UBYTE *)"Email to IDCMP (617)769-3172";
  about_t6.NextText=NULL;
  about_t1.FrontPen=0;
  about_t1.BackPen=15;
  about_t1.DrawMode=JAM1;
  about_t1.LeftEdge=6;
  about_t1.TopEdge=3;
  about_t1.ITextFont=NULL;
  about_t1.IText=(UBYTE *)"Ying";
  about_t1.NextText=NULL;
  about_t2.FrontPen=0;
  about_t2.BackPen=15;
  about_t2.DrawMode=JAM1;
  about_t2.LeftEdge=6;
  about_t2.TopEdge=3;
  about_t2.ITextFont=NULL;
  about_t2.IText=(UBYTE *)"Yang";
  about_t2.NextText=NULL;
  pal_resp1=AutoRequest(Window1,about_t0,about_t1,about_t2,FLAGYES,FLAGNO,300,85);
  return;
}
