home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / digmid / real / test.c < prev    next >
C/C++ Source or Header  |  1994-01-03  |  7KB  |  224 lines

  1. /*****************************************************************************/
  2. /* TEST.C     DIGPAK & MIDPAK test application. Dynmically loads DIGPAK and      */
  3. /*                    MIDPAK drivers, SOUNDRV.COM and MIDPAK.COM/MIDPAK.ADV/MIDPAK.AD  */
  4. /*                    then plays the MIDI file TEST.XMI and allows you to play sound     */
  5. /*                    effects TEST1.SND and TEST2.SND                                                                  */
  6. /*****************************************************************************/
  7. /*        Written by John W. Ratcliff (c) 1994                                                                     */
  8. /*             Compuserve: 70253,3237                                                                                          */
  9. /*             Genie: J.RATCLIFF3                                                                                                  */
  10. /*             BBS: 1-314-939-0200                                                                                                 */
  11. /*             Addresss:                                                                                                                     */
  12. /*                     747 Napa Lane                                                                                                     */
  13. /*                     St. Charles, MO 63304                                                                                     */
  14. /*                                                                                                                                                     */
  15. /*        A $500 per product license fee applies to all commercial software          */
  16. /*        products distributed with ANY DIGPAK and another $500 for MIDPAK             */
  17. /*        drivers.    That's a total of $1,000 if your product uses BOTH DIGPAK    */
  18. /*        and MIDPAK drivers.  If you distribute any commercial title with DIGPAK*/
  19. /*        and/or MIDPAK drivers resident then this license fee applies.                  */
  20. /*                                                                                                                                                     */
  21. /*        To pay a license, simply write a check for $500 for just DIGPAK              */
  22. /*        $500 for just MIDPAK, or $1,000 for both DIGPAK and MIDPAK single          */
  23. /*        product distribution license payable to:                                                             */
  24. /*                The Audio Solution, 747 Napa Lane, St. Charles, MO 63304                     */
  25. /*                with a copy of your commerical product.  You will receive a signed */
  26. /*                license agreement from The Audio Solution shortly thereafter.          */
  27. /*                This license fee applies specifically to the inclusion with your     */
  28. /*                distribution disk any of the DIGPAK and/or MIDPAK drivers.                 */
  29. /*                These drivers are copyrighted works, created by me, to enhance the */
  30. /*                use of sound and music in DOS based commercial software.    The          */
  31. /*                license fees collected are used to maintain the drivers and keep     */
  32. /*                the BBS running.                                                                                                     */
  33. /*                                                                                                                                                     */
  34. /*                WARNING!!!!!!  You would be ill-advised to distribute a commercial */
  35. /*                product containing either DIGPAK and/or MIDPAK drivers without         */
  36. /*                having paid the distribution license fee.  Since your product would*/
  37. /*                contain unlicensed copyrighted software from The Audio Solution,     */
  38. /*                your product could be required to be immediately removed from retail*/
  39. /*                distribution.  I doubt this is going to be a problem.  Clearly if  */
  40. /*                your product is enhanced by the use of these drivers, your company */
  41. /*                can easily afford a nominal license fee of $1,000 in exchange for  */
  42. /*                getting the use of several man-years of software engineering             */
  43. /*                resources.                                                                                                                 */
  44. /*****************************************************************************/
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <malloc.h>
  48.  
  49. #include "keys.h"         // Include #define's for keyboard commands
  50. #include "loader.h"       // Include header for midpak/digpak dynamic loader
  51. #include "midpak.h"       // Include header for link layer to MIDPAK functions.
  52. #include "digplay.h"      // Include header for link layer to DIGPAK functions.
  53. #include "doscalls.h"     // Include header to assembly DOS support functions.
  54.  
  55. #define NOBJ 4
  56.  
  57. static char *Names[NOBJ] =
  58. {
  59.     "TEST1.SND",
  60.     "TEST2.SND",
  61.     "PEND.SND",
  62.     "TEST.SND"
  63. };
  64.  
  65. static SNDSTRUC snd;
  66. static char *soundbuffer=0;
  67. static long int ssize[NOBJ];
  68. static int NALLOC=0;
  69. char *Sounds[NOBJ]; // addresses of all the beauty sounds.
  70.  
  71. void UnloadSounds(void);
  72. int  LoadSounds(void);
  73. void PlaySound(int sound);
  74. void TestDigPak(void);
  75.  
  76. // Define memory allocation functions.    If using DOS memory allocation
  77. // functions, provided through DOSCALLS, then set the conditional compilation
  78. // 'DOSALLOC' to true.  If using C compiler library function memory allocation
  79. // set 'DOSALLOC' to zero.  MUST BE SET TO 1 for RECURSE, because most memory
  80. // allocation has to be on a paragraph boundary!
  81.  
  82. #define DOSALLOC 0
  83. // Redirect memory allocation to either DOS memory allocate functions located
  84. // in DOSCALLS or to C library far memory allocation functions.
  85. unsigned char far * far memalloc(long int siz)
  86. {
  87.     unsigned char far *mem;
  88.  
  89.     #if DOSALLOC
  90.         mem = fmalloc(siz);  // DOS far memory allocation functions
  91.     #else
  92.         mem = farmalloc(siz); // C's far memory allocation functions.
  93.     #endif
  94.     return(mem);
  95. }
  96.  
  97. void far memfree(char far *memory)
  98. {
  99.     #if DOSALLOC
  100.         ffree(memory);
  101.     #else
  102.         farfree(memory);
  103.     #endif
  104. }
  105.  
  106.  
  107. void main(void)
  108. {
  109.     long int siz;
  110.     char *fname;
  111.  
  112.     if ( !LoadDigPak("SOUNDRV.COM") )
  113.     {
  114.         printf("Failed to load sound driver.\n");
  115.         exit(1);
  116.     }
  117.  
  118.     if ( !InitDigPak() )
  119.     {
  120.         UnLoadDigPak();
  121.         printf("Failed to initialize sound driver.\n");
  122.         exit(1);
  123.     }
  124.  
  125.     if ( LoadMidPak("MIDPAK.COM", "MIDPAK.ADV", "MIDPAK.AD") )
  126.     {
  127.         printf("Loaded MIDPAK.COM MIDPAK.ADV and MIDPAK.AD into Low Mem\n");
  128.         if ( InitMidPak() )
  129.         {
  130.             printf("MIDPAK driver initialized.\n");
  131.             fname = fload("TEST.XMI",&siz);
  132.             if ( fname )
  133.             {
  134.                 printf("Loaded TEST.XMI %d bytes long.\n",siz);
  135.                 RegisterXmidi(fname,siz);
  136.                 printf("Sequence registered, now playing.\n");
  137.                 PlaySequence(0);
  138.                 SegueSequence(1,-1);
  139.             }
  140.         }
  141.         else
  142.             printf("Failed to initialize MIDPAK driver.\n");
  143.     }
  144.  
  145.     TestDigPak();
  146.  
  147.     UnLoadMidPak();
  148.     UnLoadDigPak();
  149. }
  150.  
  151. void TestDigPak(void)
  152. {
  153.     int i,key,sound;
  154.  
  155.   printf("Loading digital sound effects.\n");
  156.     if ( LoadSounds() )
  157.   {
  158.         printf("Select an sound effect to play. [ESC] when finished playing around.\n");
  159.         for (i=0; i<NOBJ; i++)
  160.         {
  161.             printf("%c %s\n",i+'A',Names[i]);
  162.         }
  163.         do
  164.         {
  165.             if ( keystat() )
  166.             {
  167.                 key = getkey();
  168.                 if ( key >= 'a' && key <= 'z') key-=32;
  169.                 if ( key >= 'A' && key <= 'Z')
  170.                 {
  171.                     sound = key-'A';
  172.                     if ( sound < NOBJ ) PlaySound(sound);
  173.                 }
  174.             }
  175.         } while ( key != 27 );
  176.         UnloadSounds();
  177.     }
  178. }
  179.  
  180. // Load all of the sound files into memory.
  181. int LoadSounds(void)
  182. {
  183.   int fph;
  184.   long int siz,end;
  185.   int i,handle,j;
  186.   int select;
  187.  
  188.   for (i=0; i<NOBJ; i++)
  189.   {
  190.     Sounds[i] = fload(Names[i], &siz);
  191.     if ( !Sounds[i] )
  192.     {
  193.       printf("File '%s' not found.\n",Names[i]);
  194.       return(0);
  195.     }
  196.     ssize[i] = siz;
  197.         snd.frequency = 11000;
  198.         snd.sound = Sounds[i];
  199.         snd.sndlen = ssize[i]; // Specify length of sound effect in bytes.
  200.         MassageAudio(&snd);
  201.     printf("Sound Loaded '%s'.\n",Names[i]);
  202.   }
  203.     return(1);
  204. }
  205.  
  206. void UnloadSounds(void)
  207. {
  208.     int i;
  209.  
  210.     for (i=0; i<NALLOC; i++) memfree(Sounds[i]);
  211.     NALLOC=0;
  212. }
  213.  
  214.  
  215. void PlaySound(int sound)
  216. {
  217.     StopSound(); // Wait for previous sound to complete.
  218.     snd.frequency = 11000;
  219.     snd.sound = Sounds[sound];
  220.     snd.sndlen = ssize[sound]; // Specify length of sound effect in bytes.
  221.     DigPlay2(&snd); // play preformated sound effect.
  222. }
  223.  
  224.