?? id_sd.c
字號:
SoundPositioned = false;
}
else
DigiMissed = true;
}
}
void
SD_SetDigiDevice(SDSMode mode)
{
boolean devicenotpresent;
if (mode == DigiMode)
return;
SD_StopDigitized();
devicenotpresent = false;
switch (mode)
{
case sds_SoundBlaster:
if (!SoundBlasterPresent)
{
if (SoundSourcePresent)
mode = sds_SoundSource;
else
devicenotpresent = true;
}
break;
case sds_SoundSource:
if (!SoundSourcePresent)
devicenotpresent = true;
break;
}
if (!devicenotpresent)
{
if (DigiMode == sds_SoundSource)
SDL_ShutSS();
DigiMode = mode;
if (mode == sds_SoundSource)
SDL_StartSS();
SDL_SetTimerSpeed();
}
}
void
SDL_SetupDigi(void)
{
memptr list;
word far *p,
pg;
int i;
PM_UnlockMainMem();
MM_GetPtr(&list,PMPageSize);
PM_CheckMainMem();
p = (word far *)MK_FP(PM_GetPage(ChunksInFile - 1),0);
_fmemcpy((void far *)list,(void far *)p,PMPageSize);
pg = PMSoundStart;
for (i = 0;i < PMPageSize / (sizeof(word) * 2);i++,p += 2)
{
if (pg >= ChunksInFile - 1)
break;
pg += (p[1] + (PMPageSize - 1)) / PMPageSize;
}
PM_UnlockMainMem();
MM_GetPtr((memptr *)&DigiList,i * sizeof(word) * 2);
_fmemcpy((void far *)DigiList,(void far *)list,i * sizeof(word) * 2);
MM_FreePtr(&list);
NumDigi = i;
for (i = 0;i < LASTSOUND;i++)
DigiMap[i] = -1;
}
// AdLib Code
///////////////////////////////////////////////////////////////////////////
//
// alOut(n,b) - Puts b in AdLib card register n
//
///////////////////////////////////////////////////////////////////////////
void
alOut(byte n,byte b)
{
asm pushf
asm cli
asm mov dx,0x388
asm mov al,[n]
asm out dx,al
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm inc dx
asm mov al,[b]
asm out dx,al
asm popf
asm dec dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
asm in al,dx
}
#if 0
///////////////////////////////////////////////////////////////////////////
//
// SDL_SetInstrument() - Puts an instrument into a generator
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_SetInstrument(int track,int which,Instrument far *inst,boolean percussive)
{
byte c,m;
if (percussive)
{
c = pcarriers[which];
m = pmodifiers[which];
}
else
{
c = carriers[which];
m = modifiers[which];
}
tracks[track - 1]->inst = *inst;
tracks[track - 1]->percussive = percussive;
alOut(m + alChar,inst->mChar);
alOut(m + alScale,inst->mScale);
alOut(m + alAttack,inst->mAttack);
alOut(m + alSus,inst->mSus);
alOut(m + alWave,inst->mWave);
// Most percussive instruments only use one cell
if (c != 0xff)
{
alOut(c + alChar,inst->cChar);
alOut(c + alScale,inst->cScale);
alOut(c + alAttack,inst->cAttack);
alOut(c + alSus,inst->cSus);
alOut(c + alWave,inst->cWave);
}
alOut(which + alFeedCon,inst->nConn); // DEBUG - I think this is right
}
#endif
///////////////////////////////////////////////////////////////////////////
//
// SDL_ALStopSound() - Turns off any sound effects playing through the
// AdLib card
//
///////////////////////////////////////////////////////////////////////////
#ifdef _MUSE_
void
#else
static void
#endif
SDL_ALStopSound(void)
{
asm pushf
asm cli
(long)alSound = 0;
alOut(alFreqH + 0,0);
asm popf
}
static void
SDL_AlSetFXInst(Instrument far *inst)
{
byte c,m;
m = modifiers[0];
c = carriers[0];
alOut(m + alChar,inst->mChar);
alOut(m + alScale,inst->mScale);
alOut(m + alAttack,inst->mAttack);
alOut(m + alSus,inst->mSus);
alOut(m + alWave,inst->mWave);
alOut(c + alChar,inst->cChar);
alOut(c + alScale,inst->cScale);
alOut(c + alAttack,inst->cAttack);
alOut(c + alSus,inst->cSus);
alOut(c + alWave,inst->cWave);
// Note: Switch commenting on these lines for old MUSE compatibility
// alOut(alFeedCon,inst->nConn);
alOut(alFeedCon,0);
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_ALPlaySound() - Plays the specified sound on the AdLib card
//
///////////////////////////////////////////////////////////////////////////
#ifdef _MUSE_
void
#else
static void
#endif
SDL_ALPlaySound(AdLibSound far *sound)
{
Instrument far *inst;
byte huge *data;
SDL_ALStopSound();
asm pushf
asm cli
alLengthLeft = sound->common.length;
data = sound->data;
data++;
data--;
alSound = (byte far *)data;
alBlock = ((sound->block & 7) << 2) | 0x20;
inst = &sound->inst;
if (!(inst->mSus | inst->cSus))
{
asm popf
Quit("SDL_ALPlaySound() - Bad instrument");
}
SDL_AlSetFXInst(&alZeroInst); // DEBUG
SDL_AlSetFXInst(inst);
asm popf
}
#if 0
///////////////////////////////////////////////////////////////////////////
//
// SDL_ALSoundService() - Plays the next sample out through the AdLib card
//
///////////////////////////////////////////////////////////////////////////
//static void
void
SDL_ALSoundService(void)
{
byte s;
if (alSound)
{
s = *alSound++;
if (!s)
alOut(alFreqH + 0,0);
else
{
alOut(alFreqL + 0,s);
alOut(alFreqH + 0,alBlock);
}
if (!(--alLengthLeft))
{
(long)alSound = 0;
alOut(alFreqH + 0,0);
SDL_SoundFinished();
}
}
}
#endif
#if 0
void
SDL_ALService(void)
{
byte a,v;
word w;
if (!sqActive)
return;
while (sqHackLen && (sqHackTime <= alTimeCount))
{
w = *sqHackPtr++;
sqHackTime = alTimeCount + *sqHackPtr++;
asm mov dx,[w]
asm mov [a],dl
asm mov [v],dh
alOut(a,v);
sqHackLen -= 4;
}
alTimeCount++;
if (!sqHackLen)
{
sqHackPtr = (word far *)sqHack;
sqHackLen = sqHackSeqLen;
alTimeCount = sqHackTime = 0;
}
}
#endif
///////////////////////////////////////////////////////////////////////////
//
// SDL_ShutAL() - Shuts down the AdLib card for sound effects
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_ShutAL(void)
{
asm pushf
asm cli
alOut(alEffects,0);
alOut(alFreqH + 0,0);
SDL_AlSetFXInst(&alZeroInst);
alSound = 0;
asm popf
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_CleanAL() - Totally shuts down the AdLib card
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_CleanAL(void)
{
int i;
asm pushf
asm cli
alOut(alEffects,0);
for (i = 1;i < 0xf5;i++)
alOut(i,0);
asm popf
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_StartAL() - Starts up the AdLib card for sound effects
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_StartAL(void)
{
alFXReg = 0;
alOut(alEffects,alFXReg);
SDL_AlSetFXInst(&alZeroInst);
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_DetectAdLib() - Determines if there's an AdLib (or SoundBlaster
// emulating an AdLib) present
//
///////////////////////////////////////////////////////////////////////////
static boolean
SDL_DetectAdLib(void)
{
byte status1,status2;
int i;
alOut(4,0x60); // Reset T1 & T2
alOut(4,0x80); // Reset IRQ
status1 = readstat();
alOut(2,0xff); // Set timer 1
alOut(4,0x21); // Start timer 1
#if 0
SDL_Delay(TimerDelay100);
#else
asm mov dx,0x388
asm mov cx,100
usecloop:
asm in al,dx
asm loop usecloop
#endif
status2 = readstat();
alOut(4,0x60);
alOut(4,0x80);
if (((status1 & 0xe0) == 0x00) && ((status2 & 0xe0) == 0xc0))
{
for (i = 1;i <= 0xf5;i++) // Zero all the registers
alOut(i,0);
alOut(1,0x20); // Set WSE=1
alOut(8,0); // Set CSM=0 & SEL=0
return(true);
}
else
return(false);
}
#if 0
///////////////////////////////////////////////////////////////////////////
//
// SDL_t0Service() - My timer 0 ISR which handles the different timings and
// dispatches to whatever other routines are appropriate
//
///////////////////////////////////////////////////////////////////////////
static void interrupt
SDL_t0Service(void)
{
static word count = 1;
#if 1 // for debugging
asm mov dx,STATUS_REGISTER_1
asm in al,dx
asm mov dx,ATR_INDEX
asm mov al,ATR_OVERSCAN
asm out dx,al
asm mov al,4 // red
asm out dx,al
#endif
HackCount++;
if ((MusicMode == smm_AdLib) || (DigiMode == sds_SoundSource))
{
SDL_ALService();
SDL_SSService();
// if (!(++count & 7))
if (!(++count % 10))
{
LocalTime++;
TimeCount++;
if (SoundUserHook)
SoundUserHook();
}
// if (!(count & 3))
if (!(count % 5))
{
switch (SoundMode)
{
case sdm_PC:
SDL_PCService();
break;
case sdm_AdLib:
SDL_ALSoundService();
break;
}
}
}
else
{
if (!(++count & 1))
{
LocalTime++;
TimeCount++;
if (SoundUserHook)
SoundUserHook();
}
switch (SoundMode)
{
case sdm_PC:
SDL_PCService();
break;
case sdm_AdLib:
SDL_ALSoundService();
break;
}
}
asm mov ax,[WORD PTR TimerCount]
asm add ax,[WORD PTR TimerDivisor]
asm mov [WORD PTR TimerCount],ax
asm jnc myack
t0OldService(); // If we overflow a word, time to call old int handler
asm jmp olddone
myack:;
outportb(0x20,0x20); // Ack the interrupt
olddone:;
#if 1 // for debugging
asm mov dx,STATUS_REGISTER_1
asm in al,dx
asm mov dx,ATR_INDEX
asm mov al,ATR_OVERSCAN
asm out dx,al
asm mov al,3 // blue
asm out dx,al
asm mov al,0x20 // normal
asm out dx,al
#endif
}
#endif
////////////////////////////////////////////////////////////////////////////
//
// SDL_ShutDevice() - turns off whatever device was being used for sound fx
//
////////////////////////////////////////////////////////////////////////////
static void
SDL_ShutDevice(void)
{
switch (SoundMode)
{
case sdm_PC:
SDL_ShutPC();
break;
case sdm_AdLib:
SDL_ShutAL();
break;
}
SoundMode = sdm_Off;
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_CleanDevice() - totally shuts down all sound devices
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_CleanDevice(void)
{
if ((SoundMode == sdm_AdLib) || (MusicMode == smm_AdLib))
SDL_CleanAL();
}
///////////////////////////////////////////////////////////////////////////
//
// SDL_StartDevice() - turns on whatever device is to be used for sound fx
//
///////////////////////////////////////////////////////////////////////////
static void
SDL_StartDevice(void)
{
switch (SoundMode)
{
case sdm_AdLib:
SDL_StartAL();
break;
}
SoundNumber = SoundPriority = 0;
}
// Public routines
///////////////////////////////////////////////////////////////////////////
//
// SD_SetSoundMode() - Sets which sound hardware to use for sound effects
//
///////////////////////////////////////////////////////////////////////////
boolean
SD_SetSoundMode(SDMode mode)
{
boolean result = false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -