home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/memory.h>
- #include <utility/tagitem.h>
- #include <powerup/ppclib/interface.h>
- #include <powerup/ppclib/message.h>
- #include <powerup/gcclib/powerup_protos.h>
-
- #define TEXT "Text sent by PPC processor\n"
-
- BPTR MyFile;
-
- #define DEBUG 0
-
- #if DEBUG
- #define D(x) x;
- #else
- #define D(x) ;
- #endif
-
- int main(void)
- {
- struct TagItem MyTags[10];
- void *PPCPort;
- void *ReplyPort;
- void *M68kPort;
- void *PPCMsg;
- void *M68kMsg;
- void *Body;
- ULONG result;
-
- #if DEBUG
- if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
- {
- #endif
- D(PPCfprintf(MyFile,"Creating message port\n"));
- MyTags[0].ti_Tag = PPCPORTTAG_NAME;
- MyTags[0].ti_Data = (ULONG) "PPC port";
- MyTags[1].ti_Tag = TAG_DONE;
- if (PPCPort = PPCCreatePort(MyTags))
- {
-
- D(PPCfprintf(MyFile,"Waiting for M68k message\n"));
-
- PPCWaitPort(PPCPort);
-
- D(PPCfprintf(MyFile,"Getting message\n"));
- if (M68kMsg = PPCGetMessage(PPCPort))
- {
- D(PPCfprintf(MyFile,"Message: %s\n",
- (char*) PPCGetMessageAttr(M68kMsg, PPCMSGTAG_DATA));
- PPCReplyMessage(M68kMsg);
- }
- else
- {
- D(PPCfprintf(MyFile,"Did not get m68k msg\n"));
- }
-
- D(PPCfprintf(MyFile,"Allocating memory for message body\n"));
- if (Body = PPCAllocVec(sizeof(TEXT), MEMF_PUBLIC))
- {
- D(PPCfprintf(MyFile,"Creating reply port\n"));
- MyTags[0].ti_Tag = TAG_DONE;
- if (ReplyPort = PPCCreatePort(MyTags))
- {
- D(PPCfprintf(MyFile,"Creating message\n"));
- if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
- {
- D(PPCfprintf(MyFile,"Obtaining M68k port\n"));
- MyTags[0].ti_Tag = PPCPORTTAG_NAME;
- MyTags[0].ti_Data = (ULONG) "M68k port";
- MyTags[1].ti_Tag = TAG_DONE;
- while (!(M68kPort = PPCObtainPort(MyTags)));
-
- D(PPCfprintf(MyFile,"Sending message\n"));
- strcpy(Body, TEXT);
-
- PPCSendMessage(M68kPort,
- PPCMsg,
- Body,
- sizeof(TEXT),
- 0x87654321);
-
- D(PPCfprintf(MyFile,"Waiting for reply\n"));
- PPCWaitPort(ReplyPort);
-
- D(PPCfprintf(MyFile,"Releasing M68k port\n"));
- PPCReleasePort(M68kPort);
-
- D(PPCfprintf(MyFile,"Deleting message\n"));
- PPCDeleteMessage(PPCMsg);
-
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not create ppc msg\n"));
- }
-
- D(PPCfprintf(MyFile,"Deleting reply port\n"));
- while (PPCDeletePort(ReplyPort) == FALSE);
-
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not create reply port\n"));
- }
-
- D(PPCfprintf(MyFile,"Freeing message body memory\n"));
- PPCFreeVec(Body);
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not alloc mem for msg body\n"));
- }
-
- D(PPCfprintf(MyFile,"Deleting message port\n"));
- while (PPCDeletePort(PPCPort) == FALSE)
- {
- PPCfprintf("PPCDeletePort() failed\n"));
- }
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not create ppc port\n"));
- }
-
- D(PPCfprintf(MyFile,"Closing output\n"));
- #if DEBUG
- PPCClose(MyFile);
- }
- #endif
- }
-
-