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

  1. #include <exec/types.h>
  2. #include <functions.h>
  3. #include <exec/memory.h>
  4. #include <exec/interrupts.h>
  5. #include <hardware/custom.h>
  6. #include <hardware/intbits.h>
  7. #include <libraries/dos.h>
  8. #include <stdio.h>
  9.  
  10. #define LVODisplayBeep -96
  11.  
  12. long beep_sigbit = 0;
  13. long beep_sigmask = 0;
  14. struct Task *chatterbox_task = NULL;
  15.  
  16. extern struct IntuitionBase *IntuitionBase;
  17.  
  18. extern struct gab_info gab_data[N_GAB_TYPES];
  19.  
  20. void (*OldBeep)() = NULL;
  21.  
  22. MyBeep()
  23. {
  24.     assert((chatterbox_task != 0) && (beep_sigmask != 0));
  25.  
  26.     Signal(chatterbox_task,beep_sigmask);
  27. }
  28.  
  29. CleanupSignals()
  30. {
  31.     if (beep_sigbit)
  32.         FreeSignal(beep_sigbit);
  33.  
  34.     if (OldBeep)
  35.         SetFunction(IntuitionBase,LVODisplayBeep,OldBeep);
  36. }
  37.  
  38. /* Intuition library must have been opened before calling!
  39.  * Config() must have run before calling to initialize the
  40.  * number of samples that are to be called if beep is defined
  41.  * in the config file.  If no samples are assigned to beep,
  42.  * we do not replace the DisplayBeep function!
  43.  */
  44. InitSignals()
  45. {
  46.  
  47.     assert(IntuitionBase);
  48.  
  49.     add_cleanup(CleanupSignals);
  50.  
  51.     /* allocate a signal */
  52.     if ((beep_sigbit = AllocSignal(-1L)) < 0)
  53.         panic("can't alloc signal");
  54.  
  55.     /* precompute the mask and store for convenience */
  56.     beep_sigmask = (1 << beep_sigbit);
  57.  
  58.     /* get the task ID */
  59.     chatterbox_task = FindTask(NULL);
  60.  
  61.     /* replace DisplayBeep with our beep routine, saving
  62.      * the old vector so we can replace it when we leave
  63.      */
  64.     if (gab_data[GAB_BEEP].n_gab_items > 0)
  65.         OldBeep = SetFunction(IntuitionBase,LVODisplayBeep,MyBeep);
  66. }
  67.  
  68.