; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί OBLOGIC4.68K : OBJECT LOGIC CONTROL ROUTINES ...			   Ί
; ΜΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΉ
; Ί This file contains the CONTROL LOGIC routines for			   Ί
; Ί the following Objects ;						   Ί
; Ί 									   Ί
; Ί 									   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PLASMA HAMMER ROBOT CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ
		
		StRESET
		StDEF	PlasmaPatrolSTATE
		StDEF	PlasmaPatrolTurnSTATE
		StDEF	PlasmaPatrolIdleSTATE
		StDEF	PlasmaPatrolIdleOutSTATE
		StDEF	PlasmaPatrolStopSTATE
		StDEF	PlasmaGroundZeroSTATE
		StDEF	PlasmaWalkToSTATE
		StDEF	PlasmaTurnToSTATE
		StDEF	PlasmaTurnSTATE
		StDEF	PlasmaStopSTATE
		StDEF	PlasmaIdleSTATE
		StDEF	PlasmaIdleOutSTATE
		StDEF	PlasmaThrowBallSTATE
		StDEF	PlasmaBigStrikeSTATE
		StDEF	PlasmaQuickStrikeSTATE
		StDEF	PlasmaEdgeFallSTATE
		StDEF	PlasmaBackoffSTATE
		StDEF	PlasmaHitSTATE
		StDEF	PlasmaDeadSTATE
			

PlasmaBot_Logic		tst.b	TunnelFLG
			beq.s	.y
			cmp.b	#3,TunnelFLG
			bgt.s	.y
			rts

.y			btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			jsr	SetStartHeight
;			subq.w	#8,OB_Ypos(a0)				;pos on ground
			bsr	PlasmaSetPatrol				;initial state
			move.l	#PlasmaSetHits,OB_HitRoutine(a0)

.1			jsr	HandleBeingHit				;Generic handle hit rout
			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled

.ob			bsr	GetUnderFEET
			cmp.b	#SB_Grinder,d2
			beq	SpiBotSetAirExplode
			
			move.w	OB_State(a0),d1
			jmp	PlasmaBotLogicTable(pc,d1.w)		;jump table

PlasmaBotLogicTable	bra	PlasmaPatrolLOGIC
			bra	PlasmaPatrolTurnLOGIC
			bra	PlasmaPatrolIdleLOGIC
			bra	PlasmaPatrolIdleOutLOGIC
			bra	PlasmaPatrolStopLOGIC
			bra	PlasmaGroundZeroLOGIC
			bra	PlasmaWalkToLOGIC
			bra	PlasmaTurnToLOGIC
			bra	PlasmaTurnLOGIC
			bra	PlasmaStopLOGIC
			bra	PlasmaIdleLOGIC
			bra	PlasmaIdleOutLOGIC
			bra	PlasmaThrowBallLOGIC
			bra	PlasmaBigStrikeLOGIC
			bra	PlasmaQuickStrikeLOGIC
			bra	PlasmaEdgeFallLOGIC
			bra	PlasmaBackoffLOGIC
			bra	PlasmaHitLOGIC
			bra	PlasmaDeadLOGIC


; - Before Plasma sees player ----------------------------------------------
; - Plasma control logic ---------------------------------------------------

PlasmaSetPatrol		move.w	#PlasmaPatrolSTATE,OB_State(a0)
			jsr	ClrHitStuff
			clr.b	OB_MasterMode(a0)
			clr.b	OB_EventVar1(a0)
			lea	PlasmaWalkANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaPatrolLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.22
			clr.b	OB_EventVar1(a0)
			SFX	25	

.22			move.l	#-1,AI_Exclude
			lea	PLASMA_AI,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)

.1			jsr	Randy
			and.w	#$1ff,d6
			beq	PlasmaSetPatrolIdle
			cmp.w	#1,d6
			beq	PlasmaSetPatrolTurn
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderLEFTLEFTFEET			;turn at edge
			jsr	PullContourUnder
			beq	PlasmaSetPatrolTurn
			jsr	GetUnderLEFTLEFT
			bra	.lr
.rte			jsr	GetUnderRIGHTRIGHTFEET			;turn at edge	
			jsr	PullContourUnder
			beq	PlasmaSetPatrolTurn
			jsr	GetUnderRIGHTRIGHT		
.lr			jsr	TestLevelWalls			;turn at wall
			bmi	PlasmaSetPatrolTurn
			moveq	#1,d1
			jsr	MoveGolLeftRightFLP
			jsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	PlasmaSetPatrolTurn
			jmp	HandleContours			;handle the contours


; - Plasma control logic ---------------------------------------------------

PlasmaSetPatrolTurn	bra	PlasmaSetStopTurnP
PlasmaSPT1		move.w	#PlasmaPatrolTurnSTATE,OB_State(a0)
			lea	PlasmaTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaPatrolTurnLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	PlasmaSetPatrol
.1			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetPatrolIdle	bra	PlasmaSetStopIdleP
PlasmaSPI1		move.w	#PlasmaPatrolIdleSTATE,OB_State(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$30,d6
			move.b	d6,OB_Var1(a0)
			clr.b	OB_MasterMode(a0)
			jsr	ClrHitStuff
			lea	PlasmaIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaPatrolIdleLOGIC	subq.b	#1,OB_Var1(a0)
			beq	PlasmaSetPatrolIdleOut
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetPatrolIdleOut	move.w	#PlasmaPatrolIdleOutSTATE,OB_State(a0)
			lea	PlasmaIdleOutANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaPatrolIdleOutLOGIC
			tst.l	OB_AnSequence(a0)
			beq	PlasmaSetPatrol
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetStopIdleP	PUSHADDRS PlasmaSPI1
			bra	PlasmaSetPatrolStop
PlasmaSetStopTurnP	PUSHADDRS PlasmaSPT1
			
PlasmaSetPatrolStop	move.w	#PlasmaPatrolStopSTATE,OB_State(a0)
			lea	PlasmaStopANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaPatrolStopLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			POPADDRS
			jmp	(a1)
.1			rts


; - After Plasma sees player -----------------------------------------------
; - Plasma control logic ---------------------------------------------------

PlasmaSetGroundZero	cmp.w	#Level51,levnum
			bne.s	.2
.1			cmp.w	#$80,OB_Ypos(a0)
			bgt.s	.a
			cmp.w	#$c0,Plr_YPos
			bgt	PlasmaSetPatrol
			bra	.2
.a			cmp.w	#$80,Plr_YPos
			blt	PlasmaSetPatrol
.2			move.w	#PlasmaGroundZeroSTATE,OB_State(a0)
			rts
			jsr	DoesNmeFacePlayer
			bpl	PBSTT2
PBSGZ1			rts

PlasmaGroundZeroLOGIC	move.l	#-1,AI_Exclude
			lea	PLASMA_AI2,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)

.1			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetWalkTo		move.w	#PlasmaWalkToSTATE,OB_State(a0)
			jsr	DoesNmeFacePlayer
			bpl	PBSTT1
PBSWT1			clr.b	OB_EventVar1(a0)
			lea	PlasmaWalkToANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaWalkToLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.22
			clr.b	OB_EventVar1(a0)
			SFX	25	

.22			move.l	#PlasmaSetWalkTo,AI_Exclude
			lea	PLASMA_AI2,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)

.1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte

.lft			jsr	GetUnderLEFTLEFTFEET			;idle at edge
			jsr	PullContourUnder
			beq	PlasmaSetIdle
			jsr	GetXYpos
			sub.w	#$30,d1
			bra	.lr
.rte			jsr	GetUnderRIGHTRIGHTFEET			;idle at edge	
			jsr	PullContourUnder
			beq	PlasmaSetIdle
			jsr	GetXYpos
			add.w	#$30,d1
.lr			sub.w	#$20,d2
			jsr	GetUnderAddrs
			jsr	GetSpecial
			jsr	TestLevelWalls			;idle at wall
			bmi	PlasmaSetBackoff
			moveq	#2,d1
			jsr	MoveGolLeftRightFLP
			jsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	PlasmaSetTurn
			jmp	HandleContours			;handle the contours


; - Plasma control logic ---------------------------------------------------

PlasmaSetTurn		move.w	#PlasmaTurnSTATE,OB_State(a0)
			lea	PlasmaTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaTurnLOGIC		tst.l	OB_AnSequence(a0)
			beq	PlasmaSetGroundZero
			rts


; - Plasma control logic ---------------------------------------------------

PBSTT1			PUSHADDRS PBSWT1
			bra	PlasmaSetTurnTo
PBSTT2			PUSHADDRS PBSGZ1
			bra	PlasmaSetTurnTo
PBSTT3			PUSHADDRS PBSTB1
			bra	PlasmaSetTurnTo
PBSTT4			PUSHADDRS PBSBS1
			bra	PlasmaSetTurnTo
PBSTT5			PUSHADDRS PBSQS1

PlasmaSetTurnTo		PUSHSTATE
			move.w	#PlasmaTurnToSTATE,OB_State(a0)
			lea	PlasmaTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaTurnToLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetStop		move.w	#PlasmaPatrolStopSTATE,OB_State(a0)
			lea	PlasmaStopANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaStopLOGIC		tst.l	OB_AnSequence(a0)
			bne.s	.1
			POPADDRS
			jmp	(a1)
.1			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetIdle		move.w	#PlasmaIdleSTATE,OB_State(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$30,d6
			move.b	d6,OB_Var1(a0)
			clr.b	OB_MasterMode(a0)
			jsr	ClrHitStuff
			lea	PlasmaIdleANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaIdleLOGIC		subq.b	#1,OB_Var1(a0)
			beq	PlasmaSetIdleOut
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetIdleOut	move.w	#PlasmaIdleOutSTATE,OB_State(a0)
			lea	PlasmaIdleOutANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaIdleOutLOGIC	tst.l	OB_AnSequence(a0)
			beq	PlasmaSetGroundZero
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetThrowBall	tst.b	PlasmaBallFLG
			bne	PlasmaSetGroundZero

			move.w	#PlasmaThrowBallSTATE,OB_State(a0)
			jsr	DoesNmeFacePlayer
			bpl	PBSTT3
PBSTB1			clr.b	OB_EventVar1(a0)
			lea	PlasmaThrowBallANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


PlasmaThrowBallLOGIC	tst.l	OB_AnSequence(a0)
			beq	PlasmaSetGroundZero
			tst.b	OB_EventVar1(a0)
			bne	SetupPlasmaBall
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetBigStrike	move.w	#PlasmaBigStrikeSTATE,OB_State(a0)
			jsr	DoesNmeFacePlayer
			bpl	PBSTT4
PBSBS1			clr.w	OB_Var1(a0)
			move.b	#5,OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			move.b	#PlasmaLungeHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			SFX	22
			lea	PlasmaBigStrikeANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaBigStrikeLOGIC	tst.b	OB_Var2(a0)
			beq	PlasmaSetGroundZero
			
			tst.b	OB_EventVar1(a0)
			bne.s	.o1
.x			rts
			
.o1			addq.b	#1,OB_Var1(a0)
			and.b	#7,OB_Var1(a0)
			bne.s	.1
			subq.b	#1,OB_Var2(a0)

.1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rte
.lft			jsr	GetUnderFEET			;turn at edge
			jsr	PullContourUnder
			beq	PlasmaSetEdgeFall
			jsr	GetXYpos
			sub.w	#$30,d1
			bra	.lr
.rte			jsr	GetUnderFEET			;turn at edge	
			jsr	PullContourUnder
			beq	PlasmaSetEdgeFall
			jsr	GetXYpos
			add.w	#$30,d1
.lr			sub.w	#$20,d2
			jsr	GetUnderAddrs
			jsr	GetSpecial
			jsr	TestLevelWalls			;turn at wall
			bmi	PlasmaSetBackoff
			jsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	PlasmaSetBackoff
			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			jsr	MoveGolLeftRightFLP
			jmp	HandleContours			;handle the contours


; - Plasma control logic ---------------------------------------------------

PlasmaSetQuickStrike	move.w	#PlasmaQuickStrikeSTATE,OB_State(a0)
			jsr	DoesNmeFacePlayer
			bpl	PBSTT5
PBSQS1			move.b	#PlasmaHammerHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			SFX	88
			clr.b	OB_EventVar1(a0)
			lea	PlasmaQuickStrikeANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaQuickStrikeLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			SFX	57
			
.1			tst.l	OB_AnSequence(a0)
			beq	PlasmaSetGroundZero
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetEdgeFall	move.w	#PlasmaEdgeFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.b	#$10,OB_Var2(a0)

PlasmaEdgeFallLOGIC	addq.b	#1,OB_Var1(a0)
			and.b	#1,OB_Var1(a0)
			bne.s	.1
			cmp.b	#8,OB_Var1a(a0)
			beq.s	.1
			addq.b	#1,OB_Var1a(a0)
		
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			subq.w	#1,OB_Xpos(a0)
			bra	.o1
.r			addq.w	#1,OB_Xpos(a0)

.o1			tst.b	OB_Var2(a0)
			beq.s	.y1
			subq.b	#1,OB_Var2(a0)
			rts			
.y1			jsr	TestLand
			bmi	PlasmaSetGroundZero
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetBackoff	move.w	#PlasmaBackoffSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			lea	PlasmaBackoffANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

PlasmaBackoffLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.22
			clr.b	OB_EventVar1(a0)
			SFX	25	

.22			tst.l	OB_AnSequence(a0)
			beq	PlasmaSetGroundZero
			
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.rte
.lft			jsr	GetUnderLEFTLEFTFEET		;turn at edge
			jsr	PullContourUnder
			beq	PlasmaSetGroundZero
			jsr	GetUnderLEFTLEFT
			bra	.lr
.rte			jsr	GetUnderRIGHTRIGHTFEET		;turn at edge	
			jsr	PullContourUnder
			beq	PlasmaSetGroundZero
			jsr	GetUnderRIGHTRIGHT		
.lr			jsr	TestLevelWalls			;turn at wall
			bmi	PlasmaSetGroundZero
			moveq	#2,d1
			jsr	MoveGolLeftRightXFLP2
			jsr	CheckScreenBoundsX		;turn at screen bounds	
			bmi	PlasmaSetGroundZero
			jmp	HandleContours			;handle the contours


; - Plasma control logic ---------------------------------------------------

PlasmaSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff
			
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	PlasmaSetDead
			
			jsr	RobotRandomHitSFX
			
			move.w	#PlasmaHitSTATE,OB_State(a0)
			jsr	MakeNmeFacePlayer
			lea	PlasmaHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


PlasmaHitLOGIC		tst.l	OB_AnSequence(a0)
			beq	PlasmaSetQuickStrike	;GroundZero
			rts


; - Plasma control logic ---------------------------------------------------

PlasmaSetDead		move.w	#PlasmaDeadSTATE,OB_State(a0)
			bsr	SetupPlasmaDeadHead
			move.w	#3*60,OB_Var1(a0)
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			jsr	SetBigAirExplode
			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
.1			lea	PlasmaDeathLegsANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


PlasmaDeadLOGIC		tst.l	OB_AnSequence(a0)
			bne	.x
			subq.w	#1,OB_Var1(a0)
			beq	.ok
			move.w	OB_Var1(a0),d1
			and.w	#$f,d1
			beq.s	.y1
.x			rts

.y1			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			sub.w	#$10,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			add.w	#$10,d1
			bra	.lr
.r			sub.w	#$10,d1
.lr			move.w	d1,TempX
			move.w	d2,TempY
			SFX	83
			jmp	SetupRandomStuff
			
.ok			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			addq.w	#8,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.ra
.la			add.w	#$10,d1
			bra	.lra
.ra			sub.w	#$10,d1

.lra			jsr	SetBigAirExplode
			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			jmp	HandleEnemyKilled


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PLASMA HAMMER ROBOTS DEAD HEAD CONTROL LOGIC			   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupPlasmaDeadHead	movem.l	a0/d0,-(sp)				;setup arrow
			SPAWN_HI	PlasmaHead_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#PlasmaDeadHead_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	#$0600,OB_Yspd(a1)
			clr.w	OB_Xacc(a1)
			move.w	#$40,OB_Yacc(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.1a
			move.b	#%00111110,OB_MoveFlags(a1)
			rts
.1a			move.b	#%00111111,OB_MoveFlags(a1)
			rts
.no			movem.l	(sp)+,a0/d0
			rts

PlasmaDeadHead_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			sub.w	#$10,OB_Ypos(a0)
			lea	PlasmaDeathHeadANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			jsr	MoveGolUpDown
			moveq	#3,d1
			jsr	MGLRa
			btst.b	#ob_movydir,OB_MoveFlags(a0)
			beq.s	.x
			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
.x			bsr	GetUnderFEET
			tst.b	d2
			bmi.s	.fin
			jsr	PullContourUnder
			bne.s	.fin
			rts		
.fin			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			jsr	SetBigAirExplode
			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			jmp	SwitchObjectOff
			



; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PLASMA HAMMER ROBOTS BALLS CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetupPlasmaBall	  	clr.b	OB_EventVar1(a0)
			st.b	PlasmaBallFLG

			movem.l	a0/d0,-(sp)				;setup arrow
			SPAWN_LO	PlasmaBall_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#PlasmaBall_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			sub.w	#$28,OB_Xpos(a1)
			rts
.r			add.w	#$28,OB_Xpos(a1)
.1			rts
.no			movem.l	(sp)+,a0/d0
			rts

