home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / asm_programming / AO3.ASM < prev    next >
Assembly Source File  |  1990-10-03  |  3KB  |  109 lines

  1. ; ASCII Organ III
  2.  
  3. timer   equ     42h
  4. speaker equ     61h
  5. sponmsk equ     4fh
  6. spofmsk equ     4ch
  7. settim  equ     0b6h
  8. keyport equ     60h
  9.  
  10. doscall macro   x
  11.         mov     ah,x
  12.         int     21h
  13.         endm
  14.  
  15. pout    macro   x,y
  16.         mov     al,y
  17.         out     x,al
  18.         endm
  19.  
  20. code    segment
  21.         org     100h
  22.         assume  cs:code,ds:code
  23.  
  24. start:  jmp     begin           ; bypass variable storage
  25.  
  26. ;----- Music data -----
  27.  
  28. song    db      17,4,16,4,15,4,16,4,17,4,17,4,17,8
  29.         db      16,4,16,4,16,8,17,4,19,4,19,8
  30.         db      17,4,16,4,15,4,16,4,17,4,17,4,17,4
  31.         db      17,4,16,4,16,4,17,4,16,4,15,4
  32.  
  33. ;----- Timer divisor data (Pitch) ------
  34.  
  35. ;               C-1  D-2  E-3  F-4  G-5  A-6  B-7  C-8  D-9  E-10 F-11
  36. divsors dw 0000,9121,8126,7239,6833,6088,5423,4832,4560,4063,3620,3417
  37. ;               G-12 A-13 B-14 C-15 D-16 E-17 F-18 G-19 A-20 B-21 C-22
  38.         dw      3044,2712,2416,2280,2031,1810,1708,1522,1356,1208,1140
  39. ;               D-23 E-24 F-25 G-26 A-27 B-28
  40.         dw      1016, 905, 854, 761, 678, 604
  41.  
  42. ;----- Variables ------
  43.  
  44. notecnt dw      0                               ; counter for notes played
  45. beatcnt dw      0                               ; counter for beats
  46. tbtn    dw      0                               ; n beats
  47.  
  48. ;----- Initialize ------
  49.  
  50. begin:  mov     al, [song+1]                    ; length of first note
  51.         cbw
  52.         mov     tbtn,ax
  53.         call    playnot                         ; begin first note
  54.         mov     dx,offset target1c
  55.         mov     al,1ch                          ; get timer interrupt
  56.         doscall 25h
  57.         mov     dx,offset lbyte+1
  58.         int     27h                             ; end, make resident
  59.  
  60. ;----- target for interrupt 1Ch ------
  61.  
  62. target1c:
  63.         push    cs                      ; synchronize execution time
  64.         pop     ds     
  65.         inc     beatcnt 
  66.         mov     ax,tbtn     
  67.         cmp     ax,beatcnt              ; end of note?
  68.         je      in2                     ; yes, jump next note
  69.         iret                            ; no...
  70. in2:    cmp     notecnt,(offset divsors - offset song) / 2
  71.         jne     in3                     ; if not equal continue
  72.         mov     byte ptr target1c,0cfh
  73.         iret
  74.  
  75. ; to play following note
  76.  
  77. in3:    push    si                      ; store ds,dx,ax
  78.         inc     notecnt                 ; advance to next note
  79.         mov     beatcnt,0               ; reset beatcount=0
  80.         mov     si,notecnt
  81.         shl     si,1                    ; 2 elements for each note
  82.         mov     al,[si+offset song+1]   ; duration of the note
  83.         cbw
  84.         mov     tbtn,ax
  85.         call    playnot
  86.         pop     si
  87.         iret
  88.  
  89. playnot: mov     si,notecnt
  90.         shl     si,1
  91.         mov     al,[si+offset song]     ; AL = number of note
  92.         or      al,al                   ; force pointers
  93.         jnz     pn1                     ; note 0 is a pause
  94.         pout    speaker,spofmsk
  95.         ret
  96. pn1:    cbw                             ; AH in one byte
  97.         mov     si,ax
  98.         shl     si,1                    ; divisor table
  99.         pout    timer+1,settim
  100.         mov     ax,[si+offset divsors]
  101.         out     timer,al
  102.         mov     al,ah
  103.         out     timer,al
  104.         pout    speaker,sponmsk
  105. lbyte:  ret
  106.  
  107. code    ends
  108.         end     start
  109.