indrawbox
	;plot a box on the screen
	lea	boxes,a5
	clr.l	d0
	move.b	pencol1,d0
	rol.l	#1,d0
	add.l	d0,a5
	bsr	plotsmallbox
	clr.l	d4
	move.b	pencol1,d4
	bsr	plotadot

	bsr	checksame	;are src,dst the same as charnum
	
	bsr	grab
	rts

indrawbox2
	;plot a box on the screen
	lea	boxes,a5
	clr.l	d0
	move.b	pencol2,d0
	rol.l	#1,d0
	add.l	d0,a5
	bsr	plotsmallbox
	clr.l	d4
	move.b	pencol2,d4
	bsr	plotadot
	bsr	checksame
	bsr	grab
	rts
plotmaskbox
	move.l	edbase,a4
	add.l	#2,a4
	clr.l	d0
	clr.l	d1
	move.w	ypos,d1
	move.w	xpos,d0

	bsr	calcxy
	add.l	d1,a4
	move.w	d2,mini

	bsr	waitblit

	move.w	mini,d2
	or.w	#$0fce,d2


	move.w	#$ffff,$dff044	;fwm
	move.w	#$ffff,$dff046	;lwm
	move.w	#8-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#8-4,$dff062	;mod b
	move.w	#44-4,$dff060	;mod C
	move.w	#44-4,$dff066	;mod D



	move.w	d2,$dff040
	move.w	mini,$dff042
	move.l	#maskboxes+4,$dff050	;get gfk A
	move.l	#maskboxes,$dff04c	;get mask B
	move.l	a4,$dff048	;src C	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(8*64*5)+2,$dff058

	rts


plotsmallbox
	move.l	edbase,a4
	add.l	#2,a4
	clr.l	d0
	clr.l	d1
	move.w	ypos,d1
	move.w	xpos,d0

plotsmallbox2
	bsr	calcxy
	add.l	d1,a4
	move.w	d2,mini

	move.l	a5,a6
	bsr	waitblit
	bsr	clearsbox
	bsr	waitblit
	move.l	a6,a5
	

	bsr	waitblit

	move.w	mini,d2
	or.w	#$0dfc,d2


	move.w	#$ffff,$dff044	;fwm
	move.w	#$0000,$dff046	;lwm
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#44-4,$dff062	;mod b
	move.w	#44-4,$dff066	;mod D



	move.w	d2,$dff040
	move.w	#$00,$dff042
	move.l	a5,$dff050	;get mask A
	move.l	a4,$dff04c	;src B	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(8*64*5)+2,$dff058

	rts

clearsbox
	move.l	#boxes+(31*2),a5
	or.w	#%0000110100001100,d2
	move.w	#$ffff,$dff044	;fwm
	move.w	#$0000,$dff046	;lwm
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#44-4,$dff062	;mod b
	move.w	#44-4,$dff066	;mod D

	move.w	d2,$dff040
	move.w	#$00,$dff042
	move.l	a5,$dff050	;get mask A
	move.l	a4,$dff04c	;src B	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(8*64*5)+2,$dff058

	rts

drawbox
	
;	move.w	#$ff0,$dff180

	 
	move.l	mousepos,a4
	
	move.w	#$ffff,$dff044	;fwm
	move.w	#$0000,$dff046	;lwm
	bsr	waitblit
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#44-4,$dff062	;mod b
	move.w	#44-4,$dff066	;mod D

	move.w	mini,$dff040
	move.w	#$00,$dff042
	lea	boxes+(2*32),a5	;bob data
	move.l	a5,$dff050	;get mask A
	move.l	a4,$dff04c	;src B	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(9*64*5)+2,$dff058
	rts
drawbigbox
	
;	move.w	#$ff0,$dff180

	 
	move.l	mousepos,a4
	
	move.w	#$ffff,$dff044	;fwm
	move.w	#$f000,$dff046	;lwm
	bsr	waitblit
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#80-4,$dff062	;mod b
	move.w	#44-4,$dff060	;mod c
	move.w	#44-4,$dff066	;mod D

	move.w	#%0000111111110010,$dff040