PlasmaBall_Logic    	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	101
			move.w	Plr_XPos,TargetX
			move.w	Plr_YPos,d1
			sub.w	#$18,d1
			move.w	d1,TargetY
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			clr.w	OB_Var6(a0)
			move.b	#PlasmaBallHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			lea	PlasmaBallHeadANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			addq.b	#1,OB_Var6(a0)
			and.b	#3,OB_Var6(a0)
			bne.s	.1a
   			bsr	SetupPlasmaBallTail

.1a			moveq	#5,d1
			jsr	TrajectoryMove
			
			jsr	GetXYpos
			sub.w	#$10,d2
			jsr	GetUnderAddrs
			jsr	GetSpecial
			jsr	TestLevelWalls			;turn at wall
			bmi.s	.exp
			
			tst.b	OB_Var5(a0)
			beq.s	.1
			tst.b	OB_Var5a(a0)
			beq.s	.1
.exp			clr.b	PlasmaBallFLG				;flag ball finished
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			sub.w	#$10,d1
			add.w	#$18,d2
			jsr	SetBigAirExplode
			jmp	SwitchObjectOff
.1			jmp	TrajectoryHit

			
SetupPlasmaBallTail	movem.l	a0/d0,-(sp)				;setup arrow
			SPAWN_LOLO	PlasmaBallTail_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,a0/d0
			move.w	#PlasmaBallTail_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			lea	PlasmaBallTailANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.no			movem.l	(sp)+,a0/d0
			rts

PlasmaBallTail_Logic	tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.x			rts




; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί RABID HELL HOUND CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnEyeHellHound	move.l	a0,-(sp)
			SPAWN_HI	RabidHH_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#RabidHH_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			bclr.b	#ob_noclip,OB_Flag1(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	#RabidHH_NRG,OB_Nrg(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			bra	FlagYESd
.1			move.l	(sp)+,a0
			bra	FlagNOd


		StRESET
		StDEF	RabidHHSetEye1STATE
		StDEF	RabidHHEye1STATE
		StDEF	RabidHHTransformSTATE
		StDEF	RabidHHGroundZeroSTATE
		StDEF	RabidHHLeapToSTATE
		StDEF	RabidHHLandSTATE
		StDEF	RabidHHTurnToSTATE
		StDEF	RabidHHTurnSTATE
		StDEF	RabidHHQuickStrikeSTATE
		StDEF	RabidHHBigStrikeSTATE
		StDEF	RabidHHHitSTATE
		StDEF	RabidHHDeadSTATE

RabidHH_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			jsr	SetStartHeight
			add.w	#$10,OB_Ypos(a0)
			clr.b	RabidDeadFLG
			move.l	#RabidHHSetHits,OB_HitRoutine(a0)
			lea	RabidZeroANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.1			jsr	HandleBeingHit				;Generic handle hit rout
			jsr	ObjectOffBottom
			bgt.s	.ob
			jmp	HandleEnemyKilled

.ob			move.w	OB_State(a0),d1
			jmp	RabidLogicTable(pc,d1.w)		;jump table

RabidLogicTable		bra	RabidHHSetEye1LOGIC
			bra	RabidHHEye1LOGIC
			bra	RabidHHTransformLOGIC

			bra	RabidHHGroundZeroLOGIC
			bra	RabidHHLeapToLOGIC
			bra	RabidHHLandLOGIC
			bra	RabidHHTurnToLOGIC
			bra	RabidHHTurnLOGIC
			bra	RabidHHQuickStrikeLOGIC
			bra	RabidHHBigStrikeLOGIC
			bra	RabidHHHitLOGIC
			bra	RabidHHDeadLOGIC



RabidHHSetEye1LOGIC	move.w	#RabidHHEye1STATE,OB_State(a0)
			lea	RapBotIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
	
RabidHHEye1LOGIC	tst.b	DemonaFLG2			;wait till eye flags that its hit the raptor
			bne	RabidHHSetTransform
			rts

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

RabidHHSetTransform	move.w	#RabidHHTransformSTATE,OB_State(a0)	;raptor transforsm into the hell hound
			SFX	8
			clr.b	OB_EventVar1(a0)
			lea	RabidTransformANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
	
RabidHHTransformLOGIC	tst.b	OB_EventVar1(a0)			;flash screen each new frame of anim
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			jsr	WhitePalette
			moveq	#1,d1	       				;fast fade to proper palette
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	
			
.1			tst.l	OB_AnSequence(a0)			;anim finished?
			bne.s	.x
			clr.b	DemonaFLG1				;eneble goliath
			move.w	#-1,TrackObjectNumber			;scroll track plr
			bra.s	RabidHHSetGroundZero			;yes: set hell hound proper
.x			rts


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

RabidHHSetGroundZero	move.w	#RabidHHGroundZeroSTATE,OB_State(a0)	;hell hound proper
			lea	RabidZeroANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHGroundZeroLOGIC	move.l	#-1,AI_Exclude
			lea	RABID_AI,a1
			jsr	AI_Routine
			bpl.s	.1
			jmp	(a1)

.1			jsr	Randy
			and.w	#$1f,d6
			bne.s	.2
			move.w	#RabidHHLeapToSTATE,OB_State(a0)
			bra	RHHSWT1			
.2			cmp.w	#8,d6
			beq	RabidHHSetTurn
			lea	RabidZeroANM,a1
			jmp	SetNewAnim


; - RabidHH control logic ---------------------------------------------------

RabidHHSetLeapTo	move.w	#RabidHHLeapToSTATE,OB_State(a0)
			jsr	DoesHHFacePlayer
			bpl	RHHSTT1
RHHSWT1			move.b	#(5*16)/3,OB_Var1(a0)
			move.w	#3,OB_Var2(a0)
			move.b	#RabidLungeHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			SFX	98
			SFX	120
			lea	RabidLeapANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHLeapToLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			bsr	GetUnderLEFTLEFT
			bra	.lr
.r			bsr	GetUnderRIGHTRIGHT
.lr			cmp.b	#SB_ForceTurn,d2
			beq.s	RabidHHSetLand
			subq.b	#1,OB_Var1(a0)
			beq.s	RabidHHSetLand
			moveq	#3,d1
			jmp	MoveGolLeftRightFLP
.x			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetLand		move.w	#RabidHHLandSTATE,OB_State(a0)
			KILL	98
			lea	RabidLandANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHLandLOGIC	tst.l	OB_AnSequence(a0)
			beq	RabidHHSetGroundZero
			rts


; - RabidHH control logic ---------------------------------------------------

RHHSTT1			PUSHADDRS RHHSWT1
			bra	RabidHHSetTurnTo
RHHSTT4			PUSHADDRS RHHSBS1
			bra	RabidHHSetTurnTo
RHHSTT5			PUSHADDRS RHHSQS1

RabidHHSetTurnTo	PUSHSTATE
			move.w	#RabidHHTurnToSTATE,OB_State(a0)
			move.b	#RabidTurnHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			SFX	120
			lea	RabidTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHTurnToLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.1
			eor.b	#_ob_xflp,OB_Flag1(a0)
			POPSTATE
			POPADDRS
			jmp	(a1)
.1			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetTurn		move.w	#RabidHHTurnSTATE,OB_State(a0)
			move.b	#RabidTurnHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			lea	RabidTurnANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHTurnLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			eor.b	#_ob_xflp,OB_Flag1(a0)
			bra	RabidHHSetGroundZero
.x			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetBigStrike	move.w	#RabidHHBigStrikeSTATE,OB_State(a0)
			jsr	DoesHHFacePlayer
			bpl	RHHSTT4
RHHSBS1			move.b	#(8*16)/5,OB_Var1(a0)
			lea	RabidLeapANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			SFX	98
			SFX	120
			move.b	#RabidLungeHitPOWER,OB_HitPower(a0)
			jmp	SetBigAttack

RabidHHBigStrikeLOGIC	btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			bsr	GetUnderLEFTLEFT
			bra	.o1
.r			bsr	GetUnderRIGHTRIGHT
.o1			cmp.b	#SB_ForceTurn,d2
			beq	RabidHHSetLand
			subq.b	#1,OB_Var1(a0)
			beq	RabidHHSetLand
			moveq	#5,d1
			jmp	MoveGolLeftRightFLP
.x			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetQuickStrike	move.w	#RabidHHQuickStrikeSTATE,OB_State(a0)
			jsr	DoesHHFacePlayer
			bpl	RHHSTT5
RHHSQS1			move.b	#RabidSnapHitPOWER,OB_HitPower(a0)
			jsr	SetMediumAttack
			SFX	120
			lea	RabidQuickAttackANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

RabidHHQuickStrikeLOGIC	tst.l	OB_AnSequence(a0)
			beq	RabidHHSetGroundZero
			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff

			btst.b	#ob_dead,OB_Flag2(a0)
			bne	RabidHHSetDead
			
			jsr	RobotRandomHitSFX
			
			move.w	#RabidHHHitSTATE,OB_State(a0)
			lea	RabidHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


RabidHHHitLOGIC		tst.l	OB_AnSequence(a0)
			beq	RabidHHSetGroundZero
			rts


; - RabidHH control logic ---------------------------------------------------

RabidHHSetDead		move.w	#RabidHHDeadSTATE,OB_State(a0)
			lea	RabidDeadANM,a1				;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			st.b	RabidDeadFLG
			sub.w	#RabidHH_NRG,BossEnergy
			SFX	57
			SFX	95
			
			addq.b	#1,RabbidHHDeadCNT

			tst.b	difficulty
			beq.s	.easy
     			cmp.b	#1,difficulty
			beq.s	.normal

.hard			cmp.b	#3,RabbidHHDeadCNT
			bne.s	.h
			bra	.easy
.normal			cmp.b	#2,RabbidHHDeadCNT
			beq.s	.h
.easy			jsr	DropFULLHEALTH
			bpl.s	.h
			bset.b	#ob_nooff,OB_Flag2(a1)

.h			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			sub.w	#$10,TempY
			moveq	#2,d7
			moveq	#7,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jmp	SetRandomDebris
			
RabidHHDeadLOGIC	tst.l	OB_AnSequence(a0)
			bne	.x
			jmp	SwitchObjectOff
.x			rts


DoesHHFacePlayer	move.w	OB_Xpos(a0),d1
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.rr
.ll			sub.w	#$20,d1
			bra	.o1
.rr			add.w	#$20,d1
.o1			cmp.w	Plr_XPos,d1
			blt.s	.r
.l			btst.b	#ob_xflp,OB_Flag1(a0)
			bne	FlagYESnn
			bra	FlagNOnn
.r			btst.b	#ob_xflp,OB_Flag1(a0)
			beq	FlagYESnn
FlagNOnn		tas	no
			rts
FlagYESnn		tas	yes
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CONTROL LOGIC							   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

VertFlame_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$d,OB_Xpos(a0)
			sub.w	#$10,OB_Ypos(a0)
			move.b	#FlameThrowHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	VertFlameFlareANM,a1
			jmp	SetNewAnim

.ok			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί WALL FLAME CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnWallFlame		movem.l	a0/d0,-(sp)
			SPAWN_HI	WallFlame_MAX_Size
			bmi.s	.yes
			movem.l	(sp)+,d0/a0
			rts
.yes			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			st.b	WallFlameActiveFLG
			move.w	#WallFlame_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_setup,OB_Flag2(a1)
			st.b	OB_Var1(a1)			;flag this as spawned
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			and.w	#$fff0,d1
			and.w	#$fff0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,d1
			bclr.b	#ob_xflp,OB_Flag1(a1)
			bra	.s
.r			add.w	#$20,d1
			bset.b	#ob_xflp,OB_Flag1(a1)
.s			and.w	#$ffe0,d2
			move.w	d1,OB_Xpos(a1)
			move.w	d2,OB_Ypos(a1)
			move.b	#ForgeWallFlameHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			SFX	26
			lea	WallFlameFlareANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1


WallFlame_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.o1
			add.w	#$10,OB_Xpos(a0)
.o1			sub.w	#8,OB_Ypos(a0)
			move.b	#ForgeWallFlameHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	WallFlameZeroANM,a1
			jmp	SetNewAnim

.ok			tst.b	OB_Var1(a0)
			beq.s	.rand

.spawn			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	WallFlameActiveFLG
			jmp	SwitchObjectOff

.x			rts

.rand			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	Randy
			and.b	#$3f,d6
			bne.s	.x
			SFX	26
			lea	WallFlameFlareANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί FLOOR FLAME CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnFloorFlame		movem.l	a0/d0,-(sp)
			SPAWN_HI	FloorFlame_MAX_Size
			bmi.s	.yes
			movem.l	(sp)+,d0/a0
			rts
.yes			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			st.b	WallFlameActiveFLG
			move.w	#FloorFlame_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_setup,OB_Flag2(a1)
			st.b	OB_Var1(a1)			;flag this as spawned
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			and.w	#$fff0,d1
			and.w	#$fff0,d2
			btst.b	#grndmode,OB_MasterMode(a0)
			beq.s	.u
.d			bset.b	#ob_yflp,OB_Flag1(a1)
			add.w	#$22,d2
			bra	.s
.u			bclr.b	#ob_yflp,OB_Flag1(a1)
			sub.w	#$32,d2
.s			and.w	#$ffe0,d1
			move.w	d1,OB_Xpos(a1)
			move.w	d2,OB_Ypos(a1)
			move.b	#ForgeFloorFlameHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			SFX	26
			lea	FloorFlameFlareANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1


FloorFlame_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.d
.u			sub.w	#6,OB_Ypos(a0)
			bra	.1
.d			sub.w	#$1a,OB_Ypos(a0)
.1			move.b	#ForgeFloorFlameHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	FloorFlameZeroANM,a1
			jmp	SetNewAnim

.ok			tst.b	OB_Var1(a0)
			beq.s	.rand

.spawn			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	WallFlameActiveFLG
			jmp	SwitchObjectOff

.x			rts

.rand			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	Randy
			and.b	#$3f,d6
			bne.s	.x
			SFX	26
			lea	FloorFlameFlareANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ORB/PLATFORM PLATFORM CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnOPPlatform		move.l	a0,-(sp)
			SPAWN_HI	OPPlatform_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#OPPlatform_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			rts
.no			move.l	(sp)+,a0
			rts			
		
SpeedMin		equ	0
SpeedZero		equ	4
SpeedMax		equ	8

SpeedTable		dc.w	-4,-3,-2,-1,0,1,2,3,4
			even
			
OPPlatform_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			move.w	#$0404,OB_Var4(a0)
			lea	OrbPlatformANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			sub.w	#$20,d1
			sub.w	#$40,d2
			bsr	GetUnderAddrs
			
			move.l	LevelFlr,a1		
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderLEFTLEFTHEAD	;Special from 3rd layer
			addq.w	#8,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderRIGHTRIGHTHEAD	;Special from 3rd layer
			subq.w	#8,a5
			add.w	map_wide,a5	
			add.w	map_wide,a5	
			add.w	map_wide,a5	
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderLEFTLEFTBOT	;Special from 3rd layer
			addq.w	#8,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderRIGHTRIGHTBOT	;Special from 3rd layer
			subq.w	#6,a5
			add.w	map_wide,a5	
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderLEFTFEET	;Special from 3rd layer
			addq.w	#2,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderFEET		;Special from 3rd layer
			addq.w	#2,a5
			move.w	(a5),d1			
			lsr.w	#1,d1			
			move.b	2(a1,d1.w),NUnderRIGHTFEET	;Special from 3rd layer
			
			move.l	Plr_Database,a1
			btst.b	#wallmode,OB_MasterMode(a1)
			bne.s	.cont			
			cmp.w	#GolJumpSTATE,OB_State(a1)
			beq.s	.cont
			cmp.w	#GolJumpFlapSTATE,OB_State(a1)
			beq.s	.cont
			cmp.w	#GolFallSTATE,OB_State(a1)
			bne.s	.1
			cmp.b	#-6,GolJumpType
			beq.s	.cont
.1			jsr	PlayerFeet2EnemyBody
			bmi.s	.feet
			bclr.b	#ob_carry,OB_Flag3(a0)
			bra	.cont
.x			rts

.feet			st.b	PlrFallOnWeightFLG
			clr.b	PlrJumpOnWeightFLG
			bsr	.cont
			move.w	OB_Ypos(a0),d2
			sub.w	#$16,d2
			move.w	d2,OB_Ypos(a1)			;plrs y=top of weight
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			bset.b	#ob_carry,OB_Flag3(a0)
			move.l	a0,DetectedWeightOB
			rts
		
.cont			tst.b	IsGolOnWeightFLG
			beq.s	.x

			move.l	Plr_Database,a1
			lea	SpeedTable,a2
			move.l	OB_Task(a0),a3

			addq.b	#1,OB_Var5(a0)
			and.b	#3,OB_Var5(a0)
			bne	.update

			clr.w	OB_Var6(a0)			

.tl			btst.b	#left,joy1
			beq.s	.tr
			move.b	NUnderLEFTLEFTHEAD,d2
			or.b	NUnderLEFTLEFTBOT,d2
			bmi.s	.zx1
			move.w	OB_Xpos(a3),d7
			sub.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a0),d7
			blt.s	.ok1
.zx1			move.b	#SpeedZero,OB_Var4(a0)
			bra	.tyy
.ok1			st.b	OB_Var6(a0)
   			cmp.b	#SpeedMin,OB_Var4(a0)
			beq.s	.tyy
			subq.b	#1,OB_Var4(a0)
			bra	.tyy

