

* This table is conditioned by the various function
* selection gadgets by calling SetButtons() below with
* an entry value in d0.


ButtonInfo	dc.w	0,0,0,0,0,0



* These entry points for the function gadgets select a function
* & set the appropriate bits in the file_flags before calling
* SetButtons() below.


FNLoad		moveq	#0,d0
		bra.s	SetButtons

FNSave		moveq	#1,d0
		bra.s	SetButtons

FNRename		moveq	#2,d0
		bra.s	SetButtons

FNDelete		moveq	#3,d0
		bra.s	SetButtons

FNFormat		moveq	#4,d0
		bra.s	SetButtons

FNMakeDir	moveq	#5,d0		;this one just falls through


* SetButtons(a6,d0)
* a6 = ptr to main program variables
* d0 = entry value from gadget

* Condition the buttons for function selection.
* This allows the user to press Load, say, then
* press Save and have Load released. Note that
* the gadget responsible for calling this routine
* has its own state left unchanged.

* 'Parent' gadget skipped.

* d0-d3/a0-a2 corrupt


SetButtons	move.w	d0,-(sp)		;save gadget number

		neg.w	d0
		addq.w	#7,d0

		moveq	#0,d1		;this ensures all other
		bset	d0,d1		;function flags are
		and.b	d1,file_flag1(a6)	;killed off

		bchg	d0,file_flag1(a6)	;set function flags

		lea	ND_Load(pc),a1
		move.l	dp_window1(a6),a0
		moveq	#7,d0		;unlink this many

		CALLINT	RemoveGList

		move.w	(sp)+,d0

		move.w	#SELECTED,d1	;toggle flag
		not.w	d1		;this kills SELECTED off

		lea	ButtonInfo(pc),a0	;ptr to change table
		moveq	#6,d2		;no. to do

SBut_1		move.w	d1,d3		;copy turnoff mask
		tst.w	d0		;this gadget called it?
		bne.s	SBut_2		;skip if not
		moveq	#-1,d3		;else use this mask
SBut_2		move.w	d3,(a0)+		;pop in mask
		subq.w	#1,d0		;find next func gadget
		subq.w	#1,d2		;done them all?
		bne.s	SBut_1		;back if not

		lea	ND_Load(pc),a0	;point to 1st gadget
		lea	ND_Parent(pc),a1	;this one to skip
		lea	ButtonInfo(pc),a2	;mask table
		moveq	#6,d0		;no. to do

SBut_3		cmp.l	a1,a0		;hit skip gadget?
		bne.s	SBut_4		;skip if not
		move.l	(a0),a0		;else pick next gadget

SBut_4		move.w	gg_Flags(a0),d1	;get current flags
		and.w	(a2)+,d1		;kill off SELECTED?
		move.w	d1,gg_Flags(a0)

		move.l	(a0),a0		;get next gadget
		subq.w	#1,d0		;done them all?
		bne.s	SBut_3		;back if not

		lea	ND_Load(pc),a1
		move.l	dp_window1(a6),a0
		sub.l	a2,a2
		moveq	#4,d0
		moveq	#7,d1

		CALLINT	AddGList		;link gadgets back in

		lea	ND_Load(pc),a0
		move.l	dp_window1(a6),a1
		sub.l	a2,a2
		moveq	#7,d0

		CALLINT	RefreshGList

		rts


* CancelButtons(a6)
* a6 = ptr to main program variables
* If any of the function gadgets are set, this clears them
* upon pressing the Cancel gadget.

* d0-d2/a0-a2 corrupt


CancelButtons	lea	ND_Load(pc),a1
		move.l	dp_window1(a6),a0
		moveq	#7,d0

		CALLINT	RemoveGList

		move.w	#SELECTED,d0
		not.w	d0

		lea	ND_Load(pc),a0
		lea	ND_Parent(pc),a1
		moveq	#6,d1

CBT_1		cmp.l	a0,a1		;hit Parent gadget?
		bne.s	CBT_2		;skip if not
		move.l	(a0),a0		;else get next gadget

CBT_2		and.w	d0,gg_Flags(a0)	;kill SELECTED state

		move.l	(a0),a0		;get next gadget
		subq.l	#1,d1		;done them all?
		bne.s	CBT_1

		lea	ND_Load(pc),a1
		move.l	dp_window1(a6),a0
		sub.l	a2,a2
		moveq	#4,d0
		moveq	#7,d1

		CALLINT	AddGList

		lea	ND_Load(pc),a0
		move.l	dp_window1(a6),a1
		sub.l	a2,a2
		moveq	#7,d0

		CALLINT	RefreshGList

		clr.b	file_flag1(a6)

		rts


* FNEnact(a6)
* a6 = ptr to main program variables

* Enact the function selected, then clear all the gadgets a la
* the Cancel gadget.

* ASSUME ALL REGISTERS CORRUPT!


FNEnact		move.b	file_flag1(a6),d0	;get function flags

		lsl.b	#1,d0
		bcc.s	FNEN_1
		bsr	LoadFile
		bra.s	FNEN_6

FNEN_1		lsl.b	#1,d0
		bcc.s	FNEN_2
		bsr	SaveFile
		bra.s	FNEN_6

FNEN_2		lsl.b	#1,d0
		bcc.s	FNEN_3
		bsr	UserRename
		bra.s	FNEN_6

FNEN_3		lsl.b	#1,d0
		bcc.s	FNEN_4
		bsr	UserDelete
		bra.s	FNEN_6

FNEN_4		lsl.b	#1,d0
		bcc.s	FNEN_5
		bsr	UserFormat
		bra.s	FNEN_6

FNEN_5		lsl.b	#1,d0
		bcc.s	FNEN_6
		bsr	UserMakeDir

FNEN_6		bsr	CancelButtons
		rts


* This code is called whenever a DISKINSERTED or DISKREMOVED
* IDCMP message is received. It checks which floppy disc drive
* (Drive 0, Drive 1) 


OutDrive		nop
		rts


InDrive		nop
		rts