;	move.w	#$09f0,$dff040
	;00100010	b&C
	;11110000	or A
	move.w	#$00,$dff042
	lea	boxes+(2*34),a5	;bob data
	move.l	a5,$dff050	;get mask A
	move.l	#boxes+(2*36),$dff04c	;src B	bob
	move.l	a4,$dff048	;src C
	move.l	a4,$dff054	;dst D	screen
	move.w	#(17*64*5)+2,$dff058 
	rts

restore
	
	move.l	#$ffffffff,$dff044
	move.w	#0,$dff042
	move.l	#temp,a2	;source A temproy screen
	move.l	mousepos,a3	;dest D normal scrren			
	move.w	#44-4,$dff066	;mod D
	move.w	#0,$dff064	;mod A
	move.l	a2,$dff050	;src A
	move.l	a3,$dff054	;dst D
	move.w	#$09f0,$dff040	;bltcon0!!!!!
	move.w	#(21*64*5)+2,$dff058	;bltsize 
	
	rts
grab
	move.l	#$ffffffff,$dff044
	move.w	#0,$dff042


	move.l	edbase,a4
	add.l	#2,a4

	clr.l	d0
	clr.l	d1
	move.w	xpos,d0
	move.w	ypos,d1

	bsr	calcxy

	add.l	d1,a4
	or.w	#$0dfc,d2
	move.w	d2,mini
	move.l	a4,mousepos

	;bsr	waitblit
	move.l	mousepos,a2	;source A behind eggert
	move.l	#temp,a3	;dest D tmepscr		
	move.w	#0,$dff066	;mod D
	move.w	#44-4,$dff064	;mod A
	move.l	a2,$dff050	;src A
	move.l	a3,$dff054	;dst D
	move.w	#$09f0,$dff040	;bltcon0!!!!!
	move.w	#(21*64*5)+2,$dff058	;bltsize 
	
	rts
grabbig
	move.l	edbase,a4
	add.l	#2,a4

grabbig2
	move.l	#$ffffffff,$dff044
	move.w	#0,$dff042


	clr.l	d0
	clr.l	d1
	move.w	xpos,d0
	move.w	ypos,d1
	
	and.w	#$fff0,d0		;kill all lower bits
	and.w	#$fff0,d1		;kill all lower bits

	bsr	calcxy

	sub.l	#4*(5*44),d1
	add.l	d1,a4
	or.w	#$0dfc,d2
	move.w	d2,mini
	move.l	a4,mousepos

	;bsr	waitblit
	move.l	mousepos,a2	;source A behind eggert
	move.l	#temp,a3	;dest D tmepscr		
	move.w	#0,$dff066	;mod D
	move.w	#44-4,$dff064	;mod A
	move.l	a2,$dff050	;src A
	move.l	a3,$dff054	;dst D
	move.w	#$09f0,$dff040	;bltcon0!!!!!
	move.w	#(21*64*5)+2,$dff058	;bltsize 
	
	rts

	;Wait for him to take his finger off
waitlmb	
	bsr	vblank2
	btst	#6,$bfe001
	beq	waitlmb
	rts

	
