Subject: Re: misc kernel problems
To: Colin Wood <ender@is.rice.edu>
From: Scott Reynolds <scottr@og.org>
List: port-mac68k
Date: 03/13/1997 00:34:41
On Wed, 12 Mar 1997, Colin Wood wrote:

> > I get get a shrieking beep every time consistently now that I recompiled 
> > with newer sources (tarballs from last week). I dont do anything in MacOS 
> > but click on the booter.
> > [...]
> 
> I don't know if this is "normal" but Scott has been doing a lot of work 
> on the asc (Apple Sound Chip) driver recently,

What I did was convert it to use the machine-independent bus space code,
and allowed the address of the device to be changed in the kernel config
file.  (Mostly to make it easier for people to work on the driver -- you
can access the device registers and the buffers without recompiling your
entire kernel now!)

What follows is something I hacked together, based on the new asc.c and
some of the old info that Allen and the rest of the Alice group had
gathered about the chip.  What it does is load the buffers and play the
sound defined by the waveform.  Many of the details are still a mystery to
us, though, so please feel free to work on the algorithm.

--scott

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	bell.c
#
echo x - bell.c
sed 's/^X//' >bell.c << 'END-of-bell.c'
X/*
X * Copyright (C) 1997 Scott Reynolds
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *      This product includes software developed by Scott Reynolds for
X *      the NetBSD Project.
X * 4. The name of the author may not be used to endorse or promote products
X *    derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
X/*-
X * Copyright (C) 1993	Allen K. Briggs, Chris P. Caputo,
X *			Michael L. Finch, Bradley A. Grantham, and
X *			Lawrence A. Kesteloot
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the Alice Group.
X * 4. The names of the Alice Group or any of its members may not be used
X *    to endorse or promote products derived from this software without
X *    specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
X * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
X
X#include <sys/types.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <fcntl.h>
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <math.h>
X
Xint bf = 1880;
Xint bv = 70;
X
Xvoid
Xplayball(ad, bell_freq, bell_volume)
X	caddr_t ad;
X	int bell_freq;
X	int bell_volume;
X{
X	unsigned long freq;
X	int i;
X
X	memset(ad, 0, 0x800);
X
X#ifdef SINE_WAVE
X	for (i = 0; i < 512; i++) {
X		*(ad+i) = 0x80 + (int)(sin(i/256.0) * 127);
X		*(ad+i+1024) = 0x80 + (int)(sin(i/256.0) * 127);
X		*(ad+i+512) = 0x80 + (int)(sin(i/128.0) * 127);
X		*(ad+i+1536) = 0x80 + (int)(sin(i/128.0) * 127);
X	}
X#else
X	for (i = 0; i < 256; i++) {	/* up part of wave, four voices? */
X		*(ad+i) = i;
X		*(ad+i+512) = i;
X		*(ad+i+1024) = i;
X		*(ad+i+1536) = i;
X	}
X	for (i = 0; i < 256; i++) {	/* down part of wave, four voices? */
X		*(ad+i+256) = 0xff - i;
X		*(ad+i+768) = 0xff - i;
X		*(ad+i+1280) = 0xff - i;
X		*(ad+i+1792) = 0xff - i;
X	}
X#endif
X
X	/* Fix this.  Need to find exact ASC sampling freq */
X	freq = 65536 * bell_freq / 466;
X
X	for (i = 0; i < 8; i++) {
X		*(ad+0x814 + 8 * i) = (freq >> 24) & 0xff;
X		*(ad+0x815 + 8 * i) = (freq >> 16) & 0xff;
X		*(ad+0x816 + 8 * i) = (freq >> 8) & 0xff;
X		*(ad+0x817 + 8 * i) = (freq) & 0xff;
X	}
X
X	*(ad+0x807) = 3; /* 44 ? */
X	*(ad+0x806) = 255 * bell_volume / 100;
X	*(ad+0x805) = 0;
X	*(ad+0x80f) = 0;
X	*(ad+0x802) = 2; /* sampled */
X	*(ad+0x801) = 2; /* enable sampled */
X
X	sleep(1);
X
X	*(ad+0x801) = 0;
X}
X
Xvoid
Xgetball(ad, fn)
X	caddr_t ad;
X	char *fn;
X{
X	static char buf[0x1000];
X	int fd;
X
X	if ((fd = open(fn, O_WRONLY|O_CREAT, 0666)) == (-1)) {
X		printf("can't open %s for writing\n", fn);
X		exit(2);
X	}
X	memcpy(buf, ad, 0x1000);
X	write(fd, buf, 0x1000);
X	close(fd);
X}
X
Xvoid
Xputball(ad, fn)
X	caddr_t ad;
X	char *fn;
X{
X	static char buf[0x1000];
X	int fd, i;
X
X	if ((fd = open(fn, O_RDONLY, 0666)) == (-1)) {
X		printf("can't open %s for reading\n", fn);
X		exit(2);
X	}
X	read(fd, buf, 0x1000);
X	close(fd);
X
X	memset(ad, 0, 0x800);
X	memcpy(ad, buf, 0x800);
X
X	for (i = 0; i < 8; i++) {
X		*(ad+0x814+8*i) = buf[0x814+8*i];
X		*(ad+0x815+8*i) = buf[0x815+8*i];
X		*(ad+0x816+8*i) = buf[0x816+8*i];
X		*(ad+0x817+8*i) = buf[0x817+8*i];
X	}
X
X	*(ad+0x807) = buf[0x807];
X	*(ad+0x806) = buf[0x806];
X	*(ad+0x805) = buf[0x805];
X	*(ad+0x80f) = buf[0x80f];
X	*(ad+0x802) = buf[0x802];
X	*(ad+0x801) = buf[0x801];
X
X	sleep(1);
X
X	*(ad+0x801) = 0;
X}
X
Xint
Xmain(argc, argv)
X	int argc;
X	char *argv[];
X{
X	caddr_t ad;
X	int fd, c;
X
X	if ((fd = open("/dev/audio", O_RDWR)) == (-1)) {
X		printf("can't open /dev/audio\n");
X		exit(1);
X	}
X	ad = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_FILE, fd, 0);
X	if (ad == (caddr_t) (-1)) {
X		printf("can't mmap fd %d\n", fd);
X		exit(1);
X	}
X	close(fd);
X
X	while ((c = getopt(argc, argv, "g:p:v:")) != (-1)) {
X		switch (c) {
X		case 'g':
X			getball(ad, optarg);
X			munmap(ad, 0x1000);
X			exit(0);
X		case 'p':
X			putball(ad, optarg);
X			munmap(ad, 0x1000);
X			exit(0);
X		case 'v':
X			bv = atoi(optarg);
X			break;
X		}
X	}
X
X	playball(ad, bf, bv);
X	munmap(ad, 0x1000);
X
X	return (0);
X}
END-of-bell.c
exit