;
; dbx.arrow.s
;
; Implementation of arrow icons as dbx controls (MDW)
;
;  1994 Straylight
;

;----- Standard header ------------------------------------------------------

		GET	libs:header
		GET	libs:swis

;----- External dependencies ------------------------------------------------

		GET	sapphire:dbox
		GET	sapphire:repeater

		GET	sapphire:dbx.dbx
		GET	sapphire:dbx._dbxMacs

;----- Main code ------------------------------------------------------------

		AREA	|Sapphire$$Code|,CODE,READONLY

arrow_event	EQU	&80000002		;Click on an arrow button
						;R1 == icon handle
						;R2 == increment value or 0

; --- arrow ---
;
; Control data:	+0 == increment when clicked with Select
;		+4
;
; Workspace:	--
;
; Flags:	--
;
; Use:		Control type for an arrow button.

		EXPORT	arrow
arrow		ROUT

		DBXWS	arrow__wSpace
		DCD	dbxMask_click

		TST	R2,#5			;Is this a bona fido click?
		MOVEQS	PC,R14			;No -- then ignore it
		STMFD	R13!,{R0-R3,R14}	;Save some registers away
		STR	R1,arrow__icon		;Save the icon handle

		; --- First, select the arrow button ---

		MOV	R0,R10			;Get the dialogue handle
		MOV	R2,#1			;Set icon's select state
		BL	dbox_select		;Show the button popped in

		; --- Calculate the increment to return ---

		SUB	R13,R13,#20		;Make some space for a block
		MOV	R1,R13			;Point to the block
		SWI	Wimp_GetPointerInfo	;Get the current mouse state
		LDR	R14,[R1,#8]		;Load the button status
		LDR	R2,[R9,#0]		;Get the arrow increment
		CMP	R14,#1			;Is Adjust being clicked?
		RSBEQ	R2,R2,#0		;Yes -- negate the increment
		STR	R2,arrow__inc		;Save the increment
		ADD	R13,R13,#20		;Reclaim the stack space

		; --- Now set up the repeater ---

		ADR	R0,arrow__repeat	;Point to repeater routine
		MOV	R1,R10			;Pass dialogue in R10
		MOV	R2,R12			;And workspace in R12
		BL	repeater		;Set up the repeater

		LDMFD	R13!,{R0-R3,PC}^	;Return to caller if all OK

arrow__wSpace	DCD	0

		LTORG

; --- arrow__repeat ---
;
; On entry:	R0 == number of repeats, or 0 for end of job
;
; On exit:	--
;
; Use:		Handles autorepeating for the arrow button.

arrow__repeat	ROUT

		STMFD	R13!,{R0-R3,R14}	;Save some registers
		CMP	R0,#0			;Is this the end?
		BEQ	%50arrow__repeat	;Yes -- do different things

		; --- Send a normal continuation event ---
		;
		; To avoid `buffering' effect, remove the MUL R2,R0,R2
		; instruction.

		LDMIA	R12,{R1,R2}		;Load increment and icon
		MUL	R2,R0,R2		;Accumulate lots of ops
		MOV	R0,#arrow_event		;Get the event code
		BL	dbx_sendEvent		;Send the event along nicely
		LDMFD	R13!,{R0-R3,PC}^	;And return to caller

		; --- Send end-of-the-job event ---

50arrow__repeat	MOV	R0,R10			;Yes -- get the dialogue
		LDR	R1,arrow__icon		;Load the icon handle
		MOV	R2,#0			;Deselect the button
		BL	dbox_select		;And do the deselect op

		MOV	R0,#arrow_event		;Get the event code
		BL	dbx_sendEvent		;Send the event along nicely
		LDMFD	R13!,{R0-R3,PC}^	;And return to caller

		LTORG

;----- Workspace ------------------------------------------------------------

		^	0,R12
arrow__wStart	#	0

arrow__icon	#	4			;Icon handle of button
arrow__inc	#	4			;Increment to return

arrow__wSize	EQU	{VAR}-arrow__wStart

		AREA	|Sapphire$$LibData|,CODE,READONLY

		DCD	arrow__wSize
		DCD	arrow__wSpace
		DCD	0
		DCD	0

;----- That's all, folks ----------------------------------------------------

		END
