asc.c revision 1.3 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.3 1994/05/06 17:38:38 briggs Exp $
40 *
41 * 12/12/93 01:14:45 grantham
42 * initial revision
43 *
44 * $Log: asc.c,v $
45 * Revision 1.3 1994/05/06 17:38:38 briggs
46 * Missed some warnings...
47 *
48 * Revision 1.2 1994/05/06 03:34:53 briggs
49 * Clean up some warnings, mainly w/ timeout().
50 *
51 * Revision 1.1 1993/12/21 03:16:05 briggs
52 * Add basic sound support and a beeping (instead of flashing) console...
53 * from Brad Grantham.
54 *
55 */
56
57
58 #include <sys/types.h>
59 #include <sys/errno.h>
60 #include <sys/time.h>
61 #include <sys/systm.h>
62 #include <sys/param.h>
63
64
65 /* Global ASC location */
66 unsigned char *ASCBase = (unsigned char *)0x50014000;
67
68
69 /* bell support data */
70 static int bell_freq = 1880;
71 static int bell_length = 10;
72 static int bell_volume = 100;
73 static int bell_ringing = 0;
74
75
76 #if 0
77
78
79 int asc_probe()
80 {
81 }
82
83
84 int asc_attach(int n)
85 {
86 /* Check gestalt values and set ASCBase properly, */
87 /* or use value from MacOS */
88 }
89
90
91 #endif
92
93
94
95 int asc_setbellparams(
96 int freq,
97 int length,
98 int volume)
99 {
100 /* I only perform these checks for sanity. */
101 /* I suppose someone might want a bell that rings */
102 /* all day, but then the can make kernel mods themselves. */
103
104 if(freq < 10 || freq > 40000)
105 return(EINVAL);
106 if(length < 0 || length > 3600)
107 return(EINVAL);
108 if(volume < 0 || volume > 100)
109 return(EINVAL);
110
111 bell_freq = freq;
112 bell_length = length;
113 bell_volume = volume;
114
115 return(0);
116 }
117
118
119 int asc_getbellparams(
120 int *freq,
121 int *length,
122 int *volume)
123 {
124 *freq = bell_freq;
125 *length = bell_length;
126 *volume = bell_volume;
127
128 return(0);
129 }
130
131
132 void asc_bellstop(
133 int param)
134 {
135 if(bell_ringing > 1000 || bell_ringing < 0)
136 panic("bell got out of synch?????");
137 if(--bell_ringing == 0){
138 ASCBase[0x801] = 0;
139 }
140 /* disable ASC */
141 }
142
143
144 int asc_ringbell()
145 {
146 int i;
147 unsigned long freq;
148
149 if(bell_ringing == 0){
150 for(i = 0; i < 0x800; i++)
151 ASCBase[i] = 0;
152
153 for(i = 0; i < 256;i++){
154 ASCBase[i] = i / 4;
155 ASCBase[i + 512] = i / 4;
156 ASCBase[i + 1024] = i / 4;
157 ASCBase[i + 1536] = i / 4;
158 }/* up part of wave, four voices ? */
159 for(i = 0; i < 256;i++){
160 ASCBase[i + 256] = 0x3f - (i / 4);
161 ASCBase[i + 768] = 0x3f - (i / 4);
162 ASCBase[i + 1280] = 0x3f - (i / 4);
163 ASCBase[i + 1792] = 0x3f - (i / 4);
164 }/* down part of wave, four voices ? */
165
166 /* Fix this. Need to find exact ASC sampling freq */
167 freq = 65536 * bell_freq / 466;
168
169 /* printf("beep: from %d, %02x %02x %02x %02x\n", cur_beep.freq,
170 (freq >> 24) & 0xff, (freq >> 16) & 0xff,
171 (freq >> 8) & 0xff, (freq) & 0xff);*/
172 for(i = 0; i < 8; i++){
173 ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
174 ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
175 ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
176 ASCBase[0x817 + 8 * i] = (freq) & 0xff;
177 }/* frequency; should put cur_beep.freq in here somewhere. */
178
179 ASCBase[0x807] = 3; /* 44 ? */
180 ASCBase[0x806] = 255 * bell_volume / 100;
181 ASCBase[0x805] = 0;
182 ASCBase[0x80f] = 0;
183 ASCBase[0x802] = 2; /* sampled */
184 ASCBase[0x801] = 2; /* enable sampled */
185 }
186
187 bell_ringing++;
188 timeout((void *) asc_bellstop, 0, bell_length);
189 }
190