home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Aktief 1995 #3 / CDA3.iso / sound / tnypl211.zip / EX1.C < prev    next >
C/C++ Source or Header  |  1994-06-21  |  2KB  |  84 lines

  1. /* ex1.c - example #1 */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <malloc.h>
  7. #include <io.h>
  8. #include <fcntl.h>
  9. #include <i86.h>
  10. #include "modplay.h"
  11.  
  12.  
  13. /* ASM externals prototypes */
  14.  
  15. #pragma aux setgraphmode "_*" parm caller [];
  16. #pragma aux settextmode "_*" parm caller [];
  17. #pragma aux drawscopes "_*" parm caller [ecx];
  18. #pragma aux putlbm "_*" parm caller [esi];
  19.  
  20. extern void setgraphmode(void);
  21. extern void setrtextmode(void);
  22. extern void drawscopes(int numvoices);
  23. extern void putlbm(void *image);
  24.  
  25. /* load IFF/ILBM file */
  26.  
  27. void *loadlbm(char *path)
  28. {
  29.     int handle;
  30.     void *buffer;
  31.     int length;
  32.     if ((handle = open(path,O_RDONLY|O_BINARY)) == -1)
  33.         return NULL;
  34.     length = lseek(handle,0L,SEEK_END);
  35.     lseek(handle,0L,SEEK_SET);
  36.     if ((buffer = malloc(length)) != NULL) {
  37.         if (read(handle,buffer,length) != length) {
  38.             free(buffer);
  39.             buffer = NULL;
  40.         }
  41.     }
  42.     close(handle);
  43.     return buffer;
  44. }
  45.  
  46. void main(void)
  47. {
  48.     Module *Song;
  49.     void *Logo;
  50.     word Port;
  51.     byte IRQ,DRQ;
  52.  
  53.     if (MODDetectCard(&Port,&IRQ,&DRQ)) {
  54.         printf("Sound Blaster not found.\n");
  55.         return;
  56.     }
  57.     printf("Sound Blaster found at Addr:%03x IRQ:%d DMA:%d\n",Port,IRQ,DRQ);
  58.     if ((Song = MODLoadModule("TUNE.MOD")) == NULL) {
  59.         printf("Error loading modulefile.\n");
  60.         return;
  61.     }
  62.     if (MODPlayModule(Song,Song->NumTracks,22222,Port,IRQ,DRQ,PM_TIMER)) {
  63.         printf("Error initializing the sound system.\n");
  64.         MODFreeModule(Song);
  65.         return;
  66.     }
  67.     MODSetMusicVolume(176);
  68.     if ((Logo = loadlbm("LOGO.LBM")) == NULL) {
  69.         printf("Error loading the IFF/ILBM logo picture\n");
  70.         MODStopModule();
  71.         MODFreeModule(Song);
  72.         return;
  73.     }
  74.     setgraphmode();
  75.     putlbm(Logo);
  76.     while (!kbhit())
  77.         drawscopes(Song->NumTracks);
  78.     settextmode();
  79.     free(Logo);
  80.     MODStopModule();
  81.     MODFreeModule(Song);
  82. }
  83.  
  84.