.JE1	
	LD DE,BALL1
	CP 1
	RET Z
 	LD DE,BALL2
 	CP 2
	RET Z
 	LD DE,BALL3
 	RET

.URBBALL_CallBack
	push AF
	push HL
	inc H
	inc H
	inc H
	inc H
	ld A,(HL)
	or A
	jr z,URBBALL_CallBack_done
	cp #FF	;is module on player
	jr z,URBBALL_CallBack_onPlayer
	cp 32
	jr z,URBALL_CallBack_Erase
	jr nc,URBBALL_CallBack_done
	
	
	push BC
	ld B,1
	call THEM_MakeDamage
	pop BC
	
.URBBALL_CallBack_done
	pop HL
	pop AF
	ret
.URBALL_CallBack_Erase
	pop HL
	pop AF
	xor A
	ret
	
.URBBALL_CallBack_onPlayer
	ld A,(MASTER)	;is main module ?
	cp #F0
	jr nz,URBBALL_CallBack_done
	ld A,1
	ld (MOD_ONSHIP),A
	jr URBBALL_CallBack_done
	
.URBALL


	xor A
	ld (MOD_ONSHIP),A
	ld A,#F0	;player one main module
	ld (MASTER),A
	ld HL,URBBALL_CallBack
	call REND_SprSetCallBack
	
	jp MOD_NewCode
	read "modules_new.asm"

	LD A,(BALL1)
	AND A
 	JR Z,URBALL2
	xor A
	ld (URBALL1A_Xdec),A	;correct placement of module
	LD BC,BALL1P
	LD HL,BALL1X
	LD DE,#C06 ;12*256+6
	
	LD A,(BALL1)
	JR URBALL0
;
URBALL2	
	LD A,(BALL2)
 	AND A
 	JR Z,URBALL3
	
	ld A,#0D	;dec C
	ld (URBALL1A_Xdec),A
	LD A,(BALL2)
	
	LD BC,BALL2P
	LD HL,BALL2X
	LD DE,#C0C ;12*256+12
 	JR URBALL0
;
URBALL3	
	LD A,(BALL3)
 	AND A
 	JP Z,JEWELS
 	LD BC,BALL3P
	LD HL,BALL3X
	LD DE,#812 ;8*256+18
	
	ld A,#0D	;dec C
	ld (URBALL1A_Xdec),A
	LD A,(BALL3)
	
;
URBALL0	
	PUSH HL:PUSH BC:PUSH DE
	
	EX AF,AF'
 	LD A,(BALLTIME)
 	AND A
 	JR Z,URBALL0B
 	DEC A
 	LD (BALLTIME),A
URBALL0B	
	EX AF,AF'
 	LD BC,(SHIPX)
 	CP 1
	JR NZ,URBALL1A
;
;BALL ON FRONT
;
	INC C
 	INC C
 	INC C
URBALL0A	
	;DEC B
 	LD  (HL),C
	INC L
 	LD (HL),B
 	JP URBALL1X
 ;
;BALL ON REAR
;
URBALL1A   
	CP 2
	JR NZ,URBALL1B
	

.URBALL1A_Xdec
	DEC C
 	DEC C
 	DEC C
 	JR URBALL0A
 ;
URBALL1B	
	LD C,(HL)
 	INC L
 	LD B,(HL)
 	DEC L
 ;
;FREE FLOATING......BEHIND
 ;
	CP 3
	JR NZ,URBALL1C
	CALL URB1B10
;RIGHT..HOW FAR BEHIND ARE WE
	SUB C
 	CP 14
 	JR NC,URB1B2
	CP 13
 	JR Z,UR1B1
	EX AF,AF'
 	CALL URB7D
	CALL URB4
 	EX AF,AF'
 ;TOO NEAR
UR1B1	EX AF,AF'
	LD A,C
 CP 250
 JR NC,PLOP1
  AND A
  JR Z,PLOP1
	DEC C
PLOP1	
	LD DE,#607 ;6*256+7
UR1B1A	EX AF,AF'
 	CP D
	JR NZ,URB1B2
	LD A,(BALLTIME)
 	AND A
 	JR NZ,URB1B9
	DEC L
 	LD (HL),E
 	INC L
 	LD A,32
 	LD (BALLTIME),A
 	JR URB1B9
 ;
;JUST RIGHT !
;
URB1B2	
	CALL URBALL1VEC
URB1B9	
	LD A,(FRAME)
	AND 3
 	JR Z,URB1B9A
	LD BC,(CIRCHOLD1)
 URB1B9A	XOR A
	LD (URB3),A
 	JP URB3A
;
URB1B10	LD (CIRCHOLD1),BC
	LD A,201
	LD (URB3),A
 	LD A,(SHIPX)
	INC A
 	RET
 ;
