start	= 0

 *
 *         TURRICAN III AMIGA	
 * (C) 1992,93 SOFTGOLD/RAINBOW ARTS
 * (P) 1992,93 NEON
 *
 * original version (p) 1992  FACTOR 5
 * original GFX & co-design   KAIKO
 * original Music-score & SFX KAIKO
 * original Characters        Manfred Trenz
 *
 * started :        12-12-1992
 * finishing date : 14- 4-1993 ???
 *

SONGPLAY:		MACRO
	moveq	\1,d0
	jsr	Play_Song
	ENDM

SONGCONT:		MACRO
	moveq	#0,d0
	jsr	TFMX+72
	moveq	\1,d0
	jsr	Cont_Song
	ENDM

PLAY_FX:		MACRO
	moveq	\1,d0
	bsr	Do_FX
	ENDM

	INCDIR	work:sources/t3/areas

	;/* Hardware-include-file      */
	;/* (p) 1990 by Peter Thierolf */

custom	= $dff000

bltddat	= $000
dmaconr	= $002
vposr	= $004
vhposr	= $006
dskdatr	= $008
joy0dat	= $00a
joy1dat	= $00c
clxdat	= $00e
adkconr	= $010
pot0dat	= $012
pot1dat	= $014
potgor	= $016
serdatr	= $018
dskbytr	= $01a
intenar	= $01c
intreqr	= $01e
dskpth	= $020
dskptl	= $022
dsklen	= $024
dskdat	= $026
refptr	= $028
vposw	= $02a
vhposw	= $02c
copcon	= $02e
serdat	= $030
serper	= $032
potgo	= $034
joytest	= $036
strequ	= $038
strvbl	= $03a
strhor	= $03c
strlong	= $03e
bltcon0	= $040
bltcon1	= $042
bltafwm	= $044
bltalwm	= $046
bltcpth	= $048
bltcptl	= $04a
bltbpth	= $04c
bltbptl	= $04e
bltapth	= $050
bltaptl	= $052
bltdpth	= $054
bltdptl	= $056
bltsize	= $058

bltcmod	= $060
bltbmod	= $062
bltamod	= $064
bltdmod	= $066

bltcdat	= $070
bltbdat	= $072
bltadat	= $074

dsksync	= $07e
cop1lch	= $080
cop1lcl	= $082
cop2lch	= $084
cop2lcl	= $086
copjmp1	= $088
copjmp2	= $08a
copins	= $08c
diwstrt	= $08e
diwstop	= $090
ddfstrt	= $092
ddfstop	= $094
dmacon	= $096
clxcon	= $098
intena	= $09a
intreq	= $09c
adkcon	= $09e

audlch	= $000
audlcl	= $002
audlen	= $004
audper	= $006
audvol	= $008
auddat	= $00a

aud0	= $0a0
aud1	= $0b0
aud2	= $0c0
aud3	= $0e0

bpl1pth	= $0e0
bpl1ptl	= $0e2
bpl2pth	= $0e4
bpl2ptl	= $0e6
bpl3pth	= $0e8
bpl3ptl	= $0ea
bpl4pth	= $0ec
bpl4ptl	= $0ee
bpl5pth	= $0f0
bpl5ptl	= $0f2
bpl6pth	= $0f4
bpl6ptl	= $0f6

bplcon0	= $100
bplcon1	= $102
bplcon2	= $104

bpl1mod	= $108
bpl2mod	= $10a

bpl1dat	= $110
bpl2dat	= $112
bpl3dat	= $114
bpl4dat	= $116
bpl5dat	= $118
bpl6dat	= $11a

spr0pth	= $120
spr0ptl	= $122
spr1pth	= $124
spr1ptl	= $126
spr2pth	= $128
spr2ptl	= $12a
spr3pth	= $12c
spr3ptl	= $12e
spr4pth	= $130
spr4ptl	= $132
spr5pth	= $134
spr5ptl	= $136
spr6pth	= $138
spr6ptl	= $13a
spr7pth	= $13c
spr7ptl	= $13e

sprpos	= $000
sprctl	= $002
sprdata	= $004
sprdatb	= $006

spr0	= $140
spr1	= $148
spr2	= $150
spr3	= $158
spr4	= $160
spr5	= $168
spr6	= $170
spr7	= $178

color	= $180

	;/* Cia's */

ciaa	= $bfe001
ciab	= $bfd000

pra	= $000
prb	= $100
ddra	= $200
ddrb	= $300
talo	= $400
tahi	= $500
tblo	= $600
tbhi	= $700
todlo	= $800
todmid	= $900
todhi	= $a00
sdr	= $c00
icr	= $d00
cra	= $e00
crb	= $f00

TFMX	= $6ed20

BG_Chars	= $11300+32128

Rotate_Buffer	= $29a04

GameBpl0	= $40000
GameBpl1	= $50000
GameBpl2	= $60000

BSS_buffer	= GameBpl2+$b500

SpriteAdr	= $39a54
SpriteBuffer	= $334a8

RopeBob		= $5e380

level_Buffer	= $4d120
level_flip_len	= 10790

main_GFX	= $5b500	;$15f1c
main_Buffer	= level_Buffer+level_flip_len
main_flip_len	= 700

Score		= $5e400

Diamond_Font	= $5e080
TimeUpSpr	= $5f448
Beam_Sprites	= TimeUpSpr+288

Coll_Anker	= BSS_buffer		;Collision-Tables
Coll_Buffer	= BSS_buffer+16*4

parallax	= BSS_buffer+2000
parallax2	= parallax+208*2
parallax3	= parallax2+208*2
Rest_List1	= parallax3+32
Rest_List2	= Rest_List1+$600

Work_Buffer1	= Rest_List2+$600
Work_Buffer2	= Work_Buffer1+2116
Work_Buffer3	= Work_Buffer2+2116
Work_Buffer4	= Work_Buffer3+2116

;Joy-flags

;Byte 1

DOWN	= 0	;Runter
UP	= 1	;Hoch
LEFT	= 2	;Links
RIGHT	= 3	;Rechts
FIRE	= 4	;Schiessen
JUMP	= 5	;Springen
WHEEL	= 6	;Wheel auslsen
SMART	= 7	;Smartbomb auslsen

;Byte 2

ROPES	= 0	;Zielphase auslsen
ROPEKF	= 1	;Seil killen am Boden
ROPEKA	= 2	;Seil killen in der Luft
ROPEUP	= 3	;Seil verkrzen

planeb	=	40+4
planeh	=	208+4*16+20

MAX_ROPE	= 128
BOB_MAXIMUM	EQU	50
FLICKER		= 3

Jump_Prell	= 6
Jump_Speed2	= -$0006a800
Jump_Speed1	= -$00067800
Jump_Verz1	= $00004a00	; $00004c00
Jump_Verz2	= $00004900	; $00004c00
Fall_Prell	= 4

Bomb_Verz	= 10

Rocket_Verz	= 30

MINE_POWER	= 2
TARGET_VERZ	= 10
COPCOL		= $188

COLORTEST	= 0
SpeedCheck	= 0
BobTest		= 0
Level		= 0
NoHit		= 0
Real		= 1
Coords		= 0
CountBobs	= 0
OldScroll	= 0
DiamondTest	= 0
Keys		= 0
Press		= 1		;Presse-version ?

DATA_SCORE		= $200
DATA_LIFES		= $204
DATA_ALL_LIFES		= $206
DATA_DIAMONDS		= $208
DATA_ALL_DIAMONDS	= $20a
DATA_WORLD_CLEAR	= $20c
DATA_RAPID		= $20d
DATA_ACT_LIFES		= $20e
DATA_LEVEL		= $210	;Schwierigkeits-grad
DATA_CONTROL		= $211
DATA_WEAPONS		= $212
DATA_BIGCPU		= $222

	dc.l	$580
	IFNE	start
	dc.l	$580
	ELSEIF
	dc.l	0
	ENDC

	ORG	$580
Start:

	lea	BSS_buffer,a0
	move.w	#816,d0
.clear_bss:
	clr.l	(a0)+
	dbf	d0,.clear_bss

	clr.w	DATA_LIFES.w
	move.b	DATA_SCORE+1.w,T_score
	move.w	DATA_SCORE+2.w,T_score+1

	move.b	DATA_WEAPONS.w,T_power1
	move.b	DATA_WEAPONS+1.w,T_power2
	move.b	DATA_WEAPONS+2.w,T_power3
	move.b	DATA_WEAPONS+3.w,T_rocket
	move.b	DATA_WEAPONS+4.w,T_weapon
	move.b	DATA_WEAPONS+4.w,T_weapon_new
	move.b	DATA_WEAPONS+5.w,T_power_new
	sf	T_power

	IFEQ	start
	move.b	DATA_ACT_LIFES.w,T_lifes
	ENDC
	clr.l	Dol_Speed_X
	move.l	Act_Scr_Structure(pc),a6
	move.b	DATA_BIGCPU,Scr_BigCPU(a6)
	clr.l	Scr_X_Speed(a6)
	clr.l	Scr_Y_Speed(a6)
	move.w	#32,Scr_Y_Play_Anf(a6)
	move.w	#208+16,Scr_Y_Up_Supply(a6)
	move.w	#208+32,Scr_Y_Down_Supply(a6)

	lea	custom,a5
	bsr	Init_keys

	move.w	#$87e0,dmacon(a5)
	move.w	#$7fff,intena(a5)
	move.w	#$c008,intena(a5)
	move.w	#$0000,bltcon1(a5)

	bsr	init_score_line
	jsr	L_Init_World
	jsr	L_Copy_Colors
	jsr	TFMX+40

	cmp.b	#3,DATA_LEVEL.w
	bne.s	.no_maniac
	clr.w	DATA_ALL_LIFES.w
.no_maniac:
	move.l	#VBI,$6c
	move.w	#$c020,intena(a5)

	bsr	init_rnd

	clr.l	Rest_List1
	clr.l	Rest_List2

	move.w	T_time,T_time_def	;Speichern fr den nchsten Versuch

	;Player Sprites X-Flip.

	lea	SpriteAdr,a0		;Quell-adr
	lea	SpriteBuffer,a1		;Ziel-adr
	move.w	#s_len-1,d7		:Quell-len in Bytes.

	bsr	Flip_Sprites

	bsr	select_weapon

	move.b	#64,T_energy		;Volle Energie!
	move.w	#1024,T_wenergy		;Volle Energie!
	bsr	select_weapon
	sf	T_flash
	clr.l	T_speedY
	clr.b	T_rocket_anz
	sf	G_quit

	jsr	L_Next_Level

Init_Level:
	bsr	Do_Init_Level
	st	Col_Init_Flag

	bsr	Start_Beam

	move.b	O_energy,-(sp)
	move.b	O_wenergy,-(sp)

	move.b	T_energy,O_energy
	move.w	T_wenergy,d0
	lsr.w	#4,d0
	move.b	d0,O_wenergy

	st	Scr_No_Flicker(a6)

	bsr	game
	bsr	game
	sf	Col_Init_Flag

	sf	Scr_No_Flicker(a6)

	move.b	(sp)+,O_wenergy
	move.b	(sp)+,O_energy

	clr.w	Fade_Position
	moveq	#1,d0
	jsr	L_Fade_Colors
GameLoop:
.wait_tof:
	move.l	vposr(a5),d0
	and.l	#$1ff00,d0
	cmp.l	#$10100,d0
	blt.s	.wait_tof
	cmp.l	#$12000,d0
	bgt.s	.wait_tof

	sf	VBI_Flag
	bsr	game
.wait_vbi:
	tst.b	VBI_Flag
	beq.s	.wait_vbi

	tst.b	G_quit
	bne	.quit

	tst.b	T_dead
	beq.s	.no_dead
	subq.b	#1,T_dead
	bne	.no_dead
	tst.w	T_time
	beq	.time_up_dead
.player_dead:
	move.l	Dead_Vector(pc),a0
	jmp	(a0)
.no_dead:

	tst.w	T_time
	bne.s	.no_time_up
	sf	T_rope		;Alles clearen,Player stirbt!
	sf	T_swing
	sf	T_targeting
	sf	T_energy
	st	T_freeze
	clr.w	T_joyforce
.no_time_up:
	tst.b	Cue_Point+1
	bpl.s	.no_clear
	tst.b	VBI_count
	beq.s	.level_clear
.no_clear:
	bsr	do_pause

	bra	.wait_tof

.level_clear:
	move.w	#15,Fade_Position
	moveq	#-1,d0
	jsr	L_Fade_Colors

	move.w	#1024,T_wenergy		;Volle Energie!
	jsr	L_Next_Level
	tst.w	Cue_Point
	beq	Init_Level

	;Die Welt ist geschafft!

	st	DATA_WORLD_CLEAR.w

	bra	QUIT
.quit:
	bra	Game_over_in

.time_up_dead:
	lea	sprite_adr(pc),a1
	lea	sprite_pos(pc),a2

	move.l	#TimeUpSpr,d0

	moveq	#4-1,d7
.loop:
	move.l	d0,(a1)+
	clr.l	(a2)+
	add.l	#36,d0
	move.l	d0,(a1)+
	clr.l	(a2)+
	add.l	#36,d0
	add.l	#$00080000,d1

	dbf	d7,.loop

	bsr	.wait_frame

	lea	TimeUpColors(pc),a0
	lea	$dff1a2,a1
	moveq	#4-1,d7
.set_cols:
	move.w	(a0)+,(a1)+
	dbf	d7,.set_cols
	move.w	#$000,$dff1b8

	PLAY_FX	#$00
.wait_loop:
	bsr	.wait_frame

	move.l	Clist_Handler(pc),a0
	jsr	(a0)

	bsr	do_pause

	cmp.w	#265,time_up_xpos
	ble.s	.no_move
	subq.w	#8,time_up_xpos
	clr.l	help
	move.w	time_up_xpos,d0
	move.w	d0,d1
	lsr.w	#1,d1
	move.b	d1,help+1
	and.b	#1,d0
	move.b	d0,help+3
	move.l	help,d0
	or.l	#$90009780,d0
	lea	sprite_pos,a2
	moveq	#4-1,d7
.set_pos:
	move.l	d0,(a2)+
	move.l	d0,(a2)+
	add.l	#$00080000,d0
	dbf	d7,.set_pos
	bra	.wait_loop
.no_move:
	subq.b	#1,time_up_verz		;Lange genug angezeigt ?
	bne	.wait_loop
	move.b	#100,time_up_verz	;Initen frs nchste mal.
	move.w	#440,time_up_xpos

	lea	sprite_pos(pc),a2
	moveq	#7,d7
.clear1:
	clr.l	(a2)+
	dbf	d7,.clear1

	bsr	.wait_frame
	move.l	Clist_Handler(pc),a0
	jsr	(a0)

	bsr	.wait_frame
	move.l	Clist_Handler(pc),a0
	jsr	(a0)

	move.w	T_time_def(pc),T_time	;Das nchste mal mit neuer Zeit.

	bra	.player_dead

.wait_frame:
	sf	VBI_Flag
.do_wait:
	tst.b	VBI_Flag
	beq.s	.do_wait
	rts

do_pause:
	tst.b	pause_flag
	bne.s	.do_pause

	cmp.b	#$19,G_keycode
	bne.s	.no_pause
	clr.b	G_keycode
	st	pause_flag
	PLAY_FX	#$02
	move.l	#$00030000,d0
	jsr	TFMX+72
	tst.b	global_startsound
	beq.s	.no_sound
	move.b	global_stopsound,d0
	bsr	Do_FX
.no_sound:
.no_pause:
	rts
.do_pause:
	btst	#7,$bfe001
	beq.s	.stop_pause
	cmp.b	#$19,G_keycode		;P
	beq.s	.stop_pause

	cmp.b	#$45,G_keycode		;ESC
	beq.s	.stop_pause2

	cmp.b	#$40,G_keycode		;SPACE (Single-Step)
	bne.s	.do_pause
	clr.b	G_keycode
	rts

.stop_pause:
	clr.b	G_keycode
.stop_pause2:
	PLAY_FX	#$02
	move.l	#$00030040,d0
	jsr	TFMX+72

	move.b	global_startsound,d0
	beq.s	.no_sound2
	bsr	Do_FX
.no_sound2:

	clr.b	pause_flag
	rts

TimeUpColors:
	dc.w	$9a9,$bcb,$ded,$fff

time_up_xpos:	dc.w	440

time_up_verz:	dc.b	100
pause_flag:	dc.b	0
	even

Do_Init_Level:
	jsr	L_Init_Datas
	clr.l	Dol_Speed_X
	clr.l	Dol_Speed_Y
	clr.l	Dol_Speed_Y2
	clr.w	Accel_Flag_X
	clr.l	T_Ispeed_X
	clr.l	T_Ispeed_Y
	clr.l	T_speedY
	sf	T_rocket_anz
	sf	T_runout
	sf	T_freeze
	sf	T_shield
	sf	T_hit
	clr.w	T_joyforce
	sf	JoyFire
	sf	JoyReFire
	sf	Rapid_count1
	clr.w	JoyFlags

	sf	no_time
	sf	T_norope		;Seil zulassen!

	sf	T_rope
	sf	T_swing
	sf	T_targeting
	sf	T_wheel
	clr.b	T_state
	move.w	#-1,T_face

	lea	SW_table(pc),a0
	moveq	#4-1,d7
.clear4:
	clr.l	(a0)
	clr.l	4(a0)
	clr.l	8(a0)
	lea	SW_len(a0),a0
	dbf	d7,.clear4

	lea	Mine_X(pc),a0
	moveq	#3-1,d7
.clear5:
	clr.l	(a0)+
	move.l	#$ffff0000,(a0)+
	dbf	d7,.clear5

	move.l	#Player_Dead,Dead_Vector
	lea	BSS_buffer,a0
	move.w	#816,d0
.clear:
	clr.l	(a0)+
	dbf	d0,.clear

	move.l	Act_Bob_Structure(pc),a0
	move.w	#(BOB_MAXIMUM*BOB_ENTRY_LENGTH)-1,d7
.clear2:
	move.b	#BOB_FALSE,(a0)+
	dbf	d7,.clear2

	move.w	#AnimEntryLen*MaxAnim-1,d7
	lea	AnimList(pc),a0
.clear3:
	move.b	#-1,(a0)+
	dbf	d7,.clear3

	move.l	Act_Scr_Structure,a6
	clr.l	Scr_Up_Fix(a6)
	clr.l	Scr_X_Fix(a6)
	move.l	#RoutRts,Scr_Rout_X(a6)
	move.l	#RoutRts,Scr_Rout_Y(a6)
	bsr	Set_Player

	move.l	Act_Scr_Structure,a6
	jsr	Create_Pages

	st	KillFlash

	IFEQ	BobTest
	bsr	EnterScreen			;Alle Gegner eintragen.
	ELSEIF
	move.w	#100,d1
	move.w	#50,d2

	moveq	#0,d0
	lea	Area_Enter_Vector(pc),a1
	moveq	#0,d7

.loop:
	movem.l	d0-d2/d7/a1,-(sp)
	jsr	Search_Bob_Entry
	movem.l	(sp)+,d0-d2/d7/a1

	add.w	#32,d1
	cmp.w	#250,d1
	blt.s	.ok
	moveq	#100,d1
	add.w	#32,d2
.ok:
	dbf	d7,.loop

	ENDC
	rts

game:
	eor.w	#1,half_pixel

	clr.l	quarter_pixel
	addq.w	#1,help_pixel
	move.w	help_pixel(pc),d0
	and.w	#7,d0
	bne.s	.no_eights
	addq.w	#1,eights_pixel
.no_eights:
	and.w	#3,d0
	beq.s	.no_quarter
	addq.w	#1,quarter_pixel
.no_quarter:

	subq.b	#1,T_rocket_time
	bpl.s	.no_timeup
	sf	T_rocket_time
.no_timeup:

	IFNE	COLORTEST
	move.w	#$f00,$dff180
	ENDC
	tst.b	T_mine
	bne.s	.no_spec
	tst.b	beam_me
	bne.s	.no_spec
	move.l	SW_spec_rout(pc),a0
	jsr	(a0)
.no_spec:

	move.l	Clist_Handler(pc),a0
	jsr	(a0)

	IFNE	COLORTEST
	move.w	#$00f,$dff180
	ENDC
	bsr	make_collision

	move.l	SFX_Handler(pc),a0
	jsr	(a0)

	bsr	RestoreBobs		;Bobs lschen
	jsr	Scroll			;Playfield scrollen
	move.w	Scr_Y_Level_Pos(a6),d0
	lsr.w	#1,d0
	move.w	d0,para_ypos				;Parallax scrollen.

	bsr	Calc_Blit_Adrs
	bsr	JoyStick		;Joystick/Joypad auslesen

	IFNE	COLORTEST
	move.w	#$ff0,$dff180
	ENDC
	tst.b	beam_me
	bne.s	.is_beaming3
	move.l	Player_Vector,a0
	jsr	(a0)
.is_beaming3:
	IFNE	COLORTEST
	move.w	#$f0f,$dff180
	ENDC

	move.l	Act_Scr_Structure,a6

	bsr	BG_Anim
	bsr	show_score_line
	bsr	ExecuteHandler
	tst.b	beam_me
	bne.s	.is_beaming1
	bsr	change_weapons
.is_beaming1:

	IFNE	COLORTEST
	move.w	#$0f0,$dff180
	ENDC
	bsr	Motion_Control		;Scrolling handlen.

	tst.b	beam_me
	bne.s	.is_beaming2
	bsr	Show_SWeapons		;Sprite-Schsse darstellen.
.is_beaming2:
	IFNE	COLORTEST
	move.w	#$004,$dff180
	ENDC

	bsr	Area_Check

	bsr	check_weapons

	IFNE	COLORTEST
	move.w	#$0f0,$dff180
	ENDC
	move.l	Rope_Vector,a0
	jsr	(a0)

	move.b	vposr+1(a5),Bob_Flags
	bsr	Bob_System

	IFNE	COLORTEST
	move.w	#$f00,$dff180
	ENDC
	bsr	Anim_Player		;Spieler-Sprites bewegen.


	cmp.b	#$21,G_keycode
	bne.s	.no_sound
	sf	G_keycode
	addq.b	#1,song_mode
	and.b	#3,song_mode
	bsr	Handle_sound
.no_sound:


	IFNE	Coords
	move.w	Scr_X_Level_Pos(a6),d0
	add.w	T_posX(pc),d0
	bsr	Show_Word2
	move.w	Scr_Y_Level_Pos(a6),d0
	add.w	T_posY(pc),d0
	bsr	Show_Word
	ENDC

	IFNE	NoHit
	move.b	#10,T_flash
	ENDC

	IFNE	COLORTEST
	move.w	#$000,$dff180
	ENDC

	IFNE	Keys
	cmp.b	#$11,G_keycode
	bne.s	.no_weapon
	clr.b	G_keycode
	addq.b	#1,T_weapon_new
	cmp.b	#3,T_weapon_new
	blt.s	.no_weapon
	clr.b	T_weapon_new

.no_weapon:

	cmp.b	#$36,G_keycode
	bne.s	.no_win
	clr.b	G_keycode
	move.w	#-1,Cue_Point

.no_win:

	cmp.b	#$19,G_keycode
	bne.s	.no_power_up
	clr.b	G_keycode
	addq.b	#1,T_power_new
	cmp.b	#3,T_power_new
	bne.s	.no_power_up
	clr.b	T_power_new

.no_power_up:

	cmp.b	#$27,G_keycode
	bne.s	.no_kill
	clr.b	G_keycode
	clr.b	T_energy

.no_kill:
	cmp.b	#$13,G_keycode
	bne.s	.no_rocket
	clr.b	G_keycode
	not.b	T_rocket
.no_rocket:

	cmp.b	#$12,G_keycode
	bne.s	.no_energy
	clr.b	G_keycode
	move.b	#64,T_energy
.no_energy:

	cmp.b	#$14,G_keycode
	bne.s	.no_wenergy
	clr.b	G_keycode
	move.w	#1024,T_wenergy
.no_wenergy:

	cmp.b	#$21,G_keycode
	bne.s	.no_shield
	clr.b	G_keycode
	st	T_shield
.no_shield:

	cmp.b	#$33,G_keycode
	bne.s	.no_cpu
	clr.b	G_keycode
	not	Scr_BigCPU(a6)
.no_cpu:
	cmp.b	#$0a,G_keycode
	bne.s	.no_timeclr
	clr.b	G_keycode
	move.w	#$0015,T_time
.no_timeclr:
	ELSEIF
	cmp.b	#$45,G_keycode
	bne.s	.no_quit
	st	G_quit
.no_quit:
	ENDC
	IFNE	Keys+Press
	cmp.b	#$36,G_keycode
	bne.s	.no_win2
	clr.b	G_keycode
	move.w	#-1,Cue_Point

.no_win2:
	ENDC

	rts

Dead_Vector:	dc.l	Player_Dead
Clist_Handler:	dc.l	Return
SFX_Handler:	dc.l	Return
Player_Vector:	dc.l	Handle_Player
Rope_Vector:	dc.l	Blit_Rope

Player_Dead:
	bsr	Die_Player
	lea	AnimList(pc),a0
.aloop:
	move.l	(a0),d0
	beq	.anext
	bmi	.aend
	bsr	Out_Anim
.anext:
	lea	AnimEntryLen(a0),a0
	bra	.aloop
.aend:
	move.l	Act_Bob_Structure(pc),a4
	moveq	#BOB_MAXIMUM-1,d7
.loop:
	tst.b	Bob_Used(a4)
	bmi.s	.next
	bsr	Out_Bob
.next:
	lea	BOB_ENTRY_LENGTH(a4),a4
	dbf	d7,.loop

;	jsr	SetClist

	move.w	#15,Fade_Position
	moveq	#-1,d0
	jsr	L_Fade_Colors

	move.l	Act_Scr_Structure,a6
	clr.l	Scr_X_Fix(a6)

	bra	Init_Level

Die_Player:
	bsr	Start_Beam
	move.b	T_lifes(pc),d0
	beq	Game_over
	move.b	#0,ccr
	moveq	#1,d1
	sbcd	d1,d0
	move.b	d0,T_lifes
setup_dead:
	cmp.w	#$100,T_time
	bge.s	.ok
	move.w	#$100,T_time
.ok:
	sf	T_dead
	sf	T_dieing
	sf	T_hit
	sf	T_rope
	sf	T_swing
	sf	T_targeting
	sf	T_wheel
	clr.b	T_state

	tst.b	T_power1
	beq.s	.no_power1
	subq.b	#1,T_power1
.no_power1:
	tst.b	T_power2
	beq.s	.no_power2
	subq.b	#1,T_power2
.no_power2:
	tst.b	T_power3
	beq.s	.no_power3
	subq.b	#1,T_power3
.no_power3:

	sf	T_rocket		;Keine Raketen mehr
	sf	T_shield		;Shield ist aus!

	tst.b	T_power
	beq.s	.no_powerdown
	subq.b	#1,T_power
	move.b	T_power,T_power_new
.no_powerdown:
	

	move.b	#64,T_energy		;Volle Energie!
	move.w	#1024,T_wenergy		;Volle Energie!

	bsr	select_weapon
	sf	T_flash
	clr.l	T_speedY
	clr.b	T_rocket_anz

	move.b	#3,T_bombs

	rts

Game_over:
	addq.l	#4,sp			;Rcksprung vom Stack holen!
Game_over_in:
	bsr	setup_dead		;Alles wieder frs nchste mal herstellen.
	sf	DATA_WORLD_CLEAR.w

	moveq	#6,d0
	bsr	Play_Effekt_Song
	move.b	#190,VBI_count

	lea	sprite_pos(pc),a2
	moveq	#7,d0
.clear:
	clr.l	(a2)+
	dbf	d0,.clear

.wait:
	tst.b	VBI_count
	bne.s	.wait

	move.w	#15,Fade_Position
	moveq	#-1,d0
	jsr	L_Fade_Colors
QUIT:
	move.b	T_score,DATA_SCORE+1.w
	move.w	T_score+1,DATA_SCORE+2.w
	move.b	T_power1,DATA_WEAPONS.w
	move.b	T_power2,DATA_WEAPONS+1.w
	move.b	T_power3,DATA_WEAPONS+2.w
	move.b	T_rocket,DATA_WEAPONS+3.w
	move.b	T_weapon,DATA_WEAPONS+4.w
	move.b	T_power,DATA_WEAPONS+5.w

	move.w	#$7fff,dmacon(a5)
	rts

RoutRts:
Return:	rts

set_copcolors:
	lea	coltab+32,a0
	lea	$dff180+32,a1
	moveq	#15,d7
.copcols:
	move.w	(a0)+,(a1)+
	dbf	d7,.copcols

	moveq	#14,d7
	lea	coltab+2,a0
	move.l	Color_Pointer,a1
.setcol1:
	move.w	(a0)+,2(a1)
	addq.l	#4,a1
	dbf	d7,.setcol1
	rts

Angle_Obj:	dc.w	0
Dest_Obj:	dc.l	0

*----------------------------------------------------------------------------
waitblt:		MACRO

.w1\@	btst	#14,dmaconr(a5)
	bne.s	.w1\@

	ENDM
*----------------------------------------------------------------------------
FlipBlock_4_Planes:	MACRO

	waitblt
	move	Scr_Blt_A_Flip_Mod(a6),bltamod(a5)
	move	Scr_Blt_D_Flip_Mod(a6),bltdmod(a5)
	move.l	(a0,d0.w),a0
	add	Scr_Blt_Flip_Add(a6),a0

	movem.l	d3/a2-a3,-(sp)

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	adda.w	#40,a0
	add.w	#planeb,a2
	add.w	#planeb,a3
	add.l	#planeb,d3

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	add	#40,a0
	add	#planeb,a2
	add	#planeb,a3
	add.l	#planeb,d3

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	add	#40,a0
	add	#planeb,a2
	add	#planeb,a3
	add.l	#planeb,d3

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)

	move	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	movem.l	(sp)+,d3/a2-a3

	ENDM

*---------------------------------------------------------------------
FlipBlock_3_Planes:	MACRO

	waitblt
	move	Scr_Blt_A_Flip_Mod(a6),bltamod(a5)
	move	Scr_Blt_D_Flip_Mod(a6),bltdmod(a5)
	move.l	(a0,d0.w),a0
	add	Scr_Blt_Flip_Add(a6),a0

	movem.l	d3/a2-a3,-(sp)

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	add	#40,a0
	add	#planeb,a2
	add	#planeb,a3
	add.l	#planeb,d3

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	add	#40,a0
	add	#planeb,a2
	add	#planeb,a3
	add.l	#planeb,d3

	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
 	move	Scr_Blt_Flip_Size(a6),bltsize(a5)
	waitblt

	move	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	movem.l	(sp)+,d3/a2-a3

	ENDM

	*----------------------------------------------------------------------------
	*------------------------- FLIP & ROTATION SYSTEM ---------------------------
	*----------------------------------------------------------------------------

	;Requirements :
	;a0 = Pointer auf Quell-Daten (Normales interleaved Bob)
	;a1 = Pointer auf Chunky-Mode-Buffer
	;a2 = Pointer auf Leere Rotate-Info Struktur, die mit Daten gefllt wird.
	;a3 = Pointer auf Quell-Maske (Einfache Masken-Plane)
	;d0 = Seitenlnge des Objekts (In Pixeln).
	;d1 = Planetiefe des Objekts

Convert_to_Rotate:
	move.w	d0,d7
	move.w	d0,Rot_I_OBJ_Width(a2)
	move.w	d1,Rot_I_OBJ_Planes(a2)
	;Gre des Puffers berechnen (ZeilenModulo etc.)

	mulu	d0,d0		; L^2
	add.w	d0,d0		; *2
	bsr	sqrt
	addq.w	#1,d0
	and.w	#$fffe,d0
	move.w	d0,Rot_I_Width(a2)
	mulu	d0,d0		; Die Buffergre ist nun berechnet.
	move.w	d0,Rot_I_Size(a2)

	subq.w	#1,d0
	moveq	#0,d1
.clear:
	move.b	d1,(a1,d0.w)	;Lschen des Chunky-Buffers
	dbf	d0,.clear

	moveq	#0,d0
	move.w	Rot_I_Width(a2),d0
	sub.w	d7,d0
	lsr.w	#1,d0		;Soviele Bytes stehen an allen Rndern ber.

	move.l	d0,d1
	mulu	Rot_I_Width(a2),d0
	add.w	d0,d1		;Offset auf den Start-pixel im Dest-Buffer.
	move.w	d1,Rot_I_Offset(a2)
	lea	(a1,d1.w),a1
				;Y-Counter steht in d7.
	move.w	d7,d0
	lsr.w	#3,d0		;Modulo fr nchste BitPlane.
	move.w	d0,Rot_I_OBJ_Mod(a2)

	move.w	Rot_I_OBJ_Mod(a2),d0
	move.w	Rot_I_OBJ_Planes(a2),d1
	subq.w	#1,d1
	mulu	d1,d0
	move.w	d0,Rot_I_OBJ_Mod2(a2)

	move.w	Rot_I_OBJ_Planes(a2),a4

	subq.w	#1,d7		;Fr DBF anpassen
.loopy:
	move.w	Rot_I_OBJ_Width(a2),d6
	lsr.w	#3,d6		;Nur die Bytes beachten.
	subq.w	#1,d6		;Fr DBF anpassen
.loopx:
	cmp.w	#1,a4		;Nur eine Plane ?
	beq.s	.all_planes
	move.w	Rot_I_OBJ_Mod(a2),d5
	move.b	(a0,d5),d1
	cmp.w	#2,a4		;Zwei Planes ?
	beq.s	.all_planes
	add.w	Rot_I_OBJ_Mod(a2),d5
	move.b	(a0,d5),d2
	cmp.w	#3,a4		;Drei Planes ?
	beq.s	.all_planes
	add.w	Rot_I_OBJ_Mod(a2),d5
	move.b	(a0,d5),d3
.all_planes:
	move.b	(a0)+,d0
	move.b	(a3)+,d4
	move.w	d6,-(sp)
	moveq	#7,d6
.loopbyte:
	moveq	#0,d5
	lsl.b	#1,d4			;Die Maske ganz oben!
	addx.b	d5,d5
	lsl.b	#1,d3
	addx.b	d5,d5
	lsl.b	#1,d2
	addx.b	d5,d5
	lsl.b	#1,d1
	addx.b	d5,d5
	lsl.b	#1,d0
	addx.b	d5,d5
	move.b	d5,(a1)+
	dbf	d6,.loopbyte
	move.w	(sp)+,d6
	dbf	d6,.loopx

	move.w	Rot_I_OBJ_Mod2(a2),d0
	lea	(a0,d0.w),a0		;Zur Nchsten Quell-Zeile skippen.

	move.w	Rot_I_Width(a2),d0
	sub.w	Rot_I_OBJ_Width(a2),d0
	lea	(a1,d0.w),a1		;Zur Nchsten Dest Zeile skippen.

	dbf	d7,.loopy
	move.w	Rot_I_Width(a2),Rot_I_BUF_Width(a2)	;Normalerweise ist der Buffer gleich gro!
	clr.w	Rot_I_Single_Call(a2)
	rts

	;Requirements:
	;a0 = Pointer auf Ziel-Daten (Normales interleaved Bob)
	;a1 = Pointer auf Chunky-Mode-Buffer (Schon mit Offset !!)
	;a2 = Pointer auf gefllte Rotate-Info-Struktur
	;a3 = Pointer auf Ziel-Maske (Einfache Masken-Plane)

Convert_to_Bitplane:
	move.w	Rot_I_OBJ_Width(a2),d7
Convert_to_Bitplane2:
	move.w	Rot_I_OBJ_Planes(a2),a4
	subq.w	#1,d7		;Fr DBF anpassen
.loopy:
	move.w	Rot_I_OBJ_Width(a2),d6
	lsr.w	#3,d6		;Nur die Bytes beachten.
	subq.w	#1,d6		;Fr DBF anpassen
.loopx:
	move.w	d6,-(sp)
	moveq	#7,d6

	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
.loopbyte:
	move.b	(a1)+,d5
	beq.s	.empty

	lsr.b	#1,d5
	roxl.b	#1,d0
	lsr.b	#1,d5
	roxl.b	#1,d1
	lsr.b	#1,d5
	roxl.b	#1,d2
	lsr.b	#1,d5
	roxl.b	#1,d3
	lsr.b	#1,d5
	roxl.b	#1,d4
.back:
	dbf	d6,.loopbyte

	move.w	Rot_I_OBJ_Mod(a2),d5
	move.b	d1,(a0,d5)
	add.w	Rot_I_OBJ_Mod(a2),d5
	move.b	d2,(a0,d5)
	add.w	Rot_I_OBJ_Mod(a2),d5
	move.b	d3,(a0,d5)
.all_planes:
	move.b	d0,(a0)+
	move.b	d4,(a3)+

	move.w	(sp)+,d6
	dbf	d6,.loopx

	adda.w	Rot_I_OBJ_Mod2(a2),a0	;Zur Nchsten Dest Zeile skippen.

	move.w	Rot_I_BUF_Width(a2),d0
	sub.w	Rot_I_OBJ_Width(a2),d0
	lea	(a1,d0.w),a1		;Zur Nchsten Quell Zeile skippen.

	dbf	d7,.loopy
	rts

.empty:
	add.b	d0,d0
	add.b	d1,d1
	add.b	d2,d2
	add.b	d3,d3
	add.b	d4,d4
	bra.s	.back

Convert_to_Bitplane3:
	move.w	Rot_I_OBJ_Planes(a2),a4
	subq.w	#1,d7		;Fr DBF anpassen
.loopy:
	move.w	Rot_I_OBJ_Width(a2),d6
	lsr.w	#3,d6		;Nur die Bytes beachten.
	subq.w	#1,d6		;Fr DBF anpassen
.loopx:
	move.w	d6,-(sp)
	moveq	#7,d6

	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
.loopbyte:
	move.b	(a1)+,d5
	beq.s	.empty

	lsr.b	#1,d5
	roxl.b	#1,d0
	lsr.b	#1,d5
	roxl.b	#1,d1
	lsr.b	#1,d5
	roxl.b	#1,d2
	lsr.b	#2,d5
	roxl.b	#1,d4
.back:
	dbf	d6,.loopbyte

	move.w	Rot_I_OBJ_Mod(a2),d5
	move.b	d1,(a0,d5)
	add.w	Rot_I_OBJ_Mod(a2),d5
	move.b	d2,(a0,d5)
.all_planes:
	move.b	d0,(a0)+
	move.b	d4,(a3)+

	move.w	(sp)+,d6
	dbf	d6,.loopx

	adda.w	Rot_I_OBJ_Mod2(a2),a0	;Zur Nchsten Dest Zeile skippen.

	move.w	Rot_I_BUF_Width(a2),d0
	sub.w	Rot_I_OBJ_Width(a2),d0
	lea	(a1,d0.w),a1		;Zur Nchsten Quell Zeile skippen.

	dbf	d7,.loopy
	rts

.empty:
	add.b	d0,d0
	add.b	d1,d1
	add.b	d2,d2
	add.b	d4,d4
	bra.s	.back

Rot_I_OBJ_Width		rs.w	1
Rot_I_OBJ_Planes	rs.w	1
Rot_I_OBJ_Mod		rs.w	1
Rot_I_OBJ_Mod2		rs.w	1
Rot_I_BUF_Width		rs.w	1
Rot_I_Width		rs.w	1
Rot_I_Offset		rs.w	1
Rot_I_Size		rs.w	1
Rot_I_Single_Call	rs.w	1
Rot_I_ENTRY_LENGTH	rs.w	0

Rot_Info1:	ds.w	Rot_I_ENTRY_LENGTH

	;Requirements :
	;a0 = Pointer auf Quell-Chunky-Mode-Buffer
	;a1 = Pointer auf Ziel-Chunky-Mode-Buffer
	;a2 = Pointer auf gefllte Rotate-Info-Struktur
	;d0 = Zoom-Faktor im 16:16 Fix Format.

Do_Zoom:
	move.w	Rot_I_BUF_Width(a2),d1
	mulu	d1,d1			;Gre des Ziel-Buffers.
	lsr.w	#2,d1
	subq.w	#1,d1
	move.l	a1,a3
.clear:
	clr.l	(a3)+			;Lschen des Ziel-Buffers.
	dbf	d1,.clear

	add.w	Rot_I_Offset(a2),a0

	move.l	d0,d1
	swap	d1

	moveq	#0,d2
	moveq	#0,d3
	moveq	#0,d4
	;Feststellen, wieviele Pixel breit die Destination wird.
	;Und ausrechnen der Offsets.
	lea	Offset_Table(pc),a3
.loop:
	add.l	d1,d2
	addx.w	d3,d2
	move.w	d2,(a3)+
	addq.w	#1,d4
	cmp.w	Rot_I_OBJ_Width(a2),d2	;Vergleichen mit der Ursprnglichen Breite.
	blt.s	.loop

	;In d4 steht die Breite/Hhe in Pixeln.

	move.w	Rot_I_BUF_Width(a2),d5
	sub.w	d4,d5
	lsr.w	#1,d5			;Soviel Pixel mssen am linken Rand frei sein.

	add.w	d5,a1

	mulu	Rot_I_BUF_Width(a2),d5
	add.w	d5,a1

	moveq	#0,d0
	subq.w	#1,d4
	move.w	d4,d6

.loopy:
	move.w	d4,d5

	move.l	a1,a3
	lea	Offset_Table(pc),a4
.loopx:
	move.w	(a4)+,d2		;8
	move.b	(a0,d2.w),(a3)+		;18
	dbf	d5,.loopx		;10

	tst.w	d6			;Hiermit spare ich einmal die Multipliziererei.
	beq.s	.out

	adda.w	Rot_I_BUF_Width(a2),a1
	add.l	d1,d0
	addx.w	d3,d0
	move.w	d0,d3
	clr.w	d0
	mulu	Rot_I_Width(a2),d3
	lea	(a0,d3.w),a0
	moveq	#0,d3

	dbf	d6,.loopy
.out:
	lea	custom,a5
	rts

Offset_Table:
	ds.w	32*2

	;a0 = Pointer auf Quell-Chunky-Mode-Buffer
	;a1 = Pointer auf Ziel-Chunky-Mode-Buffer
	;a2 = Pointer auf gefllte Rotate-Info-Struktur
	;d0 = Rotier-Winkel von 0-255

	;VORSICHT ! IST NOCH AUF 32er OBJEKTE BESCHRNKT!!!

Do_Rotate:
	move.l	a0,-(sp)
	lea	Offset_Table(pc),a3

	;Berechnen der Steigung der Einzellinien, aus denen das Objekt entsteht

	move.b	d0,Angle

	bsr	cos
	ext.l	d0
	asl.l	#8,d0
	move.l	d0,X_Add

	move.b	Angle,d0
	bsr	sin
	ext.l	d0
	asl.l	#8,d0
	move.l	d0,Y_Add

	;Berechnen des Startpunkts

	move.w	Rot_I_OBJ_Width(a2),d0
	lsr.w	#1,d0
	mulu	d0,d0
	add.w	d0,d0
	bsr	sqrt
	move.w	d0,d6

	move.b	#64+32,d0
	sub.b	Angle(pc),d0
	move.w	d0,-(sp)
	bsr	cos
	muls	d6,d0
	asr.l	#8,d0

	move.w	Rot_I_Width(a2),d4
	lsr.w	#1,d4			;X0 / Y0

	add.w	d4,d0
	move.w	d0,d5			;X1

	move.w	(sp)+,d0
	bsr	sin
	neg.w	d0
	muls	d6,d0
	asr.l	#8,d0
	add.w	d4,d0			;Y1
	mulu	Rot_I_Width(a2),d0	;*Breite des Buffers
	add.w	d0,d5			;Offset fr den Startpunkt.

	;Offsets fr eine einzelne Linie ausrechnen.

	move.w	d5,(a3)+

	moveq	#0,d0
	moveq	#0,d1

	move.l	X_Add,d2
	move.l	Y_Add,d3
	swap	d2
	swap	d3			;Vorkomma-Anteil nach unten bringen.
	moveq	#31-1,d7		;Noch 31 Punkte berechnen.
.loop1:
	moveq	#0,d6
	add.l	d2,d0
	addx.w	d6,d0
	add.l	d3,d1
	addx.w	d6,d1
	add.w	d0,d5
	clr.w	d0
	move.w	d1,d6
	muls	Rot_I_Width(a2),d6
	add.w	d6,d5
	clr.w	d1
	move.w	d5,(a3)+
	dbf	d7,.loop1

	move.l	Y_Add,d2
	move.l	X_Add,d3
	neg.l	d2
	swap	d2
	swap	d3			;Vorkomma-Anteil nach unten bringen.

	;Offsets zur nchsten Zeile berechnen. (32 Stck)

	clr.w	(a3)+			;Erster Offset ist Null!

	moveq	#0,d0
	moveq	#0,d1

	moveq	#0,d5

	moveq	#31-1,d7
.loop2:
	moveq	#0,d6
	add.l	d2,d0
	addx.w	d6,d0
	add.l	d3,d1
	addx.w	d6,d1
	add.w	d0,d5
	clr.w	d0
	move.w	d1,d6
	muls	Rot_I_Width(a2),d6
	add.w	d6,d5
	clr.w	d1
	sub.w	-2(a3),d5		;Nur die Differenzen zhlen.
	move.w	d5,(a3)+
	dbf	d7,.loop2

	;Kopieren des Puffers in den Ziel-Buffer!

	move.l	(sp)+,a0

	lea	Offset_Table+64+2(pc),a4		;Y-Offsets
	moveq	#32-1,d6
	tst.w	Rot_I_Single_Call(a2)
	beq.s	.loopy
	moveq	#16-1,d6
.loopy:
	moveq	#32-1,d7
	lea	Offset_Table(pc),a3	;X-Offsets
.loopx:
	move.w	(a3)+,d0
	move.b	(a0,d0.w),(a1)+
	dbf	d7,.loopx
	add.w	(a4)+,a0
	dbf	d6,.loopy
	rts

Do_Copy:
	lea	Offset_Table+64+2(pc),a4		;Y-Offsets
	lea	32*16(a1),a1
	moveq	#16-1,d6
.skip:
	add.w	(a4)+,a0
	dbf	d6,.skip

	moveq	#16-1,d6
.loopy:
	moveq	#32-1,d7
	lea	Offset_Table(pc),a3	;X-Offsets
.loopx:
	move.w	(a3)+,d0
	move.b	(a0,d0.w),(a1)+
	dbf	d7,.loopx
	add.w	(a4)+,a0
	dbf	d6,.loopy
	rts

X_Add:	dc.l	0
Y_Add:	dc.l	0
Angle:	dc.w	0

Flip_Sprites:
	lea	flip_table(pc),a2
	moveq	#0,d0
	lsr.w	#1,d7
.next_one:
	move.b	(a0)+,d0
	move.b	(a2,d0.w),1(a1)
	move.b	(a0)+,d0
	move.b	(a2,d0.w),(a1)
	addq.l	#2,a1
	dbf	d7,.next_one
	rts

Flip_Bobs:
	lea	flip_table(pc),a2
	moveq	#0,d0
.bob_loop:
	tst.w	(a3)
	bmi.s	.end_of_list
	move.l	a0,-(sp)
	adda.w	(a3)+,a0
	move.w	(a3)+,d7
	subq.w	#1,d7
.y_loop:
	move.w	(a3),d6
	subq.w	#1,d6
.x_loop:
	move.b	(a0)+,d0
	move.b	(a2,d0.w),(a1,d6.w)
	dbf	d6,.x_loop
	adda.w	(a3),a1
	dbf	d7,.y_loop
	move.l	(sp)+,a0
	addq.l	#2,a3
	bra.s	.bob_loop

.end_of_list:
	rts


flip_table:
	dc.b	$00,$80,$40,$c0,$20,$a0,$60,$e0
	dc.b	$10,$90,$50,$d0,$30,$b0,$70,$f0

	dc.b	$08,$88,$48,$c8,$28,$a8,$68,$e8
	dc.b	$18,$98,$58,$d8,$38,$b8,$78,$f8

	dc.b	$04,$84,$44,$c4,$24,$a4,$64,$e4
	dc.b	$14,$94,$54,$d4,$34,$b4,$74,$f4

	dc.b	$0c,$8c,$4c,$cc,$2c,$ac,$6c,$ec
	dc.b	$1c,$9c,$5c,$dc,$3c,$bc,$7c,$fc

	dc.b	$02,$82,$42,$c2,$22,$a2,$62,$e2
	dc.b	$12,$92,$52,$d2,$32,$b2,$72,$f2

	dc.b	$0a,$8a,$4a,$ca,$2a,$aa,$6a,$ea
	dc.b	$1a,$9a,$5a,$da,$3a,$ba,$7a,$fa

	dc.b	$06,$86,$46,$c6,$26,$a6,$66,$e6
	dc.b	$16,$96,$56,$d6,$36,$b6,$76,$f6

	dc.b	$0e,$8e,$4e,$ce,$2e,$ae,$6e,$ee
	dc.b	$1e,$9e,$5e,$de,$3e,$be,$7e,$fe

	dc.b	$01,$81,$41,$c1,$21,$a1,$61,$e1
	dc.b	$11,$91,$51,$d1,$31,$b1,$71,$f1

	dc.b	$09,$89,$49,$c9,$29,$a9,$69,$e9
	dc.b	$19,$99,$59,$d9,$39,$b9,$79,$f9

	dc.b	$05,$85,$45,$c5,$25,$a5,$65,$e5
	dc.b	$15,$95,$55,$d5,$35,$b5,$75,$f5

	dc.b	$0d,$8d,$4d,$cd,$2d,$ad,$6d,$ed
	dc.b	$1d,$9d,$5d,$dd,$3d,$bd,$7d,$fd

	dc.b	$03,$83,$43,$c3,$23,$a3,$63,$e3
	dc.b	$13,$93,$53,$d3,$33,$b3,$73,$f3

	dc.b	$0b,$8b,$4b,$cb,$2b,$ab,$6b,$eb
	dc.b	$1b,$9b,$5b,$db,$3b,$bb,$7b,$fb

	dc.b	$07,$87,$47,$c7,$27,$a7,$67,$e7
	dc.b	$17,$97,$57,$d7,$37,$b7,$77,$f7

	dc.b	$0f,$8f,$4f,$cf,$2f,$af,$6f,$ef
	dc.b	$1f,$9f,$5f,$df,$3f,$bf,$7f,$ff

	*----------------------------------------------------------------------------
	*------------------------------ SCROLL CAMERA -------------------------------
	*----------------------------------------------------------------------------

Set_Player:
	move.w	Cue_Point(pc),d1
	add.w	d1,d1
	add.w	d1,d1
	move.l	Act_Cue_Table(pc),a0
	move.w	(a0,d1.w),d0
	move.w	2(a0,d1.w),d1
	move.w	d0,T_posX
	move.w	d1,T_posY
	move.w	d1,T_oldY

	sub.w	#150,d0
	sub.w	#90,d1
	cmp.w	#16,d0
	bge.s	.ok1
	moveq	#16,d0
.ok1:
	cmp.w	Scr_X_Max(a6),d0
	ble.s	.ok2
	move.w	Scr_X_Max(a6),d0
.ok2:
	cmp.w	#32,d1
	bge.s	.ok3
	moveq	#32,d1
.ok3:
	cmp.w	Scr_Y_Max(a6),d1
	ble.s	.ok4
	move.w	Scr_Y_Max(a6),d1
.ok4:
	move.w	d0,Scr_X_Level_Pos(a6)
	move.w	d1,Scr_Y_Level_Pos(a6)
	move.w	d0,Scr_X_Level_Pos_Old(a6)
	move.w	d1,Scr_Y_Level_Pos_Old(a6)
	sub.w	d0,T_posX
	sub.w	d1,T_posY
	move.w	Scr_Plane_Height(a6),d0
	divu	d0,d1
	swap	d1
	move.w	d1,Scr_Y_Play_Anf(a6)
	rts

Cue_Point:	dc.w	0
Act_Cue_Table:	dc.l	0

UPPER_SCROLL	equ 40
LOWER_SCROLL	equ 112

Motion_Control:
	move.l	Act_Scr_Structure,a6

	;X-Scroll-handler.

	clr.w	Scr_X_Speed(a6)		;Vorkomma-Anteil lschen.
	move.w	T_posX(pc),d0
	cmp.w	#80,d0
	blt	.x_scroll_maxl
	cmp.w	#100,d0
	blt	.x_scroll_scaledl
	cmp.w	#220,d0
	bgt	.x_scroll_maxr
	cmp.w	#180,d0
	bgt	.x_scroll_scaledr

	cmp.w	#130,d0
	blt	.x_check_flag
	cmp.w	#150,d0
	bgt	.x_check_flag

.x_slowdown:
	;Scroll-Speed Verzgern bis auf 0.
	clr.b	Accel_Flag_X
	clr.l	T_Ispeed_X		;Interne Speed lschen.
	tst.l	Dol_Speed_X
	beq	.done_x
	bpl	.x_sub

	add.l	#$00004000,Dol_Speed_X
	bmi	.done_x
	clr.l	Dol_Speed_X
	bra	.done_x

.x_sub:
	sub.l	#$00004000,Dol_Speed_X
	bpl	.done_x
	clr.l	Dol_Speed_X
	bra	.done_x

.x_check_flag:
	tst.b	Accel_Flag_X
	beq	.x_slowdown
	bpl	.x_scroll_scaledr
.x_scroll_scaledl:
	bsr	.x_set_max
	move.b	#-1,Accel_Flag_X
	sub.l	#$00004000,Dol_Speed_X
	move.l	T_Ispeed_X,d0
	neg.l	d0
	cmp.l	Dol_Speed_X,d0
	ble	.done_x
	move.l	d0,Dol_Speed_X
	bra	.done_x
.x_scroll_scaledr:
	bsr	.x_set_max
	move.b	#1,Accel_Flag_X
	add.l	#$00004000,Dol_Speed_X
	move.l	T_Ispeed_X,d0
	cmp.l	Dol_Speed_X,d0
	bge	.done_x
	move.l	d0,Dol_Speed_X
	bra	.done_x

.x_set_max:
	tst.l	T_Ispeed_X
	beq.s	.x_do
	move.l	T_Mspeed_X,d0
	cmp.l	T_Ispeed_X,d0
	blt.s	.x_dont
.x_do:
	move.l	T_Mspeed_X,T_Ispeed_X
.x_dont:
	rts

.x_scroll_maxl:
	bsr.s	.x_set_max
	move.l	T_Ispeed_X,d0
	neg.l	d0
	move.l	d0,Dol_Speed_X
	bra.s	.done_x

.x_scroll_maxr:
	bsr.s	.x_set_max
	move.l	T_Ispeed_X,Dol_Speed_X
	bra	.done_x
.done_x:

	IFNE	OldScroll

	;Y-Scroll-handler.
	clr.w	Scr_Y_Speed(a6)		;Vorkomma-Anteil lschen.
	move.w	T_posY,d0
	cmp.w	#25,d0		;5
	blt	.y_scroll_maxl
	cmp.w	#35,d0		;15
	blt	.y_scroll_scaledl
	cmp.w	#50,d0		;25
	blt	.y_check_flag

	cmp.w	#150,d0
	bgt	.y_scroll_maxr
	cmp.w	#135,d0
	bgt	.y_scroll_scaledr
	cmp.w	#125,d0
	bgt	.y_check_flag

.y_slowdown:
	;Scroll-Speed Verzgern bis auf 0.
	clr.b	Accel_Flag_Y

	clr.l	T_Ispeed_Y

	tst.l	Dol_Speed_Y
	beq	.done_y
	bpl	.y_sub

	add.l	#$00008000,Dol_Speed_Y
	bmi	.done_y
	clr.l	Dol_Speed_Y
	bra	.done_y

.y_sub:
	sub.l	#$00008000,Dol_Speed_Y
	bpl	.done_y
	clr.l	Dol_Speed_Y
	bra	.done_y

.y_check_flag:
	tst.b	Accel_Flag_Y
	beq	.y_slowdown
	bpl	.y_scroll_scaledr
.y_scroll_scaledl:
	bsr	.y_set_max
	move.b	#-1,Accel_Flag_Y
	sub.l	#$00008000,Dol_Speed_Y
	move.l	T_Ispeed_Y,d0
	neg.l	d0
	cmp.l	Dol_Speed_Y,d0
	ble	.done_y
	move.l	d0,Dol_Speed_Y
	bra	.done_y
.y_scroll_scaledr:
	bsr	.y_set_max
	move.b	#1,Accel_Flag_Y
	add.l	#$00008000,Dol_Speed_Y
	move.l	T_Ispeed_Y,d0
	cmp.l	Dol_Speed_Y,d0
	bge	.done_y
	move.l	d0,Dol_Speed_Y
	bra	.done_y

.y_set_max:
	tst.l	T_Ispeed_Y
	beq.s	.y_do
	move.l	T_Mspeed_Y,d0
	cmp.l	T_Ispeed_Y,d0
	blt.s	.y_dont
.y_do:
	move.l	T_Mspeed_Y,T_Ispeed_Y
.y_dont:
	rts

.y_scroll_maxl:
	bsr	.y_set_max
	move.l	T_Ispeed_Y,d0
	neg.l	d0
	move.l	d0,Dol_Speed_Y
	bra.s	.done_y

.y_scroll_maxr:
	bsr	.y_set_max
	move.l	T_Ispeed_Y,Dol_Speed_Y
	bra	.done_y

	ELSEIF

	clr.l	Scr_Y_Speed(a6)

	move.w	T_posY,d1
	sub.w	T_oldY,d1
	bpl.s	.ok
	neg.w	d1
.ok:
	bne.s	.ok2
	moveq	#1,d1
.ok2:
;	tst.b	no_scroll.w
;	.if (not zero) {
;		moveq	#0,d0
;		moveq	#0,d1
;	}
	move.w	d1,d7
	moveq	#0,d2

	move.w	T_posY,d1			;Same as above, just for the
	move.l	Dol_Speed_Y2,d0			;upper and lower border...
	swap	d0
	cmpi.w	#LOWER_SCROLL,d1
	ble.s	.no_y1
		cmp.w	d7,d0
		bge.s	.no_y2
			addi.l	#$80000000,d0
			addx.w	d2,d0
.no_y2:
		sf	T_ydir
		bra.s	.yset_it
.no_y1:
	cmpi.w	#UPPER_SCROLL,d1
	bge.s	.no_y3
		cmp.w	d7,d0
		bge.s	.no_y4
			addi.l	#$80000000,d0
			addx.w	d2,d0
.no_y4:
		st	T_ydir
		bra.s	.yset_it
.no_y3:
	subi.l	#$40000000,d0
	subx.w	d2,d0
	bpl.s	.yset_it
		moveq	#0,d0
.yset_it:
	swap	d0
	move.l	d0,Dol_Speed_Y2
	tst.b	T_ydir
	beq.s	.no_y5
		neg.l	d0
.no_y5:
	move.l	d0,Dol_Speed_Y

	ENDC

.done_y:

	;Dolly-speed auf den Screen addieren.

	move.w	Scr_X_Fix(a6),d0
	beq.s	.x_no_fix
	clr.l	Scr_X_Speed(a6)
	moveq	#-1,d1
	cmp.w	Scr_X_Level_Pos(a6),d0
	beq.s	.x_fix
	blt.s	.x_set
	moveq	#1,d1
.x_set:
	move.w	d1,Scr_X_Speed(a6)
	cmp.w	#-4,T_posX
	bge.s	.not_left
	bsr	check_player_quetsch
	move.w	#-4,T_posX
	sf	T_rope
	sf	T_swing
	sf	T_targeting
.not_left:
	cmp.w	#280,T_posX
	ble.s	.x_fix
	bsr	check_player_quetsch
	move.w	#280,T_posX
	sf	T_rope
	sf	T_swing
	sf	T_targeting
	bra.s	.x_fix
.x_no_fix:
	move.l	Dol_Speed_X(pc),d0
	add.l	d0,Scr_X_Speed(a6)	;Die Anzahl der zu scrollenden Pixel berechnen.
.x_fix:
	move.w	Scr_X_Speed(a6),d0
	bpl.s	.check_right
	cmp.w	#-8,d0
	bge.s	.x_maxok
	moveq	#-8,d0
	bra.s	.x_setmax8
.check_right:
	cmp.w	#8,d0
	ble.s	.x_maxok
	moveq	#8,d0
.x_setmax8:
	move.w	d0,Scr_X_Speed(a6)
.x_maxok:
	moveq	#0,d0

	move.w	Scr_Y_Fix(a6),d0
	beq.s	.y_no_fix
	clr.l	Scr_Y_Speed(a6)
	moveq	#-1,d1
	cmp.w	Scr_Y_Level_Pos(a6),d0
	beq.s	.y_fix
	blt.s	.y_set
	moveq	#1,d1
.y_set:
	move.w	d1,Scr_Y_Speed(a6)
	bra.s	.y_fix
.y_no_fix:

	move.l	Dol_Speed_Y(pc),d0
	add.l	d0,Scr_Y_Speed(a6)	;Die Anzahl der zu scrollenden Pixel berechnen.
.y_fix:
	move.w	Scr_Y_Force(a6),d0
	beq.s	.no_force
	move.w	d0,Scr_Y_Speed(a6)
	clr.w	Scr_Y_Force(a6)
.no_force:
	rts

check_player_quetsch:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#30,d1
	bsr	check_kollision
	beq.s	.no
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#22,d1
	bsr	check_kollision
	bne.s	.die
	subq.w	#8,T_posY
	rts
.die:
	sf	T_energy
	sf	T_shield
.no:
	rts

Dol_Speed_X:	dc.l	0
Dol_Speed_Y:	dc.l	0
Accel_Flag_X:	dc.b	0
Accel_Flag_Y:	dc.b	0
T_Ispeed_X:	dc.l	0
T_Ispeed_Y:	dc.l	0

T_ydir:		dc.b	0
		dc.b	0
Dol_Speed_Y2:	dc.l	0

T_lifes:	dc.b	$05
T_score:	dc.b	$00,$00,$00
T_time:		dc.w	0
T_time_def:	dc.w	0
T_wenergy:	dc.w	0
T_energy:	dc.b	0
T_bombs:	dc.b	3

O_lifes:	dc.b	$ff
O_score:	dc.b	$ff,$ff,$ff
O_time:		dc.w	0
O_energy:	dc.b	64
O_bombs:	dc.b	0
O_wenergy:	dc.b	32

no_time:	dc.b	0

	even

add_score:
	lea	help,a0
	lea	T_score+3(pc),a1
	move.l	d0,(a0)+
	move.w	#0,ccr
	abcd	-(a0),-(a1)
	abcd	-(a0),-(a1)
	abcd	-(a0),-(a1)
	rts

sub_energy:
	sub.b	d0,T_energy
	bpl.s	.ok
	clr.b	T_energy
.ok:
	rts

show_score_line:
	lea	Score+3680,a2		;Font
	moveq	#0,d0
	move.b	T_lifes,d0
	cmp.b	O_lifes,d0
	beq.s	.no_lifes
	move.b	d0,O_lifes
	lea	Score+(8*38)+5,a0
	bsr	print_byte
.no_lifes:
	moveq	#0,d0
	move.b	T_score,d0
	cmp.b	O_score,d0
	beq.s	.no_score1
	move.b	d0,O_score
	lea	Score+(8*38)+9,a0
	bsr	print_byte
.no_score1:
	moveq	#0,d0
	move.b	T_score+1,d0
	cmp.b	O_score+1,d0
	beq.s	.no_score2
	move.b	d0,O_score+1
	lea	Score+(8*38)+11,a0
	bsr	print_byte
.no_score2:
	moveq	#0,d0
	move.b	T_score+2,d0
	cmp.b	O_score+2,d0
	beq.s	.no_score3
	move.b	d0,O_score+2
	lea	Score+(8*38)+13,a0
	bsr	print_byte
.no_score3:
	moveq	#0,d0
	move.b	T_time,d0
	cmp.b	O_time,d0
	beq.s	.no_time1
	move.b	d0,O_time
	and.b	#$0f,d0
	lea	Score+(8*38)+17,a0
	bsr	pr_nibble
.no_time1:
	moveq	#0,d0
	move.b	T_time+1,d0
	cmp.b	O_time+1,d0
	beq.s	.no_time2
	move.b	d0,O_time+1
	lea	Score+(8*38)+18,a0
	bsr	print_byte
.no_time2:
	move.w	#38-2,bltdmod(a5)
.bomb_loop
	move.b	T_bombs,d0
	cmp.b	O_bombs,d0
	beq.s	.no_bomb
	bgt.s	.more
	cmp.b	#3,T_bombs
	bge.s	.set_bombanz
	cmp.b	#3,O_bombs
	ble.s	.ok
	move.b	#3,O_bombs
.ok:
	moveq	#0,d1
	move.b	O_bombs,d1
	subq.b	#1,d1
	add.w	d1,d1
	neg.l	d1
	add.l	#Score+(7*38)+26,d1
	bsr	.clr_bomb
	subq.b	#1,O_bombs
	bra.s	.bomb_loop
.more:
	cmp.b	#3,O_bombs
	bge.s	.set_bombanz
	addq.b	#1,O_bombs
	moveq	#0,d1
	move.b	O_bombs,d1
	subq.b	#1,d1
	add.w	d1,d1
	neg.l	d1
	add.l	#Score+(7*38)+26,d1

	move.l	#Score+3680+320,d0	;Source
	bsr	.set_bomb
	bra.s	.bomb_loop
.set_bombanz:
	move.b	T_bombs,O_bombs
.no_bomb:
	move.b	T_energy,d0
	cmp.b	O_energy,d0
	beq.s	.no_energy
	blt.s	.lower
	bsr	.add_energy
	bra.s	.no_energy
.lower:
	bsr	.sub_energy
.no_energy:
	move.w	T_wenergy,d0
	lsr.w	#4,d0
	cmp.b	O_wenergy,d0
	beq.s	.no_wenergy
	blt.s	.wlower
	bsr	.add_wenergy
	bra.s	.no_wenergy
.wlower:
	bsr	.sub_wenergy
.no_wenergy:
	subq.w	#1,.verz
	bpl.s	.no_timesub
	tst.w	T_time
	beq.s	.no_timesub
	tst.b	no_time
	bne.s	.no_timesub
	move.w	#49,.verz
	moveq	#1,d0
	move.w	#0,ccr
	move.b	T_time+1,d1
	sbcd	d0,d1
	move.b	d1,T_time+1
	move.b	T_time,d1
	moveq	#0,d0
	sbcd	d0,d1
	move.b	d1,T_time
	cmp.w	#$0010,T_time
	bge.s	.no_timesub

	PLAY_FX	#$01

.no_timesub:
	rts

.verz:	dc.w	0

.add_energy:
	addq.b	#1,O_energy
	moveq	#0,d0
	move.b	O_energy,d0
	move.b	d0,d1
	lsr.b	#3,d0
	move.l	d0,a1
	add.l	#Score+3680+320+128+1,a1
	add.l	#Score+(8*38)+29,d0
	move.l	d0,a0
	moveq	#0,d2
	move.b	#$ff,d2
	and.w	#7,d1
	bne.s	.do_shift
	subq.l	#1,a1
	subq.l	#1,a0
	moveq	#0,d2
	bra.s	.no_shift
.do_shift:
	lsr.w	d1,d2
.no_shift:
	move.b	d2,d3
	not.b	d3
	moveq	#0,d0
	or.b	d2,d0
	move.b	d0,(a0)
	move.b	d0,912*3(a0)
	and.b	d3,d0
	move.b	d0,912(a0)
	move.b	d0,912*2(a0)
	move.b	912*0(a0),6*38(a0)
	move.b	912*1(a0),912*1+6*38(a0)
	move.b	912*2(a0),912*2+6*38(a0)
	move.b	912*3(a0),912*3+6*38(a0)
	add.l	#38,a0
	move.b	(a1),d0
	or.b	d2,d0
	move.b	d0,(a0)
	move.b	10(a1),d0
	and.b	d3,d0
	move.b	d0,912(a0)
	move.b	20(a1),d0
	and.b	d3,d0
	move.b	d0,912*2(a0)
	move.b	30(a1),d0
	or.b	d2,d0
	move.b	d0,912*3(a0)
	bra	.copy_line

.sub_energy:
	subq.b	#1,O_energy
	moveq	#0,d0
	move.b	O_energy,d0
	move.b	d0,d1
	lsr.b	#3,d0
	add.l	#Score+(8*38)+29,d0
	move.l	d0,a0
	moveq	#0,d2
	move.b	#$ff,d2
	and.w	#7,d1
	lsr.w	d1,d2
	move.b	d2,d3
	not.b	d3
	or.b	d2,(a0)
	and.b	d3,912(a0)
	and.b	d3,912*2(a0)
	or.b	d2,912*3(a0)
	move.b	912*0(a0),6*38(a0)
	move.b	912*1(a0),912*1+6*38(a0)
	move.b	912*2(a0),912*2+6*38(a0)
	move.b	912*3(a0),912*3+6*38(a0)
	add.l	#38,a0
	or.b	d2,(a0)
	and.b	d3,912(a0)
	and.b	d3,912*2(a0)
	or.b	d2,912*3(a0)
.copy_line:
	move.b	(a0),d0
	move.b	d0,38(a0)
	move.b	d0,38*2(a0)
	move.b	d0,38*3(a0)
	move.b	d0,38*4(a0)
	move.b	912(a0),d0
	move.b	d0,912+38(a0)
	move.b	d0,912+38*2(a0)
	move.b	d0,912+38*3(a0)
	move.b	d0,912+38*4(a0)
	move.b	912*2(a0),d0
	move.b	d0,912*2+38(a0)
	move.b	d0,912*2+38*2(a0)
	move.b	d0,912*2+38*3(a0)
	move.b	d0,912*2+38*4(a0)
	move.b	912*3(a0),d0
	move.b	d0,912*3+38(a0)
	move.b	d0,912*3+38*2(a0)
	move.b	d0,912*3+38*3(a0)
	move.b	d0,912*3+38*4(a0)
	rts

.add_wenergy:
	addq.b	#1,O_wenergy
	moveq	#0,d0
	move.b	O_wenergy,d0
	move.b	d0,d1
	lsr.b	#3,d0
	add.l	#Score+(15*38)+29,d0
	move.l	d0,a0
	moveq	#0,d2
	move.b	#$ff,d2
	and.w	#7,d1
	bne.s	.do_wshift
	subq.l	#1,a1
	subq.l	#1,a0
	moveq	#0,d2
	bra.s	.no_wshift
.do_wshift:
	lsr.w	d1,d2
.no_wshift:
	move.b	d2,d3
	not.b	d3
	moveq	#0,d0
	or.b	d2,d0
	move.b	d0,(a0)
	move.b	d0,912*3(a0)
	and.b	d3,d0
	move.b	d0,912(a0)
	move.b	d0,912*2(a0)
	move.b	912*0(a0),6*38(a0)
	move.b	912*1(a0),912*1+6*38(a0)
	move.b	912*2(a0),912*2+6*38(a0)
	move.b	912*3(a0),912*3+6*38(a0)
	add.l	#38,a0
	moveq	#-1,d0
	or.b	d2,d0
	move.b	d0,(a0)
	moveq	#0,d0
	and.b	d3,d0
	move.b	d0,912(a0)
	move.b	d0,912*2(a0)
	or.b	d2,d0
	move.b	d0,912*3(a0)
	bra	.copy_line

.sub_wenergy:
	subq.b	#1,O_wenergy
	moveq	#0,d0
	move.b	O_wenergy,d0
	move.b	d0,d1
	lsr.b	#3,d0
	add.l	#Score+(15*38)+29,d0
	move.l	d0,a0
	moveq	#0,d2
	move.b	#$ff,d2
	and.w	#7,d1
	lsr.w	d1,d2
	move.b	d2,d3
	not.b	d3
	or.b	d2,(a0)
	and.b	d3,912(a0)
	and.b	d3,912*2(a0)
	or.b	d2,912*3(a0)
	move.b	912*0(a0),6*38(a0)
	move.b	912*1(a0),912*1+6*38(a0)
	move.b	912*2(a0),912*2+6*38(a0)
	move.b	912*3(a0),912*3+6*38(a0)
	add.l	#38,a0
	or.b	d2,(a0)
	and.b	d3,912(a0)
	and.b	d3,912*2(a0)
	or.b	d2,912*3(a0)
	bra	.copy_line

.clr_bomb:
	move.w	#$01ff,bltcon0(a5)
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt
	add.l	#38*24,d1
	move.w	#$0100,bltcon0(a5)
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt
	add.l	#38*24,d1
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt
	add.l	#38*24,d1
	move.w	#$01ff,bltcon0(a5)
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt
	rts

.set_bomb:
	move.l	d0,bltapth(a5)
	move.w	#$09f0,bltcon0(a5)
	move.l	#-1,bltafwm(a5)
	move.w	#0,bltamod(a5)
	moveq	#3,d7
.bloop:
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt
	add.l	#38*24,d1
	dbf	d7,.bloop
	rts

print_byte:
	move.w	d0,-(sp)
	lsr.b	#4,d0
	bsr	pr_nibble
	move.w	(sp)+,d0
	and.b	#$0f,d0
pr_nibble:
	asl.w	#5,d0
	lea	(a2,d0.w),a1
	move.b	(a1)+,912*3(a0)
	move.b	(a1)+,(912*3)+(38*1)(a0)
	move.b	(a1)+,(912*3)+(38*2)(a0)
	move.b	(a1)+,(912*3)+(38*3)(a0)
	move.b	(a1)+,(912*3)+(38*4)(a0)
	move.b	(a1)+,(912*3)+(38*5)(a0)
	move.b	(a1)+,(912*3)+(38*6)(a0)
	move.b	(a1)+,(912*3)+(38*7)(a0)
	move.b	(a1)+,(912*3)+(38*8)(a0)
	move.b	(a1)+,(912*3)+(38*9)(a0)
	move.b	(a1)+,(912*3)+(38*10)(a0)
	move.b	(a1)+,(912*3)+(38*11)(a0)
	move.b	(a1)+,(912*3)+(38*12)(a0)
	move.b	(a1)+,(912*3)+(38*13)(a0)
	move.b	(a1)+,(912*3)+(38*14)(a0)
	move.b	(a1)+,(912*3)+(38*15)(a0)

	move.b	(a1)+,(a0)
	move.b	(a1)+,(912*0)+(38*1)(a0)
	move.b	(a1)+,(912*0)+(38*2)(a0)
	move.b	(a1)+,(912*0)+(38*3)(a0)
	move.b	(a1)+,(912*0)+(38*4)(a0)
	move.b	(a1)+,(912*0)+(38*5)(a0)
	move.b	(a1)+,(912*0)+(38*6)(a0)
	move.b	(a1)+,(912*0)+(38*7)(a0)
	move.b	(a1)+,(912*0)+(38*8)(a0)
	move.b	(a1)+,(912*0)+(38*9)(a0)
	move.b	(a1)+,(912*0)+(38*10)(a0)
	move.b	(a1)+,(912*0)+(38*11)(a0)
	move.b	(a1)+,(912*0)+(38*12)(a0)
	move.b	(a1)+,(912*0)+(38*13)(a0)
	move.b	(a1)+,(912*0)+(38*14)(a0)
	move.b	(a1)+,(912*0)+(38*15)(a0)
	addq.l	#1,a0
	rts

init_score_line:
	move.l	#Score+(8*38)+30,d0
	move.w	#38-8,bltdmod(a5)
	move.w	#$01ff,bltcon0(a5)
	move.l	d0,bltdpth(a5)
	move.w	#64*14+4,bltsize(a5)
	waitblt
	move.w	#$0100,bltcon0(a5)
	add.l	#912,d0
	move.l	d0,bltdpth(a5)
	move.w	#64*14+4,bltsize(a5)
	waitblt
	add.l	#912,d0
	move.l	d0,bltdpth(a5)
	move.w	#64*14+4,bltsize(a5)
	waitblt
	move.w	#$01ff,bltcon0(a5)
	add.l	#912,d0
	move.l	d0,bltdpth(a5)
	move.w	#64*14+4,bltsize(a5)
	waitblt

	move.l	#Score+(8*38)+29,a0
	moveq	#13,d7
.loop:
	st	(a0)
	sf	912(a0)
	sf	912*2(a0)
	st	912*3(a0)
	add.l	#38,a0
	dbf	d7,.loop

	clr.b	O_energy
	clr.b	O_wenergy

	moveq	#-1,d0
	move.l	d0,O_lifes
	move.b	d0,O_time
	sf	O_bombs
	move.b	#3,T_bombs

	bra	show_score_line

	*----------------------------------------------------------------------------
	*----------------------------- BG Anim System -------------------------------
	*----------------------------------------------------------------------------
BG_Anim:
	lea	AnimList(pc),a0
.loop:
	move.l	(a0),d0
	beq	.next
	bmi	.end

	move.w	Scr_Scrolled_X(a6),d1
	sub.w	d1,AnimXpos(a0)
	move.w	Scr_Scrolled_Y(a6),d1
	sub.w	d1,AnimYpos(a0)

	move.l	AnimRout(a0),a1
	movem.l	a0/d0,-(sp)
	jsr	(a1)
	movem.l	(sp)+,a0/d0
	bne	.next

	cmp.w	#-16,AnimXpos(a0)
	blt.s	.test
	cmp.w	#304,AnimXpos(a0)
	bge.s	.test
	cmp.w	#-16,AnimYpos(a0)
	blt.s	.test
	cmp.w	#208,AnimYpos(a0)
	bge.s	.test

	add.l	Scr_Supply_Field(a6),d0

	moveq	#0,d1
	move.w	AnimChar(a0),d1
	lsl.w	#7,d1

	add.l	#BG_Chars,d1
	move.l	d1,bltapth(a5)
	move.w	#0,bltamod(a5)
	move.l	d0,bltdpth(a5)
	move.w	#planeb-2,bltdmod(a5)
	move.w	#$09f0,bltcon0(a5)
	move.w	#64*16*4+1,bltsize(a5)
	waitblt
.next:
	lea	AnimEntryLen(a0),a0
	bra	.loop
.end:
	rts

.test:
	move.w	AnimXpos(a0),d0
	bpl.s	.xpos
	neg.w	d0
	bra.s	.xneg
.xpos:
	sub.w	#304,d0
.xneg:
	move.w	AnimYpos(a0),d1
	bpl.s	.ypos
	neg.w	d1
	bra.s	.yneg
.ypos:
	sub.w	#208,d1
.yneg:
	cmp.w	#128,d0
	bgt.s	.out
	cmp.w	#128,d1
	blt.s	.next
.out:
Out_Anim:
	clr.l	AnimSAdr(a0)
	move.l	AnimArea(a0),a1
	clr.b	(a1)			;Wiedereintragen!
	rts

	;d0 = Info
	;d1 = X-Pos
	;d2 = Y-Pos

Search_Anim_Entry:
	lea	AnimList(pc),a4
	lea	AnInfoList(pc),a3
.search:
	move.l	(a4),d7
	bmi.s	.insert
	beq.s	.insert
	lea	AnimEntryLen(a4),a4
	bra	.search
.insert:
	sub.w	Scr_Y_Level_Pos(a6),d2
	move.w	d1,d3
	sub.w	Scr_X_Level_Pos(a6),d3
	move.w	d3,AnimXpos(a4)
	move.w	d2,AnimYpos(a4)
	and.w	#127,d0
	asl.w	#2,d0		;*4
	move.l	(a3,d0.w),AnimRout(a4)
	clr.w	AnimChar(a4)

	add.w	Scr_Y_Play_Anf(a6),d2
	bpl.s	.not_neg
	add.w	Scr_Plane_Height(a6),d2
	bra.s	.not_over
.not_neg:
	cmp.w	Scr_Plane_Height(a6),d2
	blt.s	.not_over
	sub.w	Scr_Plane_Height(a6),d2
.not_over:
	mulu	Scr_Plane_Width(a6),d2
	asr.w	#3,d1
	and.w	#$fffe,d1
	ext.l	d1
	add.l	d1,d2
	move.l	d2,AnimSAdr(a4)

	move.l	a1,AnimArea(a4)

	tst.l	d7
	beq.s	.out
	move.l	d7,AnimEntryLen(a4)
.out:
	rts


AnInfoList:
	dc.l	Flashlight

	rsreset
AnimSAdr	rs.l	1
AnimXpos	rs.w	1
AnimYpos	rs.w	1
AnimRout	rs.l	1
AnimChar	rs.w	1
AnimArea	rs.l	1
AnimEntryLen	rs.l	0

MaxAnim	= 15

AnimList:	dcb.b	AnimEntryLen*MaxAnim,-1

Flashlight:
	lea	Flashlight_Handler(pc),a1
	tst.w	Flash_ident
	bpl.s	.no_add
	bsr	AddHandler
	clr.w	Flash_ident
.no_add:
	addq.w	#1,Flash_ident
	move.w	Flash_Char(pc),d0
	bmi.s	.out
	move.w	d0,AnimChar(a0)
	moveq	#0,d7
.out:
	rts

Flashlight_Handler:
	subq.w	#1,Flash_ident
	bmi	.kill
	subq.w	#1,Flash_verz
	bpl.s	.no_new
	cmp.w	#4,Flash_Char
	beq.s	.waiting
	tst.w	Flash_Char
	bmi.s	.waiting
	move.w	#3,Flash_verz
	addq.w	#1,Flash_Char
	cmp.w	#4,Flash_Char
	bne	.no_new
	clr.w	Flash_Char
.waiting:
	subq.w	#1,Flash_verz2
	bpl.s	.no_new
	tst.w	Flash_Char
	bmi.s	.start_again
	cmp.w	#4,Flash_Char
	beq.s	.stop
	move.w	#0,Flash_verz2
	move.w	#4,Flash_Char
	bra.s	.no_new
.stop:
	move.w	#300,Flash_verz2
	move.w	#-1,Flash_Char
	bra.s	.no_new
.start_again:
	move.w	#15,Flash_verz2
	clr.w	Flash_Char
.no_new:
	clr.w	Flash_ident
	rts

.kill:
	move.l	#Return,-4(a0)
	rts

Flash_ident:	dc.w	-1
Flash_Char:	dc.w	0
Flash_verz:	dc.w	0
Flash_verz2:	dc.w	0

	*----------------------------------------------------------------------------
	*----------------------------- Special Handler ------------------------------
	*----------------------------------------------------------------------------
ExecuteHandler:
	lea	Handler_List(pc),a0
	moveq	#Max_Handler-1,d7
.loop:
	move.l	(a0)+,a1
	movem.l	a0/d7,-(sp)
	jsr	(a1)
	movem.l	(sp)+,a0/d7
	dbf	d7,.loop
	rts

AddHandler:
	lea	Handler_List(pc),a2
	moveq	#Max_Handler-1,d7
.search:
	cmp.l	(a2),a1
	beq.s	.dont_add
	addq.l	#4,a2
	dbf	d7,.search

	lea	Handler_List(pc),a2
	move.l	#Return,d0
	moveq	#Max_Handler-1,d7
.search2:
	cmp.l	(a2),d0
	beq.s	.add
	addq.l	#4,a2
	dbf	d7,.search2
.dont_add:
	rts
.add:
	move.l	a1,(a2)
	rts

Max_Handler	= 4
Handler_List:
		dcb.l	Max_Handler,Return

	*----------------------------------------------------------------------------
	*------------------------------- Bob System ---------------------------------
	*----------------------------------------------------------------------------

RestoreBobs:
	tst.w	Scr_Screen_num(a6)
	beq	.use_list1
	lea	Rest_List2,a0
	bra.s	.use_list2
.use_list1:
	lea	Rest_List1,a0
.use_list2:
	move.l	a0,Rest_Pointer			;Hierhin die neuen Requests eintragen.

	move.w	Scr_Supply_Field(a6),bltdpth(a5)
	move.w	Scr_Refresh_Field(a6),bltapth(a5)

	move.l	#-1,bltafwm(a5)
	move.w	RestFunction,bltcon0(a5)
	move.w	#$0000,bltcon1(a5)

	bra	.first
.loop:
	move.w	(a0)+,d1
	move.w	d1,bltamod(a5)
	move.w	d1,bltdmod(a5)
	move.l	(a0)+,d2
	move.w	d2,bltdptl(a5)
	move.w	d2,bltaptl(a5)
	move.w	d0,bltsize(a5)
.bwait0:
	btst	#14,dmaconr(a5)
	bne	.bwait0
.first:
	move.w	(a0)+,d0
	bne	.loop
.last:
	rts

RestFunction:	dc.w	$09f0
Rest_Pointer:	dc.l	0

Blit_Rope:
	tst.b	T_rope
	beq	.out
	tst.b	T_targeting
	bmi.s	.out
	tst.b	R_blink
	beq.s	.dont_blink
	subq.b	#1,R_blvz
	bpl.s	.dont_blink
	move.b	#0,R_blvz
	tst.b	Scr_Screen_num(a6)
	bne.s	.dont_blink
	move.b	#2,R_blvz
	eor.b	#$80,R_blink
.dont_blink:

	move.l	Scr_Supply_Field(a6),d0
	move.l	d0,bltdpth(a5)
	move.l	d0,bltcpth(a5)
	lea	dmaconr(a5),a4
	move.l	Rest_Pointer,a3
	lea	rope_coords(pc),a2

	tst.b	T_targeting
	bne	.skip0

	tst.w	Scr_Screen_num(a6)
	beq.s	.skip0
	addq.l	#4,a2
.skip0:
	moveq	#7,d7
.rope_loop:
	move.w	(a2)+,d0
	move.w	(a2)+,d1
	bmi.s	.end
	bsr.s	BlitRopeBall
	addq.l	#4,a2
.dont_show:
	dbf	d7,.rope_loop
.end:
	move.l	a3,Rest_Pointer
	clr.w	(a3)
.out:
	tst.b	R_blink
	bpl.s	.no_off
	tst.w	Scr_Screen_num(a6)
	beq.s	.no_off
	eor.b	#$80,R_blink
.no_off:
	rts


BlitRopeBall: 
	tst.w	d0
	bmi	.no
	cmp.w	#304,d0
	bgt	.no
	move.l	#RopeBob,d2
	tst.b	R_blink
	bpl.s	.no_blink
	move.l	#RopeBob+Rmsk01,d2
.no_blink:
	move.l	d2,bltbpth(a5)
	move.l	#RopeBob+Rmsk01,bltapth(a5)

	move.w	Scr_X_Level_Pos(a6),d2
	and.w	#15,d2
	add.w	d2,d0
	move.w	d0,d2
	lsr.w	#3,d0
	and.l	#$fffe,d0

	move.w	Scr_Plane_Height(a6),d3
	sub.w	Scr_Y_Play_Anf(a6),d3
	cmp.w	d3,d1
	bge.s	.under_wrap

	subq.w	#8,d3
	cmp.w	d3,d1
	bgt	.in_wrap

	;Komplett drber.

	add.l	Scr_Blt_Adr1(a6),d0
	bra.s	.goon
.under_wrap:

	;Komplett drunter.

	add.l	Scr_Blt_Adr2(a6),d0
	sub.w	d3,d1
.goon:
	mulu	Scr_Plane_Width(a6),d1
	add.l	d1,d0

	move.l	d0,4(a3)

	and.w	#15,d2
	cmp.w	#7,d2
	blt	.blit_small

	move.l	#$ffff0000,bltafwm(a5)
	moveq	#planeb-4,d3
	move.l	#$fffefffe,d4
	move.w	#64*8*4+2,d5
	bra.s	.blit_it
.blit_small:
	move.l	#-1,bltafwm(a5)
	moveq	#planeb-2,d3
	moveq	#0,d4
	move.w	#64*8*4+1,d5
.blit_it:
	ror.w	#4,d2
	move.w	d2,bltcon1(a5)
	or.w	#$0fca,d2
	move.w	d2,bltcon0(a5)

	add.w	Scr_Supply_Field+2(a6),d0

	move.w	d0,bltdpth+2(a5)
	move.w	d0,bltcpth+2(a5)
	move.w	d3,bltdmod(a5)
	move.w	d3,bltcmod(a5)
	move.w	d3,2(a3)
	move.l	d4,bltbmod(a5)
	move.w	d5,bltsize(a5)
.bwait0:
	btst	#14,(a4)
	bne	.bwait0
	move.w	d5,(a3)

	addq.l	#8,a3
.no:
	rts
.in_wrap:
	move.w	d3,d5
	sub.w	d1,d5
	addq.w	#8,d5

	move.l	d0,-(sp)
	add.l	Scr_Blt_Adr1(a6),d0	;Adresse fr obere Hlfte
	mulu	Scr_Plane_Width(a6),d1
	add.l	d1,d0

	move.l	d0,4(a3)
	asl.w	#8,d5

	and.w	#15,d2
	cmp.w	#7,d2
	blt	.blit_small2

	move.l	#$ffff0000,bltafwm(a5)
	moveq	#planeb-4,d3
	move.l	#$fffefffe,d4
	or.w	#2,d5
	bra.s	.blit_it2
.blit_small2:
	move.l	#-1,bltafwm(a5)
	moveq	#planeb-2,d3
	moveq	#0,d4
	or.w	#1,d5
.blit_it2:
	ror.w	#4,d2
	move.w	d2,bltcon1(a5)
	or.w	#$0fca,d2
	move.w	d2,bltcon0(a5)

	add.w	Scr_Supply_Field+2(a6),d0

	move.w	d0,bltdpth+2(a5)
	move.w	d0,bltcpth+2(a5)
	move.w	d3,bltdmod(a5)
	move.w	d3,bltcmod(a5)
	move.w	d3,2(a3)
	move.l	d4,bltbmod(a5)
	move.w	d5,bltsize(a5)
.bwait1:
	btst	#14,(a4)
	bne	.bwait1
	move.w	d5,(a3)

	addq.l	#8,a3
	move.w	d3,2(a3)

	move.l	(sp)+,d0
	add.l	Scr_Blt_Adr2(a6),d0
	move.l	d0,4(a3)
	add.w	Scr_Supply_Field+2(a6),d0

	move.w	d0,bltdpth+2(a5)
	move.w	d0,bltcpth+2(a5)
	move.w	d5,d6
	and.w	#$003f,d6
	and.w	#$ffc0,d5
	or.w	#64*8*4,d6
	sub.w	d5,d6
	move.w	d6,bltsize(a5)
.bwait2:
	btst	#14,(a4)
	bne	.bwait2
	move.w	d6,(a3)

	addq.l	#8,a3
	rts

	;Rope-bobs

Rbob00	= $000000
Rmsk01	= $000040

	*----------------------------------------------------------------------------
	*----------------------------- PLAYER CONTROL -------------------------------
	*----------------------------------------------------------------------------

Start_dieing:
	st	no_time			;Zeit nicht weiter zhlen
	st	T_dieing
	move.l	#die_tab,T_speedY
	clr.w	death_vz
	sf	T_flash
	clr.w	T_ansize
	clr.w	T_anpos

	tst.b	global_startsound
	beq.s	.no_sound
	move.b	global_stopsound,d0
	bsr	Do_FX
.no_sound:

Handle_death:
	tst.b	T_dieing
	bpl.s	.exploding
	sf	T_flash			;No flickering
	subq.w	#1,death_vz		;Phase over ?
	bpl.s	.no_new
	cmp.w	#37,T_anim		;Unter Wasser ??
	bge.s	.anim_over		;Ja, nix animieren!
	move.l	T_speedY,a0		;Yes, set next anim.-phase
	move.w	(a0)+,d0
	bmi.s	.anim_over

	move.w	d0,T_anim
	move.w	(a0)+,death_vz
	move.l	a0,T_speedY
	bra	T_handle_end
.anim_over:
	neg.b	T_dieing
	move.w	#60,T_speedY
	st	T_flash
.no_new:
	bra	T_handle_end

.exploding:
	subq.w	#1,T_speedY
	bmi.s	.die

	subq.w	#1,death_vz
	bpl	T_handle_end
	addq.w	#8,death_vz

	bsr	rnd
	andi.w	#63,d0
	add.w	T_posY,d0
	sub.w	#32,d0
	move.w	d0,d2
	bsr	rnd
	and.w	#31,d0
	add.w	T_posX(pc),d0
	sub.w	#16,d0
	move.w	d0,d1
	jsr	Start_Explo2

	PLAY_FX	#$1a

	bra	T_handle_end

.die:
	tst.b	T_dead
	bne	T_handle_end
	move.b	#50,T_dead			;End of death-show
	bra	T_handle_end

fast_die:
	PLAY_FX	#8
	move.b	#1,T_dead
	bra	T_handle_end

die_tab:
	dc.w	25,8,26,6,27,12,-1

death_vz:	dc.w	0

Handle_Player:
	tst.b	T_runout
	beq.s	.no_runout
	sf	T_rope
	sf	T_swing
	sf	T_targeting
.no_runout:
	tst.b	T_freeze
	beq.s	.no_freeze
	move.w	T_joyforce,JoyFlags
.no_freeze:
	move.l	Act_Scr_Structure,a6

	move.w	Scr_Scrolled_X(a6),d0	;Player mitscrollen X
	sub.w	d0,T_posX
	sub.w	d0,R_xpos

	move.w	Scr_Scrolled_Y(a6),d0	;mitscrollen Y
	sub.w	d0,T_posY
	sub.w	d0,R_ypos

	move.w	T_posX(pc),T_oldX
	move.w	T_posY(pc),T_oldY

	tst.b	smart_bomb
	beq	.no_bomb
	clr.w	JoyFlags		;Stehenbleiben, wenn die Smartbomb explodiert!
.no_bomb:

	tst.b	T_dieing
	bne	Handle_death

	tst.b	T_runout
	bne.s	.no_check

	cmp.w	#220,T_posY
	bgt	fast_die

.no_check:

	tst.b	T_wheel			;Player rollt als Wheel rum.
	bne	T_do_wheel

	tst.b	T_force_jump
	beq.s	.no_jump
	bmi.s	.start_force
	bset	#JUMP,JoyFlags	
	subq.b	#1,T_force_jump
	bra.s	.no_jump
.start_force:
	move.b	#10,T_force_jump
	bset	#JUMP,JoyFlags
	bra	start_jump
.no_jump:
	btst	#SMART,JoyFlags
	beq.s	.no_smart
	tst.b	T_bombs
	beq.s	.no_smart
	subq.b	#1,T_bombs
	st	smart_bomb
	PLAY_FX	#9
	bclr	#SMART,JoyFlags
.no_smart:

	tst.b	T_hit
	bne.s	.no_button
	bsr	T_handle_button		;Kmmert sich um den kmmerlichen einen Button!
.no_button:
	tst.b	T_swing
	bne	T_do_swing

	tst.b	T_state			;Player Status
	bmi	T_falling
	bne	T_jumping

	tst.b	T_rope
	bne	T_handle_rope

	cmp.w	#22,T_anim
	beq.s	no_target

	btst	#ROPES,JoyFlags+1
	bne	Start_targeting

no_target:
	tst.b	T_runout
	bne.s	.no_check
	bsr	Test_feet
	beq	start_fall
.no_check:
	tst.b	T_energy
	beq	Start_dieing

	tst.b	T_hit
	bne.s	.no_duck
	btst	#DOWN,JoyFlags
	bne	T_duck
.no_duck:
	move.w	T_forceY,d0
	beq.s	.nonew
	bpl.s	.oky
	neg.w	d0
.oky:
	move.w	d0,T_Mspeed_Y
.nonew:
	move.w	#23,T_newanim
	bsr	T_move_x
	beq	.no_xmove
	move.l	#T_walk_tab,T_antab
	move.w	#8,T_ansize
	move.w	#3,T_anspeed

	move.b	T_slope,d5
	beq.s	.no_slope
	bsr	Test_feet
	tst.b	T_slope
	bne.s	.do_slope
	btst	#4,d5
	beq.s	.test_right
	move.w	T_posY,d5
	btst	#RIGHT,JoyFlags
	beq.s	.left
	subq.w	#1,T_posY
	bra.s	.right
.left:
	addq.w	#1,T_posY
.right:
	bsr	Test_feet
	beq.s	.no_slope2
.do_slope:
	bsr	T_floor_align
	bra.s	.no_slope
.test_right:
	move.w	T_posY,d5
	btst	#RIGHT,JoyFlags
	beq.s	.left2
	addq.w	#1,T_posY
	bra.s	.right2
.left2:
	subq.w	#1,T_posY
.right2:
	bsr	Test_feet
	beq.s	.no_slope2
	bra.s	.do_slope

.no_slope2:
	move.w	d5,T_posY
.no_slope:
	bra	.xmove
.no_xmove:
	move.w	T_newanim,T_anim
	clr.w	T_ansize
	clr.w	T_anpos
.xmove:
	btst	#ROPEKF,JoyFlags+1
	beq.s	.no_ropekill

	tst.b	T_rope
	beq.s	.no_ropekill
	PLAY_FX	#6
	sf	T_rope
	sf	T_swing
	clr.w	T_target_count
	bra	stop_swing

.no_ropekill:

	move.b	T_hit,d0
	or.b	T_rejump,d0
	beq	.ask_start
	cmp.b	#Jump_Prell,Jump_Time
	ble.s	.ask_start
	btst	#JUMP,JoyFlags
	sne	T_rejump
	bra	T_handle_end

.ask_start:
	btst	#JUMP,JoyFlags
	bne	start_jump
	bra	T_handle_end

T_duck:
	move.w	#22,T_anim
	clr.w	T_ansize
	clr.w	T_anpos
	clr.b	T_rejump
	tst.b	T_rope
	bne.s	.dont_ask
	tst.w	T_wenergy
	beq	.dont_ask
	btst	#WHEEL,JoyFlags
	bne.s	.start_wheel
.dont_ask:
	move.w	T_forceX,d6
	bsr	T_move_no_dir
	btst	#LEFT,JoyFlags
	bne	.left
	btst	#RIGHT,JoyFlags
	bne	.right
	bra	T_handle_end

.left:
	clr.w	T_face
	bra	T_handle_end

.right:
	move.w	#-1,T_face
	bra	T_handle_end

.start_wheel:
	st	T_wheel
	clr.l	T_speedY
	bra	T_handle_end

Test_feet:
	tst.b	T_stand
	bne	.out2
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#31,d1
	movem.w	d0-d1,-(sp)
	bsr	check_kollision
	bne.s	.check_slopes
	btst	#4,d1
	bne.s	.slopel
	btst	#5,d1
	bne	.sloper
.no_slopes:
	movem.w	(sp),d0-d1
	subq.w	#8,d0
	bsr	check_kollision
	bne.s	.out
	movem.w	(sp)+,d0-d1
	addq.w	#8,d0
	bsr	check_kollision
	bne.s	.out2
.no_ground:
	moveq	#0,d0
	sf	T_slope
	rts
.out:
	movem.w	(sp)+,d0-d1
.out2:
	moveq	#1,d0
	rts

.check_slopes:
	sf	T_slope
	movem.w	(sp),d0-d1
	subq.w	#1,d1
	bsr	check_kollision
	move.b	d1,d2
	and.b	#%01110000,d1
	and.b	#%00110000,d2
	beq.s	.out
	movem.w	(sp)+,d2-d3
	subq.w	#1,d3
	subq.w	#1,T_posY
	movem.w	d2-d3,-(sp)
	btst	#5,d1
	bne.s	.sloper

	;Turris Fe befinden sich in einem Schrgen Modul.

.slopel:
	move.b	d1,T_slope
	move.w	d1,d2
	movem.w	(sp)+,d0-d1
	add.w	Scr_Y_Level_Pos(a6),d1
	move.w	d1,d3
	add.w	T_speedY,d1
	addq.w	#1,d1

	add.w	Scr_X_Level_Pos(a6),d0
	and.w	#15,d0
	neg.w	d0
	add.w	#15,d0
	lsr.w	#1,d0
	btst	#6,d2
	bne.s	.ok
	addq.w	#8,d0
.ok:
	and.w	#$fff0,d3
	add.w	d0,d3
	cmp.w	d1,d3
	bge.s	.no_ground

	moveq	#1,d0
	rts

.sloper:
	move.b	d1,T_slope
	move.w	d1,d2
	movem.w	(sp)+,d0-d1
	add.w	Scr_Y_Level_Pos(a6),d1
	move.w	d1,d3
	add.w	T_speedY,d1
	addq.w	#1,d1

	add.w	Scr_X_Level_Pos(a6),d0
	and.w	#15,d0
	lsr.w	#1,d0
	btst	#6,d2
	bne.s	.ok2
	addq.w	#8,d0
.ok2:
	and.w	#$fff0,d3
	add.w	d0,d3
	cmp.w	d1,d3
	bge	.no_ground

	moveq	#1,d0
	rts

Start_targeting:
	st	T_targeting
	st	T_rope
	clr.w	T_ansize		;Auto-anim stoppen.
	clr.w	T_anpos
	clr.w	R_oldradius1
	move.w	#18,T_anim		;Erste Phase des Zielens.
	move.b	#4,T_target_anvz
	bra	T_handle_end

T_handle_rope:
	tst.b	T_targeting
	beq	no_target

	bsr	Test_feet
	bne.s	.no_fall
	sf	T_rope
	bra	no_target
.no_fall:
	move.w	T_forceX,d6
	beq.s	.no_move
	bpl.s	.force_right


	;To the left
	bsr	Test_side
	beq.s	.no_move
	move.w	T_posX(pc),d0
	add.w	d6,d0
	bmi.s	.no_move	;Ausm Rand.
	bra.s	.do_move
.force_right:
	bsr	Test_side
	beq.s	.no_move
	move.w	T_posX(pc),d0
	add.w	d6,d0
	cmp.w	#320-26,d0
	bgt.s	.no_move	;Ausm Rand.
.do_move:
	add.w	d6,T_posX
.no_move:

	bsr	Test_feet
	bne.s	.on_ground
	sf	T_rope
	sf	T_targeting
	sf	T_swing
	sf	T_startswing

.on_ground:
	tst.b	T_targeting
	bpl	.not_searching
	clr.b	R_blink

	btst	#ROPES,JoyFlags+1
	beq	.stop_targeting

	btst	#LEFT,JoyFlags
	bne	.left
	btst	#RIGHT,JoyFlags
	bne	.right
.out:
	bra	T_handle_end

.left:
	subq.b	#1,T_target_anvz
	bpl	.out
	move.b	#3,T_target_anvz
	tst.w	T_face
	bne	.l_right
	cmp.w	#19,T_anim
	bgt	.out
	addq.w	#1,T_anim
	bra	T_handle_end

.l_right:
	cmp.w	#8,T_anim
	bne	.sub
	clr.w	T_face
	bra	T_handle_end

.sub:
	subq.w	#1,T_anim
	bra	T_handle_end

.right:
	subq.b	#1,T_target_anvz
	bpl	.out
	move.b	#3,T_target_anvz
	tst.w	T_face
	beq	.r_left
	cmp.w	#19,T_anim
	bgt	.out
	addq.w	#1,T_anim
	bra	T_handle_end

.r_left:
	cmp.w	#8,T_anim
	bne	.sub
	move.w	#-1,T_face
	bra	T_handle_end

.stop_targeting:
	move.b	#1,T_targeting
	move.w	#10,R_radius1
	move.w	T_anim,d0
	subq.w	#8,d0
	lea	deg_tab(pc),a0
	move.b	(a0,d0.w),d0
	tst.w	T_face
	bne	.to_right
	move.w	#128,d1
	exg	d0,d1
	sub.w	d1,d0
.to_right:
	add.b	#128,d0
	move.w	d0,R_angle

	PLAY_FX	#4

.not_searching:
	cmp.b	#1,T_targeting
	bne	.not_out

	move.w	R_radius1(pc),d7
	addq.w	#8,d7
	bsr	Rope_inout

	move.w	T_posX(pc),d4			;Get player's position
	move.w	T_posY(pc),d5			;Get player's position
	addi.w	#14,d4
	addi.w	#3,d5
	move.w	R_angle(pc),d0			;Get angle
	bsr	sin				;Calc SIN(X)
	move.w	d0,d2
	move.w	R_angle(pc),d0			;Get angle
	bsr	cos				;Calc COS(X)
	muls	R_radius1(pc),d0		;R*COS(X)
	muls	R_radius1(pc),d2		;R*SIN(X)
	asr.l	#8,d0				;Adjust to normal range
	asr.l	#8,d2
	sub.w	d0,d4				;PX-R*COS(X)
	add.w	d2,d5				;PY+R*SIN(X)

	cmpi.w	#320,d4				;Out of screen ?
	bhs.s	.missed
	cmpi.w	#200,d5
	bhs.s	.missed

	movem.w	d4-d5,-(sp)
	move.w	d4,d0				;Found background ?
	move.w	d5,d1
	addq.w	#4,d0
	add.w	Scr_X_Level_Pos(a6),d0
	add.w	Scr_Y_Level_Pos(a6),d1
	bsr	check_slope_kollision
	movem.w	(sp)+,d0-d1
	bne.s	.found_back

	move.w	d0,d2				;Hit any objects
	move.w	d1,d3
	addq.w	#4,d2
	addq.w	#4,d3
	bsr	check_rec
	tst.w	d0
	beq.s	.no_check

	tst.b	Bob_RopeEnable(a0)
	bne.s	.found_obj

.no_check:
	cmp.w	#MAX_ROPE,R_radius1	;Rope moved out to maximum ?
	blt	T_handle_end

.missed:
	move.b	#2,T_targeting		;Missing, switch to "move-in"
	bra	T_handle_end
.found_obj:				;Attached to object
	st	T_ropeobj
	st	Bob_Rope(a0)		;Tell object that player is attached
	bra.s	.rope_ok
.found_back:				;Attached to background
	sf	T_ropeobj
.rope_ok:
	PLAY_FX	#5
	sf	T_targeting		;"Start the rope"-sequence ends
	bra	T_handle_end

.not_out:
	cmp.w	#20,R_radius1
	ble	.stop_rope
	move.w	R_radius1(pc),d7
	subq.w	#8,d7
	bsr	Rope_inout
	bra	T_handle_end
.stop_rope:
	PLAY_FX	#5
	clr.b	T_targeting
	clr.b	T_rope
	move.l	#-1,rope_coords
	bra	T_handle_end

deg_tab:
	dc.b	64,61,53,46,41,35,28,21,13,6,0,-11,-19
	even

start_jump:
	st	T_rejump
	move.b	#1,T_state		;Jumping state.
	move.l	Jump_Start_Speed,T_speedY
	move.w	#5,T_jumplen
	bra	T_handle_end

Jump_Start_Speed:	dc.l	0
Jump_Verz_Lab:		dc.l	0

T_jumping:
	subq.w	#1,T_jumplen
	move.l	#$00050000,T_Mspeed_Y
	move.w	#21,T_newanim
	clr.w	T_ansize
	clr.w	T_anpos

	move.l	T_speedY,d0
	move.l	T_posY,d6
	add.l	d0,T_posY
	move.l	Jump_Verz_Lab,d0
	add.l	d0,T_speedY
	bpl	.end_jump
	btst	#JUMP,JoyFlags
	bne	.jump1

	;Sprung abbrechen, wg. Knopf losgelassen.

	cmp.l	#-$00028000,T_speedY
	bgt	.jump1
	move.l	#-$00028000,T_speedY

.jump1:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	addq.w	#3,d1
	bsr	check_head_kollision
	bne	.end_jump2
.jump0:
	tst.b	T_rope
	beq.s	.no_rope

	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#14,d0
	addq.w	#3,d1
	movem.w	R_xpos,d2-d3
	bsr	check_rope
	bne	.end_jump2

.no_rope:
	bsr	T_move_x
	move.w	T_newanim,T_anim
	bra	T_handle_end

.end_jump2:
	move.l	d6,T_posY
	tst.w	T_jumplen
	bmi.s	.end_jump
	sf	T_restand		;Bei nchster Kollision stehenbleiben!
.end_jump0:
	move.b	#-1,T_state		;Falling!
	clr.l	T_speedY
	bsr	T_move_x
	st	T_rejump
	move.w	T_newanim,T_anim
	bra	T_handle_end

.end_jump:
	st	T_restand		;Erst nach nchster Freistelle stehenbleiben!
	bra.s	.end_jump0

start_fall:
	move.b	#-1,T_state
	bsr	T_move_x
	move.b	#Fall_Prell,T_falltime
	bra	T_handle_end		;Spieler fllt!

T_falling:
	tst.b	T_falltime
	beq.s	.no_sub
	subq.b	#1,T_falltime
.no_sub:
	move.b	T_hit,d0
	or.b	T_rejump,d0
	bne	.no_ask

	tst.b	T_falltime		;Chance verpasst!
	beq.s	.no_ask

	btst	#JUMP,JoyFlags
	bne	start_jump

.no_ask:
	btst	#JUMP,JoyFlags
	sne	T_rejump

	move.l	#$00050000,T_Mspeed_Y

	move.w	#21,T_newanim
	clr.w	T_ansize
	clr.w	T_anpos

	move.l	T_posY(pc),d6
	move.l	T_speedY(pc),d0
	add.l	d0,T_posY
	add.l	#$00006000,T_speedY
	cmp.l	#$00050000,T_speedY
	blt	.move_x
	move.l	#$00050000,T_speedY

.move_x:
	tst.b	T_rope
	beq.s	.no_rope
	movem.w	R_xpos,d2-d3
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#14,d0
	addq.w	#3,d1

	bsr	check_rope
	beq.s	.no_rope
	bsr	calc_angle
	cmp.w	#128,d0
	ble.s	.no_rope

	move.l	d6,T_posY

	bra	T_start_swing

.no_rope:
	bsr	T_move_x
	move.w	T_newanim,T_anim

	bsr	Test_feet
	beq	.no_ground_found

	tst.b	T_stand
	bne.s	.on_object

	tst.b	T_restand
	beq.s	.stop			;Von Anfang des Fallens an im Background,
					;stehenbleiben NICHT erlaubt! (sonst landet man in der Grafik)
	subq.w	#4,T_posY
	bsr	Test_feet
	bne.s	.out
	addq.w	#4,T_posY
	bra.s	.stop
.out:
	addq.w	#4,T_posY
	bra	T_handle_end
.stop:
	bsr	T_floor_align

.on_object:
	PLAY_FX	#3
	move.b	#0,T_state
	bra	T_handle_end

.no_ground_found:
	sf	T_restand
	bra	T_handle_end


T_floor_align:
	;Align to Ground.
	tst.b	T_slope
	bne.s	.slope_align
	move.w	T_posY,d1
	add.w	#31,d1
	add.w	Scr_Y_Level_Pos(a6),d1
	and.w	#$fff8,d1
	sub.w	Scr_Y_Level_Pos(a6),d1
	sub.w	#31,d1
	move.w	d1,T_posY
	rts
.slope_align:
	btst	#5,T_slope
	bne.s	.align_right

	move.w	T_posY(pc),d1
	add.w	#31,d1
	add.w	Scr_Y_Level_Pos(a6),d1
	and.w	#$fff0,d1
	sub.w	Scr_Y_Level_Pos(a6),d1
	sub.w	#31,d1

	move.w	T_posX(pc),d0
	add.w	Scr_X_Level_Pos(a6),d0
	and.w	#15,d0
	neg.w	d0
	add.w	#15,d0
	lsr.w	#1,d0
	btst	#6,T_slope
	bne.s	.ok
	addq.w	#8,d0
.ok:
	add.w	d0,d1
	move.w	d1,T_posY
	rts

.align_right:
	move.w	T_posY(pc),d1
	add.w	#31,d1
	add.w	Scr_Y_Level_Pos(a6),d1
	and.w	#$fff0,d1
	sub.w	Scr_Y_Level_Pos(a6),d1
	sub.w	#31,d1

	move.w	T_posX(pc),d0
	add.w	Scr_X_Level_Pos(a6),d0
	and.w	#15,d0
	lsr.w	#1,d0
	btst	#6,T_slope
	bne.s	.ok2
	addq.w	#8,d0
.ok2:
	add.w	d0,d1
	move.w	d1,T_posY
	rts


* --------------------
* Wheel bearbeiten
* --------------------

T_do_wheel:
	move.l	#$00040000,T_Mspeed_X

	tst.w	T_wenergy
	beq.s	.stand_up

	tst.b	T_rejump
	bne	.dont_ask

	btst	#JUMP,JoyFlags
	beq	.dont_ask

	;Rad ist beendet.
.stand_up:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#8,d1
	bsr	check_kollision
	bne	.dont_ask
	sf	T_wheel			;Aufgesprungen!
	clr.w	T_anpos
	bra	T_handle_end

.dont_ask:
	btst	#JUMP,JoyFlags
	sne	T_rejump

	tst.w	T_wenergy		;Ist die Energie schon auf 0 ??
	beq.s	.no_sub
	subq.w	#1,T_wenergy
.no_sub:
	move.l	#T_roll_tab,T_antab
	move.w	#4,T_ansize
	move.w	#1,T_anspeed

	bsr	Test_feet
	bne	.is_ground

	bsr	T_handle_button_wheel
	beq.s	.no_button
	bsr	Search_Mine
	bpl	.no_button
	st	T_mine
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	move.w	d0,(a1)
	move.w	d1,2(a1)
	move.w	#1,4(a1)
.no_button:
	;Kein Grund unter den Fssen.
	tst.w	T_speedY
	bpl	.dont_check_head

	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#8,d1
	bsr	check_kollision
	beq	.dont_check_head
	;Kopf ist Kollidiert.

	clr.w	T_speedY

.dont_check_head:
	cmp.w	#5,T_speedY
	bge	.nobounce
	add.l	#$00007000,T_speedY
	bra	.nobounce

.is_ground:
	bsr	T_floor_align

	bsr	T_handle_button_wheel
	beq.s	.no_button2
	bsr	Search_Mine
	bpl	.no_button2
	st	T_mine
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#10,d0
	add.w	#28,d1
	move.w	d0,(a1)
	move.w	d1,2(a1)
	move.w	#0,4(a1)
	move.w	#30,6(a1)
	PLAY_FX	#$0b
.no_button2:

	btst	#LEFT,JoyFlags
	bne	.left
	btst	#RIGHT,JoyFlags
	beq	.nodir
	move.w	#-1,T_face
	bra.s	.nodir
.left:
	clr.w	T_face
.nodir:
	neg.l	T_speedY
	beq	.nobounce

	bpl	.subit
	PLAY_FX	#$0a
	add.l	#$14000,T_speedY
	ble.s	.nobounce
	clr.l	T_speedY
	bra.s	.nobounce
.subit:
	sub.l	#$14000,T_speedY
	bpl.s	.nobounce
	clr.l	T_speedY
.nobounce:
	move.l	T_speedY,d0
	add.l	d0,T_posY


	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1

	tst.w	T_face
	bne	.check_right
	moveq	#-4,d5
	tst.b	T_runout
	bne.s	.no_check
	tst.w	d0
	ble	.change_dir
	sub.w	#16,d0
	bra.s	.checkit
.check_right:
	moveq	#4,d5
	tst.b	T_runout
	bne.s	.no_check
	cmp.w	#320-32,d0
	bge	.change_dir
	add.w	#12,d0
.checkit:
	add.w	#16,d1
	movem.w	d0/d1,-(sp)
	bsr	check_kollision
	movem.w	(sp)+,d0/d1
	bne	.change_dir
	tst.b	T_slope
	bne.s	.no_check
	addq.w	#8,d1
	bsr	check_kollision
	bne	.change_dir
.no_check:
	add.w	d5,T_posX

	move.b	T_slope(pc),d5
	beq.s	.no_slope
	bsr	Test_feet
	tst.b	T_slope
	bne.s	.do_slope
	btst	#4,d5
	beq.s	.test_right
	move.w	T_posY(pc),d5
	tst.w	T_face
	beq.s	.left3
	subq.w	#2,T_posY
	bra.s	.right3
.left3:
	addq.w	#2,T_posY
.right3:
	bsr	Test_feet
	beq.s	.no_slope2
.do_slope:
	bsr	T_floor_align
	bra.s	.no_slope
.test_right:
	move.w	T_posY(pc),d5
	tst.w	T_face
	beq.s	.left2
	addq.w	#2,T_posY
	bra.s	.right2
.left2:
	subq.w	#2,T_posY
.right2:
	bsr	Test_feet
	beq.s	.no_slope2
	bra.s	.do_slope

.no_slope2:
	move.w	d5,T_posY
.no_slope:

	bra	T_handle_end

.change_dir:
	not.w	T_face
	bra	T_handle_end

T_handle_end:
	move.w	T_forceY(pc),d2
	beq.s	.no_forceY

	tst.b	T_rope
	beq.s	.do_force
	tst.b	T_targeting
	bne.s	.do_force
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	d2,d1
	add.w	#14,d0
	add.w	#3,d1
	movem.w	R_xpos(pc),d2-d3
	bsr	check_rope
	beq	.do_force
	tst.w	T_forceY
	bpl.s	.no_forceY
	sf	T_rope
	sf	T_swing
	bra.s	.no_forceY

.do_force:
	move.w	T_forceY(pc),d0
	add.w	d0,T_posY

.no_forceY:
	tst.b	T_rope
	beq	.no_rope
	move.w	R_radius1(pc),d0
	mulu	d0,d0
	move.w	d0,R_radius
	tst.b	T_targeting
	bmi.s	.no_rope
	bsr	draw_rope
.no_rope:
	tst.b	T_flash
	bne	.no_check
	bsr	check_player		;Kollision-Check!
	beq	.no_check
	move.b	T_wheel,d1
	or.b	T_shield,d1
	bne.s	.no_normal
	tst.w	d0
	smi	T_hitdir
	cmp.b	#BOB_NOPLHURT,Bob_Used(a0)
	bne.s	.do_hurt
	move.b	T_energy,-(sp)
	bsr	make_plhit
	move.b	(sp)+,T_energy
	bra	.no_check
.do_hurt:
	bsr	make_plhit
	bra	.no_check
.no_normal:
	move.b	T_wheel,d1
	and.b	Boss_flag,d1
	bne.s	.no_sub
	move.w	#FLICKER,Bob_Hit(a0)
	subq.w	#2,Bob_Power(a0)
	bpl.s	.no_sub
	clr.w	Bob_Power(a0)
.no_sub:
	tst.b	T_wheel
	beq	.no_check
	not.w	T_face
	tst.b	Boss_flag			;Nicht nach oben schwingen!
	bne.s	.no_check
	tst.w	T_speedY
	bne.s	.not_equ
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#8,d1
	bsr	check_kollision
	bne.s	.no_check
	subq.w	#2,T_posY
.not_equ:
	cmp.w	#-4,T_speedY
	ble.s	.no_check
	subq.w	#2,T_speedY
.no_check:
	clr.b	T_stand
	clr.l	T_forceX
	st	G_keytab+2

	move.w	T_posX(pc),d0
	sub.w	T_oldX(pc),d0
	bpl.s	.ok
	neg.w	d0
.ok:
	move.w	d0,T_Mspeed_X
	move.w	T_posY(pc),d0
	sub.w	T_oldY(pc),d0
	bpl.s	.ok2
	neg.w	d0
.ok2:
	move.w	d0,T_Mspeed_Y
	rts

T_move_x:
	move.w	T_forceX,d6
	btst	#LEFT,JoyFlags
	bne	.move_left
	btst	#RIGHT,JoyFlags
	beq	T_move_no_dir
	addq.w	#2,d6
	move.w	#-1,T_face
	bra.s	T_move_no_dir
.move_left:
	subq.w	#2,d6
	clr.w	T_face
T_move_no_dir:
	tst.b	T_hit
	beq.s	.no_hit

	move.w	#25,T_newanim
	subq.b	#1,T_hit
	beq	.no_move2

	tst.b	T_state
	bne.s	.no_slope_check
	tst.b	T_slope
	bne	.no_move2
.no_slope_check:
	tst.b	T_hitdir
	beq.s	.check_right
	moveq	#-2,d6		;Adjust for checking
	bsr	Test_side	;Check for wall
	beq	.no_move2	;Wall detected...
	bra.s	.move
.check_right:
;	cmpi.w	#320,d6
;	bgt	.no_move2
	moveq	#2,d6
	bsr	Test_side
	beq	.no_move2
.move:
	moveq	#0,d6
	move.b	T_hit(pc),d6
	lsr.w	#2,d6
	tst.b	T_hitdir
	beq.s	.not_to_left
	neg.w	d6
.not_to_left:
	bsr	.no_rope
	moveq	#0,d0
	rts
.no_move2:
	moveq	#0,d0
	rts
.no_hit:
	tst.b	T_runout
	bne.s	.no_side_check
	bsr	Test_side
	beq	.nomove2
.no_side_check:
	tst.b	T_rope
	beq.s	.no_rope
	movem.w	R_xpos,d2-d3
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#14,d0
	add.w	d6,d0
	add.w	#3,d1
	bsr	check_rope
	bmi	.nomove2
.no_rope:
	add.w	d6,T_posX
	move.w	d6,d0
	beq.s	.ok2
	bpl.s	.ok
	neg.w	d0
.ok:
	move.w	d0,T_Mspeed_X
.ok2:
	cmp.w	T_forceX,d6
	rts
.nomove2:
	moveq	#0,d0
	rts

Test_side:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	add.w	#30,d1
	tst.w	d6
	bmi.s	.left
	add.w	#10,d0
	tst.b	T_runout
	bne.s	.right
	cmp.w	#290,d0
	bge.s	.is_wall2
	bra.s	.right
.left:
	sub.w	#10,d0
	tst.b	T_runout
	bne.s	.right
	cmp.w	#-14,d0
	blt.s	.is_wall2
.right:
	add.w	d6,d0
	tst.b	T_slope
	bne.s	.skip
	movem.w	d0/d1,-(sp)
	bsr	check_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
.skip:
	sub.w	#10,d1
	movem.w	d0/d1,-(sp)
	bsr	T_check_slope_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
	sub.w	#10,d1
	movem.w	d0/d1,-(sp)
	bsr	T_check_slope_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
	moveq	#1,d0
	rts	
.is_wall:
	movem.w	(sp)+,d0/d1
.is_wall2:
	moveq	#0,d0
	rts

test_line:
	movem.l	d3-d4/a6,-(sp)
	move.l	Act_Scr_Structure,a6
	add.w	#28,d1
	movem.w	d0/d1,-(sp)
	bsr	check_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
	sub.w	#10,d1
	movem.w	d0/d1,-(sp)
	bsr	check_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
	sub.w	#10,d1
	movem.w	d0/d1,-(sp)
	bsr	check_kollision
	bne	.is_wall
	movem.w	(sp)+,d0/d1
	movem.l	(sp)+,d3-d4/a6
	moveq	#1,d0
	rts	
.is_wall:
	movem.w	(sp)+,d0/d1
	movem.l	(sp)+,d3-d4/a6
	moveq	#0,d0
	rts

*--------------------------------------------------------
*-------------- SCHWUUIINGNGNG ! ! ----------------------
*--------------------------------------------------------

T_start_swing:
	PLAY_FX	#7
	st	T_swing
	st	T_startswing
	bsr	calc_angle
	move.l	d1,R_angle

	clr.l	T_speedY
	cmp.w	#185,d0
	blo.s	.no_speed
	cmp.w	#200,d0
	bhi.s	.no_speed
	move.l	#$00018000,T_speedY
.no_speed

T_do_swing:
	move.l	#$00050000,T_Mspeed_Y

	btst	#ROPEKA,JoyFlags+1
	beq.s	.dont_ask
	PLAY_FX	#6
	sf	T_rope
	sf	T_swing
	sf	T_startswing
;	move.w	R_angle(pc),d0
;	sub.w	#64,d0
;	and.w	#255,d0
;	cmp.w	#128,d0
;	bge.s	.check_right
;	tst.l	T_speedY
;	bmi	.start_jump
;	bra.s	.dont_ask
;.check_right:
;	tst.l	T_speedY
;	ble	.dont_ask

.start_jump:
	st	T_rejump
	move.b	#1,T_state		;Jumping state.
	move.l	#-$00069000,T_speedY
	move.l	Act_Scr_Structure,a6
	lea	custom,a5
	bra	T_jumping

.dont_ask:
	move.w	#24,T_anim
	clr.w	T_ansize
	moveq	#0,d2

	move.w	R_angle(pc),d0
	cmp.w	#128,d0
	ble.s	.no_dir_check
	btst	#RIGHT,JoyFlags
	beq.s	.not_right1
	move.w	#-1,T_face
	move.w	#$0600,d2
.not_right1:	
	btst	#LEFT,JoyFlags
	beq.s	.no_dir_check
	clr.w	T_face
	move.l	#-$0600,d2
.no_dir_check:
	move.w	R_radius1(pc),a5
	btst	#DOWN,JoyFlags
	beq.s	.no_longer
	cmp.w	#MAX_ROPE,R_radius1
	bge.s	.no_longer
	addq.w	#1,R_radius1
	move.w	R_radius1(pc),d0
	lsr.w	#3,d0
	add.w	d0,d0
	lea	rope_buffer(pc),a0
	move.w	R_angle,-2(a0,d0.w)
.no_longer:
	btst	#UP,JoyFlags
	beq.s	.no_shorter
	cmp.w	#10,R_radius1
	ble.s	.no_shorter
	subq.w	#1,R_radius1
.no_shorter:
	move.l	T_speedY,d1
	move.w	R_angle,d0
	sub.w	#64,d0
	cmp.b	#128,d0

	blo.s	.lab1
	sub.l	#$00001000,d1
	add.l	d2,d1
	bra.s	.lab0
.lab1:
	add.l	#$00001000,d1
	add.l	d2,d1
.lab0:
	move.l	d1,d0

	bpl.s	.noneg
	neg.l	d0
.noneg:

	cmp.l	#$00010000,d0

	ble.s	.lab2
	tst.l	d1
	bpl.s	.lab3
	add.l	#$00000100,d1
	bra.s	.lab2
.lab3:
	sub.l	#$00000100,d1
.lab2:
	move.l	#-$00040000,d0
	cmp.l	d0,d1
	bge.s	.lab5
	move.l	d0,d1
	bra.s	.lab6
.lab5:
	neg.l	d0
	cmp.l	d0,d1
	ble.s	.lab6
	move.l	d0,d1
.lab6:
	tst.w	T_speedY			;Changed direction ?
	bpl.s	.check_left
	tst.l	d1
	bpl.s	.do_sound
	bra.s	.no_sound
.check_left:
	tst.l	d1
	bpl.s	.no_sound
.do_sound:
	PLAY_FX	#7
.no_sound:
	move.l	d1,T_speedY
	move.l	R_angle,a6
	add.l	d1,R_angle
	and.w	#255,R_angle

	bsr	calc_player

	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	cmp.w	d3,d0
	beq.s	.lab7
	blt.s	.lab8
	sub.w	#16,d0
	bsr	test_line
	beq.s	.stop_swing1
	bra.s	.lab7
.lab8:
	add.w	#16,d0
	bsr	test_line
	bne.s	.lab7
.stop_swing1:
	move.w	T_posX(pc),d3
	move.w	T_posY(pc),d4
	move.l	a6,R_angle
	move.w	a5,R_radius1
	clr.l	T_speedY
	bra.s	.end
.lab7:
	cmp.w	T_posY(pc),d4
	beq.s	.lab9
	bgt.s	.lab10
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1

	cmp.w	#-16,d1
	blt.s	.stop_swing1
	addq.w	#3,d1
	movem.l	d3-d4/a6,-(sp)
	move.l	Act_Scr_Structure,a6
	bsr	check_head_kollision
	movem.l	(sp)+,d3-d4/a6
	bne	.stop_swing1
.lab10:
	movem.l	d3-d4/a6,-(sp)
	move.l	Act_Scr_Structure,a6
	bsr	Test_feet
	movem.l	(sp)+,d3-d4/a6
	bne.s	stop_swing
.lab9:
	move.w	d3,T_posX
	move.w	d4,T_posY

.end:
	move.l	Act_Scr_Structure,a6
	lea	custom,a5

	move.w	T_oldX(pc),d0
	sub.w	T_posX(pc),d0
	beq	T_handle_end
	bpl.s	.noneg2
	neg.w	d0
.noneg2:
	cmp.w	#2,d0
	bgt.s	.set
	moveq	#2,d0
.set:
	move.w	#$0004,T_Mspeed_X

	bra	T_handle_end
stop_swing:
	sf	T_state
	sf	T_swing
	sf	T_startswing
	move.l	Act_Scr_Structure,a6
	lea	custom,a5
	tst.b	T_stand
	bne	T_handle_end
	bsr	T_floor_align
	bra	T_handle_end

T_handle_button_wheel:
	tst.b	JoyFire
	beq	.not_pressed
	tst.b	T_bomb_time
	beq.s	.start_mine
	addq.b	#1,T_bomb_time
	cmp.b	#Bomb_Verz,T_bomb_time
	bgt.s	.do_start
	moveq	#0,d0
	rts

.do_start:
	sf	T_bomb_time
.start_mine:
	addq.b	#1,T_bomb_time
	st	T_button_pressed
	moveq	#1,d0
	rts

.not_pressed:
	sf	T_button_pressed
	sf	T_button_longpressed
	sf	R_blink
	sf	T_bomb_time
	moveq	#0,d0
	rts

T_handle_button:
	btst	#FIRE,JoyFlags
	beq	.not_pressed
	tst.b	T_button_pressed
	beq	.start_bullet
	rts

.start_bullet:
	tst.b	T_wheel
	bne.s	.no_rocket
	tst.b	T_rocket
	beq.s	.no_rocket
	tst.b	T_rocket_time		;Neue Rakete mglich ?
	bne.s	.no_rocket
	jsr	start_rocket
	move.b	#Rocket_Verz,T_rocket_time
.no_rocket:
	clr.w	T_target_count
	st	T_button_pressed

	tst.b	T_noshot		;Schieen verboten !
	bne	Return

	tst.b	Mine_X+4
	bpl	Return
	tst.b	Mine_X+12
	bpl	Return
	tst.b	Mine_X+20
	bpl	Return
	tst.b	Mine_X+28
	bpl	Return

	sf	T_mine			;Keine Mine mehr da !

	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	move.b	T_power(pc),d2
	cmp.b	#1,T_weapon
	beq	.start_spread
	bgt	.start_blueshot
	cmp.b	#1,d2
	beq	.l_start2
	bgt	.l_start3

	moveq	#$0f,d6
	lea	W_lazer1_info(pc),a0
	bra	W_start_shoot
.l_start2:
	moveq	#$10,d6
	lea	W_lazer2_info(pc),a0
	bra	W_start_shoot
.l_start3:
	moveq	#$11,d6
	lea	W_lazer3_info(pc),a0
	bra	W_start_shoot

.start_spread:
	cmp.b	#1,d2
	beq	.s_start2
	bgt	.s_start3
	moveq	#$0c,d6
	lea	W_spread1_info(pc),a0
	bra	W_start_shoot
.s_start2:
	moveq	#$0d,d6
	lea	W_spread2_info(pc),a0
	bsr	W_start_shoot
	tst.w	d7
	bmi.s	.out
	addq.w	#7,d1
	move.w	d1,8(a1)
	subq.w	#3,d1
	move.w	d1,6(a1)
	rts
.s_start3:
	moveq	#$0e,d6
	lea	W_spread3_info(pc),a0
	bsr	W_start_shoot
	tst.w	d7
	bmi.s	.out
	addq.w	#7,d1
	move.w	d1,8(a1)
	subq.w	#3,d1
	move.w	d1,6(a1)
.out:
	rts

.start_blueshot:
	moveq	#$12,d6
	lea	W_bounce1_info(pc),a0
	bsr	W_start_shoot
	tst.w	d7
	bmi.s	.out
	lea	Bounce_List(pc),a0
	move.w	(a0),d2
	or.w	Bounce_len(a0),d2
	bne.s	.out

	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1

	move.w	#1,(a0)
	move.w	#1,Bounce_len(a0)
	move.b	#1,Bounce_0+1(a0)
	move.b	#0,Bounce_0+1+Bounce_len(a0)
	move.w	d0,Bounce_X(a0)
	move.w	d0,Bounce_X+Bounce_len(a0)

	move.w	d1,d2
	cmp.w	#22,T_anim
	beq.s	.ducking
	sub.w	#9,d2
.ducking:
	move.w	d2,Bounce_Y(a0)
	add.w	#16+8,d2
	move.w	d2,Bounce_Y+Bounce_len(a0)
	sf	Bounce_1(a0)
	sf	Bounce_1+Bounce_len(a0)
	move.b	T_face+1,d2
	not.b	d2
	move.b	d2,Bounce_0(a0)
	move.b	d2,Bounce_0+Bounce_len(a0)
	bne.s	.out
	add.w	#24,Bounce_X(a0)
	add.w	#24,Bounce_X+Bounce_len(a0)
	rts

.not_pressed:
	sf	T_button_pressed
	rts

T_target_count:	dc.w	0
T_weapon:	dc.b	1
T_weapon_new:	dc.b	0
T_power:	dc.b	2
T_power_new:	dc.b	0
T_power1:	dc.b	0
T_power2:	dc.b	0
T_power3:	dc.b	0
T_targeting:	dc.b	0
T_target_anvz:	dc.b	0
T_rope:		dc.b	0
T_swing:	dc.b	0
T_restand:	dc.b	0
T_stand:	dc.b	0
T_startswing:	dc.b	0
T_ropeobj:	dc.b	0
T_forceX:	dc.w	0
T_forceY:	dc.w	0
T_jumplen:	dc.w	0

T_Mspeed_X:	dc.l	0
T_Mspeed_Y:	dc.l	0

T_oldX:		dc.w	0
T_oldY:		dc.w	0
T_newanim:	dc.w	0
T_shieldpos:	dc.w	33
T_joyforce:	dc.w	0

T_state:	dc.b	0
T_wheel:	dc.b	0
T_rejump:	dc.b	0
T_force_jump:	dc.b	0
T_hit:		dc.b	0
T_hitdir:	dc.b	0
T_flash:	dc.b	0
T_shield:	dc.b	0
T_noshot:	dc.b	0
T_dieing:	dc.b	0
T_dead:		dc.b	0
T_rocket:	dc.b	0
T_rocket_anz:	dc.b	0
T_mine:		dc.b	0
T_freeze:	dc.b	0
T_runout:	dc.b	0
T_slope:	dc.b	0
T_bomb_time:	dc.b	0
T_norope:	dc.b	0
T_super_turrican:	dc.b	0

T_button_pressed:	dc.b	0
T_button_longpressed:	dc.b	0

T_rocket_time:	dc.b	0
Boss_flag:	dc.b	0
	even

* -----------------------------------------------------
* - - - - - - - - - - ? R O P E ! - - - - - - - - - - -
* -----------------------------------------------------

check_rope:
	sub.w	d0,d2				;DX
	sub.w	d1,d3				;DY
	muls	d2,d2		;KREISCH!
	muls	d3,d3		;  !!!
	add.w	d3,d2				;DX^2+DY^2
	move.w	d2,d4

	move.b	T_swing.w,d0
	tst.b	T_state
	bpl.s	.dont_set
	or.b	#1,d0
.dont_set:
	tst.b	d0
	beq.s	.not_falling
		cmp.w	R_radius,d4		;Bigger than R^2 ?
		bgt.s	.rope_illegal		;Yes, rope is "illegal"
.not_falling:
	cmpi.w	#MAX_ROPE*MAX_ROPE,d4
	bgt.s	.rope_illegal

	cmpi.w	#10*10,d4			;New R^2 smaller than 10^2 ?
	bls.s	.rope_illegal			;Yes, rope is "illegal"

	move.w	d4,R_radius			;Everything ok, save new R^2
	move.w	d4,d0
	bsr	sqrt
	move.w	d0,R_radius1
	moveq	#0,d0				;Flag to ok
	rts
.rope_illegal:
	moveq	#-1,d0				;Flag to error
	rts

check_rope2:
	sub.w	d0,d2				;DX
	sub.w	d1,d3				;DY
	muls	d2,d2		;KREISCH!
	muls	d3,d3		;  !!!
	add.w	d3,d2				;DX^2+DY^2
	move.w	d2,d4

	cmpi.w	#MAX_ROPE*MAX_ROPE,d4
	bgt.s	.rope_illegal

	cmpi.w	#10*10,d4			;New R^2 smaller than 10^2 ?
	bls.s	.rope_illegal			;Yes, rope is "illegal"

	move.w	d4,R_radius			;Everything ok, save new R^2
	move.w	d4,d0
	bsr	sqrt
	move.w	d0,R_radius1
.rope_legal:
	moveq	#0,d0				;Flag to ok
	rts
.rope_illegal:
	moveq	#-1,d0				;Flag to error
	rts

Rope_inout:
	move.w	d7,d0
	mulu	d0,d0
	move.w	d7,R_radius1
	move.w	d0,R_radius
	move.w	R_angle(pc),d3
	addi.b	#128,d3
	move.w	d3,d0
	bsr	sin
	move.w	d0,d2
	move.w	d3,d0
	bsr	cos
	muls	d7,d0
	muls	d7,d2
	asr.l	#8,d0
	asr.l	#8,d2
	move.w	T_posX(pc),d3
	move.w	T_posY(pc),d4
	addi.w	#14,d3
	addi.w	#3,d4
	add.w	d0,d3
	sub.w	d2,d4
	movem.w	d3-d4,R_xpos
	rts

draw_rope:
	move.l	R_angle(pc),-(sp)
	move.b	T_swing(pc),d0
	or.b	T_targeting(pc),d0
	bne.s	.notzero
	bsr	calc_angle
	move.l	d1,R_angle
.notzero:
	bsr	move_rope
	move.w	R_radius1(pc),d7
	lsr.w	#3,d7
	subq.w	#1,d7
	bmi	.out
		lea	rope_buffer(pc),a6
		lea	rope_coords(pc),a5
		moveq	#0,d5
.loop:
			move.w	(a6),d0
			bsr	sin
			move.w	d0,d2
			move.w	(a6)+,d0
			bsr	cos
			muls	d5,d0
			muls	d5,d2
			asr.l	#8,d0
			asr.l	#8,d2
			add.w	R_xpos(pc),d0
			move.w	R_ypos(pc),d1
			sub.w	d2,d1
			bmi.s	.no
			move.w	d0,(a5)+
			move.w	d1,(a5)+
.no:
			addq.w	#8,d5
		dbf	d7,.loop
		move.l	#-1,(a5)+
		move.l	#-1,(a5)
.out:
	move.l	(sp)+,R_angle
	lea	custom,a5

	rts

move_rope:
	move.w	R_oldradius1(pc),d0
	lsr.w	#3,d0
	lea	rope_buffer(pc),a0
	subq.w	#2,d0
	bmi.s	.no_len
.copyit:
	move.w	2(a0),(a0)+
	dbf	d0,.copyit
.no_len:
	move.w	R_angle(pc),d1
	move.w	R_oldradius1(pc),d0
	move.w	R_radius1(pc),d2
	lsr.w	#3,d0
	lsr.w	#3,d2
	cmp.w	d0,d2
	bgt.s	.higher1
	move.w	d1,(a0)
	bra.s	.lower1
.higher1:
	move.w	d0,d3
	add.w	d3,d3
	lea	rope_buffer(pc),a0
	adda.w	d3,a0
	sub.w	d0,d2
	subq.w	#1,d2
	bpl.s	.ok1
	moveq	#0,d2
.ok1:
	move.w	d1,(a0)+
	dbf	d2,.ok1
.lower1:
	move.w	R_radius1(pc),R_oldradius1
	rts

calc_player:
	move.w	R_angle(pc),d0			;Get angle
	bsr	sin				;Calc SIN(X)
	move.w	d0,d2
	move.w	R_angle(pc),d0			;Get angle
	bsr	cos				;Calc COS(X)
	muls	R_radius1(pc),d0			;R*COS(X)
	muls	R_radius1(pc),d2			;R*SIN(X)
	asr.l	#8,d0				;Adjust to normal range...
	asr.l	#8,d2
	movem.w	R_xpos(pc),d3-d4		;Get rope fix-coordinates
	add.w	d0,d3				;RX+R*COS(X)
	sub.w	d2,d4				;RY-R*SIN(X)
	sub.w	#14,d3				;Adjust to player...
	subq.w	#3,d4
	rts

calc_radius:					;Calc radius
	movem.w	R_xpos(pc),d2-d3
	sub.w	d2,d0
	sub.w	d3,d1
	muls	d0,d0
	muls	d1,d1
	add.w	d1,d0
	move.w	d0,-(sp)
	bsr	sqrt
	move.w	(sp)+,d1
	rts

calc_angle:
	movem.w	R_xpos(pc),d2-d3		;Get rope-coordinates
	move.w	T_posX(pc),d4
	move.w	T_posY(pc),d5
calc_angle2:
	addi.w	#14,d4
	addi.w	#3,d5
calc_angle1:
	moveq	#0,d1
	move.w	d3,d1
	sub.w	d5,d1				;|DY|
	bpl.s	.noneg
	neg.w	d1
.noneg:
	cmp.w	R_radius1,d1
	blt.s	.ok
	move.w	R_radius1,d1
.ok:
	asl.w	#7,d1
	divu	R_radius1(pc),d1			;SIN(X)   (|DY|/R)
	moveq	#0,d0
	lea	asin_tab(pc),a0
	move.b	(a0,d1.w),d0			;Angle	(ASIN(SIN(X)))
	cmp.w	d2,d4				;Adjust angle to full 256 "degrees"
	blt.s	.not_bigger1
	cmp.w	d3,d5
	blt.s	.not_bigger2
	move.w	#256,d1
	sub.w	d0,d1
	bra.s	set_angle
.not_bigger2:
	move.w	d0,d1
	bra.s	set_angle
.not_bigger1:
	cmp.w	d3,d5
	blt.s	.not_bigger3
	move.w	d0,d1
	addi.w	#128,d1
	bra.s	set_angle
.not_bigger3:
	move.w	#128,d1
	sub.w	d0,d1

set_angle:					;Save angle with float-part
	andi.w	#255,d1
	move.w	d1,d0
	swap	d1
	clr.w	d1
	rts

asin_tab:
	dc.b	0,1,1,1,2,2,2,3,3,3,4,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9	;29
	dc.b	10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,15,15,16,16	;20
	dc.b	16,17,17,17,18,18,18,19,19,20,20,20,21,21,21,22,22,22,23,23	;20
	dc.b	24,24,24,25,25,26,26,26,27,27,28,28,28,29,29,30,30,30,31,31	;20
	dc.b	32,32,33,33,34,34,35,35,36,36,37,37,38,38,39,39,40,40,41,42	;20
	dc.b	42,43,43,44,45,45,46,47,48,49,50,51,52,53,54,55,57,59,61,62	;20
;	dc.b	63,64
	even

R_xpos:		dc.w	0
R_ypos:		dc.w	0
R_radius:	dc.w	0
R_radius1:	dc.w	0
R_oldradius1:	dc.w	0
R_angle:	dc.l	0
R_blink:	dc.b	0
R_blvz:		dc.b	0

rope_buffer:	ds.w	32
rope_coords:	dcb.w	32*2,-1

* -----------------------------------------------------------
* ---------------- ARITHMETICS ------------------------------
* -----------------------------------------------------------
init_rnd:
	moveq	#1,d0
	move.l	d0,last_rnd
	rts

rnd:
	movem.l	d1-d2,-(sp)
	move.w	#16807,d1
	move.w	last_rnd(pc),d0
	move.w	last_rnd+2(pc),d2
	mulu	d1,d0
	mulu	d1,d2
	swap	d2
	clr.w	d2
	add.l	d2,d0
	movem.l	(sp)+,d1-d2
	move.l	d0,last_rnd
	rts

last_rnd:	dc.l	0

sqrt:
	moveq	#0,d1			;XROOT=0
	move.w	#$4000,d2		;M2=$4000
.loop:
	move.w	d1,d3
	add.w	d2,d3			;X2=XROOT+M2
	lsr.w	#1,d1			;XROOT>>=1
	cmp.w	d0,d3			;X2<=X ?

	bgt.s	.lab1
	sub.w	d3,d0			;X-=X2
	add.w	d2,d1			;XROOT+=M2
.lab1:
	lsr.w	#2,d2			;M2>>=2
	bne	.loop

	cmp.w	d0,d1			;XROOT<X ?
	bhs.s	.no_add
	addq.w	#1,d1			;XROOT++
.no_add:
	move.w	d1,d0			;XROOT nach d0
	rts


cos:
	addi.w	#64,d0
sin:
	andi.w	#$00ff,d0
	lea	sincos_tab(pc),a0
	cmpi.w	#192,d0
	blt.s	.nquad1
	move.w	#255,d1
	sub.w	d0,d1
	move.b	(a0,d1.w),d0
	neg.w	d0
	rts
.nquad1:
	cmpi.w	#128,d0
	blt.s	.nquad2
	subi.w	#128,d0
	move.b	0(a0,d0.w),d0
	neg.w	d0
	rts
.nquad2:
	cmpi.w	#64,d0
	blt.s	.nquad3
	moveq	#127,d1
	sub.w	d0,d1
	move.b	0(a0,d1.w),d0
	rts
.nquad3:
	move.b	0(a0,d0.w),d0
	rts

sincos_tab:
	dc.b	0,6,12,18,25,31,37,43,49,56,62,68,74,80,86,92
	dc.b	97,103,109,115,120,126,131,136,142,147,152,157,162,167,171,176
	dc.b	181,185,189,193,197,201,205,209,212,216,219,222,225,228,231,234
	dc.b	236,238,241,243,244,246,248,249,251,252,253,254,254,255,255,255

alias_feet:
	tst.b	T_state
	bgt.s	.jumping
	sub.w	Scr_Y_Level_Pos(a6),d1
	sub.w	#31,d1
	move.w	d1,T_posY
.jumping:
	rts

check_foot_frame:
	tst.b	T_state
	bgt.s	.no_kolli
	move.w	T_posX(pc),d4
	add.w	Scr_X_Level_Pos(a6),d4
	add.w	#12,d4
	cmp.w	d4,d2
	blt.s	.no_kolli
	add.w	#14,d4
	cmp.w	d4,d0
	bgt.s	.no_kolli
	move.w	T_posY(pc),d4
	add.w	Scr_Y_Level_Pos(a6),d4
	add.w	#31,d4
	cmp.w	d1,d4
	blt.s	.no_kolli
	subq.w	#8,d4
	cmp.w	d1,d4
	bgt.s	.no_kolli
	moveq	#1,d0
	rts
.no_kolli:
	moveq	#0,d0
	rts

check_player_die:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1
	addq.w	#8,d0
	add.w	#8,d1
	cmp.w	#22,T_anim
	bne.s	.no_duck
	add.w	#10,d1
.no_duck:
	bsr	check_kollision
	beq.s	.out
	clr.b	T_energy
.out:
	rts

check_head_kollision:
	tst.w	Scr_Y_Fix(a6)
	beq.s	check_kollision
	tst.w	Scr_Up_Fix(a6)
	beq.s	check_kollision
	tst.w	d1
	bpl	check_kollision
	rts			;Kopf aufhalten.

check_kollision:
	tst.w	d1
	bpl.s	.ok2
	moveq	#0,d1
.ok2:
	cmp.w	#208,d1
	blt.s	.ok
	move.w	#207,d1
.ok:
	add.w	Scr_X_Level_Pos(a6),d0
	add.w	Scr_Y_Level_Pos(a6),d1
	add.w	#16,d0
check_obj_kollision:
	cmp.w	#32,d1
	bge.s	.ok
	moveq	#32,d1
.ok:
	move.b	d0,d3		;fr 8*8er Abfrage.
	move.b	d1,d4		;fr 8*8er Abfrage.

	lsr.w	#4,d0
	move.l	Scr_Level(a6),a0

	sub.w	#32,d1

	adda.w	d0,a0
	lsr.w	#4,d1

	mulu	Scr_Level_Width(a6),d1
	add.l	d1,a0
	moveq	#0,d0
	move.b	-1(a0),d0
	add.w	d0,d0
	move.l	Macro_Pointer(pc),a0
	move.b	1(a0,d0.w),d0
	move.b	d0,d1
	btst	#3,d3		; 4
	beq.s	.check_left
	btst	#3,d4
	beq.s	.check_ro
;check_ru
	and.w	#%0001,d0
	rts
.check_ro:
	and.w	#%0100,d0
	rts

.check_left:
	btst	#3,d4
	beq.s	.check_lo
;check_lu
	and.w	#%0010,d0
	rts
.check_lo:
	and.w	#%1000,d0
	rts

T_check_slope_kollision:
	tst.b	T_state
	beq	check_kollision
	cmp.w	#208,d1
	blt.s	.ok
	moveq	#0,d1
	moveq	#0,d0
	rts
.ok:
	add.w	Scr_X_Level_Pos(a6),d0
	add.w	Scr_Y_Level_Pos(a6),d1
	add.w	#16,d0

check_slope_kollision:
	bsr	check_obj_kollision
	bne.s	.out
	and.b	#%00110000,d1
.out:
	rts

	;Pixel Position auf einer Schrge berechnen.
calc_position:
	addq.w	#2,d1
	movem.w	d0-d1,-(sp)
	bsr	check_obj_kollision
	bne.s	.ground
	move.b	d1,d2
	and.b	#%00110000,d1
	beq.s	.free1
.use_slope:
	movem.w	(sp)+,d0-d1
	and.w	#15,d0
	btst	#4,d2
	beq.s	.right
	neg.w	d0
	add.w	#15,d0
.right:
	lsr.w	#1,d0
	btst	#6,d2
	bne.s	.no_add
	addq.w	#8,d0
.no_add:
	and.w	#$fff0,d1
	or.w	d0,d1
	rts

.free1:
	movem.w	(sp)+,d0-d1
	subq.w	#8,d1
	movem.w	d0-d1,-(sp)
	bsr	check_obj_kollision
	bne.s	.ground
	move.b	d1,d2
	and.b	#%00110000,d1
	bne.s	.use_slope
	movem.w	(sp)+,d0-d1
	rts

.ground:
	movem.w	(sp),d0-d1
	subq.w	#8,d1
	bsr	check_obj_kollision
	move.b	d1,d2
	and.b	#%00110000,d1
	beq.s	.no_slope
	movem.w	(sp)+,d0-d1
	subq.w	#8,d1
	movem.w	d0-d1,-(sp)
	bra.s	.use_slope
.no_slope:
	movem.w	(sp)+,d0-d1
	add.w	#10,d1
	and.w	#$fff0,d1
	rts


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

Calc_Blit_Adrs:
	moveq	#0,d0
	move.w	Scr_X_Level_Pos(a6),d0
	lsr.w	#3,d0
	and.w	#$fffe,d0
	move.l	d0,Scr_Blt_Adr2(a6)

	moveq	#0,d1
	move	Scr_Y_Play_Anf(a6),d1
	mulu	Scr_Plane_Width(a6),d1
	add.l	d0,d1
	move.l	d1,Scr_Blt_Adr1(a6)
	rts

;--------------------------------------------------------------------------
;-------------                Joystick Handler        ---------------------
;--------------------------------------------------------------------------

JoyPort:	dc.w	joy1dat
JoyFlags:	dc.w	0		;format : BARLUD
JoyFire:	dc.b	0
JoyReFire:	dc.b	0

Rapid_count1:	dc.b	0
Rapid_count2:	dc.b	0
Rapid_Verz:	dc.b	6
Rapid_Anz:	dc.b	3

JoyStick:
	move.w	#$ff00,$dff034
	moveq	#0,d7
	move.w	JoyPort,d0
	move.w	(a5,d0.w),d1
	btst	#1,d1
	bne	.right
	btst	#9,d1
	bne	.left
.check_y:
	move.w	(a5,d0.w),d1
	move.w	d1,d0
	lsr.w	#1,d0
	eor.w	d1,d0
	btst	#0,d0
	bne	.down
	btst	#8,d0
	bne	.up
.check_done2:
	tst.b	DATA_CONTROL.w
	bne.s	.check_done
	sf	Jump_Time

.check_done:
	btst	#14,potgor(a5)
	bne.s	.no_smart_button
	tst.b	DATA_CONTROL.w
	bne.s	.is_pad
	tst.b	T_secbutton
	bne.s	.smart_button
	st	T_secbutton
	or.w	#1<<(SMART+8),d7
	bra.s	.smart_button
.is_pad:
	cmp.w	#22,T_anim
	bne.s	.jump
	or.w	#1<<(SMART+8),d7
	bra.s	.smart_button

.jump:
	or.w	#1<<(JUMP+8),d7

	cmp.b	#50,Jump_Time
	bge	.smart_button
	addq.b	#1,Jump_Time
	bra.s	.smart_button
.is_pad2:
	sf	Jump_Time
	bra.s	.smart_button
.no_smart_button:
	tst.b	DATA_CONTROL.w
	bne.s	.is_pad2
	sf	T_secbutton
.smart_button:

	btst	#7,$bfe001
	seq	JoyFire
	bne	.nobutton

	tst.b	T_button_longpressed
	bne.s	.start_rope			;Ist schon aktiviert.
	tst.b	T_rope
	bne.s	.add
;	tst.b	T_targeting
;	bne.s	.button_done
	cmp.w	#22,T_anim
	beq.s	.add
	btst	#LEFT+8,d7
	bne.s	.clear
	btst	#RIGHT+8,d7
	bne.s	.clear
.add:
	addq.w	#1,T_target_count
	cmp.w	#TARGET_VERZ,T_target_count
	blt.s	.button_done
	st	T_button_longpressed
	or.b	#1,R_blink			;Rope blinken wegen Joystick-Unzulnglichkeit!
	tst.b	T_rope
	beq.s	.start_rope
	bra.s	.button_done

.start_rope:
	move.w	d7,d6
	and.w	#1<<(JUMP+8),d6			;Jump kommt nicht gleichzeitig!
	beq.s	.startit
	or.w	#1<<ROPEKF,d7			;RopeKillFloor
	or.w	#1<<ROPEKA,d7			;RopeKillAir
;	and.w	#$ffff-1<<(JUMP+8),d7		;Jump lschen!
	bra.s	.nobutton
.startit:
	or.w	#1<<ROPES,d7
	bra.s	.button_done
.nobutton:
	sf	T_button_longpressed
	sf	R_blink
.clear:
	clr.w	T_target_count

.button_done:
						;Wheel ?
;	btst	#ROPES,JoyFlags+1
	tst.b	T_button_longpressed
	beq.s	.no_wheel
	cmp.w	#22,T_anim
	bne.s	.no_wheel
	or.w	#1<<(WHEEL+8),d7
.no_wheel:

	cmp.b	#$40,G_keycode			;Space gedrckt!
	bne.s	.no_smart
.start_smart:
	or.w	#1<<(SMART+8),d7
	clr.b	G_keycode
.no_smart:
	move.w	d7,JoyFlags

	tst.b	DATA_RAPID.w
	bne.s	.no_rapid_fire

	tst.b	JoyFire
	beq.s	.no_rapid_start2

	tst.b	JoyReFire
	bne.s	.no_rapid_start

	move.b	Rapid_Anz,Rapid_count1
	sf	Rapid_count2			;Sofort der erste Schuss
	st	JoyReFire

	bra.s	.no_rapid_start
.no_rapid_start2:
	sf	JoyReFire
.no_rapid_start:

	tst.b	Rapid_count1
	beq.s	.rapid_over
	subq.b	#1,Rapid_count2
	bpl.s	.rapid_over
	move.b	Rapid_Verz,Rapid_count2
	or.b	#1<<FIRE,JoyFlags
	subq.b	#1,Rapid_count1
.rapid_over:

	tst.b	T_norope
	beq.s	.rope_ok
	and.w	#$ffff-(1<<ROPES)-(1<<ROPEKF)-(1<<ROPEKA),JoyFlags

.rope_ok:
	rts

.no_rapid_fire:
	tst.b	JoyFire
	beq.s	.no_fire
	st	JoyReFire
	or.b	#1<<FIRE,JoyFlags
	bra.s	.rapid_over
.no_fire:
	sf	JoyReFire
	bra.s	.rapid_over

.right:
	or.w	#1<<(RIGHT+8),d7
	bra	.check_y
.left:
	or.w	#1<<(LEFT+8),d7
	bra	.check_y
.up:
	or.w	#1<<(UP+8),d7
	tst.b	DATA_CONTROL.w
	bne	.check_done
	or.w	#1<<(JUMP+8),d7
	cmp.b	#50,Jump_Time
	bge	.check_done
	addq.b	#1,Jump_Time
	bra	.check_done
.down:
	or.w	#1<<(DOWN+8),d7
	bra	.check_done2

Jump_Time:	dc.b	0
T_falltime:	dc.b	0
T_secbutton:	dc.b	0
		dc.b	0

;--------------------------------------------------------------------------
;-------------                 SPRITE SYSTEM          ---------------------
;--------------------------------------------------------------------------

	;Berechnet die Offsets der beiden Sprites und setzt die Koordinaten in die
	;Spritedaten.
Anim_Player:
	tst.b	beam_me
	bne	Beam_In
	tst.w	half_pixel
	beq.s	.no_shield2
	tst.b	T_shield
	beq.s	.no_shield2
	subq.b	#1,T_shield
.no_shield2:

	move.w	T_posX(pc),-(sp)
	tst.b	T_flash
	beq.s	.no_flash
	subq.b	#1,T_flash
	tst.w	half_pixel
	beq.s	.no_flash
	tst.b	T_shield
	beq.s	.be_away
	tst.w	quarter_pixel
	bne.s	.no_flash
.be_away:
	move.w	#-48,T_posX
.no_flash:

	move.w	T_anim,d0		;Anim-num von Turrican.
	tst.b	T_shield
	beq.s	.no_shield
	tst.w	half_pixel
	beq.s	.no_shield
	move.w	T_shieldpos,d0
	lea	Shield_colors(pc),a0
	lea	Col_Buffer,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	st	.shield_flag
	st	Col_Flag
	bra.s	.shield
.no_shield:
	tst.b	.shield_flag
	beq.s	.shield
	sf	.shield_flag
	move.l	L_coltab,a0
	lea	48(a0),a0
	lea	Col_Buffer,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	st	Col_Flag
.shield:
	lea	T_animtab_len(pc),a0
	lea	T_animtab_offs(pc),a1
	lea	T_animtab_adr(pc),a2
	lea	sprite_pos+16(pc),a3
	move.w	d0,d2
	add.w	d0,d0
	lea	(a0,d0.w),a0
	lea	(a1,d0.w),a1
	moveq	#0,d7
	move.w	(a2,d0.w),d7
	add.l	#SpriteAdr,d7		;Adresse des ersten Sprites.

	tst.w	T_face
	beq	.leftside2
	add.l	#SpriteBuffer-SpriteAdr,d7		;Hier starten die geflippten Sprites.
.leftside2:
	move.l	d7,sprite_adr+16

	move.l	d7,a4

	add.w	d2,d2
	lea	T_animtab_xy(pc),a2
	move.b	(a2,d2.w),d0
	move.b	1(a2,d2.w),d1
	ext.w	d0
	ext.w	d1
	tst.w	T_face
	beq	.not_right
	neg.w	d0			;X-Offset geflippt.
.not_right:
	add.w	T_posX(pc),d0

	cmp.w	#-15,T_posY
	bgt	.useit
	add.w	#-15,d1
	bra.s	.too_high
.useit:
	add.w	T_posY(pc),d1
.too_high:
	move.b	#$80,d7
	add.w	#$91,d0
	btst	#0,d0
	beq.s	.noxhalf
	move.b	#$81,d7
.noxhalf:
	lsr.w	#1,d0
	move.b	d0,1(a3)

	add.w	#$2c,d1
	move.w	d1,d6		;Speichern fr zweite Hlfte.
	moveq	#0,d0
	move.b	(a1),d0
	add.w	d0,d1
	move.b	d1,(a3)
	btst	#8,d1
	beq	.noyhi1
	or.b	#4,d7
.noyhi1:
	moveq	#0,d0
	move.b	(a0),d0
	add.w	d0,d1
	move.b	d1,2(a3)
	btst	#8,d1
	beq	.noyhi2
	or.b	#2,d7
.noyhi2:
	move.b	d7,3(a3)
	moveq	#0,d0
	move.b	(a0),d0
	addq.b	#2,d0
	asl.w	#2,d0
	move.l	(a3),d7
	move.l	#$00080000,d3

	tst.w	T_face
	beq	.left_side3
	add.l	d3,d7
	move.l	d7,(a3)
	move.l	#$00f80000,d3
.left_side3:
	adda.w	d0,a4
	addq.l	#4,a3
	move.l	d7,(a3)
	move.l	a4,sprite_adr+4+16
	adda.w	d0,a4

	move.l	a4,sprite_adr+8+16
	add.l	d3,d7
	and.l	#$00ff0081,d7
	addq.l	#4,a3
	move.l	d7,(a3)
	move.w	d6,d1		;Y-pos
	moveq	#0,d0
	move.b	1(a1),d0
	add.w	d0,d1
	move.b	d1,(a3)
	btst	#8,d1
	beq	.noyhi3
	or.b	#4,3(a3)
.noyhi3:
	moveq	#0,d0
	move.b	1(a0),d0
	add.w	d0,d1
	move.b	d1,2(a3)
	btst	#8,d1
	beq	.noyhi4
	or.b	#2,3(a3)
.noyhi4:
	moveq	#0,d0
	move.b	1(a0),d0
	addq.b	#2,d0
	asl.w	#2,d0
	move.l	(a3),d7
	adda.w	d0,a4
	addq.l	#4,a3
	move.l	d7,(a3)
	move.l	a4,sprite_adr+12+16

	tst.w	T_ansize
	beq	.noanim
	subq.w	#1,T_anvz
	bpl	.nophase
	move.w	T_anspeed,T_anvz
	addq.w	#1,T_anpos
	move.w	T_ansize(pc),d0
	cmp.w	T_anpos(pc),d0
	bgt	.nophase
	clr.w	T_anpos
.nophase:
	move.w	T_anpos(pc),d0
	move.l	T_antab(pc),a0
	move.b	(a0,d0.w),T_anim+1
.noanim:
	subq.b	#1,.shield_vz
	bpl.s	.no_new
	move.b	#1,.shield_vz
	addq.w	#1,T_shieldpos
	cmp.w	#37,T_shieldpos
	bne.s	.no_new
	move.w	#32,T_shieldpos
.no_new:
	move.w	(sp)+,T_posX
	rts

.shield_vz:	dc.b	0
.shield_flag:	dc.b	1

Shield_colors:
	dc.w	$3f1,$1b0,$080,$fe0

Beam_len	= 48+4

Start_Beam:
	lea	sprite_adr(pc),a0
	lea	adr_buffer(pc),a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+

	lea	Beam_Sprites,a0
	moveq	#4-1,d6
.xloop:
	moveq	#6-1,d7
.yloop:
	clr.l	(a0)+		;1. Control-Word
	move.l	#$01800000,(a0)+
	dbf	d7,.yloop
	clr.l	(a0)+
	dbf	d6,.xloop
	st	beam_me
	PLAY_FX	#$00
	rts

Beam_In:
	move.b	#10,T_flash
	tst.b	Col_Init_Flag
	bne	.hide
	tst.w	Beam_radius2
	beq	.beam_end

	lea	sprite_adr(pc),a0
	move.l	#Beam_Sprites,d0
	moveq	#4-1,d7
.set_adrs:
	move.l	d0,(a0)+
	add.l	#Beam_len,d0
	dbf	d7,.set_adrs

	lea	sprite_pos(pc),a0
	lea	Beam_Sprites,a1

	move.w	#128-10,d7		;Angle
	move.w	Beam_radius1,d6			;Radius
	moveq	#-20,d4
	bsr	.set_one_quarter

	lea	Beam_Sprites+Beam_len,a1

	move.w	#128+10,d7		;Angle
	moveq	#20,d4
	bsr	.set_one_quarter

	lea	Beam_Sprites+Beam_len*2,a1

	move.w	#128-10,d7		;Angle
	move.w	Beam_radius2,d6			;Radius
	moveq	#-20,d4
	bsr	.set_one_quarter

	lea	Beam_Sprites+Beam_len*3,a1

	move.w	#128+10,d7		;Angle
	moveq	#20,d4
	bsr	.set_one_quarter

	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+

	subq.w	#4,Beam_radius1
	subq.w	#4,Beam_radius2

	;Farben flashen

	move.w	Beam_color,d0
	tst.b	Beam_coldir
	beq.s	.up
	sub.w	#$011,d0
	cmp.w	#$f88,d0
	beq.s	.change
	bra.s	.set
.up:
	add.w	#$011,d0
	cmp.w	#$fff,d0
	bne.s	.set
.change:
	not.b	Beam_coldir
.set:
	move.w	d0,Beam_color

	tst.w	coltab+2
	beq.s	.dont_set

	move.w	d0,$dff1a2
	move.w	d0,$dff1aa
.dont_set:
	rts

.hide:
	lea	sprite_pos(pc),a0
	moveq	#7,d7
.hideloop:
	clr.l	(a0)+
	dbf	d7,.hideloop
	rts

.set_one_quarter:
	move.l	#$19001a00,clip_help
	cmp.w	#5,d6
	blt.s	.clear

	lea	(a1),a2
	moveq	#6-1,d5
.loop1:
	movem.l	a0,-(sp)
	move.w	d7,d0
	bsr	cos
	move.w	d0,d2
	move.w	d7,d0
	bsr	sin
	muls	d6,d0
	muls	d6,d2
	movem.l	(sp)+,a0

	asr.w	#8,d0
	asr.w	#8,d2

	add.w	T_posX(pc),d0
	add.w	T_posY(pc),d2

	add.w	#18,d2

	bsr	.calc_position
	move.l	help,(a1)
	addq.l	#8,a1
	add.w	d4,d7
	dbf	d5,.loop1

	move.l	(a2),(a0)+
	rts

.clear:
	clr.l	(a0)+
	rts

.beam_end:
	sf	beam_me
	move.w	#4*20,Beam_radius1
	move.w	#4*30,Beam_radius2
	move.w	Col_Buffer+8,d0
	move.w	d0,$dff1a2
	move.w	d0,$dff1aa
	move.w	#$fee,Beam_color
	sf	Beam_coldir
	lea	adr_buffer(pc),a0
	lea	sprite_adr(pc),a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	rts

.calc_position:
	add.w	#$99,d0
	add.w	#$30,d2
	cmp.w	#$30,d2
	bge.s	.no_clip
	move.l	clip_help,help
	add.l	#$02000200,clip_help
	rts
.no_clip:
	clr.l	help
	move.b	d0,help+3
	and.b	#1,help+3
	lsr.w	#1,d0
	move.b	d0,help+1

	move.b	d2,help
	addq.b	#1,d2
	move.b	d2,help+2

	rts

beam_me:	dc.b	1
Beam_coldir:	dc.b	0
Beam_radius1:	dc.w	4*20
Beam_radius2:	dc.w	4*30
Beam_color:	dc.w	$fee
clip_help:	dc.l	0
adr_buffer:	dc.l	0,0,0,0

	even

	; Alle Waffen darstellen 

Show_SWeapons:
	lea	SW_table(pc),a1
	lea	sprite_adr(pc),a0
	lea	sprite_pos(pc),a3
	move.l	SW_defpoint(pc),a2

	tst.b	T_mine
	bne	Show_Mines

	cmp.b	#2,T_weapon
	beq	.do_bounce

	moveq	#3,d7
	tst.w	SW_width
	beq.s	.loop
	tst.b	Scr_Screen_num(a6)
	beq.s	.loop
	lea	SW_len(a1),a1
.loop:
	move.w	(a1)+,d0		;X-pos
	move.w	(a1)+,d1		;Y-pos
	move.w	(a1)+,d3		;speed
	beq	.hide
	move.w	d1,d2
	add.w	SW_heigth,d2			;Y-stop
	bsr	.show_sprite

	tst.w	SW_width
	beq.s	.one_sprite
	move.w	-6(a1),d0
	move.w	-4(a1),d1
	moveq	#16,d4
	move.w	-2(a1),d3
	bpl.s	.ok
	neg.w	d4
.ok:
	add.w	d4,d0
	move.w	d1,d2
	add.w	SW_heigth,d2			;Y-stop
	bsr	.show_sprite
	subq.w	#1,d7
	lea	SW_len(a1),a1
.one_sprite:
.next:
	lea	SW_len-6(a1),a1
	dbf	d7,.loop
.not_lazer:

	lea	SW_table(pc),a1
	move.w	Scr_Scrolled_X(a6),d3
	move.w	Scr_Scrolled_Y(a6),d4
	moveq	#3,d7
.mloop:
	bsr	.move_lazer
	lea	SW_len(a1),a1
	dbf	d7,.mloop
	rts

.hide:
	move.l	(a2)+,(a0)+
	clr.l	(a3)+
	tst.w	SW_width
	beq.s	.next
	move.l	(a2)+,(a0)+
	clr.l	(a3)+
	subq.w	#1,d7
	lea	SW_len(a1),a1
	bra.s	.next

.move_lazer:
	sub.w	d3,(a1)
	sub.w	d4,2(a1)
	move.w	4(a1),d0
	beq.s	.out
	bmi	.L_to_left
	add.w	d0,(a1)
	cmp.w	#320,(a1)
	bgt	.L_stop
	rts
.L_to_left:
	add.w	d0,(a1)
	cmp.w	#-16,(a1)
	blt	.L_stop
.out:
	rts
.L_stop:
	clr.w	4(a1)
	rts

.show_sprite:
	move.l	(a2)+,(a0)+
	tst.w	d3
	bpl	.to_right
	add.l	#SpriteBuffer-SpriteAdr,-4(a0)
	sub.w	#16,d0
.to_right:
	add.w	#$91,d0
	btst	#0,d0
	beq	.setx0
	move.b	#1,3(a3)
	bra.s	.setx1
.setx0:
	clr.b	3(a3)
.setx1:
	lsr.w	#1,d0
	move.b	d0,1(a3)
	add.w	#$2c,d1
	move.b	d1,(a3)
	btst	#8,d1
	beq.s	.sety0
	or.b	#4,3(a3)
.sety0:
	add.w	#$2c,d2
	move.b	d2,2(a3)
	btst	#8,d2
	beq.s	.sety1
	or.b	#2,3(a3)
.sety1:
	addq.l	#4,a3
	rts

.do_bounce:
	moveq	#3,d7
.bounce_loop:
	move.l	(a2)+,d0
	tst.w	4(a1)
	bpl	.bounce_right
	add.l	#SpriteBuffer-SpriteAdr,d0
.bounce_right:
	move.l	d0,(a0)+
	lea	SW_len(a1),a1
	dbf	d7,.bounce_loop
	rts

Mine_X:	dc.w	100,100,-1,100	;Mine
	dc.w	120,100,-1,100	;Bombe.
	dc.w	100,100,-1,100
	dc.w	100,100,-1,100

Mine_vz:
	dc.b	0,0

Search_Mine:				;Freien Minen / Bomb Eintrag suchen.
	lea	SW_table(pc),a1		;Sind alle Schu-salven vom Screen ?
	moveq	#3,d7
	moveq	#0,d0
.search:
	or.w	4(a1),d0
	lea	SW_len(a1),a1
	dbf	d7,.search

	tst.w	d0
	bne	.out

	lea	Mine_X(pc),a1
	tst.b	4(a1)		;0
	bmi	Return
	addq.l	#8,a1
	tst.b	4(a1)		;1
	bmi	Return
	addq.l	#8,a1
	tst.b	4(a1)		;2
	bmi	Return
	addq.l	#8,a1
	tst.b	4(a1)		;3
	rts
.out:
	moveq	#0,d0
	rts

	; Minen / Bomben darstellen & bewegen 

Show_Mines:
	moveq	#0,d5
	tst.b	T_shield
	beq.s	.no_shield
	move.w	half_pixel,d5
.no_shield:
	sf	show_mine
	tst.w	Scr_Screen_num(a6)
	beq.s	.ok
	st	show_mine
.ok:
	lea	Mine_X(pc),a1
	lea	Mine_defTable(pc),a2
	subq.b	#1,Mine_vz
	bpl.s	.no_anim
	move.b	#8,Mine_vz
	move.l	(a2),d0
	move.l	16(a2),(a2)
	move.l	d0,16(a2)
	move.l	4(a2),d0
	move.l	20(a2),4(a2)
	move.l	d0,20(a2)
.no_anim:
	moveq	#4-1,d7
.loop:
	tst.b	4(a1)
	bmi	.hide

	movem.w	Scr_Scrolled_X(a6),d2-d3
	sub.w	d2,(a1)		;Mitscrollen
	sub.w	d3,2(a1)	;Mitscrollen

	cmp.w	#-16,(a1)	;Noch auf dem Screen ?
	blt	.clear		;Nein, austragen !
	cmp.w	#304,(a1)
	bgt	.clear
	cmp.w	#-13,2(a1)
	blt	.clear
	cmp.w	#208,2(a1)
	bgt	.clear

	tst.w	d5		;Shield-Farben dargestellt ?
	bne	.hide		;Die falschen Farben !

	move.w	(a1),d0
	move.w	2(a1),d1
	tst.b	5(a1)
	beq.s	.show_mine
				;Es ist eine Bombe !

	cmp.b	#5*4,5(a1)
	beq.s	.no_speedup
	addq.b	#2,5(a1)	;Fallbeschleunigung
.no_speedup:
	tst.b	show_mine	;Sind wir dran mit Anzeigen ?
	beq.s	.no_show_bomb	;Nein, skippen zum nchsten Eintrag
	moveq	#0,d3
	move.b	5(a1),d3
	lsr.b	#2,d3
	add.w	d3,2(a1)
	move.w	d1,d2
	add.w	#16,d2
	bsr	.show_it
	move.l	-4(a3),(a3)+
	move.l	8(a2),(a0)+
	move.l	12(a2),(a0)+
.no_show_bomb:
	move.w	(a1),d0
	move.w	2(a1),d1
	addq.w	#3,d1
	movem.l	a0-a1,-(sp)
	bsr	check_kollision
	movem.l	(sp)+,a0-a1
	bne.s	.explode
	bra.s	.next
				;Es ist eine Mine !

.show_mine:
	tst.b	show_mine
	beq.s	.no_show_mine
	move.w	d1,d2
	add.w	#8,d2
	bsr	.show_it
	move.l	-4(a3),(a3)+
	move.l	(a2),(a0)+
	move.l	4(a2),(a0)+
.no_show_mine:
	subq.w	#1,6(a1)
	bpl.s	.next

.explode:
	moveq	#9,d0		;Show Mine-explo
	move.w	(a1),d1
	move.w	2(a1),d2
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	sub.w	#28,d2
	movem.l	d7/a0-a3,-(sp)
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.no
	move.b	#BOB_NOCOL,Bob_Used(a4)
	PLAY_FX	#$1a
.no:
	movem.l	(sp)+,d7/a0-a3
.clear:
	move.w	#-1,4(a1)
	bra.s	.next
.hide:
	tst.b	show_mine			;Diese Mine ist garnicht dran!
	beq.s	.next
	clr.l	(a3)+
	clr.l	(a3)+
	move.l	8(a2),(a0)+
	move.l	12(a2),(a0)+
.next:
	not.b	show_mine			;Diese Mine wurde nicht dargestellt!
	bne.s	.no_next
	lea	16(a2),a2
.no_next:
	lea	8(a1),a1
	dbf	d7,.loop
	rts

.show_it:
	tst.w	d5		;Shield-Farben dargestellt ?
	bne	.show_hide	;Die falschen Farben !
	add.w	#$91,d0
	btst	#0,d0
	beq	.setx0
	move.b	#$81,3(a3)
	bra.s	.setx1
.setx0:
	move.b	#$80,3(a3)
.setx1:
	lsr.w	#1,d0
	move.b	d0,1(a3)
	add.w	#$2c,d1
	move.b	d1,(a3)
	btst	#8,d1
	beq.s	.sety0
	or.b	#4,3(a3)
.sety0:
	add.w	#$2c,d2
	move.b	d2,2(a3)
	btst	#8,d2
	beq.s	.sety1
	or.b	#2,3(a3)
.sety1:
	addq.l	#4,a3
	rts
.show_hide:
	clr.l	(a3)+		;Leider nicht mglich, wg. Shield Farben!
	rts

show_mine:	dc.w	0

Mine_defTable:
	dc.l	SpriteAdr+m0_adr,SpriteAdr+m0_adr+40
	dc.l	SpriteAdr+m2_adr,SpriteAdr+m2_adr+72

	dc.l	SpriteAdr+m1_adr,SpriteAdr+m1_adr+40
	dc.l	SpriteAdr+m3_adr,SpriteAdr+m3_adr+72

	; Start_Shoots 

W_start_shoot:
	lea	SW_table(pc),a1		;Schu-Eintrag frei ?
	moveq	#3,d7
.search:
	tst.w	4(a1)
	beq	.addit
	lea	SW_len(a1),a1
	dbf	d7,.search
	rts				;Nomore possible!
.addit:
	move.w	(a0),d2			;Eintrag frei, Schu starten
	tst.w	T_face
	beq	.to_left
	add.w	#32,d0
	bra.s	.to_right
.to_left:
	neg.w	d2
.to_right:
	cmp.w	#22,T_anim
	bne.s	.no_ducking
	add.w	#9,d1
.no_ducking:
	movem.l	d0-d1/a0-a1,-(sp)
	add.w	#12,d1
	tst.w	d2
	bmi.s	.to_left2
	sub.w	#8,d0
	bra.s	.to_right2
.to_left2:
	sub.w	#16,d0
.to_right2:
	bsr	check_kollision		;Steht Turri zu nahe an einer Wand ?
	movem.l	(sp)+,d0-d1/a0-a1
	bne.s	.no_start		;Ja, nicht starten !

	add.w	2(a0),d1		;Y-Offset

	move.w	d0,(a1)
	move.w	d1,2(a1)
	move.w	d2,4(a1)
	move.w	4(a0),SW_heigth
	move.l	6(a0),SW_defpoint
	move.w	10(a0),SW_width
	move.w	12(a0),10(a1)		;Alle drei Partials starten.
	move.w	14(a0),d0
	move.w	d0,SW_kolly
	lsr.w	#1,d0
	move.w	d0,SW_kolly2
	move.w	d6,d0
	jsr	TFMX+92
	moveq	#0,d7
	rts

.no_start:
	tst.w	d2
	bpl.s	.to_right3
	sub.w	#10,d0
.to_right3:
	move.w	d1,d2
	move.w	d0,d1
	moveq	#2,d0
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.no_bob
	move.b	#BOB_NOCOL,Bob_Used(a4)
.no_bob:
	move.w	d6,d0
	jsr	TFMX+92

	moveq	#-1,d7
	rts

	; Weapon-init 

set_difficulty:
	cmp.b	#1,DATA_LEVEL.w
	beq.s	.normal
	blt.s	.easy

	;Hard / Maniac

	lsr.w	#1,d0
	bne.s	.normal
	moveq	#1,d0
	bra.s	.normal
.easy:
	add.w	d0,d0
.normal:
	rts

Init_Lazer:
	moveq	#0,d0
	move.b	T_power,d0
	addq.w	#1,d0
	bsr	set_difficulty
	move.w	d0,SW_power
	rts

Init_Spread:
	moveq	#1,d0
	cmp.b	#2,T_power
	blt.s	.no_big
	moveq	#2,d0
.no_big:
	bsr	set_difficulty
	move.w	d0,SW_power

	lea	SW_deftab4(pc),a2
	lea	sprite_adr(pc),a0
	lea	sprite_pos(pc),a1
	moveq	#3,d7
.loop:
	clr.l	(a1)+
	move.l	(a2)+,(a0)+
	dbf	d7,.loop
	rts

Init_bounce:
	moveq	#0,d0
	move.b	T_power,d0
	bne.s	.ok
	addq.w	#1,d0
.ok:
	bsr	set_difficulty
	move.w	d0,SW_power

	cmp.b	#1,T_power
	beq	.b_init2
	bgt	.b_init3

	lea	SW_deftab7(pc),a0
	lea	bounce_offs(pc),a1
	bra.s	.init
.b_init2:
	lea	SW_deftab8(pc),a0
	lea	bounce_offs+8(pc),a1
	bra.s	.init
.b_init3:
	lea	SW_deftab9(pc),a0
	lea	bounce_offs+16(pc),a1
.init:
	move.l	a0,bounce_pointer
	move.l	a1,bounce_offs_pointer

	lea	W_bounce1_info(pc),a1
	move.l	a0,6(a1)
	move.l	bounce_pointer,a2
	move.l	a2,SW_defpoint
	lea	sprite_adr(pc),a0
	moveq	#3,d7
.bounce_loop:
	move.l	(a2)+,(a0)+
	dbf	d7,.bounce_loop

	lea	Bounce_List(pc),a5
	bsr	Kill_Bounce

	lea	Bounce_List+Bounce_len(pc),a5
	bsr	Kill_Bounce
	lea	bounce_coords(pc),a0
	moveq	#-16,d0
	moveq	#-13,d1
	moveq	#7,d7
.loop:
	move.w	d0,(a0)+
	move.w	d1,(a0)+
	dbf	d7,.loop

	lea	custom,a5
	rts

bounce_pointer:		dc.l	0
bounce_offs_pointer:	dc.l	0


	; Lazer-shot 

Anim_lazer:
	tst.b	T_weapon
	bne.s	.no_new
	cmp.b	#2,T_power
	bne.s	.no_new
	subq.b	#1,lazer_vz
	bpl.s	.no_new
	move.b	#2,lazer_vz
	lea	SW_deftab3(pc),a0
	cmp.l	SW_defpoint(pc),a0
	bne.s	.set
	lea	SW_deftab3B(pc),a0
.set:
	move.l	a0,SW_defpoint
.no_new:
	rts
lazer_vz:	dc.b	0
		dc.b	0

	; Bounce-shot 

Show_bounce:
	lea	SW_table(pc),a1
	lea	bounce_coords(pc),a2
	lea	sprite_adr(pc),a0
	lea	sprite_pos(pc),a3
	move.l	bounce_offs_pointer,a4
	moveq	#3,d7
.loop:
	move.w	Scr_Scrolled_X(a6),d0
	sub.w	4(a1),d0
	sub.w	d0,(a1)
	cmp.w	#-16,(a1)
	ble.s	.stop
	cmp.w	#320,(a1)
	bge.s	.stop
	move.w	Scr_Scrolled_Y(a6),d0
	sub.w	d0,2(a1)
	cmp.w	#-16,(a1)
	ble.s	.stop
	cmp.w	#208,2(a1)
	blt.s	.no_stop
.stop:
	clr.w	4(a1)
.no_stop:
	bsr	.do_one

	lea	SW_len(a1),a1
	addq.l	#4,a0
	addq.l	#4,a2
	addq.l	#4,a3
	addq.l	#2,a4
	dbf	d7,.loop
	lea	Bounce_List(pc),a5
	bsr	Do_Bounce
	move.l	Bounce_X(a5),bounce_coords
	move.l	Bounce_Buffer_1+24,bounce_coords+4
	move.l	Bounce_Buffer_1+16,bounce_coords+8
	move.l	Bounce_Buffer_1+8,bounce_coords+12

	lea	Bounce_List+Bounce_len(pc),a5
	bsr	Do_Bounce
	move.l	Bounce_X(a5),bounce_coords+16
	move.l	Bounce_Buffer_2+24,bounce_coords+20
	move.l	Bounce_Buffer_2+16,bounce_coords+24
	move.l	Bounce_Buffer_2+8,bounce_coords+28

	lea	custom,a5

	rts

.do_one:
	move.w	(a1),d0
	move.w	2(a1),d1		;Diese Y-Koordinate MUSS eingehalten werden.
	tst.w	4(a1)
	beq.s	.only_bounce		;Der Schuss ist weg, nur den bounce bearbeiten.
	bpl.s	.to_right
	sub.w	#16,d0
.to_right:
	moveq	#6,d3
	bsr	.coords_to_ctrl
	move.w	(a4),d1
	addq.w	#1,d1
	asl.w	#2,d1
	move.l	(a0),a5
	move.l	d0,(a5,d1.w)		;Coordinate des Schusses!

	move.w	(a2),d0
	move.w	2(a2),d1
	move.w	(a4),d3
	move.w	d1,d2
	add.w	d3,d2
	addq.w	#1,d2
	cmp.w	2(a1),d2
	blt.s	.no_clip1
	move.w	#-13,d1			;Der Bounce gefhrdet den Schuss -> fllt weg!
	move.w	#-20,d0
.no_clip1:
	bsr	.coords_to_ctrl
	move.l	d0,(a3)

	;Unterer Bounce-Anteil

	move.w	16(a2),d0
	move.w	18(a2),d1
	move.w	(a4),d3

;	move.w	d1,d2
;	sub.w	#8,d2
;	cmp.w	2(a1),d2
;	bge.s	.no_clip2
;	moveq	#0,d0
;	moveq	#0,d1
;.no_clip2:
	bsr	.coords_to_ctrl

	move.w	(a4),d1
	addq.w	#8,d1
	asl.w	#2,d1
	move.l	(a0),a5
	move.l	d0,(a5,d1.w)

	rts

.only_bounce:
	move.w	(a2),d0
	move.w	2(a2),d1
	move.w	(a4),d3
	move.w	d1,d2
	add.w	d3,d2
	addq.w	#1,d2
	bsr	.coords_to_ctrl
	move.l	d0,(a3)

	move.w	2(a2),d1
	move.w	(a4),d3
	add.w	d3,d1
	addq.w	#1,d1
	moveq	#-20,d0
	moveq	#6,d3
	bsr	.coords_to_ctrl
	move.w	(a4),d1
	addq.w	#1,d1
	asl.w	#2,d1
	move.l	(a0),a5
	move.l	d0,(a5,d1.w)		;Coordinate des Schusses!

	;Unterer Bounce-Anteil

	move.w	16(a2),d0
	move.w	18(a2),d1
	move.w	(a4),d3

	bsr	.coords_to_ctrl

	move.w	(a4),d1
	addq.w	#8,d1
	asl.w	#2,d1
	move.l	(a0),a5
	move.l	d0,(a5,d1.w)
	rts

.coords_to_ctrl:
	add.w	#$91,d0
	move.w	d0,d2
	lsr.w	#1,d2
	move.b	d2,help+1
	and.b	#1,d0
	move.b	d0,help+3
	add.w	#$2c,d1
	move.b	d1,help
	btst	#8,d1
	beq.s	.no_first
	or.b	#4,help+3
.no_first:
	add.w	d3,d1			;Hhe
	move.b	d1,help+2
	btst	#8,d1
	beq.s	.no_last
	or.b	#2,help+3
.no_last:
	move.l	help,d0
	rts

	rsreset
Bounce_Used	rs.w	1
Bounce_X	rs.w	1
Bounce_Y	rs.w	1
Bounce_0	rs.w	1
Bounce_1	rs.w	1
Bounce_2	rs.w	1
Bounce_3	rs.l	1
Bounce_len	rs.w	0

Bounce_List:	dc.w	0
		dc.w	100
		dc.w	50
		dc.w	0
		dc.w	0
		dc.w	0
		dc.l	Bounce_Buffer_1

		dc.w	0
		dc.w	100
		dc.w	50
		dc.w	0
		dc.w	0
		dc.w	0
		dc.l	Bounce_Buffer_2

Bounce_Buffer_1:	dc.l	0,0,0,0,0,0,0,0
Bounce_Buffer_2:	dc.l	0,0,0,0,0,0,0,0

Do_Bounce:
	tst.w	Bounce_Used(a5)
	beq	Return

	move.w	Scr_Scrolled_X(a6),d0
	sub.w	d0,Bounce_X(a5)

	move.w	Scr_Scrolled_Y(a6),d0
	sub.w	d0,Bounce_Y(a5)

	moveq	#0,d0
	move.b	Bounce_1(a5),d0			;Jump to actual handler
	jmp	.whandle_tab(pc,d0.w)
.whandle_tab:
	bra.s	.find_wall
	bra.s	.swing_wait
	bra.s	.swing_wall
	bra	.run_out

.find_wall:
	tst.b	Bounce_0+1(a5)			;Test for wall-collision
	beq.s	.to_right
	moveq	#-10,d7
	bra.s	.to_left
.to_right:
	moveq	#10,d7
.to_left:
	movem.w	Bounce_X(a5),d0-d1
	add.w	d7,d1
	bsr	check_kollision
	beq.s	.no_kolli
	addq.b	#2,Bounce_1(a5)			;Next handler
	move.w	#3,Bounce_2(a5)
	asr.w	#1,d7
.no_kolli:
	add.w	d7,Bounce_Y(a5)			;Move shot up/down
	bra	.check_out

.swing_wait:
	subq.w	#1,Bounce_2(a5)			;A short delay-time
	bpl.s	.check_out
	addq.b	#2,Bounce_1(a5)			;Next handler
	move.b	#9,Bounce_1+1(a5)			;Set 1st swing-speed-value
	bra.s	.check_out

.swing_wall:
	move.b	Bounce_1+1(a5),d0			;Get swing-speed
	ext.w	d0
	tst.b	Bounce_0+1(a5)			;Upper or lower wall-runner ?
	beq.s	.down
	add.w	d0,Bounce_Y(a5)			;Move down...
	bra.s	.up
.down:
	sub.w	d0,Bounce_Y(a5)			;Move up...
.up:
	tst.b	Bounce_0(a5)			;Left or right faced ?
	beq.s	.right
	moveq	#-12,d0				;Move left...
	bra.s	.left
.right:
	moveq	#12,d0				;Move right...
.left:
	add.w	d0,Bounce_X(a5)
	subq.b	#3,Bounce_1+1(a5)		;Speed down a bit
	cmpi.b	#-9,Bounce_1+1(a5)		;Fully reversed ?
	bne.s	.not_complete
	sf	Bounce_1(a5)			;Yes, back to first handler
	bra.s	.check_out
.not_complete:
	movem.w	Bounce_X(a5),d0-d1		;No, test for wall...
	bsr	check_kollision
	beq.s	.check_out
;	bsr	end_run				;Yes, let shot explode

	bsr	Xplo_Bounce
	bra	Kill_Bounce

.check_out:
	cmp.w	#-16,Bounce_X(a5)
	ble.s	.stop
	cmp.w	#320,Bounce_X(a5)
	bge.s	.stop
	cmp.w	#-16,Bounce_Y(a5)
	ble.s	.stop
	cmp.w	#208,Bounce_Y(a5)
	blt.s	.set_positions
.stop:
	move.w	#-16,Bounce_X(a5)
	move.w	#-13,Bounce_Y(a5)
	move.w	#7,Bounce_2(a5)
	move.b	#6,Bounce_1(a5)
.set_positions:
	move.w	Scr_Scrolled_X(a6),d0
	move.w	Scr_Scrolled_Y(a6),d1
	move.l	Bounce_3(a5),a0			;and "scroll" the stored positions
	lea	4(a0),a1
	moveq	#6,d4
.copy:
	move.w	(a1)+,d2
	move.w	(a1)+,d3
	sub.w	d0,d2
	sub.w	d1,d3
	move.w	d2,(a0)+
	move.w	d3,(a0)+
	dbf	d4,.copy
	move.l	Bounce_X(a5),(a0)
	rts

.run_out:
	move.w	#-16,Bounce_X(a5)
	move.w	#-13,Bounce_Y(a5)
	subq.w	#1,Bounce_2(a5)
	bpl.s	.set_positions
	clr.w	Bounce_Used(a5)
	rts

Kill_Bounce:
	moveq	#-16,d0
	moveq	#-13,d1
	move.l	Bounce_3(a5),a0
	moveq	#7,d7
.clear:
	move.w	d0,(a0)+
	move.w	d1,(a0)+
	dbf	d7,.clear

	move.w	d0,Bounce_X(a5)
	move.w	d1,Bounce_Y(a5)

	clr.w	Bounce_Used(a5)
	rts

Xplo_Bounce:
	moveq	#2,d0
	movem.w	Bounce_X(a5),d1-d2
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.out
	move.b	#BOB_NOCOL,Bob_Used(a4)
.out:
	rts

	;Koordinaten aller Bounce-teile.
bounce_coords:
	dc.w	10,10,20,20,30,30,40,40
	dc.w	10,110,20,120,30,130,40,140

bounce_offs:
	dc.w	11,6,6,6
	dc.w	13,11,11,6
	dc.w	15,13,11,6


	; Spread-shot 

Blit_Spread:
	lea	SW_table(pc),a1
	lea	sprite_adr(pc),a0
	lea	sprite_pos(pc),a3
	clr.l	bltcmod(a5)		;Alle Modulos lschen
	clr.l	bltamod(a5)
	move.l	#-1,bltafwm(a5)
	clr.w	bltcon1(a5)
	cmp.b	#1,T_power
	blt	Return
	bgt	.not_2
	moveq	#3,d7
.loop:
	tst.l	(a3)
	beq	.next

	move.w	Scr_Scrolled_Y(a6),d0
	sub.w	d0,6(a1)
	sub.w	d0,8(a1)

	tst.w	4(a1)
	bpl.s	.right
	lea	left_small_spread(pc),a4
	bra.s	.left
.right:
	lea	right_small_spread(pc),a4
.left:

	move.l	(a0),d0
	addq.l	#4,d0

	move.w	#$09f0,bltcon0(a5)
	btst	#0,10(a1)
	bne.s	.blit_it1
	move.w	#$0100,bltcon0(a5)
.blit_it1:
	move.l	d0,bltdpth(a5)
	move.l	(a4),bltapth(a5)	;Obersten Schuss blitten.
	move.w	#64*7+2,bltsize(a5)
.bwait1:
	btst	#14,dmaconr(a5)
	bne.s	.bwait1
	move.w	#$0100,bltcon0(a5)
	move.w	#64*15+2,bltsize(a5)	;Clearen des Sprites.
.bwait0:
	btst	#14,dmaconr(a5)
	bne.s	.bwait0

	;Checken, ob sichs noch berlappt

	moveq	#0,d1
	move.w	8(a1),d1
	sub.w	2(a1),d1
	cmp.w	#15,d1
	bge.s	.no_cross

	asl.w	#2,d1
	add.l	d0,d1

	move.l	d1,bltdpth(a5)
	move.w	#$09f0,bltcon0(a5)
	btst	#2,10(a1)
	bne.s	.blit_it2
	clr.w	bltcon0(a5)
.blit_it2:
	move.l	4(a4),bltapth(a5)
	move.w	#-8,bltamod(a5)
	move.w	#64*7+2,bltsize(a5)
.bwait2:
	btst	#14,dmaconr(a5)
	bne.s	.bwait2

	clr.w	bltamod(a5)

	btst	#1,10(a1)
	beq	.next

	moveq	#0,d2
	move.w	6(a1),d2
	sub.w	2(a1),d2

	asl.w	#2,d2
	add.l	d0,d2

	move.l	d2,bltdpth(a5)
	move.l	d2,bltcpth(a5)
	move.l	8(a4),bltbpth(a5)
	move.l	12(a4),bltapth(a5)
	move.w	#$0fca,bltcon0(a5)
	move.w	#64*6+2,bltsize(a5)
.bwait3:
	btst	#14,dmaconr(a5)
	bne.s	.bwait3

	bra	.next

.no_cross:
	move.l	d0,a2
	move.l	(a3),d6
	and.b	#$f1,d6
	move.l	d6,-4(a2)
	move.w	2(a1),d2
	moveq	#7,d3
	bsr	.calc_ycoord
	btst	#0,10(a1)
	bne.s	.is_there
	clr.b	-3(a2)
.is_there:
	move.l	-4(a2),(a3)

	add.l	#7*4,a2
	move.l	d6,(a2)+
	move.w	6(a1),d2
	moveq	#6,d3
	bsr	.calc_ycoord
	btst	#1,10(a1)
	bne.s	.is_there2
	clr.b	-3(a2)
.is_there2:

	move.w	#$09f0,bltcon0(a5)
	move.l	8(a4),bltapth(a5)
	move.l	a2,bltdpth(a5)
	move.w	#64*6+2,bltsize(a5)
.bwait4:
	btst	#14,dmaconr(a5)
	bne.s	.bwait4

	add.l	#6*4,a2
	move.l	d6,(a2)+
	move.w	8(a1),d2
	moveq	#7,d3
	bsr	.calc_ycoord
	btst	#2,10(a1)
	bne.s	.is_there3
	clr.b	-3(a2)
.is_there3:

	move.l	a2,bltdpth(a5)
	move.l	4(a4),bltapth(a5)
	move.w	#-8,bltamod(a5)
	move.w	#64*7+2,bltsize(a5)
.bwait5:
	btst	#14,dmaconr(a5)
	bne.s	.bwait5
	clr.w	bltamod(a5)
.next:
	bsr	.move_vertikal
	addq.l	#4,a0
	addq.l	#4,a3
	lea	SW_len(a1),a1
	dbf	d7,.loop
	rts

.not_2:
	moveq	#3,d7
.Bloop:
	tst.l	(a3)
	beq	.Bnext

	move.w	Scr_Scrolled_Y(a6),d0
	sub.w	d0,6(a1)
	sub.w	d0,8(a1)

	tst.w	4(a1)
	bpl.s	.Bright
	lea	left_big_spread(pc),a4
	bra.s	.Bleft
.Bright:
	lea	right_big_spread(pc),a4
.Bleft:

	move.l	(a0),d0
	addq.l	#4,d0

	move.w	#$09f0,bltcon0(a5)
	btst	#0,10(a1)
	bne.s	.Bblit_it1
	move.w	#$0100,bltcon0(a5)
.Bblit_it1:
	move.l	d0,bltdpth(a5)
	move.l	(a4),bltapth(a5)	;Obersten Schuss blitten.
	move.w	#64*14+2,bltsize(a5)
.Bbwait1:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait1
	move.w	#$0100,bltcon0(a5)
	move.w	#64*29+2,bltsize(a5)	;Clearen des Sprites.
.Bbwait0:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait0

	;Checken, ob sichs noch berlappt

	moveq	#0,d1
	move.w	8(a1),d1
	sub.w	2(a1),d1
	cmp.w	#29,d1
	bge	.Bno_cross

	move.l	4(a4),d3
	moveq	#14,d2
	sub.w	d1,d2
	ble.s	.no_lapp

	lsr.w	#1,d2
	add.w	d2,d1

	sub.w	d2,d3
	sub.w	d2,d3
	sub.w	d2,d3
	sub.w	d2,d3

	neg.w	d2
	add.w	#14,d2
	asl.w	#6,d2
	or.w	#2,d2
	bra.s	.lapp
.no_lapp:
	move.w	#64*14+2,d2
.lapp:
	asl.w	#2,d1
	add.l	d0,d1

	move.l	d1,bltdpth(a5)
	move.w	#$09f0,bltcon0(a5)
	btst	#2,10(a1)
	bne.s	.Bblit_it2
	clr.w	bltcon0(a5)
.Bblit_it2:
	move.l	d3,bltapth(a5)
	move.w	#-8,bltamod(a5)
	move.w	d2,bltsize(a5)
.Bbwait2:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait2

	clr.w	bltamod(a5)

	btst	#1,10(a1)
	beq	.Bnext

	moveq	#0,d2
	move.w	6(a1),d2
	sub.w	2(a1),d2

	asl.w	#2,d2
	add.l	d0,d2

	move.l	d2,bltdpth(a5)
	move.l	d2,bltcpth(a5)
	move.l	8(a4),bltbpth(a5)
	move.l	12(a4),bltapth(a5)
	move.w	#$0fca,bltcon0(a5)
	move.w	#64*13+2,bltsize(a5)
.Bbwait3:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait3

	bra	.Bnext

.Bno_cross:
	move.l	d0,a2
	move.l	(a3),d6
	and.b	#$f1,d6
	move.l	d6,-4(a2)
	move.w	2(a1),d2
	moveq	#14,d3
	bsr	.calc_ycoord
	btst	#0,10(a1)
	bne.s	.Bis_there1
	clr.b	-3(a2)
.Bis_there1:

	move.l	-4(a2),(a3)

	add.l	#14*4,a2
	move.l	d6,(a2)+
	move.w	6(a1),d2
	moveq	#13,d3
	bsr	.calc_ycoord
	btst	#1,10(a1)
	bne.s	.Bis_there2
	clr.b	-3(a2)
.Bis_there2:

	move.w	#$09f0,bltcon0(a5)
	move.l	8(a4),bltapth(a5)
	move.l	a2,bltdpth(a5)
	move.w	#64*13+2,bltsize(a5)
.Bbwait4:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait4

	add.l	#13*4,a2
	move.l	d6,(a2)+
	move.w	8(a1),d2
	moveq	#14,d3
	bsr	.calc_ycoord
	btst	#2,10(a1)
	bne.s	.Bis_there3
	clr.b	-3(a2)
.Bis_there3:

	move.l	a2,bltdpth(a5)
	move.l	4(a4),bltapth(a5)
	move.w	#-8,bltamod(a5)
	move.w	#64*14+2,bltsize(a5)
.Bbwait5:
	btst	#14,dmaconr(a5)
	bne.s	.Bbwait5
	clr.w	bltamod(a5)
.Bnext:
	bsr	.move_vertikal
	addq.l	#4,a0
	addq.l	#4,a3
	lea	SW_len(a1),a1
	dbf	d7,.Bloop
	rts

.move_vertikal:
	move.w	half_pixel(pc),d0
	sub.w	#1,2(a1)
	sub.w	d0,2(a1)
	add.w	#1,8(a1)
	add.w	d0,8(a1)
	rts

.calc_ycoord:
	add.w	#$2c,d2
	move.b	d2,-4(a2)
	btst	#8,d2
	beq.s	.no_y0
	or.b	#4,-1(a2)
.no_y0:
	add.w	d3,d2
	move.b	d2,-2(a2)
	btst	#8,d2
	beq.s	.no_y1
	or.b	#2,-1(a2)
.no_y1:
	rts

half_pixel:	dc.w	1
quarter_pixel:	dc.w	1
eights_pixel:	dc.w	1
help_pixel:	dc.w	0

right_small_spread:
	dc.l	s12_adr+SpriteAdr+4,s12_adr+SpriteAdr+4*7
	dc.l	s0_adr+SpriteAdr+4,sm1_adr+SpriteAdr+4

left_small_spread:
	dc.l	s12_adr+SpriteBuffer+4,s12_adr+SpriteBuffer+4*7
	dc.l	s0_adr+SpriteBuffer+4,sm1_adr+SpriteBuffer+4

right_big_spread:
	dc.l	s13_adr+SpriteAdr+4,s13_adr+SpriteAdr+4*14
	dc.l	s14_adr+SpriteAdr+4,sm1_adr+SpriteAdr+4

left_big_spread:
	dc.l	s13_adr+SpriteBuffer+4,s13_adr+SpriteBuffer+4*14
	dc.l	s14_adr+SpriteBuffer+4,sm1_adr+SpriteBuffer+4

change_weapons:
	move.b	T_weapon_new,d0
	cmp.b	T_weapon,d0
	bne.s	.in
	move.b	T_power_new,d0
	cmp.b	T_power,d0
	beq.s	.ok2

.in:
	tst.b	T_flash
	bne.s	.ok
	move.b	#29,T_flash		;Fr 29 Frames Blinken, solange die Sche den Screen verlassen!
.ok:
	st	T_noshot		;Schsse sperren.

	lea	SW_table(pc),a1		;Sind alle Schu-salven vom Screen ?
	moveq	#3,d7
	moveq	#0,d0
.search:
	or.w	4(a1),d0
	lea	SW_len(a1),a1
	dbf	d7,.search

	tst.w	d0
	bne	.out

	move.b	T_weapon_new,T_weapon	;Alle Salven vom Screen, neue Waffe initen.
	move.b	T_power_new,T_power
	bsr	select_weapon
.ok2:
	sf	T_noshot
	rts
.out:
	rts

select_weapon:
	moveq	#0,d0
	move.b	T_weapon,d0
	add.w	d0,d0
	add.w	d0,d0
	lea	.startup_tab(pc),a0
	move.l	(a0,d0.w),a0
	lea	$dff1a2,a1

	move.w	(a0)+,d0
	move.w	d0,Col_Buffer+8
	move.l	L_coltab,a2
	lea	34(a2),a2
	move.w	d0,(a2)
	move.w	d0,8(a2)
	move.w	d0,8(a1)
	move.w	d0,(a1)+
	move.w	(a0)+,d0
	move.w	d0,Col_Buffer+10
	move.w	d0,2(a2)
	move.w	d0,10(a2)
	move.w	d0,8(a1)
	move.w	d0,(a1)
	move.l	(a0)+,SW_spec_rout
	move.l	(a0)+,a1
	jmp	(a1)

.startup_tab:
	dc.l	lazer_startup
	dc.l	spread_startup
	dc.l	blue_startup

spread_startup:
	dc.w	$ec0,$e82
	dc.l	Blit_Spread
	dc.l	Init_Spread
lazer_startup:
	dc.w	$8c1,$080
	dc.l	Anim_lazer
	dc.l	Init_Lazer

blue_startup:
	dc.w	$5ad,$6bf
	dc.l	Show_bounce
	dc.l	Init_bounce

SW_deftab1:	;Lazer small.
	dc.l	w0_adr+SpriteAdr,w1_adr+SpriteAdr,w2_adr+SpriteAdr,w3_adr+SpriteAdr
SW_deftab2:	;Lazer mid.
	dc.l	w4_adr+SpriteAdr,w5_adr+SpriteAdr,w6_adr+SpriteAdr,w7_adr+SpriteAdr
SW_deftab3:	;Lazer big.
	dc.l	w8_adr+SpriteAdr,w9_adr+SpriteAdr
	dc.l	w10_adr+SpriteAdr,w11_adr+SpriteAdr
SW_deftab3B:	;Lazer big.
	dc.l	w12_adr+SpriteAdr,w13_adr+SpriteAdr
	dc.l	w14_adr+SpriteAdr,w15_adr+SpriteAdr

SW_deftab4:	;Spread small
	dc.l	s0_adr+SpriteAdr,s1_adr+SpriteAdr,s2_adr+SpriteAdr,s3_adr+SpriteAdr
SW_deftab5:	;Spread mid
	dc.l	s4_adr+SpriteAdr,s5_adr+SpriteAdr,s6_adr+SpriteAdr,s7_adr+SpriteAdr
SW_deftab6:	;Spread big
	dc.l	s8_adr+SpriteAdr,s9_adr+SpriteAdr,s10_adr+SpriteAdr,s11_adr+SpriteAdr

SW_deftab7:	;Bounce small
	dc.l	b2_adr+SpriteAdr,b4_adr+SpriteAdr,b5_adr+SpriteAdr,b6_adr+SpriteAdr
SW_deftab8:	;Bounce mid
	dc.l	b1_adr+SpriteAdr,b2_adr+SpriteAdr,b3_adr+SpriteAdr,b4_adr+SpriteAdr
SW_deftab9:	;Bounce big
	dc.l	b0_adr+SpriteAdr,b1_adr+SpriteAdr,b2_adr+SpriteAdr,b4_adr+SpriteAdr

	;In dieser Tabelle stehen alle Schsse, die OnScreen sind.

SW_len	= 12

SW_table:
	dc.w	100,100			;X,Y
	dc.w	0			;Speed
	dc.w	0,0			;Y2/Y3
	dc.w	0			;existing/notexisting Flags

	dc.w	120,100
	dc.w	0			;Speed
	dc.w	0,0			;Y2/Y3
	dc.w	0			;existing/notexisting Flags

	dc.w	140,100
	dc.w	0			;Speed
	dc.w	0,0			;Y2/Y3
	dc.w	0			;existing/notexisting Flags

	dc.w	160,100
	dc.w	0			;Speed
	dc.w	0,0			;Y2/Y3
	dc.w	0			;existing/notexisting Flags

W_lazer1_info:
	dc.w	8			;Speed
	dc.w	7			;Y-Offset
	dc.w	9			;Heigth
	dc.l	SW_deftab1		;def_table
	dc.w	0			;Width
	dc.b	1,8
	dc.w	8

W_lazer2_info:
	dc.w	8			;Speed
	dc.w	4			;Y-Offset
	dc.w	16			;Heigth
	dc.l	SW_deftab2		;def_table
	dc.w	0			;Width
	dc.b	1,3
	dc.w	15

W_lazer3_info:
	dc.w	8			;Speed
	dc.w	-4			;Y-Offset
	dc.w	31			;Heigth
	dc.l	SW_deftab3		;def_table
	dc.w	1			;Width
	dc.b	1,0
	dc.w	30

W_spread1_info:
	dc.w	8
	dc.w	8
	dc.w	6
	dc.l	SW_deftab4
	dc.w	0
	dc.b	1,8
	dc.w	8

W_spread2_info:
	dc.w	8
	dc.w	4
	dc.w	22
	dc.l	SW_deftab5
	dc.w	0
	dc.b	7,8
	dc.w	8

W_spread3_info:
	dc.w	8
	dc.w	1
	dc.w	43
	dc.l	SW_deftab6
	dc.w	0
	dc.b	7,0
	dc.w	8

W_bounce1_info:
	dc.w	8			;Speed
	dc.w	7			;Y-Offset
	dc.w	38			;Heigth
	dc.l	SW_deftab7		;def_table
	dc.w	0			;Width
	dc.b	1,8
	dc.w	8

SW_defpoint:	dc.l	SW_deftab2
SW_heigth:	dc.w	0
SW_width:	dc.w	2
SW_spec_rout:	dc.l	Return
SW_power:	dc.w	1
SW_kolly:	dc.w	0
SW_kolly2:	dc.w	0

T_anim:		dc.w	5
T_posX:		dc.l	100*65536
T_posY:		dc.l	90*65536
T_speedX:	dc.l	0
T_speedY:	dc.l	0
T_face:		dc.w	0

T_anvz:		dc.w	0
T_anpos:	dc.w	0
T_ansize:	dc.w	0
T_antab:	dc.l	0
T_anspeed:	dc.w	0

sprite_adr:	dc.l	0,0,0,0,0,0,0,0
sprite_pos:	dc.l	0,0,0,0,0,0,0,0

T_walk_tab:	dc.b	0,1,2,3,4,5,6,7
T_roll_tab:	dc.b	31,30,29,28

	even

T_animtab_len:
	dc.b	28,32, 29,36, 22,37, 34,36, 35,33, 35,37, 22,37, 23,36
	dc.b	43,36, 42,36, 41,36, 41,36, 37,36, 36,36, 34,36, 33,36
	dc.b	32,36, 29,36, 29,36, 29,36, 29,36
	dc.b	23,41, 20,27, 29,36, 29,39, 35,34, 26,32, 24,26
	dc.b	23,19, 23,19, 23,19, 21,20
	dc.b	35,36, 33,36, 36,36, 36,22, 36,36
	dc.b	21,41, 28,40, 28,40

T_animtab_offs:
	dc.b	7,0,7,0,7,0,0,0,0,0,2,0,7,0,7,0
	dc.b	0,7,0,6,0,5,0,5,0,1,0,0,2,0,3,0
	dc.b	4,0,7,0,7,0,7,0,7,0
	dc.b	7,0, 7,0, 7,0, 0,0,0,0,1,0,2,0
	dc.b	0,3,0,2,0,2,0,0
	dc.b	0,0,1,0,0,0,0,8,0,0
	dc.b	7,0, 2,0, 0,0

T_animtab_adr:
	dc.w	t01_adr,t02_adr,t03_adr,t04_adr,t05_adr,t06_adr,t07_adr,t08_adr,t09_adr,t10_adr
	dc.w	t11_adr,t12_adr,t13_adr,t14_adr,t15_adr,t16_adr,t17_adr,t18_adr,t19_adr,t20_adr
	dc.w	t21_adr,t22_adr,t23_adr,t24_adr,t25_adr,t26_adr,t27_adr,t28_adr,t29_adr,t30_adr
	dc.w	t31_adr,t32_adr,t33_adr,t34_adr,t35_adr,t36_adr,t37_adr,t38_adr,t39_adr,t40_adr

T_animtab_xy:
	dc.b	0,0, 0,-1, 0,-2, 2,-1, 2,0, 1,-2, 0,-2, 0,-2, 1,-8, 1,-7
	dc.b	1,-6,0,-6,-1,-2,-2,-1,-2,-1,-3,-1,-3,-1,-3,-1,-3,-1,-3,-1
	dc.b	-2,-1, -3,-3, -3,8, -3,-1, -3,0,1,0,0,3,0,9
	dc.b	4,13,4,13,4,13,5,14,0,0,0,0,0,0,0,0,0,0
	dc.b	0,-1, -1,-1, 2,-1

t01_len	= (28+32+4)*8
t02_len	= (29+36+4)*8
t03_len	= (22+37+4)*8
t04_len	= (34+36+4)*8
t05_len	= (35+33+4)*8
t06_len	= (35+37+4)*8
t07_len	= (22+37+4)*8
t08_len	= (23+36+4)*8
t09_len	= (43+36+4)*8
t10_len	= (42+36+4)*8
t11_len	= (41+36+4)*8
t12_len	= (41+36+4)*8
t13_len	= (37+36+4)*8
t14_len	= (36+36+4)*8
t15_len	= (34+36+4)*8
t16_len	= (33+36+4)*8
t17_len	= (32+36+4)*8
t18_len	= (29+36+4)*8
t19_len	= (29+36+4)*8
t20_len	= (29+36+4)*8

t21_len	= (29+36+4)*8

t22_len	= (23+41+4)*8
t23_len	= (20+27+4)*8
t24_len	= (29+36+4)*8
t25_len	= (29+39+4)*8
t26_len	= (35+34+4)*8
t27_len	= (26+32+4)*8
t28_len	= (24+26+4)*8
t29_len	= (23+19+4)*8
t30_len	= (23+19+4)*8
t31_len	= (23+19+4)*8
t32_len	= (21+20+4)*8

t33_len	= (35+36+4)*8
t34_len	= (33+36+4)*8
t35_len	= (36+36+4)*8
t36_len	= (36+22+4)*8
t37_len	= (36+36+4)*8

t38_len	= (21+41+4)*8
t39_len	= (28+40+4)*8
t40_len	= (28+40+4)*8

w0_len	= (9+2)*4
w4_len	= (16+2)*4
w8_len	= (31+2)*4

s0_len	= (6+2)*4
s4_len	= (22+2)*4
s8_len	= (43+2)*4
s12_len	= (7+2)*4
s13_len	= (14+2)*4
s14_len	= (13+2)*4

b0_len	= (38+2)*4
b1_len	= (34+2)*4
b2_len	= (30+2)*4
b3_len	= (20+2)*4

m0_len	= (8+2)*8
m1_len	= (8+2)*8
m2_len	= (16+2)*8

t01_adr	= 0
t02_adr = t01_adr+t01_len
t03_adr = t02_adr+t02_len
t04_adr = t03_adr+t03_len
t05_adr = t04_adr+t04_len
t06_adr = t05_adr+t05_len
t07_adr = t06_adr+t06_len
t08_adr = t07_adr+t07_len
t09_adr = t08_adr+t08_len
t10_adr = t09_adr+t09_len
t11_adr = t10_adr+t10_len
t12_adr = t11_adr+t11_len
t13_adr = t12_adr+t12_len
t14_adr = t13_adr+t13_len
t15_adr = t14_adr+t14_len
t16_adr = t15_adr+t15_len
t17_adr = t16_adr+t16_len
t18_adr = t17_adr+t17_len
t19_adr = t18_adr+t18_len
t20_adr = t19_adr+t19_len
t21_adr = t20_adr+t20_len
t22_adr = t21_adr+t21_len
t23_adr = t22_adr+t22_len
t24_adr = t23_adr+t23_len
t25_adr = t24_adr+t24_len
t26_adr = t25_adr+t25_len
t27_adr = t26_adr+t26_len
t28_adr = t27_adr+t27_len
t29_adr	= t28_adr+t28_len
t30_adr	= t29_adr+t29_len
t31_adr	= t30_adr+t30_len
t32_adr	= t31_adr+t31_len
t33_adr	= t32_adr+t32_len
t34_adr	= t33_adr+t33_len
t35_adr	= t34_adr+t34_len
t36_adr	= t35_adr+t35_len
t37_adr	= t36_adr+t36_len

w0_adr	= t37_adr+t37_len
w1_adr	= w0_adr+w0_len
w2_adr	= w1_adr+w0_len
w3_adr	= w2_adr+w0_len

w4_adr	= w3_adr+w0_len
w5_adr	= w4_adr+w4_len
w6_adr	= w5_adr+w4_len
w7_adr	= w6_adr+w4_len

w8_adr	= w7_adr+w4_len
w9_adr	= w8_adr+w8_len
w10_adr	= w9_adr+w8_len
w11_adr	= w10_adr+w8_len
w12_adr	= w11_adr+w8_len
w13_adr	= w12_adr+w8_len
w14_adr	= w13_adr+w8_len
w15_adr	= w14_adr+w8_len

s0_adr	= w15_adr+w8_len
s1_adr	= s0_adr+s0_len
s2_adr	= s1_adr+s0_len
s3_adr	= s2_adr+s0_len

s4_adr	= s3_adr+s0_len
s5_adr	= s4_adr+s4_len
s6_adr	= s5_adr+s4_len
s7_adr	= s6_adr+s4_len

s8_adr	= s7_adr+s4_len
s9_adr	= s8_adr+s8_len
s10_adr	= s9_adr+s8_len
s11_adr	= s10_adr+s8_len

s12_adr	= s11_adr+s8_len
s13_adr	= s12_adr+s12_len
s14_adr	= s13_adr+s13_len

sm1_adr	= s14_adr+s14_len

b0_adr	= sm1_adr+s14_len
b1_adr	= b0_adr+b0_len
b2_adr	= b1_adr+b1_len
b3_adr	= b2_adr+b2_len
b4_adr	= b3_adr+b2_len
b5_adr	= b4_adr+b3_len
b6_adr	= b5_adr+b3_len

m0_adr	= b6_adr+b3_len
m1_adr	= m0_adr+m0_len
m2_adr	= m1_adr+m1_len
m3_adr	= m2_adr+m2_len

t38_adr	= m3_adr+m2_len
t39_adr	= t38_adr+t38_len
t40_adr	= t39_adr+t39_len

s_len	= t40_adr+t40_len

* Tastatur-system *

Init_keys:
	move.b	#%00000000,$bfee01
	move.b	#%00000000,$bfef01
	move.b	#%01111111,$bfed01
	move.b	$bfed01,d0
	move.b	#%10001000,$bfed01
	move.b	#100,$bfe401
	move.b	#0,$bfe501
	move.b	#%00010001,$bfee01
	lea	keysin(pc),a0
	move.l	a0,$68
	rts

keysin:
	movem.l	d0-d1,-(sp)
	move.b	$bfec01,d0		;Daten auslesen.
	move.b	#%11111111,$bfec01	;Eins bit ausgeben.
	move.b	#%01001001,$bfee01
	eor.b	#$ff,d0
	ror.b	#1,d0
	move.b	d0,G_keycode

	move.b	#%01011001,$bfee01	;Timer A oneshoot

	move.b	d0,d1
	and.b	#127,d0

	cmp.b	#$66,d1
	beq	.wheel
	cmp.b	#$67,d1
	beq	.wheel
	cmp.b	#$46,d0
	beq	.key1
	cmp.b	#$5f,d0
	bne	.key0
	moveq	#0,d0
	bra	.setkey
.key1:
	moveq	#1,d0
.setkey:
	move.l	a0,-(sp)
	lea	G_keytab(pc),a0
	move.b	d1,(a0,d0.w)
	move.l	(sp)+,a0

.key0:
	move.b	$bfed01,d0
	btst	#0,d0
	beq.s	.key0		;Auf den Timeout warten.

	move.b	#%00000000,$bfee01
	move.w	#$0008,intreq+$dff000
	move.b	$bfed01,d0
	movem.l	(sp)+,d0-d1
	rte

.wheel:
 	move.b	#1,G_keytab+2
	bra	.key0


G_keycode:	dc.b	0
G_keytab:	dc.b	-1,-1,-1
G_quit:		dc.b	0

	even

VBI:
	jsr	TFMX+36
	st	VBI_Flag

	tst.b	VBI_count
	beq.s	.out
	subq.b	#1,VBI_count
.out:
;	move.w	d0,-(sp)
;.again:
	move.w	#$0020,intreq+custom
;	move.w	intreqr+custom,d0
;	and.w	#$0020,d0
;	bne.s	.again
;	move.w	(sp)+,d0
	nop
	rte

VBI_Flag:	dc.b	0
VBI_count:	dc.b	0

*--------------------------------------------------------------------------
*- - - - - - - COLLISION SYSTEM - - - - - - - -
*--------------------------------------------------------------------------
;	dc.w	100,100			;X,Y
;	dc.w	0			;Speed
;	dc.w	0,0			;Y2/Y3
;	dc.w	0			;existing/notexisting Flags

check_weapons:
	cmp.b	#2,T_weapon
	bne.s	.no_bounce_check

	lea	Bounce_List(pc),a5
	bsr	.check_bounce
	lea	Bounce_len(a5),a5
	bsr	.check_bounce

	lea	custom,a5
.no_bounce_check:
	lea	SW_table(pc),a1
	moveq	#3,d7
.mloop:
	tst.w	4(a1)
	beq	.still_alive
	bmi	.to_left

	moveq	#0,d6
	btst	#0,10(a1)
	beq.s	.no_1
	moveq	#1,d6
	move.w	(a1),d0
	move.w	2(a1),d1

	bsr	.check_shoot2
	beq.s	.no_1

.stop1:
	bclr	#0,10(a1)
	move.w	2(a1),d2
	bsr	.start_xplo
.no_1:
	btst	#1,10(a1)
	beq.s	.no_2
	st	d6
	move.w	(a1),d0
	move.w	6(a1),d1
	bsr	.check_shoot2
	beq.s	.no_2
.stop2:
	bclr	#1,10(a1)
	move.w	6(a1),d2
	bsr	.start_xplo
.no_2:
	btst	#2,10(a1)
	beq.s	.no_3
	st	d6
	move.w	(a1),d0
	move.w	8(a1),d1
	bsr	.check_shoot2
	beq.s	.no_3
.stop3:
	bclr	#2,10(a1)
	move.w	8(a1),d2
	bsr	.start_xplo
.no_3:
	bra	.next

.to_left:
	moveq	#0,d6
	btst	#0,10(a1)
	beq.s	.lno_1
	st	d6
	move.w	(a1),d0
	move.w	2(a1),d1
	sub.w	#24,d0
	bsr	.check_shoot2
	beq.s	.lno_1
.lstop1:
	bclr	#0,10(a1)
	move.w	2(a1),d2
	bsr	.start_xplo2
.lno_1:
	btst	#1,10(a1)
	beq.s	.lno_2
	st	d6
	move.w	(a1),d0
	move.w	6(a1),d1
	sub.w	#24,d0
	bsr	.check_shoot2
	beq.s	.lno_2
.lstop2:
	bclr	#1,10(a1)
	move.w	6(a1),d2
	bsr	.start_xplo2
.lno_2:
	btst	#2,10(a1)
	beq.s	.lno_3
	st	d6
	move.w	(a1),d0
	move.w	8(a1),d1
	sub.w	#24,d0
	bsr	.check_shoot2
	beq.s	.lno_3
.lstop3:
	bclr	#2,10(a1)
	move.w	8(a1),d2
	bsr	.start_xplo2
.lno_3:

.next:
	tst.w	d6
	bne.s	.still_alive
	clr.w	4(a1)		;Kill Salve!
.still_alive:
	lea	SW_len(a1),a1
	dbf	d7,.mloop
	rts

.start_xplo2:
	tst.b	Scr_Flicker(a6)
	bne	.ok2
	moveq	#2,d0
	move.w	(a1),d1
	sub.w	#16,d1
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	moveq	#0,d3
	move.b	11(a1),d3
	sub.w	d3,d2
	movem.l	d6-d7/a1,-(sp)
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Last_Entry
	tst.w	d7
	bmi.s	.no
	move.b	#BOB_NOCOL,Bob_Used(a4)
.no:
	movem.l	(sp)+,d6-d7/a1
	rts

.start_xplo:
	tst.b	Scr_Flicker(a6)
	bne	.ok2
	moveq	#2,d0
	move.w	(a1),d1
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	moveq	#0,d3
	move.b	11(a1),d3
	sub.w	d3,d2
	movem.l	d6-d7/a1,-(sp)
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Last_Entry
	tst.w	d7
	bmi.s	.no2
	move.b	#BOB_NOCOL,Bob_Used(a4)
.no2:
	movem.l	(sp)+,d6-d7/a1
	rts

.check_shoot2:
	movem.w	d0-d1,-(sp)

	addq.w	#8,d0
	move.w	d0,d2
	move.w	d1,d3
	subq.w	#8,d0
	subq.w	#4,d1
	addq.w	#8,d2
	add.w	SW_kolly,d3
	movem.l	d6/a1,-(sp)
	bsr	check_rec
	movem.l	(sp)+,d6/a1

	movem.w	(sp)+,d0-d1
	beq.s	.no3
	bsr	.hit_enemy
	moveq	#1,d0
	rts
.no3:
	add.w	SW_kolly2,d1
	bsr	check_kollision
	beq.s	.ok2
	PLAY_FX	#$15
	moveq	#1,d0
	rts

.hit_enemy:
	cmp.w	#FLICKER,Bob_Hit(a0)
	beq.s	.ok2		;Nicht im gleichen Frame von mehreren Schen treffen!
	cmp.w	#-1,Bob_Power(a0)
	beq.s	.ok
	move.w	SW_power,d0
	sub.w	d0,Bob_Power(a0)
	bpl.s	.ok
	clr.w	Bob_Power(a0)
.ok:
	move.w	#FLICKER,Bob_Hit(a0)
;	PLAY_FX	#$16
.ok2:
	rts

.check_bounce:
	tst.w	Bounce_Used(a5)
	beq.s	.no_bounce
	move.w	Bounce_X(a5),d0
	move.w	Bounce_Y(a5),d1
	move.w	d0,d2
	move.w	d1,d3
;	subq.w	#4,d1
	add.w	#16,d2
	add.w	#16,d3
	movem.l	d6/a1,-(sp)
	bsr	check_rec
	movem.l	(sp)+,d6/a1
	beq.s	.no_bounce
	move.w	SW_power,d1
	move.w	#2,SW_power
	bsr	.hit_enemy
	move.w	d1,SW_power
	bsr	Xplo_Bounce
	bsr	Kill_Bounce
.no_bounce:
	rts

check_player:
	move.w	T_posX(pc),d0
	move.w	T_posY(pc),d1

	addq.w	#4,d1
	add.w	#10,d0
	move.w	d0,d2
	move.w	d1,d3

	add.w	#24,d3
	add.w	#18,d2

	cmp.w	#22,T_anim
	bne.s	.no_duck
	add.w	#10,d1
.no_duck:
	bsr	check_rec
	beq	Return
	cmp.w	#-1,Bob_Power(a0)
	beq	Return
	move.b	T_wheel,d1
	or.b	T_shield,d1
	bne	Return
	cmp.b	#BOB_NOPLCOL,Bob_Used(a0)
	rts

make_plhit:
	tst.b	smart_bomb
	bne	Return
	tst.b	T_dieing
	bne.s	.ok
	tst.b	T_flash
	bne	Return
	tst.b	T_shield
	bne	Return
	move.b	#40+10,T_flash
	move.b	#4*4,T_hit
	tst.b	T_rope
	beq.s	.no_rope
	PLAY_FX	#6
.no_rope:
	sf	T_rope
	sf	T_swing
	sf	T_targeting
	clr.b	T_state
	clr.w	T_target_count
	sf	T_button_longpressed
	tst.l	T_speedY
	bpl.s	.ok
	clr.l	T_speedY
.ok:
	PLAY_FX	#$14
	IFEQ	SpeedCheck
	moveq	#10,d0
	bra	sub_energy
	ELSEIF
	rts
	ENDC

Make_Power:
	moveq	#0,d0
	move.b	T_weapon,d0
	cmp.b	#2,d0
	beq.s	.set
	eor.b	#1,d0		;Spread = 0,Lazer = 1,Blue = 2
.set:
	moveq	#0,d1
	move.b	T_power,d1
	move.w	d1,d2
	add.w	d1,d1
	add.w	d2,d1
	add.w	d1,d0
	add.w	d0,d0
	move.w	(a0,d0.w),d0
	tst.b	T_rocket
	beq.s	.out
	addq.w	#8,d0
.out:
	rts

make_collision:
	lea	Coll_Anker,a0
	moveq	#3,d0
.clear:
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	dbf	d0,.clear

	lea	Coll_Anker,a1
	lea	Coll_Buffer,a0
	moveq	#$3c,d6

	move.l	Act_Bob_Structure(pc),a5
.loop:
	tst.b	Bob_Used(a5)
	ble	.no_kolli				;Kein Bob

	movem.w	Bob_X_Position(a5),d0-d1	;Calculate rectangle
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d1
	move.l	Bob_Act_Anim(a5),a2
	lea	Bob_A_Table_Koll_X(a2),a2
	add.w	(a2)+,d0
	add.w	(a2)+,d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	(a2)+,d2
	add.w	(a2),d3

	move.w	d1,d4			;Calculate table-offset
	lsr.w	#2,d4
	and.w	d6,d4			;Start

	move.w	d3,d5
	lsr.w	#2,d5
	addq.w	#4,d5
	and.w	d6,d5			;End
	cmp.w	d4,d5
	beq.s	.no_kolli
.insert_loop:
	lea	0(a1,d4.w),a3
	move.l	(a3),a2
	move.l	a0,(a3)
	move.l	a2,(a0)+
	movem.w	d0-d3,(a0)
	addq.w	#8,a0
	move.l	a5,(a0)+
	addq.w	#4,d4
	and.w	d6,d4
	cmp.w	d5,d4
	bne.s	.insert_loop

.no_kolli:
	add.w	#BOB_ENTRY_LENGTH,a5
	cmp.l	Act_Bob_Structure_End(pc),a5
	blo	.loop
	lea	custom,a5
	rts


;---------------------------------------------
; Check rectangle for collision
;
; d0,d1,d2,d3	Rectangle (x1,y1,x2,y2)
;
check_rec:
	move.w	d1,d4
	andi.w	#$f0,d4
	lsr.w	#2,d4
	move.w	d3,d5
	andi.w	#$f0,d5
	lsr.w	#2,d5
	lea	Coll_Anker,a1
	adda.w	d4,a1
	sub.w	d4,d5
	bpl.s	.pos1
	moveq	#0,d5
.pos1:
	move.l	(a1)+,d6
	beq.s	.end_loop1
.loop1:
	move.l	d6,a0
	cmp.w	8(a0),d0
	bgt.s	.no_col
	cmp.w	4(a0),d2
	blt.s	.no_col
	cmp.w	10(a0),d1
	bgt.s	.no_col
	cmp.w	6(a0),d3
	bgt.s	.rec_col
.no_col:
	move.l	(a0),d6
	bne.s	.loop1
.end_loop1:
	subq.w	#4,d5
	bpl.s	.pos1
	moveq	#0,d0
	rts

.rec_col:
	cmp.w	4(a0),d0
	ble.s	.lab1
	move.l	12(a0),a0
	moveq	#1,d0
	rts
.lab1:
	move.l	12(a0),a0
	moveq	#-1,d0
	rts

*--------------------------------------------------------------------------
*--------------------------------------------------------------------------
*--------	BOB-SYSTEM     X-CLIP
*--------------------------------------------------------------------------
*--------------------------------------------------------------------------
BOB_FALSE	=	-1
BOB_TRUE	=	1
BOB_NOCOL	=	0
BOB_NOPLCOL	=	2
BOB_NOPLHURT	=	3

NO_BOBROUT	=	0
NO_BOBBLIT	=	1
BOB_URGENT	=	2

			rsreset
Bob_Used		rs.b	1	;Eintrag benutzt/unbenutzt
Bob_BlitStatus		rs.b	1	;Bob im sichtbaren Bereich
Bob_to_Info_Offs	rs.w	1	;Offset von BobStruct auf InfoTab des Bobs
Bob_Race		rs.w	1	;Art des Bobs (Normal/Planes/Object)
Bob_Entry_Adress	rs.l	1	;Pointer auf Entry Area
Bob_X_Position		rs.w	1	;X-Position
Bob_Y_Position		rs.w	1	;Y-Position
Bob_X_Offset		rs.w	1	;X-Offset
Bob_Y_Offset		rs.w	1	;Y-Offset
Bob_X_Out		rs.w	1	;Betrag der Pixels, die das Bob in X-Dir draussen ist
Bob_Y_Out		rs.w	1	;Betrag der Pixels, die das Bob in Y-Dir draussen ist
Bob_Height		rs.w	1	;Hhe in Pixels
Bob_Status		rs.w	1	;Status (laufen, rennen, etc.)
Bob_Power		rs.w	1	;Hitpoints
Bob_Routine		rs.l	1	;Routine, die Bob verwaltet
Bob_Graphics		rs.l	1	;Zeiger auf Graphics
Bob_Mask		rs.l	1	;Z	eiger auf Maske
Bob_Next_Anim		rs.l	1	;Zeiger auf nchste Animation
Bob_Act_Anim		rs.l	1	;Zeiger auf aktuelle Animation (wg. Kollision)
Bob_Anim_Delay		rs.w	1	;Anim Delay
Bob_Anim_Delay_Init	rs.w	1	;Delay Init Wert
Bob_Plane_Order		rs.l	1	;Zeiger auf Tabelle mit Zeigern, die angeben welche Planes im Playfield mit welchen Planes des Bobs oder der Maske beschrieben werden sollen.
Bob_Hit			rs.w	1	;Treffer
Bob_RopeEnable		rs.b	1	;1= Objekt kann vom Seil getroffen werden.
Bob_Rope		rs.b	1	;0= Kein Seil am Objekt.
Bob_Out_X_Val		rs.w	1	;Wert ab dem das Bob ausgetragen wird
Bob_Out_Y_Val		rs.w	1	;W	ert ab dem das Bob ausgetragen wird
Bob_Special_1		rs.w	1	;Zur freien Verfgung
Bob_Special_2		rs.w	1	;Zur freien Verfgung
Bob_Special_3		rs.w	1	;Zur freien Verfgung
Bob_Special_4		rs.w	1	;Zur freien Verfgung
Bob_Special_5		rs.w	1	;Zur freien Verfgung
Bob_Special_6		rs.w	1	;Zur freien Verfgung
Bob_Special_7		rs.w	1	;Zur freien Verfgung
BOB_ENTRY_LENGTH	rs.w	0
	
Smart_Structure:
		dc.b	BOB_TRUE,0
		dc.w	Smart_Info-Smart_Structure
		dc.w	NORM
		dc.l	Area_Enter_Vector
		dc.w	0,0		;X/Y
		dc.w	0,0
		dc.w	0,0
		dc.w	15
		dc.w	0,0
		dc.l	0
		dc.l	main_GFX+Mbob25
		dc.l	main_GFX+Mmsk25
		dc.l	0
		dc.l	0
		dc.w	0,0
		dc.l	0
		dc.w	0
		dc.b	0,0
		dc.w	0,0

Smart_Info:	dc.w	NORM		;Bob_Mode
		dc.w	64		;Bob_I_Out_X_Val
		dc.w	64		;Bob_I_Out_Y_Val
		dc.w	32		;Breite in Pixels
		dc.w	23		;Hhe in Pixels
		dc.w	4		;Tiefe in Planes
		dc.w	2		;Breite einer Zeile der Maske in Bytes
		dc.w	1*2		;A Modulo
		dc.w	1*2*4		;B Modulo
		dc.w	planeb*4	;D Modulo
		dc.w	planeb		;Save Modulo
		dc.l	$ffff0000	;Bob_I_AFWM
		dc.w	2		;Blit-Breite in Wrtern
		dc.w	4		;Blit-Breite in Bytes
		dc.w	0		;Hitpoints
		dc.l	0,0

		dc.w	0		;Delay
		dc.w	6		;Delay Init
		dc.l	$ffffffff	;Zeiger auf Tabelle mit Zeigern, die angeben welche Planes im Playfield mit welchen Planes des Bobs oder der Maske beschrieben werden sollen.


Act_Bob_Structure:	dc.l	Bob_Structure
Act_Bob_Structure_End:	dc.l	Bob_Structure_End

Bob_Not_Finished	dc.w	0
Bob_Flags:		dc.w	0
*--------------------------------------------------------------------------

BOB_LAX_VAL		=	$e8
BOB_OHNE_LAX_VAL	=	$d0
Bob_End_Val		dc.l	BOB_LAX_VAL<<8
*--------------------------------------------------------------------------

Bob_System:	;Initialize Pointer to Structures
		move.l	Act_Scr_Structure(pc),a6
		move.l	Act_Bob_Structure(pc),a4

		;Initialize Pointer to CutomChips
		lea	$dff000,a5

		;Initialize Pointer to BackBufferStructure
		move.l	Rest_Pointer,a3

		tst.b	Scr_Flicker(a6)
		beq.s	.no_sub
		subq.b	#1,Scr_Flicker(a6)
.no_sub:

		tst.w	Bob_Not_Finished
		bmi    	Blit_Backwards

		;Bob Used ???
.Loop:		tst.b	Bob_Used(a4)
		bmi.s	.Unused

		btst.b	#NO_BOBROUT,Bob_BlitStatus(a4)
		bne.s	.NoRout

		move.l	Bob_Routine(a4),a0
		movem.l	a3-a6,-(sp)
		jsr	(a0)
		movem.l	(sp)+,a3-a6
		;Nochmal Testen, da Eintrag von Rout gelscht werden kann
		tst.b	Bob_Used(a4)
		bmi.s	.Unused

.NoRout:
		tst.b	G_bobmode
		bne	.Unused

		btst.b	#NO_BOBBLIT,Bob_BlitStatus(a4)
		bne.s	.Unused
		btst.b	#BOB_URGENT,Bob_BlitStatus(a4)
		bne.s	.Blit_Bob
		;Test if Bob Time is over

		tst.w	Bob_Not_Finished
		bne.s	.Unused
		move.l	$dff004,d0
		and.l	#$1ff00,d0
		tst.b	Bob_Flags
		beq.s	.check_normal
		cmp.l	#$10000,d0
		bge.s	.Blit_Bob
		sf	Bob_Flags
.check_normal:
		cmp.l	#$0e800,d0
		blt.s	.Blit_Bob

		tst.b	Scr_No_Flicker(a6)
		bne.s	.Blit_Bob

		move.w	#-1,Bob_Not_Finished
		move.b	#4,Scr_Flicker(a6)
		IFEQ	Real
		move.w	#$f00,$dff180
		ENDC
		bra.s	.Unused

		;Jump to corresponding BobRoutine
.Blit_Bob:	move.w	Bob_to_Info_Offs(a4),d7
		bsr	BLIT_BOB_SUPERVISOR

.Unused:	;Do next Bob
		add.w	#BOB_ENTRY_LENGTH,a4
		cmp.l	Act_Bob_Structure_End(pc),a4
		blo	.Loop

		move.l	Smart_Routine(pc),a0
		jsr	(a0)

		move.l	a3,Rest_Pointer
		clr.l	(a3)

		rts

*----------------------------------------------------------------------------
Blit_Backwards:
		;Jump to last Entry
		add.w	#(BOB_MAXIMUM-1)*BOB_ENTRY_LENGTH,a4

		;Bob Used ???
.LoopBack:	tst.b	Bob_Used(a4)
		bmi.s	.Unused

		btst.b	#NO_BOBROUT,Bob_BlitStatus(a4)
		bne.s	.NoRout
		move.l	Bob_Routine(a4),a0
		movem.l	a3-a6,-(sp)
		jsr	(a0)
		movem.l	(sp)+,a3-a6
		;Nochmal Testen, da Eintrag von Rout gelscht werden kann
		tst.b	Bob_Used(a4)
		bmi.s	.Unused

.NoRout:	btst.b	#NO_BOBBLIT,Bob_BlitStatus(a4)
		bne.s	.Unused
		btst.b	#BOB_URGENT,Bob_BlitStatus(a4)
		bne.s	.Blit_Bob
		;Test if Bob Time is over
		tst.w	Bob_Not_Finished
		beq.s	.Unused
		move.l	$dff004,d0
		and.l	#$1ff00,d0
		tst.b	Bob_Flags
		beq.s	.check_normal
		cmp.l	#$10000,d0
		bge.s	.Blit_Bob
		sf	Bob_Flags
.check_normal:
		cmp.l	#$0e800,d0
		blt.s	.Blit_Bob

		clr.w	Bob_Not_Finished
		move.b	#4,Scr_Flicker(a6)
		bra.s	.Unused

		;Jump to corresponding BobRoutine
.Blit_Bob	move	Bob_to_Info_Offs(a4),d7
		bsr	BLIT_BOB_SUPERVISOR

.Unused		;Do next Bob
		sub.w	#BOB_ENTRY_LENGTH,a4
		cmp.l	Act_Bob_Structure(pc),a4
		bhs	.LoopBack

		move.l	Smart_Routine(pc),a0
		jsr	(a0)

		move.l	a3,Rest_Pointer
		clr.l	(a3)

		clr.w	Bob_Not_Finished

		rts

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

Check_Smart_Start:
	tst.b	smart_bomb
	beq.s	.out
	move.l	#Do_smart_bomb1,Smart_Routine
.out:
	rts

Do_smart_bomb1:
		tst.b	G_bobmode
		beq	.no_smart

		lea	Smart_Structure(pc),a4

		move.w	super_radius,d3		;Get radius of circle
		moveq	#19,d6			;Do 20 balls
		moveq	#0,d7
.smart_loop:
		move.b	d6,d7
		mulu	#205,d7
		lsr.w	#4,d7

		move.b	d7,d0
		bsr	sin
		move.w	d0,d2
		move.b	d7,d0
		bsr	cos
		muls	d3,d0			;Calc position
		muls	d3,d2
		asr.l	#8,d0
		asr.l	#8,d2
		add.w	T_posX(pc),d0		;X
		add.w	Scr_X_Level_Pos(a6),d0
		add.w	#8,d0
		add.w	T_posY(pc),d2		;Y
		add.w	Scr_Y_Level_Pos(a6),d2
		add.w	#16,d2

		move.w	d0,Bob_X_Position(a4)
		move.w	d2,Bob_Y_Position(a4)

		move.w	Bob_to_Info_Offs(a4),d7
		movem.l	d3/d6,-(sp)
		bsr	BLIT_BOB_SUPERVISOR
		movem.l	(sp)+,d3/d6

		dbf	d6,.smart_loop

	add.w	#12,super_radius			;Enlarge radius

	cmpi.w	#100,super_radius		;Reached size for next stage ?
	blt	.no_smart

	tst.b	flash_count
	bne.s	.no_start
	jsr	L_StartFlash
.no_start:
	cmp.b	#16,flash_count
	bne	.no_smart
	move.l	#.Do_smart_bomb2,Smart_Routine

	sf	smart_bomb
	move.b	#15,T_flash
	sf	T_hit
	sf	G_bobmode

	;Allen Gegnern 16 Hitpoints Abziehen.

	move.l	Act_Bob_Structure(pc),a0
	moveq	#BOB_MAXIMUM-1,d7
.bob_hit:
	cmp.l	#Shoot,Bob_Routine(a0)
	beq.s	.kill

	tst.b	Bob_Used(a0)
	beq.s	.not_used
	bmi.s	.not_used

	move.w	Bob_X_Position(a0),d0
	sub.w	Scr_X_Level_Pos(a6),d0
	cmp.w	#304,d0
	bge.s	.not_used
	cmp.w	#-32,d0
	ble.s	.not_used
	move.w	Bob_Y_Position(a0),d0
	sub.w	Scr_Y_Level_Pos(a6),d0
	cmp.w	#208,d0
	bge.s	.not_used
	add.w	Bob_Height(a0),d0
	bmi.s	.not_used

	move.w	#FLICKER,Bob_Hit(a0)
	tst.w	Bob_Power(a0)
	bmi.s	.not_used
	moveq	#16,d0
	tst.b	Boss_flag
	beq.s	.no_bigboss
	moveq	#32,d0
.no_bigboss:
	sub.w	d0,Bob_Power(a0)
	bpl.s	.not_used
	clr.w	Bob_Power(a0)
.not_used:
	lea	BOB_ENTRY_LENGTH(a0),a0
	dbf	d7,.bob_hit

	rts

.kill:
	st	Bob_Used(a0)
	bra.s	.not_used

.Do_smart_bomb2:
	tst.b	flash_count
	bne.s	.no_smart
.end:
	sf	flash_count
	move.w	#0,super_radius
	move.l	#Check_Smart_Start,Smart_Routine

.no_smart:
		tst.b	smart_bomb
		beq.s	.no_smart2
		not.b	G_bobmode
.no_smart2:
		rts

Smart_Routine:	dc.l	Check_Smart_Start

super_radius:	dc.w	0
G_bobmode:	dc.b	0
smart_bomb:	dc.b	0

flash_count:	dc.b	0
flash_mode:	dc.b	0

*----------------------------------------------------------------------------
*	Calculate Blit Vals
*
*	IN
*	a4 = Pointer to BobStructure
*	a6 = Pointer to ScrollStructure
*	d7 = Offset to Infotab
*
*	OUT
*	Bob
*----------------------------------------------------------------------------
BLIT_BOB_SUPERVISOR:
		bsr	Calculate_Blit_Vals
		tst.w	Bob_X_Out(a4)
		bne.s	.NoBlit
		tst.w	Bob_Y_Out(a4)
		bne.s	.NoBlit
		btst.b	#B_FAST,Bob_Race+1(a4)
		beq.s	.NormBob
		;cmp.w	#4,Bob_Race(a4)
		;bne.s	.NormBob
.FastBob	bsr	Calc_MoreMask_Bob
		rts
.NormBob	bsr	Calc_OneMask_ColBob
.NoBlit		rts

*----------------------------------------------------------------------------
*	Calculate Blit Vals
*
*	IN
*	a4 = Pointer to BobStructure
*	a6 = Pointer to ScrollStructure
*	d7 = Offset to Infotab
*
*	OUT
*	d0=XClip 0=nein -=Left +=Right
*	d1=YClip 0=nein -=Oben +=Unten
*	d2=Height First Part
*	d3=Height Second Part  0=nein
*	d4=First ScreenLine
*----------------------------------------------------------------------------
Calculate_Blit_Vals	;--XClipFlag XOutVal Lschen
		moveq	#0,d0
		clr.w	Bob_X_Out(a4)
		;--X Values berechnen
		move.w	Bob_X_Position(a4),d1
		add.w	Bob_X_Offset(a4),d1
		sub.w	Scr_X_Level_Pos(a6),d1
		bpl.s	.Bob_Rechts
		;--Test if Out-Left or XClip-Left
		move.w	d1,d2
		add.w	Bob_I_Width(a4,d7),d2
		beq.s	.Out_X_Zero
		bmi.s	.Out_X_Left
		;--XClip-Left
		move.w	d1,d0
		bra.s	.CalculateBlitValsY
.Bob_Rechts	;--Test if Out-Right 
		sub.w	Scr_X_Visible(a6),d1
		beq.s	.Out_X_Zero
		bpl.s	.Out_X_Right
		;--Test if Correct or XClip-Right
		add.w	 Bob_I_Width(a4,d7),d1
		bmi.s	.CalculateBlitValsY
		;--XClip_Right
		move	d1,d0
.CalculateBlitValsY	;--YClipFlag AnfScreenLine YOutVal Lschen
		moveq	#0,d1
		moveq	#0,d4
		clr.w	Bob_Y_Out(a4)
		;--BobHeight fr YClipBere in d2 schreiben
		move.w	Bob_Height(a4),d2
		;--Y Values berechnen
		move.w	Bob_Y_Position(a4),d3
		add.w	Bob_Y_Offset(a4),d3
		sub.w	Scr_Y_Level_Pos(a6),d3
		bpl.s	.Bob_Unten
		;--Test if Out-Up or YClip-Up
		move.w	d3,d1
		add.w	d2,d3
		beq.s	.Out_Y_Zero
		bmi.s	.Out_Y_Up
		;--YClip Up (Val in d1)
		add.w	d1,d2
		bra.s	.CalculateOn_ValsY
.Bob_Unten	;--Test if Out-Down
		move.w	d3,d4
		sub.w	Scr_Y_Visible(a6),d3
		beq.s	.Out_Y_Zero
		bpl.s	.Out_Y_Down
		;--Test if Correct or YClip-Down
		add.w	d2,d3
		bmi.s	.CalculateOn_ValsY
		;--YClip_Down
		sub.w	d3,d2
		move.w	d3,d1
.CalculateOn_ValsY	;--Bestimme AnfPlaneZeile
		add.w	Scr_Y_Play_Anf(a6),d4
		cmp.w	Scr_Plane_Height(a6),d4
		blo.s	.NoOverFlowHeight
		sub	Scr_Plane_Height(a6),d4
.NoOverFlowHeight	;--Flag auf NoWrap setzen
		moveq	#-1,d3
		;--Test auf Wrap Zeile
		move.w	Scr_Plane_Height(a6),d6
		sub.w	d4,d6
		sub.w	d2,d6
		bpl.s	.Calculate_End
		move.w	d6,d3
		;--Height of second Part of Bob
		neg.w	d3
		;--Height of first Part of Bob
		sub.w	d3,d2
.Calculate_End	rts
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Out_X_Zero	moveq	#-1,d1
.Out_X_Left	neg.w	d1
.Out_X_Right	move.w	d1,Bob_X_Out(a4)
		bra.s	.Calculate_End
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Out_Y_Zero	moveq	#-1,d3
.Out_Y_Up	neg	d3
.Out_Y_Down	move.w	d3,Bob_Y_Out(a4)
		bra.s	.Calculate_End
*----------------------------------------------------------------------------

*----------------------------------------------------------------------------
*	Calculate Blit-Values for Colour-Bob/One-Mask
*
*	IN
*	d0=XClip 0=nein -=Left +=Right
*	d1=YClip 0=nein -=Oben +=Unten
*	d2=Height First Part
*	d3=Height Second Part  0=nein
*	d4=First ScreenLine
*	d7 = Offset to Infotab
*	a4 = Pointer to BobStructure
*	a6 = Pointer to ScrollStructure
*
*	OUT
*	a0=Pointer to Graphics
*	a1=Pointer to Mask
*	a2=Offset to Playfield
*----------------------------------------------------------------------------
Calc_OneMask_ColBob	;--Get Graphik and Mask
		move.l	Bob_Graphics(a4),a0
		move.l	Bob_Mask(a4),a1
		;--YClipUp ???
		tst.w	d1
		bpl.s	.NoYClipUp
		;--Correct Pointer to Graphics and Mask
		btst	#B_FLIP,Bob_Race(a4)
		bne.s	.flip
		neg.w	d1
.flip: 
		mulu	Bob_I_Mask_Width(a4,d7),d1
		add.w	d1,a1
		mulu	Bob_I_Depth(a4,d7),d1
		add.w	d1,a0
.NoYClipUp	;--Determine YOffset to DestinationAdress
		mulu	Scr_Plane_Width(a6),d4
		move.l	d4,a2
		;--Prepare Values for XClip
		move.w	Bob_X_Position(a4),d5
		add.w	Bob_X_Offset(a4),d5
		move.w	Bob_I_Bytes(a4,d7),d1
		;--XClip
		tst.w	d0
		beq.s	.NoXClip
		bpl.s	.RightClip
.LeftClip		;--Clip it Left
		neg.w	d0
		and.w	#%1111111111110000,d0
		ext.l	d0
		add.l	d0,d5
		lsr.w	#3,d0
		add.w	d0,a0
		add.w	d0,a1
		sub.w	d0,d1
		bra.s	.NoXClip
.RightClip	;--Clip it Right
		and.w	#%1111111111110000,d0
		lsr.w	#3,d0
		sub.w	d0,d1
.NoXClip		;--Determine Breite: d0=Words d1=Bytes
		move.w	d1,d0
		ble	.End_OneMask_ColBob
		lsr.w	#1,d0
		;--Determine XOffset to DestinationAdress
		move.w	d5,d4
		and.w	#%0000000000001111,d4
		ror.w	#4,d4
		lsr.w	#3,d5
		ext.l	d5
		add.l	d5,a2
		;--Blit first-Bob-Part or One-part-Bob
		jsr	Blit_OneMask_ColBob
		;--Second Part of Bob necessary ???
		tst.w	d3
		bmi.s	.End_OneMask_ColBob
		;--Correct Pointer to Graphics and Mask
		mulu	Bob_I_Mask_Width(a4,d7),d2
		btst	#B_FLIP,Bob_Race(a4)
		beq.s	.noflip
		neg.w	d2
.noflip:
		add.w	d2,a1
		mulu	Bob_I_Depth(a4,d7),d2
		add.w	d2,a0
		;--Copy Height of second Part of Bob
		move.w	d3,d2
		;--Determine DestinationAdress
		sub.l	a2,a2
		add.w	d5,a2
		;--Blit second part of Bob
		jsr	Blit_OneMask_ColBob
.End_OneMask_ColBob	rts
*----------------------------------------------------------------------------
Calc_MoreMask_Bob:	;--Get Graphik and Mask
		move.l	Bob_Graphics(a4),a0
		move.l	Bob_Mask(a4),a1
		;--YClipUp ???
		tst.w	d1
		bpl.s	.NoYClipUp
		;--Correct Pointer to Graphics and Mask
		neg.w	d1
		mulu	Bob_I_Mask_Width(a4,d7),d1
		mulu	Bob_I_Depth(a4,d7),d1
		add.w	d1,a0
		add.w	d1,a1
.NoYClipUp	;--Determine YOffset to DestinationAdress
		mulu	Scr_Plane_Width(a6),d4
		move.l	d4,a2
		;--Prepare Values for XClip
		move.w	Bob_X_Position(a4),d5
		add.w	Bob_X_Offset(a4),d5
		move.w	Bob_I_Bytes(a4,d7),d1
		;--XClip
		tst.w	d0
		beq.s	.NoXClip
		bpl.s	.RightClip
.LeftClip		;--Clip it Left
		neg.w	d0
		and.w	#%1111111111110000,d0
		ext.l	d0
		add.l	d0,d5
		lsr.w	#3,d0
		add.w	d0,a0
		add.w	d0,a1
		sub.w	d0,d1
		bra.s	.NoXClip
.RightClip	;--Clip it Right
		and.w	#%1111111111110000,d0
		lsr.w	#3,d0
		sub.w	d0,d1
.NoXClip		;--Determine Breite: d0=Words d1=Bytes
		move.w	d1,d0
		lsr.w	#1,d0
		;--Determine XOffset to DestinationAdress
		move.w	d5,d4
		and.w	#%0000000000001111,d4
		ror.w	#4,d4
		lsr.w	#3,d5
		ext.l	d5
		add.l	d5,a2
		;--Blit first-Bob-Part or One-part-Bob
		jsr	Blit_MoreMask_Bob
		;--Second Part of Bob necessary ???
		tst.w	d3
		bmi.s	.End_OneMask_ColBob
		;--Correct Pointer to Graphics and Mask
		mulu	Bob_I_Mask_Width(a4,d7),d2
		mulu	Bob_I_Depth(a4,d7),d2
		add.w	d2,a0
		add.w	d2,a1
		;--Copy Height of second Part of Bob
		move.w	d3,d2
		;--Determine DestinationAdress
		sub.l	a2,a2
		add.w	d5,a2
		;--Blit second part of Bob
		jsr	Blit_MoreMask_Bob
.End_OneMask_ColBob	rts
*----------------------------------------------------------------------------
*	Blit Bob One-Mask Colour-Bob
*
*	a0 = Pointer to Graphics
*	a1 = Pointer to Mask
*	a2 = Pointer to PlayField
*	a3 = Pointer auf Buffer Structure
*	a4 = Pointer to BobEntry
*	a6 = Pointer to ScrollStructure
*	d0 = Breite in Words
*	d1 = Breite in Bytes
*	d2 = Height of Bob
*	d4 = Shift-Value in upper Nibble
*	d7 = Offset to Infotab
*----------------------------------------------------------------------------
Blit_OneMask_ColBob	;--TEST if COLOUR Bob
		btst.b	#B_COLOUR,Bob_Race+1(a4)
		bne	Blit_Colour
		;--Save Registers
		movem.l	d0/d2/d4-d5/a0,-(sp)
		;--TEST if BLOCK
		btst.b	#B_BLOCK,Bob_Race+1(a4)
		bne	Blit_Block
		;--Playfield-Blitsize/Height*64+Words
		lsl.w	#6,d2
		;--Storage-Blitsize/Playfield-BS*Planes+Words
		move.w	d2,d6
		mulu	Bob_I_Depth(a4,d7),d6
		add.w	d0,d2
		add.w	d0,d6
		;--TEST if no REFRESH
		btst.b	#B_NOT_REFRESH,Bob_Race(a4)
		bne.s	.NoRefresh
		;--Save Refresh-Blit-Values
		move.w	d6,(a3)+
		move.w	Scr_Single_Plane(a6),(a3)
		sub.w	d1,(a3)+
		move.l	a2,(a3)+
		;--Add BaseField to Playfield-Offset
.NoRefresh	add.l	Scr_Supply_Field(a6),a2
		;--Initialize Blitter
		lea	$dff000,a5
 		move.w	Bob_I_D_Modulo(a4,d7),d6
		sub.w	d1,d6
		move.w	Bob_I_A_Modulo(a4,d7),d5
		sub.w	d1,d5
		move.w	Bob_I_B_Modulo(a4,d7),d0
		sub.w	d1,d0
		waitblt
		move.w	d4,bltcon1(a5)
		or.w	#$0fca,d4
		move.w	d4,bltcon0(a5)
		move.w	d5,bltamod(a5)
		move.w	d0,bltbmod(a5)
		move.w	d6,bltcmod(a5)
		move.w	d6,bltdmod(a5)
		move.l	Bob_I_AFWM(a4,d7),bltafwm(a5)
		;--Initialize Loop Counter
		move.w	Bob_I_Depth(a4,d7),d5
		subq	#1,d5
		bra.s	.EnterToLoop
		;--Blit Bob
.Loop		add.w	Bob_I_Mask_Width(a4,d7),a0
		add.w	Scr_Single_Plane(a6),a2
.EnterToLoop	waitblt
		move.l	a1,bltapth(a5)
		move.l	a0,bltbpth(a5)
		move.l	a2,bltcpth(a5)
		move.l	a2,bltdpth(a5)
		IFNE	BobTest
		move.w	#$f00,$dff180
		ENDC
		move.w	d2,bltsize(a5)
		dbf	d5,.Loop
		IFNE	BobTest
		move.w	#$000,$dff180
		ENDC
		movem.l	(sp)+,d0/d2/d4-d5/a0
		rts
*---------------------------------------------------------------------------
Blit_MoreMask_Bob	;--Save Registers
		movem.l	d0/d2/d4-d5/a0,-(sp)
		;--TEST if BLOCK
		btst.b	#B_BLOCK,Bob_Race+1(a4)
		bne	Blit_Block
		;--Playfield-Blitsize/Height*64+Words
		move.w	d2,d6
		lsl.w	#6,d6
		;--Storage-Blitsize/Playfield-BS*Planes+Words
		mulu	Bob_I_Depth(a4,d7),d6
		add.w	d0,d6
		;--TEST if no REFRESH
		btst.b	#B_NOT_REFRESH,Bob_Race(a4)
		bne.s	.NoRefresh
		;--Save Refresh-Blit-Values
		move.w	d6,(a3)+
		move.w	Scr_Single_Plane(a6),(a3)
		sub.w	d1,(a3)+
		move.l	a2,(a3)+
		;--Add BaseField to Playfield-Offset
.NoRefresh	add.l	Scr_Supply_Field(a6),a2
		;--Initialize Blitter
		lea	$dff000,a5
 		move.w	Bob_I_D_Modulo(a4,d7),d2
		sub.w	d1,d2
		move.w	Bob_I_A_Modulo(a4,d7),d5
		sub.w	d1,d5
		move.w	Bob_I_B_Modulo(a4,d7),d0
		sub.w	d1,d0
		waitblt
		move.w	d4,bltcon1(a5)
		or.w	#%0000111111001010,d4
		move.w	d4,bltcon0(a5)
		move.w	d5,bltamod(a5)
		move.w	d0,bltbmod(a5)
		move.w	d2,bltcmod(a5)
		move.w	d2,bltdmod(a5)
		move.l	Bob_I_AFWM(a4,d7),bltafwm(a5)
		;--Initialize Loop Counter
		;--Blit Bob
		move.l	a1,bltapth(a5)
		move.l	a0,bltbpth(a5)
		move.l	a2,bltcpth(a5)
		move.l	a2,bltdpth(a5)
		move.w	d6,bltsize(a5)
		movem.l	(sp)+,d0/d2/d4-d5/a0
		rts
*---------------------------------------------------------------------------
Blit_Block	;--Playfield-Blitsize/Height*64+Words
		move.w	d2,d6
		lsl.w	#6,d6
		;--Storage-Blitsize/Playfield-BS*Planes+Words
		mulu	Bob_I_Depth(a4,d7),d6
		add.w	d0,d6
		;--TEST if no REFRESH
		btst.b	#B_NOT_REFRESH,Bob_Race(a4)
		bne.s	.NoRefresh
		;--Save Refresh-Blit-Values
		move.w	d6,(a3)+
		move.w	Scr_Single_Plane(a6),(a3)
		sub.w	d1,(a3)+
		move.l	a2,(a3)+
		;--Add BaseField to Playfield-Offset
.NoRefresh	add.l	Scr_Supply_Field(a6),a2
		;--Initialize Blitter
		lea	$dff000,a5
 		move.w	Bob_I_S_Modulo(a4,d7),d2
		sub.w	d1,d2
		move.w	Bob_I_A_Modulo(a4,d7),d5
		sub.w	d1,d5
		waitblt
		move.w	d4,bltcon1(a5)
		or.w	#%0000100111110000,d4
		move.w	d4,bltcon0(a5)
		move.w	d5,bltamod(a5)
		move.w	d2,bltdmod(a5)
		move.l	Bob_I_AFWM(a4,d7),bltafwm(a5)
		;--Blit Bob
		move.l	a0,bltapth(a5)
		move.l	a2,bltdpth(a5)
		move.w	d6,bltsize(a5)
		movem.l	(sp)+,d0/d2/d4-d5/a0
		rts
*---------------------------------------------------------------------------
Blit_Colour	;--Save Registers
		movem.l	d0/d2-d5/a0,-(sp)
		;Calculate Blitsize / d6-Storage d2-Playfield
		lsl.w	#6,d2
		move.w	d2,d6
		mulu	Bob_I_Depth(a4,d7),d6
		add.w	d0,d2
		add.w	d0,d6
		;--TEST if no REFRESH
		btst.b	#B_NOT_REFRESH,Bob_Race(a4)
		bne.s	.NoRefresh
		;--Save Refresh-Blit-Values
		move.w	d6,(a3)+
		move.w	Scr_Single_Plane(a6),(a3)
		sub.w	d1,(a3)+
		move.l	a2,(a3)+
		;--Add BaseField to Playfield-Offset
.NoRefresh	add.l	Scr_Supply_Field(a6),a2
		;--Initialize Blitter
		lea	$dff000,a5
 		move.w	Bob_I_D_Modulo(a4,d7),d6
		sub.w	d1,d6
		move.w	Bob_I_A_Modulo(a4,d7),d5
		sub.w	d1,d5
		move.w	Bob_I_B_Modulo(a4,d7),d0
		sub.w	d1,d0
		waitblt
		move.w	d4,bltcon1(a5)
		move.w	d5,bltamod(a5)
		move.w	d0,bltbmod(a5)
		move.w	d6,bltcmod(a5)
		move.w	d6,bltdmod(a5)
		move.l	Bob_I_AFWM(a4,d7),bltafwm(a5)

.Plane1		cmp.b	#-3,Bob_Plane_Order(a4)
		beq	.EndBlit
		cmp.b	#-2,Bob_Plane_Order(a4)
		beq	.Forget2
		tst.b	Bob_Plane_Order(a4)
		beq.s	.E1
		bmi.s	.M1
.P1		moveq	#0,d6
		move.b	Bob_Plane_Order(a4),d6
		bsr	.BlitItPlane
		bra.s	.Plane2
.M1		bsr	.BlitItMask
		bra.s	.Plane2
.E1		bsr	.BlitItEmpty
		bra.s	.Plane2
.Forget2
		add.w	Scr_Single_Plane(a6),a2
.Plane2		cmp.b	#-3,Bob_Plane_Order+1(a4)
		beq	.EndBlit
		cmp.b	#-2,Bob_Plane_Order+1(a4)
		beq	.Forget3
		tst.b	Bob_Plane_Order+1(a4)
		beq.s	.E2
		bmi.s	.M2
.P2		moveq	#0,d6
		move.b	Bob_Plane_Order+1(a4),d6
		bsr	.BlitItPlane
		bra.s	.Plane3
.M2		bsr	.BlitItMask
		bra.s	.Plane3
.E2		bsr	.BlitItEmpty
		bra.s	.Plane3
.Forget3
		add.w	Scr_Single_Plane(a6),a2
.Plane3		cmp.b	#-3,Bob_Plane_Order+2(a4)
		beq.s	.EndBlit
		cmp.b	#-2,Bob_Plane_Order+2(a4)
		beq	.Forget4
		tst.b	Bob_Plane_Order+2(a4)
		beq.s	.E3
		bmi.s	.M3
.P3		moveq	#0,d6
		move.b	Bob_Plane_Order+2(a4),d6
		bsr	.BlitItPlane
		bra.s	.Plane4
.M3		bsr	.BlitItMask
		bra.s	.Plane4
.E3		bsr	.BlitItEmpty
		bra.s	.Plane4
.Forget4
		add.w	Scr_Single_Plane(a6),a2
.Plane4		cmp.b	#-3,Bob_Plane_Order+3(a4)
		beq.s	.EndBlit
		cmp.b	#-2,Bob_Plane_Order+3(a4)
		beq	.Plane5
		tst.b	Bob_Plane_Order+3(a4)
		beq.s	.E4
		bmi.s	.M4
.P4		moveq	#0,d6
		move.b	Bob_Plane_Order+3(a4),d6
		bsr	.BlitItPlane
		bra.s	.Plane5
.M4		bsr	.BlitItMask
		bra.s	.Plane5
.E4		bsr	.BlitItEmpty
.Plane5
.EndBlit	movem.l	(sp)+,d0/d2-d5/a0
		rts

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.BlitItPlane	waitblt
		move.l	a0,-(sp)
		subq.w	#1,d6
		mulu	Bob_I_Mask_Width(a4,d7),d6
		add.w	d6,a0
		move.w	d4,d6
		or.w	#%0000111111001010,d6
		move.w	d6,bltcon0(a5)
		move.w	d0,bltbmod(a5)
		move.l	a1,bltapth(a5)
		move.l	a0,bltbpth(a5)
		move.l	a2,bltcpth(a5)
		move.l	a2,bltdpth(a5)
		move.w	d2,bltsize(a5)
		add.w	Scr_Single_Plane(a6),a2
		move.l	(sp)+,a0
		rts
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.BlitItMask	waitblt
		move.w	d4,d6
		or.w	#%0000111111001010,d6
		move.w	d6,bltcon0(a5)
		move.w	d5,bltbmod(a5)
		move.l	a1,bltapth(a5)
		move.l	a1,bltbpth(a5)
		move.l	a2,bltcpth(a5)
		move.l	a2,bltdpth(a5)
		move.w	d2,bltsize(a5)
		add.w	Scr_Single_Plane(a6),a2
		rts
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.BlitItEmpty	waitblt
		move.w	d4,d6
		or.w	#%0000101100001010,d6
		move.w	d6,bltcon0(a5)
		move.l	a1,bltapth(a5)
		move.l	a2,bltcpth(a5)
		move.l	a2,bltdpth(a5)
		move.w	d2,bltsize(a5)
		add.w	Scr_Single_Plane(a6),a2
		rts

*--------------------------------------------------------------------------
*-------		INFO STRUCTURE        ---------------------------------
*--------------------------------------------------------------------------
		rsreset
Bob_I_Race	rs.w	1	;Art des Bobs
Bob_I_Out_X_Val	rs.w	1	;Wert ab dem Bob ausgetragen wird
Bob_I_Out_Y_Val	rs.w	1	;Wert ab dem Bob ausgetragen wird
Bob_I_Width	rs.w	1	;Breite in Bytes
Bob_I_Height	rs.w	1	;Hhe in Pixels
Bob_I_Depth	rs.w	1	;Tiefe in Planes
Bob_I_Mask_Width	rs.w	1	;Breite der Maske
Bob_I_A_Modulo	rs.w	1	;A Modulo
Bob_I_B_Modulo	rs.w	1	;B Modulo
Bob_I_D_Modulo	rs.w	1	;D Modulo
Bob_I_S_Modulo	rs.w	1	;Save Modulo
Bob_I_AFWM	rs.l	1	;Mask for Blit
Bob_I_Words	rs.w	1	;Breite in Wrtern
Bob_I_Bytes	rs.w	1	:Breite in Bytes
Bob_I_Power	rs.w	1	;Hitpoints
Bob_I_Routine	rs.l	1	;Routine, die Bob verwaltet
Bob_I_Next_Anim	rs.l	1	;Zeiger auf nchste Animation
Bob_I_Anim_Delay	rs.w	1	;Anim Delay
Bob_I_Anim_Del_Init	rs.w	1	;Delay Init Wert
Bob_I_Plane_Order	rs.l	1	;Flags fr Maskenplanes
BOB_I_ENTRY_LENGTH	rs.w	0


*---------------------------------------------------------------------------
*-------		Animation Structure

		rsreset
Bob_A_Table_Gfx	rs.l	1	;Pointer auf GFX
Bob_A_Table_Msk	rs.l	1	;Pointer auf Msk
Bob_A_Table_X_Off	rs.w	1	;X Add zustzlich zu X pos
Bob_A_Table_Y_Off	rs.w	1	;Y Add zustzlich zu Y pos
Bob_A_Table_Height	rs.w	1	;Hhe der zu blittenden Anim
Bob_A_Table_Koll_X	rs.w	1	;X-Offset zu X pos fr Kollision
Bob_A_Table_Koll_Y	rs.w	1	;Y-Offset zu Y pos fr Kollision
Bob_A_Table_Koll_W	rs.w	1	;X-Breite zu X pos fr Kollision
Bob_A_Table_Koll_H	rs.w	1	;X-Hhe   zu X pos fr Kollision
BOB_A_ENTRY_SIZE	rs.w	0
		rsreset
Bob_A_Table_End	rs.w	1	;-1 bei Ende
Bob_A_Table_Cont	rs.l	1	;Pointer auf Table, mit dem weitergemacht wird 
BOB_A_END_SIZE	rs.w	0

*---------------------------------------------------------------------------
* SEARCH FREE ENTRY IN BOB TABLE AND ENTER NEW
*
*	d0	Number of BobInfoTab
*	d1	X-Position
*	d2	Y-Position
*	a1	EntryAdr
*---------------------------------------------------------------------------
Check_Entries:
	move.l	Act_Bob_Structure(pc),a0
	moveq	#BOB_MAXIMUM-1,d7
.loop:
	tst.b	Bob_Used(a0)
	bpl.s	.search_next
	subq.w	#1,d0
	beq.s	.found_all
.search_next:
	add.w	#BOB_ENTRY_LENGTH,a0
	dbf	d7,.loop
.found_all:
	rts

Search_Last_Entry:
	move.l	Act_Bob_Structure(pc),a4
	lea	(BOB_MAXIMUM-1)*BOB_ENTRY_LENGTH(a4),a4
	moveq	#BOB_MAXIMUM-1,d7
.Loop:
	tst.b	Bob_Used(a4)
	bmi.s	ENTER_BOB
	sub.w	#BOB_ENTRY_LENGTH,a4
	dbf	d7,.Loop
	rts

Search_Bob_Entry:	;and Enter Bob
		move.l	Act_Bob_Structure(pc),a4

		;Bob Used ???
		moveq	#BOB_MAXIMUM-1,d7
.Loop		tst.b	Bob_Used(a4)
		bmi.s	ENTER_BOB

		add.w	#BOB_ENTRY_LENGTH,a4
		dbf	d7,.Loop
		rts			;NoFreeEntry

ENTER_BOB:		;Enter Bob
	IFNE	CountBobs

	movem.l	d0/d1,-(sp)
	move.b	T_time,d0
	move.b	#0,ccr
	moveq	#1,d1
	abcd	d1,d0
	move.b	d0,T_time
	movem.l	(sp)+,d0/d1

	ENDC

		move.l	a1,Bob_Entry_Adress(a4)

		;Determine Info Tab Adress
		move.l	L_Info_Tab_Adrs,a0
		add.w	d0,d0
		add.w	d0,d0
		move.l	(a0,d0),a2

		;Write Values
		move.l	a2,d0
		sub.l	a4,d0
		move.w	d0,Bob_to_Info_Offs(a4)
		move.w	Bob_I_Race(a2),Bob_Race(a4)
		move.w	Bob_I_Height(a2),Bob_Height(a4)
		move.w	Bob_I_Power(a2),Bob_Power(a4)
		move.l	Bob_I_Routine(a2),Bob_Routine(a4)
		move.l	Bob_I_Next_Anim(a2),Bob_Next_Anim(a4)
		move.w	Bob_I_Anim_Delay(a2),Bob_Anim_Delay(a4)
		move.w	Bob_I_Anim_Del_Init(a2),Bob_Anim_Delay_Init(a4)
		move.l	Bob_I_Plane_Order(a2),Bob_Plane_Order(a4)
		move.w	Bob_I_Out_X_Val(a2),Bob_Out_X_Val(a4)
		move.w	Bob_I_Out_Y_Val(a2),Bob_Out_Y_Val(a4)

		;Write Values which are not in Info Table
		move.b	#BOB_TRUE,Bob_Used(a4)
		clr.b	Bob_BlitStatus(a4)
		move.w	d1,Bob_X_Position(a4)
		move.w	d2,Bob_Y_Position(a4)
		clr.w	Bob_X_Out(a4)
		clr.w	Bob_Y_Out(a4)
		clr.w	Bob_Special_1(a4)
		clr.w	Bob_Special_2(a4)
		clr.w	Bob_Special_3(a4)
		clr.w	Bob_Special_4(a4)
		clr.w	Bob_Hit(a4)
		clr.w	Bob_RopeEnable(a4)
		clr.w	Bob_Status(a4)

		bsr	Get_Next_Bob_Frame

		rts
*---------------------------------------------------------------------------
*	ENTER ALL DATA RESPONSIBLE FOR NEXT BOB FRAME
*
*	a4	Pointer to Bob Structure
*---------------------------------------------------------------------------

END_OUT_DAMAGE	EQU	-2
END_OUT		EQU	-3
ENTRY_END	EQU	-1

Get_Next_Bob_Frame:	;Test if End of Table is reached
		move.l	Bob_Next_Anim(a4),a1
		cmp.w	#END_OUT_DAMAGE,Bob_A_Table_End(a1)
		beq.s	.OutitDam
		cmp.w	#END_OUT,Bob_A_Table_End(a1)
		beq.s	.Outit
		cmp.w	#ENTRY_END,Bob_A_Table_End(a1)
		bne.s	.ok
		move.l	Bob_A_Table_Cont(a1),Bob_Next_Anim(a4)
		bra.s	Get_Next_Bob_Frame
.ok		;Enter new Values
		move.l	Bob_A_Table_Gfx(a1),Bob_Graphics(a4)
		move.l	Bob_A_Table_Msk(a1),Bob_Mask(a4)
		move.w	Bob_A_Table_X_Off(a1),Bob_X_Offset(a4)
		move.w	Bob_A_Table_Y_Off(a1),Bob_Y_Offset(a4)
		move.w	Bob_A_Table_Height(a1),Bob_Height(a4)
		move.l	a1,Bob_Act_Anim(a4)
		add.l	#BOB_A_ENTRY_SIZE,Bob_Next_Anim(a4)
		rts
.Outit		bra	Out_Bob
.OutitDam	bra	Out_Bob_Damage

Get_Next_Frame_OOff:	;Test if End of Table is reached
		move.l	Bob_Next_Anim(a4),a1
		cmp.w	#ENTRY_END,Bob_A_Table_End(a1)
		bne.s	.ok
		move.l	Bob_A_Table_Cont(a1),Bob_Next_Anim(a4)
		bra.s	Get_Next_Bob_Frame
.ok		;Enter new Values
		move.l	Bob_A_Table_Gfx(a1),Bob_Graphics(a4)
		move.l	Bob_A_Table_Msk(a1),Bob_Mask(a4)
		move.w	Bob_A_Table_Height(a1),Bob_Height(a4)
		add.l	#BOB_A_ENTRY_SIZE,Bob_Next_Anim(a4)
		rts

*---------------------------------------------------------------------------
*	ENTER ALL DATA RESPONSIBLE FOR NEXT BOB FRAME
*	
*	a4	Pointer to Bob Structure
*---------------------------------------------------------------------------
Test_Bob_Out:	move.w	Bob_X_Out(a4),d0
		lsr.w	#1,d0
		cmp.w	Bob_Out_X_Val(a4),d0
		blo.s	.No_X_Out

		bsr	Out_Bob
		rts

.No_X_Out	move.w	Bob_Y_Out(a4),d0
		lsr.w	#1,d0
		cmp.w	Bob_Out_Y_Val(a4),d0
		blo.s	.No_Y_Out

		bsr	Out_Bob

.No_Y_Out	rts


Out_Bob:	move.b	#BOB_FALSE,Bob_Used(a4)
		move.l	Bob_Entry_Adress(a4),a1
		clr.b	(a1)
	IFNE	CountBobs
	move.b	T_time,d0
	move.b	#0,ccr
	moveq	#1,d1
	sbcd	d1,d0
	move.b	d0,T_time
	ENDC
		rts

Out_Bob_Damage	move.b	#BOB_FALSE,Bob_Used(a4)
	IFNE	CountBobs
	move.b	T_time,d0
	move.b	#0,ccr
	moveq	#1,d1
	sbcd	d1,d0
	move.b	d0,T_time
	ENDC
		rts

Kill_Objects:
	move.l	a4,-(sp)
	move.l	a4,a0
	move.l	Act_Bob_Structure(pc),a4
	moveq	#BOB_MAXIMUM-1,d7
.loop:
	cmp.l	a0,a4				;Dont kill yourself!
	beq.s	.not_used
	;move.b	#BOB_FALSE,Bob_Used(a4)
	tst.b	Bob_Used(a4)
	bmi.s	.not_used
	bsr	Out_Bob
.not_used:
	lea	BOB_ENTRY_LENGTH(a4),a4
	dbf	d7,.loop
	sf	T_rocket_anz

	move.l	(sp)+,a4

	rts

Test_Bob_Out2:	move.l	a4,a0
		add.w	Bob_to_Info_Offs(a4),a0

		move.w	Bob_X_Position(a4),d0
		sub.w	Scr_X_Level_Pos(a6),d0
		bpl.s	.not1x
		add.w	Bob_I_Width(a0),d0
		bpl.s	.not2x
		neg.w	d0
		bra.s	.outx
.not1x:
		cmp.w	#304,d0
		blt.s	.not2x
		sub.w	#304,d0
		bra.s	.outx
.not2x:
		moveq	#0,d0
.outx:
		cmp.w	Bob_I_Out_X_Val(a0),d0
		bgt	Out_Bob

		move.w	Bob_Y_Position(a4),d0
		sub.w	Scr_Y_Level_Pos(a6),d0
		bpl.s	.not1y
		add.w	Bob_Height(a4),d0
		bpl.s	.not2y
		neg.w	d0
		bra.s	.outy
.not1y:
		cmp.w	#208,d0
		blt.s	.not2y
		sub.w	#208,d0
		bra.s	.outy
.not2y:
		moveq	#0,d0
.outy:
		cmp.w	Bob_I_Out_Y_Val(a0),d0
		bgt	Out_Bob
		rts

*---------------------------------------------------------------------------
Standart_BobAnim:
		subq.w	#1,Bob_Anim_Delay(a4)
		bpl.s	.NoNewAnim
		move.w	Bob_Anim_Delay_Init(a4),Bob_Anim_Delay(a4)
		bsr	Get_Next_Bob_Frame
.NoNewAnim
		bra	Test_Bob_Out

*---------------------------------------------------------------------------
*	CHECK IF BOB SHOULD BE ENTERED IN BOB STRUCTURE
*	
*	a6	Pointer to Scr-Structure
*	
*---------------------------------------------------------------------------
Area_Check:	;Test ob Eintragen ntig ist ?
		move.l	Act_Scr_Structure,a6
.TestX	  	;--Test ob X-64er Grenze berschritten wurde
		move	Scr_X_Level_Pos_Old(a6),d0
		move	Scr_X_Level_Pos(a6),d1
		and	#%1111111111000000,d0
		and	#%1111111111000000,d1
		cmp	d0,d1
		beq.s	.TestY
		;--Enter X according to Scroll-Direction
		bsr	.EnterX
.TestY		;--Test ob Y-64er Grenze berschritten wurde
		move	Scr_Y_Level_Pos_Old(a6),d0
		move	Scr_Y_Level_Pos(a6),d1
		and	#%1111111111000000,d0
		and	#%1111111111000000,d1
		cmp	d0,d1
		beq.s	.NoMoreTest
		;--Enter Y according to Scroll-Direction
		bsr	.EnterY
.NoMoreTest	rts
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -
.EnterX:	;--Calculate Base for X-Clr

		move	Scr_X_Level_Pos(a6),d5
		move	d5,d1
		and	#%1111111111000000,d1
		lsr	#6,d5
		;--Testen ob eins nach links mglich ist
		moveq	#0,d0	;NoSubFlag setzen
		tst.w	d5
		beq.s	.NoSubd5
		subq.w	#1,d5
		sub.w	#64,d1
		moveq	#1,d0	;NoSubFlag lschen
.NoSubd5	tst.w	Scr_X_Speed(a6)
		bmi.s	.NoOffsetAddX
		addq.w	#4+1,d5
		add.w	#(4+1)*64,d1
		tst.w	d0		;NoSubFlag testen
		beq.s	.NoOffsetAddX	;Weg,da nicht subtrahiert wurde
		addq.w	#1,d5
		add.w	#64,d1
.NoOffsetAddX:
		moveq	#4+1-1,d7
		move.w	Scr_Y_Level_Pos(a6),d6
		move.w	d6,d2
		and.w	#%1111111111000000,d2
		lsr.w	#6,d6
		beq.s	.no_sub
		subq.w	#1,d6
		sub.w	#64,d2
		addq.w	#1,d7
.no_sub:
		move.l	Area_Vector(pc),a0
		add.w	d5,d5
		mulu	Scr_BA_Anz_Area_X(a6),d6
		add.w	d6,d6
		add.w	d5,a0
		add.w	d6,a0
		;--Enter Loop

.LoopX		bsr	Enter_Bobs_of_Area
		add.w	Scr_BA_Anz_Area_X(a6),a0
		add.w	Scr_BA_Anz_Area_X(a6),a0
		add.w	#64,d2
		dbf	d7,.LoopX
.End_CheckX	rts
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -
.EnterY:	;--Calculate Base for X-Clr
		move.w	Scr_X_Level_Pos(a6),d5
		move.w	d5,d1
		and.w	#%1111111111000000,d1
		lsr.w	#6,d5
		moveq	#5+2-1,d7	;LoopCounter
		;--Testen ob eins nach links mglich ist
		tst.w	d5
		beq.s	.NoSubd5Y
		subq.w	#1,d5
		sub.w	#64,d1
		addq.w	#1,d7
.NoSubd5Y	move	Scr_Y_Level_Pos(a6),d6
		move.w	d6,d2
		and.w	#%1111111111000000,d2
		lsr.w	#6,d6
		subq.w	#1,d6
		bmi	.End_CheckY
		sub.w	#64,d2
		tst.w	Scr_Y_Speed(a6)
		bmi.s	.NoOffsetAddY
		addq.w	#3+1,d6
		add.w	#(3+1)*64,d2
.NoOffsetAddY	move.l	Area_Vector(pc),a0
		add.w	d5,d5
		mulu	Scr_BA_Anz_Area_X(a6),d6
		add.w	d6,d6
		add.w	d5,a0
		add.w	d6,a0
		;--Enter Loop
.LoopY		bsr	Enter_Bobs_of_Area
		addq.w	#2,a0
		add.w	#64,d1
		dbf	d7,.LoopY
.End_CheckY	rts
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -
EnterScreen:	;--Calculate Base for X-Clr
		move.w	#5+2-2,help
		move	Scr_X_Level_Pos(a6),d5
		cmp.w	#64,d5
		blt.s	.nosub
		sub.w	#64,d5
		addq.w	#1,help
.nosub:
		move	d5,d1
		and	#%1111111111000000,d1
		lsr	#6,d5
		moveq	#4+2-2,d7

		move	Scr_Y_Level_Pos(a6),d6
		cmp.w	#64,d6
		blt.s	.ok
		sub.w	#64,d6
		addq.w	#1,d7
.ok:
		move	d6,d2
		and	#%1111111111000000,d2
		lsr	#6,d6
		move.l	Area_Vector(pc),a0
		add	d5,d5
		mulu	Scr_BA_Anz_Area_X(a6),d6
		add	d6,d6
		add	d5,a0
		add	d6,a0
		;--Enter Loops
.LoopY		movem.l	d1-d2/a0,-(sp)
		move.w	help,d6
.LoopX		bsr	Enter_Bobs_of_Area
		addq	#2,a0
		add	#64,d1
		dbf	d6,.LoopX
		movem.l	(sp)+,d1-d2/a0
		add	Scr_BA_Anz_Area_X(a6),a0
		add	Scr_BA_Anz_Area_X(a6),a0
		add	#64,d2
		dbf	d7,.LoopY
		rts
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -
*------------------ - - - - - - - - - - - - - - - - - - - - - - - - -

*----------------------------------------------------------------------------
*	Enter all Bobs of Area in BobStructure
*	a0	Pointer to OffsetTab
*----------------------------------------------------------------------------
Enter_Bobs_of_Area:
		movem.l	d0-d1/d6-d7/a0/a6,-(sp)
		;--Test if Bobs/Anims are in Area
		tst.w	(a0)
		bmi.s	.End_of_Table
		move.l	Area_Vector(pc),a1
		adda.w	(a0),a1
.Loop		tst.b	(a1)
		bmi.s	.End_of_Table
		bne.s	.Already_entered

		;Bobs will now entered
		movem.l	d1-d2/a1,-(sp)
		move.b	#1,(a1)
		moveq	#0,d0
		move.b	Area_Bob_Info_Num(a1),d0
		add.w	Area_X_Position(a1),d1
		add.w	Area_Y_Position(a1),d2
		cmp.w	#128,d0
		blo.s	.Bob
		bsr	Search_Anim_Entry	;Background Anim
		bra.s	.next
.Bob		move.w	Area_Special(a1),d6
		bsr	Search_Bob_Entry
		tst.w	d7
		bmi.s	.not_possible
		move.w	d6,Bob_Special_4(a4)
.next		movem.l	(sp)+,d1-d2/a1
.Already_entered:
		addq.l	#AREA_ENTRY_LENGTH,a1
		bra	.Loop
.End_of_Table	movem.l	(sp)+,d0-d1/d6-d7/a0/a6
		rts

.not_possible:
		sf	(a1)
		bra.s	.next

		rsreset
Area_Bob_Entered	rs.b	1
Area_Bob_Info_Num	rs.b	1
Area_X_Position		rs.w	1
Area_Y_Position		rs.w	1
Area_Special		rs.w	1
AREA_ENTRY_LENGTH	rs.w	0


Area_Vector:		dc.l	0

Area_Enter_Vector	dc.w	0

Hit_Sound:	dc.w	$16

Standart_Hit_Handler:
	tst.w	Bob_Hit(a4)
	beq.s	.no_hit
	cmp.w	#FLICKER,Bob_Hit(a4)
	bne.s	.no_sound
	move.l	d0,-(sp)
	move.w	Hit_Sound,d0
	bsr	Do_FX
	move.l	(sp)+,d0
.no_sound:
	move.b	#COLOUR,Bob_Race+1(a4)
	subq.w	#1,Bob_Hit(a4)
	bne.s	.no_hit
.set_norm:
	move.b	#NORM,Bob_Race+1(a4)
.no_hit:
	move.w	#$16,Hit_Sound
	IFEQ	SpeedCheck
	tst.w	Bob_Power(a4)
	rts
	ELSEIF
	moveq	#1,d0
	rts
	ENDC

Standart_Destruction:
	move.l	d0,-(sp)
	PLAY_FX	#$1b
	move.l	(sp)+,d0
Silent_Destruction:
	bsr	add_score
	bsr	Out_Bob_Damage
	bra	Start_Explo


*---------------------------------------------------------------------------
*---------	RACE_MODIS/BITS
*---------------------------------------------------------------------------
;2.Byte
NORM		=	2
FAST		=	4
BLOCK		=	8
COLOUR		=	16
;1.Byte
NOT_REFRESH	=	256
FLIP		=	512
OR_REFRESH_FIELD	=	1024
BACK_ANIM		=	2048

;2.Byte
B_NORMAL		=	1	;ok
B_FAST		=	2	;ok
B_BLOCK		=	3	;ok
B_COLOUR		=	4	;ok
;1.Byte
B_NOT_REFRESH	=	0	;ok
B_FLIP		=	1
B_OR_REFRESH_FIELD	=	2
B_BACK_ANIM	=	3


Mbob00 	= $00000
Mmsk00 	= $00120
Mbob01 	= $00168
Mmsk01 	= $00318
Mbob02 	= $00384
Mmsk02 	= $00564
Mbob03 	= $005dc
Mmsk03 	= $007dc
Mbob04 	= $0085c
Mmsk04 	= $00a5c
Mbob05 	= $00adc
Mmsk05 	= $00cdc
Mbob06 	= $00d5c
Mmsk06 	= $00f4c
Mbob07 	= $00fc8
Mmsk07 	= $01178
Mbob08 	= $011e4
Mmsk08 	= $01364
Mbob09 	= $013c4
Mmsk09 	= $014c4
Mbob0a 	= $01504
Mmsk0a 	= $01574
Mbob0b 	= $01590
Mmsk0b 	= $015c8
Mbob0c 	= $015d6
Mmsk0c 	= $01636
Mbob0d 	= $0164e
Mmsk0d 	= $016be
Mbob0e 	= $016da
Mmsk0e 	= $0174a
Mbob0f 	= $01766
Mmsk0f 	= $017d6
Mbob10 	= $017f2
Mmsk10 	= $0185a
Mbob11 	= $01874
Mmsk11 	= $018dc
Mbob12 	= $018f6
Mmsk12 	= $0195e
Mbob13 	= $01978
Mmsk13 	= $019e0
Mbob14 	= $019fa
Mmsk14 	= $01a5a
Mbob15 	= $01a72
Mmsk15 	= $01ada
Mbob16 	= $01af4
Mmsk16 	= $01b54
Mbob17 	= $01b6c
Mmsk17 	= $01ba4
Mbob18 	= $01bb2
Mmsk18 	= $01c1a
Mbob19 	= $01c34
Mmsk19 	= $01ca4
Mbob1a 	= $01cc0
Mmsk1a 	= $01d28
Mbob1b 	= $01d42
Mmsk1b 	= $01dba
Mbob1c 	= $01dd8
Mmsk1c 	= $01e50
Mbob1d 	= $01e6e
Mmsk1d 	= $01eee
Mbob1e 	= $01f0e
Mmsk1e 	= $01f8e
Mbob1f 	= $01fae
Mmsk1f 	= $0202e
Mbob20 	= $0204e
Mmsk20 	= $021ce
Mbob21 	= $0222e
Mmsk21 	= $0235e
Mbob22 	= $023aa
Mmsk22 	= $0248a
Mbob23 	= $024c2
Mmsk23 	= $02542
Mbob24 	= $02562
Mmsk24 	= $025e2
Mbob25 	= $02602
Mmsk25 	= $0267a
Mbob26 	= $02698
Mmsk26 	= $02718
Mbob27 	= $02738
Mmsk27 	= $02808
Mbob28 	= $0283c
Mmsk28 	= $0293c
Mbob29 	= $0297c
Mmsk29 	= $029fc
Mbob2a 	= $02a1c
Mmsk2a 	= $02a9c
Mbob2b 	= $02abc
Mmsk2b 	= $02b3c

main_flipI:	dc.w	Mbob18,13*5,16/8
		dc.w	Mbob19,14*5,16/8
		dc.w	Mbob1a,13*5,16/8
		dc.w	Mbob1b,15*5,16/8
		dc.w	Mbob1c,15*5,16/8
		dc.w	-1

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

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Start_Explo:
	moveq	#1,d0
	move.w	Bob_X_Position(a4),d1
	move.w	Bob_Y_Position(a4),d2
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.out
	move.b	#BOB_NOCOL,Bob_Used(a4)
.out:
	rts
Start_Explo2:
	moveq	#1,d0
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.out
	move.b	#BOB_NOCOL,Bob_Used(a4)
.out:
	rts

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

;--------------------------------------------------------------------------
;-------------                   SCROLLING            ---------------------
;--------------------------------------------------------------------------
		rsreset
Scr_Y_Max		rs.w	1		;maximale Hhe des Levels in Zeilen
Scr_Y_Level_Pos		rs.w	1		;aktuelle Y-Position im Level in Zeilen
Scr_Y_Level_Pos_Old	rs.w	1		;aktuelle Y-Position im Level in Zeilen
Scr_Y_Play_Anf		rs.w	1		;Offset auf Playfield-Zeile, die am oberen Bildschirmrand sichtbar ist
Scr_Y_Up_Supply		rs.w	1		;Offset fr unteren Nachschub
Scr_Y_Down_Supply	rs.w	1		;Offset fr oberen Nachschub
Scr_X_Max		rs.w	1		;maximale Breite des Levels in Pixels
Scr_X_Level_Pos		rs.w	1		;aktuelle X-Position im Level in Pixels
Scr_X_Level_Pos_Old	rs.w	1		;aktuelle X-Position im Level in Pixels
Scr_X_Visible		rs.w	1		;maximale Breite des sichtbaren Bereiches
Scr_Y_Visible		rs.w	1		;maximale Hhe des sichtbaren Bereiches
Scr_Plane_Height	rs.w	1		;Hhe der Plane in Zeilen
Scr_Plane_Width		rs.w	1		;Breite einer Zeile des Playfields
Scr_Single_Plane	rs.w	1		;Breite einer Plane Zeile
Scr_X_Speed		rs.l	1		;Geschwindigkeit des X-Scrollings (- = links)
Scr_Y_Speed		rs.l	1		;Geschwindigkeit des Y-Scrollings
Scr_Show_Field		rs.l	1		;Adresse auf aktuelles Playfield
Scr_Supply_Field	rs.l	1		;Adresse auf Supply-Playfield
Scr_Refresh_Field	rs.l	1		;Adresse auf Refresh-Field
Scr_Level_Pointer	rs.l	1		;Adresse auf LevelMap
Scr_Level_Width		rs.w	1		;Breite des Level in Bytes

Scr_Blt_Mask		rs.l	1		;Blittermasken
Scr_Blt_Con_0		rs.w	1		;bltcon0
Scr_Bob_Con_0		rs.w	1		;bltcon0
Scr_Bob_A_Modulo	rs.w	1		;Bob bltamod
Scr_Blt_A_Modulo	rs.w	1		;bltamod
Scr_Blt_D_Modulo	rs.w	1		;bltdmod
Scr_Blt_Blit_Size	rs.w	1		;bltsize
Scr_Blt_Len		rs.w	1		;Lnge eines Modules in Bytes
Scr_Blt_A_Flip_Mod	rs.w	1		;Flip bltamod
Scr_Blt_D_Flip_Mod	rs.w	1		;Flip bltdmod
Scr_Blt_Flip_Size	rs.w	1		;Flip BlitSize
Scr_Blt_Flip_Add	rs.w	1		;Flip Jump End of Block

Scr_Rout_X		rs.l	1		;Adr der Routine fr linken oder rechten teilweisen Nachschub
Scr_Rout_Y		rs.l	1		;Adr der Routine fr oberen oder unteren teilweisen Nachschub
Scr_AnzSupplyPlates	rs.w	1		;XAnzahl der Blcke, die pro Rasterdurchlauf Nachgeschoben werden
Scr_SupplyFirst_Flg	rs.w	1		;siehe unten
Scr_Register_X		rs.l	6		;Buffer um Register zu speichern
Scr_Register_Y		rs.l	5		;Buffer um Register zu speichern
Scr_X_Supply_Plates	rs.w	1		;Anzahl der SupplyPlaettchen in X Dir
Scr_Y_Supply_Plates	rs.w	1		;Anzahl der SupplyPlaettchen in Y Dir
Scr_X_Supply_Offs	rs.w	1		;Supply am rechten Rand
Scr_X_Supply_Sub	rs.l	1		;Subtrahierwert auf d5 bei X Supply
Scr_X_Supply_Add	rs.l	1		;Addierwert auf d5 bei X Supply

		;BE=Bob BackgroundAnimation
Scr_BA_Area_Vector	rs.l	1		;Pointer auf zweidimensionales Array fr Bobs
Scr_BA_Byte_Vector	rs.l	1		;Pointer auf Array fr Bytes 1 eingetragen 0 nicht eingetragen
Scr_BA_Area_Width	rs.w	1		;Breite eines Array
Scr_BA_Area_Height	rs.w	1		;Hhe eines Array
Scr_BA_Shift_X		rs.w	1		;Durch wieviel wird Level_X_Pos geteilt
Scr_BA_Shift_Y		rs.w	1		;Durch wieviel wird Level_Y_Pos geteilt
Scr_BA_Add_Border_X	rs.w	1		;Wert um auf rechten Rand des Areas bezogen auf den Screen zu kommen
Scr_BA_Add_Border_Y	rs.w	1		;Wert um auf unteren Rand usw.
Scr_BA_Count_Clr_X	rs.w	1		;LoopCounter Wert fr alte Werte Lschen
Scr_BA_Count_Set_X	rs.w	1		;LoopCounter Wert fr neue Werte Setzen
Scr_BA_Count_Clr_Y	rs.w	1		;LoopCounter Wert fr alte Werte Lschen
Scr_BA_Count_Set_Y	rs.w	1		;LoopCounter Wert fr neue Werte Setzen
Scr_BA_Anz_Area_X	rs.w	1		;Anzahl der Areas in X Richtung
Scr_Scrolled_X		rs.w	1		;Tatschlich gescrollt X
Scr_Scrolled_Y		rs.w	1		;Tatschlich gescrollt Y
Scr_Screen_num		rs.w	1		;Screen-nr (0/-1)
Scr_Blt_Adr1		rs.l	1		;Hier ist die l.o. Ecke.
Scr_Blt_Adr2		rs.l	1		;Hier ist die Wrapzeile.
Scr_Up_Fix		rs.w	1
Scr_Down_Fix		rs.w	1
Scr_Left_Fix		rs.w	1
Scr_Right_Fix		rs.w	1
Scr_X_Fix		rs.w	1
Scr_Y_Fix		rs.w	1
Scr_Level		rs.l	1
Scr_Supply_Rout		rs.l	1
Scr_Character		rs.l	1
Scr_Y_Force		rs.w	1
Scr_BigCPU		rs.b	1
Scr_Flicker		rs.b	1
Scr_No_Flicker		rs.b	1
			rs.b	1

SCR_ENTRY_LENGTH	rs.w	0

Scr_Structure:
	dc.w	0			;Scr_Y_Max
	dc.w	32			;Scr_Y_Level_Pos
	dc.w	0			;Scr_Y_Level_Pos_Old
	dc.w	32			;Scr_Y_Play_Anf
	dc.w	208+16			;Scr_Y_Up_Supply
	dc.w	208+32			;Scr_Y_Down_Supply
	dc.w	0			;Scr_X_Max
	dc.w	16			;Scr_X_Level_Pos
	dc.w	16			;Scr_X_Level_Pos_Old
	dc.w	336			;Scr_X_Visible
	dc.w	208			;Scr_Y_Visible
	dc.w	208+48			;Scr_Plane_Height
	dc.w	planeb*4		;Scr_Plane_Width
	dc.w	planeb			;Single_Plane
	dc.l	0			;Scr_X_Speed
	dc.l	0			;Scr_Y_Speed

	dc.l	GameBpl1		;Scr_Show_Field
	dc.l	GameBpl0		;Scr_Supply_Field
	dc.l	GameBpl2		;Scr_Refresh_Field

	dc.l	0			;Scr_Level_Pointer
	dc.w	0			;Breite des Level in Bytes

	dc.l	-1			;Blittermasken
	dc.w	%0000100111110000	;bltcon0
	dc.w	%0000111111000010	;bltcon0 fr BobBlttchen
	dc.w	32-2			;Bob bltamod
	dc.w	0			;bltamod (Font mod)
	dc.w	planeb-2		;bltdmod
	dc.w	(4*16*64)+1		;bltsize
	dc.w	128			;Len
	dc.w	-(2+3*40)		;Flip bltamod
	dc.w	planeb*3-1*2		;Flip bltdmod
	dc.w	16*64+1			;Flip BlitSize
	dc.w	40*3*16-40*3		;Flip Jump End of Block

	dc.l	RoutRts			;Adr der Routine fr linken oder rechten teilweisen Nachschub
	dc.l	RoutRts			;Adr der Routine fr oberen oder unteren teilweisen Nachschub
	dc.w	(16+22)/2+1		;X Anzahl der Blcke, die pro Rasterdurchlauf Nachgeschoben werden
	dc.w	0			;Flag, 0-X als letztes eing. 1-Y als letztes eing. 
	ds.l	6			;Buffer um Register zu speichern
	ds.l	5			;Buffer um Register zu speichern
	dc.w	16			;Anzahl der SupplyPlaettchen in X Dir
	dc.w	22			;Anzahl der SupplyPlaettchen in Y Dir
	dc.w	20*2			;Supply am rechten Rand
	dc.l	(208+48)*planeb*4	;Subtrahierwert auf DestAdr. bei Supply am rechten Rand
	dc.l	16*planeb*4		;Addierwert auf DestAdr. bei Supply am rechten Rand

	dc.l	Area_Vector		;Scr_Bob_Area_Vector
	dc.l	Area_Enter_Vector	;Scr_Bob_Area_Enter_Vector
	dc.w	64			;Scr_BA_Area_Width
	dc.w	64			;Scr_BA_Area_Height
	dc.w	6			;Scr_BA_Shift_X
	dc.w	6			;Scr_BA_Shift_Y
	dc.w	320/64			;Scr_BA_Add_Border_X
	dc.w	208/64+1		;Scr_BA_Add_Border_Y
	dc.w	208/64+1+2-1		;Scr_BA_Count_Clr_X
	dc.w	208/64+1		;Scr_BA_Count_Set_X
	dc.w	320/64+2-1		;Scr_BA_Count_Clr_Y
	dc.w	320/64			;Scr_BA_Count_Set_Y
	dc.w	46			;Scr_BA_Anz_Area_X

	dc.w	0			;Tatschliche Scrollweite X
	dc.w	0			;Tatschliche Scrollweite Y

	dc.w	0			;Scr_Screen_num
	dc.l	0			;Scr_Blt_Adr
	dc.l	0			;Scr_Blt_Adr

	dc.w	0			;Scr_Up_Fix
	dc.w	0			;Scr_Down_Fix

	dc.w	0			;Scr_Left_Fix
	dc.w	0			;Scr_Right_Fix

	dc.w	0			;Scr_X_Fix
	dc.w	0			;Scr_Y_Fix

	dc.l	0

	dc.l	SupplyX			;Scr_Supply_Rout

	dc.l	0

	dc.w	0			;Y-Scroll-Force

	dc.b	0			;BigCPU
	dc.b	0
	dc.b	0			;No Flicker
	dc.b	0

Act_Scr_Structure:	dc.l	Scr_Structure
X_KOLLBIT		=	14
Y_KOLLBIT		=	12

	even

;--------------------------------------------------------------------------
Scroll:
	move.l	Act_Scr_Structure,a6

	move.w	Scr_X_Speed(a6),d0
	bpl	.norm1
	neg.w	d0
.norm1:
	move.w	Scr_Y_Speed(a6),d1
	bpl	.norm2
	neg.w	d1
.norm2:
	add.w	d0,d0
	add.w	d1,d1

	clr.w	Scr_Scrolled_Y(a6)
	clr.w	Scr_Scrolled_X(a6)

	move.w	Scr_Y_Level_Pos(a6),Scr_Y_Level_Pos_Old(a6)
	move.w	Scr_X_Level_Pos(a6),Scr_X_Level_Pos_Old(a6)


	move.w	Scr_Y_Speed(a6),d7
	tst.b	d7					;Runter gedrueckt
	bmi.s	.nru
	beq.s	.nru
	move	Scr_Y_Level_Pos(a6),d1
	jsr	ScrUp
	move	Scr_Y_Level_Pos(a6),d2
	and	#%1111111111110000,d1
	and	#%1111111111110000,d2
	cmp	d1,d2
	beq.s	.nru
	jsr	SupplyUp

.nru:
	tst.b	d7
	bpl.s	.nho
	move	Scr_Y_Level_Pos(a6),d1
	jsr	ScrDown
	move	Scr_Y_Level_Pos(a6),d2
	and	#%1111111111110000,d1
	and	#%1111111111110000,d2
	cmp	d1,d2
	beq.s	.nho
	jsr	SupplyDown

.nho:
	move.w	Scr_X_Speed(a6),d7
	tst.b	d7
	bmi.s	.nre
	beq.s	.nre
	move	Scr_X_Level_Pos(a6),d1
	jsr	ScrLeft
	move	Scr_X_Level_Pos(a6),d2
	and	#%1111111111110000,d1
	and	#%1111111111110000,d2
	cmp	d1,d2
	beq.s	.nre
	jsr	SupplyLeft

.nre:
	tst.w	d7
	bpl.s	.nli
	move	Scr_X_Level_Pos(a6),d1
	jsr	ScrRight
	move	Scr_X_Level_Pos(a6),d2
	and	#%1111111111110000,d1
	and	#%1111111111110000,d2
	cmp	d1,d2
	beq.s	.nli
	jsr	SupplyRight

.nli:
						;Supply in der richtigen Reihenfolge bearbeiten
	tst	Scr_SupplyFirst_Flg(a6)
	beq.s	.X_Last

						;Y zuletzt eingetragen
	move.w	Scr_AnzSupplyPlates(a6),d4
	move.l	Scr_Rout_X(a6),a0
	jsr	(a0)
	tst	d4
	beq.s	.NoPlatesLeft

	move.l	Scr_Rout_Y(a6),a0
	jsr	(a0)
	bra.s	.NoPlatesLeft

						;X zuletzt eingetragen
.X_Last:
	move.w	Scr_AnzSupplyPlates(a6),d4
	move.l	Scr_Rout_Y(a6),a0
	jsr	(a0)
	tst	d4
	beq.s	.NoPlatesLeft
	move.l	Scr_Rout_X(a6),a0
	jsr	(a0)

.NoPlatesLeft:
	clr.l	Scr_Up_Fix(a6)
	clr.l	Scr_Left_Fix(a6)
	rts

;--------------------------------------------------------------------------
ScrDown:
	move.w	Scr_Y_Speed(a6),d0		;Ist negativ.
	neg.w	d0
	moveq	#32,d3
	add.w	d0,d3
	cmp.w	Scr_Y_Level_Pos(a6),d3
	bls.s	.ok
	move.w	Scr_Y_Level_Pos(a6),d0
	sub.w	#32,d0
.ok:
	move.w	Scr_Up_Fix(a6),d3
	beq.s	.no_fix
	add.w	d0,d3
	cmp.w	Scr_Y_Level_Pos(a6),d3
	bls.s	.no_fix
	move.w	Scr_Y_Level_Pos(a6),d0
	sub.w	Scr_Up_Fix(a6),d0
.no_fix:
	sub.w	d0,Scr_Y_Level_Pos(a6)
	move.w	Scr_Y_Play_Anf(a6),d3
	sub.w	d0,d3
	bpl.s	.nop
	add.w	Scr_Plane_Height(a6),d3
.nop:
	move.w	d3,Scr_Y_Play_Anf(a6)
	neg.w	d0
	move.w	d0,Scr_Scrolled_Y(a6)
	rts
;--------------------------------------------------------------------------
ScrUp:
	move.w	Scr_Y_Max(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d0
	cmp.w	Scr_Y_Speed(a6),d0
	bls.s	.ok
	move.w	Scr_Y_Speed(a6),d0		;Ist positiv.
.ok:
	tst.w	Scr_Down_Fix(a6)
	beq.s	.no_fix
	move.w	Scr_Y_Level_Pos(a6),d3
	add.w	d0,d3
	cmp.w	Scr_Down_Fix(a6),d3
	bls.s	.no_fix
	move.w	Scr_Down_Fix(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d0
.no_fix:

	add.w	d0,Scr_Y_Level_Pos(a6)
	move.w	Scr_Y_Play_Anf(a6),d3
	add.w	d0,d3
	cmp.w	Scr_Plane_Height(a6),d3
	blo.s	.nop
	sub.w	Scr_Plane_Height(a6),d3
.nop:
	move.w	d3,Scr_Y_Play_Anf(a6)
	move.w	d0,Scr_Scrolled_Y(a6)
	rts
;--------------------------------------------------------------------------
ScrRight:
	move.w	Scr_X_Speed(a6),d0		;Ist negativ.
	neg.w	d0
	moveq	#16,d3
	add.w	d0,d3
	cmp.w	Scr_X_Level_Pos(a6),d3
	bls	.ok
	move.w	Scr_X_Level_Pos(a6),d0
	sub.w	#16,d0
.ok:
	move.w	Scr_Left_Fix(a6),d3
	beq.s	.no_fix
	add.w	d0,d3
	cmp.w	Scr_X_Level_Pos(a6),d3
	bls.s	.no_fix
	move.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Left_Fix(a6),d0
.no_fix:

	sub	d0,Scr_X_Level_Pos(a6)
	neg.w	d0
	move.w	d0,Scr_Scrolled_X(a6)
	rts
;--------------------------------------------------------------------------
ScrLeft:
	move.w	Scr_X_Max(a6),d0
	sub.w	Scr_X_Level_Pos(a6),d0
	cmp.w	Scr_X_Speed(a6),d0
	bls.s	.ok
	move.w	Scr_X_Speed(a6),d0
.ok:
	tst.w	Scr_Right_Fix(a6)
	beq.s	.no_fix
	move.w	Scr_X_Level_Pos(a6),d3
	add.w	d0,d3
	cmp.w	Scr_Right_Fix(a6),d3
	bls.s	.no_fix
	move.w	Scr_Right_Fix(a6),d0
	sub.w	Scr_X_Level_Pos(a6),d0
.no_fix:

	add.w	d0,Scr_X_Level_Pos(a6)
	move.w	d0,Scr_Scrolled_X(a6)
	rts
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
SupplyDown:
	moveq	#0,d0
	move	Scr_Y_Level_Pos(a6),d0
	lsr	#4,d0
	subq	#2,d0
	mulu	Scr_Level_Width(a6),d0
	move	Scr_X_Level_Pos(a6),d1
	lsr	#4,d1
	add	d1,d0
	subq	#1,d0
	move.l	Scr_Level_Pointer(a6),a1
	add.l	d0,a1

	move	Scr_Y_Play_Anf(a6),d0
	add	Scr_Y_Down_Supply(a6),d0
	cmp	Scr_Plane_Height(a6),d0
	blo.s	.ok
	sub	Scr_Plane_Height(a6),d0
.ok:
	and	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	moveq	#0,d1
	move	Scr_X_Level_Pos(a6),d1
	lsr	#3,d1
	and	#%1111111111111110,d1
	add.l	d1,d0
	subq.l	#2,d0

	move.l	Scr_Show_Field(a6),a2
	move.l	Scr_Supply_Field(a6),a3
	move.l	Scr_Refresh_Field(a6),d3
	add.l	d0,a2
	add.l	d0,a3
	add.l	d0,d3

	move.l	#SupplyY,Scr_Rout_Y(a6)
	move	Scr_Y_Supply_Plates(a6),d6
	move.l	a6,a4
	add	#Scr_Register_Y+5*4,a4
	movem.l	d3/d6/a1-a3,-(a4)
	move	#1,Scr_SupplyFirst_Flg(a6)

	rts
;--------------------------------------------------------------------------
SupplyUp:
	moveq	#0,d0
	moveq	#0,d1
	move	Scr_Y_Level_Pos(a6),d0
	lsr	#4,d0
	move	Scr_Y_Up_Supply(a6),d1
	lsr	#4,d1
	add	d1,d0
	subq.w	#1,d0
	mulu	Scr_Level_Width(a6),d0
	move	Scr_X_Level_Pos(a6),d1
	lsr	#4,d1
	subq	#1,d1
	move.l	Scr_Level_Pointer(a6),a1
	add.l	d0,a1
	add.l	d1,a1

	move	Scr_Y_Play_Anf(a6),d0
	add	Scr_Y_Up_Supply(a6),d0
	cmp	Scr_Plane_Height(a6),d0
	blo.s	.ok
	sub	Scr_Plane_Height(a6),d0
.ok:
	and	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	moveq	#0,d1
	move	Scr_X_Level_Pos(a6),d1
	lsr	#3,d1
	and	#%1111111111111110,d1
	add.l	d1,d0
	subq.l	#2,d0

	move.l	Scr_Show_Field(a6),a2
	move.l	Scr_Supply_Field(a6),a3
	move.l	Scr_Refresh_Field(a6),d3
	add.l	d0,a2
	add.l	d0,a3
	add.l	d0,d3

	move.l	#SupplyY,Scr_Rout_Y(a6)
	move	Scr_Y_Supply_Plates(a6),d6
	move.l	a6,a4
	add	#Scr_Register_Y+5*4,a4
	movem.l	d3/d6/a1-a3,-(a4)
	move	#1,Scr_SupplyFirst_Flg(a6)

	rts

;--------------------------------------------------------------------------
SupplyRight:
	moveq	#0,d0
	moveq	#0,d1
	move	Scr_Y_Level_Pos(a6),d0
	lsr	#4,d0
	subq	#2,d0
	muls	Scr_Level_Width(a6),d0
	move	Scr_X_Level_Pos(a6),d1
	lsr	#4,d1
	subq	#1,d1
	move.l	Scr_Level_Pointer(a6),a1
	add.l	d0,a1
	add.l	d1,a1

	move	Scr_Y_Play_Anf(a6),d0
	add	Scr_Y_Down_Supply(a6),d0
	cmp	Scr_Plane_Height(a6),d0
	blo.s	.ok
	sub	Scr_Plane_Height(a6),d0
.ok:
	and	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	moveq	#0,d1
	move	Scr_X_Level_Pos(a6),d1
	lsr	#3,d1
	and	#%1111111111111110,d1
	add.l	d1,d0
	subq.l	#2,d0

	move.l	Scr_Show_Field(a6),a2
	move.l	Scr_Supply_Field(a6),a3
	move.l	Scr_Refresh_Field(a6),d3
	add.l	d0,a2
	add.l	d0,a3
	add.l	d0,d3

	move.l	Scr_Supply_Rout(a6),Scr_Rout_X(a6)
	move.l	a6,a4
	add	#Scr_Register_X+6*4,a4
	move	Scr_X_Supply_Plates(a6),d6

	move	Scr_Y_Play_Anf(a6),d5
	add	Scr_Y_Down_Supply(a6),d5
	cmp	Scr_Plane_Height(a6),d5
	blo.s	.ok1
	sub	Scr_Plane_Height(a6),d5
.ok1:
	and	#%1111111111110000,d5
	movem.l	d3/d5-d6/a1-a3,-(a4)
	move	#0,Scr_SupplyFirst_Flg(a6)

	rts
;--------------------------------------------------------------------------
SupplyLeft:
	moveq	#0,d0
	moveq	#0,d1
	move	Scr_Y_Level_Pos(a6),d0
	lsr	#4,d0
	subq	#2,d0
	muls	Scr_Level_Width(a6),d0
	move	Scr_X_Level_Pos(a6),d1
	lsr	#4,d1
	move.l	Scr_Level_Pointer(a6),a1
	add.l	d0,a1
	move.w	Scr_X_Supply_Offs(a6),d0
	asr.w	#1,d0
	add.w	d0,a1
	add.l	d1,a1

	move	Scr_Y_Play_Anf(a6),d0
	add	Scr_Y_Down_Supply(a6),d0
	cmp	Scr_Plane_Height(a6),d0
	blo.s	.ok
	sub	Scr_Plane_Height(a6),d0
.ok:
	and	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	move.l	Scr_Show_Field(a6),a2
	move.l	Scr_Supply_Field(a6),a3
	move.l	Scr_Refresh_Field(a6),d3
	moveq	#0,d1
	move	Scr_X_Level_Pos(a6),d1
	lsr	#3,d1
	and	#%1111111111111110,d1
	add.l	d1,d0
	move	Scr_X_Supply_Offs(a6),d1
	add.l	d1,d0
	add.l	d0,a2
	add.l	d0,a3
	add.l	d0,d3

	move.l	Scr_Supply_Rout(a6),Scr_Rout_X(a6)
	move.l	a6,a4
	add	#Scr_Register_X+6*4,a4
	move	Scr_X_Supply_Plates(a6),d6
	move	Scr_Y_Play_Anf(a6),d5
	add	Scr_Y_Down_Supply(a6),d5
	cmp	Scr_Plane_Height(a6),d5
	blo.s	.ok1
	sub	Scr_Plane_Height(a6),d5
.ok1:
	and	#%1111111111110000,d5
	movem.l	d3/d5-d6/a1-a3,-(a4)
	move	#0,Scr_SupplyFirst_Flg(a6)
	rts

;--------------------------------------------------------------------------
SupplyY:
	lea	$dff000,a5
	waitblt
	move.l	Scr_Blt_Mask(a6),bltafwm(a5)
	move	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	move	Scr_Blt_Con_0(a6),bltcon0(a5)
	move	#0,bltcon1(a5)

	move.l	a6,a4  
	add	#Scr_Register_Y,a4
	movem.l	(a4)+,d3/d6/a1-a3

.loop:
	moveq	#0,d0
	move.b	(a1),d0
	add.w	d0,d0
	move.l	Macro_Pointer(pc),a0
	moveq	#0,d1
	move.b	(a0,d0.w),d1
	mulu	Scr_Blt_Len(a6),d1	;Modul-adresse berechnen (fr 4Planes)
	move.l	Scr_Character(a6),a0
	lea	(a0,d1.w),a0
							;Test if there is a flip Block
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
	move.w	Scr_Blt_Blit_Size(a6),bltsize(a5)	;Screen1
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
	move.w	Scr_Blt_Blit_Size(a6),bltsize(a5)	;Screen2
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
	move.w	Scr_Blt_Blit_Size(a6),bltsize(a5)	;Screen3

.Add_Pointers:
	addq.l	#1,a1
	addq	#2,a2
	addq	#2,a3
	addq.l	#2,d3

	subq	#1,d6
	beq.s	.Finish
	subq	#1,d4
	bne	.loop

	movem.l	d3/d6/a1-a3,-(a4)
	rts

.Finish:
	subq	#1,d4
	move.l	#RoutRts,Scr_Rout_Y(a6)
	rts
;--------------------------------------------------------------------------
SupplyX:
	lea	$dff000,a5
	waitblt
	move.l	Scr_Blt_Mask(a6),bltafwm(a5)
	move	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	move	Scr_Blt_Con_0(a6),bltcon0(a5)
	clr.w	bltcon1(a5)

	move.l	a6,a4
	add	#Scr_Register_X,a4
	movem.l	(a4)+,d3/d5-d6/a1-a3

.loop:
	moveq	#0,d0
	move.b	(a1),d0
	add.w	d0,d0
	move.l	Macro_Pointer(pc),a0
	moveq	#0,d1
	move.b	(a0,d0.w),d1

	mulu	Scr_Blt_Len(a6),d1	;Modul-adresse berechnen
	move.l	Scr_Character(a6),a0

	lea	(a0,d1.w),a0
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)
	move	Scr_Blt_Blit_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	a3,bltdpth(a5)
	move	Scr_Blt_Blit_Size(a6),bltsize(a5)
	waitblt
	move.l	a0,bltapth(a5)
	move.l	d3,bltdpth(a5)
	move	Scr_Blt_Blit_Size(a6),bltsize(a5)

.Add_Pointers:
	moveq	#0,d0
	move	Scr_Level_Width(a6),d0
	add.l	d0,a1
	add	#16,d5
	cmp	Scr_Plane_Height(a6),d5
	blo.s	.ok
	sub	Scr_Plane_Height(a6),d5
	sub.l	Scr_X_Supply_Sub(a6),a2
	sub.l	Scr_X_Supply_Sub(a6),a3
	sub.l	Scr_X_Supply_Sub(a6),d3
.ok	add.l	Scr_X_Supply_Add(a6),a2
	add.l	Scr_X_Supply_Add(a6),a3
	add.l	Scr_X_Supply_Add(a6),d3

	subq	#1,d6
	beq.s	.Finish
	subq	#1,d4
	bne	.loop

	movem.l	d3/d5-d6/a1-a3,-(a4)
	rts

.Finish:
	subq	#1,d4
	move.l	#RoutRts,Scr_Rout_X(a6)
	rts

Macro_Pointer:	dc.l	0

Set_Char:
	and.w	#255,d2

	add.w	d2,d2
	move.l	Macro_Pointer(pc),a0
	move.b	(a0,d2.w),d2
	and.w	#$ff,d2
	mulu	Scr_Blt_Len(a6),d2	;Modul-adresse berechnen (fr 4Planes)
	add.l	Scr_Character(a6),d2

Set_Char_In:

	move.w	Scr_X_Level_Pos(a6),d3
	sub.w	d3,d0
	cmp.w	#-16,d0
	blt	.out
	cmp.w	#320,d0
	bgt	.out

	sub.w	Scr_Y_Level_Pos(a6),d1
	cmp.w	#-16,d1
	blt.s	.out
	cmp.w	#208+16,d1
	bgt.s	.out

	and.w	#15,d3
	add.w	d3,d0

	tst.w	d1
	bpl.s	.no_upper_check

	cmp.w	#16,Scr_Y_Play_Anf(a6)
	bge.s	.no_upper_check
	and.w	#255,d1

.no_upper_check:
	move.w	Scr_Plane_Height(a6),d3
	sub.w	Scr_Y_Play_Anf(a6),d3
	cmp.w	d3,d1
	bge.s	.under_wrap


	;ber der Wrap-Zeile.

	move.l	Scr_Blt_Adr1(a6),d4
	bra.s	.goon
.under_wrap:
	move.l	Scr_Blt_Adr2(a6),d4
	sub.w	d3,d1
.goon:
	mulu	Scr_Plane_Width(a6),d1
	add.l	d1,d4

	asr.w	#3,d0
	and.w	#$fffe,d0
	ext.l	d0
	add.l	d0,d4
	add.l	Scr_Refresh_Field(a6),d4

	move.l	d2,bltapth(a5)
	move.l	d4,bltdpth(a5)
	move.w	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	move.w	#$0000,bltamod(a5)
	move.w	#$09f0,bltcon0(a5)
	move.l	#-1,bltafwm(a5)
	move.w	#64*16*4+1,bltsize(a5)
	waitblt
.out:
	rts

Check_shoot:
	movem.w	d1-d2,-(sp)
	sub.w	Scr_X_Level_Pos(a6),d1
	bmi.s	.no
	cmp.w	#304,d1
	bge.s	.no

	sub.w	Scr_Y_Level_Pos(a6),d2
	bmi.s	.no
	cmp.w	#224,d2
	bge.s	.no
	movem.w	(sp)+,d1-d2
	rts
.no:
	move.w	#0,d1
	movem.w	(sp)+,d1-d2
	rts

	;Eingabe-Parameter :
	;d0 = 1	Bob hat sich verndert, aus dem Background lschen.
	;d0 = 0 Bob hat sich nicht verndert, in den Background kopieren, wenn ntig.
	;d6 = Maximal-Hhe des Bobs.

Use_Background:
	tst.b	Plane_flag
	beq	.out

	move.w	d6,help
	tst.w	d0
	bne	.clear_from_BG

	;Check, ob sich der COLOUR status gendert hat.

	cmp.w	#COLOUR,Bob_Race(a4)
	bne.s	.check_off
	bset	#3,Bob_Status(a4)
	beq	.clear_from_BG
	bra.s	.check_ok
.check_off:
	bclr	#3,Bob_Status(a4)
	bne	.clear_from_BG
.check_ok:
	;Feststellen, ob das Bob an den Rand stsst.
	move.w	Bob_X_Position(a4),d0
	sub.w	Scr_X_Level_Pos(a6),d0
	bmi	.clear_from_BG
	move.w	Bob_to_Info_Offs(a4),d7
	add.w	Bob_I_Width(a4,d7.w),d0
	cmp.w	#304,d0
	bge	.clear_from_BG

	move.w	Bob_Y_Position(a4),d0
	sub.w	Scr_Y_Level_Pos(a6),d0
	bmi	.clear_from_BG
	add.w	Bob_Height(a4),d0
	cmp.w	#208,d0
	bge	.clear_from_BG

	bset	#2,Bob_Status(a4)
	beq	.out

	bset	#BOB_URGENT,Bob_BlitStatus(a4)	;Wurde das Bob im letzten Frame schon geblittet ?
	beq	.out				;Mglicherweise noch nicht!

	;Das Bob muss in den Hintergrund kopiert werden!
	bset	#0,Bob_Status(a4)
	bne	.already_there

	movem.w	Bob_X_Position(a4),d0-d1
	add.w	Bob_X_Offset(a4),d0
	add.w	Bob_Y_Offset(a4),d1

	bsr	Calc_Adress			;1.Blitadresse berechnet!


	move.w	Bob_Y_Position(a4),d1
	add.w	Bob_Y_Offset(a4),d1
	sub.w	Scr_Y_Level_Pos(a6),d1

	move.w	Scr_Plane_Height(a6),d3
	sub.w	Scr_Y_Play_Anf(a6),d3
	cmp.w	d3,d1
	bge.s	.no_wrap
	add.w	Bob_Height(a4),d1
	cmp.w	d3,d1
	blt.s	.no_wrap

	bclr	#0,Bob_Status(a4)		;Wir sind IN der Wrap-Zeile,
	rts					;Nix blitten. (Einfach aus der Affre gezogen!)

.no_wrap:
	add.l	Scr_Refresh_Field(a6),d4
	waitblt
	move.l	Bob_Graphics(a4),d2
	move.l	Bob_Mask(a4),d3
	move.w	Bob_to_Info_Offs(a4),d7
	move.l	Bob_I_AFWM(a4,d7.w),bltafwm(a5)

	move.w	Bob_X_Position(a4),d0
	add.w	Bob_X_Offset(a4),d0

	and.w	#15,d0
	ror.w	#4,d0
	move.w	d0,bltcon1(a5)
	or.w	#$0fca,d0
	move.w	d0,bltcon0(a5)

	moveq	#0,d1
	move.w	Bob_I_Bytes(a4,d7.w),d1
	move.w	Bob_I_A_Modulo(a4,d7.w),d0
	sub.w	d1,d0
	move.w	d0,bltamod(a5)
	move.w	Bob_I_B_Modulo(a4,d7.w),d0
	sub.w	d1,d0
	move.w	d0,bltbmod(a5)
	move.w	Bob_I_D_Modulo(a4,d7.w),d0
	sub.w	d1,d0
	move.w	d0,bltcmod(a5)
	move.w	d0,bltdmod(a5)

	move.w	Bob_Height(a4),d0
	asl.w	#6,d0
	add.w	Bob_I_Words(a4,d7.w),d0

	move.w	Bob_I_Mask_Width(a4,d7.w),d1
	move.w	Bob_I_Depth(a4,d7.w),d7
	subq.w	#1,d7
.blitloop:
	move.l	d4,bltdpth(a5)
	move.l	d4,bltcpth(a5)

	move.l	d2,bltbpth(a5)
	move.l	d3,bltapth(a5)

	move.w	d0,bltsize(a5)


	add.l	#planeb,d4
	add.l	d1,d2

	waitblt
	dbf	d7,.blitloop


	bset	#1,Bob_Status(a4)	;Bob nur noch 1 Frame lang blitten!
	bset	#BOB_URGENT,Bob_BlitStatus(a4)	;Bob AUF JEDEN FALL BLITTEN!!!!!

	rts

.already_there:
	bclr	#1,Bob_Status(a4)
	beq	.out
	move.b	#1<<NO_BOBBLIT,Bob_BlitStatus(a4)

	rts

.clear_from_BG:
	bclr	#2,Bob_Status(a4)
	bclr	#0,Bob_Status(a4)
	beq	.out			;Bob ist schon gelscht.

	;Bob aus dem Hintergrund lschen. (Alte Character wiederherstellen!)

	move.w	Bob_to_Info_Offs(a4),d7

	movem.w	Bob_X_Position(a4),d0-d1
	and.w	#$fff0,d0
	and.w	#$fff0,d1
	move.w	Bob_I_Words(a4,d7.w),d4
	subq.w	#1,d4
	move.w	Bob_Height(a4),d5
	add.w	#15,d5
	lsr.w	#4,d5

	move.l	Backblit_Vector,a3

	movem.w	d0/d4,-(sp)
.char_loopy:
	movem.w	(sp),d0/d4
.char_loopx:
	movem.w	d0-d1,-(sp)

	lsr.w	#4,d0
	move.l	Scr_Level(a6),a0

	adda.w	d0,a0

	sub.w	#32,d1
	lsr.w	#4,d1

	mulu	Scr_Level_Width(a6),d1
	add.l	d1,a0
	moveq	#0,d0
	move.b	-1(a0),d2

	movem.w	(sp)+,d0-d1

	movem.w	d0-d1/d4-d5,-(sp)

	jsr	(a3)

	movem.w	(sp)+,d0-d1/d4-d5
	add.w	#16,d0
	dbf	d4,.char_loopx
	add.w	#16,d1
	dbf	d5,.char_loopy
	movem.w	(sp)+,d0/d4

	;Kopieren der Module in den aktuellen Screen.

	movem.w	Bob_X_Position(a4),d0-d1
	add.w	Bob_X_Offset(a4),d0

	bsr	Calc_Adress			;1.Blitadresse berechnet!

	waitblt

	move.l	d4,d0
	add.l	Scr_Refresh_Field(a6),d0
	move.l	d0,bltapth(a5)
	add.l	Scr_Supply_Field(a6),d4
	move.l	d4,bltdpth(a5)


	move.w	Bob_to_Info_Offs(a4),d7
	move.w	Bob_I_S_Modulo(a4,d7.w),d1
	sub.w	Bob_I_Bytes(a4,d7.w),d1
	move.w	d1,bltamod(a5)
	move.w	d1,bltdmod(a5)

	move.w	#$09f0,bltcon0(a5)
	move.l	#-1,bltafwm(a5)

	move.w	help,d0
	asl.w	#6,d0
	add.w	d0,d0
	add.w	d0,d0

	add.w	Bob_I_Words(a4,d7.w),d0
	move.w	d0,bltsize(a5)

	;Restore-Auftrag eintragen

	lea	Rest_List2,a1
	move.l	Rest_Pointer,a0
	cmp.l	a1,a0
	blt.s	.use_list2
	lea	Rest_List1,a1
.use_list2:
	tst.w	(a1)
	beq.s	.insert
	addq.l	#8,a1
	bra.s	.use_list2
.insert:
	move.w	d0,(a1)+
	move.w	d1,(a1)+
	move.l	d4,(a1)+
	clr.l	(a1)

	sf	Bob_BlitStatus(a4)	;Bob wieder darstellen.
.out:
	rts

Backblit_Vector:	dc.l	Set_Char

Calc_Adress:
	move.w	Scr_X_Level_Pos(a6),d3
	sub.w	d3,d0
	sub.w	Scr_Y_Level_Pos(a6),d1

	and.w	#15,d3
	add.w	d3,d0

	move.w	Scr_Plane_Height(a6),d3
	sub.w	Scr_Y_Play_Anf(a6),d3
	cmp.w	d3,d1
	bge.s	.under_wrap

	;ber der Wrap-Zeile.

	move.l	Scr_Blt_Adr1(a6),d4
	bra.s	.goon
.under_wrap:
	move.l	Scr_Blt_Adr2(a6),d4
	sub.w	d3,d1
.goon:
	mulu	Scr_Plane_Width(a6),d1
	add.l	d1,d4

	lsr.w	#3,d0
	and.w	#$fffe,d0
	add.w	d0,d4
	rts

*----------------------------------------------------------------------------
*	Create Level at present Position at all Pages
*
*	no Requirements
*----------------------------------------------------------------------------
Create_Pages:			;Initialize Pointer to CutomChips

	move.l	Act_Scr_Structure,a6

	lea	custom,a5
				;Wait until Blitter has finished
	waitblt

				;Initialize BlitterRegister
	move.l	Scr_Blt_Mask(a6),bltafwm(a5)
	move.w	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move.w	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	move.w	Scr_Blt_Con_0(a6),bltcon0(a5)
	clr.w	bltcon1(a5)

				;Create first Page
	move.l	Scr_Level_Pointer(a6),a3
	move.l	Scr_Show_Field(a6),a4
	bsr.s	Create_single_Page

				;Create second Page
	move.l	Scr_Level_Pointer(a6),a3
	move.l	Scr_Supply_Field(a6),a4
	bsr.s	Create_single_Page

				;Create Third Page
	move.l	Scr_Level_Pointer(a6),a3
	move.l	Scr_Refresh_Field(a6),a4
	bsr.s	Create_single_Page
	rts

*----------------------------------------------------------------------------
*	Create Level at present Position at mentioned Pages
*
*	a3 = Pointer to Level
*	a4 = Pointer to Page
*----------------------------------------------------------------------------
Wait_Line:
	move.l	$dff004,d0
	and.l	#$1ff00,d0
	cmp.l	#$10000,d0
	bne	Wait_Line
	rts

Create_single_Page:

	;Calculate Adresses
	moveq	#0,d0
	move.w	Scr_Y_Level_Pos(a6),d0
	lsr.w	#4,d0
	subq.w	#2,d0
	mulu	Scr_Level_Width(a6),d0
	move.w	Scr_X_Level_Pos(a6),d1
	lsr.w	#4,d1
	add.w	d1,d0
	subq.l	#1,d0
	add.l	d0,a3

	moveq	#0,d0
	move.w	Scr_Y_Play_Anf(a6),d0
	sub.w	#16,d0
	bpl.s	.ok
	add.w	Scr_Plane_Height(a6),d0
.ok:
	move.w	d0,d5
	and.w	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	moveq	#0,d1
	move.w	Scr_X_Level_Pos(a6),d1
	lsr.w	#3,d1
	and.w	#%1111111111111110,d1
	add.l	d1,d0
	subq.l	#2,d0
	add.l	d0,a4

	;Initialize LoopCounter for Lines
	move.w	Scr_X_Supply_Plates(a6),d7
	subq.w	#1,d7


	move.w	Scr_Blt_Con_0(a6),bltcon0(a5)
	move.w	#$09f0,bltcon0(a5)
	lea	$dff000,a5
	waitblt
	move.l	Scr_Blt_Mask(a6),bltafwm(a5)
	move.w	Scr_Blt_A_Modulo(a6),bltamod(a5)
	move.w	Scr_Blt_D_Modulo(a6),bltdmod(a5)
	move.w	#0,bltcon1(a5)
.loop1
	move.l	a3,a1
	move.l	a4,a2

	move.w	Scr_Y_Supply_Plates(a6),d6
	subq.w	#1,d6	;+2-1
.loop2
	moveq	#0,d0
	move.b	(a1)+,d0
	move.l	Macro_Pointer(pc),a0
	add.w	d0,d0
	moveq	#0,d1
	move.b	(a0,d0.w),d1

	move.l	Char_Vector(pc),a0
	jsr	(a0)

	waitblt
	move.l	a0,bltapth(a5)
	move.l	a2,bltdpth(a5)

	move.w	Scr_Blt_Blit_Size(a6),bltsize(a5)

	addq.l	#2,a2
	dbf	d6,.loop2

	moveq	#0,d0
	move.w	Scr_Level_Width(a6),d0
	add.l	d0,a3
	add.l	Scr_X_Supply_Add(a6),a4
	add.w	#16,d5

	cmp.w	Scr_Plane_Height(a6),d5
	blt.s	.nowrap
	move.w	Scr_Plane_Height(a6),d0
	and.w	#%1111111111110000,d0
	mulu	Scr_Plane_Width(a6),d0
	sub.l	d0,a4
	moveq	#0,d5
.nowrap:
	dbf	d7,.loop1
	rts

Calc_Char:
	mulu	Scr_Blt_Len(a6),d1	;Modul-adresse berechnen (fr 4Planes)
	move.l	Scr_Character(a6),a0
	lea	(a0,d1.w),a0
	rts

Char_Vector:	dc.l	Calc_Char
help:	dc.l	0

Start_Shoot:
	move.l	a4,-(sp)
	movem.l	d2-d3,-(sp)
	move.w	d1,d2
	move.w	d0,d1
	lea	Area_Enter_Vector(pc),a1
	moveq	#7,d0
	bsr	Search_Bob_Entry
	movem.l	(sp)+,d2-d3
	tst.w	d7
	bmi.s	.no
	move.w	d2,Bob_Special_1(a4)
	move.w	d3,Bob_Special_2(a4)
	PLAY_FX	#$13
.no:
	move.l	(sp)+,a4
	rts

Shoot_Start:
	move.l	#Shoot,Bob_Routine(a4)
	move.b	#BOB_NOCOL,Bob_Used(a4)
Shoot:
	tst.b	T_wheel
	bne.s	.no_hit
	move.w	Bob_X_Position(a4),d0
	move.w	Bob_Y_Position(a4),d1
	addq.w	#3,d0
	addq.w	#3,d1

	move.w	T_posX(pc),d2
	add.w	Scr_X_Level_Pos(a6),d2
	add.w	#10,d2
	cmp.w	d0,d2
	bgt.s	.no_hit
	add.w	#18,d2
	cmp.w	d0,d2
	blt.s	.no_hit

	move.w	T_posY(pc),d3
	add.w	Scr_Y_Level_Pos(a6),d3
	addq.w	#4,d3
	cmp.w	d1,d3
	bgt.s	.no_hit
	add.w	#24,d3
	cmp.w	d1,d3
	blt.s	.no_hit

	sub.w	#9,d2
	sub.w	d0,d2
	bmi.s	.ok
	moveq	#0,d2
.ok:
	move.b	d2,T_hitdir

	bsr	make_plhit
	bra	Out_Bob_Damage

.no_hit:
	movem.w	d0-d1,-(sp)
	bsr	check_obj_kollision
	movem.w	(sp)+,d0-d1
	bne.s	.destruct	

	move.w	Bob_Special_1(a4),d0
	add.w	d0,Bob_Special_3(a4)
	move.w	Bob_Special_3(a4),d0
	asr.w	#6,d0
	add.w	d0,Bob_X_Position(a4)
	move.w	Bob_Special_3(a4),d0
	and.w	#$ffc0,d0
	sub.w	d0,Bob_Special_3(a4)

	move.w	Bob_Special_2(a4),d0
	add.w	d0,Bob_Special_4(a4)
	move.w	Bob_Special_4(a4),d0
	asr.w	#6,d0
	add.w	d0,Bob_Y_Position(a4)

	move.w	Bob_Special_4(a4),d0
	and.w	#$ffc0,d0
	sub.w	d0,Bob_Special_4(a4)

	bra	Test_Bob_Out

.destruct:
	move.l	a4,-(sp)

	move.w	d1,d2
	move.w	d0,d1
	subq.w	#8,d1
	subq.w	#8,d2
	moveq	#2,d0
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.no
	move.b	#BOB_NOCOL,Bob_Used(a4)
.no:
	PLAY_FX	#$15

	move.l	(sp)+,a4
	bra	Out_Bob_Damage	

	;------------------------------------------------------------------
	;               Blit Diamondcount
	;------------------------------------------------------------------

Init_Diamondcount:
	move.l	#Work_Buffer4,d1		;Dest-Adress
	move.l	d1,bltdpth(a5)
	move.w	#0,bltdmod(a5)
	move.w	#$0100,bltcon0(a5)
	move.w	#64*16*4+4,bltsize(a5)
	waitblt

	move.l	Diamond_Pointer(pc),d2		;Adresse des Diamanten.
	move.l	d2,bltapth(a5)
	move.l	d1,bltdpth(a5)
	move.w	#4,bltdmod(a5)
	move.w	#0,bltamod(a5)
	move.l	#-1,bltafwm(a5)
	move.w	#$09f0,bltcon0(a5)
	clr.w	bltcon1(a5)
	move.w	#64*16*3+1,d0
	add.w	#16*3*2,d2			;Zeiger auf die Maske stellen.
	lea	Diamond_Info_0(pc),a0

	move.w	#3,Bob_I_Depth(a0)
	move.w	#3*2*3,Bob_I_B_Modulo(a0)
	move.w	#planeb*3,Bob_I_D_Modulo(a0)

	tst.b	Plane_flag
	beq.s	.three_planes
	move.w	#64*16*4+1,d0
	add.w	#16*2,d2			;Vier Planes sind lnger!
	move.w	#4,Bob_I_Depth(a0)
	move.w	#3*2*4,Bob_I_B_Modulo(a0)
	move.w	#planeb*4,Bob_I_D_Modulo(a0)

.three_planes:
	move.w	d0,bltsize(a5)
	waitblt
	move.l	d2,bltapth(a5)
	add.l	#16*4*6,d1
	move.l	d1,bltdpth(a5)
	move.w	#64*16+1,bltsize(a5)
	waitblt

	lea	Work_Buffer4+2,a0
	moveq	#0,d0
	bsr	Write_Diamondchar

	bsr	Show_Diamondcount

	move.l	a4,-(sp)

	move.w	Scr_X_Level_Pos(a6),d1
	move.w	Scr_Y_Level_Pos(a6),d2
	add.w	#128,d1
	add.w	#100,d2
	moveq	#0,d0
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.no
	move.b	#BOB_NOCOL,Bob_Used(a4)
	bset	#BOB_URGENT,Bob_BlitStatus(a4)	;Bob AUF JEDEN FALL BLITTEN!!!!!
.no:
	move.l	(sp)+,a4

	;Zhlgeschwindigkeit berechnen :

	move.w	#1,Diamond_Sub
	move.w	Diamond_Count(pc),d0
	cmp.w	#250,d0
	blt.s	.no_speeds
	move.w	d0,d1
	sub.w	#128,d1
	lsr.w	#7,d1
	addq.w	#1,d1
	move.w	d1,Diamond_Sub
.no_speeds:
	moveq	#0,d1
	cmp.w	#200,d0
	bgt.s	.set
	moveq	#1,d1
	cmp.w	#150,d0
	bgt.s	.set
	moveq	#2,d1
	cmp.w	#100,d0
	bgt.s	.set
	moveq	#3,d1
	cmp.w	#50,d0
	bgt.s	.set
	moveq	#4,d1
.set:
	move.b	d1,Diamond_Verz_def
	move.w	Diamond_Count(pc),DATA_DIAMONDS.w
	rts

Count_Diamonds:
	subq.b	#1,Diamond_Verz
	bpl.s	.out
	move.b	Diamond_Verz_def(pc),Diamond_Verz
	tst.w	Diamond_Count
	beq.s	.end
	move.l	#$100,d0
	bsr	add_score
	PLAY_FX	#$1e
	move.w	Diamond_Sub(pc),d0
	sub.w	d0,Diamond_Count
	bpl.s	.ok
	clr.w	Diamond_Count
.ok:
	bsr	Show_Diamondcount
.out:
	moveq	#1,d0
.end:
	rts

Show_Diamondcount:
	lea	Work_Buffer4+3,a0

	moveq	#0,d0
	move.w	Diamond_Count(pc),d0

	divu	#100,d0
	bsr.s	.do_one
	addq.l	#1,a0
	swap	d0
	divu	#10,d0
	bsr.s	.do_one
	swap	d0
	addq.l	#1,a0
.do_one:
	movem.l	d0/a0,-(sp)
	addq.w	#1,d0
	bsr	Write_Diamondchar
	movem.l	(sp)+,d0/a0
	clr.w	d0
	rts

Write_Diamondchar:
	lea	16*4*6(a0),a2
	ext.l	d0
	add.l	#Diamond_Font,d0
	move.l	d0,a1
	move.w	#12*15,d5		;Offset fr Plane 2
	move.w	#12*15*2,d6		;Offset fr Plane 3
	move.w	#12*15*3,d7		;Offset fr Plane 4
	moveq	#15-1,d1
.loop:
	moveq	#0,d0			;Fr Maske!
	tst.b	Plane_flag
	beq.s	.three_planes

	move.b	(a1),d0
	move.b	d0,(a0)
	move.b	(a1,d5.w),6(a0)
	or.b	(a1,d5.w),d0
	move.b	(a1,d6.w),12(a0)
	or.b	(a1,d6.w),d0
	move.b	(a1,d7.w),18(a0)
	or.b	(a1,d7.w),d0
	addq.l	#6,a0
	move.b	d0,(a2)
.back:
	add.l	#18,a0
	addq.l	#6,a2
	add.l	#12,a1
	dbf	d1,.loop
	rts

.three_planes:
	move.b	(a1),d0
	move.b	d0,(a0)
	move.b	(a1,d5.w),6(a0)
	or.b	(a1,d5.w),d0
	move.b	(a1,d6.w),12(a0)
	or.b	(a1,d6.w),d0
	move.b	d0,(a2)
	move.b	d0,(a0)
	move.b	d0,6(a0)
	move.b	d0,12(a0)
	bra.s	.back

Diamond_Pointer:	dc.l	0
Plane_flag:		dc.b	1
Diamond_Verz:		dc.b	0
Diamond_Sub:		dc.w	0
Diamond_Count:		dc.w	DiamondTest
Diamond_Verz_def:	dc.b	0
	even

Diamondcount_AnimTable:
	dc.l	Work_Buffer4,Work_Buffer4+16*4*6
	dc.w	0,0,16,0,0,0,0

	dc.w	ENTRY_END
	dc.l	Diamondcount_AnimTable

Diamond_Info_0:	dc.w	NORM		;Bob_Mode
		dc.w	64		;Bob_I_Out_X_Val
		dc.w	64		;Bob_I_Out_Y_Val
		dc.w	32		;Breite in Pixels
		dc.w	32		;Hhe in Pixels
		dc.w	4		;Tiefe in Planes
		dc.w	6		;Breite einer Zeile der Maske in Bytes
		dc.w	3*2		;A Modulo
		dc.w	3*2*4		;B Modulo
		dc.w	planeb*4	;D Modulo
		dc.w	planeb		;Save Modulo
		dc.l	$ffff0000		;Bob_I_AFWM
		dc.w	4		;Blit-Breite in Wrtern
		dc.w	8		;Blit-Breite in Bytes
		dc.w	-1		;Hitpoints
		dc.l	Standart_BobAnim	;Routine, die Bob verwaltet
		dc.l	Diamondcount_AnimTable	;Zeiger auf nchste Anim

		dc.w	0		;Delay
		dc.w	6		;Delay Init
		dc.l	$ffffffff	;Zeiger auf Tabelle mit Zeigern, die angeben welche Planes im Playfield mit welchen Planes des Bobs oder der Maske beschrieben werden sollen.

	IFNE	Coords

Show_Word:
	divu	#1000,d0
	asl.b	#4,d0
	move.b	d0,T_score+1
	clr.w	d0
	swap	d0
	divu	#100,d0
	or.b	d0,T_score+1
	clr.w	d0
	swap	d0
	divu	#10,d0
	asl.b	#4,d0
	move.b	d0,T_score+2
	clr.w	d0
	swap	d0
	or.b	d0,T_score+2
	rts

Show_Word2:
	divu	#1000,d0
	asl.b	#4,d0
	move.b	d0,T_lifes
	clr.w	d0
	swap	d0
	divu	#100,d0
	or.b	d0,T_lifes
	clr.w	d0
	swap	d0
	divu	#10,d0
	asl.b	#4,d0
	move.b	d0,T_score
	clr.w	d0
	swap	d0
	or.b	d0,T_score
	rts
	ENDC

*---------------------------------------------------------------------------
*	Routine of      Extrabox
*---------------------------------------------------------------------------
Extrabox:
;	move.w	Bob_X_Position(a4),d0
;	move.w	Bob_Y_Position(a4),d1
;
;	move.w	d0,d2
;	add.w	#32,d2
;	jsr	check_foot_frame
;	beq.s	.no_feet
;	st	T_stand
;	move.w	Bob_Y_Position(a4),d1
;	jsr	alias_feet
;.no_feet:
	tst.w	Bob_Hit(a4)
	beq	.nothing

	moveq	#24,d6
	moveq	#1,d0
	bsr	Use_Background			;Box aus dem Background lschen!

	bsr	Get_Next_Bob_Frame
	move.l	#Box_Out,Bob_Routine(a4)
	move.b	#BOB_NOCOL,Bob_Used(a4)

	move.l	a4,-(sp)
	moveq	#4,d0
	move.w	Bob_X_Position(a4),d1
	move.w	Bob_Y_Position(a4),d2
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	move.l	a4,a0
	move.l	(sp)+,a4

	tst.w	d7
	bmi.s	.ok

	move.l	#-$00060000,Bob_Special_1(a0)
	move.w	#2,Bob_Special_3(a0)

	move.w	Bob_X_Position(a4),d0
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	T_posX(pc),d0
	bpl.s	.ok
	move.w	#-2,Bob_Special_3(a0)
	move.b	#BOB_NOCOL,Bob_Used(a0)
.ok:

	PLAY_FX	#$1a

	;Inhalt der Box starten.

	move.w	Bob_X_Position(a4),d5
	move.w	Bob_Y_Position(a4),d6
	addi.w	#12,d5
	sub.w	#12,d6
	lea	extra_xtab(pc),a2
	jsr	rnd
	and.w	#$0060,d0
	lea	(a2,d0.w),a2
	moveq	#6,d4
	cmp.b	#3,DATA_LEVEL.w
	bne.s	.loop
	subq.w	#1,d4				;Keine OneUps
.loop:
	btst	d4,Bob_Special_4+1(a4)
	beq.s	.no_start
	move.w	d4,d0
	move.w	d5,d1
	move.w	d6,d2
	bsr	.init_extra
.no_start:
	dbf	d4,.loop

	move.l	#.Box2,Bob_Routine


	bra	Test_Bob_Out

.nothing:
	moveq	#24,d6
	moveq	#0,d0
	bsr	Use_Background
	bra	Test_Bob_Out

.init_extra:
	move.l	a4,-(sp)

	lea	Area_Enter_Vector(pc),a1
	movem.l	a2/d0,-(sp)
	moveq	#5,d0
	bsr	Search_Last_Entry
	tst.w	d7
	bmi.s	.no_extra
	move.l	#Move_Bonus_Jump,Bob_Routine(a4)
	movem.l	(sp)+,a2/d0
	mulu	#22,d0
	add.l	Bob_Act_Anim(a4),d0
	move.l	d0,Bob_Next_Anim(a4)
	bsr	Get_Next_Bob_Frame
	move.b	#BOB_NOCOL,Bob_Used(a4)
	move.w	#450,Bob_Special_4(a4)

	move.w	(a2)+,Bob_Special_1(a4)		;X - Dir

	move.w	(a2)+,Bob_Special_2(a4)
.lab0:
	move.l	(sp)+,a4
	rts

.no_extra:
	movem.l	(sp)+,a2/d0
	addq.l	#4,a2
	bra.s	.lab0

.Box2:
	moveq	#0,d0
	moveq	#14,d6
	bsr	Use_Background
	bra	Test_Bob_Out

Box_Out:
		move.w	Bob_X_Out(a4),d0
		lsr.w	#1,d0
		cmp.w	Bob_Out_X_Val(a4),d0
		bhs	Out_Bob_Damage

		move.w	Bob_Y_Out(a4),d0
		lsr.w	#1,d0
		cmp.w	Bob_Out_Y_Val(a4),d0
		bhs	Out_Bob_Damage
		rts

extra_xtab:	dc.w	0,0,2,8,-1,2,1,10,-2,0,0,8,2,2
		dc.l	0

		dc.w	-1,2,-2,0,0,8,2,8,0,0,2,2,1,10
		dc.l	0

		dc.w	2,8,1,10,2,2,0,8,-1,2,0,0,-2,0
		dc.l	0

		dc.w	0,8,-1,2,2,2,1,10,2,8,-2,0,0,0
		dc.l	0

Box_Deckel:
	move.w	Bob_Special_3(a4),d0
	add.w	d0,Bob_X_Position(a4)
	move.w	Bob_Special_1(a4),d0
	add.w	d0,Bob_Y_Position(a4)
	add.l	#$00008000,Bob_Special_1(a4)

	move.w	Bob_X_Position(a4),d0
	move.w	Bob_Y_Position(a4),d1
	add.w	#16,d1
	add.w	#16,d0

	jsr	check_obj_kollision
	beq	Test_Bob_Out
	moveq	#0,d0
	bra	Standart_Destruction

*---------------------------------------------------------------------------
*	Routine of      Bonus1-4
*---------------------------------------------------------------------------
Start_Bonus:					;Flying Extra!
	move.l	#Move_Bonus,Bob_Routine(a4)

	moveq	#6,d7
	cmp.b	#3,DATA_LEVEL.w
	bne.s	.search
	subq.w	#1,d7				;Keine OneUps
.search:
	btst	d7,Bob_Special_4+1(a4)
	bne.s	.found
	dbf	d7,.search
	moveq	#0,d7
.found:
	mulu	#22,d7
	add.l	Bob_Act_Anim(a4),d7
	move.l	d7,Bob_Next_Anim(a4)
	bsr	Get_Next_Bob_Frame
	move.b	#BOB_NOCOL,Bob_Used(a4)
	move.w	#$7fff,Bob_Special_4(a4)

	rts

Move_Bonus_Jump:
	movem.w	Bob_X_Position(a4),d6-d7
	move.w	d6,d0
	move.w	d7,d1

	tst.w	Bob_Special_1(a4)
	bpl.s	.add
	subq.w	#8,d0
	bra.s	.sub
.add:
	addq.w	#8,d0
.sub:
	bsr	check_obj_kollision		;Way blocked ?
	bne.s	.no_xmove
	add.w	Bob_Special_1(a4),d6		;X - Movement
	cmpi.w	#304,d6
	bhi.s	.no_xmove
	sub.w	Bob_Special_1(a4),d6
.no_xmove:
	move.w	Bob_Special_2(a4),d2		;Get jump-index
	cmpi.w	#24*2,d2			;Maximum reached ?
	blt.s	.not_ready
.ready:
	move.l	#Move_Bonus,Bob_Routine(a4)	;Just let extra flow up
	bra.s	.exit_jmp
.not_ready:

	lea	.ExtBounce(pc),a0		;Jump-table
	move.w	d6,d0
	move.w	d7,d1
	move.w	0(a0,d2.w),d5
	bpl.s	.add2
	sub.w	#8,d1
	bra.s	.sub2
.add2:
	addq.w	#8,d1
.sub2:
	bsr	check_obj_kollision		;Way blocked ?
	bne.s	.ready
	add.w	d5,d7
.no_ymove:
	addq.w	#2,Bob_Special_2(a4)		;Increase index
.exit_jmp:
	movem.w	d6-d7,Bob_X_Position(a4)
	bra	Bonus_Check_Collect

.ExtBounce:
	dc.w	-6,-6,-5,-5,-4,-4,-3,-3,-2,-2,-1,-1,0,0
	dc.w	1,1,1,1,2,2,3,3,4,4,5

BONUS_POWER	= 1
BONUS_WEAPON1	= 2
BONUS_WEAPON2	= 3
BONUS_WEAPON3	= 4
BONUS_SHIELD	= 5
BONUS_ROCKET	= 6
BONUS_ONEUP	= 7


Move_Bonus:
	move.w	Bob_X_Position(a4),d0
	move.w	Bob_Y_Position(a4),d1

	addq.w	#8,d0

	bsr	check_obj_kollision
	bne.s	.no_move

	move.w	eights_pixel(pc),d0
	sub.w	d0,Bob_Y_Position(a4)
.no_move:

	subq.w	#1,Bob_Special_4(a4)
	bpl	.wait

	btst	#1,Bob_Special_4+1(a4)
	beq.s	.clear
	bset	#NO_BOBBLIT,Bob_BlitStatus(a4)
	bra.s	.set
.clear:
	bclr	#NO_BOBBLIT,Bob_BlitStatus(a4)
.set:
	cmp.w	#-50,Bob_Special_4(a4)
	bgt.s	.wait

	move.w	Bob_X_Position(a4),d1
	move.w	Bob_Y_Position(a4),d2

	move.w	Bob_to_Info_Offs(a4),d3
	cmp.w	#2,Bob_I_Mask_Width(a4,d3.w)
	beq.s	.start
	addq.w	#4,d1
	addq.w	#2,d2

.start:
	move.l	a4,-(sp)
	moveq	#2,d0
	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.no
	move.b	#BOB_NOCOL,Bob_Used(a4)
.no:
	move.l	(sp)+,a4
	bra	Out_Bob_Damage
.wait:
Bonus_Check_Collect:
	move.w	Bob_X_Position(a4),d0
	move.w	Bob_Y_Position(a4),d1
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d1

	move.w	T_posX(pc),d2
	move.w	T_posY(pc),d3
	add.w	#10,d2
	addq.w	#4,d3

	move.w	d2,d4
	move.w	d3,d5

	add.w	#18,d4
	add.w	#24,d5

	cmp.w	d4,d0
	bgt	.no_collect

	move.l	Bob_Act_Anim(a4),a0

	add.w	18(a0),d0
	cmp.w	d2,d0
	blt	.no_collect

	cmp.w	d5,d1
	bgt	.no_collect
	add.w	20(a0),d1
	cmp.w	d3,d1
	blt	.no_collect

	move.w	14(a0),d0
	cmp.w	#BONUS_POWER,d0
	beq	.power
	cmp.w	#BONUS_WEAPON1,d0
	beq.s	.weapon1
	cmp.w	#BONUS_WEAPON2,d0
	beq	.weapon2
	cmp.w	#BONUS_WEAPON3,d0
	beq	.weapon3
	cmp.w	#BONUS_SHIELD,d0
	beq.s	.shield
	cmp.w	#BONUS_ROCKET,d0
	beq.s	.rocket
	moveq	#1,d0
	move.b	T_lifes(pc),d1
	move.w	#0,ccr
	abcd	d0,d1
	move.b	d1,T_lifes
	addq.w	#1,DATA_LIFES.w
	PLAY_FX	#$22
	bra	Out_Bob_Damage
.rocket:
	st	T_rocket
	PLAY_FX	#$25
	bra	Out_Bob_Damage
.shield:
	st	T_shield
	PLAY_FX	#$21
	bra	Out_Bob_Damage
.weapon1:
	PLAY_FX	#$24
	moveq	#0,d0
.do_weapon:
	cmp.b	T_weapon_new,d0
	beq.s	.powup
	move.b	T_power_new(pc),d1
	moveq	#0,d2
	move.b	T_weapon_new(pc),d2
	lea	T_power1(pc),a0
	move.b	d1,(a0,d2.w)
	move.b	d0,T_weapon_new
	move.b	(a0,d0.w),T_power_new
.powup:
	cmp.b	#2,T_power_new
	beq	Out_Bob_Damage
	addq.b	#1,T_power_new
	bra	Out_Bob_Damage
.weapon2:
	PLAY_FX	#$1f
	moveq	#1,d0
	bra.s	.do_weapon
.weapon3:
	PLAY_FX	#$20
	moveq	#2,d0
	bra.s	.do_weapon

.power:
	PLAY_FX	#$23
	move.b	#64,T_energy
	bra	Out_Bob_Damage

.no_collect:
	bra	Test_Bob_Out

RSPEED	= 8

start_rocket:
	cmp.b	#2,T_rocket_anz
	beq.s	.out				;Schon genug Raketen!

	moveq	#6,d0
	bsr	.get_origin		;Get start-position

	lea	Area_Enter_Vector(pc),a1
	bsr	Search_Bob_Entry
	tst.w	d7
	bmi.s	.out
	tst.b	T_face			;Which direction ?
	beq.s	.to_left
	moveq	#RSPEED<<1,d0	;Right
	move.b	#128,d1
	bra.s	.set
.to_left:
	moveq	#-RSPEED<<1,d0	;Left
	moveq	#0,d1
.set:
	clr.w	Bob_Anim_Delay(a4)
	move.w	d0,Bob_Special_1(a4)
	clr.w	Bob_Special_2(a4)
	move.b	d1,Bob_Special_3(a4)
	movem.w	Bob_X_Position(a4),d0-d1
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d1
	asl.w	#3,d0
	asl.w	#3,d1
	movem.w	d0-d1,Bob_Special_4(a4)	;Store in fix-format
	sf	Bob_Special_3+1(a4)		;Clear counter
	move.b	#BOB_NOCOL,Bob_Used(a4)
	move.b	T_rocket_flash,Bob_Status(a4)
	not.b	T_rocket_flash
	addq.b	#1,T_rocket_anz
.out:
	rts

.get_origin:
	move.w	T_posX(pc),d1
	move.w	T_posY(pc),d2
	add.w	Scr_X_Level_Pos(a6),d1
	add.w	Scr_Y_Level_Pos(a6),d2
	tst.w	T_face
	beq.s	.ok
	add.w	#16,d1
.ok:
	cmp.w	#22,T_anim
	bne.s	.no_knee
	add.w	#16,d2
.no_knee:
	rts

Super_Player_Start:
	move.l	#Super_Player,Bob_Routine(a4)
	move.b	#1<<NO_BOBBLIT,Bob_BlitStatus(a4)
	move.b	#BOB_NOCOL,Bob_Used(a4)
	move.w	#16,Bob_Height(a4)

Super_Player:
	tst.w	Bob_Special_1(a4)
	bne.s	.wait_flash
	move.w	Bob_X_Position(a4),d0
	move.w	Bob_Y_Position(a4),d1
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d1

	move.w	T_posX(pc),d2
	move.w	T_posY(pc),d3
	add.w	#10,d2
	addq.w	#4,d3

	move.w	d2,d4
	move.w	d3,d5

	add.w	#18,d4
	add.w	#24,d5

	cmp.w	d4,d0
	bgt	.no_collect

	addq.w	#8,d0
	cmp.w	d2,d0
	blt.s	.no_collect

	cmp.w	d5,d1
	bgt.s	.no_collect
	addq.w	#8,d1
	cmp.w	d3,d1
	blt.s	.no_collect

	jsr	L_StartFlash
	st	Bob_Special_1(a4)
	rts
.no_collect:
	bra	Test_Bob_Out2

.wait_flash:
	cmp.w	#$fff,coltab
	bne.s	.out
	move.l	#$0cc00b60,S_coltab+16
	jsr	L_Copy_Colors
	st	T_super_turrican
	bra	Out_Bob_Damage
.out:
	rts

Super_Info:
		dc.w	NORM		;Bob_Mode
		dc.w	128		;Bob_I_Out_X_Val
		dc.w	128		;Bob_I_Out_Y_Val
		dc.w	16		;Breite in Pixels
		dc.w	16		;Hhe in Pixels
		dc.w	4		;Tiefe in Planes
		dc.w	2		;Breite einer Zeile der Maske in Bytes
		dc.w	1*2		;A Modulo
		dc.w	1*2*4		;B Modulo
		dc.w	planeb*4	;D Modulo
		dc.w	planeb		;Save Modulo
		dc.l	$ffff0000	;Bob_I_AFWM
		dc.w	2		;Blit-Breite in Wrtern
		dc.w	4		;Blit-Breite in Bytes
		dc.w	-1		;Hitpoints
		dc.l	Super_Player_Start	;Routine, die Bob verwaltet
		dc.l	0		;Zeiger auf nchste Anim

coltab:		dcb.w	32,0


Start_Sound_Fade:
	move.b	d0,sound_song
	move.l	#$00030000,d0
	jsr	TFMX+72
	lea	Sound_Fade_Handler(pc),a1
	bra	AddHandler
Sound_Fade_Handler:
	subq.b	#1,sound_fade_verz
	bpl.s	.out
	move.l	#Return,-4(a0)
	move.b	#40,sound_fade_verz
	move.b	sound_song(pc),d0
	tst.b	effekt_song
	beq	Play_Song
	sf	effekt_song
	bra	Play_Effekt_Song
.out:
	rts

sound_fade_verz:	dc.b	40
xplo_time:		dc.b	5
sound_song:		dc.b	0
song_mode:		dc.b	1
song_last:		dc.b	0
effekt_num:		dc.b	0
effekt_song:		dc.b	0
global_startsound:	dc.b	0
global_stopsound:	dc.b	0
	even

Handle_sound:
	moveq	#0,d0
	move.b	song_last(pc),d0
	bsr	Play_Song
	rts

Play_Song:
	move.b	d0,song_last
	btst	#0,song_mode
	bne.s	.ok
	moveq	#-1,d0
.ok:
	jsr	TFMX+44
	move.l	#$00000040,d0
	jmp	TFMX+72

Play_Effekt_Song:
	move.b	song_mode(pc),-(sp)
	bset	#0,song_mode
	bsr	Play_Song
	move.b	(sp)+,song_mode
	rts

Cont_Song:
	move.b	d0,song_last
	btst	#0,song_mode
	bne.s	.ok
	moveq	#-1,d0
.ok:
	jsr	TFMX+96
	move.l	#$00060040,d0		;Langsam einfaden
	jmp	TFMX+72

Do_FX:
;	btst	#1,song_mode
;	bne.s	.no_fx
	jsr	TFMX+92
.no_fx:
	rts

Start_Effekt:
	move.b	d0,effekt_num
	lea	Xplo_Handler(pc),a1
	bra	AddHandler

Xplo_Handler:
	subq.b	#1,xplo_time
	bpl.s	.out
	move.b	#5,xplo_time
	move.l	#Return,-4(a0)
	moveq	#0,d0
	move.b	effekt_num(pc),d0
	bra	Do_FX
.out:
	rts

Rocket:
	movem.w	Bob_X_Position(a4),d0-d1
	sub.w	Scr_X_Level_Pos(a6),d0
	sub.w	Scr_Y_Level_Pos(a6),d1
	move.w	d0,d2
	move.w	d1,d3
	add.w	#16,d2
	add.w	#16,d3
	bsr	check_rec
	beq.s	.no_hit
	cmp.w	#-1,Bob_Power(a0)
	beq.s	.powerok
	move.w	SW_power,d0
	sub.w	d0,Bob_Power(a0)
	bpl.s	.powerok
	clr.w	Bob_Power(a0)
.powerok:
	move.w	#4,Bob_Hit(a0)

.end_rocket:					;make explosion (free rocket)
	subq.b	#1,T_rocket_anz
	sub.w	#16,Bob_X_Position(a4)
	sub.w	#16,Bob_Y_Position(a4)
	bsr	Out_Bob_Damage
	bsr	Start_Explo
	move.w	#0,Bob_Anim_Delay_Init(a4)
	PLAY_FX	#$26
	rts
.no_hit:

	movem.w	Bob_Special_1(a4),d0-d1		;Get direction
	add.w	d0,Bob_Special_4(a4)		;Add to position
	add.w	d1,Bob_Special_5(a4)

	movem.w	Bob_Special_4(a4),d0-d1		;Convert position to normal format
	asr.w	#3,d0
	asr.w	#3,d1
	add.w	Scr_X_Level_Pos(a6),d0
	add.w	Scr_Y_Level_Pos(a6),d1
	movem.w	d0-d1,Bob_X_Position(a4)	;Store into object's position

	moveq	#0,d0
	move.b	Bob_Special_3(a4),d0			;Get angle
	addq.w	#8,d0				;Round result to 16-border
	lsr.w	#4,d0
	subq.w	#8,d0
	andi.w	#15,d0				;Mask lower 4 bits
	move.w	d0,Bob_Anim_Delay(a4)		;Take as phase
	add.w	d0,d0
	move.w	d0,d6
	add.w	d0,d0
	add.w	d0,d6
	asl.w	#2,d0
	add.w	d0,d6
	move.l	Rocket_AnimTable_Pointer(pc),a0
	lea	(a0,d6.w),a0
	move.l	a0,Bob_Next_Anim(a4)
	bsr	Get_Next_Bob_Frame

	cmp.w	#8,Bob_Anim_Delay(a4)
	ble.s	.set_noflip
	move.l	Rocket_AnimTable_Pointer+8(pc),a0
	sub.l	a4,a0
	or.w	#FLIP,Bob_Race(a4)
	bra.s	.setit
.set_noflip:
	move.l	Rocket_AnimTable_Pointer+4(pc),a0
	sub.l	a4,a0
	and.w	#$ffff-FLIP,Bob_Race(a4)
.setit:
	move.w	a0,Bob_to_Info_Offs(a4)

	subq.b	#1,Bob_Special_3+1(a4)		;Time out ?
	bpl.s	.no_timeout
	move.b	#55,Bob_Special_3+1(a4)
	jsr	rnd
	move.w	d0,d6
	jsr	rnd
	andi.w	#$03ff,d0
	andi.w	#$00ff,d6
	subi.w	#96,d0
	subi.w	#16,d6
	movem.w	d0/d6,Bob_Special_6(a4)		;Set next random-position
.no_timeout:
	movem.w	Bob_Special_6(a4),d6-d7

	moveq	#-1,d4				;Set first dummy delta...
	tst.b	Scr_BigCPU(a6)
	bne.s	.do_not_aim
	move.l	Act_Bob_Structure,a0
.loop:
	movem.w	Bob_X_Position(a4),d2-d3
	tst.b	Bob_Used(a0)
	bmi.s	.next
;		move.b	O_COLEN(a0),d0		;Collision on player ?
;		and.b	O_PHITEN(a0),d0
	cmp.w	#-1,Bob_Power(a0)
	beq.s	.next
	cmp.b	#BOB_NOCOL,Bob_Used(a0)
	bmi.s	.next
	move.w	Bob_X_Position(a0),d0		;Calc |DX|+|DY| as target 'distance'
	sub.w	d2,d0
	bpl.s	.noneg
	neg.w	d0
.noneg:
	move.w	Bob_Y_Position(a0),d1
	sub.w	d3,d1
	bpl.s	.noneg2
	neg.w	d1
.noneg2:
	add.w	d1,d0
	cmp.w	d4,d0				;Lower than last choice ?
	bhs.s	.next
	move.w	Bob_X_Position(a0),d6		;Yes, remember position
	move.w	Bob_Y_Position(a0),d7
	move.w	d0,d4				;Remember 'distance'
.next:
	lea	BOB_ENTRY_LENGTH(a0),a0
	cmp.l	#Bob_Structure_End,a0
	bne	.loop

.no_object:
	bsr	calc_ene_angle			;Calc new angle
.do_not_aim:
	moveq	#0,d0				;Get angle
	move.b	Bob_Special_3(a4),d0
	cmp.b	d0,d1				;Turning neccessary ?
	beq	.no_change

	move.b	d0,d2				;Which side is the shorter
	sub.b	d1,d2				;way ?
	sub.b	d0,d1
	cmp.b	d1,d2
	bls.s	.lower
	cmpi.b	#RSPEED,d1			;Difference big enough ?
	bls.s	.lab1
	addi.b	#RSPEED,Bob_Special_3(a4)	;Yes...
	bra.s	.ok
.lab1:
	add.b	d1,Bob_Special_3(a4)		;No, only add right diff.
	bra.s	.ok
.lower:
	cmpi.b	#RSPEED,d2			;Difference big enough ?
	bls.s	.lab2
	subi.b	#RSPEED,Bob_Special_3(a4)	;Yes...
	bra.s	.ok
.lab2:
	sub.b	d2,Bob_Special_3(a4)		;No...
.ok:

	move.b	Bob_Special_3(a4),d0		;Calc x,y - deltas
	jsr	sin
	move.w	d0,d2
	move.b	Bob_Special_3(a4),d0
	jsr	cos
	neg.w	d0
	asr.w	#4,d0
	asr.w	#4,d2
	movem.w	d0/d2,Bob_Special_1(a4)		;Store deltas

.no_change:
	movem.w	Bob_Special_1(a4),d0-d1		;Get deltas
	add.w	d0,Bob_Special_4(a4)		;Add to position
	add.w	d1,Bob_Special_5(a4)

	movem.w	Bob_X_Position(a4),d0-d1	;Check wall-collision
	jsr	check_obj_kollision
	bne	.end_rocket			;Rocket hit ground
	bsr	Test_Bob_Out
	tst.b	Bob_Used(a4)
	bpl.s	.out
	subq.b	#1,T_rocket_anz
.out:
	rts


calc_ene_angle:
	move.l	a6,-(sp)
	movem.w	Bob_X_Position(a4),d4-d5	;Rocket coordinates
	moveq	#0,d1				;Calc |DY|
	move.w	d7,d1
	sub.w	d5,d1
	bpl.s	.cok
	neg.w	d1
.cok:
	move.w	d1,a6				;Remember |DY| in a6
	move.w	d6,d0				;Calc DX
	sub.w	d4,d0
	muls	d0,d0				;DX*DX
	mulu	d1,d1				;|DY|*|DY|
	add.w	d1,d0				;DX^2+DY^2
	bsr	sqrt				;Pythagoras...
	move.l	a6,d1				;Get and adjust |DY|
	asl.w	#7,d1
	tst.w	d0
	beq.s	.nodiv
	nop
	divu	d0,d1				;SIN(X)   (|DY|/R)
.nodiv:
	moveq	#0,d0				;Calculate ASIN
	lea	asin_tab(pc),a0
	move.b	0(a0,d1.w),d0			;Angle	(ASIN(SIN(X)))
	cmp.w	d6,d4				;Adjust angle to full 256 "degrees"
	ble.s	.not_bigger
	cmp.w	d7,d5
	ble.s	.no1
	move.w	#256,d1
	sub.w	d0,d1
	bra.s	.set_angle
.no1:
	move.w	d0,d1
	bra	.set_angle
.not_bigger:
	cmp.w	d7,d5
	ble.s	.no2
	move.w	d0,d1
	addi.w	#128,d1
	bra.s	.set_angle
.no2:
	move.w	#128,d1
	sub.w	d0,d1
.set_angle:					;Save angle with float-part
	move.l	(sp)+,a6
	andi.w	#255,d1				;Mask only lower 8 bits
	rts

Rocket_AnimTable_Pointer:
	dc.l	0,0,0

	;Sprite-Colors

S_coltab:
		;Normal-Turrican
		dc.w	$000,$8c1,$080,$fff,$442,$8c1,$080,$fff
		dc.w	$8ae,$26a,$e00,$820,$ea2,$aaa,$666,$000
		;Super-Turrican
;		dc.w	$000,$8c1,$080,$fff,$442,$8c1,$080,$fff
;		dc.w	$cc0,$b60,$e00,$820,$ea2,$aaa,$666,$000


Col_Buffer:	dc.l	0,0,0
Color_Pointer:	dc.l	0
para_ypos:	dc.l	0
Fade_Position:	dc.w	0
T_rocket_flash:	dc.b	0
Col_Flag:	dc.b	0
Col_Init_Flag:	dc.b	0
KillFlash:	dc.b	0

	even
Bob_Structure:	dcb.b	BOB_MAXIMUM*BOB_ENTRY_LENGTH,BOB_FALSE
Bob_Structure_End = *

	IFEQ	Coords
	ds.b	$9100-*
	ENDC	

JumpTable:
		rsset	JumpTable

L_Init_World	rs.l	1
L_Init_Datas	rs.l	1
L_Next_Level	rs.l	1
L_Fade_Colors	rs.l	1
L_StartFlash	rs.l	1
L_Copy_Colors	rs.l	1
L_Info_Tab_Adrs	rs.l	1
L_coltab	rs.l	1

	IFND	levelflag
includeflag	= 1
	include	Work:Sources/T3/T3_level1
;	include	Work:Sources/T3/T3_level2
;	include	Work:Sources/T3/T3_level3
;	include	Work:Sources/T3/T3_level4
;	include	Work:Sources/T3/T3_level5
	ENDC
