! A simple raw sample playback program for soundblaster
! Not worth much, just testing my sound code.
! Doesn't even work; there are lots of places I cut corners
! But feel free to write a much improved version in C for me...


use16
.text
.data
.bss

.align 0

.globl _main         ! for ld86
_main:
	.org	0x100

	push	cs
	pop	ds
	mov	dx, #string
	mov	ax, #0x3D00
	int	0x21

! The following section arbitarily transfers data to the highest 64K of the
! 640K area.  If you have tons of TSRs, it WILL crash!
	mov	bx, ax
	mov	ds, #0x9000
	mov	dx, #0
        mov     cx, #0xFFFF
        mov	ah, #0x3F
        int	0x21

! We'll "forget" to close the file and let the OS take care of it for us
! when we terminate

! We now program the DMA controller
! We assume you use DMA channel 1
! First set the page
        mov	al, #9
	out	0x83, al
! Set the mask bit; not required in dosemu, but we need to be
! able to use this in real dos to verify ITS acuracy!
	mov	al, #5
	out	0x0a, al
! Now clear the byte pointer
	xor	al, al
	out	0x0C, al
! Set the mode
	mov	al, #0x49
	out	0x0b, al
! Set address (0), length
	mov	al, #0
	out	2, al
	out	2, al
	mov	al, #0xFF
	out	3, al
	out	3, al
! Now clear the mask
	mov	al, 1
	out	0x0A, al

! Okay, now program the SB
! We assume that the mixer has been sanely programmed!
! We ignore reset; dosemu doesn't care!

	mov	al, #0x40
	mov	dx, #0x22C
	out	dx, al
	mov	al, #156
	out	dx, al
	mov	al, #0x14
	out	dx, al
	mov	al, #0xff
	out	dx, al
	out	dx, al

! Note that the above fragment didn't wait for the dsp to be ready!

! Now we do one more stupid thing that the docs wouldn't recomend: we exit
! to DOS while the music keeps playing.

	mov	ah, #0x4c
	int	0x21


string:
	.ascii "D:\PCAUDIO\AUDCLIPS\PHRASES\BOTTOMLN.WAV"
! An arbitrarily selected .wav on my system.

