
**	CODE	GADGETS 
**	CODER	MARC.B

; coded using the intuition tutorials by Mark Meany .....


	incdir		sys:include/
	
	include		intuition/intuition.i
	include		intuition/intuition_lib.i
	include		exec/exec.i
	include		exec/exec_lib.i



finish		equ	999

	

	
************************************
*	OPEN INTUITION LIBRARY	   *
************************************

	lea		int_name,a1
	moveq		#0,d0
	CALLEXEC	OldOpenLibrary
	tst		d0
	beq		the_end
	move.l		d0,_IntuitionBase


***************************************
*		OPEN WINDOW	      *
***************************************

	lea		window_main,a0
	CALLINT		OpenWindow
	tst		d0
	beq		exit
	move.l		d0,window_handle
	move.l		d0,a0	
	move.l		wd_UserPort(a0),main.up
	move.l		wd_RPort(a0),main.rp
	move.l		main.up,window.up

****************************************
*	MAIN CODE LOOP		       *
****************************************

	
loop
	bsr	WaitForMsg
	cmp.l	#finish,d5
	beq	close
	bra 	loop

****************************************
*	CHECK MESSAGE STATUS	       *
****************************************

WaitForMsg	
	move.l		window.up,a0	a0-->user port
	CALLEXEC	WaitPort	wait for something to happen
	move.l		window.up,a0	a0-->window pointer
	CALLEXEC	GetMsg		get any messages
	tst.l		d0		was there a message ?
	beq.s		WaitForMsg	if not loop back
	move.l		d0,a1		a1-->message
	move.l		im_Class(a1),d2	d2=IDCMP flags
	move.l		im_IAddress(a1),a5 a5=addr of structure
	CALLEXEC	ReplyMsg	answer os or it get angry
	move.l		d2,d0
	and.l		#GADGETUP!GADGETDOWN,d0
	beq.s		WaitForMsg
	move.l		gg_UserData(a5),d0
	move.l		d0,a0
	jsr		(a0)
		
.test_win	
	rts
	


***************************************** 
*	   CLOSE WINDOW			*
*****************************************

close
	move.l		window_handle,a0
	CALLINT		CloseWindow
		

*****************************************
*		CLOSE INTUITION		*
*****************************************

exit
	
	move.l		_IntuitionBase,a1
	CALLEXEC	CloseLibrary

the_end
	rts

*****************************************
*	    CODE DATA SECTION		*
*****************************************


window_main
	dc.w	0,0,640,250
	dc.b	1,0
	dc.l	GADGETUP!GADGETDOWN
	dc.l	ACTIVATE
	dc.l  	Gadget0,0,title,0,0
	dc.w	80,24,-1,-1,WBENCHSCREEN
title	dc.b	'GADGETS..................',0
	even


window_help
	dc.w	120,40,370,100
	dc.b	1,3
	dc.l	GADGETUP!GADGETDOWN
	dc.l	ACTIVATE
	dc.l  	gadjet3,0,.title,0,0
	dc.w	80,24,-1,-1,WBENCHSCREEN
.title	dc.b	'HELP IS AT HAND !!',0
	even

window_exit
	dc.w	120,40,370,100
	dc.b	1,3
	dc.l	GADGETUP!GADGETDOWN
	dc.l	ACTIVATE
	dc.l  	gadjet4,0,.title,0,0
	dc.w	80,24,-1,-1,WBENCHSCREEN
.title	dc.b	'ARE YOU SURE ?',0
	even


******************************************
*	    GADGET STRUCTURES		 *
******************************************

Gadget0_info:
    DC.W    FREEHORIZ!PROPBORDERLESS
    DC.W    $0000
    DC.W    $0000
    DC.W    $ffff/8
    DC.W    $ffff
    DC.W    0,0,0,0,0,0

Gadget0_image:
    DC.W    0,0,86,35,2
    DC.L    IM7Data
    DC.B    3,0
    DC.L    0

Gadget0_text0:
    DC.B    1,0
    DC.B    RP_JAM1+RP_COMPLEMENT
    DC.W    45,-11
    DC.L    0
    DC.L    Gadget0_itext0
    DC.L    Gadget0_text1

Gadget0_itext0:
    DC.B    'MOUSE  SPEED',0
    CNOP    0,2

Gadget0_text1
    DC.B    1,0
    DC.B    RP_JAM1
    DC.W   -40,20
    DC.L    0
    DC.L    Gadget0_itext1
    DC.L    Gadget0_text2

Gadget0_itext1:
    DC.B    'FAST',0
    CNOP    0,2

Gadget0_text2
    DC.B    1,0
    DC.B    RP_JAM1
    DC.W    190,20
    DC.L    0
    DC.L    Gadget0_itext2
    DC.L    0

