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

  1. //** Demonstration program for the new MIDPAK and DIGPAK loading and
  2. //** unloading system.    Uses LOADER.C.
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <alloc.h>
  7.  
  8. #include "midpak.h"
  9. #include "doscalls.h"
  10. #include "loader.h"
  11.  
  12. // Define memory allocation functions.    If using DOS memory allocation
  13. // functions, provided through DOSCALLS, then set the conditional compilation
  14. // 'DOSALLOC' to true.  If using C compiler library function memory allocation
  15. // set 'DOSALLOC' to zero.  MUST BE SET TO 1 for RECURSE, because most memory
  16. // allocation has to be on a paragraph boundary!
  17.  
  18. #define DOSALLOC 0
  19. // Redirect memory allocation to either DOS memory allocate functions located
  20. // in DOSCALLS or to C library far memory allocation functions.
  21. unsigned char far * far memalloc(long int siz)
  22. {
  23.     unsigned char far *mem;
  24.  
  25.     #if DOSALLOC
  26.         mem = fmalloc(siz);  // DOS far memory allocation functions
  27.     #else
  28.         mem = farmalloc(siz); // C's far memory allocation functions.
  29.     #endif
  30.     return(mem);
  31. }
  32.  
  33. void far memfree(char far *memory)
  34. {
  35.     #if DOSALLOC
  36.         ffree(memory);
  37.     #else
  38.         farfree(memory);
  39.     #endif
  40. }
  41.  
  42.  
  43. void main(int argc,char **argv)
  44. {
  45.     char far *song;
  46.     long int siz,songlen;
  47.     int xcon,keypress,sequence=0,SegueNumber=0;
  48.     char str[80];
  49.  
  50.     if ( LoadMidPak("MIDPAK.COM", "MIDPAK.ADV", "MIDPAK.AD" ) ) // Load MIDPAK into memory.
  51.     {
  52.         if ( InitMidPak() ) // Initialize MIDPAK driver.
  53.         {
  54.             song = fload("TEST.XMI", &songlen); // Load song into memory.
  55.             if ( song )
  56.             {
  57.                 RegisterXmidi(song,songlen); // register the song.
  58.                 SetRelativeVolume(100,0) ;
  59.                 PlaySequence(0); // play the song.
  60.                 printf("Have begun to play the song...\n");
  61.                 printf("Press a key '0'-'4' to 'segue' to that sequence.\n");
  62.                 xcon = 0;
  63.                 do
  64.                 {
  65.                     sequence = ReportSequenceNumber(); // Find out current sequence number.
  66.                     if ( SequenceStatus() == SEQ_PLAYING )
  67.                         sprintf(str,"Playing sequence #%d",sequence);
  68.                     else
  69.                         sprintf(str,"Sequence #%d not playing.",sequence);
  70.                     tprint(0,0,40,str,BLUE BEHIND YELLOW);
  71.                     sprintf(str,"Next segue request #%d",SegueNumber);
  72.                     tprint(0,1,40,str,BLUE BEHIND YELLOW);
  73.                     if ( keystat() )
  74.                     {
  75.                         keypress = getkey();
  76.                         switch ( keypress )
  77.                         {
  78.                             case 27: xcon = 1;
  79.                             default:
  80.                                 if ( keypress >= '0' && keypress <= '4' )
  81.                                 {
  82.                                     SegueNumber = keypress-'0';
  83.                                     SegueSequence(SegueNumber,-1);
  84.                                     if ( SequenceStatus() != SEQ_PLAYING )
  85.                                     {
  86.                                         PlaySequence(SegueNumber);
  87.                                     }
  88.                                 }
  89.                                 break;
  90.                         }
  91.                     }
  92.                 } while (!xcon);
  93.             }
  94.         }
  95.     }
  96.  
  97.     DeInitMidPak();
  98.     UnLoadMidPak();
  99. }
  100.