Skip to content

Commit

Permalink
Merge pull request #89 from jiyunomegami/forupstream2
Browse files Browse the repository at this point in the history
Add /SCFM and /SCMPU options, to select which cards to use for FM/MPU
  • Loading branch information
crazii authored Feb 15, 2024
2 parents 3a57cdd + b462736 commit f95af9d
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 165 deletions.
214 changes: 128 additions & 86 deletions main.c

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ VERSION ?= $(shell git describe --tags)

INCLUDES := -I./mpxplay -I./sbemu
DEFINES := -D__DOS__ -DSBEMU -DDEBUG=$(DEBUG) -DMAIN_SBEMU_VER=\"$(VERSION)\"
CFLAGS := -fcommon -march=i386 -O2 -flto=auto -Wno-attributes $(INCLUDES) $(DEFINES)
LDFLAGS := -lstdc++ -lm -save-temps
CFLAGS := -fcommon -march=i386 -Os -flto=auto -Wno-attributes $(INCLUDES) $(DEFINES)
LDFLAGS := -lstdc++ -lm

ifeq ($(DEBUG),0)
LDFLAGS += -s
Expand All @@ -34,6 +34,7 @@ CARDS_SRC := mpxplay/au_cards/ac97_def.c \
mpxplay/au_cards/au_cards.c \
mpxplay/au_cards/dmairq.c \
mpxplay/au_cards/pcibios.c \
mpxplay/au_cards/ioport.c \
mpxplay/au_cards/sc_e1371.c \
mpxplay/au_cards/sc_ich.c \
mpxplay/au_cards/sc_cmi.c \
Expand Down
121 changes: 104 additions & 17 deletions mpxplay/au_cards/au_cards.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
#include "au_cards.h"
#include "dmairq.h"

#define AU_CARDS_DEBUG 0

#if AU_CARDS_DEBUG
#include "dpmi/dbgutil.h"
#define aucardsdbg(...) DBG_Logi(__VA_ARGS__)
#else
#define aucardsdbg(...)
#endif

typedef int (*aucards_writedata_t)(struct mpxplay_audioout_info_s *aui,unsigned long);

static unsigned int cardinit(struct mpxplay_audioout_info_s *aui);
Expand Down Expand Up @@ -49,6 +58,11 @@ extern one_sndcard_info VIA82XX_sndcard_info;
extern one_sndcard_info SBLIVE_sndcard_info;
extern one_sndcard_info CMI8X38_sndcard_info;
extern one_sndcard_info EMU20KX_sndcard_info;
extern one_sndcard_info CTXFI_sndcard_info;
extern one_sndcard_info EMU10K1X_sndcard_info;
extern one_sndcard_info TRIDENT_sndcard_info;
extern one_sndcard_info ALS4000_sndcard_info;
extern one_sndcard_info OXYGEN_sndcard_info;
extern one_sndcard_info YMF_sndcard_info;
extern one_sndcard_info YMFSB_sndcard_info;
#ifndef SBEMU
Expand Down Expand Up @@ -162,27 +176,33 @@ unsigned char au_cards_fallback_to_null = 0;

static aucards_writedata_t aucards_writedata_func;

void AU_init(struct mpxplay_audioout_info_s *aui)
void AU_init(struct mpxplay_audioout_info_s *aui,struct mpxplay_audioout_info_s *fm_aui,struct mpxplay_audioout_info_s *mpu401_aui)
{
struct mpxplay_audioout_info_s initaui;
struct mpxplay_audioout_info_s detectedaui;
unsigned int error_code = MPXERROR_SNDCARD;
one_sndcard_info **asip;
char cardselectname[32]="";
char sout[100];

fm_aui->fm = 0;
mpu401_aui->mpu401 = 0;
detectedaui.pcm = 0;
aui->card_dmasize=aui->card_dma_buffer_size=MDma_get_max_pcmoutbufsize(aui,65535,4608,2,0);
initaui = *aui;

#ifndef MPXPLAY_GUI_CONSOLE
auinit_retry:
#endif

#ifndef SBEMU
if(aui->card_selectname){
pds_strncpy(cardselectname,aui->card_selectname,sizeof(cardselectname)-1);
cardselectname[sizeof(cardselectname)-1]=0;
pds_strcutspc(cardselectname);
if(pds_stricmp(cardselectname,"AUTO")==0)
cardselectname[0]=0;
}

if(cardselectname[0]){
asip=&all_sndcard_info[0];
aui->card_handler=*asip;
Expand Down Expand Up @@ -238,7 +258,10 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
goto err_out_auinit;
}
}
}else{
}else
#endif
{
#ifndef SBEMU
// init/search card(s) via environment variable
if(!(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD)){
asip=&all_sndcard_info[0];
Expand Down Expand Up @@ -274,8 +297,8 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
}
#endif
}