.tr			btst.b	#right,joy1
			beq.s	.tyy
			move.b	NUnderRIGHTRIGHTHEAD,d2
			or.b	NUnderRIGHTRIGHTBOT,d2
			bmi.s	.zx2
			move.w	OB_Xpos(a3),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a0),d7
			bgt.s	.ok2
.zx2			move.b	#SpeedZero,OB_Var4(a0)
			bra	.tyy
.ok2			st.b	OB_Var6(a0)
   			cmp.b	#SpeedMax,OB_Var4(a0)
			beq.s	.tyy
			addq.b	#1,OB_Var4(a0)

.tyy			btst.b	#up,joy1
			beq.s	.td
			move.w	OB_Ypos(a3),d7
			sub.w	#PlatformMaxDist-$20,d7
			cmp.w	OB_Ypos(a0),d7
			blt.s	.ok3
.zy1			move.b	#SpeedZero,OB_Var4a(a0)
			bra	.n1
.ok3			st.b	OB_Var6a(a0)
   			cmp.b	#SpeedMin,OB_Var4a(a0)
			beq.s	.n1
			subq.b	#1,OB_Var4a(a0)
			bra	.n1

.td			btst.b	#down,joy1
			beq.s	.n1
			move.b	NUnderFEET,d2
			or.b	NUnderLEFTFEET,d2
			or.b	NUnderRIGHTFEET,d2
			bmi.s	.zy2
			move.w	OB_Ypos(a3),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Ypos(a0),d7
			bgt.s	.ok4
.zy2			move.b	#SpeedZero,OB_Var4a(a0)
			bra	.n1
.ok4			st.b	OB_Var6a(a0)
   			cmp.b	#SpeedMax,OB_Var4a(a0)
			beq.s	.n1
			addq.b	#1,OB_Var4a(a0)

.n1			tst.b	OB_Var6(a0)
			bne.s	.o1
			cmp.b	#SpeedZero,OB_Var4(a0)
			beq.s	.o1
			bgt.s	.decx
.incx			addq.b	#1,OB_Var4(a0)
			bra	.o1
.decx			subq.b	#1,OB_Var4(a0)

.o1			tst.b	OB_Var6a(a0)
			bne.s	.update
			cmp.b	#SpeedZero,OB_Var4a(a0)
			beq.s	.update
			bgt.s	.decy
.incy			addq.b	#1,OB_Var4a(a0)
			bra	.update
.decy			subq.b	#1,OB_Var4a(a0)
			
.update			moveq	#0,d1
			move.b	OB_Var4(a0),d1
			asl.b	#1,d1
			move.w	0(a2,d1.w),d1
			beq.s	.dyy
			bpl.s	.rte
			neg.w	d1
.lft			sub.w	d1,OB_Xpos(a0)
			bra	.dyy
.rte			add.w	d1,OB_Xpos(a0)
			
.dyy			moveq	#0,d2
			move.b	OB_Var4a(a0),d2
			asl.b	#1,d2
			move.w	0(a2,d2.w),d2
			beq.s	.xx
			bpl.s	.down
.up			neg.w	d2
			sub.w	d2,OB_Ypos(a0)
.xx			rts
.down			add.w	d2,OB_Ypos(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ORB/PLATFORM LINK CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnOPLink		movem.l	a0/d0,-(sp)
			SPAWN_LOLO	OPLink_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#OPLink_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			addq.w	#4,OB_Ypos(a1)
			move.l	OB_Task(a0),OB_Task(a1)
			rts
.no			movem.l	(sp)+,d0/a0
			rts			
		

OPLink_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			clr.w	OB_Var5(a0)
			lea	OrbPlatformLinkANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			bra	.1st

.ok			moveq	#8,d1
			jsr	TrajectoryMove
			
			jsr	TrajectoryHit2
			tst.b	OB_Var5(a0)
			beq.s	.1st
			tst.b	OB_Var5a(a0)
			beq.s	.1st
			jmp	SwitchObjectOff

.1st			move.l	OB_Task(a0),a1
			move.w	OB_Xpos(a1),TargetX		;set target x,y to platforms x,y
			move.w	OB_Ypos(a1),TargetY
			sub.w	#8,TargetY
			move.w	TargetX,OB_Var6(a0)
			move.w	TargetY,OB_Var7(a0)
			jmp	TrajectorySetup


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ORB/PLATFORM ORB CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

PlatformMaxDist		equ	$80

_ur			equ	0
_dr			equ	1
_ul			equ	2
_dl			equ	3


OPOrb_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			SFX 	13
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_hiprior,OB_Flag2(a0)
			move.b	#_dr,OPToggle1
			move.w	OB_Xpos(a0),OB_WXpos(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)
			add.w	#$10,OB_Xpos(a0)
			sub.w	#$c,OB_Ypos(a0)
			clr.b	OB_Var6(a0)
			bsr	SpawnOPPlatform
			lea	OrbPlatformOrbANM,a1
			jmp	SetNewAnim

.ok			jsr	AITestPlrIsAbove
			bmi.s	.y2
			move.w	#$100,d1
			jsr	TestProxY_Below
			bmi.s	.y2
			move.w	OB_WXpos(a0),OB_Xpos(a0)
			move.w	OB_WYpos(a0),OB_Ypos(a0)
			bclr.b	#ob_setup,OB_Flag2(a0)
			move.l	OB_Task(a0),a1
			bset.b	#ob_kill,OB_Flag2(a1)		;turn object off
			KILL	13
			rts

.y2			tst.b	OB_Var6(a0)
			bne.s	.y1
   			tst.b	IsGolOnWeightFLG
			beq.s	.x
			st.b	OB_Var6(a0)

.y1			addq.b	#1,OB_Var4(a0)
			cmp.b	#7,OB_Var4(a0)
			bne.s	.1a
			clr.b	OB_Var4(a0)
			bsr	SpawnOPLink

.1a			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			
			tst.b	OB_Var1a(a0)
			beq.s	.tur
			cmp.b	#_dr,OB_Var1a(a0)
			beq.s	.tdr
			cmp.b	#_dl,OB_Var1a(a0)
			beq.s	.tdl
			cmp.b	#_ul,OB_Var1a(a0)
			beq.s	.tul
.x			rts

.tur			sub.w	#2,d1
			add.w	#3,d2
			jsr	GetUnderAddrs
			jsr	GetSpecial
			bra	.dot
.tdr			sub.w	#$c,d1
			sub.w	#$c,d2
			jsr	GetUnderAddrs
			jsr	GetSpecial
			bra	.dot
.tdl			jsr	GetUnderAddrs
			jsr	GetSpecial
			bra	.dot
.tul			jsr	GetUnderAddrs
			jsr	GetSpecial

.dot			cmp.b	#SB_DownRight,d2
			beq.s	.dr
			cmp.b	#SB_UpRight,d2
			beq.s	.ur
			cmp.b	#SB_UpLeft,d2
			beq.s	.ul
			cmp.b	#SB_DownLeft,d2
			beq.s	.dl
			cmp.b	#SB_Tog1,d2
			beq.s	.tog1
			clr.b	OPToggledFLG
			bra	.do

.tog1			tst.b	OPToggledFLG
			bne.s	.do
			st.b	OPToggledFLG
			move.b	OPToggle1,OB_Var1a(a0)
			eor.b	#_ur^_dr,OPToggle1
			bra	.do				;toggle gate
.dr			move.b	#_dr,OB_Var1a(a0)
			bra	.do			
.ur			clr.b	OB_Var1a(a0)
			bra	.do			
.ul			move.b	#_ul,OB_Var1a(a0)
			bra	.do			
.dl			move.b	#_dl,OB_Var1a(a0)

.do			moveq	#0,d1				;x & y speed
			moveq	#0,d2
			move.b	OB_Var2(a0),d1
			move.b	OB_Var2a(a0),d2

			move.l	OB_Task(a0),a1			;platforms database

			tst.b	OB_Var1a(a0)
			beq.s	.upright
			cmp.b	#_dr,OB_Var1a(a0)
			beq.s	.downright
			cmp.b	#_dl,OB_Var1a(a0)
			beq.s	.downleft
			cmp.b	#_ul,OB_Var1a(a0)
			beq.s	.upleft
			rts

.upright		add.w	d1,OB_Xpos(a0)
			sub.w	d2,OB_Ypos(a0)
			move.w	OB_Xpos(a0),d7
			sub.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a1),d7
			blt.s	.ur1
			add.w	d1,OB_Xpos(a1)
.ur1			move.w	OB_Ypos(a0),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Ypos(a1),d7
			bgt.s	.urx
			sub.w	d2,OB_Ypos(a1)
.urx			rts

.downright		add.w	d1,OB_Xpos(a0)
			add.w	d2,OB_Ypos(a0)
			move.w	OB_Xpos(a0),d7
			sub.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a1),d7
			blt.s	.dr1
			add.w	d1,OB_Xpos(a1)
.dr1			move.w	OB_Ypos(a0),d7
			sub.w	#PlatformMaxDist-$20,d7
			cmp.w	OB_Ypos(a1),d7
			blt.s	.drx
			add.w	d2,OB_Ypos(a1)
.drx			rts

.downleft		sub.w	d1,OB_Xpos(a0)
			add.w	d2,OB_Ypos(a0)
			move.w	OB_Xpos(a0),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a1),d7
			bgt.s	.dl1
			sub.w	d1,OB_Xpos(a1)
.dl1			move.w	OB_Ypos(a0),d7
			sub.w	#PlatformMaxDist-$20,d7
			cmp.w	OB_Ypos(a1),d7
			blt.s	.dlx
			add.w	d2,OB_Ypos(a1)
.dlx			rts

.upleft			sub.w	d1,OB_Xpos(a0)
			sub.w	d2,OB_Ypos(a0)
			move.w	OB_Xpos(a0),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Xpos(a1),d7
			bgt.s	.ul1
			sub.w	d1,OB_Xpos(a1)
.ul1			move.w	OB_Ypos(a0),d7
			add.w	#PlatformMaxDist,d7
			cmp.w	OB_Ypos(a1),d7
			bgt.s	.ulx
			sub.w	d2,OB_Ypos(a1)
.ulx			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Furnace_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			addq.w	#8,OB_Xpos(a0)
			add.w	#$e,OB_Ypos(a0)
			clr.b	OB_EventVar1(a0)
			move.b	#FurnaceHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	FurnaceZeroANM,a1
			jmp	SetNewAnim

.ok			tst.b	OB_Var1(a0)
			bne.s	.prox

.rand			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jsr	Randy
			and.w	#$3f,d6
			bne.s	.x
			lea	FurnaceFlareANM,a1
			jmp	SetNewAnim

.prox			tst.l	OB_AnSequence(a0)
			beq.s	.1
.x			tst.b	OB_EventVar1(a0)
			beq.s	.ss
			clr.b	OB_EventVar1(a0)
   			SFX	97
.ss			rts
.1			move.w	#$a0,d1
			jsr	TestProxX
			bpl.s	.x
			move.w	#$a0,d1
			jsr	TestProxY
			bpl.s	.x
			lea	FurnaceFlareANM,a1
			jmp	SetNewAnim


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

MaxRobotCount		equ	2

RobotGenerator_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$20,OB_Xpos(a0)
			sub.w	#$c,OB_Ypos(a0)
			clr.b	OB_Var1a(a0)
			lea	RobotGenZeroANM,a1
			jmp	SetNewAnim

.ok			cmp.b	#1,OB_Var1a(a0)
			beq.s	.opening
			cmp.b	#2,OB_Var1a(a0)
			beq	.wait
			
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			cmp.b	#MaxRobotCount,GeneratedRobotCNT
			blt.s	.1
.x			rts
.1			jsr	Randy
			and.w	#$7f,d6
			bne.s	.x
			SFX	2
			move.b	#1,OB_Var1a(a0)
			lea	RobotGenOpenANM,a1
			jmp	SetNewAnim

.opening		tst.l	OB_AnSequence(a0)
			bne.s	.x
			move.b	#2,OB_Var1a(a0)
			move.b	#32,OB_Var3(a0)

			move.l	a0,-(sp)
			SPAWN_HI	WaspBot_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#WaspBot_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$10,OB_Ypos(a1)
			clr.w	OB_Var1(a1)
			clr.w	OB_Var2(a1)
			move.l	#GeneratedRobotOff,OB_OffRoutine(a1)
			addq.b	#1,GeneratedRobotCNT
.o1			rts
.no			move.l	(sp)+,a0
			rts			

.wait			subq.b	#1,OB_Var3(a0)
			bne.s	.o1
			SFX	3
			clr.b	OB_Var1a(a0)
			lea	RobotGenCloseANM,a1
			jmp	SetNewAnim
			

GeneratedRobotOff	tst.b	GeneratedRobotCNT
			beq.s	.x
			sub.b	#1,GeneratedRobotCNT
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ROCK GENERATOR CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

RockGenerator_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.b	OB_Var2(a0)

.ok			addq.b	#1,OB_Var2(a0)
			move.b	OB_Var2(a0),d1
			cmp.b	OB_Var1a(a0),d1
			bne	.x
			clr.b	OB_Var2(a0)
			
			movem.l	a0/d0,-(sp)
			
			tst.b	OB_Var1(a0)
			beq.s	.big
    			cmp.b	#1,OB_Var1(a0)
			beq.s	.medium
.small			SPAWN_HI	SmallRock_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#SmallRock_OB,OB_Type(a1)
			bra	.gen
.medium			SPAWN_HI	MediumRock_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#MediumRock_OB,OB_Type(a1)
			bra	.gen
.big			SPAWN_HI	BigRock_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			movem.l	(sp)+,d0/a0
			move.w	#BigRock_OB,OB_Type(a1)
			move.b	#ForgeBigRockHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			
.gen			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			clr.w	OB_Var1(a1)
			clr.w	OB_Var2(a1)
.x			rts
.no			movem.l	(sp)+,d0/a0
			rts			


RockBounceBit		jsr	MoveGolUpDown
			jsr	MoveGolLeftRight			

			btst.b	#ob_movydir,OB_MoveFlags(a0)
			bne.s	.b1
			bsr	GetXYpos
			bsr	GetUnderAddrs
			bsr	GetContour
			jsr	PullContourUnder
			beq.s	.x			
			sub.w	#$e0,OB_Yspd(a0)
			bmi.s	.finbounce
			addq.w	#8,OB_Ypos(a0)
			bset.b	#ob_movyacc,OB_MoveFlags(a0)
			bset.b	#ob_movydir,OB_MoveFlags(a0)
.x			rts
.b1			tst.w	OB_Yspd(a0)
			bne.s	.x
			bclr.b	#ob_movyacc,OB_MoveFlags(a0)
			bclr.b	#ob_movydir,OB_MoveFlags(a0)
			tst.b	PlayingBOSS
			beq.s	.x
			clr.b	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			rts
.finbounce		move.b	#2,OB_Var1(a0)
			and.w	#$fff0,OB_Ypos(a0)
			addq.w	#8,OB_Ypos(a0)
			rts


RockFallBit		addq.b	#1,OB_Var1a(a0)
			and.b	#3,OB_Var1a(a0)
			bne.s	.f1
			cmp.b	#6,OB_Var2(a0)
			beq.s	.f1
			addq.b	#1,OB_Var2(a0)
.f1			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			add.w	d1,OB_Ypos(a0)
			tst.b	OB_Var7(a0)
			beq.s	.ok
			jmp	MoveGolLeftRight			
.ok			jmp	TestLand


; - Big Rock Control Logic -------------------------------------------------

BigRock_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$10,OB_Xpos(a0)
			clr.b	OB_Var7(a0)
			lea	BigRockANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq	.fall
			cmp.b	#1,OB_Var1(a0)
			beq	.bounce
			cmp.b	#2,OB_Var1(a0)
			beq.s	.rest

.grind			tst.b	OB_Var3a(a0)
			beq.s	.g1
			subq.b	#1,OB_Var3a(a0)
			tst.b	OB_Var3(a0)	
			bne	.lft
			bra	.rte
.g1			subq.b	#1,OB_Var4(a0)
			bne.s	.g2
   			jmp	SwitchObjectOff
.g2			add.w	#$2,OB_Ypos(a0)
			rts
			
.rest			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			bsr	GetUnderAddrs
			bsr	GetSpecial
			cmp.b	#SB_Grinder,d2
			bne.s	.r1
			move.b	#6,OB_Var4(a0)	
			move.b	#$18,OB_Var3a(a0)
			move.b	#3,OB_Var1(a0)
			rts
.r1			cmp.b	#SB_ConveyLeft,d2
			beq.s	.lft
			cmp.b	#SB_ConveyRight,d2
			beq.s	.rte
			clr.b	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			st.b	OB_Var7(a0)
			rts

.lft			subq.w	#1,OB_Xpos(a0)
			st.b	OB_Var3(a0)
			rts
.rte			addq.w	#1,OB_Xpos(a0)
			clr.b	OB_Var3(a0)
			rts

.bounce			bra	RockBounceBit

.fall			bsr	RockFallBit
			bpl.s	.x
			move.b	#1,OB_Var1(a0)
			move.w	#$200,OB_Xspd(a0)
			move.w	#$600,OB_Yspd(a0)
			move.w	#$a0,OB_Yacc(a0)
			clr.w	OB_Xacc(a0)
			btst.b	#0,second
			beq.s	.fl
.fr			move.b	#%00111111,OB_MoveFlags(a0)
			rts
.fl			move.b	#%00111110,OB_MoveFlags(a0)
.x			rts


