Procedures in Sound.asm

All procedures either property of Charles Chandler or the SoundLib291

Introduction

The procedures below are used to play wav and midi files. The sound library provided to us took care of all DMA transactions and the

heart of playing wav files. The procedures themselves are used in conjunction with the library to ensure that the entire wav file is being

played. Online documentation for MidPak was very instrumental in developing the code to play midi files. Interrupts were used to setup

the midi files, start the file playing, and to the stop the music.
 
ALLDEAD EQU 0
ANGRY EQU 1
CANNON2 EQU 2
DEMENTED EQU 3
EXPLOSION1 EQU 4
EXPLOSION2 EQU 5
GOODLAFF EQU 6
STARTUP EQU 7
LAUNCH EQU 8
LAUNCH3 EQU 9
WAVHDR STRUCT

format db 'RIFF'

filelen dd ?

wavefmt db 'WAVEfmt_'

fmt_len dd ?

fmt_tag dw ?

channel dw ?

samples dd ?

bytesps dd ?

bkalign dw ?

bitsps dw ?

data db 'data'

datalen dd ?

WaveHdr Ends

 

WAV Variables

sbuf_page db ?

sbuf_offset dw ?

sbuf_length dw 8192

Pbuf db 7 dup (?)

finalbuffersize dw ?

mycounter dw -1

counter dw -1

needrefill dw 0

loadbuf WaveHdr < >

WavMsg db 'Played wav file in ','$'

CyclesMsg db ' cycles.',13,10,'$'

wavfile db 'xxxxxxxx.wav',0

fileno dw ?

wavremaining dd 0

wavlength dd 0

wavdone db 0

 

WAV Files

SoundHandler

Purpose: This handler increases the value in the buffer, which generates the continually loudening tone.

Inputs:

CS = Source segment of the sound file

ES = Destination segment of the buffer

Description: Called whenever the DSP generates an interrupt. The variable "mycounter" is incremented so

outside program knows where DMA is. "needrefill" also incremented to indicate if half buffer needs to be filled.

OpenWav

Purpose: Opens a wav file and advances to the beginning of data

Inputs: None.

Outputs: EAX = data length = bytes of Sound Data.

 

LoadHalfBuffer

Purpose: Takes a 1 or 0 in AX, and reads from the file into the appropriate half of sndbuf.

Input: AX = secondhalf

Output:

CF = 1 if just loaded last buffer

AX = number of bytes read

 

PLAY_WAV

Purpose: Plays a specified wav file.

Input: AX = number of wav file to be played

Output: Specified wav file

Calls:

OpenWAV

LoadHalfBuffer

LIB291 functions

 

Midi Music File
 
Rainmain.xmi 0
Settings.xmi 1
LoadXMI

Description: Loads a XMI file into memory to be read by Midpak

Inputs: DX = offset of file name in memory

Outputs: MidiSeg = segment with midi data

Calls: Nothing

 

RegisterMidi

Description: Registers a MIDI file with Midpak

Inputs:

MidiSize

MidiSeg

Outputs: Midi file registered by Midpak

 

StartMidi

Descrioption: Starts the loaded and registered midi file playing

Inputs: The registered Midi file

Outputs: Audio

 

StopMidi

Description: Stops the currently playing MIDI file

Outputs: Silence

 

PlayIntroMidi

Description: Calls the above three procedures to decrease the number of

calls in main.asm. DX is set to the offset of the midi file for the intro screen.

Inputs: None

Outputs: Settings.xmi

Calls:

LoadXMI

RegisterMidi

StartMidi

 

PlayGameMidi

Description: Calls the above three procedures to decrease the number of

calls in main.asm. DX is set to the offset of the midi file for game play.

Inputs: None

Outputs: Rainman.xmi

Calls:

LoadXMI

RegisterMidi

StartMidi