; БББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ
;    It's too bad I didn't own a GUS, instead I have a SB16ASP...oh well...
; I really wanted to experience this demo with music playing in the back-
; ground.  I decided to rip the MOD and use IPLAY to play it, then excute
; the demo...well...it works fine...the demo is a little slow, but what
; the hell.  You will need about 2MB of Expanded memory for this to work.
; Load the MOD with Inertia Player, shell to dos and run the demo.
;
; This file will extract the 8 channel mod file from the VERSES demo by EMF
; to disk in order for you to play it.
;
;							Bad Sector/iLL
; БББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББББ

.MODEL SMALL
DOSSEG

.STACK 0

.DATA
	Demo_File	db	'VERSES.EXE',0
	Mod_File	db	'DTROUBLE.MOD',0
	Error_Msg	db	'Sorry, a critical error has occurred'
			db	13,10,'$'
.DATA?
	Demo_Handle	dw	?
	Mod_Handle	dw	?
	Byte_Read	dw	8000 dup(?)

.CODE

Main	proc
	
	mov	ax,dgroup		; program setup
	mov	ds,ax

	mov	ah,4ah			; reduce program memory size
	mov	bx,437fh		; i dunno..EXEMOD gave me this
	int	21h


	mov	ax,3d00h		; open file for reading
	mov	dx,offset Demo_File
	int	21h
	jnc	@FileOkay		; error check

@Error:
	mov	ah,09h			; If error, display warning
	mov	dx,offset Error_Msg	; then exit.
	int	21h
	jmp	@Exit

@FileOkay:
	mov	Demo_Handle,ax		; make a backup of handle

	mov	ax,4200h		; LSEEK to MOD offset
	mov	bx,Demo_Handle
	mov	cx,0006h
	mov	dx,0BD35h
	int	21h

	mov	ah,3ch			; Create MOD file
	xor	cx,cx
	mov	dx,offset Mod_File
	int	21h
	jc	@Error			; error check

	mov	ax,3d01h		; open file for writing
	mov	dx,offset Mod_File
	int	21h
	jc	@Error			; error check

 	mov	Mod_Handle,ax		; make backup of new file handle

 	mov	cx,64			; number of cycles
@ReadLoop:
 	push	cx			; preserve loop count

 	mov	ah,3fh			; read from file
 	mov	bx,Demo_Handle
 	mov	cx,5536
 	mov	dx,offset Byte_Read
 	int	21h
 	jc	@Error			; error check
 	mov	cx,ax			; number of bytes read

 	mov	ah,40h			; write to (mod) file
 	mov	bx,Mod_Handle
 	mov	dx,offset Byte_Read
 	int	21h
 	jc	@Error			; error check

 	pop	cx			; restore loop count
 	loop	@ReadLoop

@Done:
	mov	ah,3eh			; close files handles
	mov	bx,Demo_Handle
	int	21h

	mov	ah,3eh
	mov	bx,Mod_Handle
	int	21h

@Exit:
	mov	ah,4ch			; Exit to Dos
	int	21h

Main	endp

	end Main
	