home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / gallery / vtasm.inc < prev   
Text File  |  1994-04-17  |  13KB  |  322 lines

  1. ; ------------------------- VTASM.INC -------------------------
  2. ; ASM include file for accessing the DemoVT.
  3. ; (C) Copyright 1993-1994 by the VangeliSTeam. However, it is made
  4. ; public domain for non-commercial use.
  5.  
  6. ; First we declare the structure that holds the DemoVT variables.
  7. ; We will get its address to check semaphores, modify volume, and
  8. ; all that.
  9.  
  10. TChanData STRUC
  11.       Period DW ?
  12.       Ins    DB ?
  13.       Vol    DB ?
  14. ENDS
  15.  
  16. VTRunInfo SEGMENT AT 0
  17.   ; These are modified by DemoVT, and you can read them.
  18.       Semaphores     DB 256 DUP(?)      ; Array of semaphores. You can read or
  19.                                         ; modify them (usually cleaning them).
  20.  
  21.  
  22.       ChansTrig      DB  32 DUP(?)      ; == 1 -> channel retriggered a note.
  23.       NumChannels    DB ?               ; Number of channels in the MOD.
  24.  
  25.       CtrlEntryPoint DD ?               ; Address of ther DemoVT service proc.
  26.       TickCounter    DD ?               ; This one provides some form for you
  27.                                         ; to do timing, incremented at 50Hz.
  28.       RegEntryPoint  DD ?               ; DVT Service taking parm in AX.
  29.       ChansData      TChanData 32 DUP (<>) ; Per-channel info.
  30.       Pos            DB ?               ; Note in the current pattern.
  31.       Seq            DB ?               ; Number of playing pattern.
  32.  
  33.                      DB 81 DUP(?)      ; Reserved.
  34.  
  35.   ; These are supposed to be modified by you to tell DemoVT your intentions. :)
  36.                      DB  ?              ; Reserved.
  37.                      DW  ?              ; Reserved.
  38.  
  39.       JumpNewPos     DB  ?              ; Indicates that you want to jump to
  40.                                         ; another position inside the MOD.
  41.       JumpPosSeq     DB  ?              ; Sequence position to jump to.
  42.       JumpPosNote    DB  ?              ; Note inside the pattern to jump to.
  43.  
  44.       SoundVolume    DB  ?              ; Put your favourite volume here.
  45.                                         ; You can perform fades and the like.
  46.                                         ; 0-255.
  47.       Abort          DB ?               ; Set to 1 to force DVT to exit after
  48.                                         ; your program exits.
  49.  
  50.                      DB 248 DUP(?)      ; Reserved.
  51.  
  52. ENDS
  53.  
  54.         .CODE           ; Easy way to make a code segment. U may want to
  55.                         ; modify it if you don't use simplified directives.
  56.  
  57.   MagicAX    = 5654h;  {'VT'}   ; Some constants for the DemoVT detection.
  58.   MagicBX    = 5472h;  {'Tr'}
  59.   MagicCX    = 6163h;  {'ac'}
  60.   MagicXorBX = 6B65h;  {'ke'}
  61.   MagicXorCX = 7220h;  {'r '}
  62.  
  63.  
  64. AppIDFound DD 0         ; Address inside the DemoVT.
  65. DVTRunInfo DD 0         ; Address of the VTRunInfo declared above.
  66.  
  67. TickVal    DW 0         ; Temporary var used by VTWaitForStart.
  68.  
  69.  
  70. ; ========================== FUNCTIONS ==========================
  71. ; You can count these modify ALL registers.
  72.  
  73. ; -------------------------------- InitMusic
  74. ; Call this if you want to mess with the DemoVT. I suppose you want to.
  75. ; It detects whether DemoVT is present (DL = 1) or not (DL = 0), and
  76. ; initalizes the above pointers.
  77.  
  78. InitMusic:
  79.                 MOV     AX,MagicAX      ; DemoVT's complex detection scheme.
  80.                 MOV     BX,MagicBX      ; If MicroZooft had been a bit more
  81.                 MOV     CX,MagicCX      ; precise when creating the INT 2Fh
  82.                 XOR     DI,DI           ; maybe this would be more standard.
  83.                 MOV     ES,DI           ; Don't try to understand WHY this,
  84.                 INT     2Fh             ; just believe it.
  85.                 XOR     DL,DL
  86.                 AND     AX,AX
  87.                 JNZ     @@no
  88.                 CMP     BX,MagicBX XOR MagicXorBX
  89.                 JNZ     @@no
  90.                 CMP     CX,MagicCX XOR MagicXorCX
  91.                 JNZ     @@no
  92.                                         ; Geez, it really IS present!
  93.                 INC     DL              ; Save pointers.
  94.                 MOV     WORD PTR CS:[AppIDFound+2],ES
  95.                 MOV     WORD PTR CS:[AppIDFound],DI
  96.                 LES     DI,ES:[DI-4]
  97.                 MOV     WORD PTR CS:[DVTRunInfo+2],ES
  98.                 MOV     WORD PTR CS:[DVTRunInfo],DI
  99.         @@no:   MOV     AL,DL
  100.                 RET
  101.  
  102. ; -------------------------------- CallMusic
  103. ; Calls the player when in polled mode. This means that if you want
  104. ; to use the timer (IRQ 0) for your application, you must manually
  105. ; call the DemoVT so that it will play the partiture. This routine
  106. ; must be called at least at a 50Hz average rate; if you don't, the
  107. ; music will jump. You can call it several times before making a
  108. ; long process; experiment how many times you need to avoid jumps.
  109.  
  110. CallMusic:
  111.                 CMP     WORD PTR CS:[DVTRunInfo+2],0    ; Check.
  112.                 JZ      @@Fin
  113.                 LES     SI,CS:[DVTRunInfo]              ; ES:SI = DemoVT info.
  114.                 PUSH    2                               ; Select CallMusic.
  115.                 CALL    ES:[SI+CtrlEntryPoint]          ; Call the DemoVT.
  116.         @@Fin:
  117.                 RET
  118.  
  119. ; -------------------------------- VTConnectTimer
  120. ; Turn on timer mode. In this mode the player uses the system timer to
  121. ; perform its task, so you don't need to manually call InitMusic. But
  122. ; you also can't use the timer for you. Please don't hook to the IRQ0
  123. ; and then call the old handler (DemoVT's), if you want to do such a
  124. ; thing use the polled mode.
  125.  
  126. VTConnectTimer:
  127.                 CMP     WORD PTR CS:[DVTRunInfo+2],0    ; Check.
  128.                 JZ      @@Fin
  129.                 LES     SI,CS:[DVTRunInfo]              ; ES:SI = DemoVT info.
  130.                 PUSH    0                               ; Select VTConnectTimer.
  131.                 CALL    ES:[SI+CtrlEntryPoint]          ; Call the DemoVT.
  132.         @@Fin:
  133.                 RET
  134.  
  135. ; -------------------------------- VTDisconnectTimer
  136. ; Enter polled mode. From now on, make frequent calls to CallMusic, and
  137. ; feel free to do what you desire with the IRQ0 timer.
  138.  
  139. VTDisconnectTimer:
  140.                 CMP     WORD PTR CS:[DVTRunInfo+2],0    ; Check.
  141.                 JZ      @@Fin
  142.                 LES     SI,CS:[DVTRunInfo]              ; ES:SI = DemoVT info.
  143.                 PUSH    1                               ; Select VTDisconnectTimer.
  144.                 CALL    ES:[SI+CtrlEntryPoint]          ; Call the DemoVT.
  145.         @@Fin:
  146.                 RET
  147.  
  148. ; -------------------------------- VTGetTickCounter
  149. ; Reads the internal 50Hz counter of the DemoVT into DX:AX. Use this to
  150. ; synchronize with the music in terms of time played. (For synchronization
  151. ; you can also use the semaphores described later.)
  152.  
  153. VTGetTickCounter:
  154.                 XOR     AX,AX                             ; If DemoVT is not present,
  155.                 XOR     DX,DX                             ; the value is always zero.
  156.                 CMP     WORD PTR CS:[DVTRunInfo+2],0      ; Check.
  157.                 JZ      @@Fin
  158.  
  159.                 LES     SI,CS:[DVTRunInfo]
  160.                 MOV     AX,WORD PTR ES:[SI+TickCounter]   ; Now get the real values.
  161.                 MOV     DX,WORD PTR ES:[SI+TickCounter+2]
  162.  
  163.         @@Fin:  RET
  164.  
  165. ; -------------------------------- VTBeginSync
  166. ; Performs the usual preparations for calling the next routines. Call
  167. ; this when you want to be a bit in sync with the music. If you just
  168. ; want a background music you won't need this, but I'd advise you to
  169. ; call it anyway 'cause I'm not sure of the behaviour (I ALWAYS call
  170. ; it).
  171.  
  172. VTBeginSync:
  173.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  174.                 JZ      @@Fin
  175.  
  176.                 LES     SI,CS:[DVTRunInfo]
  177.                 PUSH    3
  178.                 CALL    ES:[SI+CtrlEntryPoint]
  179.  
  180.         @@Fin:  RET
  181.  
  182. ; -------------------------------- VTWaitForStart
  183. ; Performs a half-second wait and initializes the tick counter to
  184. ; zero. In the DemoVT, the music always goes half a second behind
  185. ; you; this means that, for example, a volume change will take
  186. ; effect that half second later. Use this routine to prepare yourself
  187. ; for that change.
  188. ; Another place where you will want to use this is at the start of a
  189. ; song. Right after calling VTBeginSync, there will be no music; call
  190. ; VTWaitForStart, and it will return at the precise moment when the
  191. ; first note of the song is starting to fill your ears.
  192.  
  193. VTWaitForStart:
  194.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  195.                 JZ      @@Fin
  196.  
  197.                 CALL    VTGetTickCounter
  198.                 XOR     AX,AX
  199.                 MOV     WORD PTR ES:[SI+TickCounter],AX
  200.                 MOV     WORD PTR ES:[SI+TickCounter+2],AX
  201.  
  202.                 MOV     CS:[TickVal],AX
  203.         @@lp:    CALL   CallMusic
  204.                  CALL   VTGetTickCounter
  205.                  SUB    AX,25
  206.                  CMP    AX,CS:[TickVal]
  207.                  JNZ    @@lp
  208.  
  209.                 XOR     AX,AX
  210.                 MOV     WORD PTR ES:[SI+TickCounter],AX
  211.                 MOV     WORD PTR ES:[SI+TickCounter+2],AX
  212.  
  213.         @@Fin:  RET
  214.  
  215. ; -------------------------------- VTJumpPos
  216. ; Jump to some precise pattern in the sequence (AH) , and to a note inside
  217. ; that pattern (AL). Both values range from 1 to whatever. Remeber this,
  218. ; FastTracker musicians!
  219.  
  220. VTJumpPos:
  221.                 CMP     WORD PTR CS:[DVTRunInfo+2],0    ; Check.
  222.                 JZ      @@Fin
  223.  
  224.                 LES     SI,CS:[DVTRunInfo]              ; Will take place in the
  225.                 MOV     ES:[SI+JumpNewPos],1            ; next CallMusic or so.
  226.                 MOV     ES:[SI+JumpPosSeq],AH
  227.                 MOV     ES:[SI+JumpPosNote],AL
  228.  
  229.         @@Fin:  RET
  230.  
  231. ; -------------------------------- VTCheckSemaphore
  232. ; Compares AL with the value of the semaphore number 'BX'. Sempahore
  233. ; values are incremented by a special command embedded in the MOD:
  234. ; Command number 8. The parameter of this command gives the number of
  235. ; the semaphore to increment.
  236.  
  237. VTCheckSemaphore:
  238.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  239.                 JZ      @@Fin
  240.  
  241.                 LES     SI,CS:[DVTRunInfo]
  242.                 CMP     ES:[SI+Semaphores+BX],AL
  243.  
  244.         @@Fin:  RET
  245.  
  246. ; -------------------------------- VTSetSemaphore
  247. ; Sets the value of the semaphore # BX to the value AL. You'll find this
  248. ; useful to clear the value of a semaphore that gets set by a command
  249. ; in a pattern that repeats several times. Huuhh... when you need this
  250. ; you will know, I guess.
  251.  
  252. VTSetSemaphore:
  253.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  254.                 JZ      @@Fin
  255.  
  256.                 LES     SI,CS:[DVTRunInfo]
  257.                 MOV     ES:[SI+Semaphores+BX],AL
  258.  
  259.         @@Fin:  RET
  260.  
  261. ; -------------------------------- VTMiddleSync
  262. ; Checks if the sempahore # BX is set. If not, it jumps to the position
  263. ; DH, DL (pattern, note) in the MOD. In any case, it waits for the next
  264. ; semaphore (BX +1) to activate and exits without jumping.
  265. ;
  266. ; You can use this to set precise synchronization points, for example,
  267. ; when starting some part of a trackmo. If you want the music to start at
  268. ; a precise point when you start an effect, you place a pair of semaphores.
  269. ; One before the desired synch point, and the next (numerical) one, half a
  270. ; second after the synch point. If the song has already reached half a
  271. ; second before the first semaphore, then this routine just waits for the
  272. ; second, which is set exactly when the synch point is sounding. If the first
  273. ; semaphore is not set, it jumps to the position and waits for the second as
  274. ; before.
  275. ;
  276. ; We used this to allow you to skip parts of the Inconexia trackmo and keep
  277. ; the music synchronized. It's hard to explain; read the above description
  278. ; and keep it in mind when you need something like this.
  279.  
  280. VTMiddleSync:
  281.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  282.                 JZ      @@Fin
  283.  
  284.                 XOR     AL,AL
  285.                 CALL    VTCheckSemaphore
  286.                 JNZ     @@cont
  287.                  MOV    AX,DX
  288.                  CALL   VTJumpPos
  289.         @@cont: INC     BX
  290.         @@wlp:   CALL   CallMusic
  291.                  MOV    AL,0
  292.                  CALL   VTCheckSemaphore
  293.                  JZ     @@wlp
  294.  
  295.         @@Fin:  RET
  296.  
  297. ; -------------------------------- VTSetSoundVolume
  298. ; Changes the sound's volume to AL. It will really change 1/2 second after
  299. ; this call.
  300. ;
  301. ; You don't have to worry about the delay when you use this to fade the music.
  302. ; Just wait half a second after you finish fading.
  303.  
  304. VTSetSoundVolume:
  305.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  306.                 JZ      @@Fin
  307.                  LES    SI,CS:[DVTRunInfo]
  308.                  MOV    ES:[SI+SoundVolume],AL
  309.         @@Fin:  RET
  310.  
  311. ; -------------------------------- VTGetSoundVolume
  312. ; Reads the sound's volume into AL. Fairly straightforward, ain't it?
  313.  
  314. VTGetSoundVolume:
  315.                 CMP     WORD PTR CS:[DVTRunInfo+2],0
  316.                 JZ      @@Fin
  317.                  LES    SI,CS:[DVTRunInfo]
  318.                  MOV    AL,ES:[SI+SoundVolume]
  319.         @@Fin:  RET
  320.  
  321. ; --------------------- End of VTASM.INC ------------------
  322.