// autodetect sound card(s) (on brutal force way)
#endif
// autodetect sound card(s) (by brute force)
if(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD) // -sct
pds_textdisplay_printf("Autodetecting/testing available outputs/soundcards, please wait...");

Expand All @@ -284,34 +307,79 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
asip=&all_sndcard_info[0];
aui->card_handler=*asip;
#ifdef SBEMU
aui->card_test_index = 1;
initaui.card_test_index = aui->card_test_index = 1;
#endif
do{
aui->pcm = 1;
aui->fm = aui->mpu401 = 0;
if(aui->card_handler->card_detect){
if(!(aui->card_handler->infobits&SNDCARD_SELECT_ONLY)
#ifndef MPXPLAY_WIN32
&& (!(aui->card_handler->infobits&SNDCARD_LOWLEVELHAND) || !iswin9x)
#endif
){
if(carddetect(aui,0)){
if(!(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD)
aucardsdbg("detected %d (want %d)\n", aui->card_test_index, aui->card_select_index);
#ifdef SBEMU
&& (aui->card_select_index == 0 || aui->card_select_index == aui->card_test_index)
if (!(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD)) {
// Disable HW FM/MPU if another card was selected
if (!aui->card_select_index_fm && !(!aui->card_select_index || aui->card_select_index == aui->card_test_index)) {
aucardsdbg("disabling fm\n");
aui->fm_port = 0;
aui->fm = 0;
}
if (!aui->card_select_index_mpu401 && !(!aui->card_select_index || aui->card_select_index == aui->card_test_index)) {
aucardsdbg("disabling mpu401\n");
aui->mpu401_port = 0;
aui->mpu401 = 0;
}
if (aui->fm) {
if (!aui->card_select_index_fm || aui->card_select_index_fm == aui->card_test_index) {
*fm_aui = *aui;
}
}
if (aui->mpu401) {
if (!aui->card_select_index_mpu401 || aui->card_select_index_mpu401 == aui->card_test_index) {
*mpu401_aui = *aui;
}
}
if (!aui->card_select_index || aui->card_select_index == aui->card_test_index) {
detectedaui = *aui;
if (!aui->card_select_index_fm && !aui->card_select_index_mpu401) {
// no other cards to find
break;
}
if (aui->pcm && fm_aui->fm && mpu401_aui->mpu401) {
// found all other cards
break;
}
}
}
#else
if(!(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD))
break;
#endif
)
break;

aucardsdbg("%d: pcm: %d fm: %d mpu401: %d\n", aui->card_test_index, aui->pcm, aui->fm, aui->mpu401);
if (!(aui->pcm || aui->fm || aui->mpu401) || (!aui->fm && !aui->mpu401 && (aui->card_test_index > aui->card_select_index))) {
aucardsdbg("closing %d\n", aui->card_test_index);
if (aui->card_handler->card_close)
aui->card_handler->card_close(aui);
aui->card_private_data = NULL;
}
#ifdef SBEMU
++aui->card_test_index;
++initaui.card_test_index;
#endif
if(aui->card_handler->card_close)
aui->card_handler->card_close(aui);
aui->card_private_data=NULL;
}
}
}
asip++;
*aui = initaui;
aui->card_handler=*asip;
}while(aui->card_handler);
if (detectedaui.pcm) {
*aui = detectedaui;
}
}

#ifdef MPXPLAY_LINK_DLLLOAD
Expand Down Expand Up @@ -347,7 +415,11 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
if(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_TESTCARD){
pds_textdisplay_printf("Autodetecting finished... Exiting...");
error_code = MPXERROR_UNDEFINED;
#ifdef SBEMU
return;
#else
goto err_out_auinit;
#endif
}
if(!aui->card_handler && !(aui->card_controlbits&AUINFOS_CARDCNTRLBIT_SILENT)){
#ifdef SBEMU
Expand Down Expand Up @@ -394,6 +466,7 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
return;

err_out_auinit:
#ifndef SBEMU
#ifdef MPXPLAY_GUI_CONSOLE
mpxplay_close_program(error_code);
#else
Expand All @@ -403,6 +476,7 @@ void AU_init(struct mpxplay_audioout_info_s *aui)
goto auinit_retry;
}
#endif
#endif
}