;FREE FLOATING......IN FRONT
 ;
URBALL1F	
	CP 7
	JP NZ,URBALL1X
	CALL URB1B10
;RIGHT..HOW FAR IN FRONT ARE WE
	LD E,A
	LD A,C
	SUB E
 	CP 11
 	JR NC,URB1B2
	CP 10
 	JR Z,URBALL1F1
	EX AF,AF'
 	CALL URB7C
	CALL URB4
 	EX AF,AF'
 ;TOO NEAR
URBALL1F1	
	EX AF,AF'
	LD A,C
	CP 30
 	JR NC,PLOP2		;JR Z,PLOP2
	INC C
 PLOP2	
	LD DE,#403 ;4*256+3
	JR UR1B1A
 ;
;FIRED OFF FORWARDS
;
URBALL1C	
	CP 4
	JR NZ,URBALL1D
	PUSH BC
 	;INC C
 	;INC C
 	INC C
 	;INC B
 	;CALL CONVERT
	;CALL MBLOB251
	call COLL_CheckPosition
	jr nc,URBALL1C_skip
	cp 32	
.URBALL1C_skip
	ccf
 	POP BC
	LD A,7
	JR NC,URBALL1C1
 	LD A,C
	CP 29			;30
 	JR NC,URBALL1C2
 	INC C
 	LD (HL),C
 	JP URBALL1X
URBALL1C2	
	LD (HL),29
 	LD A,7
URBALL1C1	
	DEC L
	LD (HL),A
 	JP URBALL1X
 ;
;FIRED OFF BACKWARDS
 ;
URBALL1D	
	CP 5
	JR NZ,URBALL1E
	PUSH BC
 	;DEC C
 	;INC B
 	;CALL CONVERT
	;CALL MBLOB251
	call COLL_CheckPosition
	jr nc,URBALL1D_skip
	cp 32	
.URBALL1D_skip
	ccf
 	POP BC
	LD A,3
	JR NC,URBALL1C1
 	LD A,C
	CP 2
	JR C,URBALL1D1
	AND A
 	JR Z,URBALL1D1
	DEC C
 	LD (HL),C
 	JP URBALL1X
 URBALL1D1	
	LD (HL),1
	LD A,3
	JR URBALL1C1
;
;COMING BACK TO DADDY !!!!
 ;
URBALL1E	
	CP 6
	JR NZ,URBALL1F
	LD A,(FRAME)
	AND 3
 	JP NZ,URBALL1X
URBALL1VEC	
	INC B
 	INC C
 ;
	LD E,0
	LD A,(SHIPY)
	CP B
	JR Z,URB1E6
 	JR C,URB1E5
 	CALL URB7A
	CALL URB4
 	JR URB1E6
URB1E5	
	CALL URB7B
	CALL URB4
URB1E6	
	LD A,(SHIPX)
	CP C
	JR Z,URB1E9
 	JR C,URB1E7
 	CALL URB7C
	CALL URB4
 	JR URB1E9
 URB1E7	CALL URB7D
	CALL URB4
 ;
URB1E9	
	CALL URB7A
	CALL URB5
 	CALL URB7B
	CALL URB5
 	CALL URB7C
	CALL URB5
 	CALL URB7D
	CALL URB5
 	DEC B
 	DEC C
 	LD A,C
	CP 254
	JR C,URB1E9A
	LD C,0
URB1E9A	
	LD A,B
 	CP 255
	JR NZ,URB3
	INC B
 ;
URB3	NOP
URB3A	
	LD (HL),C
	INC L
 	LD (HL),B
 	JR URBALL1X
 ;
URB5	PUSH BC
 	LD (URB5A),A
	LD A,D
	LD (URB5C),A
URB5A	
	NOP
	;CALL CONVERT
	;CALL MBLOB251
	call COLL_CheckPosition
	jr nc,URB5A_skip
	cp 32	
.URB5A_skip
	ccf
 	POP BC
	RET C
 URB5C	
	NOP
	RET
 ;
URB7A	LD A,4   ;INC B
	LD D,5
	RET
 URB7B	LD A,5   ;DEC B
	LD D,4
	RET
 URB7C	LD A,12  ;INC C
	LD D,13
 	RET
 URB7D	LD A,13  ;DEC C
	LD D,12
 	RET
 ;
URB4	
	PUSH DE:PUSH BC
	LD (URB4A),A
	LD (URB4A+1),A
	LD (URB4B),A
	LD A,D
	LD (URB4C),A
URB4A	
	NOP
	NOP
 	;CALL CONVERT
	;CALL MBLOB251
	call COLL_CheckPosition
	jr nc,URB4A_skip
	cp 32	
.URB4A_skip
	ccf
 	POP BC
	JR NC,URB4C0