; - Medium Rock Control Logic ----------------------------------------------

MediumRock_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			addq.w	#8,OB_Xpos(a0)
			lea	MediumRockANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq	.fall
			cmp.b	#1,OB_Var1(a0)
			beq	.bounce
			cmp.b	#2,OB_Var1(a0)
			beq.s	.rest

.grind			tst.b	OB_Var3a(a0)
			beq.s	.g1
			subq.b	#1,OB_Var3a(a0)
			tst.b	OB_Var3(a0)	
			bne	.lft
			bra	.rte
.g1			subq.b	#1,OB_Var4(a0)
			bne.s	.g2
   			jmp	SwitchObjectOff
.g2			add.w	#$2,OB_Ypos(a0)
			rts
			
.rest			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			bsr	GetUnderAddrs
			bsr	GetSpecial
			cmp.b	#SB_Grinder,d2
			bne.s	.r1
			move.b	#6,OB_Var4(a0)	
			move.b	#$18,OB_Var3a(a0)
			move.b	#3,OB_Var1(a0)
			rts
.r1			cmp.b	#SB_ConveyLeft,d2
			beq.s	.lft
			cmp.b	#SB_ConveyRight,d2
			beq.s	.rte
			clr.b	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			st.b	OB_Var7(a0)
			rts

.lft			subq.w	#1,OB_Xpos(a0)
			st.b	OB_Var3(a0)
			rts
.rte			addq.w	#1,OB_Xpos(a0)
			clr.b	OB_Var3(a0)
			rts

.bounce			bra	RockBounceBit

.fall			bsr	RockFallBit
			bpl.s	.x
			move.b	#1,OB_Var1(a0)
			move.w	#$200,OB_Xspd(a0)
			move.w	#$600,OB_Yspd(a0)
			move.w	#$80,OB_Yacc(a0)
			move.w	#4,OB_Xacc(a0)
			btst.b	#0,second
			beq.s	.fl
.fr			move.b	#%00111111,OB_MoveFlags(a0)
			rts
.fl			move.b	#%00111110,OB_MoveFlags(a0)
.x			rts


; - Small Rock Control Logic ----------------------------------------------

SmallRock_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			addq.w	#8,OB_Xpos(a0)
			lea	SmallRockANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq	.fall
			cmp.b	#1,OB_Var1(a0)
			beq.s	.bounce
			cmp.b	#2,OB_Var1(a0)
			beq.s	.rest

.grind			subq.b	#1,OB_Var4(a0)
			bne.s	.g1
   			jmp	SwitchObjectOff
.g1			add.w	#$2,OB_Ypos(a0)
			rts
			
.rest			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			bsr	GetUnderAddrs
			bsr	GetSpecial
			cmp.b	#SB_Grinder,d2
			bne.s	.r1
			move.b	#6,OB_Var4(a0)	
			move.b	#3,OB_Var1(a0)
			rts
.r1			cmp.b	#SB_ConveyLeft,d2
			beq.s	.lft
			cmp.b	#SB_ConveyRight,d2
			beq.s	.rte
			clr.b	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			st.b	OB_Var7(a0)
			rts

.lft			subq.w	#1,OB_Xpos(a0)
			rts
.rte			addq.w	#1,OB_Xpos(a0)
			rts

.bounce			bra	RockBounceBit

.fall			bsr	RockFallBit
			bpl.s	.x
			tst.b	PlayingBOSS
			beq.s	.f1
			tst.b	OB_Var7(a0)
			beq.s	.f1
			rts
.f1			st.b	OB_Var7(a0)
			move.b	#1,OB_Var1(a0)
			move.w	#$200,OB_Xspd(a0)
			move.w	#$600,OB_Yspd(a0)
			move.w	#$70,OB_Yacc(a0)
			move.w	#6,OB_Xacc(a0)
			btst.b	#0,second
			beq.s	.fl
.fr			move.b	#%00111111,OB_MoveFlags(a0)
			rts
.fl			move.b	#%00111110,OB_MoveFlags(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BIG COULDRON CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

BigCouldronGen_Logic	move.w	#BigCouldron_OB,d2
			jsr	FindObject
			bmi.s	.x
			move.l	a0,-(sp)
			SPAWN_HI	BigCouldron_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#BigCouldron_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	OB_Var1(a0),OB_Var1(a1)
			move.w	OB_Var2(a0),OB_Var2(a1)
			rts
.no			move.l	(sp)+,a0
.x			rts

			;big couldron doesn't work!!!!!
			;re-write the jumping on/snapping to the sides

BigCouldron_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$28,OB_Xpos(a0)
			cmp.b	#1,OB_Var1a(a0)
			bgt.s	.no
			add.w	#58,OB_Ypos(a0)
.no			move.b	#ForgeCouldronHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	BigCouldronANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

.ok			move.l	Plr_Database,a1
			cmp.w	#GolPotBumpSTATE,OB_State(a1)
			beq	.stuff
			cmp.w	#GolJumpToWeightSTATE,OB_State(a1)
			bge	.stuff
			jsr	PlayerBody2EnemyBody
			bmi.s	.body
			bclr.b	#ob_carry,OB_Flag3(a0)
			bra	.stuff

.body			move.l	Plr_Database,a1
			move.w	OB_Xpos(a0),d1
			sub.w	#$20,d1
			cmp.w	OB_Xpos(a1),d1
			bgt.s	.onleft
			add.w	#$40,d1
			cmp.w	OB_Xpos(a1),d1
			blt.s	.onright

			move.w	OB_Ypos(a0),d1
			add.w	#$40,d1
			cmp.w	OB_Ypos(a1),d1
			blt.s	.stuff
			addq.w	#8,d1
			cmp.w	OB_Ypos(a1),d1
			blt.s	.stuff
			move.l	a0,-(sp)
			move.l	a1,a0
			jsr	GolSetPotBump
			move.l	(sp)+,a0
			bra	.stuff

.onright		btst.b	#ob_xflp,OB_Flag1(a1)			;facing couldron?
			bne.s	.b1
			bra.s	.stuff
.onleft			btst.b	#ob_xflp,OB_Flag1(a1)			;facing couldron?
			bne.s	.stuff
.b1			clr.b	PlrFallOnWeightFLG
			st.b	PlrJumpOnWeightFLG
.so			bset.b	#ob_carry,OB_Flag3(a0)
			clr.b	GolSpriteCarryDLY
			move.l	a0,DetectedWeightOB

.stuff			tst.b	OB_Var2(a0)
			beq.s	.y1
   			subq.b	#1,OB_Var2(a0)
			bne	.x
			jmp	SwitchObjectOff

.y1			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			
			tst.b	OB_Var1a(a0)
			beq.s	.tr
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.tl
			cmp.b	#2,OB_Var1a(a0)
			beq.s	.td
			cmp.b	#3,OB_Var1a(a0)
			beq.s	.tu
			rts

.tr			sub.w	#$28,d1
			sub.w	#$50,d2
			bra	.dot
.tl			sub.w	#$18,d1
			sub.w	#$50,d2
			bra	.dot
.td			sub.w	#$20,d1
			sub.w	#$50,d2
			bra	.dot
.tu			sub.w	#$20,d1
			sub.w	#$50,d2

.dot			jsr	GetUnderAddrs
			jsr	GetSpecial
			cmp.b	#SB_Left,d2
			beq.s	.ml
			cmp.b	#SB_Right,d2
			beq.s	.mr
			cmp.b	#SB_Up,d2
			beq.s	.mu
			cmp.b	#SB_Down,d2
			beq.s	.md
			cmp.b	#SB_Stop,d2
			bne.s	.do
			move.w	#$50,OB_Var2(a0)
			bra	.do

.ml			move.b	#1,OB_Var1a(a0)
			bra	.do			
.mr			clr.b	OB_Var1a(a0)
			bra	.do			
.mu			move.b	#3,OB_Var1a(a0)
			bra	.do			
.md			move.b	#2,OB_Var1a(a0)

.do			move.l	Plr_Database,a1
			tst.b	OB_Var1a(a0)
			beq.s	.right
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.left
			cmp.b	#2,OB_Var1a(a0)
			beq.s	.down
			cmp.b	#3,OB_Var1a(a0)
			beq.s	.up
.x			rts

.right			addq.w	#1,OB_Xpos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			addq.w	#1,OB_Xpos(a1)
			rts
.left			subq.w	#1,OB_Xpos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			subq.w	#1,OB_Xpos(a1)
			rts
.down			addq.w	#1,OB_Ypos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			addq.w	#1,OB_Ypos(a1)
			rts
.up			subq.w	#1,OB_Ypos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			subq.w	#1,OB_Ypos(a1)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TIPPING TROUGH CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Trough_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$15,OB_Xpos(a0)
			add.w	#4,OB_Ypos(a0)
			clr.b	OB_Var3(a0)
			lea	TroughANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			move.l	Plr_Database,a1
			jsr	PlayerFeet2EnemyBody
			bmi.s	.feet
			bclr.b	#ob_carry,OB_Flag3(a0)
			bra	.stuff

.feet			tst.b	GolSpriteCarryDLY
			bne	.stuff
			st.b	PlrFallOnWeightFLG
			clr.b	PlrJumpOnWeightFLG
			move.w	OB_Ypos(a0),d1
			subq.w	#4,d1
			move.w	d1,OB_Ypos(a1)			;plrs y=top of weight
			bset.b	#ob_carry,OB_Flag3(a0)
			move.l	a0,DetectedWeightOB

.stuff			tst.b	OB_Var3(a0)
			beq.s	.n1
			tst.l	OB_AnSequence(a0)
			bne.s	.xx
			clr.b	OB_Var3(a0)
			move.b	#$10,OB_Var3a(a0)
	
.n1			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			
			tst.b	OB_Var1a(a0)
			beq.s	.tr
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.tl
			cmp.b	#2,OB_Var1a(a0)
			beq.s	.td
			cmp.b	#3,OB_Var1a(a0)
			beq.s	.tu
.xx			rts

.tr			sub.w	#$10,d1
			sub.w	#$10,d2
			bra	.dot
.tl			sub.w	#$7,d1
			sub.w	#$10,d2
			bra	.dot
.td			sub.w	#$10,d1
			sub.w	#$1c,d2
			bra	.dot
.tu			sub.w	#$10,d1
			sub.w	#$10,d2

.dot			jsr	GetUnderAddrs
			jsr	GetSpecial
			cmp.b	#SB_Left,d2
			beq.s	.ml
			cmp.b	#SB_Right,d2
			beq.s	.mr
			cmp.b	#SB_Up,d2
			beq.s	.mu
			cmp.b	#SB_Down,d2
			beq.s	.md
			cmp.b	#SB_Tip,d2
			beq.s	.tip
			cmp.b	#SB_Stop,d2
			bne.s	.do
			jmp	SwitchObjectOff

.tip			tst.b	OB_Var3a(a0)
			beq.s	.ytip
     			subq.b	#1,OB_Var3a(a0)
			bra	.do
.ytip			st.b	OB_Var3(a0)
			lea	TroughTipANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ml			move.b	#1,OB_Var1a(a0)
			bra	.do			
.mr			clr.b	OB_Var1a(a0)
			bra	.do			
.mu			move.b	#3,OB_Var1a(a0)
			bra	.do			
.md			move.b	#2,OB_Var1a(a0)

.do			move.l	Plr_Database,a1
			tst.b	OB_Var1a(a0)
			beq.s	.right
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.left
			cmp.b	#2,OB_Var1a(a0)
			beq.s	.down
			cmp.b	#3,OB_Var1a(a0)
			beq.s	.up
.x			rts

.right			addq.w	#1,OB_Xpos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			addq.w	#1,OB_Xpos(a1)
			rts
.left			subq.w	#1,OB_Xpos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			subq.w	#1,OB_Xpos(a1)
			rts
.down			addq.w	#1,OB_Ypos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			addq.w	#1,OB_Ypos(a1)
			rts
.up			subq.w	#1,OB_Ypos(a0)
			tst.b	IsGolOnWeightFLG
			beq.s	.x
			cmp.l	DetectedWeightOB,a0
			bne.s	.x
			btst.b	#ob_carry,OB_Flag3(a0)
			beq.s	.x
			subq.w	#1,OB_Ypos(a1)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TIPPING TROUGH GENERATOR CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

TroughGen_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	OB_Var1(a0),OB_Var2(a0)
			bra	.gen

.ok			subq.b	#1,OB_Var1(a0)
			beq.s	.gen
			rts

.gen			move.b	OB_Var2(a0),OB_Var1(a0)
			
			move.l	a0,-(sp)
			SPAWN_HI	Trough_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Trough_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.b	OB_Var1a(a0),OB_Var1a(a1)
			rts
.no			move.l	(sp)+,a0
			rts			


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ENERGIZER UMBILICAL CORD CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

Energizer_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$7,OB_Xpos(a0)
			sub.w	#$30+16,OB_Ypos(a0)
			clr.w	OB_Var2(a0)
			clr.w	Pal1+4
			move.b	#$40,OB_Var1a(a0)
			lea	EnergizerANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim

.ok			moveq	#0,d1				;energizer takes 4 hits
			move.b	OB_Var1(a0),d1
			lea	EnergizerWalls,a1
			tst.b	0(a1,d1.w)
			beq.s	.n1
			move.w	OB_Xpos(a0),d1			
			move.w	OB_Ypos(a0),d2			
			add.w	#$10,d2
			jsr	SetBigAirExplode
			bpl.s	.o1aa
			bset.b	#ob_hiprior,OB_Flag2(a1)
.o1aa			moveq	#2,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			move.l	a0,-(sp)
			move.l	Plr_Database,a0
			jsr	GolSetRunAttackWall
			move.l	(sp)+,a0
			jmp	HandleEnemyKilled
   	
.n1			moveq	#0,d1				
			move.b	OB_Var1(a0),d1
			lea	EnergizedFLG,a1
			cmp.b	#2,0(a1,d1.w)
			bge.s	.x
			tst.w	OB_Var2(a0)
			beq.s	.gen
			subq.w	#1,OB_Var2(a0)
.x			rts

.gen			subq.b	#1,OB_Var1a(a0)
			bne.s	.x
.stuff			moveq	#0,d1				
			move.b	OB_Var1(a0),d1
			lea	EnergizedFLG,a1
			addq.b	#1,0(a1,d1.w)
			
			move.b	#$40,OB_Var1a(a0)
			move.w	#$120,OB_Var2(a0)
			
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			movem.l	a1/d1,-(sp)
			asl.b	#2,d1
			jsr	EnergizeJumpTab(pc,d1.w)
			SFX	108
			movem.l	(sp)+,a1/d1
			rts

EnergizeJumpTab		bra	E_spider1
			bra	E_spider2
			bra	E_wasp1
			bra	E_wasp2
			bra	E_sniper1
			bra	E_sniper2
			bra	E_raptor1
			bra	E_raptor2
			bra	E_plasma1
			bra	E_plasma2


E_spider1
E_spider2		move.w	#SpiderBot_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.x
			move.w	#SpiderBot_OB,OB_Type(a1)
			move.w	#SpiBotSetHorzSTATE,OB_State(a1)
			move.w	#SpiderBot_NRG,OB_Nrg(a1)
			add.w	#$40,OB_Ypos(a1)
			bra	SetEnergizerSparks
.x			rts

E_wasp1
E_wasp2			move.w	#WaspBot_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.x
			move.w	#WaspBot_OB,OB_Type(a1)
			move.w	#WaspBot_NRG,OB_Nrg(a1)
			add.w	#$30,OB_Ypos(a1)
			bra	SetEnergizerSparks
.x			rts

E_sniper1
E_sniper2		move.w	#SniperBot_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.x
			move.w	#SniperBot_OB,OB_Type(a1)
			move.w	#SniperBot_NRG,OB_Nrg(a1)
			add.w	#$40,OB_Ypos(a1)
			bra	SetEnergizerSparks
.x			rts
	
E_raptor1		bsr	SetEnergizerSparks
			move.w	#RaptorBot_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.x
			move.w	#RaptorBot_OB,OB_Type(a1)
			move.w	#RaptorBot_NRG,OB_Nrg(a1)
			add.w	#$40,OB_Ypos(a1)
.x			rts
E_raptor2		bsr	E_raptor1
			move.w	#RapBotJumpAttackSTATE,OB_State(a1)
			rts

E_plasma1
E_plasma2		bsr	SetEnergizerSparks
			move.w	#PlasmaBot_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.x
			move.w	#PlasmaBot_OB,OB_Type(a1)
			move.w	#PlasmaBot_NRG,OB_Nrg(a1)
			add.w	#$40,OB_Ypos(a1)
.x			rts



EnergizedRobotOff	moveq	#0,d1				;this routine is called whenever an enrgized robot
			move.b	OB_EventVar4(a0),d1		;is ultimately destroyed by the player or
			lea	EnergizedFLG,a1			;the scroller
			subq.b	#1,0(a1,d1.w)
			rts

