home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / pps110.zip / PPSSRC.ZIP / PPSINS.ASM < prev    next >
Assembly Source File  |  1992-07-23  |  7KB  |  176 lines

  1. ;┌───────────────────────────────────────────────────────────────────────────┐
  2. ;│  FILENAME: PPSINS.ASM  Version 1.01                         │
  3. ;│                                         │
  4. ;│  DATE    : July 15, 1992                             │
  5. ;│                                                                           │
  6. ;│  Ideal Mode -- Turbo Assembler v2.01 and above                 │
  7. ;│                                                                           │
  8. ;│  DESCRIPTION: This file includes all routines for playing instruments.    │
  9. ;└───────────────────────────────────────────────────────────────────────────┘
  10.  
  11.     ideal                ; Use TASM's Ideal mode.
  12.     model    Small,Pascal        ; Define the memory model.
  13.     P286                ; Set up for 286 instructions.
  14.     jumps                ; Have TASM automatically resolve out-
  15.                     ; of-range jumps.
  16.  
  17.     include "pps.inc"
  18.  
  19. codeseg
  20.  
  21. ;╒═══════════════════════════════════════════════════════════════════════════╕
  22. ;│ NAME       : sd_PlayIns                                                   │
  23. ;│                                                                           │
  24. ;│ ENTRY      : AX - Period                                                  │
  25. ;│              BX - RepLen                                                  │
  26. ;│              CX - MaxRep                                                  │
  27. ;│              DX - Repeat                                                  │
  28. ;│              SI - Volume                                                  │
  29. ;│              ES - Sample Segment                                          │
  30. ;│                                                                           │
  31. ;│ RETURN     : Carry Set - Error                                            │
  32. ;│              Carry Clear - Everything OK, music should be playing         │
  33. ;│                                                                           │
  34. ;│ DESCRIPTION: This procedure sets up all pointers, interrupts, and the     │
  35. ;│              likes for the instrument specified.                          │
  36. ;│                                                                           │
  37. ;│              *** Written by Joshua C. Jensen                              │
  38. ;╘═══════════════════════════════════════════════════════════════════════════╛
  39. proc    sd_PlayIns
  40.         uses    ds
  41.         push    ax
  42.         mov     ax,@data
  43.         mov     ds,ax
  44.         pop     ax
  45.         cmp     [Byte MusicPlayerInstalled],1
  46.         jnz     @@End
  47.         call    sd_ShutDownMusicInt
  48.         or      si,si
  49.         jz      @@End
  50.         dec     si
  51.         shl     si,2                    ; Give the effect of all four voices
  52.                                         ; playing at once.
  53.         shl     bx,1
  54.         shl     cx,1
  55.         shl     dx,1
  56.         mov     [Channel1RepLen],bx
  57.         mov     [Channel1MaxRep],cx
  58.         mov     [Channel1Repeat],dx
  59.         mov     bx,si
  60.         mov     [Channel1Vol1],bl
  61.         mov     [Channel1Seg],es
  62.         mov     [Word Channel1Ofs],0
  63.         push    ax
  64.         call    sd_SetFreq
  65.         pop     bx
  66.         or      bx,bx
  67.         jz      @@BlankPeriod
  68.         div     bx
  69.         mov     bx,ax
  70. @@BlankPeriod:
  71.         mov     [Channel1Freq],bx
  72.         call    sd_ReturnInfo
  73.         mov     dx,offset sd_InsInterrupt
  74.         mov     [PlayerInterrupt],dx
  75.         call    sd_SetMainAddr
  76. @@SetupForIns:
  77.         mov     [Byte TypeOfInt],2      ; Specify that the interrupt to be
  78.                                         ; set up is the sample interrupt.
  79.         call    sd_SetupForMusic
  80. @@End:
  81.         ret
  82. endp    sd_PlayIns
  83.  
  84. ;──────────────────────────────────────────────────────────────────────────────┐
  85. ;┌─────────────────────────────────────────────────────────────────────────────┘
  86. ;└─────────────────────────────────────────────────────────────────────────────┐
  87. ;┌─────────────────────────────────────────────────────────────────────────────┘
  88. ;├─────────────────────────────────────────────────────────────────────────────┐
  89. ;│ ******************  Instrument Playback Interrupts  **********************  │
  90. ;└─────────────────────────────────────────────────────────────────────────────┤
  91. ;┌─────────────────────────────────────────────────────────────────────────────┘
  92. ;└─────────────────────────────────────────────────────────────────────────────┐
  93. ;┌─────────────────────────────────────────────────────────────────────────────┘
  94. ;└──────────────────────────────────────────────────────────────────────────────
  95. ;│ The below code was written by Joshua C. Jensen.  Help was obtained from   │
  96. ;│ several professional programmers, the most helpful being Dave Ashcroft.   │
  97. ;│ The help was in building the initial interrupt routines around two years  │
  98. ;│ ago.  They have since been rewritten for speed many times over by myself. │
  99. macro   sd_MonoLessIns
  100.         xor     cx,cx
  101.         xor     dx,dx
  102.  
  103. @@Channel1:
  104.         cmp     [Word Channel1Seg],0    ;;<--Is the channel even on?
  105.         jz      @@ChannelDone           ;;<--If not jump to channel 2
  106.         mov     es,[Channel1Seg]
  107.  
  108.         mov     bx,[Channel1Ofs]
  109.         cmp     bx,[Channel1MaxRep]
  110.         jb      @@Channel1_1
  111.  
  112.         cmp     [Channel1RepLen],0
  113.         jz      @@ChannelTurnInsOff
  114.  
  115.         mov     bx,[Channel1Repeat]
  116.         mov     ax,[Channel1RepLen]
  117.         mov     [Channel1MaxRep],ax
  118. @@Channel1_1:
  119.         mov     ax,[Channel1Freq]
  120.         add     [Byte Channel1OFlow],al
  121.         xchg    ah,cl
  122.         adc     bx,cx
  123.         mov     [Channel1Ofs],bx
  124.         mov     al,[es:bx]
  125.         xor     al,10000000b    ;<-remove the sign
  126.     mul    [Byte Channel1Vol1]
  127. @@ChannelDone:
  128.         mov     al,ah
  129.         jmp     @@DoneWithIt
  130. @@ChannelTurnInsOff:
  131.         mov     [Byte MStatus],1
  132. @@DoneWithIt:
  133. endm    sd_MonoLessIns
  134.  
  135. proc    sd_InsInterrupt near
  136.     push    ds ax es di si bx cx dx bp
  137.         mov     ax,@data
  138.         mov     ds,ax
  139.         cmp     [Byte SoundSource],1
  140.     jnz    @@GetValueToOutput
  141.     mov    dx,[MainAddr]
  142. @@0:    in    al,dx
  143.     rol    al,1
  144.     jb    @@0
  145.     mov    al,10h
  146.         out     dx,al
  147. @@GetValueToOutput:
  148.     sd_MonoLessIns
  149.     cmp    [Byte MStatus],1
  150.     jz    @@FinishTheInterrupt
  151.     mov    dx,[MainAddr]
  152.     mov    bx,ax
  153.     cmp    [Byte SoundSource],1
  154.     jz    @@FinishTheSB
  155.     cmp    [Byte SoundSource],2
  156.     jz    @@FinishTheDAC
  157. @@FinishTheSB:
  158.     in    al,dx                ; tell us to send.
  159.     rol    al,1
  160.     jb    @@FinishTheSB
  161.     mov    ax,bx
  162.     out    dx,al
  163.     jmp    @@FinishTheInterrupt
  164. @@FinishTheDAC:
  165.     out    dx,al
  166.     jmp    @@FinishTheInterrupt
  167. @@FinishTheInterrupt:
  168. @@FinishTheInterrupt2:
  169.     pop    bp dx cx bx si di es
  170.     pop    ax ds
  171.     sti
  172.     iret
  173. endp    sd_InsInterrupt
  174.  
  175. end
  176.