Skip to content

Commit 8b3fc54

Browse files
made source compatible with djgpp again
1 parent eda7fb5 commit 8b3fc54

File tree

12 files changed

+109
-99
lines changed

12 files changed

+109
-99
lines changed

History.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
v1.5,
2+
v1.5, 8.6.2024
33
- MPU port emulation if BLASTER variable contains P=xxx.
44
- cmdline option /P added.
55
- cmdline option /SD added.
@@ -13,7 +13,6 @@
1313
non-autoinit DSP cmds.
1414

1515
v1.4, 20.4.2024
16-
1716
- added 16-bit protected-mode variant vsbhda16.exe.
1817
- reworked HDA initialization code
1918
- Creative's diagnose.exe accepts vsbhda's SB emulation.
@@ -29,19 +28,15 @@
2928
- direct DSP cmd 0x10 supported.
3029

3130
v1.3, 5.3.2024
32-
3331
- source made compatible with Open Watcom 2.0.
3432
- tool chain changed to Open Watcom 2.0;
3533

3634
v1.2, 26.2.2024
37-
3835
- reset "interrupt disable" bit in PCI config space
3936
- PCI access with BIOS functions.
4037

4138
v1.1, 9.2.2024
42-
4339
- fix: code for port trap 0x20 in real-mode modified AH register
4440

4541
v1.0, 12.4.2023
46-
4742
- initial

