home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / R.Mainz / msg9 / Msg9PPC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-03  |  2.9 KB  |  132 lines

  1.  
  2. /*
  3. **
  4. **  $VER: msg9ppc.c 46.1 (3.6.98)
  5. **  Msg9 46.1
  6. **
  7. **  ppc side of Msg9
  8. **
  9. **  Written 1997/1998 by Roland Mainz (gisburn@w-specht.rhein-ruhr.de)
  10. **
  11. */
  12.  
  13. /* amiga includes */
  14. #include <exec/types.h>
  15. #include <exec/nodes.h>
  16. #include <exec/lists.h>
  17. #include <exec/memory.h>
  18. #include <utility/tagitem.h>
  19.  
  20. /* ppc includes */
  21. #include <powerup/ppclib/interface.h>
  22. #include <powerup/ppclib/message.h>
  23. #include <powerup/ppclib/tasks.h>
  24.  
  25. /* ppc prototypes */
  26. #include <powerup/gcclib/powerup_protos.h>
  27.  
  28. /* ANSI C includes */
  29. #include <string.h>
  30.  
  31. /* protject includes */
  32. #include "msg9.h"
  33.  
  34. /******************************************************************************/
  35.  
  36. #if USE_PPC_STDIO
  37. #define printf PPCprintf
  38. #else
  39. BPTR MyFile = NULL;
  40.  
  41. static void printf( char *s ) { PPCWrite( MyFile, s, (ULONG)strlen( s ) ); }
  42. #endif /* USE_PPC_STDIO */
  43.  
  44. /******************************************************************************/
  45.  
  46. /* ppc code entry */
  47. int main( void )
  48. {
  49.     struct StartupData *StartupData;
  50.     ULONG               BodySize;
  51.  
  52.     StartupData = (struct StartupData *)PPCGetTaskAttr( PPCTASKTAG_STARTUP_MSGDATA );
  53.  
  54.     BodySize = StartupData -> BodySize;
  55.  
  56. #if USE_PPC_STDIO == 0
  57.     if( MyFile = PPCOpen( "CON:////MessageDemo 9 - PPC output/CLOSE/AUTO/WAIT/INACTIVE", MODE_NEWFILE ) )
  58. #endif /* USE_PPC_STDIO == 0 */
  59.     {
  60.       APTR PPCPort;
  61.  
  62.       printf( "Creating message port\n" );
  63.  
  64.       if( PPCPort = (APTR)PPCGetTaskAttr( PPCTASKTAG_MSGPORT ) )
  65.       {
  66.         ULONG which = 0UL;
  67.         BOOL  done  = FALSE;
  68.  
  69.         printf( "Waiting for M68k message\n" );
  70.  
  71.         while( !done )
  72.         {
  73.           APTR M68kMsg;
  74.  
  75.           PPCWaitPort( PPCPort );
  76.  
  77.           while( M68kMsg = PPCGetMessage( PPCPort ) )
  78.           {
  79.             ULONG  sum,
  80.                    i;
  81.             ULONG  id     =             PPCGetMessageAttr( M68kMsg, PPCMSGTAG_MSGID       );
  82.             ULONG  MsgLen =             PPCGetMessageAttr( M68kMsg, PPCMSGTAG_DATALENGTH  );
  83.             UBYTE *Body   =    (UBYTE *)PPCGetMessageAttr( M68kMsg, PPCMSGTAG_DATA        );
  84.  
  85.             which++;
  86.  
  87.             /* Calc checksum... */
  88.             for( sum = 0UL, i = 0UL ; i < MsgLen ; i++ )
  89.             {
  90.               sum += Body[ i ];
  91.             }
  92.  
  93.             /* ...and check if the m68k side has the same result. */
  94.             if( sum != id )
  95.             {
  96. #if USE_PPC_STDIO
  97.               printf( "Checksum error %lu\n", which );
  98. #else
  99.               char buffer[ 256 ];
  100.  
  101.               PPCsprintf( buffer, "Checksum error %lu\n", which );
  102.  
  103.               printf( buffer );
  104. #endif /* USE_PPC_STDIO */
  105.             }
  106.  
  107.             if( BodySize != MsgLen )
  108.             {
  109.               done = TRUE;
  110.             }
  111.  
  112.             PPCReplyMessage( M68kMsg );
  113.           }
  114.         }
  115.       }
  116.       else
  117.       {
  118.         printf( "Could not find PPC Task's msgport\n" );
  119.       }
  120.  
  121. #if USE_PPC_STDIO == 0
  122.       printf( "Closing output\n" );
  123.       PPCClose( MyFile );
  124. #endif /* USE_PPC_STDIO == 0 */
  125.     }
  126.  
  127.     return( RETURN_OK );
  128. }
  129.  
  130.  
  131.  
  132.