home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d158 / yachtc3.lha / YachtC3 / src / callsound.c < prev    next >
C/C++ Source or Header  |  1988-10-02  |  4KB  |  169 lines

  1. /*
  2.  
  3.  
  4.             callsound2.c     M.E.Schretlen.   88-01-28
  5.  
  6.  
  7.             Sends messages to message port "gimme.my.message"
  8.  
  9.             (this is the message port for "soundproc" )
  10.  
  11.             Compiled with ye old non-proto Lattice 3.10
  12.  
  13. */
  14. #include "soundproc.h"
  15. #include "libraries/dos.h"
  16. #include "exec/memory.h"
  17. #include "workbench/startup.h"
  18. #include "workbench/workbench.h"
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <time.h>
  22.  
  23. struct MsgPort *crazyPort;
  24. struct MsgPort *mainPort;
  25. extern struct WBStartup *WBenchMsg; /* def in Lattice _main.c */
  26. extern int argc;                    /* def in Lattice _main.c */
  27.  
  28. ULONG what;
  29. UBYTE whatid;
  30.  
  31. #define NOFILE  1
  32. UBYTE nofiles = 0;
  33. extern void getpath();
  34. ULONG IconBase = NULL;
  35. char buffer[256] = "\0";
  36. static char * path = &buffer[0];
  37. char load[256] = "LOADPROC";
  38. char soundproc[256] = "SOUNDPROC";
  39. char command[256] = "";
  40.  
  41. init_sound()
  42. {
  43.    int success;
  44.    long * timeptr = NULL;
  45.    long timein;
  46.  
  47.    /* Find out where we started ( CLI or Workbench ?). */
  48.  
  49.    if ( argc == 0 )          /* then this was started from WB */
  50.       {
  51.          getpath(WBenchMsg->sm_ArgList->wa_Name);
  52.          strins(load,path);
  53.          strins(soundproc,path);
  54.       }
  55.  
  56.    /* check for loadproc & soundprocess in given path  */
  57.  
  58.    if ( (access(load,0) == -1 ))
  59.      {
  60.         nofiles = NOFILE;
  61.         printf("no loadproc on this path\n");
  62.         return;
  63.      }
  64.    if ( (access(soundproc,0) == -1 ))
  65.      {
  66.         nofiles = NOFILE;
  67.         printf("no soundproc on this path\n");
  68.         return;
  69.      }
  70.    strins(command,soundproc);
  71.    strins(command," ");
  72.    strins(command,load);
  73.  
  74.    timein = time(timeptr);
  75.    success = Execute ( command,0,0);
  76.    while (  (crazyPort = (struct MsgPort *)FindPort("gimme.my.message"))  == 0)
  77.       {
  78.          /*  "while" for a half minute then kick out */
  79.  
  80.          if ( (time(timeptr) - timein) > 30 )
  81.            {
  82.              nofiles = NOFILE;
  83.              printf("Where is the sound message port ?\n");
  84.              return;
  85.            }
  86.       }
  87.    t = (struct test_message *)AllocMem(sizeof(*t),(1<<0));
  88.    if(t == 0)
  89.       {
  90.          printf("not enough memory for message!\n");
  91.          exit(20);
  92.       }
  93.    if((mainPort = CreatePort("callingreplyport",0)) == 0)
  94.       {
  95.          printf("could not create the reply port\n");
  96.          FreeMem(t,sizeof(*t));
  97.          exit(20);
  98.       }
  99.  
  100.    t->m.mn_Node.ln_Type = NT_MESSAGE;
  101.    t->m.mn_Length = sizeof(struct data);
  102.    t->m.mn_ReplyPort = mainPort;
  103.    t->d.flags = VERBAGE;
  104.    t->d.string = "The child awakes.\n";
  105.    t->d.function = YAHSOUND;
  106.    t->d.id = 0;
  107.  
  108.    return;
  109. }
  110.  
  111. void do_sound(thisSOUND,length)
  112. ULONG thisSOUND;
  113. int length;
  114. {
  115.        if (nofiles) return;
  116.        if (thisSOUND == NULL)
  117.               {
  118.                 t->d.flags = TURNOFF;
  119.                 t->d.id = (UBYTE)TURNOFF;
  120.               }
  121.        else
  122.               {
  123.                 t->d.flags = VERBAGE;
  124.                 t->d.length = length;
  125.                 t->d.function = thisSOUND;
  126.               }
  127.  
  128.       PutMsg(crazyPort,t);
  129.  
  130.    /* this expects a reply from a PutMsg() to crazyPort before proceeding */
  131.  
  132.       Wait(1L << mainPort -> mp_SigBit);
  133.       while((t = (struct test_message *)GetMsg(mainPort)) != 0)
  134.          {
  135.             what = t->d.flags;
  136.             whatid = t->d.id;
  137.             if ( whatid == TURNOFF )
  138.               {
  139.                 FreeMem(t,sizeof(*t));
  140.                 DeletePort(mainPort);
  141.               }
  142.             return;
  143.          }
  144. }
  145.  
  146.  
  147. void getpath(name_of_icon)
  148. char * name_of_icon;
  149.    {
  150.    struct DiskObject *diskobj;
  151.    char **toolarray;
  152.    char * string;
  153.    extern char * path;
  154.  
  155.    if((IconBase = OpenLibrary("icon.library", 0)))
  156.       {
  157.       diskobj=(struct DiskObject *)GetDiskObject(name_of_icon);
  158.       if(diskobj)
  159.          {
  160.          toolarray = (char **)diskobj->do_ToolTypes;
  161.          string=(char *)FindToolType(toolarray,"PATH");
  162.          strcpy(path,string);
  163.          FreeDiskObject(diskobj);
  164.          }
  165.       CloseLibrary(IconBase);
  166.       }
  167.    return;
  168.    }
  169.