home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff588.lza / MandelSquare / Source / PlayAnim / dbf.c next >
C/C++ Source or Header  |  1992-01-04  |  4KB  |  229 lines

  1. /** dbf.c *******************************************************************
  2.  *
  3.  * Intuition integrated doubly buffered display routines.
  4.  *
  5.  * Written by Olaf `Olsen' Barthel, 16-Sep-1991
  6.  *
  7.  ***************************************************************************/
  8.  
  9. #include <graphics/displayinfo.h>
  10. #include <intuition/intuition.h>
  11. #include <hardware/intbits.h>
  12. #include <exec/interrupts.h>
  13. #include <exec/memory.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/exec_protos.h>
  18.  
  19. extern struct BitMap * __regargs     CreateBitMap(BYTE Depth,UWORD Width,UWORD Height);
  20. extern VOID __regargs             DeleteBitMap(struct BitMap *BitMap);
  21.  
  22. STATIC VOID __regargs             make_ytable(WORD width,WORD height);
  23. STATIC LONG __saveds             VBlankServer(VOID);
  24. VOID                     FrameSync(ULONG jiffies);
  25. VOID                     DeleteBuffer(VOID);
  26. BYTE                     CreateBuffer(VOID);
  27. VOID                     SwapBits(VOID);
  28. VOID                     CopyBits(VOID);
  29. VOID                     LoadPalette(UWORD *Palette);
  30.  
  31.     WORD                *ytable;
  32.     struct BitMap            *DrawBitMap;
  33. STATIC    struct BitMap            *BitMap1,*BitMap2,*OtherBitMap,*OrigBitMap;
  34. STATIC    WORD                 table[500];
  35. STATIC    struct Interrupt        *VBlank;
  36. STATIC    ULONG                 Skip;
  37. STATIC    BYTE                 SigBit = -1;
  38. STATIC    BYTE                 Colours;
  39. STATIC    UWORD                 OrigPalette[32];
  40.  
  41. extern    struct Screen            *Screen;
  42. extern    struct Process            *ThisProcess;
  43.  
  44. STATIC VOID __regargs
  45. make_ytable(WORD width,WORD height)
  46. {
  47.     WORD linebytes,*pt,acc;
  48.  
  49.     linebytes    = (((width + 15) >> 4) << 1);
  50.  
  51.     ytable        = &table[0];
  52.     pt        = ytable;
  53.     acc        = 0;
  54.  
  55.     while(--height >= 0)
  56.     {
  57.         *pt++    = acc;
  58.         acc    += linebytes;
  59.     }
  60. }
  61.  
  62. STATIC LONG __saveds
  63. VBlankServer()
  64. {
  65.     STATIC BYTE Sentinel = FALSE;
  66.  
  67.     if(Sentinel && !Skip)
  68.     {
  69.         Signal(ThisProcess,(1 << SigBit));
  70.  
  71.         Sentinel = FALSE;
  72.     }
  73.  
  74.     if(Skip)
  75.     {
  76.         Sentinel = TRUE;
  77.  
  78.         Skip--;
  79.     }
  80.  
  81.     return(0);
  82. }
  83.  
  84. VOID
  85. FrameSetup(ULONG jiffies)
  86. {
  87.     SetSignal(0,1 << SigBit);
  88.  
  89.     Skip = jiffies;
  90. }
  91.  
  92. VOID
  93. FrameSync()
  94. {
  95.     Wait(1 << SigBit);
  96. }
  97.  
  98. VOID
  99. DeleteBuffer()
  100. {
  101.     if(VBlank)
  102.     {
  103.         RemIntServer(INTB_VERTB,VBlank);
  104.  
  105.         FreeMem(VBlank,sizeof(struct Interrupt));
  106.  
  107.         VBlank = NULL;
  108.     }
  109.  
  110.     if(SigBit != -1)
  111.     {
  112.         FreeSignal(SigBit);
  113.  
  114.         SigBit = -1;
  115.     }
  116.  
  117.     if(OrigBitMap)
  118.     {
  119.         UWORD Table[32];
  120.  
  121.         memset(Table,0,sizeof(Table));
  122.  
  123.         LoadRGB4(&Screen -> ViewPort,Table,Colours);
  124.  
  125.         Screen -> ViewPort . RasInfo -> BitMap = OrigBitMap;
  126.  
  127.         MakeScreen(Screen);
  128.         RethinkDisplay();
  129.  
  130.         LoadRGB4(&Screen -> ViewPort,OrigPalette,Colours);
  131.  
  132.         OrigBitMap = NULL;
  133.     }
  134.  
  135.     if(BitMap1)
  136.     {
  137.         DeleteBitMap(BitMap1);
  138.  
  139.         BitMap1 = NULL;
  140.     }
  141.  
  142.     if(BitMap2)
  143.     {
  144.         DeleteBitMap(BitMap2);
  145.  
  146.         BitMap2 = NULL;
  147.     }
  148. }
  149.  
  150. BYTE
  151. CreateBuffer()
  152. {
  153.     WORD i;
  154.  
  155.     if((Colours = (1 << Screen -> RastPort . BitMap -> Depth)) > 32)
  156.         Colours = 32;
  157.  
  158.     for(i = 0 ; i < Colours ; i++)
  159.         OrigPalette[i] = GetRGB4(Screen -> ViewPort. ColorMap,i);
  160.  
  161.     if(!(BitMap1 = CreateBitMap(Screen -> RastPort . BitMap -> Depth,Screen -> Width,Screen -> Height)))
  162.         return(FALSE);
  163.  
  164.     if(!(BitMap2 = CreateBitMap(Screen -> RastPort . BitMap -> Depth,Screen -> Width,Screen -> Height)))
  165.     {
  166.         DeleteBuffer();
  167.  
  168.         return(FALSE);
  169.     }
  170.  
  171.     DrawBitMap    = BitMap1;
  172.     OtherBitMap    = BitMap2;
  173.  
  174.     make_ytable(Screen -> Width,Screen -> Height);
  175.  
  176.     if((SigBit = AllocSignal(-1)) == -1)
  177.     {
  178.         DeleteBuffer();
  179.  
  180.         return(FALSE);
  181.     }
  182.  
  183.     if(!(VBlank = (struct Interrupt *)AllocMem(sizeof(struct Interrupt),MEMF_PUBLIC|MEMF_CLEAR)))
  184.     {
  185.         DeleteBuffer();
  186.  
  187.         return(FALSE);
  188.     }
  189.  
  190.     VBlank -> is_Node . ln_Name    = "FrameSync Interrupt";
  191.     VBlank -> is_Node . ln_Type    = NT_INTERRUPT;
  192.     VBlank -> is_Code        = (APTR)VBlankServer;
  193.  
  194.     Skip = 0;
  195.  
  196.     AddIntServer(INTB_VERTB,VBlank);
  197.  
  198.     OrigBitMap = Screen -> ViewPort . RasInfo -> BitMap;
  199.  
  200.     return(TRUE);
  201. }
  202.  
  203. VOID
  204. SwapBits()
  205. {
  206.     struct BitMap    *Swap;
  207.  
  208.     Screen -> ViewPort . RasInfo -> BitMap = DrawBitMap;
  209.  
  210.     MakeScreen(Screen);
  211.     RethinkDisplay();
  212.  
  213.     Swap        = OtherBitMap;
  214.     OtherBitMap    = DrawBitMap;
  215.     DrawBitMap    = Swap;
  216. }
  217.  
  218. VOID
  219. CopyBits()
  220. {
  221.     CopyMem(OtherBitMap -> Planes[0],DrawBitMap -> Planes[0],OtherBitMap -> BytesPerRow * OtherBitMap -> Rows * OtherBitMap -> Depth);
  222. }
  223.  
  224. VOID
  225. LoadPalette(UWORD *Palette)
  226. {
  227.     LoadRGB4(&Screen -> ViewPort,Palette,Colours);
  228. }
  229.