

* This file contains stuff for solving the crossword.
* At last! We get to enter solutions!


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

* Insert the clue text into the IntuiTexts for the
* solve requester, so that when it comes up, the user knows
* what the clue number is.

* Also gets pointer to clue text for the ShowQuestion()
* routine.

* This one for across clues: ShowDownClue() below does
* the same for down clues


* d0-d2/d7/a0-a1 corrupt


ShowAcrossClue	bsr	TXAcross

		lea	SolveT3(pc),a0	;ptr to 1st IText
		lea	ITT_Alt1(pc),a1	;ptr to Across text
		move.l	a1,12(a0)	;pop in text ptr
		move.w	#64,4(a0)	;and position
		move.l	16(a0),a0	;point to next IText
		move.l	a1,12(a0)	;and insert text ptr here too
		move.w	#63,4(a0)	;and print position

		move.w	pick_across(a6),d0
		move.l	clue_list(a6),a0
		move.w	clh_AcCount(a0),d7
		move.l	clh_AcList(a0),a0

SACL_1		cmp.w	(a0),d0		;this clue?
		beq.s	SACL_2		;yes-go get pointer

		add.w	#cle_sizeof,a0	;else get next clue
		subq.w	#1,d7		;done them all?
		bne.s	SACL_1		;no, go back

		sub.l	a0,a0		;else there isn't one!
		bra.s	SACL_3

SACL_2		move.l	cle_Text(a0),a0	;get ptr to clue text

SACL_3		move.l	a0,solve_ptr(a6)	;save it!

		rts


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

* See above for description & corrupt reg list


ShowDownClue	bsr	TXDown

		lea	SolveT3(pc),a0	;ptr to 1st IText
		lea	ITT_Alt2(pc),a1	;ptr to Across text
		move.l	a1,12(a0)	;pop in text ptr
		move.w	#72,4(a0)	;and print position
		move.l	16(a0),a0	;point to next IText
		move.l	a1,12(a0)	;and insert text ptr here too
		move.w	#71,4(a0)	;and print position

		move.w	pick_down(a6),d0
		move.l	clue_list(a6),a0
		move.w	clh_DnCount(a0),d7
		move.l	clh_DnList(a0),a0

SDCL_1		cmp.w	(a0),d0		;this clue?
		beq.s	SDCL_2		;yes-go get pointer

		add.w	#cle_sizeof,a0	;else get next clue
		subq.w	#1,d7		;done them all?
		bne.s	SDCL_1		;no, go back

		sub.l	a0,a0		;else there isn't one!
		bra.s	SDCL_3

SDCL_2		move.l	cle_Text(a0),a0	;get ptr to clue text

SDCL_3		move.l	a0,solve_ptr(a6)	;save it!

		rts


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

* This routine pops the actual clue question into the
* solve requester. It also formats the text!

* d0-d4/d7/a0-a2 corrupt


ShowQuestion	move.l	solve_ptr(a6),d0	;any clue text?
;		beq	SQ_Done		;no
		beq	SQ_NoText

		move.l	d0,a0		;else this is source text ptr

		lea	SolveBuf(pc),a1	;ptr to dest buffer

SQ_L1		moveq	#0,d0		;no of chars copied

SQ_L2		tst.b	(a0)		;get char-EOS met?
		beq.s	SQ_B1		;skip if so

		move.b	(a0)+,(a1)+	;copy chars
		addq.w	#1,d0		;no. of chars processed
		cmp.w	#MAXCTLEN,d0	;done enough for 1 line?
		bcs.s	SQ_L2		;loop back if so

		subq.l	#1,a1		;point to last char copied

		cmp.b	#" ",(a1)	;last char a " "?
		bne.s	SQ_B2		;skip if not

SQ_L3		subq.l	#1,a1		;skip back until a
		cmp.b	#" ",(a1)	;non-space char found
		beq.s	SQ_L3
		addq.l	#1,a1		;point beyond chars
		clr.b	(a1)+		;and pop in an EOS
		bra.s	SQ_L1		;and do another string

SQ_B2		moveq	#0,d4		;special flags

		moveq	#0,d1		;forward scan count
		move.l	d1,d2		;backward scan count

SQ_L4		subq.w	#1,d2		;point backwards
		move.b	0(a0,d2.w),d3	;get prev char
		cmp.b	#" ",d3		;prev char a space?
		bne.s	SQ_L4		;back if not

SQ_L4a		move.b	0(a0,d1.w),d3	;get next char
		beq.s	SQ_B3		;Exit if EOS
		cmp.b	#" ",d3		;and also
		beq.s	SQ_B3		;exit if space
		addq.w	#1,d1		;else next char forward
		bra.s	SQ_L4a		;back for more

SQ_B3		move.w	d2,d3
		neg.w	d3		;no of back chars

		cmp.w	#4,d1		;more than 4 forward chars?
		bls.s	SQ_B3a		;don't hyphenate if not

		cmp.w	#4,d3		;more than 4 back chars?
		bhi.s	SQ_B4		;hyphenate if so

SQ_B3a		clr.b	1(a1,d2.w)
		addq.l	#1,a1		;point to proper insert spot
		neg.w	d2
		move.w	d2,d0		;proper char count
		bra.s	SQ_L2		;and back for next string

SQ_B4		move.b	(a1),d3		;get char to be scratched
		move.b	#"-",(a1)+	;here hyphenate
		clr.b	(a1)+		;and pop in EOS
		move.b	d3,(a1)+		;replace scratched char

		moveq	#1,d0		;new init char count
		bra.s	SQ_L2		;and continue scan

SQ_B1		clr.b	(a1)+		;pop in final EOS

		move.b	#-1,(a1)+	;signal end of strings
		clr.b	(a1)+		;and another EOS


* Now that we have a collection of correctly formatted text strings
* located in SolveBuf, pop pointers to them into the requester ITexts.


		lea	SolveBuf(pc),a0

		lea	SolveT5(pc),a1

SQ_L5		cmp.b	#-1,(a0)		;hit end of clue strings?
		beq.s	SQ_B5		;skip if so

		move.l	a1,-(sp)		;save IText ptr
		bsr	StrLen		;how long is the string?
		move.l	(sp)+,a1		;recover IText ptr

		add.w	d0,d0		;length * 8
		add.w	d0,d0
		add.w	d0,d0

		neg.w	d0
		add.w	#270,d0
		lsr.w	#1,d0		;xpos = (270-len*8)/2

		move.w	d0,d1		;d0 = pos of 2nd text
		addq.w	#1,d1		;pos of 1st text

		move.l	a0,12(a1)	;pop in text ptr
		move.w	d1,4(a1)		;and its position
		move.l	16(a1),a2	;get ptr to next IText
		move.l	a0,12(a2)	;and pop in text ptr
		move.w	d0,4(a2)		;and position

		move.l	16(a2),d0	;get next IText ptr
		bne.s	SQ_B6		;skip if it exists
		pea	20(a2)		;ptr to next next IText!
		move.l	(sp)+,d0		;how to do it without a3...

