home *** CD-ROM | disk | FTP | other *** search
- /* Msg6 and Msg6PPC.elf
- *
- * This test program sends 1000 messages to the M68k and
- * shows how long this takes.
- * The Messages are send asynchron and every msg must
- * be replied after another.
- * Each Message has the Body "Text sent by PPC processor\n"
- */
-
- #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/ppclib/tasks.h>
- #include <powerup/gcclib/powerup_protos.h>
-
- #define DEBUG 0
-
- #if DEBUG
- #define D(x) x;
- #else
- #define D(x) ;
- #endif
-
- #define TEXT "Text sent by PPC processor\n"
-
- BPTR MyFile;
-
- struct StartupData
- {
- void *MsgPort;
- ULONG MsgCount;
- };
-
-
- int main(void)
- {
- struct TagItem MyTags[10];
- struct StartupData *StartupData;
- void *ReplyPort;
- void *M68kPort;
- void *PPCMsg;
- void *Body;
- ULONG result;
- ULONG MsgCount;
- ULONG i;
- void **MsgArray;
-
- StartupData =(struct StartupData *) PPCGetTaskAttr(PPCTASKTAG_STARTUP_MSGDATA);
- MsgCount = StartupData->MsgCount;
-
- #if DEBUG
- if (MyFile = PPCOpen("con:0/0/640/200/MessageDemo - PPC output/CLOSE", MODE_NEWFILE))
- {
- #endif
- if (MsgArray=(void**) PPCAllocVec(sizeof(void*) * MsgCount, MEMF_PUBLIC))
- {
- if (M68kPort=StartupData->MsgPort)
- {
- 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,"Create 1000 Messages..."));
-
- for (i=0;i<MsgCount;i++)
- {
- if ((MsgArray[i]=PPCCreateMessage(ReplyPort,
- sizeof(TEXT)))==NULL)
- {
- break;
- }
- }
-
- D(PPCfprintf(MyFile,"done\n"));
-
- if (i>=MsgCount)
- {
- D(PPCfprintf(MyFile,"Sending 1000 Messages..."));
- strcpy(Body, TEXT);
-
- for (i=0;i<MsgCount;i++)
- {
- PPCSendMessage(M68kPort,
- MsgArray[i],
- Body,
- sizeof(TEXT),
- i);
- }
-
- D(PPCfprintf(MyFile,"done\n"));
-
- D(PPCfprintf(MyFile,"Waiting for 1000 Replies..."));
-
- i = 0;
-
- while (i<MsgCount)
- {
- PPCWaitPort(ReplyPort);
- while (i<MsgCount && (PPCMsg=PPCGetMessage(ReplyPort)))
- {
- D(PPCfprintf(MyFile,
- "MsgObject 0x%lx MsgID %ld ReceivedMsg %ld\n",
- PPCMsg,
- PPCGetMessageAttr(PPCMsg, PPCMSGTAG_MSGID),
- i));
-
- i++;
- }
- }
-
- D(PPCfprintf(MyFile,"done\n"));
-
- D(PPCfprintf(MyFile,"Deleting messages...\n"));
-
- for (i=0;i<MsgCount;i++)
- {
- if (MsgArray[i])
- {
- PPCDeleteMessage(MsgArray[i]);
- }
- }
- }
- 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"));
- }
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not get a M68k msgport\n"));
- }
- PPCFreeVec(MsgArray);
- }
- else
- {
- D(PPCfprintf(MyFile,"Could not alloc mem for msg array\n"));
- }
-
- D(PPCfprintf(MyFile,"Closing output\n"));
- #if DEBUG
- PPCClose(MyFile);
- }
- #endif
- }
-
-