

* Code include file for handling "New Crossword" requester.
* Contains all the routines linked to the CWNewReq.i gadgets.


* BusyWait(d0)
* d0 = wait time

* d0 corrupt

BusyWait		subq.l	#1,d0
		bne.s	BusyWait
		rts


* ResetAcross(a6)

* a6 = ptr to main program variables

* Set Across size string gadget.
* Called by LOTS of routines!

* d0-d2/a0-a2 corrupt


ResetAcross	lea	NC_AC(pc),a1	;ptr to gadget
		move.l	mw_handle(a6),a0	;ptr to main window handle

		moveq	#1,d0		;remove 1 gadget
		CALLINT	RemoveGList

		lea	NC_AC(pc),a0
		move.l	gg_SpecialInfo(a0),a0	;ptr to si_ struct
		move.l	si_Buffer(a0),a0		;ptr to buffer to alter

		move.w	tmp_across(a6),d0		;value to use
		moveq	#2,d1			;fieldwidth

		bsr	ItoA			;int to ASCII string

		lea	NC_AC(pc),a1
		move.l	mw_handle(a6),a0
		move.l	ThisReq(a6),a2

		move.l	rhb_Requester(a2),a2

		moveq	#7,d0			;8th position in
		moveq	#1,d1			;gadget list, 1 gadget

		CALLINT	AddGList			;add it in

		lea	NC_AC(pc),a0
		move.l	mw_handle(a6),a1
		move.l	ThisReq(a6),a2

		move.l	rhb_Requester(a2),a2

		moveq	#1,d0

		CALLINT	RefreshGList	;now display new status

		rts


* ResetDown(a6)

* a6 = ptr to main program variables

* Set Down size string gadget.
* Called by LOTS of routines!


ResetDown	lea	NC_DN(pc),a1	;ptr to gadget
		move.l	mw_handle(a6),a0	;ptr to main window handle

		moveq	#1,d0		;remove 1 gadget
		CALLINT	RemoveGList

		lea	NC_DN(pc),a0
		move.l	gg_SpecialInfo(a0),a0	;ptr to si_ struct
		move.l	si_Buffer(a0),a0		;ptr to buffer to alter

		move.w	tmp_down(a6),d0		;value to use
		moveq	#2,d1			;fieldwidth

		bsr	ItoA			;int to ASCII string

		lea	NC_DN(pc),a1
		move.l	mw_handle(a6),a0
		move.l	ThisReq(a6),a2

		move.l	rhb_Requester(a2),a2

		moveq	#7,d0			;8th position in
		moveq	#1,d1			;gadget list, 1 gadget

		CALLINT	AddGList			;add it in

		lea	NC_DN(pc),a0
		move.l	mw_handle(a6),a1
		move.l	ThisReq(a6),a2

		move.l	rhb_Requester(a2),a2

		moveq	#1,d0

		CALLINT	RefreshGList	;now display new status

		rts


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

* Sets temporary across size for provisional new grid
* to be converted to REAL across size later.

* Gets info from Across string gadget

* d0/a0 corrupt


SetAcross	lea	NC_AC(pc),a0	;get ptr to NC_AC gadget

		move.l	gg_SpecialInfo(a0),a0

		move.l	si_LongInt(a0),d0

		move.w	d0,tmp_across(a6)

		rts


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

* Sets temporary down size for provisional new grid
* to be converted to REAL down size later.

* Gets info from Down string gadget

* d0/a0 corrupt


SetDown		lea	NC_DN(pc),a0	;get ptr to NC_DN gadget

		move.l	gg_SpecialInfo(a0),a0

		move.l	si_LongInt(a0),d0

		move.w	d0,tmp_down(a6)

		rts


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

* Change across size of new grid while in contact
* with the horizontal change gadget.

* d0-d2/a0-a2/a5 corrupt


ChangeAcross	lea	NC_HPot(pc),a0		;ptr to gadget
		move.l	gg_SpecialInfo(a0),a0	;ptr to PropInfo
		move.l	a0,a5			;make permanent ptr

CAC_1		moveq	#0,d0
		move.l	d0,d1

		move.w	pi_HorizPot(a5),d0
		move.w	pi_HorizBody(a5),d1

		divu	d1,d0	;create across value

		cmp.w	#MINSQ_X,d0	;less than minimum value?
		bcc.s	CAC_2		;skip if not
		moveq	#3,d0		;else set minimum

CAC_2		move.w	d0,tmp_across(a6)	;& set it


* Now alter status of the String gadget associated with the
* Across size of the propsed new grid.


		bsr	ResetAcross