MPXPLAY/TIMER.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
static inline uint16_t gettimercnt(void)
2828
{
29-
uint16_t tsc;
29+
unsigned short oldstate;
30+
uint16_t tsc;
3031
_disableint();
3132
outp( 0x43, 0x04 );
3233
tsc = inp(0x40);
@@ -62,7 +63,6 @@ void pds_delay_10us(unsigned int ticks) //each tick is 10us
6263
unsigned int divisor = PIT_DIVISOR_DEFAULT; // is 65536
6364
unsigned int i;
6465
unsigned short oldtsc, tsctemp, tscdif;
65-
unsigned short oldstate;
6666

6767
oldtsc = gettimercnt();
6868
for( i = 0; i < ticks; i++ ){

djgpp.mak

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ vpath %.o $(vpath_obj)
2828

2929
OBJFILES=\
3030
$(OUTD)/main.o $(OUTD)/sndisr.o $(OUTD)/ptrap.o $(OUTD)/dbopl.o $(OUTD)/linear.o $(OUTD)/pic.o\
31-
$(OUTD)/vsb.o $(OUTD)/vdma.o $(OUTD)/virq.o $(OUTD)/vopl3.o\
31+
$(OUTD)/vsb.o $(OUTD)/vdma.o $(OUTD)/virq.o $(OUTD)/vopl3.o $(OUTD)/vmpu.o\
3232
$(OUTD)/ac97mix.o $(OUTD)/au_cards.o\
3333
$(OUTD)/dmairq.o $(OUTD)/pcibios.o $(OUTD)/memory.o $(OUTD)/physmem.o $(OUTD)/timer.o\
3434
$(OUTD)/sc_e1371.o $(OUTD)/sc_ich.o $(OUTD)/sc_inthd.o $(OUTD)/sc_via82.o $(OUTD)/sc_sbliv.o $(OUTD)/sc_sbl24.o\
@@ -101,12 +101,13 @@ $(OUTD)/dbopl.o:: dbopl.cpp dbopl.h
101101
$(OUTD)/linear.o:: linear.c linear.h platform.h
102102
$(OUTD)/main.o:: main.c linear.h platform.h ptrap.h vopl3.h pic.h config.h vsb.h vdma.h virq.h au.h
103103
$(OUTD)/pic.o:: pic.c pic.h platform.h ptrap.h
104-
$(OUTD)/ptrap.o:: ptrap.c linear.h platform.h ptrap.h config.h ports.h
104+
$(OUTD)/ptrap.o:: ptrap.c linear.h platform.h ptrap.h config.h
105105
$(OUTD)/sndisr.o:: sndisr.c linear.h platform.h vopl3.h pic.h config.h vsb.h vdma.h virq.h ctadpcm.h au.h
106106
$(OUTD)/vdma.o:: vdma.c linear.h platform.h ptrap.h vdma.h config.h
107107
$(OUTD)/virq.o:: virq.c linear.h platform.h pic.h ptrap.h virq.h config.h
108108
$(OUTD)/vopl3.o:: vopl3.cpp dbopl.h vopl3.h config.h
109109
$(OUTD)/vsb.o:: vsb.c linear.h platform.h vsb.h config.h
110+
$(OUTD)/vmpu.o:: vmpu.c linear.h platform.h vmpu.h config.h
110111

111112
$(OUTD)/djdpmi.o:: djdpmi.asm
112113
$(OUTD)/dprintf.o:: dprintf.asm

src/CONFIG.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define SETABSVOL 0 /* 0=the master volume is set by /VOL cmdline option and isn't modified by the application */
1616
#define VMPU 1 /* 1=virtualize MPU at port 0x330-0x331 if BLASTER contains P=xxx */
1717
#define SLOWDOWN 1 /* 1=support /SD option */
18-
#define JHDPMI 0 /* 1=check if JLM jhdpmi is loaded */
18+
//#define JHDPMI 0 /* 1=check if JLM jhdpmi is loaded */
1919
#define DISPSTAT 1 /* 1=display VSB status */
2020

2121
#ifdef __cplusplus

src/INT31.ASM

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ externdef _Snd_Notify31:near
1919
if TRAPINT21
2020
externdef _SB_Notify21:near
2121
externdef _Snd_Notify21:near
22+
ifndef NOTFLAT
23+
if @Model ne 7
24+
externdef c DSBase:dword
25+
endif
26+
endif
2227
endif
2328

2429
ifdef NOTFLAT
@@ -128,7 +133,7 @@ if TRAPINT21
128133
;--- (because DOS/4GW, after reading this vector, sets exception vectors without
129134
;--- clearing hiword(edx).
130135

131-
if @Model eq 7
136+
ifndef NOTFLAT
132137
.data
133138
align 4
134139
int21tmp label byte
@@ -218,7 +223,13 @@ if TRAPINT21
218223
mov ebx, eax
219224
;--- setup non-zerobased CS
220225
mov [int21tmpCS], cs
226+
if @Model eq 7
221227
push offset int21tmp
228+
else
229+
mov eax, [DSBase] ; for DJGPP's non-zerobased model
230+
add eax, offset int21tmp
231+
push eax
232+
endif
222233
pop dx
223234
pop cx
224235
mov ax, 7

src/LINEAR.C

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44
#include <stdlib.h>
55
#include <stdint.h>
66
#include <assert.h>
7-
#ifdef DJGPP
8-
#include <crt0.h>
9-
#endif
107

118
#include "LINEAR.H"
129

13-
#ifdef DJGPP
14-
int _crt0_startup_flags = _CRT0_FLAG_PRESERVE_FILENAME_CASE | _CRT0_FLAG_KEEP_QUOTES | _CRT0_FLAG_NEARPTR;
15-
#endif
16-
1710
#if defined(DJGPP) || defined(NOTFLAT)
1811
uint32_t DSBase = 0;
1912
#else

src/MAIN.C

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifdef DJGPP
1212
#include <go32.h>
1313
#include <sys/exceptn.h>
14+
#include <crt0.h>
1415
#endif
1516

1617
#include "CONFIG.H"
@@ -43,14 +44,21 @@
4344
bool _InstallInt31( void );
4445
bool _UninstallInt31( void );
4546

46-
#ifndef DJGPP
47+
#ifdef DJGPP
48+
49+
int _crt0_startup_flags = _CRT0_FLAG_PRESERVE_FILENAME_CASE | _CRT0_FLAG_KEEP_QUOTES | _CRT0_FLAG_NEARPTR;
50+
51+
#else
52+
4753
uint32_t __djgpp_stack_top;
4854
uint32_t _linear_psp;
4955
uint32_t _linear_rmstack;
5056
uint32_t _get_linear_psp( void );
5157
uint32_t _get_linear_rmstack( int * );
5258
uint32_t _get_stack_top( void );
5359

60+
extern uint32_t STACKTOP;
61+
5462
/* don't assume hdpmi is loaded - get PSP selector from OW's _psp global var! */
5563
#pragma aux _get_linear_psp = \
5664
"mov ebx, [_psp]" \
@@ -73,25 +81,24 @@ uint32_t _get_stack_top( void );
7381
modify exact [bx dx eax]
7482

7583
#pragma aux _get_stack_top = \
76-
"mov eax, esp" \
84+
"mov eax, [STACKTOP]" \
7785
parm [] \
7886
modify exact[eax];
7987

8088
#endif
8189

82-
int hAU; /* handle audioout_info; we don't want to know mpxplay internals */
83-
static int freq = 22050; /* default value for AU_setrate() */
84-
8590
uint8_t bOMode = 1; /* 1=output DOS, 2=direct, 4=debugger */
8691

87-
#if SETABSVOL
88-
extern uint16_t SNDISR_SB_VOL = 0; //initial set volume will cause interrupt missing?
89-
#endif
92+
struct MAIN_s {
93+
int hAU; /* handle audioout_info; we don't want to know mpxplay internals */
94+
int freq; /* default value for AU_setrate() */
95+
bool bISR; /* 1=ISR installed */
96+
bool bQemm; /* 1=QPI API found */
97+
bool bHdpmi;/* 1=HDPMI found */
98+
int bHelp; /* 1=show help */
99+
};
90100

91-
static bool bISR; /* 1=ISR installed */
92-
static bool bQemm = false;
93-
static bool bHdpmi = false;
94-
static int bHelp = false;
101+
static struct MAIN_s gm = { 0, 22050, false, false, false, false };
95102

96103
struct globalvars gvars = { BASE_DEFAULT, IRQ_DEFAULT, DMA_DEFAULT,
97104
#if SB16
@@ -112,7 +119,7 @@ static const struct {
112119
const char *desc;
113120
int *pValue;
114121
} GOptions[] = {
115-
"/?", "Show help", &bHelp,
122+
"/?", "Show help", &gm.bHelp,
116123
"/A", "Set IO base address [220|240, def 220]", &gvars.base,
117124
"/I", "Set IRQ number [2|5|7, def 7]", &gvars.irq,
118125
"/D", "Set DMA channel [0|1|3, def 1]", &gvars.dma,
@@ -128,7 +135,7 @@ static const struct {
128135
"/OPL","Set OPL3 emulation [0|1, def 1]", &gvars.opl3,
129136
"/PM", "Set protected-mode support [0|1, def 1]", &gvars.pm,
130137
"/RM", "Set real-mode support [0|1, def 1]", &gvars.rm,
131-
"/F", "Set frequency [22050|44100, def 22050]", (int *)&freq,
138+
"/F", "Set frequency [22050|44100, def 22050]", &gm.freq,
132139
"/VOL", "Set master volume [0-9, def 7]", &gvars.vol,
133140
"/BS", "Set PCM buffer size [in 4k pages, def 16]", &gvars.buffsize,
134141
#if SLOWDOWN
@@ -182,9 +189,9 @@ static void ReleaseRes( void )
182189
//////////////////////////////
183190
{
184191
_UninstallInt31(); /* must be called before SNDISR_Exit() */
185-
if (bISR) {
192+
if ( gm.bISR ) {
186193
VIRQ_Exit( gvars.irq );
187-
SNDISR_Exit( PIC_IRQ2VEC( AU_getirq( hAU ) ) );
194+
SNDISR_Exit();
188195
}
189196

190197
if( gvars.rm )
@@ -207,7 +214,7 @@ void MAIN_Uninstall( void )
207214
///////////////////////////
208215
{
209216
ReleaseRes();
210-
AU_close( hAU );
217+
AU_close( gm.hAU );
211218
_uninstall_tsr( _my_psp() ); /* should not return */
212219
return;
213220
}
@@ -219,7 +226,7 @@ void MAIN_ReinitOPL( void )
219226
if( gvars.opl3 ) {
220227
uint8_t buffer[108];
221228
fpu_save(buffer);
222-
VOPL3_Reinit( AU_getfreq( hAU ) );
229+
VOPL3_Reinit( AU_getfreq( gm.hAU ) );
223230
fpu_restore(buffer);
224231
}
225232
}
@@ -305,12 +312,12 @@ int main(int argc, char* argv[])
305312
}
306313
}
307314
if ( GOptions[j].option == NULL )
308-
bHelp = true;
315+
gm.bHelp = true;
309316
}
310317

311318
/* if -? or unrecognised option was entered, display help and exit */
312-
if( bHelp ) {
313-
bHelp = false;
319+
if( gm.bHelp ) {
320+
gm.bHelp = false;
314321
printf("VSBHDA v" VERMAJOR "." VERMINOR "; Sound Blaster emulation on HDA/AC97. Usage:\n");
315322

316323
for( i = 0; GOptions[i].option; i++ )
@@ -361,8 +368,8 @@ int main(int argc, char* argv[])
361368
printf("Error: Invalid PCM buffer size %d\n", gvars.buffsize );
362369
return 1;
363370
}
364-
if( freq != 22050 && freq != 44100 ) {
365-
printf("Error: Invalid frequency %d\n", freq );
371+
if( gm.freq != 22050 && gm.freq != 44100 ) {
372+
printf("Error: Invalid frequency %d\n", gm.freq );
366373
return 1;
367374
}
368375
#if defined(DJGPP)
@@ -398,24 +405,21 @@ int main(int argc, char* argv[])
398405
}
399406
//aui.card_select_config = gvars.pin;
400407
//aui.card_select_devicenum = gvars.device;
401-
if ( (hAU = AU_init( gvars.device, gvars.pin ) ) == 0 ) {
408+
if ( (gm.hAU = AU_init( gvars.device, gvars.pin ) ) == 0 ) {
402409
printf("No soundcard found!\n");
403410
return 1;
404411
}
405-
printf("Found sound card: %s\n", AU_getshortname( hAU ) );
406-
if( AU_getirq( hAU ) == gvars.irq ) {
412+
printf("Found sound card: %s\n", AU_getshortname( gm.hAU ) );
413+
if( AU_getirq( gm.hAU ) == gvars.irq ) {
407414
printf("Sound card IRQ conflict, abort.\n");
408415
return 1;
409416
}
410-
AU_setmixer_init( hAU );
417+
AU_setmixer_init( gm.hAU );
411418

412-
#if SETABSVOL
413-
SNDISR_SB_VOL = gvars.vol * 256/9; /* translate 0-9 to 0-256 */
414-
#endif
415-
AU_setmixer_outs( hAU, MIXER_SETMODE_ABSOLUTE, gvars.vol * 100/9 );
416-
//AU_setmixer_one( hAU, AU_MIXCHAN_MASTER, MIXER_SETMODE_ABSOLUTE, gvars.vol * 100/9 );
419+
AU_setmixer_outs( gm.hAU, MIXER_SETMODE_ABSOLUTE, gvars.vol * 100/9 );
420+
//AU_setmixer_one( gm.hAU, AU_MIXCHAN_MASTER, MIXER_SETMODE_ABSOLUTE, gvars.vol * 100/9 );
417421

418-
AU_setrate( hAU, freq, HW_CHANNELS, HW_BITS );
422+
AU_setrate( gm.hAU, gm.freq, HW_CHANNELS, HW_BITS );
419423

420424
if( gvars.rm ) {
421425
gvars.rm = PTRAP_Prepare_RM_PortTrap();
@@ -437,15 +441,15 @@ int main(int argc, char* argv[])
437441
gvars.hdma = 0;
438442
#endif
439443

440-
VPIC_Init( AU_getirq( hAU ) );
444+
VPIC_Init( AU_getirq( gm.hAU ) );
441445

442446
#ifdef NOFM
443447
gvars.opl3 = 0;
444448
#endif
445449
#if SB16
446-
PTRAP_Prepare( gvars.opl3, gvars.base, gvars.dma, gvars.hdma, AU_getirq( hAU ) );
450+
PTRAP_Prepare( gvars.opl3, gvars.base, gvars.dma, gvars.hdma, AU_getirq( gm.hAU ) );
447451
#else
448-
PTRAP_Prepare( gvars.opl3, gvars.base, gvars.dma, 0, AU_getirq( hAU ) );
452+
PTRAP_Prepare( gvars.opl3, gvars.base, gvars.dma, 0, AU_getirq( gm.hAU ) );
449453
#endif
450454
#if SB16
451455
VSB_Init( gvars.irq, gvars.dma, gvars.hdma, gvars.type );
@@ -459,20 +463,20 @@ int main(int argc, char* argv[])
459463
#endif
460464

461465
if ( gvars.rm ) {
462-
if ((bQemm = PTRAP_Install_RM_PortTraps()) == 0 )
466+
if ((gm.bQemm = PTRAP_Install_RM_PortTraps()) == 0 )
463467
printf("Error: Failed installing IO port trap for real-mode.\n");
464468
}
465469
if ( gvars.pm ) {
466-
if(( bHdpmi = PTRAP_Install_PM_PortTraps()) == 0 )
470+
if(( gm.bHdpmi = PTRAP_Install_PM_PortTraps()) == 0 )
467471
printf("Error: Failed installing IO port trap for protected-mode.\n");
468472
#ifdef _DEBUG
469473
//PTRAP_PrintPorts(); /* for debugging */
470474
#endif
471475
}
472476
#ifndef NOFM
473477
if( gvars.opl3 ) {
474-
VOPL3_Init( AU_getfreq( hAU ) );
475-
printf("OPL3 emulation enabled at port 388h (%u Hz).\n", AU_getfreq( hAU ) );
478+
VOPL3_Init( AU_getfreq( gm.hAU ) );
479+
printf("OPL3 emulation enabled at port 388h (%u Hz).\n", AU_getfreq( gm.hAU ) );
476480
}
477481
#endif
478482
printf("SB emulation enabled at Addr=%x, Irq=%d, Dma=%d, ", gvars.base, gvars.irq, gvars.dma );
@@ -501,20 +505,20 @@ int main(int argc, char* argv[])
501505
if (p = malloc( 0x10000 ) )
502506
free( p );
503507

504-
bISR = SNDISR_Init(PIC_IRQ2VEC( AU_getirq( hAU ) ) );
508+
gm.bISR = SNDISR_Init( gm.hAU, gvars.vol * 256/9 ); /* vol: translate 0-9 to 0-256 */
505509

506-
if ( bISR ) {
510+
if ( gm.bISR ) {
507511
VIRQ_Init( gvars.irq );
508512
_InstallInt31();
509513
}
510514

511-
PIC_UnmaskIRQ( AU_getirq( hAU ) );
515+
PIC_UnmaskIRQ( AU_getirq( gm.hAU ) );
512516

513-
//AU_prestart( hAU );
514-
AU_start( hAU );
517+
//AU_prestart( gm.hAU );
518+
AU_start( gm.hAU );
515519
if (bOMode & 1 ) bOMode = 2; /* switch to low-level i/o */
516520

517-
if( bISR && ( bQemm || (!gvars.rm) ) && ( bHdpmi || (!gvars.pm) ) ) {
521+
if( gm.bISR && ( gm.bQemm || (!gvars.rm) ) && ( gm.bHdpmi || (!gvars.pm) ) ) {
518522
uint32_t psp;
519523
__dpmi_regs r = {0};
520524
__dpmi_set_coprocessor_emulation( 0 );
@@ -539,7 +543,7 @@ int main(int argc, char* argv[])
539543
r.x.ax = 0x3100;
540544
__dpmi_simulate_real_mode_interrupt(0x21, &r); //won't return on success
541545
}
542-
dbgprintf(("main: bISR=%u, bQemm=%u, bHdpmi=%u\n", bISR, bQemm, bHdpmi ));
546+
dbgprintf(("main: bISR=%u, bQemm=%u, bHdpmi=%u\n", gm.bISR, gm.bQemm, gm.bHdpmi ));
543547
ReleaseRes();
544548
printf("Error: Failed installing TSR.\n");
545549
return 1;

0 commit comments

Comments
 (0)