home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / Devices / other / cycvb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  2.7 KB  |  125 lines

  1. /*
  2.  * cycvb.c --- Dan Silva's DPaint color cycling interrupt code
  3.  *
  4.  *    Use this fragment as an example for interrupt driven color cycling
  5.  *    If compiled with SAS, include flags -v -y on LC2
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/interrupts.h>
  10. #include <graphics/view.h>
  11. #include <iff/compiler.h>
  12.  
  13. #define MAXNCYCS 4
  14. #define NO  FALSE
  15. #define YES TRUE
  16. #define LOCAL static
  17.  
  18. typedef struct {
  19.     SHORT count;
  20.     SHORT rate;
  21.     SHORT flags;
  22.     UBYTE low, high;  /* bounds of range */
  23.     } Range;
  24.  
  25. /* Range flags values */
  26. #define RNG_ACTIVE  1
  27. #define RNG_REVERSE 2
  28. #define RNG_NORATE 36  /* if rate == NORATE, don't cycle */
  29.  
  30. /* cycling frame rates */
  31. #define OnePerTick   16384
  32. #define OnePerSec    OnePerTick/60
  33.  
  34. extern Range  cycles[];
  35. extern BOOL   cycling[];
  36. extern WORD   cycols[];
  37. extern struct ViewPort *vport;
  38. extern SHORT  nColors;
  39.  
  40.  
  41. MyVBlank()  {
  42.    int i,j;
  43.    LOCAL  Range *cyc;
  44.    LOCAL  WORD  temp;
  45.    LOCAL  BOOL  anyChange;
  46.  
  47. #ifdef IS_AZTEC
  48. #asm
  49.        movem.l  a2-a7/d2-d7,-(sp)
  50.        move.l   a1,a4
  51. #endasm
  52. #endif
  53.  
  54.    if (cycling)  {
  55.       anyChange = NO;
  56.       for (i=0; i<MAXNCYCS; i++)  {
  57.          cyc = &cycles[i];
  58.          if ( (cyc->low == cyc->high) ||
  59.               ((cyc->flags&RNG_ACTIVE) == 0) ||
  60.               (cyc->rate == RNG_NORATE) )
  61.                  continue;
  62.  
  63.          cyc->count += cyc->rate;
  64.          if (cyc->count >= OnePerTick)  {
  65.             anyChange = YES;
  66.             cyc->count -= OnePerTick;
  67.  
  68.             if (cyc->flags&RNG_REVERSE)  {
  69.                temp = cycols[cyc->low];
  70.                for (j=cyc->low; j < cyc->high; j++)
  71.                   cycols[j] = cycols[j+1];
  72.                cycols[cyc->low] = temp;
  73.                }
  74.             else  {
  75.                temp = cycols[cyc->high];
  76.                for (j=cyc->high; j > cyc->low; j--)
  77.                   cycols[j] = cycols[j-1];
  78.                cycols[cyc->low] = temp;
  79.                }
  80.             }
  81.          }
  82.       if (anyChange) LoadRGB4(vport,cycols,nColors);
  83.       }
  84.  
  85. #ifdef IS_AZTEC
  86.       ;   /* this is necessary */
  87. #asm
  88.       movem.l  (sp)+,a2-a7/d2-d7
  89. #endasm
  90. #endif
  91.  
  92.    return(0);  /* interrupt routines have to do this */
  93.    }
  94.  
  95.  
  96. /*
  97.  *  Code to install/remove cycling interrupt handler
  98.  */
  99.  
  100. LOCAL char myname[] = "MyVB";  /* Name of interrupt handler */
  101. LOCAL struct Interrupt intServ;
  102.  
  103. typedef void (*VoidFunc)();
  104.  
  105. StartVBlank()  {
  106. #ifdef IS_AZTEC
  107.    intServ.is_Data = GETAZTEC();  /* returns contents of register a4 */
  108. #else
  109.    intServ.is_Data = NULL;
  110. #endif
  111.    intServ.is_Code = (VoidFunc)&MyVBlank;
  112.    intServ.is_Node.ln_Succ = NULL;
  113.    intServ.is_Node.ln_Pred = NULL;
  114.    intServ.is_Node.ln_Type = NT_INTERRUPT;
  115.    intServ.is_Node.ln_Pri  = 0;
  116.    intServ.is_Node.ln_Name = myname;
  117.    AddIntServer(5,&intServ);
  118.    }
  119.  
  120. StopVBlank() { RemIntServer(5,&intServ); }
  121.  
  122. /**/
  123.  
  124.  
  125.