
	;-----------------------------
	; Whittaker-Play'routine' for DeliTracker
	;
	; this plays all WhittakerModules with these relativ
	; label addresses: init = $00; play = $04; end = $1c
	;
	; Anmerkung:
	; Whittakermodule die mit dem Ripper von 'Direct' gerippt wurden
	; sind um ca. 80 Byte zu kurz. Darum hört man beim Abspielen dieser
	; Module unangenehme (: Töne.
	; ( dies kann durch anhängen von 80 NULL-Bytes behoben werden)
	;
	; Also : Derartiges pfeifen wird NICHT durch dieses Playerinterface
	;  hervorgerufen.
	;-----------------------------
	; date : 26.05.91
	; by : Biohazard
	; on : DevPac Assembler V2(.30)d
	;-----------------------------

	;-----------------------------
	; Changed to fit the new playerinterface, slight changes
	; by Delirium, but the most importent thing 
	; (recogition of subsongnumber) was done by Biohazard !!!
	; I got this routine from Biohazard on 16.01.1992
	; Thank you very much !


	incdir	'includes:'
	include	'misc/deliplayer.i'

Init		EQU $00
Play		EQU $0e
End		EQU $1c

;
;
	SECTION	Whittaker-Deli,CODE
;
;

	PLAYERHEADER PlayerTagArray

	dc.b '$VER: David Whittaker player module V2.7 (12 Sep 92)',0
	even

PlayerTagArray
	dc.l	DTP_PlayerVersion,5
	dc.l	DTP_PlayerName,PlayerName
	dc.l	DTP_Creator,Creator
	dc.l	DTP_Check2,ChkFormat
	dc.l	DTP_Interrupt,Int
	dc.l	DTP_SubSongRange,SubSong
	dc.l	DTP_InitPlayer,InitPlay
	dc.l	DTP_EndPlayer,EndPlay
	dc.l	DTP_InitSound,InitSnd
	dc.l	DTP_EndSound,RemSnd
	dc.l	DTP_PrevSong,PrevSub
	dc.l	DTP_NextSong,NextSub
	dc.l	TAG_DONE

;------------------------------------------------------------------------------

PlayerName	dc.b	"Whittaker",0
Creator		dc.b	"David Whittaker, adapted by Biohazard",0
	even

ModuleAddr	dc.l	0			; module address
Cleanup		dc.l	0			; cleanup routine
Cleanup2	dc.l	0			; buffer for checking
MaxSong		dc.w	0			; maximal subsongnumber
MaxSong2	dc.w	0			; buffer for checking

;------------------------------------------------------------------------------

ChkFormat
	move.l	dtg_ChkData(a5),a0		; get moduladdress
	move.l	dtg_ChkSize(a5),d0		; and size

	cmpi.w	#$48e7,(a0)
	bne.s	Unknown
	cmpi.w	#$6100,4(a0)
	bne.s	Unknown
	cmpi.w	#$4cdf,8(a0)
	bne.s	Unknown
	cmpi.w	#$4e75,12(a0)
	bne.s	Unknown

	cmpi.w	#$48e7,14(a0)
	bne.s	Unknown
	cmpi.w	#$6100,18(a0)
	bne.s	Unknown
	cmpi.w	#$4cdf,22(a0)
	bne.s	Unknown
	cmpi.w	#$4e75,26(a0)
	beq.s	ChkFormat1
Unknown	moveq	#-1,d0				; module not known
	bra	ChkEnd
ChkFormat1
	moveq	#28,d1
	add.l	d1,a0				; set moduladdress
	sub.l	d1,d0				; and size
Check1	cmpi.w	#$43fa,(a0)
	bne.s	Check2
	cmpi.l	#$4880c0fc,4(a0)
	bne.s	Check2
	cmpi.w	#$41fa,10(a0)
	beq.s	ChkFormat2
Check2	addq.l	#2,a0
	subq.l	#2,d0
	bpl.s	Check1
	bra.s	Unknown
ChkFormat2
	move.l	a0,a1				; copy moduladdress
	move.l	d0,d1				; and size
Check3	cmpi.w	#$47fa,(a1)
	bne.s	Check4
	cmpi.w	#$51eb,4(a1)
	bne.s	Check4
	cmpi.w	#$51eb,8(a1)
	beq.s	FindLastSong
	cmpi.w	#$33fc,8(a1)
	beq.s	FindLastSong
Check4	addq.l	#2,a1
	subq.l	#2,d1
	bpl.s	Check3
	bra.s	Unknown
FindLastSong
	move.l	a1,Cleanup2

	move.w	2(a1),d1
	lea	2-12(a1,d1.w),a1
	move.l	a0,d1
	sub.l	a1,d1
	move.w	12(a0),d2			; offset for Whittaker_Array
	moveq	#0,d3				; test-offset
	move.w	#$7fff,d4			; max. offset
	moveq	#-1,d5				; song counter

TryNext	move.w	8(a0),d0			; Array Size
	lsr.w	#1,d0
	subq.w	#1,d0
	addq.w	#2,d2
TryLoop	move.w	12(a0,d2.w),d3			; get offset
	btst	#0,d3
	bne.s	TryEnd				; until odd
	sub.w	d1,d3
	cmp.w	d4,d3
	bge.s	TryOk
	move.w	d3,d4
TryOk	cmp.w	d4,d2
	bge.s	TryEnd				; until array end
	addq.w	#2,d2
	subq.w	#1,d0
	bne.s	TryLoop
	addq.l	#1,d5				; MaxSong+1
	bra.s	TryNext
TryEnd	move.w	d5,MaxSong2			; store MaxSong

	moveq	#0,d0				; we can play this song :-)
ChkEnd	rts

;------------------------------------------------------------------------------
;
; Set min. & max. subsong number

SubSong
	moveq	#0,d0				; min.
	move.w	MaxSong(pc),d1			; max.
	rts

;------------------------------------------------------------------------------
;
; Init Player

InitPlay
	moveq	#0,d0				; (file 0)
	move.l	dtg_GetListData(a5),a0		; get the module address
	jsr	(a0)
	move.l	a0,ModuleAddr			; and store it

	move.l	Cleanup2(pc),Cleanup		; copy buffer
	move.w	MaxSong2(pc),MaxSong		; copy buffer

	move.l	dtg_AudioAlloc(a5),a0		; allocate the audiochannels
	jsr	(a0)				; returncode is already set !
	rts

;------------------------------------------------------------------------------
;
; End Player

EndPlay
	move.l	dtg_AudioFree(a5),a0		; deallocate the audiochannels
	jsr	(a0)
	rts

;------------------------------------------------------------------------------

InitSnd	
	move.l	ModuleAddr(pc),a0		; ^module
	moveq	#0,d0				; for clearing the upper 16 bits
	move.w	dtg_SndNum(a5),d0		; dtg_SndNum
	jsr	Init(a0)			; init
	rts

;------------------------------------------------------------------------------

RemSnd
	move.l	Cleanup(pc),a0
	moveq	#0,d0
	jsr	(a0)				; call the cleanup function
	rts

;------------------------------------------------------------------------------
;
; Previous SubSong

PrevSub
	tst.w	dtg_SndNum(a5)			; first subsung ?
	beq.s	PrevSubEnd

	move.l	dtg_StopInt(a5),a0		; remove interrupt
	jsr	(a0)
	bsr	RemSnd
	subq.w	#1,dtg_SndNum(a5)		; prev sound
	bsr	InitSnd
	move.l	dtg_StartInt(a5),a0		; restart interrupt
	jsr	(a0)
PrevSubEnd
	rts

;------------------------------------------------------------------------------
;
; Next SubSong

NextSub
	move.w	dtg_SndNum(a5),d0		; dtg_SndNum
	cmp.w	MaxSong(pc),d0			; max. subsongnumber reached?
	bge.s	NextSubEnd			; yes, then exit ...

	move.l	dtg_StopInt(a5),a0
	jsr	(a0)
	bsr	RemSnd
	addq.w	#1,dtg_SndNum(a5)		; next sound
	bsr	InitSnd
	move.l	dtg_StartInt(a5),a0
	jsr	(a0)
NextSubEnd
	rts

;------------------------------------------------------------------------------

Int
	movem.l	d0-d7/a0-a6,-(sp)
	move.l	ModuleAddr(pc),a0
	moveq	#0,d0
	jsr	Play(a0)
	movem.l	(sp)+,d0-d7/a0-a6
	rts

;------------------------------------------------------------------------------

