home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / kazoo.asm < prev    next >
Assembly Source File  |  1985-06-21  |  4KB  |  103 lines

  1. ;KAZOO--Uses Timer2 to run speaker
  2. ;  produces variable pitch sounds
  3. ;
  4. portB         equ      61h             ;I/O Port B
  5. keybd2        equ      7h              ;keybd input, no echo
  6. status        equ      0bh             ;check kbd status
  7. doscall       equ      21h             ;DOS interrupt number
  8. ;********************************************************************
  9. prognam       segment                  ;define code segment
  10. ;
  11. ;--------------------------------------------------------------------
  12. main          proc      far            ;main part of program
  13. ;
  14.               assume    cs:prognam
  15. ;
  16.               org       100h           ;first address
  17. ;
  18. ;
  19. start:                                 ;starting execution address
  20. ;
  21. ;intial values
  22.               mov bx,500h              ;set 1/pitch in BX
  23.               mov dl,0                 ;set pitch change to 0
  24.               mov dh,3                 ;set on/off status on
  25. ;
  26. sounder:
  27.               mov  al,10110110b        ;put magic number
  28.               out 43h,al               ;   into timer2
  29. tone:
  30.               mov  ax,bx               ;move 1/pitch into AX
  31.               out 42h,al               ;LSB into timer2
  32.               mov  al,ah               ;MSB to AL, then
  33.               out 42h,al               ;   to timer2
  34. ;
  35.               in  al,portB             ;read port B into AL
  36.               and al,11111100b         ;mask off bits 0, 1
  37.               add al,dh                ;add on/off status
  38.               out portB,al             ;to turn speaker on/off
  39. ;
  40. ;raise or lower pitch by amount in AX
  41.               mov  al,bh               ;divide BX by 100h
  42.               mov  ah,0                ;top half of AX = 0
  43.               or   ax,1                ;make sure at least 1
  44.               or   dl,dl               ;does DL = 0 ?
  45.               jz   skip                ;  if so, AX is plus
  46.               neg  ax                  ;make AX negative
  47. skip:         add  bx,ax               ;add change to pitch
  48. ;
  49.               mov  cx,200h             ;set up wait loop
  50. wait:         loop wait                ;   loop a while
  51. ;
  52. ;
  53.               mov  ah,status           ;check status function
  54.               int  doscall              ;call DOS
  55. ;
  56.               inc al                   ;if AL was FF, then
  57.               jz read_key              ;  character was typed
  58.               jmp tone                 ;sound tone again
  59. ;
  60. ;read keyboard to get digit
  61. ; 1=lower pitch, 2=raise pitch,  9=on,  0=off
  62. ;
  63. read_key:
  64.               mov  ah,keybd2           ;keybd function, no echo
  65.               int  doscall             ;call DOS
  66.               cmp al,'1'               ;is it 1 ?
  67.               jz  lower                ;  lower pitch
  68.               cmp al,'2'               ;is it 2 ?
  69.               jz  higher               ;  raise pitch
  70.               cmp al,'9'               ;is it 9 ?
  71.               jz  turn_on              ;  turn on tone
  72.               cmp al,'0'               ;is it 0 ?
  73.               jz  turn_off             ;  turn off tone
  74.               jmp tone                 ;not regognized
  75. ;
  76. lower:
  77.               mov  dl,0
  78.               jmp  tone
  79. higher:
  80.               mov  dl,+1
  81.               jmp  tone
  82. turn_on:
  83.               mov  dh,00000011b
  84.               jmp  sounder
  85. turn_off:
  86.               mov  dh,0
  87.               jmp  sounder
  88. ;
  89. main          endp                     ;end main part of program
  90. ;--------------------------------------------------------------------
  91. prognam       ends                     ;end code segment
  92. ;********************************************************************
  93.               end  start               ;end of assembly
  94. ;====================================================================
  95. main          endp                     ;end main part of program
  96. ;--------------------------------------------------------------------
  97. ;
  98. prognam       ends                    ;end of code segment
  99. ;********************************************************************
  100. ;
  101.               end       start         ;end assembly
  102. ;====================================================================
  103.