home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / sound_falcon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  3.5 KB  |  176 lines

  1.  
  2. #include "config.h"
  3.  
  4. #ifdef DMASOUND
  5. #include <osbind.h>
  6. #include "pokey23.h"
  7.  
  8. static char *rcsid = "$Id: sound_falcon.c,v 1.2 1998/02/21 15:00:23 david Exp $";
  9.  
  10. #define FALSE 0
  11. #define TRUE 1
  12.  
  13. extern int get_cookie(long cookie, long *value);
  14.  
  15. static char *dsp_buffer1, *dsp_endbuf1;
  16. static char *dsp_buffer2, *dsp_endbuf2;
  17.  
  18. static sound_enabled = FALSE;
  19.  
  20. static int dsp_sample_rate = 12517;
  21. static int sndbufsize = 600;
  22. static int AUDCTL = 0x00;
  23. static int AUDF[4] =
  24. {0, 0, 0, 0};
  25. static int AUDC[4] =
  26. {0, 0, 0, 0};
  27.  
  28. /* Atari DMA sound hardware */
  29. extern void timer_A(void);
  30.  
  31. #ifndef UBYTE
  32. #define UBYTE    unsigned char
  33. #endif
  34.  
  35. #define    TIMERA        *(long *)0x134
  36.  
  37. #define    TACTRL        *(UBYTE *)0xFFFA19
  38. #define    TADATA        *(UBYTE *)0xFFFA1F
  39.  
  40. #define    IEA            *(UBYTE *)0xFFFA07
  41. #define    ISRA        *(UBYTE *)0xFFFA0F
  42. #define    IMA            *(UBYTE *)0xFFFA13
  43. #define IVECTOR        *(UBYTE *)0xFFFA17
  44.  
  45. long old_timer_A;
  46. UBYTE old_tactrl, old_tadata, old_ivector, old_iea, old_isra, old_ima;
  47. short *DMActrlptr = (short *) 0xff8900;
  48.  
  49. void Setbuffer(long bufbeg, long bufsize)
  50. {
  51.     long bufend = bufbeg + bufsize;
  52.     DMActrlptr[1] = (bufbeg >> 16) & 0xff;
  53.     DMActrlptr[2] = (bufbeg >> 8) & 0xff;
  54.     DMActrlptr[3] = bufbeg & 0xff;
  55.     DMActrlptr[7] = (bufend >> 16) & 0xff;
  56.     DMActrlptr[8] = (bufend >> 8) & 0xff;
  57.     DMActrlptr[9] = bufend & 0xff;
  58. }
  59.  
  60. void timer_A_v_C(void)
  61. {
  62.     static int first = FALSE;    /* start computing second buffer */
  63.  
  64.     if (first) {
  65.         Setbuffer(dsp_buffer1, sndbufsize);        /* set next DMA buffer */
  66.         Pokey_process(dsp_buffer1, sndbufsize);        /* quickly compute it */
  67.         first = FALSE;
  68.     }
  69.     else {
  70.         Setbuffer(dsp_buffer2, sndbufsize);
  71.         Pokey_process(dsp_buffer2, sndbufsize);
  72.         first = TRUE;
  73.     }
  74. }
  75.  
  76. void MFP_IRQ_on(void)
  77. {
  78.     Setbuffer(dsp_buffer1, sndbufsize);        /* start playing first buffer */
  79.     DMActrlptr[0x10] = 0x80 | 1;    /* mono 12 kHz */
  80.     DMActrlptr[0] = 0x400 | 3;    /* play until stopped, interrupt at end of frame */
  81.  
  82.     Mfpint(13, timer_A);
  83.     Xbtimer(0, 8, 1, timer_A);    /* event count mode, interrupt after 1st frame */
  84.     IVECTOR &= ~(1 << 3);        /* turn on AEO */
  85.     Jenabint(13);
  86. }
  87.  
  88. void MFP_IRQ_off(void)
  89. {
  90.     Jdisint(13);
  91.     DMActrlptr[0] = 0;            /* stop playing */
  92. }
  93.  
  94. void Sound_Initialise(int *argc, char *argv[])
  95. {
  96.     int i, j;
  97.  
  98.     for (i = j = 1; i < *argc; i++) {
  99.         if (strcmp(argv[i], "-sound") == 0)
  100.             sound_enabled = TRUE;
  101.         else if (strcmp(argv[i], "-nosound") == 0)
  102.             sound_enabled = FALSE;
  103.         else
  104.             argv[j++] = argv[i];
  105.     }
  106.  
  107.     *argc = j;
  108.  
  109.     /* test of Sound hardware availability */
  110.     if (sound_enabled) {
  111.         long val;
  112.  
  113.         if (get_cookie('_SND', &val)) {
  114.             if (!(val & 2))
  115.                 sound_enabled = FALSE;    /* Sound DMA hardware is missing */
  116.         }
  117.         else
  118.             sound_enabled = FALSE;    /* CookieJar is missing */
  119.     }
  120.  
  121.     if (sound_enabled) {
  122.         dsp_buffer1 = (char *) Mxalloc(2 * sndbufsize, 0);
  123.         dsp_buffer2 = dsp_endbuf1 = dsp_buffer1 + sndbufsize;
  124.         dsp_endbuf2 = dsp_buffer2 + sndbufsize;
  125.         memset(dsp_buffer1, 0, sndbufsize);
  126.         memset(dsp_buffer2, 127, sndbufsize);
  127.         if (!dsp_buffer1) {
  128.             printf("can't allocate sound buffer\n");
  129.             exit(1);
  130.         }
  131.  
  132.         Pokey_sound_init(FREQ_17_EXACT, dsp_sample_rate, 1);
  133.         Supexec(MFP_IRQ_on);
  134.     }
  135. }
  136.  
  137. void Sound_Exit(void)
  138. {
  139.     if (sound_enabled) {
  140.         Supexec(MFP_IRQ_off);
  141.         Mfree(dsp_buffer1);
  142.     }
  143. }
  144.  
  145. void Atari_AUDC(int channel, int byte)
  146. {
  147.     channel--;
  148.     Update_pokey_sound(0xd201 + channel + channel, byte, 0, 4);
  149. }
  150.  
  151. void Atari_AUDF(int channel, int byte)
  152. {
  153.     channel--;
  154.     Update_pokey_sound(0xd200 + channel + channel, byte, 0, 4);
  155. }
  156.  
  157. void Atari_AUDCTL(int byte)
  158. {
  159.     Update_pokey_sound(0xd208, byte, 0, 4);
  160. }
  161.  
  162. #else
  163. void Atari_AUDC(int channel, int byte)
  164. {
  165. }
  166.  
  167. void Atari_AUDF(int channel, int byte)
  168. {
  169. }
  170.  
  171. void Atari_AUDCTL(int byte)
  172. {
  173. }
  174.  
  175. #endif
  176.