makeslist
	move.l	#pointer,d0		;pointer to sprite data list
	move.w	d0,spr0l
	swap	d0
	move.w	d0,spr0h
	move.l	#pointer2,d0	;pointer to sprite data list
	move.w	d0,spr1l
	swap	d0
	move.w	d0,spr1h
	move.l	#sprbox,d0		;pointer to sprite data list
	move.w	d0,spr2l
	swap	d0
	move.w	d0,spr2h
	move.l	#sprbox2,d0		;pointer to sprite data list
	move.w	d0,spr3l
	move.w	d0,lspr3l
	swap	d0
	move.w	d0,spr3h
	move.w	d0,lspr3h
	move.l	#slist2,d0	;pointer to sprite data list
	move.w	d0,spr4l
	move.w	d0,lspr4l
	swap	d0
	move.w	d0,spr4h
	move.w	d0,lspr4h
	move.l	#slist2,d0	;pointer to sprite data list
	move.w	d0,spr5l
	move.w	d0,lspr5l
	swap	d0
	move.w	d0,spr5h
	move.w	d0,lspr5h
	move.l	#slist2,d0	;pointer to sprite data list
	move.w	d0,spr6l
	move.w	d0,lspr6l
	swap	d0
	move.w	d0,spr6h
	move.w	d0,lspr6h
	move.l	#slist2,d0	;pointer to sprite data list
	move.w	d0,spr7l
	move.w	d0,lspr7l
	swap	d0
	move.w	d0,spr7h
	move.w	d0,lspr7h

	;setup for level editor
	move.l	#pointer,d0		;pointer to sprite data list
	move.w	d0,lspr0l
	swap	d0
	move.w	d0,lspr0h
	move.l	#pointer2,d0	;pointer to sprite data list
	move.w	d0,lspr1l
	swap	d0
	move.w	d0,lspr1h
	move.l	#sprbox,d0		;pointer to sprite data list
	move.w	d0,lspr2l
	swap	d0
	move.w	d0,lspr2h
	move.l	#sprbox2,d0	;pointer to sprite data list
	move.w	d0,lspr3l
	swap	d0
	move.w	d0,lspr3h


	rts

show_gfx_scr
	
	move.w	#5-1,d7		;number of bitplanes
	move.l	gfkmem,d0
	lea	bit1h,a0
.show1
	move.w	d0,4(a0)	;copy in low
	swap	d0
	move.w	d0,(a0)		;copy in high

	swap	d0
	add.l	#44,d0		;next bitplane (clever blit)
	add.l	#8,a0		;next pointer in clist
	dbra	d7,.show1
	rts
show_lvl_scr
	;**** the level editor SCREEN ****	
	move.w	#5-1,d7		;number of bitplanes
	move.l	lvlmem,d0		;IS RIGHT!!!!!!!
	lea	lvlA1h,a0
.show1
	move.w	d0,4(a0)	;copy in low
	swap	d0
	move.w	d0,(a0)		;copy in high

	swap	d0
	add.l	#44,d0		;next bitplane (clever blit)
	add.l	#8,a0		;next pointer in clist
	dbra	d7,.show1


	rts

gosprite

	
	move.w	msxpos,d0		;x pos
	sub.w	#16,d0
	move.w	msypos,d1		;y pos	;okay
	move.w	#16,d2		;height of sprite (poetry!)
	lea	pointer,a0	;pointer to sprite structure
	bsr	gospr2
	
	move.l	pointer,pointer2	;copy spr1 ctrl to spr2

	rts

gospr2
	
	add.w	#$60,d0		;FRIG X Just a little


	move.l	#0,(a0)		;kill Controll words

	move.w	d0,d3		;copy d0 (x0)
	 
	and.w	#%1,d3		;kill all but Lowest bit
	move.w	d3,2(a0)	;DONE H0			*

	and.w	#%1111111111111110,d0
	ror.w	#1,d0
	move.w	d0,(a0)		;DONE H1-H8			*

	move.w	d1,d3
	and.w	#%0000000100000000,d3	;kill all but E8
	ror.w	#6,d3
	or.w	d3,2(a0)	;DONE E8			*

	move.w	d1,d3
	and.w	#%1111111011111111,d3	;Kill E8 Bit
	rol.w	#8,d3		;Shift Im lieft
	or.w	d3,(a0)		;DONE E0-E7			*

	add.w	d2,d1		;add height
	move.w	d1,d3
	and.w	#%0000000100000000,d3	;Kill all but L8
	ror.w	#7,d3
	or.w	d3,2(a0)	;DONE L8			*	

	move.w	d1,d3
	and.w	#%1111111011111111,d3	;Kill L8 Bit
	rol.w	#8,d3		;Shift Im lieft
	bset	#7,d3		;attach bit
	or.w	d3,2(a0)	;DONE L0-L7			*
	rts		

	