EnergizerSpawnOb	move.l	a0,-(sp)
			jsr	SpawnBasicOBJECT_HI
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.b	OB_Var1(a0),OB_EventVar4(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.l	#EnergizedRobotOff,OB_OffRoutine(a1)
			tas	yes
			rts
.no			move.l	(sp)+,a0
			tas	no
			rts


SetEnergizerSparks	moveq	#6,d5
.l1			movem.l	a0/d0-d5,-(sp)
			SPAWN_HI	Spark_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			movem.l	(sp)+,d0-d5/a0
			move.w	#Spark2_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			jsr	RandomParabolaSmallA1
			add.w	#$0300,OB_Xspd(a1)
			add.w	#$30,OB_Ypos(a1)
			move.b	#%00111111,OB_MoveFlags(a1)
			dbra	d5,.l1
			rts
.1			movem.l	(sp)+,d0-d5/a0
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί DEMONA BOSS CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnDemona		move.l	a0,-(sp)
			SPAWN_HI	Demona_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Demona_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),d1
			sub.w	#$b0,d1
			move.w	d1,OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$50,d1
			move.w	d1,OB_Ypos(a1)
			clr.b	DemonaFLG1
			clr.b	DemonaFLG2
			rts
.1			move.l	(sp)+,a0
			rts


		StRESET
		StDEF	DemonaSetStory1STATE
		StDEF	DemonaStory1STATE
		StDEF	DemonaBlastOffSTATE
		StDEF	DemonaSetWait1STATE
		StDEF	DemonaWait1STATE
		StDEF	DemonaStory2STATE
		StDEF	DemonaTentacleGrabSTATE
		
		StDEF	DemonaElectrifySTATE
		StDEF	DemonaTentacleHoldSTATE
		StDEF	DemonaLookSTATE
		StDEF	DemonaAttackSTATE
		StDEF	DemonaHovverSTATE
		StDEF	DemonaFlyToSideSTATE
		StDEF	DemonaHawkDiveSTATE
		StDEF	DemonaEyeBackSTATE
		StDEF	DemonaAirZeroSTATE

		StDEF	DemonaStartPhoenixSTATE
		StDEF	MDemonaZeroSTATE
		StDEF	MDemonaFlySTATE
		StDEF	MDemonaOnCeilSTATE
		StDEF	MDemonaOnWallSTATE
		StDEF	MDemonaWallIdleSTATE
		StDEF	MDemonaOffWallSTATE
		StDEF	MDemonaHitSTATE
		StDEF	MDemonaDeadSTATE

Demona_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)

.1			jsr	HandleBeingHit				;Generic handle hit rout
			
			tst.b	HitDemonaFloorFLG
			beq.s	.n1
   			clr.b	HitDemonaFloorFLG
			bsr	SetMDemonaFloorFire

.n1			cmp.w	#DemonaStartPhoenixSTATE,OB_State(a0)
			bge.s	.o1
			tst.b	PhoenixDemonaFLG
			bne	DemonaSetStartPhoenix
			
.o1			move.w	OB_State(a0),d1
			jmp	DemonaLogicTable(pc,d1.w)		;jump table

DemonaLogicTable	bra	DemonaSetStory1LOGIC
			bra	DemonaStory1LOGIC
			bra	DemonaBlastOffLOGIC
			bra	DemonaSetWait1LOGIC
			bra	DemonaWait1LOGIC
			bra	DemonaStory2LOGIC
			bra	DemonaTentacleGrabLOGIC
			 
			bra	DemonaElectrifyLOGIC
			bra	DemonaTentacleHoldLOGIC
			bra	DemonaLookLOGIC
			bra	DemonaAttackLOGIC
			bra	DemonaHovverLOGIC
			bra	DemonaFlyToSideLOGIC
			bra	DemonaHawkDiveLOGIC
			bra	DemonaEyeBackLOGIC
			bra	DemonaAirZeroLOGIC

			bra	DemonaStartPhoenixLOGIC
			bra	MDemonaZeroLOGIC
			bra	MDemonaFlyLOGIC
			bra	MDemonaOnCeilLOGIC
			bra	MDemonaOnWallLOGIC
			bra	MDemonaWallIdleLOGIC
			bra	MDemonaOffWallLOGIC
			bra	MDemonaHitLOGIC
			bra	MDemonaDeadLOGIC

; - Demona Logic -----------------------------------------------------------

DemonaSetStory1LOGIC	move.w	#DemonaStory1STATE,OB_State(a0)
			move.b	#$a0,OB_Var1(a0)
			lea	DemonaIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

DemonaStory1LOGIC	subq.b	#1,OB_Var1(a0)
			beq	DemonaSetBlastOff
			rts
	

; - Demona Logic -----------------------------------------------------------

DemonaSetBlastOff	move.w	#DemonaBlastOffSTATE,OB_State(a0)
			move.l	OB_Task(a0),a1
			jsr	SwitchObjectOffA1
			move.b	#$20,OB_Var1(a0)
			clr.b	OB_EventVar1(a0)
			SFX	22	
			lea	DemonaBlastOffANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

DemonaBlastOffLOGIC	tst.b	OB_EventVar1(a0)
			beq.s	.x
			subq.b	#1,OB_Var1(a0)
			beq.s	.fin
			moveq	#8,d1
			jmp	MoveGolUp_Smooth
.fin			clr.b	NoFollowFLG
			move.l	Plr_Database,a1
			move.b	#$10,OB_Var2(a1)
			jmp	SwitchObjectOff
.x			rts			


; - Demona Logic -----------------------------------------------------------

DemonaSetWait1LOGIC	move.w	#DemonaWait1STATE,OB_State(a0)
			move.b	#$d0,OB_Var1(a0)
			lea	DemonaIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

DemonaWait1LOGIC	tst.b	DemonaFLG3
			bne.s	DemonaSetStory2
			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetStory2		move.w	#DemonaStory2STATE,OB_State(a0)
			rts

DemonaStory2LOGIC	tst.b	DemonaFLG3
			beq.s	DemonaSetTentacleGrab
			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetTentacleGrab	move.w	#DemonaTentacleGrabSTATE,OB_State(a0)
			jsr	ClrHitStuff
			move.w	d0,TrackObjectNumber
			move.l	a0,TrackObjectDatabase
			clr.b	OB_Var1(a0)
			move.l	OB_Task(a0),a1			;switch off dialogue
			jmp	SwitchObjectOffA1
	
DemonaTentacleGrabLOGIC	tst.b	OB_Var1(a0)
			bne.s	.up
			tst.b	DemonaFLG4	
			beq.s	.x
			st.b	OB_Var1(a0)
			lea	DemonaTentacleGrabANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts

.up			tst.b	DemonaFLG4
			beq.s	DemonaSetElectrify
			moveq	#1,d1
			jmp	MoveGolUp_Smooth
			

; - Demona Logic -----------------------------------------------------------

DemonaSetElectrify	move.w	#DemonaElectrifySTATE,OB_State(a0)
			KILL	55
			clr.b	OB_Var1(a0)
			move.b	#$10,OB_Var1a(a0)
			rts

DemonaElectrifyLOGIC	addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.x
  			subq.b	#1,OB_Var1a(a0)
			beq.s	.aa
			SFX	110
			move.w	#$444,d6
			jmp	LightenPalette2
.x			rts
.aa			SFX	95
			jsr	WhitePalette
			moveq	#1,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein  
			st.b	DemonaFLG3
			
			lea	AMAP_FORGFLMC0_START,a2			;start fire animation
			jsr	SetupCharAnim						
			move.b	#2,CH_AnCnt(a1)	
			st.b	PlayingBOSS
			clr.b	BossDefeatedFLG
			
			
; - Demona Logic -----------------------------------------------------------

DemonaSetTentacleHold	move.w	#DemonaTentacleHoldSTATE,OB_State(a0)
			move.w	#-1,TrackObjectNumber
			clr.b	OB_Var1(a0)
			clr.b	DemonaFLG1				;enable player
			clr.b	DemonaAttackFLG
			clr.b	DemonaLookFLG
			jsr	ClrHitStuff
			lea	DemonaTentacleIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

DemonaTentacleHoldLOGIC	tst.b	DemonaAttackFLG
			bne	DemonaSetAttack
			tst.b	DemonaLookFLG
			bne.s	DemonaSetLook
			btst.b	#ob_beinghit,OB_Flag1(a0)
			beq.s	.x
;			sub.w	#$10,BossEnergy
			st.b	DemonaAttackFLG
			jsr	ClrHitStuff
			bra	DemonaSetAttack

.x			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetLook		move.w	#DemonaLookSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			jsr	Randy
			and.b	#1,d6
			move.b	d6,OB_Var1(a0)
			beq.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			lea	DemonaLookLeftRightANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
		
DemonaLookLOGIC		tst.b	OB_EventVar1(a0)
			beq.s	.1
			clr.b	OB_EventVar1(a0)
			jmp	SpawnBigGuns
			
.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			tst.b	DemonaAttackFLG
			bne.s	DemonaSetAttack
			tst.b	DemonaLookFLG
			beq	DemonaSetTentacleHold
.x			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetAttack		move.w	#DemonaAttackSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			clr.b	OB_EventVar1(a0)
			move.b	#5,OB_Var7(a0)
			lea	DemonaUnHookANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
		
DemonaAttackLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.2
  			moveq	#$20,d1
			lea	DemonaSetFlyToSide,a1
			bra	DemonaSetHovver
.2			tst.b	OB_EventVar1(a0)
			beq.s	.x
			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)
.x			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetHovver		move.w	#DemonaHovverSTATE,OB_State(a0)
			move.b	d1,OB_Var3(a0)
			clr.w	OB_Var4(a0)
			move.l	a1,OB_Task(a0)
			lea	DemonaAirIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
	
DemonaHovverLOGIC	subq.b	#1,OB_Var3(a0)
			bne.s	.x
			move.l	OB_Task(a0),a1
			jmp	(a1)

.x			addq.b	#1,OB_Var3a(a0)
			and.b	#3,OB_Var3a(a0)
			bne.s	.4
			addq.b	#1,OB_Var4(a0)

.1			moveq	#0,d1
			moveq	#0,d2
			move.b	OB_Var4(a0),d1
			lea	WaspBobTab,a1
			move.b	0(a1,d1.w),d2
			bpl.s	.2
			cmp.b	#$80,d2
			bne.s	.3
			clr.b	OB_Var4(a0)
			bra.s	.1
.3			neg.b	d2
			sub.w	d2,OB_Ypos(a0)
.4			rts
.2			add.w	d2,OB_Ypos(a0)
			rts

				
; - Demona Logic -----------------------------------------------------------

DemonaSetFlyToSide	move.w	#DemonaFlyToSideSTATE,OB_State(a0)
			move.w	#256,OB_Var1(a0)
			move.w	#256+128,OB_Var2(a0)
			clr.b	OB_Var5(a0)
			move.w	#$142,OB_Var6(a0)
			move.w	OB_Xpos(a0),OB_WXpos(a0)
			move.w	OB_Ypos(a0),OB_WYpos(a0)
			jsr	Randy
			and.b	#1,d6
			beq.s	.1
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bclr.b	#ob_xflp,OB_Flag1(a0)
.2			SFX	5
			lea	DemonaAirAscendANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
DemonaFlyToSideLOGIC	bsr	DemonaDiveBit
  
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			subq.w	#2,OB_Var1(a0)
			subq.w	#2,OB_Var2(a0)
 			cmp.w	#128,OB_Var1(a0)
			bgt.s	.a
    			move.w	#$20,d1
			lea	DemonaSetHawkDive,a1
			bra	DemonaSetHovver
						
.r			addq.w	#2,OB_Var1(a0)
			addq.w	#2,OB_Var2(a0)
  			cmp.w	#256+128,OB_Var1(a0)
			blt.s	.a
    			move.w	#$20,d1
			lea	DemonaSetHawkDive,a1
			bra	DemonaSetHovver
			
.a			and.w	#$1ff,OB_Var1(a0)
			and.w	#$1ff,OB_Var2(a0)
			rts


DemonaDiveBit		lea	SinTable,a1
						
			move.w	OB_Var1(a0),d1		;x
			move.w	OB_Var2(a0),d2		;y
			
			move.w	OB_WXpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d1.w),d3		;sin x	
			bpl.s	.x1
   			neg.w	d3
			divu	#$18,d3
			sub.w	d3,d4
			bra	.xx
.x1			divu	#$18,d3
			add.w	d3,d4
.xx			move.w	d4,OB_Xpos(a0)			
			
			move.w	OB_WYpos(a0),d4
			moveq	#0,d3
			move.w	0(a1,d2.w),d3		;cos y
			bpl.s	.y1
   			neg.w	d3
			divu	#$20,d3
			sub.w	d3,d4
			bra	.yy
.y1			divu	#$20,d3
			add.w	d3,d4
.yy			sub.w	#$80,d4
			move.w	d4,OB_Ypos(a0)			
  			rts

			
; - Demona Logic -----------------------------------------------------------

DemonaSetHawkDive	tst.b	GolOnFloorFLG
			beq	DemonaSetEyeBack
			subq.b	#1,OB_Var7(a0)
			bmi	DemonaSetEyeBack
			move.w	#DemonaHawkDiveSTATE,OB_State(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			st.b	OB_Var3(a0)
			bra	.1
.r			clr.b	OB_Var3(a0)
.1			eor.b	#_ob_xflp,OB_Flag1(a0)
			clr.w	OB_Var4(a0)
			clr.w	OB_Var5(a0)
			move.b	#DemDiveAttkHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	DemonaAirAttackANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
DemonaHawkDiveLOGIC	bsr	DemonaDiveBit
			
			addq.b	#1,OB_Var4a(a0)
			cmp.b	#7,OB_Var4a(a0)
			bne.s	.1
			clr.b	OB_Var4a(a0)
 			tst.b	OB_Var4(a0)
			beq.s	.acc
.dec			cmp.w	#$02,OB_Var5(a0)
			beq.s	.1
			sub.w	#$02,OB_Var5(a0)
			bra	.1
.acc			cmp.w	#$06,OB_Var5(a0)
			beq.s	.1
			add.w	#$02,OB_Var5(a0)
					
.1			move.w	OB_Var5(a0),d1
			tst.b	OB_Var3(a0)
			bne.s	.r
.l			sub.w	d1,OB_Var1(a0)
			sub.w	d1,OB_Var2(a0)
 			cmp.w	#128+16,OB_Var1(a0)
			bgt.s	.a
.fin			move.w	#$30,d1
			lea	DemonaSetHawkDive,a1
			bra	DemonaSetHovver
						
.r			add.w	d1,OB_Var1(a0)
			add.w	d1,OB_Var2(a0)
  			cmp.w	#(256+128)-16,OB_Var1(a0)
			blt.s	.a
    			move.w	#$30,d1
			lea	DemonaSetHawkDive,a1
			bra	DemonaSetHovver
			
.a			and.w	#$1ff,OB_Var1(a0)
			and.w	#$1ff,OB_Var2(a0)
			
			tst.b	OB_Var4(a0)
			bne.s	.x
  			tst.b	OB_Var3(a0)
			beq.s	.tr
.tl			cmp.w	#272,OB_Var1(a0)
			bgt.s	.s
			rts
.tr			cmp.w	#240,OB_Var1(a0)
			bgt.s	.x
.s			st.b	OB_Var4(a0)
			SFX	22
			lea	DemonaAirAscendANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts


; - Demona Logic -----------------------------------------------------------

DemonaSetEyeBack	move.w	#DemonaEyeBackSTATE,OB_State(a0)
			move.w	#$140,TargetX
			move.w	#$14a,TargetY
			move.w	TargetX,OB_Var6(a0)
			move.w	TargetY,OB_Var7(a0)
			jsr	TrajectorySetup
			clr.w	OB_Var5(a0)
			SFX	5
			lea	DemonaAirAscendANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

DemonaEyeBackLOGIC	moveq	#4,d1
			jsr	TrajectoryMove
			tst.b	OB_Var5(a0)
			beq.s	.1
			tst.b	OB_Var5a(a0)
			bne	DemonaSetTentacleHold
.1			jmp	TrajectoryHit2
			

; - Demona Logic -----------------------------------------------------------

DemonaSetAirZero	move.w	#DemonaAirZeroSTATE,OB_State(a0)
			clr.b	DemonaFLG1				;give control back to plr
			lea	DemonaAirIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
DemonaAirZeroLOGIC	rts

			
; - Demona Logic -----------------------------------------------------------
		
DemonaSetStartPhoenix	move.w	#DemonaStartPhoenixSTATE,OB_State(a0)
			move.l	a0,Boss_Database
			clr.w	OB_Var1(a0)
			move.l	#MDemonaSetHit,OB_HitRoutine(a0)
			move.b	#DemPhoenixAttkHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	DemonaStartPhoenixANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
			
DemonaStartPhoenixLOGIC	addq.b	#1,OB_Var1(a0)
			and.b	#7,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)

.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)	
			addq.w	#1,OB_Xpos(a0)
			jsr	ObjectOffBottom
			bgt.s	.x
			moveq	#$f,d1
			lea	Pal4,a2
			lea	DemonaPal2,a1
			jsr	SetupGamePalette
			lea	DemonaPal2a,a1
			jsr	SetSinglePalette
			bra	MDemonaSetZero2
.x			rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetHit		jsr	ClrHitStuff
			move.w	#MDemonaHitSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			clr.b	OB_Var2(a0)
			move.b	#4,OB_Var2a(a0)
			SFX	23	
			lea	MDemonaHitANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


MDemonaHitLOGIC		addq.b	#1,OB_Var1(a0)
			and.b	#7,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var2(a0)
			cmp.b	#1,OB_Var2a(a0)
			beq.s	.1
			subq.b	#1,OB_Var2a(a0)

.1			jsr	ObjectOffBottom
			bgt.s	.2
			btst.b	#ob_dead,OB_Flag2(a0)
			bne	MDemonaSetDead
			bra	MDemonaSetZero2

