*****************************************************************************
**                                                                         **
** Eagleripper: J.C. Brooke                                                **
**                                                                         **
** Project: Eagleplayer 2.04                                               **
** Authors: Jan Blumenthal & Henryk Richter                                **
** Start  : 1993/01/09                                                     **
** $Header$                                                                **
**                                                                         **
*****************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program (See the included file COPYING);
** if not, write to the Free Software Foundation, Inc.,
** 675 Mass Ave, Cambridge, MA 02139, USA.
**
***************************************************************************** 


*-----------------------------------------------------------------------------*
*			      Eagleripper V1.0				      *
*				JC.Brooke				      *
*-----------------------------------------------------------------------------*
Test	= 0
		incdir	include:
		include	misc/eagleplayerripper.i
		include	exec/exec_lib.i
			
	if	Test
	lea	data,a0
	*lea	JC_Tags,a0
	move.l	#datasize,d0
	move.l	a0,a5
	move.l	a0,a4
	move.l	d0,d4
	move.l	d0,d6
wait:	move.l	a5,a1
	move.l	a4,a0
	move.l	d4,d0
	move.l	(a1),d1
	bsr	JC_Ripp1
	tst.l	d0
	beq.s	.Ja
	addq.l	#2,a5
	subq.l	#2,d6
	blt.s	.Err
	btst	#6,$bfe001
	bne.s	wait
.err:	moveq	#-1,d0
.ret:	illegal

.ja:	move.l	d1,d0
	*bsr	GetModuleName
	bra.s	.Ret
	endc
		RIPPERHEADER	JC_Tags

	dc.b	"Jesper Olsen EagleRipper V1.0",10
	dc.b	"done by Eagleeye/DFT 28.08.97",0
	even

JC_Tags:	dc.l	RPT_Formatname,.Formatname
		dc.l	RPT_Ripp1,JC_Ripp1
		dc.l	RPT_RequestRipper,1
		dc.l	RPT_Version,1<<16!0
		dc.l	RPT_Creator,.Creator
		dc.l	RPT_Prefix,.Prefix
		dc.l	RPT_Playername,.Playername
		dc.l	0

.Prefix:	dc.b	"JC.",0
.Formatname:
.Playername:	dc.b	"J.C.Brooke",0
.Creator:	dc.b	"J.C.Brooke (from Elite Software),"
		dc.b	"adapted by Eagleeye of DEFECT",0
		even

*-----------------------------------------------------------------------------*
* Input: a0=Adr (start of memory)
*	 d0=Size (size of memory)
*	 a1=current adr
*	 d1=(a1.l)
* Output:d0=Error oder NULL
*	 d1=Size
*	 a0=Startadr (data)
*-----------------------------------------------------------------------------*
JC_Ripp1:	lsr.l	#8,d1
		lsr.l	#8,d1
		cmp.w	#$48e7,d1
		beq.s	.Ja
		rts

		*--- Jetzt testen, ob es ein korrektes Module sein kann ---*
.Ja:		lea	2(a1),a0
		cmpi.l	#$8F90001,2(a0)
		bne.w	.Error
		cmpi.l	#$BFE001,6(a0)
		bne.w	.Error
		cmpi.l	#$33FC0780,10(a0)
		bne.w	.Error
		cmpi.l	#$DFF09A,14(a0)
		bne.w	.Error
		cmpi.w	#$47FA,$12(a0)
		bne.w	.Error

		lea	Load_ModuleStart(pc),a2
		clr.l	(a2)
		clr.l	4(a2)
		clr.l	8(a2)
		clr.l	12(a2)
		clr.l	16(a2)
		clr.l	20(a2)

		subq.l	#2,a0
		move.l	a0,Load_InterruptJump
		lea	$16(a0),a0
		adda.w	(a0),a0
		move.l	a0,Load_ModuleStart
		move.w	#$1000,d1
.lbC0001A6:	cmpi.w	#$2F08,(a0)+
		beq.s	.lbC0001B4
.lbC0001AC:	subq.w	#2,d1
		ble.l	.lbC0002C4
		bra.s	.lbC0001A6

.lbC0001B4:	cmpi.w	#$41FA,(a0)
		bne.s	.lbC0001AC
		lea	2(a0),a1
		adda.w	(a1),a1
		cmpa.l	Load_ModuleStart(pc),a1
		bne.s	.lbC0001AC
		subq.l	#2,a0
		move.l	a0,Load_EndSoundJump
		move.l	Load_ModuleStart(pc),a0
		move.w	#$1000,d1
