From d956a9d9273eebfacfda58cb3bafff017269d5dc Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Mon, 8 Jun 2020 19:23:36 +0300 Subject: [PATCH] backporting... --- Makefile.wat | 12 +- libs/midas/license.txt | 86 ++++++++ libs/midas/midasdll.h | 518 ++++++++++++++++++++++++++++++++++++++++++++++++ src/audio.h | 54 +++++ src/demo.c | 63 ++++-- src/demo.h | 22 +- src/dos/gfx.c | 7 +- src/dos/main.c | 2 + src/music.c | 96 --------- src/music.h | 10 - 10 files changed, 738 insertions(+), 132 deletions(-) create mode 100644 libs/midas/license.txt create mode 100644 libs/midas/midasdll.h create mode 100644 src/audio.h delete mode 100644 src/music.c delete mode 100644 src/music.h diff --git a/Makefile.wat b/Makefile.wat index 22e909d..8268d57 100644 --- a/Makefile.wat +++ b/Makefile.wat @@ -1,25 +1,25 @@ obj = 3dgfx.obj bsptree.obj bump.obj cfgopt.obj demo.obj djdpmi.obj dynarr.obj & fract.obj gfx.obj gfxutil.obj greets.obj grise.obj hairball.obj infcubes.obj & keyb.obj logger.obj main.obj mesh.obj meshload.obj metaball.obj metasurf.obj & -mouse.obj music.obj noise.obj plasma.obj polyclip.obj polyfill.obj polytest.obj & +mouse.obj audos.obj noise.obj plasma.obj polyclip.obj polyfill.obj polytest.obj & rbtree.obj sball.obj screen.obj smoketxt.obj thunder.obj tilemaze.obj timer.obj & tinyfps.obj treestor.obj ts_text.obj tunnel.obj util.obj vbe.obj vga.obj bin = demo.exe -libs = imago.lib anim.lib +libs = imago.lib anim.lib midas.lib def = -dM_PI=3.141592653589793 -dUSE_HLT opt = -5 -fp5 -otexan -oh -oi -ei dbg = -d2 !ifdef __UNIX__ -incpath = -Isrc -Isrc/dos -Ilibs -Ilibs/imago/src -Ilibs/anim/src -libpath = libpath libs/imago libpath libs/anim +incpath = -Isrc -Isrc/dos -Ilibs -Ilibs/imago/src -Ilibs/anim/src -Ilibs/midas +libpath = libpath libs/imago libpath libs/anim libpath libs/midas RM = rm -f !else -incpath = -Isrc -Isrc\dos -Ilibs -Ilibs\imago\src -Ilibs\anim\src -libpath = libpath libs\imago libpath libs\anim +incpath = -Isrc -Isrc\dos -Ilibs -Ilibs\imago\src -Ilibs\anim\src -Ilibs\midas +libpath = libpath libs\imago libpath libs\anim libpath libs\midas RM = del !endif diff --git a/libs/midas/license.txt b/libs/midas/license.txt new file mode 100644 index 0000000..e905b08 --- /dev/null +++ b/libs/midas/license.txt @@ -0,0 +1,86 @@ + MIDAS Digital Audio System LICENSE + ---------------------------------- + Copyright 1996,1997 Housemarque Inc. + +0. Throughout this license, "the original MIDAS Digital Audio System archive" +or "the original archive" refers to the set of files originally distributed by +Housemarque Inc. as MIDAS Digital Audio System. This license only applies to +the freely distributable versions of MIDAS Digital Audio System, Housemarque +Inc. may make MIDAS Digital Audio System, or portions of it, available under +different licensing conditions for selected licensees. + +"You" refers to the licensee, the person or other legal entity using MIDAS +Digital Audio System. "Using" MIDAS Digital Audio System includes compiling +MIDAS Digital Audio System source code, linking it to other parts of MIDAS +Digital Audio System or your own code to form an executable program, and +distributing portions of MIDAS Digital Audio System with the program. This +program is referred to as "a program using MIDAS Digital Audio System". + +This license applies to all files distributed in the original MIDAS Digital +Audio System archive, including all source code, libraries, binaries and +documentation, unless otherwise stated in the file in its original, unmodified +form as distributed in the original archive. If you are unsure whether or not +a particular file is covered by this license, you must contact us to verify +this. + +MIDAS DIGITAL AUDIO SYSTEM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL ANY OF +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES CAUSED BY THE USE +OR INABILITY TO USE, OF MIDAS DIGITAL AUDIO SYSTEM. + +As you have not signed this license, you are not required to accept it. +However, as MIDAS Digital Audio System is copyrighted material, only this +license grants you the right to use, distribute and modify it. Therefore, by +using, distributing or modifying MIDAS Digital Audio System, you indicate that +you understand and accept all the terms of this license. + + +1. MIDAS Digital Audio System may freely be copied and distributed in its +original, unmodified form as long as no fee is charged for MIDAS Digital Audio +System itself. A fee, not exceeding 10USD, may be charged for the physical act +of copying, as long as it is clearly stated that MIDAS Digital Audio System +itself is free and may always be distributed free of charge. When ever MIDAS +Digital Audio System or portions of it are distributed, this license must be +included in unmodified form, and all files must contain their original +copyright notices. If only a portion of a file is being distributed, the +appropriate copyright notice must be copied into it from the beginning of the +file, and this license must still be included in unmodified form. + + +2. MIDAS Digital Audio System files may freely be modified, and these modified +files distributed under the terms of Section 1 above, provided that the +following conditions are met: + + 2.1. All the modified files must carry their original copyright + notice, in addition to a list of modifications made and their + respective authors. + + 2.2. Modified versions files belonging under this license still do so, + no matter what kind of modifications have been made. + + +3. MIDAS Digital Audio System may not be used in commercial programs, +including shareware. No program using MIDAS Digital Audio System may be sold +for any price, and neither may any fee be charged for the right to use the +program. Programs using MIDAS Digital Audio System may always be freely +distributed if no fee is charged for the distribution and may freely be used +by anyone. The Program and its documentation must clearly state that the +program uses MIDAS Digital Audio System and that it may freely be used and +distributed under the terms of this Section 3. + + +4. MIDAS Digital Audio System, or portions of it, may not be included as parts +of a commercial software package, in source code, object module or any other +form. Neither may MIDAS Digital Audio System, or portions of it, be printed in +a commercial publication, including, but not limited to, magazines and +books. Any software package or publication including portions of MIDAS Digital +Audio System may freely be used and distributed, as stated in Section 3. + +MIDAS Digital Audio System may, however, be included in free software packages +as long as the whole software package can freely be distributed under the +terms of section 3 and all conditions of this license are met. MIDAS Digital +Audio System, or portions of it, may also be printed for personal or +educational usage, provided that no attempt is made to restrict the copying +and usage of any parts of the printout or the publication in which portions of +MIDAS Digital Audio System are included. diff --git a/libs/midas/midasdll.h b/libs/midas/midasdll.h new file mode 100644 index 0000000..13de0a6 --- /dev/null +++ b/libs/midas/midasdll.h @@ -0,0 +1,518 @@ +/* midasdll.h + * + * MIDAS DLL programming interface + * + * $Id: midasdll.h,v 1.32 1997/08/15 16:48:25 pekangas Exp $ + * + * Copyright 1996,1997 Housemarque Inc. + * + * This file is part of MIDAS Digital Audio System, and may only be + * used, modified and distributed under the terms of the MIDAS + * Digital Audio System license, "license.txt". By continuing to use, + * modify or distribute this file you indicate that you have + * read the license and understand and accept it fully. +*/ + + +#ifndef __midasdll_h +#define __midasdll_h + + +/* This is a kluge, but necessary as Watcom C sucks: */ +#ifdef EXPORT_IN_MIDASDLL_H + +#ifdef __WC32__ + #define _FUNC(x) x __export __stdcall + #define MIDAS_CALL __cdecl +#else + #define _FUNC(x) __declspec(dllexport) x __stdcall + #define MIDAS_CALL __cdecl +#endif + +#else + #if defined(__linux__) || defined(__UNIX__) || defined(__DJGPP__) + #define _FUNC(x) x + #define MIDAS_CALL + #else + #ifdef __DOS__ + #define _FUNC(x) x cdecl + #define MIDAS_CALL __cdecl + #else + #define _FUNC(x) x __stdcall + #define MIDAS_CALL __cdecl + #endif + #endif +#endif + + +#if defined(__WATCOMC__) && defined(__cplusplus) +/* Disable to annoying Watcom C++ warnings - I have no idea how to get around + these without breaking Visual C compatibility: */ +#pragma warning 604 9 +#pragma warning 594 9 +#endif + + +/* We'll need to define DWORD, BOOL, TRUE and FALSE if someone hasn't + done that before. For now, we'll just assume that if no-one has defined + TRUE we need to define everything. There definitions are compatible with + windows.h. If something else in your system defines these differently, + things should still work OK as long as FALSE is 0, TRUE is nonzero and + DWORD is 32-bit. Take care that you don't compare BOOLs like "bool == TRUE" + in that case though, just use "bool". + + THIS IS UGLY AND MAY NEED FIXING! + --------------------------------- +*/ + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +typedef int BOOL; +typedef unsigned long DWORD; +#endif /* ifndef TRUE */ + + + +enum MIDASoptions +{ + MIDAS_OPTION_NONE = 0, + MIDAS_OPTION_MIXRATE, + MIDAS_OPTION_OUTPUTMODE, + MIDAS_OPTION_MIXBUFLEN, + MIDAS_OPTION_MIXBUFBLOCKS, + MIDAS_OPTION_DSOUND_MODE, + MIDAS_OPTION_DSOUND_HWND, + MIDAS_OPTION_DSOUND_OBJECT, + MIDAS_OPTION_DSOUND_BUFLEN, + MIDAS_OPTION_16BIT_ULAW_AUTOCONVERT, + MIDAS_OPTION_FILTER_MODE, + MIDAS_OPTION_MIXING_MODE, + MIDAS_OPTION_DEFAULT_STEREO_SEPARATION, + MIDAS_OPTION_FORCE_NO_SOUND +}; + + +enum MIDASmodes +{ + MIDAS_MODE_NONE = 0, + MIDAS_MODE_MONO = 1, + MIDAS_MODE_STEREO = 2, + MIDAS_MODE_8BIT = 4, + MIDAS_MODE_16BIT = 8, + MIDAS_MODE_8BIT_MONO = MIDAS_MODE_8BIT | MIDAS_MODE_MONO, + MIDAS_MODE_8BIT_STEREO = MIDAS_MODE_8BIT | MIDAS_MODE_STEREO, + MIDAS_MODE_16BIT_MONO = MIDAS_MODE_16BIT | MIDAS_MODE_MONO, + MIDAS_MODE_16BIT_STEREO = MIDAS_MODE_16BIT | MIDAS_MODE_STEREO +}; + + + +enum MIDASsampleTypes +{ + MIDAS_SAMPLE_NONE = 0, + MIDAS_SAMPLE_8BIT_MONO = 1, + MIDAS_SAMPLE_16BIT_MONO = 2, + MIDAS_SAMPLE_8BIT_STEREO = 3, + MIDAS_SAMPLE_16BIT_STEREO = 4, + MIDAS_SAMPLE_ADPCM_MONO = 5, + MIDAS_SAMPLE_ADPCM_STEREO = 6, + MIDAS_SAMPLE_ULAW_MONO = 7, + MIDAS_SAMPLE_ULAW_STEREO = 8 +}; + + + +enum MIDASloop +{ + MIDAS_LOOP_NO = 0, + MIDAS_LOOP_YES +}; + + +enum MIDASpanning +{ + MIDAS_PAN_LEFT = -64, + MIDAS_PAN_MIDDLE = 0, + MIDAS_PAN_RIGHT = 64, + MIDAS_PAN_SURROUND = 0x80 +}; + + +enum MIDASchannels +{ + MIDAS_CHANNEL_AUTO = 0xFFFF, + MIDAS_ILLEGAL_CHANNEL = 0xFFFF +}; + + +enum MIDASdsoundModes +{ + MIDAS_DSOUND_DISABLED = 0, + MIDAS_DSOUND_STREAM, + MIDAS_DSOUND_PRIMARY, + MIDAS_DSOUND_FORCE_STREAM +}; + + +enum MIDASpositions +{ + MIDAS_POSITION_DEFAULT = 0xFFFFFFFF +}; + + + +enum MIDASfilterModes +{ + MIDAS_FILTER_NONE = 0, + MIDAS_FILTER_LESS = 1, + MIDAS_FILTER_MORE = 2, + MIDAS_FILTER_AUTO = 3 +}; + + +enum MIDASechoFilterTypes +{ + MIDAS_ECHO_FILTER_NONE = 0, + MIDAS_ECHO_FILTER_LOWPASS = 1, + MIDAS_ECHO_FILTER_HIGHPASS = 2 +}; + + +enum MIDASmixingModes +{ + MIDAS_MIX_NORMAL_QUALITY = 0, + MIDAS_MIX_HIGH_QUALITY = 1 +}; + + +enum MIDASsamplePlayStatus +{ + MIDAS_SAMPLE_STOPPED = 0, + MIDAS_SAMPLE_PLAYING = 1 +}; + + +enum MIDASpostProcPosition +{ + MIDAS_POST_PROC_FIRST = 0, + MIDAS_POST_PROC_LAST +}; + + + +typedef struct +{ + char songName[32]; + unsigned songLength; + unsigned numPatterns; + unsigned numInstruments; + unsigned numChannels; +} MIDASmoduleInfo; + + + +typedef struct +{ + char instName[32]; +} MIDASinstrumentInfo; + + + +typedef struct +{ + unsigned position; + unsigned pattern; + unsigned row; + int syncInfo; + unsigned songLoopCount; +} MIDASplayStatus; + + +typedef struct +{ + unsigned delay; /* milliseconds, 16.16 fixed point */ + int gain; /* gain, 16.16 fixed point */ + int reverseChannels; /* reverse channels? */ + unsigned filterType; /* filter type, MIDASechoFilterTypes */ +} MIDASecho; + + +typedef struct +{ + int feedback; /* feedback, 16.16 fixed point */ + int gain; /* total gain, 16.16 fixed point */ + unsigned numEchoes; /* number of echoes */ + MIDASecho *echoes; /* the echoes */ +} MIDASechoSet; + + +typedef void (MIDAS_CALL *MIDASpostProcFunction)(void *data, + unsigned numSamples, void *user); + +typedef struct _MIDASpostProcessor +{ + struct _MIDASpostProcessor *next, *prev; /* reserved */ + void *userData; /* reserved */ + MIDASpostProcFunction floatMono; + MIDASpostProcFunction floatStereo; + MIDASpostProcFunction intMono; + MIDASpostProcFunction intStereo; +} MIDASpostProcessor; + + + +typedef void* MIDASmodule; +typedef DWORD MIDASmodulePlayHandle; +typedef DWORD MIDASsample; +typedef DWORD MIDASsamplePlayHandle; +typedef void* MIDASstreamHandle; +typedef void* MIDASechoHandle; + + +#ifdef __cplusplus +extern "C" { +#endif + +_FUNC(int) MIDASgetLastError(void); +_FUNC(char*) MIDASgetErrorMessage(int errorCode); + +_FUNC(DWORD) MIDASgetDisplayRefreshRate(void); + +_FUNC(BOOL) MIDASstartup(void); +_FUNC(BOOL) MIDASdetectSD(void); +_FUNC(BOOL) MIDASdetectSoundCard(void); +_FUNC(BOOL) MIDASconfig(void); +_FUNC(BOOL) MIDASloadConfig(char *fileName); +_FUNC(BOOL) MIDASsaveConfig(char *fileName); +_FUNC(BOOL) MIDASreadConfigRegistry(DWORD key, char *subKey); +_FUNC(BOOL) MIDASwriteConfigRegistry(DWORD key, char *subKey); + +_FUNC(BOOL) MIDASinit(void); +_FUNC(BOOL) MIDASsetOption(int option, DWORD value); +_FUNC(DWORD) MIDASgetOption(int option); +_FUNC(BOOL) MIDASclose(void); +_FUNC(BOOL) MIDASsuspend(void); +_FUNC(BOOL) MIDASresume(void); +_FUNC(BOOL) MIDASopenChannels(int numChannels); +_FUNC(BOOL) MIDAScloseChannels(void); +_FUNC(BOOL) MIDASsetAmplification(DWORD amplification); +_FUNC(BOOL) MIDASstartBackgroundPlay(DWORD pollRate); +_FUNC(BOOL) MIDASstopBackgroundPlay(void); +_FUNC(BOOL) MIDASpoll(void); +_FUNC(void) MIDASlock(void); +_FUNC(void) MIDASunlock(void); +_FUNC(char*) MIDASgetVersionString(void); +_FUNC(BOOL) MIDASsetTimerCallbacks(DWORD rate, BOOL displaySync, + void (MIDAS_CALL *preVR)(), + void (MIDAS_CALL *immVR)(), + void (MIDAS_CALL *inVR)()); +_FUNC(BOOL) MIDASremoveTimerCallbacks(void); + +_FUNC(DWORD) MIDASallocateChannel(void); +_FUNC(BOOL) MIDASfreeChannel(DWORD channel); + +_FUNC(MIDASmodule) MIDASloadModule(char *fileName); +_FUNC(MIDASmodulePlayHandle) MIDASplayModule(MIDASmodule module, + BOOL loopSong); +_FUNC(MIDASmodulePlayHandle) MIDASplayModuleSection(MIDASmodule module, + unsigned startPos, + unsigned endPos, + unsigned restartPos, + BOOL loopSong); +_FUNC(BOOL) MIDASstopModule(MIDASmodulePlayHandle playHandle); +_FUNC(BOOL) MIDASfreeModule(MIDASmodule module); + +_FUNC(BOOL) MIDASgetPlayStatus(MIDASmodulePlayHandle playHandle, + MIDASplayStatus *status); +_FUNC(BOOL) MIDASsetPosition(MIDASmodulePlayHandle playHandle, + int newPosition); +_FUNC(BOOL) MIDASsetMusicVolume(MIDASmodulePlayHandle playHandle, + unsigned volume); +_FUNC(BOOL) MIDASgetModuleInfo(MIDASmodule module, MIDASmoduleInfo *info); +_FUNC(BOOL) MIDASgetInstrumentInfo(MIDASmodule module, int instNum, + MIDASinstrumentInfo *info); +_FUNC(BOOL) MIDASsetMusicSyncCallback(MIDASmodulePlayHandle playHandle, + void (MIDAS_CALL *callback) + (unsigned syncInfo, + unsigned position, unsigned row)); +_FUNC(BOOL) MIDASfadeMusicChannel(MIDASmodulePlayHandle playHandle, + unsigned channel, unsigned fade); + +_FUNC(MIDASsample) MIDASloadRawSample(char *fileName, int sampleType, + int loopSample); +_FUNC(MIDASsample) MIDASloadWaveSample(char *fileName, int loopSample); +_FUNC(BOOL) MIDASfreeSample(MIDASsample sample); +_FUNC(BOOL) MIDASallocAutoEffectChannels(unsigned numChannels); +_FUNC(BOOL) MIDASfreeAutoEffectChannels(void); +_FUNC(MIDASsamplePlayHandle) MIDASplaySample(MIDASsample sample, + unsigned channel, int priority, unsigned rate, + unsigned volume, int panning); +_FUNC(BOOL) MIDASstopSample(MIDASsamplePlayHandle sample); +_FUNC(BOOL) MIDASsetSampleRate(MIDASsamplePlayHandle sample, + unsigned rate); +_FUNC(BOOL) MIDASsetSampleVolume(MIDASsamplePlayHandle sample, + unsigned volume); +_FUNC(BOOL) MIDASsetSamplePanning(MIDASsamplePlayHandle sample, + int panning); +_FUNC(BOOL) MIDASsetSamplePriority(MIDASsamplePlayHandle sample, + int priority); +_FUNC(DWORD) MIDASgetSamplePlayStatus(MIDASsamplePlayHandle sample); + +_FUNC(MIDASstreamHandle) MIDASplayStreamFile(char *fileName, + unsigned sampleType, + unsigned sampleRate, + unsigned bufferLength, + int loopStream); +_FUNC(BOOL) MIDASstopStream(MIDASstreamHandle stream); + +_FUNC(MIDASstreamHandle) MIDASplayStreamWaveFile(char *fileName, + unsigned bufferLength, + int loopStream); + +_FUNC(MIDASstreamHandle) MIDASplayStreamPolling(unsigned sampleType, + unsigned sampleRate, + unsigned bufferLength); +_FUNC(unsigned) MIDASfeedStreamData(MIDASstreamHandle stream, + unsigned char *data, unsigned numBytes, BOOL feedAll); + +_FUNC(BOOL) MIDASsetStreamRate(MIDASstreamHandle stream, unsigned rate); +_FUNC(BOOL) MIDASsetStreamVolume(MIDASstreamHandle stream, + unsigned volume); +_FUNC(BOOL) MIDASsetStreamPanning(MIDASstreamHandle stream, int panning); + +_FUNC(DWORD) MIDASgetStreamBytesBuffered(MIDASstreamHandle stream); +_FUNC(BOOL) MIDASpauseStream(MIDASstreamHandle stream); +_FUNC(BOOL) MIDASresumeStream(MIDASstreamHandle stream); + +_FUNC(MIDASechoHandle) MIDASaddEchoEffect(MIDASechoSet *echoSet); +_FUNC(BOOL) MIDASremoveEchoEffect(MIDASechoHandle echoHandle); + +_FUNC(BOOL) MIDASaddPostProcessor(MIDASpostProcessor *postProc, + unsigned procPos, void *userData); +_FUNC(BOOL) MIDASremovePostProcessor(MIDASpostProcessor *postProc); + + + +#ifdef __cplusplus +} +#endif + + + + +#endif + + +/* + * $Log: midasdll.h,v $ + * Revision 1.32 1997/08/15 16:48:25 pekangas + * Added user post-processing functions + * + * Revision 1.31 1997/07/31 16:36:34 pekangas + * Fixed to work in Linux again + * + * Revision 1.30 1997/07/31 14:30:58 pekangas + * Added option MIDAS_OPTION_FORCE_NO_SOUND + * + * Revision 1.29 1997/07/31 10:56:48 pekangas + * Renamed from MIDAS Sound System to MIDAS Digital Audio System + * + * Revision 1.28 1997/07/29 16:51:09 pekangas + * Added sample playing status query + * + * Revision 1.27 1997/07/25 13:49:47 pekangas + * Actually added MIDAS_FILTER_AUTO (oops) + * + * Revision 1.26 1997/07/25 13:48:24 pekangas + * Changed MIDAS_OPTION_OVERSAMPLING setting to MIDAS_OPTION_MIXING_MODE + * Added automatic filtering + * Added MIDASgetOption() + * + * Revision 1.25 1997/07/11 11:05:54 pekangas + * Added new options to the echoes: Each echo now has its own filter setting + * (low/high-pass or nothing) and the whole echo set has a common gain. + * + * Revision 1.24 1997/07/10 18:40:23 pekangas + * Added echo effect support + * + * Revision 1.23 1997/07/09 08:58:00 pekangas + * Added default stereo separation + * + * Revision 1.22 1997/07/08 19:16:44 pekangas + * Added Win32 setup functions, save/restore setup from registry, and + * fixed WinWave to ignore buffer blocks -setting to be compatible with the + * new setup. + * + * Revision 1.21 1997/06/05 20:18:49 pekangas + * Added preliminary support for interpolating mixing (mono only at the + * moment) + * + * Revision 1.20 1997/06/02 00:54:15 jpaana + * Changed most __LINUX__ defines to __UNIX__ for generic *nix porting + * + * Revision 1.19 1997/05/21 17:47:41 pekangas + * Changed MIDASfilterTypes to MIDASfilterModes + * + * Revision 1.18 1997/05/20 20:37:59 pekangas + * Added WAVE support to both streams and samples + * + * Revision 1.17 1997/05/07 17:14:53 pekangas + * Added a lot of new thread synchronization code, mainly to minimize the + * cases where MIDAS state may be modified when the player thread is active + * and vice versa. Added MIDASlock() and MIDASunlock() to the API. + * + * Revision 1.16 1997/05/03 17:54:02 pekangas + * Added optional simple output filtering + * + * Revision 1.15 1997/05/02 13:19:49 pekangas + * Several changes: Added support for non-looping module playback, added + * support for playing several modules simultaneously, added module section + * playback, added automatic channel allocation and deallocation to stream + * playback, simplified automatic effect channel handling and added functions + * for allocating and deallocating individiual channels. + * + * Revision 1.14 1997/04/08 15:48:07 pekangas + * Added gmpFadeChannel / MIDASfadeMusicChannel functions + * + * Revision 1.13 1997/04/07 21:07:51 pekangas + * Added the ability to pause/resume streams. + * Added functions to query the number of stream bytes buffered + * + * Revision 1.12 1997/03/09 19:13:01 pekangas + * Added the possibility to turn off u-law autoconvert + * + * Revision 1.11 1997/03/05 16:49:49 pekangas + * Added timer functions to DLL, some other minor modifications + * + * Revision 1.10 1997/02/27 16:03:36 pekangas + * Added DJGPP support + * + * Revision 1.9 1997/02/20 19:49:40 pekangas + * Added u-law sample type + * + * Revision 1.8 1997/02/19 20:45:09 pekangas + * Added functions MIDASsuspend() and MIDASresume() + * + * Revision 1.7 1997/02/12 17:18:37 pekangas + * Added MIDASsetAmplification() + * + * Revision 1.6 1997/02/12 16:28:12 pekangas + * Added ADPCM sample type + * + * Revision 1.5 1997/02/06 20:58:20 pekangas + * Added DirectSound support - new files, errors, and global flags + * + * Revision 1.4 1997/01/16 18:41:59 pekangas + * Changed copyright messages to Housemarque + * + * Revision 1.3 1997/01/16 18:26:27 pekangas + * Added numerous new functions + * + * Revision 1.2 1996/09/28 08:12:40 jpaana + * Fixed for Linux + * + * Revision 1.1 1996/09/25 18:38:12 pekangas + * Initial revision + * +*/ diff --git a/src/audio.h b/src/audio.h new file mode 100644 index 0000000..f362781 --- /dev/null +++ b/src/audio.h @@ -0,0 +1,54 @@ +#ifndef AUDIO_H_ +#define AUDIO_H_ + +enum { AU_STOPPED, AU_PLAYING }; + +enum { + AU_CUR = 0x7000, + AU_VOLUP = 0x7100, + AU_VOLDN = 0x7200 +}; + +struct au_module { + char *name; + void *impl; +}; + +int au_init(void); +void au_shutdown(void); + +struct au_module *au_load_module(const char *fname); +void au_free_module(struct au_module *mod); + +int au_play_module(struct au_module *mod); +void au_update(void); +int au_stop_module(struct au_module *mod); +int au_module_state(struct au_module *mod); + +int au_volume(int vol); +int au_sfx_volume(int vol); +int au_music_volume(int vol); + +/* pay no attention to the man behind the curtain */ +#define AU_VOLADJ(vol, newvol) \ + do { \ + int d; \ + switch(newvol & 0xff00) { \ + case AU_CUR: \ + return (vol); \ + case AU_VOLUP: \ + d = newvol & 0xff; \ + (newvol) = (vol) + (d ? d : 16); \ + if((newvol) >= 256) (newvol) = 255; \ + break; \ + case AU_VOLDN: \ + d = newvol & 0xff; \ + (newvol) = (vol) - (d ? d : 16); \ + if((newvol) < 0) (newvol) = 0; \ + break; \ + default: \ + break; \ + } \ + } while(0) + +#endif /* AUDIO_H_ */ diff --git a/src/demo.c b/src/demo.c index 7067ccd..f9d4900 100644 --- a/src/demo.c +++ b/src/demo.c @@ -8,7 +8,7 @@ #include "demo.h" #include "screen.h" #include "3dgfx.h" -#include "music.h" +#include "audio.h" #include "cfgopt.h" #include "console.h" #include "tinyfps.h" @@ -16,19 +16,21 @@ #define MOUSE_TIMEOUT 1200 -/* -#define FB_WIDTH 320 -#define FB_HEIGHT 240 +#define GUARD_XPAD 0 +#define GUARD_YPAD 32 -int fb_width = FB_WIDTH; -int fb_height = FB_HEIGHT; -int fb_bpp = 16; -*/ +int fb_width, fb_height, fb_bpp, fb_scan_size; +float fb_aspect; +long fb_size, fb_buf_size; uint16_t *fb_pixels, *vmem; +uint16_t *fb_buf; + unsigned long time_msec; int mouse_x, mouse_y; unsigned int mouse_bmask; +static struct au_module *mod; + float sball_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; static unsigned long last_mouse_move; @@ -71,7 +73,7 @@ int demo_init(int argc, char **argv) g3d_framebuffer(FB_WIDTH, FB_HEIGHT, fb_pixels); if(opt.music) { - if(music_open("data/test.mod") == -1) { + if(!(mod = au_load_module("data/test.mod"))) { return -1; } } @@ -94,7 +96,7 @@ int demo_init(int argc, char **argv) memset(fb_pixels, 0, FB_WIDTH * FB_HEIGHT * FB_BPP / CHAR_BIT); if(opt.music) { - music_play(); + au_play_module(mod); } return 0; } @@ -102,7 +104,7 @@ int demo_init(int argc, char **argv) void demo_cleanup(void) { if(opt.music) { - music_close(); + au_free_module(mod); } scr_shutdown(); g3d_destroy(); @@ -113,6 +115,43 @@ void demo_cleanup(void) } } +int demo_resizefb(int width, int height, int bpp) +{ + int newsz, new_scansz; + + if(!width || !height || !bpp) { + free(fb_buf); + fb_buf = fb_pixels = 0; + fb_size = fb_buf_size = fb_scan_size = 0; + fb_width = fb_height = fb_bpp = 0; + return 0; + } + + new_scansz = ((width + GUARD_XPAD * 2) * bpp + 7) / 8; + newsz = (height + GUARD_YPAD * 2) * new_scansz; + + if(!fb_buf || newsz > fb_buf_size) { + void *tmp = malloc(newsz); + if(!tmp) return -1; + + free(fb_buf); + fb_buf = tmp; + fb_buf_size = newsz; + } + + fb_scan_size = new_scansz; + fb_pixels = (uint16_t*)((char*)fb_buf + GUARD_YPAD * fb_scan_size + (GUARD_XPAD * bpp + 7) / 8); + fb_width = width; + fb_height = height; + fb_bpp = bpp; + fb_size = fb_scan_size * fb_height; + + fb_aspect = (float)fb_width / (float)fb_height; + + return 0; +} + + void demo_draw(void) { if(opt.mouse) { @@ -128,7 +167,7 @@ void demo_draw(void) } if(opt.music) { - music_update(); + au_update(); } scr_update(); scr_draw(); diff --git a/src/demo.h b/src/demo.h index 349cc53..2060630 100644 --- a/src/demo.h +++ b/src/demo.h @@ -2,13 +2,15 @@ #define DEMO_H_ #include "inttypes.h" +#include "gfx.h" +#include "cfgopt.h" /*extern int fb_width, fb_height, fb_bpp;*/ #define FB_WIDTH 320 #define FB_HEIGHT 240 #define FB_BPP 16 -extern uint16_t *fb_pixels; /* system-RAM pixel buffer: use swap_buffers(fb_pixels) */ -extern uint16_t *vmem; /* visible video memory pointer */ +extern uint16_t *fb_pixels; +extern uint16_t *vmem; extern unsigned long time_msec; extern int mouse_x, mouse_y; @@ -22,8 +24,9 @@ enum { /* special keys */ enum { + KB_BACKSP = 8, KB_ESC = 27, - KB_BACKSP = 127, + KB_DEL = 127, KB_NUM_0, KB_NUM_1, KB_NUM_2, KB_NUM_3, KB_NUM_4, KB_NUM_5, KB_NUM_6, KB_NUM_7, KB_NUM_8, KB_NUM_9, @@ -39,11 +42,21 @@ enum { KB_HELP, KB_PRINT, KB_SYSRQ, KB_BREAK }; +#ifndef KB_ANY +#define KB_ANY (-1) +#define KB_ALT (-2) +#define KB_CTRL (-3) +#define KB_SHIFT (-4) +#endif + + extern float sball_matrix[16]; int demo_init(int argc, char **argv); void demo_cleanup(void); +int demo_resizefb(int width, int height, int bpp); + void demo_draw(void); void demo_post_draw(void *pixels); @@ -55,8 +68,7 @@ void demo_quit(void); unsigned long get_msec(void); void set_palette(int idx, int r, int g, int b); -/* if pixels is 0, it defaults to fb_pixels */ -void swap_buffers(void *pixels); +#define swap_buffers(pix) blit_frame(pix ? pix : fb_pixels, opt.vsync) void change_screen(int idx); diff --git a/src/dos/gfx.c b/src/dos/gfx.c index 1f9b727..48b5c20 100644 --- a/src/dos/gfx.c +++ b/src/dos/gfx.c @@ -229,7 +229,7 @@ void *set_video_mode(int idx, int nbuf) } /* allocate main memory framebuffer */ - if(resizefb(vm->xsz, vm->ysz, vm->bpp) == -1) { + if(demo_resizefb(vm->xsz, vm->ysz, vm->bpp) == -1) { fprintf(stderr, "failed to allocate %dx%d (%d bpp) framebuffer\n", vm->xsz, vm->ysz, vm->bpp); set_text_mode(); @@ -269,7 +269,8 @@ void *page_flip(int vsync) static void blit_frame_lfb(void *pixels, int vsync) { - if(show_fps) dbg_fps(pixels); + demo_post_draw(pixels); + if(vsync) wait_vsync(); memcpy64(vpgaddr[frontidx], pixels, pgsize >> 3); } @@ -280,7 +281,7 @@ static void blit_frame_banked(void *pixels, int vsync) unsigned int pending; unsigned char *pptr = pixels; - if(show_fps) dbg_fps(pixels); + demo_post_draw(pixels); if(vsync) wait_vsync(); diff --git a/src/dos/main.c b/src/dos/main.c index 7535681..0de90ed 100644 --- a/src/dos/main.c +++ b/src/dos/main.c @@ -8,6 +8,8 @@ #include "logger.h" #include "cdpmi.h" #include "audio.h" +#include "sball.h" +#include "vmath.h" static int handle_sball_event(sball_event *ev); static void recalc_sball_matrix(float *xform); diff --git a/src/music.c b/src/music.c deleted file mode 100644 index fe8ed6d..0000000 --- a/src/music.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include "music.h" - -#ifdef __WATCOMC__ -#define NO_MUSIC -#endif - -#ifndef NO_MUSIC -#include "mikmod.h" - -static MODULE *mod; -static int initialized; - -static int init(void) -{ - MikMod_RegisterAllDrivers(); - MikMod_RegisterAllLoaders(); - - md_mode |= DMODE_SOFT_MUSIC | DMODE_16BITS | DMODE_STEREO | DMODE_INTERP; - if(MikMod_Init("") != 0) { - fprintf(stderr, "mikmod init failed: %s\n", - MikMod_strerror(MikMod_errno)); - return -1; - } - - return 0; -} - -int music_open(const char *fname) -{ - if(!initialized) { - if(init() == -1) { - return -1; - } - initialized = 1; - } - - if(!(mod = Player_Load(fname, 64, 0))) { - fprintf(stderr, "failed to load music: %s: %s\n", fname, - MikMod_strerror(MikMod_errno)); - return -1; - } - return 0; -} - -void music_close(void) -{ - if(mod) { - printf("shutting down music playback\n"); - music_stop(); - Player_Free(mod); - mod = 0; - } -} - -void music_play(void) -{ - Player_Start(mod); -} - -void music_stop(void) -{ - Player_Stop(); -} - -void music_update(void) -{ - if(Player_Active()) { - MikMod_Update(); - } -} - -#else /* NO_MUSIC */ - -int music_open(const char *fname) -{ - return 0; -} - -void music_close(void) -{ -} - -void music_play(void) -{ -} - -void music_stop(void) -{ -} - -void music_update(void) -{ -} - -#endif diff --git a/src/music.h b/src/music.h deleted file mode 100644 index 7f388ae..0000000 --- a/src/music.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MUSIC_H_ -#define MUSIC_H_ - -int music_open(const char *fname); -void music_close(void); -void music_play(void); -void music_stop(void); -void music_update(void); - -#endif /* MUSIC_H_ */ -- 1.7.10.4