* Now check if PropGadget is still being played with, and if so
* go back & change the value again. Note that the KNOBHIT flag is
* NOT cleared if the slider is released! The mouse button must be
* tested for instead. 


		move.w	pi_Flags(a5),d0	;check PropInfo flags
		and.w	#KNOBHIT,d0	;did we click on the knob?
		beq.s	CAC_Done		;skip if not (clicked in box)

		btst	#6,$BFE001	;mouse button pressed?
		beq.s	CAC_1		;skip back if so

CAC_Done		rts			;finished with this gadget!


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

* Change down size of new grid while in contact
* with the vertical change gadget.

* d0-d2/a0-a2/a5 corrupt


ChangeDown	lea	NC_VPot(pc),a0		;ptr to gadget
		move.l	gg_SpecialInfo(a0),a0	;ptr to PropInfo
		move.l	a0,a5			;make permanent ptr

CDN_1		moveq	#0,d0
		move.l	d0,d1

		move.w	pi_VertPot(a5),d0
		move.w	pi_VertBody(a5),d1

		divu	d1,d0	;create across value
		neg.w	d0
		add.w	#MAXSQ_Y,d0	;inverted gadget Y axis!

		cmp.w	#MINSQ_Y,d0	;less than minimum value?
		bcc.s	CDN_2		;skip if not
		moveq	#3,d0		;else set minimum

CDN_2		move.w	d0,tmp_down(a6)	;& set it


* Now alter status of the String gadget associated with the
* Down size of the propsed new grid.


		bsr	ResetDown


* Now check if PropGadget is still being played with, and if so
* go back & change the value again. Note that the KNOBHIT flag is
* NOT cleared if the slider is released! The mouse button must be
* tested for instead. 


		move.w	pi_Flags(a5),d0	;check PropInfo flags
		and.w	#KNOBHIT,d0	;did we click on the knob?
		beq.s	CDN_Done		;skip if not (clicked in box)

		btst	#6,$BFE001	;mouse button pressed?
		beq.s	CDN_1		;skip back if so

CDN_Done		rts			;finished with this gadget!


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

* Add 1 to current Across size of proposed new grid
* unless size already over the limit.

* d0-d2/a0-a2 corrupt


IncAcross	move.w	tmp_across(a6),d0	;get Across size

		addq.w	#1,d0		;increase Across size

		cmp.w	#MAXSQ_X,d0	;over the limit?
		bhi.s	IncAc_1		;skip if so

		move.w	d0,tmp_across(a6)	;else set new value

IncAc_1		bsr	ResetAcross	;set string gadget
		bsr	SetHVPots1

		move.l	#HANG1,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	IncAcross	;back for more if so

		rts			;else done


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

* add 1 to current Down size of proposed new grid
* unless size already over the limit.

* d0-d2/a0-a2 corrupt


IncDown		move.w	tmp_down(a6),d0	;get Down size

		addq.w	#1,d0		;increase Down size

		cmp.w	#MAXSQ_Y,d0	;over the limit?
		bhi.s	IncDn_1		;skip if so

		move.w	d0,tmp_down(a6)	;else set new value

IncDn_1		bsr	ResetDown	;set string gadget
		bsr	SetHVPots1

		move.l	#HANG1,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	IncDown		;back for more if so

		rts			;else done


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

* Subtract 1 from current Across size of proposed new grid
* unless size already under the limit.

* d0-d2/a0-a2 corrupt


DecAcross	move.w	tmp_across(a6),d0	;get Across size

		subq.w	#1,d0		;increase Across size

		cmp.w	#MINSQ_X,d0	;under the limit?
		bcs.s	DecAc_1		;skip if so

		move.w	d0,tmp_across(a6)	;else set new value

DecAc_1		bsr	ResetAcross	;set string gadget
		bsr	SetHVPots1

		move.l	#HANG1,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	DecAcross	;back for more if so

		rts			;else done


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

* Subtract 1 from current Down size of proposed new grid
* unless size already under the limit.

* d0-d2/a0-a2 corrupt


DecDown		move.w	tmp_down(a6),d0	;get Down size

		subq.w	#1,d0		;increase Down size

		cmp.w	#MINSQ_Y,d0	;over the limit?
		bcs.s	DecDn_1		;skip if so

		move.w	d0,tmp_down(a6)	;else set new value

DecDn_1		bsr	ResetDown	;set string gadget
		bsr	SetHVPots1

		move.l	#HANG1,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	DecDown		;back for more if so

		rts			;else done


* The following routines are linked to the main gadgets
* attached to the BackDrop window. They handle scrolling
* of the crossword grid.


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