.2			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			add.w	d1,OB_Ypos(a0)
			move.b	OB_Var2a(a0),d1
			btst.b	#ob_hitside,OB_Var1(a0)	
			beq.s	.r
.l			jsr	GolTestLeftSide2
			bmi.s	.x
			sub.w	d1,OB_Xpos(a0)
			rts
.r			jsr	GolTestRightSide2
			bmi.s	.x
			add.w	d1,OB_Xpos(a0)
.x			rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetDead		move.w	#MDemonaDeadSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			st.b	NextLevelFLG
			lea	MDemonaHitANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaDeadLOGIC	rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetZero2		move.w	#MDemonaZeroSTATE,OB_State(a0)
			move.b	#$70,OB_Var2(a0)
			rts
MDemonaSetZero		move.w	#MDemonaZeroSTATE,OB_State(a0)
			clr.b	OB_Var2(a0)
			rts

MDemonaZeroLOGIC	tst.b	GolOnFloorFLG
			bne.s	.of
			clr.b	OB_Var4(a0)
			
.of			tst.b	OB_Var2(a0)
			beq.s	.y1
  			subq.b	#1,OB_Var2(a0)
			rts

.y1			addq.b	#1,OB_Var4(a0)
			cmp.b	#2,OB_Var4(a0)
			blt.s	.111
			clr.b	OB_Var4(a0)
			bsr	SetupBigFireballHead
			cmp.w	#$140,Plr_XPos
			blt.s	.fr
.fl			move.w	#$a0,TempX
			move.b	#%00111110,OB_MoveFlags(a1)
			bra	.flr
.fr			move.w	#$1c0,TempX
			move.b	#%00111111,OB_MoveFlags(a1)
.flr			move.w	#$1d0,OB_Ypos(a1)
			move.w	TempX,OB_Xpos(a1)
			move.w	#$0980,OB_Yspd(a1)
			move.w	#$200,OB_Xspd(a1)
			move.w	OB_Xspd(a1),OB_Var2(a1)
			
.111			lea	Pal4,a2
			lea	DemonaPal2,a1
			moveq	#$f,d1
			jsr	SetupGamePalette
			
			jsr	Randy
			and.w	#$17f,d6
			add.w	#$80,d6
			move.w	d6,OB_Xpos(a0)
			cmp.w	#$140,d6
			blt.s	.r
			bset.b	#ob_xflp,OB_Flag1(a0)
			bra	.1
.r			bclr.b	#ob_xflp,OB_Flag1(a0)
.1			bclr.b	#ob_yflp,OB_Flag1(a0)
			move.w	#MDemonaFlySTATE,OB_State(a0)
			SFX	24
			lea	MDemonaAirIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


; - Demona Logic -----------------------------------------------------------

MDemonaSetFly1		move.w	#MDemonaFlySTATE,OB_State(a0)
			lea	MDemonaAirIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaFlyLOGIC		tst.b	GolOnFloorFLG
			beq	.aa
			addq.b	#1,OB_Var3(a0)
			and.b	#$3f,OB_Var3(a0)
			bne.s	.aa
			bsr	SetupFireballHead
			btst.b	#ob_yflp,OB_Flag1(a0)
			bne.s	.y1
			sub.w	#$10,OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.y3
			add.w	#$10,OB_Xpos(a1)
			bra.s	.aa
.y3			sub.w	#$10,OB_Xpos(a1)
			bra.s	.aa
.y1			add.w	#$50,OB_Ypos(a1)
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.y2
			add.w	#$10,OB_Xpos(a1)
			bra.s	.aa
.y2			sub.w	#$10,OB_Xpos(a1)

.aa			cmp.w	#$180,OB_Ypos(a0)
			bgt.s	.2
			btst.b	#ob_yflp,OB_Flag1(a0)
			bne.s	.1
			bsr	GetUnderHEAD
			btst	#7,d2
			bne	MDemonaSetOnCeil
.1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.l1
			bsr	GetUnderLEFTGROUND
			bra	.lr
.l1			bsr	GetUnderLEFT
			bra	.lr
.r			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.r1
			bsr	GetUnderRIGHTGROUND
			bra	.lr
.r1			bsr	GetUnderRIGHT
.lr			btst	#7,d2
			beq.s	.2
			bne	MDemonaSetOnWall

.2			moveq	#6,d1
			jsr	MoveGolLeftRightFLP3
			jsr	MoveGolUpDownFLP
			jsr	ObjectOffBottom
			blt	MDemonaSetZero
			rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetOnCeil	move.w	#MDemonaOnCeilSTATE,OB_State(a0)
			and.w	#$fff0,OB_Ypos(a0)
			add.w	#$20,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			add.w	#$8,OB_Xpos(a0)
			bra	.1
.r			sub.w	#$8,OB_Xpos(a0)
.1			lea	MDemonaFloorBounceANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaOnCeilLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			eor.b	#_ob_yflp,OB_Flag1(a0)
			sub.w	#$50,OB_Ypos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$28,OB_Xpos(a0)
			bra	MDemonaSetFly1
.r			add.w	#$28,OB_Xpos(a0)
			bra	MDemonaSetFly1
.x			rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetOnWall	move.w	#MDemonaOnWallSTATE,OB_State(a0)
			and.w	#$fff0,OB_Xpos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
			nop
			bra	.2
.r			add.w	#$10,OB_Xpos(a0)
.2			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.u
.d			add.w	#$28,OB_Ypos(a0)
			bra	.1
.u			sub.w	#$28,OB_Ypos(a0)

.1			lea	MDemonaFlyWallTransANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaOnWallLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			tst.b	GolOnWallLeftFLG
			beq.s	.1
			btst.b	#ob_xflp,OB_Flag1(a0)	
			bne	MDemonaSetWallIdle
			bra	MDemonaSetOffWall
.1			tst.b	GolOnWallRightFLG
			beq	MDemonaSetOffWall
			btst.b	#ob_xflp,OB_Flag1(a0)	
			beq	MDemonaSetWallIdle
			bra	MDemonaSetOffWall
.x			rts

			
; - Demona Logic -----------------------------------------------------------

MDemonaSetWallIdle	move.w	#MDemonaWallIdleSTATE,OB_State(a0)
			move.b	#$30,OB_Var2(a0)
			move.b	#4,OB_Var2a(a0)
			clr.b	OB_Var3(a0)
			lea	MDemonaWallIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaWallIdleLOGIC	tst.b	OB_Var2(a0)
			beq.s	.fire
  			subq.b	#1,OB_Var2(a0)
			bra.s	.1
.fire			addq.b	#1,OB_Var3(a0)
			and.b	#$f,OB_Var3(a0)
			bne.s	.1
			subq.b	#1,OB_Var2a(a0)
			beq	MDemonaSetOffWall
			bsr	SetMDemonaWallFire

.1			tst.b	GolOnWallRightFLG
			bne.s	.x
			tst.b	GolOnWallLeftFLG
			beq	MDemonaSetOffWall
.x			rts


; - Demona Logic -----------------------------------------------------------

MDemonaSetOffWall	move.w	#MDemonaOffWallSTATE,OB_State(a0)
			lea	MDemonaWallFlyTransANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

MDemonaOffWallLOGIC	tst.l	OB_AnSequence(a0)
			bne.s	.x
			eor.b	#_ob_xflp,OB_Flag1(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			sub.w	#$10,OB_Xpos(a0)
			bra	.1
.r			add.w	#$18,OB_Xpos(a0)
.1			btst.b	#ob_yflp,OB_Flag1(a0)
			beq.s	.u
.d			sub.w	#$18,OB_Ypos(a0)
			bra	MDemonaSetFly1
.u			add.w	#$8,OB_Ypos(a0)
			bra	MDemonaSetFly1
.x			rts


; - Demona Logic -----------------------------------------------------------

; - Demona Logic -----------------------------------------------------------
; - Demona Logic -----------------------------------------------------------
; - Demona Logic -----------------------------------------------------------
; - Demona Logic -----------------------------------------------------------


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT DEMONAS WALL FIRE						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetMDemonaWallFire	tst.b	GolOnWallLeftFLG
			beq.s	.1
			move.w	#$64,TempX
			bra	.1a
.1			tst.b	GolOnWallRightFLG
			beq.s	.2
			move.w	#$21c,TempX
.1a			move.w	#$98,TempY

.2			moveq	#4,d6
.l1			move.l	d6,-(sp)
			move.l	a0,-(sp)
			SPAWN_LO	MDemWallFire_MAX_Size
			bmi.s	.y
			move.l	(sp)+,a0
			bra	.nxt
.y			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#MDemonaWallFire_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			jsr	SetFlipFromMother
			bclr.b	#ob_yflp,OB_Flag1(a1)
;			eor.b	#_ob_xflp,OB_Flag1(a1)
			move.b	#DemAllFlamesHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a1)
			clr.b	OB_Var1a(a1)
.nxt			add.w	#$32,TempY
			move.l	(sp)+,d6
			dbra	d6,.l1
			rts

MDemonaWallFire_Logic	tst.b	OB_Var1a(a0)
			beq.s	.wait
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.burn
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.burn			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			addq.b	#1,OB_Var1a(a0)
			lea	MDemonaWallFireDnANM,a1
			bra.s	.aa
.wait			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			addq.b	#1,OB_Var1a(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a0)
			lea	MDemonaWallFireUpANM,a1
.aa			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί MUTANT DEMONAS FLOOR FIRE						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SetMDemonaFloorFire	cmp.w	#$140,Plr_XPos
			blt.s	.r
.l			move.w	#$108,TempX
			bra	.1a
.r			move.w	#$178,TempX
.1a			move.w	#$1ab,TempY

			clr.w	TempA

			SFX	26

			moveq	#2,d6
.l1			move.l	d6,-(sp)
			move.l	a0,-(sp)
			SPAWN_LO	MDemFloorFire_MAX_Size
			bmi.s	.y
			move.l	(sp)+,a0
			bra	.nxt
.y			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#MDemonaFloorFire_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.b	#DemAllFlamesHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			move.b	TempA,d1
			asl.b	#4,d1
			addq.b	#1,d1
			move.b	d1,OB_Var1(a1)
			clr.b	OB_Var1a(a1)
.nxt			cmp.w	#$140,Plr_XPos
			blt.s	.ra
.la			add.w	#$1c*2,TempX
			bra	.lra
.ra			sub.w	#$1c*2,TempX
.lra			addq.b	#1,TempA
			move.l	(sp)+,d6
			dbra	d6,.l1
			rts

MDemonaFloorFire_Logic	tst.b	OB_Var1a(a0)
			beq.s	.wait
			cmp.b	#1,OB_Var1a(a0)
			beq.s	.burn
			tst.l	OB_AnSequence(a0)
			bne.s	.x
			jmp	SwitchObjectOff
.burn			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			addq.b	#1,OB_Var1a(a0)
			lea	MDemonaFloorFireDnANM,a1
			bra.s	.aa
.wait			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			addq.b	#1,OB_Var1a(a0)
			jsr	Randy
			and.b	#$3f,d6
			or.b	#$10,d6
			move.b	d6,OB_Var1(a0)
			lea	MDemonaFloorFireUpANM,a1
.aa			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BIG GUNS CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnBigGuns		move.l	a0,-(sp)
			SPAWN_LO	BigGuns_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#BigGuns_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			tst.b	OB_Var1(a0)
			bne.s	.r
.l			move.w	#$30,OB_Xpos(a1)
			bset.b	#ob_xflp,OB_Flag1(a1)
			bra	.1a
.r			move.w	#$248,OB_Xpos(a1)
			bclr.b	#ob_xflp,OB_Flag1(a1)
.1a			move.w	#$d8,OB_Ypos(a1)
			move.b	OB_Var1(a0),OB_Var1(a1)
			move.b	#$50,OB_Var1a(a1)
			clr.b	OB_Var2(a1)
			move.b	#DemPlasmaArrayHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			lea	BigGunsANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			move.l	(sp)+,a0
			rts

BigGuns_Logic		tst.b	OB_Var2(a0)
			beq.s	.out
			bmi.s	.in

.fire			subq.b	#1,OB_Var1a(a0)
			beq.s	.ff
			move.b	OB_Var1a(a0),d1
			and.b	#$7,d1
			bne.s	.x
			SFX	47
			jmp	SpawnBigGunsProj	
.ff			st.b	OB_Var2(a0)
			move.b	#$50,OB_Var1a(a0)
.x			rts		

.in			subq.b	#1,OB_Var1a(a0)
			beq.s	.fin
			sub.w	#1,OB_Ypos(a0)
			tst.b	OB_Var1(a0)
			bne.s	.r
.l			subq.w	#1,OB_Xpos(a0)
			rts
.r			addq.w	#1,OB_Xpos(a0)
			rts

.fin			clr.b	DemonaLookFLG
			jmp	SwitchObjectOff
		
.out			subq.b	#1,OB_Var1a(a0)
			bne.s	.o1
			move.b	#1,OB_Var2(a0)
			move.b	#$80,OB_Var1a(a0)
.o1			addq.w	#1,OB_Ypos(a0)
			tst.b	OB_Var1(a0)
			bne.s	.ra
.la			addq.w	#1,OB_Xpos(a0)
			rts
.ra			subq.w	#1,OB_Xpos(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BIG GUNS PROJECTILE CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

BGxyTAB			dc.w	8,4
			dc.w	-$28,6
			dc.w	-$28,-$10
			dc.w	-$20,-$30

SpawnBigGunsProj	move.l	a0,-(sp)
			SPAWN_HI	BigGunsProj_MAX_Size
			bpl	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#BigGunsProj_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			addq.b	#1,BigGunCycle
			and.b	#3,BigGunCycle
			moveq	#0,d6
			move.b	BigGunCycle,d6
			asl.w	#2,d6
			lea	BGxyTAB,a2
			tst.b	OB_Var1(a0)
			bne.s	.r
.l			bset.b	#ob_xflp,OB_Flag1(a1)
			move.w	0(a2,d6.w),d1
			neg.w	d1
			add.w	d1,OB_Xpos(a1)
			bra	.1a
.r			bclr.b	#ob_xflp,OB_Flag1(a1)
			move.w	0(a2,d6.w),d1
			add.w	d1,OB_Xpos(a1)
.1a			move.w	2(a2,d6.w),d1
			add.w	d1,OB_Ypos(a1)
			clr.b	OB_EventVar1(a1)
			clr.w	OB_Var1(a1)
			move.b	#DemPlasmaArrayProjHitPOWER,OB_HitPower(a1)
			jsr	SetMediumAttackA1
			lea	BigGunsProjANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.1			move.l	(sp)+,a0
			rts

BigGunsProj_Logic	tst.b	OB_EventVar1(a0)
			bne.s	.1
.x			rts

.1			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.2
  			addq.b	#1,OB_Var1a(a0)
.2			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
			add.w	d1,OB_Ypos(a0)

			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.r
.l			sub.w	d1,OB_Xpos(a0)
			bra	.3
.r			add.w	d1,OB_Xpos(a0)
.3			jsr	TestProjHitting
			bpl.s	.x
			jsr	SetBigAirExplodeAtOB_XY
			bmi.s	.y
			jsr	SetSmallAirExplodeAtOB_XY
			bpl.s	.y
			add.w	#$8,OB_Xpos(a1)
.y			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EYE TENTACLE CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnTentacles		clr.b	DemonaFLG4
			move.l	a0,-(sp)
			SPAWN_LOLO	Tentacle_MAX_Size
			bpl.s	.1
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Tentacle_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			add.w	#$30,OB_Ypos(a1)
			move.l	a0,OB_Task(a1)
			move.l	a1,OB_Task(a0)
			rts
.1			move.l	(sp)+,a0
			rts

Tentacle_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$70,OB_Ypos(a0)
			SFX	48
			lea	TentacleStartANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			bne.s	.up
.down			tst.l	OB_AnSequence(a0)
			bne.s	.x
			SFX	118
			st.b	OB_Var1(a0)
			move.b	#$10,OB_Var2(a0)
			jsr	WhitePalette
			st.b	DemonaFLG4
			moveq	#1,d1
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jmp	set_whitein	

.up			tst.b	OB_Var2(a0)
			beq.s	.1
			subq.b	#1,OB_Var2(a0)
			bne.s	.x
			lea	TentacleRiseANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts

.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	DemonaFLG4
			jmp	SwitchObjectOff


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PASTE OVER WALL PIECES CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

WallPaste_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			addq.w	#8,OB_Xpos(a0)
			subq.w	#8,OB_Ypos(a0)
			lea	WallPasteANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			moveq	#0,d1
			move.b	OB_Var2(a0),d1
			lea	WallPasteTimers,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
.yup			subq.w	#1,OB_Var1(a0)
			bmi.s	.boom
.x			rts
.boom			jsr	SetBigAirExplodeAtOB_XY
			moveq	#4,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			jmp	HandleEnemyKilled


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί PASTE OVER EDGE PIECES CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

EdgePaste_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			addq.w	#8,OB_Xpos(a0)
			bra	.o1
.r			add.w	#$16,OB_Xpos(a0)
.o1			add.w	#$a,OB_Ypos(a0)
			move.b	#DemSpikesHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	EdgePasteANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	EyeHitEdgeFLG
			beq.s	.x
			clr.b	EyeHitEdgeFLG
			jmp	HandleEnemyKilled
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί LEVEL 5 MISC. CONTROL LOGIC ROUTINES				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί HIGH DUCKING SIGNS POLE CONTROL LOGIC				   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnPatternSignPOLE	move.l	a0,-(sp)
			SPAWN_LO	HighSignPole_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#HighSignPole_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),d1
			sub.w	#$23,d1
			move.w	d1,OB_Ypos(a1)
			move.w	#SubwaySignHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			lea	L5HighSignPoleANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.no			move.l	(sp)+,a0
			rts