static unsigned int cardinit(struct mpxplay_audioout_info_s *aui)
Expand All @@ -427,15 +501,24 @@ static unsigned int carddetect(struct mpxplay_audioout_info_s *aui, unsigned int
aui->bits_card=16;
aui->bytespersample_card=(aui->bits_card+7)/8;
}
aui->card_irq=0xff;
#ifndef SBEMU
aui->card_port=aui->card_type=0xffff;
aui->card_irq=aui->card_isa_dma=aui->card_isa_hidma=0xff;
aui->card_isa_dma=aui->card_isa_hidma=0xff;
aui->freq_card=44100;
#else
aui->freq_card=22050;
#endif
aui->chan_card=2;

if(aui->card_handler->card_detect){
if(aui->card_handler->card_detect(aui))
ok=1;
else{
if (aui->fm || aui->mpu401) {
au_cards_fallback_to_null = 1;
}
aui->pcm = 0;
if(!retry)
return 0;
funcbit_disable(outmode,OUTMODE_CONTROL_FILE_FLOATOUT);
Expand Down Expand Up @@ -486,7 +569,7 @@ void AU_ini_interrupts(struct mpxplay_audioout_info_s *aui)

void AU_del_interrupts(struct mpxplay_audioout_info_s *aui)
{
AU_close(aui);
AU_close(aui, NULL, NULL);
#ifndef __DOS__
mpxplay_timer_deletefunc(&aucards_dma_monitor,NULL);
#ifndef SBEMU
Expand Down Expand Up @@ -593,13 +676,17 @@ void AU_resume_decoding(struct mpxplay_audioout_info_s *aui)
}
#endif

void AU_close(struct mpxplay_audioout_info_s *aui)
void AU_close(struct mpxplay_audioout_info_s *aui,struct mpxplay_audioout_info_s *fm_aui,struct mpxplay_audioout_info_s *mpu401_aui)
{
if(!aui)
return;
AU_stop(aui);
if(aui->card_handler && aui->card_handler->card_close)
aui->card_handler->card_close(aui);
if(fm_aui && fm_aui->card_handler && fm_aui->card_handler->card_close)
fm_aui->card_handler->card_close(fm_aui);
if(mpu401_aui && mpu401_aui->card_handler && mpu401_aui->card_handler->card_close)
mpu401_aui->card_handler->card_close(mpu401_aui);
}

void AU_pause_process(struct mpxplay_audioout_info_s *aui)
Expand Down
26 changes: 21 additions & 5 deletions mpxplay/au_cards/au_cards.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,25 @@ typedef struct mpxplay_audioout_info_s{

char *card_selectname; // select card by name - NOT used by SBEMU
#ifdef SBEMU
int card_test_index; //tmp curret test index
int card_select_index; //user selection via cmd line
int card_test_index; //current test index for main card
int card_select_index; //user selection for main card
int card_select_index_fm; //user selection for FM(OPL) card
int card_select_index_mpu401; //user selection via MPU-401 card
int card_samples_per_int; //samples per interrupt
struct pci_config_s* card_pci_dev;
uint16_t fm_port;
uint16_t mpu401_port;
unsigned int pcm: 1, fm: 1, mpu401: 1;
#endif
struct one_sndcard_info *card_handler; // function structure of the card
void *card_private_data; // extra private datas can be pointed here (with malloc)
unsigned char card_irq;
#ifndef SBEMU
unsigned short card_type;
unsigned short card_port;
unsigned char card_irq;
unsigned char card_isa_dma;
unsigned char card_isa_hidma;
#endif

struct mainvars *mvp;
struct playlist_entry_info *pei; // for encoders
Expand Down Expand Up @@ -270,10 +277,15 @@ typedef struct one_sndcard_info{
void (*card_writemixer)(struct mpxplay_audioout_info_s *,unsigned long mixreg,unsigned long value);
unsigned long (*card_readmixer)(struct mpxplay_audioout_info_s *,unsigned long mixreg);
aucards_allmixerchan_s *card_mixerchans;

void (*card_fm_write)(struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data);
uint8_t (*card_fm_read)(struct mpxplay_audioout_info_s *aui, unsigned int idx);
void (*card_mpu401_write)(struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data);
uint8_t (*card_mpu401_read)(struct mpxplay_audioout_info_s *aui, unsigned int idx);
}one_sndcard_info;

//main soundcard routines
extern void AU_init(struct mpxplay_audioout_info_s *aui);
extern void AU_init(struct mpxplay_audioout_info_s *aui,struct mpxplay_audioout_info_s *fm_aui,struct mpxplay_audioout_info_s *mpu401_aui);
extern void AU_ini_interrupts(struct mpxplay_audioout_info_s *);
extern void AU_del_interrupts(struct mpxplay_audioout_info_s *aui);
extern void AU_prestart(struct mpxplay_audioout_info_s *);
Expand All @@ -282,7 +294,7 @@ extern void AU_wait_and_stop(struct mpxplay_audioout_info_s *);
extern void AU_stop(struct mpxplay_audioout_info_s *);
extern void AU_suspend_decoding(struct mpxplay_audioout_info_s *aui);
extern void AU_resume_decoding(struct mpxplay_audioout_info_s *aui);
extern void AU_close(struct mpxplay_audioout_info_s *);
extern void AU_close(struct mpxplay_audioout_info_s *aui,struct mpxplay_audioout_info_s *fm_aui,struct mpxplay_audioout_info_s *mpu401_aui);
extern void AU_setrate(struct mpxplay_audioout_info_s *aui,struct mpxplay_audio_decoder_info_s *adi);
extern void AU_setmixer_init(struct mpxplay_audioout_info_s *aui);
extern void AU_setmixer_one(struct mpxplay_audioout_info_s *,unsigned int mixch,unsigned int setmode,int value);
Expand All @@ -297,6 +309,10 @@ extern int AU_writedata(struct mpxplay_audioout_info_s *);

#ifdef SBEMU
extern unsigned char au_cards_fallback_to_null;
extern uint8_t ioport_fm_read (struct mpxplay_audioout_info_s *aui, unsigned int idx);
extern void ioport_fm_write (struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data);
extern uint8_t ioport_mpu401_read (struct mpxplay_audioout_info_s *aui, unsigned int idx);
extern void ioport_mpu401_write (struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data);
#endif

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion mpxplay/au_cards/dmairq.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void MDma_interrupt_monitor(struct mpxplay_audioout_info_s *aui)

//------------------------------------------------------------------------
//ISA
#ifdef AU_CARDS_LINK_ISA
#if defined(AU_CARDS_LINK_ISA) && !defined(SBEMU)

#define MDMA_ISA_DMABUFSIZE_MAX 65535
#define MDMA_ISA_BLOCKSIZE 4608 // PCM_OUTSAMPLES*2*2 (4608%256==0 for GUS!)
Expand Down
27 changes: 27 additions & 0 deletions mpxplay/au_cards/ioport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "au_cards.h"

#define hw_fm_outb(reg,data) outp(aui->fm_port+reg,data)
#define hw_fm_inb(reg) inp(aui->fm_port+reg)

uint8_t ioport_fm_read (struct mpxplay_audioout_info_s *aui, unsigned int idx)
{
return hw_fm_inb(idx);
}

void ioport_fm_write (struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data)
{
hw_fm_outb(idx, data);
}

#define hw_mpu_outb(reg,data) outp(aui->mpu401_port+reg,data)
#define hw_mpu_inb(reg) inp(aui->mpu401_port+reg)

uint8_t ioport_mpu401_read (struct mpxplay_audioout_info_s *aui, unsigned int idx)
{
return hw_mpu_inb(idx);
}

void ioport_mpu401_write (struct mpxplay_audioout_info_s *aui, unsigned int idx, uint8_t data)
{
hw_mpu_outb(idx, data);
}
2 changes: 0 additions & 2 deletions mpxplay/au_cards/sc_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@

static int NUL_init(struct mpxplay_audioout_info_s *aui)
{
aui->card_port=aui->card_isa_dma=aui->card_irq=aui->card_isa_hidma=aui->card_type=0;
return 1;
}

static int NUL_detect(struct mpxplay_audioout_info_s *aui)
{
aui->card_port=aui->card_isa_dma=aui->card_irq=aui->card_isa_hidma=aui->card_type=0;
return 1;
}

Expand Down
Loading

0 comments on commit f95af9d

Please sign in to comment.