3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: drivers/dd/sndblst/portio.c (see also sndblst.h)
6 * PURPOSE: Sound Blaster port I/O helper
7 * PROGRAMMER: Andrew Greenwood
9 * Sept 28, 2003: Created
15 BOOLEAN
WaitToSend(ULONG BasePort
)
19 DPRINT("WaitToSend ");
21 // Check if it's OK to send
22 for (TimeOut
= SB_TIMEOUT
;
23 ! SB_READY_TO_SEND(BasePort
) && TimeOut
> 0;
26 // If a time-out occurs, we report failure
33 DPRINT("SUCCEEDED\n");
38 BOOLEAN
WaitToReceive(ULONG BasePort
)
42 DPRINT("WaitToReceive ");
44 // Check if it's OK to receive
45 for (TimeOut
= SB_TIMEOUT
;
46 ! SB_READY_TO_RECEIVE(BasePort
) && TimeOut
> 0;
49 // If a time-out occurs, we report failure
56 DPRINT("SUCCEEDED\n");
62 USHORT
InitSoundCard(ULONG BasePort
)
66 UCHAR DSP_Major
, DSP_Minor
;
68 DPRINT("InitSoundCard() called\n");
70 DPRINT("Resetting sound card\n");
71 // if (!WaitToSend(BasePort))
74 SB_WRITE_RESET(BasePort
, 0x01);
75 for (TimeOut
= 0; TimeOut
< 30000; TimeOut
++); // Wait a while
76 SB_WRITE_RESET(BasePort
, 0x00);
78 // Check if it's OK to receive (some cards will ignore the above reset
79 // command and so will not issue an ACK, so time out is NOT an error)
80 DPRINT("Waiting for an ACK\n");
81 if (WaitToReceive(BasePort
))
83 // Check to make sure the reset was acknowledged:
84 for (TimeOut
= SB_TIMEOUT
;
85 (Status
= (SB_READ_DATA(BasePort
) != SB_DSP_READY
) && (TimeOut
> 0));
89 DPRINT("Querying DSP version\n");
90 if (! WaitToSend(BasePort
))
93 SB_WRITE_DATA(BasePort
, SB_GET_DSP_VERSION
);
95 if (! WaitToReceive(BasePort
))
98 DSP_Major
= SB_READ_DATA(BasePort
);
99 DSP_Minor
= SB_READ_DATA(BasePort
);
101 DPRINT("DSP v%d.%d\n", DSP_Major
, DSP_Minor
);
103 // if audio is disabled,
104 // version tests return 0xFF everywhere
105 if (DSP_Major
== 0xFF && DSP_Minor
== 0xFF)
108 DPRINT("Sound card initialized!\n");
110 return (DSP_Major
* 256) + DSP_Minor
;