HighSignPole_Logic	subq.w	#8,OB_Xpos(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί HIGH DUCKING SIGN CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnPatternSIGN	move.l	a0,-(sp)
			SPAWN_HI	HighSign_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#HighSign_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	map_x_p,d1
			add.w	#44*8,d1
			move.w	d1,OB_Xpos(a1)
			move.w	#$60,OB_Ypos(a1)
			rts
.no			move.l	(sp)+,a0
			rts			

HighSign_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	111
			bsr	SpawnPatternSignPOLE
			move.b	#SubwaySignHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			lea	L5HighSignANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			btst.b	#ob_hitting,OB_Flag1(a0)
			beq.s	.1
			SFX	34
			move.w	OB_Xpos(a0),TempX
			move.w	OB_Ypos(a0),TempY
			moveq	#5,d7
			moveq	#2,d3
			jsr	SetRandomDebris
			jmp	SwitchObjectOff

.1			subq.w	#8,OB_Xpos(a0)
			tst.l	OB_AnSequence(a0)
			bne.s	.x
  			jmp	SwitchObjectOff
.x			rts

		
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί LOW JUMPING LIGHTS CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnPatternLIGHT	move.w	#LowLight_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.n1
			move.w	#LowLight_OB,OB_Type(a1)
			move.w	#$6e,OB_Ypos(a1)
			move.b	#3,OB_Var1(a1)
.n1			move.w	#LowLight_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.n2
			move.w	#LowLight_OB,OB_Type(a1)
			move.w	#$6e,OB_Ypos(a1)
			move.b	#2,OB_Var1(a1)
.n2			move.w	#LowLight_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.n3
			move.w	#LowLight_OB,OB_Type(a1)
			move.w	#$6e,OB_Ypos(a1)
			move.b	#1,OB_Var1(a1)
.n3			move.w	#LowLight_MAX_Size,d3
			bsr	EnergizerSpawnOb
			bpl.s	.n4
			move.w	#$78,OB_Ypos(a1)
			move.w	#LowLight_OB,OB_Type(a1)
			clr.b	OB_Var1(a1)
.n4			SFX	111
			rts			


LowLightANM_TAB		dc.l	L5LowLightMountANM,L5LowLight1ANM,L5LowLight2ANM,L5LowLight3ANM	
LowLightXSUB_TAB	dc.w	$06a0,$0700,$0760,$07c0

LowLight_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.b	#SubwayLightHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			move.l	#-1,OB_OffRoutine(a0)
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			asl.b	#1,d1
			move.w	LowLightXSUB_TAB(pc,d1.w),OB_Var2(a0)
			asl.b	#1,d1
			move.l	LowLightANM_TAB(pc,d1.w),a1
			jsr	SetNewAnim
			asl.w	#2,d1				;set start pos
			move.w	map_x_p,d2
			add.w	#54*8,d2
			add.w	d1,d2				;use light # to stagger x pos
			move.w	d2,OB_Xpos(a0)
 			move.w	OB_Xpos(a0),OB_WXpos(a0)
			clr.l	OB_Var3(a0)
			move.b	#$50,OB_Var5(a0)
			rts

.ok			move.w	OB_WXpos(a0),d1
			moveq	#0,d2
			move.w	OB_Var2(a0),d2
			tst.b	OB_Var5(a0)
			bne.s	.1
  			move.w	#$0700,d2
			bra	.2
.1			subq.b	#1,OB_Var5(a0)
.2			add.l	d2,OB_Var3(a0)
			move.l	OB_Var3(a0),d3
			lsr.l	#8,d3
			sub.w	d3,d1
			move.w	d1,OB_Xpos(a0)
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BREAKTHRU SKYLIGHT CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

L5Skylight_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			beq.s	.1
			jmp	SwitchObjectOff
.1			bset.b	#ob_setup,OB_Flag2(a0)
			add.w	#$18,OB_Xpos(a0)
			sub.w	#$10,OB_Ypos(a0)
			clr.b	OB_Var1a(a0)
			lea	L5SkylightANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelSkylights,a1
			tst.b	0(a1,d1.w)
			beq.s	.x
			SFX	49
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			move.w	d1,TempX
			move.w	d2,TempY
			moveq	#6,d7
			move.w	#MaxDebris,d3		   			;# of debris peices (NOTE: d1/d2 should comntain x,y)
			jsr	SetRandomDebris
			jmp	HandleEnemyKilled
.x			rts

; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί BREAKTHRU DOOR CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

L5Wall_Logic		btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelWalls,a1
			tst.b	0(a1,d1.w)
			beq.s	.1a
			jmp	SwitchObjectOff
.1a			move.b	#_ob_setup+_ob_hiprior,OB_Flag2(a0)
			sub.w	#$e,OB_Ypos(a0)
			lea	L5DoorANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			lea	LevelWalls,a1
			moveq	#0,d1
			move.b	OB_Var1(a0),d1
			tst.b	0(a1,d1.w)
			beq.s	.x
			
			move.w	OB_Xpos(a0),d1
			sub.w	Plr_XPos,d1
			bmi.s	.1
			moveq	#0,d4
			bra	.2
.1			moveq	#1,d4

.2			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			add.w	#$8,d2
			move.w	d1,TempX
			move.w	d2,TempY
			moveq	#3,d3
			jsr	WallDebris
			
			SFX 	34

			jmp	HandleEnemyKilled
.x			rts			


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ELECTRICITY GENERATOR CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

ElecGenerator_Logic	tst.b	TunnelFLG
			beq.s	.y
			cmp.b	#3,TunnelFLG
			bgt.s	.y
			rts

.y			addq.b	#1,OB_Var1(a0)
			and.b	#$1f,OB_Var1(a0)
			beq.s	SpawnElectricity
			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί ELECTRICITY FLUFF CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnElectricity	move.l	a0,-(sp)
			SPAWN_HI	Electricity_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#Electricity_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			clr.w	OB_Var1(a1)
			clr.w	OB_Var2(a1)
			rts
.no			move.l	(sp)+,a0
			rts			

Electricity_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			SFX	14
			sub.w	#$20,OB_Ypos(a0)
			add.w	#$10,OB_Xpos(a0)
			eor.b	#1,ElecSideTOG
			beq.s	.r
.l			bset.b	#ob_xflp,OB_Flag1(a0)
			subq.w	#2,OB_Xpos(a0)
			bra	.1
.r			bclr.b	#ob_xflp,OB_Flag1(a0)
			addq.w	#2,OB_Xpos(a0)
.1			clr.b	OB_Var1(a0)
			move.b	#$1d,OB_Var1a(a0)
			clr.b	OB_Var2(a0)
			lea	L5ElecBarANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.ok			tst.b	OB_Var1(a0)
			beq.s	.bar

.ball			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	OB_Var1(a0)
			move.b	#$1d,OB_Var1a(a0)
			eor.b	#_ob_xflp,OB_Flag1(a0)
			sub.w	#$a,OB_Ypos(a0)
			lea	L5ElecBarANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

.bar			subq.b	#1,OB_Var1a(a0)
			bne.s	.b1
			tst.b	OB_Var2(a0)
			beq.s	.b2
			jmp	SwitchObjectOff
