home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
bmd-1.0beta.tar.Z
/
bmd-1.0beta.tar
/
bmd-1.0beta
/
sun4c
/
midiclock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-20
|
3KB
|
128 lines
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "bmd.h"
#if NBMD > 0
#ifndef lint
static char rcsid[] =
"@(#) $Header: midiclock.c,v 1.2 91/08/20 19:20:56 mccanne Exp $";
#endif
#include <sys/types.h>
#include <machine/clock.h>
#include <machine/intreg.h>
#include <machine/midiclock.h>
struct miditime midiclk;
void bmdtrap();
void bmdupdate();
#ifdef BMD_CTRAP
/*
* Called by clock interrupt (level 14 on a sparc).
*/
void
bmdtrap()
{
int x;
register struct miditime *p;
x = COUNTER->limit14;
p = &midiclk;
if (p->mt_pause)
return;
if (++p->mt_now >= p->mt_work)
bmdupdate();
}
#endif
#ifndef BMDCLOCKGRAN
#define BMDCLOCKGRAN 1000
#endif
u_int midiclk_defrate = BMDCLOCKGRAN;
u_int midiclk_rate;
u_int midiclk_refcnt;
extern void (*int_vector[])();
u_int
midiclk_start()
{
register int rate;
if (midiclk_refcnt++)
return midiclk_rate;
midiclk.mt_pause = 0;
midiclk.mt_now = 0;
midiclk.mt_work = ~0;
#ifdef BMD_CTRAP
int_vector[14] = bmdtrap;
#else
int_vector[14] = bmdupdate;
settrap(14, (int (*)())bmdtrap);
#endif
rate = midiclk_defrate;
midiclk_rate = rate;
COUNTER->limit14 = (rate << CTR_USEC_SHIFT) & CTR_USEC_MASK;
set_clk_mode(IR_ENA_CLK14, 0);
return rate;
}
void
midiclk_stop()
{
if (--midiclk_refcnt != 0)
return;
set_clk_mode(0, IR_ENA_CLK14);
int_vector[14] = 0;
}
void
midiclk_pause()
{
if (midiclk.mt_pause == 0) {
set_clk_mode(0, IR_ENA_CLK14);
++midiclk.mt_pause;
}
}
void
midiclk_resume()
{
if (--midiclk.mt_pause == 0)
set_clk_mode(IR_ENA_CLK14, 0);
}
void
midiclk_setrate(usec)
int usec;
{
if (midiclk_refcnt == 0)
panic("midiclk_setrate");
midiclk_rate = usec;
COUNTER->limit14 = (usec << CTR_USEC_SHIFT) & CTR_USEC_MASK;
}
#endif