home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / cycleII.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  4KB  |  176 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains the functions to manage the task that
  25.  * performs the color cycling.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. /* Cycle Task stuff */
  31. #define CYCLETIME  16384L
  32. #define ACTIVE     0x01
  33.  
  34. extern VOID cycleTask();
  35. char  *cyTaskName = "CycleTask";
  36. struct Task *cyTask;
  37.  
  38. /* Data shared with cycleTask */
  39. CrngChunk       *cyCrngs;
  40. struct ViewPort *cyVport;
  41. int    cyRegs, cyCnt;
  42. BOOL   CycleOn, PrepareToDie;
  43. USHORT cyMap[maxColorReg];
  44. LONG   cyClocks[maxCycles];
  45. LONG   cyRates[maxCycles];
  46.  
  47. extern LONG MainPri;
  48.  
  49. CreateCycle()
  50. {
  51.    extern int Num_vp_Colors;
  52.  
  53.    if (cyTask) {
  54.      KillCycle();
  55.      LoadRGB4(vp, CurPict->RGBs, Num_vp_Colors);
  56.    }
  57.  
  58.    /* Set up cycle task */
  59.  
  60.    initCycle(CurPict, Num_vp_Colors, 4, vp);
  61.  
  62.    cyTask = (struct Task *)CreateTask(cyTaskName,MainPri,cycleTask,4000);
  63.  
  64.    if(!cyTask) {
  65.      DispErrMsg("Can't create cycling task",0);
  66.      return;
  67.    }
  68.    CycleOn = TRUE;
  69. }
  70.  
  71. KillCycle()
  72. {
  73.    if (cyTask) {
  74.       CycleOn = FALSE;
  75.       PrepareToDie = TRUE;
  76.       while(PrepareToDie);
  77.       DeleteTask(cyTask);
  78.       cyTask = NULL;
  79.       LoadRGB4(vp, CurPict->RGBs, Num_vp_Colors);
  80.    }
  81. }
  82.  
  83.  
  84. initCycle(Pict, Regs, Cnts, vp)
  85.   struct Picture *Pict;
  86.   int Regs, Cnts;
  87.   struct ViewPort *vp;
  88. {
  89.    int k;
  90.  
  91.    CycleOn  = FALSE;
  92.    PrepareToDie = FALSE;
  93.    cyCrngs  = Pict->Crngs;
  94.    cyVport  = vp;
  95.    cyRegs   = Regs;
  96.    cyCnt    = Cnts;
  97.  
  98.    for(k=0; k<cyRegs; k++) {
  99.       cyMap[k] = Pict->RGBs[k];
  100.    }
  101.  
  102.    /* Init Rates and Clocks */
  103.    for(k=0; k<cyCnt; k++) {
  104.  
  105.       /* In DPaint CRNG, rate = RNG_NORATE (36) means don't cycle */
  106.  
  107.       if(cyCrngs[k].rate == RNG_NORATE) {
  108.          cyCrngs[k].rate = 0;
  109.          cyCrngs[k].active &= ~ACTIVE;
  110.       }
  111.  
  112.       if((cyCrngs[k].active & ACTIVE)&&(cyCrngs[k].rate)) {
  113.          cyRates[k] = cyCrngs[k].rate;
  114.       } else {
  115.          cyRates[k] = 0;  /* Means don't cycle to my cycleTask */
  116.       }
  117.       cyClocks[k] = 0;
  118.    }
  119. }
  120.  
  121.  
  122. VOID cycleTask()
  123.    {
  124.    int    k, i, j;
  125.    UBYTE  low, high;
  126.    USHORT cyTmp;
  127.    BOOL   Cycled;
  128.  
  129.    geta4();
  130.  
  131.    while (!PrepareToDie) {
  132.       WaitTOF();
  133.  
  134.       if (CycleOn) {
  135.          Cycled = FALSE;
  136.  
  137.          for(k=0; k<cyCnt; k++) {
  138.  
  139.             if(cyCrngs[k].rate)  /* cyRate 0 = inactive */ {
  140.  
  141.                cyClocks[k] += cyCrngs[k].rate;
  142.  
  143.                if(cyClocks[k] >= CYCLETIME) {
  144.  
  145.                   Cycled = TRUE;
  146.                   cyClocks[k] -= CYCLETIME;
  147.                   low = cyCrngs[k].low;
  148.                   high= cyCrngs[k].high;
  149.  
  150.                   if(cyCrngs[k].active & REVERSE) { /* Reverse cycle */
  151.                      cyTmp = cyMap[low];
  152.  
  153.                      for(i=low,j=low+1; i < high; i++,j++) {
  154.                         cyMap[i] = cyMap[j];
  155.                      }
  156.                      cyMap[high] = cyTmp;
  157.                   } else {    /* Forward cycle */
  158.                      cyTmp = cyMap[high];
  159.                      for(i=high,j=high-1; i > low; i--,j--) {
  160.                         cyMap[i] = cyMap[j];
  161.                      }
  162.                      cyMap[low] = cyTmp;
  163.                   }
  164.                }
  165.             }
  166.          }
  167.          if(Cycled) {
  168.             LoadRGB4(cyVport,cyMap,cyRegs);
  169.          }
  170.       }
  171.    }
  172.    PrepareToDie = FALSE;
  173.    while(TRUE);  /* Busy wait to die */
  174. }
  175.  
  176.