11
11
#ifdef DJGPP
12
12
#include <go32.h>
13
13
#include <sys/exceptn.h>
14
+ #include <crt0.h>
14
15
#endif
15
16
16
17
#include "CONFIG.H"
43
44
bool _InstallInt31 ( void );
44
45
bool _UninstallInt31 ( void );
45
46
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
+
47
53
uint32_t __djgpp_stack_top ;
48
54
uint32_t _linear_psp ;
49
55
uint32_t _linear_rmstack ;
50
56
uint32_t _get_linear_psp ( void );
51
57
uint32_t _get_linear_rmstack ( int * );
52
58
uint32_t _get_stack_top ( void );
53
59
60
+ extern uint32_t STACKTOP ;
61
+
54
62
/* don't assume hdpmi is loaded - get PSP selector from OW's _psp global var! */
55
63
#pragma aux _get_linear_psp = \
56
64
"mov ebx, [_psp]" \
@@ -73,25 +81,24 @@ uint32_t _get_stack_top( void );
73
81
modify exact [bx dx eax]
74
82
75
83
#pragma aux _get_stack_top = \
76
- "mov eax, esp " \
84
+ "mov eax, [STACKTOP] " \
77
85
parm [] \
78
86
modify exact[eax];
79
87
80
88
#endif
81
89
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
-
85
90
uint8_t bOMode = 1 ; /* 1=output DOS, 2=direct, 4=debugger */
86
91
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
+ };
90
100
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 };
95
102
96
103
struct globalvars gvars = { BASE_DEFAULT , IRQ_DEFAULT , DMA_DEFAULT ,
97
104
#if SB16
@@ -112,7 +119,7 @@ static const struct {
112
119
const char * desc ;
113
120
int * pValue ;
114
121
} GOptions [] = {
115
- "/?" , "Show help" , & bHelp ,
122
+ "/?" , "Show help" , & gm . bHelp ,
116
123
"/A" , "Set IO base address [220|240, def 220]" , & gvars .base ,
117
124
"/I" , "Set IRQ number [2|5|7, def 7]" , & gvars .irq ,
118
125
"/D" , "Set DMA channel [0|1|3, def 1]" , & gvars .dma ,
@@ -128,7 +135,7 @@ static const struct {
128
135
"/OPL" ,"Set OPL3 emulation [0|1, def 1]" , & gvars .opl3 ,
129
136
"/PM" , "Set protected-mode support [0|1, def 1]" , & gvars .pm ,
130
137
"/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 ,
132
139
"/VOL" , "Set master volume [0-9, def 7]" , & gvars .vol ,
133
140
"/BS" , "Set PCM buffer size [in 4k pages, def 16]" , & gvars .buffsize ,
134
141
#if SLOWDOWN
@@ -182,9 +189,9 @@ static void ReleaseRes( void )
182
189
//////////////////////////////
183
190
{
184
191
_UninstallInt31 (); /* must be called before SNDISR_Exit() */
185
- if (bISR ) {
192
+ if ( gm . bISR ) {
186
193
VIRQ_Exit ( gvars .irq );
187
- SNDISR_Exit ( PIC_IRQ2VEC ( AU_getirq ( hAU ) ) );
194
+ SNDISR_Exit ();
188
195
}
189
196
190
197
if ( gvars .rm )
@@ -207,7 +214,7 @@ void MAIN_Uninstall( void )
207
214
///////////////////////////
208
215
{
209
216
ReleaseRes ();
210
- AU_close ( hAU );
217
+ AU_close ( gm . hAU );
211
218
_uninstall_tsr ( _my_psp () ); /* should not return */
212
219
return ;
213
220
}
@@ -219,7 +226,7 @@ void MAIN_ReinitOPL( void )
219
226
if ( gvars .opl3 ) {
220
227
uint8_t buffer [108 ];
221
228
fpu_save (buffer );
222
- VOPL3_Reinit ( AU_getfreq ( hAU ) );
229
+ VOPL3_Reinit ( AU_getfreq ( gm . hAU ) );
223
230
fpu_restore (buffer );
224
231
}
225
232
}
@@ -305,12 +312,12 @@ int main(int argc, char* argv[])
305
312
}
306
313
}
307
314
if ( GOptions [j ].option == NULL )
308
- bHelp = true;
315
+ gm . bHelp = true;
309
316
}
310
317
311
318
/* if -? or unrecognised option was entered, display help and exit */
312
- if ( bHelp ) {
313
- bHelp = false;
319
+ if ( gm . bHelp ) {
320
+ gm . bHelp = false;
314
321
printf ("VSBHDA v" VERMAJOR "." VERMINOR "; Sound Blaster emulation on HDA/AC97. Usage:\n" );
315
322
316
323
for ( i = 0 ; GOptions [i ].option ; i ++ )
@@ -361,8 +368,8 @@ int main(int argc, char* argv[])
361
368
printf ("Error: Invalid PCM buffer size %d\n" , gvars .buffsize );
362
369
return 1 ;
363
370
}
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 );
366
373
return 1 ;
367
374
}
368
375
#if defined(DJGPP )
@@ -398,24 +405,21 @@ int main(int argc, char* argv[])
398
405
}
399
406
//aui.card_select_config = gvars.pin;
400
407
//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 ) {
402
409
printf ("No soundcard found!\n" );
403
410
return 1 ;
404
411
}
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 ) {
407
414
printf ("Sound card IRQ conflict, abort.\n" );
408
415
return 1 ;
409
416
}
410
- AU_setmixer_init ( hAU );
417
+ AU_setmixer_init ( gm . hAU );
411
418
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 );
417
421
418
- AU_setrate ( hAU , freq , HW_CHANNELS , HW_BITS );
422
+ AU_setrate ( gm . hAU , gm . freq , HW_CHANNELS , HW_BITS );
419
423
420
424
if ( gvars .rm ) {
421
425
gvars .rm = PTRAP_Prepare_RM_PortTrap ();
@@ -437,15 +441,15 @@ int main(int argc, char* argv[])
437
441
gvars .hdma = 0 ;
438
442
#endif
439
443
440
- VPIC_Init ( AU_getirq ( hAU ) );
444
+ VPIC_Init ( AU_getirq ( gm . hAU ) );
441
445
442
446
#ifdef NOFM
443
447
gvars .opl3 = 0 ;
444
448
#endif
445
449
#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 ) );
447
451
#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 ) );
449
453
#endif
450
454
#if SB16
451
455
VSB_Init ( gvars .irq , gvars .dma , gvars .hdma , gvars .type );
@@ -459,20 +463,20 @@ int main(int argc, char* argv[])
459
463
#endif
460
464
461
465
if ( gvars .rm ) {
462
- if ((bQemm = PTRAP_Install_RM_PortTraps ()) == 0 )
466
+ if ((gm . bQemm = PTRAP_Install_RM_PortTraps ()) == 0 )
463
467
printf ("Error: Failed installing IO port trap for real-mode.\n" );
464
468
}
465
469
if ( gvars .pm ) {
466
- if (( bHdpmi = PTRAP_Install_PM_PortTraps ()) == 0 )
470
+ if (( gm . bHdpmi = PTRAP_Install_PM_PortTraps ()) == 0 )
467
471
printf ("Error: Failed installing IO port trap for protected-mode.\n" );
468
472
#ifdef _DEBUG
469
473
//PTRAP_PrintPorts(); /* for debugging */
470
474
#endif
471
475
}
472
476
#ifndef NOFM
473
477
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 ) );
476
480
}
477
481
#endif
478
482
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[])
501
505
if (p = malloc ( 0x10000 ) )
502
506
free ( p );
503
507
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 */
505
509
506
- if ( bISR ) {
510
+ if ( gm . bISR ) {
507
511
VIRQ_Init ( gvars .irq );
508
512
_InstallInt31 ();
509
513
}
510
514
511
- PIC_UnmaskIRQ ( AU_getirq ( hAU ) );
515
+ PIC_UnmaskIRQ ( AU_getirq ( gm . hAU ) );
512
516
513
- //AU_prestart( hAU );
514
- AU_start ( hAU );
517
+ //AU_prestart( gm. hAU );
518
+ AU_start ( gm . hAU );
515
519
if (bOMode & 1 ) bOMode = 2 ; /* switch to low-level i/o */
516
520
517
- if ( bISR && ( bQemm || (!gvars .rm ) ) && ( bHdpmi || (!gvars .pm ) ) ) {
521
+ if ( gm . bISR && ( gm . bQemm || (!gvars .rm ) ) && ( gm . bHdpmi || (!gvars .pm ) ) ) {
518
522
uint32_t psp ;
519
523
__dpmi_regs r = {0 };
520
524
__dpmi_set_coprocessor_emulation ( 0 );
@@ -539,7 +543,7 @@ int main(int argc, char* argv[])
539
543
r .x .ax = 0x3100 ;
540
544
__dpmi_simulate_real_mode_interrupt (0x21 , & r ); //won't return on success
541
545
}
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 ));
543
547
ReleaseRes ();
544
548
printf ("Error: Failed installing TSR.\n" );
545
549
return 1 ;
0 commit comments