**************  ¨ 
* ¨ 
* ¨ 
* ¨ 
* ¨ 
* ¨ 
* ¨ 
* ¨¨΅±ΡΩ₯έΑ½ΙΠ‘ΝΡΙΥΠY₯έA½ΙΠ¨±1=9€μ(¨δ5Ι¬9Υ₯ΩΘΐΤΌΘΠΌΰά(¨΅½ΝΠ½Ρ‘½₯Μ½ΙΙ½έΙ½΄MΡΑ‘Έ½δΜ5±ΠΉ(¨ΑΙ½Ι΄Έ(¨Q‘½₯Μ΅½₯₯‘Ι₯ΉΡΌΉΙ°ΥΉΡ₯½ΈΡΌ΅±Π(¨ΉδY₯έA½ΙΠΈ(¨ΥΉΡ₯½Έ₯Μ±±Μ΅±ΡΩ₯έΑ½ΙΠ‘Ωΐ±ΝΜ€μέ₯Ρ Ωΐ₯ΉΑ½₯ΉΡΘ(¨ΡΌY₯έA½ΙΠΝΡΙΥΠΉΝΜ1=9ΉΥ΅Θ½Ν½ΉΜΡΌ΅±Π½Ι(¨ΙΡΥΙΉ₯ΉΈ(¨(¨=5A%1H%9=I5P   D#ION:
 *    Lattice C version 3.10
 *    AmigaDOS 1.2
 * LINKING INFORMATION:
 *    link with LIB:lcm.lib (first library)
 ***********************************************************************/

#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/tasks.h>
#include <exec/ports.h>
#include <exec/io.h>

#include <graphics/gfx.h>
#include <graphics/view.h>

#include <intuition/intuition.h>

#include <math.h>

extern struct IntuiMessage *GetMsg();
extern struct MsgPort      *CreatePort();

void meltviewport(vp,secs) struct ViewPort *vp;
                           LONG secs; {
   struct BitMap   *bitmap;
   struct timerequest tr;
   LONG   x, y,         /* start positions       */
          dx, dy,       /* offsets               */
          u, v;         /* size                  */
   LONG   TempA[32];    /* temp buffer           */
   UBYTE  mask;         /* bit-plane mask for blitter   */
   SHORT  width,height;
   UBYTE  depth;

/* create a reply port for the timer device */
   if ((tr.tr_node.io_Message.mn_ReplyPort = CreatePort(0,0)) == NULL)
      return;
/* open the timer device */
   if (OpenDevice(TIMERNAME,UNIT_VBLANK,&tr,0) != NULL) return;
/* send a time request */
   tr.tr_node.io_Command = TR_ADDREQUEST;
   tr.tr_node.io_Message.mn_Node.ln_Pri = 10;
   tr.tr_time.tv_secs = secs;
   tr.tr_time.tv_micro = 0;
   SendIO(&tr);

   bitmap = vp->RasInfo->BitMap;
   width = vp->DWidth;
   height = vp->DHeight;
   depth = bitmap->Depth;
/* do until the timerequest is returned */
   FOREVER {
     if(CheckIO(&tr) != NULL) {
         CloseDevice(&tr);
         return;
     }

     for(mask=1; mask<((1<<depth)-1); mask*=2) {
       u = (drand48() * (width - 3)) + 1;
       v = (drand48() * (height - 3)) + 1;
       x = (drand48() * (width - 1 - u)) + 1;
       y = (drand48() * (height - 2 - v)) + 1;
       dx = (drand48() * 3) - 1;
       dy = drand48() * 3;

       BltBitMap(bitmap, x, y,
                 bitmap, x+dx, y+dy,
                 u, v, 0x0c0, mask, TempA);

     }
   }     /* end of FOREVER */
}     /* end of meltviewport */
