home *** CD-ROM | disk | FTP | other *** search
/ Dr. CD ROM (Annual Premium Edition) / premium.zip / premium / DOSUTIL1 / BLRMU13.ZIP / OLDBLUZ.ASM < prev    next >
Assembly Source File  |  1991-08-06  |  11KB  |  366 lines

  1. page ,132
  2. title oldbluz ( blues # 1 ) as of 08-06-91  04:25 pm
  3. ;
  4. ;   read through arrays of tones and times using timer channel 2
  5. ;
  6. ;   Program originally
  7. ;   from p. 109 - PC Resource May 1987 ( hardin brothers )
  8. ;
  9. ;*-----------------------------------------------
  10. ;*  ( minor modifications by bud rasmussen )
  11. ;*  ( tune by bud rasmussen )
  12. ;*-----------------------------------------------
  13. ;
  14. code     segment
  15. ;
  16.          assume cs:code,ds:code
  17. ;
  18.          org   256
  19. ;
  20. oldbluz:
  21. ;
  22.          jmp   play
  23. ;
  24. ppipb    equ   61h                     ; PPI port b
  25. tccr     equ   43h                     ; timer chip cmd reg
  26. tc2      equ   42h                     ; timer channel 2
  27. ;
  28. ;    This is the tone table -- the calculation formula is:
  29. ;    tone value = int ((1193180 / frequency) +.5)
  30. ;
  31. tones:
  32. ;
  33.          dw    9122                    ; c    1   ( c below middle c )
  34.          dw    8609                    ; c#   2
  35.          dw    8128                    ; d    3
  36.          dw    7668                    ; d#   4
  37.          dw    7240                    ; e    5
  38.          dw    6834                    ; f    6
  39.          dw    6450                    ; f#   7
  40.          dw    6088                    ; g    8
  41.          dw    5745                    ; g#   9
  42.          dw    5424                    ; a    10
  43.          dw    5119                    ; a#   11
  44.          dw    4833                    ; b    12
  45. ;
  46.          dw    4559                    ; c    13  ( middle c )
  47.          dw    4304                    ; c#   14
  48.          dw    4063                    ; d    15
  49.          dw    3835                    ; d#   16
  50.          dw    3620                    ; e    17
  51.          dw    3417                    ; f    18
  52.          dw    3225                    ; f#   19
  53.          dw    3044                    ; g    20
  54.          dw    2873                    ; g#   21
  55.          dw    2712                    ; a    22
  56.          dw    2559                    ; a#   23
  57.          dw    2416                    ; b    24
  58. ;
  59.          dw    2280                    ; c    25  ( c above middle c )
  60.          dw    2152                    ; c#   26
  61.          dw    2031                    ; d    27
  62.          dw    1917                    ; d#   28
  63.          dw    1810                    ; e    29
  64.          dw    1708                    ; f    30
  65.          dw    1612                    ; f#   31
  66.          dw    1522                    ; g    32
  67.          dw    1436                    ; g#   33
  68.          dw    1356                    ; a    34
  69.          dw    1279                    ; a#   35
  70.          dw    1208                    ; b    36
  71. ;
  72. ;*----------------
  73. ;*   tune table
  74. ;*----------------
  75. ;
  76. ;    This is the tune to be played.  The numbers are
  77. ;    indexes into the tone table above.
  78. ;
  79. ;    The list is terminated with a -1.
  80. ;
  81. ;    to make a rest:
  82. ;    use tone of 0 in tune table and length in time table
  83. ;
  84. ;
  85. tune:
  86.          db    13      ; c
  87. ;   bar 1                         c
  88.          db    16      ; d#
  89.          db    17      ; e
  90.          db    20      ; g
  91.          db    22      ; a
  92.          db    25      ; c
  93.          db    23      ; a#
  94.          db    0       ; rest
  95.          db    18      ; f
  96. ;   bar 2                         f
  97.          db    21      ; g#
  98.          db    22      ; a
  99.          db    25      ; c
  100.          db    27      ; d
  101.          db    30      ; f
  102.          db    28      ; d#
  103.          db    0       ; rest
  104. ;   bar 3                         c
  105.          db    29      ; e
  106.          db    0       ; rest
  107.          db    29      ; e
  108.          db    29      ; e
  109.          db    28      ; d#
  110.          db    27      ; d
  111.          db    25      ; c
  112.          db    24      ; b
  113. ;   bar 4                         c 7
  114.          db    23      ; a#
  115.          db    0       ; rest
  116.          db    18      ; f
  117. ;   bar 5                         f
  118.          db    21      ; g#
  119.          db    22      ; a
  120.          db    21      ; g#
  121.          db    22      ; a
  122.          db    18      ; f
  123.          db    0       ; rest
  124. ;   bar 6
  125.          db    27      ; d
  126.          db    25      ; c
  127.          db    27      ; d
  128.          db    25      ; c
  129.          db    23      ; a#
  130.          db    21      ; g#
  131. ;   bar 7                         c
  132.          db    20      ; g
  133.          db    16      ; d#
  134.          db    17      ; e
  135.          db    20      ; g
  136.          db    16      ; d#
  137.          db    17      ; e
  138. ;   bar 8
  139.          db    23      ; a#
  140.          db    0       ; rest
  141. ;   bar 9                         g 7
  142.          db    23      ; a#
  143.          db    22      ; a
  144.          db    23      ; a#
  145.          db    22      ; a
  146.          db    20      ; g
  147.          db    18      ; f
  148. ;   bar 10                        f 7
  149.          db    21      ; g#
  150.          db    20      ; g
  151.          db    21      ; g#
  152.          db    20      ; g
  153.          db    18      ; f
  154.          db    16      ; d#
  155. ;   bar 11                        c
  156.          db    20      ; g
  157.          db    16      ; d#
  158.          db    17      ; e
  159.          db    20      ; g
  160.          db    16      ; d#
  161.          db    17      ; e
  162. ;   bar 12
  163.          db    23      ; a#
  164.          db    0       ; rest
  165. ;
  166.          db    -1                      ; end of tune table
  167. ;
  168. ;*----------------
  169. ;*   time table
  170. ;*----------------
  171. ;
  172. ;    Each entry in the time table corresponds to one of the
  173. ;    tones above.  Times are multiples of
  174. ;    the 18.2159 Hz heartbeat.
  175. ;
  176. ;    2 = eighth triplet
  177. ;    3 = eighth
  178. ;    4 = quarter triplet
  179. ;    6 = quarter
  180. ;   12 = half
  181. ;   24 = whole
  182. ;
  183. time:
  184. ;
  185.          db    3
  186. ;   bar 1
  187.          db    2
  188.          db    2
  189.          db    2
  190.          db    2
  191.          db    2
  192.          db    8
  193.          db    3
  194.          db    3
  195. ;   bar 2
  196.          db    2
  197.          db    2
  198.          db    2
  199.          db    2
  200.          db    2
  201.          db    8
  202.          db    6
  203. ;   bar 3
  204.          db    3
  205.          db    3
  206.          db    3
  207.          db    3
  208.          db    3
  209.          db    3
  210.          db    3
  211.          db    3
  212. ;   bar 4
  213.          db    12
  214.          db    9
  215.          db    3
  216. ;   bar 5
  217.          db    3
  218.          db    3
  219.          db    3
  220.          db    3
  221.          db    6
  222.          db    6
  223. ;   bar 6
  224.          db    3
  225.          db    6
  226.          db    3
  227.          db    3
  228.          db    6
  229.          db    3
  230. ;   bar 7
  231.          db    6
  232.          db    3
  233.          db    3
  234.          db    6
  235.          db    3
  236.          db    3
  237. ;   bar 8
  238.          db    12
  239.          db    12
  240. ;   bar 9
  241.          db    3
  242.          db    6
  243.          db    3
  244.          db    3
  245.          db    6
  246.          db    3
  247. ;   bar 10
  248.          db    3
  249.          db    6
  250.          db    3
  251.          db    3
  252.          db    6
  253.          db    3
  254. ;   bar 11
  255.          db    6
  256.          db    3
  257.          db    3
  258.          db    6
  259.          db    3
  260.          db    3
  261. ;   bar 12
  262.          db    12
  263.          db    12
  264. ;
  265.          db    -1                      ; end of time table
  266. ;
  267. ;*------------------------------
  268. ;*   start of program
  269. ;*------------------------------
  270. ;
  271. play:
  272.          mov   bx,1                    ; synchronize with the timer ticks
  273.          call  delay                   ; by waiting for next one
  274.          in    al,ppipb                ; get current port status
  275.          or    al,3                    ; turn on lo 2 bits
  276.          out   ppipb,al                ; open gate to timer
  277.          mov   bx,0                    ; tone count
  278.          lea   di,time                 ; point to time table
  279. ;
  280. ;   music loop
  281. ;
  282. ml:
  283.          lea   si,tune                 ; point to tune table
  284.          mov   al,[si][bx]             ; get tone
  285.          mov   dl,[di][bx]             ; get duration
  286.          mov   dh,0                    ; clear duration word
  287.          cmp   al,-1                   ; end ?
  288.          je    done                    ; if so, get out
  289.          push  bx                      ; save count
  290.          test  al,al                   ; rest ?
  291.          jne   norest                  ; if not, carry on
  292.          mov   bx,dx                   ; move duration
  293.          call  rest                    ; turn speaker off
  294.          jmp   repeat                  ; goto repeat
  295. ;
  296. norest:
  297.          cbw                           ; make tone a word
  298.          dec   ax                      ; offset ftom 0
  299.          shl   ax,1                    ; * 2 to index word table
  300.          mov   bx,ax                   ; move to bx
  301.          lea   si,tones                ; point to tone table
  302.          mov   cx,[si][bx]             ; get the tone
  303.          call  maketone                ; turn speaker on
  304.          mov   bx,dx                   ; move duration
  305.          call  delay                   ; wait while it plays
  306. ;
  307. repeat:
  308.          mov   bx,0                    ; break between tones
  309.          call  rest                    ; turn spekaer off
  310.          pop   bx                      ; retrieve count
  311.          inc   bx                      ; + 1
  312.          jmp   ml                      ; loop
  313. ;
  314. ;*-------------------------
  315. ;*  sub routines
  316. ;*-------------------------
  317. ;
  318. ;   Enter maketone with frequency in cx
  319. ;   This routine starts the speaker going
  320. ;   Uses: AX
  321. ;
  322. maketone:
  323.          mov   al,10110110b            ; set up timer for ch 2
  324.          out   tccr,al                 ; timer chip ready for count
  325.          mov   al,cl                   ; get lsb of tone
  326.          out   tc2,al                  ; send to timer
  327.          mov   al,ch                   ; get msb of tone
  328.          out   tc2,al                  ; now tone has started
  329.          ret
  330. ;
  331. ;     Enter delay with delay count in bx
  332. ;     This routine will pause for bx / 18.2 seconds
  333. ;     Uses: AX, CX, DX
  334. ;
  335. delay:
  336.          mov   ah,0                    ; timer function - get time count
  337.          int   26                      ; timer count in cx:dx
  338.          add   bx,dx                   ; add to delay count
  339. delayl:
  340.          int   26                      ; get new timer count
  341.          cmp   bx,dx                   ; thru ?
  342.          jne   delayl                  ; if not, carry on
  343.          ret
  344. ;
  345. ;     Enter rest routine with count in BX
  346. ;
  347. rest:
  348.          in    al,ppipb                ; get current port status
  349.          push  ax                      ; save status
  350.          and   al,11111100b            ; turn off 2 lo bits
  351.          out   ppipb,al                ; send out
  352.          call  delay                   ; now wait
  353.          pop   ax                      ; get back value
  354.          out   ppipb,al                ; turn speaker on
  355.          ret
  356. ;
  357. done:
  358.          in    al,ppipb                ; get port status
  359.          and   al,11111100b            ; turn off 2 lo bits
  360.          out   ppipb,al                ; send it out
  361.          int   32                      ; get out
  362. ;
  363. code     ends
  364. ;
  365.          end   oldbluz
  366.