Sound Engine
Sound Engine
Segments
MIDISeg segment PUBLIC 'DATA8' ; ** Holds MIDI stuff **
MIDIBuffer DB 65535 dup(?)
MIDISeg ENDS
SoundSeg segment PUBLIC 'DATA9' ; ** Holds sound stuff **
SoundBuffer db 65535 dup(?)
SoundSeg ENDS
Constants
MIDI_1 db 'MIDI/Award.xmi' , 0
MIDI_2 db 'MIDI/End.xmi' , 0
MIDI_3 db 'MIDI/Kalimari.xmi' , 0
MIDI_4 db 'MIDI/Luigi.xmi' , 0
MIDI_5 db 'MIDI/Rainbow.xmi' , 0
================ Sounds ======================
GO db 'Sound/Go.VOC' , 0
MENU db 'Sound/Menu.VOC' , 0
ENGINE db 'Sound/Engine.VOC' , 0
ALRIGHT1 db 'Sound/Alright1.VOC' , 0
ALRIGHT2 db 'Sound/Alright2.VOC' , 0
ALRIGHT3 db 'Sound/Alright3.VOC' , 0
FINALLAP db 'Sound/Finallap.VOC' , 0
GETYOU db 'Sound/Getyou.VOC' , 0
NOTIME db 'Sound/NoTime.VOC' , 0
COMPLETED db 'Sound/Completed.VOC' , 0
SKID1 db 'Sound/Skid1.VOC' , 0
SKID2 db 'Sound/Skid2.VOC' , 0
SMASH db 'Sound/Smash1.VOC' , 0
CLAP db 'Sound/Theclap.VOC' , 0
THREE db 'Sound/Three.VOC' , 0
TWO db 'Sound/Two.VOC' , 0
ONE db 'Sound/One.VOC' , 0
WOOO db 'Sound/Wooo.VOC' , 0
SWEAR db 'Sound/Swear.VOC' , 0
========================================================
SOUND VARIABLES
========================================================
================= SoundBlaster SETUP ==================
BaseAddr EQU 0220h ; SoundBlaster base address
IRQ7 EQU 13 ; SoundBlaster IRQ (8 +
IRQ)
DMAchannel EQU 1 ; SoundBlaster DMA channel
============ PIC MASKS FOR MASK/DEMASK IRQ =============
PICANDMASK EQU 11011111b ; 'AND' PIC mask for clear
IRQ7
PICORMASK EQU 00100000b ; 'OR' PIC mask for set
IRQ7
============== DMA CONTROLLER REGISTERS ================
WRITEMASK EQU 00ah ; WRITE MASK REGISTER
WRITEMODE EQU 00bh ; WRITE MODE REGISTER
CLEARFLIPFLOP EQU 00ch
PAGE_CHN EQU 083h ; PAGE REGISTER FOR
DMAChannel 1
BASE_CHN EQU 002h ; BaseAddress REGISTER
DMAChannel 1
COUNT_CHN EQU 003h ; COUNT REGISTER DMAChannel
1
============= SAMPLERATE ==============================
if you change it pay attention to maximum samplerate
Files have to be in the frequency of 10989 Hz
TIMECONST EQU 165 ; = 10989 Hz
(256-1000000/11000)
================ DMA WRITE MODE ========================
WANTEDMODE EQU 01001000b ; singlemode, autoinit,readmode
Variables
SoundSize dw ? , size of the VOC file
MIDISize dw ? , size of the MIDI file
WriteDSP MACRO X
- Owner: Jaime Chu
- Purpose: Write to the DSP
-
It does the following two things
- 1) Reads the DSP's WRITE BUFFER STATUS port (2xCh) till bit 7
- 2) Writes the value to the WRITE COMMAND/DATA port (2xCh)
- Inputs: X = Data to be written
- Outputs: None
- Notes: Reference off Programming the SoundBlaster DSP by Mark
Feldman
LoadMIDI
- Owner: Jaime Chu
- Purpose: This procedure loads the MIDI file into the memory
using the DOS interrupt 21 command. It opens the file and
then it loads into the MIDIBuffer and stores the length
of it in MIDISize
- Inputs: DX = offset of the string containing the MIDI
filename
- Outputs:
- MIDI file size is loaded into the MIDIBuffer
- MIDISize - Gets the size of the MIDI file
RegisterXMIDI
- Owner: Jaime Chu
- Purpose: This routine register an XMIDI file by address for
playback
- Inputs: AX = 704h , Command number
- BX = Offset , Offset portion of far address of XMIDI data
- SI = Low len , Low word of length XMIDI data
- DI = High Len , High word of length of XMIDI data
- Outputs: AX = 0 , Unable to register XMIDI data
- AX = 1 , XMIDI file registered resident, This means that the
XMIDI file was able to be held entirely in MIDPAK's internal buffer
area. The application can throw away the memory associated with
this XMIDI file because MIDPAK has made a copy of it itself.
This is very useful in virtual memory environments where the
applications program does not always have fixed addresses in memory.
It also allows MIDPAK to play back MIDI files in the background from
DOS.
- AX = 2 , XMIDI file was registered to the application. The
caller is responsible for making sure that this fixed memory address always
contains the data passed.
- Notes: Function # 5 from the document MIDPAK writtten by John
W.RatCliff
PlayMIDI
- Owner: Jaime Chu
- Purpose: Plays a sequence from the currently registered
Xmidi file
- Inputs: AX = 702h, Command number
- BX = Sequence number, numbered starting from zero
- Outputs: AX = 1, MIDI is being played
- AX = 0, MIDI is not available
- Notes: Function #3 from the document MIDPAK by John W.
Ratcliff
StopMIDI
- Owner: Jaime Chu
- Purpose: Stops playing current MIDI sequence
- Inputs: AX = 705h, Command
- Outputs: MIDI stops playing
- Notes: Function #6 from the document MIDPAK by John W.
RatCliff.
LoadSound
- Owner: Jaime Chu
- Purpose: This procedure loads the VOC
file into the memory segment
using the DOS interrupt 21 command. It opens the file and
then it loads into the SoundBuffer and stores the length
of it in SoundSize
- Inputs: DX = offset of the string containing the VOC
filename
- Outputs: Sound file size is loaded into the SoundBuffer
- SoundSize - Gets the size of the VOC file
ResetDSP
- Owner: Jaime Chu
- Purpose: This function resets the DSP
- It does the following.
- 1) Writes a 1 to the reset port
- 2) Waits for 3 microseconds
- 3) Writes a 0 to the reset port
- 4) Poll the read-buffer status until bit 7 is set
- 5) Poll the read data port until you receive AAh
- Inputs: BaseAddr
- Outputs: AL = 0 ; Reset unsucessfully
- AL = 1 ; Reset successfully
- Notes: This function is based off the DMASTEP7 program.
SoundBlaster 16 Programming Document written by Etahn Brodsky
was used as
reference.
SetupDMA
- Owner: Jaime Chu
- Purpose: This routine sets up the DMA
- It does the following steps
- 1) Calculates page and offset for the DMAcontroller
- 2) Mask DMA Channel
- 3) Clear flipflop
- 4) Write page number
- 5) Write DMA base address
- 6) Write Basecounter = samplelength - 1
- 7) Demask channel
- Inputs: SoundBuffer
- Outputs: DMA is set up
- Notes: This is based off the DMASTEP7 as well as the
SoundBlaster 16
Programming Document written by Ethan Brodsky
LoadSound
- Owner: Jaime Chu
- Purpose: Sets up the soundblaster and plays the VOC file
- It does the following
- 1) Sets up the timeconstant
- 2) Uses the highspeed, autoinit DMA (90h)
- 3) Sets up the playmode and transfers.
- Inputs : SoundSize
- Outputs: Sound to the speakers
- Notes: Based off DMASTEP7 as well as PASCAL source code by Mark
Feldman from the Programming the SoundBlaster DSP doc.
Refer to the beginning of sound code for DSP commands.