SQ_B6		move.l	d0,16(a2)	;and set it up

		move.l	d0,a1		;now point to it properly...

SQ_L6		tst.b	(a0)+		;skip to EOS
		bne.s	SQ_L6		;and beyond...

		bra.s	SQ_L5		;back for more!!!

SQ_B5		clr.l	16(a2)		;ensure last IText...

SQ_Done		rts


* Note: the following code MUST clear TWO IText structures of string
* pointers, then clear the it_NextText pointer of the SECOND IText
* structure to maintain compatibility with the above routine. This is
* added code to kill off the minor niggle of leftover text when a new
* rendition of the GetSolution requester occurs with a nonexistent
* clue question.


SQ_NoText	lea	SolveT5(pc),a0	;ptr to 1st IText
		clr.l	12(a0)		;clear actual text ptr
		move.l	16(a0),a0	;point to next IText
		clr.l	12(a0)		;clear actual text ptr
		clr.l	16(a0)		;and next IText ptr

		rts


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

* Attempt to erase a solution from an Across clue.
* Perform an intelligent erase, i.e., erase only those
* characters unique to the chosen solution. Any chars
* forming part of an intersecting solution are left
* unerased.


* d0-d3/a0-a1 corrupt.


ClearAcross	btst	#6,applic_flag1(a6)	;Type 1 crossword?
		bne	CAC_B5			;skip if not


* Here handle Type 1 crossword.


		move.w	pick_across(a6),d0	;Across clue?
		beq.s	CAC_B4			;no, so skip

		move.w	pick_Ach(a6),d0		;get start position
		move.w	pick_Acv(a6),d1

CAC_L1		cmp.w	grid_across(a6),d0	;hit RHS?
		bhi.s	CAC_B4			;exit if so

		move.w	d1,d2			;create pointer
		subq.w	#1,d2			;to array
		mulu	grid_across(a6),d2	;element
		add.l	d2,d2
		move.l	d2,a0
		move.w	d0,d2
		subq.w	#1,d2
		add.w	d2,d2
		add.w	d2,a0
		add.l	grid_array(a6),a0		;this is pointer

		move.w	(a0),d2		;get square data
		tst.b	d2		;black square?
		beq.s	CAC_B4		;skip-done erasing!

		move.w	d1,d3		;previous down square
		subq.w	#1,d3		;does it exist?
		beq.s	CAC_B1		;no, check next

		move.l	a0,a1			;copy ptr
		move.w	grid_across(a6),d3
		add.w	d3,d3
		sub.w	d3,a1			;point to prev

		move.w	(a1),d3		;get square data
		tst.b	d3		;black square?
		beq.s	CAC_B1		;yes, check next
		cmp.b	#" ",d3		;white square?
		bne.s	CAC_B3		;no, DON'T erase

CAC_B1		move.w	d1,d3		;next down square
		addq.w	#1,d3		;does it exist?
		cmp.w	grid_down(a6),d3
		bhi.s	CAC_B2		;no, go and erase

		move.l	a0,a1			;copy ptr
		move.w	grid_across(a6),d3
		add.w	d3,d3
		add.w	d3,a1			;point to next

		move.w	(a1),d3		;get square data
		tst.b	d3		;black square?
		beq.s	CAC_B2		;yes, so erase
		cmp.b	#" ",d3		;white square?
		bne.s	CAC_B3		;no, DON'T erase

CAC_B2		move.b	#" ",d2		;erase solution char
		move.w	d2,(a0)		;from this square

		movem.w	d0-d1,-(sp)	;save position data
		bsr	SetSquare	;change graphic on grid
		movem.w	(sp)+,d0-d1	;recover position data

CAC_B3		addq.w	#1,d0		;next across square
		bra.s	CAC_L1


* Here, we're done.


CAC_B4		move.l	clue_AcEntry(a6),a0
		clr.b	cle_Solved(a0)

		rts


* Here, erasing from a Type 2 crossword.


CAC_B5		move.w	pick_across(a6),d0	;Across clue?
		beq	CAC_B9			;no, so skip

		move.w	pick_Ach(a6),d0		;get start position
		move.w	pick_Acv(a6),d1

CAC_L2		cmp.w	grid_across(a6),d0	;hit RHS?
		bhi.s	CAC_B9			;exit if so

		move.w	d1,d2			;create pointer
		subq.w	#1,d2			;to array
		mulu	grid_across(a6),d2	;element
		add.l	d2,d2
		move.l	d2,a0
		move.w	d0,d2
		subq.w	#1,d2
		add.w	d2,d2
		add.w	d2,a0
		add.l	grid_array(a6),a0		;this is pointer

		move.w	(a0),d2		;get square data
		tst.b	d2		;black square?
		beq.s	CAC_B9		;skip-done erasing!

		move.w	d1,d3		;previous down square
		subq.w	#1,d3		;does it exist?
		beq.s	CAC_B6		;no, check next

		move.l	a0,a1			;copy ptr
		move.w	grid_across(a6),d3
		add.w	d3,d3
		sub.w	d3,a1			;point to prev

		move.w	(a1),d3		;get square data
		btst	#8,d3		;prev square vert barred?
		bne.s	CAC_B6		;yes, check next

		cmp.b	#" ",d3		;white square?
		bne.s	CAC_B8		;no, DON'T erase

CAC_B6		btst	#8,d2		;this square vert barred?
		bne.s	CAC_B7		;yes, go and erase

		move.w	d1,d3		;next down square
		addq.w	#1,d3		;does it exist?
		cmp.w	grid_down(a6),d3
		bhi.s	CAC_B7		;no, go and erase

		move.l	a0,a1			;copy ptr
		move.w	grid_across(a6),d3
		add.w	d3,d3
		add.w	d3,a1			;point to next

		move.w	(a1),d3		;get square data
		cmp.b	#" ",d3		;white square?
		bne.s	CAC_B8		;no, DON'T erase

CAC_B7		move.b	#" ",d2		;erase solution char
		move.w	d2,(a0)		;from this square

		movem.w	d0-d1,-(sp)	;save position data
		bsr	SetSquare	;change graphic on grid
		movem.w	(sp)+,d0-d1	;recover position data

CAC_B8		addq.w	#1,d0		;next across square
		bra.s	CAC_L2


* Here, we're done.


CAC_B9		move.l	clue_AcEntry(a6),a0
		clr.b	cle_Solved(a0)
		rts



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

* Attempt to erase a solution from a Down clue.
* Perform an intelligent erase, i.e., erase only those
* characters unique to the chosen solution. Any chars
* forming part of an intersecting solution are left
* unerased.


* d0-d3/a0-a1 corrupt.


ClearDown	btst	#6,applic_flag1(a6)	;Type 1 crossword?
		bne	CDN_B5			;skip if not


* Here handle Type 1 crossword.


		move.w	pick_down(a6),d0		;Down clue?
		beq.s	CDN_B4			;no, so skip

		move.w	pick_Dnh(a6),d0		;get start position
		move.w	pick_Dnv(a6),d1

CDN_L1		cmp.w	grid_down(a6),d1		;hit bottom?
		bhi.s	CDN_B4			;exit if so

		move.w	d1,d2			;create pointer
		subq.w	#1,d2			;to array
		mulu	grid_across(a6),d2	;element
		add.l	d2,d2
		move.l	d2,a0
		move.w	d0,d2
		subq.w	#1,d2
		add.w	d2,d2
		add.w	d2,a0
		add.l	grid_array(a6),a0		;this is pointer

		move.w	(a0),d2		;get square data
		tst.b	d2		;black square?
		beq.s	CDN_B4		;skip-done erasing!

		move.w	d0,d3		;previous across square
		subq.w	#1,d3		;does it exist?
		beq.s	CDN_B1		;no, check next

		move.w	-2(a0),d3	;get square data
		tst.b	d3		;black square?
		beq.s	CDN_B1		;yes, check next
		cmp.b	#" ",d3		;white square?
		bne.s	CDN_B3		;no, DON'T erase

CDN_B1		move.w	d0,d3		;next across square
		addq.w	#1,d3		;does it exist?
		cmp.w	grid_across(a6),d3
		bhi.s	CDN_B2		;no, go and erase

		move.w	2(a0),d3		;get square data
		tst.b	d3		;black square?
		beq.s	CDN_B2		;yes, so erase
		cmp.b	#" ",d3		;white square?
		bne.s	CDN_B3		;no, DON'T erase

CDN_B2		move.b	#" ",d2		;erase solution char
		move.w	d2,(a0)		;from this square

		movem.w	d0-d1,-(sp)	;save position data
		bsr	SetSquare	;change graphic on grid
		movem.w	(sp)+,d0-d1	;recover position data

CDN_B3		addq.w	#1,d1		;next down square
		bra.s	CDN_L1


* Here, we're done.


CDN_B4		move.l	clue_DnEntry(a6),a0
		clr.b	cle_Solved(a0)
		rts


* Here, erasing from a Type 2 crossword.


CDN_B5		move.w	pick_down(a6),d0		;Down clue?
		beq.s	CDN_B9			;no, so skip

		move.w	pick_Dnh(a6),d0		;get start position
		move.w	pick_Dnv(a6),d1

CDN_L2		cmp.w	grid_down(a6),d1		;hit bottom?
		bhi.s	CDN_B9			;exit if so

		move.w	d1,d2			;create pointer
		subq.w	#1,d2			;to array
		mulu	grid_across(a6),d2	;element
		add.l	d2,d2
		move.l	d2,a0
		move.w	d0,d2
		subq.w	#1,d2
		add.w	d2,d2
		add.w	d2,a0
		add.l	grid_array(a6),a0		;this is pointer

		move.w	(a0),d2		;get square data
		tst.b	d2		;black square?
		beq.s	CDN_B9		;skip-done erasing!

		move.w	d0,d3		;previous across square
		subq.w	#1,d3		;does it exist?
		beq.s	CDN_B6		;no, check next

		move.w	-2(a0),d3	;get square data
		btst	#9,d3		;prev square horiz barred?
		bne.s	CDN_B6		;yes, check next

		cmp.b	#" ",d3		;white square?
		bne.s	CDN_B8		;no, DON'T erase

CDN_B6		btst	#9,d2		;this square horiz barred?
		bne.s	CDN_B7		;yes, go and erase

		move.w	d0,d3		;next across square
		addq.w	#1,d3		;does it exist?
		cmp.w	grid_across(a6),d3
		bhi.s	CDN_B7		;no, go and erase

		move.w	2(a0),d3		;get square data
		cmp.b	#" ",d3		;white square?
		bne.s	CDN_B8		;no, DON'T erase

CDN_B7		move.b	#" ",d2		;erase solution char
		move.w	d2,(a0)		;from this square

		movem.w	d0-d1,-(sp)	;save position data
		bsr	SetSquare	;change graphic on grid
		movem.w	(sp)+,d0-d1	;recover position data

CDN_B8		addq.w	#1,d1		;next down square
		bra.s	CDN_L2


* Here, we're done.


CDN_B9		move.l	clue_DnEntry(a6),a0
		clr.b	cle_Solved(a0)
		rts


* ShowPartAcross(a6)
* a6 = ptr to main string variables

* Create a string containing those letters currently
* in the solution, e.g.,

*		--S--T-

* to insert into the string gadget, obtained from an across
* clue.

* DO NOT CALL IF REQUESTER (AND THEREFORE THE GADGET) IS ACTIVE!

* d0-d1/a0-a1 corrupt


ShowPartAcross	tst.w	pick_across(a6)		;got an across clue?
		beq.s	SPAC_Done		;exit if not

		move.w	pick_Ach(a6),d0		;get start square
		move.w	pick_Acv(a6),d1		;position
		move.w	d0,d2			;copy horiz pos
		subq.w	#1,d1
		mulu	grid_across(a6),d1
		add.l	d1,d1
		add.l	grid_array(a6),d1
		move.l	d1,a0
		add.w	d0,a0
		add.w	d0,a0
		subq.l	#2,a0		;point to 1st square

		lea	GetSolution(pc),a1
		move.l	gg_SpecialInfo(a1),a1
		clr.w	si_BufferPos(a1)
		move.l	si_Buffer(a1),a1

		btst	#6,applic_flag1(a6)	;which crossword type?
		bne.s	SPAC_L2			;skip if type 2

SPAC_L1		move.w	(a0)+,d0		;get square data
		tst.b	d0		;hit black square?
		beq.s	SPAC_B2		;exit loop if so
		cmp.b	#" ",d0		;char a " "?
		bne.s	SPAC_B1		;skip if not
		move.b	#"-",d0		;else make a "-"
SPAC_B1		move.b	d0,(a1)+		;insert char into buffer
		addq.w	#1,d2		;next horiz pos

		cmp.w	grid_across(a6),d2	;hit end of grid?
		bls.s	SPAC_L1			;back for more if not

SPAC_B2		clr.b	(a1)		;insert EOS

SPAC_Done	rts

SPAC_L2		move.w	(a0)+,d0		;get square data
		cmp.b	#" ",d0		;hit a " "?
		bne.s	SPAC_B3		;skip if not
		move.b	#"-",d0		;else change it into a "-"
SPAC_B3		move.b	d0,(a1)+		;pop char into buffer

		btst	#8,d0		;hit vertical bar?
		bne.s	SPAC_B2		;exit if so

		addq.w	#1,d2			;next horiz pos
		cmp.w	grid_across(a6),d2	;hit end of grid?
		bls.s	SPAC_L2			;do more if not

		clr.b	(a1)		;else pop in final EOS
		rts			;and done.


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

* Perform the same function as ShowPartAcross(), except
* this time do it for a down clue.

* d0-d3/a0-a1 corrupt

ShowPartDown	tst.w	pick_down(a6)		;got a down clue?
		beq.s	SPDN_Done		;exit if not

		move.w	pick_Dnh(a6),d0		;get start square
		move.w	pick_Dnv(a6),d1		;position
		move.w	d1,d2			;copy vert pos
		subq.w	#1,d1
		move.w	grid_across(a6),d3
		add.w	d3,d3
		mulu	d3,d1
		add.l	grid_array(a6),d1
		move.l	d1,a0
		add.w	d0,a0
		add.w	d0,a0
		subq.l	#2,a0		;point to 1st square

		lea	GetSolution(pc),a1
		move.l	gg_SpecialInfo(a1),a1
		clr.w	si_BufferPos(a1)
		move.l	si_Buffer(a1),a1

		btst	#6,applic_flag1(a6)	;which crossword type?
		bne.s	SPDN_L2			;skip if type 2

SPDN_L1		move.w	(a0),d0		;get square data
		add.w	d3,a0		;point to next down square
		tst.b	d0		;hit black square?
		beq.s	SPDN_B2		;exit loop if so
		cmp.b	#" ",d0		;char a " "?
		bne.s	SPDN_B1		;skip if not
		move.b	#"-",d0		;else make a "-"
SPDN_B1		move.b	d0,(a1)+		;insert char into buffer
		addq.w	#1,d2		;next vert pos

		cmp.w	grid_down(a6),d2	;hit end of grid?
		bls.s	SPDN_L1			;back for more if not

SPDN_B2		clr.b	(a1)		;insert EOS

SPDN_Done	rts

SPDN_L2		move.w	(a0),d0		;get square data
		add.w	d3,a0		;point to next square
		cmp.b	#" ",d0		;hit a " "?
		bne.s	SPDN_B3		;skip if not
		move.b	#"-",d0		;else change it into a "-"
SPDN_B3		move.b	d0,(a1)+		;pop char into buffer

		btst	#9,d0		;hit horizontal bar?
		bne.s	SPDN_B2		;exit if so

		addq.w	#1,d2		;next vert pos
		cmp.w	grid_down(a6),d2	;hit end of grid?
		bls.s	SPDN_L2		;do more if not

		clr.b	(a1)		;else pop in final EOS
		rts			;and done.


* TransferSoln(a0,a1)
* a0 = ptr to string gadget structure
* a1 = ptr to transfer buffer

* Transfers solution from string gadget in Solve Requester
* to the appropriate buffer. Also converts to upper case and
* strips out spaces and other non-alphabetic/non-digit charac-
* ters.

* This routine allows solutions typed into the string gadget to
* contain embedded spaces, e.g.:

*		three stooges

* or hyphens, e.g.:

*		jean-paul sartre

* which will be stripped prior to entry into the grid.
* The routine allows digits 0-9 to be accepted so that the
* program can be used to solve number jigs or cross-number
* puzzles.

* a0/a1 corrupt


TransferSoln	move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0		;point to text

TSN_L1		move.b	(a0)+,d0		;get char
		beq.s	TSN_B2		;EOS hit-finish!

		cmp.b	#"0",d0		;Digit?
		bcs.s	TSN_L1		;get next if not
		cmp.b	#"9",d0		;Digit?
		bls.s	TSN_B1		;copy it if so

		cmp.b	#"A",d0		;Capital letter?
		bcs.s	TSN_L1		;get next if not
		cmp.b	#"Z",d0		;Capital letter?
		bls.s	TSN_B1		;copy it if so

		cmp.b	#"a",d0		;small letter?
		bcs.s	TSN_L1		;get next if not
		cmp.b	#"z",d0		;small letter?
		bhi.s	TSN_L1		;get next if not

;		cmp.b	#" ",d0		;space?
;		beq.s	TSN_L1		;skip it if so

;		cmp.b	#"a",d0		;outside lower case range?
;		bcs.s	TSN_B1		;skip if so

;		cmp.b	#"z",d0		;outside lower case range?
;		bhi.s	TSN_B1		;skip if so

		and.b	#$DF,d0		;convert to upper case

TSN_B1		move.b	d0,(a1)+		;copy chars across
		bra.s	TSN_L1		;and back for more

TSN_B2		move.b	d0,(a1)		;write EOS to buffer
		rts			;done!





* InsertAcross(a6) -> d0
* a6 = ptr to main program variables

* Takes solution for across clue, and tries to insert it into
* the grid. Failure conditions are:

*	1) Trial solution string length wrong

*	2) Solution clashes with existing solutions
*	   already in grid

* Return code in D0:

* 0	: Successful insertion (or else no text to insert)

* 1	: Solution clashes with existing solutions

* 2	: Solution has too few chars

* 3	: Solution has too many chars


* d0-d6/a0-a1 corrupt (because SetSquare() corrupts
* d4-d6 in addition to others)


InsertAcross	btst	#6,applic_flag1(a6)	;Type 1 crossword?
		bne	IA_B7			;skip if not


* Here handle solution insertion for Type 1 crossword.


		move.l	soln_across(a6),d0	;ptr to solution text
		beq	IA_Done			;no ptr-exit

		move.l	d0,a0			;ptr in proper location
		tst.b	(a0)			;null string?
		beq	IA_B6			;exit NOW if so

		move.w	pick_across(a6),d0	;got an across clue?
		beq	IA_Done			;no, so exit without fuss

		move.w	pick_Ach(a6),d0		;get position of 1st
		move.w	pick_Acv(a6),d1		;square of clue


IA_L1		move.b	(a0)+,d2			;get char
		beq.s	IA_B4			;exit-no more text

		cmp.w	grid_across(a6),d0	;off RHS edge?
		bls.s	IA_B1			;no, continue

		moveq	#3,d0		;else exit with ERROR
		bra.s	IA_Done		;if off RHS edge

IA_B1		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;current square

		move.w	(a1),d3		;get square data
		tst.b	d3		;black square?
		bne.s	IA_B2		;no, ok

		moveq	#3,d0		;exit with ERROR
		bra.s	IA_Done		;if black square hit

IA_B2		cmp.b	#" ",d3		;this square blank?
		beq.s	IA_B3		;skip if so
		cmp.b	d3,d2		;chars equal?
		beq.s	IA_B3		;skip if so

		moveq	#1,d0		;exit with ERROR
		bra.s	IA_Done		;if solution clashes

IA_B3		move.b	d2,d3		;else insert square char
		move.w	d3,(a1)

		movem.l	d0-d2/a0,-(sp)	;save this lot

		move.w	d3,d2
		bsr	SetSquare	;put char in synthetic rastport

		movem.l	(sp)+,d0-d2/a0	;recover this lot

		addq.w	#1,d0			;next across square
		bra.s	IA_L1

		moveq	#3,d0		;exit with ERROR
		bra.s	IA_Done		;if run off grid

IA_B4		cmp.w	grid_across(a6),d0	;next square exists?
		bls.s	IA_B5			;skip if so

IA_B6		moveq	#0,d0		;else return with OK signal
		rts			;(solution fits)

IA_B5		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;next square

		move.w	(a1),d3		;get square data
		tst.b	d3		;next square black?
		beq.s	IA_B6		;return if black (OK)

		moveq	#2,d0		;else error return
IA_Done		rts			;(too few chars)