* Scroll crossword grid 1 square to the right
* unless extreme right hand edge of grid already hit.
* Checks to see if grid large enough to be scrolled,
* and exits if not.

* d0-d2/a0-a2 corrupt


IncHScr		bset	#2,applic_flag2(a6)	;hold InfoReq
		bsr	SGHelp
		beq.s	IHSZ_1

		cmp.w	#MAX_DISPX,grid_across(a6)
		bhi.s	IncHScr_2

IHSZ_1		rts

IncHScr_2	move.w	grid_firstx(a6),d0	;get TLC X position

		addq.w	#1,d0			;move 1 square right

		move.w	d0,d1
		add.w	#MAX_DISPX,d1	;check if hit extreme RHS
		subq.w	#1,d1		;correct for LHS=1

		cmp.w	grid_across(a6),d1	;Hit right edge?
		bhi.s	IncHScr_1		;skip if so

		move.w	d0,grid_firstx(a6)	;else set new value

		lea	ScrHPG(pc),a0
		move.l	gg_SpecialInfo(a0),a1
		move.w	pi_HorizBody(a1),d1	;copy Body to Pot
		move.w	d1,d3			;this is true Body
		subq.w	#1,d0			;conform to Pot value
		mulu	d0,d1			;this is true Pot
		moveq	#-1,d2			;these are VPot
		move.l	d2,d4			;and VBody
		moveq	#1,d5			;no. to refresh

		move.w	#FREEHORIZ+PROPBORDERLESS,d0

		move.l	mw_handle(a6),a1
		sub.l	a2,a2
		CALLINT	NewModifyProp

IncHScr_1	bsr	DisplayGrid	;show new grid area

		move.l	#HANG2,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	IncHScr_2	;back for more if so

		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;else done


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

* Scroll crossword grid 1 square down unless extreme
* bottom edge already reached.
* Checks to see if grid large enough to be scrolled,
* and exits if not.

* d0-d2/a0-a2 corrupt


IncVScr		bset	#2,applic_flag2(a6)	;hold InfoReq
		bsr	SGHelp
		beq.s	IVSZ_1

		cmp.w	#MAX_DISPY,grid_down(a6)
		bhi.s	IncVScr_2

IVSZ_1		rts

IncVScr_2	move.w	grid_firsty(a6),d0	;get TLC Y position

		addq.w	#1,d0		;move 1 square down

		move.w	d0,d1
		add.w	#MAX_DISPY,d1	;check if hit hit extreme bottom
		subq.w	#1,d1		;correct for top=1

		cmp.w	grid_down(a6),d1	;hit bottom edge?
		bhi.s	IncVScr_1	;skip if so

		move.w	d0,grid_firsty(a6)	;else set new value

		lea	ScrVPG(pc),a0
		move.l	gg_SpecialInfo(a0),a1
		move.w	pi_VertBody(a1),d2	;copy Body to Pot
		move.w	d2,d4			;this is true Body
		subq.w	#1,d0			;conform to Pot value
		mulu	d0,d2			;this is true Pot
		moveq	#-1,d1			;these are HPot
		move.l	d2,d3			;and HBody
		moveq	#1,d5			;no. to refresh

		move.w	#FREEVERT+PROPBORDERLESS,d0

		move.l	mw_handle(a6),a1
		sub.l	a2,a2
		CALLINT	NewModifyProp

IncVScr_1	bsr	DisplayGrid	;show new grid area

		move.l	#HANG2,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	IncVScr_2	;back for more if so

		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;else done


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

* Scroll crossword grid 1 square to the left
* unless extreme left hand edge already reached.
* Checks to see if grid large enough to be scrolled,
* and exits if not.

* d0-d2/a0-a2 corrupt


DecHScr		bset	#2,applic_flag2(a6)	;hold InfoReq
		bsr	SGHelp
		beq.s	DHSZ_1

		cmp.w	#MAX_DISPX,grid_across(a6)
		bhi.s	DecHScr_2

DHSZ_1		rts

DecHScr_2	move.w	grid_firstx(a6),d0	;get TLC X position

		subq.w	#1,d0		;move 1 square to the left
		beq.s	DecHScr_1	;skip if hit left edge

		move.w	d0,grid_firstx(a6)	;else set new value

		lea	ScrHPG(pc),a0
		move.l	gg_SpecialInfo(a0),a1
		move.w	pi_HorizBody(a1),d1	;copy Body to Pot
		move.w	d1,d3			;this is true Body
		subq.w	#1,d0			;conform to Pot value
		mulu	d0,d1			;this is true Pot
		moveq	#-1,d2			;these are VPot
		move.l	d2,d4			;and VBody
		moveq	#1,d5			;no. to refresh

		move.w	#FREEHORIZ+PROPBORDERLESS,d0

		move.l	mw_handle(a6),a1
		sub.l	a2,a2
		CALLINT	NewModifyProp

