[net.micro.pc] Speaker control on XTs

demillo@uwmacc.UUCP (Rob DeMillo) (11/12/85)

I find myself in need of some help. Can anyone out there point
me in there direction of finding a reference? I am trying to
access the speaker of my XT via assmebly language routines, and
I am having a devil of a time. Any magazine or journal references
that you might recommend?

Thanks in advance.

-- 
                           --- Rob DeMillo 
                               Madison Academic Computer Center
                               ...seismo!uwvax!uwmacc!demillo


     "...I suppose you think the concept of a 
         robot with an artificial leg is amusing?"

                    -- Marvin, the Paranoid Android
 

vch@rruxo.UUCP (Kerro Panille) (11/19/85)

>I find myself in need of some help. Can anyone out there point
>me in there direction of finding a reference? I am trying to
>access the speaker of my XT via assmebly language routines, and
>I am having a devil of a time. Any magazine or journal references
>that you might recommend?

The speaker is accessed by a port number - use the IN and OUT instructions
to access it. I don't know exactly what port it is, but it should be in the
IBM Technical Reference Manual. Peter Norton has a few sample assembler 
programs in his book, Inside The IBM PC. Chapter 3, listing 3.2. Norton
also goes into a little detail as to how this works. Here it is, the 
speaker port is number 61 (hex).

Inside The IBM PC is a good book for beginners - it does not go into great
detail, but should be sufficient for most simple tasks. Buy an assembly 
language book for more details. Manuals also help.


-- 
Vince Hatem          	               ----------------		           A
Bell Communications Research           | UZI          |----------|_ _ _\/  T
Raritan River Software Systems Center  |              |----------|     /\  &
444 Hoes Lane                          ----------------  ROGER GUTS 	   T 
4D-360                                   /     /\  DON'T NEED NO STINKIN' 
Piscataway, NJ 08854                    /     /           NECKTIES
(201) 699-4869                         /-----/
...ihnp4!rruxo!vch

   TRUE GRIT MYSTERIES - The detective series for those who NEVER eat quiche!
         (WARNING - MAY BE EMOTIONALLY DISTURBING TO HAMSTER LOVERS)

mjm@cantor.UUCP (Michael Markowitz) (11/21/85)

> 
> >... I am trying to
> >access the speaker of my XT via assmebly language routines, and
> >I am having a devil of a time. Any magazine or journal references
> >that you might recommend?
> 
> The speaker is accessed by a port number - use the IN and OUT instructions
> to access it. I don't know exactly what port it is, but it should be in the
> IBM Technical Reference Manual. Peter Norton has a few sample assembler 
> programs in his book, Inside The IBM PC. Chapter 3, listing 3.2. Norton
> also goes into a little detail as to how this works. Here it is, the 
> speaker port is number 61 (hex).
> 
First of all, port 61H is port B of the 8255A-5 PPI (programmable peripheral
interface).  If you start OUT'ing indescriminant data to that port you are
probably going to disable your keyboard and parity checking--although you might
get the speaker to go on at the same time!  Actually you enable the ouput
of timer channel 2 (which is fed to the speaker) by writing a 1 to bit 0 of
this port.  Bit 1 may be used to turn the speaker on and off.  To get
a specific frequency to sound you must program counter 2 of the timer.

Try the following as an example (there are other ways to do this):

	middle_C	dw	262	;261.6 Hz

	mov	al,0B6H		;select channel 2, mode 3 (square wave)
	out	43H,al		;  send to timer (order 16-bit read)

	mov	ax,34dcH	;calculate initial count (1.193MHz/262Hz)
	mov	dx,12H
	div	middle_C

	out	42H,al		;send LSB to counter 2
	mov	al,ah
	out	42H,al		;  then send MSB

	in	al,61H		;read data latched in output port B of PPI
	or	al,3		;enable timer channel 2 output and speaker
	out	61H,al		;send back to PPI (don't mess with other bits)

	mov	bx,????		;you'll have to choose appropriate values
again:	mov	cx,????		;  here to generate the desired delay
play:	loop	play		;(off the top of my head I estimate 64K
	dec	bx		;iterations will give you .2 seconds on a PC)
	jnz	again		;(this is using a bx=1, cx=0)

	in	al,61H		;(this is redundant, status is already in AL!)
	xor	al,3		;disable timer channel 2 output and speaker
	out	61H,al		;have PPI turn off that damn noise!


Hope this helps.

Michael Markowitz
Dept. of Math. Sciences
Loyola Univ. of Chicago
Chicago, IL  60626

ihnp4!gargoyle!cantor!able!mjm