home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / CDMP16.ZIP / SOURCE.ZIP / CDMIDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-28  |  14.1 KB  |  503 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*                                                                         */
  4. /*                   (c) 1993,1994 by Kaya Memisoglu                       */
  5. /*                                    aka Marc van Shaney                  */
  6. /*                                                                         */
  7. /* Die KOMMERZIELLE Nutzung des Source-Codes ohne meine schriftliche       */
  8. /* Genehmigung ist untersagt. Desweiteren hafte ich für keinerlei          */
  9. /* Schaden den das Programm verursacht.                                    */
  10. /*                                                                         */
  11. /* Geschrieben mit Borland C++ 3.1                                         */
  12. /*     Borland C++ ist eingetragenes Warenzeichen der                      */
  13. /*                                  Borland Inernational INC               */
  14. /*                                                                         */
  15. /*                                                                         */
  16. /* 18.1.1994 - Kaya Memisoglu                                              */
  17. /*                                                                         */
  18. /***************************************************************************/
  19.  
  20.  
  21. #include <dos.h>
  22. #include <bios.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <mem.h>
  26. #include <string.h>
  27.  
  28. #include "ext386.h"
  29. #include "cdmi.h"
  30. #include "vga.h"
  31. #include "frame.h"
  32.  
  33. /****************************************************************************
  34.  **
  35.  ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  36.  ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  37.  **
  38.  ** THERE IS A *VERY* IMPORTANT THING I HAVE TO TELL YOU, BEFORE YOU COMPILE
  39.  ** THIS CODE:
  40.  ** MAKE SURE THAT SI AND DI ARE *NOT* USED AS REGISTER VARIABLES, BECAUSE I
  41.  ** DO NOT SAVE THEM IN THE CDMI. IF YOU WANT TO USE THEM, YOU MUST CHANGE
  42.  ** THE CDMI.ASM CODE PLUS THE DRIVERS (ADLIB.ASM, SPEAKER.ASM, ...)
  43.  **
  44.  ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  45.  ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
  46.  **
  47.  **/
  48.  
  49.  
  50. /****************************************************************************
  51.  **
  52.  ** Any sounddriver you link in must contain such a header structure. Look
  53.  ** at the SBDMA_Driver routine in SBDMA.ASM what I mean. This header is
  54.  ** then used by CDMI in order to activate/deactivate the soundoutput.
  55.  ** Also have a look at the structure SoundDrv in SOUNDDRV.H. The structure
  56.  ** you use (you can also implement such a driver in C) must mach this
  57.  ** structure. And DO NOT FORGET to initilize these pointers !!!
  58.  **
  59.  ** P.S.: The drivers supplied with this demo have a configuration-info
  60.  ** which enables you to select the Interrupt etc. In order to parse
  61.  ** this info-structur, Config_Driver(Driver_Header *) is supplied here.
  62.  **
  63.  **/
  64.  
  65. extern SoundDrv *SBDMA_Driver;
  66. extern SoundDrv *SPEAKER_Driver;
  67. extern SoundDrv *SBTIMER_Driver;
  68. extern SoundDrv *LPT_Driver;
  69. extern SoundDrv *ADLIB_Driver;
  70.  
  71. #ifndef __DRIVER_STRUCT
  72. #define __DRIVER_STRUCT
  73.  
  74. #define CONFIG_MAGIC        0x36bea73f
  75. #define CONFIG_STRING        1
  76. #define CONFIG_INTEGER        2
  77. #define CONFIG_SELECT        3
  78. #define CONFIG_SWITCH        4
  79. #define CONFIG_TEXT        5
  80.  
  81. typedef struct {
  82.         char Type;
  83.         char Text_Len;
  84.         int Dataptr;
  85.         int Parameter[6];
  86.         char Text[];
  87.            } Config_Object;
  88. typedef struct {
  89.         long Magic;
  90.         int  Config_Count;
  91.         Config_Object First_Object;
  92.            } Driver_Setup;
  93.  
  94. typedef struct {
  95.         char Copyright[28];
  96.         long Size;
  97.         char Type[16];
  98.         char Name[32];
  99.         int Version;
  100.         int Function_Count;
  101.         Driver_Setup *Config;
  102.         int Driver[];
  103.            } Driver_Header;
  104.  
  105. #endif
  106.  
  107. int Config_Driver(Driver_Header *Drv)
  108. {
  109.  Config_Object *Cur_Obj;
  110.  int *dataptr,i;
  111.  
  112.  if ((Drv->Config->Magic!=CONFIG_MAGIC) || (Drv->Config->Config_Count==0))
  113.      return TRUE;
  114.  
  115.  Cur_Obj=&Drv->Config->First_Object;
  116.  
  117.  for (i=0;i<Drv->Config->Config_Count;i++)
  118.     {
  119.      dataptr=MK_FP(FP_SEG(Drv),Cur_Obj->Dataptr);
  120.      switch (Cur_Obj->Type)
  121.         {
  122.          case CONFIG_TEXT:
  123.                      printf("%s\n",Cur_Obj->Text);
  124.             break;
  125.          case CONFIG_INTEGER:
  126.                      printf("%s (%d - %d):",Cur_Obj->Text,Cur_Obj->Parameter[0],Cur_Obj->Parameter[1]);
  127.                         scanf("%d",dataptr);
  128.             break;
  129.         }
  130.      Cur_Obj=MK_FP(FP_SEG(Cur_Obj),FP_OFF(Cur_Obj)+16+(int)Cur_Obj->Text_Len);
  131.     }
  132.  
  133.  return TRUE;
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. /***************************************************************************
  143.  **
  144.  ** Here's a little getkey function. It substitutes the Borland getch()
  145.  ** function,because it also return special codes.
  146.  **
  147.  **/
  148.  
  149.  
  150. int getkey(void)
  151. {
  152.  int key, lo, hi;
  153.  
  154.  key = bioskey(0);
  155.  lo = key & 0X00FF;
  156.  hi = (key & 0XFF00) >> 8;
  157.  return((lo == 0) ? hi + 256 : lo);
  158. }
  159.  
  160.  
  161.  
  162. /***************************************************************************
  163.  **
  164.  **  This little MACRO is used to find out if there is a key in the buffer.
  165.  ** I don't use kbhit(), because there is a conflict between this function
  166.  ** and my interrupt-handler causing a lock-up.
  167.  **
  168.  **/
  169.  
  170. #ifndef BIOS_kbhit
  171. #define BIOS_kbhit    ((*((int *)MK_FP(0x040,0x01c)))-(*((int *)MK_FP(0x040,0x01a))))
  172. #endif
  173.  
  174.  
  175.  
  176.  
  177.  
  178. /****************************************************************************
  179.  **
  180.  ** Well, dude , this should be all needed for a basic CDMI-support. I
  181.  ** suggest, that you copy these routines in a seperate file (e.g. CDMISYS.C)
  182.  ** for reuse in your own applications.
  183.  ** Now follows the specific stuff. Just look at the end for driver setup
  184.  ** and music loading/playing.
  185.  **
  186.  **/
  187.  
  188. extern Bitmap CDMI_PIC;
  189. extern Bitmap WALL_PIC;
  190. extern Palette FIRE_PAL;
  191. extern char SCROLLER[1024];
  192. extern int SCROLLER_LEN;
  193. extern int Voice_Loudness(char far *,int);
  194. int ScopeSize=300;
  195.  
  196. static char *Fire_Messages[]={
  197.                "",
  198.                "",
  199.                "",
  200.                "",
  201.                "",
  202.                "",
  203.                "",
  204.                "",
  205.                "Welcome",
  206.                "to",
  207.                "CDMI",
  208.                        "",
  209.                        "I Hope",
  210.                        "you like",
  211.                        "the demo",
  212.                        "and the music !",
  213.                        "",
  214.                        "BTW the music",
  215.                        "is not done by",
  216.                "me, I found it",
  217.                "on a CD and even",
  218.                "the writer stole",
  219.                "it from",
  220.                "Pachelbel",
  221.                        "",
  222.                        "This is my",
  223.                        "first demo",
  224.                        "and I did it",
  225.                        "in only 3 days !",
  226.                        "",
  227.                "I used Borland C",
  228.                "and TASM ;-)",
  229.                        "",
  230.                "These are two",
  231.                "G R E A T",
  232.                "tools",
  233.                        "",
  234.                        "I also wrote a",
  235.                        "386-extender",
  236.                        "to use up to",
  237.                        "4 GigaBytes",
  238.                        "in ASM and C",
  239.                        "",
  240.                        "If you have",
  241.                        "some questions",
  242.                        "about CDMI",
  243.                        "or if you simply",
  244.                        "want to write",
  245.                "to me,"
  246.                        "here is my",
  247.                        "address:",
  248.                        "",
  249.                        "Kaya Memisoglu",
  250.                        "Reichenberger ...",
  251.                        "... Ring 50",
  252.                        "63512 Hainburg",
  253.                        "Germany",
  254.                        "",
  255.                        "",
  256.                "",
  257.                        "",
  258.                        "",
  259.                "E O F",
  260.                "",
  261.                "",
  262.                        "",
  263.                        "",
  264.                "Really, this is",
  265.                "T H E    E N D"
  266.                "",
  267.                "",
  268.                "",
  269.                "",
  270.                        "",
  271.                        "",
  272.                        "",
  273.                        "",
  274.                        "",
  275.                        "",
  276.                        "",
  277.                        "",
  278.                        "",
  279.                        "",
  280.                        "",
  281.                        "Okay,",
  282.                        "here are some",
  283.                        "secret keys:",
  284.                        "1 on/off chn 1",
  285.                        "2 on/off chn 2",
  286.                "7 off/on chn 4",
  287.                "0 on/on chn 3",
  288.                        "L lowpass filter",
  289.                        "M midpass filter",
  290.                        "A highpass filter"
  291.                        "",
  292.                        "Is that enoguh ?",
  293.                        "",
  294.                        "",
  295.                        "",
  296.                        "",
  297.                        "",
  298.                        "",
  299.                        "",
  300.                        "",
  301.                        "",
  302.                        "",
  303.                        "",
  304.                        "",
  305.                ""};
  306.  
  307.  
  308. void Set_Palette(Palette *Pal)
  309. {
  310.  int i;
  311.  
  312.  for (i=0;i<256;i++)
  313.      Set_Colour(&Pal->Colour[i],i);
  314. }
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323. void main (void)
  324. {
  325.  int SONG_Frequency,i,j,k,LastTick=0,l,key=0;
  326.  char *Frame;
  327.  SoundDrv *SND;
  328.  Bitmap *Fire;
  329.  
  330.  if(Init_EXT386(16000,EXT_VERBOSE_RESET|EXT_VERBOSE_PAUSE)<0)
  331.      exit(-1);
  332.  printf("\nCDMI - Demo\n");
  333.  printf("(c) 1994 by Marc van Shaney\n");
  334.  printf("         a.k.a. Kaya Memisoglu\n");
  335.  printf("\nPlease select your Sound device:\n");
  336.  printf("  1. PC-Speaker\n");
  337.  printf("  2. AdLib\n");
  338.  printf("  3. DAC at printer-port\n");
  339.  printf("  4. SoundBlaster DMA\n");
  340.  printf("  5. SoundBlaster Timer\n");
  341.  
  342.  do {
  343.      i=getkey();
  344.      switch (i)
  345.          {
  346.          case '1':
  347.              SND=SPEAKER_Driver;
  348.                 break;
  349.          case '2':
  350.              SND=ADLIB_Driver;
  351.                 break;
  352.          case '3':
  353.              SND=LPT_Driver;
  354.                 break;
  355.          case '4':
  356.              SND=SBDMA_Driver;
  357.                 break;
  358.          case '5':
  359.              SND=SBTIMER_Driver;
  360.                 break;
  361.         }
  362.     }
  363.  while ((i<'1') && (i>'5'));
  364.  
  365.  Config_Driver((Driver_Header *)SND);
  366.  
  367.  printf("\nSelect song frequency:\n");
  368.  printf("  1. 8  kHz\n");
  369.  printf("  2. 12 kHz\n");
  370.  printf("  3. 16 kHz\n");
  371.  printf("  4. 22 kHz\n");
  372.  printf("  5. 30 kHz\n");
  373.  printf("  6. 44 kHz\n");
  374.  
  375.  do {
  376.      i=getkey();
  377.      switch (i)
  378.          {
  379.          case '1':
  380.              SONG_Frequency=8000;
  381.                 break;
  382.          case '2':
  383.              SONG_Frequency=12000;
  384.                 break;
  385.          case '3':
  386.              SONG_Frequency=16000;
  387.                 break;
  388.          case '4':
  389.              SONG_Frequency=22000;
  390.                 break;
  391.          case '5':
  392.              SONG_Frequency=30000;
  393.                 break;
  394.          case '6':
  395.              SONG_Frequency=44000;
  396.                 break;
  397.         }
  398.     }
  399.  while ((i<'1') && (i>'6'));
  400.  
  401.  (*SND->Init_Driver)();
  402.  if(CDMI_Load_MOD("CDMIDEMO.MOD")<0)
  403.      {
  404.          printf("Error loading demo-song !\n\n");
  405.          Exit_EXT386();
  406.      exit(-1);
  407.         }
  408.  
  409.  Init_Graphic();
  410.  Set_Palette(&FIRE_PAL);
  411.  Frame=Malloc(FRAME_SIZE);
  412.  Fire=Malloc((unsigned long)320*140+32);
  413.  memset(Fire,0,320*140+32);
  414.  Fire->Width=320;
  415.  Fire->Height=120;
  416.  Clear_Frame(Frame,0);
  417.  
  418.  CDMI_Play_Song(SONG_Frequency,LOOP_FLAG,SND);
  419.  if (ScopeSize>CDMI_DMA_Size)
  420.      ScopeSize=CDMI_DMA_Size;
  421.  i=0;
  422.  j=0;
  423.  l=0;
  424.  while (key!=27)
  425.      {
  426.          k=80-strlen(Fire_Messages[j])*4;
  427.          Clear_Frame(Frame,0);
  428.          FMove_Fire(Fire);
  429.          FWrite_in_Fire(Fire,k,42,Fire_Messages[j],30);
  430.          FPut_Image(Frame,0,7,Fire);
  431.          FWrite_in_Fire(Fire,k,42,Fire_Messages[j],70);
  432.          FPut_Image(Frame,0,125,&WALL_PIC);
  433.          FDraw_Scroller(Frame,134,SCROLLER,30,i);
  434.          FDraw_Oscilloscope(Frame,160-(ScopeSize>>1),110,ScopeSize,CDMI_DMA_Address,238);
  435.          if (i>199)
  436.             FPut_Sprite(Frame,98,2,&CDMI_PIC);
  437.          else
  438.          if (i<99)
  439.              FZoom_Sprite(Frame,159-i,99-i,161+i,101+i,&CDMI_PIC);
  440.          else
  441.              FZoom_Sprite(Frame,60+((i-99)*4/10),
  442.                    ((i-99)/50),
  443.                    260-((i-99)*42/100),
  444.                    200-((i-99)*143/100),&CDMI_PIC);
  445.  
  446.          FDraw_Water(Frame,156,44);
  447.          Put_Frame(Frame);
  448.          i+=CDMI_Tick-LastTick;
  449.          l+=CDMI_Tick-LastTick;
  450.          LastTick=CDMI_Tick;
  451.          if (i>SCROLLER_LEN)
  452.              i=0;
  453.          if (l>70)
  454.              {
  455.                  FWrite_in_Fire(Fire,k,42,Fire_Messages[j],160);
  456.               if((++j)>105)    j=0;
  457.                  l=0;
  458.                 }
  459.          if (BIOS_kbhit)
  460.              {
  461.                  key=getkey();
  462.                  switch (key)
  463.                      {
  464.                          case '1':
  465.                              CDMI_Channel_Flags^=1;
  466.                                 break;
  467.                          case '2':
  468.                              CDMI_Channel_Flags^=2;
  469.                                 break;
  470.                          case '0':
  471.                              CDMI_Channel_Flags^=4;
  472.                                 break;
  473.                          case '7':
  474.                              CDMI_Channel_Flags^=8;
  475.                                 break;
  476.                          case 'l':
  477.                          case 'L':
  478.                              CDMI_Flags^=LOW_PASS;
  479.                                 break;
  480.                          case 'm':
  481.                          case 'M':
  482.                              CDMI_Flags^=MID_PASS;
  483.                                 break;
  484.                          case 'a':
  485.                          case 'A':
  486.                              CDMI_Flags^=HIGH_PASS;
  487.                                 break;
  488.                         }
  489.                 }
  490.         }
  491.  CDMI_Stop_Song();
  492.  CDMI_Free_Song();
  493.  
  494.  Free(Fire);
  495.  Free(Frame);
  496.  (*SND->Exit_Driver)();
  497.  
  498.  Exit_Graphic();
  499.  printf("\nCDMI 1.0\nCyberDyne Music Interface\nWritten by:\n    Marc van Shaney aka");
  500.  printf(" Kaya Memisoglu\n    Reichenberger Ring 50\n    63512 Hainburg\n    Germany\n\n\n");
  501.  Exit_EXT386();
  502. }
  503.