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