Home | History | Annotate | Line # | Download | only in obio
asc.c revision 1.13
      1 /*	$NetBSD: asc.c,v 1.13 1996/10/13 03:21:15 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1993	Allen K. Briggs, Chris P. Caputo,
      5  *			Michael L. Finch, Bradley A. Grantham, and
      6  *			Lawrence A. Kesteloot
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the Alice Group.
     20  * 4. The names of the Alice Group or any of its members may not be used
     21  *    to endorse or promote products derived from this software without
     22  *    specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 /*
     37  * ASC driver code and asc_ringbell() support
     38  */
     39 
     40 #include <sys/types.h>
     41 #include <sys/cdefs.h>
     42 #include <sys/errno.h>
     43 #include <sys/time.h>
     44 #include <sys/systm.h>
     45 #include <sys/param.h>
     46 #include <sys/device.h>
     47 #include <machine/cpu.h>
     48 
     49 #include "ascvar.h"
     50 
     51 /* Global ASC location */
     52 volatile unsigned char *ASCBase = (unsigned char *) 0x14000;
     53 
     54 
     55 /* bell support data */
     56 static int bell_freq = 1880;
     57 static int bell_length = 10;
     58 static int bell_volume = 100;
     59 static int bell_ringing = 0;
     60 
     61 static int  ascmatch __P((struct device *, void *, void *));
     62 static void ascattach __P((struct device *, struct device *, void *));
     63 
     64 struct cfattach asc_ca = {
     65 	sizeof(struct device), ascmatch, ascattach
     66 };
     67 
     68 struct cfdriver asc_cd = {
     69 	NULL, "asc", DV_DULL, NULL, 0
     70 };
     71 
     72 static int
     73 ascmatch(pdp, match, auxp)
     74 	struct device	*pdp;
     75 	void	*match, *auxp;
     76 {
     77 	return 1;
     78 }
     79 
     80 static void
     81 ascattach(parent, dev, aux)
     82 	struct device *parent, *dev;
     83 	void   *aux;
     84 {
     85 	printf(" Apple sound chip.\n");
     86 }
     87 
     88 int
     89 asc_setbellparams(freq, length, volume)
     90     int freq;
     91     int length;
     92     int volume;
     93 {
     94 	/* I only perform these checks for sanity. */
     95 	/* I suppose someone might want a bell that rings */
     96 	/* all day, but then the can make kernel mods themselves. */
     97 
     98 	if (freq < 10 || freq > 40000)
     99 		return (EINVAL);
    100 	if (length < 0 || length > 3600)
    101 		return (EINVAL);
    102 	if (volume < 0 || volume > 100)
    103 		return (EINVAL);
    104 
    105 	bell_freq = freq;
    106 	bell_length = length;
    107 	bell_volume = volume;
    108 
    109 	return (0);
    110 }
    111 
    112 
    113 int
    114 asc_getbellparams(freq, length, volume)
    115     int *freq;
    116     int *length;
    117     int *volume;
    118 {
    119 	*freq = bell_freq;
    120 	*length = bell_length;
    121 	*volume = bell_volume;
    122 
    123 	return (0);
    124 }
    125 
    126 
    127 void
    128 asc_bellstop(param)
    129     int param;
    130 {
    131 	if (bell_ringing > 1000 || bell_ringing < 0)
    132 		panic("bell got out of synch?????");
    133 	if (--bell_ringing == 0) {
    134 		ASCBase[0x801] = 0;
    135 	}
    136 	/* disable ASC */
    137 }
    138 
    139 
    140 int
    141 asc_ringbell()
    142 {
    143 	int     i;
    144 	unsigned long freq;
    145 
    146 	if (bell_ringing == 0) {
    147 		for (i = 0; i < 0x800; i++)
    148 			ASCBase[i] = 0;
    149 
    150 		for (i = 0; i < 256; i++) {
    151 			ASCBase[i] = i / 4;
    152 			ASCBase[i + 512] = i / 4;
    153 			ASCBase[i + 1024] = i / 4;
    154 			ASCBase[i + 1536] = i / 4;
    155 		}		/* up part of wave, four voices ? */
    156 		for (i = 0; i < 256; i++) {
    157 			ASCBase[i + 256] = 0x3f - (i / 4);
    158 			ASCBase[i + 768] = 0x3f - (i / 4);
    159 			ASCBase[i + 1280] = 0x3f - (i / 4);
    160 			ASCBase[i + 1792] = 0x3f - (i / 4);
    161 		}		/* down part of wave, four voices ? */
    162 
    163 		/* Fix this.  Need to find exact ASC sampling freq */
    164 		freq = 65536 * bell_freq / 466;
    165 
    166 		/* printf("beep: from %d, %02x %02x %02x %02x\n",
    167 		 * cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
    168 		 * (freq >> 8) & 0xff, (freq) & 0xff); */
    169 		for (i = 0; i < 8; i++) {
    170 			ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
    171 			ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
    172 			ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
    173 			ASCBase[0x817 + 8 * i] = (freq) & 0xff;
    174 		}		/* frequency; should put cur_beep.freq in here
    175 				 * somewhere. */
    176 
    177 		ASCBase[0x807] = 3;	/* 44 ? */
    178 		ASCBase[0x806] = 255 * bell_volume / 100;
    179 		ASCBase[0x805] = 0;
    180 		ASCBase[0x80f] = 0;
    181 		ASCBase[0x802] = 2;	/* sampled */
    182 		ASCBase[0x801] = 2;	/* enable sampled */
    183 	}
    184 	bell_ringing++;
    185 	timeout((void *) asc_bellstop, 0, bell_length);
    186 
    187 	return 0;
    188 }
    189