* Here, handle solution insertion for Type 2 crossword.


IA_B7		move.l	soln_across(a6),d0	;ptr to solution text
		beq.s	IA_Done			;no ptr-exit

		move.l	d0,a0			;ptr in proper location
		tst.b	(a0)			;null string?
		beq.s	IA_B6			;exit NOW if so

		move.w	pick_across(a6),d0	;got an across clue?
		beq.s	IA_Done			;no, so exit without fuss

		move.w	pick_Ach(a6),d0		;get position of 1st
		move.w	pick_Acv(a6),d1		;square of clue

		moveq	#0,d3		;safe initialisation

IA_L2		move.b	(a0)+,d2		;get char
		beq.s	IA_B11		;EOS met-done so exit

		btst	#8,d3		;prev square vert barred?
		bne.s	IA_B8		;exit if so with error

		cmp.w	grid_across(a6),d0	;off RHS edge?
		bls.s	IA_B9			;continue if so

IA_B8		moveq	#3,d0		;else exit with ERROR
		rts			;if RHS edge hit

IA_B9		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;current square

		move.w	(a1),d3			;get square data
		cmp.b	d3,d2			;chars equal?
		beq.s	IA_B10			;yes, so insert
		cmp.b	#" ",d3			;blank space?
		beq.s	IA_B10			;yes, so insert

		moveq	#1,d0		;else exit with ERROR
		rts			;if chars clash	

IA_B10		move.b	d2,d3		;insert char into grid
		move.w	d3,(a1)

		move.w	d3,d2		;save new grid data
		movem.l	d0-d2/a0,-(sp)	;save position data & char
		bsr	SetSquare	;change grid graphic
		movem.l	(sp)+,d0-d2/a0	;recover position data & char

		move.w	d2,d3

		addq.w	#1,d0		;next across square
		bra.s	IA_L2

IA_B11		cmp.w	grid_across(a6),d0	;off RHS?
		bhi	IA_B6			;yes, so exit OK

		btst	#8,d3		;last square vert barred?
		bne	IA_B6		;exit OK if so

		moveq	#2,d0		;else exit with ERROR
		rts			;if not hit a bar




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

* Performs identical function to InsertAcross() above,
* except for down clues.

* d0-d6/a0-a1 corrupt (because SetSquare() corrupts
* d4-d6 in addition to others)


InsertDown	btst	#6,applic_flag1(a6)	;Type 1 crossword?
		bne	ID_B7			;skip if not


* Here, handle solution insertion for Type 1 crossword.


		move.l	soln_down(a6),d0	;ptr to solution text
		beq	ID_Done		;no ptr-exit

		move.l	d0,a0		;ptr in proper location
		tst.b	(a0)		;null string?
		beq	ID_B6		;exit NOW if so

		move.w	pick_down(a6),d0		;got a down clue?
		beq	ID_Done			;no, so exit without fuss

		move.w	pick_Dnh(a6),d0		;get position of 1st
		move.w	pick_Dnv(a6),d1		;square of clue

ID_L1		move.b	(a0)+,d2			;get char
		beq.s	ID_B4			;exit-no more text

		cmp.w	grid_down(a6),d1		;off bottom edge?
		bls.s	ID_B1			;no, continue

		moveq	#3,d0		;else exit with ERROR
		bra.s	ID_Done		;if off bottom edge

ID_B1		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;current square

		move.w	(a1),d3		;get square data
		tst.b	d3		;black square?
		bne.s	ID_B2		;no, ok

		moveq	#3,d0		;exit with ERROR
		bra.s	ID_Done		;if black square hit

ID_B2		cmp.b	#" ",d3		;this square blank?
		beq.s	ID_B3		;skip if so
		cmp.b	d3,d2		;chars equal?
		beq.s	ID_B3		;skip if so

		moveq	#1,d0		;exit with ERROR
		bra.s	ID_Done		;if solution clashes

ID_B3		move.b	d2,d3		;else insert square char
		move.w	d3,(a1)

		movem.l	d0-d2/a0,-(sp)	;save this lot

		move.w	d3,d2
		bsr	SetSquare	;put char in synthetic rastport

		movem.l	(sp)+,d0-d2/a0	;recover this lot

		addq.w	#1,d1		;next down square
		bra.s	ID_L1

		moveq	#3,d0		;exit with ERROR
		bra.s	ID_Done		;if run off grid

ID_B4		cmp.w	grid_down(a6),d1	;next square exists?
		bls.s	ID_B5		;skip if so

ID_B6		moveq	#0,d0		;else return with OK signal
		rts			;(solution fits)

ID_B5		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;next square

		move.w	(a1),d3		;get square data
		tst.b	d3		;next square black?
		beq.s	ID_B6		;return if black (OK)

		moveq	#2,d0		;else error return

ID_Done		rts


* Here, handle solution insertion for Type 2 crossword.


ID_B7		move.l	soln_down(a6),d0	;ptr to solution text
		beq.s	ID_Done		;no ptr-exit

		move.l	d0,a0		;ptr in proper location
		tst.b	(a0)		;null string?
		beq.s	ID_B6		;exit NOW if so

		move.w	pick_down(a6),d0	;got a down clue?
		beq.s	ID_B6		;no, so exit without fuss

		move.w	pick_Dnh(a6),d0	;get position of 1st
		move.w	pick_Dnv(a6),d1	;square of clue

		moveq	#0,d3		;safe initialisation

ID_L2		move.b	(a0)+,d2		;get char
		beq.s	ID_B11		;EOS met-done so exit

		btst	#9,d3		;prev square horiz barred?
		bne.s	ID_B8		;exit if so with error

		cmp.w	grid_down(a6),d1	;off bottom edge?
		bls.s	ID_B9		;continue if so

ID_B8		moveq	#3,d0		;else exit with ERROR
		rts			;if RHS edge hit

ID_B9		move.w	d1,d3
		subq.w	#1,d3
		mulu	grid_across(a6),d3
		move.l	d3,a1
		add.w	d0,a1
		subq.l	#1,a1
		add.l	a1,a1			;point to
		add.l	grid_array(a6),a1		;current square

		move.w	(a1),d3		;get square data
		cmp.b	d3,d2		;chars equal?
		beq.s	ID_B10		;yes, so insert
		cmp.b	#" ",d3		;blank space?
		beq.s	ID_B10		;yes, so insert

		moveq	#1,d0		;else exit with ERROR
		rts			;if chars clash	

ID_B10		move.b	d2,d3		;insert char into grid
		move.w	d3,(a1)

		move.w	d3,d2		;save new grid data
		movem.l	d0-d2/a0,-(sp)	;save position data & char
		bsr	SetSquare	;change grid graphic
		movem.l	(sp)+,d0-d2/a0	;recover position data & char

		move.w	d2,d3

		addq.w	#1,d1		;next down square
		bra.s	ID_L2

ID_B11		cmp.w	grid_down(a6),d1	;off bottom?
		bhi	ID_B6		;yes, so exit OK

		btst	#9,d3		;last square horiz barred?
		bne	ID_B6		;exit OK if so

		moveq	#2,d0		;else exit with ERROR
		rts			;if not hit a bar


