home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / dnet / dnet2.3.2 / amiga / suplib / rastport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.4 KB  |  80 lines

  1.  
  2. /*
  3.  *  RASTPORT.C
  4.  */
  5.  
  6. #include <local/typedefs.h>
  7.  
  8. extern struct IntuitionBase *IntuitionBase;
  9.  
  10. int
  11. MakeRastPort(rp, bm, tmprassize, numai)
  12. RP *rp;
  13. BM *bm;
  14. long  tmprassize;
  15. short numai;
  16. {
  17.     if (!IntuitionBase)
  18.     OpenIntuitionLibrary();
  19.  
  20.     InitRastPort(rp);
  21.     if (numai) {
  22.     register char *buf;
  23.     rp->AreaInfo = AllocMem(sizeof(AREAINFO), MEMF_PUBLIC | MEMF_CLEAR);
  24.     if (!rp->AreaInfo)
  25.         goto fail;
  26.     buf = AllocMem(numai * 5, MEMF_PUBLIC|MEMF_CLEAR);
  27.     if (!buf)
  28.         goto fail;
  29.     InitArea(rp->AreaInfo, (short *)buf, numai);
  30.     }
  31.     if (tmprassize) {
  32.     PLANEPTR tmpraster;
  33.     if (tmprassize == -1)
  34.         tmprassize = bm->Rows * bm->BytesPerRow;
  35.     rp->TmpRas = AllocMem(sizeof(TMPRAS), MEMF_PUBLIC | MEMF_CLEAR);
  36.     if (!rp->TmpRas)
  37.         goto fail;
  38.     tmpraster = AllocMem(tmprassize, MEMF_PUBLIC | MEMF_CLEAR);
  39.     if (!tmpraster)
  40.         goto fail;
  41.     InitTmpRas(rp->TmpRas, tmpraster, tmprassize);
  42.     }
  43.     rp->BitMap = bm;
  44.     SetAPen(rp, 1);
  45.     SetDrMd(rp, JAM2);
  46.     return(1);
  47. fail:
  48.     FreeRastPort(rp);
  49.     return(0);
  50. }
  51.  
  52. void
  53. FreeRastPort(rp)
  54. RP *rp;
  55. {
  56.     if (rp) {
  57.     WaitBlit();
  58.     {
  59.         register AREAINFO *ai;
  60.         if (ai = rp->AreaInfo) {
  61.         if (ai->VctrTbl)
  62.             FreeMem(ai->VctrTbl, ai->MaxCount * 5);
  63.         FreeMem(ai, sizeof(AREAINFO));
  64.         rp->AreaInfo = NULL;
  65.         }
  66.     }
  67.     {
  68.         register TMPRAS *tr;
  69.         if (tr = rp->TmpRas) {
  70.         if (tr->RasPtr)
  71.             FreeMem(tr->RasPtr, tr->Size);
  72.         FreeMem(tr, sizeof(TMPRAS));
  73.         }
  74.         rp->TmpRas = NULL;
  75.     }
  76.     rp->BitMap = NULL;
  77.     }
  78. }
  79.  
  80.