'=========================================================================== ' Subject: PLAY NOTE VIA SB CARD Date: Unknown Date ' Author: Brandon Callison Code: QB, QBasic, PDS ' Origin: QBTIPS Packet: SOUND.ABC '=========================================================================== ' Sound Blaster Source Code ' Made by Brandon Callison ' Register 388h is the address/status port, and 389h is the data port. 'This is, of course, only for the FM music. (The cannels 1-11) which are 'compatible with Ad-Lib, Sound Blaster, SB Pro, Thunder Board, and many 'others. All boards advertised as compatible with Ad-Lib or Sound Blaster 'are compatible with this. Explainations of the mysterious code will be 'throughout the program. DEFINT A-Z DECLARE SUB SBStop () DECLARE SUB SBReset () DECLARE SUB SBOutPort (reg, x) DECLARE SUB SBPlayNote (freq#, oct) ' vvvvvvvvvvvvvvvvvvvvvvv ' The following are his variable declarations; I'm leaving them in so you ' can see what all the variables are for: ' 'float freq; /* Frequency */ 'int oct; /* Octave */ 'int reg; /* Register no. */ 'int x; /* Poke number to register */ 'int i; /* GLOBAL Dummy loop signal */ ' ' ^^^^^^^^^^^^^^^^^^^^^^^ SBReset SBPlayNote 277.2, 5 'Middle C sharp on octave 5 SLEEP 2 SBStop 'Must be called to cut sound END SUB SBOutPort (reg, x) OUT &H388, reg 'Outputs the register to be written to FOR I = 1 TO 6 reg = INP(&H388) NEXT I ' ^- This loop requires some explaining. The sound card must allow time 'to process it's code. 6 reads from the status port will cause it to wait 'for 2.3 microseconds. You MUST NOT make any outputs to the sound card port 'without waiting at least this amount of time in-between calls. The same 'applies below, except the wait is 23 microseconds, by 35 reads from the data 'port. OUT &H389, x FOR I = 1 TO 35 'Outputs the data into the register reg = INP(&H389) NEXT I END SUB SUB SBPlayNote (freq#, oct) freq2 = INT(1.31 * freq#) 'Convert from hz to raw frequency?!?! SBOutPort &H60, &HF0 SBOutPort &HC0, 1 SBOutPort &HA0, freq2 AND &HFF SBOutPort &HB0, ((freq2 AND &HFF00) / &H100) OR (oct * 4) OR 32 ' ^- for different channels, do anywhere from the register ' 0xB0 to 0xBA. (channels 1-11) END SUB SUB SBReset FOR I = 1 TO 244 ' The sound card has 244 data ports. Just clears OUT &H388, 0 ' all of them. NEXT I END SUB SUB SBStop SBOutPort &HB0, 0 ' As I said earlier for different channels END SUB