* This small jump table used to access error routines by the
* Solve() code without the need for branches.


ReportList	dc.l	RPT_Solveit	;Solution inserted OK
		dc.l	RPT_Clash	;Solution clashes!
		dc.l	RPT_TooFew	;too few chars
		dc.l	RPT_TooMany	;too many chars


* And this is the code that handles the reporting of the various
* solution entry type errors. 3 entry points, one common exit point
* resulting in a requester being displayed and then any mistakes
* being erased. Also handles marking of solved clues.


Mark_Across	move.l	clue_AcEntry(a6),a0
		st	cle_Solved(a0)
		rts


Mark_Down	move.l	clue_DnEntry(a6),a0
		st	cle_Solved(a0)
		rts


RPT_Solveit	move.l	solvecode(a6),a0
		jmp	(a0)


RPT_Clash	lea	IRT_1(pc),a0
		lea	Clashes(pc),a1
		moveq	#5,d0

		move.l	a0,irt_itext(a6)
		move.l	a1,irt_tlist(a6)
		move.w	d0,irt_count(a6)

		bra.s	RPT_Doit

RPT_TooFew	lea	IRT_1(pc),a0
		lea	TooFew(pc),a1
		moveq	#4,d0

		move.l	a0,irt_itext(a6)
		move.l	a1,irt_tlist(a6)
		move.w	d0,irt_count(a6)

		bra.s	RPT_Doit

RPT_TooMany	lea	IRT_1(pc),a0
		lea	TooMany(pc),a1
		moveq	#4,d0

		move.l	a0,irt_itext(a6)
		move.l	a1,irt_tlist(a6)
		move.w	d0,irt_count(a6)

RPT_Doit		bsr	LinkInfoText		;pop up the
		bsr	ShowInfoReq		;InfoRequester

		move.l	erasecode(a6),a0		;now perform the
		jmp	(a0)			;erasing operation!

		rts



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

* Pop up 'Enter Solution' requester, including clue information
* etc., and then request a solution.

* d0-d3/d7/a0-a2 corrupt


Solve		btst	#1,applic_flag2(a6)	;HELP on?
		beq.s	Solve_Z1			;skip if not

		lea	Help_ES(pc),a0	;else pop up the
		moveq	#4,d0		;help box
		bsr	_PopUpQR

		beq	Solve_B2		;exit if user cancels

Solve_Z1		bsr	PickClue		;see above


* Now handle mouse events here, until a clue has been picked.
* Temporarily restrict IDCMP to MOUSEMOVE/MOUSEBUTTONS and the
* gadget selection IDCMPs only (latter to allow grid to be
* scrolled to find clue to solve etc!).
* Then recover the normal IDCMP at the end.


		move.l	mw_handle(a6),a0
		move.l	#MOUSEMOVE+MOUSEBUTTONS,d0
		add.l	#GADGETDOWN+GADGETUP,d0

		CALLINT	ModifyIDCMP

Solve_L1		move.l	mw_userport(a6),a0
		lea	ehb_std(pc),a5

		bsr	DoEvent		;completely event driven!

		btst	#3,applic_flag1(a6)	;picked a clue?
		bne.s	Solve_L1			;loop until done

		move.l	grid_array(a6),a0
		add.l	grid_offset(a6),a0	;point to square data
		move.w	(a0),d0			;get square data
		tst.b	d0			;check if white square
		bne.s	Solve_1a			;and continue if OK

		lea	BlackIsNoNo(pc),a0
		lea	IRT_1(pc),a1
		moveq	#3,d0

		move.l	a0,irt_tlist(a6)	;inform user that a
		move.l	a1,irt_itext(a6)	;white square MUST
		move.w	d0,irt_count(a6)	;be selected!

		bsr	LinkInfoText
		bsr	ShowInfoReq

		bra	Solve_B2		;and exit cleanly


* If we get to this point, then we've picked a white square. Now
* find out which clue(s) it belongs to. Could be an across clue,
* a down clue, or both.


Solve_1a		bsr	WhichClue	;find which clue picked


* Now tell user which clues have been picked to be solved,
* and request a solution. If both across and down clue picked
* pop up QueryRequester to see which one is to be solved.


		move.w	pick_across(a6),d0	;got an across clue?
		beq	Solve_B1			;no, skip

		tst.w	pick_down(a6)		;down clue also?
		beq.s	Solve_Z2			;skip if not

		lea	QRT_1(pc),a0
		lea	SAC_YN(pc),a1
		moveq	#3,d0

		move.l	a0,irt_itext(a6)	;else pop up a
		move.l	a1,irt_tlist(a6)	;QueryReq
		move.w	d0,irt_count(a6)

		bsr	DoQueryReq

		btst	#6,applic_flag2(a6)	;"YES" gadget hit?
		beq.s	Solve_B1			;skip if not

Solve_Z2		lea	ClearAcross(pc),a0	;addr of erase routine
		move.l	a0,erasecode(a6)		;to use on error

		lea	Mark_Across(pc),a0	;addr of marker code
		move.l	a0,solvecode(a6)		;if sol'n fits

		bsr	ShowAcrossClue		;get clue number & display
		bsr	ShowQuestion		;as it says!-see above

;		lea	GetSolution(pc),a0	;clear the text
;		move.l	gg_SpecialInfo(a0),a0	;buffer in the
;		clr.w	si_BufferPos(a0)		;string gadget
;		move.l	si_Buffer(a0),a0
;		clr.b	(a0)

		bsr	ShowPartAcross	;display part solution


* Now set up rhb_ structure for the requester and the
* HandleRequest() routine and do it...


		move.l	ThisReq(a6),a4
		lea	SolveReq(pc),a0
		move.l	a0,rhb_Requester(a4)
		lea	DG_Done(pc),a0
		move.l	a0,rhb_PreCode(a4)
		move.l	mw_handle(a6),rhb_Window(a4)
		move.l	mw_userport(a6),rhb_UserPort(a4)
		move.l	mw_IDCMP(a6),rhb_IDCMP(a4)
		lea	ehb_req(pc),a0
		move.l	a0,rhb_EHB(a4)

		bsr	HandleRequest		;handle requester

		lea	GetSolution(pc),a0	;copy solution
		move.l	soln_across(a6),a1	;from string gadget
		bsr	TransferSoln

		bsr	InsertAcross		;try putting it in

		lea	ReportList(pc),a0

		add.l	d0,d0		;error code * 4 as index
		add.l	d0,d0		;into jump table

		add.l	d0,a0		;point to jump table

		move.l	(a0),a0		;get jump address

		jsr	(a0)		;and execute 'error' routine

Solve_B1		move.w	pick_down(a6),d0		;got a down clue?
		beq	Solve_B2			;no, skip

		tst.w	pick_across(a6)		;across clue also?
		beq.s	Solve_Z3			;skip if not

		lea	QRT_1(pc),a0
		lea	SDC_YN(pc),a1
		moveq	#3,d0

		move.l	a0,irt_itext(a6)	;else pop up a
		move.l	a1,irt_tlist(a6)	;QueryReq
		move.w	d0,irt_count(a6)

		bsr	DoQueryReq

		btst	#6,applic_flag2(a6)	;"YES" gadget hit?
		beq.s	Solve_B2			;skip if not

