home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg2oldPPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-06  |  3.3 KB  |  135 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #include <powerup/gcclib/powerup_protos.h>
  9.  
  10. #define TEXT    "Text sent by PPC processor\n"
  11.  
  12. BPTR    MyFile;
  13.  
  14. #define    DEBUG    0
  15.  
  16. #if DEBUG
  17. #define    D(x)    x;
  18. #else
  19. #define    D(x)    ;
  20. #endif
  21.  
  22. int    main(void)
  23. {
  24. struct TagItem    MyTags[10];
  25. void        *PPCPort;
  26. void        *ReplyPort;
  27. void        *M68kPort;
  28. void        *PPCMsg;
  29. void        *M68kMsg;
  30. void        *Body;
  31. ULONG           result;
  32.  
  33. #if DEBUG
  34.   if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
  35.   {
  36. #endif
  37.     D(PPCfprintf(MyFile,"Creating message port\n"));
  38.     MyTags[0].ti_Tag  = PPCPORTTAG_NAME;
  39.     MyTags[0].ti_Data = (ULONG) "PPC port";
  40.     MyTags[1].ti_Tag  = TAG_DONE;
  41.     if (PPCPort = PPCCreatePort(MyTags))
  42.     {
  43.  
  44.       D(PPCfprintf(MyFile,"Waiting for M68k message\n"));
  45.  
  46.       PPCWaitPort(PPCPort);
  47.  
  48.       D(PPCfprintf(MyFile,"Getting message\n"));
  49.       if (M68kMsg = PPCGetMessage(PPCPort))
  50.       {
  51.         D(PPCfprintf(MyFile,"Message: %s\n",
  52.                      (char*) PPCGetMessageAttr(M68kMsg, PPCMSGTAG_DATA));
  53.         PPCReplyMessage(M68kMsg);
  54.       }
  55.       else
  56.       {
  57.         D(PPCfprintf(MyFile,"Did not get m68k msg\n"));
  58.       }
  59.  
  60.       D(PPCfprintf(MyFile,"Allocating memory for message body\n"));
  61.       if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
  62.       {
  63.         D(PPCfprintf(MyFile,"Creating reply port\n"));
  64.         MyTags[0].ti_Tag = TAG_DONE;
  65.         if (ReplyPort = PPCCreatePort(MyTags))
  66.         {
  67.           D(PPCfprintf(MyFile,"Creating message\n"));
  68.           if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  69.           {
  70.             D(PPCfprintf(MyFile,"Obtaining M68k port\n"));
  71.             MyTags[0].ti_Tag  = PPCPORTTAG_NAME;
  72.             MyTags[0].ti_Data = (ULONG) "M68k port";
  73.             MyTags[1].ti_Tag  = TAG_DONE;
  74.             while (!(M68kPort = PPCObtainPort(MyTags)));
  75.  
  76.             D(PPCfprintf(MyFile,"Sending message\n"));
  77.             strcpy(Body, TEXT);
  78.  
  79.             PPCSendMessage(M68kPort,
  80.                            PPCMsg,
  81.                            Body,
  82.                            sizeof(TEXT),
  83.                            0x87654321);
  84.  
  85.             D(PPCfprintf(MyFile,"Waiting for reply\n"));
  86.             PPCWaitPort(ReplyPort);
  87.  
  88.             D(PPCfprintf(MyFile,"Releasing M68k port\n"));
  89.             PPCReleasePort(M68kPort);
  90.  
  91.             D(PPCfprintf(MyFile,"Deleting message\n"));
  92.             PPCDeleteMessage(PPCMsg);
  93.  
  94.           }
  95.           else
  96.           {
  97.             D(PPCfprintf(MyFile,"Could not create ppc msg\n"));
  98.           }
  99.  
  100.           D(PPCfprintf(MyFile,"Deleting reply port\n"));
  101.           while (PPCDeletePort(ReplyPort) == FALSE);
  102.  
  103.         }
  104.         else
  105.         {
  106.           D(PPCfprintf(MyFile,"Could not create reply port\n"));
  107.         }
  108.  
  109.         D(PPCfprintf(MyFile,"Freeing message body memory\n"));
  110.         PPCFreeVec(Body);
  111.       }
  112.       else
  113.       {
  114.         D(PPCfprintf(MyFile,"Could not alloc mem for msg body\n"));
  115.       }
  116.  
  117.       D(PPCfprintf(MyFile,"Deleting message port\n"));
  118.       while (PPCDeletePort(PPCPort) == FALSE)
  119.       {
  120.         PPCfprintf("PPCDeletePort() failed\n"));
  121.       }
  122.     }
  123.     else
  124.     {
  125.       D(PPCfprintf(MyFile,"Could not create ppc port\n"));
  126.     }
  127.  
  128.     D(PPCfprintf(MyFile,"Closing output\n"));
  129. #if DEBUG
  130.     PPCClose(MyFile);
  131.   }
  132. #endif
  133. }
  134.  
  135.