home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /* */
- /* */
- /* (c) 1993,1994 by Kaya Memisoglu */
- /* aka Marc van Shaney */
- /* */
- /* Die KOMMERZIELLE Nutzung des Source-Codes ohne meine schriftliche */
- /* Genehmigung ist untersagt. Desweiteren hafte ich für keinerlei */
- /* Schaden den das Programm verursacht. */
- /* */
- /* Geschrieben mit Borland C++ 3.1 */
- /* Borland C++ ist eingetragenes Warenzeichen der */
- /* Borland Inernational INC */
- /* */
- /* */
- /* 18.1.1994 - Kaya Memisoglu */
- /* */
- /***************************************************************************/
-
-
- #include <dos.h>
- #include <bios.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <mem.h>
- #include <string.h>
-
- #include "ext386.h"
- #include "cdmi.h"
- #include "vga.h"
- #include "frame.h"
-
- /****************************************************************************
- **
- ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
- ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
- **
- ** THERE IS A *VERY* IMPORTANT THING I HAVE TO TELL YOU, BEFORE YOU COMPILE
- ** THIS CODE:
- ** MAKE SURE THAT SI AND DI ARE *NOT* USED AS REGISTER VARIABLES, BECAUSE I
- ** DO NOT SAVE THEM IN THE CDMI. IF YOU WANT TO USE THEM, YOU MUST CHANGE
- ** THE CDMI.ASM CODE PLUS THE DRIVERS (ADLIB.ASM, SPEAKER.ASM, ...)
- **
- ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
- ** !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!
- **
- **/
-
-
- /****************************************************************************
- **
- ** Any sounddriver you link in must contain such a header structure. Look
- ** at the SBDMA_Driver routine in SBDMA.ASM what I mean. This header is
- ** then used by CDMI in order to activate/deactivate the soundoutput.
- ** Also have a look at the structure SoundDrv in SOUNDDRV.H. The structure
- ** you use (you can also implement such a driver in C) must mach this
- ** structure. And DO NOT FORGET to initilize these pointers !!!
- **
- ** P.S.: The drivers supplied with this demo have a configuration-info
- ** which enables you to select the Interrupt etc. In order to parse
- ** this info-structur, Config_Driver(Driver_Header *) is supplied here.
- **
- **/
-
- extern SoundDrv *SBDMA_Driver;
- extern SoundDrv *SPEAKER_Driver;
- extern SoundDrv *SBTIMER_Driver;
- extern SoundDrv *LPT_Driver;
- extern SoundDrv *ADLIB_Driver;
-
- #ifndef __DRIVER_STRUCT
- #define __DRIVER_STRUCT
-
- #define CONFIG_MAGIC 0x36bea73f
- #define CONFIG_STRING 1
- #define CONFIG_INTEGER 2
- #define CONFIG_SELECT 3
- #define CONFIG_SWITCH 4
- #define CONFIG_TEXT 5
-
- typedef struct {
- char Type;
- char Text_Len;
- int Dataptr;
- int Parameter[6];
- char Text[];
- } Config_Object;
- typedef struct {
- long Magic;
- int Config_Count;
- Config_Object First_Object;
- } Driver_Setup;
-
- typedef struct {
- char Copyright[28];
- long Size;
- char Type[16];
- char Name[32];
- int Version;
- int Function_Count;
- Driver_Setup *Config;
- int Driver[];
- } Driver_Header;
-
- #endif
-
- int Config_Driver(Driver_Header *Drv)
- {
- Config_Object *Cur_Obj;
- int *dataptr,i;
-
- if ((Drv->Config->Magic!=CONFIG_MAGIC) || (Drv->Config->Config_Count==0))
- return TRUE;
-
- Cur_Obj=&Drv->Config->First_Object;
-
- for (i=0;i<Drv->Config->Config_Count;i++)
- {
- dataptr=MK_FP(FP_SEG(Drv),Cur_Obj->Dataptr);
- switch (Cur_Obj->Type)
- {
- case CONFIG_TEXT:
- printf("%s\n",Cur_Obj->Text);
- break;
- case CONFIG_INTEGER:
- printf("%s (%d - %d):",Cur_Obj->Text,Cur_Obj->Parameter[0],Cur_Obj->Parameter[1]);
- scanf("%d",dataptr);
- break;
- }
- Cur_Obj=MK_FP(FP_SEG(Cur_Obj),FP_OFF(Cur_Obj)+16+(int)Cur_Obj->Text_Len);
- }
-
- return TRUE;
- }
-
-
-
-
-
-
-
- /***************************************************************************
- **
- ** Here's a little getkey function. It substitutes the Borland getch()
- ** function,because it also return special codes.
- **
- **/
-
-
- int getkey(void)
- {
- int key, lo, hi;
-
- key = bioskey(0);
- lo = key & 0X00FF;
- hi = (key & 0XFF00) >> 8;
- return((lo == 0) ? hi + 256 : lo);
- }
-
-
-
- /***************************************************************************
- **
- ** This little MACRO is used to find out if there is a key in the buffer.
- ** I don't use kbhit(), because there is a conflict between this function
- ** and my interrupt-handler causing a lock-up.
- **
- **/
-
- #ifndef BIOS_kbhit
- #define BIOS_kbhit ((*((int *)MK_FP(0x040,0x01c)))-(*((int *)MK_FP(0x040,0x01a))))
- #endif
-
-
-
-
-
- /****************************************************************************
- **
- ** Well, dude , this should be all needed for a basic CDMI-support. I
- ** suggest, that you copy these routines in a seperate file (e.g. CDMISYS.C)
- ** for reuse in your own applications.
- ** Now follows the specific stuff. Just look at the end for driver setup
- ** and music loading/playing.
- **
- **/
-
- extern Bitmap CDMI_PIC;
- extern Bitmap WALL_PIC;
- extern Palette FIRE_PAL;
- extern char SCROLLER[1024];
- extern int SCROLLER_LEN;
- extern int Voice_Loudness(char far *,int);
- int ScopeSize=300;
-
- static char *Fire_Messages[]={
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "Welcome",
- "to",
- "CDMI",
- "",
- "I Hope",
- "you like",
- "the demo",
- "and the music !",
- "",
- "BTW the music",
- "is not done by",
- "me, I found it",
- "on a CD and even",
- "the writer stole",
- "it from",
- "Pachelbel",
- "",
- "This is my",
- "first demo",
- "and I did it",
- "in only 3 days !",
- "",
- "I used Borland C",
- "and TASM ;-)",
- "",
- "These are two",
- "G R E A T",
- "tools",
- "",
- "I also wrote a",
- "386-extender",
- "to use up to",
- "4 GigaBytes",
- "in ASM and C",
- "",
- "If you have",
- "some questions",
- "about CDMI",
- "or if you simply",
- "want to write",
- "to me,"
- "here is my",
- "address:",
- "",
- "Kaya Memisoglu",
- "Reichenberger ...",
- "... Ring 50",
- "63512 Hainburg",
- "Germany",
- "",
- "",
- "",
- "",
- "",
- "E O F",
- "",
- "",
- "",
- "",
- "Really, this is",
- "T H E E N D"
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "Okay,",
- "here are some",
- "secret keys:",
- "1 on/off chn 1",
- "2 on/off chn 2",
- "7 off/on chn 4",
- "0 on/on chn 3",
- "L lowpass filter",
- "M midpass filter",
- "A highpass filter"
- "",
- "Is that enoguh ?",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- ""};
-
-
- void Set_Palette(Palette *Pal)
- {
- int i;
-
- for (i=0;i<256;i++)
- Set_Colour(&Pal->Colour[i],i);
- }
-
-
-
-
-
-
-
-
- void main (void)
- {
- int SONG_Frequency,i,j,k,LastTick=0,l,key=0;
- char *Frame;
- SoundDrv *SND;
- Bitmap *Fire;
-
- if(Init_EXT386(16000,EXT_VERBOSE_RESET|EXT_VERBOSE_PAUSE)<0)
- exit(-1);
- printf("\nCDMI - Demo\n");
- printf("(c) 1994 by Marc van Shaney\n");
- printf(" a.k.a. Kaya Memisoglu\n");
- printf("\nPlease select your Sound device:\n");
- printf(" 1. PC-Speaker\n");
- printf(" 2. AdLib\n");
- printf(" 3. DAC at printer-port\n");
- printf(" 4. SoundBlaster DMA\n");
- printf(" 5. SoundBlaster Timer\n");
-
- do {
- i=getkey();
- switch (i)
- {
- case '1':
- SND=SPEAKER_Driver;
- break;
- case '2':
- SND=ADLIB_Driver;
- break;
- case '3':
- SND=LPT_Driver;
- break;
- case '4':
- SND=SBDMA_Driver;
- break;
- case '5':
- SND=SBTIMER_Driver;
- break;
- }
- }
- while ((i<'1') && (i>'5'));
-
- Config_Driver((Driver_Header *)SND);
-
- printf("\nSelect song frequency:\n");
- printf(" 1. 8 kHz\n");
- printf(" 2. 12 kHz\n");
- printf(" 3. 16 kHz\n");
- printf(" 4. 22 kHz\n");
- printf(" 5. 30 kHz\n");
- printf(" 6. 44 kHz\n");
-
- do {
- i=getkey();
- switch (i)
- {
- case '1':
- SONG_Frequency=8000;
- break;
- case '2':
- SONG_Frequency=12000;
- break;
- case '3':
- SONG_Frequency=16000;
- break;
- case '4':
- SONG_Frequency=22000;
- break;
- case '5':
- SONG_Frequency=30000;
- break;
- case '6':
- SONG_Frequency=44000;
- break;
- }
- }
- while ((i<'1') && (i>'6'));
-
- (*SND->Init_Driver)();
- if(CDMI_Load_MOD("CDMIDEMO.MOD")<0)
- {
- printf("Error loading demo-song !\n\n");
- Exit_EXT386();
- exit(-1);
- }
-
- Init_Graphic();
- Set_Palette(&FIRE_PAL);
- Frame=Malloc(FRAME_SIZE);
- Fire=Malloc((unsigned long)320*140+32);
- memset(Fire,0,320*140+32);
- Fire->Width=320;
- Fire->Height=120;
- Clear_Frame(Frame,0);
-
- CDMI_Play_Song(SONG_Frequency,LOOP_FLAG,SND);
- if (ScopeSize>CDMI_DMA_Size)
- ScopeSize=CDMI_DMA_Size;
- i=0;
- j=0;
- l=0;
- while (key!=27)
- {
- k=80-strlen(Fire_Messages[j])*4;
- Clear_Frame(Frame,0);
- FMove_Fire(Fire);
- FWrite_in_Fire(Fire,k,42,Fire_Messages[j],30);
- FPut_Image(Frame,0,7,Fire);
- FWrite_in_Fire(Fire,k,42,Fire_Messages[j],70);
- FPut_Image(Frame,0,125,&WALL_PIC);
- FDraw_Scroller(Frame,134,SCROLLER,30,i);
- FDraw_Oscilloscope(Frame,160-(ScopeSize>>1),110,ScopeSize,CDMI_DMA_Address,238);
- if (i>199)
- FPut_Sprite(Frame,98,2,&CDMI_PIC);
- else
- if (i<99)
- FZoom_Sprite(Frame,159-i,99-i,161+i,101+i,&CDMI_PIC);
- else
- FZoom_Sprite(Frame,60+((i-99)*4/10),
- ((i-99)/50),
- 260-((i-99)*42/100),
- 200-((i-99)*143/100),&CDMI_PIC);
-
- FDraw_Water(Frame,156,44);
- Put_Frame(Frame);
- i+=CDMI_Tick-LastTick;
- l+=CDMI_Tick-LastTick;
- LastTick=CDMI_Tick;
- if (i>SCROLLER_LEN)
- i=0;
- if (l>70)
- {
- FWrite_in_Fire(Fire,k,42,Fire_Messages[j],160);
- if((++j)>105) j=0;
- l=0;
- }
- if (BIOS_kbhit)
- {
- key=getkey();
- switch (key)
- {
- case '1':
- CDMI_Channel_Flags^=1;
- break;
- case '2':
- CDMI_Channel_Flags^=2;
- break;
- case '0':
- CDMI_Channel_Flags^=4;
- break;
- case '7':
- CDMI_Channel_Flags^=8;
- break;
- case 'l':
- case 'L':
- CDMI_Flags^=LOW_PASS;
- break;
- case 'm':
- case 'M':
- CDMI_Flags^=MID_PASS;
- break;
- case 'a':
- case 'A':
- CDMI_Flags^=HIGH_PASS;
- break;
- }
- }
- }
- CDMI_Stop_Song();
- CDMI_Free_Song();
-
- Free(Fire);
- Free(Frame);
- (*SND->Exit_Driver)();
-
- Exit_Graphic();
- printf("\nCDMI 1.0\nCyberDyne Music Interface\nWritten by:\n Marc van Shaney aka");
- printf(" Kaya Memisoglu\n Reichenberger Ring 50\n 63512 Hainburg\n Germany\n\n\n");
- Exit_EXT386();
- }
-