Article View: net.micro.pc
Article #7820Re: How do you beep?
From: Bill Mayhew
Date: Fri, 05 Sep 1986 03:50
Date: Fri, 05 Sep 1986 03:50
68 lines
3371 bytes
3371 bytes
The following information is based on Appendix H of the book,
"C Primer Plus"; Waite, Prata & Martin; Sams Books.
I. The speaker is connected to an 8255 Parallel Interface
Controller chip in an IBM xt. It should be in the same place on
true clones. The port number for the speaker connection is 97
decimal. (Anyone know if the 8255 is in the same place on the AT?,
I'm pretty sure it is.)
II. Bits 0 and 1 of the above port both have to be set to logic
state 1 to move the cone of the speaker in and conversely, setting
those bits to 0 reverses the direction of the cone.
III. Note that the above register is bidirectional. The keyboard
strobe and cassette motor are also hooked there, so you want to
preserve the state of the bits other than the ones you are playing
with.
IV. The basic process is something like:
for (duration = tone_length; duration > 0; duration--) {
state = inp(97) ^ 0x03; */complement lower 2 bits /*
outp(97, state);
for (clik_wdth = pitch_const; clik_wdth >0; clik_wdth--){
*/waste some time /*
};
}
V. Obviously, the sound that you get with the above is going to be
processor speed dependent. What you can do is in the
initialization part of your program is to call the DOS time
interrupt (sorry don't remember the number at the moment) and then
count to some big number in a tight loop (10,000 would be good).
Call the dos time interrupt again and see how long it took you to
count. You'll then know the clock speed of the processor that you
are running on. It's easiest to have a table of note valuse for
"pitch_const" already calculated before hand, and have the results
of your test select the correct table. In theory, you could count
the number of CPU cycles in your loop, and thus you'd be able to
compute the table values so that you could normalize to weirdo
clock speeds.
VI. There is also an 8253 Counter/Timer chip in a Pee-cee that you
can use to set the durrations of things. See the book I referenced
for instructions on using the 8253. On the XT, the 8253 counts
down at a rate of 1.190 MHz. Beware that the counting rate is a
little faster on the original models of PC. I suppose it is
something odd on ATs as well, but I haven't had any reason to
check.
VII. Of course, if you could care less about what pitch you're
making just send a 0x07 (control G) with the DOS console print
interrupt. Normally DOS will take care of beeping the speaker for
you.
I don't normally hack C for a living, so I apologise if there are
any typos in the C example I stuck in. I think you get the gist of
it any way, right?
--Bill
Bill Mayhew
Division of Basic Medical Sciences
Northeastern Ohio Universities College of Medicine
Rootstown, OH 44272 USA (216) 325-2511
(wtm@neoucom.UUCP)
Technical Details
Message-ID:
<268@neoucom.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!neoucom!wtmReferences:
<23900032@siemens.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!caip!clyde!cbatt!neoucom!wtm From: wtm@neoucom.UUCP (Bill Mayhew) Newsgroups: net.micro.pc Subject: Re: How do you beep? Message-ID: <268@neoucom.UUCP> Date: Thu, 4-Sep-86 23:50:25 EDT Article-I.D.: neoucom.268 Posted: Thu Sep 4 23:50:25 1986 Date-Received: Fri, 5-Sep-86 05:09:55 EDT References: <23900032@siemens.UUCP> Organization: Northeastern Ohio Universities College of Medicine Lines: 68 Summary: See _C_Primer_Plus_, pp. 509-514