home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 314.lha / WatchMan / WatchMan.c < prev    next >
C/C++ Source or Header  |  1989-12-01  |  16KB  |  403 lines

  1. /****************************************************************
  2. *      A little hack inspired by "EyeCon" on the Suns.  
  3. *      I use something like this on my workbench: 
  4. *      SetRGB4(vp, 0, 6, 6, 4); 
  5. *      SetRGB4(vp, 1, 4, 3, 0); 
  6. *      SetRGB4(vp, 2, 15, 12, 5); 
  7. *      SetRGB4(vp, 3, 10, 8, 3); 
  8. *      Looks good in interlace and gives Amy a more 'pro' look.  
  9. *      (C) 1989 Jonas Petersson & Sirius Soft
  10. *
  11. *      Comments to zaphod@malmax.maxcimator.se or
  12. *                  zaphod@magrathea.sirius.se
  13. */
  14.  
  15.  
  16. /* Figure out the #includes for yourself - or use the trick... */
  17.  
  18. #define Lx 29          /* The eyes offset from upper left corner */
  19. #define Ly 49
  20. #define Rx 49
  21. #define Ry 46
  22.  
  23. struct IntuitionBase *IntuitionBase;
  24. struct GfxBase *GfxBase;
  25.  
  26. struct MsgPort *timerport;          /* for timer communications */
  27. struct IOStdReq *timermsg;          /* for timer */
  28.  
  29. USHORT         *Manmap_chip[2]= {NULL,NULL};   /* Chip copy */
  30.  
  31. USHORT Manmap[2][528] = {              /* Background head image */
  32.                                        /* Probably in fastmem */
  33.     {  0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFF00,
  34.        0x8000,0x0000,0x0000,0x0000,0x0000,0x0100,
  35.        0x9555,0x5555,0x7555,0x5555,0x5555,0x5700,
  36.        0xAAAA,0xAAAF,0xFAAF,0xAAAA,0xAAAA,0xAB00,
  37.        0x9555,0x557F,0xFD7F,0xD555,0x5555,0x5700,
  38.        0xAAAA,0xBFFF,0xFDFF,0xFEAA,0xAAAA,0xAB00,
  39.        0x9555,0xFFFF,0xFE7F,0xFFD5,0x5555,0x5700,
  40.        0xAAFF,0xFFFF,0xFFBF,0xFFFA,0xAAAA,0xAB00,
  41.        0x97FF,0xFFFF,0xFFCF,0xFFF5,0x5555,0x5700,
  42.        0xBFFF,0xFFFF,0xFFF7,0xFFFA,0xAAAA,0xAB00,
  43.        0xBFFF,0xFFFF,0xFFF9,0xFFF5,0x5555,0x5700,
  44.        0xBFFF,0xFFFF,0xFFFE,0xFFFA,0xAAAA,0xAB00,
  45.        0x9FFF,0xFFFF,0xFFFF,0x3FFD,0x5555,0x5700,
  46.        0xAFFF,0xFFFF,0xFFFF,0xDFFA,0xAAAA,0xAB00,
  47.        0x97FF,0xFFFF,0xFFFF,0xFFFD,0x5555,0x5700,
  48.        0xAAFF,0xFFFF,0xFFFF,0xFFFE,0xAAAA,0xAB00,
  49.        0x957F,0xFFFF,0xFFFF,0xFFFD,0x5555,0x5700,
  50.        0xAABF,0xFFFF,0xFFFF,0xFFFE,0xAAAA,0xAB00,
  51.        0x955F,0xFFFF,0xFFFF,0x5FFF,0x5555,0x5700,
  52.        0xAAAF,0xFFFF,0xFFAA,0xAAFE,0xAAAA,0xAB00,
  53.        0x9555,0xFFFF,0x807F,0xFD55,0x5555,0x5700,
  54.        0xAAAA,0xFFF0,0x0FFF,0xFAAA,0xAAAA,0xAB00,
  55.        0x9555,0x500F,0xFFFF,0xFF55,0x5555,0x5700,
  56.        0xAAAA,0xA1FF,0xFFFF,0xFDAA,0xAAAA,0xAB00,
  57.        0x9555,0x5FFF,0xFFFF,0xFAD5,0x5555,0x5700,
  58.        0xAAAA,0xAFFF,0xFFFF,0xFD6A,0xAAAA,0xAB00,
  59.        0x9555,0x5FFF,0xFFFF,0xFEB5,0x5555,0x5700,
  60.        0xAAAA,0xAFFF,0xFFFF,0xFF5E,0xAAAA,0xAB00,
  61.        0x9555,0x5FFF,0xFFFF,0xFFAD,0x5555,0x5700,
  62.        0xAAAA,0xAFFF,0xFFFF,0xFFD6,0xAAAA,0xAB00,
  63.        0x9555,0x5FFF,0xFFFF,0xFFAB,0x5555,0x5700,
  64.        0xAAAA,0xAFFF,0xFFFF,0xFFD5,0xAAAA,0xAB00,
  65.        0x9555,0x5FFF,0xFFFF,0xFFEB,0x5555,0x5700,
  66.        0xAAAA,0xAFFF,0xFFFF,0xFFF5,0xAAAA,0xAB00,
  67.        0x9555,0x5FFF,0xFFFF,0xFFEA,0xD555,0x5700,
  68.        0xAAAA,0xAFFF,0xFFFF,0xFFF5,0x6AAA,0xAB00,
  69.        0x9555,0x5FFF,0xFFFF,0xFFFA,0xB555,0x5700,
  70.        0xAAAA,0xAFFF,0xFFFF,0xFFFD,0x6EAA,0xAB00,
  71.        0x9555,0x5FFF,0xFFFF,0xFFEA,0xBB55,0x5700,
  72.        0xAAAA,0xAFFF,0xFFFF,0xFD55,0x56AA,0xAB00,
  73.        0x9555,0x5FFF,0xFFEA,0xBAAA,0xAB55,0x5700,
  74.        0xAAAA,0xAFFF,0xFF55,0x7F55,0x56AA,0xAB00,
  75.        0x9555,0x5FFE,0xAABA,0xFFFA,0xAD75,0x5700,
  76.        0xAAAA,0xAF7F,0x555F,0xFFFD,0x5ABA,0xAB00,
  77.        0x9555,0x5AFF,0xAEBF,0xC3FE,0xAD7D,0x5700,
  78.        0xAAAA,0xADD5,0xFFFE,0x00FD,0x5ABC,0xAB00,
  79.        0x9555,0x56BF,0xFFFC,0x007E,0xB57B,0x5700,
  80.        0xAAAA,0xABF0,0x1FF4,0x007F,0x5ABC,0xAB00,
  81.        0x9555,0x55E0,0x0FFC,0x007E,0xB57B,0x5700,
  82.        0xAAAA,0xAAC0,0x07F4,0x007F,0x5AB4,0xAB00,
  83.        0x9555,0x55C0,0x07FA,0x00FE,0xAF6B,0x5700,
  84.        0xAAAA,0xAAC0,0x07F7,0xC7FF,0x55B6,0xAB00,
  85.        0x9555,0x5560,0x0FEB,0xFF55,0x5551,0x5700,
  86.        0xAAAA,0xAAF0,0x1FF7,0xEAAA,0xAAAA,0xAB00,
  87.        0x9555,0x5578,0x3FAA,0x0005,0x5553,0x5700,
  88.        0xAAAA,0xAABF,0xED50,0x0002,0xAAA8,0xAB00,
  89.        0x9555,0x557D,0x5A00,0x0001,0x5555,0x5700,
  90.        0xAAAA,0xAAAA,0xA000,0x0000,0xAAAA,0xAB00,
  91.        0x9555,0x5550,0x0000,0x0001,0x5555,0x5700,
  92.        0xAAAA,0xAA00,0x0000,0x0000,0xAAAA,0xAB00,
  93.        0x9555,0x5400,0x0000,0x0000,0x5555,0x5700,
  94.        0xAAAA,0xAA00,0x0000,0x0000,0x2AAA,0xAB00,
  95.        0x9555,0x5500,0x0000,0x0000,0x5555,0x5700,
  96.        0xAAAA,0xAA00,0x1E00,0x0000,0x2AAA,0xAB00,
  97.        0x9555,0x5500,0x3F00,0x0020,0x1555,0x5700,
  98.        0xAAAA,0xAA80,0xFF01,0x5550,0x0AAA,0xAB00,
  99.        0x9555,0x5502,0xFF2A,0xAAA0,0x0555,0x5700,
  100.        0xAAAA,0xAA87,0xFD55,0x5000,0x0FFF,0xFB00,
  101.        0x9555,0x5545,0x7AA8,0x0000,0x1FFF,0xF700,
  102.        0xAAAA,0xAA82,0xD540,0x0000,0x1FFF,0xFB00,
  103.        0x9555,0x5541,0x0000,0x0000,0x3FFF,0xF700,
  104.        0xAAAA,0xAA80,0x0000,0x0002,0xBFFF,0xFB00,
  105.        0x9555,0x5540,0x0000,0x0555,0x7FFF,0xF700,
  106.        0xAAAA,0xAA80,0x0002,0xAAAA,0xBFFF,0xEB00,
  107.        0x9555,0x5540,0x0555,0x5555,0x7FFF,0xF700,
  108.        0xAAAA,0xAA82,0xAAAA,0xAAAA,0xBFFF,0xEB00,
  109.        0x9555,0x5555,0x5555,0x5555,0x5FFF,0xD700,
  110.        0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xBFFF,0xAB00,
  111.        0x9555,0x5555,0x5555,0x5555,0x5FFF,0xD700,
  112.        0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xBFFF,0xAB00,
  113.        0x9555,0x5555,0x5555,0x5555,0x5FEA,0xD700,
  114.        0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xD555,0x2B00,
  115.        0x9555,0x5555,0x5555,0x56AA,0xAA55,0x5700,
  116.        0xAAAA,0xAAAA,0xAAAB,0x5555,0x56AA,0xAB00,
  117.        0x9555,0x5555,0x5555,0x5555,0x5555,0x5700,
  118.        0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xAAAA,0xAB00,
  119.        0xBFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFF00,
  120.        0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFF00,
  121.     },{
  122.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  123.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  124.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  125.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  126.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  127.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  128.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  129.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  130.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  131.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  132.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  133.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  134.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  135.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  136.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  137.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  138.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  139.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  140.        0x0000,0x0000,0x0000,0xA000,0x0000,0x0000,
  141.        0x0000,0x0000,0x0055,0x5501,0x0000,0x0000,
  142.        0x0000,0x0000,0x7FFF,0xFAAA,0x8000,0x0000,
  143.        0x0000,0x000F,0xFFFF,0xF555,0x0000,0x0000,
  144.        0x0000,0x0FFF,0xFFFF,0xFAAA,0x8000,0x0000,
  145.        0x0000,0x1FFF,0xFFFF,0xFF55,0x4000,0x0000,
  146.        0x0000,0x0FFF,0xFFFF,0xFFAA,0xA000,0x0000,
  147.        0x0000,0x07FF,0xFFFF,0xFFD5,0x5000,0x0000,
  148.        0x0000,0x0FFF,0xFFFF,0xFFEA,0xA000,0x0000,
  149.        0x0000,0x07FF,0xFFFF,0xFFF5,0x5000,0x0000,
  150.        0x0000,0x0FFF,0xFFFF,0xFFFA,0xA800,0x0000,
  151.        0x0000,0x07FF,0xFFFF,0xFFFD,0x5400,0x0000,
  152.        0x0000,0x0FFF,0xFFFF,0xFFFE,0xAA00,0x0000,
  153.        0x0000,0x07FF,0xFFFF,0xFFFF,0x5500,0x0000,
  154.        0x0000,0x0FFF,0xFFFF,0xFFFE,0xAA00,0x0000,
  155.        0x0000,0x07FF,0xFFFF,0xFFFF,0x5500,0x0000,
  156.        0x0000,0x0FFF,0xFFFF,0xFFFF,0xAA80,0x0000,
  157.        0x0000,0x07FF,0xFFFF,0xFFFF,0xD540,0x0000,
  158.        0x0000,0x0FFF,0xFFFF,0xFFFF,0xEAA0,0x0000,
  159.        0x0000,0x07FF,0xFFFF,0xFFFF,0xD540,0x0000,
  160.        0x0000,0x0FFF,0xFFFF,0xFFFF,0xEEA0,0x0000,
  161.        0x0000,0x07FF,0xFFFF,0xFFFF,0xFD50,0x0000,
  162.        0x0000,0x0FFF,0xFFFF,0xE7FF,0xFEA8,0x0000,
  163.        0x0000,0x07FF,0xFFFF,0xC0FF,0xFD54,0x0000,
  164.        0x0000,0x0FE3,0xFFE7,0x0FFF,0xFAAA,0x0000,
  165.        0x0000,0x07C0,0xFFE0,0x3FFF,0xF554,0x0000,
  166.        0x0000,0x0F80,0x71F8,0x03FF,0xFAB8,0x0000,
  167.        0x0000,0x067E,0x0FFE,0x00FF,0xF55E,0x0000,
  168.        0x0000,0x03FF,0xBFFC,0x007F,0xEABE,0x0000,
  169.        0x0000,0x01F0,0x1FFC,0x007F,0xF55E,0x0000,
  170.        0x0000,0x00E0,0x0FFC,0x007F,0xEABE,0x0000,
  171.        0x0000,0x0040,0x07FC,0x007F,0xF55E,0x0000,
  172.        0x0000,0x00C0,0x07FE,0x00FF,0xFABE,0x0000,
  173.        0x0000,0x0040,0x07FF,0xC7FF,0xFF5C,0x0000,
  174.        0x0000,0x0020,0x0FFF,0xFEAA,0xAAAC,0x0000,
  175.        0x0000,0x0070,0x1FFF,0xD555,0x5556,0x0000,
  176.        0x0000,0x0038,0x3FFF,0xFFFA,0xAAAE,0x0000,
  177.        0x0000,0x001F,0xD7FF,0xFFFD,0x5557,0x0000,
  178.        0x0000,0x003A,0xAFFF,0xFFFE,0xAAAA,0x0000,
  179.        0x0000,0x0055,0x5FFF,0xFFFF,0x5555,0x0000,
  180.        0x0000,0x00AF,0xFFFF,0xFFFE,0xAAAA,0x8000,
  181.        0x0000,0x01FF,0xFFFF,0xFFFF,0x5555,0x4000,
  182.        0x0000,0x03FF,0xFFE0,0x7FFF,0xAAAA,0x8000,
  183.        0x0000,0x01FF,0xFF00,0x01FF,0xD555,0x4000,
  184.        0x0000,0x00FF,0xF800,0x000F,0xAAAA,0xA000,
  185.        0x0000,0x01FF,0xE000,0x000F,0xD555,0x4000,
  186.        0x0000,0x00FF,0xC000,0x007F,0xEAAA,0xA000,
  187.        0x0000,0x007F,0x0003,0xFFFF,0xF555,0x5000,
  188.        0x0000,0x00FC,0x003F,0xFFFF,0xFAAA,0xA800,
  189.        0x0000,0x0078,0x03FF,0xFFFF,0xF000,0x0000,
  190.        0x0000,0x0038,0x0FFF,0xFFFF,0xE000,0x0000,
  191.        0x0000,0x007C,0x3FFF,0xFFFF,0xE000,0x0000,
  192.        0x0000,0x003E,0xFFFF,0xFFFF,0xC000,0x0000,
  193.        0x0000,0x007F,0xFFFF,0xFFFD,0x4000,0x0000,
  194.        0x0000,0x003F,0xFFFF,0xFAAA,0x8000,0x0000,
  195.        0x0000,0x007F,0xFFFD,0x5555,0x4000,0x0000,
  196.        0x0000,0x003F,0xFAAA,0xAAAA,0x8000,0x0000,
  197.        0x0000,0x007D,0x5555,0x5555,0x4000,0x0000,
  198.        0x0000,0x00AA,0xAAAA,0xAAAA,0xA000,0x0000,
  199.        0x0000,0x0055,0x5555,0x5555,0x4000,0x0000,
  200.        0x0000,0x002A,0xAAAA,0xAAAA,0xA000,0x0000,
  201.        0x0000,0x0015,0x5555,0x5555,0x4000,0x0000,
  202.        0x0000,0x000A,0xAAAA,0xAAAA,0xA03F,0x8000,
  203.        0x0000,0x0005,0x5555,0x5555,0x7FFF,0x8000,
  204.        0x0000,0x0002,0xAAAA,0xABFF,0xFF00,0x0000,
  205.        0x0000,0x0001,0x5555,0xFFFF,0xFC00,0x0000,
  206.        0x0000,0x0000,0xAAAA,0x0000,0x0000,0x0000,
  207.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  208.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  209.        0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  210.    }
  211. };
  212.  
  213.  
  214. USHORT (*Eyemap_chip);                         /* Eye */
  215. USHORT Eyemap [4] = {
  216.         0x6000,
  217.         0xf000,
  218.         0xf000,
  219.         0x6000
  220. };
  221.  
  222. static struct Gadget gadget =          /* Used to move and quit */
  223. { NULL,
  224.   0, 0, 0, 0,
  225.   GADGHNONE|GRELWIDTH|GRELHEIGHT,
  226.   GADGIMMEDIATE|RELVERIFY,
  227.   WDRAGGING,
  228.   NULL,
  229.   NULL,
  230.   NULL,
  231.   NULL,
  232.   NULL,
  233.   0, 0
  234. };
  235.  
  236. static struct NewWindow IconNW =       /* The window */
  237. { 351, 11,
  238.   88, 88,
  239.   -1, -1,
  240.   GADGETDOWN,
  241.   RMBTRAP|BORDERLESS|SMART_REFRESH|NOCAREREFRESH,
  242.   &gadget,
  243.   NULL,
  244.   NULL,
  245.   NULL,
  246.   NULL,
  247.   0, 0, 0, 0,
  248.   WBENCHSCREEN
  249. };
  250.  
  251. struct Window *win, *OpenWindow();
  252.  
  253. OpenStuff () {
  254.         int i,j;
  255.         extern USHORT *Eyemap_chip;
  256.         extern USHORT *Manmap_chip[];
  257.         PLANEPTR pl;
  258.  
  259.         if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.li
  260. rary", 0L)))
  261.                 CloseStuff (1);
  262.         if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L)))
  263.                 CloseStuff (1);
  264.         if (!(win = OpenWindow (&IconNW)))
  265.                 CloseStuff (1);
  266.         if ((Eyemap_chip = AllocMem((LONG)sizeof(Eyemap),MEMF_CHIP))== 0) 
  267.                CloseStuff (1);   /* allocate chip memory for images */
  268.         for (i=0 ; i < 4 ;i++) {
  269.                 Eyemap_chip[i] = Eyemap[i];
  270.         }
  271.         if ((Manmap_chip[0] = AllocMem((LONG)sizeof(Manmap[0]),MEMF_CHIP)) == N
  272. LL)
  273.              CloseStuff (1);
  274.         if ((Manmap_chip[1] = AllocMem((LONG)sizeof(Manmap[1]),MEMF_CHIP)) == N
  275. LL)
  276.              CloseStuff (1);
  277.  
  278.         for (i=0 ; i < 528 ;i++) {
  279.                 Manmap_chip[0][i] = Manmap[0][i];
  280.                 Manmap_chip[1][i] = Manmap[1][i];
  281.         }
  282.         SetAPen(win->RPort, 1L);
  283.         SetDrMd(win->RPort, JAM1);
  284.         BltTemplate(Manmap_chip[0], 0L, 12L, win->RPort, 0L, 0L, 88L, 88L);
  285.         SetAPen(win->RPort, 2L);
  286.        SetWrMsk(win->RPort, 2L);       /* Braindead COMPLEMENT */
  287.         BltTemplate(Manmap_chip[1], 0L, 12L, win->RPort, 0L, 0L, 88L, 88L);
  288.         SetWrMsk(win->RPort, 255L);     /* Braindead COMPLEMENT */
  289.         if (!(timerport = CreatePort(NULL, 0L))
  290.             || !(timermsg = CreateStdIO(timerport))
  291.             || OpenDevice(TIMERNAME,UNIT_VBLANK, timermsg, 0L))
  292.                 CloseStuff(1);
  293. }
  294.  
  295. CloseStuff (exitcode)
  296. int exitcode; 
  297. {
  298.         if (timermsg)       {
  299.                 CloseDevice(timermsg);
  300.                 DeleteStdIO(timermsg);
  301.         }
  302.         if (timerport)          DeletePort(timerport);
  303.         if (win)                CloseWindow(win);
  304.         if (IntuitionBase)      CloseLibrary(IntuitionBase);
  305.         if (GfxBase)            CloseLibrary(GfxBase);
  306.         if (Eyemap_chip)        FreeMem(Eyemap_chip, (LONG)sizeof(Eyemap));
  307.         if (Manmap_chip[0])     FreeMem(Manmap_chip[0], (LONG)sizeof(Manmap[0])
  308. ;
  309.         if (Manmap_chip[1])     FreeMem(Manmap_chip[1], (LONG)sizeof(Manmap[1])
  310. ;
  311.         exit (exitcode);
  312. }
  313.  
  314. /* Hmm, this seems to work - a bit strange, but it works... */
  315. #define ABS(x) (x<0 ? -x : x)
  316. #define index(x,y)   (((y<0)<<2) + ((x<0)<<1) + (ABS(x)>ABS(y)))
  317.  
  318. /****************************************************************
  319. *      Draw the eye at OffX, OffY but with an extra offset
  320. *      given by idx in a direct[]-table.
  321. *      col is used to erase/draw.
  322. */
  323.  
  324. void DrawEye(idx, OffX, OffY, col)
  325. int idx, OffX, OffY, col;
  326. {
  327.         static int direct[2][8] = {
  328.                 { 1, 2,-1,-2, 1, 2,-1,-2},
  329.                 { 2, 1, 2, 1,-2,-1,-2,-1}};
  330.  
  331.         SetAPen(win->RPort, (LONG)col);
  332.         BltTemplate(Eyemap_chip, 0L, 2L, win->RPort,
  333.                 (LONG)(OffX + direct[0][idx&7]), 
  334.                 (LONG)(OffY + direct[1][idx&7]), 4L, 4L);
  335. }
  336.  
  337. /****************************************************************
  338. *      Get mouse position relative to windows upper left corner.
  339. *      (A lot easier than I thought...) A very nice programmer
  340. *      probably would get the mouse coords in another way, but
  341. *      I'm not very paranoid...
  342. */
  343.  
  344. void GetRelMp(x,y)
  345. int *x,*y;
  346. {
  347.         *x = win->WScreen->MouseX - win->LeftEdge;
  348.         *y = win->WScreen->MouseY - win->TopEdge;
  349. }
  350.  
  351. /****************************************************************
  352. *      The main loop. Ok, I COULD do the timer and intuimsgs
  353. *      in a nicer way, but it wouldn't make much of a difference
  354. *      so why bother?
  355. */
  356.  
  357. _main ()
  358. {
  359.     ULONG msgclass;            /* Message class from Intuition message */
  360.     struct IntuiMessage *msg;  /* The msg we got */
  361.     int Mx, My,                        /* Mouse's current relative offset */ 
  362.        LastL, LastR,           /* Last index for left&right Eye */
  363.        NewL, NewR;             /* New index    --   ""   --     */
  364.     ULONG PrevSecs, PrevMics;  /* Time of last click */
  365.  
  366.     /* Init */
  367.     OpenStuff ();
  368.     DrawEye(LastL, Lx, Ly, 1);
  369.     DrawEye(LastR, Rx, Ry, 1);
  370.  
  371.     for(;;) {
  372.         timermsg->io_Command = TR_ADDREQUEST;   /* add a new timer request */
  373.         timermsg->io_Actual = 0;                /* seconds */
  374.         timermsg->io_Length = 100000;           /* microseconds */
  375.         DoIO(timermsg);                         /* Wait for a while... */
  376.         while(msg = (struct IntuiMessage *)GetMsg(win->UserPort)) {    
  377.             /* User action */
  378.             msgclass = msg->Class;
  379.             ReplyMsg (msg);
  380.             switch (msgclass) {
  381.             case GADGETDOWN:
  382.                 if (DoubleClick(PrevSecs, PrevMics, msg->Seconds, msg->Micros))
  383.                     CloseStuff(0);
  384.                 else {
  385.                     PrevSecs = msg->Seconds;
  386.                     PrevMics = msg->Micros;
  387.                 }
  388.             }
  389.         }
  390.         GetRelMp(&Mx, &My);                      /* Action ! */
  391.         if (LastL != (NewL = index(Mx - Lx, My - Ly))) {
  392.             DrawEye(LastL, Lx, Ly, 0);
  393.             DrawEye(LastL=NewL, Lx, Ly, 1);
  394.         }
  395.         if (LastR != (NewR = index(Mx - Rx, My - Ry))) {
  396.             DrawEye(LastR, Rx, Ry, 0);
  397.             DrawEye(LastR=NewR, Rx, Ry, 1);
  398.         }
  399.     }
  400. }
  401.