home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Sound / Subspace68k / src / Subspace68k_MS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-04  |  54.3 KB  |  1,566 lines

  1. #define P96 //SuRgEoN :for compatibility - still through cgfx
  2.  
  3.  
  4. #ifdef __PPC__
  5. #define MAXWIDTH  640
  6. #define MAXHEIGHT 480
  7. #else
  8. #define MAXWIDTH  640
  9. #define MAXHEIGHT 480
  10. #endif
  11.  
  12. #define NUMFIELDS 19
  13. #define NUMWAVES 12
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include <math.h>
  20.  
  21. #include <exec/types.h>
  22. #include <exec/libraries.h>
  23. #include <exec/memory.h>
  24. #include <exec/devices.h>
  25. #include <graphics/gfx.h>
  26. #include <graphics/gfxbase.h>
  27. #include <intuition/intuition.h>
  28. #include <cybergraphics/cybergraphics.h>
  29.  
  30. #include <proto/exec.h>
  31. #include <proto/dos.h>
  32. #include <proto/intuition.h>
  33. #include <proto/graphics.h>
  34. #include <proto/cybergraphics.h>
  35. #include <proto/icon.h>
  36. #include <proto/keymap.h>
  37. #include <devices/timer.h>
  38. #include <proto/timer.h>
  39.  
  40. #include <workbench/startup.h>
  41. #include <dos/dostags.h>
  42. //#include <graphics/gfxbase.h>
  43. //#include <cybergraphx/cybergraphics.h>
  44. //#include <libraries/picasso96.h>
  45. //#include <clib/picasso96_protos.h>
  46.  
  47. static int BytesPerRow;
  48. static BYTE *GfxAddr;
  49.  
  50. /*
  51. #ifndef __PPC__
  52. extern void ASM TurboUpdate68k(REG(a0,BYTE *), REG(a1,BYTE *),
  53.                                REG(d4,int), REG(d0,int), REG(d1,int),
  54.                                REG(d2,int), REG(d3,int));
  55. #endif
  56. */
  57.  
  58. #ifdef __SASC
  59. struct Library *PPCLibBase;
  60. #include <PowerUP/PPCLib/tasks.h>
  61. ULONG   PPCCallOS(struct Caos*);
  62. ULONG   PPCSetTaskAttrs(void*, struct TagItem*);
  63.  
  64. #define PPCSetTaskAttrs(TaskObject, Tags)       _PPCSetTaskAttrs(PPC_BASE_NAME, TaskObject, Tags)
  65. static __inline ULONG _PPCSetTaskAttrs(void *PPCLibBase, void*TaskObject, struct TagItem*Tags) {
  66.         struct Caos     MyCaos;
  67.         MyCaos.M68kCacheMode    =       IF_CACHEFLUSHALL;
  68.         MyCaos.PPCCacheMode     =       IF_CACHEFLUSHALL;
  69.         MyCaos.a0               =(ULONG) TaskObject;
  70.         MyCaos.a1               =(ULONG) Tags;
  71.         MyCaos.caos_Un.Offset   =       (-192);
  72.         MyCaos.a6               =(ULONG) PPCLibBase;    
  73.         return((ULONG)PPCCallOS(&MyCaos));
  74. }
  75. #endif
  76.  
  77.  
  78. #include "TrackInfo.h"
  79.  
  80. BOOL PluginInit(int argc, char **argv);
  81. void PluginExit(void);
  82. void PluginLoop(void); //mainloop for viasualization effects
  83. void ShowRequester(char *Text, char *Button);
  84. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri);
  85. void MyDeletePort(struct MsgPort *mp);
  86.  
  87. /***************************************************************************/
  88. /* This is the global variables section. Don't change anything here unless */
  89. /* you know what you're doing!                                             */
  90. /***************************************************************************/
  91.  
  92. BYTE             PluginSignal, InfoSignal, ConfigSignal;
  93. ULONG            PluginMask,   InfoMask,   ConfigMask;
  94. BOOL             Accepted;
  95. struct Process   *PluginTask;
  96. struct MsgPort   *PluginMP;
  97. struct MsgPort   *PluginRP;
  98. struct TrackInfo *tinfo;
  99.  
  100. #ifdef __SASC
  101. struct Library     *TimerBase;
  102. #else
  103.  #ifdef __VBCC__ //SuRgEoN
  104. struct Library      *TimerBase = NULL;
  105.  #else
  106. struct Device      *TimerBase;
  107.  #endif
  108. #endif
  109. struct MsgPort     *TimerMP;
  110. struct timerequest *TimerIO = NULL;
  111. struct EClockVal   ev1;
  112. struct EClockVal   ev2;
  113. BYTE               TimerError = -1;
  114. ULONG              EFreq=0;
  115. ULONG              TimerMask;
  116.  
  117. UWORD   TrackInfoPos = 1;
  118.  
  119. UWORD   *PluginRawL;
  120. UWORD   *PluginRawR;
  121. WORD    *PluginSamples;
  122. UWORD   *SpecRawL;
  123. UWORD   *SpecRawR;
  124. WORD *SampleRaw;
  125.  
  126. struct PluginMessage {
  127.         struct Message   msg;
  128.         ULONG            PluginMask;
  129.         struct Process   *PluginTask;
  130.         UWORD            **SpecRawL;
  131.         UWORD            **SpecRawR;
  132.         UWORD            Accepted;
  133.         UWORD            reserved0;
  134.         ULONG            InfoMask;
  135.         struct TrackInfo **tinfo;
  136.         ULONG            ConfigMask;
  137.         WORD             **SampleRaw;
  138. };
  139.  
  140. BOOL OpenTimer(void);
  141. void CloseTimer(void);
  142. void StartTimer(void);
  143.  
  144. /***************************************************************************/
  145. /* This is the main part. Again, don't change anything here if you haven't */
  146. /* got a very good reason to do so!                                        */
  147. /***************************************************************************/
  148.  
  149. int main(int argc, char **argv) {
  150.         struct PluginMessage *PluginMsg;
  151.         struct PluginMessage *ReplyMsg;
  152.  
  153.  
  154.         /* Allocate all user resources */
  155.         if(PluginInit(argc, argv)) {
  156.                 /* Check if a plugin capable instance of AmigaAMP is running */
  157.                 if(PluginMP=FindPort("AmigaAMP plugin port"))   {
  158.                         /* Allocate some sigbits for receiving signals FROM AmigaAMP */
  159.                         PluginSignal = AllocSignal(-1);
  160.                         ConfigSignal = AllocSignal(-1);
  161.                         InfoSignal   = AllocSignal(-1);
  162.                         PluginTask   = (struct Process *)FindTask(NULL);
  163.  
  164.                         if(PluginSignal != -1 && InfoSignal != -1 && PluginSignal != -1) {
  165.                                 PluginMask = 1L << PluginSignal;
  166.                                 ConfigMask = 1L << ConfigSignal;
  167.                                 InfoMask   = 1L << InfoSignal;
  168.  
  169.                                 /* Allocate a message and reply port for sending messages TO AmigaAMP */
  170.                                 #if defined (__SASC) || defined (__VBCC__) //SuRgEoN
  171. #ifdef __PPC__
  172.                                 PluginMsg=PPCAllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  173. #else
  174.                                 PluginMsg=AllocVec(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR);
  175. #endif
  176.                                 PluginRP=(struct MsgPort*)MyCreatePort(0,0);
  177.                                 #else
  178.                                 PluginMsg=AllocVecPPC(sizeof(struct PluginMessage), MEMF_PUBLIC|MEMF_CLEAR, 0);
  179.  
  180.                                 PluginRP=(struct MsgPort*)CreatePort(0,0);
  181.                                 #endif
  182.  
  183.                                 /* Tell AmigaAMP all the details it needs to know */
  184.                                 PluginMsg->msg.mn_Node.ln_Type = NT_MESSAGE;
  185.                                 PluginMsg->msg.mn_Length       = sizeof(struct PluginMessage);
  186.                                 PluginMsg->msg.mn_ReplyPort    = PluginRP;
  187.                                 PluginMsg->PluginMask          = PluginMask;
  188.                                 PluginMsg->PluginTask          = PluginTask;
  189.                                 PluginMsg->SpecRawL            = &SpecRawL;
  190.                                 PluginMsg->SpecRawR            = &SpecRawR;
  191.                                 PluginMsg->InfoMask            = InfoMask;
  192.                                 PluginMsg->tinfo               = &tinfo;
  193.                                 PluginMsg->ConfigMask          = ConfigMask;
  194.                                 PluginMsg->SampleRaw           = &SampleRaw;
  195.                                 PutMsg(PluginMP, (struct Message *)PluginMsg);
  196.                                 /* Wait for a reply */
  197.                                 WaitPort(PluginRP);
  198.                                 /* Let's see if AmigaAMP accepted our registration attempt */
  199.                                 if(ReplyMsg = (struct PluginMessage *)GetMsg(PluginRP)) Accepted=ReplyMsg->Accepted;
  200.                                 else Accepted=FALSE;
  201.  
  202.                                 if(Accepted) {
  203.                                         /* If it did, start the plugin loop */
  204.                                         //printf("Init ok! - entering plugin loop\n");
  205.                                         PluginLoop();
  206.  
  207.                                         /* Tell AmigaAMP that this plugin is going down */
  208.                                         PluginMsg->PluginMask          = 0;
  209.                                         PluginMsg->PluginTask          = NULL;
  210.                                         PluginMsg->SpecRawL            = NULL;
  211.                                         PluginMsg->SpecRawR            = NULL;
  212.                                         PluginMsg->ConfigMask          = 0;
  213.                                         PluginMsg->InfoMask            = 0;
  214.                                         PluginMsg->tinfo               = NULL;
  215.                                         PluginMsg->SampleRaw           = NULL;
  216.                                         PutMsg(PluginMP, (struct Message *)PluginMsg);
  217.                                         /* Wait for confirmation before going on! */
  218.                                         WaitPort(PluginRP);
  219.                                         GetMsg(PluginRP);
  220.                                         /* Now that AmigaAMP knows that we're gone, we can quit */
  221.                                 }
  222.                                 else {
  223.                                         /* If AmigaAMP didn't accept us, tell the user about it */
  224.                                         ShowRequester("Plugin rejected by AmigaAMP!\nPerhaps there's another one running.", "Abort");
  225.                                 }
  226.  
  227.                                 /* Free all resources */
  228.                                 #ifdef __SASC
  229.  
  230.                                         PPCFreeVec(PluginMsg);
  231.                                         MyDeletePort(PluginRP);
  232.                                 #else
  233.                                         #ifndef PPC__ //SuRgEoN
  234.                                         FreeVec(PluginMsg);
  235.                                         DeletePort(PluginRP);
  236.                                         #else
  237.                                         FreeVecPPC(PluginMsg);
  238.                                         DeletePort(PluginRP);
  239.                                         #endif
  240.                                 #endif
  241.                         }
  242.                         else {
  243.                                 ShowRequester("Signal allocation failure!", "Abort");
  244.                         }
  245.                         if(PluginSignal != -1) FreeSignal(PluginSignal);
  246.                         if(ConfigSignal != -1) FreeSignal(ConfigSignal);
  247.                         if(InfoSignal   != -1) FreeSignal(InfoSignal);
  248.                 }
  249.                 else {
  250.                         ShowRequester("Could not find message port!\nAmigaAMP probably not running.", "Abort");
  251.                 }
  252.         }
  253.         else {
  254.                 ShowRequester("Plugin initialisation failed!", "Ok");
  255.         }
  256.         /* Free all user resources */
  257.         PluginExit();
  258. }
  259.  
  260. /*****************************************************************************/
  261. /* Ok, now for the individual plugin sourcecode. Everything below should be  */
  262. /* changed to your needs.                                                    */
  263. /* Just like before, we start with the global variables section              */
  264. /*****************************************************************************/
  265.  
  266. void InitWave(UBYTE WaveNum, ULONG BufNum);
  267. void CalcWave(UBYTE WaveNum, ULONG BufNum);
  268. void DrawWave(LONG *WaveX, LONG *WaveY, ULONG Width, ULONG Height, UBYTE WaveNum, ULONG BufNum);
  269.  
  270. void InitField(LONG *Zoom, ULONG Width, ULONG Height);
  271. void PrepareConstants(UBYTE FieldNum);
  272. void CalcLine(LONG *Zoom, ULONG Width, ULONG Height, UBYTE FieldNum);
  273. void MakeCMap(void);
  274. void Blur(UBYTE *PixelC, UBYTE *PixelD);
  275. void ReColor(void);
  276. void MakeTitle(void);
  277. float rnd(float max);
  278. float sgn(float val);
  279.  
  280. const char VersionString[]="\0$VER: Subspace68k 1.0 (14.03.01)";
  281. const char Line1[]="Subspace";
  282. const char Line2[]="by Thomas Wenzel";
  283.  
  284. #define PRECISION PRECISION_EXACT
  285.  
  286. struct IntuitionBase *IntuitionBase = NULL;
  287. struct GfxBase *GfxBase      = NULL;
  288. struct Library *IconBase     = NULL;
  289. struct Library *KeymapBase   = NULL;
  290. struct Library *AslBase      = NULL;
  291. struct Library *GadToolsBase = NULL;
  292. struct Library *CyberGfxBase = NULL;
  293. struct Library *P96Base = NULL;
  294. struct Screen  *PluginScreen = NULL;
  295. struct Window  *PluginWin    = NULL;
  296. struct RastPort *rp;
  297. struct ViewPort *vp;
  298.  
  299.  
  300. struct EClockVal ev1;
  301. struct EClockVal ev2;
  302.  
  303.  
  304. ULONG ModeID;
  305. ULONG WinMask;
  306.  
  307. UBYTE *PixelD;
  308. UBYTE *PixelC;
  309. ULONG *Colour;
  310.  
  311. UWORD *EmptyPointer;
  312.  
  313. char InfoLine[256];
  314.  
  315. LONG Zoom[MAXWIDTH*MAXHEIGHT];
  316. LONG Zoom2[MAXWIDTH*MAXHEIGHT];
  317. LONG WaveX[MAXWIDTH*2];
  318. LONG WaveY[MAXWIDTH*2];
  319. LONG WaveX2[MAXWIDTH*2];
  320. LONG WaveY2[MAXWIDTH*2];
  321.  
  322. ULONG MidR[4], MidG[4], MidB[4];
  323. ULONG DisplayFPS;
  324. ULONG DisplayTi;
  325. ULONG EffectLock;
  326. ULONG ShowWave;
  327. ULONG LimitFPS;
  328. #ifdef __PPC__
  329. ULONG ScreenSize = 100;
  330. #else
  331. ULONG ScreenSize = 80;
  332. #endif
  333. #ifdef PPC
  334. ULONG Width      = 320;
  335. ULONG Height     = 240;
  336. ULONG HalfHeight = 120;
  337. #else
  338. ULONG Width      = 272; //240*112    60, 256, 170
  339. ULONG Height     = 180; //120 with ScreenSize 80!
  340. ULONG HalfHeight = 100;
  341. #endif
  342. #ifndef __PPC__
  343. ULONG Woffset     = 24;// 32 for width 256
  344. #else
  345. ULONG Woffset     = 0;
  346. #endif
  347.  
  348. ULONG Cutoff     = 1;
  349. ULONG InfoCount;
  350. ULONG FrameCountLow;
  351. ULONG FrameCountHigh;
  352. ULONG FrameCountWave;
  353. ULONG FrameCountField;
  354. ULONG TimeWave;
  355. ULONG DestWaveNum;
  356. ULONG DestWaveBuffer;
  357. float WaveMorph;
  358. ULONG MidRdst[3], MidGdst[3], MidBdst[3];
  359. ULONG LineToCalc;
  360. UBYTE FieldToCalc;
  361. UBYTE WaveToCalc, WaveToCalc0, WaveToCalc1;
  362. UBYTE PrevField;
  363.  
  364. /****************************************************************************/
  365. /* This function will be called once when the plugin is started. You should */
  366. /* allocate all needed resources here. Return TRUE if all went well.        */
  367. /****************************************************************************/
  368.  
  369. BOOL PluginInit(int argc, char **argv) {
  370.         long i,xs,ys,xd,yd,ysp,ydp;
  371.         float xf,yf;
  372.         UBYTE **ttypes = 0; //VBCC
  373.         char *str;
  374.         struct DiskObject *IconObj = NULL; //VBCC
  375.         struct WBStartup  *WBStart = NULL; //VBCC
  376.         #ifdef __SASC
  377.         void *ThisTask;
  378.         #else
  379.         struct TaskPPC *ThisTask;
  380.         #endif
  381.         WORD Length;
  382.  
  383.   char *module = "CGfx_Init: ";
  384.  
  385. #ifdef __PPC__
  386.         struct TagItem ModeIDtags[] = {
  387.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 240, TAG_DONE};
  388. #else
  389. /*
  390.         struct TagItem ModeIDtags[] = {
  391.                 CYBRBIDTG_Depth, 8, CYBRBIDTG_NominalWidth, 320, CYBRBIDTG_NominalHeight, 200, TAG_DONE};
  392. */
  393. /*
  394.         struct TagItem ModeIDtags[] = {CYBRMREQ_MinWidth, 320,  CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxHeight, 240, TAG_DONE};
  395. */
  396.  
  397.   int DispID, ScrWidth, ScrHeight;
  398.   static short ColorModel[] = {PIXFMT_LUT8,-1};
  399.   struct TagItem CyberModeTags[] =
  400.   {
  401.    CYBRMREQ_MinWidth, 320, CYBRMREQ_MinHeight, 200, CYBRMREQ_MaxWidth, 320, CYBRMREQ_MaxHeight, 240, CYBRMREQ_CModelArray,(ULONG)ColorModel, TAG_DONE,0
  402.   };
  403.  
  404.  
  405. #endif
  406.         AslBase=OpenLibrary("asl.library", 0);
  407.         if(!AslBase) {
  408.                 ShowRequester("Can't open asl.library!", "Abort");
  409.                 return(FALSE);
  410.         }
  411.  
  412.         IconBase=OpenLibrary("icon.library", 0);
  413.         if(!IconBase) {
  414.                 ShowRequester("Can't open icon.library!", "Abort");
  415.                 return(FALSE);
  416.         }
  417.  
  418.         KeymapBase=OpenLibrary("keymap.library", 0);
  419.         if(!KeymapBase) {
  420.                 ShowRequester("Can't open keymap.library!", "Abort");
  421.                 return(FALSE);
  422.         }
  423.  
  424.         IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 0);
  425.         if(!IntuitionBase) {
  426.                 ShowRequester("Can't open intuition.library!", "Abort");
  427.                 return(FALSE);
  428.         }
  429.  
  430.         GadToolsBase=OpenLibrary("gadtools.library", 0);
  431.         if(!GadToolsBase) {
  432.                 ShowRequester("Can't open gadtools.library!", "Abort");
  433.                 return(FALSE);
  434.         }
  435.  
  436.         if(!(GfxBase= (struct GfxBase*) OpenLibrary("graphics.library", 0)))
  437.        {
  438.                 ShowRequester("Can't open graphics.library!", "Abort");
  439.                 return(FALSE);
  440.         }
  441.  
  442.         if(GfxBase->LibNode.lib_Version < 39) {
  443.                 ShowRequester("This plugin requires AmigaOS 3.0 or greater!", "Abort");
  444.                 return(FALSE);
  445.         }
  446.         if (!(CyberGfxBase = (struct Library *) OpenLibrary("cybergraphics.library", 0)))
  447.        {
  448.                 ShowRequester("This plugin requires CyberGraphX v3 or higher!", "Abort");
  449.                 return(FALSE);
  450.         }
  451.  
  452.       P96Base = (struct Library *) OpenLibrary("Picasso96API.library",0);
  453.         if(!P96Base) {
  454.                 ShowRequester("This plugin requires Picasso96", "Abort");
  455.                 return(FALSE);
  456.         }
  457.  
  458.         #ifdef __SASC
  459.                 /* Increase the priority of the 68k mirror task */
  460.                 SetTaskPri(FindTask(NULL), 15);
  461.                 /* Increase our own priority (if it only would work...) */
  462.                 PPCSetTaskAttr(PPCTASKTAG_PRIORITY, 15);
  463.         #else
  464.                 #ifdef __VBCC__
  465.         //              SetTaskPri(FindTask(NULL), 15);
  466.                 #else
  467.                 /* Increase our own priority */
  468.                 ThisTask = FindTaskPPC(NULL);
  469.                 SetNiceValue(ThisTask, -15);
  470.                 #endif
  471.         #endif
  472.  
  473.         WBStart=(struct WBStartup *)argv;
  474.  
  475. // if(argc==0) printf("IconName: %s\n", WBStart->sm_ArgList[0].wa_Name);
  476.  
  477.         if(argc==0) IconObj=GetDiskObject(WBStart->sm_ArgList[0].wa_Name);
  478.         else        IconObj=GetDiskObject(argv[0]);
  479.  
  480.         LimitFPS = 999;
  481.  
  482.         if(IconObj) {
  483.                 if(str=FindToolType(IconObj->do_ToolTypes,"MAXFPS"))
  484.                 {
  485.                         LimitFPS = atol(str);
  486.                 }
  487.  
  488.                 if(str=FindToolType(IconObj->do_ToolTypes,"RESOLUTION"))
  489.                 {
  490.                         if(stricmp(str,"high") == 0) {
  491.                                 Width      = 640;
  492.                                 Height     = 480;
  493.                                 ScreenSize = 66;
  494.                         }
  495.                         else {
  496. #ifdef __PPC__
  497.                                 Width      = 320;
  498.                                 Height     = 240;
  499.                                 ScreenSize = 100;
  500. #else
  501.                                 Width      = 272;
  502.                                 Height     = 180;
  503.                                 ScreenSize = 80;
  504. #endif
  505.  
  506.                         }
  507.                 }
  508.  
  509.                 if(str=FindToolType(IconObj->do_ToolTypes,"SCREENSIZE"))
  510.                 {
  511.                         ScreenSize = atol(str);
  512.                 }
  513.         FreeDiskObject(IconObj);
  514.         }
  515.  
  516.         if(ttypes=(UBYTE**)ArgArrayInit(argc, argv)) {
  517.                 str=(char*)ArgString(ttypes, "MAXFPS", "0");
  518.                 LimitFPS = atol(str);
  519.  
  520.                 str=(char*)ArgString(ttypes, "RESOLUTION", "low");
  521.                 if(stricmp(str,"high") == 0) {
  522.                         Width      = 640;
  523.                         Height     = 480;
  524.                         ScreenSize = 66;
  525.                         ShowWave   = 1;
  526.                 }
  527.                 else {
  528. #ifdef __PPC__
  529.                         Width      = 320;
  530.                         Height     = 240;
  531.                         ScreenSize = 100;
  532. #else
  533.                         Width      = 272; //240
  534.                         Height     = 180; //190
  535.                         ScreenSize = 80;//60
  536. #endif
  537.                         ShowWave   = 0;
  538.                 }
  539.  
  540.                 if(str=(char*)ArgString(ttypes, "SCREENSIZE", NULL)) {
  541.                         ScreenSize = atol(str);
  542.                 }
  543.  
  544.                 ArgArrayDone();
  545.         }
  546. #ifndef PPC
  547.         if(LimitFPS == 0)  LimitFPS = 999;
  548.         if(LimitFPS > 999) LimitFPS = 999;
  549. #else
  550.     LimitFPS = 10;
  551. #endif
  552.         if(ScreenSize <  25) ScreenSize =  25;
  553.         if(ScreenSize > 100) ScreenSize = 100;
  554.  
  555.         Cutoff = Height * (100-ScreenSize) / 200;
  556.         if(Cutoff <   1) Cutoff =   1;
  557.         if(Cutoff > 200) Cutoff = 200;
  558.  
  559. //        ModeIDtags[1].ti_Data = Width;
  560. //        ModeIDtags[2].ti_Data = Height;
  561. //        CyberModeTags[1].ti_Data = Width;
  562. //        CyberModeTags[2].ti_Data = Height;
  563.  
  564.         HalfHeight = Height/2;
  565.  
  566.         #if defined (__SASC) || defined (__VBCC__)
  567.                 #ifdef __PPC__
  568.                 PixelD       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  569.                 PixelC       = PPCAllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  570.                 Colour       = PPCAllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  571.                 EmptyPointer = PPCAllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  572.                 #else //68k
  573.                 PixelD       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  574.                 PixelC       = AllocVec(Width*Height, MEMF_PUBLIC|MEMF_CLEAR);
  575.                 Colour       = AllocVec(770*4,        MEMF_PUBLIC|MEMF_CLEAR);
  576.                 EmptyPointer = AllocVec(512,          MEMF_CHIP|MEMF_CLEAR);
  577.                 #endif
  578.         #else
  579.                 PixelD       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  580.                 PixelC       = AllocVecPPC(Width*Height, MEMF_PUBLIC|MEMF_CLEAR, 0);
  581.                 Colour       = AllocVecPPC(770*4,        MEMF_PUBLIC|MEMF_CLEAR, 0);
  582.                 EmptyPointer = AllocVecPPC(512,          MEMF_CHIP|MEMF_CLEAR,   0);
  583.         #endif
  584.  
  585.         OpenTimer();
  586.  
  587.         if(PixelD==NULL || PixelC==NULL) {
  588.                 ShowRequester("Out of memory for graphics buffers!", "Abort");
  589.                 return(FALSE);
  590.         }
  591.  
  592.         srand(time(NULL));
  593.  
  594.         MidR[0] = 230;
  595.         MidG[0] = 230;
  596.         MidB[0] = 230;
  597.  
  598.         MidR[1] = 86;
  599.         MidG[1] = 86;
  600.         MidB[1] = 170;
  601.  
  602.         MidR[2] = 25;
  603.         MidG[2] = 25;
  604.         MidB[2] = 100;
  605.  
  606.         MidR[3] = 0;
  607.         MidG[3] = 0;
  608.         MidB[3] = 0;
  609.  
  610.         MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  611.         MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  612.         MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  613.  
  614.         MidRdst[1] = (UBYTE)(rand()>>25) + 96;
  615.         MidGdst[1] = (UBYTE)(rand()>>25) + 96;
  616.         MidBdst[1] = (UBYTE)(rand()>>25) + 96;
  617.  
  618.         MidRdst[2] = (UBYTE)(rand()>>25) + 64;
  619.         MidGdst[2] = (UBYTE)(rand()>>25) + 64;
  620.         MidBdst[2] = (UBYTE)(rand()>>25) + 64;
  621.  
  622.         DisplayFPS      = 0;
  623.         DisplayTi       = 1;
  624.         EffectLock      = 0;
  625.         InfoCount       = 0;
  626.         FrameCountLow   = 0;
  627.         FrameCountHigh  = 0;
  628.         FrameCountWave  = 0;
  629.         FrameCountField = 0;
  630.         TimeWave        = 0;
  631.         DestWaveNum     = 1;
  632.         DestWaveBuffer  = 1;
  633.         WaveMorph       = 0.0;
  634.         LineToCalc      = 0;
  635.         WaveToCalc      = 0;
  636.         WaveToCalc0     = 0;
  637.  
  638. FieldToCalc=16;
  639. WaveToCalc1=5;
  640.  
  641. //        FieldToCalc     = (UBYTE)(rand() % NUMFIELDS);
  642. //        WaveToCalc1     = (UBYTE)(rand() % NUMWAVES);
  643.  
  644. //      FieldToCalc   = 0; //10=endblur;16=radial;2=tunnel
  645. //      WaveToCalc1   = 1;
  646. //1=tunnel;2=lines;3=radar;4=flower;5=solsweep;6=xx;7=chaoticlines;8=circwaves;9=occludinglines;10=quad;11=;
  647. //      FieldToCalc   = NUMFIELDS-1;
  648. //      WaveToCalc1   = NUMWAVES-1;
  649.  
  650.  
  651.         PrepareConstants(FieldToCalc);
  652.  
  653.         MakeCMap();
  654.  
  655. #ifdef P96
  656. //      ModeID=CModeRequestTagList(NULL, ModeIDtags);
  657. if (!(DispID = CModeRequestTagList(NULL,CyberModeTags)))
  658. {
  659.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  660.                 return(FALSE);
  661. };
  662.  
  663. //        ModeID=p96RequestModeIDTagList(ModeIDtags);
  664. #else
  665.         ModeID=BestCModeIDTagList(NULL, ModeIDtags);
  666. #endif
  667. /*
  668.         if(ModeID == INVALID_ID) {
  669.                 ShowRequester("Could not find suitable screen mode!", "Abort");
  670.                 return(FALSE);
  671.         }
  672. */        
  673. /*
  674.         PluginScreen=OpenScreenTags(NULL, SA_DisplayID, ModeID, SA_Depth, 8, SA_Width, Width, SA_Height, Height, SA_SharePens, TRUE, SA_ShowTitle, FALSE, SA_Quiet, TRUE, TAG_DONE);
  675. */
  676.   ScrWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,DispID);
  677.   ScrHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,DispID);
  678.  
  679. PluginScreen = OpenScreenTags(NULL,
  680.                                      SA_Quiet,TRUE,
  681.                                      SA_Width,ScrWidth,
  682.                                      SA_Height,ScrHeight,
  683.                                      SA_Depth,8,
  684.                                      SA_DisplayID,DispID,
  685.                                      TAG_DONE);
  686.  
  687.   BytesPerRow = GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_XMOD);
  688.   GfxAddr = (BYTE *)GetCyberMapAttr(PluginScreen->RastPort.BitMap,CYBRMATTR_DISPADR);
  689.  
  690.         if(PluginScreen == NULL) {
  691.                 ShowRequester("Could not open screen!", "Abort");
  692.                 return(FALSE);
  693.         }
  694.  
  695.         rp = &PluginScreen->RastPort;
  696.         vp = &PluginScreen->ViewPort;
  697.  
  698.  
  699.         LoadRGB32(vp, Colour);
  700.  
  701.         PluginWin=OpenWindowTags(NULL, WA_CustomScreen, (ULONG)PluginScreen,
  702.                                        WA_Left,         0,
  703.                                        WA_Top,          0,
  704.                                        WA_Width,        Width,
  705.                                        WA_Height,       Height,
  706.                                        WA_SizeGadget,   FALSE,
  707.                                        WA_DragBar,      FALSE,
  708.                                        WA_DepthGadget,  FALSE,
  709.                                        WA_CloseGadget,  FALSE,
  710.                                        WA_Backdrop,     TRUE,
  711.                                        WA_Borderless,   TRUE,
  712.                                        WA_Activate,     TRUE,
  713.                                        WA_AutoAdjust,   TRUE,  // Just to be sure :-)
  714.                                        WA_IDCMP,        IDCMP_RAWKEY | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
  715.                                        TAG_DONE);
  716.         if(PluginWin == NULL) {
  717.                 ShowRequester("Could not open window!", "Abort");
  718.                 return(FALSE);
  719.         }
  720.  
  721.         SetPointer(PluginWin, EmptyPointer, 1, 1, 0, 0);
  722.         SetAPen(rp, 1);
  723.         RectFill(rp, 0, 0, (Width-1), (Height-1));
  724.         SetAPen(rp, 255);
  725.  
  726.         WinMask = 1L << PluginWin->UserPort->mp_SigBit;
  727.  
  728.         InitField(Zoom, Width, Height);
  729.         MakeTitle();
  730.  
  731.         return(TRUE);
  732. }
  733.  
  734. /******************************************************************************/
  735. /* This function will be called when the plugin is shut down. You should free */
  736. /* all previously allocated resources here.                                   */
  737. /******************************************************************************/
  738.  
  739. void PluginExit(void) {
  740.         long i;
  741.  
  742.         if(PluginWin)    CloseWindow(PluginWin);
  743.         if(PluginScreen) CloseScreen(PluginScreen);
  744.         #ifdef __SASC
  745.                 if(PixelD)       PPCFreeVec(PixelD);
  746.                 if(PixelC)       PPCFreeVec(PixelC);
  747.                 if(Colour)       PPCFreeVec(Colour);
  748.                 if(EmptyPointer) PPCFreeVec(EmptyPointer);
  749.         #else
  750.          #ifdef __PPC__ 
  751.                 if(PixelD)       FreeVecPPC(PixelD);
  752.                 if(PixelC)       FreeVecPPC(PixelC);
  753.                 if(Colour)       FreeVecPPC(Colour);
  754.                 if(EmptyPointer) FreeVecPPC(EmptyPointer);
  755.          #else
  756.                 if(PixelD)       FreeVec(PixelD);
  757.                 if(PixelC)       FreeVec(PixelC);
  758.                 if(Colour)       FreeVec(Colour);
  759.                 if(EmptyPointer) FreeVec(EmptyPointer);
  760.          #endif
  761.         #endif
  762.  
  763.         CloseTimer();
  764.         if(CyberGfxBase)  CloseLibrary(CyberGfxBase);
  765.         if(P96Base)    CloseLibrary(P96Base);
  766. //      if(GfxBase)       CloseLibrary(GfxBase);
  767.         if(AslBase)       CloseLibrary(AslBase);
  768.         if(IconBase)      CloseLibrary(IconBase);
  769.         if(KeymapBase)    CloseLibrary(KeymapBase);
  770.         if(GadToolsBase)  CloseLibrary(GadToolsBase);
  771. //      if(IntuitionBase) CloseLibrary(IntuitionBase);
  772. }
  773.  
  774. /*******************************************************************************/
  775. /* This is the main Plugin Loop. It will receive a signal matching PluginMask  */
  776. /* each time new spectral data is ready. The data is stored in two arrays,     */
  777. /* UWORD Spec[512] in structures DataL and DataR. The scale is logarithmic,    */
  778. /* 0 means below -96dB, 65535 means 0dB.                                       */
  779. /* No matter how long it takes until your plugin actually processes the data,  */
  780. /* the memory referenced by the array pointers always remains valid!           */
  781. /*                                                                             */
  782. /* Your plugin loop MUST quit when it receives SIGBREAKF_CTRL_C. If you've     */
  783. /* opened a window you should react to the close gadget as well. For full      */
  784. /* screen plugins I strongly recommend checking the ESC key.                   */
  785. /*******************************************************************************/
  786.  
  787. void PluginLoop(void) {
  788.         struct TextExtent te;
  789.         ULONG *PixelL = 0;
  790.         UBYTE *ActPixel;
  791.         ULONG Signals = 0;
  792.         LONG i,j,k;
  793.         LONG l,r;
  794.         LONG x,y;
  795.         UBYTE v;
  796.         UWORD w;
  797.         UBYTE ColorMode;
  798.  
  799.         ULONG   hi,lo,itime,eclock;
  800.         char FPStext[64];
  801.         UBYTE Vanilla;
  802.         struct InputEvent ie;
  803.         WORD    RawLen;
  804.       int ti_len,ti_center,ti_start = 0;
  805.       
  806.         //printf("entering main loop\n");
  807.         Wait(SIGBREAKF_CTRL_C | PluginMask);
  808.       
  809.  
  810.         /* Make a backup of the data pointers */
  811.         PluginRawL    = SpecRawL;
  812.         PluginRawR    = SpecRawR;
  813.         PluginSamples = SampleRaw;
  814.         WritePixelArray(PixelC, 0, 0, Width, rp, Woffset, 0, Width, Height, RECTFMT_LUT8);
  815.  
  816.         Delay(100);
  817.  
  818.         StartTimer();
  819.  
  820.         InitWave(WaveToCalc0, 0);
  821.         InitWave(WaveToCalc1, 1);
  822.  
  823.         for(;;) {
  824.                 /* Wait until there's something to do */
  825.  
  826.                 Signals=Wait(SIGBREAKF_CTRL_C | PluginMask | ConfigMask | InfoMask | WinMask | TimerMask);
  827.                 if(Signals & TimerMask) {
  828.                         WaitIO((struct IORequest *) TimerIO);
  829.                 }
  830.  
  831.                 /* Break received -> quit at once! */
  832.                 if(Signals & SIGBREAKF_CTRL_C) break;
  833.  
  834.                 /* Window close gadget hit -> quit as well! */
  835.                 if(Signals & WinMask) {
  836.                         struct IntuiMessage *imsg;
  837.                         BOOL done=0;
  838.  
  839.                         while(imsg=(struct IntuiMessage *)GetMsg(PluginWin->UserPort)) {
  840.                                 if(imsg->Class == IDCMP_RAWKEY) {
  841.                                         ie.ie_Class        = IECLASS_RAWKEY;
  842.                                         ie.ie_SubClass     = 0;
  843.                                         ie.ie_Code         = imsg->Code;
  844.                                         ie.ie_Qualifier    = 0;
  845.                                         ie.ie_EventAddress = imsg->IAddress;
  846.                                         RawLen = MapRawKey(&ie, &Vanilla, 1, 0);
  847.  
  848.                                         switch(imsg->Code) {
  849.                                                 case 0x45: done=1; break;
  850.                                         }
  851.  
  852.                                         if(RawLen==1) {
  853.                                                 switch(Vanilla) {
  854.                                                         case 'f': DisplayFPS = 1-DisplayFPS; break;
  855.                                                         case 'w': ShowWave   = 1-ShowWave;   break;
  856.                                                         case 'i': InfoCount  = 0;            break;
  857.                               case 't': if(!DisplayTi) DisplayTi = 1;else DisplayTi = 0;        break;
  858.                               case 'l': if(!EffectLock) EffectLock = 1;else EffectLock = 0;        break;
  859.  
  860. //                                              case '+': Cutoff--;                  break;
  861. //                                              case '-': Cutoff++;                  break;
  862.                                                 }
  863.                                                 if(Cutoff < 1) Cutoff =   1;
  864.                                                 if(Cutoff > HalfHeight-10) Cutoff = HalfHeight-10;
  865.                                                 for(i=0; i<Width*Cutoff; i++) {
  866.                                                         PixelC[i]=PixelD[i]=0;
  867.                                                 }
  868.                                                 for(i=Width*(Height-Cutoff); i<Width*Height; i++) {
  869.                                                         PixelC[i]=PixelD[i]=0;
  870.                                                 }
  871.                                         }
  872.                                 }
  873.                                 ReplyMsg((struct Message *)imsg);
  874.                         }
  875.                         if(done) break;
  876.                 }
  877.  
  878.                 if(Signals & TimerMask) {
  879.                         StartTimer();
  880. //printf("timer started\n");
  881.       Blur(PixelC, PixelD);
  882.  
  883.                         FrameCountLow++;
  884.                         if(FrameCountLow > 4) {
  885.                                 FrameCountLow = 0;
  886.                                 eclock=ReadEClock(&ev2);
  887.                                 hi = ev2.ev_hi - ev1.ev_hi;
  888.                                 lo = ev2.ev_lo - ev1.ev_lo;
  889.                                 itime = hi*eclock+lo;
  890.  
  891.                                 if(itime==0) itime=1;
  892.  
  893.                                 ev1.ev_hi = ev2.ev_hi;
  894.                                 ev1.ev_lo = ev2.ev_lo;
  895.                                 ReColor();
  896.                         }
  897.  
  898.                         FrameCountHigh++;
  899.                 if(FrameCountHigh > 600) {
  900.                                 FrameCountHigh = 0;
  901. #ifndef __VBCC__
  902.                                 ColorMode = (UBYTE)(rand()>>24) % 10;
  903.  
  904. #else
  905. /*
  906. if(ColorMode==0)
  907. {
  908.         MidR[0] = 255;
  909.         MidG[0] = 220;
  910.         MidB[0] = 200;
  911.  
  912.         MidR[1] = 170;
  913.         MidG[1] = 96;
  914.         MidB[1] = 170;
  915.  
  916.         MidR[2] = 10;
  917.         MidG[2] = 100;
  918.         MidB[2] = 52;
  919.  
  920. ColorMode=1;
  921. }
  922. */
  923. /*
  924. if(ColorMode==0)
  925. {
  926.         MidR[0] = 255;
  927.         MidG[0] = 200;
  928.         MidB[0] = 255;
  929.  
  930.         MidR[1] = 96;
  931.         MidG[1] = 76;
  932.         MidB[1] = 178;
  933.  
  934.         MidR[2] = 100;
  935.         MidG[2] = 55;
  936.         MidB[2] = 65;
  937.  
  938. ColorMode=1;
  939. }
  940. */
  941.  
  942. if(ColorMode == 0)
  943. {
  944. //blue
  945.         MidR[0] = 230;
  946.         MidG[0] = 230;
  947.         MidB[0] = 230;
  948.  
  949.         MidR[1] = 86;
  950.         MidG[1] = 86;
  951.         MidB[1] = 170;
  952.  
  953.         MidR[2] = 25;
  954.         MidG[2] = 25;
  955.         MidB[2] = 100;
  956.  
  957. ColorMode = 1;
  958. }
  959. else
  960. {
  961. //fire
  962.         MidR[0] = 255;
  963.         MidG[0] = 255;
  964.         MidB[0] = 100;
  965.  
  966.         MidR[1] = 200;
  967.         MidG[1] = 120;
  968.         MidB[1] = 10;
  969.  
  970.         MidR[2] = 100;
  971.         MidG[2] = 25;
  972.         MidB[2] = 25;
  973.  
  974.         MidR[3] = 0;
  975.         MidG[3] = 0;
  976.         MidB[3] = 0;
  977.  
  978. ColorMode = 0;
  979. }
  980.  
  981. #endif
  982.                         //printf("ColorMode: %d\n", ColorMode);
  983. #ifndef __VBCC__
  984.                                 switch(ColorMode) {
  985.                                         case 0:
  986.                                         case 1:
  987.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  988.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  989.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  990.  
  991.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  992.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  993.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  994.  
  995.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  996.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  997.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  998.                                         break;
  999.  
  1000.                                         case 2:
  1001.                                                 MidRdst[0] = (UBYTE)(rand()>>24) + 0;
  1002.                                                 MidGdst[0] = (UBYTE)(rand()>>24) + 0;
  1003.                                                 MidBdst[0] = (UBYTE)(rand()>>24) + 0;
  1004.  
  1005.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  1006.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  1007.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  1008.  
  1009.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  1010.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  1011.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1012.                                         break;
  1013.  
  1014.                                         case 3:
  1015.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 0;
  1016.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 0;
  1017.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 0;
  1018.  
  1019.                                                 MidRdst[1] = (UBYTE)(rand()>>24) + 0;
  1020.                                                 MidGdst[1] = (UBYTE)(rand()>>24) + 0;
  1021.                                                 MidBdst[1] = (UBYTE)(rand()>>24) + 0;
  1022.  
  1023.                                                 MidRdst[2] = (UBYTE)(rand()>>24) + 0;
  1024.                                                 MidGdst[2] = (UBYTE)(rand()>>24) + 0;
  1025.                                                 MidBdst[2] = (UBYTE)(rand()>>24) + 0;
  1026.                                         break;
  1027.  
  1028.                                         default:
  1029.                                                 MidRdst[0] = (UBYTE)(rand()>>25) + 127;
  1030.                                                 MidGdst[0] = (UBYTE)(rand()>>25) + 127;
  1031.                                                 MidBdst[0] = (UBYTE)(rand()>>25) + 127;
  1032.  
  1033.                                                 MidRdst[1] = (UBYTE)(rand()>>25) + 64;
  1034.                                                 MidGdst[1] = (UBYTE)(rand()>>25) + 64;
  1035.                                                 MidBdst[1] = (UBYTE)(rand()>>25) + 64;
  1036.  
  1037.                                                 MidRdst[2] = (UBYTE)(rand()>>25) + 32;
  1038.                                                 MidGdst[2] = (UBYTE)(rand()>>25) + 32;
  1039.                                                 MidBdst[2] = (UBYTE)(rand()>>25) + 32;
  1040.                                         break;
  1041.                                 }
  1042. #endif
  1043.                         }
  1044.  
  1045.                         CalcLine(Zoom2, Width, Height, FieldToCalc);
  1046.                         LineToCalc++;
  1047.                         if(LineToCalc > Height-1) LineToCalc = Height-1;
  1048.                         if(!EffectLock)FrameCountField++;
  1049.                         
  1050.                         if(FrameCountField > 500) {
  1051.  
  1052.                         //printf("FCF 500\n");
  1053.                                 FrameCountField=0;
  1054.  
  1055.                                 LineToCalc = 1;
  1056.                                 PrevField = FieldToCalc;
  1057.  
  1058. #ifdef __VBCC__
  1059.                                 do {
  1060.                         FieldToCalc=(UBYTE)(rand() % NUMFIELDS);
  1061.                                 } while (FieldToCalc == PrevField);
  1062.  
  1063. /*                              if(FieldToCalc == 0)
  1064.                                 FieldToCalc = 1;
  1065.                                 else if(FieldToCalc == 1)
  1066.                                 FieldToCalc = 2;
  1067.                                 else if(FieldToCalc == 2)
  1068.                                 FieldToCalc = 3;
  1069.                                 else if(FieldToCalc == 3)
  1070.                                 FieldToCalc = 4;
  1071.                                 else if(FieldToCalc == 4)
  1072.                                 FieldToCalc = 6;
  1073.                                 else if(FieldToCalc == 6)
  1074.                                 FieldToCalc = 7;
  1075.                                 else if(FieldToCalc == 7)
  1076.                                 FieldToCalc = 9;
  1077.                                 else if(FieldToCalc == 9)
  1078.                                 FieldToCalc = 10;
  1079.                                 else if(FieldToCalc == 10)
  1080.                                 FieldToCalc = 13;
  1081.                                 else if(FieldToCalc == 13)
  1082.                                 FieldToCalc = 14;
  1083.                                 else if(FieldToCalc == 14)
  1084.                                 FieldToCalc = 15;
  1085.                                 else if(FieldToCalc == 15)
  1086.                                 FieldToCalc = 16;
  1087.                                 else if(FieldToCalc == 16)
  1088.                                 FieldToCalc = 18;
  1089.                                 else
  1090.                                 FieldToCalc = 0;
  1091. */
  1092. #endif
  1093.  
  1094. #ifndef __VBCC__
  1095.                                 do {
  1096.                         FieldToCalc=(UBYTE)(rand()>>24) % NUMFIELDS;
  1097.                                 } while (FieldToCalc == PrevField);
  1098. #endif
  1099.  
  1100.                                 for(j=0; j<Width*Height; j++)
  1101.                                 {
  1102.                                         Zoom[j]=Zoom2[j];
  1103.                                 }
  1104.                                 //printf("preparing field %d\n", FieldToCalc);
  1105.                                 PrepareConstants(FieldToCalc);
  1106.  
  1107.                         }
  1108.  
  1109.                         for(i=Width*Cutoff; i<Width*(Height-Cutoff); i++) {
  1110.                                 PixelC[i]=PixelD[Zoom[i]];
  1111.                         }
  1112.  
  1113.  
  1114.                         /* Make a backup of the data pointers */
  1115.                         PluginRawL    = SpecRawL;
  1116.                         PluginRawR    = SpecRawR;
  1117.                         PluginSamples = SampleRaw;
  1118.  
  1119.                         InfoCount++;
  1120.                         if(InfoCount < 75) MakeTitle();
  1121.                         else InfoCount=75;
  1122.  
  1123.                         //TimeWave++;
  1124. /*
  1125. surgeon:frametiming ++ for 20fps; +2 for 10fps; +4 for 5fps
  1126. */
  1127.             TimeWave+=3; //framerate adjust
  1128.  
  1129.                         if(!EffectLock)FrameCountWave++;
  1130.                         CalcWave(WaveToCalc0, 0);
  1131.                         DrawWave(WaveX,  WaveY,  Width, Height, WaveToCalc0, 0);
  1132.                         CalcWave(WaveToCalc1, 1);
  1133.                         DrawWave(WaveX2, WaveY2, Width, Height, WaveToCalc1, 1);
  1134.                         if(FrameCountWave > 200) {
  1135.  
  1136.                                 if(DestWaveBuffer == 1) WaveMorph += 0.015; //was 0.005
  1137.                                 else                    WaveMorph -= 0.015; //was 0.005
  1138.                         }
  1139.                         if (WaveMorph > 1.0) WaveMorph = 1.0;
  1140.                         if (WaveMorph < 0.0) WaveMorph = 0.0;
  1141.  
  1142.                         if(FrameCountWave > 400) {
  1143.                         //printf("FCW 400\n");
  1144.                         FrameCountWave = 0;
  1145.                         DestWaveBuffer = 1 - DestWaveBuffer;
  1146. #ifdef __VBCC__
  1147.                                 do {
  1148.                                         WaveToCalc = (UBYTE)(rand() % NUMWAVES);
  1149.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1 || WaveToCalc == 10 || WaveToCalc == 8 || WaveToCalc == 6);
  1150.  
  1151.                                 if(DestWaveBuffer) {
  1152.                                         WaveToCalc1 = WaveToCalc;
  1153.                                         InitWave(WaveToCalc1, 1);
  1154.                                 }
  1155.                                 else {
  1156.                                         WaveToCalc0 = WaveToCalc;
  1157.                                         InitWave(WaveToCalc0, 0);
  1158.                                 }
  1159.  
  1160. /*
  1161. if (WaveToCalc1 == 1)
  1162. WaveToCalc1 = 5;
  1163. else if (WaveToCalc1 == 2)
  1164. WaveToCalc1 = 7;
  1165. else if (WaveToCalc1 == 3)
  1166. WaveToCalc1 = 11;
  1167. else if (WaveToCalc1 == 4)
  1168. WaveToCalc1 = 1;
  1169. else if (WaveToCalc1 == 5)
  1170. WaveToCalc1 = 2;
  1171. else if (WaveToCalc1 == 7)
  1172. WaveToCalc1 = 3;
  1173. else
  1174. WaveToCalc1 = 4;
  1175.  
  1176. WaveToCalc0 = 0;
  1177.  
  1178.         InitWave(WaveToCalc1, 1);
  1179.         //printf("initializing wave %d\n",WaveToCalc1);
  1180.         InitWave(WaveToCalc0, 0);
  1181. */
  1182. #endif
  1183.  
  1184. #ifndef __VBCC__
  1185.                                 do {
  1186.                                         WaveToCalc = (UBYTE)(rand()>>24) % NUMWAVES;
  1187.                                         WaveToCalc = NUMWAVES-1;
  1188.                                 } while (WaveToCalc == WaveToCalc0 || WaveToCalc == WaveToCalc1);
  1189.  
  1190.                                 if(DestWaveBuffer) {
  1191.                                         WaveToCalc1 = WaveToCalc;
  1192.                                         InitWave(WaveToCalc1, 1);
  1193.                                 }
  1194.                                 else {
  1195.                                         WaveToCalc0 = WaveToCalc;
  1196.                                         InitWave(WaveToCalc0, 0);
  1197.                                 }
  1198. #endif
  1199.                         }
  1200.  
  1201.                         for(i=0; i<Width*2; i++) {
  1202.                                 float xf,yf;
  1203.                                 ULONG x,y;
  1204.                                 xf = (float)WaveX[i]*(1.0-WaveMorph) + (float)WaveX2[i]*(WaveMorph);
  1205.                                 yf = (float)WaveY[i]*(1.0-WaveMorph) + (float)WaveY2[i]*(WaveMorph);
  1206.                                 x  = (ULONG)xf + Width/2;
  1207.                                 y  = (ULONG)yf + Height/2;
  1208.                                 if(x < Width-1) {
  1209.                                         if(y < Height-1) {
  1210.                                                 if(x > 0) {
  1211.                                                         if(y > 0) {
  1212.                                                                 ActPixel = PixelC + y * Width + x;
  1213.                                                                 *ActPixel=255;
  1214.                                                         }
  1215.                                                 }
  1216.                                         }
  1217.                                 }
  1218.                         }
  1219.  
  1220.                         SetAPen(rp, 0);
  1221. /*                      if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1222.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, 0, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1223.                         RectFill(rp, 0, 0, Width, Cutoff);
  1224.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1225. */
  1226.                         if(ShowWave) WritePixelArray(PixelC, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1227.                         else         WritePixelArray(PixelD, 1, Cutoff+1, Width, rp, Woffset, Cutoff+1, Width-2, Height-2*Cutoff-2, RECTFMT_LUT8);
  1228.                         RectFill(rp, 0, 0, Width, Cutoff);
  1229.                         RectFill(rp, 0, Height-Cutoff-1, Width, Height-1);
  1230.  
  1231.  
  1232.  
  1233.  
  1234.                         if(DisplayFPS)
  1235.                         {
  1236.                                 Move(rp, 0, 15);
  1237.                                 SetABPenDrMd(rp, 255, 0, JAM2);
  1238.                                 sprintf(FPStext, "%3ld fps       ", 5*eclock/itime);
  1239.                                 Text(rp, FPStext, 7);
  1240.                         }
  1241.  
  1242. /* New track info has arrived! */
  1243.         if(Signals & InfoMask)
  1244.         {
  1245.         if(tinfo)
  1246.             {
  1247. /* process contents of tinfo here */
  1248. /* see "TrackInfo.h" for details! */
  1249. /* Example: Display the track info text */
  1250.             if(tinfo->TrackInfoText)
  1251.             sprintf(InfoLine, "%s", tinfo->TrackInfoText);
  1252.             }
  1253.         }
  1254.  
  1255.         SetABPenDrMd(rp, 0, 0, JAM2);
  1256.         RectFill(rp, 0, 170, 320, 30);
  1257.  
  1258.         if(DisplayTi && InfoLine)
  1259.             {
  1260.             ti_len = strlen(InfoLine);
  1261.             Move(rp, Woffset, 180);
  1262.             SetABPenDrMd(rp, 255, 0, JAM2);
  1263.             Text(rp, InfoLine, ti_len);
  1264.             }
  1265.                 }
  1266.         }
  1267. }
  1268.  
  1269.  
  1270.  
  1271.  
  1272. void Blur(UBYTE *PixelC, UBYTE *PixelD) {
  1273.   UBYTE *ActPixel;
  1274.   UBYTE *DstPixel;
  1275.   UBYTE *AbovePixel, *BelowPixel;
  1276.   UBYTE Left, Act, Right;
  1277.   WORD w;
  1278.   ULONG i;
  1279.  
  1280.         PixelC += Width*Cutoff;
  1281.         PixelD += Width*Cutoff;
  1282.  
  1283.   ActPixel   = PixelC+Width+1;
  1284.   AbovePixel = ActPixel-Width;
  1285.   BelowPixel = ActPixel+Width;
  1286.   DstPixel   = PixelD+Width+1;
  1287.  
  1288.   Left  = 0;
  1289.   Act   = 0;
  1290.   Right = 0;
  1291.  
  1292.         for(i=Width*(Cutoff+1); i<(Width*(Height-Cutoff-2)-2); i++) {
  1293.     Right = *(ActPixel+1);
  1294.  
  1295.     w = (Right + Act + Left + *AbovePixel + *BelowPixel) * 3 / 16;
  1296.                 if(w<0) w=0;
  1297.     *DstPixel++ = w;
  1298.  
  1299.     ActPixel++;
  1300.     AbovePixel++;
  1301.     BelowPixel++;
  1302.  
  1303.     Left = Act;
  1304.     Act = Right;
  1305.   }
  1306. }
  1307.  
  1308. void ShowRequester(char *Text, char *Button) {
  1309.         struct EasyStruct Req;
  1310.         Req.es_StructSize   = sizeof(struct EasyStruct);
  1311.         Req.es_Flags        = 0;
  1312.   Req.es_Title        = "AmigaAMP Plugin";
  1313.   Req.es_TextFormat   = (UBYTE*)Text;
  1314.   Req.es_GadgetFormat = (UBYTE*)Button;
  1315.         EasyRequestArgs(NULL, &Req, NULL, NULL);
  1316. }
  1317.  
  1318. BOOL OpenTimer(void) {
  1319.         struct EClockVal ev = {0,0};
  1320.  
  1321.         if(TimerMP=(struct MsgPort*)CreatePort(0,0)) {
  1322.                 if(TimerIO=(struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest))) {
  1323.                         TimerError=OpenDevice("timer.device", UNIT_ECLOCK, (struct IORequest *)TimerIO, 0);
  1324.                         if(TimerError==0) {
  1325.  
  1326.                                 TimerBase = (struct Library*) &TimerIO->tr_node.io_Device->dd_Library;
  1327.                                 EFreq=ReadEClock(&ev);
  1328.  
  1329.                                 TimerMask = 1L << TimerMP->mp_SigBit;
  1330.  
  1331.                                 return(TRUE);
  1332.                         }
  1333.                 }
  1334.         }
  1335.         return(FALSE);
  1336. }
  1337.  
  1338. void CloseTimer(void) {
  1339.         if(!TimerError)   CloseDevice((struct IORequest *)TimerIO);
  1340.         if(TimerIO)       DeleteIORequest(TimerIO);
  1341.         if(TimerMP)       DeletePort(TimerMP);
  1342. }
  1343.  
  1344. void StartTimer(void) {
  1345.         TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  1346.         TimerIO->tr_node.io_Flags   = 0;
  1347.         TimerIO->tr_time.tv_secs    = 0;
  1348.         TimerIO->tr_time.tv_micro   = EFreq/LimitFPS;
  1349.         SendIO((struct IORequest *)TimerIO);
  1350. }
  1351.  
  1352. struct MsgPort *MyCreatePort(UBYTE *name, LONG pri) {
  1353.         int sigBit;
  1354.         struct MsgPort *mp;
  1355.  
  1356.         if((sigBit = AllocSignal(-1L)) == -1)   return(NULL);
  1357.  
  1358.         mp = (struct MsgPort*) AllocVec(sizeof(struct MsgPort), MEMF_PUBLIC|MEMF_CLEAR);
  1359.  
  1360.         if(!mp) {
  1361.                 FreeSignal(sigBit);
  1362.                 return(NULL);
  1363.         }
  1364.  
  1365.         mp->mp_Node.ln_Name = name;
  1366.         mp->mp_Node.ln_Pri  = pri;
  1367.         mp->mp_Node.ln_Type = NT_MSGPORT;
  1368.         mp->mp_Flags        = PA_SIGNAL;
  1369.         mp->mp_SigBit       = sigBit;
  1370.         mp->mp_SigTask      = FindTask(NULL);
  1371.         if(name) AddPort(mp);
  1372.         #if defined (__SASC) || defined (__VBCC__)
  1373.                 else NewList(&(mp->mp_MsgList));
  1374.         #else
  1375.                 else NewListPPC(&(mp->mp_MsgList));
  1376.         #endif
  1377.  
  1378.         return(mp);
  1379. }
  1380.  
  1381. void MyDeletePort(struct MsgPort *mp) {
  1382.         if(mp->mp_Node.ln_Name) RemPort(mp);
  1383.         mp->mp_SigTask         = (struct Task *) -1;
  1384.         mp->mp_MsgList.lh_Head = (struct Node *) -1;
  1385.         FreeSignal(mp->mp_SigBit);
  1386.         FreeVec(mp); mp=NULL;
  1387. }
  1388.  
  1389. void InitField(LONG *Zoom, ULONG Width, ULONG Height) {
  1390.         LONG i,xs,ys,xd,yd;
  1391.  
  1392.         float scale,greater;
  1393.         float xsf,ysf,xdf,ydf;
  1394.         float rsf,tsf,rdf,tdf;
  1395.         float wf,hf;
  1396.  
  1397.         wf=(float)Width;
  1398.         hf=(float)Height;
  1399.  
  1400.         greater=1.0;
  1401.         if(wf > greater) greater = wf;
  1402.         if(hf > greater) greater = hf;
  1403.  
  1404.         scale = 1.0 / (greater/2.0);
  1405.  
  1406.         for(yd=0; yd<(Height); yd++) {
  1407.                 for(xd=0; xd<(Width); xd++) {
  1408.                         xdf = (xd - wf/2.0) * scale;
  1409.                         ydf = (yd - hf/2.0) * scale;
  1410.  
  1411.                         xsf = xdf - xdf * 0.075;
  1412.                         ysf = ydf - ydf * 0.075;
  1413.  
  1414.                         xs = xsf/scale + wf/2.0;
  1415.                         ys = ysf/scale + hf/2.0;
  1416.  
  1417.                         if(xs < Width/2)  xs++;
  1418.                         if(ys < Height/2) ys++;
  1419.  
  1420.                         if(xs < 0)      xs = 0;
  1421.                         if(xs > Width)  xs = Width;
  1422.                         if(ys < 0)      ys = 0;
  1423.                         if(ys > Height) ys = Height;
  1424.  
  1425.                         Zoom[Width * yd + xd] = Width * ys + xs;
  1426.                 }
  1427.         }
  1428. }
  1429.  
  1430.  
  1431. void MakeCMap(void) {
  1432.         int j,i,c;
  1433.         float r,g,b;
  1434.         float rs,gs,bs;
  1435.  
  1436.         r=255; g=255; b=255;
  1437.  
  1438.         c=255;
  1439.  
  1440.         Colour[0]=256L<<16+0;
  1441.  
  1442.         for(j=0; j<4; j++) {
  1443.                 rs = (r - (float)MidR[j]) / 64.0;
  1444.                 gs = (g - (float)MidG[j]) / 64.0;
  1445.                 bs = (b - (float)MidB[j]) / 64.0;
  1446.                 for(i=0; i<64; i++) {
  1447.                         Colour[1+3*c+0] = (ULONG)r << 24;
  1448.                         Colour[1+3*c+1] = (ULONG)g << 24;
  1449.                         Colour[1+3*c+2] = (ULONG)b << 24;
  1450.                         r -= rs;
  1451.                         g -= gs;
  1452.                         b -= bs;
  1453.                         c--;
  1454.                 }
  1455.         }
  1456.  
  1457. }
  1458.  
  1459. void MakeTitle(void) {
  1460.         long x,y,i,p,s,v,xs,ys;
  1461.         UWORD Blt1[27] = {
  1462.                 0x7008,0x0000,0x0000,0x8808,0x0000,0x0000,0x822B,0x1963,
  1463.                 0x8E38,0x722C,0xA590,0x5144,0x0A28,0x9913,0xD07C,0x8A28,
  1464.                 0x8514,0x5040,0x8A68,0xA594,0xD144,0x71AF,0x1963,0x4E38,
  1465.                 0x0000,0x0100,0x0000
  1466.         }; // W=46, H=9
  1467.         UWORD Blt2[54] = {
  1468.                 0x8001,0xF400,0x0000,0x0101,0x0000,0x0080,0x8000,0x4400,
  1469.                 0x0000,0x0111,0x0000,0x0080,0xB220,0x458E,0x7638,0xC111,
  1470.                 0x3967,0x9C80,0xCA20,0x4651,0x4905,0x2092,0x4590,0xA280,
  1471.                 0x8940,0x4451,0x493C,0xC0AA,0x7D11,0x3E80,0x8940,0x4451,
  1472.                 0x4944,0x20AA,0x4112,0x2080,0x8880,0x4451,0x494D,0x2044,
  1473.                 0x4514,0x2280,0xF080,0x444E,0x4934,0xC044,0x3917,0x9C80,
  1474.                 0x0100,0x0000,0x0000,0x0000,0x0000,0x0000
  1475.         }; // W=89, H=9
  1476.  
  1477.         xs = (Width-46)/2;
  1478.         ys = Height/2-30-9;
  1479.         s=0;
  1480.         for(y=0; y<9; y++) {
  1481.                 x=0;
  1482.                 for(i=0; i<3; i++) {
  1483.                         for(p=0; p<16; p++) {
  1484.                                 x++;
  1485.                                 v = Blt1[s] & (1<<(15-p));
  1486.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1487.                         }
  1488.                         s++;
  1489.                 }
  1490.         }
  1491.         xs = (Width-89)/2;
  1492.         ys = Height/2+30;
  1493.         s=0;
  1494.         for(y=0; y<9; y++) {
  1495.                 x=0;
  1496.                 for(i=0; i<6; i++) {
  1497.                         for(p=0; p<16; p++) {
  1498.                                 x++;
  1499.                                 v = Blt2[s] & (1<<(15-p));
  1500.                                 if(v) PixelC[(ys+y)*Width+xs+x] = 255;
  1501.                         }
  1502.                         s++;
  1503.                 }
  1504.         }
  1505. }
  1506.  
  1507.  
  1508. void ReColor(void) {
  1509. #ifndef __VBCC__
  1510.  
  1511.         int i;
  1512.         for(i=0; i<3; i++) {
  1513.                 if(MidR[i] > MidRdst[i]) MidR[i] --;
  1514.                 if(MidG[i] > MidGdst[i]) MidG[i] --;
  1515.                 if(MidB[i] > MidBdst[i]) MidB[i] --;
  1516.                 if(MidR[i] < MidRdst[i]) MidR[i] ++;
  1517.                 if(MidG[i] < MidGdst[i]) MidG[i] ++;
  1518.                 if(MidB[i] < MidBdst[i]) MidB[i] ++;
  1519.  
  1520.         }
  1521. #endif
  1522.         MakeCMap();
  1523.         LoadRGB32(&PluginScreen->ViewPort, Colour);
  1524. }
  1525.  
  1526. float rnd(float max) {
  1527.         ULONG r;
  1528.         ULONG m;
  1529.  
  1530.         m = (ULONG)(max * 10000.0);
  1531. #ifndef __VBCC__
  1532.         r=(rand()>>8) % m;
  1533. #else
  1534.         r=(rand() % m);
  1535. #endif
  1536.         return (float)r/10000.0;
  1537. }
  1538.  
  1539. float sgn(float val) {
  1540.         if(val > 0.0) return  1.0;
  1541.         if(val < 0.0) return -1.0;
  1542.         return 0.0;
  1543. }
  1544.  
  1545. float trnc(float value) {
  1546.         return ceil(value);
  1547. }
  1548.  
  1549. #ifdef __SASC
  1550. void SetPriority(void) {
  1551.         struct TagItem MyTags[2];
  1552.         if(PPCLibBase=OpenLibrary("ppc.library",0)) {
  1553.                 MyTags[0].ti_Tag  = PPCTASKTAG_PRIORITY;
  1554.                 MyTags[0].ti_Data = 15;
  1555.                 MyTags[1].ti_Tag         = TAG_END;
  1556.                 CloseLibrary(PPCLibBase);
  1557.         }
  1558. }
  1559. #endif
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.