How to program your SoundBlaster board
(see at the end of document for Copyrights and Warranties)
Chapter 1 - Basis of DSP Programming
Ok, I'll start this chapter giving you all the DSP I/O port adresses and a bit of information about each of them. Note that the real I/O adress is the base adress plus the relative adress shown in the following table
Adress (base +) | Explanation & note |
________________ | _______________________________________________________ |
06h | Reset port (Write only) |
0Ah | Read Data port (Read only) |
0Ch | Write Command/Data port (Write only) |
0Ch | Write ready status (Read only) |
(when DSP is ready to receive a data or a command, the MSB will be 1.) | |
0Eh | Data available status (Read only) |
(when data is available, the MSB will become 1.) | |
0Eh | IRQ Acknowledge (8 bit - Read only) |
0Fh | IRQ Acknowledge (16 bit - Read only) |
(Apply only on SB 16 or later) |
Well, first we want to reset the DSP. The procedure will be:
- Write 01h in DSP reset port (06h)
- Wait at least 3.3 microseconds
- Write 00h in DSP reset port (06h)
- Read the Data available status (OEh) until data becomes
available. If data is still unavailable after 100 microseconds,
reset has failed.
- Read a value from the Read data port
(0Ah). This should be AAh. If it's not, reset has failed.
Note: resetting the DSP, you'll terminate also any possible pending operation and you'll turn off speakers.
If reset fails when you're scanning the I/O ports for the DSP chip, it's possible that your SB is mapped on a different location. Try another base port adress. If reset has been completed, your SB is ready to being programmed. Before starting outputting samples it's better to discover which model of SB are we communicating to. This is done giving the DSP its Chip Version command.
As a general rule remember that the DSP could be busy so, before sending him a command (or a data, as we will see) check if it's ready to answer reading the Write ready status port (0Ch).
Ok, say the DSP is ready to accept a command and we want to ask its Version number. This is done writing command E1h (Chip Version command) on Write Command/Data port (0Ch). When data becomes available (remember?) you can read the Read Data port (0Ah). Well... the Version is two bytes long (most significant byte first), so read the port twice. Here's a table showing the Chip Version - SB Model correspondancy.
DSP Version | SB Model |
_______________ | ________________ |
100h to 1FFh | SB 1.0, SB 1.5 |
200h to 2FFh | SB 2.0 |
300h | SB Pro |
301h to 3FFh | SB Pro2 |
400h to 411h | SB 16 |
412h | SB AWE 32 |
Now it's time to turn on speakers; it can be done throught DSP command D1h. Command D3h instead, is to turn off speakers. Both commands does not return any data. To retrieve the speaker current status use command D8h; DSP will return 00h if speakers are disabled and FFh if they are enabled.
Now that the speakers has been enabled, it's time to play our first sample. In this chapter I'll show the easyest way to do that; we'll play a sample without using any IRQ nor DMA channel programming. Take this only as an example: the way we'll really use the SB it's far from here (I'll show you that way in the next chapter).
I assume we have loaded an 8 bit sample as an array of byte somewhere in memory. Now, iterating from the first to the last byte in the array, do this for each value: write command 10h into DSP' Write Command/Data port, when the DSP is ready again write the current data byte into the same port. Do that until you reach the end of the array. It works? Well, here are the disadvantages of that system. First: You must provide correct timing at the rate you want to play the sample. Second: The maximum sample rate that your SB can reach must be divided by two because you write a command and a data for each byte you want to output. Third, not the less important, while you're playing a sample in that way, the CPU is spending the whole (or a lot of) time doing nothing but waiting for the timing and the Write ready status ok flag!
I hope you have an idea about what does it means having your SB playing and your CPU almost totally free to do other, more sophisticated, tasks. But that's the next chapter! Advanced DSP Programming: I will teach you how to use the DMA channels and the IRQ, how to make a double (or even triple) buffering scheme to play samples at full speed, also with real-time sample interpolation, even if the samples can't fit in memory in the whole!
Here's a table showing the DSP commands we have used in this chapter
DSP Command | What it does |
___________________ | _________________________ |
10h | Direct output |
D1h | Enable speakers |
D3h | Disable speakers |
D8h | Retrieve current speaker status |
E1h | Chip Version |
Stay tuned! Sverx, 23 / 05 / 98 __________________________________________________________________
Warranty and Copyright Policy
This document is provided on an "as-is" basis, and its author makes no warranty or representation, express or implied, with respect to its quality performance or fitness for a particular purpose. In no event will the author of this document be liable for direct, indirect, special, incidental, or consequential damages arising out of the use or inability to use the information contained within. Use of this document is at your own risk.
This file may be used and copied freely so long as the applicable copyright notices are retained, and no modifications are made to the text of the document. No money shall be charged for its distribution beyond reasonable shipping, handling and duplication costs, nor shall proprietary changes be made to this document so that it cannot be distributed freely. This document may not be included in published material or commercial packages without the written consent of its author.
ALL COPYRIGHTS AND TRADEMARKS BELONG TO THEIR RESPECTIVE OWNERS.
_________________________________________________________________
[ Back to Main Programming Page - Back to Chapter 0 - Go to Chapter 2 - Back to Home Page ]