gomouse:
;*****************************************************************************
;edits made to this routine!!!!!
;*****************************************************************************


	clr.l	d6
	clr.l	d7
	move.w	oldpos,d7
	move.l	#$dff000,a6
	move.w	joy0dat(a6),d6
	move.w	d6,oldpos	;copy to oldpos

	move.w	d7,d0		;oldpos
	and.w	#$00ff,d0	;kill top byte
	move.w	d6,d1		;newpos
	and.w	#$00ff,d1	;kill top byte
	bsr	xmov		;check x movement

	cmp.w	#24+8,msxpos
	bgt	nox1
	move.w	#24+8,msxpos

nox1
	cmp.w	#320+(1*16)+7+8,msxpos
	blt	nox2
	move.w	#320+(1*16)+7+8,msxpos
nox2

	move.w	d7,d0		;oldpos
	and.w	#$ff00,d0	;kill top byte
	move.w	d6,d1		;newpos
	and.w	#$ff00,d1	;kill top byte
	bsr	ymov		;check y movement

	cmp.w	#37,msypos
	bgt	noy1
	move.w	#37,msypos

noy1
	cmp.w	#255+37,msypos
	blt	noy2
	move.w	#255+37,msypos
noy2

	rts			;




xmov	cmp.w	d0,d1
	bne	movementx
				;hasnt moved in X direction
	rts			;or bra updown
movementx
	sub.w	d0,d1		;differance in d1
	cmp.w	#127,d1		;greater than 127 overflow
	bgt	flowy
	cmp.w	#-127,d1	;less than -127 underflow
	blt	flowy
	asr	#1,d1
	add.w	d1,msxpos		;save new xpos if nowt occurs
	rts	

	
ymov	cmp.w	d0,d1
	bne	movementy
				;hasnt moved in y direction
	rts			;or bra updown
movementy
	ror.w	#8,d0		;get the data into the
	ror.w	#8,d1		;bottom 8 bits yeh!!!
	sub.w	d0,d1		;differance in d1
	cmp.w	#127,d1		;greater than 127 overflow
	bgt	flowy
	cmp.w	#-127,d1	;less than -127 underflow
	blt	flowy
	asr	#1,d1
	add.w	d1,msypos		;save new ypos if nowt occurs
	
flowy	rts

doxposr
	and.w	#$00ff,d1
	asr	#1,d1
	add.w	d1,msxpos
	rts



eortopbox
	
;	move.w	#$ff0,$dff180

	move.w	#$ffff,$dff044	;fwm
	move.w	#$0000,$dff046	;lwm
	bsr	waitblit
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#44-4,$dff062	;mod b
	move.w	#44-4,$dff066	;mod D

	move.w	d2,d7
	and.w	#$f000,d7
	or.w	#%0000110100111100,d7
	move.w	d7,$dff040
	move.w	#$00,$dff042
	lea	boxes+(2*32),a5	;bob data
	move.l	a5,$dff050	;get mask A
	move.l	a4,$dff04c	;src B	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(1*64*5)+2,$dff058
	rts
eorsidebox
	
;	move.w	#$ff0,$dff180

	move.w	#$8000,$dff044	;fwm
	move.w	#$0000,$dff046	;lwm
	bsr	waitblit
	move.w	#80-4,$dff064	;mod A .gfx map = 6 bytes. ball = 4
	move.w	#44-4,$dff062	;mod b
	move.w	#44-4,$dff066	;mod D

	move.w	d2,d7
	and.w	#$f000,d7
	or.w	#%0000110100111100,d7
	move.w	d7,$dff040
	move.w	#$00,$dff042
	lea	boxes+(2*32),a5	;bob data
	move.l	a5,$dff050	;get mask A
	move.l	a4,$dff04c	;src B	bob
	move.l	a4,$dff054	;dst D	screen
	move.w	#(9*64*5)+2,$dff058
	rts
