Page 1 of 1

Making the PC internal speaker beep...

Posted: Fri May 17, 2002 5:18 pm
by K.J.
Anyone know how to make the internal PC speaker beep?

Thanks in advance,
K.J.

Re:Making the PC internal speaker beep...

Posted: Fri May 17, 2002 8:38 pm
by Anonymous
look at one of the early versions of Linux
version 0.11 I think -- search for "wonder-kernel" :)

Re:Making the PC internal speaker beep...

Posted: Sat May 18, 2002 5:23 am
by unknown user
i geuss you can poke the speaker with the interrupts from the timer.

Re:Making the PC internal speaker beep...

Posted: Sat May 18, 2002 6:44 am
by Tim
This is sound.c from the DJGPP library source:

Code: Select all

/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <pc.h>

void
sound(int freq)
{
  int scale;
  if (freq == 0)
  {
    outportb(0x61, inportb(0x61) & ~3);
    return;
  }
  scale = 1193046 / freq;
  outportb(0x43, 0xb6);
  outportb(0x42, scale & 0xff);
  outportb(0x42, scale >> 8);
  outportb(0x61, inportb(0x61) | 3);
}

Re:Making the PC internal speaker beep...

Posted: Sat May 18, 2002 11:59 am
by crazybuddha
Sorry this isn't commented. I'd be happy to elaborate, if anyone cares. This COM program should generate a tone until you hit a key. It is assembled in NASM (see Refs. below).


;------------ CUT HERE ---------------
; nasmw beep.asm -o beep.com

org 0x0100

in al, 61h???
jmp $+2
or al, 03h
out 61h, al
???
mov al, 0b6h
out 43h, al
???
mov ax, 1193
out 42h, al
mov al, ah
out 42h, al
???
xor ah, ah
int 16h
???
in al, 61h
jmp $+2
and al, 0fdh
out 61h, al

mov ah,4Ch ???
int 21h ???

;Refs:
;nasm.2y.net
;www.ctyme.com/rbrown.htm

;------------ CUT HERE ---------------

Re:Making the PC internal speaker beep...

Posted: Thu May 23, 2002 10:23 am
by K.J.
Thanks for the code Tim and crazybuddha.

K.J.