Gadget0_itext2:
    DC.B    'SLOW',0
    CNOP    0,2

Gadget0_ID   EQU     0

Gadget0:
    DC.L    gadjet
    DC.W    -400,-40
    DC.W    180,35
    DC.W    GRELBOTTOM!GRELRIGHT!GADGHIMAGE!GADGIMAGE!SELECTED
    DC.W    RELVERIFY
    DC.W    PROPGADGET
    DC.L    Gadget0_image
    DC.L    Gadget0_image
    DC.L    Gadget0_text0,0
    DC.L    Gadget0_info
    DC.W    Gadget0_ID
    DC.L    mouse_speed





gadjet
	dc.l	gadjet2
	dc.w	-100,-34
.topleft
	dc.w	58,16
	dc.w	GRELBOTTOM!GRELRIGHT!GADGHBOX
	dc.w	RELVERIFY
	dc.w	BOOLGADGET
	dc.l	0
	dc.l	0
	dc.l	.itext
	dc.l	0
	dc.l	0
	dc.w	0
	dc.l	cancel



.itext
	dc.b	1,0,RP_JAM1,0
	dc.w	16,5
	dc.l	0
	dc.l	.string
	dc.l	0
.string
	dc.b	'QUIT',0
	even


gadjet2
	dc.l	0
	dc.w	-580,-34
.topleft
	dc.w	58,13
	dc.w	GADGHIMAGE!GADGIMAGE!GRELBOTTOM!GRELRIGHT
	dc.w	RELVERIFY
	dc.w	BOOLGADGET
	dc.l	.IMD1
	dc.l	.IMD2
	dc.l	.itext
	dc.l	0
	dc.l	0
	dc.w	0
	dc.l	get_help

.IMD1
	dc.w	0,0,60,16,2
	dc.l	IM1Data
	dc.b	3,0
	dc.l	0

.IMD2
	dc.w	0,0,60,16,2
	dc.l	IM2Data
	dc.b	3,0
	dc.l	0

.itext
	dc.b	1,0,RP_JAM1,0
	dc.w	16,5
	dc.l	0
	dc.l	.string
	dc.l	0
.string
	dc.b	'HELP',0
	even


gadjet3
	dc.l	0
	dc.w	-80,-24
.topleft
	dc.w	58,13
	dc.w	GRELBOTTOM!GRELRIGHT
	dc.w	RELVERIFY
	dc.w	BOOLGADGET
	dc.l	.border
	dc.l	0
	dc.l	.itext
	dc.l	0
	dc.l	0
	dc.w	0
	dc.l	ok
.border
	dc.w	-2,-1
	dc.b	2,0,RP_JAM1
	dc.b	5
	dc.l	.vectors
	dc.l	0
.vectors
	dc.w	0,0
	dc.w	60,0
	dc.w	60,14
	dc.w	0,14
	dc.w	0,0
.itext
	dc.b	1,0,RP_JAM1,0
	dc.w	16,3
	dc.l	0
	dc.l	.string
	dc.l	0
.string
	dc.b	'O.K',0
	even

help_txt
	dc.b	1,0,RP_JAM1,0
	dc.w	15,10
	dc.l	0
	dc.l	.txt
	dc.l	help_txt2

.txt	dc.b	'So you need help . . . . . . .',0
	even

help_txt2
	dc.b	1,0,RP_JAM1,0
	dc.w	15,25
	dc.l	0
	dc.l	.txt
	dc.l	help_txt3

.txt	dc.b	'Well you need to read the excellent',0
	even

help_txt3

	dc.b	1,0,RP_JAM1,0
	dc.w	15,40
	dc.l	0
	dc.l	.txt
	dc.l	0

.txt	dc.b	'intuition tutorials by Mark Meany !!',0
	even

gadjet4
	dc.l	gadjet5
	dc.w	-100,-40
.topleft
	dc.w	81,32
	dc.w	GRELBOTTOM!GRELRIGHT!GADGHIMAGE!GADGIMAGE
	dc.w	RELVERIFY
	dc.w	BOOLGADGET
	dc.l	.IMD1
	dc.l	.IMD2
	dc.l	0
	dc.l	0
	dc.l	0
	dc.w	0
	dc.l	wrap_up

.IMD1
	dc.w	0,0,96,31,2
	dc.l	IM6Data
	dc.b	3,0
	dc.l	0

.IMD2
	dc.w	0,0,96,31,2
	dc.l	IM5Data
	dc.b	3,0
	dc.l	0




exit_txt
	dc.b	1,0,RP_JAM1,0
	dc.w	15,10
	dc.l	0
	dc.l	.txt
	dc.l	0

.txt	dc.b	'Are you sure about this . . . . . . . ?',0
	even

gadjet5
	dc.l	0
	dc.w	-345,-40
