home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 348.lha / chatterbox_v1.0 / sources / loop.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  2KB  |  122 lines

  1. #include <exec/types.h>
  2. #include <exec/devices.h>
  3. #include <exec/memory.h>
  4. #include <devices/timer.h>
  5. #include <functions.h>
  6. #include <stdio.h> 
  7. #include <libraries/dos.h>
  8. #include <intuition/intuition.h>
  9.  
  10. #include "hackercore.h"
  11.  
  12. #include "chatter.h"
  13. #include "channels.h"
  14.  
  15. extern struct timerequest *CreateTimer();
  16.  
  17. struct timerequest *tr = NULL;
  18.  
  19. struct IntuiMessage *msg;
  20.  
  21. extern int gab_interval;
  22. extern int minimum_timer_interval, maximum_timer_interval;
  23.  
  24. short KeepGoing;
  25.  
  26. extern struct Window *win;
  27.  
  28. #define CheckMsg(m) (m->mp_MsgList.lh_Head->ln_Succ != 0L)
  29.  
  30. extern struct SMUS_IOAudio *SMUS_GetMsg();
  31.  
  32. extern long beep_sigmask;
  33.  
  34. loop()
  35. {
  36.     ULONG waitflags;
  37.     ULONG timermask;
  38.     struct SMUS_IOAudio *audio_msg_ptr;
  39.  
  40.     KeepGoing = YES;
  41.  
  42.     timermask = (1 << (long)tr->tr_node.io_Message.mn_ReplyPort->mp_SigBit);
  43.  
  44.     determine_and_set_wait_seconds();
  45.  
  46.     /* main loop */
  47.  
  48.     while (KeepGoing)
  49.     {
  50.         /* wait for an event */
  51.         /* (we want for -1 to reduce the overhead of looking up all our
  52.          * sigbits */
  53.  
  54.         waitflags = Wait(-1L);
  55.  
  56.         /* timer message */
  57.         if (waitflags & timermask)
  58.         {
  59.             /* if there's really a timer message */
  60.             if (GetMsg(tr->tr_node.io_Message.mn_ReplyPort) != (struct Message *)NULL) 
  61.             {
  62.                 blather(GAB_EVERY_SO_OFTEN);
  63.                 determine_and_set_wait_seconds();
  64.             }
  65.         }
  66.  
  67.         while ((audio_msg_ptr = SMUS_GetMsg()) != NULL)
  68.             StopChannelNote(audio_msg_ptr->channelp);
  69.  
  70.         if (waitflags & beep_sigmask)
  71.             blather(GAB_BEEP);
  72.  
  73.         if (waitflags & SIGBREAKF_CTRL_C)
  74.             KeepGoing = NO;
  75.  
  76.         if (CheckMsg(win->UserPort) && (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  77.         {
  78.             switch(msg->Class)
  79.             {
  80.                 case CLOSEWINDOW:
  81.                     KeepGoing = NO;
  82.                     break;
  83.  
  84.                 case NEWPREFS:
  85.                     blather(GAB_NEW_PREFERENCES);
  86.                     break;
  87.                 
  88.                 case DISKINSERTED:
  89.                     blather(GAB_DISKIN);
  90.                     break;
  91.  
  92.                 case DISKREMOVED:
  93.                     blather(GAB_DISKOUT);
  94.                     break;
  95.  
  96.                 case ACTIVEWINDOW:
  97.                     blather(GAB_WINDOWACTIVE);
  98.                     break;
  99.  
  100.                 case INACTIVEWINDOW:
  101.                     blather(GAB_WINDOWINACTIVE);
  102.                     break;
  103.  
  104.                 case MENUPICK:
  105.                     ProcessMenu(msg->Code);
  106.                     break;
  107.  
  108.                 default:
  109.                     printf("default %lx\n",msg->Class);
  110.                     break;
  111.             }
  112.             ReplyMsg(msg);
  113.         }
  114.     }
  115.     AbortIO(tr);
  116.  
  117. Quit()
  118. {
  119.     KeepGoing = NO;
  120. }
  121.