TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: FRANCESCO RABBI
from: JAMES VAHN
date: 1998-01-15 17:49:00
subject: Re: PC speaker

> Hi! I need a routine in assembly that drive the speaker, somebody
> can help me?
This is a crude TSR to beep on a keypress.
cseg segment
assume cs:cseg, ds:cseg
org 100h                           ;COM format.
.286
Begin:
        jmp Init                   ;Jump over the ISR code
Old_Int dd ?                       ;Storage- points to the old ISR.
toggle  db 0
New_ISR:
        pusha                      ;Save the registers.
        xor     cs:[toggle],0FFh   ;Toggle so routine only
        jz      exit               ; executes on keyPRESS.
        call    beep
exit:   popa                       ;End of ISR- exit
        jmp     cs:[Old_Int]       ; to old vector.
beep:   in      al,61h             ;Save original.
        push    ax
        mov     al,0B6h            ;Channel 2, LSB/MSB
        out     43h,al             ;
        in      al,61h             ;Turn speaker on.
        or      al,3h              ;
        out     61h,al             ;
        mov     al,82h             ;500 Hz :
        out     42h,al             ;1193180 / (9*256+82)
        mov     al,9h
        out     42h,al
        mov     cx, 02000h
  L1:   in      al,04Fh            ;Delay with speaker on.
        loop    L1
        pop     ax
        out     61h,al             ;Turn speaker off, exit
        ret
; Initialization code
Init:
        mov     ax,3509h           ;Get old vector and store it.
        int     21h
        mov     word ptr [Old_Int],bx
        mov     word ptr [Old_Int+2],es
        mov     ax,2509h           ;Change the target vector.
        mov     dx,offset New_ISR
        int     21h
        mov     dx,offset Init     ;Allocate TSR memory
        int     27h                ; and exit to DOS.
cseg ends
end Begin
--- ifmail-tx (i386 Linux)
---------------
* Origin: jvahn@short.circuit.com (1:346/15.1@fidonet)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.