URB4B	
	NOP
	JR URB4D
URB4C0	LD A,(URB4C)
	CP 6
	JR C,URB4D
URB4C	
	NOP
URB4D	
	POP DE
 	RET
 ;
;EVERYTHING SORTED OUT
 ;NOW ROTATE BALL.
;
.URBALL1X	
	POP DE:POP HL
 	LD A,(HL)
 	INC A
 	CP D
	JR NZ,URBALL1Y
	XOR A
 URBALL1Y	
	LD (HL),A
 	SRL A
 	ADD E
 	LD L,A
;
;CHECK FOR BALL 2 REVERSE ARMS
 ;
	;inc B ;lower module because new ship design
	
	push BC
 
	LD A,(BALL2)
	CP 2
	LD A,L
	JR NZ,URBALL1Q
	
	CALL USPM
	
 	JR URBALL1R
 ;
URBALL1Q
	;break
	CALL USPN
 ;
;NOW SEE IF OK TO CONNECT TO SHIP
;	
URBALL1R
	pop BC

	;ld A,(SHIPX)
	;cp C
	;jr nz,URB99
	;ld A,(SHIPY)
	;cp B
	;jr nz,URB99
	ld A,(MOD_ONSHIP)	;collision ?
	or A
	jr z,URB99
	
	;LD A,(COLLP)
	;AND A
 	;JR Z,URB99
	;LD HL,COLLTABLE
 	;LD B,A
URBALL1Z	
	;LD A,(HL)
 	;CP 6
	;JR C,URB1
 	;INC HL
	;DJNZ URBALL1Z
 	;JR URB99
;
;YEP..DO CONNECT LOGIC
 ;
URB1	
	POP HL
	LD C,(HL)
 	INC C
 	DEC L
 	LD A,(SHIPX)
	LD B,1
	CP C
	JR C,URB2
 	INC B
URB2	
	LD A,B
	LD (HL),A
 	LD (ATTATCH),A
 ;LD HL,20*256+FULL+1
  ;CALL BEEP
	ld A,sfx_attach
	call SND_SfxPlay
  
 	PUSH DE
 ;
URB99	
	POP DE
 	;CALL KILL_1
 ;
.JEWELS	
	;CALL CLEARCOL
 	;CALL JEWEL1
 	;CALL CLEARCOL
 	;CALL JEWEL2
 	;CALL CLEARCOL
 	;JP URPILL1
	
URPILL1	
	ld A,#F1	;player one pills
	ld (MASTER),A

	LD A,(PILL1)
 	AND A
 	JR Z,URPILL2
	CALL URPILL9
	DEC D
 	DEC D
 	DEC D
 	;DEC D
 	LD (PILL1X),DE
	LD B,8
URPILL1X	
	LD HL,PILL1P
	CALL URPILL6
URPILL1XA	
	LD BC,(PILL1X)
 	CALL USPN
 	;CALL KILL_1
 ;
URPILL2	
	LD A,(PILL2)
 	AND A
 	RET Z
 	CALL URPILL9
	INC D
 	INC D
 	INC D
 	LD (PILL2X),DE
	LD B,8
URPILL2X	
	LD HL,PILL2P
	CALL URPILL6
URPILL2XA	
	LD BC,(PILL2X)
 	CALL USPF
 	;CALL KILL_1
 	RET
 ;
URPILL6	
	LD A,(HL)
	INC A
 	CP 16
 	JR NZ,URPILL6A
	XOR A
 URPILL6A	
	LD (HL),A
 	SRA A
 	ADD 22
	ADD B
 	RET
 ;
URPILL7	
	LD A,(HL)
	INC A
 	CP 8
	JR NZ,URPILL7A
	XOR A
 URPILL7A	
	LD (HL),A
 	LD B,0
	LD C,A
	LD HL,JEWELTYPE
 	ADD HL,BC
 	LD A,(HL)
 	RET
 ;
URPILL8	
	LD B,0
 	LD A,(TILESCROLL)
 	AND A
 	RET NZ
	LD A,(HL)
 	DEC A
 	LD (HL),A
 	CP 254
	RET
 ;
URPILL9	
	LD A,(FRAME)
 	AND 3
 	ADD A
 	LD HL,PILLBUFF
	ADD L
 	LD L,A
	LD DE,(SHIPX)
 	LD (HL),E
 	INC L
 	LD (HL),D
 	INC L
 	LD A,(FRAME)
	AND 3
 	CP 3
	JR NZ,URPILL9A
	LD HL,PILLBUFF
URPILL9A	LD E,(HL)
 	INC L
 	LD D,(HL)
 	INC E
 	RET
	
.JEWELTYPE		DEFB 107,108,109,110,111
				DEFB 110+128,109+128,108+128