home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / msdos / sndbords / proaudio / pas_sdk1 / pas / subs / mixers / mixerc.c < prev    next >
C/C++ Source or Header  |  1992-07-27  |  8KB  |  296 lines

  1. /*$Author:   DCODY  $*/
  2. /*$Date:   27 Jul 1992 12:02:46  $*/
  3. /*$Header:   W:/sccs/mixers/mixerc.c_v   1.3   27 Jul 1992 12:02:46   DCODY  $*/
  4. /*$Log:   W:/sccs/mixers/mixerc.c_v  $
  5.  * 
  6.  *    Rev 1.3   27 Jul 1992 12:02:46   DCODY
  7.  * initialized the 32 bit vectors to 0 so they are placed in the initialized
  8.  * static data segment.
  9.  * 
  10.  *    Rev 1.2   25 Jun 1992 23:49:44   DCODY
  11.  * Simplified the routine by eliminating the static linked and disk
  12.  * resident driver loading.
  13.  * 
  14.  *    Rev 1.1   23 Jun 1992 16:45:12   DCODY
  15.  * PAS2 update
  16.  * 
  17.  *    Rev 1.0   15 Jun 1992 09:41:34   BCRANE
  18.  * Initial revision.
  19. */
  20. /*$Logfile:   W:/sccs/mixers/mixerc.c_v  $*/
  21. /*$Modtimes$*/
  22.  
  23. ;    /*\
  24. ;---|*|----====< MIXERC.C >====----
  25. ;---|*|
  26. ;---|*| Initialize and setup the access to the mixers, volume, filter, etc
  27. ;---|*|
  28. ;---|*| Copyright (c) 1991, Media Vision, Inc. All rights reserved
  29. ;---|*|
  30. ;    \*/
  31.  
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. // #include "mixbin.h"              // the actual mixer code
  35. #include "state.h"                  // the state structure
  36.  
  37.         int  ThePASDMAChannel = 0;    // DMA channel
  38.         int  ThePASIRQChannel = 0;    // IRQ channel
  39.  
  40.         static int dummyroutine        ();
  41.  
  42.         int (far *MVSetMixerFunction)  () = 0;
  43.         int (far *MVSetVolumeFunction) () = 0;
  44.         int (far *MVSetFilterFunction) () = 0;
  45.         int (far *MVSetCrossChannel)   () = 0;
  46.         int (far *MVGetMixerFunction)  () = 0;
  47.         int (far *MVGetVolumeFunction) () = 0;
  48.         int (far *MVGetFilterFunction) () = 0;
  49.         int (far *MVGetCrossChannel)   () = 0;
  50.         int (far *MVRealSoundSwitch)   () = 0;
  51.         int (far *MVFMSplitSwitch)       () = 0;
  52.  
  53. #define STATICDRIVER    0x0000        // The static driver is loaded.
  54. #define DOSDRIVER        0x0001        // The DOS driver is loaded.
  55. // #define DISKDRIVER    0x0002        // The Disk resident driver is loaded.
  56.  
  57.         // shadow pointer has the active state table pointer
  58.  
  59.         extern struct MVState far *mvhwShadowPointer;
  60.  
  61.         // MVMixerHWState allows the pointer to be changed
  62.  
  63.         struct MVState far *MVMixerHWState(struct MVState far *);
  64.  
  65. ////
  66. ////  /*\
  67. ////  |*|----====< test code >====----
  68. ////  |*|
  69. ////  |*| this is test code to be removed
  70. ////  |*|
  71. ////  \*/
  72. //// int main()
  73. //// {
  74. ////
  75. ////    // In each of the following calls, MVInitMixerCode will search for
  76. ////    // the DOS driver, "MVSOUND.SYS". If found, all succeeding calls to
  77. ////    // the mixers will be routed through MVSOUND.SYS. If the DOS driver
  78. ////    // is not found, then either the DISK based version, or the static
  79. ////    // version will be used. To select the DISK based version, pass a
  80. ////    // path to MVInitMixerCode. Any pointer (other than a NULL) will tell
  81. ////    // the routine to load the driver from the disk. NOTE: If loading from
  82. ////    // the disk fails, then the static driver will be used.
  83. ////
  84. ////    //
  85. ////    // EXAMPLE #1 - The following will attempt to
  86. ////    //                load the driver from the disk.
  87. ////
  88. ////        MVInitMixerCode ( "." );
  89. ////
  90. ////    //
  91. ////    // EXAMPLE #2 - the following will use the
  92. ////    //                static built-in driver.
  93. ////
  94. ////        MVInitMixerCode ( 0 );
  95. //// }
  96. ////
  97.  
  98. ;    /*\
  99. ;---|*|----====< MVInitMixerCode >====----
  100. ;---|*|
  101. ;---|*| Load link to the DOS driver, or load the mixer code
  102. ;---|*|
  103. ;---|*| Entry Conditions:
  104. ;---|*|     char *path is the path to the disk resident driver.
  105. ;---|*|
  106. ;---|*| Return Value:
  107. ;---|*|      0, the mixer code is using the static driver.
  108. ;---|*|      1, the mixer code is using DOS driver.
  109. ;---|*|
  110. ;    \*/
  111.  
  112. int MVInitMixerCode()
  113. {
  114. char *p,*p1;
  115. int n,mx,tablelen;
  116. long far *bfp;            // buffer far pointer
  117. long far *tfp;            // table far pointer
  118. long mvver;             // MVSOUND.SYS version #
  119.  
  120. static int retry = 0;    // reentry flag. We will only execute once
  121. static int retcode = 0;
  122.  
  123.     // exit if this code has already been executed
  124.  
  125.         if (retry++)
  126.             return(retcode);
  127.  
  128.     // flush some variables
  129.  
  130.         mx = 0;
  131.  
  132.         _asm {
  133.  
  134.             ; fill in the functions in case MVSOUND.SYS is not loaded
  135.  
  136.             mov     bx, offset dummyroutine
  137.             mov     word ptr [MVSetMixerFunction+0],bx
  138.             mov     word ptr [MVSetMixerFunction+2],cs
  139.  
  140.             mov     word ptr [MVSetVolumeFunction+0],bx
  141.             mov     word ptr [MVSetVolumeFunction+2],cs
  142.  
  143.             mov     word ptr [MVSetFilterFunction+0],bx
  144.             mov     word ptr [MVSetFilterFunction+2],cs
  145.  
  146.             mov     word ptr [MVSetCrossChannel+0],bx
  147.             mov     word ptr [MVSetCrossChannel+2],cs
  148.  
  149.             mov     word ptr [MVGetMixerFunction+0],bx
  150.             mov     word ptr [MVGetMixerFunction+2],cs
  151.  
  152.             mov     word ptr [MVGetVolumeFunction+0],bx
  153.             mov     word ptr [MVGetVolumeFunction+2],cs
  154.  
  155.             mov     word ptr [MVGetFilterFunction+0],bx
  156.             mov     word ptr [MVGetFilterFunction+2],cs
  157.  
  158.             mov     word ptr [MVGetCrossChannel+0],bx
  159.             mov     word ptr [MVGetCrossChannel+2],cs
  160.  
  161.             mov     word ptr [MVRealSoundSwitch+0],bx
  162.             mov     word ptr [MVRealSoundSwitch+2],cs
  163.  
  164.             mov     word ptr [MVFMSplitSwitch+0],bx
  165.             mov     word ptr [MVFMSplitSwitch+2],cs
  166.  
  167.         ; deterine if the DOS driver is loaded
  168.  
  169.             mov     ax,0xbc00                ; function 0 is for ID
  170.             mov     bx,0x3f3f
  171.             sub     cx,cx
  172.             sub     dx,dx
  173.             int     2fh                     ; go get it...
  174.             xor     bx,cx                    ; combine all registers
  175.             xor     bx,dx
  176.             cmp     bx,0x4d56                ; to form 'MV'
  177.             jnz     mvininodosdriver
  178.  
  179.             mov     ax,0xbc01                ; get the version
  180.             int     2fh
  181.  
  182.             mov     word ptr [mvver+0],bx    ; save the version
  183.             mov     word ptr [mvver+2],cx
  184.  
  185.         ; the DOS driver is loaded, use it's vectors, data, etc
  186.  
  187.             sub     cx,cx                    ; comes back 0 or the entry length
  188.             mov     ax,0xbc03                ; get the vector table
  189.             int     0x2f                    ; from the DOS driver
  190.  
  191.             mov     word ptr [tfp+0],bx     ; save the function pointer offset
  192.             mov     word ptr [tfp+2],dx     ; and segment
  193.             mov     [tablelen],cx
  194.  
  195.             mov     ax,0bc04h                ; get the DMA & IRQ
  196.             int     0x2f                    ; from the DOS driver
  197.  
  198.             mov     byte ptr ThePASDMAChannel,bl    ; DMA channel
  199.             mov     byte ptr ThePASIRQChannel,cl    ; IRQ channel
  200.  
  201.           mvininodosdriver:
  202.  
  203.         }
  204.  
  205.     // we have the pointer to some table. Now, load each function
  206.     // pointer into the individual far pointers.
  207.  
  208.         if (mvver > 0x30313032)         // ASCII version 0102
  209.             retcode = DOSDRIVER;        // indicate the DOS driver is loaded
  210.  
  211.     // set the first 4 (1st rev of MVSOUND just had 4 functions)
  212.  
  213.         (long) MVSetMixerFunction  = (long) *tfp++;
  214.         (long) MVSetVolumeFunction = (long) *tfp++;
  215.         (long) MVSetFilterFunction = (long) *tfp++;
  216.         (long) MVSetCrossChannel   = (long) *tfp++;
  217.  
  218.     // set the next entries (later revs of MVSOUND had 10 functions)
  219.  
  220.         if (tablelen > 4) {
  221.             (long) MVGetMixerFunction  = (long) *tfp++;
  222.             (long) MVGetVolumeFunction = (long) *tfp++;
  223.             (long) MVGetFilterFunction = (long) *tfp++;
  224.             (long) MVGetCrossChannel   = (long) *tfp++;
  225.             (long) MVRealSoundSwitch   = (long) *tfp++;
  226.             (long) MVFMSplitSwitch       = (long) *tfp;
  227.         }
  228.  
  229.     // return the code
  230.  
  231.     return retcode;
  232. }
  233.  
  234.  
  235. ;    /*\
  236. ;---|*|----====< MVMixerHWState >====----
  237. ;---|*|
  238. ;---|*| fetch and/or load a pointer to the state table.
  239. ;---|*|
  240. ;---|*| Entry Conditions:
  241. ;---|*|     MVState far *  --  pointer to another table. If NULL (0),
  242. ;---|*|                        the current pointer is only returned. Only
  243. ;---|*|                        non-zero table pointers will be loaded.
  244. ;---|*| Return Value:
  245. ;---|*|      Returns the pointer to the table currently
  246. ;---|*|      used by the mixer code.
  247. ;---|*|
  248. ;    \*/
  249.  
  250. struct MVState far *MVMixerHWState(tbl)
  251.     struct MVState far *tbl;
  252. {
  253.  
  254.     // if the shadow pointer is not initialized, then do it...
  255.  
  256.         if (!mvhwShadowPointer)
  257.             MVInitStatePtr();
  258.  
  259.     // In the first rev of software the static driver could receive
  260.     // the caller's state table. Now that the static driver is gone,
  261.     // we don't want to mess with...
  262.  
  263.         //    if (tbl)
  264.         //        mvhwShadowPointer = tbl;
  265.  
  266.     // return the active table
  267.  
  268.         return (tbl);
  269. }
  270.  
  271.  
  272. ;    /*\
  273. ;---|*|----====< static dummyroutine >====----
  274. ;---|*|
  275. ;---|*| This routine no-ops out the function calls in case MVSOUND.SYS
  276. ;---|*| is not loaded.
  277. ;---|*|
  278. ;---|*| Entry Conditions:
  279. ;---|*|     none
  280. ;---|*|
  281. ;---|*| Return Value:
  282. ;---|*|      0
  283. ;---|*|
  284. ;    \*/
  285.  
  286. static int dummyroutine ()
  287. {
  288.     return 0;
  289. }
  290.  
  291. ;    /*\
  292. ;---|*| End of MIXERC.C
  293. ;    \*/
  294.  
  295.  
  296.