;$VER: module.i 1.22 (28-02-1997) damian@cybercomm.nl

nb_SIZEOF		EQU	26	;why not in includes?
LINK_KIND		EQU	10	;next gadget to the right of previous
OFF_KIND		EQU	15	;following gadget disabled

;------------------------------ GENERAL -----------------------------------

;Custom blanker-modules:
;input:		a5	=	APTR Globals (saved/restored before/after
;				calling you blanker code.)
;output:	status register's zeroflag SET on failure, UNSET
;		on succes:	moveq #TRUE,d0
;				rts		;succesfull exit

;				moveq #FALSE,d0
;				rts		;unsuccesfull exit
;		in the latter case, MBlank will use its internal
;		'Black-Screen' as a backup.

;Your code MUST be 100% position-independant.

;--------------------------- MODULE STRUCTURE --------------------------------

;Blanker module structure, equates, flags etc.
 STRUCTURE BlmSimple,0

    LONG	blm_ID		;allways 'BLMS' for simples, other types
				;may be added in future.
    LONG	blm_Length	;length of module-file in bytes.
    BPTR	blm_Code	;code-entry of your module, MUST be relative
				;to module start. (blm_structure)
;blm_Info not yet implemented, set to NULL for backwards compatibility.
    APTR	blm_Info	;currently unused, set to NULL
    APTR	blm_Settings	;set to NULL if you don't support.
    APTR	blm_Extend	;currently unused, set to NULL
    BYTE	blm_Flags	;general flags field. Set to NULL for BWC.
    BYTE	blm_Pad1
    WORD	blm_Pad2
    LABEL	blm_SIZEOF	;This size will remain constant.

;SETTINGS structures
;all pointers must be relative to module address
 STRUCTURE ModSlide,0
    APTR	slide_TTName	;tooltype name, so MBlank can parse
    LONG	slide_Default	;used if tooltype 'TTName' not found
    LONG	slide_Min	;
    LONG	slide_Max	;
    APTR	slide_GText	;gadget text, if NULL single height used
    LABEL	slide_SIZE

 STRUCTURE ModCycle,0
    APTR	cycle_TTName	;tooltype 'NAME'
    LONG	cycle_Default	;ordinal number of selected item (0 - ...)
    LONG	cycle_Count	;number of items
    APTR	cycle_GText	;gadget text
    LABEL	cycle_SIZEOF
    APTR	cycle_Items	;the rest are #Count APTRs to item
				;texts which should match the tooltype
				;values exactly, so MBlank can find out
				;what the current setting is and set it.
;   APTR	cycle_Item...	;etc.
;   APTR	NULL-termination

 STRUCTURE ModCheck,0
    APTR	check_TTName
    LONG	check_Default	;TRUE or FALSE
    APTR	check_GText
    LABEL	check_SIZE

 STRUCTURE ModString,0
    APTR	string_TTName	;value will be initial contents of string
    APTR	string_GText
    LABEL	string_SIZE

;--------------------------- GLOBAL STRUCTURE ---------------------------------
;Instructions on using the AllGlobals(a5) structure:

;- PRIVATE	Blanker modules may not use these in any way!
;- LIB		A library pointer which is valid. (blanker modules run
;		on the same context as the Process which opened the Libs.)
;		Don't close these Libs. under any circumstance.
;- READ		May be read, contents are valid.
;- USE		Space may be used, contents may not be valid!
;- CHANGE	May be set, according to rules.

; A module can Wait() on the gb_ResetSignal(a5) if it doesn't have to keep
; working. You can ofcourse also poll this signal.
; If the module does polling to determine wether or not a significant
; input-event ocurred, use btst #GB_BLANK,gb_Flags(a5).(beq ABORT_blanking).

; The gb_Random(a5) pointer is a pointer to a pseudo-random generator, which
; I copied from one of Toby Simpson's example Lottery programs.(Shopper)
; input:	d0.w	=	maximum value (1 to 65535).
; All registers get saved/restored, therefore the gb_Random entry can
; easily be used from within iterations.
; output:	d0.w	=	Random number (0 to maximum value-1).