Solve_Z3		lea	ClearDown(pc),a0	;addr of erase routine
		move.l	a0,erasecode(a6)	;to use in case of error

		lea	Mark_Down(pc),a0	;addr of marker code
		move.l	a0,solvecode(a6)	;if sol'n fits

		bsr	ShowDownClue	;get clue no. & display it
		bsr	ShowQuestion	;as it says!-see above

;		lea	GetSolution(pc),a0	;clear the text
;		move.l	gg_SpecialInfo(a0),a0	;buffer in the
;		clr.w	si_BufferPos(a0)		;string gadget
;		move.l	si_Buffer(a0),a0
;		clr.b	(a0)

		bsr	ShowPartDown


* Now set up rhb_ structure for the requester and the
* HandleRequest() routine and do it...


		move.l	ThisReq(a6),a4
		lea	SolveReq(pc),a0
		move.l	a0,rhb_Requester(a4)
;		lea	DG_Done(pc),a0
		lea	InitSolnGad(pc),a0
		move.l	a0,rhb_PreCode(a4)
		move.l	mw_handle(a6),rhb_Window(a4)
		move.l	mw_userport(a6),rhb_UserPort(a4)
		move.l	mw_IDCMP(a6),rhb_IDCMP(a4)
		lea	ehb_req(pc),a0
		move.l	a0,rhb_EHB(a4)

		bsr	HandleRequest

		lea	GetSolution(pc),a0
		move.l	soln_down(a6),a1
		bsr	TransferSoln

		bsr	InsertDown	;try putting it in

		lea	ReportList(pc),a0

		add.l	d0,d0		;error code * 4 as index
		add.l	d0,d0		;into jump table

		add.l	d0,a0		;point to jump table

		move.l	(a0),a0		;get jump address

		jsr	(a0)		;and execute 'error' routine


* Here, we've finished. Restore normal IDCMP & return to
* main event handler.


Solve_B2		move.l	mw_handle(a6),a0
		move.l	mw_IDCMP(a6),d0

		CALLINT	ModifyIDCMP

		move.l	mw_handle(a6),a0
		CALLINT	ActivateWindow

		bsr	DisplayGrid		;and show the results

		rts


* InitSolnGad(a4)
* a4 = ptr to initialised requester handler block

* Activate the solution requester gadget.

* a0-a2 corrupt


InitSolnGad	lea	GetSolution(pc),a0
		move.l	rhb_Window(a4),a1
		move.l	rhb_Requester(a4),a2

		CALLINT	ActivateGadget

		rts


* GotSolution(a6)
* a6 = ptr to main program variables
* handles text transfer from GetSolution requester
* once entered, & releases the requester loop.

* nothing corrupt


GotSolution	bra	QuitReq


* Rubout(a6)
* a6 = ptr to main program variables
* Perform the "Rubout Solution" function.


* Assume ALL registers corrupt!


Rubout		btst	#1,applic_flag2(a6)	;HELP on?
		beq.s	Rubout_Z1		;skip if not

		lea	Help_RS(pc),a0	;else pop up a
		moveq	#4,d0		;help box
		bsr	_PopUpQR

		beq	Rubout_B2	;skip if user cancels

Rubout_Z1	bsr	PickClue		;see above


* Now handle mouse events here, until a clue has been picked.
* Temporarily restrict IDCMP to MOUSEMOVE/MOUSEBUTTONS and the
* gadget selection IDCMPs only (latter to allow grid to be
* scrolled to find clue to solve etc!).
* Then recover the normal IDCMP at the end.


		move.l	mw_handle(a6),a0
		move.l	#MOUSEMOVE+MOUSEBUTTONS,d0
		add.l	#GADGETDOWN+GADGETUP,d0

		CALLINT	ModifyIDCMP

Rubout_L1	move.l	mw_userport(a6),a0
		lea	ehb_std(pc),a5

		bsr	DoEvent		;completely event driven!

		btst	#3,applic_flag1(a6)	;picked a clue?
		bne.s	Rubout_L1		;loop until done

		move.l	grid_array(a6),a0
		add.l	grid_offset(a6),a0	;point to square data
		move.w	(a0),d0			;get square data
		tst.b	d0			;check if white square
		bne.s	Rubout_1a		;and continue if OK

		lea	BlackIsNoNo(pc),a0
		lea	IRT_1(pc),a1
		moveq	#3,d0

		move.l	a0,irt_tlist(a6)	;inform user that a
		move.l	a1,irt_itext(a6)	;white square MUST
		move.w	d0,irt_count(a6)	;be selected!

		bsr	LinkInfoText
		bsr	ShowInfoReq

		bra	Rubout_B2	;exit cleanly

Rubout_1a	bsr	WhichClue	;find which clue picked

		move.w	pick_across(a6),d0	;across clue?
		beq.s	Rubout_B1		;skip if not

		tst.w	pick_down(a6)	;down clue also?
		beq.s	Rubout_Y1	;skip if not

		lea	QRT_1(pc),a0
		lea	RAC_YN(pc),a1
		moveq	#3,d0

		move.l	a0,irt_itext(a6)	;else pop up a
		move.l	a1,irt_tlist(a6)	;QueryReq
		move.w	d0,irt_count(a6)

		bsr	DoQueryReq

		btst	#6,applic_flag2(a6)	;"YES" gadget hit?
		beq.s	Rubout_B1		;skip if not

Rubout_Y1	move.l	pick_offset(a6),a0	;point to picked
		add.l	grid_array(a6),a0		;grid square
		move.w	(a0),d0			;get square data
		cmp.b	#" ",d0			;blank white square?
		bne.s	Rubout_Z2		;continue if not

;		move.l	clue_AcEntry(a6),a0	;is there a
;		tst.b	cle_Solved(a0)		;solution to rub out?
;		bne.s	Rubout_Z2		;skip if there is

		lea	IRT_1(pc),a0		;else pop up a
		lea	NoASolnHere(pc),a1	;requester to inform
		moveq	#5,d0			;user

		move.l	a0,irt_itext(a6)	;that there is no
		move.l	a1,irt_tlist(a6)	;valid solution here
		move.w	d0,irt_count(a6)

		bsr	LinkInfoText
		bsr	ShowInfoReq

		bra.s	Rubout_B1	;and go for down clue

Rubout_Z2	bsr	ClearAcross	;here erase across solution
		bsr	DisplayGrid	;and show the results

		move.l	clue_AcEntry(a6),a1	;and signal that
		clr.b	cle_Solved(a1)		;it's now erased

