2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
snd_dos.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dosisms.h"
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int BLASTER_GetDMAPos (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
GUS SUPPORT
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean GUS_Init (void);
|
|
|
|
int GUS_GetDMAPos (void);
|
|
|
|
void GUS_Shutdown (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
BLASTER SUPPORT
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
short *dma_buffer = 0;
|
|
|
|
static int dma_size;
|
|
|
|
static int dma;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int dsp_port;
|
|
|
|
static int irq;
|
|
|
|
static int low_dma;
|
|
|
|
static int high_dma;
|
|
|
|
static int mixer_port;
|
|
|
|
static int mpu401_port;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int dsp_version;
|
|
|
|
int dsp_minor_version;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int timeconstant = -1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
PrintBits (byte b)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
char str[9];
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
str[i] = '0' + ((b & (1 << (7 - i))) > 0);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
str[8] = 0;
|
|
|
|
Con_Printf ("%s (%i)", str, b);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SB_Info_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf ("BLASTER=%s\n", getenv ("BLASTER"));
|
|
|
|
Con_Printf ("dsp version=%d.%d\n", dsp_version, dsp_minor_version);
|
|
|
|
Con_Printf ("dma=%d\n", dma);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (timeconstant != -1)
|
2001-02-26 06:48:02 +00:00
|
|
|
Con_Printf ("timeconstant=%d\n", timeconstant);
|
|
|
|
Con_Printf ("dma position:%i\n", BLASTER_GetDMAPos ());
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
// Interprets BLASTER variable
|
|
|
|
// =======================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
GetBLASTER (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
char *BLASTER;
|
|
|
|
char *param;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
BLASTER = getenv ("BLASTER");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!BLASTER)
|
|
|
|
return 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'A');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'a');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%x", &dsp_port);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'I');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'i');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%d", &irq);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'D');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'd');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
|
|
|
return 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%d", &low_dma);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'H');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'h');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (param)
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%d", &high_dma);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'M');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'm');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (param)
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%x", &mixer_port);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
|
|
|
mixer_port = dsp_port;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'P');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!param)
|
2001-02-26 06:48:02 +00:00
|
|
|
param = strchr (BLASTER, 'p');
|
2001-02-19 21:15:25 +00:00
|
|
|
if (param)
|
2001-02-26 06:48:02 +00:00
|
|
|
sscanf (param + 1, "%x", &mpu401_port);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ==================================================================
|
|
|
|
// Resets DSP. Returns 0 on success.
|
|
|
|
// ==================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
ResetDSP (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
volatile int i;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (dsp_port + 6, 1);
|
|
|
|
for (i = 65536; i; i--);
|
|
|
|
dos_outportb (dsp_port + 6, 0);
|
|
|
|
for (i = 65536; i; i--) {
|
|
|
|
if (!(dos_inportb (dsp_port + 0xe) & 0x80))
|
|
|
|
continue;
|
|
|
|
if (dos_inportb (dsp_port + 0xa) == 0xaa)
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (i)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
ReadDSP (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while (!(dos_inportb (dsp_port + 0xe) & 0x80));
|
|
|
|
return dos_inportb (dsp_port + 0xa);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
WriteDSP (int val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
while ((dos_inportb (dsp_port + 0xc) & 0x80));
|
|
|
|
dos_outportb (dsp_port + 0xc, val);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
ReadMixer (int addr)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (mixer_port + 4, addr);
|
|
|
|
return dos_inportb (mixer_port + 5);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
WriteMixer (int addr, int val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (mixer_port + 4, addr);
|
|
|
|
dos_outportb (mixer_port + 5, val);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int oldmixervalue;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
StartSB
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
StartSB (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// version 4.xx startup code
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dsp_version >= 4) {
|
|
|
|
Con_Printf ("Version 4 SB startup\n");
|
|
|
|
WriteDSP (0xd1); // turn on speaker
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0x41);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (shm->speed >> 8);
|
|
|
|
WriteDSP (shm->speed & 0xff);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0xb6); // 16-bit output
|
|
|
|
WriteDSP (0x30); // stereo
|
|
|
|
WriteDSP ((shm->samples - 1) & 0xff); // # of samples - 1
|
|
|
|
WriteDSP ((shm->samples - 1) >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// version 3.xx startup code
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (dsp_version == 3) {
|
|
|
|
Con_Printf ("Version 3 SB startup\n");
|
|
|
|
WriteDSP (0xd1); // turn on speaker
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
oldmixervalue = ReadMixer (0xe);
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteMixer (0xe, oldmixervalue | 0x2); // turn on stereo
|
|
|
|
|
|
|
|
WriteDSP (0x14); // send one byte
|
|
|
|
WriteDSP (0x0);
|
|
|
|
WriteDSP (0x0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 0x10000; i++)
|
|
|
|
dos_inportb (dsp_port + 0xe); // ack the dsp
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
timeconstant = 65536 - (256000000 / (shm->channels * shm->speed));
|
|
|
|
WriteDSP (0x40);
|
|
|
|
WriteDSP (timeconstant >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteMixer (0xe, ReadMixer (0xe) | 0x20); // turn off filter
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0x48);
|
|
|
|
WriteDSP ((shm->samples - 1) & 0xff); // # of samples - 1
|
|
|
|
WriteDSP ((shm->samples - 1) >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0x90); // high speed 8 bit stereo
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// normal speed mono
|
2001-02-26 06:48:02 +00:00
|
|
|
else {
|
|
|
|
Con_Printf ("Version 2 SB startup\n");
|
|
|
|
WriteDSP (0xd1); // turn on speaker
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
timeconstant = 65536 - (256000000 / (shm->channels * shm->speed));
|
|
|
|
WriteDSP (0x40);
|
|
|
|
WriteDSP (timeconstant >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0x48);
|
|
|
|
WriteDSP ((shm->samples - 1) & 0xff); // # of samples - 1
|
|
|
|
WriteDSP ((shm->samples - 1) >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0x1c); // normal speed 8 bit mono
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int page_reg[] = { 0x87, 0x83, 0x81, 0x82, 0x8f, 0x8b, 0x89, 0x8a };
|
|
|
|
static int addr_reg[] = { 0, 2, 4, 6, 0xc0, 0xc4, 0xc8, 0xcc };
|
|
|
|
static int count_reg[] = { 1, 3, 5, 7, 0xc2, 0xc6, 0xca, 0xce };
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int mode_reg;
|
|
|
|
static int flipflop_reg;
|
|
|
|
static int disable_reg;
|
|
|
|
static int clear_reg;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
StartDMA
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
StartDMA (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int mode;
|
|
|
|
int realaddr;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
realaddr = ptr2real (dma_buffer);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// use a high dma channel if specified
|
|
|
|
if (high_dma && dsp_version >= 4) // 8 bit snd can never use 16 bit dma
|
|
|
|
dma = high_dma;
|
|
|
|
else
|
|
|
|
dma = low_dma;
|
|
|
|
|
|
|
|
Con_Printf ("Using DMA channel %i\n", dma);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dma > 3) {
|
2001-02-19 21:15:25 +00:00
|
|
|
mode_reg = 0xd6;
|
|
|
|
flipflop_reg = 0xd8;
|
|
|
|
disable_reg = 0xd4;
|
|
|
|
clear_reg = 0xdc;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
mode_reg = 0xb;
|
|
|
|
flipflop_reg = 0xc;
|
|
|
|
disable_reg = 0xa;
|
|
|
|
clear_reg = 0xe;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (disable_reg, dma | 4); // disable channel
|
2001-02-19 21:15:25 +00:00
|
|
|
// set mode- see "undocumented pc", p.876
|
2001-02-26 06:48:02 +00:00
|
|
|
mode = (1 << 6) // single-cycle
|
|
|
|
+ (0 << 5) // address increment
|
|
|
|
+ (1 << 4) // auto-init dma
|
|
|
|
+ (2 << 2) // read
|
|
|
|
+ (dma & 3); // channel #
|
|
|
|
dos_outportb (mode_reg, mode);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// set address
|
|
|
|
// set page
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (page_reg[dma], realaddr >> 16);
|
|
|
|
|
|
|
|
if (dma > 3) { // address is in words
|
|
|
|
dos_outportb (flipflop_reg, 0); // prepare to send 16-bit value
|
|
|
|
dos_outportb (addr_reg[dma], (realaddr >> 1) & 0xff);
|
|
|
|
dos_outportb (addr_reg[dma], (realaddr >> 9) & 0xff);
|
|
|
|
|
|
|
|
dos_outportb (flipflop_reg, 0); // prepare to send 16-bit value
|
|
|
|
dos_outportb (count_reg[dma], ((dma_size >> 1) - 1) & 0xff);
|
|
|
|
dos_outportb (count_reg[dma], ((dma_size >> 1) - 1) >> 8);
|
|
|
|
} else { // address is in bytes
|
|
|
|
dos_outportb (flipflop_reg, 0); // prepare to send 16-bit value
|
|
|
|
dos_outportb (addr_reg[dma], realaddr & 0xff);
|
|
|
|
dos_outportb (addr_reg[dma], (realaddr >> 8) & 0xff);
|
|
|
|
|
|
|
|
dos_outportb (flipflop_reg, 0); // prepare to send 16-bit value
|
|
|
|
dos_outportb (count_reg[dma], (dma_size - 1) & 0xff);
|
|
|
|
dos_outportb (count_reg[dma], (dma_size - 1) >> 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (clear_reg, 0); // clear write mask
|
|
|
|
dos_outportb (disable_reg, dma & ~4);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
BLASTER_Init
|
|
|
|
|
|
|
|
Returns false if nothing is found.
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
BLASTER_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int size;
|
|
|
|
int realaddr;
|
|
|
|
int rc;
|
|
|
|
int p;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
shm = 0;
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// must have a blaster variable set
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!GetBLASTER ()) {
|
|
|
|
Con_NotifyBox ("The BLASTER environment variable\n"
|
|
|
|
"is not set, sound effects are\n"
|
|
|
|
"disabled. See README.TXT for help.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ResetDSP ()) {
|
|
|
|
Con_Printf ("Could not reset SB");
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// get dsp version
|
|
|
|
//
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteDSP (0xe1);
|
|
|
|
dsp_version = ReadDSP ();
|
|
|
|
dsp_minor_version = ReadDSP ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// we need at least v2 for auto-init dma
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dsp_version < 2) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("Sound blaster must be at least v2.0\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// allow command line parm to set quality down
|
|
|
|
p = COM_CheckParm ("-dsp");
|
2001-02-26 06:48:02 +00:00
|
|
|
if (p && p < com_argc - 1) {
|
|
|
|
p = Q_atoi (com_argv[p + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (p < 2 || p > 4)
|
|
|
|
Con_Printf ("-dsp parameter can only be 2, 3, or 4\n");
|
|
|
|
else if (p > dsp_version)
|
|
|
|
Con_Printf ("Can't -dsp %i on v%i hardware\n", p, dsp_version);
|
|
|
|
else
|
|
|
|
dsp_version = p;
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
// everyone does 11khz sampling rate unless told otherwise
|
|
|
|
shm = &sn;
|
|
|
|
shm->speed = 11025;
|
2001-02-26 06:48:02 +00:00
|
|
|
rc = COM_CheckParm ("-sspeed");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (rc)
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->speed = Q_atoi (com_argv[rc + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// version 4 cards (sb 16) do 16 bit stereo
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dsp_version >= 4) {
|
2001-02-19 21:15:25 +00:00
|
|
|
shm->channels = 2;
|
|
|
|
shm->samplebits = 16;
|
|
|
|
}
|
|
|
|
// version 3 cards (sb pro) do 8 bit stereo
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (dsp_version == 3) {
|
2001-02-19 21:15:25 +00:00
|
|
|
shm->channels = 2;
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->samplebits = 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
// v2 cards do 8 bit mono
|
2001-02-26 06:48:02 +00:00
|
|
|
else {
|
2001-02-19 21:15:25 +00:00
|
|
|
shm->channels = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->samplebits = 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
Cmd_AddCommand ("sbinfo", SB_Info_f, "No Description");
|
2001-02-19 21:15:25 +00:00
|
|
|
size = 4096;
|
|
|
|
|
|
|
|
// allocate 8k and get a 4k-aligned buffer from it
|
2001-02-26 06:48:02 +00:00
|
|
|
dma_buffer = dos_getmemory (size * 2);
|
|
|
|
if (!dma_buffer) {
|
|
|
|
Con_Printf ("Couldn't allocate sound dma buffer");
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
realaddr = ptr2real (dma_buffer);
|
|
|
|
realaddr = (realaddr + size) & ~(size - 1);
|
|
|
|
dma_buffer = (short *) real2ptr (realaddr);
|
2001-02-19 21:15:25 +00:00
|
|
|
dma_size = size;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (dma_buffer, 0, dma_size);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
shm->soundalive = true;
|
|
|
|
shm->splitbuffer = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->samples = size / (shm->samplebits / 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
shm->samplepos = 0;
|
|
|
|
shm->submission_chunk = 1;
|
|
|
|
shm->buffer = (unsigned char *) dma_buffer;
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->samples = size / (shm->samplebits / 8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
StartDMA ();
|
|
|
|
StartSB ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
BLASTER_GetDMAPos
|
|
|
|
|
|
|
|
return the current sample position (in mono samples read)
|
|
|
|
inside the recirculating dma buffer, so the mixing code will know
|
|
|
|
how many sample are required to fill it up.
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
BLASTER_GetDMAPos (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int count;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// this function is called often. acknowledge the transfer completions
|
|
|
|
// all the time so that it loops
|
|
|
|
if (dsp_version >= 4)
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_inportb (dsp_port + 0xf); // 16 bit audio
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_inportb (dsp_port + 0xe); // 8 bit audio
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// clear 16-bit reg flip-flop
|
|
|
|
// load the current dma count register
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dma < 4) {
|
|
|
|
dos_outportb (0xc, 0);
|
|
|
|
count = dos_inportb (dma * 2 + 1);
|
|
|
|
count += dos_inportb (dma * 2 + 1) << 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (shm->samplebits == 16)
|
|
|
|
count /= 2;
|
2001-02-26 06:48:02 +00:00
|
|
|
count = shm->samples - (count + 1);
|
|
|
|
} else {
|
|
|
|
dos_outportb (0xd8, 0);
|
|
|
|
count = dos_inportb (0xc0 + (dma - 4) * 4 + 2);
|
|
|
|
count += dos_inportb (0xc0 + (dma - 4) * 4 + 2) << 8;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (shm->samplebits == 8)
|
|
|
|
count *= 2;
|
2001-02-26 06:48:02 +00:00
|
|
|
count = shm->samples - (count + 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// Con_Printf("DMA pos = 0x%x\n", count);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
shm->samplepos = count & (shm->samples - 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
return shm->samplepos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
BLASTER_Shutdown
|
|
|
|
|
|
|
|
Reset the sound device for exiting
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
BLASTER_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dsp_version >= 4) {
|
|
|
|
} else if (dsp_version == 3) {
|
|
|
|
ResetDSP (); // stop high speed mode
|
|
|
|
WriteMixer (0xe, oldmixervalue); // turn stereo off and filter on
|
|
|
|
} else {
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
WriteDSP (0xd3); // turn off speaker
|
2001-02-19 21:15:25 +00:00
|
|
|
ResetDSP ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (disable_reg, dma | 4); // disable dma channel
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
INTERFACE
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef enum {
|
2001-02-19 21:15:25 +00:00
|
|
|
dma_none,
|
|
|
|
dma_blaster,
|
|
|
|
dma_gus
|
|
|
|
} dmacard_t;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dmacard_t dmacard;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
SNDDM_Init
|
|
|
|
|
|
|
|
Try to find a sound device to mix for.
|
|
|
|
Returns false if nothing is found.
|
|
|
|
Returns true and fills in the "shm" structure with information for the mixer.
|
|
|
|
==================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean
|
|
|
|
SNDDMA_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
if (GUS_Init ()) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dmacard = dma_gus;
|
|
|
|
return true;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (BLASTER_Init ()) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dmacard = dma_blaster;
|
|
|
|
return true;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
dmacard = dma_none;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
SNDDMA_GetDMAPos
|
|
|
|
|
|
|
|
return the current sample position (in mono samples, not stereo)
|
|
|
|
inside the recirculating dma buffer, so the mixing code will know
|
|
|
|
how many sample are required to fill it up.
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
SNDDMA_GetDMAPos (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (dmacard) {
|
|
|
|
case dma_blaster:
|
2001-02-19 21:15:25 +00:00
|
|
|
return BLASTER_GetDMAPos ();
|
2001-02-26 06:48:02 +00:00
|
|
|
case dma_gus:
|
2001-02-19 21:15:25 +00:00
|
|
|
return GUS_GetDMAPos ();
|
2001-02-26 06:48:02 +00:00
|
|
|
case dma_none:
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
SNDDMA_Shutdown
|
|
|
|
|
|
|
|
Reset the sound device for exiting
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SNDDMA_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (dmacard) {
|
|
|
|
case dma_blaster:
|
2001-02-19 21:15:25 +00:00
|
|
|
BLASTER_Shutdown ();
|
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
case dma_gus:
|
2001-02-19 21:15:25 +00:00
|
|
|
GUS_Shutdown ();
|
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
case dma_none:
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dmacard = dma_none;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
SNDDMA_Submit
|
|
|
|
|
|
|
|
Send sound to device if buffer isn't really the dma buffer
|
|
|
|
===============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SNDDMA_Submit (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|