; variables/pointers/structures
 STRUCTURE AllGlobals,0
    STRUCT	gb_NewBrokerStruct,nb_SIZEOF
    BYTE	gb_ExtFlags
    BYTE	gb_ActionFlags
    STRUCT	gb_HotKeyIX,ix_SIZEOF
    APTR	gb_WBstartupMsg
    APTR	gb_Broker
    APTR	gb_WBLock
    APTR	gb_Screen
    APTR	gb_VisInfo
    APTR	gb_Menu
    APTR	gb_Window
    APTR	gb_BitMap
    APTR	gb_DiskObject	;READ, if MBlank found your mod's icon, its
				;address is stored here.(DO NOT FREE!)
    APTR	gb_Process
    APTR	gb_AppItem
    APTR	gb_ModLock
    APTR	gb_FIB
    APTR	gb_ModHandle
    APTR	gb_Module	;READ, address of your module
    APTR	gb_Random	;READ, entry point to pseudo random-number
				;generator. (Toby Simpson)
    LONG	gb_ModType
    LONG	gb_ModSize
    APTR	_IconBase	;LIB, you can use all of the following
    APTR	_IntBase	;LIB, pointers as if you had opened the
    APTR	_CxBase		;LIB, libraries yourself. NEVER close
    APTR	_DOSBase	;LIB, these libraries!!! You don't have
    APTR	_WBBase		;LIB, to check these pointers first, if
    APTR	_GTBase		;LIB, MBlank has come this far, ALL libs
    APTR	_GfxBase	;LIB, will have opened. (versions 37+ min.).
    LONG	gb_OldDir
    LONG	gb_Ticks
    LONG	gb_Counter
    LONG	gb_Delay
    LONG	gb_Store	;USE, used by ToolType macros
    LONG	gb_SigNums
    LONG	gb_CountSignal
    LONG	gb_PopSignal
    LONG	gb_ResetSignal	;READ, WAIT() on this one, or poll
    BYTE	gb_CountSigNum
    BYTE	gb_PopSigNum
    BYTE	gb_ResetSigNum	;READ, the bitnumber of the above
    BYTE	gb_Flags	;READ, btst #GB_BLANK,gb_Flags(a5), beq Quit
    STRUCT	gb_ModPath,128
    STRUCT	gb_ModName,32
    STRUCT	gb_User,512	;USE, space can be used, contains path/name
				;to your module on entry

;Do NOT rely on the size of this structure, it may be extended.
;In fact, internally it allready has been extended for MBlank itself.

;gb_Flags:		Bit:	Flagging:
GB_BLANK	EQU	4	;if CLEAR, blanking should abort right now,
				;but first CLEAN UP EVERYTHING.!

;--------------------------- TOOLTYPE MACROS -------------------------------

;Macros for convenience and clarity
;FINDTT		-	Checks existence of a tooltype
;Example usage:	FINDTT	ALERT
;		beq.s	NotFound
;		...	...
;ALERT		dc.b	'ALERT',NULL

;Always tst.l gb_DiskObject(a5) first, maybe MBlank didn't get it!

FINDTT		MACRO
		move.l	gb_DiskObject(a5),a0
		move.l	do_ToolTypes(a0),a0
		lea	\1(pc),a1
		CALLIC	FindToolType
		tst.l	d0
		ENDM

;TTVAL		-	Translates a number tooltype value and stores
;			it in the global-structure.
;Template:	TTVAL	offset,size,minimum,maximum
;			(defaults should be set in advance!)
;function:	can be used directly after FINDTT, translates a string
;		to an integer and stores it in <variable>(a5).
;offset:	must be a field in the (a5) AllGlobals structure.
;size:		b, w, l. (byte, word, long)
;minimum:	if<minimum, uses default. (not changed)
;maximum:	if>maximum, uses default. (not changed)

;for example:	Handle SPHERES tooltype
;		FINDTT	TT_SPHERES
;		TTVAL	bog_Spheres,w,1,30,10
;		...	...
;TT_SPHERES	dc.b	'SPHERES',NULL

;The above two lines will:	-check the existence of 'SPHERES' tooltype
;				    -read the tooltype value
;				    -check its range and validity, if ok
;					-move.w #result,bog_Spheres(a5)
;				-end

_ttvalused	set	0
TTVAL		MACRO
		beq.s	TTMnext\<_ttvalused>	;not found by FINDTT
		move.l	d0,d1			;found it, extract value
		lea	gb_Store(a5),a0
		move.l	a0,d2
		CALLDOS	StrToLong	;gb_Store=longalligned, don't worry.
		tst.l	d0
		ble.s	TTMnext\<_ttvalused>	;no digits found, default
		move.l	gb_Store(a5),d0		;StrToLong results
		cmp.\2	#\3,d0			;no smaller than \3 argument
		bcs.s	TTMnext\<_ttvalused>	;otherwise default used
		cmp.\2	#\4,d0			;no larger than \4 argument
		bhi.s	TTMnext\<_ttvalused>	;otherwise default used
		move.\2	d0,\1(a5)
TTMnext\<_ttvalused>	
_ttvalused	set	_ttvalused+1
		ENDM

;--------------------------- MISCELLENEOUS -------------------------------

;handy macros
CALLDOS		MACRO				;call dos.library
		move.l	_DOSBase(a5),a6
		jsr	_LVO\1(a6)
		ENDM

CALLINT		MACRO				;call intuition.library
		move.l	_IntBase(a5),a6
		jsr	_LVO\1(a6)
		ENDM

CALLGFX		MACRO				;call graphics.library
		move.l	_GfxBase(a5),a6
		jsr	_LVO\1(a6)
		ENDM

CALLEXEC	MACRO				;call the almighty
		movea.l	(4),a6
		jsr	_LVO\1(a6)
		ENDM

CALLEX		MACRO
		move.l	(4),a6
		jsr	_LVO\1(a6)
		ENDM

CALLIC		MACRO				;call icon.library
		move.l	_IconBase(a5),a6
		jsr	_LVO\1(a6)
		ENDM

CALLWB		MACRO				;call workbench.library
		move.l	_WBBase(a5),a6
		jsr	_LVO\1(a6)
		ENDM