Rubout_B1	move.w	pick_down(a6),d0	;down clue exists?
		beq.s	Rubout_B2	;skip if not

		tst.w	pick_across(a6)	;across clue also?
		beq.s	Rubout_Y2	;skip if not

		lea	QRT_1(pc),a0
		lea	RDC_YN(pc),a1
		moveq	#3,d0

		move.l	a0,irt_itext(a6)	;else pop up a
		move.l	a1,irt_tlist(a6)	;QueryReq
		move.w	d0,irt_count(a6)

		bsr	DoQueryReq

		btst	#6,applic_flag2(a6)	;"YES" gadget hit?
		beq.s	Rubout_B2		;skip if not

Rubout_Y2	move.l	pick_offset(a6),a0	;point to picked
		add.l	grid_array(a6),a0		;grid square
		move.w	(a0),d0			;get square data
		cmp.b	#" ",d0			;blank white square?
		bne.s	Rubout_Z3		;continue if not

;		move.l	clue_DnEntry(a6),a0	;is there a
;		tst.b	cle_Solved(a0)		;solution to rub out?
;		bne.s	Rubout_Z3		;skip if there is

		lea	IRT_1(pc),a0		;else pop up a
		lea	NoDSolnHere(pc),a1	;requester to inform
		moveq	#5,d0			;user

		move.l	a0,irt_itext(a6)	;that there is no
		move.l	a1,irt_tlist(a6)	;valid solution here
		move.w	d0,irt_count(a6)

		bsr	LinkInfoText
		bsr	ShowInfoReq

		bra.s	Rubout_B2	;and leave

Rubout_Z3	bsr	ClearDown	;here erase down solution
		bsr	DisplayGrid	;and show the results

		move.l	clue_DnEntry(a6),a1	;and signal that
		clr.b	cle_Solved(a1)		;it's erased

Rubout_B2	move.l	mw_handle(a6),a0	;reset original IDCMP
		move.l	mw_IDCMP(a6),d0

		CALLINT	ModifyIDCMP

		move.l	mw_handle(a6),a0	;reactivate the main window
		CALLINT	ActivateWindow

		rts


* Various data structures for the solve requester


SolveReq:
	dc.l	NULL
	dc.w	25,12
	dc.w	270,220
	dc.w	0,0
	dc.l	GetSolution
	dc.l	NULL
	dc.l	NULL		;SolveT1
	dc.w	NULL
	dc.b	1,0
	dc.l	NULL
	dcb.b	32,0
	dc.l	NULL
	dc.l	NULL
	dcb.b	36,0

GetSolution:
	dc.l	SolvePanel
	dc.w	88,188
	dc.w	100,8
	dc.w	GADGIMAGE
	dc.w	GADGIMMEDIATE+RELVERIFY+ENDGADGET
	dc.w	STRGADGET+REQGADGET
	dc.l	HBoxS1
	dc.l	NULL
	dc.l	IText1
	dc.l	NULL
	dc.l	GetSolutionSInfo
	dc.w	NULL
	dc.l	DoneIG
	dc.l	GotSolution

GetSolutionSInfo:
	dc.l	GetSolutionSIBuff
	dc.l	NULL
	dc.w	0
	dc.w	256
	dc.w	0
	dc.w	0,0,0,0,0
	dc.l	0
	dc.l	0
	dc.l	NULL

GetSolutionSIBuff:
	dcb.b	256,0
	cnop	0,2

HBoxS1:
	dc.w	-5,-6
	dc.w	110,20
	dc.w	4
	dc.l	HBox2Data
	dc.b	$000F,$0000
	dc.l	NULL


IText1:
	dc.b	9,0,RP_JAM1,0
	dc.w	-29,-20
	dc.l	NULL
	dc.l	ITextText1
	dc.l	IText2
ITextText1:
	dc.b	'Enter Solution Below:',0
	cnop	0,2
IText2:
	dc.b	1,0,RP_JAM1,0
	dc.w	-30,-21
	dc.l	NULL
	dc.l	ITextText2
	dc.l	NULL
ITextText2:
	dc.b	'Enter Solution Below:',0
	cnop	0,2

SolvePanel:
	dc.l	NULL
	dc.w	0,0
	dc.w	1,1
	dc.w	GADGHBOX+GADGHIMAGE+GADGIMAGE
	dc.w	NULL
	dc.w	BOOLGADGET+REQGADGET
	dc.l	PanelImage
	dc.l	NULL
	dc.l	SolveT1
	dc.l	NULL
	dc.l	NULL
	dc.w	NULL
	dc.l	NULL
	dc.l	NULL	;extra entry!

SolveT1:
	dc.b	9,0,RP_JAM1,0
	dc.w	77,9
	dc.l	NULL
	dc.l	STT_1
	dc.l	SolveT2

STT_1:
	dc.b	'Enter Solution',0
	cnop	0,2

SolveT2:
	dc.b	1,0,RP_JAM1,0
	dc.w	76,8
	dc.l	NULL
	dc.l	STT_1
	dc.l	SolveT3

SolveT3:
	dc.b	4,0,RP_JAM1,0
	dc.w	62,33
	dc.l	NULL
	dc.l	ITT_Alt1
	dc.l	SolveT4

SolveT4:
	dc.b	5,0,RP_JAM1,0
	dc.w	61,32
	dc.l	NULL
	dc.l	ITT_Alt1
	dc.l	SolveT5

SolveT5:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,49
	dc.l	NULL
	dc.l	NULL		;STT_3
	dc.l	SolveT6

SolveT6:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,48
	dc.l	NULL
	dc.l	NULL		;STT_3
	dc.l	SolveT7

SolveT7:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,63
	dc.l	NULL
	dc.l	NULL		;STT_4
	dc.l	SolveT8

SolveT8:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,62
	dc.l	NULL
	dc.l	NULL		;STT_4
	dc.l	SolveT9

SolveT9:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,77
	dc.l	NULL
	dc.l	NULL		;STT_5
	dc.l	SolveT10

SolveT10:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,76
	dc.l	NULL
	dc.l	NULL		;STT_5
	dc.l	SolveT11

SolveT11:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,91
	dc.l	NULL
	dc.l	NULL		;STT_6
	dc.l	SolveT12

SolveT12:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,90
	dc.l	NULL
	dc.l	NULL		;STT_6
	dc.l	SolveT13

SolveT13:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,105
	dc.l	NULL
	dc.l	NULL		;STT_7
	dc.l	SolveT14

SolveT14:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,104
	dc.l	NULL
	dc.l	NULL		;STT_7
	dc.l	SolveT15

SolveT15:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,119
	dc.l	NULL
	dc.l	NULL		;STT_8
	dc.l	SolveT16

SolveT16:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,118
	dc.l	NULL
	dc.l	NULL		;STT_8
	dc.l	SolveT17

SolveT17:
	dc.b	9,0,RP_JAM1,0
	dc.w	11,133
	dc.l	NULL
	dc.l	NULL		;STT_9
	dc.l	SolveT18

SolveT18:
	dc.b	1,0,RP_JAM1,0
	dc.w	10,132
	dc.l	NULL
	dc.l	NULL		;STT_9
	dc.l	NULL


SolveBuf		ds.b	256

AcrossBuf	ds.b	256

DownBuf		ds.b	256







