home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / asm / tchasm / kazoo.asm < prev    next >
Assembly Source File  |  1986-01-28  |  4KB  |  100 lines

  1. ;KAZOO produces variable pitched sounds
  2. ; 1 - raises pitch
  3. ; 2 - lowers pitch
  4. ; 9 - turns sound on
  5. ; 0 - turns sound off
  6. ; From Assembly Language Primer - The Waite Group
  7. ;
  8. portB           EQU 61H         ; I/O Port B
  9. keybd2          EQU  7H         ; keybd input, no echo
  10. status          EQU 0BH         ; check kbd status
  11. dosexit         EQU 20H         ; DOS exit interrupt
  12. doscall         EQU 21H         ; DOS interrupt number
  13. ;
  14. main            PROC FAR
  15.                 ORG 100H
  16. ;
  17. start:                          ; starting execution address
  18.                 mov dx,Offset(message); Point to the message
  19.                 mov ah,9        ; Set up for displaying the message
  20.                 int doscall     ; Do the DOS call
  21. ;
  22. ;initial values
  23.                 mov bx,500H     ; set 1/pitch in BX
  24.                 mov dl,0        ; set pitch change to 0
  25.                 mov dh,3        ; set on/off status on
  26. ;
  27. sounder:
  28.                 mov al,10110110b; put magic number
  29.                 out 43H,al      ;  into timer2
  30. tone:
  31.                 mov ax,bx       ; move 1/pitch into AX
  32.                 out 42H,al      ; LSB into timer2
  33.                 mov al,ah       ; MSB to AL, then
  34.                 out 42H,al      ;  to timer2
  35.  
  36.                 in al,portB     ; read port B into AL
  37.                 and al,11111100B; mask off bits 0 & 1
  38.                 add al,dh       ; add on/off status
  39.                 out portB,al    ; to turn speaker on/off
  40.  
  41. ;raise or lower pitch by amount in AX
  42.                 mov al,bh       ; divide BX by 100H
  43.                 mov ah,0        ; top half of AX = 0
  44.                 or ax,1         ; make sure at least 1
  45.                 or dl,dl        ; does DL = 0?
  46.                 jz skip         ;  if so, AX is plus
  47.                 neg ax          ; make AX negative
  48. skip:           add bx,ax       ; add change to pitch
  49.                 mov cx,200H     ; set up wait loop
  50. wait:           loop wait       ;  loop a while...
  51. ;
  52.                 mov ah,status   ; check status function
  53.                 int doscall     ; call DOS
  54.                 cmp al,FFH      ; if AL was FF, then
  55.                 jz read_key     ;  character was typed
  56.                 jmps tone       ; sound tone again
  57. ;
  58. ; read keyboard to get digit
  59. ; 1 = lower pitch, 2 = raise pitch, 9 = on, 0 = off
  60.  
  61. read_key:
  62.                 mov ah,keybd2   ; keyboard function, no echo
  63.                 int doscall     ; call DOS
  64.                 cmp al,"1"      ; is it 1?
  65.                 jz lower        ;   lower pitch
  66.                 cmp al,"2"      ; is it 2?
  67.                 jz higher       ;   raise pitch
  68.                 cmp al,"9"      ; is it 9?
  69.                 jz turn_on      ;   turn on tone
  70.                 cmp al,"0"      ; is it 0?
  71.                 jz turn_off     ;   turn off tone
  72.                 cmpb al,"Q"     ; is it Q?
  73.                 jz quit         ;   then quit
  74.                 cmp al,"q"      ; is it still q
  75.                 jz quit         ;   then quit
  76.                 jmps tone       ; not recognized key
  77.  
  78. lower:          mov dl,0
  79.                 jmps tone
  80.  
  81. higher:         mov dl,1
  82.                 jmps tone
  83.  
  84. turn_on:        mov dh,00000011B
  85.                 jmps sounder
  86.  
  87. turn_off:       mov dh,0
  88.                 jmps sounder
  89.  
  90. quit:           mov dh,0
  91.                 in al,portB     ; read port B into AL
  92.                 and al,11111100B; mask off bits 0 & 1
  93.                 add al,dh       ; add on/off status
  94.                 out portB,al    ; to turn speaker on/off
  95.                 int dosexit     ; quit
  96.  
  97. message:        DB "KAZOO, 1 = Down Pitch, 2=Up Pitch, 9=On, 0=Off, Q=Quit$"
  98.  
  99.                 ENDP
  100.