Add hooks for custom audio players. This is the original untouched
authorniklas <niklas@openbsd.org>
Sun, 14 Jan 1996 16:05:23 +0000 (16:05 +0000)
committerniklas <niklas@openbsd.org>
Sun, 14 Jan 1996 16:05:23 +0000 (16:05 +0000)
kernel diffs from Tim Newsham <newsham@hookomo.aloha.net> found in his
well-known audio LKM kit.

sys/arch/amiga/amiga/cc.c
sys/arch/amiga/amiga/cc.h

index 2d2ba1a..1bf1b4c 100644 (file)
@@ -323,12 +323,13 @@ copper_handler()
  */
 
 struct audio_channel {
-       u_short  play_count;
+       u_short  play_count;            /* number of times to loop sample */
+       handler_func_t handler;         /* interupt handler for channel */
 };
 
 /* - channel[4] */
 /* the data for each audio channel and what to do with it. */
-static struct audio_channel channel[4];
+struct audio_channel channel[4];
 
 /* audio vbl node for vbl function  */
 struct vbl_node audio_vbl_node;    
@@ -337,6 +338,7 @@ void
 cc_init_audio()
 {
        int i;
+       extern int defchannel_handler();
 
        /*
         * disable all audio interupts
@@ -346,8 +348,10 @@ cc_init_audio()
        /*
         * initialize audio channels to off.
         */
-       for (i=0; i < 4; i++)
+       for (i=0; i < 4; i++) {
                channel[i].play_count = 0;
+               channel[i].handler = defchannel_handler;
+       }
 }
 
 
@@ -393,22 +397,14 @@ audio_handler()
                if ((ir & (flag << 7)) == 0)
                        continue;
 
-               if (channel[i].play_count)
-                       channel[i].play_count--;
-               else {
-                       /*
-                        * disable DMA to this channel and
-                        * disable interrupts to this channel
-                        */
-                       custom.dmacon = flag;
-                       custom.intena = (flag << 7);
-               }
+               if (channel[i].handler)
+                       channel[i].handler(i);
+
                /*
                 * clear this channels interrupt.
                 */
                custom.intreq = (flag << 7);
        }
-
 out:
        /*
         * enable audio interupts with dma still set.
@@ -418,6 +414,26 @@ out:
        custom.intena = INTF_SETCLR | (audio_dma << 7);
 }
 
+/*
+ * this is the channel handler used by the system
+ * other software modules are free to install their own
+ * handler
+ */
+defchannel_handler(i)
+       int i;
+{
+       if (channel[i].play_count)
+               channel[i].play_count--;
+       else {
+               /*
+                * disable DMA to this channel and
+                * disable interrupts to this channel
+                */
+               custom.dmacon = (1 << i);
+               custom.intena = (1 << (i + 7));
+       }
+}
+
 void
 play_sample(len, data, period, volume, channels, count)
        u_short len, *data, period, volume, channels;
@@ -430,13 +446,16 @@ play_sample(len, data, period, volume, channels, count)
 
        /* load the channels */
        for (ch = 0; ch < 4; ch++) {
-               if ((dmabits & (ch << ch)) == 0)
+               if ((dmabits & (1 << ch)) == 0)
                        continue;
-               custom.aud[ch].len = len;
-               custom.aud[ch].lc = data;
+               /* busy */
+               if (channel[ch].handler != defchannel_handler)
+                       continue;
+               channel[ch].play_count = count;
                custom.aud[ch].per = period;
                custom.aud[ch].vol = volume;
-               channel[ch].play_count = count;
+               custom.aud[ch].len = len;
+               custom.aud[ch].lc = data;
        }
        /*
         * turn on interrupts and enable dma for channels and
index 3b85f8f..29464e7 100644 (file)
@@ -147,6 +147,8 @@ vm_offset_t chipmem_end;
 #define CHIPMEMTOP     (0x00200000)
 #define NCHIPMEMPG     btoc(CHIPMEMTOP - CHIPMEMBASE)
 
+typedef int (*handler_func_t)();
+
 /*
  * Prototypes.
  */