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