1996-10-11 04:24:36 +04:00
|
|
|
/* $NetBSD: spkr.c,v 1.26 1996/10/11 00:27:13 christos Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-05-07 10:50:18 +04:00
|
|
|
/*
|
|
|
|
* spkr.c -- device driver for console speaker on 80386
|
|
|
|
*
|
|
|
|
* v1.1 by Eric S. Raymond (esr@snark.thyrsus.com) Feb 1990
|
|
|
|
* modified for 386bsd by Andrew A. Chernov <ache@astral.msk.su>
|
|
|
|
* 386bsd only clean version, all SYSV stuff removed
|
|
|
|
* use hz value from param.c
|
|
|
|
*/
|
|
|
|
|
1996-02-22 08:53:16 +03:00
|
|
|
#include "spkr.h"
|
|
|
|
#if NSPKR > 0
|
1996-03-07 03:54:14 +03:00
|
|
|
#if NSPKR > 1
|
|
|
|
#error only one speaker device per system
|
|
|
|
#endif
|
1993-05-07 10:50:18 +04:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
1996-05-05 23:31:25 +04:00
|
|
|
#include <sys/systm.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
1996-02-22 08:53:16 +03:00
|
|
|
#include <sys/device.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/uio.h>
|
1996-05-05 23:31:25 +04:00
|
|
|
#include <sys/proc.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1994-03-08 15:21:10 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
#include <machine/spkr.h>
|
1996-05-05 23:31:25 +04:00
|
|
|
#include <machine/conf.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-02-22 08:53:16 +03:00
|
|
|
#include <dev/isa/isareg.h>
|
1996-03-03 07:12:48 +03:00
|
|
|
#include <dev/isa/isavar.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <i386/isa/timerreg.h>
|
1994-04-24 05:34:05 +04:00
|
|
|
#include <i386/isa/spkrreg.h>
|
1993-05-07 10:50:18 +04:00
|
|
|
|
1996-02-22 08:53:16 +03:00
|
|
|
int spkrprobe __P((struct device *, void *, void *));
|
|
|
|
void spkrattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct spkr_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
};
|
|
|
|
|
1996-03-17 04:26:49 +03:00
|
|
|
struct cfattach spkr_ca = {
|
|
|
|
sizeof(struct spkr_softc), spkrprobe, spkrattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver spkr_cd = {
|
|
|
|
NULL, "spkr", DV_TTY
|
1996-02-22 08:53:16 +03:00
|
|
|
};
|
|
|
|
|
1993-05-07 10:50:18 +04:00
|
|
|
/**************** MACHINE DEPENDENT PART STARTS HERE *************************
|
|
|
|
*
|
|
|
|
* This section defines a function tone() which causes a tone of given
|
|
|
|
* frequency and duration from the 80x86's console speaker.
|
|
|
|
* Another function endtone() is defined to force sound off, and there is
|
|
|
|
* also a rest() entry point to do pauses.
|
|
|
|
*
|
|
|
|
* Audible sound is generated using the Programmable Interval Timer (PIT) and
|
|
|
|
* Programmable Peripheral Interface (PPI) attached to the 80x86's speaker. The
|
|
|
|
* PPI controls whether sound is passed through at all; the PIT's channel 2 is
|
|
|
|
* used to generate clicks (a square wave) of whatever frequency is desired.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1993-06-16 23:41:54 +04:00
|
|
|
* Magic numbers for timer control.
|
1993-05-07 10:50:18 +04:00
|
|
|
*/
|
1993-10-28 17:00:54 +03:00
|
|
|
#define PIT_MODE (TIMER_SEL2|TIMER_16BIT|TIMER_SQWAVE)
|
1993-05-07 10:50:18 +04:00
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void endtone __P((void *));
|
|
|
|
static void tone __P((u_int, u_int));
|
|
|
|
static void endrest __P((void *));
|
|
|
|
static void rest __P((int));
|
|
|
|
static void playinit __P((void));
|
|
|
|
static void playtone __P((int, int, int));
|
1996-07-14 05:03:13 +04:00
|
|
|
static void playstring __P((char *, int));
|
1996-05-05 23:31:25 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
endtone(v)
|
|
|
|
void *v;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
1996-05-05 23:31:25 +04:00
|
|
|
wakeup(endtone);
|
1993-06-16 23:41:54 +04:00
|
|
|
outb(PITAUX_PORT, inb(PITAUX_PORT) & ~PIT_SPKR);
|
1993-05-07 10:50:18 +04:00
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static
|
|
|
|
void tone(hz, ticks)
|
1993-05-07 10:50:18 +04:00
|
|
|
/* emit tone of frequency hz for given number of ticks */
|
1996-05-05 23:31:25 +04:00
|
|
|
u_int hz, ticks;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
1996-05-05 23:31:25 +04:00
|
|
|
u_int divisor = TIMER_DIV(hz);
|
1993-05-07 10:50:18 +04:00
|
|
|
int sps;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("tone: hz=%d ticks=%d\n", hz, ticks);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/* set timer to generate clicks at given frequency in Hertz */
|
|
|
|
sps = spltty();
|
1993-06-16 23:41:54 +04:00
|
|
|
outb(TIMER_MODE, PIT_MODE); /* prepare timer */
|
|
|
|
outb(TIMER_CNTR2, (unsigned char) divisor); /* send lo byte */
|
|
|
|
outb(TIMER_CNTR2, (divisor >> 8)); /* send hi byte */
|
1993-05-07 10:50:18 +04:00
|
|
|
splx(sps);
|
|
|
|
|
|
|
|
/* turn the speaker on */
|
1993-06-16 23:41:54 +04:00
|
|
|
outb(PITAUX_PORT, inb(PITAUX_PORT) | PIT_SPKR);
|
1993-05-07 10:50:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set timeout to endtone function, then give up the timeslice.
|
|
|
|
* This is so other processes can execute while the tone is being
|
|
|
|
* emitted.
|
|
|
|
*/
|
1996-05-05 23:31:25 +04:00
|
|
|
timeout(endtone, NULL, ticks);
|
|
|
|
sleep(endtone, PZERO - 1);
|
1993-05-07 10:50:18 +04:00
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void
|
|
|
|
endrest(v)
|
1993-05-07 10:50:18 +04:00
|
|
|
/* end a rest */
|
1996-05-05 23:31:25 +04:00
|
|
|
void *v;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
1996-05-05 23:31:25 +04:00
|
|
|
wakeup(endrest);
|
1993-05-07 10:50:18 +04:00
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void
|
|
|
|
rest(ticks)
|
1993-05-07 10:50:18 +04:00
|
|
|
/* rest for given number of ticks */
|
1996-05-05 23:31:25 +04:00
|
|
|
int ticks;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set timeout to endrest function, then give up the timeslice.
|
|
|
|
* This is so other processes can execute while the rest is being
|
|
|
|
* waited out.
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("rest: %d\n", ticks);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
1996-05-05 23:31:25 +04:00
|
|
|
timeout(endrest, NULL, ticks);
|
|
|
|
sleep(endrest, PZERO - 1);
|
1993-05-07 10:50:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************** PLAY STRING INTERPRETER BEGINS HERE **********************
|
|
|
|
*
|
|
|
|
* Play string interpretation is modelled on IBM BASIC 2.0's PLAY statement;
|
|
|
|
* M[LNS] are missing and the ~ synonym and octave-tracking facility is added.
|
|
|
|
* Requires tone(), rest(), and endtone(). String play is not interruptible
|
|
|
|
* except possibly at physical block boundaries.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef int bool;
|
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
|
|
|
|
|
|
|
#define toupper(c) ((c) - ' ' * (((c) >= 'a') && ((c) <= 'z')))
|
|
|
|
#define isdigit(c) (((c) >= '0') && ((c) <= '9'))
|
|
|
|
#define dtoi(c) ((c) - '0')
|
|
|
|
|
|
|
|
static int octave; /* currently selected octave */
|
|
|
|
static int whole; /* whole-note time at current tempo, in ticks */
|
|
|
|
static int value; /* whole divisor for note time, quarter note = 1 */
|
|
|
|
static int fill; /* controls spacing of notes */
|
|
|
|
static bool octtrack; /* octave-tracking on? */
|
|
|
|
static bool octprefix; /* override current octave-tracking state? */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Magic number avoidance...
|
|
|
|
*/
|
|
|
|
#define SECS_PER_MIN 60 /* seconds per minute */
|
|
|
|
#define WHOLE_NOTE 4 /* quarter notes per whole note */
|
|
|
|
#define MIN_VALUE 64 /* the most we can divide a note by */
|
|
|
|
#define DFLT_VALUE 4 /* default value (quarter-note) */
|
|
|
|
#define FILLTIME 8 /* for articulation, break note in parts */
|
|
|
|
#define STACCATO 6 /* 6/8 = 3/4 of note is filled */
|
|
|
|
#define NORMAL 7 /* 7/8ths of note interval is filled */
|
|
|
|
#define LEGATO 8 /* all of note interval is filled */
|
|
|
|
#define DFLT_OCTAVE 4 /* default octave */
|
|
|
|
#define MIN_TEMPO 32 /* minimum tempo */
|
|
|
|
#define DFLT_TEMPO 120 /* default tempo */
|
|
|
|
#define MAX_TEMPO 255 /* max tempo */
|
|
|
|
#define NUM_MULT 3 /* numerator of dot multiplier */
|
|
|
|
#define DENOM_MULT 2 /* denominator of dot multiplier */
|
|
|
|
|
|
|
|
/* letter to half-tone: A B C D E F G */
|
|
|
|
static int notetab[8] = {9, 11, 0, 2, 4, 5, 7};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the American Standard A440 Equal-Tempered scale with frequencies
|
|
|
|
* rounded to nearest integer. Thank Goddess for the good ol' CRC Handbook...
|
|
|
|
* our octave 0 is standard octave 2.
|
|
|
|
*/
|
|
|
|
#define OCTAVE_NOTES 12 /* semitones per octave */
|
|
|
|
static int pitchtab[] =
|
|
|
|
{
|
|
|
|
/* C C# D D# E F F# G G# A A# B*/
|
|
|
|
/* 0 */ 65, 69, 73, 78, 82, 87, 93, 98, 103, 110, 117, 123,
|
|
|
|
/* 1 */ 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247,
|
|
|
|
/* 2 */ 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494,
|
|
|
|
/* 3 */ 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988,
|
|
|
|
/* 4 */ 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1975,
|
|
|
|
/* 5 */ 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951,
|
|
|
|
/* 6 */ 4186, 4435, 4698, 4978, 5274, 5588, 5920, 6272, 6644, 7040, 7459, 7902,
|
|
|
|
};
|
1996-07-14 05:03:13 +04:00
|
|
|
#define NOCTAVES (sizeof(pitchtab) / sizeof(pitchtab[0]) / OCTAVE_NOTES)
|
1993-05-07 10:50:18 +04:00
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void
|
|
|
|
playinit()
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
octave = DFLT_OCTAVE;
|
|
|
|
whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / DFLT_TEMPO;
|
|
|
|
fill = NORMAL;
|
|
|
|
value = DFLT_VALUE;
|
|
|
|
octtrack = FALSE;
|
|
|
|
octprefix = TRUE; /* act as though there was an initial O(n) */
|
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void
|
|
|
|
playtone(pitch, value, sustain)
|
1993-05-07 10:50:18 +04:00
|
|
|
/* play tone of proper duration for current rhythm signature */
|
1996-05-05 23:31:25 +04:00
|
|
|
int pitch, value, sustain;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
register int sound, silence, snum = 1, sdenom = 1;
|
|
|
|
|
|
|
|
/* this weirdness avoids floating-point arithmetic */
|
|
|
|
for (; sustain; sustain--)
|
|
|
|
{
|
|
|
|
snum *= NUM_MULT;
|
|
|
|
sdenom *= DENOM_MULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pitch == -1)
|
|
|
|
rest(whole * snum / (value * sdenom));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sound = (whole * snum) / (value * sdenom)
|
|
|
|
- (whole * (FILLTIME - fill)) / (value * FILLTIME);
|
|
|
|
silence = whole * (FILLTIME-fill) * snum / (FILLTIME * value * sdenom);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("playtone: pitch %d for %d ticks, rest for %d ticks\n",
|
|
|
|
pitch, sound, silence);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
tone(pitchtab[pitch], sound);
|
|
|
|
if (fill != LEGATO)
|
|
|
|
rest(silence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
static void
|
|
|
|
playstring(cp, slen)
|
1993-05-07 10:50:18 +04:00
|
|
|
/* interpret and play an item from a notation string */
|
1996-05-05 23:31:25 +04:00
|
|
|
char *cp;
|
1996-07-14 05:03:13 +04:00
|
|
|
int slen;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
int pitch, lastpitch = OCTAVE_NOTES * DFLT_OCTAVE;
|
|
|
|
|
1996-07-21 08:01:01 +04:00
|
|
|
#define GETNUM(cp, v) for(v=0; slen > 0 && isdigit(cp[1]); ) \
|
1993-05-07 10:50:18 +04:00
|
|
|
{v = v * 10 + (*++cp - '0'); slen--;}
|
|
|
|
for (; slen--; cp++)
|
|
|
|
{
|
|
|
|
int sustain, timeval, tempo;
|
|
|
|
register char c = toupper(*cp);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("playstring: %c (%x)\n", c, c);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
|
|
|
|
|
|
|
|
/* compute pitch */
|
|
|
|
pitch = notetab[c - 'A'] + octave * OCTAVE_NOTES;
|
|
|
|
|
|
|
|
/* this may be followed by an accidental sign */
|
1996-07-14 05:03:13 +04:00
|
|
|
if (slen > 0 && (cp[1] == '#' || cp[1] == '+'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
++pitch;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
1996-07-14 05:03:13 +04:00
|
|
|
else if (slen > 0 && cp[1] == '-')
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
--pitch;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If octave-tracking mode is on, and there has been no octave-
|
|
|
|
* setting prefix, find the version of the current letter note
|
|
|
|
* closest to the last regardless of octave.
|
|
|
|
*/
|
|
|
|
if (octtrack && !octprefix)
|
|
|
|
{
|
|
|
|
if (abs(pitch-lastpitch) > abs(pitch+OCTAVE_NOTES-lastpitch))
|
|
|
|
{
|
|
|
|
++octave;
|
|
|
|
pitch += OCTAVE_NOTES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(pitch-lastpitch) > abs((pitch-OCTAVE_NOTES)-lastpitch))
|
|
|
|
{
|
|
|
|
--octave;
|
|
|
|
pitch -= OCTAVE_NOTES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
octprefix = FALSE;
|
|
|
|
lastpitch = pitch;
|
|
|
|
|
|
|
|
/* ...which may in turn be followed by an override time value */
|
|
|
|
GETNUM(cp, timeval);
|
|
|
|
if (timeval <= 0 || timeval > MIN_VALUE)
|
|
|
|
timeval = value;
|
|
|
|
|
|
|
|
/* ...and/or sustain dots */
|
1996-07-14 05:03:13 +04:00
|
|
|
for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
slen--;
|
|
|
|
sustain++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* time to emit the actual tone */
|
|
|
|
playtone(pitch, timeval, sustain);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O':
|
1996-07-14 05:03:13 +04:00
|
|
|
if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
octprefix = octtrack = FALSE;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
1996-07-14 05:03:13 +04:00
|
|
|
else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
octtrack = TRUE;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GETNUM(cp, octave);
|
1996-07-14 05:03:13 +04:00
|
|
|
if (octave >= NOCTAVES)
|
1993-05-07 10:50:18 +04:00
|
|
|
octave = DFLT_OCTAVE;
|
|
|
|
octprefix = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '>':
|
1996-07-14 05:03:13 +04:00
|
|
|
if (octave < NOCTAVES - 1)
|
1993-05-07 10:50:18 +04:00
|
|
|
octave++;
|
|
|
|
octprefix = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
if (octave > 0)
|
|
|
|
octave--;
|
|
|
|
octprefix = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'N':
|
|
|
|
GETNUM(cp, pitch);
|
1996-07-14 05:03:13 +04:00
|
|
|
for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
slen--;
|
|
|
|
sustain++;
|
|
|
|
}
|
|
|
|
playtone(pitch - 1, value, sustain);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
GETNUM(cp, value);
|
|
|
|
if (value <= 0 || value > MIN_VALUE)
|
|
|
|
value = DFLT_VALUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
case '~':
|
|
|
|
/* this may be followed by an override time value */
|
|
|
|
GETNUM(cp, timeval);
|
|
|
|
if (timeval <= 0 || timeval > MIN_VALUE)
|
|
|
|
timeval = value;
|
1996-07-14 05:03:13 +04:00
|
|
|
for (sustain = 0; slen > 0 && cp[1] == '.'; cp++)
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
slen--;
|
|
|
|
sustain++;
|
|
|
|
}
|
|
|
|
playtone(-1, timeval, sustain);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
GETNUM(cp, tempo);
|
|
|
|
if (tempo < MIN_TEMPO || tempo > MAX_TEMPO)
|
|
|
|
tempo = DFLT_TEMPO;
|
|
|
|
whole = (hz * SECS_PER_MIN * WHOLE_NOTE) / tempo;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
1996-07-14 05:03:13 +04:00
|
|
|
if (slen > 0 && (cp[1] == 'N' || cp[1] == 'n'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
fill = NORMAL;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
1996-07-14 05:03:13 +04:00
|
|
|
else if (slen > 0 && (cp[1] == 'L' || cp[1] == 'l'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
fill = LEGATO;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
1996-07-14 05:03:13 +04:00
|
|
|
else if (slen > 0 && (cp[1] == 'S' || cp[1] == 's'))
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
fill = STACCATO;
|
|
|
|
++cp;
|
|
|
|
slen--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************* UNIX DRIVER HOOKS BEGIN HERE **************************
|
|
|
|
*
|
|
|
|
* This section implements driver hooks to run playstring() and the tone(),
|
|
|
|
* endtone(), and rest() functions defined above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int spkr_active; /* exclusion flag */
|
|
|
|
static struct buf *spkr_inbuf; /* incoming buf */
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
int
|
|
|
|
spkrprobe (parent, match, aux)
|
1996-03-07 03:54:14 +03:00
|
|
|
struct device *parent;
|
|
|
|
void *match;
|
|
|
|
void *aux;
|
1996-02-22 08:53:16 +03:00
|
|
|
{
|
1996-03-18 04:26:10 +03:00
|
|
|
struct cfdata *cf = match;
|
|
|
|
/*
|
|
|
|
* We only attach to the keyboard controller via
|
|
|
|
* the console drivers. (We really wish we could be the
|
|
|
|
* child of a real keyboard controller driver.)
|
|
|
|
*/
|
|
|
|
if ((parent == NULL) ||
|
|
|
|
((strcmp(parent->dv_cfdata->cf_driver->cd_name, "pc") != 0) &&
|
|
|
|
(strcmp(parent->dv_cfdata->cf_driver->cd_name, "vt") != 0)))
|
|
|
|
return (0);
|
|
|
|
if (cf->cf_loc[1] != PITAUX_PORT)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
1996-02-22 08:53:16 +03:00
|
|
|
}
|
|
|
|
|
1996-03-18 04:26:10 +03:00
|
|
|
static int spkr_attached = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
spkrattach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
1996-02-22 08:53:16 +03:00
|
|
|
{
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf(" port 0x%x\n", self->dv_cfdata->cf_loc[1]);
|
1996-03-18 04:26:10 +03:00
|
|
|
spkr_attached = 1;
|
1996-02-22 08:53:16 +03:00
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
int
|
|
|
|
spkropen(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("spkropen: entering with dev = %x\n", dev);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
1996-03-18 04:26:10 +03:00
|
|
|
if (minor(dev) != 0 || !spkr_attached)
|
1993-05-07 10:50:18 +04:00
|
|
|
return(ENXIO);
|
|
|
|
else if (spkr_active)
|
|
|
|
return(EBUSY);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playinit();
|
|
|
|
spkr_inbuf = geteblk(DEV_BSIZE);
|
|
|
|
spkr_active = 1;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
int
|
|
|
|
spkrwrite(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
1996-07-14 05:03:13 +04:00
|
|
|
register int n;
|
1993-05-07 10:50:18 +04:00
|
|
|
char *cp;
|
|
|
|
int error;
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("spkrwrite: entering with dev = %x, count = %d\n",
|
1993-05-07 10:50:18 +04:00
|
|
|
dev, uio->uio_resid);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
if (minor(dev) != 0)
|
|
|
|
return(ENXIO);
|
|
|
|
else
|
|
|
|
{
|
1994-05-24 11:31:12 +04:00
|
|
|
n = min(DEV_BSIZE, uio->uio_resid);
|
1994-06-16 05:07:30 +04:00
|
|
|
cp = spkr_inbuf->b_data;
|
1993-05-07 10:50:18 +04:00
|
|
|
error = uiomove(cp, n, uio);
|
|
|
|
if (!error)
|
|
|
|
playstring(cp, n);
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-05 23:31:25 +04:00
|
|
|
int spkrclose(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("spkrclose: entering with dev = %x\n", dev);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
if (minor(dev) != 0)
|
|
|
|
return(ENXIO);
|
|
|
|
else
|
|
|
|
{
|
1996-05-05 23:31:25 +04:00
|
|
|
endtone(NULL);
|
1993-05-07 10:50:18 +04:00
|
|
|
brelse(spkr_inbuf);
|
|
|
|
spkr_active = 0;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-02-10 00:06:46 +03:00
|
|
|
int spkrioctl(dev, cmd, data, flag, p)
|
1996-05-05 23:31:25 +04:00
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
1993-05-07 10:50:18 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
1996-10-11 04:24:36 +04:00
|
|
|
kprintf("spkrioctl: entering with dev = %x, cmd = %lx\n", dev, cmd);
|
1993-05-07 10:50:18 +04:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
if (minor(dev) != 0)
|
|
|
|
return(ENXIO);
|
|
|
|
else if (cmd == SPKRTONE)
|
|
|
|
{
|
1994-02-10 00:06:46 +03:00
|
|
|
tone_t *tp = (tone_t *)data;
|
1993-05-07 10:50:18 +04:00
|
|
|
|
|
|
|
if (tp->frequency == 0)
|
|
|
|
rest(tp->duration);
|
|
|
|
else
|
|
|
|
tone(tp->frequency, tp->duration);
|
|
|
|
}
|
|
|
|
else if (cmd == SPKRTUNE)
|
|
|
|
{
|
1994-02-10 00:06:46 +03:00
|
|
|
tone_t *tp = (tone_t *)(*(caddr_t *)data);
|
1993-05-07 10:50:18 +04:00
|
|
|
tone_t ttp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
for (; ; tp++) {
|
|
|
|
error = copyin(tp, &ttp, sizeof(tone_t));
|
|
|
|
if (error)
|
|
|
|
return(error);
|
|
|
|
if (ttp.duration == 0)
|
|
|
|
break;
|
|
|
|
if (ttp.frequency == 0)
|
|
|
|
rest(ttp.duration);
|
|
|
|
else
|
|
|
|
tone(ttp.frequency, ttp.duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return(EINVAL);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NSPEAKER > 0 */
|
|
|
|
/* spkr.c ends here */
|