home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Resources / System / BoingBag1 / Contributions / Workbench / RexxArpLib3p6 / src / allocrastport.c next >
C/C++ Source or Header  |  1998-06-21  |  2KB  |  103 lines

  1. /**    AllocRastPort.c
  2.   *
  3.   *    Implement the Amiga RasterPort access functions for rexxarplib.library.
  4.   *
  5.   *   AUTHOR/DATE:  W.G.J. Langeveld, November 1987.
  6.   *   ============
  7.   *
  8.   *    CURRENT VERSION:
  9.   *
  10.   *    This version has been converted to SAS C 6.5 format. It has been modified
  11.   *    for modern definition sequences for ANSI compilation. This no longer works
  12.   *    with OS versions prior to 2.04.
  13.   *
  14.   *   AUTHOR/DATE:  Joanne Dow, jdow@bix.com, June 1998.
  15.   *   ============
  16.   *
  17.   **/
  18. #include <functions.h>
  19. #include "ralprotos.h"
  20. #include <exec/types.h>
  21. #include <exec/exec.h>
  22. #include <libraries/dos.h>
  23. #include <intuition/intuition.h>
  24. #include <graphics/gfx.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <devices/timer.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30.  
  31. #define BMSIZE ((long) sizeof(struct BitMap))
  32. #define RPSIZE ((long) sizeof(struct RastPort))
  33.     
  34. struct RastPort *AllocRastPort( int depth, int width, int height )
  35. {
  36.     int i;
  37.     
  38.     struct BitMap *b = NULL;
  39.     struct RastPort *rp = NULL;
  40.     
  41.     b = (struct BitMap *) AllocMem(BMSIZE, MEMF_CLEAR|MEMF_CHIP);
  42.     if (b == NULL)
  43.         return(NULL);
  44.     
  45.     rp = (struct RastPort *) AllocMem(RPSIZE, MEMF_CLEAR);
  46.     if (rp == NULL)
  47.         goto cleanup;
  48.     
  49.     if (width & 0x7)
  50.         width = (width & 0xFFF8) + 8;
  51.     
  52.     InitBitMap(b, (long) depth, (long) width, (long) height);
  53.     for (i = 0; i < depth; i++) 
  54.     {
  55.         b->Planes[i] = (PLANEPTR) AllocRaster((long) width, (long) height);
  56.         if (b->Planes[i] == NULL)
  57.             goto cleanup;
  58.     }
  59.     
  60.     InitRastPort(rp);
  61.     rp->BitMap = b;
  62.     
  63.     return(rp);
  64.     
  65.     cleanup:
  66.     if (b) 
  67.     {
  68.         width = b->BytesPerRow << 3;
  69.         height = b->Rows;
  70.         for (i = 0; i < depth; i++)
  71.         if (b->Planes[i])
  72.             FreeRaster(b->Planes[i], (long) width, (long) height);
  73.         FreeMem(b, BMSIZE);
  74.     }
  75.     if (rp)
  76.         FreeMem(rp, RPSIZE);
  77.     
  78.     return(NULL);
  79. }
  80.  
  81.  
  82. struct RastPort *FreeRastPort( struct RastPort *rp )
  83. {
  84.     int width, height, i;
  85.     struct BitMap *b;
  86.     
  87.     if (rp == NULL)
  88.         return(NULL);
  89.     
  90.     if (b = rp->BitMap) 
  91.     {
  92.         width = b->BytesPerRow << 3;
  93.         height = b->Rows;
  94.         for (i = 0; i < (int) b->Depth; i++)
  95.         if (b->Planes[i])
  96.             FreeRaster(b->Planes[i], (long) width, (long) height);
  97.         FreeMem(b, BMSIZE);
  98.     }
  99.     FreeMem(rp, RPSIZE);
  100.     
  101.     return(NULL);
  102. }
  103.