b_wd:		equ	0
b_ht:		equ	2
plane_ct:	equ	4
fg_col:		equ	6
bg_col:		equ	8
op_tab:		equ	10
s_xmin:		equ	14
s_ymin:		equ	16
s_form:		equ	18
s_nxwd:		equ	22
s_nxln:		equ	24
s_nxpl:		equ	26
d_xmin:		equ	28
d_ymin:		equ	30
d_form:		equ	32
d_nxwd:		equ	36
d_nxln:		equ	38
d_nxpl:		equ	40
p_addr:		equ	42
p_nxln:		equ	46
p_nxpl:		equ	48
p_mask:		equ	50
space:		equ	52
numpanels:	equ	2
panel1:		equ	0
panel2:		equ	1


start:
	lea	p1dots,a1
	bsr	dobuttonsupdown

	clr.w	-(sp)
	trap	#1

*****************************************************************
*	On entry a1 points to the current button .		*
*	run through the list of buttons that this one deselects	*
*	and raise them all. Then select this one.		*
*****************************************************************
dobuttonsupdown:
	movem.l	d0-d1/a1,-(sp)		;save this for later
*	move.w	#-1,mouseonoff		;turn the mouse off
*	bsr	waitvbl
	lea	buttondeselects(a1),a0
dbuttonsup:
	move.l	(a0)+,d0
	beq	dbudover	;have we finished the list to raise
	move.l	d0,a2		;get address of button
	tst.w	buttonselected(a2)
	beq	dbuttonsup	;was it actually down ?
	lea	buttonbltblk,a6
	move.w	buttonwidth(a2),b_wd(a6)
	move.w	buttonheight(a2),b_ht(a6)
	move.w	#8,plane_ct(a6)
	move.w	#1,fg_col(a6)
	move.w	#0,bg_col(a6)
	move.l	#$07070707,op_tab(a6)
	move.w	buttonpartx(a2),s_xmin(a6)
	move.w	buttonparty(a2),s_ymin(a6)
	move.l	#panel,s_form(a6)
	move.w	#2,s_nxwd(a6)
	move.w	#320,s_nxln(a6)
	move.w	#16,s_nxpl(a6)
	move.w	buttonx(a2),d_xmin(a6)
	move.w	buttony(a2),d_ymin(a6)
	move.l	#panel,d_form(a6)
	move.w	#2,d_nxwd(a6)
	move.w	#320,d_nxln(a6)
	move.w	#16,d_nxpl(a6)
	move.l	#0,p_addr(a6)
	movem.l	a0-a2,-(sp)
*	dc.w	$a007
	movem.l	(sp)+,a0-a2
	move.w	#-1,buttonselected(a2)	;set the select flag to not
	bra	dbuttonsup
dbudover:

	move.l	a1,a2		;get the hit button again
	tst.w	buttonselectable(a2)
	beq	notselectable
	move.w	#1,buttonselected(a2)	;set the select flag to selected

	lea	buttonbltblk,a6
	move.w	buttonwidth(a2),b_wd(a6)
	move.w	buttonheight(a2),b_ht(a6)
	move.w	#8,plane_ct(a6)
	move.w	#1,fg_col(a6)
	move.w	#0,bg_col(a6)
	move.l	#$07070707,op_tab(a6)
	move.w	buttonpartx(a2),s_xmin(a6)
	move.w	buttonparty(a2),s_ymin(a6)
	move.w	buttonheight(a2),d0
	add.w	d0,s_ymin(a6)		;make it blit the selected version
	move.l	#panel,s_form(a6)
	move.w	#2,s_nxwd(a6)
	move.w	#320,s_nxln(a6)
	move.w	#16,s_nxpl(a6)
	move.w	buttonx(a2),d_xmin(a6)
	move.w	buttony(a2),d_ymin(a6)
	move.l	#panel,d_form(a6)
	move.w	#2,d_nxwd(a6)
	move.w	#320,d_nxln(a6)
	move.w	#16,d_nxpl(a6)
	move.l	#0,p_addr(a6)
	movem.l	a0-a2,-(sp)
*	dc.w	$a007
	movem.l	(sp)+,a0-a2
notselectable:
	movem.l	(sp)+,d0-d1/a1
	rts


buttonbltblk:
	ds.b	76



buttonx:	equ	0
buttony:	equ	2
buttonpartx:	equ	4
buttonparty:	equ	6
buttonwidth:	equ	8
buttonheight:	equ	10
buttonselectable:	equ	12
buttonlroutine:	equ	14
buttonrroutine:	equ	18
buttonselected:	equ	22
buttondeselects:equ	24

p1drag:
	dc.w	264,5	;x,y on panel screen
	dc.w	0,0	;x,y of unselected part(not needed here cause button does not depress)
	dc.w	55,24	;xwidth,yheight
	dc.w	0	;doesn't depress
	dc.l	0	;routine to jump to on left button
	dc.l	0		;routine for right button
	dc.w	0	;selected toggle
	dc.l	0	;null terminated list of buttons this one raises (none)
p1dots:
	dc.w	16,5	;x,y on panel screen
	dc.w	0,161	;x,y of unselected part
	dc.w	23,24	;xwidth,yheight
	dc.w	1	;does depress
	dc.l	0	;routine to jump to on left button
	dc.l	0		;routine for right button
	dc.w	0	;selected toggle
	dc.l	0	;null terminated list of buttons this one raises


panel:
	ds.b	32000