home *** CD-ROM | disk | FTP | other *** search
- ;KAZOO produces variable pitched sounds
- ; 1 - raises pitch
- ; 2 - lowers pitch
- ; 9 - turns sound on
- ; 0 - turns sound off
- ; From Assembly Language Primer - The Waite Group
- ;
- portB EQU 61H ; I/O Port B
- keybd2 EQU 7H ; keybd input, no echo
- status EQU 0BH ; check kbd status
- dosexit EQU 20H ; DOS exit interrupt
- doscall EQU 21H ; DOS interrupt number
- ;
- main PROC FAR
- ORG 100H
- ;
- start: ; starting execution address
- mov dx,Offset(message); Point to the message
- mov ah,9 ; Set up for displaying the message
- int doscall ; Do the DOS call
- ;
- ;initial values
- mov bx,500H ; set 1/pitch in BX
- mov dl,0 ; set pitch change to 0
- mov dh,3 ; set on/off status on
- ;
- sounder:
- mov al,10110110b; put magic number
- out 43H,al ; into timer2
- tone:
- mov ax,bx ; move 1/pitch into AX
- out 42H,al ; LSB into timer2
- mov al,ah ; MSB to AL, then
- out 42H,al ; to timer2
-
- in al,portB ; read port B into AL
- and al,11111100B; mask off bits 0 & 1
- add al,dh ; add on/off status
- out portB,al ; to turn speaker on/off
-
- ;raise or lower pitch by amount in AX
- mov al,bh ; divide BX by 100H
- mov ah,0 ; top half of AX = 0
- or ax,1 ; make sure at least 1
- or dl,dl ; does DL = 0?
- jz skip ; if so, AX is plus
- neg ax ; make AX negative
- skip: add bx,ax ; add change to pitch
- mov cx,200H ; set up wait loop
- wait: loop wait ; loop a while...
- ;
- mov ah,status ; check status function
- int doscall ; call DOS
- cmp al,FFH ; if AL was FF, then
- jz read_key ; character was typed
- jmps tone ; sound tone again
- ;
- ; read keyboard to get digit
- ; 1 = lower pitch, 2 = raise pitch, 9 = on, 0 = off
-
- read_key:
- mov ah,keybd2 ; keyboard function, no echo
- int doscall ; call DOS
- cmp al,"1" ; is it 1?
- jz lower ; lower pitch
- cmp al,"2" ; is it 2?
- jz higher ; raise pitch
- cmp al,"9" ; is it 9?
- jz turn_on ; turn on tone
- cmp al,"0" ; is it 0?
- jz turn_off ; turn off tone
- cmpb al,"Q" ; is it Q?
- jz quit ; then quit
- cmp al,"q" ; is it still q
- jz quit ; then quit
- jmps tone ; not recognized key
-
- lower: mov dl,0
- jmps tone
-
- higher: mov dl,1
- jmps tone
-
- turn_on: mov dh,00000011B
- jmps sounder
-
- turn_off: mov dh,0
- jmps sounder
-
- quit: mov dh,0
- in al,portB ; read port B into AL
- and al,11111100B; mask off bits 0 & 1
- add al,dh ; add on/off status
- out portB,al ; to turn speaker on/off
- int dosexit ; quit
-
- message: DB "KAZOO, 1 = Down Pitch, 2=Up Pitch, 9=On, 0=Off, Q=Quit$"
-
- ENDP
-