.lbC0001D6:	cmpi.w	#$6100,(a0)+
		beq.s	.lbC0001E4
.lbC0001DC:	subq.w	#2,d1
		ble.l	.lbC0002C4
		bra.s	.lbC0001D6

.lbC0001E4:	cmpi.w	#$4E75,-4(a0)
		bne.s	.lbC0001DC
		cmpi.l	#$48E7E0D0,2(a0)
		bne.s	.lbC0001DC
		cmpi.w	#$41FA,8(a0)
		bne.s	.lbC0001DC
		subq.l	#2,a0
		move.l	a0,Load_InitSound2
		moveq	#$7F,d1
.lbC000208:	cmpi.w	#$43FA,(a0)+
		beq.s	.lbC000216
.lbC00020E:	subq.w	#2,d1
		ble.l	.lbC0002C4
		bra.s	.lbC000208

.lbC000216:	cmpi.w	#$51C9,-6(a0)
		bne.s	.lbC00020E
		move.l	a0,a1
		adda.w	(a1),a1
		subq.l	#1,a1
		moveq	#$40,d1
.lbC000226:	cmpi.w	#$C0FC,(a0)+
		beq.s	.lbC000234
		subq.w	#2,d1
		ble.l	.lbC0002C4
		bra.s	.lbC000226

.lbC000234:	move.w	(a0),d2
		moveq	#0,d0
.lbC000238:	cmpi.w	#$FF,(a1)
		bhi.s	.lbC000244
		addq.w	#1,d0
		adda.w	d2,a1
		bra.s	.lbC000238

.lbC000244:	subq.w	#2,d0
		move.w	d0,Load_MaxSubSongs2
		move.w	d0,Load_MaxSubSongs
		move.l	Load_ModuleStart(pc),a0
		move.w	#$1000,d1
.lbC00025A:	cmpi.w	#$48E7,(a0)+
		beq.s	.lbC000266
.lbC000260:	subq.w	#2,d1
		ble.s	.lbC0002C4
		bra.s	.lbC00025A

.lbC000266:	cmpi.w	#$50C1,-4(a0)
		bne.s	.lbC000260
		cmpi.w	#$4880,2(a0)
		bne.s	.lbC000260
		subq.l	#2,a0
		move.l	a0,Load_InitSound1
		moveq	#$7F,d1
.lbC000280:	cmpi.w	#$C0FC,(a0)+
		beq.s	.lbC00028C
		subq.w	#2,d1
		ble.s	.lbC0002C4
		bra.s	.lbC000280

.lbC00028C:	move.w	(a0),d2
		move.l	Load_InitSound1(pc),a0
		move.w	#$80,d1
.lbC000296:	cmpi.w	#$41FA,(a0)+
		beq.s	.lbC0002A2
		subq.w	#2,d1
		ble.s	.lbC0002C4
		bra.s	.lbC000296

.lbC0002A2:	adda.w	(a0),a0
		moveq	#0,d0
.lbC0002A6:	tst.l	2(a0)
		beq.s	.lbC0002B2
		addq.w	#1,d0
		adda.w	d2,a0
		bra.s	.lbC0002A6

.lbC0002B2:
	*	add.w	d0,Load_MaxSubSongs
		*subq.w	#1,d0
		*move.w	d0,lbW000144

		move.l	Load_ModuleStart(pc),a0
		moveq	#-1,d1
		moveq	#0,d0
		rts
.Error:
.lbC0002C4:	moveq	#0,d1
		sub.l	a1,a1
		moveq	#-1,d0
		rts

*-----------------------------------------------------------------------------*
Load_ModuleStart:	dc.l	0	\
Load_InterruptJump:	dc.l	0	 \
Load_EndSoundJump:	dc.l	0	  \
Load_InitSound2:	dc.l	0	   > zusammenlassen !!!
Load_InitSound1:	dc.l	0	  /
Load_MaxSubSongs2:	dc.w	0	 /
Load_MaxSubSongs:	dc.w	0	/ 

*-----------------------------------------------------------------------------*

	if	test
data:		incdir	"Modules:Whittaker/"
	*	ds.b	200

		incbin	"JCB.101"
		*incbin	"JCB.1943"
		*incbin	"JCB.Afterburner_II"
		*incbin	"JCB.Freestyle"
		*incbin	"JCB.IkariWarriors"
		*incbin	"JCB.Outrun"
		*incbin	"JCB.SpaceHarrier"
		*incbin	"JCB.ThunderStrike"


datasize	= *-data
	endc


*$2f08
