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

  1. ;PIANO--Uses Timer2 to run speaker
  2. ;  number keys play notes of the scale
  3. ;
  4. portB         equ      61h             ;I/O Port B
  5. keybd2        equ      7h              ;keybd input, no echo
  6. doscall       equ      21h             ;DOS interrupt number
  7. cont_c        equ      03h             ;ctrl-C ASCII code
  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. read_key:
  22.               mov  ah,keybd2           ;keybd function, no echo
  23.               int  doscall             ;call DOS
  24.               cmp  al,cont_c           ;is it Ctrl C ?
  25.               jz   exit                ;  yes, so exit
  26.               sub  al,31h              ;change ASCII to digit
  27.               and  al,00000111b        ;mask off upper five bits
  28.               shl  al,1                ;* by 2 (2 bytes/word)
  29.               cbw                      ;byte --> word in AX
  30.               mov  bx,ax               ;put in BX (for table)
  31.               mov  ax,0                ;numerator (low word)
  32.               mov  dx,12h              ;  (high word)
  33.               div  [13Eh  + bx]        ;divisor from table
  34.               mov  bx,ax               ;save quotient in BX
  35. ;
  36. ;set 1/pitch into timer, then turn on tone
  37.               mov  al,10110110b        ;put magic number
  38.               out 43h,al               ;   into timer2
  39.               mov  ax,bx               ;move 1/pitch into AX
  40.               out 42h,al               ;LSB into timer2
  41.               mov  al,ah               ;MSB to AL, then
  42.               out 42h,al               ;   to timer2
  43.               in  al,portB             ;read port B into AL
  44.               or  al,3                 ;turn on bits 0, 1
  45.               out portB,al             ;to turn speaker on/off
  46. ;
  47. ;sound note for a while, then turn in off
  48.               mov  cx,0ffffh           ;set up for delay
  49. wait:         loop wait                ;delay
  50.               in   al,portB            ;read port B into AL1
  51.               and  al,11111100b        ;mask off lower 2 bits
  52.               out  portB,al            ;to turn off speaker
  53.               jmp  read_key            ;go get another digit
  54. ;
  55. ;
  56. ;control-C typed so exit
  57. exit:
  58.               int  20h                 ;return to DOS
  59. ;
  60. ;frequencies of notes
  61.               dw   262d                ;C
  62.               dw   294d                ;D
  63.               dw   330d                ;E
  64.               dw   347d                ;F
  65.               dw   392d                ;G
  66.               dw   440d                ;A
  67.               dw   494d                ;B
  68.               dw   524d                ;C
  69. ;
  70. main          endp                     ;end main part of program
  71. ;--------------------------------------------------------------------
  72. prognam       ends                     ;end code segment
  73. ;********************************************************************
  74.               end  start               ;end of assembly
  75. ;====================================================================
  76. main          endp                     ;end main part of program
  77. ;--------------------------------------------------------------------
  78. ;
  79. prognam       ends                    ;end of code segment
  80. ;********************************************************************
  81. ;
  82.               end       start         ;end assembly
  83. ;====================================================================
  84.