.topleft
	dc.w	81,32
	dc.w	GRELBOTTOM!GRELRIGHT!GADGHIMAGE!GADGIMAGE
	dc.w	RELVERIFY
	dc.w	BOOLGADGET
	dc.l	.IMD1
	dc.l	.IMD2
	dc.l	0
	dc.l	0
	dc.l	0
	dc.w	0
	dc.l	no_exit

.IMD1
	dc.w	0,0,96,31,2
	dc.l	IM4Data
	dc.b	3,0
	dc.l	0

.IMD2
	dc.w	0,0,96,31,2
	dc.l	IM3Data
	dc.b	3,0
	dc.l	0


***************************************
*	  GADGET SUBROUTINES	      *
***************************************

;this routine opens a window and displays some text
;above two gadgets the user_port and ras_port
;are loaded into the window.up variable
;so the main prog can monitor the two gadgets

cancel
	lea		window_exit,a0
	CALLINT		OpenWindow
	tst		d0
	beq		exit
	move.l		d0,exit_handle
	move.l		d0,a0	
	move.l		wd_UserPort(a0),exit.up
	move.l		wd_RPort(a0),exit.rp
	move.l		exit.up,window.up
	move.l		exit.rp,a0
	lea		exit_txt,a1
	move.l		#15,d0
	move.l		#15,d1
	CALLINT		PrintIText
	rts

*************************************
*		HELP GADGET	    *
*************************************

;this routine does basically the same as the above one

get_help
		
	lea		window_help,a0
	CALLINT		OpenWindow
	tst		d0
	beq		exit
	move.l		d0,help_handle
	move.l		d0,a0	
	move.l		wd_UserPort(a0),help.up
	move.l		wd_RPort(a0),help.rp
	move.l		help.up,window.up
	move.l		help.rp,a0
	lea		help_txt,a1
	move.l		#15,d0
	move.l		#15,d1
	CALLINT		PrintIText
	rts

;this routine closes the help window and passes
;the main user_port back into the window.up variable
;so it can monitor the main display gadgets

ok
	move.l		help_handle,a0
	CALLINT		CloseWindow
	move.l		main.up,window.up
	rts

*************************************
*		QUIT GADGETS	    *
*************************************

;these next two routines do the same as the o.k routine
;except one ends the program while the other
;returns control as above

wrap_up
	move.l		exit_handle,a0
	CALLINT		CloseWindow
	move.l		#finish,d5
	move.l		main.rp,window.rp
	move.l		main.up,window.up
	rts

no_exit
	move.l		exit_handle,a0
	CALLINT		CloseWindow
	move.l		main.rp,window.rp
	move.l		main.up,window.up
	rts

**************************************
*	MOUSE GADGET		     *
**************************************

;this routine alters the pointer speed via preferences
;it does this by reading the values returned in the gadget
;structure ,converting them and loading them into
;the preferences structure.
	
mouse_speed

	move.l		gg_SpecialInfo(a5),a1
	move.w		pi_HorizPot(a1),h_pot
	move.w		h_pot,d2
	mulu		#6,d2
	divu		#$ffff,d2
	and.w		#$fffe,d2
	


************************************
*	GET CURRENT PREF'S	   *
************************************

	lea		prefbuffer,a0		this routine loads
	move.l		#232,d0			the current pref's settings
	CALLINT		GetPrefs		into a buffer
	

************************************
*	SET CURRENT PREF'S	   *
************************************

	lea		prefbuffer,a0		load preferences buffer
	move.w		d2,108(a0)		alter mouse speed
	move.l		#232,d0
	move.l		#1,d1			send IDCMP flag
	CALLINT		SetPrefs
	rts

	

***************************************
*	CODE VARIABLES		      *
***************************************

_IntuitionBase	dc.l 0
window_handle	dc.l 0
window.up	dc.l 0
window.rp	dc.l 0
main.up		dc.l 0
main.rp		dc.l 0
help.up		dc.l 0
help.rp		dc.l 0
help_handle	dc.l 0
exit_handle	dc.l 0
exit.up		dc.l 0
exit.rp		dc.l 0
h_pot		dc.w 0
prefbuffer	ds.b 232
int_name	dc.b 'intuition.library',0

	SECTION	gfx.data,CODE_C


IM2Data		incbin	Source:M.Bateson/Gadgets/GADGET
IM1Data		incbin	Source:M.Bateson/Gadgets/GADGET1
IM3Data		incbin	Source:M.Bateson/Gadgets/GADGET2
IM4Data		incbin	Source:M.Bateson/Gadgets/GADGET3
IM5Data		incbin	Source:M.Bateson/Gadgets/GADGET4
IM6Data		incbin	Source:M.Bateson/Gadgets/GADGET5
IM7Data		incbin	Source:M.Bateson/Gadgets/mous_gadget
		
end

