R&D Books Book Cover
[Return]

Listing 2: Produce a Tone on the Loudspeaker

.CODE
;I've put this data in the code segment ...
dsselector    DW   0             ;data alias to code seg
musicflag     DB   0             ;turn music on/off
;
runtime:
   pusha ;save all regs.
   push   ds
   push   es
   mov    es,cs:dsselector       ;get alias
   push   es                     ;can also set ds to alias.
   pop    ds                     ;(so seg.override isn't needed to access data).
   sti                           ;enable interrupts.
     ;(STI and reentrancy issues discussed on page 323).
   cmp    musicflag,20           ;musicflag is used as a counter, for
   jb     jumpout3               ;turning the tone on or off on each
   mov    musicflag,0            ;10th entry to the routine.
   jmp    turnoff
jumpout3:
   inc    musicflag
   cmp    musicflag,10
   jne    jumpout2
timeron:
   mov    al,0b6h                ;turn on the hardware timer.
   out    43h,al
   mov    bx,07c5h               ;frequency 600Hz.
   mov    al,bl
   out    42h,al
   mov    al,bh
   out    42h,al
   in     al,61h
   or     al,03
   out    61h,al
   jmp    SHORT jumpout2
turnoff:
   in     al,61h                 ;turn off the hardware timer.
   and    al,0fch
   out    61h,al
jumpout2:
   pop    es
   pop    ds                     ;restore all regs.
   popa
   iret

[Return]

Copyright © 1997, R&D Books, an imprint of Miller Freeman, Inc. All rights reserved. Last updated: 10/09/97