DecHScr_1	bsr	DisplayGrid	;show new grid area

		move.l	#HANG2,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	DecHScr_2	;back for more if so

		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;else done


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

* Scroll crossword grid 1 square up
* unless extreme top edge already reached.
* Checks to see if grid large enough to be scrolled,
* and exits if not.

* d0-d2/a0-a2 corrupt


DecVScr		bset	#2,applic_flag2(a6)	;hold InfoReq
		bsr	SGHelp
		beq.s	DVSZ_1

		cmp.w	#MAX_DISPY,grid_down(a6)
		bhi.s	DecVScr_2

DVSZ_1		rts

DecVScr_2	move.w	grid_firsty(a6),d0	;get TLC Y position

		subq.w	#1,d0		;move 1 square up
		beq.s	DecVScr_1	;skip if hit top edge

		move.w	d0,grid_firsty(a6)	;else set new value

		lea	ScrVPG(pc),a0
		move.l	gg_SpecialInfo(a0),a1
		move.w	pi_VertBody(a1),d2	;copy Body to Pot
		move.w	d2,d4			;this is true Body
		subq.w	#1,d0			;conform to Pot value
		mulu	d0,d2			;this is true Pot
		moveq	#-1,d1			;these are HPot
		move.l	d2,d3			;and HBody
		moveq	#1,d5			;no. to refresh

		move.w	#FREEVERT+PROPBORDERLESS,d0

		move.l	mw_handle(a6),a1
		sub.l	a2,a2
		CALLINT	NewModifyProp

DecVScr_1	bsr	DisplayGrid	;show new area

		move.l	#HANG2,d0
		bsr	BusyWait

		btst	#6,$BFE001	;mouse held down?
		beq.s	DecVScr_2	;back for more if so

		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;else done


* NewModifyProp (Gad,Win,Req,Flags,HPot,VPot,HBody,VBody,NumGad)
*		a0  a1  a2   d0   d1   d2   d3     d4   d5


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

* Set the pot values for the main window slider gadgets
* according to the current values of the grid size, and
* save the scroll values

* d0-d5/a0-a1 corrupt


SetMainHVPots	move.w	grid_across(a6),d1	;get across size

		sub.w	#MAX_DISPX,d1	;too small to scroll?
		bmi.s	SMHV_1		;skip if so
		beq.s	SMHV_1

		addq.w	#1,d1
		move.w	d1,grid_hscrl(a6)	;save this value
		bra.s	SMHV_2		;and set the PropGadget

SMHV_1		moveq	#0,d1
		move.w	d1,grid_hscrl(a6)	;use this instead
		moveq	#1,d1

SMHV_2		moveq	#1,d2
		neg.w	d2
		divu	d1,d2		;create HBody value
		move.w	d2,d3
		moveq	#0,d1		;create HPot value

		moveq	#-1,d2		;VPot, VBody not used
		move.w	d2,d4

		move.w	#FREEHORIZ+PROPBORDERLESS,d0	;flags

		moveq	#1,d5		;only 1 gadget to refresh

		lea	ScrHPG(pc),a0	;act upon this gadget

		move.l	mw_handle(a6),a1	;this window
		sub.l	a2,a2		;no requester

		CALLINT	NewModifyProp

		move.w	#1,grid_firstx(a6)	;and set TLC X position


		move.w	grid_down(a6),d1		;get down size

		sub.w	#MAX_DISPY,d1	;too small to scroll?
		bmi.s	SMHV_3		;skip if so
		beq.s	SMHV_3

		addq.w	#1,d1
		move.w	d1,grid_vscrl(a6)	;save this value
		bra.s	SMHV_4		;and set the PropGadget

SMHV_3		moveq	#0,d1
		move.w	d1,grid_vscrl(a6)	;use this instead
		moveq	#1,d1

SMHV_4		moveq	#1,d2
		neg.w	d2
		divu	d1,d2		;create VBody value
		move.w	d2,d4
		moveq	#0,d2		;create VPot value

		moveq	#0,d1		;HPot, HBody not used
		moveq	#-1,d3

		move.w	#FREEVERT+PROPBORDERLESS,d0	;flags

		moveq	#1,d5		;only 1 gadget to refresh

		lea	ScrVPG(pc),a0	;act upon this gadget

		move.l	mw_handle(a6),a1	;this window
		sub.l	a2,a2		;no requester

		CALLINT	NewModifyProp

		move.w	#1,grid_firsty(a6)	;and set TLC Y position

		rts


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

