home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 287.lha / TY_v1.3 / src / bell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  2.7 KB  |  80 lines

  1. /*************************************************************************
  2.  ***                        bell.c                       (JJB TEMPLAR) ***
  3.  *** Date begun: 26/8/89.                                              ***
  4.  *** Last modified: 26/8/89.                                           ***
  5.  *************************************************************************/
  6.  
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <devices/audio.h>
  10. #include <intuition/intuition.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14.  
  15. extern struct Window    *Window;
  16. extern int              quiet;
  17.  
  18. int     audio;      /* Flag: 1 means can use audio bell */
  19. int     gotdev;     /* Flag: 1 means succeeded to open device */
  20. UBYTE   allocmap[] = {0x01,0x02,0x04,0x08};
  21. BYTE    sinedat[] = {0,90,127,90,0,-90,-127,-90};
  22.  
  23. struct IOAudio  *audIO;
  24. UBYTE           *auddat;
  25. struct MsgPort  *audport;
  26.  
  27. void    initbell();
  28. void    bell();
  29. void    freebell();
  30.  
  31. void    initbell() /*====================================================*/
  32. {
  33. register int    j;
  34.     if (quiet) return;
  35.     if (!(audIO = (struct IOAudio *)AllocMem(sizeof(*audIO),MEMF_PUBLIC|MEMF_CLEAR)))
  36.         return;     /* Failed to get IO structure */
  37.     if (!(auddat = AllocMem(sizeof(sinedat),MEMF_CHIP))) goto ERROR;
  38.  
  39.     for (j = 0; j < sizeof(sinedat); j++) auddat[j] = sinedat[j];
  40.     audIO->ioa_Length = 4;      audIO->ioa_Data = allocmap;
  41.     audIO->ioa_Request.io_Message.mn_Node.ln_Pri = 127;
  42.  
  43.     if (!(audport = CreatePort("ty audio bell",0))) goto ERROR;
  44.     audIO->ioa_Request.io_Message.mn_ReplyPort = audport;
  45.  
  46.     if (OpenDevice(AUDIONAME,0,audIO,0)) goto ERROR;
  47.     gotdev = 1;         /* So freebell() knows to close device */
  48.  
  49.     audio = 1;          /* So I know I can use the audio bell */
  50.     return;
  51. ERROR:
  52.     freebell();
  53. }
  54.  
  55. void    bell() /*========================================================*/
  56. {
  57.     if (!audio) DisplayBeep(Window->WScreen);
  58.     else {
  59.         audIO->ioa_Request.io_Command = CMD_WRITE;
  60.         audIO->ioa_Request.io_Flags = ADIOF_PERVOL;
  61.         audIO->ioa_Data = auddat;
  62.         audIO->ioa_Length = sizeof(sinedat);
  63.         audIO->ioa_Period = 447;        /* From HRM */
  64.         audIO->ioa_Volume = 64;         /* Max vol */
  65.         audIO->ioa_Cycles = 250;        /* 1 second? */
  66.         BeginIO(audIO);
  67.         if (WaitIO(audIO)) freebell();  /* Error check */
  68.     }
  69. }
  70.  
  71. void    freebell() /*====================================================*/
  72. {
  73.     if (gotdev) CloseDevice(audIO);
  74.     if (audport) DeletePort(audport);
  75.     if (auddat) FreeMem(auddat,sizeof(sinedat));
  76.     if (audIO) FreeMem(audIO,sizeof(*audIO));
  77.     gotdev = audio = 0;
  78.     audport = NULL;     auddat = NULL;      audIO = NULL;
  79. }
  80.