.b2			st.b	OB_Var2(a0)
			st.b	OB_Var1(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.br
			subq.w	#2,OB_Xpos(a0)
			bra	.b3
.br			addq.w	#2,OB_Xpos(a0)
.b3			addq.w	#1,OB_Ypos(a0)
			lea	L5ElecBallANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.b1			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.ur
.ul			subq.w	#2,OB_Xpos(a0)
			bra	.2
.ur			addq.w	#2,OB_Xpos(a0)
.2			subq.w	#2,OB_Ypos(a0)
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί WASP GENERATOR CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

WaspGenerator_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			clr.w	OB_Var1(a0)
			rts

.ok			subq.w	#1,OB_Var1(a0)
			bpl.s	.x
			move.w	#$c0,OB_Var1(a0)
.y			cmp.b	#MaxRobotCount-1,GeneratedRobotCNT
			blt.s	.1
.x			rts
.1			jsr	Randy
			and.b	#1,d6
			bne.s	.x
			move.l	a0,-(sp)
			SPAWN_HI	WaspBot_MAX_Size
			bpl.s	.no
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#WaspBot_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			sub.w	#$10,OB_Ypos(a1)
			clr.w	OB_Var1(a1)
			clr.w	OB_Var2(a1)
			move.l	#GeneratedRobotOff,OB_OffRoutine(a1)
			addq.b	#1,GeneratedRobotCNT
.o1			rts
.no			move.l	(sp)+,a0
			rts			


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί TUNNEL EDGE CONTROL LOGIC						   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnTunnelEdge		move.w	#TunnelEdge_MAX_Size,d3
			jsr	VRamAlloc_BF			;allocate the VRAM
			bpl.s	.x
			move.w	d3,WEIGHT_VRAM_L		;save length of block
			move.w	d1,WEIGHT_VRAM_A		;save address of block
			lsr.w	#5,d1				;/32
			move.w	d1,WEIGHT_VRAM_Adiv32		;save address/32 of block
			lea	L5TunnelEdgeANM,a1		;set anim
			move.w	WEIGHT_VRAM_A,d1		;address in VRAM to DMA to
			move.w	WEIGHT_VRAM_L,d2		;length  of DMA block
			jmp	ResidentObjectDMA		;do initial DMA
.x			rts

SetupTunnelEdge		move.w	#$30,TempY
			move.w	#(62*8)+4,TempX
			move.l	a0,-(sp)
			moveq	#6,d1
.l1			jsr	GetFreeOBJECT_HI 			;get a free object
			bpl	.no
			jsr	SetupObject
			jsr	GetObRAMTab				;get table for objects RAM info (a2)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bclr.b	#ob_flown,OB_Flag3(a0)			;set this object resident
			bset.b	#ob_noscroll,OB_Flag5(a0)		;does scroll effect object
			move.w	#TunnelEdge_OB,OB_Type(a0)
			move.w	TempX,OB_Xpos(a0)
			move.w	TempY,OB_Ypos(a0)
			tst.b	TunnelEdgeFlipFLG
			beq.s	.ok
			bset.b	#ob_xflp,OB_Flag1(a0)
			add.w	#$20,OB_Xpos(a0)				
.ok			add.w	#$20,TempY
			dbra	d1,.l1
			move.l	(sp)+,a0
			rts
.no			move.l	(sp)+,d1
			move.l	(sp)+,a0
			rts

TunnelEdge_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	OB_RefAnRam(a0),a2
			move.w	WEIGHT_VRAM_L,_VRAM_L(a2)		;save length of block
			move.w	WEIGHT_VRAM_A,_VRAM_A(a2)		;save address of block
			move.w	WEIGHT_VRAM_Adiv32,_VRAM_Adiv32(a2)	;save address/32 of block
			clr.w	OB_Var1(a0)
			lea	L5TunnelEdgeANM,a1				;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim

.ok			sub.w	#$10,OB_Xpos(a0)
			bpl.s	.x
			jmp	SwitchObjectOff
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί FOREGROUND FLUFF POST CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnForegroundPost	move.w	#ForegroundPost_MAX_Size,d3
			jsr	VRamAlloc_BF			;allocate the VRAM
			bpl.s	.x
			move.w	d3,FPOST_VRAM_L			;save length of block
			move.w	d1,FPOST_VRAM_A			;save address of block
			lsr.w	#5,d1				;/32
			move.w	d1,FPOST_VRAM_Adiv32		;save address/32 of block
			lea	L5ForegroundPostANM,a1		;set anim
			move.w	FPOST_VRAM_A,d1			;address in VRAM to DMA to
			move.w	FPOST_VRAM_L,d2			;length  of DMA block
			jmp	ResidentObjectDMA		;do initial DMA
.x			rts

SetupForegroundPost	move.w	#$30,TempY
			move.w	#64*8,TempX
			move.l	a0,-(sp)
			moveq	#6,d1
.l1			jsr	GetFreeOBJECT_HI 			;get a free object
			bpl	.no
			jsr	SetupObject
			jsr	GetObRAMTab				;get table for objects RAM info (a2)
			bset.b	#ob_noclip,OB_Flag1(a0)			;clipping off
			move.b	#_ob_hiprior+_ob_nooff,OB_Flag2(a0)
			bclr.b	#ob_flown,OB_Flag3(a0)			;set this object resident
			bset.b	#ob_noscroll,OB_Flag5(a0)		;does scroll effect object
			move.w	#ForegroundPost_OB,OB_Type(a0)
			move.w	TempX,OB_Xpos(a0)
			move.w	TempY,OB_Ypos(a0)
			add.w	#$20,TempY
			dbra	d1,.l1
			move.l	(sp)+,a0
			rts
.no			move.l	(sp)+,d1
			move.l	(sp)+,a0
			rts

ForegroundPost_Logic	btst.b	#ob_setup,OB_Flag2(a0)
			bne	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			move.l	OB_RefAnRam(a0),a2
			move.w	FPOST_VRAM_L,_VRAM_L(a2)		;save length of block
			move.w	FPOST_VRAM_A,_VRAM_A(a2)		;save address of block
			move.w	FPOST_VRAM_Adiv32,_VRAM_Adiv32(a2)	;save address/32 of block
			clr.w	OB_Var1(a0)
			lea	L5ForegroundPostANM,a1				;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim

.ok			sub.w	#$c,OB_Xpos(a0)
			and.w	#$3ff,OB_Xpos(a0)
			move.w	OB_Xpos(a0),ForegroundPostX
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VIKING SORCERER BOSS CONTROL LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

		StRESET
		StDEF	SorcerStartupSTATE
		StDEF	SorcerIdleSTATE
		StDEF	SorcerSwingSTATE
		StDEF	SorcerCallLightSTATE
		StDEF	SorcerRezzingSTATE
		StDEF	SorcerHitSTATE
		StDEF	SorcerThrownSTATE
		StDEF	SorcerThrownReleaseSTATE
		StDEF	SorcerThrownFallSTATE
		StDEF	SorcerHitWallSTATE
		StDEF	SorcerDeadSTATE

Sorcerer_Logic		btst.b	#ob_setup,OB_Flag2(a0)			;initial setups
			bne.s	.1
			bset.b	#ob_setup,OB_Flag2(a0)
			st.b	PlayingBOSS
			clr.b	BossDefeatedFLG
			move.l	a0,Boss_Database			;boss' database
			move.w	#CastleBOSS_NRG,OB_Nrg(a0)
			move.w	OB_Nrg(a0),d1
			move.w	d1,BossEnergy
			lsr.w	#5,d1
			move.w	d1,BossPercentile
			move.l	#SorcerSetHits,OB_HitRoutine(a0)
			st.b	BossFirstPass
			bra	SorcerSetStartup
			
.1			jsr	HandleBeingHit				;Generic handle hit rout
    
			move.w	OB_State(a0),d1
			jmp	SorcerLogicTable(pc,d1.w)		;jump table

SorcerLogicTable	bra	SorcerStartupLOGIC
			bra	SorcerIdleLOGIC
			bra	SorcerSwingLOGIC
			bra	SorcerCallLightLOGIC
			bra	SorcerRezzingLOGIC
			bra	SorcerHitLOGIC
			bra	SorcerThrownLOGIC
			bra	SorcerThrownReleaseLOGIC
			bra	SorcerThrownFallLOGIC
			bra	SorcerHitWallLOGIC
			bra	SorcerDeadLOGIC

			
; - Viking Sorcerer Hit --------------------------------------------------

SorcerSetHits		move.b	OB_Flag6(a0),d2
			jsr	ClrHitStuff
			clr.b	SorcererCallingFLG

			move.l	Plr_Database,a1
			cmp.w	#GolGroundGrabSTATE,OB_State(a1)
			bne.s	.1
			tst.b	RapBotThrownFLG
			bne.s	.1
			btst.b	#grabmode,OB_MasterMode(a1)
			bne	SorcerSetThrown

.1			btst	#ob_hit_small,d2
			bne.s	SorcerSetHit
			btst	#ob_hit_med,d2
			bne.s	SorcerSetHit
			btst	#ob_hit_big,d2
			bne.s	SorcerSetHit
			rts

SorcerSetHit		move.w	#SorcerHitSTATE,OB_State(a0)
			jsr	MakeNmeFacePlayer
			SFX	16
			move.w	#MediumHitSlideAMT,OB_Var1(a0)
			clr.w	OB_Var2(a0)
			lea	SorcerHitANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerHitLOGIC		tst.w	OB_Var1(a0)
			bne.s	.2
			btst.b	#ob_dead,OB_Flag2(a0)
			beq	SorcerSetRezOut
			bra	SorcerSetDead

.2			move.w	OB_Var1(a0),d1
			btst.b	#ob_hitside,OB_Flag1(a0)
			beq.s	.3
			jsr	MoveGolLeft_NF_Smooth
			clr.b	walking_right
			st.b	walking_left
			bra	.4
.3			jsr	MoveGolRight_NF_Smooth
			st.b	walking_right
			clr.b	walking_left
.4			addq.b	#1,OB_Var2(a0)
			and.b	#3,OB_Var2(a0)
			bne.s	.1
  			subq.w	#1,OB_Var1(a0)
.1			rts



; - Throw Routines ---------------------------------------------------------

SorcerSetThrown		move.w	#SorcerThrownSTATE,OB_State(a0)
			;SFX	10
			move.b	#10,OB_Var4(a0)
			st.b	RapBotThrownFLG
			btst.b	#ob_xflp,Plr_Flag1			;make sure enemy faces right way
			beq.s	.1
			bclr.b	#ob_xflp,OB_Flag1(a0)
			bra	.2
.1			bset.b	#ob_xflp,OB_Flag1(a0)
.2			lea	SorcerGrabANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim


SorcerThrownLOGIC	tst.b	GolThrowReleaseFLG
			bne	SorcerSetThrownRelease
			tst.b	GolSlamFLG
			bne	SorcerSetThrownRelease
			
			tst.b	OB_Var4(a0)
			beq.s	.y1
   			subq.b	#1,OB_Var4(a0)
			rts
.y1			move.w	GolThrowXPos,OB_Xpos(a0)
			move.w	GolThrowYPos,OB_Ypos(a0)
			add.w	#8,OB_Ypos(a0)
			rts


; - Logic ------------------------------------------------------------------

SorcerSetThrownRelease	move.w	#SorcerThrownReleaseSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			move.w	#4,OB_Var2(a0)
			lea	SorcerThrownANM,a1			;set anim
			jsr	SetNewAnim

SorcerThrownReleaseLOGIC
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	SorcerSetHitWall
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	SorcerSetHitWall
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightFLP3
			addq.b	#1,OB_Var1a(a0)				
			and.b	#3,OB_Var1a(a0)				
			bne.s	.3					
			subq.w	#1,OB_Var2(a0)				;decrease upward velocity				
			beq	SorcerSetThrownFall
.3			move.w	OB_Var2(a0),d1				;get speed
			jmp	MoveGolUp_Smooth			;move up


; - Sorcerer falls from thrown --------------------------------------------

SorcerSetThrownFall	move.w	#SorcerThrownFallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			lea	SorcerThrownFallANM,a1			;set anim
			jmp	SetNewAnim

SorcerThrownFallLOGIC	jsr	GetUnderNME
			
			moveq	#0,d2
			btst.b	#ob_xflp,OB_Flag1(a0)
			beq.s	.r
.l			move.b	NUnderLEFT,d2
			or.b	NUnderLEFTTOP,d2
			or.b	NUnderLEFTBOT,d2
			bmi	SorcerSetHitWall
			bra	.lr	
.r			move.b	NUnderRIGHT,d2
			or.b	NUnderRIGHTTOP,d2
			or.b	NUnderRIGHTBOT,d2
			bmi	SorcerSetHitWall
.lr			moveq	#3,d1
			jsr	MoveGolLeftRightFLP3		

			addq.b	#1,OB_Var1(a0)
			and.b	#3,OB_Var1(a0)
			bne.s	.1
			addq.b	#1,OB_Var1a(a0)
.1			moveq	#0,d1
			move.b	OB_Var1a(a0),d1
		
			jsr	MoveGolDown_Smooth
			jsr	TestLand
			bmi	SorcerSetRezOut
			rts


; - Sorcerer hits a wall ---------------------------------------------------

SorcerSetHitWall	move.w	#SorcerHitWallSTATE,OB_State(a0)
			clr.w	OB_Var1(a0)
			clr.w	OB_Var2(a0)
			clr.b	OB_EventVar1(a0)
			and.w	#$fff8,OB_Xpos(a0)
			btst.b	#ob_xflp,OB_Flag1(a0)
			bne.s	.1
.l			add.w	#$10,OB_Xpos(a0)
.1			lea	SorcerHitWallANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerHitWallLOGIC	tst.b	OB_Var1(a0)
			beq.s	.hit
			
.fall			jsr	TestLand
			bmi.s	SorcerSetDead
			
			cmp.b	#6,OB_Var2a(a0)
			beq.s	.1
			addq.b	#1,OB_Var2(a0)
			and.b	#3,OB_Var2(a0)
			bne.s	.1
			addq.b	#1,OB_Var2a(a0)
		
.1			moveq	#0,d1
			move.b	OB_Var2a(a0),d1
			jmp	MoveGolDown_Smooth

.hit			tst.b	OB_EventVar1(a0)
			beq.s	.x
			btst.b	#ob_dead,OB_Flag2(a0)
			beq	SorcerSetRezOut
			st.b	OB_Var1(a0)
.x			rts


; - Sorcerer Dead ----------------------------------------------------------

SorcerSetDead		move.w	#SorcerDeadSTATE,OB_State(a0)
			st.b	BossDefeatedFLG
			move.b	#8,OB_Var1(a0)
			move.l	a0,TrackObjectDatabase
			move.w	d0,TrackObjectNumber
			clr.b	SorcererCallingFLG
			
			move.w	#LightningTop_OB,d2
			jsr	FindObject
			bpl.s	.1
			jsr	SwitchObjectOffA1
.1			move.w	#LightningBot_OB,d2
			jsr	FindObject
			bpl.s	.2
			jsr	SwitchObjectOffA1
			
.2			lea	SorcerDeadANM,a1			;set anim
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerDeadLOGIC  	tst.l	OB_AnSequence(a0)
			bne.s	.1
			lea	SorcerDeadANM,a1			;set anim
			jsr	SetNewAnim
			jsr	ForceNewAnim
			tst.b	SorcererCallingFLG
			bne.s	.1
			subq.b	#1,OB_Var1(a0)
			beq.s	.fin
			st.b	SorcererCallingFLG
			move.w	OB_Xpos(a0),d1
			move.w	OB_Ypos(a0),d2
			bra	SpawnLightning
.1			rts
.fin			st.b	NextLevelFLG
			jmp	SwitchObjectOff


; - Viking Sorcerer Logic --------------------------------------------------

SorcerSetStartup	move.w	#SorcerStartupSTATE,OB_State(a0)
			move.b	#$80,OB_Var1(a0)	
			clr.b	OB_Var1a(a0)
			move.w	#$108,OB_Xpos(a0)
			move.w	#$1c7-8,OB_Ypos(a0)
			lea	SorcerBlankANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerStartupLOGIC	tst.b	OB_Var1a(a0)
			bne.s	.1
			subq.b	#1,OB_Var1(a0)
			bne.s	.x
			st.b	OB_Var1a(a0)
			jsr	WhitePalette
			moveq	#1,d1	       				;fast fade to proper palette
			lea	GamePalette,a1
			move.w	#def_blkwhtin,d2
			jsr	set_whitein	
			lea	SorcerDeRezANM,a1
			jsr	SetNewAnim
			jsr	ForceNewAnim
			move.w	#$108,d1					;spawn lightning
			move.w	#$1c6-8,d2
			bsr	SpawnLightning
			lea	SorcerWaitANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.x			rts	

.1			tst.l	OB_AnSequence(a0)
			beq	SorcerSetIdle
			rts


; - Viking Sorcerer Logic --------------------------------------------------

SorcerSetIdle		move.w	#SorcerIdleSTATE,OB_State(a0)
			lea	SorcerIdleANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerIdleLOGIC		move.w	#$60,d1				;if player get too far away on the y
			jsr	TestProxY			;then sorcerer rezzes out and finds a closer
			bpl	SorcerSetRezOut			;platform

			tst.l	OB_AnSequence(a0)
			bne.s	.x
			
			move.w	#$30,d1
			jsr	TestProxX
			bpl.s	.1
			move.w	#$20,d1
			jsr	TestProxY
			bmi	SorcerSetSwing
			
.1			jsr	Randy
			and.b	#$3f,d6
			beq.s	.a
			cmp.b	#1,d6
			beq.s	SorcerSetIdle
.a			tst.b	SorcererCallingFLG
			bne.s	.x
			bra	SorcerSetCallLight
.x			rts


; - Viking Sorcerer Logic --------------------------------------------------

SorcerSetSwing		move.w	#SorcerSwingSTATE,OB_State(a0)
			clr.b	SorcererCallingFLG
			jsr	MakeNmeFacePlayer
			move.b	#SorHammerAttkHitPOWER,OB_HitPower(a0)
			jsr	SetBigAttack
			clr.b	OB_Var1(a0)
			move.b	#$10,OB_Var1a(a0)
			rts
			
SorcerSwingLOGIC	tst.b	OB_Var1a(a0)
			beq.s	.y1
			subq.b	#1,OB_Var1a(a0)
			bne.s	.x
			SFX	22
			lea	SorcerSwingANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim
.y1			tst.l	OB_AnSequence(a0)
			beq	SorcerSetIdle
.x			rts


; - Viking Sorcerer Logic --------------------------------------------------

SorcerSetCallLight	move.w	#SorcerCallLightSTATE,OB_State(a0)
			clr.b	OB_EventVar1(a0)
			clr.b	OB_Var1(a0)
			st.b	SorcererCallingFLG
			move.w	Plr_XPos,TempX
			move.w	Plr_YPos,TempY
			
			lea	SorcerCallLightANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim

SorcerCallLightLOGIC	move.w	#$30,d1
			jsr	TestProxX
			bpl.s	.2
			move.w	#$20,d1
			jsr	TestProxY
			bpl.s	.2
			jsr	Randy
			and.b	#$f,d6
			beq	SorcerSetSwing
			
.2			tst.b	OB_Var1(a0)
			bne.s	.1
			tst.b	OB_EventVar1(a0)
			beq.s	.x
			clr.b	OB_EventVar1(a0)
			st.b	OB_Var1(a0)
			bra	SpLi2

.1			tst.l	OB_AnSequence(a0)
			beq	SorcerSetIdle
.x			rts


; - Viking Sorcerer Logic --------------------------------------------------

SorcerSetRezIn		clr.b	OB_Var1(a0)
			SFX	125
			bra	SSR2
SorcerSetRezOut		cmp.w	#$1a8,Plr_YPos
			bgt.s	.y1
			rts
.y1			SFX	31
			st.b	OB_Var1(a0)
SSR2			move.w	#SorcerRezzingSTATE,OB_State(a0)
			lea	SorcerDeRezANM,a1
			jsr	SetNewAnim
			jmp	ForceNewAnim


SorcerRezzingLOGIC	tst.l	OB_AnSequence(a0)
			beq.s	.ok
.x			rts

.ok			tst.b	OB_Var1(a0)
			beq	SorcerSetIdle
			
.rezout			cmp.w	#$258,Plr_YPos
			bgt.s	.low
			cmp.w	#$218,Plr_YPos
			bgt.s	.mid
			cmp.w	#$1c8,Plr_YPos
			ble.s	.mid
.hi			move.w	#$108,OB_Xpos(a0)
			move.w	#$1c7-8,OB_Ypos(a0)
			bra	SorcerSetRezIn
.mid			move.w	#$7a,OB_Xpos(a0)
			move.w	#$217-8,OB_Ypos(a0)
			bra	SorcerSetRezIn
.low			move.w	#$f4,OB_Xpos(a0)
			move.w	#$257-8,OB_Ypos(a0)
			bra	SorcerSetRezIn

; - Viking Sorcerer Logic --------------------------------------------------


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί VIKING SORCERER BOSS' LIGHTNING CONTROL LOGIC			   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

SpawnLightning		move.w	d1,TempX
			move.w	d2,TempY

SpLi2			move.l	a0,-(sp)
			SPAWN_HI	LightningBot_MAX_Size
			bpl	.2
			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#LightningBot_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_nooffy,OB_Flag2(a1)
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			move.w	OB_Xpos(a1),OB_WXpos(a1)
			move.b	#SorLightningHitPOWER,OB_HitPower(a1)
			jsr	SetBigAttackA1
			lea	LightningBotANM,a2
			jsr	SetNewAnimA1
			jsr	ForceNewAnimA1
			jsr	LightenPalette
			move.l	a0,-(sp)
			SPAWN_HI	LightningTop_MAX_Size
			bpl.s	.2
			move.l	a0,a1
			move.l	(sp)+,a0
			move.l	a1,LightningTopOB
			move.w	#LightningTop_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_nooffy,OB_Flag2(a1)
			move.w	TempX,OB_Xpos(a1)
			move.w	TempY,OB_Ypos(a1)
			sub.w	#$92,OB_Ypos(a1)
			lea	LightningTopANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
.2			move.l	(sp)+,a0
			rts

LightningTop_Logic	rts

LightningBot_Logic	jsr	Randy
			and.b	#$f,d7
			bne.s	.1
 			and.w	#$f,d6
			move.w	OB_WXpos(a0),d1
			btst	#0,d6
			beq.s	.r
.l			sub.w	d6,d1
			bra	.lr
.r			add.w	d6,d1
.lr			move.l	LightningTopOB,a1
			move.w	d1,OB_Xpos(a0)
			move.w	d1,OB_Xpos(a1)
			eor.b	#_ob_xflp,OB_Flag1(a0)
			eor.b	#_ob_xflp,OB_Flag1(a1)
			jsr	SetSmallAirExplodeAtOB_XY
			jsr	Randy
			and.l	#1,d6
			add.l	#95,d6
			move.l	d6,sfx_poll
			jsr	SetSFX
			jmp	LightenPalette

.1			tst.l	OB_AnSequence(a0)
			bne.s	.x
			clr.b	SorcererCallingFLG
			move.l	LightningTopOB,a1
			jsr	SwitchObjectOff
			jmp	SwitchObjectOffA1
.x			rts


; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EYE OF ODIN/SKYLIGHT SEQUENCE LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

EyeRooftopUp_Logic	tst.b	EyeRooftopUpDoneFLG
			bne.s	.x

			btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_nooff,OB_Flag2(a0)
			bsr	SpawnEyeOfOdin
			add.w	#$30,OB_Xpos(a1)
			add.w	#$30,OB_Ypos(a1)
			move.w	#EyeOfOdinRooftopUpSTATE,OB_State(a1)
			bclr.b	#ob_hiprior,OB_Flag2(a1)
			clr.w	OB_Var1(a1)
			move.b	#$98/4,	OB_Var2(a1)
			bsr	EyeSpawnSkylight
			sub.w	#4,OB_Xpos(a1)
			rts

.ok			tst.b	EyeRooftopUpTRG
			beq.s	.x
			SFX	55
			st.b	EyeRooftopUpFLG
			st.b	EyeRooftopUpDoneFLG
.x			rts


EyeRooftopDn_Logic	tst.b	EyeRooftopDnDoneFLG
			bne.s	.x
			
			btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.ok
			bset.b	#ob_setup,OB_Flag2(a0)
			bset.b	#ob_nooff,OB_Flag2(a0)
			bsr	SpawnEyeOfOdin
			add.w	#$30,OB_Xpos(a1)
			sub.w	#$60,OB_Ypos(a1)
			move.w	#EyeOfOdinRooftopDnSTATE,OB_State(a1)
			bclr.b	#ob_hiprior,OB_Flag2(a1)
			clr.w	OB_Var1(a1)
			move.b	#$98/4,OB_Var2(a1)
			SFX	55
			bra	EyeSpawnSkylight

.ok			tst.b	EyeRooftopDnTRG
			beq.s	.x
			st.b	EyeRooftopDnFLG
			st.b	EyeRooftopDnDoneFLG
.x			rts
	       

EyeSpawnSkylight	clr.b	EyeRooftopSmashFLG
			
			move.l	a0,-(sp)
			SPAWN_HI	SkyLight_MAX_Size
			bmi.s	.ok
			move.l	(sp)+,a0
			rts
.ok			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#SkyLight_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_hiprior,OB_Flag2(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			bset.b	#ob_setup,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			add.w	#$3b,OB_Xpos(a1)
			subq.w	#$8,OB_Ypos(a1)
			clr.b	OB_Var1a(a1)
			st.b	OB_Var4(a1)
			lea	SkyLightANM,a2
			jsr	SetNewAnimA1
			jmp	ForceNewAnimA1
			
			
; ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ»
; Ί EYE OF ODIN RAPTOR GENERATOR LOGIC					   Ί
; ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ

EyeRaptor_Logic		moveq	#0,d1
			move.b	OB_Var1(a0),d1
			lea	LevelEyeRaptors,a1
			tst.b	0(a1,d1.w)
			bne.s	.x
			btst.b	#ob_setup,OB_Flag2(a0)
			bne.s	.x
			bset.b	#ob_setup,OB_Flag2(a0)
			bsr	SpawnEyeOfOdin
			move.w	OB_Var1(a0),OB_Var1(a1)
			move.w	#EyeOfOdinRaptorSTATE,OB_State(a1)
			bclr.b	#ob_nooff,OB_Flag2(a1)
			bclr.b	#ob_hiprior,OB_Flag2(a1)
			clr.w	OB_Var5(a1)
			SFX	55
.x			rts


SetupEyeRaptorRaptor	move.l	a0,-(sp)
			SPAWN_HI	RaptorBot_MAX_Size
			bmi.s	.1
			move.l	(sp)+,a0
    			rts
.1			move.l	a0,a1
			move.l	(sp)+,a0
			move.w	#RaptorBot_OB,OB_Type(a1)
			bset.b	#ob_tidy,OB_Flag5(a1)
			bset.b	#ob_nooff,OB_Flag2(a1)
			move.w	OB_Xpos(a0),OB_Xpos(a1)
			move.w	OB_Ypos(a0),OB_Ypos(a1)
			move.w	#RaptorBot_NRG,OB_Nrg(a1)
			move.b	#-3,OB_Var1(a1)
			rts
			