* Scroll crossword grid using the horizontal PropGadget.
* Only perform the scroll if grid big enough to (no
* more small grid hiccups).

* d0-d5/a0/a5 corrupt


ScrollHoriz	lea	ScrHPG(pc),a0
		move.l	gg_SpecialInfo(a0),a0
		move.w	pi_Flags(a0),d0		;check if Knob hit
		and.w	#KNOBHIT,d0
		bne.s	SHZZ_2			;skip if so

		bset	#2,applic_flag2(a6)	;else hold InfoReq

SHZZ_2		bsr	SGHelp
		beq.s	SHZZ_1

		cmp.w	#MAX_DISPX,grid_across(a6)
		bhi.s	SHZ_3

SHZZ_1		rts

SHZ_3		lea	ScrHPG(pc),a0		;ptr to gadget
		move.l	gg_SpecialInfo(a0),a0	;ptr to PropInfo
		move.l	a0,a5			;make permanent ptr

SHZ_1		moveq	#0,d0
		move.l	d0,d1

		move.w	pi_HorizPot(a5),d0
		move.w	pi_HorizBody(a5),d1

		divu	d1,d0	;create TLC X value

		move.w	d0,d1	;check if off RHS

		addq.w	#1,d0	;make it 1 - N

		add.w	#MAX_DISPX,d1
		cmp.w	grid_across(a6),d1
		bls.s	SHZ_2			;skip if not off RHS

		subq.w	#1,d0			;else correct

SHZ_2		move.w	d0,grid_firstx(a6)	;& set it


* Now display the new grid area


		bsr	DisplayGrid


* Now check if PropGadget is still being played with, and if so
* go back & change the value again. Note that the KNOBHIT flag is
* NOT cleared if the slider is released! The mouse button must be
* tested for instead. 


		move.w	pi_Flags(a5),d0	;check PropInfo flags
		and.w	#KNOBHIT,d0	;did we click on the knob?
		beq.s	SHZ_Done		;skip if not (clicked in box)

		btst	#6,$BFE001	;mouse button pressed?
		beq.s	SHZ_1		;skip back if so

SHZ_Done		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;finished with this gadget!


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

* Scroll crossword grid using the vertical PropGadget.
* Only perform the scroll if grid big enough to (no
* more small grid hiccups).

* d0-d5/a0/a5 corrupt


ScrollVert	lea	ScrVPG(pc),a0
		move.l	gg_SpecialInfo(a0),a0
		move.w	pi_Flags(a0),d0		;check if Knob hit
		and.w	#KNOBHIT,d0
		bne.s	SVTZ_2			;skip if so

		bset	#2,applic_flag2(a6)	;hold InfoReq

SVTZ_2		bsr	SGHelp
		beq.s	SVTZ_1

		cmp.w	#MAX_DISPY,grid_down(a6)
		bhi.s	SVT_3

SVTZ_1		rts

SVT_3		lea	ScrVPG(pc),a0		;ptr to gadget
		move.l	gg_SpecialInfo(a0),a0	;ptr to PropInfo
		move.l	a0,a5			;make permanent ptr

SVT_1		moveq	#0,d0
		move.l	d0,d1

		move.w	pi_VertPot(a5),d0
		move.w	pi_VertBody(a5),d1

		divu	d1,d0	;create TLC Y value

		move.w	d0,d1	;check if off bottom

		addq.w	#1,d0	;make it 1 - N

		add.w	#MAX_DISPY,d1
		cmp.w	grid_down(a6),d1
		bls.s	SVT_2			;skip if not off bottom

		subq.w	#1,d0			;else correct

SVT_2		move.w	d0,grid_firsty(a6)	;& set it


* Now display the new grid area


		bsr	DisplayGrid


* Now check if PropGadget is still being played with, and if so
* go back & change the value again. Note that the KNOBHIT flag is
* NOT cleared if the slider is released! The mouse button must be
* tested for instead. 


		move.w	pi_Flags(a5),d0	;check PropInfo flags
		and.w	#KNOBHIT,d0	;did we click on the knob?
		beq.s	SVT_Done		;skip if not (clicked in box)

		btst	#6,$BFE001	;mouse button pressed?
		beq.s	SVT_1		;skip back if so

SVT_Done		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		rts			;finished with this gadget!







