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

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <powerup/ppclib/interface.h>
  6. #include <powerup/gcclib/powerup_protos.h>
  7. #include <powerup/ppcinline/exec.h>
  8.  
  9. #define    LOOP    10
  10.  
  11. char    Buffer[LOOP][256];
  12.  
  13. /* Attention
  14.  * You can share the Caos structure for asynchronus calls because
  15.  * it`s copied to some internal buffer BUT you must be very careful
  16.  * about the data which is touched by the AmigaOS function.
  17.  * In this example Buffer is the problem and each asynchron call
  18.  * is using a different buffer.
  19.  */
  20.  
  21. int    main(void)
  22. {
  23. struct Caos    *MyCaos;
  24. BPTR        MyFile;
  25. ULONG        i;
  26. void        *DOSBase;
  27. void        *SysBase;
  28. int        Length;
  29.  
  30.   MyFile    =    PPCOutput();
  31.   if (MyCaos = (struct Caos*) PPCAllocVec(sizeof(struct Caos),MEMF_PUBLIC|MEMF_CLEAR))
  32.   {
  33.     SysBase    =(void*)    *((ULONG*) 4L);
  34.  
  35.     /* The OpenLibrary() call is defined in the powerup/ppcinline/exec.h
  36.        call.
  37.      */
  38.  
  39.     if (DOSBase=(void*) OpenLibrary("dos.library",0))
  40.     {
  41.       for (i=0;i<LOOP;i++)
  42.       {
  43.         Length            =    PPCsprintf(Buffer[i],
  44.                                                    "Asynchron String %ld\n",
  45.                                                    i);
  46.  
  47.  
  48.         /* Do a simple AmigaOS dos.library/Write */
  49.         MyCaos->caos_Un.Offset        =    -0x30;
  50.         MyCaos->d1            =    (ULONG) MyFile;
  51.         MyCaos->d2            =    (ULONG) Buffer[i];
  52.         MyCaos->d3            =    Length;
  53.         MyCaos->a6            =    (ULONG) DOSBase;
  54.         MyCaos->M68kCacheMode        =    IF_CACHEFLUSHALL | IF_ASYNC;
  55.         MyCaos->PPCCacheMode        =    IF_CACHEFLUSHALL;
  56.         PPCCallOS(MyCaos);
  57.       }
  58.     }
  59.     PPCFreeVec(MyCaos);
  60.   }
  61.   return(0);
  62. }
  63.