/***



               soundproc.c    M.E.S.   87-12-28

                  a process for multitasking "scales"


***/
#include "soundproc.h"

main()
 {
    register int  howlong;
    register struct MsgPort *gimmemessagePort;
    register char *words;
    register ULONG what;
    register ULONG class;
    register UBYTE type;

    if ( !(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0)))  return;

/*    SysBase = (struct ExecBase *)OpenLibrary("exec.library", 0);

    echo = (int)Output(); */


/*  Allocating memory for the message "t" is done in the parent.
      "sounproc" just shares this memory block temporarily.      */

   if((gimmemessagePort = CreatePort("gimme.my.message",0)) == 0)
      {
         printf("could not create the reply port\n");
         return(0);
      }

   InitIOA(); /* in bonesound.c  */

   makewaves();

   for (;;)
      {
         Wait( 1L << gimmemessagePort->mp_SigBit);
         while( t = (struct test_message *)GetMsg(gimmemessagePort))
            {
               words = t->d.string;
               what = t->d.function;
               howlong = t->d.length;
               class = t->d.flags;
               type = t->d.id;
               t->d.flags = IGOTMESSAGE;
               ReplyMsg(t);

               if (class == TURNOFF)   /* then turn this task off */
                  {
                     printf("So long ......\n");
                     goto cleanup;
                  }

               /* check if we're already making sounds */

               if (class == VERBAGE)  /* actually this is the task */
                  {
                      switch(what)  /* call the function */
                        {
                          case DICEROLL:
                                    Click(howlong);
                                    break;
                          case YAHSOUND:
                                    YahtzeeSound(howlong);
                                    break;
                          case HAPPYSOUND:
                                    Happy(howlong);
                                    break;
                          case BOMBSOUND:
                                    Bomb(howlong);
                                    break;
                          default:
                                    Happy(howlong);
                                    break;
                        }
                  }
            }
      }  /*   end of forever loop */

cleanup:
        printf("for now ......\n");
        FinishProg(0);
        DeletePort(gimmemessagePort);
      /*  return(0); */
}
