		NOLIST
* This can only be assembled under DEVPAC V3.01 since there are many opcodes
* only DEVPAC 3.01 understands. As far as I know.

		OPT	ow-,o+,ow6+,NODEBUG,NOLINE,ALINK

*AUTO:		make KCommodity

;* $Revision Header built automatically *************** (do not edit) ************
;*
;* © Copyright by GuntherSoft
;*
;* File             : KCommodity.Asm
;* Created on       : Sunday, 05-Jan-92 14:22:48
;* Created by       : Kai Iske
;* Current revision : V2.00
;*
;*
;* Purpose
;* -------
;*     This is a multifunctional Commodity including many useful tools.
;*     The best part of it is the revision control system this header was made
;*     with. All previous LogMessages got lost due to change to KCommodity to
;*     arrange the new ones.
;*
;* Revision V2.00
;* --------------
;* changed on Thursday, 07-Sep-92 04:07:07  by  Kai Iske.   LogMessage :
;*     Again, many, many changes were made to KCommodity. One of
;*     the most significant changes is, that all windows are font-
;*     sensitive now. Many new options added. That`s why the
;*     version shows 2.0 now. :-)
;*
;* Revision V1.75
;* --------------
;* changed on Wednesday, 16-May-92 00:04:04  by  Kai Iske.   LogMessage :
;*     Too many things :-) Some of the major changes are : Better Screen/Window
;*     Cycling, Exploding Layers, Screen-Dimmer, ........
;*     See History.Txt for more and detailed information
;*
;* Revision V1.70
;* --------------
;* changed on Thursday, 19-Mar-92 16:02:34  by  Kai Iske.   LogMessage :
;*     Many, many, many, many changes made. See History.TXT for a complete list
;*
;* Revision V1.63
;* --------------
;* changed on Sunday, 15-Mar-92 01:14:29  by  Kai Iske.   LogMessage :
;*     Bugs in ESC-WindowClose, LeftyMouse and MouseBlanking removed.
;*     When Mouse is blanked no other sprites will be turned off now.
;*     Shell created now gets all the paths you used a PATH for.
;*
;* Revision V1.62
;* --------------
;* changed on Friday, 13-Mar-92 01:18:36  by  Kai Iske.   LogMessage :
;*     Added an Online-Help function giving help for almost every function
;*     KCommodity provides. Some bug fixes and remakes.
;*
;* Revision V1.61
;* --------------
;* changed on Wednesday, 11-Mar-92 22:33:00  by  Kai Iske.   LogMessage :
;*     All windows (except for Clock-Window) are menu driven now. The old shortcuts
;*     are kept. Improved StringGadget-Editing by adding a StringEdit-Hook. Menu-
;*     ShortCuts may be used while editing a StringGadget. Normal ShortCuts may
;*     still be used for convenience.
;*
;* Revision V1.60
;* --------------
;* changed on Wednesday, 11-Mar-92 02:09:43  by  Kai Iske.   LogMessage :
;*     Added function to map german "Umlauts" so that these are translated into
;*     "normal" chars. Registration may be printed out now.
;*
;* Revision V1.59
;* --------------
;* changed on Friday, 21-Feb-92 00:24:52  by  Kai Iske.   LogMessage :
;*     Removed most of the ToolTypes, since all settings may be stored to a file.
;*     Added an AppIcon and an AppMenuItem for easy popup of the control-window
;*     (for people who can`t remember HotKeys)
;*
;* Revision V1.58
;* --------------
;* changed on Tuesday, 18-Feb-92 01:32:26  by  Kai Iske.   LogMessage :
;*     Added HotKeys for all windows of KCommodity. HotKey for Shell added.
;*     HotKey definitions may be done within a window now
;*
;* Revision V1.57
;* --------------
;* changed on Sunday, 16-Feb-92 04:25:26  by  Kai Iske.   LogMessage :
;*     Preferences can be saved to alternative files to have several settings
;*     available. Interfaces between routines enhanced. KCommodity didn`t get
;*     quite larger (due to optimaziation). Control window now has menues.
;*
;* Revision V1.56
;* --------------
;* changed on Monday, 10-Feb-92 02:58:12  by  Kai Iske.   LogMessage :
;*     Shortened KCommodity. Added Window-Close via ESC-Key. Bugs removed.
;*     Layout changed.
;*
;* Revision V1.55
;* --------------
;* changed on Sunday, 09-Feb-92 03:32:21  by  Kai Iske.   LogMessage :
;*     Bugs removed. Added function to display costs for one day in telephone bill.
;*     Lefty mouse function added. When channels get stolen KCommodity will try
;*     to reallocate new ones the next time.
;*
;* Revision V1.54
;* --------------
;* changed on 02-Feb-92, Sunday 02-Feb-92  by  Kai Iske.   LogMessage :
;*     TimeZone/Tariff defaults can be set and will be saved to PREFSFILE.
;*     Position of PrefsWindow may be changed via ToolType/ARexx. ESC-Key is the
;*     terminator for a window. WB can be popped to fron when control window
;*     should be (re)opened. PrefsWindow-Pos may be set.
;*
;* Revision V1.53
;* --------------
;* changed on 31-Jan-92, Friday 31-Jan-92  by  23:10:34.   LogMessage :
;*     Now also generates Revision Headers for Pascal/Modula programs.
;*     Revision defines for Assembler improved since macros are created now.
;*     Added a gadget and an ARexx command to clear the logfile.
;*
;* Revision V1.52
;* --------------
;* changed on Friday, 31-Jan-92 22:02:26  by  Kai Iske.   LogMessage :
;*     Now the time and online displays and checks area handeled by a spererate
;*     process so that the displays and values are always adjusted correctly.
;*     Move the bill-checkbox-gadgets to the preferences window.
;*
;* Revision V1.51
;* --------------
;* changed on Sunday, 26-Jan-92 00:05:39  by  Kai Iske.   LogMessage :
;*     Added a telephone bill calculator, which keeps track of all logins made and
;*     saves them to a logfile. 3 definable times/unit for normal or cheap tariff.
;*     Accumulated costs can be retrieved. Writing to log file can be turned off.
;*
;* Revision V1.50
;* --------------
;* changed on Sunday, 19-Jan-92 23:19:59  by  Kai Iske.   LogMessage :
;*     Added new displaymodes in (Window)-TitleBar. Total amount of free memory,
;*     graphical display of free memory and accumulated online time.
;*
;* Revision V1.49
;* --------------
;* changed on Saturday, 18-Jan-92 23:23:55  by  Kai Iske.   LogMessage :
;*     Again some stupid bugs removed (why not). Added KeyStroke-Clicker with
;*     userdefinable volume. Changed layout. Screen/Mouse-Times are reset to
;*     previous values if a wrong one was entered.
;*
;* Revision V1.48
;* --------------
;* changed on Saturday, 18-Jan-92 02:28:32  by  Kai Iske.   LogMessage :
;*     Now includes Window-Cycling with user-definable Qualifiers.
;*     Bug hunting, but I still don`t know why it sometimes crashes on other
;*     machines, but not on mine.
;*
;* Revision V1.47
;* --------------
;* changed on Monday, 13-Jan-92 23:05:42  by  Kai Iske.   LogMessage :
;*     Now adds revision date within defines and skips defines if commented out
;*     or just thrown away. Bug in finding the current dir removed.
;*
;* Revision V1.46
;* --------------
;* changed on Monday, 13-Jan-92 17:15:37  by  Kai Iske.   LogMessage :
;*     Bug hunting. But still XOper displays some weird info. I think that`s a bug
;*     of XOper2.3 since it displays these infos while KCommodity isn`t running.
;*     Revision control system now gives one more define : DATE of revision
;*
;* Revision V1.45
;* --------------
;* changed on Monday, 13-Jan-92 13:50:39  by  Kai Iske.   LogMessage :
;*     Removed some weird bugs which made KCommodity crash the system.
;*
;* Revision V1.44
;* --------------
;* changed on Sunday, 12-Jan-92 00:04:32  by  Kai Iske.   LogMessage :
;*     Bug hunt (I hope the final). Some modifications the user probably won`t
;*     notice
;*
;* Revision V1.43
;* --------------
;* changed on Saturday, 11-Jan-92 03:26:14  by  Kai Iske.   LogMessage :
;*     Error in Event-Handler removed due to the fact that not all registers have
;*     been stored on stack before workthrough of routine
;*
;* Revision V1.42
;* --------------
;* changed on Friday, 10-Jan-92 23:23:00  by  Kai Iske.   LogMessage :
;*     Added a Screen/Mouseblanker. Mouse is either blanked after the given period
;*     of time or when key pressed. Blanking is turned off when pressing a key
;*     or moving the mouse.
;*
;* Revision V1.41
;* --------------
;* changed on Friday, 10-Jan-92 16:09:29  by  Kai Iske.   LogMessage :
;*     Did some 'tuning'. ARexx ClockWinPos wasn`t recognized just after a
;*     ClockWin 1. Control window comes to front if already active and HotKey is
;*     pressed.
;*
;* Revision V1.40
;* --------------
;* changed on Thursday, 09-Jan-92 18:33:19  by  Kai Iske.   LogMessage :
;*     Did some fine things on layout :-). Now a screentitle is set for all
;*     windows used by KCommodity. Also all windows are centered when poped up
;*     but they will keep their positions moved to during runtime
;*
;* Revision V1.39
;* --------------
;* changed on Thursday, 09-Jan-92 15:39:22  by  Kai Iske.   LogMessage :
;*     Bad errors removed. KCommodity didn`t keep track of absolute path of file.
;*     Now uses CurrentDir if no ???: is specified to get a correct lock to a
;*     file. It gets the lock of ARexx`s Process->pr_CurrentDir. Clock is now
;*     visible again :-)
;*
;* Revision V1.38
;* --------------
;* changed on Monday, 06-Jan-92 14:40:20  by  Kai Iske.   LogMessage :
;*     Corrected a little bug in environment variable settings
;*
;* Revision V1.37
;* --------------
;* changed on Sunday, 05-Jan-92 15:22:13  by  Kai Iske.   LogMessage :
;*     Added possibilty to 'jump over' some revisions by inserting the next
;*     revision number into gadgets
;*
;* Revision V1.36
;* --------------
;*     --- Initial release ---
;*
;*********************************************************************************
REVISION  MACRO
          dc.b "2.00"
          ENDM
REVDATE   MACRO
          dc.b "07-Sep-92"
          ENDM
REVTIME   MACRO
          dc.b "04:07:07"
          ENDM
AUTHOR    MACRO
          dc.b "Kai Iske"
          ENDM
VERNUM    EQU   2
REVNUM    EQU   00


		XREF	_InvertString
		XREF	_FreeIEvents
		XREF	_HotKey
		XDEF	_CxBase
		XDEF	_SysBase

		INCLUDE	System.gs			; Include our Headers
							; For DevPac >= 3 the preincludes
							; will be loaded
							; Otherwise the includes will be taken
		INCLUDE	Rexx/Errors.i
		INCLUDE	Rexx/Rxslib.i
		INCLUDE	Rexx/Storage.i
		INCLUDE	Libraries/ReqTools_Lib.i

		INCLUDE	Misc/MyMacros.i




**********************************************************************
*                Macros for defining the patchtable                  *
**********************************************************************
PATCHES		MACRO
NumPatch	SET	1
		IFEQ	NARG-2
		dc.w	\2,_LVO\1
		dc.l	New\1
		dc.w	Old\1
		ELSE
		FAIL
		ENDC
		ENDM
PATCH		MACRO
NumPatch	SET	NumPatch+1
		IFEQ	NARG-2
		dc.w	\2,_LVO\1
		dc.l	New\1
		dc.w	Old\1
		ELSE
		FAIL
		ENDC
		ENDM


**********************************************************************
*                   Versionnumber of libs, we need                   *
**********************************************************************
NEED_LIBVER	EQU	37

AREXXBUFFSIZE	EQU	8192
HOTKEYSIZE	EQU	128
FILEBUFFSIZE	EQU	256
LOGENTRYSIZE	EQU	80
STATUSLINESIZE	EQU	128

DEPTHWIDTH	EQU	28
MAXBARLEN	EQU	150
MAXPAGES	EQU	6
TIMEPAGE	EQU	0
DMEMPAGE	EQU	1
TMEMPAGE	EQU	2
TIMEMEMPAGE	EQU	3
GMEMPAGE	EQU	4
ONLINEPAGE	EQU	5
SNAPMEMPAGE	EQU	6

ESCKEY		EQU	$1B
HELPKEY		EQU	$5f
RESCKEY		EQU	$45

MINFRAMES	EQU	10
MAXFRAMES	EQU	64

MINACC		EQU	2
MAXACC		EQU	10
MINTHRES	EQU	0
MAXTHRES	EQU	10

MAXCLICKS	EQU	5

MAXFKEYWIDTH	EQU	80

MAXPOINTERS	EQU	50
MAXSCREENS	EQU	25

SIGHANDSHAKE	EQU	SIGBREAKF_CTRL_E
SIGTIMEREMAKE	EQU	SIGBREAKF_CTRL_F
SIGBILLWIN	EQU	SIGBREAKF_CTRL_D

SIGMOUSE	EQU	SIGBREAKF_CTRL_E
SIGLBUTTON	EQU	SIGBREAKF_CTRL_F
SIGRBUTTON	EQU	SIGBREAKF_CTRL_D

REQ_CYCLE	EQU	-1
REQ_TIMER	EQU	-2
REQ_DISKCHANGE	EQU	-3
REQ_SCRBACK	EQU	-4
REQ_WBFRONT	EQU	-5
REQ_ACTIVATE	EQU	-6


MAXEVENTS	EQU	30

FULL                 EQU     65536
FRAC                 EQU     8192



**********************************************************************
*         Local parameters for font-sensitive window open up         *
**********************************************************************
		CARGS	#-(4+4+2+2+2+2),OffY.W,OffX.W,FontY.W,FontX.W,FontPtr.L

		SECTION	MyCode,CODE

Main		move.l	$4.w,_SysBase
		bra	START

**********************************************************************
*                  Versionstring for C:Version-Prg                   *
*       I place it right here, so that it can be found quickly       *
**********************************************************************
VersionString	dc.b	0,"$VER:KCommodity "
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	")",0
		EVEN

**********************************************************************
*               Fade a layer explode/implode/size/move               *
*                     Vars are passed on stack.                      *
* ScreenAdr                                                          *
* LeftEdge                                                           *
* TopEdge                                                            *
* Width                                                              *
* Height                                                             *
* DeltaX                                                             *
* DeltaY                                                             *
* DeltaWidth                                                         *
* DeltaHeight                                                        *
* Number of Frames to be drawn                                       *
**********************************************************************
LayerFade	CARGS	#8,.Screen.L,.XPos.L,.YPos.L,.LWidth.L,.LHeight.L,.DX.L,.DY.L,.DW.L,.DH.L,.Frames.L
		CARGS	#-36,.Left.L,.Top.L,.Width.L,.Height.L,.LeftStep.L,.TopStep.L,.WidthStep.L,.HeightStep.L,.OldMask.W,.OldMode.W
		link	a5,#-36
		tst.l	.DX(a5)
		bne.s	.GoOn
		tst.l	.DY(a5)
		bne.s	.GoOn
		tst.l	.DW(a5)
		bne.s	.GoOn
		tst.l	.DH(a5)
		beq	.NoMove
.GoOn		addq.w	#1,SizeUse(a4)
		move.l	.DX(a5),d0			; Calc X-Step Rate
		lsl.l	#7,d0
		move.l	.Frames(a5),d1
		RELLIB	SDivMod32,_UtilityBase
		move.l	d0,.LeftStep(a5)

		move.l	.DY(a5),d0			; Y-Step Rate
		lsl.l	#7,d0
		move.l	.Frames(a5),d1
		DOLIB	SDivMod32
		move.l	d0,.TopStep(a5)

		move.l	.DW(a5),d0			; Width Rate
		lsl.l	#7,d0
		move.l	.Frames(a5),d1
		DOLIB	SDivMod32
		move.l	d0,.WidthStep(a5)

		move.l	.DH(a5),d0			; Height Rate
		lsl.l	#7,d0
		move.l	.Frames(a5),d1
		DOLIB	SDivMod32
		move.l	d0,.HeightStep(a5)

		move.l	.Screen(a5),a0
		lea	sc_LayerInfo(a0),a0
		RELLIB	LockLayers,_LayersBase

		move.l	.Screen(a5),a0
		lea	sc_LayerInfo(a0),a0
		DOLIB	LockLayerInfo

		move.l	.Screen(a5),a3			; Get address for screen
		lea	sc_RastPort(a3),a0
		move.b	rp_Mask(a0),d0			; Get old BitPlane-Mask
		ext.w	d0
		move.w	d0,.OldMask(a5)			; Store Mask
		move.b	#2,rp_Mask(a0)			; Only allow BitPlane 2 (White color)
		move.b	rp_DrawMode(a0),d0		; Get old DrawMode
		ext.w	d0
		move.w	d0,.OldMode(a5)			; Store it
		move.l	a0,a1
		move.l	#RP_COMPLEMENT,d0
		RELLIB	SetDrMd,_GfxBase		; Set new DrawMode

		moveq	#1,d6
.Again		move.l	.XPos(a5),d0			; copy dims to workbuffer and
		move.l	.YPos(a5),d1			; calc to our values
		move.l	.LWidth(a5),d2
		move.l	.LHeight(a5),d3
		lsl.l	#7,d0
		lsl.l	#7,d1
		lsl.l	#7,d2
		lsl.l	#7,d3
		move.l	d0,.Left(a5)
		move.l	d1,.Top(a5)
		move.l	d2,.Width(a5)
		move.l	d3,.Height(a5)

		move.l	.Frames(a5),d7
.Loop		lea	sc_RastPort(a3),a1		; Draw Recs. It`s faster than
		move.l	.Left(a5),d0			; using DrawBorder
		move.l	.Top(a5),d1
		lsr.l	#7,d0
		lsr.l	#7,d1
		tst.w	d0
		bge.s	.X1Ok
		moveq	#0,d0
.X1Ok		tst.w	d1
		bge.s	.Y1Ok
		moveq	#0,d1
.Y1Ok		RELLIB	Move,_GfxBase

		lea	sc_RastPort(a3),a1
		move.l	.Left(a5),d0
		add.l	.Width(a5),d0
		move.l	.Top(a5),d1
		lsr.l	#7,d0
		lsr.l	#7,d1
		cmp.w	sc_Width(a3),d0
		blt.s	.W1Ok
		move.w	sc_Width(a3),d0
		subq.w	#1,d0
.W1Ok		tst.w	d1
		bge.s	.Y2Ok
		moveq	#0,d1
.Y2Ok		DOLIB	Draw

		lea	sc_RastPort(a3),a1
		move.l	.Left(a5),d0
		add.l	.Width(a5),d0
		move.l	.Top(a5),d1
		add.l	.Height(a5),d1
		lsr.l	#7,d0
		lsr.l	#7,d1
		cmp.w	sc_Width(a3),d0
		blt.s	.W2Ok
		move.w	sc_Width(a3),d0
		subq.w	#1,d0
.W2Ok		cmp.w	sc_Height(a3),d1
		blt.s	.H1Ok
		move.w	sc_Height(a3),d1
		subq.w	#1,d1
.H1Ok		DOLIB	Draw

		lea	sc_RastPort(a3),a1
		move.l	.Left(a5),d0
		move.l	.Top(a5),d1
		add.l	.Height(a5),d1
		lsr.l	#7,d0
		lsr.l	#7,d1
		tst.w	d0
		bge.s	.X2Ok
		moveq	#0,d0
.X2Ok		cmp.w	sc_Height(a3),d1
		blt.s	.H2Ok
		move.w	sc_Height(a3),d1
		subq.w	#1,d1
.H2Ok		DOLIB	Draw

		lea	sc_RastPort(a3),a1
		move.l	.Left(a5),d0
		move.l	.Top(a5),d1
		lsr.l	#7,d0
		lsr.l	#7,d1
		tst.w	d0
		bge.s	.X3Ok
		moveq	#0,d0
.X3Ok		tst.w	d1
		bge.s	.Y3Ok
		moveq	#0,d1
.Y3Ok		DOLIB	Draw

		move.l	.WidthStep(a5),d0
		move.l	.HeightStep(a5),d1
		add.l	d0,.Width(a5)			; Width/Height decreases
		add.l	d1,.Height(a5)
		move.l	.LeftStep(a5),d0
		move.l	.TopStep(a5),d1
		add.l	d0,.Left(a5)			; And Left/TopEdge moves
		add.l	d1,.Top(a5)			; half the way...
		dbf	d7,.Loop
		dbf	d6,.Again			; Clear frames again

		move.l	.Screen(a5),a0			; Remake Old Mode and Mask
		lea	sc_RastPort(a0),a1
		move.w	.OldMask(a5),d0
		move.b	d0,rp_Mask(a1)
		move.w	.OldMode(a5),d0
		ext.l	d0
		RELLIB	SetDrMd,_GfxBase
		move.l	.Screen(a5),a0
		lea	sc_LayerInfo(a0),a0
		RELLIB	UnlockLayers,_LayersBase

		move.l	.Screen(a5),a0
		lea	sc_LayerInfo(a0),a0
		DOLIB	UnlockLayerInfo

		subq.w	#1,SizeUse(a4)
.NoMove		unlk	a5
		rts



**********************************************************************
*                 Get a file name via ASL-Requester                  *
* Parameters must be passed on stack in given order                  *
*  1. Pointer to window                                              *
*  2. Pointer to requester header                                    *
*  3. Pointer to complete filename                                   *
*  4. Number of gadget to change                                     *
*  5. Pointer to GadgetArray                                         *
*  6. Mode for filerequester                                         *
*  7. Pointer to Gadgetroutine                                       *
**********************************************************************
GetFileName	CARGS	#64,.Window.l,.Header.l,.CompleteName.l,.GadgetNum.w,.GadgetList.l,.Mode.L,.GadFunc.L
		movem.l	d1-d7/a0-a6,-(sp)
		link	a5,#0
		move.l	.Mode(a5),FileReqDirs
		RELLIB	AllocFileRequest,_AslBase	; Get structure for filerequester
		move.l	d0,MyAslRequest(a4)
		tst.l	d0
		beq	NoFileName

		clr.b	DirPath(a4)
		clr.b	DirFile(a4)
		move.l	.CompleteName(a5),a0
		jsr	StrLen
		lea	0(a0,d0),a0
.GetFile	cmp.b	#":",(a0)
		beq.s	.GotFile
		cmp.b	#"/",(a0)
		beq.s	.GotFile
		subq.l	#1,a0
		dbf	d0,.GetFile
.GotFile	addq.l	#1,a0
		lea	DirFile(a4),a1
		move.l	a0,a2
		jsr	StrCpy
		tst.l	d0
		blt.s	.NoDir
		move.b	(a2),d6
		clr.b	(a2)
		move.l	.CompleteName(a5),a0
		lea	DirPath(a4),a1
		jsr	StrCpy
		move.b	d6,(a2)
.NoDir		move.l	.Window(a5),FileReqWin		; Set up filerequester
		lea	DirPath(a4),a0
		move.l	a0,FileReqDir
		lea	DirFile(a4),a0
		move.l	a0,FileReqFile
		move.l	.Header(a5),FileReqHeader
		move.l	MyAslRequest(a4),a0
		lea	AslFileTags(pc),a1
		RELLIB	AslRequest,_AslBase		; Do the request
		move.l	d0,d7
		tst.l	d0
		beq.s	.Canceled
		move.l	MyAslRequest(a4),a2
		move.l	rf_Dir(a2),a0
		move.l	.CompleteName(a5),a1		; Copy Dir name
		moveq	#-1,d7
		jsr	StrCpy
		move.l	.CompleteName(a5),a0
		jsr	StrLen
		tst.b	(a0)
		beq.s	.GotPath
		lea	0(a0,d0),a0
		cmp.b	#"/",-1(a0)
		beq.s	.GotPath
		cmp.b	#":",-1(a0)
		beq.s	.GotPath
		move.b	#"/",(a0)+
.GotPath	move.l	a0,a1
		move.l	rf_File(a2),a0
		jsr	StrCpy
		tst.l	.GadgetList(a5)
		beq.s	.Canceled
		move.w	.GadgetNum(a5),d0
		ext.l	d0
		move.l	.GadgetList(a5),a0
		move.l	.Window(a5),a1
		move.l	.CompleteName(a5),a2
		move.l	.GadFunc(a5),a3
		jsr	(a3)
		moveq	#1,d7
.Canceled	move.l	MyAslRequest(a4),a0		; Copy new position of filereq
		move.w	rf_LeftEdge(a0),d0
		move.w	rf_TopEdge(a0),d1
		ext.l	d0
		ext.l	d1
		move.l	d0,FileReqLeft
		move.l	d1,FileReqTop
		move.w	rf_Width(a0),d0
		move.w	rf_Height(a0),d1
		ext.l	d0
		ext.l	d1
		move.l	d0,FileReqWidth
		move.l	d1,FileReqHeight
		RELLIB	FreeFileRequest,_AslBase	; Free request
NoFileName	unlk	a5
		move.l	d7,d0
		movem.l	(sp)+,d1-d7/a0-a6
		rts
**********************************************************************
*                         FileRequester tags                         *
**********************************************************************
AslFileTags	dc.l	ASL_Hail
FileReqHeader	dc.l	0
		dc.l	ASL_Window
FileReqWin	dc.l	0
		dc.l	ASL_LeftEdge
FileReqLeft	dc.l	0
		dc.l	ASL_TopEdge
FileReqTop	dc.l	0
		dc.l	ASL_Width
FileReqWidth	dc.l	320
		dc.l	ASL_Height
FileReqHeight	dc.l	140
		dc.l	ASL_File
FileReqFile	dc.l	0
		dc.l	ASL_Dir
FileReqDir	dc.l	0
		dc.l	ASL_ExtFlags1
FileReqDirs	dc.l	FIL1F_NOFILES
		dc.l	TAG_DONE





**********************************************************************
*           This part removes all waiting msgs for a port            *
**********************************************************************
KillMessages	CARGS	#0,.Wnd.L,.Port.L,.Base.L
		movem.l	a0/a1/a6,-(sp)			; Store pointers
.Loop		move.l	.Port(sp),a0			; Get pointer to port
		CALLSYS	GetMsg
		tst.l	d0
		beq.s	NoMoreMsgs
		move.l	d0,a1				; Reply msg
		DOLIB	ReplyMsg
		bra	.Loop
NoMoreMsgs	movem.l	(sp)+,a0/a1/a6			; Reget pointers
		rts



**********************************************************************
*                            Main program                            *
**********************************************************************
START		movem.l	d1-d7/a0-a6,-(sp)

		lea	ZeroPage,a4

		move.l	$4,a6				; Test, if we`re running under 2.x
		cmp.w	#NEED_LIBVER,LIB_VERSION(a6)
		bge.s	.IsOver20

		jsr	OnlyKick20
		bra	.EndPrg

* First some needed initializations

.IsOver20	bsr	OpenLibs			; Open libs
		tst.l	d0
		beq	.OpenError

		bsr	InitMem				; Init memory buffers
		tst.l	d0
		beq	.OpenError

* Now to the ToolTypes/CommandLine parsing

		sub.l	a1,a1				; Get pointer to our process
		CALLSYS	FindTask
		move.l	d0,OurTask(a4)
		move.l	d0,a5
		tst.l	pr_CLI(a5)			; Did we come from WB ?
		bne.s	.GoOn				; Yep -> go on

.FromWB		lea	pr_MsgPort(a5),a0		; Get WB-Message
		CALLSYS	WaitPort
		lea	pr_MsgPort(a5),a0
		DOLIB	GetMsg
		move.l	d0,WBMsg(a4)

		move.l	d0,a5
		move.l	sm_ArgList(a5),a5		; Get pointer to ArgList
		move.l  a5,d0
		beq.s	.GoOn
		move.l	wa_Lock(a5),d1			; Get lock to Prg-Dir
		RELLIB	CurrentDir,_DOSBase
		move.l	wa_Name(a5),a0			; Get .info-File
		RELLIB	GetDiskObject,_IconBase
		move.l	d0,MyDiskObj(a4)
		tst.l	d0
		beq	.EndPrg
		move.l	d0,a0
		move.l	do_ToolTypes(a0),MyToolTypes(a4)	; Store pointer to ToolTypes

.GoOn		bsr	InitZeroPage
		bsr	InitWindows
		bsr	MakeHotKeys			; Copy defaults to hotkey buffs

		move.l	OurTask(a4),a0			; Check where to get parameters from
		tst.l	pr_CLI(a0)
		beq.s	.GetTypes
		bsr	GetCommandLine			; Get command line
		tst.l	d7
		beq	.OpenError
		cmp.l	#1,d7
		beq.s	.WildThing
		pea	0
		bra	.NoWBMsg
.GetTypes	bsr	GetToolTypes			; Get ToolTypes

* Now initialize the main thingies

.WildThing	lea	StrEditHook(a4),a0		; Initialize the StringEdit-Hook
		move.l	#StrEditFunc,h_Entry(a0)
		clr.l	h_SubEntry(a0)
		clr.l	h_Data(a0)

		move.l	_DOSBase(a4),a0			; Patch STAR function
		move.l	dl_Root(a0),a0
		move.l	rn_Flags(a0),d0
		bchg	#RNB_WILDSTAR,d0
		move.l	d0,rn_Flags(a0)

		lea	WindowBase(a4),a0		; Init Window list header
		NEWLIST	a0

		bsr	LoadPrefs			; Read in preferences
		bsr	RemakeWindows			; Remake window width/height

		move.b	PDispAppIcon(a4),d0		; Copy flag for AppIcon
		blt.s	.NoPAppIcon
		move.b	d0,DispAppIcon(a4)
.NoPAppIcon	tst.b	ToolPopUpKey(a4)		; Had a PopUpkey from CLI/Icon ?
		beq.s	.NoToolPopKey
		lea	ToolPopUpKey(a4),a0
		lea	PopUpKey(a4),a1
		jsr	StrCpy

.NoToolPopKey	bsr	InitDrives			; Check for existing external drives
		jsr	SetNoClick

		bsr	InitBroker			; Initialize broker
		tst.l	d0
		beq.s	.OpenError

		bsr	InitGfx				; Initialize graphics
		tst.l	d0
		beq.s	.OpenError

		bsr	InitConsole			; Open Console-Device
		tst.l	d0
		beq.s	.OpenError

		bsr	InitAppIcon			; Init our AppIcon
		bsr	InitAppItem			; Init AppTools menuitem
		jsr	SetPatch			; Set library patches

		bsr	InitChecker			; Init the Checker process
		tst.l	CheckerProc(a4)
		beq.s	.OpenError

		bsr	InitRexxProc			; Init Rexx process
		tst.l	RexxProc(a4)
		beq.s	.OpenError

		jsr	InitPrintProc			; Init printer process
		tst.l	PrintProc(a4)
		beq.s	.OpenError

		tst.b	DoPopUp(a4)			; If pop up was requested
		beq.s	.NoInitPop
		bsr	OpenMainWin			; Do so
		tst.l	d0
		bne.s	.OpenError

.NoInitPop	clr.b	Disabled(a4)
		jsr	EnableBroker			; Start broker

		move.l	OurTask(a4),a1			; Set user`s priority
		move.l	ToolPri(a4),d0
		CALLSYS	SetTaskPri
		move.l	d0,-(sp)

		bsr	CheckBroker			; Do the wild thing

		move.l	OurTask(a4),a1			; Reset old Task-Pri
		move.l	(sp)+,d0			; Necessary when launched from CLI
		CALLSYS	SetTaskPri
		bra.s	.EndPrg

.OpenError	tst.l	ErrorNum(a4)			; Error occured ?
		blt.s	.EndPrg
		jsr	DisplayError			; Display error
.EndPrg		moveq	#0,d0				; No error
.CloseDown	move.l	d0,-(sp)

		tst.l	PrintProc(a4)
		beq.s	.NoPrintDown
		move.l	PrintProc(a4),a1		; Tell Printer-Proc to go away
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal
		move.l	#SIGHANDSHAKE,d0		; wait for reply
		DOLIB	Wait

.NoPrintDown	tst.l	RexxProc(a4)
		beq.s	.NoRexxDown
		move.l	RexxProc(a4),a1			; Tell Rexx-Proc to go away
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal
		move.l	#SIGHANDSHAKE,d0		; wait for reply
		DOLIB	Wait

.NoRexxDown	tst.l	CheckerProc(a4)
		beq.s	.NoCheckerDown
		move.l	CheckerProc(a4),a1		; Tell Time-Proc to go away
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal
		move.l	#SIGHANDSHAKE,d0		; wait for reply
		DOLIB	Wait

.NoCheckerDown	CALLSYS	Forbid
		jsr	UnPatch
		jsr	CloseWins			; Close all windows first
		bsr	RemoveDrives			; Remove drive structures
		jsr	RemoveAlarmSmp			; Remove Alarm Sample
		bsr	RemoveAppItems			; Remove AppMenu
		bsr	RemoveAppIcon			; Remove AppIcon-Stuff
		bsr	RemoveConsole			; Remove Console-Device
		bsr	RemoveGfx			; Remove our gfx
		jsr	DeleteEnvs			; Remove environment vars
		bsr	RemoveBroker			; Close resources
		bsr	FreeWindows			; Free list of windows

		tst.l	MyDiskObj(a4)			; Got a Disk-Object ?
		beq.s	.NoDiskObj
		move.l	MyDiskObj(a4),a0		; release it
		RELLIB	FreeDiskObject,_IconBase
.NoDiskObj	tst.l	WBMsg(a4)			; Got a workbench message ?
		beq.s	.NoWBMsg
		move.l	WBMsg(a4),a1
		CALLSYS	ReplyMsg			; Do a reply

.NoWBMsg	bsr	RemoveMem			; Remove those needed resources
		bsr	CloseLibs
		move.l	(sp)+,d0
		movem.l	(sp)+,d1-d7/a0-a6
		rts





**********************************************************************
*                      Attempt to load the libs                      *
**********************************************************************
OpenLibs	move.l	#NOTFOUND_ERR,ErrorNum(a4)
		lea	IntName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		CALLSYS	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_IntuitionBase(a4)

		lea	DosName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_DOSBase(a4)

		lea	IconName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_IconBase(a4)

		lea	ComName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_CxBase

		lea	LayerName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_LayersBase(a4)

		lea	GadName(pc),a1
		move.l	a1,EasyArg(a4)
		moveq	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_GadToolsBase(a4)

		lea	GfxName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_GfxBase(a4)

		lea	RexxSysName(pc),a1
		move.l	a1,EasyArg(a4)
		moveq	#0,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.LibError
		move.l	d0,_RexxSysBase(a4)

		lea	AslName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq.s	.LibError
		move.l	d0,_AslBase(a4)

		lea	WBName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		move.l	d0,_WorkBenchBase(a4)
		tst.l	d0
		beq.s	.LibError

		lea	UtilityName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		move.l	d0,_UtilityBase(a4)
		tst.l	d0
		beq.s	.LibError

		lea	IFFParseName(pc),a1
		move.l	a1,EasyArg(a4)
		move.l	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		move.l	d0,_IFFParseBase(a4)
		tst.l	d0
		beq.s	.LibError

		lea	ReqName(pc),a1			; Open libs to be patched
		moveq	#0,d0
		DOLIB	OpenLibrary
		move.l	d0,_ReqBase(a4)

		lea	ReqToolsName(pc),a1
		moveq	#0,d0
		DOLIB	OpenLibrary
		move.l	d0,_ReqToolsBase(a4)

		lea	ArpName(pc),a1
		moveq	#0,d0
		DOLIB	OpenLibrary
		move.l	d0,_ArpBase(a4)
.LibError	rts

**********************************************************************
*                           Library names                            *
**********************************************************************
IntName		dc.b	"intuition.library",0
ComName		dc.b	"commodities.library",0
DosName		dc.b	"dos.library",0
IconName	dc.b	"icon.library",0
LayerName	dc.b	"layers.library",0
GadName		dc.b	"gadtools.library",0
GfxName		dc.b	"graphics.library",0
RexxSysName	dc.b	"rexxsyslib.library",0
WBName		dc.b	"workbench.library",0
AslName		dc.b	"asl.library",0
UtilityName	dc.b	"utility.library",0
IFFParseName	dc.b	"iffparse.library",0
ReqName		dc.b	"req.library",0
ReqToolsName	dc.b	"reqtools.library",0
ArpName		dc.b	"arp.library",0
		EVEN





**********************************************************************
*                          Close Libs again                          *
**********************************************************************
CloseLibs	tst.l	_ArpBase(a4)
		beq.s	.NoArp
		move.l	_ArpBase(a4),a1
		CALLSYS	CloseLibrary

.NoArp		tst.l	_ReqToolsBase(a4)
		beq.s	.NoReqTools
		move.l	_ReqToolsBase(a4),a1
		CALLSYS	CloseLibrary

.NoReqTools	tst.l	_ReqBase(a4)
		beq.s	.NoReq
		move.l	_ReqBase(a4),a1
		CALLSYS	CloseLibrary

.NoReq		tst.l	_IFFParseBase(a4)
		beq.s	.NoIFFParseBase
		move.l	_IFFParseBase(a4),a1
		CALLSYS	CloseLibrary

.NoIFFParseBase	tst.l	_UtilityBase(a4)
		beq.s	.NoUtilityBase
		move.l	_UtilityBase(a4),a1
		CALLSYS	CloseLibrary

.NoUtilityBase	tst.l	_WorkBenchBase(a4)
		beq.s	.NoWBBase
		move.l	_WorkBenchBase(a4),a1
		CALLSYS	CloseLibrary

.NoWBBase	tst.l	_AslBase(a4)
		beq.s	.NoAslBase
		move.l	_AslBase(a4),a1
		CALLSYS	CloseLibrary

.NoAslBase	tst.l	_RexxSysBase(a4)
		beq.s	.NoRexxSysBase
		move.l	_RexxSysBase(a4),a1
		CALLSYS	CloseLibrary

.NoRexxSysBase	tst.l	_GfxBase(a4)
		beq.s	.NoGfxBase
		move.l	_GfxBase(a4),a1
		CALLSYS	CloseLibrary

.NoGfxBase	tst.l	_GadToolsBase(a4)
		beq.s	.NoGadToolsBase
		move.l	_GadToolsBase(a4),a1
		CALLSYS	CloseLibrary

.NoGadToolsBase	tst.l	_LayersBase(a4)
		beq.s	.NoLayersBase
		move.l	_LayersBase(a4),a1
		CALLSYS	CloseLibrary

.NoLayersBase	tst.l	_CxBase
		beq.s	.NoCxBase
		move.l	_CxBase,a1
		CALLSYS	CloseLibrary

.NoCxBase	tst.l	_IconBase(a4)
		beq.s	.NoIconBase
		move.l	_IconBase(a4),a1
		CALLSYS	CloseLibrary

.NoIconBase	tst.l	_DOSBase(a4)
		beq.s	.NoDosBase
		move.l	_DOSBase(a4),a1
		CALLSYS	CloseLibrary

.NoDosBase	tst.l	_IntuitionBase(a4)
		beq.s	.NoIntBase
		move.l	_IntuitionBase(a4),a1
		CALLSYS	CloseLibrary
.NoIntBase	rts




**********************************************************************
*           Initialize some structures from system-memory            *
**********************************************************************
InitMem		move.l	#AREXXBUFF_ERR,ErrorNum(a4)	; A small dummy buffer
		move.l	#AREXXBUFFSIZE,d0
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		move.l	d0,ARexxBuffer(a4)
		tst.l	d0
		beq.s	.Error

		move.l	#INPUTREQ_ERR,ErrorNum(a4)	; Input Request
		move.l	#IOSTD_SIZE,d0
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		DOLIB	AllocVec
		move.l	d0,InputReq(a4)

.Error		rts




**********************************************************************
*                       Remove used resources                        *
**********************************************************************
RemoveMem	tst.l	InputReq(a4)			; Remove Input Request
		beq.s	.NoInputReq
		move.l	InputReq(a4),a1
		CALLSYS	FreeVec

.NoInputReq	tst.l	ARexxBuffer(a4)			;  Remove buffer for ARexx
		beq.s	.NoReadBuff
		move.l	ARexxBuffer(a4),a1
		CALLSYS	FreeVec
.NoReadBuff	rts




**********************************************************************
*                Init the Rastport for the title bar                 *
**********************************************************************
InitGfx		link	a5,#-4				; Lock WB Screen
		jsr	LockScreen
		tst.l	d0
		beq	.NoGfx

		move.l	d0,a0				; Get font for titlebar
		move.l	sc_BarLayer(a0),a0
		move.l	lr_rp(a0),a0
		move.l	rp_Font(a0),a0			; A0 = Font used in bar layer-rastport
		move.l	a0,OldSysFont(a4)
		lea	TxtAttr,a1			; Store attributes of font
		movem.l	a0/a1,-(sp)
		move.l	LN_NAME(a0),a0
		lea	TxtAttrFont(a4),a1
		jsr	StrCpy
		movem.l	(sp)+,a0/a1
		moveq	#0,d7
		move.w	tf_YSize(a0),d7			; Get height of font
		move.w	d7,ta_YSize(a1)			; and for bitplanes of title
		move.b	tf_Style(a0),ta_Style(a1)
		move.b	tf_Flags(a0),ta_Flags(a1)

		move.l	-4(a5),a0
		lea	sc_BitMap(a0),a0		; Get depth of workbench
		moveq	#0,d0
		move.b	bm_Depth(a0),d0
		move.w	d0,BitMapDepth(a4)

		moveq	#0,d1
		move.l	-4(a5),a0
		move.w	sc_Width(a0),d1
		move.w	d1,BitMapWidth(a4)		; Store sizes
		moveq	#0,d1
		move.b	sc_BarHeight(a0),d1
		move.w	d1,BitMapHeight(a4)		; To get the full width and height
							; isn`t quite intelligent, but
							; it doesn`t take too much memory.
							; SO WHAT

		move.l	#BITMAP_ERR,ErrorNum(a4)	; Get mem for BitMap
		move.l	#bm_SIZEOF,d0
		move.l	#MEMF_PUBLIC|MEMF_CLEAR,d1
		CALLSYS	AllocVec
		move.l	d0,MyBitMap(a4)
		tst.l	d0
		beq	.NoGfx

		move.l	#RASTPORT_ERR,ErrorNum(a4)	; Get mem for RastPort
		move.l	#rp_SIZEOF,d0
		move.l	#MEMF_PUBLIC|MEMF_CLEAR,d1
		CALLSYS	AllocVec
		move.l	d0,MyRastPort(a4)
		tst.l	d0
		beq	.NoGfx

		move.l	MyBitMap(a4),a0			; Initialize our BitMap
		move.w	BitMapDepth(a4),d0
		move.w	BitMapWidth(a4),d1
		move.w	BitMapHeight(a4),d2
		RELLIB	InitBitMap,_GfxBase

		move.l	#BITPLANE_ERR,ErrorNum(a4)
		move.l	MyBitMap(a4),a3
		lea	bm_Planes(a3),a3		; Get address of Planes array
		move.w	BitMapDepth(a4),d7		; Make all planes
		subq.w	#1,d7
.MakeBitMaps	move.w	BitMapWidth(a4),d0
		move.w	BitMapHeight(a4),d1
		RELLIB	AllocRaster,_GfxBase
		tst.l	d0
		beq.s	.NoGfx
		move.l	d0,(a3)+
		dbf	d7,.MakeBitMaps

		move.l	MyRastPort(a4),a1		; Init RPort
		RELLIB	InitRastPort,_GfxBase

		move.l	MyRastPort(a4),a1
		move.l	MyBitMap(a4),a0
		move.l	a0,rp_BitMap(a1)		; Add pointer of BitMap to RPort
		moveq	#1,d0
		DOLIB	SetRast

		move.l	#FONT_ERR,ErrorNum(a4)
		lea	TxtAttr,a0			; Try to open font in RAM
		DOLIB	OpenFont
		move.l	d0,MyFont(a4)
		tst.l	d0
		beq.s	.NoGfx				; THIS SHOULD NEVER HAPPEN

		move.l	MyRastPort(a4),a1		; Set font for rastport
		move.l	d0,a0
		DOLIB	SetFont

		move.l	MyRastPort(a4),a1		; Set draw mode
		move.l	#RP_JAM1,d0
		DOLIB	SetDrMd

		move.l	MyRastPort(a4),a1		; Set back pen
		moveq	#1,d0
		DOLIB	SetBPen
		move.l	MyRastPort(a4),a1
		moveq	#0,d0
		DOLIB	SetAPen

		move.l	#MEMF_TOTAL,d1			; Get total available mem
		CALLSYS	AvailMem
		move.l	d0,MaxMem(a4)

		moveq	#1,d0
.NoGfx		move.l	d0,-(sp)
		jsr	UnlockScreen
		move.l	(sp)+,d0
		unlk	a5
		rts



**********************************************************************
*                    Removes the Gfx areas again                     *
**********************************************************************
RemoveGfx	tst.l	MyFont(a4)			; Did we have a font
		beq.s	.GotNoFont

		move.l	MyFont(a4),a1			; Close font
		RELLIB	CloseFont,_GfxBase

.GotNoFont	tst.l	MyRastPort(a4)			; Free rastport
		beq.s	.GotNoRastPort
		move.l	MyRastPort(a4),a1
		CALLSYS	FreeVec

.GotNoRastPort	tst.l	MyBitMap(a4)
		beq.s	.AllFreed
		move.l	MyBitMap(a4),a5			; Free bitplanes of BitMap
		lea	bm_Planes(a5),a5
		move.w	BitMapDepth(a4),d7
		subq.w	#1,d7
.ClearBitPlanes	move.l	(a5)+,d0
		beq.s	.FreeBitMap
		move.l	d0,a0
		move.w	BitMapWidth(a4),d0
		move.w	BitMapHeight(a4),d1
		RELLIB	FreeRaster,_GfxBase
		dbf	d7,.ClearBitPlanes
.FreeBitMap	move.l	MyBitMap(a4),a1			; Free bitmap
		CALLSYS	FreeVec
.AllFreed	rts




**********************************************************************
*              Open Up console device for RAWKEYCONVERT              *
**********************************************************************
InitConsole	move.l	#CONSOLEREQ_ERR,ErrorNum(a4)	; Console Request
		move.l	#IOSTD_SIZE,d0
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		move.l	d0,ConsoleReq(a4)
		tst.l	d0
		beq.s	.ConsoleError

		move.l	#NOTFOUND_ERR,ErrorNum(a4)
		lea	ConsoleName(pc),a0
		move.l	a0,EasyArg(a4)
		move.l	#CONU_LIBRARY,d0		; We don`t need no unit
		move.l	ConsoleReq(a4),a1
		moveq	#0,d1
		CALLSYS	OpenDevice
		tst.l	d0
		bne.s	.ConsoleError
		move.l	ConsoleReq(a4),a1
		move.l	IO_DEVICE(a1),_ConsoleBase(a4)	; Get base
		moveq	#1,d0
		rts
.ConsoleError	moveq	#0,d0
		rts
ConsoleName	dc.b	"console.device",0
		EVEN




**********************************************************************
*                     Close ConsoleDevice again                      *
**********************************************************************
RemoveConsole	move.l	ConsoleReq(a4),a1
		move.l	a1,d0
		beq.s	.NoDev
		tst.l	IO_DEVICE(a1)
		beq.s	.NoDev
		CALLSYS	CloseDevice
.NoDev		move.l	ConsoleReq(a4),a1
		CALLSYS	FreeVec
.Error		rts




**********************************************************************
*                          Init Audio-Data                           *
**********************************************************************
InitAudio	move.l	#AUDIOPORT_ERR,ErrorNum(a4)
		CALLSYS	CreateMsgPort			; Create port
		move.l	d0,AudioPort(a4)
		tst.l	d0
		beq.s	.AudioError
		move.l	#AUDIOREQ_ERR,ErrorNum(a4)	; Create Request
		move.l	d0,a0
		move.l	#ioa_SIZEOF,d0
		DOLIB	CreateIORequest
		move.l	d0,AudioReq(a4)
		tst.l	d0
		beq.s	.AudioError
		move.l	d0,a1
		move.b	#-50,LN_PRI(a1)
.AudioError	rts



**********************************************************************
*                         Remove Audio-Stuff                         *
**********************************************************************
RemoveAudio	tst.l	AudioReq(a4)			; Remove request
		beq.s	.NoReq
		move.l	AudioReq(a4),a0
		CALLSYS	DeleteIORequest
.NoReq		tst.l	AudioPort(a4)			; Remove port
		beq.s	.NoAudioPort
		move.l	AudioPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoAudioPort	rts



**********************************************************************
*                     Initialize the ARexx Port                      *
**********************************************************************
InitARexx	move.l	#AREXXPORT_ERR,ErrorNum(a4)
		CALLSYS	CreateMsgPort			; Create a Msg Port for ARexx
		move.l	d0,ARexxPort(a4)
		tst.l	d0
		beq.s	.ARexxError
		move.l	d0,a1
		moveq	#0,d0
		moveq	#1,d1
		move.b	MP_SIGBIT(a1),d0		; Get Sig flag
		lsl.l	d0,d1
		move.l	d1,ARexxSigFlag(a4)
		lea	ARexxPortName(pc),a0
		move.l	a0,LN_NAME(a1)
		clr.b	LN_PRI(a1)
		DOLIB	AddPort				; Add port to system
		moveq	#1,d0
.ARexxError	rts
ARexxPortName	dc.b	"KComm.1",0
		ds.b	10
		EVEN


**********************************************************************
*                 Remove our ARexx port from System                  *
**********************************************************************
RemoveARexx	tst.l	ARexxPort(a4)
		beq.s	.NoARexxPort
		move.l	ARexxPort(a4),a1
		jsr	KillMessages			; Kill remaining messages
		CALLSYS	RemPort				; Remove port
		move.l	ARexxPort(a4),a0
		DOLIB	DeleteMsgPort
.NoARexxPort	rts



**********************************************************************
*                    Initialize and start broker                     *
**********************************************************************
InitBroker	bsr	RemoveBroker			; Begin from scratch

		move.l	#SIGNAL_ERR,ErrorNum(a4)

		moveq	#-1,d0				; Try to allocate signal for
		CALLSYS	AllocSignal			; alarm
		move.l	d0,AlarmSigBit(a4)
		tst.l	d0
		blt	.NoBroker
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,AlarmSigFlag(a4)

		moveq	#-1,d0				; Allocate signal for formatter
		DOLIB	AllocSignal
		move.l	d0,FormatSigBit(a4)
		tst.l	d0
		blt	.NoBroker
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,FormatSigFlag(a4)

		moveq	#-1,d0				; Allocate signal for dragging
		DOLIB	AllocSignal
		move.l	d0,DragSigBit(a4)
		tst.l	d0
		blt	.NoBroker
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,DragSigFlag(a4)

		move.l	#WINDOWPORT_ERR,ErrorNum(a4)
		DOLIB	CreateMsgPort			; Create Msg Port for main windows
		move.l	d0,WindowPort(a4)
		tst.l	d0
		beq	.NoBroker
		move.l	d0,a0
		moveq	#0,d0
		moveq	#1,d1
		move.b	MP_SIGBIT(a0),d0
		lsl.l	d0,d1
		move.l	d1,WindowPortSig(a4)

		lea	MySemaphore(a4),a0		; Initialize our Semphore
		DOLIB	InitSemaphore

		lea	PortName(pc),a1			; Find port name
		CALLSYS	FindPort			; This is for identification
		move.l	d0,DoublePort(a4)		; whether we are to quit

		move.l	#BROKERPORT_ERR,ErrorNum(a4)
		DOLIB	CreateMsgPort			; Try to set msg-port
		move.l	d0,BrokerPort(a4)
		tst.l	d0
		beq	.NoBroker
		move.l	d0,a1
		moveq	#1,d0
		moveq	#0,d1
		move.b	MP_SIGBIT(a1),d1
		lsl.l	d1,d0
		move.l	d0,BrokerSigFlag(a4)		; Calc sig-flag
		lea	PortName(pc),a0
		move.l	a0,LN_NAME(a1)
		move.b	#5,LN_PRI(a1)
		DOLIB	AddPort				; Add port to system

		move.l	#BROKER_ERR,ErrorNum(a4)
		lea	MyBrokerDef,a0			; Create broker
		move.l	BrokerPort(a4),nb_Port(a0)	; add Port-Address
		move.l	CxPri(a4),d0
		move.b	d0,nb_Pri(a0)			; and Priority
		moveq	#0,d0				; No errors
		LNKLIB	CxBroker,_CxBase		; install broker structure
		tst.l	d0
		beq.s	.NoBroker
		move.l	d0,MyBroker(a4)

		lea	DefaultHotKeys,a0		; Init HotKeys
		lea	HotKeyGadVars,a1
		lea	HotKeyGadStat,a2
		move.l	#POPUPKEYID,d6
		move.w	#HOTKEYNUM-1,d7
.InitHKs	move.l	8(a1),-(sp)
		move.l	d6,-(sp)
		move.l	(a0)+,-(sp)
		move.l	(a2)+,-(sp)
		bsr	InstallHotKey
		lea	16(sp),sp
		tst.l	d0
		beq.s	.NoBroker
		lea	12(a1),a1
		addq.l	#1,d6
		dbf	d7,.InitHKs

		move.l	#BROKERUP_ERR,ErrorNum(a4)
		move.l	MyBroker(a4),a0			; Check for an error in broker
		DOLIB	CxObjError
		tst.l	d0
		bne.s	.NoBroker

		jsr	DisableBroker			; Disable broker for now
		moveq	#1,d0				; No error
		rts
.NoBroker	moveq	#0,d0				; error occured
		rts
PortName	dc.b	"KComm-Port",0
		EVEN



**********************************************************************
*                         Remove the broker                          *
**********************************************************************
RemoveBroker	tst.l	MyBroker(a4)
		beq.s	.NoBroker
		clr.b	Disabled(a4)			; Disable broker
		jsr	DisableBroker
		move.l	MyBroker(a4),a0			; Delete broker
		LNKLIB	DeleteCxObjAll,_CxBase
.NoBroker	tst.l	BrokerPort(a4)			; Remove broker and all
		beq.s	.NoPort				; attached objects
		move.l	BrokerPort(a4),a1
		jsr	KillMessages			; remove messages
		CALLSYS	RemPort
		move.l	BrokerPort(a4),a0		; Finally delete the
		DOLIB	DeleteMsgPort			; Messageport
.NoPort		tst.l	WindowPort(a4)
		beq.s	.NoWinPort
		move.l	WindowPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoWinPort	tst.l	AlarmSigBit(a4)
		blt.s	.NoSigBit
		move.l	AlarmSigBit(a4),d0
		CALLSYS	FreeSignal			; Free Alarm-Signal
.NoSigBit	tst.l	FormatSigBit(a4)
		blt.s	.NoFormSig
		move.l	FormatSigBit(a4),d0
		CALLSYS	FreeSignal
.NoFormSig	tst.l	DragSigBit(a4)
		blt.s	.NoDragSig
		move.l	DragSigBit(a4),d0
		CALLSYS	FreeSignal
.NoDragSig	rts



**********************************************************************
*                        Free list of windows                        *
**********************************************************************
FreeWindows	lea	WindowBase(a4),a2		; Get address of list base
		move.l	LH_HEAD(a2),d0			; Get address of first entry
		cmp.l	LH_TAIL+LN_PRED(a2),a2
		beq.s	.Done

		move.l	d0,a2
.FreeEntries	move.l	a2,a1
		SUCC	a2,a2
		CALLSYS	FreeVec
		move.l	LN_SUCC(a2),d0
		beq.s	.Done
		bra.s	.FreeEntries
.Done		lea	WindowBase(a4),a0
		NEWLIST	a0
		rts




**********************************************************************
*                      Install the InputHandler                      *
**********************************************************************
InitHandler	move.l	#INPUTPORT_ERR,ErrorNum(a4)
		CALLSYS	CreateMsgPort			; Create a Port
		tst.l	d0
		beq	.Error
		move.l	d0,InputPort(a4)
		move.l	d0,a1
		clr.b	LN_PRI(a1)
		clr.l	LN_NAME(a1)

		move.l	#NOTFOUND_ERR,ErrorNum(a4)
		lea	InputName(pc),a0		; Try to open the device
		move.l	a0,EasyArg(a4)
		move.l	InputReq(a4),a1
		move.l	InputPort(a4),MN_REPLYPORT(a1)
		clr.b	LN_PRI(a1)
		moveq	#0,d0
		moveq	#0,d1
		CALLSYS	OpenDevice
		tst.l	d0
		bne.s	.Error

		move.l	#HANDLER_ERR,ErrorNum(a4)
		lea	HandlerIRQ(a4),a0		; Set up Handler
		move.l	a4,IS_DATA(a0)
		move.l	#RawEventAction,IS_CODE(a0)
		move.l	HandlerPri(a4),d0		; Set priority
		move.b	d0,LN_PRI(a0)
		lea	HandlerName(pc),a2
		move.l	a2,LN_NAME(a0)
		move.l	InputReq(a4),a1
		move.l	a0,IO_DATA(a1)
		move.w	#IND_ADDHANDLER,IO_COMMAND(a1)
		CALLSYS	DoIO
		tst.b	d0
		bne.s	.Error
		move.l	InputReq(a4),a1
		DOLIB	WaitIO
		tst.b	d0
		bne.s	.Error
.End		moveq	#1,d0
		rts
.Error		moveq	#0,d0
		rts
InputName	dc.b	"input.device",0
HandlerName	dc.b	"KComm-InputHandler",0
		EVEN



**********************************************************************
*                        Remove InputHandler                         *
**********************************************************************
RemoveHandler	move.l	InputReq(a4),a1
		tst.l	IO_DEVICE(a1)
		beq.s	.NoDevice
		lea	HandlerIRQ(a4),a0
		move.l	a0,IO_DATA(a1)			; Remove Handler
		move.w	#IND_REMHANDLER,IO_COMMAND(a1)
		CALLSYS	DoIO
		move.l	InputReq(a4),a1			; Wait until Handler is removed
		DOLIB	WaitIO
		move.l	InputReq(a4),a1			; Close device
		CALLSYS	CloseDevice
.NoDevice	tst.l	InputPort(a4)
		beq.s	.NoPort				; Delete message
		move.l	InputPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoPort		rts



**********************************************************************
*           Add an AppIcon. This one uses the Broker-Port            *
**********************************************************************
InitAppIcon	CALLSYS	CreateMsgPort			; Create Msg-Port
		tst.l	d0
		beq.s	.Error
		move.l	d0,AppPort(a4)
		move.l	d0,a1
		clr.b	LN_PRI(a1)
		clr.l	LN_NAME(a1)
		moveq	#0,d0
		moveq	#1,d1
		move.b	MP_SIGBIT(a1),d0
		lsl.l	d0,d1
		move.l	d1,AppSigFlag(a4)		; Get SigFlag
		moveq	#1,d0
		tst.b	DispAppIcon(a4)
		beq.s	.End
		jsr	OnAppIcon
		bra.s	.End
.Error		move.l	#APPICON_ERR,ErrorNum(a4)
		jsr	DisplayError
.End		rts



**********************************************************************
*                         Remove our AppIcon                         *
**********************************************************************
RemoveAppIcon	jsr	OffAppIcon
		tst.l	AppPort(a4)
		beq.s	.NoPort
		move.l	AppPort(a4),a1			; Clear all pending messages
		jsr	KillMessages
		move.l	AppPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoPort		rts




**********************************************************************
*               Add some menu items to the tools menu                *
**********************************************************************
InitAppItem	tst.b	DispAppMenu(a4)
		beq.s	.End
		move.l	#MAINITEM,d0			; Create an item
		moveq	#0,d1
		lea	AppMenuTxt,a0
		move.l	AppPort(a4),a1
		sub.l	a2,a2
		RELLIB	AddAppMenuItemA,_WorkBenchBase
		move.l	d0,KCXAppMenuItem(a4)
		tst.l	d0
		bne.s	.End
		move.l	#APPMENU_ERR,ErrorNum(a4)
		jsr	DisplayError
.End		rts




**********************************************************************
*                    Remove our menu items again                     *
**********************************************************************
RemoveAppItems	tst.l	KCXAppMenuItem(a4)
		beq.s	.NoRemove
		move.l	KCXAppMenuItem(a4),a0
		RELLIB	RemoveAppMenuItem,_WorkBenchBase
.NoRemove	rts




**********************************************************************
*          Try to set a hotkey. Inputs are given on stack :          *
* 1. HotKey Definition                                               *
* 2. Default HotKey Definition                                       *
* 3. HotKey ID                                                       *
* 4. Address of filter                                               *
**********************************************************************
InstallHotKey	CARGS	#68,HotKey.l,DefHotKey.l,ID.l,Filter.l
		movem.l	RegsAll,-(sp)
		link	a5,#-HOTKEYSIZE
		move.l	#HOTKEY_ERR,ErrorNum(a4)
		move.l	ID(a5),-(sp)
		move.l	BrokerPort(a4),-(sp)
		move.l	HotKey(a5),-(sp)
		jsr	_HotKey
		lea	12(sp),sp
		tst.l	d0
		bne.s	.GotUserHotKey			; Got it -> go on
		move.l	HotKey(a5),a0			; Clone user-hotkey
		lea	-HOTKEYSIZE(a5),a1
		jsr	StrCpy
		move.l	DefHotKey(a5),a0		; Try default
		move.l	HotKey(a5),a1
		jsr	StrCpy				; First copy it
		move.l	ID(a5),-(sp)
		move.l	BrokerPort(a4),-(sp)
		move.l	DefHotKey(a5),-(sp)
		jsr	_HotKey
		lea	12(sp),sp
		tst.l	d0
		bne.s	.GotDefHotKey			; Error ???
		jsr	DisplayError			; Display error
		bra.s	.Error
.GotDefHotKey	move.l	#USERHOTKEY_ERR,ErrorNum(a4)	; Tell user we`re using ours
		lea	-HOTKEYSIZE(a5),a0
		move.l	a0,EasyArg(a4)
		move.l	DefHotKey(a5),EasyArg2(a4)
		jsr	DisplayError
.GotUserHotKey	move.l	Filter(a5),a0
		move.l	d0,(a0)
		move.l	MyBroker(a4),a0
		move.l	d0,a1
		LNKLIB	AttachCxObj,_CxBase		; Attach hotkey stuff
		unlk	a5
		movem.l	(sp)+,RegsAll
		moveq	#1,d0
		rts
.Error		unlk	a5
		movem.l	(sp)+,RegsAll
		moveq	#0,d0
		rts






**********************************************************************
*                        Init Windowpositions                        *
**********************************************************************
InitWindows	move.w	#58,MainWinLeft(a4)
		move.w	#37,MainWinTop(a4)

		move.w	#44,SetWinLeft(a4)
		move.w	#46,SetWinTop(a4)

		move.w	#57,MiscWinLeft(a4)
		move.w	#44,MiscWinTop(a4)

		move.w	#133,AlarmWinLeft(a4)
		move.w	#67,AlarmWinTop(a4)

		move.w	#110,QualWinLeft(a4)
		move.w	#82,QualWinTop(a4)

		move.w	#118,CycleWinLeft(a4)
		move.w	#53,CycleWinTop(a4)

		move.w	#167,BlankWinLeft(a4)
		move.w	#61,BlankWinTop(a4)

		move.w	#164,ColsWinLeft(a4)
		move.w	#51,ColsWinTop(a4)

		move.w	#78,MouseWinLeft(a4)
		move.w	#68,MouseWinTop(a4)

		move.w	#168,HotKeyWinLeft(a4)
		move.w	#40,HotKeyWinTop(a4)

		move.w	#138,FKeyWinLeft(a4)
		move.w	#13,FKeyWinTop(a4)

		move.w	#120,FormWinLeft(a4)
		move.w	#65,FormWinTop(a4)

		move.w	#397,BillWinLeft(a4)
		move.w	#11,BillWinTop(a4)

		move.w	#120,PrefsWinLeft(a4)
		move.w	#17,PrefsWinTop(a4)

		move.w	#65,LogWinLeft(a4)
		move.w	#50,LogWinTop(a4)

		move.w	#166,ProgWinLeft(a4)
		move.w	#68,ProgWinTop(a4)

		move.w	#70,PrintWinLeft(a4)
		move.w	#23,PrintWinTop(a4)

		move.w	#55,LockWinLeft(a4)
		move.w	#51,LockWinTop(a4)
		rts





**********************************************************************
*                     Remake widths and heights                      *
**********************************************************************
RemakeWindows	move.w	#503,MainWinWidth(a4)
		move.w	#126,MainWinHeight(a4)

		move.w	#545,SetWinWidth(a4)
		move.w	#108,SetWinHeight(a4)

		move.w	#526,MiscWinWidth(a4)
		move.w	#112,MiscWinHeight(a4)

		move.w	#394,AlarmWinWidth(a4)
		move.w	#66,AlarmWinHeight(a4)

		move.w	#421,QualWinWidth(a4)
		move.w	#35,QualWinHeight(a4)

		move.w	#407,CycleWinWidth(a4)
		move.w	#94,CycleWinHeight(a4)

		move.w	#305,BlankWinWidth(a4)
		move.w	#78,BlankWinHeight(a4)

		move.w	#311,ColsWinWidth(a4)
		move.w	#98,ColsWinHeight(a4)

		move.w	#484,MouseWinWidth(a4)
		move.w	#63,MouseWinHeight(a4)

		move.w	#301,HotKeyWinWidth(a4)
		move.w	#121,HotKeyWinHeight(a4)

		move.w	#364,FKeyWinWidth(a4)
		move.w	#173,FKeyWinHeight(a4)

		move.w	#421,FormWinWidth(a4)
		move.w	#70,FormWinHeight(a4)

		move.w	#236,BillWinWidth(a4)
		move.w	#92,BillWinHeight(a4)

		move.w	#421,PrefsWinWidth(a4)
		move.w	#165,PrefsWinHeight(a4)

		move.w	#511,LogWinWidth(a4)
		move.w	#100,LogWinHeight(a4)

		move.w	#309,ProgWinWidth(a4)
		move.w	#23,ProgWinHeight(a4)

		move.w	#501,PrintWinWidth(a4)
		move.w	#154,PrintWinHeight(a4)

		move.w	#530,LockWinWidth(a4)
		move.w	#98,LockWinHeight(a4)
		rts





**********************************************************************
*                      Init ZeroPage-Parameters                      *
**********************************************************************
InitZeroPage	move.l	#-1,FCycleSecs(a4)		; Init some longs
		move.l	#-1,BCycleSecs(a4)
		move.l	#-1,MCycleSecs(a4)
		move.w	#-1,OldX(a4)
		move.l	#-1,ThisHour(a4)

		move.b	#1,DoPopUp(a4)			; Set some bool flags
		move.b	#1,TimeReset(a4)
		move.b	#1,DispAppIcon(a4)
		move.b	#-1,PDispAppIcon(a4)
		move.b	#1,DispAppMenu(a4)

		move.b	#1,DoActivate(a4)		; Init default settings
		move.b	#1,ShowClock(a4)
		move.b	#1,DoShowTime(a4)
		move.b	#1,ShowSecs(a4)
		move.b	#1,DoShowAlarm(a4)
		move.b	#1,CycleWin(a4)
		move.b	#1,KeyClick(a4)
		move.b	#1,BillPopUp(a4)
		move.b	#1,WBFront(a4)
		move.b	#1,ESCClose(a4)
		move.b	#1,MakeIcons(a4)
		move.b	#1,QuickFormat(a4)
		move.b	#1,FFSDrive(a4)
		move.b	#1,WatchDisks(a4)
		move.b	#1,AutoCenter(a4)
		move.b	#1,MMBShift(a4)
		move.b	#1,LogCalls(a4)
		move.b	#1,Saturday(a4)
		move.b	#1,Sunday(a4)
		move.b	#1,MouseEver(a4)
		move.b	#1,DriveNoClick(a4)
		move.b	#1,GfxCenter(a4)
		move.b	#1,GfxFormFeed(a4)
		move.b	#1,GfxKeepAspect(a4)

		move.l	#60,ScreenTime(a4)
		move.l	#10,MouseTime(a4)
		move.l	#64,ClickVol(a4)
		move.l	#5,DimmValue(a4)
		move.l	#20,ExpFrames(a4)
		move.l	#20,ImpFrames(a4)
		move.l	#15,SizeFrames(a4)
		move.l	#4,Accelerate(a4)
		move.l	#2,ThresHold(a4)
		move.w	#IECODE_LBUTTON,FrontCode(a4)
		move.w	#IECODE_RBUTTON,BackCode(a4)
		move.w	#IEQUALIFIER_LEFTBUTTON,BackQual(a4)
		move.w	#2,FrontClicks(a4)
		move.w	#2,BackClicks(a4)
		move.w	#2,MiddleClicks(a4)
		move.l	#8*6,CheapStop(a4)
		move.l	#18*6,CheapStart(a4)
		clr.l	TextFrontPen(a4)
		move.l	#1,TextBackPen(a4)
		move.l	#3,GaugeFrontPen(a4)
		clr.l	GaugeBackPen(a4)
		move.w	#IEQUALIFIER_LSHIFT,FullDragQual(a4)
		move.l	#360,CostUnit1(a4)
		move.l	#720,CostUnit1+4(a4)
		move.l	#60,CostUnit2(a4)
		move.l	#120,CostUnit2+4(a4)
		move.l	#21,CostUnit3(a4)
		move.l	#42,CostUnit3+4(a4)
		move.l	#23,CostUnit(a4)
		move.l	#4,GfxScale(a4)
		move.l	#2,GfxDensity(a4)
		move.l	#4,GfxThreshold(a4)
		move.l	#NO_ERR,ErrorNum(a4)
		move.l	#55,HandlerPri(a4)
		move.w	#IEQUALIFIER_LALT,HoldXQual(a4)
		move.w	#IEQUALIFIER_CONTROL,HoldYQual(a4)

		lea	DefControlTitle,a0		; Init Main window title
		lea	ControlTitle(a4),a1
		jsr	StrCpy
		lea	DefSetTitle,a0			; Init Settings window title
		lea	SetTitle(a4),a1
		jsr	StrCpy
		lea	DefMiscTitle,a0			; Init Misc window title
		lea	MiscTitle(a4),a1
		jsr	StrCpy
		lea	DefAlarmTitle,a0		; Init alarm window title
		lea	AlarmTitle(a4),a1
		jsr	StrCpy
		lea	DefQualTitle,a0			; Init qualifier window file
		lea	QualTitle(a4),a1
		jsr	StrCpy
		lea	DefCycleTitle,a0		; Init cycle window title
		lea	CycleTitle(a4),a1
		jsr	StrCpy
		lea	DefBlankTitle,a0		; Init blank window title
		lea	BlankTitle(a4),a1
		jsr	StrCpy
		lea	DefColsTitle,a0			; Init blank window title
		lea	ColsTitle(a4),a1
		jsr	StrCpy
		lea	DefMouseTitle,a0		; Init mouse window title
		lea	MouseTitle(a4),a1
		jsr	StrCpy
		lea	DefHotKeyTitle,a0		; Init HotKey title
		lea	HotKeyTitle(a4),a1
		jsr	StrCpy
		lea	DefFKeyTitle,a0			; Init fkeys window
		lea	FKeyTitle(a4),a1
		jsr	StrCpy
		lea	DefFormTitle,a0			; Init formatter window title
		lea	FormTitle(a4),a1
		jsr	StrCpy
		lea	DefBillTitle,a0			; Init bill window title
		lea	BillTitle(a4),a1
		jsr	StrCpy
		lea	DefPrefsTitle,a0		; Init prefs window title
		lea	PrefsTitle(a4),a1
		jsr	StrCpy
		lea	DefPrintTitle,a0		; Init dump screen title
		lea	PrintTitle(a4),a1
		jsr	StrCpy
		lea	DefLockTitle,a0			; Init lock window title
		lea	LockTitle(a4),a1
		jsr	StrCpy
		lea	DefPubScrName,a0		; Init default public screen list
		lea	PubScreenName(a4),a1
		jsr	StrCpy
		lea	DefSystemComm,a0		; Init default system command
		lea	SystemComm(a4),a1
		jsr	StrCpy
		lea	DefLogFileName,a0		; Init default LogFile name
		lea	LogFileName(a4),a1
		jsr	StrCpy
		lea	DefPrefsFName,a0		; Init default Prefs filename
		lea	PrefsFileName(a4),a1
		jsr	StrCpy
		rts



**********************************************************************
*               Copy default hotkeys to "user" buffers               *
**********************************************************************
MakeHotKeys	lea	DefaultHotKeys,a2
		lea	HotKeyGadStat,a3
		move.w	#HOTKEYNUM-1,d7
.Loop		move.l	(a2)+,a0
		move.l	(a3)+,a1
		jsr	StrCpy
		dbf	d7,.Loop
		rts



**********************************************************************
*                      Get the given tooltypes                       *
**********************************************************************
GetToolTypes	tst.l	MyToolTypes(a4)
		bne.s	.GoOn
		rts
.GoOn		move.l	MyToolTypes(a4),a0
		lea	ToolPriStr(pc),a1		; Change Tool-Pri ?
		RELLIB	FindToolType,_IconBase
		tst.l	d0
		beq.s	.NoToolPri			; No -> go on
		move.l	d0,d1
		lea	ToolPri(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		bge.s	.NoToolPri
		clr.l	ToolPri(a4)
.NoToolPri	move.l	MyToolTypes(a4),a0			; New Handler-Priority ?
		lea	HandlerPriStr(pc),a1
		RELLIB	FindToolType,_IconBase
		tst.l	d0
		beq.s	.NoHandlerPri
		move.l	d0,d1
		lea	HandlerPri(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		bge.s	.NoHandlerPri
		cmp.l	#51,HandlerPri(a4)
		bge.s	.NoHandlerPri
		move.l	#55,HandlerPri(a4)
.NoHandlerPri	move.l	MyToolTypes(a4),a0
		lea	PriStr(pc),a1			; Change broker pri ?
		RELLIB	FindToolType,_IconBase
		tst.l	d0
		beq.s	.NoCxPri			; No -> go on
		move.l	d0,d1
		lea	CxPri(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase		; Set pri
		tst.l	d0
		bge.s	.NoCxPri
		clr.l	CxPri(a4)
.NoCxPri	move.l	MyToolTypes(a4),a0
		lea	PortNameStr(pc),a1
		RELLIB	FindToolType,_IconBase		; New ARexx-PortName ?
		tst.l	d0
		beq.s	.NoPortName
		move.l	d0,a0
		lea	ARexxPortName(pc),a1
		moveq	#15,d7				; Copy only 16 Chars
		jsr	StrNCpy
.NoPortName	move.l	MyToolTypes(a4),a0
		lea	KeyStr(pc),a1
		DOLIB	FindToolType			; Do we have a new pop up key ?
		tst.l	d0
		beq.s	.NoPopKey			; Nope -> go on
		move.l	d0,a0
		lea	ToolPopUpKey(a4),a1			; Copy PopUpKey
		jsr	StrCpy
.NoPopKey	move.l	MyToolTypes(a4),a0		; Check for PopUp flag
		lea	PopUpStr(pc),a1
		DOLIB	FindToolType
		tst.l	d0
		beq.s	.DoNotPopUp
		move.l	d0,a0				; Do we have a NO flag
		lea	NoString(pc),a1
		DOLIB	MatchToolValue
		tst.l	d0
		beq.s	.DoNotPopUp
		clr.b	DoPopUp(a4)			; Let the window pop up
.DoNotPopUp	move.l	MyToolTypes(a4),a0		; Display AppIcon ?
		lea	IconStr(pc),a1
		DOLIB	FindToolType
		tst.l	d0
		beq.s	.NoAppIcon
		clr.b	PDispAppIcon(a4)
.NoAppIcon	move.l	MyToolTypes(a4),a0		; Display AppMenuItem ?
		lea	MenuStr(pc),a1
		DOLIB	FindToolType
		tst.l	d0
		beq.s	.NoAppMenu
		clr.b	DispAppMenu(a4)
.NoAppMenu	move.l	MyToolTypes(a4),a0		; New Icon-X-Pos ?
		lea	IconXStr(pc),a1
		DOLIB	FindToolType
		tst.l	d0
		beq.s	.NoIconX
		move.l	d0,d1
		move.l	#IconXPos,d2
		RELLIB	StrToLong,_DOSBase
.NoIconX	move.l	MyToolTypes(a4),a0		; New Icon-Y-Pos ?
		lea	IconYStr(pc),a1
		RELLIB	FindToolType,_IconBase
		tst.l	d0
		beq.s	.NoIconY
		move.l	d0,d1
		move.l	#IconYPos,d2
		RELLIB	StrToLong,_DOSBase
.NoIconY	move.l	MyToolTypes(a4),a0		; Change PrefsFileName ?
		lea	PrefsStr(pc),a1
		RELLIB	FindToolType,_IconBase
		tst.l	d0
		beq.s	.NoPrefs
		move.l	d0,a0
		lea	PrefsFileName(a4),a1
		jsr	StrCpy
.NoPrefs	rts
**********************************************************************
*                       Parse the command line                       *
**********************************************************************
GetCommandLine	move.l	#((HELP_ARG+1)*4),d0		; Get buffer for parsed arguments
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		move.l	d0,Args(a4)
		moveq	#0,d7
		move.l	#MEMORY_ERR,ErrorNum(a4)		; Set Errornumber
		tst.l	d0
		beq	.HelpDone
		move.l	#CLITemplate,d1			; Parse commandline
		move.l	Args(a4),d2
		moveq	#0,d3
		RELLIB	ReadArgs,_DOSBase
		move.l	d0,MyRDArgs(a4)
		move.l	#NO_ERR,ErrorNum(a4)		; Set errornumber
		tst.l	d0
		beq	.Error

		move.l	Args(a4),a5			; Now check args

		tst.l	(CXPRI_ARG*4)(a5)		; Get Priority for broker ?
		beq.s	.NoCxPri
		move.l	(CXPRI_ARG*4)(a5),a0
		move.l	(a0),CxPri(a4)
.NoCxPri	tst.l	(CXKEY_ARG*4)(a5)		; New PopKey ???
		beq.s	.NoCxKey
		move.l	(CXKEY_ARG*4)(a5),a0
		lea	ToolPopUpKey(a4),a1
		jsr	StrCpy
.NoCxKey	tst.l	(CXPOP_ARG*4)(a5)		; Do popup ???
		beq.s	.CxPopUp
		move.l	(CXPOP_ARG*4)(a5),a0
		lea	NoString(pc),a1
		moveq	#-1,d7
		jsr	StrCmp
		tst.l	d0
		bne.s	.CxPopUp
		clr.b	DoPopUp(a4)			; Clear flag
.CxPopUp	tst.l	(PORT_ARG*4)(a5)		; New Portname ???
		beq.s	.NoPortName
		move.l	(PORT_ARG*4)(a5),a0
		lea	ARexxPortName(pc),a1
		moveq	#15,d7				; Only 16 chars allowed
		jsr	StrNCpy
.NoPortName	tst.l	(PRGPRI_ARG*4)(a5)		; New ToolPri(a4) ???
		beq.s	.NoToolPri
		move.l	(PRGPRI_ARG*4)(a5),a0
		move.l	(a0),ToolPri(a4)
.NoToolPri	tst.l	(HANDPRI_ARG*4)(a5)		; New Handler priority ?
		beq.s	.NoHandlerPri
		move.l	(HANDPRI_ARG*4)(a5),a0
		move.l	(a0),d0
		cmp.l	#51,d0
		blt.s	.NoHandlerPri
		move.l	d0,HandlerPri(a4)
.NoHandlerPri	tst.l	(ICON_ARG*4)(a5)		; Display Icon ???
		beq.s	.Icon
		clr.b	PDispAppIcon(a4)
.Icon		tst.l	(MENU_ARG*4)(a5)		; Attach menu ???
		beq.s	.Menu
		clr.b	DispAppMenu(a4)
.Menu		tst.l	(PREFS_ARG*4)(a5)		; Alternative Prefs-File ?
		beq.s	.NoPrefs
		move.l	(PREFS_ARG*4)(a5),a0
		lea	PrefsFileName(a4),a1
		jsr	StrCpy
.NoPrefs	tst.l	(ICONX_ARG*4)(a5)		; Icon X-Position ?
		beq.s	.NoIconX
		move.l	(ICONX_ARG*4)(a5),a0
		move.l	(a0),IconXPos
.NoIconX	tst.l	(ICONY_ARG*4)(a5)		; Icon Y-Position ?
		beq.s	.NoIconY
		move.l	(ICONY_ARG*4)(a5),a0
		move.l	(a0),IconYPos
.NoIconY	tst.l	(HELP_ARG*4)(a5)		; Display Help ???
		beq.s	.NoCommand
		RELLIB	Output,_DOSBase
		move.l	d0,d1
		lea	CliHelpPage(pc),a0
		move.l	a0,d2
		move.l	#CliHelpPageLen,d3
		DOLIB	Write
		moveq	#2,d7
		move.l	#NO_ERR,ErrorNum(a4)
		bra.s	.HelpDone
.NoCommand	moveq	#1,d7
		bra.s	.HelpDone
.Error		DOLIB	IoErr				; On error get code
		move.l	d0,d1				; ... and display the message
		lea	CommandHeader(pc),a0
		move.l	a0,d2
		DOLIB	PrintFault
		moveq	#0,d7
.HelpDone	tst.l	MyRDArgs(a4)
		beq.s	.NoRDArgs
		move.l	MyRDArgs(a4),d1			; Free structure passed by ReadArgs()
		RELLIB	FreeArgs,_DOSBase
.NoRDArgs	tst.l	Args(a4)
		beq.s	.NoArgs
		move.l	Args(a4),a1			; Free Vector-Table
		CALLSYS	FreeVec
.NoArgs		rts
**********************************************************************
*             Definition for the template and ToolTypes              *
**********************************************************************
NoString	dc.b	"NO",0
PriStr		dc.b	"CX_PRIORITY",0
KeyStr		dc.b	"CX_POPKEY",0
PopUpStr	dc.b	"CX_POPUP",0
PortNameStr	dc.b	"PORTNAME",0
ToolPriStr	dc.b	"TOOLPRI",0
HandlerPriStr	dc.b	"HANDLERPRI",0
IconStr		dc.b	"NOICON",0
MenuStr		dc.b	"NOMENU",0
PrefsStr	dc.b	"SETTINGS",0
IconXStr	dc.b	"ICONX",0
IconYStr	dc.b	"ICONY",0
		EVEN
CLITemplate	dc.b	"CP=CX_PRIORITY/N,CK=CX_POPKEY/K,CU=CX_POPUP/K,P=PORTNAME/K,T=TOOLPRI/N,H=HANDLERPRI/N,N=NOICON/S,M=NOMENU/S,R=PREFS/K,X=ICONX/N,Y=ICONY/N,HELP/S",0
		EVEN
CommandHeader	dc.b	"KCommodity error occured ",0
		EVEN
CXPRI_ARG	EQU	0
CXKEY_ARG	EQU	1
CXPOP_ARG	EQU	2
PORT_ARG	EQU	3
PRGPRI_ARG	EQU	4
HANDPRI_ARG	EQU	5
ICON_ARG	EQU	6
MENU_ARG	EQU	7
PREFS_ARG	EQU	8
ICONX_ARG	EQU	9
ICONY_ARG	EQU	10
HELP_ARG	EQU	11
**********************************************************************
*                          Helppage for CLI                          *
**********************************************************************
CliHelpPage	dc.b	$0a,$0a
		BOLDON
		SETFRONTPEN 2
		dc.b	"KCommodity V"
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	") "
		STYLENORMAL
		SETFRONTPEN 1
		dc.b "by Kai Iske. SHAREWARE",$0a
		dc.b	"USAGE : KCommodity",$0a
		dc.b	"        ToolType :             Description :              Default :",$0a
		dc.b	"        -------------------------------------------------------------------",$0a
		dc.b	"        [CX_PRIORITY=n]        Priority of Broker         5",$0a
		dc.b    "        [CX_POPKEY=s]          PopUpKey for Window        LCOMMAND HELP",$0a
		dc.b	"        [CX_POPUP=YES|NO]      PopUp on startup           YES",$0a
		dc.b	"        [PORTNAME=s]           Set name for ARexx-Port    KComm.1",$0a
		dc.b	"        [TOOLPRI=n]            Priority for Program       0",$0a
		dc.b	"        [HANDLERPRI=n]         Priority for Handler       55; must be >= 51",$0a
		dc.b	"        [SETTINGS=s]           New filename for Prefs     ENV:KCX/KCX.PREFS",$0a
		dc.b	"        [NOICON]               Don`t display AppIcon      ---",$0a
		dc.b	"        [NOMENU]               Don`t add AppMenuItem      ---",$0a
		dc.b	"        [ICONX]                New X-Position for AppIcon FINDBEST",$0a
		dc.b	"        [ICONY]                New Y-Position for AppIcon FINDBEST",$0a
		dc.b	$0a,$0a
CliHelpPageLen	EQU	*-CliHelpPage
		EVEN





**********************************************************************
*   This routine checks for existing drives and initializes stuff    *
*                       for each drive present                       *
**********************************************************************
InitDrives	move.l	#TRACKPORT_ERR,ErrorNum(a4)
		CALLSYS	CreateMsgPort
		move.l	d0,TrackPort(a4)
		tst.l	d0
		beq	.Error

		clr.w	NumDrives(a4)
		lea	DriveNames,a0
		lea	DriveList(a4),a2
		lea	DriveRequests(a4),a3
		lea	DriveChange(a4),a5
		moveq	#0,d7
.LoopDrives	movem.l	a0-a3,-(sp)
		move.l	TrackPort(a4),a0
		move.l	#IOTD_SIZE,d0
		CALLSYS	CreateIORequest
		movem.l	(sp)+,a0-a3
		tst.l	d0
		beq.s	.Error
		move.l	d0,(a3)
		movem.l	a0-a3,-(sp)
		lea	TrackName(pc),a0
		move.l	d0,a1
		move.l	d7,d0
		move.l	#TDF_ALLOW_NON_3_5,d1
		DOLIB	OpenDevice
		movem.l	(sp)+,a0-a3
		tst.l	d0
		beq.s	.GotDrive
		move.l	(a3),a0
		DOLIB	DeleteIORequest
		clr.l	(a3)
		bra.s	.NextDrive
.GotDrive	addq.w	#1,NumDrives(a4)
		move.l	(a0),(a2)
		move.l	(a3),a1
		move.w	#TD_CHANGENUM,IO_COMMAND(a1)
		clr.b	IO_FLAGS(a1)
		movem.l	a0-a3,-(sp)
		DOLIB	DoIO
		movem.l	(sp)+,a0-a3
		move.l	IO_ACTUAL(a1),(a5)
.NextDrive	addq.l	#4,a0
		addq.l	#4,a2
		addq.l	#4,a3
		addq.l	#4,a5
		addq.l	#1,d7
		cmp.l	#4,d7
		bne.s	.LoopDrives
.Error		rts
TrackName	dc.b	"trackdisk.device",0
		EVEN



**********************************************************************
*            Remove occupied resources for drive checking            *
**********************************************************************
RemoveDrives	lea	DriveRequests(a4),a3
		moveq	#3,d7
.FreeRequests	tst.l	(a3)
		beq.s	.NoReq
		move.l	(a3),a1
		tst.l	IO_DEVICE(a1)
		beq.s	.NoDevice
		CALLSYS	CloseDevice
.NoDevice	move.l	(a3),a0
		CALLSYS	DeleteIORequest
.NoReq		addq.l	#4,a3
		dbf	d7,.FreeRequests

		tst.l	TrackPort(a4)
		beq.s	.NoPort
		move.l	TrackPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoPort		rts




**********************************************************************
*                Try to read in the default PrefsFile                *
**********************************************************************
LoadPrefs	bsr	FreeWindows			; Free windows
		move.l	#GD_WindowList,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		move.l	#~0,a2
		jsr	SetListViewLst

		move.l	#NOIFF_ERR,ErrorNum(a4)
		RELLIB	AllocIFF,_IFFParseBase
		move.l	d0,MyIFFHandle(a4)
		tst.l	d0
		beq	.LoadError1

		lea	PrefsFileName(a4),a0
		move.l	a0,d1			; Try to open user-defined file
		move.l	d1,EasyArg(a4)
		move.l	#MODE_OLDFILE,d2
		RELLIB	Open,_DOSBase
		tst.l	d0
		bne.s	.GotPrefFile
		tst.b	FirstPrefs(a4)
		bne	.DosLoadError

		lea	DirPrefsName,a0
		lea	PrefsFileName(a4),a1
		jsr	StrCpy

		move.l	#DirPrefsName,d1		; Try to open file in current directory
		move.l	d1,EasyArg(a4)
		move.l	#MODE_OLDFILE,d2
		DOLIB	Open
		tst.l	d0
		bne.s	.GotPrefFile

		lea	EnvPrefsName,a0
		lea	PrefsFileName(a4),a1
		jsr	StrCpy

		move.l	#EnvPrefsName,d1		; Try to open File within env:kcx/
		move.l	d1,EasyArg(a4)
		move.l	#MODE_OLDFILE,d2
		DOLIB	Open
		tst.l	d0
		beq	.EndLoad

.GotPrefFile	move.l	MyIFFHandle(a4),a0
		move.l	d0,iff_Stream(a0)

		RELLIB	InitIFFasDOS,_IFFParseBase

		move.l	MyIFFHandle(a4),a0
		move.l	#IFFF_READ,d0
		DOLIB	OpenIFF
		tst.l	d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Find version ID
		move.l	#'KCXM',d0
		move.l	#'VERS',d1
		DOLIB	PropChunk
		tst.l	d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Get to 'KCXM' -> 'PREF'
		move.l	#'KCXM',d0
		move.l	#'PREF',d1
		DOLIB	StopChunk
		tst.l	d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Scan to chunk
		move.l	#IFFPARSE_SCAN,d0
		DOLIB	ParseIFF
		tst.l	d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Did we have a VERSion chunk ?
		move.l	#'KCXM',d0
		move.l	#'VERS',d1
		DOLIB	FindProp
		tst.l	d0
		beq.s	.PrefsError
		move.l	d0,a0				; Correct version ?
		move.l	spr_Data(a0),a0
		lea	VersChunk,a1
		move.w	(a0)+,d0
		move.w	(a0),d1
		cmp.w	(a1),d0
		bne.s	.PrefsError
		cmp.w	(a1),d0
		beq.s	.IsPrefs
.PrefsError	move.l	#PREFS_ERR,ErrorNum(a4)
		jsr	DisplayError
		bra	.LoadError

.IsPrefs	move.l	MyIFFHandle(a4),a0		; Read Bool qualifiers
		lea	BOOLQUALSTART(a4),a1
		move.l	#FLAGSET,d0
		DOLIB	ReadChunkBytes
		cmp.l	#FLAGSET,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read Long qualifiers
		lea	LONGQUALSTART(a4),a1
		move.l	#LONGQUAL,d0
		DOLIB	ReadChunkBytes
		cmp.l	#LONGQUAL,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read window positions
		lea	MainWinLeft(a4),a1
		move.l	#WINPOSLEN,d0
		DOLIB	ReadChunkBytes
		cmp.l	#WINPOSLEN,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read zoomed size of Bill window
		lea	BillZoomSize,a1
		moveq	#8,d0
		DOLIB	ReadChunkBytes
		cmp.l	#8,d0
		bne	.LoadError

		lea	HotKeyGadStat,a3		; Read HotKey definitions
		move.l	#HOTKEYNUM-1,d7
.LoopHKeys	move.l	MyIFFHandle(a4),a0
		move.l	(a3)+,a1
		move.l	#40,d0
		DOLIB	ReadChunkBytes
		cmp.l	#40,d0
		bne	.LoadError
		dbf	d7,.LoopHKeys

		move.l	MyIFFHandle(a4),a0		; Read User-Shell command
		lea	SystemComm(a4),a1
		move.l	#256,d0
		DOLIB	ReadChunkBytes
		cmp.l	#256,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read Logfilename
		lea	LogFileName(a4),a1
		move.l	#300,d0
		DOLIB	ReadChunkBytes
		cmp.l	#300,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read Public Screen list
		lea	PubScreenName(a4),a1
		move.l	#256,d0
		DOLIB	ReadChunkBytes
		cmp.l	#256,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read FKeys
		lea	FKeys(a4),a1
		move.l	#(MAXFKEYWIDTH+2)*10*4,d0
		DOLIB	ReadChunkBytes
		cmp.l	#(MAXFKEYWIDTH+2)*10*4,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read FileReq position
		lea	FileReqLeft,a1
		move.l	#28,d0
		DOLIB	ReadChunkBytes
		cmp.l	#28,d0
		bne	.LoadError

		move.l	MyIFFHandle(a4),a0		; Read sample name
		lea	AlSampleName(a4),a1
		move.l	#256,d0
		DOLIB	ReadChunkBytes
		cmp.l	#256,d0
		bne	.LoadError

		clr.w	NumWindows(a4)
		lea	WindowBase(a4),a0
		NEWLIST	a0
.LoopWins	move.l	#lw_SIZEOF,d0			; Read in window names
		move.l	#MEMF_CLEAR,d1
		CALLSYS	AllocVec
		tst.l	d0
		bne.s	.GotEntry
		move.l	#MEMORY_ERR,ErrorNum(a4)
		jsr	DisplayError
		moveq	#0,d0
		bra.s	.LoadError
.GotEntry	lea	WindowBase(a4),a0		; Add entry
		move.l	d0,a1
		move.l	d0,a2
		ADDTAIL	a0,a1
		move.l	MyIFFHandle(a4),a0
		lea	lw_Name(a2),a1
		move.l	a1,LN_NAME(a2)
		move.l	#82,d0
		RELLIB	ReadChunkBytes,_IFFParseBase
		tst.l	d0
		bne.s	.GotName
		move.l	a2,a1
		REMOVE
		move.l	a2,a1
		CALLSYS	FreeVec
		bra.s	.EndLoad
.GotName	cmp.l	#82,d0
		bne.s	.LoadError
		addq.w	#1,NumWindows(a4)
		bra	.LoopWins

.LoadError	tst.l	d0				; Handle errors ...
		beq.s	.EndLoad
		neg.l	d0
		add.l	#400,d0
		move.l	d0,ErrorNum(a4)
.LoadError1	jsr	DisplayError
		bra.s	.EndLoad
.DosLoadError	RELLIB	IoErr,_DOSBase
		move.l	d0,ErrorNum(a4)
		jsr	DisplayError
.EndLoad	tst.l	MyIFFHandle(a4)			; and close resources
		beq.s	.NoHandle
		move.l	MyIFFHandle(a4),a0
		RELLIB	CloseIFF,_IFFParseBase
		move.l	MyIFFHandle(a4),a0
		tst.l	iff_Stream(a0)
		beq.s	.NoStream
		move.l	iff_Stream(a0),d1
		RELLIB	Close,_DOSBase
.NoStream	move.l	MyIFFHandle(a4),a0
		RELLIB	FreeIFF,_IFFParseBase

.NoHandle	move.l	SavedPage(a4),d0
		cmp.l	#SNAPMEMPAGE,PageNum(a4)
		beq.s	.RestoreOld
		move.l	d0,PageNum(a4)
		bra.s	.GotPage
.RestoreOld	move.l	d0,OldPageNum(a4)
.GotPage	bsr	SetSetGads
		bsr	SetMiscGads
		bsr	SetAlarmGads
		bsr	SetBlankGads
		bsr	SetCycleGads
		bsr	SetColsGads
		bsr	SetMouseGads
		bsr	SetFKeyGads
		bsr	SetFormGads
		bsr	SetBillGads
		bsr	SetPrefsGads

		move.b	#1,DoRemakeCosts(a4)
		jsr	RemakeCosts			; Remake costs to new values

		lea	HotKeyGadStat,a3		; Remake HotKeys
		lea	HotKeyGadVars,a5
		move.l	#HOTKEYNUM-1,d7
.SetHKeys	movem.l	(a5),a0-a2
		move.l	a0,d0
		beq.s	.GoOn
		move.l	(a0),a0
.GoOn		move.l	(a2),a2
		movem.l	a3/a5,-(sp)
		move.l	(a3),a5
		move.l	a5,a3
		jsr	RemakeHotKey
		movem.l	(sp)+,a3/a5
		addq.l	#4,a3
		lea	12(a5),a5
		dbf	d7,.SetHKeys

		lea	MainWinLeft(a4),a3		; Reposition windows
		lea	WindowHandles,a5
		move.l	#WINDOWNUM-1,d7
.ReposLoop	move.l	(a5)+,a0
		tst.l	(a0)
		beq.s	.NoWinPos
		move.l	(a0),a0
		move.w	(a3),d0
		move.w	2(a3),d1
		sub.w	wd_LeftEdge(a0),d0
		sub.w	wd_TopEdge(a0),d1
		tst.w	d0
		bne.s	.GoMove
		tst.w	d1
		beq.s	.NoMove
.GoMove		RELLIB	MoveWindow,_IntuitionBase
.NoMove		addq.l	#8,a3
.NoWinPos	dbf	d7,.ReposLoop

		move.w	#-1,SelWindow(a4)		; Set lock windows gadgets
		clr.w	TopWindow(a4)
		move.l	#GD_WindowList,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		lea	WindowBase(a4),a2
		jsr	SetListViewLst
		move.w	SelWindow(a4),d1
		move.w	TopWindow(a4),d2
		jsr	SetListViewGad
		move.l	#GD_WindowName,d0
		sub.l	a2,a2
		bsr	SetStringGad
		moveq	#1,d1
		jsr	GhostGadget
		move.l	#GD_SelectWindow,d0
		jsr	GhostGadget
		move.l	#GD_DeleteWindow,d0
		jsr	GhostGadget

		jsr	RemoveAlarmSmp			; Init new alarm sample
		jsr	InitAlarmSmp
		jsr	SetNoClick
		move.b	#1,FirstPrefs(a4)
		rts





**********************************************************************
*            On a save to ENV: do another save to ENVARC:            *
**********************************************************************
DoublePrefs	link	a5,#-256

		move.l	a5,-(sp)
		bsr.s	SavePrefs
		move.l	(sp)+,a5

		lea	PrefsFileName(a4),a0
		lea	EnvPrefsName,a1
		moveq	#-1,d7
		bsr	StrCmp
		tst.l	d0
		bne.s	.End

		lea	PrefsFileName(a4),a0
		lea	-256(a5),a1
		bsr	StrCpy

		lea	EnvArcPrefsName,a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy

		move.l	a5,-(sp)
		bsr.s	SavePrefs
		move.l	(sp)+,a5

		lea	-256(a5),a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy

.End		unlk	a5
		rts



**********************************************************************
*                      Save preferences to disk                      *
**********************************************************************
SavePrefs	cmp.l	#SNAPMEMPAGE,PageNum(a4)
		beq.s	.StoreOldPage
		move.l	PageNum(a4),d0
		move.l	d0,SavedPage(a4)
		bra.s	.GotPage
.StoreOldPage	move.l	OldPageNum(a4),d0
		move.l	d0,SavedPage(a4)

.GotPage	move.l	#NOIFF_ERR,ErrorNum(a4)
		RELLIB	AllocIFF,_IFFParseBase
		move.l	d0,MyIFFHandle(a4)
		tst.l	d0
		beq	.SaveError1

		lea	PrefsFileName(a4),a0
		move.l	a0,d1
		move.l	d1,EasyArg(a4)
		move.l	#MODE_NEWFILE,d2
		RELLIB	Open,_DOSBase
		move.l	MyIFFHandle(a4),a0
		move.l	d0,iff_Stream(a0)
		tst.l	d0
		beq	.DosSaveError

		RELLIB	InitIFFasDOS,_IFFParseBase

		move.l	MyIFFHandle(a4),a0
		move.l	#IFFF_WRITE,d0
		DOLIB	OpenIFF
		tst.l	d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Push FORM chunk
		move.l	#'KCXM',d0
		move.l	#'FORM',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Push Version Chunk
		move.l	#'KCXM',d0
		move.l	#'VERS',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0
		lea	VersChunk,a1
		move.l	#VersChunkSize,d0
		DOLIB	WriteChunkBytes
		cmp.l	#VersChunkSize,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0
		DOLIB	PopChunk
		tst.l	d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Preferences
		move.l	#'KCXM',d0
		move.l	#'PREF',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Bool qualifiers
		lea	BOOLQUALSTART(a4),a1
		move.l	#FLAGSET,d0
		DOLIB	WriteChunkBytes
		cmp.l	#FLAGSET,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Long qualifiers
		lea	LONGQUALSTART(a4),a1
		move.l	#LONGQUAL,d0
		DOLIB	WriteChunkBytes
		cmp.l	#LONGQUAL,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write window positions
		lea	MainWinLeft(a4),a1
		move.l	#WINPOSLEN,d0
		DOLIB	WriteChunkBytes
		cmp.l	#WINPOSLEN,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write zoomed size of Bill window
		lea	BillZoomSize,a1
		moveq	#8,d0
		DOLIB	WriteChunkBytes
		cmp.l	#8,d0
		bne	.SaveError

		lea	HotKeyGadStat,a3		; Write HotKey definitions
		move.l	#HOTKEYNUM-1,d7
.LoopHKeys	move.l	MyIFFHandle(a4),a0
		move.l	(a3)+,a1
		move.l	#40,d0
		DOLIB	WriteChunkBytes
		cmp.l	#40,d0
		bne	.SaveError
		dbf	d7,.LoopHKeys

		move.l	MyIFFHandle(a4),a0		; Write User-Shell command
		lea	SystemComm(a4),a1
		move.l	#256,d0
		DOLIB	WriteChunkBytes
		cmp.l	#256,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Logfilename
		lea	LogFileName(a4),a1
		move.l	#300,d0
		DOLIB	WriteChunkBytes
		cmp.l	#300,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Public Screen list
		lea	PubScreenName(a4),a1
		move.l	#256,d0
		DOLIB	WriteChunkBytes
		cmp.l	#256,d0
		bne	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write FKeys
		lea	FKeys(a4),a1
		move.l	#(MAXFKEYWIDTH+2)*10*4,d0
		DOLIB	WriteChunkBytes
		cmp.l	#(MAXFKEYWIDTH+2)*10*4,d0
		bne.s	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write FileReq position
		lea	FileReqLeft,a1
		move.l	#28,d0
		DOLIB	WriteChunkBytes
		cmp.l	#28,d0
		bne.s	.SaveError

		move.l	MyIFFHandle(a4),a0		; Write Sample name
		lea	AlSampleName(a4),a1
		move.l	#256,d0
		DOLIB	WriteChunkBytes
		cmp.l	#256,d0
		bne.s	.SaveError

		lea	WindowBase(a4),a2		; Write window names to be locked
		SUCC	a2,a2
.Loop		TSTLST2	a2,a0
		beq.s	.NoNames
		move.l	MyIFFHandle(a4),a0
		lea	lw_Name(a2),a1
		move.l	#82,d0
		DOLIB	WriteChunkBytes
		cmp.l	#82,d0
		bne.s	.SaveError
		SUCC	a2,a2
		bra.s	.Loop

.NoNames	move.l	MyIFFHandle(a4),a0		; Pop Prefs chunk
		DOLIB	PopChunk
		tst.l	d0
		bne.s	.SaveError

		move.l	MyIFFHandle(a4),a0		; Pop last Chunk (FORM)
		DOLIB	PopChunk
		tst.l	d0
		bne.s	.SaveError
		bra.s	.EndSave

.SaveError	tst.l	d0				; Dos error occured ?
		beq.s	.EndSave
		neg.l	d0
		add.l	#400,d0				; Identify error code
		move.l	d0,ErrorNum(a4)
.SaveError1	jsr	DisplayError
		bra.s	.EndSave
.DosSaveError	RELLIB	IoErr,_DOSBase
		move.l	d0,ErrorNum(a4)
		jsr	DisplayError
.EndSave	tst.l	MyIFFHandle(a4)
		beq.s	.NoHandle
		move.l	MyIFFHandle(a4),a0
		RELLIB	CloseIFF,_IFFParseBase
		move.l	MyIFFHandle(a4),a0
		tst.l	iff_Stream(a0)
		beq.s	.NoStream
		move.l	iff_Stream(a0),d1
		RELLIB	Close,_DOSBase
.NoStream	move.l	MyIFFHandle(a4),a0
		RELLIB	FreeIFF,_IFFParseBase
.NoHandle	rts



**********************************************************************
*  This routine initializes the process to handle all check events   *
**********************************************************************
InitChecker	lea	CheckerTags(pc),a0
		move.l	a0,d1				; Start Process with tags
		RELLIB	CreateNewProc,_DOSBase
		tst.l	d0
		beq.s	.Error
		move.l	#SIGHANDSHAKE,d0		; Wait for reply
		CALLSYS	Wait
.Error		rts
**********************************************************************
*               Tags for new process of checker events               *
**********************************************************************
CheckerTags	dc.l	NP_Entry			; We only supply an entry point
		dc.l	TimeChecker
		dc.l	NP_Name				; Name of process
		dc.l	CheckerName
		dc.l	NP_Priority			; We run at a higher proirity
		dc.l	10				; so that we`re quite fast
		dc.l	NP_StackSize			; Stack-Size to be used
		dc.l	4096
		dc.l	TAG_DONE




**********************************************************************
*                     Install the ARexx-Process                      *
**********************************************************************
InitRexxProc	lea	RexxTags(pc),a0
		move.l	a0,d1				; Start Process
		RELLIB	CreateNewProc,_DOSBase
		tst.l	d0
		beq.s	.Error
		move.l	#SIGHANDSHAKE,d0		; Wait for reply
		CALLSYS	Wait
.Error		rts
**********************************************************************
*                Tags for new process of ARexx events                *
**********************************************************************
RexxTags	dc.l	NP_Entry			; We only supply an entry point
		dc.l	RexxChecker
		dc.l	NP_Name				; Name of process
		dc.l	RexxName
		dc.l	NP_Priority			; We run at a higher proirity
		dc.l	0				; so that we`re quite fast
		dc.l	NP_StackSize			; Stack-Size to be used
		dc.l	4096
		dc.l	TAG_DONE





**********************************************************************
*          This is the small process to handle timer events          *
**********************************************************************
TimeChecker	movem.l	RegsAll,-(sp)

		lea	ZeroPage,a4

		bsr	InitHandler			; Install the InputHandler
		tst.l	d0
		beq	CheckerError

		bsr	InitAudio			; Init Audio-Stuff
		tst.l	d0
		beq	CheckerError

		moveq	#-1,d0				; Get signal for Events
		CALLSYS	AllocSignal
		move.l	d0,EventSigBit(a4)
		tst.l	d0
		blt	CheckerError
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,EventSigFlag(a4)

		sub.l	a1,a1
		DOLIB	FindTask
		move.l	d0,CheckerProc(a4)

		move.l	OurTask(a4),a1			; Signal mother
		move.l	#SIGHANDSHAKE,d0
		DOLIB	Signal

.Loop		move.l	#SIGHANDSHAKE,d0		; for signal to go away
		or.l	#SIGTIMEREMAKE,d0		; for signal to remake display
		or.l	#SIGBILLWIN,d0			; pop up bill window
		or.l	BillSigFlag(a4),d0		; message from bill window
		or.l	ClockSigFlag(a4),d0		; message from clock window
		or.l	EventSigFlag(a4),d0		; for input events
		CALLSYS	Wait
		move.l	d0,CheckerProcSig(a4)

		move.l	CheckerProcSig(a4),d0		; Got signal to cycle ?
		and.l	EventSigFlag(a4),d0
		beq.s	.NoEventSig

		bsr	EventMsgLoop			; Check for pending "events"

.NoEventSig	move.l	CheckerProcSig(a4),d0		; Are we to go away ?
		and.l	#SIGHANDSHAKE,d0
		bne	CheckerError			; Yep -> do so

		move.l	CheckerProcSig(a4),d0		; Did it come from the
		and.l	BillSigFlag(a4),d0		; Bill window ?
		beq.s	.NoBillSig
		bsr	CheckBillWindow

.NoBillSig	move.l	CheckerProcSig(a4),d0		; Only remake time display ?
		and.l	#SIGTIMEREMAKE,d0
		beq.s	.NoTimeRemake
		jsr	SetTime				; Yep -> do so
		jsr	RemakeCosts			; Also redisplay billstuff

.NoTimeRemake	move.l	CheckerProcSig(a4),d0		; Pop up bill window ?
		and.l	#SIGBILLWIN,d0
		beq.s	.NoBillOpenUp
		tst.l	BillHandle(a4)			; Window already open ?
		bne.s	.CloseBill			; yep -> close it
		bsr	OpenBillWin
		bra.s	.NoBillOpenUp
.CloseBill	bsr	CloseBillWin

.NoBillOpenUp	move.l	CheckerProcSig(a4),d0		; Message from clock window ?
		and.l	ClockSigFlag(a4),d0
		beq.s	.NoClockMsg

.LoopClockMsg	move.l	ClockHandle(a4),a0
		move.l	wd_UserPort(a0),a0
		CALLSYS	GetMsg
		tst.l	d0
		beq.s	.NoClockMsg

		move.l	d0,a1
		move.l	im_Class(a1),d7

		DOLIB	ReplyMsg

		cmp.l	#IDCMP_CLOSEWINDOW,d7		; Clock window closed ?
		bne.s	.NoClockClose
		clr.b	ClockWin(a4)
		bsr	CloseClockWin
		tst.l	MainHandle(a4)
		beq.s	.NoClockMsg
		move.b	ClockWin(a4),d0
		move.l	#GD_DisplayWin,d1		; Set checkbox tick
		jsr	SetMiscBox
		bra.s	.NoClockMsg

.NoClockClose	cmp.l	#IDCMP_CHANGEWINDOW,d7		; Window moved ?
		bne.s	.LoopClockMsg
		move.l	ClockHandle(a4),a0
		lea	ClockWinLeft(a4),a1
		jsr	StoreWinPos
		bra	.LoopClockMsg
.NoClockMsg	bra	.Loop

CheckerError	bsr	RemoveHandler			; Remove Handler
		bsr	RemoveAudio			; Remove Audio-Stuff
		bsr	CloseBillWin			; Close the billwindow

		tst.l	EventSigBit(a4)			; Clear SigBit
		blt.s	.NoEventSig
		move.l	EventSigBit(a4),d0
		CALLSYS	FreeSignal

.NoEventSig	jsr	OnMouse
		CALLSYS	Forbid
		jsr	OnScreen
		CALLSYS	Permit
		move.l	OurTask(a4),a1			; Signal mother that we`re fine
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal
		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                  Handler for incoming InputEvents                  *
**********************************************************************
EventMsgLoop	lea	ZeroPage,a4
		lea	EventPool(a4),a0		; Find an event
		moveq	#MAXEVENTS-1,d7
.Find		tst.l	LN_NAME(a0)
		bne.s	.GoOn
		lea	req_SIZEOF(a0),a0
		dbf	d7,.Find
		rts

.GoOn		move.l	a0,EventMsg(a4)			; Store pointer to event

		move.l	EventMsg(a4),a0			; Activate window ?
		cmp.l	#REQ_ACTIVATE,LN_NAME(a0)
		bne	NoActiveEvent
		jsr	Activate
		move.l	EventMsg(a4),a0
		lea	req_IEvent(a0),a0
		cmp.b	#IECLASS_RAWKEY,ie_Class(a0)
		bne	EventDone
		tst.b	MapUmlaut(a4)			; Map "Umlauts" ?
		beq	NoUmlaut
		move.l	EventMsg(a4),a1			; Check for "Umlauts"
		lea	req_IEvent(a1),a1
		move.w	ie_Qualifier(a1),d1		; Only accept plain and shifted keys
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		move.w	d1,d2
		and.w	#(IEQUALIFIER_LALT|IEQUALIFIER_RALT|IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND),d2
		bne	NoUmlaut
		movem.l	d1/a1,-(sp)
		link	a5,#-20
		move.l	a1,a0
		lea	-20(a5),a1
		clr.b	(a1)
		move.l	#19,d1
		sub.l	a2,a2
		RELLIB	RawKeyConvert,_ConsoleBase
		moveq	#0,d0
		move.b	-20(a5),d0
		unlk	a5
		movem.l	(sp)+,d1/a1
.UmlautOk	lea	UmlautTab,a3			; Get UmlautTab
		moveq	#7,d7
.GetUmlaut	cmp.w	(a3),d0				; Got "Umlaut" ?
		beq.s	.GotUmlaut			; Yep -> go on
		addq.l	#6,a3
		dbf	d7,.GetUmlaut
		bra.s	NoUmlaut			; No "Umlaut"
.GotUmlaut	cmp.b	#'ß',d0
		bne.s	.NoSS
		move.w	d1,d0
		and.w	#(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),d0
		bne.s	NoUmlaut
		bra.s	.NoShift
.NoSS		tst.w	(a3)				; Skip shifted ß
		beq.s	NoUmlaut

.NoShift	link	a5,#-ie_SIZEOF			; Get space for one IEs
		move.b	ie_SubClass(a1),d0		; Get subclass
		move.l	ie_EventAddress(a1),d2		; Address

		move.b	#IECLASS_NULL,ie_Class(a1)	; Clear current event

		lea	-ie_SIZEOF(a5),a0		; Create new event -> Clear link to next
		clr.l	ie_NextEvent(a0)
		move.b	#IECLASS_RAWKEY,ie_Class(a0)
		move.b	d0,ie_SubClass(a0)
		move.w	2(a3),ie_Code(a0)		; Get first char for "Umlaut"
		move.w	d1,ie_Qualifier(a0)
		move.l	d2,ie_EventAddress(a0)
		LNKLIB	AddIEvents,_CxBase		; Add events
		lea	-ie_SIZEOF(a5),a0
		move.w	4(a3),ie_Code(a0)		; Get second char for "Umlaut"
		and.w	#~(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),ie_Qualifier(a0)
		DOLIB	AddIEvents
		unlk	a5
		bra.s	HadUmlaut
NoUmlaut	clr.l	ie_NextEvent(a0)
		LNKLIB	AddIEvents,_CxBase
HadUmlaut	bsr	GetSemaphore
		tst.b	MouseEver(a4)			; Blank mouse ?
		beq.s	.NoMouseOff
		move.l	MBlankWindow(a4),d0
		move.l	_IntuitionBase(a4),a0
		cmp.l	ib_ActiveWindow(a0),d0
		beq.s	.NoMouseOff
		jsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		jsr	OffMouse			; On key-press allways blank mouse
.NoMouseOff	bsr	FreeSemaphore
		bra	EventDone

NoActiveEvent	move.l	EventMsg(a4),a0			; Work window cycling
		cmp.l	#REQ_CYCLE,LN_NAME(a0)
		bne	NoMouseEvent

		move.l	EventMsg(a4),a1
		lea	req_IEvent(a1),a1
		move.w	ie_Code(a1),d0
		move.w	ie_Qualifier(a1),d1
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	FrontCode(a4),d0
		bne.s	.NotFront
		cmp.w	FrontQual(a4),d1
		beq	.CheckCycle
.NotFront	cmp.w	BackCode(a4),d0
		bne.s	.NotBack
		cmp.w	BackQual(a4),d1
		beq	.NoPopFront
.NotBack	cmp.w	#IECODE_MBUTTON,d0
		bne	.EndCycle
		cmp.w	MiddleQual(a4),d1
		bne	.EndCycle

		cmp.w	#1,MiddleClicks(a4)
		beq.s	.DoBackM
		tst.l	MCycleSecs(a4)
		bge.s	.CheckDoubleM
.RemakeDoubleM	move.l	EventMsg(a4),a1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	TV_SECS(a1),MCycleSecs(a4)	; Copy current system ticks
		move.l	TV_MICRO(a1),MCycleMicro(a4)
		bra	.RemakeCounters
.CheckDoubleM	subq.w	#1,ThisMiddleClick(a4)
		bgt	.EndCycle
		move.l	EventMsg(a4),a1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	MCycleSecs(a4),d0
		move.l	MCycleMicro(a4),d1
		move.l	TV_SECS(a1),d2
		move.l	TV_MICRO(a1),d3
		move.l	#-1,MCycleSecs(a4)
		RELLIB	DoubleClick,_IntuitionBase
		tst.l	d0
		beq.s	.RemakeDoubleM
.DoBackM	move.l	_IntuitionBase(a4),a0
		move.l	ib_FirstScreen(a0),a0
		bra	.PopScrBack

.CheckCycle	move.l	#-1,BCycleSecs(a4)
		move.l	#-1,MCycleSecs(a4)
		cmp.w	#1,FrontClicks(a4)
		beq	.OneFront
		tst.l	FCycleSecs(a4)			; Double click to front ?
		bge.s	.CheckDoubleF
.RemakeDouble	move.l	EventMsg(a4),a1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	TV_SECS(a1),FCycleSecs(a4)	; Copy current system ticks
		move.l	TV_MICRO(a1),FCycleMicro(a4)
		clr.l	CycledWin(a4)			; Clear window pointer
		clr.l	CycledScreen(a4)		; Clear screen pointer
		jsr	FindWindow			; Find a layer
		tst.l	d0				; Got one ?
		beq	.RemakeCounters			; Nope -> No window
		move.l	a0,CycledScreen(a4)
		move.l	d0,a0
		move.l	lr_Window(a0),CycledWin(a4)	; Store pointer to window
		bra	.RemakeCounters
.CheckDoubleF	jsr	FindWindow			; Check if window is still the same
		cmp.l	CycledScreen(a4),a0		; Same screen ?
		bne.s	.RemakeDouble			; Nope -> remake
		tst.l	d0				; Got a window ?
		beq.s	.NoWindow			; Nope -> go on
		move.l	d0,a1				; Window the same a last one ?
		move.l	lr_Window(a1),d1		; Layer with a window ?
		beq.s	.NoWindow			; Nope -> Could be a screen
		cmp.l	CycledWin(a4),d1		; Window the same ? Nope -> go on
		bne.s	.RemakeDouble
.NoWindow	subq.w	#1,ThisFrontClick(a4)
		bgt	.EndCycle
		movem.l	d0/a0,-(sp)
		move.l	EventMsg(a4),a1
		move.l	FCycleSecs(a4),d0		; Check for double click
		move.l	FCycleMicro(a4),d1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	TV_SECS(a1),d2
		move.l	TV_MICRO(a1),d3
		move.l	#-1,FCycleSecs(a4)
		RELLIB	DoubleClick,_IntuitionBase
		movem.l	(sp)+,d1/a0
		tst.l	d0				; Click OK ?
		beq	.RemakeDouble			; Nope -> Remake ticks
		tst.l	d1				; Did we have a layer ?
		beq.s	.PopScrFront			; Nope -> check for screen
		move.l	d1,d0				; Check window
		bra.s	.SpecToFront
.OneFront	jsr	FindWindow			; Find window underneith layer
		tst.l	d0
		beq.s	.PopScrFront			; No layer, no window
.SpecToFront	move.l	d0,a5
		move.l	lr_Window(a5),d1		; Layer with window ?
		beq.s	.PopScrFront			; Nope -> screen
		move.l	lr_ClipRect(a5),a1		; Window hidden by others ?
		move.l	a1,d0
		beq	.EndCycle
		tst.l	cr_Next(a1)
		beq	.EndCycle
		move.l	lr_Window(a5),a5
		move.l	wd_Flags(a5),d1
		move.l	d1,d2
		and.l	#WFLG_BACKDROP,d1		; BackDrop window -> Pop Screen
		bne.s	.PopScrFront
		and.l	#WFLG_DEPTHGADGET,d2		; Does the window have a DEPTH-Gad ???
		beq	.EndCycle			; Nope -> no pop to front
		move.l	a5,a0
		RELLIB	WindowToFront,_IntuitionBase
		bra.s	.EndFront
.PopScrFront	move.l	a0,d0				; Got Screen address ???
		beq	.EndCycle
		RELLIB	ScreenToFront,_IntuitionBase	; Pop screen to front
.EndFront	bra	.EndCycle
.NoPopFront	move.l	#-1,FCycleSecs(a4)
		move.l	#-1,MCycleSecs(a4)


		cmp.w	#1,BackClicks(a4)
		beq	.OneBack
		tst.l	BCycleSecs(a4)			; Double click to front ?
		bge.s	.CheckDoubleB
.RemakeDoubleB	move.l	EventMsg(a4),a1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	TV_SECS(a1),BCycleSecs(a4)	; Copy current system ticks
		move.l	TV_MICRO(a1),BCycleMicro(a4)
		clr.l	CycledWin(a4)			; Clear window pointer
		clr.l	CycledScreen(a4)		; Clear screen pointer
		jsr	FindWindow			; Find a layer
		tst.l	d0				; Got one ?
		beq	.RemakeCounters			; Nope -> No window
		move.l	a0,CycledScreen(a4)
		move.l	d0,a0
		move.l	lr_Window(a0),CycledWin(a4)	; Store pointer to window
		bra	.RemakeCounters
.CheckDoubleB	jsr	FindWindow			; Check if window is still the same
		cmp.l	CycledScreen(a4),a0		; Same screen ?
		bne.s	.RemakeDoubleB			; Nope -> remake
		tst.l	d0				; Got a window ?
		beq.s	.NoWindowB			; Nope -> go on
		move.l	d0,a1				; Window the same a last one ?
		move.l	lr_Window(a1),d1		; Layer with a window ?
		beq.s	.NoWindowB			; Nope -> Could be a screen
		cmp.l	CycledWin(a4),d1		; Window the same ? Nope -> go on
		bne.s	.RemakeDoubleB
.NoWindowB	subq.w	#1,ThisBackClick(a4)
		bgt	.EndCycle
		movem.l	d0/a0,-(sp)
		move.l	EventMsg(a4),a1
		move.l	BCycleSecs(a4),d0		; Check for double click
		move.l	BCycleMicro(a4),d1
		lea	req_IEvent(a1),a1
		lea	ie_TimeStamp(a1),a1
		move.l	TV_SECS(a1),d2
		move.l	TV_MICRO(a1),d3
		move.l	#-1,BCycleSecs(a4)
		RELLIB	DoubleClick,_IntuitionBase
		movem.l	(sp)+,d1/a0
		tst.l	d0				; Click OK ?
		beq	.RemakeDoubleB			; Nope -> Remake ticks
		tst.l	d1				; Did we have a layer ?
		beq.s	.PopScrBack			; Nope -> check for screen
		move.l	d1,d0				; Check window
		bra.s	.SpecToBack
.OneBack	jsr	FindWindow			; Find layer
		tst.l	d0
		beq.s	.PopScrBack			; No layer, no window
.SpecToBack	move.l	d0,a1
		move.l	lr_Window(a1),a1
		move.l	a1,d0				; Got a window ?
		beq.s	.PopScrBack
		move.l	wd_Flags(a1),d0
		move.l	d0,d1
		and.l	#WFLG_BACKDROP,d0		; BackDrop window ?
		bne.s	.PopScrBack
		and.l	#WFLG_DEPTHGADGET,d1		; DEPTH-Gad there ?
		beq	EventDone			; Nope -> go on
		tst.l	wd_NextWindow(a1)
		bne.s	.ToBack
		move.l	wd_WScreen(a1),a0
		cmp.l	sc_FirstWindow(a0),a1
		beq	EventDone
.ToBack		move.l	a1,-(sp)
		RELLIB	WaitTOF,_GfxBase		; Wait a bit so that
							; the ButtonUp message can arrive
		move.l	(sp)+,a0
		RELLIB	WindowToBack,_IntuitionBase
		bra	EventDone
.PopScrBack	move.l	a0,d0				; If we have a screen ->
		beq	EventDone			; Let it pop
		RELLIB	ScreenToBack,_IntuitionBase
.EndCycle	bra	EventDone
.RemakeCounters	move.w	FrontClicks(a4),d0		; Reset click counter
		subq.w	#1,d0
		move.w	d0,ThisFrontClick(a4)
		move.w	MiddleClicks(a4),d0		; Reset click counter
		subq.w	#1,d0
		move.w	d0,ThisMiddleClick(a4)
		move.w	BackClicks(a4),d0		; Reset click counter
		subq.w	#1,d0
		move.w	d0,ThisBackClick(a4)
		bra.s	.EndCycle

NoMouseEvent	move.l	EventMsg(a4),a0			; Disk Event ?
		cmp.l	#REQ_DISKCHANGE,LN_NAME(a0)
		bne	NoDiskChEvent

		link	a5,#-4

		move.l	#id_SIZEOF,d0			; Allocate InfoData Buffer
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		move.l	d0,-4(a5)
		tst.l	d0
		beq	.Error

		lea	DriveNames,a1
		lea	DriveChange(a4),a2
		lea	DriveRequests(a4),a3
		moveq	#0,d7
.FindDrive	tst.l	(a3)
		beq	.NotThisOne
		movem.l	a1/a2,-(sp)
		move.l	(a3),a1
		move.w	#TD_CHANGENUM,IO_COMMAND(a1)
		clr.b	IO_FLAGS(a1)
		CALLSYS	DoIO
		movem.l	(sp)+,a1/a2
		move.l	(a3),a0
		move.l	IO_ACTUAL(a0),d0
		move.l	(a2),d1
		move.l	d0,(a2)
		cmp.l	d1,d0
		ble.s	.NotThisOne
		move.l	a1,-(sp)
		move.l	(a1),d1
		RELLIB	DeviceProc,_DOSBase
		move.l	(sp)+,a1
		tst.l	d0
		beq.s	.NotThisOne
		movem.l	d7/a1,-(sp)
		move.l	d0,d1
		move.l	#ACTION_DISK_INFO,d2
		move.l	-4(a5),d3
		lsr.l	#2,d3
		moveq	#0,d4
		moveq	#0,d5
		moveq	#0,d6
		moveq	#0,d7
		DOLIB	DoPkt
		movem.l	(sp)+,d7/a1
		tst.l	d0
		beq.s	.NotThisOne
		move.l	-4(a5),a0
		cmp.l	#ID_UNREADABLE_DISK,id_DiskType(a0)
		beq.s	.ThisOne
		cmp.l	#ID_NOT_REALLY_DOS,id_DiskType(a0)
		bne.s	.NotThisOne
.ThisOne	move.w	d7,FormatDrive(a4)
		move.l	-4(a5),a1
		CALLSYS	FreeVec
		unlk	a5
		move.l	OurTask(a4),a1
		move.l	FormatSigFlag(a4),d0
		DOLIB	Signal
		bra	EventDone
.NotThisOne	addq.l	#4,a1
		addq.l	#4,a2
		addq.l	#4,a3
		addq.l	#1,d7
		cmp.l	#4,d7
		bne	.FindDrive

.Error		tst.l	-4(a5)
		beq.s	.EndDisk
		move.l	-4(a5),a1
		CALLSYS	FreeVec
.EndDisk	unlk	a5
		bra	EventDone

NoDiskChEvent	move.l	EventMsg(a4),a0			; Scr to back ?
		cmp.l	#REQ_SCRBACK,LN_NAME(a0)
		bne.s	NoScrBackEvent
		CALLSYS	Forbid
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase
		move.l	ib_ActiveScreen(a6),a2
		move.l	d0,a0
		DOLIB	UnlockIBase
		CALLSYS	Permit
		move.l	a2,d0
		beq	EventDone
		move.l	a2,a0
		RELLIB	ScreenToBack,_IntuitionBase
		bra	EventDone

NoScrBackEvent	move.l	EventMsg(a4),a0			; WB to front ?
		cmp.l	#REQ_WBFRONT,LN_NAME(a0)
		bne.s	NoWBFrontEvent
		RELLIB	WBenchToFront,_IntuitionBase
		bra	EventDone

NoWBFrontEvent	move.l	EventMsg(a4),a0			; Timer Event ?
		cmp.l	#REQ_TIMER,LN_NAME(a0)
		bne	EventDone

		CALLSYS	Forbid
		link	a5,#-4				; Check for system font
		moveq	#0,d7				; within titlebar
		bsr	LockScreen
		tst.l	d0
		beq.s	.NoScreen
		move.l	d0,a0
		move.l	sc_BarLayer(a0),a1
		move.l	lr_rp(a1),a1
		move.l	rp_Font(a1),d1
		cmp.l	OldSysFont(a4),d1		; Still the same font used ?
		bne.s	.NewFont			; Yep -> go on
		move.l	a0,a1
		lea	sc_BitMap(a1),a1
		moveq	#0,d0
		move.b	bm_Depth(a1),d0
		cmp.w	BitMapDepth(a4),d0
		beq.s	.NoFont
.NewFont	moveq	#1,d7
.NoFont		bsr	UnlockScreen
.NoScreen	unlk	a5
		CALLSYS	Permit
		tst.b	d7
		beq.s	.NoRemakeFont
		CALLSYS	Forbid
		jsr	ClearTitleBar
		bsr	RemoveGfx
		bsr	InitGfx
		CALLSYS	Permit

.NoRemakeFont	jsr	SetTime				; Set new time
		jsr	CheckOnline			; Set new online time

		tst.b	TimeReset(a4)			; Reset timers ?
		beq.s	.NoTime				; (if times were altered)
		move.l	EventMsg(a4),a0
		lea	req_IEvent(a0),a0
		jsr	ResetTimer
		bra	.NoMouseOff
.NoTime		move.l	EventMsg(a4),a0
		lea	req_IEvent(a0),a0
		lea	ie_TimeStamp(a0),a0
		tst.b	DoBlankNow(a4)
		bne.s	.BlankNow
		tst.b	ScrTimeOut(a4)
		bne.s	.NoScreenOff
		tst.l	ScreenTime(a4)			; Screen to be blanked ?
		beq.s	.NoScreenOff			; nope -> go on
		move.l	ScreenOff(a4),d0		; Screen timeout ?
		sub.l	TV_SECS(a0),d0
		bge.s	.NoScreenOff			; Nope -> go on
.BlankNow	move.l	TV_SECS(a0),d1			; Set time for next timeout
		add.l	ScreenTime(a4),d1
		add.l	#10,d1
		move.l	d1,ScreenOff(a4)
		tst.b	DoBlankNow(a4)
		bne.s	.ComeOnBlank
		cmp.l	#-10,d0
		blt.s	.NoScreenOff
.ComeOnBlank	clr.b	DoBlankNow(a4)
		move.b	#1,ScrTimeOut(a4)		; Screen and mouse are timed out
		move.b	#1,MouseTimeOut(a4)
		CALLSYS	Forbid
		jsr	OffScreen
		CALLSYS	Permit
.NoScreenOff	tst.b	MouseTimeOut(a4)
		bne.s	.NoMouseOff
		tst.l	MouseTime(a4)			; Mouse to be blanked ?
		beq.s	.NoMouseOff			; Nope -> go on
		move.l	EventMsg(a4),a0			; Check, whether time for
		lea	req_IEvent(a0),a0
		lea	ie_TimeStamp(a0),a0		; blank has come
		move.l	MouseOff(a4),d0
		sub.l	TV_SECS(a0),d0
		bge.s	.NoMouseOff			; Nope -> go on
		move.l	TV_SECS(a0),d1			; Store new values for next
		add.l	MouseTime(a4),d1		; blank.
		addq.l	#1,d1
		move.l	d1,MouseOff(a4)
		cmp.l	#-10,d0
		blt.s	.NoMouseOff
		bsr	GetSemaphore
		move.l	_IntuitionBase(a4),a0
		move.l	ib_ActiveWindow(a0),a0
		cmp.l	MBlankWindow(a4),a0
		beq.s	.NoMouseOff
		jsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		jsr	OffMouse			; Blank mouse
		bsr	FreeSemaphore

.NoMouseOff	tst.l	BlankScrHandle(a4)		; Do we have a "blank screen" ?
		bne.s	.CheckScreen
		tst.l	DimmBase(a4)
		beq.s	EventDone

.CheckScreen	CALLSYS	Forbid

		move.l	_IntuitionBase(a4),a0
		move.l	ib_FirstScreen(a0),a0

		tst.b	ScreenDimm(a4)
		bne.s	.StillBlank
		cmp.l	BlankScrHandle(a4),a0		; If not close it
		beq.s	.StillBlank
		jsr	OnScreen

.StillBlank	CALLSYS	Permit

EventDone	move.l	EventMsg(a4),a1
		clr.l	LN_NAME(a1)
		bra	EventMsgLoop			; Loop for remaining messages







**********************************************************************
*                   Check the BillWindow-Messages                    *
**********************************************************************
CheckBillWindow	move.l	BillHandle(a4),a0		; Get message
		move.l	wd_UserPort(a0),a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq	NoBillMsg
		move.l	d0,a1

		move.l	im_Class(a1),d6
		move.w	im_Code(a1),d5
		cmp.w	#'a',d5
		blt.s	.End
		and.w	#~$20,d5
.End		move.l	d6,d0
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		move.l	im_IAddress(a1),a0
		move.w	gg_GadgetID(a0),d7

.NoGad		DOLIB	GT_ReplyIMsg

		cmp.l	#IDCMP_CLOSEWINDOW,d6		; Window close ???
		bne.s	NoBillClose
BillClose	bsr	CloseBillWin
		bra	NoBillMsg

NoBillClose	cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved/zoomed ?
		bne.s	NoBillChange
		move.l	BillHandle(a4),a0
		move.l	wd_Flags(a0),d0
		and.l	#WFLG_ZOOMED,d0
		bne.s	.IsZoomed
		clr.b	Zipped(a4)
		move.l	BillHandle(a4),a0
		lea	BillWinLeft(a4),a1		; Store pos for normal size
		jsr	StoreWinPos
		move.l	BillHandle(a4),a0
		lea	BillTitle(a4),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		jsr	RemakeCosts
		bra	CheckBillWindow
.IsZoomed	move.b	#1,Zipped(a4)
		move.w	wd_LeftEdge(a0),BillZoomSize	; Store pos for zoomed size
		move.w	wd_TopEdge(a0),BillZoomSize+2
		jsr	RemakeCosts
		bra	CheckBillWindow

NoBillChange	cmp.l	#IDCMP_GADGETDOWN,d6
		bne.s	NoBillGadDown

		cmp.w	#GD_BillTimeMX,d7			; Changed timezone ?
		bne.s	NoTimeZoneGad
		move.b	#1,DoRemakeCosts(a4)
		ext.l	d5
		move.l	d5,TimeZone
		jsr	RemakeCosts
		bra	CheckBillWindow

NoTimeZoneGad	cmp.w	#GD_BillCheap,d7			; Changed timemode
		bne	CheckBillWindow
		move.b	#1,DoRemakeCosts(a4)
		move.b	#1,DontCheckTime(a4)
		move.b	d5,CheapMode(a4)
		jsr	RemakeCosts
		bra	CheckBillWindow

NoBillGadDown	cmp.l	#IDCMP_GADGETUP,d6		; GadgetUp ?
		bne.s	NoBillGadUp

		cmp.w	#GD_LogCall,d7			; Enable/Disable phone logs ?
		bne	CheckBillWindow
		bra.s	LogCallKey

NoBillGadUp	cmp.l	#IDCMP_VANILLAKEY,d6
		bne	CheckBillWindow

		cmp.w	#ESCKEY,d5			; Hide window ?
		bne.s	BNoEscKey
		bra	BillClose

BNoEscKey	cmp.w	#KD_LogCall,d5			; Enable/Disable phone logs ?
		bne.s	NoLogKey
LogCallKey	bchg	#0,LogCalls(a4)
		move.b	LogCalls(a4),d0
		move.l	#GD_LogCall,d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetCheckBox
		bra	CheckBillWindow

NoLogKey	cmp.w	#KD_BillTime1,d5		; Change time zone ?
		blt.s	NoTimeKeys
		cmp.w	#KD_BillTime3,d5
		bgt.s	NoTimeKeys
		sub.w	#'1',d5				; Calc new zone
		move.b	#1,DoRemakeCosts(a4)
		ext.l	d5
		move.l	d5,TimeZone
		move.l	#GD_BillTimeMX,d0
		move.l	d5,d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetMXGad
		jsr	RemakeCosts
		bra	CheckBillWindow

NoTimeKeys	cmp.w	#KD_BillNormal,d5		; Activate normal time mode ?
		bne.s	NoNormalKey

		clr.b	CheapMode(a4)
SetNewTariff	move.b	#1,DoRemakeCosts(a4)
		move.b	#1,DontCheckTime(a4)
		move.l	#GD_BillCheap,d0
		moveq	#0,d1
		move.b	CheapMode(a4),d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetMXGad
		jsr	RemakeCosts
		bra	CheckBillWindow

NoNormalKey	cmp.w	#KD_BillCheap,d5			; Activate cheap time mode ?
		bne	CheckBillWindow
		move.b	#1,CheapMode(a4)
		bra	SetNewTariff
NoBillMsg	rts




**********************************************************************
*          This is the process to check for ARexx-Commands           *
**********************************************************************
RexxChecker	movem.l	RegsAll,-(sp)

		lea	ZeroPage,a4

		bsr	InitARexx			; Init ARexx-Port
		tst.l	d0
		beq.s	NoRexx

		move.l	OurTask(a4),a1			; Signal mother A.Ok
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal

		sub.l	a1,a1				; Store address to this proc
		CALLSYS	FindTask
		move.l	d0,RexxProc(a4)

CheckRexx	move.l	#SIGHANDSHAKE,d0		; Wait for signals
		or.l	ARexxSigFlag(a4),d0
		CALLSYS	Wait
		move.l	d0,RexxSig(a4)

		move.l	RexxSig(a4),d0			; Remove Process ?
		and.l	#SIGHANDSHAKE,d0
		bne.s	NoRexx

		move.l	RexxSig(a4),d0			; Did it come from ARexx ?
		and.l	ARexxSigFlag(a4),d0
		beq.s	CheckRexx
		jsr	HandleARexx			; Handle ARexx commands
		bra	CheckRexx

NoRexx		bsr	RemoveARexx			; Remove ARexx-Port

		move.l	OurTask(a4),a1			; Signal mother A.Ok
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal

		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*                 Check the main part of this proggy                 *
**********************************************************************
CheckBroker	tst.w	QuitBroker(a4)			; Quit our broker ?
		bne	AbortBroker

		move.l	#SIGBREAKF_CTRL_C,d0		; Accept a BREAK (like from c:break)
		or.l	BrokerSigFlag(a4),d0		; Wait for sig on port of
		or.l	WindowPortSig(a4),d0		; ... a window
		or.l	AlarmSigFlag(a4),d0		; ... Display alarm
		or.l	FormatSigFlag(a4),d0		; ... Formatter
		or.l	AppSigFlag(a4),d0		; ... of App-Icon
		or.l	DragSigFlag(a4),d0		; ... do dragging
		CALLSYS	Wait
		move.l	d0,ThisSig(a4)

		move.l	ThisSig(a4),d0			; Got signal from child to
		and.l	AlarmSigFlag(a4),d0		; alarm
		beq	NoAlarmDisp

		bsr	OnMouse				; User can see what`s up
		CALLSYS	Forbid
		bsr	OnScreen			; Turn on everything, so that
		CALLSYS	Permit

		link	a5,#-4
		bsr	LockScreen
		tst.l	d0
		beq	.Error

		tst.b	AlarmSample(a4)
		beq.s	.PlayBeep
		tst.b	SampleLoaded(a4)
		bne.s	.PlaySample
.PlayBeep	move.l	-4(a5),a0			; Make it beep
		DOLIB	DisplayBeep
		bra	.BeepDone

.PlaySample	move.l	_GfxBase(a4),a0			; Get clock rates
		move.w	gb_DisplayFlags(a0),d0
		and.w	#PAL,d0
		beq.s	.IsNTSC
		move.l	#3546895,d7
		bra.s	.DoSample
.IsNTSC		move.l	#3579545,d7

.DoSample	lea	AudioName(pc),a0		; Try to open device
		moveq	#0,d0
		move.l	AlarmReq(a4),a1
		move.w	#ADCMD_ALLOCATE,IO_COMMAND(a1)
		move.b	#ADIOF_NOWAIT,IO_FLAGS(a1)
		clr.w	ioa_AllocKey(a1)
		move.l	#AnyChannel,ioa_Data(a1)
		move.l	#4,ioa_Length(a1)
		move.l	AlarmPort(a4),MN_REPLYPORT(a1)
		move.b	#-50,LN_PRI(a1)
		moveq	#0,d1				; suggested by UISG
		CALLSYS	OpenDevice
		tst.l	d0
		bne.s	.BeepDone

		move.l	d7,d0				; Calculate period
		moveq	#0,d1
		move.w	AlarmSmpSec(a4),d1
		RELLIB	UDivMod32,_UtilityBase

		move.l	AlarmReq(a4),a1			; Play alarm
		move.w	#CMD_WRITE,IO_COMMAND(a1)
		move.b	#ADIOF_PERVOL,IO_FLAGS(a1)
		move.l	AlarmSmpStart(a4),ioa_Data(a1)
		move.l	AlarmSmpLen(a4),ioa_Length(a1)
		move.w	d0,ioa_Period(a1)
		move.w	#64,ioa_Volume(a1)
		move.w	#1,ioa_Cycles(a1)
		move.l	AlarmPort(a4),MN_REPLYPORT(a1)
		move.b	#-50,LN_PRI(a1)
		move.l	IO_DEVICE(a1),a6
		jsr	DEV_BEGINIO(a6)
		move.l	AlarmReq(a4),a1
		CALLSYS	WaitIO
		move.l	AlarmReq(a4),a1
		CALLSYS	CloseDevice

.BeepDone	tst.b	DoShowAlarm(a4)
		beq.s	.Error

		lea	MyEasyRequest,a1		; Display Easy-Requester
		move.l	#EasyTitle,es_Title(a1)
		move.l	#AlarmReqText,es_TextFormat(a1)
		move.l	#EasyGadget,es_GadgetFormat(a1)
		sub.l	a0,a0
		sub.l	a2,a2
		sub.l	a3,a3
		RELLIB	EasyRequestArgs,_IntuitionBase

.Error		bsr	UnlockScreen
		unlk	a5

NoAlarmDisp	move.l	ThisSig(a4),d0
		and.l	BrokerSigFlag(a4),d0		; If it was on the Msg-Port
		beq	NoCxMsgs

WorkAllMsgs	move.l	BrokerPort(a4),a0		; Check the msgs
		CALLSYS	GetMsg
		tst.l	d0
		beq	NoCxMsgs
		move.l	d0,a3

		move.l	a3,a0				; Get Msg-Type
		LNKLIB	CxMsgType,_CxBase
		move.l	d0,MsgType(a4)

		move.l	a3,a0				; Get ID of msg
		DOLIB	CxMsgID
		move.l	d0,MsgID(a4)

		move.l	a3,a1
		CALLSYS	ReplyMsg

		cmp.l	#CXM_COMMAND,MsgType(a4)	; Commodities command ?
		bne.s	NoXCommand			; Yep -> go on

		move.l	MsgID(a4),d0

		cmp.l	#CXCMD_KILL,d0			; Are we to go away ?
		bne.s	NoKill
		move.w	#1,QuitBroker(a4)
		bra	WorkAllMsgs

NoKill		cmp.l	#CXCMD_DISABLE,d0		; Disable broker ?
		bne.s	DontDisable
		jsr	DisableBroker
		move.b	#1,Disabled(a4)
		bra	WorkAllMsgs

DontDisable	cmp.l	#CXCMD_ENABLE,d0		; Enable ???
		bne.s	DontEnable
		move.b	#1,TimeReset(a4)
		clr.b	Disabled(a4)
		jsr	EnableBroker
		bra	WorkAllMsgs

DontEnable	cmp.l	#CXCMD_UNIQUE,d0		; Another broker with same name
		bne.s	NoUnique			; -> Quit program
		move.w	#1,QuitBroker(a4)
		bra	WorkAllMsgs

NoUnique	cmp.l	#CXCMD_APPEAR,d0		; Open our window ?
		bne.s	NoAppear
		bsr	OpenMainWin
		bra	WorkAllMsgs

NoAppear	cmp.l	#CXCMD_DISAPPEAR,d0		; Close our window ?
		bne	WorkAllMsgs
		bsr	CloseMainWin
		bra	WorkAllMsgs

NoXCommand	cmp.l	#CXM_IEVENT,MsgType(a4)		; Pop up key used ???
		bne	WorkAllMsgs			; Nope -> Loop for msgs

		cmp.l	#POPUPKEYID,MsgID(a4)		; Are we to pop up ?
		bne.s	NoPopUpWindow
		bsr	OpenMainWin			; Open our window
		bra	WorkAllMsgs

NoPopUpWindow	cmp.l	#PAGEKEYID,MsgID(a4)		; Change display mode of time ?
		bne.s	NoPageChange
		cmp.l	#SNAPMEMPAGE,PageNum(a4)
		bne.s	.GoOn
		move.l	OldPageNum(a4),d0			; Restore old Page
		move.l	d0,PageNum(a4)
		bra.s	.End1
.GoOn		addq.l	#1,PageNum(a4)
		cmp.l	#MAXPAGES,PageNum(a4)
		blt.s	.End
		clr.l	PageNum(a4)
.End		move.l	PageNum(a4),d0
		move.l	d0,OldPageNum(a4)
.End1		jsr	ClearTitleBar
		jsr	SigTime
		bra	WorkAllMsgs

NoPageChange	cmp.l	#PREFSKEYID,MsgID(a4)		; Pop Up prefs window ?
		bne.s	NoPrefsPopUp
		bsr	OpenPrefsWin
		bra	WorkAllMsgs

NoPrefsPopUp	cmp.l	#BILLKEYID,MsgID(a4)		; Pop Up Bill window ?
		bne.s	NoBillHotKey
		move.l	CheckerProc(a4),a1
		move.l	#SIGBILLWIN,d0
		CALLSYS	Signal
		bra	WorkAllMsgs

NoBillHotKey	cmp.l	#HOTWINKEYID,MsgID(a4)		; Pop Up HotKey window ?
		bne.s	NoHotKeyPop
		bsr	OpenHotKeyWin
		bra	WorkAllMsgs

NoHotKeyPop	cmp.l	#SHELLKEYID,MsgID(a4)		; Pop Up Shell ?
		bne	NoShellPop
		lea	SystemInOut(pc),a0
		move.l	a0,d1				; Open the dummy Files NIL:
		move.l	#MODE_NEWFILE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,SysInput
		move.l	#SystemInOut,d1
		move.l	#MODE_NEWFILE,d2
		DOLIB	Open
		move.l	d0,SysOutput
		move.l	OurTask(a4),a0			; Make Path-List, only if NOT
		tst.l	pr_CLI(a0)			; Startet from CLI
		beq.s	.NoPath
		move.l	#TAG_DONE,SysCLI		; Clear remaining tags
		bra	.GotPath
.NoPath		move.l	#NP_Path,SysCLI			; Allow Process tags
		move.l	pr_CurrentDir(a0),d1		; Clone mother`s current dir
		RELLIB	DupLock,_DOSBase
		tst.l	d0
		beq	.NoProc
		move.l	d0,SysDir
		lea	WBPName(pc),a1			; Try to get a pointer to a process
		CALLSYS	FindTask			; we can clone the pathlist from
		tst.l	d0				; Try to get the Workbench,
		bne.s	.GotProc			; AmigaShell, InitialCLI,
		lea	ICLIName(pc),a1			; Background CLI or New CLI processes
		DOLIB	FindTask			; This is needed, so that the new
		tst.l	d0				; shell may execute Prgs, which
		bne.s	.GotProc			; are located in dirs you
		lea	NCLIName(pc),a1			; worked a PATH on.
		DOLIB	FindTask			; We have to arrange a pathlist
		tst.l	d0				; which looks like this :
		bne.s	.GotProc			; Size of block, Link to next, Lock-BPTR
		lea	AShellName(pc),a1
		DOLIB	FindTask
		tst.l	d0
		bne.s	.GotProc
		lea	BCLIName(pc),a1
		DOLIB	FindTask
		tst.l	d0
		beq	.NoProc
.GotProc	DOLIB	Forbid
		move.l	d0,a0				; So we have a process -> go on
		move.l	pr_CLI(a0),d0			; Get pointer to it`s CLI-Structure
		lsl.l	#2,d0				; Convert the BPTR
		move.l	d0,a0				; Get pointer to A0
		move.l	cli_CommandDir(a0),d0		; Get pointer to CommandDir
		lsl.l	#2,d0				; Convert to normal Pointer
		move.l	d0,a2				; Store pointer
		lea	SysPath,a5			; Get Pointer to Tags-Entry
.GetPath	move.l	a2,d0				; No (more) path ?
		beq.s	.GotPath			; -> Start Shell
		moveq	#12,d0				; Allocate a small link-structure
		move.l	#MEMF_PUBLIC|MEMF_CLEAR,d1
		CALLSYS	AllocVec
		tst.l	d0				; Could not get mem for one more
		beq.s	.GotPath			; path lock -> start Shell
		move.l	d0,d1				; Get pointer to memory block
		addq.l	#4,d1				; Point to middle of these 3 LongWords
		lsr.l	#2,d1				; Convert to BPTR
		move.l	d1,(a5)				; Store Pointer to structure
		move.l	d0,a5				; Let A5 point to new memory block
		addq.l	#4,a5				; -> right to the middle
		move.l	d0,a3				; Store pointer
		move.l	4(a2),d1			; Duplicate Lock to Path
		RELLIB	DupLock,_DOSBase
		move.l	d0,8(a3)			; Store LockPointer
		clr.l	4(a3)				; Clear link-pointer
		move.l	#12,0(a3)			; Store length of one Path-Entry
		move.l	(a2),d0				; Get pointer to mother`s next path
		lsl.l	#2,d0				; Convert to normal pointer
		move.l	d0,a2				; Now restart for next path
		bra.s	.GetPath
.GotPath	CALLSYS	Permit
		lea	SystemComm(a4),a0
		move.l	a0,d1				; Start Shell...
		lea	SystemTags(pc),a0
		move.l	a0,d2
		RELLIB	SystemTagList,_DOSBase
.NoProc		bra	WorkAllMsgs

NoShellPop	cmp.l	#UMLAUTKEYID,MsgID(a4)		; Change "Umlaut" mode ?
		bne.s	NoUmlautEx
		bchg	#0,MapUmlaut(a4)
		move.b	MapUmlaut(a4),d0
		move.l	#GD_MapUmlauts,d1
		jsr	SetSetBox
		bra	WorkAllMsgs

NoUmlautEx	cmp.l	#MISCKEYID,MsgID(a4)		; Open Misc window ?
		bne.s	NoMiscHotKey
		bsr	OpenMiscWin
		bra	WorkAllMsgs

NoMiscHotKey	cmp.l	#SNAPKEYID,MsgID(a4)		; Snap memory ?
		bne	NoSnapHotKey
		tst.b	Snapped(a4)
		bne.s	.DisplaySnap
		sub.l	a0,a0				; Give feedback
		RELLIB	DisplayBeep,_IntuitionBase
		CALLSYS	Forbid
		move.l	#MEMF_CHIP,d1			; Get current memory settings
		DOLIB	AvailMem
		move.l	d0,ThisChip
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		move.l	d0,ThisFast
		move.b	#1,Snapped(a4)
		cmp.l	#SNAPMEMPAGE,PageNum(a4)
		bne.s	.End
		jsr	ClearTitleBar
.End		move.l	OldPageNum(a4),d0
		move.l	d0,PageNum(a4)
		CALLSYS	Permit
		bra	WorkAllMsgs
.DisplaySnap	CALLSYS	Forbid
		move.l	#MEMF_CHIP,d1			; Get current memory settings
		DOLIB	AvailMem
		sub.l	ThisChip,d0			; Get delta mem usage
		move.l	d0,ThisChip
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		sub.l	ThisFast,d0			; Get delta mem usage
		move.l	d0,ThisFast
		jsr	ClearTitleBar
		move.l	PageNum(a4),d0
		move.l	d0,OldPageNum(a4)
		move.l	#SNAPMEMPAGE,PageNum(a4)	; Switch to correct display
		clr.b	Snapped(a4)			; Clear flag
		CALLSYS	Permit
		bra	WorkAllMsgs

NoSnapHotKey	cmp.l	#DOBLANKKEYID,MsgID(a4)		; Blank screen ?
		bne.s	NoDoBlankHKey
		move.b	#1,DoBlankNow(a4)
		bra	WorkAllMsgs

NoDoBlankHKey	cmp.l	#FORMKEYID,MsgID(a4)		; Format window ?
		bne.s	NoFormHKey
		jsr	OpenFormWin
		bra	WorkAllMsgs

NoFormHKey	cmp.l	#CYCLEKEYID,MsgID(a4)		; Cycle window ?
		bne.s	NoCycleHKey
		jsr	OpenCycleWin
		bra	WorkAllMsgs

NoCycleHKey	cmp.l	#FKEYKEYID,MsgID(a4)		; FKeys window ?
		bne.s	NoFKeyHKey
		jsr	OpenFKeyWin
		bra	WorkAllMsgs

NoFKeyHKey	cmp.l	#SETKEYID,MsgID(a4)		; Settings window ?
		bne.s	NoSetHKey
		bsr	OpenSetWin
		bra	WorkAllMsgs

NoSetHKey	cmp.l	#ALARMKEYID,MsgID(a4)		; Alarm window ?
		bne.s	NoAlarmHKey
		bsr	OpenAlarmWin
		bra	WorkAllMsgs

NoAlarmHKey	cmp.l	#BLANKKEYID,MsgID(a4)		; Blank window ?
		bne.s	NoBlankHKey
		bsr	OpenBlankWin
		bra	WorkAllMsgs

NoBlankHKey	cmp.l	#COLSKEYID,MsgID(a4)		; Colors window ?
		bne.s	NoColsHKey
		bsr	OpenColsWin
		bra	WorkAllMsgs

NoColsHKey	cmp.l	#MOUSEKEYID,MsgID(a4)		; Mouse window ?
		bne.s	NoMouseHKey
		bsr	OpenMouseWin
		bra	WorkAllMsgs

NoMouseHKey	cmp.l	#DUMPKEYID,MsgID(a4)		; Dump screen ?
		bne.s	NoDumpHKey
		tst.b	Dumping(a4)
		beq.s	.GoOn
		move.l	PrintProc(a4),a1
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal
		bra	WorkAllMsgs
.GoOn		tst.b	GetSource(a4)
		bne.s	.GetSource
		tst.l	PrintHandle(a4)
		bne.s	.End
.GetSource	move.l	PrintProc(a4),a1
		move.l	GfxDumpFlag(a4),d0
		CALLSYS	Signal
.End		bra	WorkAllMsgs

NoDumpHKey	cmp.l	#LOCKKEYID,MsgID(a4)		; Open Lock window ?
		bne.s	NoLockHKey
		bsr	OpenLockWin
		bra	WorkAllMsgs

NoLockHKey	cmp.l	#CENTERKEYID,MsgID(a4)		; Recenter a screen ?
		bne.s	NoCenterHKey
		CALLSYS	Forbid
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase
		move.l	d0,-(sp)
		jsr	GetDispCols
		move.l	ib_ActiveScreen(a6),a3
		move.l	(sp)+,a0
		DOLIB	UnlockIBase
		move.l	a3,a0
		move.w	sc_Width(a0),d1
		move.l	sc_ViewPort(a0),a1
		move.w	vp_Modes(a1),d7
		move.w	d7,d6
		and.w	#V_HIRES,d7
		bne.s	.IsHires
		and.w	#V_SUPERHIRES,d6
		bne.s	.SuperHires
		lsr.w	#1,d5
		bra.s	.IsHires
.SuperHires	lsl.w	#1,d5
.IsHires	sub.w	d1,d5
		ble.s	.FullSize
		lsr.w	#1,d5
.FullSize	move.w	sc_LeftEdge(a0),d0
		sub.w	d0,d5
		move.w	d5,d0
		moveq	#0,d1
		DOLIB	MoveScreen
.End		CALLSYS	Permit
		bra	WorkAllMsgs

NoCenterHKey	bra	WorkAllMsgs

NoCxMsgs	move.l	ThisSig(a4),d0			; of a window ?
		and.l	WindowPortSig(a4),d0
		beq.s	NoWindowMsg

LoopWndMsg	move.l	WindowPort(a4),a0		; Loop for all messages
		RELLIB	GT_GetIMsg,_GadToolsBase	; Get gadtools message
		tst.l	d0
		beq.s	NoWindowMsg
		move.l	d0,a1

		move.l	im_Class(a1),d6			; Get class
		moveq	#0,d5
		move.w	im_Code(a1),d5			; Get code
		cmp.l	#IDCMP_VANILLAKEY,d6
		bne.s	.End
		move.w	im_Qualifier(a1),d4
		cmp.w	#'a',d5
		blt.s	.End
		and.w	#~$20,d5
.End		move.l	d6,d0
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		move.l	im_IAddress(a1),a2		; Get gadget id
		move.w	gg_GadgetID(a2),d7

.NoGad		move.l	im_IDCMPWindow(a1),a3
		DOLIB	GT_ReplyIMsg			; Reply gadtools msg

		move.l	a3,d0
		beq	LoopWndMsg
		lea	WindowHandles,a0
		lea	WindowRoutines,a1
		move.l	#WINDOWNUM-1,d0
.FindWindow	move.l	(a0)+,a5
		cmp.l	(a5),a3
		bne.s	.GoOn
		move.l	(a1),a0
		jsr	(a0)
		bra	LoopWndMsg
.GoOn		addq.l	#4,a1
		dbf	d0,.FindWindow
		bra	LoopWndMsg

NoWindowMsg	move.l	ThisSig(a4),d0			; App-Message ?
		and.l	AppSigFlag(a4),d0
		beq.s	NoAppMsg

.LoopAppMsg	move.l	AppPort(a4),a0			; Get message
		CALLSYS	GetMsg
		tst.l	d0
		beq.s	NoAppMsg
		move.l	d0,a1
		cmp.w	#MTYPE_APPICON,am_Type(a1)	; Did it come from window ?
		bne.s	.NoAppIcon
		tst.l	am_NumArgs(a1)
		bne.s	.ReplyAppMsg
		tst.l	am_ArgList(a1)
		bne.s	.ReplyAppMsg
		move.l	a1,-(sp)
		bsr	OpenMainWin			; Open our window
		move.l	(sp)+,a1
		bra.s	.ReplyAppMsg
.NoAppIcon	cmp.w	#MTYPE_APPMENUITEM,am_Type(a1)	; Was a menu item ?
		bne.s	.ReplyAppMsg
		cmp.l	#MAINITEM,am_ID(a1)		; The control-window ?
		bne.s	.ReplyAppMsg
		move.l	a1,-(sp)
		bsr	OpenMainWin			; Open it
		move.l	(sp)+,a1
.ReplyAppMsg	CALLSYS	ReplyMsg
		bra	.LoopAppMsg

NoAppMsg	move.l	ThisSig(a4),d0			; Signal for formatter ?
		and.l	FormatSigFlag(a4),d0
		beq.s	NoFormSig
		jsr	CheckFormat

NoFormSig	move.l	ThisSig(a4),d0			; Signal for dragging ?
		and.l	DragSigFlag(a4),d0
		beq.s	NoDragSig
		jsr	DoDragging

NoDragSig	bra	CheckBroker			; Loop for all stuff

AbortBroker	clr.b	Disabled(a4)			; Disable broker
		jsr	DisableBroker
		rts
**********************************************************************
*                  Tags for use to open a new shell                  *
**********************************************************************
SystemTags	dc.l	SYS_Input
SysInput	dc.l	0
		dc.l	SYS_Output
SysOutput	dc.l	0
		dc.l	SYS_Asynch
		dc.l	1
		dc.l	NP_Priority
		dc.l	0
SysCLI		dc.l	NP_Path
SysPath		dc.l	0
		dc.l	NP_CurrentDir
SysDir		dc.l	0
		dc.l	TAG_DONE
DefSystemComm	dc.b	"NewSHELL CON:0/11//200/KCX-Shell/CLOSE/ALT///50/50",0
SystemInOut	dc.b	"NIL:",0
WBPName		dc.b	"Workbench",0			; Names of processes we want
							; to clone path-lists from :-)
NCLIName	dc.b	"New CLI",0
ICLIName	dc.b	"Initial CLI",0
AShellName	dc.b	"AmigaShell",0
BCLIName	dc.b	"Background CLI",0
		EVEN





**********************************************************************
*               Handle the gadgets of the main window                *
**********************************************************************
HandleMainWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseMainWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Windo moved ?
		bne.s	NoMainMove
		move.l	MainHandle(a4),a0
		lea	MainWinLeft(a4),a1
		bra	StoreWinPos

NoMainMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoMainGadUp

		cmp.w	#GD_Settings,d7			; Open settings window ?
		beq	OpenSetWin

		cmp.w	#GD_Misc,d7			; Open misc window ?
		beq	OpenMiscWin

		cmp.w	#GD_Blanking,d7			; Open blanking window ?
		beq	OpenBlankWin

		cmp.w	#GD_Cycling,d7			; Open cycling window ?
		beq	OpenCycleWin

		cmp.w	#GD_Mouse,d7			; Open Mouse window ?
		beq	OpenMouseWin

		cmp.w	#GD_HotKey,d7			; Open HotKeys window ?
		beq	OpenHotKeyWin

		cmp.w	#GD_FKey,d7			; Open FKeys window ?
		beq	OpenFKeyWin

		cmp.w	#GD_Format,d7			; Open Formatter window ?
		beq	OpenFormWin

		cmp.w	#GD_BillWin,d7			; Open Bill window ?
		bne.s	NoBillWinGad
DoOpenBillWin	move.l	CheckerProc(a4),a1
		move.l	#SIGBILLWIN,d0
		CALLSYS	Signal
		rts

NoBillWinGad	cmp.w	#GD_BillPrefs,d7		; Open prefs window ?
		beq	OpenPrefsWin

		cmp.w	#GD_Alarm,d7			; Open alarm window ?
		beq	OpenAlarmWin

		cmp.w	#GD_Colors,d7			; Open colors window ?
		beq	OpenColsWin

		cmp.w	#GD_HardCopy,d7			; Open Dump window ?
		bne.s	NoDumpGad
DumpKey		move.l	PrintProc(a4),a1
		move.l	GfxDumpFlag(a4),d0
		CALLSYS	Signal
		rts

NoDumpGad	cmp.w	#GD_LockWins,d7			; Open Lock windows win ?
		beq	OpenLockWin

		cmp.w	#GD_LoadPrefs,d7		; Load prefs ?
		bne.s	NoLoadPrefs
LoadPrefsGad	pea	SetStringGad
		clr.l	-(sp)
		clr.l	-(sp)
		clr.w	-(sp)
		pea	PrefsFileName+ZeroPage
		pea	PrefsLoadHeader
		move.l	MainHandle(a4),-(sp)
		jsr	GetFileName
		lea	26(sp),sp
		tst.l	d0
		beq.s	.End
		bsr	LoadPrefs
		jsr	ClearTitleBar
		bsr	SigTime
.End		rts

NoLoadPrefs	cmp.w	#GD_SavePrefs,d7		; Save Prefs ?
		bne.s	NoSavePrefsGad
SavePrefsGad	pea	SetStringGad
		clr.l	-(sp)
		clr.l	-(sp)
		clr.w	-(sp)
		pea	PrefsFileName+ZeroPage
		pea	PrefsSaveHeader
		move.l	MainHandle(a4),-(sp)
		jsr	GetFileName
		lea	26(sp),sp
		tst.l	d0
		beq.s	.End
		bsr	DoublePrefs
.End		rts

NoSavePrefsGad	cmp.w	#GD_HideGad,d7			; Hide ???
		beq	CloseMainWin

		cmp.w	#GD_Enable,d7			; Enable Broker ?
		bne.s	NoEnableGad
EnableKey	clr.b	Disabled(a4)
		jsr	EnableBroker
		rts

NoEnableGad	cmp.w	#GD_Disable,d7			; Disable Broker ?
		bne.s	NoDisableGad
DisableKey	jsr	DisableBroker
		move.b	#1,Disabled(a4)
		rts

NoDisableGad	cmp.w	#GD_Quit,d7			; Quit stuff ?
		bne.s	NoQuitGad
QuitKey		move.w	#1,QuitBroker(a4)
NoQuitGad	rts

NoMainGadUp	cmp.l	#IDCMP_MENUPICK,d6		; Menu Picked ???
		bne	NoMainMenu

		cmp.w	#MENUNULL,d5
		beq.s	.End
		move.l	MainMenu(a4),a0
		move.w	d5,d0
		ext.l	d0
		RELLIB	ItemAddress,_IntuitionBase
		move.l	d0,a0
		GTMENUITEM_USERDATA a0,a0
		move.l	a0,d0
		beq.s	.End
		jmp	(a0)
.End		rts

DisplayAbout	lea	MyEasyRequest,a1		; Display Easy-Requester
		move.l	#EasyTitle,es_Title(a1)
		move.l	#AboutText,es_TextFormat(a1)
		move.l	#AboutGadgets,es_GadgetFormat(a1)
		sub.l	a0,a0
		sub.l	a2,a2
		sub.l	a3,a3
		RELLIB	EasyRequestArgs,_IntuitionBase
		tst.l	d0
		bne.s	.NoRegister
		lea	PrtName(pc),a0
		move.l	a0,d1
		move.l	#MODE_NEWFILE,d2
		RELLIB	Open,_DOSBase
		tst.l	d0
		beq.s	.NoRegister
		move.l	d0,d7
		move.l	d0,d1
		move.l	#RegisterTxt,d2
		move.l	#REGISTERLEN,d3
		DOLIB	Write
.Error		move.l	d7,d1
		DOLIB	Close
.NoRegister	rts
ReSavePrefs	bra	DoublePrefs
PrtName		dc.b	"PRT:",0
		EVEN

NoMainMenu	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoMainVKey

		cmp.w	#KD_Settings,d5			; Open settings window ?
		bne.s	NoSettingsKey
		move.l	#GD_Settings,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenSetWin

NoSettingsKey	cmp.w	#KD_Misc,d5			; Open misc window ?
		bne.s	NoMiscKey
		move.l	#GD_Misc,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenMiscWin

NoMiscKey	cmp.w	#KD_Alarm,d5			; Open alarm win ?
		bne.s	NoAlarmWinKey
		move.l	#GD_Alarm,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenAlarmWin

NoAlarmWinKey	cmp.w	#KD_Blanking,d5			; Open blanking window ?
		bne.s	NoBlankWinKey
		move.l	#GD_Blanking,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenBlankWin

NoBlankWinKey	cmp.w	#KD_Cycling,d5			; Open cycle window ?
		bne.s	NoCycleWinKey
		move.l	#GD_Cycling,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenCycleWin

NoCycleWinKey	cmp.w	#KD_Colors,d5			; Open colors window ?
		bne.s	NoColorsKey
		move.l	#GD_Colors,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenColsWin

NoColorsKey	cmp.w	#KD_Mouse,d5			; Open mouse window ?
		bne.s	NoMouseWinKey
		move.l	#GD_Mouse,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenMouseWin

NoMouseWinKey	cmp.w	#KD_HotKey,d5			; Open HotKey window ?
		bne.s	NoHotKeyWinKey
		move.l	#GD_HotKey,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenHotKeyWin

NoHotKeyWinKey	cmp.w	#KD_FKey,d5			; Open fkeys window ?
		bne.s	NoFKeyWinKey
		move.l	#GD_FKey,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenFKeyWin

NoFKeyWinKey	cmp.w	#KD_Format,d5			; Open format window ?
		bne.s	NoFormWinKey
		move.l	#GD_Format,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenFormWin

NoFormWinKey	cmp.w	#KD_Bill,d5			; Open bill window ?
		bne.s	NoBillWinKey
		move.l	#GD_BillWin,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	DoOpenBillWin

NoBillWinKey	cmp.w	#KD_BillPrefs,d5		; Open prefs window ?
		bne.s	NoPrefsWinKey
		move.l	#GD_BillPrefs,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenPrefsWin

NoPrefsWinKey	cmp.w	#KD_HardCopy,d5			; Open HardCopy window ?
		bne.s	NoDumpKey
		move.l	#GD_HardCopy,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	DumpKey

NoDumpKey	cmp.w	#KD_LockWins,d5			; Open LockWins window ?
		bne.s	NoLockWinKey
		move.l	#GD_LockWins,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	OpenLockWin

NoLockWinKey	cmp.w	#ESCKEY,d5			; Close window ?
		beq.s	.GoOn
		cmp.w	#KD_HideGad,d5
		bne.s	NoHideKey
.GoOn		move.l	#GD_HideGad,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	CloseMainWin

NoHideKey	cmp.w	#KD_LoadPrefs,d5		; Load Prefs
		bne.s	NoLoadPrefsKey
		move.l	#GD_LoadPrefs,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	LoadPrefsGad

NoLoadPrefsKey	cmp.w	#KD_SavePrefs,d5		; Save Prefs
		bne.s	NoSavePrefsKey
		move.l	#GD_SavePrefs,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	SavePrefsGad

NoSavePrefsKey	cmp.w	#KD_Enable,d5			; Enable broker ???
		bne.s	NoEnableKey
		move.l	#GD_Enable,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	EnableKey

NoEnableKey	cmp.w	#KD_Disable,d5			; Disable broker ???
		bne.s	NoDisableKey
		move.l	#GD_Disable,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	DisableKey

NoDisableKey	cmp.w	#KD_Quit,d5			; Quit programm ???
		bne.s	NoQuitKey
		move.l	#GD_Quit,d0
		lea	MainGads(a4),a0
		move.l	MainHandle(a4),a5
		bsr	ButtonCheck
		bra	QuitKey

NoQuitKey
NoMainVKey	rts




**********************************************************************
*                       Handle Settings window                       *
**********************************************************************
HandleSetWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close Window ?
		beq	CloseSetWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoSetMove
		move.l	SetHandle(a4),a0
		lea	SetWinLeft(a4),a1
		bra	StoreWinPos

NoSetMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released ?
		bne	NoSetGadUp

		cmp.w	#GD_Display,d7			; Clock on/off ?
		bne.s	NoDisplayGad
DisplayKey	bchg	#0,ShowClock(a4)
		move.b	ShowClock(a4),d0		; reflect new choice
		move.l	#GD_Display,d1
		bsr	SetSetBox
		jsr	ClearTitleBar			; Clear titlebar
		bsr	CloseClockWin			; Close clock window
		bra	SigTime

NoDisplayGad	cmp.w	#GD_DisplayWin,d7		; Display in window ?
		bne.s	NoDisplayWinGad
WindowKey	bchg	#0,ClockWin(a4)
		move.b	#1,ShowClock(a4)
		move.b	ClockWin(a4),d0
		move.l	#GD_DisplayWin,d1
		bsr	SetSetBox
		moveq	#1,d0
		move.l	#GD_Display,d1
		bsr	SetSetBox
		jsr	ClearTitleBar
		bra	SigTime

NoDisplayWinGad	cmp.w	#GD_ShowTime,d7			; Display time ?
		bne.s	NoShowTimeGad
ShowTimeKey	bchg	#0,DoShowTime(a4)
		move.b	DoShowTime(a4),d0
		move.l	#GD_ShowTime,d1
		bsr	SetSetBox
		jsr	ClearTitleBar
		bra	SigTime

NoShowTimeGad	cmp.w	#GD_ShowSecs,d7			; Display seconds ?
		bne.s	NoShowSecsGad
SecsKey		bchg	#0,ShowSecs(a4)
		move.b	ShowSecs(a4),d0
		move.l	#GD_ShowSecs,d1
		bsr	SetSetBox
		jsr	ClearTitleBar
		bra	SigTime

NoShowSecsGad	cmp.w	#GD_ShowDate,d7			; Show date ?
		bne.s	NoShowDateGad
DateKey		bchg	#0,ShowDate(a4)
		move.b	ShowDate(a4),d0
		move.l	#GD_ShowDate,d1
		bsr	SetSetBox
		bsr	ClearTitleBar
		bra	SigTime

NoShowDateGad	cmp.w	#GD_AmiDate,d7			; American date ?
		bne.s	NoAmiDateGad
AmiKey		bchg	#0,AmiDate(a4)
		move.b	AmiDate(a4),d0
		move.l	#GD_AmiDate,d1
		bsr	SetSetBox
		bsr	ClearTitleBar
		bra	SigTime

NoAmiDateGad	cmp.w	#GD_ShowDay,d7			; Show day ?
		bne.s	NoShowDayGad
DayKey		bchg	#0,ShowDay(a4)
		move.b	ShowDay(a4),d0
		move.l	#GD_ShowDay,d1
		bsr	SetSetBox
		bsr	ClearTitleBar
		bra	SigTime

NoShowDayGad	cmp.w	#GD_ShortDay,d7			; Short day ?
		bne.s	NoShortDayGad
ShortDayKey	bchg	#0,ShortDay(a4)
		move.b	ShortDay(a4),d0
		move.l	#GD_ShortDay,d1
		bsr	SetSetBox
		bsr	ClearTitleBar
		bra	SigTime

NoShortDayGad	cmp.w	#GD_WriteEnv,d7			; Environment vars ?
		bne.s	NoWriteEnvGad
WriteEnvKey	bchg	#0,SetEnv(a4)
		tst.b	SetEnv(a4)
		bne.s	.NoDel
		jsr	DeleteEnvs			; Delete vars, if turned off
.NoDel		move.b	SetEnv(a4),d0
		move.l	#GD_WriteEnv,d1
		bra	SetSetBox

NoWriteEnvGad	cmp.w	#GD_WBFront,d7			; WB to front ?
		bne.s	NoWBFrontGad
WBFrontKey	bchg	#0,WBFront(a4)
		move.b	WBFront(a4),d0
		move.l	#GD_WBFront,d1
		bra	SetSetBox

NoWBFrontGad	cmp.w	#GD_Lefty,d7			; LeftyMouse ?
		bne.s	NoLeftyGad
LeftyKey	bchg	#0,LeftyMouse(a4)
		move.b	LeftyMouse(a4),d0
		move.l	#GD_Lefty,d1
		bra	SetSetBox

NoLeftyGad	cmp.w	#GD_MapUmlauts,d7		; Map umlauts ?
		bne.s	NoUmlautsGad
MapUmlautsKey	bchg	#0,MapUmlaut(a4)
		move.b	MapUmlaut(a4),d0
		move.l	#GD_MapUmlauts,d1
		bra	SetSetBox

NoUmlautsGad	cmp.w	#GD_AppIcon,d7			; Show AppIcon ?
		bne.s	NoAppIconGad
AppIconKey	bchg	#0,DispAppIcon(a4)
		tst.b	DispAppIcon(a4)
		beq.s	.IconOff
		jsr	OnAppIcon
		bra.s	.GoOn
.IconOff	jsr	OffAppIcon
.GoOn		move.b	DispAppIcon(a4),d0
		move.l	#GD_AppIcon,d1
		bra	SetSetBox

NoAppIconGad	cmp.w	#GD_AutoCtr,d7			; Changed Auto Center mode ?
		bne.s	NoAutoCtrGad
AutoCtrKey	bchg	#0,AutoCenter(a4)
		move.b	AutoCenter(a4),d0		; Set Auto Center gadget
		move.l	#GD_AutoCtr,d1
		bra	SetSetBox

NoAutoCtrGad	cmp.w	#GD_MMBShift,d7			; Changed MMB-Shift mode ?
		bne.s	NoMMBShiftGad
MMBShiftKey	bchg	#0,MMBShift(a4)
		move.b	MMBShift(a4),d0			; Set Auto Center gadget
		move.l	#GD_MMBShift,d1
		bra	SetSetBox

NoMMBShiftGad	cmp.w	#GD_GermanDays,d7		; Changed German day mode ?
		bne.s	NoGermanDayGad
GermanDaysKey	bchg	#0,GermanDays(a4)
		bsr	ClearTitleBar
		bsr	SigTime
		move.b	GermanDays(a4),d0
		move.l	#GD_GermanDays,d1
		bra	SetSetBox

NoGermanDayGad	cmp.w	#GD_PDate,d7			; Change date format ?
		bne.s	NoPointDateGad
PDateKey	bchg	#0,PointDates(a4)
		bsr	ClearTitleBar
		bsr	SigTime
		move.b	PointDates(a4),d0
		move.l	#GD_PDate,d1
		bra	SetSetBox

NoPointDateGad	cmp.w	#GD_NoClick,d7			; Change noclick state ?
		bne.s	NoNoClickGad
NoClickKey	bchg	#0,DriveNoClick(a4)
		move.b	DriveNoClick(a4),d0
		move.l	#GD_NoClick,d1
		bsr	SetSetBox
		jmp	SetNoClick

NoNoClickGad	cmp.w	#GD_ShowMouse,d7		; Show mouse positions ?
		bne.s	NoShowMouseGad
ShowMouseKey	bchg	#0,ShowMouse(a4)
		bsr	ClearTitleBar
		bsr	SigTime
		move.b	ShowMouse(a4),d0
		move.l	#GD_ShowMouse,d1
		bra	SetSetBox

NoShowMouseGad	rts

NoSetGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoSetVKey

		cmp.w	#ESCKEY,d5			; Close window ?
		beq	CloseSetWin

		cmp.w	#KD_Display,d5			; Display time
		beq	DisplayKey

		cmp.w	#KD_DisplayWin,d5		; Display window
		beq	WindowKey

		cmp.w	#KD_ShowTime,d5			; Display time
		beq	ShowTimeKey

		cmp.w	#KD_ShowDate,d5			; Show date
		beq	DateKey

		cmp.w	#KD_AmiDate,d5			; Ami date
		beq	AmiKey

		cmp.w	#KD_ShowDay,d5			; Show day
		beq	DayKey

		cmp.w	#KD_ShowSecs,d5			; Show secs
		beq	SecsKey

		cmp.w	#KD_ShortDay,d5			; Short day string
		beq	ShortDayKey

		cmp.w	#KD_WriteEnv,d5			; Write env vars
		beq	WriteEnvKey

		cmp.w	#KD_WBFront,d5			; WB to front
		beq	WBFrontKey

		cmp.w	#KD_Lefty,d5			; LeftyMouse
		beq	LeftyKey

		cmp.w	#KD_MapUmlauts,d5		; Map Umlauts
		beq	MapUmlautsKey

		cmp.w	#KD_AppIcon,d5			; Display AppIcon
		beq	AppIconKey

		cmp.w	#KD_AutoCtr,d5			; Auto center
		beq	AutoCtrKey

		cmp.w	#KD_MMBShift,d5			; MMB-Shift
		beq	MMBShiftKey

		cmp.w	#KD_GermanDays,d5		; German days
		beq	GermanDaysKey

		cmp.w	#KD_PDate,d5			; Points within date
		beq	PDateKey

		cmp.w	#KD_NoClick,d5			; NoClick ?
		beq	NoClickKey

		cmp.w	#KD_ShowMouse,d5		; Show mouseposition ?
		beq	ShowMouseKey

NoSetVKey	rts



**********************************************************************
*                       Handle the Misc window                       *
**********************************************************************
HandleMiscWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseMiscWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoMiscMove
		move.l	MiscHandle(a4),a0
		lea	MiscWinLeft(a4),a1
		bra	StoreWinPos

NoMiscMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released ?
		bne	NoMiscGadUp

		cmp.w	#GD_KeyClick,d7			; KeyClick ?
		bne.s	NoKeyClickGad
KeyClickKey	bchg	#0,KeyClick(a4)
		move.b	KeyClick(a4),d0
		move.l	#GD_KeyClick,d1
		bra	SetMiscBox

NoKeyClickGad	cmp.w	#GD_ClickVol,d7			; Change click vol ?
		bne.s	NoClickVolGad
		ext.l	d5
		move.l	d5,ClickVol(a4)
		rts

NoClickVolGad	cmp.w	#GD_ESCClose,d7			; Escclose ?
		bne.s	NoESCCloseGad
ESCCloseKey	bchg	#0,ESCClose(a4)
		move.b	ESCClose(a4),d0
		move.l	#GD_ESCClose,d1
		bra	SetMiscBox

NoESCCloseGad	cmp.w	#GD_ESCQual,d7			; New Qualifier ?
		bne.s	NoESCQualGad
GetESCQual	move.w	#RESCKEY,NewCode(a4)
		move.w	ESCQual(a4),NewQual(a4)
		move.b	#1,KeepCode(a4)			; Code may not be changed
		lea	ESCQualTxt,a0
		jsr	GetQualifier
		tst.w	NewCode(a4)
		beq.s	.End
		move.w	NewQual(a4),ESCQual(a4)
		bra	SetMiscGads
.End		rts

NoESCQualGad	cmp.w	#GD_UserShell,d7		; New UserShell ?
		bne.s	NoUserShellGad
		lea	SystemComm(a4),a0
		move.l	#GD_UserShell,d0
		lea	MiscGads(a4),a0
		jsr	GetGadgetPtr
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	SystemComm(a4),a1
		jmp	StrCpy

NoUserShellGad	cmp.w	#GD_ExpWindows,d7		; Exploding windows ?
		bne.s	NoExpWindowsGad
ExpWindowsKey	bchg	#0,ExpWindows(a4)
		bra	SetWindowsGads

NoExpWindowsGad	cmp.w	#GD_MouseCtr,d7			; Explode to mouse ?
		bne.s	NoMouseCtrGad
MouseCtrKey	bchg	#0,MouseCenter(a4)
		move.b	MouseCenter(a4),d0
		move.l	#GD_MouseCtr,d1
		bra	SetMiscBox

NoMouseCtrGad	cmp.w	#GD_ExpFrames,d7		; Explode frames ?
		bne.s	NoExpFramesGad
		ext.l	d5
		move.l	d5,ExpFrames(a4)
		rts

NoExpFramesGad	cmp.w	#GD_ImpFrames,d7		; Implode frames ?
		bne.s	NoImpFramesGad
		ext.l	d5
		move.l	d5,ImpFrames(a4)
		rts

NoImpFramesGad	cmp.w	#GD_SizeFrames,d7		; Size frames ?
		bne.s	NoSizeFramesGad
		ext.l	d5
		move.l	d5,SizeFrames(a4)

NoSizeFramesGad	cmp.w	#GD_FullDrag,d7			; Full dragging ?
		bne.s	NoFullDragGad
FullDragKey	bchg	#0,FullDrag(a4)
		move.b	FullDrag(a4),d0
		move.l	#GD_FullDrag,d1
		bra	SetMiscBox

NoFullDragGad	cmp.w	#GD_DragQual,d7			; New Dragging qualifier ?
		bne.s	NoDragQualGad
GetDragQual	move.w	#IECODE_LBUTTON,NewCode(a4)
		move.w	FullDragQual(a4),NewQual(a4)
		move.b	#1,KeepCode(a4)			; Code may not be changed
		lea	DragQualTxt,a0
		jsr	GetQualifier
		tst.w	NewCode(a4)
		beq.s	.End
		move.w	NewQual(a4),FullDragQual(a4)
		bra	SetMiscGads
.End		rts
NoDragQualGad	rts

NoMiscGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoMiscVKey

		cmp.w	#ESCKEY,d5
		beq	CloseMiscWin

		cmp.w	#KD_KeyClick,d5			; KeyClick ?
		beq	KeyClickKey

		cmp.w	#KD_ClickVol,d5			; Change click volume ?
		bne.s	NoClickVolKey
		move.l	ClickVol(a4),d0
		and.w	#(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),d4
		beq.s	.Up
		subq.l	#1,d0
		bne.s	.GoOn
		move.l	#64,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#65,d0
		bne.s	.GoOn
		moveq	#1,d0
.GoOn		move.l	d0,ClickVol(a4)
		move.l	d0,d1
		move.l	#GD_ClickVol,d0
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bsr	SetIntegerGad
		rts

NoClickVolKey	cmp.w	#KD_ESCClose,d5			; ESC close ?
		beq	ESCCloseKey

		cmp.w	#KD_ESCQual,d5			; ESC Qualifier ?
		bne.s	NoESCQualKey
		move.l	#GD_ESCQual,d0
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a5
		bsr	ButtonCheck
		bra	GetESCQual

NoESCQualKey	cmp.w	#KD_UserShell,d5		; Enter new UserShell ?
		bne.s	NoUserShellKey
		move.l	#GD_UserShell,d0
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bra	ActStringGad

NoUserShellKey	cmp.w	#KD_ExpWindows,d5		; Exploding windows ?
		beq	ExpWindowsKey

		cmp.w	#KD_MouseCtr,d5			; From to mouse ?
		beq	MouseCtrKey

		cmp.w	#KD_ExpFrames,d5		; Explode frames ?
		bne.s	NoExpFramesKey
		lea	ExpFrames(a4),a0
		move.l	#GD_ExpFrames,d7
SetFrameGad	tst.b	ExpWindows(a4)
		beq.s	.End
		move.l	(a0),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		cmp.l	#9,d0
		bne.s	.NoRestart
		move.l	#MAXFRAMES,d0
		bra.s	.NoRestart
.Up		addq.l	#1,d0				; Increase value
		cmp.l	#MAXFRAMES,d0			; Over 48 ?
		ble.s	.NoRestart
		moveq	#MINFRAMES,d0			; Restart from scratch
.NoRestart	move.l	d0,(a0)				; Remake slider gad
		move.l	d0,d1
		move.l	d7,d0
		bsr	SetMiscSlids
.End		rts

NoExpFramesKey	cmp.w	#KD_ImpFrames,d5		; Changed frames for Implode ?
		bne.s	NoImpFramesKey
		lea	ImpFrames(a4),a0
		move.l	#GD_ImpFrames,d7
		bra	SetFrameGad

NoImpFramesKey	cmp.w	#KD_SizeFrames,d5		; Changes frames for sizing ?
		bne.s	NoSizeFramesKey
		lea	SizeFrames(a4),a0
		move.l	#GD_SizeFrames,d7
		bra	SetFrameGad

NoSizeFramesKey	cmp.w	#KD_FullDrag,d5			; Full dragging ?
		beq	FullDragKey

		cmp.w	#KD_DragQual,d5			; New drag qualifier ?
		bne.s	NoMiscVKey
		move.l	#GD_DragQual,d0
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a5
		bsr	ButtonCheck
		bra	GetDragQual

NoMiscVKey	rts



**********************************************************************
*                      Handle the alarm window                       *
**********************************************************************
HandleAlarmWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseAlarmWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoAlarmMove
		move.l	AlarmHandle(a4),a0
		lea	AlarmWinLeft(a4),a1
		bra	StoreWinPos

NoAlarmMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released ?
		bne	NoAlarmGadUp

		cmp.w	#GD_AlarmOn,d7			; Alarm ?
		bne.s	NoAlarmOnGad
AlarmOnKey	bchg	#0,DoAlarm(a4)
		move.b	DoAlarm(a4),d0
		move.l	#GD_AlarmOn,d1
		bra	SetAlarmBox

NoAlarmOnGad	cmp.w	#GD_AllHours,d7			; Alarm every hour ?
		bne.s	NoAllHoursGad
AllHoursKey	bchg	#0,EveryHour(a4)
		move.b	EveryHour(a4),d0
		move.l	#GD_AllHours,d1
		bra	SetAlarmBox

NoAllHoursGad	cmp.w	#GD_ShowAlarm,d7		; Display requester ?
		bne.s	NoShowAlarmGad
ShowAlarmKey	bchg	#0,DoShowAlarm(a4)
		move.b	DoShowAlarm(a4),d0
		move.l	#GD_ShowAlarm,d1
		bra	SetAlarmBox

NoShowAlarmGad	cmp.w	#GD_AlarmTime,d7		; New alarm time ?
		bne.s	NoAlarmTimeGad
		ext.l	d5
		move.l	d5,AlarmTime(a4)
		rts

NoAlarmTimeGad	cmp.w	#GD_AlSoundType,d7		; New sound type ?
		bne.s	NoAlSTypeGad
		move.b	d5,AlarmSample(a4)
SetSampleGad	move.l	#GD_AlarmSample,d0
		moveq	#0,d1
		move.b	AlarmSample(a4),d1
		bchg	#0,d1
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bsr	GhostGadget
		tst.b	HadASample(a4)
		beq.s	.OnlyRemove
		jsr	RemoveAlarmSmp
		jmp	InitAlarmSmp
.OnlyRemove	jmp	RemoveAlarmSmp

NoAlSTypeGad	cmp.w	#GD_AlarmSample,d7		; Load new Sample ?
		bne.s	NoAlSampleGad
GetNewSample	pea	SetTextGad
		clr.l	-(sp)
		pea	AlarmGads+ZeroPage
		move.w	#GD_SampleName,-(sp)
		pea	AlSampleName+ZeroPage
		pea	AlSampLoadHead
		move.l	AlarmHandle(a4),-(sp)
		bsr	GetFileName
		lea	26(sp),sp
		tst.l	d0
		beq.s	.End
		bsr	RemoveAlarmSmp
		bsr	InitAlarmSmp
.End		rts
NoAlSampleGad	rts

NoAlarmGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoAlarmVKey

		cmp.w	#ESCKEY,d5			; Close window
		beq	CloseAlarmWin

		cmp.w	#KD_AlarmOn,d5			; Alarm ?
		beq	AlarmOnKey

		cmp.w	#KD_AllHours,d5			; every hour ?
		beq	AllHoursKey

		cmp.w	#KD_ShowAlarm,d5		; show requester ?
		beq	ShowAlarmKey

		cmp.w	#KD_AlarmTime,d5		; change alarm time ?
		bne.s	NoAlarmTimeKey
		move.l	AlarmTime(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bge.s	.GoOn
		move.l	#(24*60)-1,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#(24*60),d0
		bne.s	.GoOn
		moveq	#0,d0
.GoOn		move.l	d0,AlarmTime(a4)
		move.l	d0,d1
		move.l	#GD_AlarmTime,d0
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bsr	SetSliderGad
		rts

NoAlarmTimeKey	cmp.w	#KD_AlSoundType,d5		; New sound type ?
		bne.s	NoAlSTypeKey
		bchg	#0,AlarmSample(a4)
		move.l	#GD_AlSoundType,d0
		moveq	#0,d1
		move.b	AlarmSample(a4),d1
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bsr	SetCycleGad
		bra	SetSampleGad

NoAlSTypeKey	cmp.w	#KD_AlarmSample,d5		; New sample name ?
		bne.s	NoAlarmVKey
		move.l	#GD_AlarmSample,d0
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a5
		bsr	ButtonCheck
		bra	GetNewSample
NoAlarmVKey	rts



**********************************************************************
*                       Handle the cyle window                       *
**********************************************************************
HandleCycleWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseCycleWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoCycleMove
		move.l	CycleHandle(a4),a0
		lea	CycleWinLeft(a4),a1
		bra	StoreWinPos

NoCycleMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget used ?
		bne	NoCycleGadUp

		cmp.w	#GD_CycleOn,d7			; Cycling ?
		bne.s	NoCycleOnGad
CycleOnKey	bchg	#0,CycleWin(a4)
		move.b	CycleWin(a4),d0
		move.l	#GD_CycleOn,d1
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a1
		bra	SetCheckBox

NoCycleOnGad	cmp.w	#GD_FrontClick,d7		; New Frontclick ?
		bne.s	NoFrontClickGad
		move.w	d5,FrontClicks(a4)
		rts

NoFrontClickGad	cmp.w	#GD_MiddleClick,d7		; middle click ?
		bne.s	NoMidClickGad
		move.w	d5,MiddleClicks(a4)
		rts

NoMidClickGad	cmp.w	#GD_BackClick,d7		; back click ?
		bne.s	NoBackClickGad
		move.w	d5,BackClicks(a4)
		rts

NoBackClickGad	cmp.w	#GD_FrontKey,d7			; Change front qualifier ?
		bne.s	NoFrontQual
GetFrontQual	move.w	FrontCode(a4),NewCode(a4)
		move.w	FrontQual(a4),NewQual(a4)
		clr.b	KeepCode(a4)			; Code may be changed too
		lea	FrontClickTxt,a0
		jsr	GetQualifier
		tst.w	NewCode(a4)
		beq.s	.End
		move.w	NewCode(a4),FrontCode(a4)
		move.w	NewQual(a4),FrontQual(a4)
		bsr	SetCycleQuals
.End		rts

NoFrontQual	cmp.w	#GD_BackKey,d7			; Change back qualifier ?
		bne.s	NoBackQual
GetBackQual	move.w	BackCode(a4),NewCode(a4)
		move.w	BackQual(a4),NewQual(a4)
		clr.b	KeepCode(a4)			; Code may be changed too
		lea	BackClickTxt,a0
		jsr	GetQualifier
		tst.w	NewCode(a4)
		beq.s	.End
		move.w	NewCode(a4),BackCode(a4)
		move.w	NewQual(a4),BackQual(a4)
		bsr	SetCycleQuals
.End		rts

NoBackQual	cmp.w	#GD_MiddleKey,d7		; Change middle qualifier ?
		bne.s	NoMiddleQual
GetMiddleQual	move.w	#IECODE_MBUTTON,NewCode(a4)
		move.w	MiddleQual(a4),NewQual(a4)
		move.b	#1,KeepCode(a4)			; Code should be kept
		lea	MiddleClickTxt,a0
		jsr	GetQualifier
		tst.w	NewCode(a4)
		beq.s	NoMiddleQual
		move.w	NewQual(a4),MiddleQual(a4)
		bsr	SetCycleQuals
NoMiddleQual	rts

NoCycleGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoCycleVKey

		cmp.w	#ESCKEY,d5			; Close window ?
		beq	CloseCycleWin

		cmp.w	#KD_CycleOn,d5			; Cycling ?
		beq	CycleOnKey

		cmp.w	#KD_FrontClick,d5		; New front clicks ?
		bne.s	NoFrontClickKey
		lea	FrontClicks(a4),a0
SetClickSlid	move.w	(a0),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.w	#1,d0
		bne.s	.NoRestart
		move.w	#MAXCLICKS,d0
		bra.s	.NoRestart
.Up		addq.w	#1,d0
		cmp.w	#MAXCLICKS,d0
		ble.s	.NoRestart
		moveq	#1,d0
.NoRestart	move.w	d0,(a0)
		bra	SetCycleSlids

NoFrontClickKey	cmp.w	#KD_MiddleClick,d5		; New middle click ?
		bne.s	NoMClickKey
		lea	MiddleClicks(a4),a0
		bra.s	SetClickSlid

NoMClickKey	cmp.w	#KD_BackClick,d5		; New Back click ?
		bne.s	NoBClickKey
		lea	BackClicks(a4),a0
		bra.s	SetClickSlid

NoBClickKey	cmp.w	#KD_FrontKey,d5			; New front qualifier ?
		bne.s	NoFrontKey
		move.l	#GD_FrontKey,d0
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a5
		bsr	ButtonCheck
		bra	GetFrontQual

NoFrontKey	cmp.w	#KD_MiddleKey,d5		; New middle qualifier ?
		bne.s	NoMiddleKey
		move.l	#GD_MiddleKey,d0
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a5
		bsr	ButtonCheck
		bra	GetMiddleQual

NoMiddleKey	cmp.w	#KD_BackKey,d5			; new back qualifier ?
		bne.s	NoCycleVKey
		move.l	#GD_BackKey,d0
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a5
		bsr	ButtonCheck
		bra	GetBackQual
NoCycleVKey	rts



**********************************************************************
*                     Handle the blanking window                     *
**********************************************************************
HandleBlankWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseBlankWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoBlankMove
		move.l	BlankHandle(a4),a0
		lea	BlankWinLeft(a4),a1
		bra	StoreWinPos

NoBlankMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne.s	NoBlankGadUp

		cmp.w	#GD_BlankMouse,d7		; Blank mouse ?
		bne.s	NoBlankMouseGad
BlankMouseKey	bchg	#0,MouseEver(a4)
		move.b	MouseEver(a4),d0
		move.l	#GD_BlankMouse,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bra	SetCheckBox

NoBlankMouseGad	cmp.w	#GD_ScrTime,d7			; New screen time ?
		bne.s	NoScrTimeGad
		ext.l	d5
		move.l	d5,ScreenTime(a4)
		move.b	#1,TimeReset(a4)
		rts

NoScrTimeGad	cmp.w	#GD_MouseTime,d7		; new mouse time ?
		bne.s	NoMouseTimeGad
		ext.l	d5
		move.l	d5,MouseTime(a4)
		move.b	#1,TimeReset(a4)
		rts

NoMouseTimeGad	cmp.w	#GD_BlankType,d7		; Change blank type ?
		bne.s	NoBlankTypeGad
		move.b	d5,ScreenDimm(a4)
BlankTypeKey	move.l	#GD_DimmFac,d0
		moveq	#0,d1
		move.b	ScreenDimm(a4),d1
		bchg	#0,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bra	GhostGadget

NoBlankTypeGad	cmp.w	#GD_DimmFac,d7			; New dimm factor ?
		bne.s	NoDimmFacGad
		ext.l	d5
		move.l	d5,DimmValue(a4)
NoDimmFacGad	rts

NoBlankGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoBlankVKey

		cmp.w	#ESCKEY,d5			; Close window ?
		beq	CloseBlankWin

		cmp.w	#KD_BlankMouse,d5		; Blank mouse ?
		beq	BlankMouseKey

		cmp.w	#KD_ScrTime,d5			; New screen time ?
		bne.s	NoScrTimeKey
		lea	ScreenTime(a4),a0
		move.l	#GD_ScrTime,d7
SetTimeOut	move.l	(a0),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bge.s	.GoOn
		move.l	#(30*60),d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#(30*60),d0
		ble.s	.GoOn
		moveq	#0,d0
.GoOn		move.l	d0,(a0)
		move.l	d0,d1
		move.l	d7,d0
		bsr	SetBlankSlid
		move.b	#1,TimeReset(a4)
		rts

NoScrTimeKey	cmp.w	#KD_MouseTime,d5		; New mouse time ?
		bne.s	NoMouseTimeKey
		lea	MouseTime(a4),a0
		move.l	#GD_MouseTime,d7
		bra	SetTimeOut

NoMouseTimeKey	cmp.w	#KD_BlankType,d5		; Blank type ?
		bne.s	NoBlankTypeKey
		bchg	#0,ScreenDimm(a4)
		move.l	#GD_BlankType,d0
		moveq	#0,d1
		move.b	ScreenDimm(a4),d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	SetCycleGad
		bra	BlankTypeKey

NoBlankTypeKey	cmp.w	#KD_DimmFac,d5			; New dimm factor ?
		bne.s	NoBlankVKey
		tst.b	ScreenDimm(a4)
		beq.s	NoBlankVKey
		move.l	DimmValue(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bne.s	.GoOn
		moveq	#48,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#48,d0
		ble.s	.GoOn
		moveq	#1,d0
.GoOn		move.l	d0,DimmValue(a4)
		move.l	d0,d1
		move.l	#GD_DimmFac,d0
		bsr	SetBlankSlid
NoBlankVKey	rts



**********************************************************************
*                        Handle colors window                        *
**********************************************************************
HandleColsWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseColsWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoColsMove
		move.l	ColsHandle(a4),a0
		lea	ColsWinLeft(a4),a1
		bra	StoreWinPos

NoColsMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne.s	NoColsGadUp

		cmp.w	#GD_TFrontPen,d7		; New text front pen ?
		bne.s	NoTFrontPenGad
		ext.l	d5
		move.l	d5,TextFrontPen(a4)
RemakeBCols	bsr	ClearTitleBar
		bra	SigTime

NoTFrontPenGad	cmp.w	#GD_TBackPen,d7			; New text back pen ?
		bne.s	NoTBackPenGad
		ext.l	d5
		move.l	d5,TextBackPen(a4)
		bra.s	RemakeBCols

NoTBackPenGad	cmp.w	#GD_GFrontPen,d7		; New gauge front pen ?
		bne.s	NoGFrontPenGad
		ext.l	d5
		move.l	d5,GaugeFrontPen(a4)
		bra.s	RemakeBCols

NoGFrontPenGad	cmp.w	#GD_GBackPen,d7			; New gauge back pen ?
		bne.s	NoGBackPenGad
		ext.l	d5
		move.l	d5,GaugeBackPen(a4)
		bra.s	RemakeBCols
NoGBackPenGad	rts

NoColsGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoColsVKey

		cmp.w	#ESCKEY,d5
		beq	CloseColsWin

		cmp.w	#KD_TFrontPen,d5		; new text front pen ?
		bne.s	NoTFrontPenKey
		lea	TextFrontPen(a4),a0
		move.l	#GD_TFrontPen,d7
SetDisplayPen	moveq	#1,d1
		move.l	ScrDepth+4,d2
		lsl.l	d2,d1
		subq.l	#1,d1
		move.l	(a0),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bge.s	.GoOn
		move.l	d1,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	d1,d0
		ble.s	.GoOn
		moveq	#0,d0
.GoOn		move.l	d0,(a0)
		move.l	d0,d1
		move.l	d7,d0
		bsr	SetColsPal
		bsr	ClearTitleBar
		bra	SigTime

NoTFrontPenKey	cmp.w	#KD_TBackPen,d5			; New text back pen ?
		bne.s	NoTextBackKey
		lea	TextBackPen(a4),a0
		move.l	#GD_TBackPen,d7
		bra.s	SetDisplayPen

NoTextBackKey	cmp.w	#KD_GFrontPen,d5		; New gauge front pen ?
		bne.s	NoGaugeFrontKey
		lea	GaugeFrontPen(a4),a0
		move.l	#GD_GFrontPen,d7
		bra.s	SetDisplayPen

NoGaugeFrontKey	cmp.w	#KD_GBackPen,d5			; New gauge back pen ?
		bne.s	NoColsVKey
		lea	GaugeBackPen(a4),a0
		move.l	#GD_GBackPen,d7
		bra.s	SetDisplayPen
NoColsVKey	rts



**********************************************************************
*                        Handle mouse window                         *
**********************************************************************
HandleMouseWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseMouseWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoMouseMove
		move.l	MouseHandle(a4),a0
		lea	MouseWinLeft(a4),a1
		bra	StoreWinPos

NoMouseMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoMouseGadUp

		cmp.w	#GD_WindowAct,d7		; Window activation
		bne.s	NoWindowActGad
WindowActKey	bchg	#0,DoActivate(a4)
		move.b	DoActivate(a4),d0
		move.l	#GD_WindowAct,d1
		bra	SetMouseBox

NoWindowActGad	cmp.w	#GD_SunMouse,d7			; Sun mouse ?
		bne.s	NoSunMouseGad
SunMouseKey	bchg	#0,SunMouse(a4)
		move.b	SunMouse(a4),d0
		move.l	#GD_SunMouse,d1
		bra	SetMouseBox

NoSunMouseGad	cmp.w	#GD_MouseAccel,d7		; Mouse acceleration ?
		bne.s	NoMouseAGad
MouseAKey	bchg	#0,MouseAccel(a4)
		move.b	MouseAccel(a4),d0
		move.l	#GD_MouseAccel,d1
		bsr	SetMouseBox
		bra	SetMouseGads

NoMouseAGad	cmp.w	#GD_Accelerate,d7		; Acceleration ?
		bne.s	NoAccelGad
		ext.l	d5
		move.l	d5,Accelerate(a4)
		rts

NoAccelGad	cmp.w	#GD_Threshold,d7		; Threshold ?
		bne.s	NoThreshGad
		ext.l	d5
		move.l	d5,ThresHold(a4)

NoThreshGad	cmp.w	#GD_HoldXQual,d7		; HoldX qualifier ?
		bne.s	NoHoldXGad
HoldXKey	clr.w	NewCode(a4)
		move.w	HoldXQual(a4),NewQual(a4)
		move.b	#1,KeepCode(a4)			; Code should be kept
		lea	HoldXQualTxt,a0
		jsr	GetQualifier
		tst.w	NewQual(a4)
		beq.s	.End
		move.w	NewQual(a4),HoldXQual(a4)
		bsr	SetMouseGads
.End		rts

NoHoldXGad	cmp.w	#GD_HoldYQual,d7		; New HoldY qualifier ?
		bne.s	NoHoldYGad
HoldYKey	clr.w	NewCode(a4)
		move.w	HoldYQual(a4),NewQual(a4)
		move.b	#1,KeepCode(a4)			; Code should be kept
		lea	HoldYQualTxt,a0
		jsr	GetQualifier
		tst.w	NewQual(a4)
		beq.s	NoHoldYGad
		move.w	NewQual(a4),HoldYQual(a4)
		bsr	SetMouseGads
NoHoldYGad	rts

NoMouseGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoMouseVKey

		cmp.w	#ESCKEY,d5
		beq	CloseMouseWin

		cmp.w	#KD_WindowAct,d5		; activation ?
		beq	WindowActKey

		cmp.w	#KD_SunMouse,d5			; Sun mouse ?
		beq	SunMouseKey

		cmp.w	#KD_MouseAccel,d5		; acceleration ?
		beq	MouseAKey

		cmp.w	#KD_Accelerate,d5		; new speed ?
		bne.s	NoAccelKey
		move.l	Accelerate(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		cmp.l	#MINACC,d0
		bge.s	.GoOn
		moveq	#MAXACC,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#MAXACC,d0
		ble.s	.GoOn
		move.l	#MINACC,d0
.GoOn		move.l	d0,Accelerate(a4)
		move.l	d0,d1
		move.l	#GD_Accelerate,d0
		lea	MouseGads(a4),a0
		move.l	MouseHandle(a4),a1
		bra	SetIntegerGad

NoAccelKey	cmp.w	#KD_Threshold,d5		; New threshold ?
		bne.s	NoThreshKey
		move.l	ThresHold(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		cmp.l	#MINTHRES,d0
		bge.s	.GoOn
		moveq	#MAXTHRES,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#MAXTHRES,d0
		ble.s	.GoOn
		move.l	#MINTHRES,d0
.GoOn		move.l	d0,ThresHold(a4)
		move.l	d0,d1
		move.l	#GD_Threshold,d0
		lea	MouseGads(a4),a0
		move.l	MouseHandle(a4),a1
		bra	SetIntegerGad

NoThreshKey	cmp.w	#KD_HoldXQual,d5		; New Hold X qualifier ?
		bne.s	NoHoldXKey
		move.l	#GD_HoldXQual,d0
		lea	MouseGads(a4),a0
		move.l	MouseHandle(a4),a5
		bsr	ButtonCheck
		bra	HoldXKey

NoHoldXKey	cmp.w	#KD_HoldYQual,d5		; New Hold Y qualifier ?
		bne.s	NoMouseVKey
		move.l	#GD_HoldYQual,d0
		lea	MouseGads(a4),a0
		move.l	MouseHandle(a4),a5
		bsr	ButtonCheck
		bra	HoldYKey
NoMouseVKey	rts


**********************************************************************
*                        Close HotKey window                         *
**********************************************************************
HandleHotKeyWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseHotKeyWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Move window ?
		bne.s	NoHotKeyMove
		move.l	HotKeyHandle(a4),a0
		lea	HotKeyWinLeft(a4),a1
		bra	StoreWinPos

NoHotKeyMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoHotKeyGadUp

		cmp.w	#GD_HotKeyList,d7		; New HotKey
		bne.s	NoHotKeyList
NextHotKey	ext.l	d5				; Get number of HotKey to change
		move.l	d5,HotKeyChange(a4)

		move.l	#GD_HotKeyDef,d0
		lea	HotKeyGads(a4),a0
		move.l	HotKeyHandle(a4),a1
		lea	HotKeyGadStat,a2		; Copy HotKey definition to
		lsl.l	#2,d5				; String-Gadget
		move.l	0(a2,d5),a2
		bsr	SetStringGad

		moveq	#GD_HotKeyDef,d0		; Activate Stringgadget
		moveq	#0,d1
		lea	HotKeyGads(a4),a0
		move.l	HotKeyHandle(a4),a1
		bra	GhostGadget

NoHotKeyList	cmp.w	#GD_HotKeyDef,d7		; Changed HotKey definition ?
		bne.s	NoHotKeyDefGad

		cmp.w	#HELPKEY,d5			; Help used to escape gadgets ?
		beq.s	NoHotKeyDefGad

		lea	HotKeyGadVars,a2		; Get Vars for HotKey
		move.l	HotKeyChange(a4),d0
		mulu	#12,d0
		move.l	0(a2,d0),a0
		move.l	4(a2,d0),a1
		move.l	8(a2,d0),a2
		move.l	a0,d0
		beq.s	.NoWindow
		move.l	(a0),a0
.NoWindow	move.l	(a2),a2
		lea	HotKeyGads(a4),a3		; Get new definition for HotKey
		move.l	4(a3),a3
		move.l	gg_SpecialInfo(a3),a3
		move.l	si_Buffer(a3),a3
		lea	HotKeyGadStat,a5		; Try to remake HotKey
		move.l	HotKeyChange(a4),d0
		lsl.l	#2,d0
		move.l	0(a5,d0),a5
		jsr	RemakeHotKey
NoHotKeyDefGad	rts

NoHotKeyGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoHotKeyVKey

		cmp.w	#ESCKEY,d5
		beq	CloseHotKeyWin

		cmp.w	#KD_HotKeyList,d5		; Scroll through listview ?
		bne.s	NoHotKeyListKey
		move.l	HotKeyChange(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		cmp.l	#-1,d0
		beq.s	NoHotKeyVKey
		tst.l	d0
		beq.s	.GoOn
		subq.l	#1,d0
		bra.s	.GoOn
.Up		cmp.l	#HOTKEYNUM-1,d0
		bge.s	.GoOn
		addq.l	#1,d0
.GoOn		move.l	d0,HotKeyChange(a4)
		move.l	HotKeyVisTop(a4),d1
		move.l	d1,d2
		addq.l	#8,d2
		cmp.l	d1,d0
		blt.s	.Over
		cmp.l	d2,d0
		bgt.s	.Under
		bra.s	.GotTop
.Over		subq.l	#1,d1
		bra.s	.GotTop
.Under		addq.l	#1,d1
.GotTop		move.l	d1,HotKeyVisTop(a4)
		move.l	d1,d2
		move.l	d0,d1
		move.l	#GD_HotKeyList,d0
		lea	HotKeyGads(a4),a0
		move.l	HotKeyHandle(a4),a1
		bsr	SetListViewGad

		move.l	HotKeyChange(a4),d5
		bra	NextHotKey

NoHotKeyListKey	cmp.w	#KD_HotKeyDef,d5		; Activate String gadget ?
		bne.s	NoHotKeyVKey
		move.l	#GD_HotKeyDef,d0
		lea	HotKeyGads(a4),a0
		move.l	HotKeyHandle(a4),a1
		bra	ActStringGad

NoHotKeyVKey	rts




**********************************************************************
*                        Handle FKeys window                         *
**********************************************************************
HandleFKeyWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseFKeyWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoFKeyMove
		move.l	FKeyHandle(a4),a0
		lea	FKeyWinLeft(a4),a1
		bra	StoreWinPos

NoFKeyMove	cmp.l	#IDCMP_ACTIVEWINDOW,d6		; Window activated ?
		bne.s	NoFKeyAct
		move.l	#GD_F1,d0
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
		bra	ActStringGad

NoFKeyAct	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoFKeyGadUp

		cmp.w	#GD_F10,d7			; New F-Key ?
		bgt.s	NoNewFKey
		lea	FKeysNew(a4),a1
		move.l	FKeyQual(a4),d0
		mulu	#(MAXFKEYWIDTH+2)*10,d0
		lea	0(a1,d0),a1
		sub.w	#GD_F1,d7
		mulu	#(MAXFKEYWIDTH+2),d7
		lea	0(a1,d7.w),a1
		move.l	gg_SpecialInfo(a2),a0
		move.l	si_Buffer(a0),a0
		jmp	StrCpy

NoNewFKey	cmp.w	#GD_FKeyQual,d7			; Changed qualifier ?
		bne.s	NoNewFQual
		ext.l	d5
		move.l	d5,FKeyQual(a4)
NewFKeyQual	jmp	SetFKeyGads

NoNewFQual	cmp.w	#GD_FKeyAct,d7			; Activate stuff ?
		bne.s	NoFKeyOnGad
FKeyOnKey	bchg	#0,FKeysOn(a4)
		move.b	FKeysOn(a4),d0
		move.l	#GD_FKeyAct,d1
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
		bra	SetCheckBox

NoFKeyOnGad	cmp.w	#GD_FKeyOk,d7			; Clicked OK ?
		bne.s	NoFKeyOkGad

IsFKeyOkKey	lea	FKeysNew(a4),a0
		lea	FKeys(a4),a1
		move.w	#((MAXFKEYWIDTH+2)*10*4)-1,d7
.Loop		move.b	(a0)+,(a1)+
		dbf	d7,.Loop
		bra	CloseFKeyWin

NoFKeyOkGad	cmp.w	#GD_FKeyCancel,d7		; Clicked Cancel ?
		beq	CloseFKeyWin

NoFKeyGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoFKeyVKey

		cmp.w	#ESCKEY,d5
		beq.s	FKeyCancel

		cmp.w	#KD_F10,d5
		blt.s	NoFKeyGads
		cmp.w	#KD_F9,d5			; Activate one of the gadgets
		bgt.s	NoFKeyGads
		cmp.w	#KD_F10,d5
		bne.s	.IsNormal
		move.l	#GD_F10,d0
		bra.s	.GoOn
.IsNormal	sub.w	#(KD_F1),d5
		move.w	d5,d0
		and.w	#$0000ffff,d0
.GoOn		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
		bra	ActStringGad

NoFKeyGads	cmp.w	#KD_FKeyOk,d5			; Ok pressed
		bne.s	NoFKeyOkKey
		move.l	#GD_FKeyOk,d0
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a5
		bsr	ButtonCheck
		bra	IsFKeyOkKey

NoFKeyOkKey	cmp.w	#KD_FKeyCancel,d5		; Cancel pressed
		bne.s	NoFKeyCancelKey
FKeyCancel	move.l	#GD_FKeyCancel,d0
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a5
		bsr	ButtonCheck
		bra	CloseFKeyWin

NoFKeyCancelKey	cmp.w	#KD_FKeyQual,d5			; New qualifier ?
		bne.s	NoFKeyQualKey
		move.l	FKeyQual(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bge.s	.GoOn
		moveq	#3,d0
		bra.s	.GoOn
.Up		addq.l	#1,d0
		cmp.l	#4,d0
		blt.s	.GoOn
		moveq	#0,d0
.GoOn		move.l	d0,FKeyQual(a4)
		bra	NewFKeyQual

NoFKeyQualKey	cmp.w	#KD_FKeyAct,d5
		beq	FKeyOnKey

NoFKeyVKey	rts


**********************************************************************
*                    Handle the formatter window                     *
**********************************************************************
HandleFormWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseFormWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoFormMove
		move.l	FormHandle(a4),a0
		lea	FormWinLeft(a4),a1
		bra	StoreWinPos

NoFormMove	cmp.l	#IDCMP_ACTIVEWINDOW,d6		; Window activated ?
		beq	LabelKey

		cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoFormGadUp

		cmp.w	#GD_Label,d7			; Changed Label ?
		bne.s	NoLabelGad
		move.l	d7,d0				; Copy new string
		lea	FormGads(a4),a0
		jsr	GetGadgetPtr
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		lea	DefLabel,a1
		jmp	StrCpy

NoLabelGad	cmp.w	#GD_Trashcan,d7			; Trashcan ?
		bne.s	NoTrashGad
TrashcanKey	bchg	#0,MakeIcons(a4)
		move.b	MakeIcons(a4),d0
		move.l	#GD_Trashcan,d1
		bra	SetFormBox

NoTrashGad	cmp.w	#GD_Quick,d7			; Quick format ?
		bne.s	NoQuickGad
QuickKey	bchg	#0,QuickFormat(a4)
		move.b	QuickFormat(a4),d0
		move.l	#GD_Quick,d1
		bra	SetFormBox

NoQuickGad	cmp.w	#GD_FFS,d7			; FFS format ?
		bne.s	NoFFSGad
FFSKey		bchg	#0,FFSDrive(a4)
		move.b	FFSDrive(a4),d0
		move.l	#GD_FFS,d1
		bra	SetFormBox

NoFFSGad	cmp.w	#GD_NoVerify,d7			; No verify ?
		bne.s	NoVerifyGad
VerifyKey	bchg	#0,NoVerify(a4)
		move.b	NoVerify(a4),d0
		move.l	#GD_NoVerify,d1
		bra	SetFormBox

NoVerifyGad	cmp.w	#GD_Install,d7			; Install disk ?
		bne.s	NoInstallGad
InstallKey	bchg	#0,Install(a4)
		move.b	Install(a4),d0
		move.l	#GD_Install,d1
		bra	SetFormBox

NoInstallGad	cmp.w	#GD_Eject,d7			; Eject disk ?
		bne.s	NoEjectGad
EjectKey	bchg	#0,EjectDrive(a4)
		move.b	EjectDrive(a4),d0
		move.l	#GD_Eject,d1
		bra	SetFormBox

NoEjectGad	cmp.w	#GD_WatchDisks,d7		; Watch disks ?
		bne.s	NoWatchGad
WatchKey	bchg	#0,WatchDisks(a4)
		move.b	WatchDisks(a4),d0
		move.l	#GD_WatchDisks,d1
		bra	SetFormBox

NoWatchGad	cmp.w	#GD_FormOk,d7			; Format ?
		beq.s	StartFormat

		cmp.w	#GD_FormCancel,d7		; Cancel ?
		beq	CloseFormWin

		cmp.w	#GD_Drive,d7			; New drive selected ?
		bne.s	NoDriveGad
		move.w	d5,FormatDrive(a4)
SetDriveGad	move.l	#GD_Drive,d0
		move.w	FormatDrive(a4),d1
		ext.l	d1
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		bsr	SetCycleGad
NoDriveGad	rts
StartFormat	jsr	GoGoGoFormat			; Start format
		bra	CloseFormWin

NoFormGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoFormVKey

		cmp.w	#ESCKEY,d5
		beq	FormCancelKey

		cmp.w	#KD_Trashcan,d5			; Trashcan
		beq	TrashcanKey

		cmp.w	#KD_Quick,d5			; Quick
		beq	QuickKey

		cmp.w	#KD_FFS,d5			; FFS
		beq	FFSKey

		cmp.w	#KD_NoVerify,d5			; Verify
		beq	VerifyKey

		cmp.w	#KD_Install,d5			; Install
		beq	InstallKey

		cmp.w	#KD_Eject,d5			; Eject
		beq	EjectKey

		cmp.w	#KD_WatchDisks,d5		; Watch disks ?
		beq	WatchKey

		cmp.w	#KD_Label,d5			; Enter label ?
		bne.s	NoLabelKey
LabelKey	move.l	#GD_Label,d0
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		bra	ActStringGad

NoLabelKey	cmp.w	#KD_Drive,d5			; Next drive ?
		bne.s	NoDriveKey
		move.w	FormatDrive(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		addq.w	#1,d0
		cmp.w	NumDrives(a4),d0
		blt.s	.GoOn
		moveq	#0,d0
		bra.s	.GoOn
.Up		subq.w	#1,d0
		bge.s	.GoOn
		move.w	NumDrives(a4),d0
		subq.w	#1,d0
.GoOn		move.w	d0,FormatDrive(a4)
		bra	SetDriveGad

NoDriveKey	cmp.w	#KD_FormOk,d5			; Start ?
		bne.s	NoFormOkKey
		move.l	#GD_FormOk,d0
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a5
		bsr	ButtonCheck
		bra	StartFormat

NoFormOkKey	cmp.w	#KD_FormCancel,d5		; Cancel ?
		bne.s	NoFormVKey
FormCancelKey	move.l	#GD_FormCancel,d0
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a5
		bsr	ButtonCheck
		bra	CloseFormWin
NoFormVKey	rts



**********************************************************************
*                   Handle the Preferences window                    *
**********************************************************************
HandlePrefsWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	ClosePrefsWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoPrefsMove
		move.l	PrefsHandle(a4),a0
		lea	PrefsWinLeft(a4),a1
		bra	StoreWinPos

NoPrefsMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoPrefsGadUp

		cmp.w	#GD_Normal1,d7			; One of the cost gadgets ?
		blt.s	NoCostTimeGad
		cmp.w	#GD_Cheap3,d7
		bgt.s	NoCostTimeGad

		ext.l	d7				; Calc offset to time
		move.l	d7,d6				; Copy number of gadget
		move.l	d7,d0
		lsr.w	#1,d0				; D0 = Offset to timezone
		move.l	d0,d1
		add.l	d1,d1
		sub.l	d1,d7				; D7 = Offset to normal/cheap

		lea	CostUnit1(a4),a0
		lsl.l	#3,d0
		lsl.l	#2,d7
		lea	0(a0,d0),a0
		move.l	0(a0,d7),d1			; Get old cost
		move.l	gg_SpecialInfo(a2),a3
		move.l	si_LongInt(a3),d0		; Get new one
		tst.l	d0				; Less zero or even equal ?
		ble.s	.Error
		move.l	d0,0(a0,d7)			; Store new time
		bra.s	.End
.Error		move.l	d6,d0
		bsr	SetPrefsInteger
.End		move.b	#1,DoRemakeCosts(a4)
		bra	RemakeCosts

NoCostTimeGad	cmp.w	#GD_CostUnit,d7			; New cost/unit entered ?
		bne.s	NoCostGad

		move.l	gg_SpecialInfo(a2),a3
		move.l	si_LongInt(a3),d0		; Get new value
		tst.l	d0				; <= 0 ?
		ble.s	.Error
		move.l	d0,CostUnit(a4)			; Store new value
		bra.s	.End
.Error		move.l	#GD_CostUnit,d0
		move.l	CostUnit(a4),d1
		bsr	SetPrefsInteger
.End		move.b	#1,DoRemakeCosts(a4)
		bra	RemakeCosts

NoCostGad	cmp.w	#GD_ClearLog,d7			; Clear log file ?
		bne.s	NoClearGad
DoClearLog	lea	LogFileName(a4),a0
		move.l	a0,d1
		RELLIB	DeleteFile,_DOSBase
		rts

NoClearGad	cmp.w	#GD_PopUpBill,d7		; Enable/Disable PopUp fo BillWin
		beq	BillPopKey

		cmp.w	#GD_OpenBill,d7			; New public screen chosen ?
		bne.s	NoWinScrGad
		move.l	gg_SpecialInfo(a2),a0
		move.l	si_Buffer(a0),a0
		lea	PubScreenName(a4),a1
		move.l	#256,d7
		jmp	StrNCpy

NoWinScrGad	cmp.w	#GD_SaveLog,d7			; Select a file via ASL-Request ?
		bne.s	NoSaveToGad
SaveLogGad	pea	SetStringGad
		clr.l	-(sp)
		pea	PrefsGads(a4)
		move.w	#GD_LogName,-(sp)
		pea	LogFileName+ZeroPage
		pea	LogFileHeader
		move.l	PrefsHandle(a4),-(sp)
		bsr	GetFileName
		lea	26(sp),sp
		rts

NoSaveToGad	cmp.w	#GD_LogName,d7			; Entered new logfilename ?
		bne	NoLogFileGad

		link	a3,#-FILEBUFFSIZE		; Get Buffer for FileName

		move.l	gg_SpecialInfo(a2),a5		; Check if can be saved to dir
		move.l	si_Buffer(a5),a0
		lea	-FILEBUFFSIZE(a3),a1
		bsr	StrCpy				; copy new filename
		lea	-FILEBUFFSIZE(a3),a0
		bsr	StrLen
		subq.l	#1,d0
.CheckLoop	cmp.b	#':',(a0)			; Dir entered ?
		beq.s	.DoDirCheck
		cmp.b	#'/',(a0)
		beq.s	.DoDirCheck
		addq.l	#1,a0
		dbf	d0,.CheckLoop
		bra.s	.OnlyFile
.DoDirCheck	move.l	a0,a1				; Yep...Extract dir name
.FindDir	tst.b	(a0)
		beq.s	.NameEnd
		cmp.b	#'/',(a0)
		bne.s	.Loop
		move.l	a0,a1
.Loop		addq.l	#1,a0
		bra.s	.FindDir
.NameEnd	clr.b	1(a1)			; Dir name extracted
		lea	-FILEBUFFSIZE(a3),a0		; try to lock it
		move.l	a0,d1
		move.l	#ACCESS_READ,d2
		RELLIB	Lock,_DOSBase
		tst.l	d0
		bne.s	.Ok
		DOLIB	IoErr				; Error
		move.l	d0,ErrorNum(a4)
		jsr	DisplayError
		bra.s	.Error
.Ok		move.l	d0,d1				; No Error
		DOLIB	UnLock
.OnlyFile	move.l	si_Buffer(a5),a0		; Copy new filename
		lea	LogFileName(a4),a1
		bsr	StrCpy
.Error		move.l	#GD_LogName,d0
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		lea	LogFileName(a4),a2
		bsr	SetStringGad
		unlk	a3				; Clear buffer
		rts

NoLogFileGad	cmp.w	#GD_TotalSum,d7			; Display total sum ?
		bne.s	NoSumGad
		bra	DisplayTotalSum

NoSumGad	cmp.w	#GD_StartCheap,d7		; New Starttime ?
		bne.s	NoCheapStartGad
		ext.l	d5
		move.l	d5,CheapStart(a4)
		bra	RemakeCosts

NoCheapStartGad	cmp.w	#GD_StartNorm,d7		; New Endtime ?
		bne.s	NoStartNormGad
		ext.l	d5
		move.l	d5,CheapStop(a4)
		bra	RemakeCosts

NoStartNormGad	cmp.w	#GD_Saturday,d7			; Day changed ?
		blt.s	.End
		cmp.w	#GD_Friday,d7
		bgt.s	.End
		sub.w	#GD_Saturday,d7
		add.w	#'1',d7
		move.w	d7,d5
		bra	PrefsDayKey
.End		rts

NoPrefsGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoPrefsVKey

		cmp.w	#ESCKEY,d5			; Hide window ?
		beq	ClosePrefsWin

		cmp.w	#KD_Normal1,d5			; Activate first integer gad ?
		bne.s	NoNormal1Key
		move.l	#GD_Normal1,d0
Normal1Key	lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		bra	ActStringGad

NoNormal1Key	cmp.w	#KD_Normal2,d5			; Activate normal 2 gad ?
		bne.s	NoNormal2Key
		move.l	#GD_Normal2,d0
		bra.s	Normal1Key

NoNormal2Key	cmp.w	#KD_Normal3,d5			; Activate normal 3 gad ?
		bne.s	NoNormal3Key
		move.l	#GD_Normal3,d0
		bra.s	Normal1Key

NoNormal3Key	cmp.w	#KD_Cheap1,d5			; Activate cheap 1 gad ?
		bne.s	NoCheap1Key
		move.l	#GD_Cheap1,d0
		bra.s	Normal1Key

NoCheap1Key	cmp.w	#KD_Cheap2,d5			; Activate cheap 2 gad ?
		bne.s	NoCheap2Key
		move.l	#GD_Cheap2,d0
		bra.s	Normal1Key

NoCheap2Key	cmp.w	#KD_Cheap3,d5			; Activate cheap 3gad ?
		bne.s	NoCheap3Key
		move.l	#GD_Cheap3,d0
		bra.s	Normal1Key

NoCheap3Key	cmp.w	#KD_CostUnit,d5			; Activate cost/unit gad ?
		bne.s	NoCostUnitKey
		move.l	#GD_CostUnit,d0
		bra.s	Normal1Key

NoCostUnitKey	cmp.w	#KD_OpenBill,d5			; Change public screen name ?
		bne.s	NoWinScrKey
		move.l	#GD_OpenBill,d0			; Activate Stringgadget
		bra.s	Normal1Key

NoWinScrKey	cmp.w	#KD_SaveLog,d5			; Select new log filename ?
		bne.s	NoSaveToKey
		move.l	#GD_SaveLog,d0
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a5
		bsr	ButtonCheck
		bra	SaveLogGad

NoSaveToKey	cmp.w	#KD_TotalSum,d5			; Display total costs ?
		bne.s	NoTotalSumGad
		move.l	#GD_TotalSum,d0
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a5
		bsr	ButtonCheck
		bra	DisplayTotalSum

NoTotalSumGad	cmp.w	#KD_ClearLog,d5			; Clear log file ?
		bne.s	NoClearKey
		move.l	#GD_ClearLog,d0
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a5
		bsr	ButtonCheck
		bra	DoClearLog

NoClearKey	cmp.w	#KD_PopUpBill,d5		; Enable/Disable PopUp of BillWin
		bne.s	NoPrefsBillKey
BillPopKey	bchg	#0,BillPopUp(a4)
		move.b	BillPopUp(a4),d0
		move.l	#GD_PopUpBill,d1
		jmp	SetPrefsBox

NoPrefsBillKey	cmp.w	#KD_StartCheap,d5		; Change start time ?
		bne.s	NoCheapStartKey
		lea	CheapStart(a4),a0
		move.l	#GD_StartCheap,d7
SetTimeGad	move.l	(a0),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d0
		bge.s	.NoRestart
		move.l	#143,d0
		bra.s	.NoRestart
.Up		addq.l	#1,d0
		cmp.l	#144,d0
		blt.s	.NoRestart
		moveq	#0,d0
.NoRestart	move.l	d0,(a0)
		move.l	d0,d1
		move.l	d7,d0
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		bsr	SetIntegerGad
		bra	RemakeCosts

NoCheapStartKey	cmp.w	#KD_StartNorm,d5		; New Endtime ?
		bne.s	NoStartNormKey
		lea	CheapStop(a4),a0
		move.l	#GD_StartNorm,d7
		bra	SetTimeGad

NoStartNormKey	cmp.w	#KD_LogName,d5			; Activate Logname ?
		bne.s	NoLogNameKey
		move.l	#GD_LogName,d0
		bra	Normal1Key

NoLogNameKey	cmp.w	#KD_Friday,d5
		bne.s	.GoOn
		move.w	#':',d5
.GoOn		cmp.w	#KD_Saturday,d5			; Any day changed ?
		blt.s	NoPrefsVKey
		cmp.w	#':',d5
		bgt.s	NoPrefsVKey
PrefsDayKey	sub.w	#KD_Saturday,d5
		lea	Saturday(a4),a0
		bchg	#0,0(a0,d5)
		move.b	0(a0,d5),d0
		move.b	d0,d7
		add.w	#GD_Saturday,d5
		move.w	d5,d1
		jsr	SetPrefsBox
		bra	RemakeCosts
NoPrefsVKey	rts



**********************************************************************
*                   Handle the Preferences window                    *
**********************************************************************
HandleLockWin	cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close window ?
		beq	CloseLockWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoLockMove
		move.l	LockHandle(a4),a0
		lea	LockWinLeft(a4),a1
		bra	StoreWinPos

NoLockMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released ?
		bne	NoLockGadUp

		cmp.w	#GD_WindowList,d7		; Selected an entry ?
		bne.s	NoWindowListGad
		move.w	d5,SelWindow(a4)
		move.l	#GD_WindowName,d0
		moveq	#0,d1
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		bsr	GhostGadget
		move.l	#GD_SelectWindow,d0
		bsr	GhostGadget
		move.l	#GD_DeleteWindow,d0
		bra	GhostGadget

NoWindowListGad	cmp.w	#GD_WindowName,d7		; Changed name for window ?
		bne.s	NoWindowNameGad
		move.w	SelWindow(a4),d0
		bsr	GetEntry
		move.l	a1,d0
		beq.s	.End
		move.l	gg_SpecialInfo(a2),a0
		move.l	si_Buffer(a0),a0
		lea	lw_Name(a1),a1
		moveq	#79,d7
		bsr	StrNCpy
		move.l	LockHandle(a4),a0
		RELLIB	GT_RefreshWindow,_GadToolsBase
.End		rts

NoWindowNameGad	cmp.w	#GD_AddWindow,d7		; New entry ?
		bne	NoAddWinGad
AddWindowKey	move.l	#lw_SIZEOF,d0
		move.l	#MEMF_CLEAR,d1
		CALLSYS	AllocVec
		tst.l	d0
		beq	.Error
		move.l	d0,-(sp)
		move.l	#GD_WindowList,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		move.l	#~0,a2
		bsr	SetListViewLst
		move.l	(sp)+,d0
		lea	WindowBase(a4),a0		; Add entry to tail of list
		move.l	d0,a1
		move.l	d0,a2
		ADDTAIL
		addq.w	#1,NumWindows(a4)
		move.w	NumWindows(a4),d0
		subq.w	#1,d0
		move.w	d0,SelWindow(a4)
		lea	UnusedStr,a0
		lea	lw_Name(a2),a1
		move.l	a1,a3
		move.l	a1,LN_NAME(a2)
		moveq	#79,d7
		bsr	StrNCpy
		move.l	#GD_WindowList,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		lea	WindowBase(a4),a2
		bsr	SetListViewLst
		move.l	#GD_WindowName,d0
		moveq	#0,d1
		bsr	GhostGadget
		move.l	a3,a2
		bsr	SetStringGad
		move.l	#GD_SelectWindow,d0
		bsr	GhostGadget
		move.l	#GD_DeleteWindow,d0
		bsr	GhostGadget
		move.l	#GD_WindowName,d0
		bra	ActStringGad
.Error		move.l	#MEMORY_ERR,ErrorNum(a4)
		jsr	DisplayError
		rts

NoAddWinGad	cmp.w	#GD_SelectWindow,d7		; Select a new window now ?
		bne	NoSelectWinGad
SelectWindowKey	move.l	LockHandle(a4),a0
		lea	SelectWinTxt,a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		move.b	#1,GetNewWindow(a4)
		move.l	#SIGLBUTTON,d0
		CALLSYS	Wait
		clr.b	GetNewWindow(a4)
		move.l	LockHandle(a4),a0
		lea	LockTitle(a4),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		CALLSYS	Forbid
		bsr	FindWindow
		tst.l	d0
		beq.s	.End
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.End
		move.l	d0,a3
		move.w	SelWindow(a4),d0
		bsr	GetEntry
		move.l	a1,d0
		beq.s	.End
		move.l	a1,a2
		lea	lw_Name(a1),a1
		move.l	wd_Title(a3),a0
		move.l	a0,d0
		beq.s	.Error
		moveq	#79,d7
		bsr	StrNCpy
.End		CALLSYS	Permit
		move.l	#GD_WindowName,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		lea	lw_Name(a2),a2
		bsr	SetStringGad
		move.l	LockHandle(a4),a0
		RELLIB	GT_RefreshWindow,_GadToolsBase
		rts
.Error		CALLSYS	Permit
		move.l	#NOTITLE_ERR,ErrorNum(a4)
		jsr	DisplayError
		rts

NoSelectWinGad	cmp.w	#GD_DeleteWindow,d7		; Delete an entry ?
		bne	NoDeleteWinGad
DeleteWindowKey	move.l	#GD_WindowList,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		move.l	#~0,a2
		bsr	SetListViewLst
		move.w	SelWindow(a4),d0
		bsr	GetEntry
		move.l	a1,d0
		beq	.End
		move.l	a1,a2
		REMOVE
		move.l	a2,a1
		CALLSYS	FreeVec
		subq.w	#1,NumWindows(a4)
		move.w	NumWindows(a4),d0
		move.w	SelWindow(a4),d1
		cmp.w	d0,d1
		blt.s	.GoOn
		move.w	d0,d1
		subq.w	#1,d1
.GoOn		move.w	d1,SelWindow(a4)
		move.w	TopWindow(a4),d0
		cmp.w	d0,d1
		bge.s	.NoUp
		subq.w	#1,d0
.NoUp		move.w	d0,TopWindow(a4)
		move.l	#GD_WindowList,d0
		move.w	SelWindow(a4),d1
		move.w	TopWindow(a4),d2
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		bsr	SetListViewGad
		lea	WindowBase(a4),a2
		bsr	SetListViewLst
.Disable	tst.w	NumWindows(a4)
		bgt.s	.End
		moveq	#1,d1
		move.l	#GD_WindowName,d0
		bsr	GhostGadget
		move.l	#GD_SelectWindow,d0
		bsr	GhostGadget
		move.l	#GD_DeleteWindow,d0
		bsr	GhostGadget
.End		rts
NoDeleteWinGad	rts

NoLockGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoLockVKey

		cmp.w	#ESCKEY,d5			; Close window ?
		beq	CloseLockWin

		cmp.w	#KD_WindowName,d5		; Activate String gadget ?
		bne.s	NoWinNameKey
		tst.w	SelWindow(a4)
		blt.s	NoWinNameKey
		move.l	#GD_WindowName,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		bra	ActStringGad

NoWinNameKey	cmp.w	#KD_WindowList,d5		; New entry ?
		bne	NoWinListKey
		tst.w	NumWindows(a4)
		beq.s	.End
		move.w	SelWindow(a4),d0
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		tst.w	d0
		blt.s	.End
		beq.s	.GoOn
		subq.w	#1,d0
		bra.s	.GoOn
.Up		addq.w	#1,d0
		cmp.w	NumWindows(a4),d0
		blt.s	.GoOn
		move.w	NumWindows(a4),d0
		subq.w	#1,d0
.GoOn		move.w	d0,SelWindow(a4)
		move.w	TopWindow(a4),d1
		move.w	d1,d2
		addq.w	#6,d2
		cmp.w	d1,d0
		bge.s	.GoOn1
		subq.w	#1,d1
		bra.s	.New
.GoOn1		cmp.w	d2,d0
		ble.s	.New
		addq.w	#1,d1
.New		move.w	d1,TopWindow(a4)
		move.l	#GD_WindowList,d0
		move.w	SelWindow(a4),d1
		move.w	TopWindow(a4),d2
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a1
		bsr	SetListViewGad
		moveq	#0,d1
		move.l	#GD_WindowName,d0
		bsr	GhostGadget
		move.l	#GD_SelectWindow,d0
		bsr	GhostGadget
		move.l	#GD_DeleteWindow,d0
		bsr	GhostGadget
.End		rts

NoWinListKey	cmp.w	#KD_AddWindow,d5		; New entry ?
		bne.s	NoAddWinKey
		move.l	#GD_AddWindow,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a5
		bsr	ButtonCheck
		bra	AddWindowKey

NoAddWinKey	cmp.w	#KD_SelectWindow,d5		; Select window ?
		bne.s	NoSelectWinKey
		tst.w	SelWindow(a4)
		blt.w	NoSelectWinKey
		move.l	#GD_SelectWindow,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a5
		bsr	ButtonCheck
		bra	SelectWindowKey


NoSelectWinKey	cmp.w	#KD_DeleteWindow,d5		; Delete a window ?
		bne.s	NoLockVKey
		tst.w	SelWindow(a4)
		blt.s	NoLockVKey
		move.l	#GD_DeleteWindow,d0
		lea	LockGads(a4),a0
		move.l	LockHandle(a4),a5
		bsr	ButtonCheck
		bra	DeleteWindowKey
NoLockVKey	rts




**********************************************************************
*              Open our window. if not already open :-)              *
**********************************************************************
OpenMainWin	tst.l	MainHandle(a4)			; Window already open ?
		beq.s	.End
		move.l	MainHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		tst.b	WBFront(a4)
		beq.s	.NoWB
		move.l	MainHandle(a4),a0
		move.l	wd_WScreen(a0),a0
		DOLIB	ScreenToFront
.NoWB		rts
.End		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.MainWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,MainVisInfo(a4)
		beq	.MainWinError

		tst.b	WBFront(a4)
		beq.s	.NoWBFront
		move.l	-4(a5),a0
		RELLIB	ScreenToFront,_IntuitionBase

.NoWBFront	move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	MainWinWidth(a4),d2
		move.w	MainWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	MainWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	MainWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	MainGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.MainWinError

		lea	MainGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Settings gadget
		move.l	MainVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#9*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#6*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#159*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#SettingsText,gng_GadgetText(a1)
		move.w	#GD_Settings,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Misc gadget
		move.l	#172*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#MiscText,gng_GadgetText(a1)
		move.w	#GD_Misc,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Blanking gadget
		move.l	#9*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#22*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#BlankingText,gng_GadgetText(a1)
		move.w	#GD_Blanking,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Cycling gadget
		move.l	#172*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#CyclingText,gng_GadgetText(a1)
		move.w	#GD_Cycling,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Mouse gadget
		move.l	#9*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#38*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#MouseText,gng_GadgetText(a1)
		move.w	#GD_Mouse,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; HotKey gadget
		move.l	#172*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#HotKeyText,gng_GadgetText(a1)
		move.w	#GD_HotKey,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; FKeys gadget
		move.l	#9*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#54*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#FKeyText,gng_GadgetText(a1)
		move.w	#GD_FKey,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Format gadget
		move.l	#172*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#FormatText,gng_GadgetText(a1)
		move.w	#GD_Format,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Bill win gadget
		move.l	#9*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#70*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#BillWinText,gng_GadgetText(a1)
		move.w	#GD_BillWin,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Bill prefs gadget
		move.l	#172*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#BillPrefsText,gng_GadgetText(a1)
		move.w	#GD_BillPrefs,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Load Prefs gadget
		move.l	#81*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#93*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#111*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#LoadPrefsText,gng_GadgetText(a1)
		move.w	#GD_LoadPrefs,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Save prefs gadget
		move.l	#196*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#SavePrefsText,gng_GadgetText(a1)
		move.w	#GD_SavePrefs,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Hide gadget
		move.l	#311*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#HideGadText,gng_GadgetText(a1)
		move.w	#GD_HideGad,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Enable gadget
		move.l	#81*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#109*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#EnableText,gng_GadgetText(a1)
		move.w	#GD_Enable,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Disable gadget
		move.l	#196*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#DisableText,gng_GadgetText(a1)
		move.w	#GD_Disable,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Quit gadget
		move.l	#311*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#QuitText,gng_GadgetText(a1)
		move.w	#GD_Quit,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1		; Alarm gadget
		move.l	#335*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#6*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#159*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#AlarmText,gng_GadgetText(a1)
		move.w	#GD_Alarm,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#22*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ColorsText,gng_GadgetText(a1)
		move.w	#GD_Colors,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#38*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#HardCopyText,gng_GadgetText(a1)
		move.w	#GD_HardCopy,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#54*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#LockWinsText,gng_GadgetText(a1)
		move.w	#GD_LockWins,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.MainWinError
		move.l	MainGadget(a4),MainWinWG+4

		lea.l	MainWinMenuDef,a0		; Create menues
		sub.l	a1,a1
		DOLIB	CreateMenusA
		move.l	d0,MainMenu(a4)
		beq	.MainWinError
		move.l	d0,a0
		move.l	MainVisInfo(a4),a1
		sub.l	a2,a2
		DOLIB	LayoutMenusA

		move.l	-4(a5),MainWinSC+4		; Open window
		ext.l	d2
		ext.l	d3
		move.l	d2,MainWinL+4
		move.l	d3,MainWinT+4
		move.l	-4(a5),a0
		move.w	MainWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.w	d5,d0
		move.l	d0,MainWinW+4
		move.w	MainWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.w	d6,d0
		move.l	d0,MainWinH+4
		suba.l	a0,a0
		lea.l	MainWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,MainHandle(a4)
		beq.s	.MainWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#MAINWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	MainHandle(a4),a0
		move.l	MainMenu(a4),a1
		DOLIB	SetMenuStrip

		move.l	MainHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr	UnlockScreen
		moveq	#0,d0
		unlk	a5
		rts
.MainWinError	bsr.s	CloseMainWin
		bsr	UnlockScreen
		move.l	#MEMORY_ERR,ErrorNum(a4)
		jsr	DisplayError
		moveq	#-1,d0
		unlk	a5
		rts


**********************************************************************
*                Close the main window with it`s menu                *
**********************************************************************
CloseMainWin	tst.l	MainHandle(a4)
		beq.s	.NoWin
		move.l	MainHandle(a4),a0
		RELLIB	ClearMenuStrip,_IntuitionBase
		lea	MainHandle(a4),a3
		bsr	CloseAWindow
.NoWin		tst.l	MainMenu(a4)			; Free GadTools-Menus
		beq.s	.NoMenu
		move.l	MainMenu(a4),a0
		RELLIB	FreeMenus,_GadToolsBase
.NoMenu		clr.l	MainMenu(a4)
		rts



**********************************************************************
*                      Open the settings window                      *
**********************************************************************
OpenSetWin	tst.l	SetHandle(a4)
		beq.s	.GoOn
		move.l	SetHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.SetWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,SetVisInfo(a4)
		beq	.SetWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	SetWinWidth(a4),d2
		move.w	SetWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	SetWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	SetWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	SetGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.SetWinError

		lea	SetGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	SetVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#DisplayText,gng_GadgetText(a1)
		move.w	#GD_Display,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#19*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#DisplayWinText,gng_GadgetText(a1)
		move.w	#GD_DisplayWin,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShowTimeText,gng_GadgetText(a1)
		move.w	#GD_ShowTime,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#64*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShowDateText,gng_GadgetText(a1)
		move.w	#GD_ShowDate,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#AmiDateText,gng_GadgetText(a1)
		move.w	#GD_AmiDate,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#194*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#19*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShowDayText,gng_GadgetText(a1)
		move.w	#GD_ShowDay,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShowSecsText,gng_GadgetText(a1)
		move.w	#GD_ShowSecs,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#194*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShortDayText,gng_GadgetText(a1)
		move.w	#GD_ShortDay,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#370*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#WriteEnvText,gng_GadgetText(a1)
		move.w	#GD_WriteEnv,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#19*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#WBFrontText,gng_GadgetText(a1)
		move.w	#GD_WBFront,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#LeftyText,gng_GadgetText(a1)
		move.w	#GD_Lefty,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#MapUmlautsText,gng_GadgetText(a1)
		move.w	#GD_MapUmlauts,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#194*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#AppIconText,gng_GadgetText(a1)
		move.w	#GD_AppIcon,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#64*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#AutoCtrText,gng_GadgetText(a1)
		move.w	#GD_AutoCtr,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#370*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#MMBShiftText,gng_GadgetText(a1)
		move.w	#GD_MMBShift,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#194*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GermanDaysText,gng_GadgetText(a1)
		move.w	#GD_GermanDays,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#PDateText,gng_GadgetText(a1)
		move.w	#GD_PDate,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l  #370*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#NoClickText,gng_GadgetText(a1)
		move.w	#GD_NoClick,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l  #7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#94*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ShowMouseText,gng_GadgetText(a1)
		move.w	#GD_ShowMouse,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0
		tst.l	d0
		beq	.SetWinError

		move.l	SetGadget(a4),SetWinWG+4
		move.l	-4(a5),SetWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,SetWinL+4
		move.l	d3,SetWinT+4
		move.l	-4(a5),a0
		move.w	SetWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.w	d5,d0
		move.l	d0,SetWinW+4
		move.w	SetWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.w	d6,d0
		move.l	d0,SetWinH+4
		suba.l	a0,a0
		lea.l	SetWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,SetHandle(a4)
		beq.s	.SetWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#SETWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	SetHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetSetGads
		bsr	UnlockScreen
		unlk	a5
		rts
.SetWinError	bsr.s	CloseSetWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		jsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts

**********************************************************************
*                     Close the settings window                      *
**********************************************************************
CloseSetWin	lea	SetHandle(a4),a3
		bsr	CloseAWindow
		rts


**********************************************************************
*                      Set the settings gadgets                      *
**********************************************************************
SetSetGads	move.b	ShowClock(a4),d0
		move.l	#GD_Display,d1
		bsr	SetSetBox
		move.b	DoShowTime(a4),d0
		move.l	#GD_ShowTime,d1
		bsr	SetSetBox
		move.b	ClockWin(a4),d0
		move.l	#GD_DisplayWin,d1
		bsr	SetSetBox
		move.b	AmiDate(a4),d0
		move.l	#GD_AmiDate,d1
		bsr	SetSetBox
		move.b	ShowDate(a4),d0
		move.l	#GD_ShowDate,d1
		bsr	SetSetBox
		move.b	ShowDay(a4),d0
		move.l	#GD_ShowDay,d1
		bsr	SetSetBox
		move.b	ShowSecs(a4),d0
		move.l	#GD_ShowSecs,d1
		bsr	SetSetBox
		move.b	ShortDay(a4),d0
		move.l	#GD_ShortDay,d1
		bsr	SetSetBox
		move.b	SetEnv(a4),d0
		move.l	#GD_WriteEnv,d1
		bsr.s	SetSetBox
		move.b	WBFront(a4),d0
		move.l	#GD_WBFront,d1
		bsr.s	SetSetBox
		move.b	LeftyMouse(a4),d0
		move.l	#GD_Lefty,d1
		bsr.s	SetSetBox
		move.b	MapUmlaut(a4),d0
		move.l	#GD_MapUmlauts,d1
		bsr.s	SetSetBox
		move.b	DispAppIcon(a4),d0
		move.l	#GD_AppIcon,d1
		bsr.s	SetSetBox
		move.b	AutoCenter(a4),d0		; Set Auto Center gadget
		move.l	#GD_AutoCtr,d1
		bsr.s	SetSetBox
		move.b	MMBShift(a4),d0			; Set MMB Shift
		move.l	#GD_MMBShift,d1
		bsr.s	SetSetBox
		move.b	GermanDays(a4),d0		; Set German day
		move.l	#GD_GermanDays,d1
		bsr.s	SetSetBox
		move.b	PointDates(a4),d0		; Set point dates
		move.l	#GD_PDate,d1
		bsr.s	SetSetBox
		move.b	DriveNoClick(a4),d0
		move.l	#GD_NoClick,d1
		bsr.s	SetSetBox
		move.b	ShowMouse(a4),d0
		move.l	#GD_ShowMouse,d1
		bsr.s	SetSetBox
		rts
SetSetBox	lea	SetGads(a4),a0
		move.l	SetHandle(a4),a1
		bra	SetCheckBox


**********************************************************************
*                   Open the miscellaneous window                    *
**********************************************************************
OpenMiscWin	tst.l	MiscHandle(a4)
		beq.s	.GoOn
		move.l	MiscHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.MiscWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,MiscVisInfo(a4)
		beq	.MiscWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	MiscWinWidth(a4),d2
		move.w	MiscWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	MiscWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	MiscWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	MiscGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.MiscWinError

		lea	MiscGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	MiscVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#10*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#ESCCloseText,gng_GadgetText(a1)
		move.w	#GD_ESCClose,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#182*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#142*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#ESCQualText,gng_GadgetText(a1)
		move.w	#GD_ESCQual,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#328*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#190*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_ESCQualTxt,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#10*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#KeyClickText,gng_GadgetText(a1)
		move.w	#GD_KeyClick,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#340*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#178*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#ClickVolText,gng_GadgetText(a1)
		move.w	#GD_ClickVol,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#11,d0
		lea.l	ClickVolTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#161*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
 ;		  add.w	 d2,gng_LeftEdge(a1)
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#357*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#UserShellText,gng_GadgetText(a1)
		move.w	#GD_UserShell,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	UserShellTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#10*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#74*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ExpWindowsText,gng_GadgetText(a1)
		move.w	#GD_ExpWindows,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#218*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#MouseCtrText,gng_GadgetText(a1)
		move.w	#GD_MouseCtr,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#37*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#100*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#112*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#10*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#ExpFramesText,gng_GadgetText(a1)
		move.w	#GD_ExpFrames,gng_GadgetID(a1)
		move.l	#PLACETEXT_ABOVE,gng_Flags(a1)
		move.l	#11,d0
		lea.l	ExpFramesTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#218*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#ImpFramesText,gng_GadgetText(a1)
		move.w	#GD_ImpFrames,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	ExpFramesTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#400*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#SizeFramesText,gng_GadgetText(a1)
		move.w	#GD_SizeFrames,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	ExpFramesTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#10*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#33*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#FullDragText,gng_GadgetText(a1)
		move.w	#GD_FullDrag,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#143*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#181*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#DragQualText,gng_GadgetText(a1)
		move.w	#GD_DragQual,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#328*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#190*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_DragQualTxt,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.MiscWinError

		lea	MiscGads(a4),a0
		bsr	SetStrIntGads

		move.l	MiscGadget(a4),MiscWinWG+4
		move.l	-4(a5),MiscWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,MiscWinL+4
		move.l	d3,MiscWinT+4
		move.l	-4(a5),a0
		move.w	MiscWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.w	d5,d0
		move.l	d0,MiscWinW+4
		move.w	MiscWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.w	d6,d0
		move.l	d0,MiscWinH+4
		suba.l	a0,a0
		lea.l	MiscWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,MiscHandle(a4)
		beq.s	.MiscWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#MISCWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	MiscHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetMiscGads
		bsr	UnlockScreen
		unlk	a5
		rts
.MiscWinError	bsr	CloseMiscWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                        Set other misc gads                         *
**********************************************************************
SetMiscGads	move.b	KeyClick(a4),d0			; Set Click gadgets
		move.l	#GD_KeyClick,d1
		bsr	SetMiscBox

		move.l	#GD_ClickVol,d0
		move.l	ClickVol(a4),d1
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bsr	SetSliderGad

		move.b	ESCClose(a4),d0			; Set Exploding windows gads
		move.l	#GD_ESCClose,d1
		bsr	SetMiscBox

		move.l	#RESCKEY,d0
		move.w	ESCQual(a4),d1
		move.l	#GD_ESCQualTxt,d2
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		lea	EscQualStr(a4),a2
		jsr	DisplayHotKey

		move.b	FullDrag(a4),d0			; Front drag settings
		move.l	#GD_FullDrag,d1
		bsr	SetMiscBox

		move.l	#IECODE_LBUTTON,d0
		move.w	FullDragQual(a4),d1
		move.l	#GD_DragQualTxt,d2
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		lea	DragQualStr(a4),a2
		jsr	DisplayHotKey

		bsr.s	SetWindowsGads
		rts



**********************************************************************
*                 Set gads and menues for ExpWindows                 *
**********************************************************************
SetWindowsGads	move.l	#GD_ExpFrames,d0
		move.l	ExpFrames(a4),d1
		bsr.s	SetMiscSlids

		move.l	#GD_ImpFrames,d0
		move.l	ImpFrames(a4),d1
		bsr.s	SetMiscSlids

		move.l	#GD_SizeFrames,d0
		move.l	SizeFrames(a4),d1
		bsr.s	SetMiscSlids

		move.l	#GD_ExpFrames,d0		; On/Off frames gadgets
		move.l	MiscHandle(a4),a1		; on setting of ExpWindows Gad
		moveq	#0,d1
		move.b	ExpWindows(a4),d1
		bchg	#0,d1
		bsr	GhostGadget

		move.l	#GD_ImpFrames,d0
		bsr	GhostGadget

		move.l	#GD_SizeFrames,d0
		bsr	GhostGadget

		move.l	#GD_MouseCtr,d0
		bsr	GhostGadget

		move.b	ExpWindows(a4),d0
		move.l	#GD_ExpWindows,d1
		bsr.s	SetMiscBox

		move.b	MouseCenter(a4),d0
		move.l	#GD_MouseCtr,d1
		bsr.s	SetMiscBox
		rts
SetMiscBox	lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bra	SetCheckBox
SetMiscSlids	lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bra	SetSliderGad


**********************************************************************
*                   Close the miscellaneous window                   *
**********************************************************************
CloseMiscWin	lea	MiscHandle(a4),a3
		bra	CloseAWindow


**********************************************************************
*                        Open the alarm window                       *
**********************************************************************
OpenAlarmWin	tst.l	AlarmHandle(a4)
		beq.s	.GoOn
		move.l	AlarmHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.AlarmWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,AlarmVisInfo(a4)
		beq	.AlarmWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	AlarmWinWidth(a4),d2
		move.w	AlarmWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	AlarmWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	AlarmWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	AlarmGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.AlarmWinError

		lea	AlarmGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	AlarmVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#6*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#AlarmOnText,gng_GadgetText(a1)
		move.w	#GD_AlarmOn,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#118*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#AllHoursText,gng_GadgetText(a1)
		move.w	#GD_AllHours,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#244*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#ShowAlarmText,gng_GadgetText(a1)
		move.w	#GD_ShowAlarm,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#165*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#225*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#AlarmTimeText,gng_GadgetText(a1)
		move.w	#GD_AlarmTime,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#11,d0
		lea.l	AlarmTimeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#94*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#33*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#131*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#AlSoundTypeText,gng_GadgetText(a1)
		move.w	#GD_AlSoundType,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	AlSoundTypeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#236*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#153*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#AlarmSampleText,gng_GadgetText(a1)
		move.w	#GD_AlarmSample,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#101*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#50*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#288*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#SampleNameText,gng_GadgetText(a1)
		move.w	#GD_SampleName,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.AlarmWinError
		move.l	AlarmGadget(a4),AlarmWinWG+4

		move.l	-4(a5),AlarmWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,AlarmWinL+4
		move.l	d3,AlarmWinT+4
		move.l	-4(a5),a0
		move.w	AlarmWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,AlarmWinW+4
		move.w	AlarmWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,AlarmWinH+4
		suba.l	a0,a0
		lea.l	AlarmWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,AlarmHandle(a4)
		beq.s	.AlarmWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#ALARMWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	AlarmHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetAlarmGads
		bsr	UnlockScreen
		unlk	a5
		rts
.AlarmWinError	bsr	CloseAlarmWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                  Set gadgets within alarm window                   *
**********************************************************************
SetAlarmGads	move.b	DoAlarm(a4),d0
		move.l	#GD_AlarmOn,d1
		bsr.s	SetAlarmBox

		move.b	EveryHour(a4),d0
		move.l	#GD_AllHours,d1
		bsr.s	SetAlarmBox

		move.b	DoShowAlarm(a4),d0
		move.l	#GD_ShowAlarm,d1
		bsr.s	SetAlarmBox

		move.l	#GD_AlarmTime,d0
		move.l	AlarmTime(a4),d1
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bsr	SetSliderGad

		move.l	#GD_AlSoundType,d0
		moveq	#0,d1
		move.b	AlarmSample(a4),d1
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bsr	SetCycleGad

		move.l	#GD_AlarmSample,d0
		bchg	#0,d1
		bsr	GhostGadget

		move.l	#GD_SampleName,d0
		lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		lea	AlSampleName(a4),a2
		bsr	SetTextGad
		rts
SetAlarmBox	lea	AlarmGads(a4),a0
		move.l	AlarmHandle(a4),a1
		bra	SetCheckBox


**********************************************************************
*                         Close alarm window                         *
**********************************************************************
CloseAlarmWin	lea	AlarmHandle(a4),a3
		bra	CloseAWindow



**********************************************************************
*                   Open the cycle settings window                   *
**********************************************************************
OpenCycleWin	tst.l	CycleHandle(a4)
		beq.s	.GoOn
		move.l	CycleHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.CycleWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,CycleVisInfo(a4)
		beq	.CycleWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	CycleWinWidth(a4),d2
		move.w	CycleWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	CycleWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	CycleWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	CycleGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.CycleWinError

		lea	CycleGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	CycleVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#5*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#CycleOnText,gng_GadgetText(a1)
		move.w	#GD_CycleOn,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#23*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#32*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#105*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#FrontClickText,gng_GadgetText(a1)
		move.w	#GD_FrontClick,gng_GadgetID(a1)
		move.l	#PLACETEXT_ABOVE,gng_Flags(a1)
		move.l	#11,d0
		lea.l	FrontClickTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#160*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#MiddleClickText,gng_GadgetText(a1)
		move.w	#GD_MiddleClick,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	FrontClickTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#297*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#BackClickText,gng_GadgetText(a1)
		move.w	#GD_BackClick,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	FrontClickTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#5*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#47*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#93*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#FrontKeyText,gng_GadgetText(a1)
		move.w	#GD_FrontKey,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#63*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#MiddleKeyText,gng_GadgetText(a1)
		move.w	#GD_MiddleKey,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#BackKeyText,gng_GadgetText(a1)
		move.w	#GD_BackKey,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#103*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#47*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#299*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_FrontQual,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#63*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.w	#GD_MiddleQual,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.w	#GD_BackQual,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.CycleWinError
		move.l	CycleGadget(a4),CycleWinWG+4

		move.l	-4(a5),CycleWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,CycleWinL+4
		move.l	d3,CycleWinT+4
		move.l	-4(a5),a0
		move.w	CycleWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,CycleWinW+4
		move.w	CycleWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,CycleWinH+4
		suba.l	a0,a0
		lea.l	CycleWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,CycleHandle(a4)
		beq.s	.CycleWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#CYCLEWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	CycleHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetCycleGads
		bsr	UnlockScreen
		unlk	a5
		rts
.CycleWinError	bsr	CloseCycleWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                       Set all cycle gadgets                        *
**********************************************************************
SetCycleGads	bsr.s	SetCycleSlids
		bsr.s	SetCycleQuals
		move.b	CycleWin(a4),d0
		move.l	#GD_CycleOn,d1
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a1
		bsr	SetCheckBox
		rts
**********************************************************************
*                    Set sliders of cycle window                     *
**********************************************************************
SetCycleSlids	moveq	#0,d1

		move.l	#GD_FrontClick,d0
		move.w	FrontClicks(a4),d1
		bsr.s	SetCycleSlider

		move.l	#GD_MiddleClick,d0
		move.w	MiddleClicks(a4),d1
		bsr.s	SetCycleSlider

		move.l	#GD_BackClick,d0
		move.w	BackClicks(a4),d1
		bsr.s	SetCycleSlider
		rts
SetCycleSlider	lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a1
		bra	SetSliderGad
**********************************************************************
*                   Display all cycling qualifiers                   *
**********************************************************************
SetCycleQuals	move.w	FrontCode(a4),d0
		move.w	FrontQual(a4),d1
		move.l	#GD_FrontQual,d2
		lea	FrontQualStr(a4),a2
		bsr.s	SetCycleText

		move.w	#IECODE_MBUTTON,d0
		move.w	MiddleQual(a4),d1
		move.l	#GD_MiddleQual,d2
		lea	MiddleQualStr(a4),a2
		bsr.s	SetCycleText

		move.w	BackCode(a4),d0
		move.w	BackQual(a4),d1
		move.l	#GD_BackQual,d2
		lea	BackQualStr(a4),a2
		bsr.s	SetCycleText
		rts
SetCycleText	lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a1
		bra	DisplayHotKey



**********************************************************************
*                      Close Cycle window again                      *
**********************************************************************
CloseCycleWin	lea	CycleHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*                        Open Blanking window                        *
**********************************************************************
OpenBlankWin	tst.l	BlankHandle(a4)
		beq.s	.GoOn
		move.l	BlankHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.BlankWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,BlankVisInfo(a4)
		beq	.BlankWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	BlankWinWidth(a4),d2
		move.w	BlankWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	BlankWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	BlankWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	BlankGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.BlankWinError

		lea	BlankGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	BlankVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#BlankMouseText,gng_GadgetText(a1)
		move.w	#GD_BlankMouse,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#174*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#126*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#ScrTimeText,gng_GadgetText(a1)
		move.w	#GD_ScrTime,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#11,d0
		lea.l	ScrTimeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#33*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#MouseTimeText,gng_GadgetText(a1)
		move.w	#GD_MouseTime,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	ScrTimeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#152*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#48*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#88*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#BlankTypeText,gng_GadgetText(a1)
		move.w	#GD_BlankType,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	BlankTypeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#64*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#148*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#DimmFacText,gng_GadgetText(a1)
		move.w	#GD_DimmFac,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	DimmFacTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.BlankWinError

		move.l	BlankGadget(a4),BlankWinWG+4
		move.l	-4(a5),BlankWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,BlankWinL+4
		move.l	d3,BlankWinT+4
		move.l	-4(a5),a0
		move.w	BlankWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,BlankWinW+4
		move.w	BlankWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,BlankWinH+4
		suba.l	a0,a0
		lea.l	BlankWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,BlankHandle(a4)
		beq.s	.BlankWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#BLANKWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	BlankHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetBlankGads
		bsr	UnlockScreen
		unlk	a5
		rts
.BlankWinError	bsr	CloseBlankWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                Set all gadgets within blank window                 *
**********************************************************************
SetBlankGads	move.b	MouseEver(a4),d0
		move.l	#GD_BlankMouse,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	SetCheckBox

		move.l	#GD_ScrTime,d0
		move.l	ScreenTime(a4),d1
		bsr.s	SetBlankSlid

		move.l	#GD_MouseTime,d0
		move.l	MouseTime(a4),d1
		bsr.s	SetBlankSlid

		move.l	#GD_DimmFac,d0
		move.l	DimmValue(a4),d1
		bsr.s	SetBlankSlid

		move.l	#GD_BlankType,d0
		moveq	#0,d1
		move.b	ScreenDimm(a4),d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	SetCycleGad

		move.l	#GD_DimmFac,d0
		moveq	#0,d1
		move.b	ScreenDimm(a4),d1
		bchg	#0,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	GhostGadget
		rts
SetBlankSlid	lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bra	SetSliderGad

**********************************************************************
*                     Close the blanking window                      *
**********************************************************************
CloseBlankWin	lea	BlankHandle(a4),a3
		bra	CloseAWindow



**********************************************************************
*                        Open colors windows                         *
**********************************************************************
OpenColsWin	tst.l	ColsHandle(a4)
		beq.s	.GoOn
		move.l	ColsHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.ColsWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,ColsVisInfo(a4)
		beq	.ColsWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	ColsWinWidth(a4),d2
		move.w	ColsWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	ColsWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	ColsWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	ColsGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.ColsWinError

		lea	ColsGads(a4),a3

		move.l	-4(a5),a1			; Set depth of screen
		lea	sc_BitMap(a1),a1
		moveq	#0,d0
		move.b	bm_Depth(a1),d0
		move.l	d0,ScrDepth+4

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	ColsVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#134*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#170*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#20*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#TFrontPenText,gng_GadgetText(a1)
		move.w	#GD_TFrontPen,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#8,d0
		lea.l	TFrontPenTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#27*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#TBackPenText,gng_GadgetText(a1)
		move.w	#GD_TBackPen,gng_GadgetID(a1)
		move.l	#8,d0
		lea.l	TFrontPenTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#51*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GFrontPenText,gng_GadgetText(a1)
		move.w	#GD_GFrontPen,gng_GadgetID(a1)
		move.l	#8,d0
		lea.l	TFrontPenTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#75*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GBackPenText,gng_GadgetText(a1)
		move.w	#GD_GBackPen,gng_GadgetID(a1)
		move.l	#8,d0
		lea.l	TFrontPenTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.ColsWinError

		move.l	ColsGadget(a4),ColsWinWG+4
		move.l	-4(a5),ColsWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,ColsWinL+4
		move.l	d3,ColsWinT+4
		move.l	-4(a5),a0
		move.w	ColsWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,ColsWinW+4
		move.w	ColsWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,ColsWinH+4
		suba.l	a0,a0
		lea.l	ColsWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,ColsHandle(a4)
		beq.s	.ColsWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#COLSWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	ColsHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetColsGads
		bsr	UnlockScreen
		unlk	a5
		rts
.ColsWinError	bsr.s	CloseColsWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                         Set colors gadgets                         *
**********************************************************************
SetColsGads	move.l	#GD_TFrontPen,d0
		move.l	TextFrontPen(a4),d1
		bsr.s	SetColsPal

		move.l	#GD_TBackPen,d0
		move.l	TextBackPen(a4),d1
		bsr.s	SetColsPal

		move.l	#GD_GFrontPen,d0
		move.l	GaugeFrontPen(a4),d1
		bsr.s	SetColsPal

		move.l	#GD_GBackPen,d0
		move.l	GaugeBackPen(a4),d1
		bsr.s	SetColsPal
		rts
SetColsPal	lea	ColsGads(a4),a0
		move.l	ColsHandle(a4),a1
		bra	SetPaletteGad


**********************************************************************
*                      Close the colors window                       *
**********************************************************************
CloseColsWin	lea	ColsHandle(a4),a3
		bra	CloseAWindow


**********************************************************************
*                         Open mouse window                          *
**********************************************************************
OpenMouseWin	tst.l	MouseHandle(a4)
		beq.s	.GoOn
		move.l	MouseHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.MouseWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,MouseVisInfo(a4)
		beq	.MouseWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	MouseWinWidth(a4),d2
		move.w	MouseWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	MouseWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	MouseWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	MouseGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.MouseWinError

		lea	MouseGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	MouseVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#152*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#WindowActText,gng_GadgetText(a1)
		move.w	#GD_WindowAct,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#272*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#SunMouseText,gng_GadgetText(a1)
		move.w	#GD_SunMouse,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#452*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#MouseAccelText,gng_GadgetText(a1)
		move.w	#GD_MouseAccel,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#159*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#87*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#AccelerateText,gng_GadgetText(a1)
		move.w	#GD_Accelerate,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	AccelerateTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#391*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#ThresholdText,gng_GadgetText(a1)
		move.w	#GD_Threshold,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	ThresholdTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0


		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#154*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#324*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_HoldX,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_HoldY,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#140*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#HoldXQualText,gng_GadgetText(a1)
		move.w	#GD_HoldXQual,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#HoldYQualText,gng_GadgetText(a1)
		move.w	#GD_HoldYQual,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.MouseWinError
		move.l	MouseGadget(a4),MouseWinWG+4
		move.l	-4(a5),MouseWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,MouseWinL+4
		move.l	d3,MouseWinT+4
		move.l	-4(a5),a0
		move.w	MouseWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,MouseWinW+4
		move.w	MouseWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,MouseWinH+4
		suba.l	a0,a0
		lea.l	MouseWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,MouseHandle(a4)
		beq.s	.MouseWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#MOUSEWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	MouseHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetMouseGads
		bsr	UnlockScreen
		unlk	a5
		rts
.MouseWinError	bsr	CloseMouseWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts

**********************************************************************
*                         Set mouse gadgets                          *
**********************************************************************
SetMouseGads	move.b	DoActivate(a4),d0
		move.l	#GD_WindowAct,d1
		bsr.s	SetMouseBox

		move.b	SunMouse(a4),d0
		move.l	#GD_SunMouse,d1
		bsr.s	SetMouseBox

		move.b	MouseAccel(a4),d0
		move.l	#GD_MouseAccel,d1
		bsr.s	SetMouseBox

		move.l	#GD_Accelerate,d0
		move.l	Accelerate(a4),d1
		bsr	SetSliderGad

		move.l	#GD_Threshold,d0
		move.l	ThresHold(a4),d1
		bsr	SetSliderGad

		move.l	#GD_Accelerate,d0
		moveq	#0,d1
		move.b	MouseAccel(a4),d1
		bchg	#0,d1
		bsr	GhostGadget

		move.l	#GD_Threshold,d0
		bsr	GhostGadget

		moveq	#0,d0
		move.w	HoldXQual(a4),d1
		move.l	#GD_HoldX,d2
		lea	HoldXQualStr(a4),a2
		bsr	DisplayHotKey

		move.w	HoldYQual(a4),d1
		move.l	#GD_HoldY,d2
		lea	HoldYQualStr(a4),a2
		bsr	DisplayHotKey

		rts
SetMouseBox	lea	MouseGads(a4),a0
		move.l	MouseHandle(a4),a1
		bra	SetCheckBox

**********************************************************************
*                         Close mouse window                         *
**********************************************************************
CloseMouseWin	lea	MouseHandle(a4),a3
		bra	CloseAWindow



**********************************************************************
*                         Open HotKey window                         *
**********************************************************************
OpenHotKeyWin	tst.l	HotKeyHandle(a4)
		beq.s	.GoOn
		move.l	HotKeyHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.HotKeyWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,HotKeyVisInfo(a4)
		beq	.HotKeyWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	HotKeyWinWidth(a4),d2
		move.w	HotKeyWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	HotKeyWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	HotKeyWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	HotKeyGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.HotKeyWinError

		lea	HotKeyGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	HotKeyVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#48*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#17*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#246*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#88*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#HotKeyListText,gng_GadgetText(a1)
		move.w	#GD_HotKeyList,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#4,d0
		lea.l	HotKeyListTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#107*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
;		add.w	d3,gng_TopEdge(a1)
		move.l	#248*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#HotKeyDefText,gng_GadgetText(a1)
		move.w	#GD_HotKeyDef,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	HotKeyDefTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.HotKeyWinError

		lea	HotKeyGads(a4),a0
		bsr	SetStrIntGads

		move.l	HotKeyGadget(a4),HotKeyWinWG+4
		move.l	-4(a5),HotKeyWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,HotKeyWinL+4
		move.l	d3,HotKeyWinT+4
		move.l	-4(a5),a0
		move.w	HotKeyWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,HotKeyWinW+4
		move.w	HotKeyWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,HotKeyWinH+4
		suba.l	a0,a0
		lea.l	HotKeyWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,HotKeyHandle(a4)
		beq.s	.HotKeyWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#HOTKEYWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	HotKeyHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		move.l	#-1,HotKeyChange(a4)
		clr.l	HotKeyVisTop(a4)

		bsr	UnlockScreen
		unlk	a5
		rts
.HotKeyWinError	bsr.s	CloseHotKeyWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                        Close HotKey window                         *
**********************************************************************
CloseHotKeyWin	lea	HotKeyHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*                       Open the FKeys-window                        *
**********************************************************************
OpenFKeyWin	tst.l	FKeyHandle(a4)
		beq.s	.GoOn
		move.l	FKeyHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.FKeyWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,FKeyVisInfo(a4)
		beq	.FKeyWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	FKeyWinWidth(a4),d2
		move.w	FKeyWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	FKeyWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	FKeyWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	FKeyGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.FKeyWinError

		lea	FKeyGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	FKeyVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#36*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#2*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#322*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#F1Text,gng_GadgetText(a1)
		move.w	#GD_F1,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#16*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F2Text,gng_GadgetText(a1)
		move.w	#GD_F2,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#30*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F3Text,gng_GadgetText(a1)
		move.w	#GD_F3,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#44*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F4Text,gng_GadgetText(a1)
		move.w	#GD_F4,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#58*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F5Text,gng_GadgetText(a1)
		move.w	#GD_F5,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#72*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F6Text,gng_GadgetText(a1)
		move.w	#GD_F6,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#86*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F7Text,gng_GadgetText(a1)
		move.w	#GD_F7,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#100*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F8Text,gng_GadgetText(a1)
		move.w	#GD_F8,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#114*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F9Text,gng_GadgetText(a1)
		move.w	#GD_F9,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#128*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#F10Text,gng_GadgetText(a1)
		move.w	#GD_F10,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	F1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#116*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#144*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#109*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#FKeyQualText,gng_GadgetText(a1)
		move.w	#GD_FKeyQual,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	FKeyQualTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#332*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#FKeyActText,gng_GadgetText(a1)
		move.w	#GD_FKeyAct,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#36*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#160*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#69*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#FKeyOkText,gng_GadgetText(a1)
		move.w	#GD_FKeyOk,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#289*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#159*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#FKeyCancelText,gng_GadgetText(a1)
		move.w	#GD_FKeyCancel,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+
		tst.l	d0
		beq	.FKeyWinError

		lea	FKeyGads(a4),a0
		bsr	SetStrIntGads

		move.l	FKeyGadget(a4),FKeyWinWG+4
		move.l	-4(a5),FKeyWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,FKeyWinL+4
		move.l	d3,FKeyWinT+4
		move.l	-4(a5),a0
		move.w	FKeyWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,FKeyWinW+4
		move.w	FKeyWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,FKeyWinH+4
		suba.l	a0,a0
		lea.l	FKeyWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,FKeyHandle(a4)
		beq.s	.FKeyWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#FKEYWINIDCMP,d0
		DOLIB	ModifyIDCMP

		lea	FKeys(a4),a2			; Copy FKeys
		lea	FKeysNew(a4),a3
		move.w	#((MAXFKEYWIDTH+2)*40)-1,d7
.Loop		move.b	(a2)+,(a3)+
		dbf	d7,.Loop

		move.l	FKeyHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetFKeyGads
		bsr	UnlockScreen
		unlk	a5
		move.l	FKeyHandle(a4),a0
		RELLIB	ActivateWindow,_IntuitionBase
		rts
.FKeyWinError	bsr.s	CloseFKeyWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                    Set gadgets of FKeys window                     *
**********************************************************************
SetFKeyGads	move.l	FKeyQual(a4),d0
		mulu	#(MAXFKEYWIDTH+2)*10,d0		; Display new list
		lea	FKeysNew(a4),a2
		lea	0(a2,d0),a2
		move.l	#GD_F1,d0
		moveq	#9,d6
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
.Loop		bsr	SetStringGad
		lea	(MAXFKEYWIDTH+2)(a2),a2
		addq.l	#1,d0
		dbf	d6,.Loop

		move.l	#GD_FKeyQual,d0			; Set cycle gadget
		move.l	FKeyQual(a4),d1
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
		bsr	SetCycleGad

		move.b	FKeysOn(a4),d0			; Set checkbox gadget
		move.l	#GD_FKeyAct,d1
		lea	FKeyGads(a4),a0
		move.l	FKeyHandle(a4),a1
		bsr	SetCheckBox
		rts



**********************************************************************
*                         Close FKeys window                         *
**********************************************************************
CloseFKeyWin	lea	FKeyHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*                     Open the formatter window                      *
**********************************************************************
OpenFormWin	tst.l	FormHandle(a4)
		beq.s	.GoOn
		move.l	FormHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.FormWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,FormVisInfo(a4)
		beq	.FormWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	FormWinWidth(a4),d2
		move.w	FormWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	FormWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	FormWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	FormGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.FormWinError

		lea	FormGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	FormVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#56*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#69*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#DriveText,gng_GadgetText(a1)
		move.w	#GD_Drive,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#7,d0
		lea.l	DriveTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#135*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
 ;		  add.w	 d2,gng_LeftEdge(a1)
		move.l	#235*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#LabelText,gng_GadgetText(a1)
		move.w	#GD_Label,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	LabelTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#22*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#TrashcanText,gng_GadgetText(a1)
		move.w	#GD_Trashcan,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#222*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#QuickText,gng_GadgetText(a1)
		move.w	#GD_Quick,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#389*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#23*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#FFSText,gng_GadgetText(a1)
		move.w	#GD_FFS,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#37*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#NoVerifyText,gng_GadgetText(a1)
		move.w	#GD_NoVerify,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#222*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#InstallText,gng_GadgetText(a1)
		move.w	#GD_Install,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#389*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#38*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#EjectText,gng_GadgetText(a1)
		move.w	#GD_Eject,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#8*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#56*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#59*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#FormOkText,gng_GadgetText(a1)
		move.w	#GD_FormOk,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#356*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#FormCancelText,gng_GadgetText(a1)
		move.w	#GD_FormCancel,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#222*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#WatchDisksText,gng_GadgetText(a1)
		move.w	#GD_WatchDisks,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.FormWinError

		lea	FormGads(a4),a0
		bsr	SetStrIntGads

		move.l	FormGadget(a4),FormWinWG+4
		move.l	-4(a5),FormWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,FormWinL+4
		move.l	d3,FormWinT+4
		move.l	-4(a5),a0
		move.w	FormWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,FormWinW+4
		move.w	FormWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,FormWinH+4
		suba.l	a0,a0
		lea.l	FormWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,FormHandle(a4)
		beq.s	.FormWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#FORMWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	FormHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetFormGads
		bsr	UnlockScreen
		unlk	a5
		move.l	FormHandle(a4),a0
		RELLIB	ActivateWindow,_IntuitionBase
		rts
.FormWinError	bsr	CloseFormWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts



**********************************************************************
*                        Set Formatter gadget                        *
**********************************************************************
SetFormGads	move.b	MakeIcons(a4),d0
		move.l	#GD_Trashcan,d1
		bsr.s	SetFormBox
		move.b	QuickFormat(a4),d0
		move.l	#GD_Quick,d1
		bsr.s	SetFormBox
		move.b	FFSDrive(a4),d0
		move.l	#GD_FFS,d1
		bsr.s	SetFormBox
		move.b	NoVerify(a4),d0
		move.l	#GD_NoVerify,d1
		bsr.s	SetFormBox
		move.b	Install(a4),d0
		move.l	#GD_Install,d1
		bsr.s	SetFormBox
		move.b	EjectDrive(a4),d0
		move.l	#GD_Eject,d1
		move.b	WatchDisks(a4),d0
		move.l	#GD_WatchDisks,d1
		bsr.s	SetFormBox

		move.l	#GD_Label,d0
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		lea	DefLabel,a2
		bra	SetStringGad
SetFormBox	lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		bra	SetCheckBox



**********************************************************************
*                       Close formatter window                       *
**********************************************************************
CloseFormWin	lea	FormHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*                        Open the bill window                        *
**********************************************************************
OpenBillWin	tst.l	BillHandle(a4)
		beq.s	.End
		move.l	BillHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.End		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)	; Try to lock public screen
		lea	PubScreenName(a4),a3		; named in prefs
.FindScreen	tst.b	(a3)
		beq.s	.WBScreen
		move.l	a3,a2
.FindEnd	tst.b	(a2)
		beq.s	.GoOn
		cmp.b	#';',(a2)
		beq.s	.GoOn
		addq.l	#1,a2
		bra.s	.FindEnd
.GoOn		move.b	(a2),d6
		clr.b	(a2)
		move.l	a3,a0
		lea	BillPubScr(a4),a1
		bsr	StrCpy
		move.l	a3,a0
		RELLIB	LockPubScreen,_IntuitionBase
		move.l	d0,-4(a5)
		move.b	d6,(a2)
		tst.l	d0
		bne.s	.GotPubScreen
.FindNext	tst.b	(a3)
		beq.s	.WBScreen
		cmp.b	#';',(a3)+
		bne.s	.FindNext
		bra.s	.FindScreen

.WBScreen	sub.l	a0,a0				; On error -> Try to lock WB
		RELLIB	LockPubScreen,_IntuitionBase
		move.l	d0,-4(a5)
		tst.l	d0
		beq	.BillWinError

.GotPubScreen	moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,BillVisInfo(a4)
		beq	.BillWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	BillWinWidth(a4),d2
		move.w	BillWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	BillWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	BillWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	BillGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.BillWinError

		lea	BillGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	BillVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#72*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#BillTimeText,gng_GadgetText(a1)
		move.w	#GD_BillTime,gng_GadgetID(a1)
		move.l	#PLACETEXT_ABOVE,gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#83*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#BillOnlineText,gng_GadgetText(a1)
		move.w	#GD_BillOnline,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#159*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#BillCostText,gng_GadgetText(a1)
		move.w	#GD_BillCost,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#62*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#30*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_BillTimeMX,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#5,d0
		lea.l	BillTimeMXTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#214*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.w	#GD_BillCheap,gng_GadgetID(a1)
		move.l	#5,d0
		lea.l	BillCheapTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#63*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#225*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.w	#GD_BillHour,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#LogCallText,gng_GadgetText(a1)
		move.w	#GD_LogCall,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.BillWinError

		move.l	BillGadget(a4),BillWinWG+4
		move.l	-4(a5),BillWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,BillWinL+4
		move.l	d3,BillWinT+4
		move.l	-4(a5),a0
		move.w	BillWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,BillWinW+4
		move.w	d0,BillZoomSize+4
		move.w	OffY(a5),BillZoomSize+6
		move.w	BillWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,BillWinH+4
		suba.l	a0,a0
		lea.l	BillWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,BillHandle(a4)
		beq.s	.BillWinError
		move.l	d0,a0
		moveq	#0,d0
		moveq	#1,d1
		move.l	wd_UserPort(a0),a0
		move.b	MP_SIGBIT(a0),d0
		lsl.l	d0,d1
		move.l	d1,BillSigFlag(a4)

		move.l	BillHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetBillGads

		tst.b	Zipped(a4)
		beq.s	.NoBillClose
		move.l	BillHandle(a4),a0
		RELLIB	ZipWindow,_IntuitionBase
		bsr	RemakeCosts
		bra.s	.NoBillClose

.BillWinError	bsr.s	CloseBillWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
.NoBillClose	bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                       Set bill window gadget                       *
**********************************************************************
SetBillGads	move.l	#GD_LogCall,d1			; Set LogCalls gadget
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		moveq	#0,d0
		move.b	LogCalls(a4),d0
		bsr	SetCheckBox

		move.l	#GD_BillTimeMX,d0
		move.l	TimeZone,d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetMXGad

		move.l	#GD_BillCheap,d0
		moveq	#0,d1
		move.b	CheapMode(a4),d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetMXGad
		rts


**********************************************************************
*                       Close the bill window                        *
**********************************************************************
CloseBillWin	lea	BillHandle(a4),a3
		bra	CloseNormWindow



**********************************************************************
*                      Open Preferences window                       *
**********************************************************************
OpenPrefsWin	tst.l	PrefsHandle(a4)
		beq.s	.GoOn
		move.l	PrefsHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.PrefsWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,PrefsVisInfo(a4)
		beq	.PrefsWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	PrefsWinWidth(a4),d2
		move.w	PrefsWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	PrefsWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	PrefsWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	PrefsGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.PrefsWinError

		lea	PrefsGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	PrefsVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#78*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#52*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#Normal1Text,gng_GadgetText(a1)
		move.w	#GD_Normal1,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#219*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#Cheap1Text,gng_GadgetText(a1)
		move.w	#GD_Cheap1,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#78*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#20*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#Normal2Text,gng_GadgetText(a1)
		move.w	#GD_Normal2,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#219*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#Cheap2Text,gng_GadgetText(a1)
		move.w	#GD_Cheap2,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#78*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#37*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#Normal3Text,gng_GadgetText(a1)
		move.w	#GD_Normal3,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#219*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#Cheap3Text,gng_GadgetText(a1)
		move.w	#GD_Cheap3,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#147*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#54*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#CostUnitText,gng_GadgetText(a1)
		move.w	#GD_CostUnit,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	Normal1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#181*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#71*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#90*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#StartNormText,gng_GadgetText(a1)
		move.w	#GD_StartNorm,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	StartNormTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#86*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#StartCheapText,gng_GadgetText(a1)
		move.w	#GD_StartCheap,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	StartNormTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#101*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#PopUpBillText,gng_GadgetText(a1)
		move.w	#GD_PopUpBill,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#116*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#83*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#ClearLogText,gng_GadgetText(a1)
		move.w	#GD_ClearLog,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#115*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#156*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#TotalSumText,gng_GadgetText(a1)
		move.w	#GD_TotalSum,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#132*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#157*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#OpenBillText,gng_GadgetText(a1)
		move.w	#GD_OpenBill,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	OpenBillTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#7*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#149*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#119*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#SaveLogText,gng_GadgetText(a1)
		move.w	#GD_SaveLog,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#131*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
 ;		  add.w	 d2,gng_LeftEdge(a1)
		move.l	#148*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.l	#141*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#14*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#LogNameText,gng_GadgetText(a1)
		move.w	#GD_LogName,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	LogNameTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#294*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#3*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#121*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.w	#GD_EverCheap,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	EverCheapTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#19*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#SaturdayText,gng_GadgetText(a1)
		move.w	#GD_Saturday,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#SundayText,gng_GadgetText(a1)
		move.w	#GD_Sunday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#49*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#MondayText,gng_GadgetText(a1)
		move.w	#GD_Monday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#64*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#TuesdayText,gng_GadgetText(a1)
		move.w	#GD_Tuesday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#79*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#WednesdayText,gng_GadgetText(a1)
		move.w	#GD_Wednesday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#94*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#ThursdayText,gng_GadgetText(a1)
		move.w	#GD_Thursday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#109*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#FridayText,gng_GadgetText(a1)
		move.w	#GD_Friday,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.PrefsWinError

		lea	PrefsGads(a4),a0
		bsr	SetStrIntGads

		move.l	PrefsGadget(a4),PrefsWinWG+4
		move.l	-4(a5),PrefsWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,PrefsWinL+4
		move.l	d3,PrefsWinT+4
		move.l	-4(a5),a0
		move.w	PrefsWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,PrefsWinW+4
		move.w	PrefsWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,PrefsWinH+4
		suba.l	a0,a0
		lea.l	PrefsWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,PrefsHandle(a4)
		beq.s	.PrefsWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#PREFSWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	PrefsHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetPrefsGads
		bsr	UnlockScreen
		unlk	a5
		rts
.PrefsWinError	bsr	ClosePrefsWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                      Set Preferences gadgets                       *
**********************************************************************
SetPrefsGads	lea	CostUnit1(a4),a3		; Remake these 6 cost gadgets
		moveq	#GD_Normal1,d7
		moveq	#5,d6
.RemakeCosts	move.l	d7,d0
		move.l	(a3)+,d1
		addq.l	#1,d7
		bsr.s	SetPrefsInteger
		dbf	d6,.RemakeCosts

		move.l	#GD_CostUnit,d0			; Remake cost/unit gad
		move.l	CostUnit(a4),d1
		bsr.s	SetPrefsInteger

		move.l	#GD_LogName,d0			; Remake Log-FileName
		lea	LogFileName(a4),a2
		bsr	SetStringGad

		move.l	#GD_OpenBill,d0			; Remake Public Screen Name
		lea	PubScreenName(a4),a2
		bsr	SetStringGad

		move.l	#GD_StartNorm,d0
		move.l	CheapStop(a4),d1
		bsr	SetSliderGad

		move.l	#GD_StartCheap,d0
		move.l	CheapStart(a4),d1
		bsr	SetSliderGad

		moveq	#0,d0
		move.b	BillPopUp(a4),d0
		move.l	#GD_PopUpBill,d1
		bsr.s	SetPrefsBox

		lea	Saturday(a4),a3
		moveq	#6,d7
		move.l	#GD_Saturday,d1
.Loop		move.b	(a3)+,d0
		bsr.s	SetPrefsBox
		addq.l	#1,d1
		dbf	d7,.Loop
		rts
SetPrefsInteger	lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		bra	SetIntegerGad
SetPrefsBox	lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		bra	SetCheckBox


**********************************************************************
*                      Close Preferences window                      *
**********************************************************************
ClosePrefsWin	lea	PrefsHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*                      Open Preferences window                       *
**********************************************************************
OpenLockWin	tst.l	LockHandle(a4)
		beq.s	.GoOn
		move.l	LockHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.LockWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,LockVisInfo(a4)
		beq	.LockWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	LockWinWidth(a4),d2
		move.w	LockWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	LockWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	LockWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	LockGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.LockWinError

		lea	LockGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	LockVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#116*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#64*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#395*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#14*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#WindowNameText,gng_GadgetText(a1)
		move.w	#GD_WindowName,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#12,d0
		lea.l	WindowNameTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0
		move.l	d0,WindowListGad+4

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#72*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#WindowListText,gng_GadgetText(a1)
		move.w	#GD_WindowList,gng_GadgetID(a1)
		move.l	#4,d0
		lea.l	WindowListTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#82*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#129*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#AddWindowText,gng_GadgetText(a1)
		move.w	#GD_AddWindow,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#249*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#SelectWindowText,gng_GadgetText(a1)
		move.w	#GD_SelectWindow,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	SelectWindowTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#382*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#DeleteWindowText,gng_GadgetText(a1)
		move.w	#GD_DeleteWindow,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	SelectWindowTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+
		tst.l	d0
		beq	.LockWinError

		lea	LockGads(a4),a0
		bsr	SetStrIntGads

		move.l	LockGadget(a4),LockWinWG+4
		move.l	-4(a5),LockWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,LockWinL+4
		move.l	d3,LockWinT+4
		move.l	-4(a5),a0
		move.w	LockWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,LockWinW+4
		move.w	LockWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,LockWinH+4
		suba.l	a0,a0
		lea.l	LockWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,LockHandle(a4)
		beq.s	.LockWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#LOCKWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	LockHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		move.w	#-1,SelWindow(a4)

		bsr	UnlockScreen
		unlk	a5
		rts
.LockWinError	bsr.s	CloseLockWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts



**********************************************************************
*                      Close Preferences window                      *
**********************************************************************
CloseLockWin	lea	LockHandle(a4),a3
		bra.s	CloseAWindow



**********************************************************************
*                    This part closes our window                     *
**********************************************************************
CloseAWindow	tst.l	(a3)
		beq.s	NoWindow2Close
		CALLSYS	Forbid				; Free all messages for that window
		move.l	(a3),a0
		move.l	wd_UserPort(a0),a0
		lea	MP_MSGLIST(a0),a0
		move.l	LH_HEAD(a0),a5
.Loop		move.l	a5,d0
		beq.s	.End
		lea	im_ExecMessage(a5),a0
		move.l	LN_SUCC(a5),-(sp)
		move.l	im_IDCMPWindow(a5),d0
		cmp.l	(a3),d0
		bne.s	.GoOn
		move.l	a5,a1
		DOLIB	Remove
		move.l	a5,a1
		DOLIB	ReplyMsg
.GoOn		move.l	(sp)+,a5
		bra.s	.Loop
.End		move.l	(a3),a0
		clr.l	wd_UserPort(a0)
		moveq	#0,d0
		RELLIB	ModifyIDCMP,_IntuitionBase
		CALLSYS	Permit
		move.l	(a3),a0
		RELLIB	CloseWindow,_IntuitionBase	; Close Window
NoWindow2Close	tst.l	4(a3)
		beq.s	GotNoGadgets
		move.l	4(a3),a0			; Free GadTools-Gadgets
		RELLIB	FreeGadgets,_GadToolsBase
GotNoGadgets	tst.l	8(a3)				; Free Visual-Info
		beq.s	NoVisInfo
		move.l	8(a3),a0
		RELLIB	FreeVisualInfo,_GadToolsBase
NoVisInfo	clr.l	(a3)				; Clear flags for later
		clr.l	4(a3)				; identification
		clr.l	8(a3)
		rts



**********************************************************************
*            Close down a window with a non-shared IDCMP             *
**********************************************************************
CloseNormWindow	tst.l	(a3)
		beq.s	.NoWindow
		move.l	(a3),a0
		RELLIB	CloseWindow,_IntuitionBase	; Close Window
.NoWindow	tst.l	4(a3)
		beq.s	.NoGadgets
		move.l	4(a3),a0			; Free GadTools-Gadgets
		RELLIB	FreeGadgets,_GadToolsBase
.NoGadgets	tst.l	8(a3)				; Free Visual-Info
		beq.s	.NoVisInfo
		move.l	8(a3),a0
		RELLIB	FreeVisualInfo,_GadToolsBase
.NoVisInfo	clr.l	(a3)				; Clear flags for later
		clr.l	4(a3)				; identification
		clr.l	8(a3)
		rts


**********************************************************************
*                    Close all remaining windows                     *
**********************************************************************
CloseWins	bsr	ClearTitleBar			; Clear title bar
		bsr	CloseClockWin			; Close clock window
		bsr	CloseLockWin			; Close control windows
		bsr	ClosePrefsWin
		bsr	CloseFormWin
		bsr	CloseFKeyWin
		bsr	CloseHotKeyWin
		bsr	CloseMouseWin
		bsr	CloseColsWin
		bsr	CloseBlankWin
		bsr	CloseCycleWin
		bsr	CloseAlarmWin
		bsr	CloseMiscWin
		bsr	CloseSetWin
		bsr	CloseMainWin
		rts



**********************************************************************
*                        Compare two strings                         *
**********************************************************************
StrCmp		moveq	#0,d0
		moveq	#0,d1
		movem.l	a0/a1,-(sp)			; Store pointers
.Loop		move.b	(a0)+,d0			; get chars
		move.b	(a1)+,d1
		tst.b	d0				; Source string ended ?
		beq.s	.EndSrc				; yep -> final check
		cmp.b	#$0a,d0				; a newline ?
		beq.s	.EndSrc				; yep -> final check
		or.b	#$20,d0				; make case-insensitive
		or.b	#$20,d1
		cmp.b	d0,d1				; equal ?
		bne.s	.Invalid
		dbf	d7,.Loop
		movem.l	(sp)+,a0/a1
		moveq	#0,d0
		rts
.Invalid	moveq	#1,d0				; Error flag
		movem.l	(sp)+,a0/a1
		rts
.EndSrc		cmp.b	d0,d1				; last chars equal ?
		bne.s	.Invalid			; Nope -> error
		moveq	#0,d0				; a ok
		movem.l	(sp)+,a0/a1
		rts


**********************************************************************
*               Compare two strings (case sensitive)                 *
**********************************************************************
StrCmp2		moveq	#0,d0
		moveq	#0,d1
		movem.l	a0/a1,-(sp)			; Store pointers
.Loop		move.b	(a0)+,d0			; get chars
		move.b	(a1)+,d1
		tst.b	d0				; Source string ended ?
		beq.s	.EndSrc				; yep -> final check
		cmp.b	#$0a,d0				; a newline ?
		beq.s	.EndSrc				; yep -> final check
		cmp.b	d0,d1				; equal ?
		bne.s	.Invalid
		dbf	d7,.Loop
		movem.l	(sp)+,a0/a1
		moveq	#0,d0
		rts
.Invalid	moveq	#1,d0				; Error flag
		movem.l	(sp)+,a0/a1
		rts
.EndSrc		cmp.b	d0,d1				; last chars equal ?
		bne.s	.Invalid			; Nope -> error
		moveq	#0,d0				; a ok
		movem.l	(sp)+,a0/a1
		rts

**********************************************************************
*                           Copy a string                            *
**********************************************************************
StrCpy		move.b	(a0)+,d0
		move.b	d0,(a1)+
		tst.b	d0
		beq.s	.End
		bra.s	StrCpy
.End		rts


**********************************************************************
*                          Concat 2 string                           *
**********************************************************************
StrCat		tst.b	(a1)+
		beq.s	.Loop
		bra	StrCat
.Loop		subq.l	#1,a1
		bra	StrCpy


**********************************************************************
*            Copy a string up to x chars or end of string            *
**********************************************************************
StrNCpy		move.b	(a0)+,d0
		move.b	d0,(a1)+
		tst.b	d0
		beq.s	.End
		dbf	d7,StrNCpy
.End		rts


**********************************************************************
*                      Calc length of a string                       *
**********************************************************************
StrLen		move.l	a0,-(sp)
		moveq	#0,d0
.Loop		tst.b	(a0)+
		beq.s	.End
		addq.w	#1,d0
		bne.s	.Loop
.End		move.l	(sp)+,a0
		rts





**********************************************************************
*                      Font-sensitive routines                       *
**********************************************************************
ComputeX	movem.l	d1/a0-a3/a6,-(sp)
		move.w	FontX(a5),d1
		bra.s   ComputeIt
ComputeY	movem.l d1/a0-a3/a6,-(sp)
		move.w  FontY(a5),d1
ComputeIt	ext.l   d1
		RELLIB  UMult32,_UtilityBase
		move.l  #FULL,d1
		DOLIB   UDivMod32
		movem.l (sp)+,d1/a0-a3/a6
		rts
ComputeFont	move.l	-4(a5),a0
		move.l	sc_Font(a0),a1
		move.l	a1,FontPtr(a5)
		move.w	ta_YSize(a1),d0
		move.w	d0,FontY(a5)
		moveq	#0,d1
		move.b	sc_WBorTop(a0),d1
		add.w	d1,d0
		addq.w	#1,d0
		move.w	d0,OffY(a5)
		lea.l	sc_RastPort(a0),a1
		lea.l	XStr,a0
		moveq	#1,d0
		movem.l	a3/a6,-(sp)
		RELLIB	TextLength,_GfxBase
		movem.l	(sp)+,a3/a6
		move.w	d0,FontX(a5)
		move.l	-4(a5),a0
		move.b	sc_WBorLeft(a0),d0
		ext.w	d0
		move.w	d0,OffX(a5)
		tst.w	d2
		beq.s	CompDone
		tst.w	d3
		beq.s	CompDone
		move.w	d2,d0
		move.w	#FRAC,d1
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		moveq	#0,d1
		move.b	sc_WBorRight(a0),d1
		add.w	d1,d0
		cmp.w	sc_Width(a0),d0
		bhi.s	UseTopaz
		move.w	d3,d0
		move.w	#FRAC,d1
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		moveq	#0,d1
		move.b	sc_WBorBottom(a0),d1
		add.w	d1,d0
		cmp.w	sc_Height(a0),d0
		bhi.s	UseTopaz
CompDone	rts
UseTopaz	lea.l	GadgetTxtAttr,a0
		move.l	a0,FontPtr(a5)
		move.w	#8,FontX(a5)
		move.w	#8,FontY(a5)
		rts



**********************************************************************
*                 Set a checkbox to specified value                  *
* D0 = Mode                                                          *
* D1 = Number of gadget                                              *
* A0 = Address of GadgetList                                         *
* A1 = Address of window                                             *
**********************************************************************
SetCheckBox	movem.l	RegsAll,-(sp)
		move.l	a1,d2
		beq.s	.End
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTCB_Checked,(a3)
		and.l	#$000000ff,d0
		move.l	d0,4(a3)			; Set tag state
		move.l	#TAG_DONE,8(a3)
		move.l	d1,d0
		bsr	GetGadgetPtr
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                  Set MX Gadget to specified value                  *
* D0 = Number of gadget                                              *
* D1 = Number of button to activate                                  *
* A0 = Address of GadgetList                                         *
* A1 = Address of window                                             *
* A2 = Address of tags                                               *
**********************************************************************
SetMXGad	movem.l	RegsAll,-(sp)
		move.l	a1,d2
		beq.s	.End
		and.l	#$000000ff,d0
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTMX_Active,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*              Set a cycle gadget to a specified value               *
* D0 = Number of gadget                                              *
* D1 = Number of active item                                         *
* A0 = Address of GadgetList                                         *
* A1 = Pointer to window                                             *
**********************************************************************
SetCycleGad	movem.l	RegsAll,-(sp)
		move.l	a1,d2
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTCY_Active,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*                Set the contents of a string gadget                 *
* D0 = Number of gadget                                              *
* A0 = Address of GadgetList                                         *
* A1 = Pointer to window                                             *
* A2 = Pointer to string                                             *
**********************************************************************
SetStringGad	movem.l	RegsAll,-(sp)
		move.l	a1,d2
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTST_String,(a3)
		move.l	a2,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts





**********************************************************************
*               Set the contents of an integer gadget                *
* D0 = Number of gadget                                              *
* D1 = New value                                                     *
* A0 = Address of GadgetList                                         *
* A1 = Pointer to window                                             *
**********************************************************************
SetIntegerGad	movem.l	RegsAll,-(sp)
		move.l	a1,d3
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTIN_Number,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*                        Set a slider gadget                         *
* D0 = GadgetNumber                                                  *
* D1 = New level                                                     *
* A0 = Pointer to GadList                                            *
* A1 = Pointer to window                                             *
**********************************************************************
SetSliderGad	movem.l	RegsAll,-(sp)
		move.l	a1,d5
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTSL_Level,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                   Set a TextGadget to new values                   *
* D0 = Number of gadget                                              *
* A0 = Pointer to gadget list                                        *
* A1 = Pointer to window                                             *
* A2 = Pointer to text                                               *
**********************************************************************
SetTextGad	movem.l	RegsAll,-(sp)
		move.l	a1,d1
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTTX_Text,(a3)
		move.l	a2,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts


**********************************************************************
*                       Set a palette gadget                         *
* D0 = GadgetNumber                                                  *
* D1 = Number of color                                               *
* A0 = Pointer to GadList                                            *
* A1 = Pointer to window                                             *
**********************************************************************
SetPaletteGad	movem.l	RegsAll,-(sp)
		move.l	a1,d5
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTPA_Color,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts


**********************************************************************
*                      Set a ListView gadget                         *
* D0 = GadgetNumber                                                  *
* D1 = Active item                                                   *
* D2 = Top item                                                      *
* A0 = Pointer to GadList                                            *
* A1 = Pointer to window                                             *
**********************************************************************
SetListViewGad	movem.l	RegsAll,-(sp)
		move.l	a1,d5
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-20
		lea	-20(a5),a3
		ext.l	d1
		ext.l	d2
		move.l	#GTLV_Selected,(a3)
		move.l	d1,4(a3)
		move.l	#GTLV_Top,8(a3)
		move.l	d2,12(a3)
		move.l	#TAG_DONE,16(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                      Set a ListView gadget                         *
* D0 = GadgetNumber                                                  *
* A0 = Pointer to GadList                                            *
* A1 = Pointer to window                                             *
* A2 = New list                                                      *
**********************************************************************
SetListViewLst	movem.l	RegsAll,-(sp)
		move.l	a1,d5
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GTLV_Labels,(a3)
		move.l	a2,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts





**********************************************************************
*                           Ghost a gadget                           *
* D0 = Number of gadget                                              *
* D1 = State                                                         *
* A0 = Pointer to gadgetlist                                         *
* A1 = Pointer to window                                             *
**********************************************************************
GhostGadget	movem.l	RegsAll,-(sp)
		move.l	a1,d2
		beq.s	.End
		bsr	GetGadgetPtr
		link	a5,#-12
		lea	-12(a5),a3
		move.l	#GA_Disabled,(a3)
		move.l	d1,4(a3)
		move.l	#TAG_DONE,8(a3)
		sub.l	a2,a2
		RELLIB	GT_SetGadgetAttrsA,_GadToolsBase
		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*           Store new position of window within NewWindow            *
**********************************************************************
StoreWinPos	move.w	wd_LeftEdge(a0),0(a1)
		move.w	wd_TopEdge(a0),2(a1)
		rts



**********************************************************************
*               Give visual feedback for button press                *
* D0 = Number of gadget                                              *
* A0 = Pointer to first gadget                                       *
* A5 = Pointer to window                                             *
**********************************************************************
ButtonCheck	movem.l	RegsAll,-(sp)
		move.l	a5,d1
		beq.s	.End
		bsr	GetGadgetPtr
		move.l	a0,a3
		move.l	a0,a1
		or.w	#GFLG_SELECTED,gg_Flags(a3)
		move.l	a3,a0
		move.l	a5,a1
		sub.l	a2,a2
		moveq	#1,d0
		RELLIB	RefreshGList,_IntuitionBase
		move.l	#5,d1
		RELLIB	Delay,_DOSBase
		and.w	#~GFLG_SELECTED,gg_Flags(a3)
		move.l	a3,a0
		move.l	a5,a1
		sub.l	a2,a2
		moveq	#1,d0
		RELLIB	RefreshGList,_IntuitionBase
.End		movem.l	(sp)+,RegsAll
		rts


**********************************************************************
*                      Activate a string gadget                      *
* D0 = Number of gadget                                              *
* A0 = Pointer to GadgetList                                         *
* A1 = Pointer to Window                                             *
**********************************************************************
ActStringGad	movem.l	RegsAll,-(sp)
		move.l	a1,d1
		beq.s	.End
		bsr.s	GetGadgetPtr
		sub.l	a2,a2
		RELLIB	ActivateGadget,_IntuitionBase
		movem.l	(sp)+,RegsAll
.End		rts


**********************************************************************
*                   Get address of selected entry                    *
* D0 = Number of entry                                               *
* A1 = Address of entry or NULL                                      *
**********************************************************************
GetEntry	movem.l	d1-d7/a2-a6,-(sp)
		lea	WindowBase(a4),a0
		SUCC	a0,a0
		sub.l	a1,a1
		tst.w	d0
		blt.s	.Done
.Loop		TSTLST2	a0,a2
		beq.s	.Done
		tst.w	d0
		beq.s	.GotIt
		move.l	a0,d1
		beq.s	.Done
		SUCC	a0,a0
		subq.w	#1,d0
		bra.s	.Loop
.GotIt		move.l	a0,a1
.Done		movem.l	(sp)+,d1-d7/a2-a6
		rts


**********************************************************************
*                      Get Address of a gadget                       *
* D0 = Number of gadget                                              *
* A0 = Pointer to first gadget                                       *
**********************************************************************
GetGadgetPtr	lsl.l	#2,d0
		move.l	0(a0,d0),a0
		rts




**********************************************************************
*                 String/Integer Gadget pens setten                  *
**********************************************************************
SetStrIntGads	movem.l	RegsAll,-(sp)

.Loop		move.l	(a0),d0
		beq.s	.End
		move.l	(a0)+,a1
		move.w	gg_GadgetType(a1),d0
		and.w	#GTYP_STRGADGET,d0
		beq.s	.NoStrGad
		move.l	gg_SpecialInfo(a1),a1
		move.l	si_Extension(a1),a1
		move.w	#$0102,sex_ActivePens(a1)
.NoStrGad	bra.s	.Loop
.End		movem.l	(sp)+,RegsAll
		rts





**********************************************************************
*                     Lock the Workbench-Screen                      *
**********************************************************************
LockScreen	lea	WBScrName(pc),a0
		RELLIB	LockPubScreen,_IntuitionBase
		move.l	d0,-4(a5)
		rts
WBScrName	dc.b	"Workbench",0
		EVEN


**********************************************************************
*                      Unlock the locked screen                      *
**********************************************************************
UnlockScreen	tst.l	-4(a5)
		beq.s	.End
		sub.l	a0,a0
		move.l	-4(a5),a1
		RELLIB	UnlockPubScreen,_IntuitionBase
.End		rts





**********************************************************************
*                         Lock our semaphore                         *
**********************************************************************
GetSemaphore	movem.l	a0/a6,-(sp)
		lea	ZeroPage,a0
		lea	MySemaphore(a0),a0
		CALLSYS	ObtainSemaphore
		movem.l	(sp)+,a0/a6
		rts




**********************************************************************
*                       Unlock semaphore again                       *
**********************************************************************
FreeSemaphore	movem.l	a0/a6,-(sp)
		lea	ZeroPage,a0
		lea	MySemaphore(a0),a0
		CALLSYS	ReleaseSemaphore
		movem.l	(sp)+,a0/a6
		rts



**********************************************************************
*                   Open clock window. Width in D6                   *
**********************************************************************
OpenClockWin	add.w	#DEPTHWIDTH*2+8,d6		; approximate width of close/depth gadgets
		ext.l	d6
		move.l	d6,ClockWidth			; Store for compare

		tst.l	ClockHandle(a4)			; Window already open ?
		bne.s	ClockWinOpen

		bsr	ClearTitleBar			; Clear titlebar first

		link	a5,#-4
		bsr	LockScreen
		tst.l	d0
		beq	ClockError

		sub.l	a0,a0				; Open clock window
		move.l	-4(a5),a1
		moveq	#0,d1
		move.b	sc_WBorTop(a1),d1
		moveq	#0,d0
		moveq	#0,d1
		move.w	ClockWinLeft(a4),d0
		move.w	ClockWinTop(a4),d1
		move.l	d0,ClockLeft
		move.l	d1,ClockTop
		lea	ClockWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,ClockHandle(a4)
		tst.l	d0
		bne.s	GotClockWin
		clr.b	ClockWin(a4)			; On failure close
		moveq	#0,d0				; disable clockwin mode
		move.l	#GD_DisplayWin,d1
		bsr	SetMiscBox
		bra.s	ClockError
GotClockWin	move.l	ClockHandle(a4),a0		; Get sig flag
		moveq	#0,d0
		move.l	wd_UserPort(a0),a0
		move.b	MP_SIGBIT(a0),d0
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,ClockSigFlag(a4)
		bsr	UnlockScreen
		unlk	a5
ClockWinOpen	move.l	ClockHandle(a4),a0		; Current width not equal
		moveq	#0,d0				; to width needed
		moveq	#0,d1
		moveq	#0,d2
		moveq	#0,d3
		move.w	wd_LeftEdge(a0),d0
		move.w	wd_TopEdge(a0),d1
		move.l	ClockWidth,d2
		cmp.w	wd_Width(a0),d2
		beq.s	CWidthOk
		moveq	#0,d3
		move.b	wd_BorderTop(a0),d3
		RELLIB	ChangeWindowBox,_IntuitionBase	; so readjust width
		bsr	ClockRemake			; Wait until window has been remade
CWidthOk	moveq	#1,d0
		rts
ClockError	bsr	UnlockScreen
		moveq	#0,d0
		unlk	a5
		rts



**********************************************************************
*                Close clockwindow and remove pointer                *
**********************************************************************
CloseClockWin	tst.l	ClockHandle(a4)
		beq.s	NoCWOpen
		move.l	ClockHandle(a4),a0		; Store new coords in structure
		RELLIB	CloseWindow,_IntuitionBase	; and now....CLOSE IT
NoCWOpen	clr.l	ClockHandle(a4)
		clr.l	ClockSigFlag(a4)
		rts




**********************************************************************
*        Display the correct time for the two slider gadgets         *
**********************************************************************
ShowTime	movem.l	d1-d7/a0-a6,-(sp)
		link	a5,#-8				; Get buffer for variables
		move.l	68(a5),d0			; Get number
		lea	ZeroPage,a4			; Recalculate
		divu	#6,d0
		move.w	d0,d1
		swap	d0
		and.l	#$0000ffff,d0
		and.l	#$0000ffff,d1
		mulu	#10,d0
		move.l	d1,-8(a5)
		move.l	d0,-4(a5)
		lea	FormLongNSStr,a0		; Format
		lea	-8(a5),a1
		lea	PutChProc,a2
		lea	HourStr(a4),a3
		CALLSYS	RawDoFmt
		lea	HourStr(a4),a0
		move.l	a0,d0
		unlk	a5
		movem.l	(sp)+,d1-d7/a0-a6
		rts


**********************************************************************
*                         Display alarm time                         *
**********************************************************************
ShowAlarm	movem.l	d1-d7/a0-a6,-(sp)
		link	a5,#-8				; Get buffer for variables
		move.l	68(a5),d0			; Get number
		lea	ZeroPage,a4			; Recalculate
		divu	#60,d0
		move.w	d0,d1
		swap	d0
		and.l	#$0000ffff,d0
		and.l	#$0000ffff,d1
		move.l	d1,-8(a5)
		move.l	d0,-4(a5)
		lea	FormLongNSStr,a0		; Format
		lea	-8(a5),a1
		lea	PutChProc,a2
		lea	HourStr(a4),a3
		CALLSYS	RawDoFmt
		lea	HourStr(a4),a0
		move.l	a0,d0
		unlk	a5
		movem.l	(sp)+,d1-d7/a0-a6
		rts


**********************************************************************
*          This is the routine to handle RAW-Event actions           *
**********************************************************************
RawEventAction	movem.l	RegsAll,-(sp)

		move.l	a1,a4
		bsr	GetSemaphore

		move.l	a0,IEvent(a4)

EventLoop	move.l	IEvent(a4),a0
		moveq	#0,d0
		move.b	ie_Class(a0),d0
		move.w	d0,IEClass(a4)			; Store class

		tst.b	Disabled(a4)
		bne	NoTimerEvent

		tst.b	LeftyMouse(a4)			; We have to swap Buttonqualifiers
		beq.s	.NoLeftyAll			; for every message if needed
		move.w	ie_Qualifier(a0),d0		; Change qualifiers for all events
		move.w	d0,d1
		btst	#IEQUALIFIERB_RBUTTON,d1
		beq.s	.NoRight
		bset	#IEQUALIFIERB_LEFTBUTTON,d0
		beq.s	.CheckLeft
.NoRight	bclr	#IEQUALIFIERB_LEFTBUTTON,d0
.CheckLeft	btst	#IEQUALIFIERB_LEFTBUTTON,d1
		beq.s	.NoLeft
		bset	#IEQUALIFIERB_RBUTTON,d0
		beq.s	.SaveQual
.NoLeft		bclr	#IEQUALIFIERB_RBUTTON,d0
.SaveQual	move.w	d0,ie_Qualifier(a0)

.NoLeftyAll	cmp.w	#IECLASS_RAWKEY,IEClass(a4)
		beq.s	.DoSpec
		cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)
		bne	NoSpec

.DoSpec		move.l	IEvent(a4),a0
		bsr	ResetTimer

		tst.b	LeftyMouse(a4)
		beq.s	.CheckCycle

		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	d0,d1
		and.w	#~IECODE_UP_PREFIX,d0
		cmp.w	#IECODE_LBUTTON,d0
		beq.s	.SwapThem
		cmp.w	#IECODE_RBUTTON,d0
		bne.s	.CheckCycle
.SwapThem	eor.w	#1,d1
		move.w	d1,ie_Code(a0)

.CheckCycle	cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)	; Mouse movement ?
		bne.s	.NoHold
		move.l	IEvent(a4),a2
		move.w	ie_Qualifier(a2),d1
		move.w	d1,d0
		and.w	HoldXQual(a4),d0		; Hold qualifier pressed ?
		cmp.w	HoldXQual(a4),d0
		bne.s	.NoVertHold
		clr.w	ie_X(a2)			; Clear delta-movement
.NoVertHold	and.w	HoldYQual(a4),d1
		cmp.w	HoldYQual(a4),d1
		bne.s	.NoHold
		clr.w	ie_Y(a2)

.NoHold		tst.b	GfxGetting(a4)			; Printer process getting new area ?
		beq.s	.NoGfxGetting
		cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)
		bne.s	.NoGfxGetting
		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	ie_Qualifier(a0),d1
		move.w	d1,d3
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	#IECODE_LBUTTON,d0
		beq.s	.LButton
		cmp.w	#IECODE_RBUTTON,d0
		beq.s	.RButton
		tst.w	d0
		move.l	#SIGMOUSE,d0
		bra.s	.SendSig2
.LButton	move.l	#SIGLBUTTON,d0
		bra.s	.SendSig
.RButton	move.l	#SIGRBUTTON,d0
.SendSig	move.b	#IECLASS_NULL,ie_Class(a0)
.SendSig2	move.l	PrintProc(a4),a1
		CALLSYS	Signal
		bra	NoTimerEvent

.NoGfxGetting	tst.b	ImDragging(a4)
		beq.s	.NoDragging
		cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)
		bne.s	.NoDragging
		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	ie_Qualifier(a0),d1
		move.w	d1,d3
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	#IECODE_LBUTTON|IECODE_UP_PREFIX,d0
		bne.s	.NoButton
		move.l	#SIGLBUTTON,d0
		bra.s	.SigDrag
.NoButton	move.l	#SIGMOUSE,d0
.SigDrag	move.l	OurTask(a4),a1
		CALLSYS	Signal
		bra	NoTimerEvent

.NoDragging	tst.b	GetNewWindow(a4)
		beq.s	.NoNewWin
		cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)
		bne.s	.NoDragging
		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	ie_Qualifier(a0),d1
		move.w	d1,d3
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	#IECODE_LBUTTON,d0
		bne.s	.NoNewWin
		move.l	#SIGLBUTTON,d0
		move.l	OurTask(a4),a1
		CALLSYS	Signal
		bra	NoTimerEvent

.NoNewWin	tst.b	CycleWin(a4)			; Are we to cycle windows ?
		beq	.NoCycle
		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	ie_Qualifier(a0),d1
		move.w	d1,d3
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	BackCode(a4),d0			; Check for Back key
		bne.s	.NotBack
		cmp.w	BackQual(a4),d1
		bne.s	.NotBack
		cmp.w	#1,BackClicks(a4)
		beq.s	.IsFront
		cmp.w	#1,ThisBackClick(a4)
		bne	.EndCycle
		bra.s	.IsFront
.NotBack	cmp.w	#IECODE_MBUTTON,d0
		bne.s	.NotMiddle
		cmp.w	MiddleQual(a4),d1
		bne.s	.NotMiddle
		cmp.w	#1,MiddleClicks(a4)
		beq.s	.IsFront
		cmp.w	#1,ThisMiddleClick(a4)
		bne.s	.EndCycle
		bra.s	.IsFront
.NotMiddle	cmp.w	FrontCode(a4),d0		; Check for Front key
		bne.s	.EndCycle
		cmp.w	FrontQual(a4),d1
		bne.s	.EndCycle
		cmp.w	#1,FrontClicks(a4)
		beq.s	.IsFront
		cmp.w	#1,ThisFrontClick(a4)
		bne.s	.EndCycle
.IsFront	cmp.w	#IECODE_RBUTTON,d0
		beq.s	.Clear
		cmp.w	#IECODE_MBUTTON,d0
		bne.s	.EndCycle
.Clear		move.b	#IECLASS_NULL,ie_Class(a0)	; Clear event
		and.w	#IEQUALIFIER_LEFTBUTTON,d3	; Left button pressed
		beq.s	.EndCycle
		move.l	ie_EventAddress(a0),d2		; WB windows won`t take this combination
		link	a5,#-ie_SIZEOF
		lea	-ie_SIZEOF(a5),a0
		clr.l	ie_NextEvent(a0)		; Send LeftButtonUp, so that
		move.b	#IECLASS_RAWMOUSE,ie_Class(a0)
		clr.b	ie_SubClass(a0)
		move.w	#IECODE_LBUTTON|IECODE_UP_PREFIX,ie_Code(a0)
		clr.w	ie_Qualifier(a0)
		move.l	d2,ie_EventAddress(a0)
		LNKLIB	AddIEvents,_CxBase		; Add events
		unlk	a5
.EndCycle	move.l	IEvent(a4),a0
		move.l	#REQ_CYCLE,d0
		bsr	SendEvent

.NoCycle	tst.b	FullDrag(a4)
		beq.s	NoSpec
		move.l	IEvent(a4),a0
		move.w	ie_Code(a0),d0
		move.w	ie_Qualifier(a0),d1
		move.w	d1,d3
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		cmp.w	#IECODE_LBUTTON,d0
		bne.s	NoSpec
		cmp.w	FullDragQual(a4),d1
		bne.s	NoSpec
		move.l	OurTask(a4),a1
		move.l	DragSigFlag(a4),d0
		CALLSYS	Signal
		move.l	IEvent(a4),a0
		move.b	#IECLASS_NULL,ie_Class(a0)

NoSpec		cmp.w	#IECLASS_DISKINSERTED,IEClass(a4)
		bne.s	NoDiskEvent
		tst.b	WatchDisks(a4)
		beq	NoTimerEvent
		move.l	IEvent(a4),a0
		move.l	#REQ_DISKCHANGE,d0
		bsr	SendEvent
		bra	NoTimerEvent

NoDiskEvent	cmp.w	#IECLASS_RAWMOUSE,IEClass(a4)	; Mouse moved ???
		bne	NoRawMouse

		tst.b	ShowMouse(a4)
		beq.s	.NoMouse
		bsr	SigTime

.NoMouse	move.l	IEvent(a4),a0			; Get current micro seconds
		lea	ie_TimeStamp(a0),a0		; so that checking of stopped
		move.l	TV_MICRO(a0),OldCheckMicro(a4)	; mouse takes the same amount of time

		tst.b	MMBShift(a4)
		beq.s	.NoMMBShift
		move.l	IEvent(a4),a0
		cmp.w	#IECODE_LBUTTON,ie_Code(a0)
		bne.s	.NoMMBShift
		move.w	ie_Qualifier(a0),d0
		move.w	d0,d1
		and.w	#IEQUALIFIER_MIDBUTTON,d0
		beq.s	.NoMMBShift
		and.w	#~IEQUALIFIER_MIDBUTTON,d1
		or.w	#IEQUALIFIER_LSHIFT,d1
		move.w	d1,ie_Qualifier(a0)

.NoMMBShift	tst.b	MouseAccel(a4)			; Accelerate mouse ?
		beq.s	.NoYAcc
		move.l	IEvent(a4),a3
		move.w	ie_X(a3),d4			; Get current X Position of mouse
		ext.l	d4
		moveq	#1,d5				; Get direction to be moved
		tst.l	d4
		bge.s	.XBig
		neg.l	d4				; Make position positive
		moveq	#-1,d5				; And invert direction
.XBig		cmp.l	ThresHold(a4),d4		; Check for threshold
		ble.s	.NoXAcc
		move.l	d4,d0
		sub.l	ThresHold(a4),d0		; Sub threshold
		subq.l	#1,d0
		move.l	Accelerate(a4),d1		; Accelerate
		RELLIB	SMult32,_UtilityBase
		add.l	ThresHold(a4),d0		; Add threshold
		addq.l	#1,d0
		move.l	d5,d1				; Now for the direction
		DOLIB	SMult32
		move.w	d0,ie_X(a3)

.NoXAcc		move.w	ie_Y(a3),d4			; Do the same for Y Position
		ext.l	d4
		moveq	#1,d5
		tst.l	d4
		bge.s	.YBig
		neg.l	d4
		moveq	#-1,d5
.YBig		cmp.l	ThresHold(a4),d4		; Check for threshold
		ble.s	.NoYAcc
		move.l	d4,d0
		sub.l	ThresHold(a4),d0		; Sub threshold
		subq.l	#1,d0
		move.l	Accelerate(a4),d1		; Acceleration
		RELLIB	SMult32,_UtilityBase
		add.l	ThresHold(a4),d0		; Add threshold
		addq.l	#1,d0
		move.l	d5,d1
		DOLIB	SMult32
		move.w	d0,ie_Y(a3)

.NoYAcc		tst.b	DoActivate(a4)			; Activation of Windows ?
		beq	.End1
		tst.b	SunMouse(a4)			; MousMode active ?
		beq	.End1
		move.l	IEvent(a4),a0			; Get current event
		move.w	ie_Code(a0),d0
		cmp.w	#IECODE_NOBUTTON,d0		; Any button pressed ?
		bne.s	.End1				; Yep -> no activation
		move.w	ie_Qualifier(a0),d0		; Any button pressed ?
		and.w	#(IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_RBUTTON|IEQUALIFIER_MIDBUTTON),d0
		bne.s	.End1				; No activation
		move.l	_IntuitionBase(a4),a6
		move.w	ib_MouseX(a6),d0		; Get current mouse-position
		move.w	ib_MouseY(a6),d1
		move.w	OldX(a4),d2
		move.w	OldY(a4),d3
		tst.w	d2
		blt.s	.NoEnd1
		sub.w	d0,d2
		bge.s	.XPos
		neg.w	d2
.XPos		cmp.w	#15,d2
		bgt.s	.End1
		sub.w	d1,d3
		bge.s	.YPos
		neg.w	d3
.YPos		cmp.w	#15,d3
		bgt.s	.End1
.NoEnd1		move.w	d0,OldX(a4)			; Store new one
		move.w	d1,OldY(a4)
		bsr	FindWindow
		tst.l	d0
		beq.s	.End1
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.End1
		move.l	_IntuitionBase(a4),a0
		cmp.l	ib_ActiveWindow(a0),d0
		beq.s	.End1
		move.l	ib_ActiveWindow(a0),a0
		bsr	CheckWinGads
		move.l	a0,d0
		beq.s	.End1
		move.l	IEvent(a4),a0
		move.l	#REQ_ACTIVATE,d0
		bsr	SendEvent

.End1		tst.b	ScrTimeOut(a4)
		beq.s	.NoScr
		bsr	OnScreen			; Activate screen if not blanked
.NoScr		clr.b	ScrTimeOut(a4)			; out anymore
		clr.b	MouseTimeOut(a4)
		bsr	OnMouse
		bra	NoTimerEvent

NoRawMouse	cmp.w	#IECLASS_RAWKEY,IEClass(a4)	; Key pressed ???
		bne	NoRawKey

		move.l	IEvent(a4),a1			; If key released -> break
		move.w	ie_Code(a1),d0
		and.w	#IECODE_UP_PREFIX,d0
		bne	NoTimerEvent

		move.w	ie_Qualifier(a1),d0
		and.w	#IEQUALIFIER_LCOMMAND,d0
		beq.s	.NoLAmiga
		move.l	_IntuitionBase(a4),a0
		cmp.w	#$37,ie_Code(a1)
		bne.s	.NoM
		clr.b	ie_Class(a1)
		move.l	#REQ_SCRBACK,d0
		bsr	SendEvent
		bra.s	.NoLAmiga
.NoM		cmp.w	#$36,ie_Code(a1)
		bne.s	.NoLAmiga
		clr.b	ie_Class(a1)
		move.l	#REQ_WBFRONT,d0
		bsr	SendEvent

.NoLAmiga	tst.b	KeyClick(a4)			; Enabled Key-Click ?
		beq	.NoClickYet
		link	a5,#-128
		move.l	IEvent(a4),a0			; Convert RAW-Key
		lea	-128(a5),a1
		clr.b	(a1)				; Clear previous keys
		move.l	#127,d1
		sub.l	a2,a2
		RELLIB	RawKeyConvert,_ConsoleBase	; Convert raw key
		lea	-128(a5),a1
		move.b	(a1),d0
		unlk	a5
		tst.b	d0				; No keys ?
		beq	.NoClickYet
		cmp.b	#$9b,d0				; Initial ANSI-Code
		beq	.NoClickYet			; No click
		cmp.b	#$09,d0				; TAB-Key pressed ?
		beq	.NoClickYet

		move.l	IEvent(a4),a1			; Let it click
		tst.w	ie_Code(a1)
		beq	.NoClickYet

		lea	AudioName(pc),a0		; Try to open device and
		moveq	#0,d0				; allocate a channel
		move.l	AudioReq(a4),a1
		move.w	#ADCMD_ALLOCATE,IO_COMMAND(a1)
		move.b	#ADIOF_NOWAIT,IO_FLAGS(a1)
		clr.w	ioa_AllocKey(a1)
		move.l	#AnyChannel,ioa_Data(a1)
		move.l	#4,ioa_Length(a1)
		move.l	AudioPort(a4),MN_REPLYPORT(a1)
		move.b	#-50,LN_PRI(a1)
		moveq	#0,d1				; suggested by UISG
		CALLSYS	OpenDevice
		tst.l	d0
		beq.s	.NoError
		moveq	#0,d0				; Disable
		move.b	d0,KeyClick(a4)			; ... the click function
		move.l	#GD_KeyClick,d1			; and the gadget tick
		bsr	SetMiscBox
		bra.s	.NoClickYet
.NoError	move.l	AudioReq(a4),a1			; Let`s hear it for the click
		move.w	#CMD_WRITE,IO_COMMAND(a1)
		move.b	#ADIOF_PERVOL,IO_FLAGS(a1)
		move.w	#400,ioa_Period(a1)		; 150
		move.l	ClickVol(a4),d0
		move.w	d0,ioa_Volume(a1)
		move.l	#CLICKLEN,ioa_Length(a1)
		move.l	#ClickData,ioa_Data(a1)
		move.w	#1,ioa_Cycles(a1)
		move.l	AudioPort(a4),MN_REPLYPORT(a1)
		move.b	#-50,LN_PRI(a1)
		move.l	IO_DEVICE(a1),a6
		jsr	DEV_BEGINIO(a6)
.WaitClick	move.l	AudioReq(a4),a1			; Wait until request is finished
		CALLSYS	CheckIO
		tst.l	d0
		beq.s	.WaitClick
		move.l	 AudioReq(a4),a1		; Close device again and
		DOLIB	CloseDevice			; free channels

.NoClickYet	tst.b	DoActivate(a4)
		beq.s	.CheckMouseOff
		tst.b	SunMouse(a4)
		bne.s	.CheckMouseOff
		bsr	FindWindow
		tst.l	d0
		beq.s	.CheckMouseOff
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.CheckMouseOff
		move.l	_IntuitionBase(a4),a0
		cmp.l	ib_ActiveWindow(a0),d0
		beq.s	.CheckMouseOff
		move.l	ib_ActiveWindow(a0),a0
		bsr	CheckWinGads
		move.l	a0,d0
		beq.s	.CheckMouseOff
		move.l	IEvent(a4),a0
		move.l	#REQ_ACTIVATE,d0
		bsr	SendEvent
		move.l	IEvent(a4),a0
		clr.b	ie_Class(a0)
		bra.s	.End1

.CheckMouseOff	tst.b	MouseEver(a4)			; Blank mouse ?
		beq.s	.End1
		move.l	MBlankWindow(a4),d0
		move.l	_IntuitionBase(a4),a0
		cmp.l	ib_ActiveWindow(a0),d0
		beq.s	.End1
		jsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		jsr	OffMouse			; On key-press allways blank mouse

.End1		tst.b	ScrTimeOut(a4)			; Screen blanked ?
		beq.s	.NoScr
		move.l	IEvent(a4),a0
		lea	ie_TimeStamp(a0),a0		; Reset screen delay
		move.l	TV_SECS(a0),d0
		add.l	ScreenTime(a4),d0
		move.l	d0,ScreenOff(a4)
		clr.b	ScrTimeOut(a4)			; Screen timed out
		tst.l	DimmBase(a4)
		bne.s	.NotDimmed
		move.l	IEvent(a4),a0			; Only kill char if not dimmed
		move.b	#IECLASS_NULL,ie_Class(a0)
.NotDimmed	bsr	OnScreen			; UnBlank it

.NoScr		tst.b	FKeysOn(a4)			; FKeys enabled ?
		beq	.NoFKeys
		move.l	IEvent(a4),a1
		move.w	ie_Code(a1),d0
		cmp.w	#$50,d0
		blt	.NoFKeys
		cmp.w	#$59,d0
		bgt	.NoFKeys
		move.w	ie_Qualifier(a1),d1
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		jsr	FilterDouble
		moveq	#0,d7
		moveq	#3,d6
		lea	FKeyQualFlags,a0
.CheckQual	cmp.w	(a0)+,d1
		beq.s	.GotQual
		cmp.w	(a0)+,d1
		beq.s	.GotQual
		add.l	#(MAXFKEYWIDTH+2)*10,d7
		dbf	d6,.CheckQual
		bra	.NoFKeys
.GotQual	lea	FKeys(a4),a0
		lea	0(a0,d7),a0
		sub.w	#$50,d0
		mulu	#(MAXFKEYWIDTH+2),d0
		lea	0(a0,d0.w),a0
		lea	FKeyCmds,a2			; Check for any commands entered
		lea	FKeyRouts,a3
		move.w	#FKEYCMDNUM-1,d6
.CheckCmds	move.l	(a2)+,a1
		moveq	#-1,d7
		bsr	StrCmp2
		tst.l	d0
		bne.s	.NoCmd
		move.l	(a3),a3
		jsr	(a3)
		bra	.NoFKeys
.NoCmd		addq.l	#4,a3
		dbf	d6,.CheckCmds
		clr.l	-(a7)
		move.l	a0,-(a7)
		jsr	_InvertString			; Invert String "inverts" the string
		addq.l	#8,sp				; but we can`t simply reverse the string
		tst.l	d0				; otherwise all special codes will get lost
		beq	.NoFKeys			; so we flip the list of events now
		move.l	d0,a0
		move.l	d0,a5				; Store pointer to events
		moveq	#4,d0				; Calc number of events
.Loop		tst.l	ie_NextEvent(a0)
		beq.s	.Done
		addq.l	#4,d0
		move.l	ie_NextEvent(a0),a0
		bra.s	.Loop
.Done		move.l	d0,d7
		lsr.l	#2,d7				; Alloc table for pointers
		move.l	#MEMF_PUBLIC|MEMF_CLEAR,d1
		CALLSYS	AllocVec
		tst.l	d0
		beq.s	.NoTable
		move.l	a5,a0				; Copy adresses of events
		move.l	d0,a3
		move.l	d0,a1
		move.l	d7,d0
		subq.w	#1,d0
.CopyPtrs	move.l	a0,(a1)+			; Store all addresses of events
		move.l	ie_NextEvent(a0),a0		; within table
		dbf	d0,.CopyPtrs
		move.l	a3,a0				; Remake pointers
		subq.w	#1,d7				; sub one
		move.l	d7,d0
		lsl.l	#2,d0				; Calc offset
		lea	0(a0,d0),a0			; a0 points to end of list
		move.l	(a0),a5				; Get address of "last" event
		subq.w	#1,d7				; sub one for loop
		blt.s	.OnlyOne			; Ok -> There only way one
.Remake		move.l	(a0),a1				; Get address of event
		move.l	-4(a0),ie_NextEvent(a1)		; Create link to previous one
		subq.l	#4,a0				; Next event
		dbf	d7,.Remake
.OnlyOne	move.l	(a0),a0				; Get last event
		clr.l	ie_NextEvent(a0)		; Clear old link
		move.l	a5,a0				; Add events
		LNKLIB	AddIEvents,_CxBase
		move.l	IEvent(a4),a0
		move.b	#IECLASS_NULL,ie_Class(a0)
.NoEvents	move.l	a3,a1				; Free table
		CALLSYS	FreeVec
.NoTable	move.l	a5,-(sp)			; Free events
		jsr	_FreeIEvents
		addq.l	#4,sp

.NoFKeys	tst.b	ESCClose(a4)			; Allow closing of windows
		beq	.NoEscape			; via ESC-Key ???
		move.l	IEvent(a4),a1
		cmp.w	#RESCKEY,ie_Code(a1)
		bne.s	.NoEscape
		move.w	ie_Qualifier(a1),d1
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		move.w	#RESCKEY,d0
		jsr	FilterDouble
		cmp.w	ESCQual(a4),d1
		bne.s	.NoEscape
		bsr	FindWindow			; Find window underneith mouse
		tst.l	d0				; No layer -> no close
		beq.s	.NoEscape
		move.l	d0,a0
		move.l	lr_Window(a0),a3		; Not a window-layer ???
		move.l	a3,d0
		beq.s	.NoEscape			; Yep -> no close
		move.l	wd_Flags(a3),d0			; Window has a closegadget ?
		and.l	#WFLG_CLOSEGADGET,d0
		beq.s	.NoEscape			; Nope -> go on
		tst.l	wd_FirstRequest(a3)		; Requester visible ???
		bne.s	.NoEscape
		cmp.l	ActWindow(a4),a3
		beq.s	.IsAct
		move.l	a3,a0				; Only active windows can be closed
		RELLIB	ActivateWindow,_IntuitionBase
.IsAct		link	a5,#-ie_SIZEOF
		lea	-ie_SIZEOF(a5),a0		; fill in Event structure
		clr.l	ie_NextEvent(a0)
		move.b	#IECLASS_CLOSEWINDOW,ie_Class(a0)
		clr.b	ie_SubClass(a0)
		clr.w	ie_Code(a0)
		clr.w	ie_Qualifier(a0)
		clr.l	ie_EventAddress(a0)
		LNKLIB	AddIEvents,_CxBase		; Add event
		unlk	a5
		bra	NoTimerEvent

.NoEscape	tst.b	MapUmlaut(a4)			; Map "Umlauts" ?
		beq	.NoUmlaut
		move.l	IEvent(a4),a1			; Check for "Umlauts"
		move.w	ie_Qualifier(a1),d1		; Only accept plain and shifted keys
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_MULTIBROADCAST),d1
		move.w	d1,d2
		and.w	#(IEQUALIFIER_LALT|IEQUALIFIER_RALT|IEQUALIFIER_LCOMMAND|IEQUALIFIER_RCOMMAND),d2
		bne	.NoUmlaut
		movem.l	d1/a1,-(sp)
		link	a5,#-20
		move.l	a1,a0
		lea	-20(a5),a1
		clr.b	(a1)
		move.l	#19,d1
		sub.l	a2,a2
		RELLIB	RawKeyConvert,_ConsoleBase
		moveq	#0,d0
		move.b	-20(a5),d0
		unlk	a5
		movem.l	(sp)+,d1/a1
.UmlautOk	lea	UmlautTab,a3			; Get UmlautTab
		moveq	#7,d7
.GetUmlaut	cmp.w	(a3),d0				; Got "Umlaut" ?
		beq.s	.GotUmlaut			; Yep -> go on
		addq.l	#6,a3
		dbf	d7,.GetUmlaut
		bra.s	.NoUmlaut			; No "Umlaut"
.GotUmlaut	cmp.b	#'ß',d0
		bne.s	.NoSS
		move.w	d1,d0
		and.w	#(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),d0
		bne.s	.NoUmlaut
		bra.s	.NoShift
.NoSS		tst.w	(a3)				; Skip shifted ß
		beq.s	.NoUmlaut

.NoShift	link	a5,#-ie_SIZEOF			; Get space for one IEs
		move.b	ie_SubClass(a1),d0		; Get subclass
		move.l	ie_EventAddress(a1),d2		; Address

		move.b	#IECLASS_NULL,ie_Class(a1)	; Clear current event

		lea	-ie_SIZEOF(a5),a0		; Create new event -> Clear link to next
		clr.l	ie_NextEvent(a0)
		move.b	#IECLASS_RAWKEY,ie_Class(a0)
		move.b	d0,ie_SubClass(a0)
		move.w	2(a3),ie_Code(a0)		; Get first char for "Umlaut"
		move.w	d1,ie_Qualifier(a0)
		move.l	d2,ie_EventAddress(a0)
		LNKLIB	AddIEvents,_CxBase		; Add events
		lea	-ie_SIZEOF(a5),a0
		move.w	4(a3),ie_Code(a0)		; Get second char for "Umlaut"
		and.w	#~(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),ie_Qualifier(a0)
		DOLIB	AddIEvents
		unlk	a5
.NoUmlaut	bra	NoTimerEvent

NoRawKey	cmp.w	#IECLASS_TIMER,IEClass(a4)	; Timer event ?
		bne	NoTimerEvent

		tst.b	MouseTimeOut(a4)		; Still blank mouse ?
		beq.s	.NoMouseOff
		move.l	_IntuitionBase(a4),a0
		move.l	ib_ActiveWindow(a0),d0
		cmp.l	MBlankWindow(a4),d0
		beq.s	.NoMouseOff
		bsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		bsr	OffMouse

.NoMouseOff	move.l	IEvent(a4),a0			; A little delay for check
		lea	ie_TimeStamp(a0),a0		; Only check every half a second
		move.l	TV_MICRO(a0),d0			; If mouse was moved
		move.l	d0,d1				; so that SUN-Mouse may
		move.l	OldCheckMicro(a4),d2		; activate windows if the
		sub.l	d2,d0				; mouse has come to a complete
		bge.s	.IsPos				; stop
		neg.l	d0
.IsPos		cmp.l	#150000,d0
		blt.s	.NoCheck
		move.l	d1,OldCheckMicro(a4)
		move.w	#-1,OldX(a4)
		tst.b	DoActivate(a4)			; WindowActivation active ?
		beq.s	.NoCheck
		tst.b	SunMouse(a4)			; Mouse mode active ?
		beq.s	.NoCheck
		move.l	_IntuitionBase(a4),a6
		move.w	ib_MouseX(a6),d5		; Get current mouse position
		move.w	ib_MouseY(a6),d6
		move.w	CheckX(a4),d2			; Get old position
		move.w	CheckY(a4),d3
		move.w	d5,CheckX(a4)			; Store new one
		move.w	d6,CheckY(a4)
		cmp.w	d5,d2				; Mouse moved since last change ?
		bne.s	.NoCheck1
		cmp.w	d6,d3
		bne.s	.NoCheck1
		tst.b	Moved(a4)			; Already activated on that position ?
		bne.s	.NoCheck
		bsr	FindWindow
		tst.l	d0
		beq.s	.NoCheck
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.NoCheck
		move.l	_IntuitionBase(a4),a0
		cmp.l	ib_ActiveWindow(a0),d0
		beq.s	.NoCheck
		move.l	ib_ActiveWindow(a0),a0
		bsr	CheckWinGads
		move.l	a0,d0
		beq.s	.NoCheck
		move.b	#1,Moved(a4)			; Set flag that already activated
		move.l	IEvent(a4),a0
		move.l	#REQ_ACTIVATE,d0
		bsr.s	SendEvent
		bra.s	.NoCheck
.NoCheck1	clr.b	Moved(a4)			; Clear flag

.NoCheck	move.l	IEvent(a4),a0			; Check if one second
		lea	ie_TimeStamp(a0),a1		; has elapsed since last
		move.l	TV_SECS(a1),d1			; signal
		cmp.l	OldTimeSig(a4),d1
		beq.s	NoTimerEvent
		move.l	d1,OldTimeSig(a4)		; put the message
		move.l	#REQ_TIMER,d0
		bsr.s	SendEvent

NoTimerEvent	move.l	IEvent(a4),a0			; Try to get next event linked
		move.l	ie_NextEvent(a0),d0		; to this one
		beq.s	NoEvent				; No other one -> that`s it
		move.l	d0,IEvent(a4)			; Store address
		bra	EventLoop			; Loop

NoEvent		bsr	FreeSemaphore
		movem.l	(sp)+,RegsAll
		move.l	a0,d0				; Rstore pointer to "new" events
		rts
AudioName	dc.b	"audio.device",0
		EVEN



**********************************************************************
*      Append the current event to a message and send that one       *
*                        to the event handler                        *
**********************************************************************
SendEvent	movem.l	d0/a0,-(sp)
		move.l	CheckerProc(a4),a1		; Set pri of checker to a higher
		move.l	#31,d0				; value for faster work
		CALLSYS	SetTaskPri
		move.l	d0,d6
		movem.l	(sp)+,d0/a0
		lea	EventPool(a4),a1		; Find free entry
		moveq	#MAXEVENTS-1,d7
.Find		tst.l	LN_NAME(a1)
		bne.s	.GoOn
		move.l	d0,LN_NAME(a1)
		lea	req_IEvent(a1),a1
		moveq	#(ie_SIZEOF>>1)-1,d5
.CopyEvent	move.w	(a0)+,(a1)+
		dbf	d5,.CopyEvent
		move.l	CheckerProc(a4),a1
		move.l	EventSigFlag(a4),d0
		CALLSYS	Signal
		bra.s	.End
.GoOn		lea	req_SIZEOF(a1),a1
		dbf	d7,.Find
.End		move.l	d6,d0
		move.l	CheckerProc(a4),a1
		DOLIB	SetTaskPri
		rts





**********************************************************************
*             Wait until remakes on clockwindow are made             *
**********************************************************************
ClockRemake	move.l	ClockHandle(a4),a0		; Wait until window popped up
		move.l	wd_UserPort(a0),a0
		CALLSYS	WaitPort
.Loop		move.l	ClockHandle(a4),a0
		move.l	wd_UserPort(a0),a0
		DOLIB	GetMsg
		tst.l	d0
		beq.s	.End
		move.l	d0,a1
		DOLIB	ReplyMsg
		bra.s	.Loop
.End		rts



**********************************************************************
*                          Reset the timers                          *
**********************************************************************
ResetTimer	lea	ie_TimeStamp(a0),a0
		move.l	TV_SECS(a0),d0			; Get current seconds
		move.l	d0,d1
		add.l	ScreenTime(a4),d0		; add delay for screen blank
		move.l	d0,ScreenOff(a4)
		add.l	MouseTime(a4),d1		; add delay for mouse blank
		move.l	d1,MouseOff(a4)
		clr.b	TimeReset(a4)
		rts



**********************************************************************
*                          Blank the mouse                           *
**********************************************************************
OffMouse	bsr	GetSemaphore
		move.l	_IntuitionBase(a4),a6
		move.l	ib_ActiveWindow(a6),d0
		beq.s	.NoSpr0
		cmp.l	MBlankWindow(a4),d0
		beq.s	.NoSpr0
		move.l	d0,MBlankWindow(a4)
		move.l	d0,a0
		lea	NoSpriteDat,a1
		moveq	#1,d0
		moveq	#16,d1
		moveq	#0,d2
		moveq	#0,d3
		pea	.NoSpr0(pc)
		move.l	OldSetPointer(a4),-(sp)
		rts
.NoSpr0		bsr	FreeSemaphore
		rts





**********************************************************************
*                           UnBlank mouse                            *
**********************************************************************
OnMouse		bsr	GetSemaphore
		move.l	_IntuitionBase(a4),a6
		move.l	MBlankWindow(a4),d0
		beq.s	.NoSpr0
		move.l	d0,a0
		clr.l	MBlankWindow(a4)
		lea	PointerList(a4),a1
		moveq	#MAXPOINTERS-1,d0
.Loop		cmp.l	pt_Window(a1),a0
		beq.s	.GotIt
		lea	pt_SIZEOF(a1),a1
		dbf	d0,.Loop
		pea	.NoSpr0(pc)
		move.l	OldClearPointer(a4),-(sp)
		rts
.GotIt		move.l	a1,a2
		movem.l	(a2),d0-d3/a0-a1
		pea	.NoSpr0(pc)
		move.l	OldSetPointer(a4),-(sp)
		rts
.NoSpr0		clr.b	MouseTimeOut(a4)
		bsr	FreeSemaphore
		rts





**********************************************************************
*                     UnBlank/UnDimm the Screen                      *
**********************************************************************
OnScreen	tst.b	ScreenDimm(a4)
		beq.s	.UnDimm
		tst.l	DimmBase(a4)
		beq.s	.End

		moveq	#0,d0				; Check if screen to be undimmed
		RELLIB	LockIBase,_IntuitionBase	; is still there
		move.l	d0,d7

		move.l	ib_FirstScreen(a6),a3		; Get frontmost screen

		move.l	DimmBase(a4),a2
.ScreenLoop	move.l	dm_Screen(a2),a0
		move.l	a0,d0
		beq.s	.NoMoreScrs
		move.l	a3,a1
.CheckScreen	move.l	a1,d0
		beq.s	.ScreenNotThere
		cmp.l	a0,a1
		bne.s	.NotEqual
		lea	sc_ViewPort(a1),a0
		lea	dm_Colors(a2),a1
		move.l	#32,d0
		RELLIB	LoadRGB4,_GfxBase
		bra.s	.ScreenNotThere
.NotEqual	move.l	sc_NextScreen(a1),a1
		bra.s	.CheckScreen
.ScreenNotThere	lea	dm_SIZEOF(a2),a2
		bra.s	.ScreenLoop

.NoMoreScrs	move.l	d7,a0
		RELLIB	UnlockIBase,_IntuitionBase

		move.l	DimmBase(a4),a1
		CALLSYS	FreeVec
		clr.l	DimmBase(a4)
		bra.s	.End

.UnDimm		tst.l	BlankScrHandle(a4)			; Close blank-screen if there
		beq.s	.End
		move.l	BlankScrHandle(a4),a0
		RELLIB	CloseScreen,_IntuitionBase
		clr.l	BlankScrHandle(a4)
.End		rts




**********************************************************************
*                       Blank/Dimm the screen                        *
**********************************************************************
OffScreen	tst.b	ScreenDimm(a4)			; To be dimmed ?
		beq	.NoDimm
		tst.l	BlankScrHandle(a4)			; Blank Screen there ?
		beq.s	.NoBlankOff
		move.l	BlankScrHandle(a4),a0		; Close it first
		RELLIB	CloseScreen,_IntuitionBase
		clr.l	BlankScrHandle(a4)
.NoBlankOff	tst.l	DimmBase(a4)			; Already dimmed ?
		bne	.EndDimm

		moveq	#0,d0				; Lock Base
		RELLIB	LockIBase,_IntuitionBase
		move.l	d0,-(sp)
		move.l	ib_FirstScreen(a6),a3
		move.l	a3,a0

		moveq	#1,d0				; Calc number of screens
.CalcScreens	move.l	a0,d1
		beq.s	.NoMoreScreens
		addq.l	#1,d0
		move.l	sc_NextScreen(a0),a0
		bra.s	.CalcScreens

.NoMoreScreens	mulu	#dm_SIZEOF,d0			; Get buffer for screens
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		move.l	d0,DimmBase(a4)
		tst.l	d0
		beq	.DimmError

		move.l	d0,a2				; Get pointer to buffer

.GetColors	move.l	a3,d0
		beq.s	.GotColors			; available to the structure
		move.l	a3,dm_Screen(a2)		; allocated
		lea	sc_ViewPort(a3),a3
		move.l	vp_ColorMap(a3),a3
		move.l	a2,a1
		move.l	#31,d7
		moveq	#0,d6
.LoopColors	move.l	a3,a0
		move.l	d6,d0
		move.l	a1,-(sp)
		RELLIB	GetRGB4,_GfxBase
		move.l	(sp)+,a1
		move.w	d0,dm_Colors(a1)
		move.w	d0,dm_Dimmed(a1)
		addq.l	#2,a1
		addq.l	#1,d6
		dbf	d7,.LoopColors
		move.l	dm_Screen(a2),a3
		lea	dm_SIZEOF(a2),a2
		move.l	sc_NextScreen(a3),a3
		bra.s	.GetColors

.GotColors	move.l	DimmBase(a4),a2
.ScreenLoop	moveq	#31,d7
		lea	dm_Dimmed(a2),a3
.RemakeAll	move.l	DimmValue(a4),d4
.RemakeCols	move.w	(a3),d0
		move.w	d0,d1
		move.w	d0,d2
		and.w	#$0f00,d0
		and.w	#$00f0,d1
		and.w	#$000f,d2
		lsr.w	#8,d0
		lsr.w	#4,d1
		subq.w	#1,d0
		bge.s	.GoRed
		moveq	#0,d0
.GoRed		subq.w	#1,d4
		ble.s	.GoBlue
		subq.w	#1,d1
		bge.s	.GoGreen
		moveq	#0,d1
.GoGreen	subq.w	#1,d4
		ble.s	.GoBlue
		subq.w	#1,d2
		bge.s	.GoBlue
		moveq	#0,d2
.GoBlue		lsl.w	#8,d0
		lsl.w	#4,d1
		or.w	d1,d2
		or.w	d0,d2
		move.w	d2,(a3)
		subq.w	#1,d4
		bgt.s	.RemakeCols
		addq.l	#2,a3
		dbf	d7,.RemakeAll
		move.l	dm_Screen(a2),a0
		lea	sc_ViewPort(a0),a0
		lea	dm_Dimmed(a2),a1
		move.l	#32,d0
		RELLIB	LoadRGB4,_GfxBase
		lea	dm_SIZEOF(a2),a2
		tst.l	dm_Screen(a2)
		bne.s	.ScreenLoop
.DimmError	move.l	(sp)+,a0
		RELLIB	UnlockIBase,_IntuitionBase
.EndDimm	rts

.NoDimm		tst.l	BlankScrHandle(a4)			; Screen already blanked ?
		bne.s	.End				; Yep -> pop it to front
		lea	BlankScreenDef,a0		; Open dummy (Blank) screen
		RELLIB	OpenScreen,_IntuitionBase
		move.l	d0,BlankScrHandle(a4)
		tst.l	d0
		beq.s	.EndIt
		move.l	d0,a0
		lea	sc_ViewPort(a0),a0		; Set all cols to black
		moveq	#0,d0
		moveq	#0,d1
		moveq	#0,d2
		moveq	#0,d3
		RELLIB	SetRGB4,_GfxBase
		bsr	GetSemaphore
		bsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		bsr	OffMouse			; Disable mouse
		bsr	FreeSemaphore
		rts
.End		move.l	BlankScrHandle(a4),a0		; Get screen to front :-)
		RELLIB	ScreenToFront,_IntuitionBase
		bsr	GetSemaphore
		bsr	OnMouse
		move.b	#1,MouseTimeOut(a4)
		bsr	OffMouse
		bsr	FreeSemaphore
.EndIt		rts




**********************************************************************
*                   This is the activation-routine                   *
**********************************************************************
Activate	bsr	GetSemaphore
		movem.l	d0-d7/a0-a6,-(sp)
		link	a5,#-180
		tst.w	RequestsOpen(a4)
		bne	.NotAct

		bsr	FindWindow
		tst.l	d0
		beq	.NotAct

		movem.l	d0/a0,-(sp)
		CALLSYS	Forbid
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase

		move.l	ib_ActiveWindow(a6),a2		; First look if it`s a "locked" window

		move.l	d0,a0
		DOLIB	UnlockIBase

		move.l	a2,a0				; Active window has an active
		bsr	CheckWinGads			; String Gadget ?
		move.l	a0,d0
		bne.s	.NoStrGad
		sub.l	a0,a0
		bra.s	.GotWindow

.NoStrGad	move.l	wd_Title(a2),d0
		beq.s	.DoAct
		lea	WindowBase(a4),a3
		move.l	LH_HEAD(a3),d0			; Get address of first entry
		cmp.l	LH_TAIL+LN_PRED(a3),a3
		beq.s	.DoAct
		move.l	d0,a3
.Loop		TSTLST2	a3,a1
		beq.s	.DoAct
		lea	lw_Name(a3),a0			; Get name
		move.l	a0,d1
		lea	-180(a5),a0			; Get buffer for pattern
		move.l	a0,d2
		move.l	#180,d3
		RELLIB	ParsePatternNoCase,_DOSBase	; Tokenize pattern
		lea	-180(a5),a0			; Check if title of window matches
		move.l	a0,d1
		move.l	wd_Title(a2),a0
		move.l	a0,d2
		DOLIB	MatchPatternNoCase
		tst.l	d0
		beq.s	.NotSame
		movem.l	(sp)+,d0/a0
		sub.l	a0,a0
		bra.s	.GotWindow
.NotSame	SUCC	a3,a3
		bra.s	.Loop

.DoAct		movem.l	(sp)+,d0/a0
		move.l	d0,a1
		move.l	lr_Window(a1),a1
		cmp.l	ActWindow(a4),a1
		bne.s	.GoOn
		sub.l	a0,a0
		bra.s	.GotWindow
.GoOn		move.l	d0,a0
		move.l	lr_Window(a0),a0
.GotWindow	move.l	a0,-(sp)
		CALLSYS	Permit
		move.l	(sp)+,a0
		move.l	a0,d0
		beq.s	.NotAct
		RELLIB	ActivateWindow,_IntuitionBase	; activate window
.NotAct		unlk	a5
		movem.l	(sp)+,d0-d7/a0-a6
		bra	FreeSemaphore




**********************************************************************
*           Checks for any active gadgets within a window            *
**********************************************************************
CheckWinGads	movem.l	d1/a1,-(sp)
		move.l	wd_FirstGadget(a0),a1		; First gadget of window

.CheckGadgets	move.l	a1,d1
		beq.s	.GadgetsChecked

		move.w	gg_GadgetType(a1),d1		; Is it a string-gadget ?
		and.w	#STRGADGET,d1
		beq.s	.NoStrGad			; No -> go on

		move.w	gg_Flags(a1),d1			; Is it selected ?
		and.w	#GFLG_SELECTED,d1
		bne.s	.NoWindow			; Yep -> No more actions

.NoStrGad	move.l	gg_NextGadget(a1),a1		; Check all gads in window
		bra	.CheckGadgets
.NoWindow	sub.l	a0,a0
.GadgetsChecked	movem.l	(sp)+,d1/a1
		rts



**********************************************************************
*                    Find underneith mousepointer                    *
**********************************************************************
FindWindow	movem.l	d2-d7/a2-a6,-(sp)
		moveq	#0,d0				; Lock Intuition-Base
		RELLIB	LockIBase,_IntuitionBase

		move.l	ib_ActiveWindow(a6),ActWindow(a4)	; Is a requester active on
		move.l	ib_FirstScreen(a6),a3

		move.l	d0,a0
		DOLIB	UnlockIBase

		CALLSYS	Forbid

		move.l	a3,a0

CheckScreens	moveq	#0,d0
		moveq	#0,d1
		move.w	sc_MouseX(a0),d0
		move.w	sc_MouseY(a0),d1

		movem.l	a0/d1,-(sp)			; Check layer
		lea	sc_LayerInfo(a0),a0
		RELLIB	WhichLayer,_LayersBase
		movem.l	(sp)+,a0/d1
		tst.l	d0
		bne.s	GotLayer

		move.l	sc_NextScreen(a0),a0		; Next Screen
		move.l	a0,d3				; No more screens ?
		beq.s	ScreenError			; Error
		bra	CheckScreens			; Find screen

ScreenError	moveq	#0,d0
GotLayer	movem.l	d0/a0,-(sp)
		CALLSYS	Permit
		movem.l	(sp)+,d0/a0
		movem.l	(sp)+,d2-d7/a2-a6
		rts


**********************************************************************
*            Signal the timer process to remake the time             *
**********************************************************************
SigTime		move.l	CheckerProc(a4),a1
		move.l	#SIGTIMEREMAKE,d0
		CALLSYS	Signal
		rts


**********************************************************************
*                          Display new time                          *
**********************************************************************
SetTime		lea	MyDateTime(a4),a0		; Get datestamp
		move.l	a0,d1
		RELLIB	DateStamp,_DOSBase

		lea	MyDateTime(a4),a0		; Do the string formatings
		move.b	#FORMAT_DOS,dat_Format(a0)
		lea	RevDayString(a4),a1
		move.l	a1,dat_StrDay(a0)		; First create the whole string
		lea	RevDateString(a4),a1
		move.l	a1,dat_StrDate(a0)		; for revision
		lea	RevTimeString(a4),a1
		move.l	a1,dat_StrTime(a0)
		move.l	a0,d1
		DOLIB	DateToStr

		lea	MyDateTime(a4),a0		; Do the string formatings
		tst.b	AmiDate(a4)
		beq.s	.Loop1
		move.b	#FORMAT_USA,dat_Format(a0)	; Set american date format
		bra.s	.Loop2
.Loop1		move.b	#FORMAT_CDN,dat_Format(a0)	; Set "canadian" date format
.Loop2		clr.b	dat_Flags(a0)

		lea	AllDayString(a4),a1
		move.l	a1,dat_StrDay(a0)		; First create the whole string
		lea	AllDateString(a4),a1
		move.l	a1,dat_StrDate(a0)		; for environment variables
		lea	AllTimeString(a4),a1
		move.l	a1,dat_StrTime(a0)
		move.l	a0,d1
		DOLIB	DateToStr

		lea	AllDayString(a4),a0
		bsr	ConvertDays
		lea	AllDateString(a4),a0
		bsr	ConvertDates

		tst.b	SetEnv(a4)			; Write env vars
		beq.s	NoEnvTime

		lea	EnvDayString(pc),a1
		move.l	a1,d1				; set env vars
		lea	AllDayString(a4),a1
		move.l	a1,d2
		moveq	#-1,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		DOLIB	SetVar
		tst.l	d0
		beq.s	.Error

		lea	EnvDateString(pc),a1
		move.l	a1,d1
		lea	AllDateString(a4),a1
		move.l	a1,d2
		moveq	#-1,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		DOLIB	SetVar
		tst.l	d0
		beq.s	.Error

		lea	EnvTimeString(pc),a1
		move.l	a1,d1
		lea	AllTimeString(a4),a1
		move.l	a1,d2
		moveq	#-1,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		DOLIB	SetVar
		tst.l	d0
		bne.s	NoEnvTime

.Error		clr.b	SetEnv(a4)		; Disable setenv if errors
		moveq	#0,d0			; occured
		move.l	#GD_WriteEnv,d1
		bsr	SetMiscBox

NoEnvTime	clr.b	DayString(a4)		; clear previous strings
		clr.b	DateString(a4)
		clr.b	TimeString(a4)

		lea	MyDateTime(a4),a0
		tst.b	ShowDay(a4)		; Now create the rest for clock
		beq.s	.Loop3			; display
		lea	DayString(a4),a1
		move.l	a1,dat_StrDay(a0)
		bra.s	.Loop4
.Loop3		clr.l	dat_StrDay(a0)

.Loop4		tst.b	ShowDate(a4)		; Are we to show a date ?
		beq.s	.Loop5
		lea	DateString(a4),a1
		move.l	a1,dat_StrDate(a0)	; Yep
		bra.s	.Loop6
.Loop5		clr.l	dat_StrDate(a0)		; Nope
.Loop6		tst.b	DoShowTime(a4)		; Show time ?
		beq.s	.Loop6a
		lea	TimeString(a4),a1
		move.l	a1,dat_StrTime(a0)
		bra.s	.Loop6b
.Loop6a		clr.l	dat_StrTime(a0)
.Loop6b		move.l	a0,d1
		DOLIB	DateToStr
		tst.l	d0
		beq	NoTime

		lea	DayString(a4),a0
		bsr	ConvertDays
		lea	DateString(a4),a0
		bsr	ConvertDates

		bsr	CheckForAlarm			; Are we to alarm ?

		tst.b	ShowClock(a4)			; Show clock ?
		beq	NoTime

		cmp.l	#TIMEPAGE,PageNum(a4)		; Display normal time ?
		bgt	NoClockDisp

		lea	TimeFormats,a0			; Change to different
		tst.b	ShortDay(a4)			; time format strings
		beq.s	.Loop7
		addq.l	#8,a0				; Use the ones with long days
.Loop7		tst.b	ShowSecs(a4)
		bne.s	.Loop8
		addq.l	#4,a0				; use the one without secs
.Loop8		move.l	(a0),a0
		lea	FormatData(pc),a1
		lea	PutChProc(pc),a2
		lea	FinalString(a4),a3
		CALLSYS	RawDoFmt

		tst.b	ShowMouse(a4)			; Show Mouse positions ?
		beq.s	.NoMousePos
		link	a5,#-(4+30)
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase
		move.l	d0,d7
		move.l	ib_ActiveScreen(a6),a0
		move.w	sc_MouseX(a0),-4(a5)
		move.w	sc_MouseY(a0),-2(a5)
		move.l	d7,a0
		DOLIB	UnlockIBase
		lea	MousePosForm,a0
		lea	-4(a5),a1
		lea	PutChProc(pc),a2
		lea	-(4+30)(a5),a3
		CALLSYS	RawDoFmt
		lea	-(4+30)(a5),a0
		lea	FinalString(a4),a1
		bsr	StrCat
		unlk	a5
.NoMousePos	bsr	MakeDisplay			; Display the stuff
		bra	NoTime

NoClockDisp	cmp.l	#DMEMPAGE,PageNum(a4)		; Display Chip/Fast mem seperately ?
		bne.s	NoDoubleMem

		move.l	#MEMF_CHIP,d1			; Get available memory
		CALLSYS	AvailMem
		move.l	d0,ChipMem
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		move.l	d0,FastMem

		lea	FormMemString,a0		; Format string
		lea	ChipMem,a1
		lea	PutChProc(pc),a2
		lea	FinalString(a4),a3
		DOLIB	RawDoFmt

		bsr	MakeDisplay			; Display
		bra	NoTime

NoDoubleMem	cmp.l	#TMEMPAGE,PageNum(a4)		; Display total memory ?
		bne.s	NoTotalMem

		move.l	#MEMF_CHIP,d1			; Calc total memory
		CALLSYS	AvailMem
		move.l	d0,d7
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		add.l	d0,d7
		move.l	d7,TotalMem

		lea	FormTMemString,a0
		lea	TotalMem,a1
		lea	PutChProc(pc),a2
		lea	FinalString(a4),a3
		DOLIB	RawDoFmt

		bsr	MakeDisplay
		bra	NoTime

NoTotalMem	cmp.l	#TIMEMEMPAGE,PageNum(a4)	; Display time and memory ?
		bne	NoDoublePage

		lea	TimeFormats,a0			; Change to different
		tst.b	ShortDay(a4)			; time format strings
		beq.s	.Loop7
		addq.l	#8,a0				; Use the ones with long days
.Loop7		tst.b	ShowSecs(a4)
		bne.s	.Loop8
		addq.l	#4,a0				; use the one without secs
.Loop8		move.l	(a0),a0
		lea	FormatData(pc),a1
		lea	PutChProc(pc),a2
		lea	FinalString(a4),a3
		CALLSYS	RawDoFmt

		move.l	#MEMF_CHIP,d1			; Get available memory
		CALLSYS	AvailMem
		lsr.l	#8,d0
		lsr.l	#2,d0
		move.l	d0,ChipMem
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		lsr.l	#8,d0
		lsr.l	#2,d0
		move.l	d0,FastMem

		link	a5,#-80

		lea	DoubleMemString,a0		; Format string
		lea	ChipMem,a1
		lea	PutChProc(pc),a2
		lea	-80(a5),a3
		DOLIB	RawDoFmt

		lea	-80(a5),a0
		lea	FinalString(a4),a1
		bsr	StrCat
		unlk	a5

		bsr	MakeDisplay
		bra	NoTime

NoDoublePage	cmp.l	#GMEMPAGE,PageNum(a4)		; Display fillgauge
		bne	NoGfxMem

		link	a5,#-4
		bsr	LockScreen
		tst.l	d0
		bne.s	.GoOn
		clr.l	PageNum(a4)
		bra	NoGfxMem

.GoOn		move.l	MyRastPort(a4),a1
		move.l	TextBackPen(a4),d0
		RELLIB	SetRast,_GfxBase

		move.l	#MEMF_CHIP,d1			; Calc total memory

		CALLSYS	AvailMem
		move.l	d0,d7
		move.l	#MEMF_FAST,d1
		DOLIB	AvailMem
		add.l	d7,d0
		move.l	MaxMem(a4),d7
		sub.l	d0,d7

		move.l	MyRastPort(a4),a1		; Get length of E and F
		lea	EString(pc),a0			; chars
		moveq	#1,d0
		RELLIB	TextLength,_GfxBase
		move.l	d0,EWidth(a4)
		move.l	d0,d5
		move.l	MyRastPort(a4),a1
		lea	FString(pc),a0
		moveq	#1,d0
		DOLIB	TextLength
		move.l	d0,FWidth(a4)
		add.l	d5,d0				; d0 length of both
		add.l	#MAXBARLEN,d0
		addq.l	#4,d0
		move.l	d0,BlitWidth(a4)
		moveq	#0,d2
		move.l	-4(a5),a0
		move.w	sc_Width(a0),d2
		sub.l	#DEPTHWIDTH,d2
		sub.l	d0,d2
		move.l	d2,LeftEdge(a4)
		move.l	#MAXBARLEN,d0			; Get maximum length of bar
		move.l	d7,d1
		RELLIB	UMult32,_UtilityBase
		move.l	MaxMem(a4),d1
		DOLIB	UDivMod32
		move.l	d0,d5				; D5 = Length of gauge

		move.l	MyRastPort(a4),a1
		move.l	TextFrontPen(a4),d0
		RELLIB	SetAPen,_GfxBase

		move.l	MyRastPort(a4),a1		; Write E
		moveq	#0,d1
		move.l	MyFont(a4),a0
		move.w	tf_Baseline(a0),d1
		moveq	#0,d0
		DOLIB	Move
		move.l	MyRastPort(a4),a1
		lea	EString(pc),a0
		moveq	#1,d0
		DOLIB	Text

		move.l	MyRastPort(a4),a1		; Draw "non-filled" rec
		move.l	GaugeBackPen(a4),d0
		DOLIB	SetAPen

		move.l	MyRastPort(a4),a1
		move.l	EWidth(a4),d0
		addq.l	#2,d0
		moveq	#0,d1
		move.l	d0,d2
		add.l	#MAXBARLEN,d2
		moveq	#0,d3
		move.l	MyFont(a4),a0
		move.w	tf_YSize(a0),d3
		subq.l	#1,d3
		DOLIB	RectFill

		move.l	MyRastPort(a4),a1		; Draw gauge
		move.l	GaugeFrontPen(a4),d0
		DOLIB	SetAPen

		move.l	MyRastPort(a4),a1
		move.l	EWidth(a4),d0
		addq.l	#2,d0
		moveq	#0,d1
		move.l	d5,d2
		add.l	d0,d2
		moveq	#0,d3
		move.l	MyFont(a4),a0
		move.w	tf_YSize(a0),d3
		subq.l	#1,d3
		DOLIB	RectFill

		move.l	MyRastPort(a4),a1		; Draw F
		move.l	TextFrontPen(a4),d0
		DOLIB	SetAPen

		move.l	MyRastPort(a4),a1
		move.l	EWidth(a4),d0
		addq.l	#4,d0
		add.l	#MAXBARLEN,d0
		move.l	MyFont(a4),a0
		moveq	#0,d1
		move.w	tf_Baseline(a0),d1
		DOLIB	Move
		move.l	MyRastPort(a4),a1
		lea	FString(pc),a0
		moveq	#1,d0
		DOLIB	Text

		move.l	MyRastPort(a4),a1		; Reset color for our RastPort
		moveq	#0,d0
		DOLIB	SetAPen

		tst.b	ClockWin(a4)			; Window active ?
		beq.s	TitleGauge

		move.l	BlitWidth(a4),d6
		bsr	OpenClockWin
		tst.l	d0
		beq	NoTime
		bra.s	.NoClear
.Clear		move.l	ClockHandle(a4),a0
		tst.l	wd_Title(a0)			; Window-Title already cleard ?
		beq.s	.NoClear
		sub.l	a1,a1				; Clear window-title
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase

.NoClear	move.l	ClockHandle(a4),a1		; Blit gauge into window-title
		move.l	wd_RPort(a1),a1
		move.l	#DEPTHWIDTH,d2
		bra.s	DoGauge

TitleGauge	bsr	CloseClockWin
		move.l	-4(a5),a1			; Blit gauge into title/window
		move.l	sc_BarLayer(a1),a1
		move.l	lr_rp(a1),a1
		move.l	LeftEdge(a4),d2

DoGauge		move.l	MyRastPort(a4),a0
		moveq	#0,d0
		moveq	#0,d1
		move.l	#1,d3
		move.l	BlitWidth(a4),d4
		moveq	#0,d5
		move.w	BitMapHeight(a4),d5
		move.l	#$c0,d6
		RELLIB	ClipBlit,_GfxBase

		bsr	UnlockScreen
		unlk	a5
		bra.s	NoTime

NoGfxMem	cmp.l	#ONLINEPAGE,PageNum(a4)		; Display online-time ?
		bne.s	NoOnlinePage			; Nope -> go on
		lea	OnlineFormStr(pc),a0		; Copy online string
		lea	FinalString(a4),a1
		bsr	StrCpy
		lea	OnlineString(a4),a0		; Concat time string
		lea	FinalString(a4),a1
		bsr	StrCat
		bsr.s	MakeDisplay
		bra.s	NoTime

NoOnlinePage	cmp.l	#SNAPMEMPAGE,PageNum(a4)	; Display snapped memory ?
		bne.s	NoTime
		lea	FormSnapMemStr,a0		; Format string
		lea	ThisChip,a1
		lea	PutChProc(pc),a2
		lea	FinalString(a4),a3
		CALLSYS	RawDoFmt
		bsr.s	MakeDisplay			; Display
NoTime		rts
EnvDayString	dc.b	"DAY",0
EnvDateString	dc.b	"DATE",0
EnvTimeString	dc.b	"TIME",0
		EVEN



**********************************************************************
*                Make up the display for clock/memory                *
**********************************************************************
MakeDisplay	lea	FinalString(a4),a0		; Get length of time string
		bsr	StrLen
		move.l	d0,d7
		move.l	MyRastPort(a4),a1		; Get width of string (pixels)
		RELLIB	TextLength,_GfxBase
		move.l	d0,d6

		tst.b	ClockWin(a4)			; Display in window ?
		beq.s	DisplayInTitle			; Nope -> do it in title

		bsr	OpenClockWin
		tst.l	d0
		beq	NoDisplay

		move.l	ClockHandle(a4),a0		; Set new title of window
		lea	FinalString(a4),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		rts

DisplayInTitle	link	a5,#-4
		bsr	LockScreen
		tst.l	d0
		beq	NoDisplay

		bsr	CloseClockWin

		move.l	-4(a5),a0
		lea	sc_LayerInfo(a0),a0
		RELLIB	LockLayers,_LayersBase

		move.l	-4(a5),a0
		lea	sc_LayerInfo(a0),a0
		DOLIB	LockLayerInfo

		move.l	MyRastPort(a4),a1		; Clear rastport
		move.l	TextBackPen(a4),d0
		RELLIB	SetRast,_GfxBase

		move.l	MyRastPort(a4),a1		; Set text pen
		move.l	TextFrontPen(a4),d0
		DOLIB	SetAPen

		moveq	#0,d1				; Move cursor to position
		move.l	MyFont(a4),a0
		move.w	tf_Baseline(a0),d1
		move.l	MyRastPort(a4),a1
		moveq	#0,d0
		DOLIB	Move

		move.l	MyRastPort(a4),a1		; Draw string
		lea	FinalString(a4),a0
		move.l	d7,d0
		DOLIB	Text

		moveq	#0,d2
		move.l	-4(a5),a0
		move.w	sc_Width(a0),d2			; Get width of screen
		sub.l	#DEPTHWIDTH,d2			; Skip depth gadget
		sub.l	d6,d2				; Skip width of string
		move.l	d2,LeftEdge(a4)			; Store new X-Position in TitleBar
		move.l	d6,d4
		add.w	#DEPTHWIDTH,d6
		cmp.w	BitMapWidth(a4),d6		; If width to be blitted is
		ble.s	.End				; > Plane width : Skip some pixels
		move.w	BitMapWidth(a4),d4
		sub.w	#DEPTHWIDTH,d4
.End		move.l	d4,BlitWidth(a4)			; Store width of string

		move.l	MyRastPort(a4),a0		; Blit our rastport into
		moveq	#0,d0				; rastport of layer which
		moveq	#0,d1				; is the titlebar
		move.l	-4(a5),a1
		move.l	sc_BarLayer(a1),a1
		move.l	lr_rp(a1),a1
		move.l	#1,d3
		moveq	#0,d5
		move.w	BitMapHeight(a4),d5
		move.l	#$c0,d6
		DOLIB	ClipBlit

		move.l	-4(a5),a0
		lea	sc_LayerInfo(a0),a0
		RELLIB	UnlockLayerInfo,_LayersBase

		move.l	-4(a5),a0
		lea	sc_LayerInfo(a0),a0
		DOLIB	UnlockLayers

NoDisplay	bsr	UnlockScreen
		unlk	a5
		rts




**********************************************************************
*                   Clears the workbench titlebar                    *
**********************************************************************
ClearTitleBar	tst.l	CheckerProc(a4)
		beq.s	.Error
		link	a5,#-4
		bsr	LockScreen
		tst.l	d0
		beq.s	.End

		RELLIB	WaitTOF,_GfxBase

		move.l	MyRastPort(a4),a1
		moveq	#1,d0				; Clear rastport
		DOLIB	SetRast

		move.l	MyRastPort(a4),a0		; Blit
		moveq	#0,d0				; to restore titlebar shape
		moveq	#0,d1
		move.l	-4(a5),a1
		move.l	sc_BarLayer(a1),a1
		move.l	lr_rp(a1),a1
		move.l	LeftEdge(a4),d2
		move.l	#1,d3
		moveq	#0,d5
		move.w	BitMapHeight(a4),d5
		move.l	BlitWidth(a4),d4
		move.l	#$c0,d6
		DOLIB	ClipBlit

.End		bsr	UnlockScreen
		unlk	a5
.Error		rts



**********************************************************************
*                Convert day-name to german if needed                *
**********************************************************************
ConvertDays	tst.b	GermanDays(a4)
		beq.s	.End
		move.l	a0,a3
		lea	DayNamesEng(pc),a2
		moveq	#0,d5
		moveq	#6,d6
.FindDay	move.l	(a2),a0
		move.l	a3,a1
		bsr	StrCmp
		tst.l	d0
		bne.s	.NotThisOne
		lea	DayNamesGer(pc),a0
		move.l	0(a0,d5.w),a0
		move.l	a3,a1
		bsr	StrCpy
		rts
.NotThisOne	addq.l	#4,a2
		addq.l	#4,d5
		dbf	d6,.FindDay
.End		rts



**********************************************************************
*                  Make "." out of "-" within dates                  *
**********************************************************************
ConvertDates	tst.b	PointDates(a4)
		beq.s	.End
.Loop		tst.b	(a0)
		beq.s	.End
		cmp.b	#"-",(a0)
		bne.s	.GoOn
		move.b	#".",(a0)
.GoOn		addq.l	#1,a0
		bra.s	.Loop
.End		rts



**********************************************************************
*                  Load the specified Alarm sample                   *
**********************************************************************
InitAlarmSmp	tst.b	AlarmSample(a4)
		beq	.End

		clr.b	SampleLoaded(a4)
		clr.b	HadASample(a4)

		move.l	#AUDIOPORT_ERR,ErrorNum(a4)		; Get Message Port
		CALLSYS	CreateMsgPort
		move.l	d0,AlarmPort(a4)
		tst.l	d0
		beq	.AlarmError1

		move.l	#AUDIOREQ_ERR,ErrorNum(a4)		; Create Request
		move.l	AlarmPort(a4),a0
		move.l	#ioa_SIZEOF,d0
		CALLSYS	CreateIORequest
		move.l	d0,AlarmReq(a4)
		tst.l	d0
		beq	.AlarmError1

		move.l	#NOIFF_ERR,ErrorNum(a4)		; Open IFF handle
		RELLIB	AllocIFF,_IFFParseBase
		move.l	d0,MyIFFHandle(a4)
		tst.l	d0
		beq	.AlarmError1

		lea	AlSampleName(a4),a0		; Open file
		move.l	a0,d1
		move.l	d1,EasyArg(a4)
		move.l	#MODE_OLDFILE,d2
		RELLIB	Open,_DOSBase
		move.l	MyIFFHandle(a4),a0
		move.l	d0,iff_Stream(a0)
		tst.l	d0
		beq	.DosAlarmError

		RELLIB	InitIFFasDOS,_IFFParseBase

		move.l	MyIFFHandle(a4),a0		; Open for IFF read
		move.l	#IFFF_READ,d0
		DOLIB	OpenIFF
		tst.l	d0
		bne	.AlarmError

		move.l	MyIFFHandle(a4),a0		; Search for these two
		move.l	#'8SVX',d0			; chunks
		move.l	#'VHDR',d1
		DOLIB	PropChunk
		tst.l	d0
		bne	.AlarmError

		move.l	MyIFFHandle(a4),a0
		move.l	#'8SVX',d0
		move.l	#'BODY',d1
		DOLIB	StopChunk
		tst.l	d0
		bne	.AlarmError

		move.l	MyIFFHandle(a4),a0		; Scan file
		move.l	#IFFPARSE_SCAN,d0
		DOLIB	ParseIFF
		tst.l	d0
		bne	.AlarmError

		move.l	MyIFFHandle(a4),a0		; Check for VHDR
		move.l	#'8SVX',d0
		move.l	#'VHDR',d1
		DOLIB	FindProp
		tst.l	d0
		beq	.AlarmError
		move.l	d0,a0				; Read out VHDR chunk
		move.l	spr_Data(a0),a0
		move.l	oneShotHiSamples(a0),AlarmHiSmp(a4)
		move.l	repeatHiSamples(a0),AlarmHiRep(a4)
		move.l	samplesPerHiCycle(a0),AlarmHiCyc(a4)
		move.w	samplesPerSec(a0),AlarmSmpSec(a4)
		move.b	ctOctave(a0),AlarmOctave(a4)
		move.l	Volume(a0),AlarmVolume(a4)
		move.l	AlarmHiSmp(a4),d0
		add.l	AlarmHiRep(a4),d0
		move.l	d0,AlarmSmpLen(a4)

		move.l	MyIFFHandle(a4),a0		; Check for BODY
		DOLIB	CurrentChunk
		move.l	#MEMORY_ERR,ErrorNum(a4)		; Try to get memory block
		move.l	d0,a3
		move.l	cn_Size(a3),d0
		move.l	#MEMF_CHIP,d1
		CALLSYS	AllocVec
		move.l	d0,AlarmSmpStart(a4)
		tst.l	d0
		beq.s	.AlarmError1

		move.l	MyIFFHandle(a4),a0		; Read sample
		move.l	d0,a1
		move.l	cn_Size(a3),d0
		RELLIB	ReadChunkBytes,_IFFParseBase
		cmp.l	cn_Size(a3),d0
		bne.s	.AlarmError
		move.b	#1,SampleLoaded(a4)
		move.b	#1,HadASample(a4)
		bra.s	.EndAlarm

.AlarmError	tst.l	d0
		beq.s	.EndAlarm
		neg.l	d0
		add.l	#400,d0
		move.l	d0,ErrorNum(a4)
.AlarmError1	jsr	DisplayError
		bra.s	.EndAlarm
.DosAlarmError	DOLIB	IoErr
		move.l	d0,ErrorNum(a4)
		jsr	DisplayError
.EndAlarm	tst.l	MyIFFHandle(a4)
		beq.s	.NoHandle
		move.l	MyIFFHandle(a4),a0
		RELLIB	CloseIFF,_IFFParseBase
		move.l	MyIFFHandle(a4),a0
		move.l	iff_Stream(a0),d1
		beq.s	.NoFile
		RELLIB	Close,_DOSBase
.NoFile		move.l	MyIFFHandle(a4),a0
		RELLIB	FreeIFF,_IFFParseBase
.NoHandle
.End		rts



**********************************************************************
*                     Remove Alarm sample stuff                      *
**********************************************************************
RemoveAlarmSmp	tst.l	AlarmSmpStart(a4)
		beq.s	.NoSample
		move.l	AlarmSmpStart(a4),a1
		CALLSYS	FreeVec
.NoSample	tst.l	AlarmPort(a4)
		beq.s	.NoPort
		move.l	AlarmPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoPort		tst.l	AlarmReq(a4)
		beq.s	.NoReq
		move.l	AlarmReq(a4),a0
		CALLSYS	DeleteIORequest
.NoReq		clr.l	AlarmPort(a4)
		clr.l	AlarmReq(a4)
		clr.l	AlarmSmpStart(a4)
		clr.b	SampleLoaded(a4)
		rts



**********************************************************************
*                      Set drive noclick/click                       *
**********************************************************************
SetNoClick	movem.l	RegsAll,-(sp)
		lea	DriveRequests(a4),a3
		moveq	#3,d7
.Loop		move.l	(a3)+,d0
		beq.s	.GoOn
		move.l	d0,a0
		move.l	IO_UNIT(a0),a0
		tst.b	DriveNoClick(a4)
		beq.s	.ClickOFF
		or.b	#TDPF_NOCLICK,TDU_PUBFLAGS(a0)
		bra.s	.GoOn
.ClickOFF	and.b	#~TDPF_NOCLICK,TDU_PUBFLAGS(a0)
.GoOn		dbf	d7,.Loop
		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*           Routine for keeping up the correct online time           *
**********************************************************************
CheckOnline	tst.b	Online(a4)			; Already online ?
		bne.s	StillOnline

		lea	$bfd000,a5
		btst	#CIAB_COMCD,ciapra(a5)
		bne	NotOnline

		move.b	#1,Online(a4)			; Reset flags
		clr.b	DontCheckTime(a4)
		clr.l	OnlineHour
		clr.l	OnlineMinute
		move.l	#5,OnlineSeconds		; We already have a connect of about 3 secs
		move.l	#-5,NextUnit			; Store for next unit calc
		move.l	#5,UnitsDone
		clr.l	TotalCost(a4)
		lea	AllTimeString(a4),a0		; Copy current time and date
		lea	LogInTime(a4),a1
		bsr	StrCpy
		lea	AllDateString(a4),a0
		lea	LogInDate(a4),a1
		bsr	StrCpy
		lea	AllTimeString+6(a4),a0
		lea	CopyTime(a4),a1
		bsr	StrCpy

StillOnline	lea	$bfd000,a5
		btst	#CIAB_COMCD,ciapra(a5)		; Still online ?
		beq	.GoOn

		clr.b	Online(a4)			; Nope....
		clr.b	DontCheckTime(a4)

		tst.b	LogCalls(a4)			; Save log to file ?
		beq	.NoReenable

		cmp.l	#6,UnitsDone			; Skip for extreme short calls (like 3 secs)
		blt	.NoReenable

		move.w	#'N',d0				; Set char for either normal
		tst.b	CheapMode(a4)
		beq.s	.NoCheap
		move.w	#'C',d0				; ... or cheap mode
.NoCheap	move.w	d0,LogEntryTariff
		clr.l	CostMajor			; Calc total costs
		clr.l	CostMinor
		move.l	TotalCost(a4),d0
.CostLoop	cmp.l	#100,d0
		blt.s	.CostEnd
		sub.l	#100,d0
		addq.l	#1,CostMajor
		bra.s	.CostLoop
.CostEnd	move.l	d0,CostMinor

		link	a5,#-LOGENTRYSIZE		; Get Buffer for log-entry

		lea	LogEntryFormat,a0		; Format log entry
		lea	LogEntryDat,a1
		lea	PutChProc(pc),a2
		lea	-LOGENTRYSIZE(a5),a3
		CALLSYS	RawDoFmt

		lea	LogFileName(a4),a0
		move.l	a0,d1				; Open log file
		move.l	#MODE_READWRITE,d2
		RELLIB	Open,_DOSBase
		tst.l	d0
		beq.s	.NoLogWrite
		move.l	d0,d7
		move.l	d0,d1
		moveq	#0,d2
		move.l	#OFFSET_END,d3			; Seek to end
		DOLIB	Seek
		lea	-LOGENTRYSIZE(a5),a0
		move.l	d7,d1
		move.l	a0,d2				; Write new logentry
		DOLIB	FPuts
		move.l	d7,d1
		DOLIB	Close
.NoLogWrite	unlk	a5

.NoReenable	tst.b	BillPopUp(a4)
		beq.s	.EndLogOff
		tst.b	NoBillPDown(a4)
		bne.s	.EndLogOff
		bsr	CloseBillWin
.EndLogOff	clr.b	NoBillPDown(a4)
		clr.b	BillPopedUp(a4)
		bra	NotOnline

.GoOn		move.b	#1,Online(a4)			; Yep, we`re online

		cmp.l	#6,UnitsDone			; Open Bill window ?
		blt.s	.NoOpen
		tst.l	BillHandle(a4)

		tst.b	BillPopUp(a4)
		beq.s	.NoOpen
		tst.b	BillPopedUp(a4)
		bne.s	.NoOpen
		tst.l	BillHandle(a4)
		beq.s	.DoOpen
		move.b	#1,NoBillPDown(a4)
.DoOpen		move.b	#1,BillPopedUp(a4)
		bsr	OpenBillWin

.NoOpen		link	a5,#-4
		lea	-4(a5),a3
		lea	AllTimeString+6(a4),a0		; Get current seconds
		move.l	a0,d1
		move.l	a3,d2
		RELLIB	StrToLong,_DOSBase
		move.l	d1,d7				; Convert to long
		lea	CopyTime(a4),a0			; Get last seconds
		move.l	a0,d1
		move.l	a3,d2
		DOLIB	StrToLong			; Convert to long
		unlk	a5
		moveq	#0,d5
.GetValue	cmp.l	d1,d7				; Got seconds elapsed ?
		beq.s	.GotValue			; Yep -> go on
		addq.l	#1,d5				; One more second done
		addq.l	#1,d1
		cmp.l	#60,d1				; Over 60 boundary ?
		bne.s	.GetValue
		moveq	#0,d1				; Restart from scratch
		bra.s	.GetValue
.GotValue	add.l	d5,OnlineSeconds		; Remake online time
		cmp.l	#60,OnlineSeconds		; One minute done ?
		blt.s	.End				; Nope -> go on
		sub.l	#60,OnlineSeconds
		addq.l	#1,OnlineMinute
		cmp.l	#60,OnlineMinute		; One hour online ? GOSH
		bne.s	.End				; Nope -> go on
		clr.l	OnlineMinute
		addq.l	#1,OnlineHour

.End		lea	AllTimeString+6(a4),a0		; Copy current time
		lea	CopyTime(a4),a1
		bsr	StrCpy

		sub.l	d5,NextUnit
		add.l	d5,UnitsDone

NotOnline	bsr.s	RemakeCosts
		rts



**********************************************************************
*                  Remake texts within Bill window                   *
**********************************************************************
RemakeCosts	tst.b	DontCheckTime(a4)
		bne	.NoRemake
		lea	AllDayString(a4),a2
		tst.b	GermanDays(a4)
		beq.s	.CheckEng
		lea	DayNamesGer,a3
		bra.s	.CheckDays
.CheckEng	lea	DayNamesEng,a3
.CheckDays	moveq	#6,d6
		moveq	#0,d5
.DaysLoop	move.l	a2,a0
		move.l	(a3)+,a1
		bsr	StrCmp
		tst.l	d0
		beq.s	.GotDay
		addq.l	#1,d5
		dbf	d6,.DaysLoop
.GotDay		lea	Saturday(a4),a0
		tst.b	0(a0,d5)
		beq.s	.NormalDay
		link	a5,#-12
		moveq	#1,d3
		bra	.Done

.NormalDay	link	a5,#-12
		lea	AllTimeString(a4),a0		; Create Long value
		lea	-12(a5),a1
		move.b	(a0)+,(a1)
		move.b	(a0)+,1(a1)
		clr.b	2(a1)
		move.l	a1,d1
		lea	-8(a5),a1
		move.l	a1,d2
		RELLIB	StrToLong,_DOSBase		; Make longs out of hour

		lea	AllTimeString+3(a4),a0		; Create Long value
		lea	-12(a5),a1
		move.b	(a0)+,(a1)
		move.b	(a0)+,1(a1)
		clr.b	2(a1)
		move.l	a1,d1
		lea	-4(a5),a1
		move.l	a1,d2
		DOLIB	StrToLong			; now for the minutes

		move.l	CheapStart(a4),d0
		move.l	CheapStop(a4),d1

		move.l	-8(a5),d2
		mulu	#6,d2
		and.l	#$0000ffff,d2
		move.l	-4(a5),d3
		divu	#10,d3
		and.l	#$0000ffff,d3
		addq.l	#1,d3
		add.l	d3,d2				; d2 = Current time

		cmp.l	d0,d2
		blt.s	.NoCheap1
		cmp.l	d1,d2
		bgt.s	.NoCheap1
		moveq	#1,d3
		bra.s	.Done
.NoCheap1	cmp.l	d1,d2
		blt.s	.NoCheap2
		cmp.l	d0,d2
		bgt.s	.NoCheap2
		moveq	#0,d3
		bra.s	.Done
.NoCheap2	cmp.l	d0,d2
		blt.s	.NoCheap3
		cmp.l	d1,d2
		blt.s	.NoCheap3
		cmp.l	d0,d1
		bgt.s	.NoCheap4
		moveq	#1,d3
		bra.s	.Done
.NoCheap4	moveq	#0,d3
		bra.s	.Done
.NoCheap3	cmp.l	d0,d2
		bgt.s	.Done
		cmp.l	d1,d2
		bgt.s	.Done
		cmp.l	d0,d1
		bgt.s	.NoCheap6
		moveq	#1,d3
		bra.s	.Done
.NoCheap6	moveq	#0,d3
.Done		cmp.b	CheapMode(a4),d3
		beq.s	.TimeDone
		move.b	d3,CheapMode(a4)
		move.l	#GD_BillCheap,d0
		move.l	d3,d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetMXGad
		clr.b	DoRemakeCosts(a4)
.TimeDone	unlk	a5

.NoRemake	tst.b	Online(a4)			; Are we online ?
		beq.s	.NotOnline
		tst.l	NextUnit			; Next unit
		bgt.s	.NotOnline			; Nope...
		move.l	NextUnit,d1
		neg.l	d1
		move.l	TimeZone,d0			; Get timezone
		lsl.l	#3,d0
		lea	CostUnit1(a4),a0
		tst.b	CheapMode(a4)
		beq.s	.Normal
		move.l	cu_Cheap(a0,d0),d0		; Get costs for cheap mode
		bra.s	.GoOn
.Normal		move.l	cu_Normal(a0,d0),d0		; or for normal mode

.GoOn		sub.l	d1,d0				; Skip "over" seconds
		move.l	d0,NextUnit			; Store for next unit calc

		move.l	CostUnit(a4),d0			; Remake costs
		add.l	d0,TotalCost(a4)
		bsr	DisplayCost

.NotOnline	tst.b	DoRemakeCosts(a4)
		beq.s	.NoCostRemake
		clr.b	DoRemakeCosts(a4)
		move.l	TimeZone,d0			; Changed time/cheap mode ?
		lea	CostUnit1(a4),a0
		lsl.l	#3,d0
		tst.b	CheapMode(a4)
		beq.s	.RemNormal
		move.l	cu_Cheap(a0,d0),d0		; Get new time
		bra.s	.GoOnRemake
.RemNormal	move.l	cu_Normal(a0,d0),d0
.GoOnRemake	move.l	UnitsDone,d2
		divu	d0,d2
		and.l	#$0000ffff,d2
		tst.b	Online(a4)
		beq.s	.NoInitial
		tst.l	TotalCost(a4)
		bne.s	.DoInitial
.DoInitial	addq.l	#1,d2				; D2 = Number of units done for new time
.NoInitial	move.l	CostUnit(a4),d3
		mulu	d3,d2				; Get new costs for new time
		move.l	d2,TotalCost(a4)			; Store costs
		move.l	UnitsDone,d2			; Units done
		divu	d0,d2				; Calc overlap for next unit
		clr.w	d2
		swap	d2
		sub.l	d2,d0				; D0 = Event for next unit
		bge.s	.NoSubUnit			; On negative value
		neg.l	d0				; make it positive
.NoSubUnit	move.l	d0,NextUnit
		bsr	DisplayCost
.NoCostRemake	clr.l	CostMajor
		clr.l	CostMinor
		move.l	TimeZone,d0			; Calc total costs
		lsl.l	#3,d0
		lea	CostUnit1(a4),a0
		lea	0(a0,d0),a0
		tst.b	CheapMode(a4)
		beq.s	.StillNormal
		move.l	cu_Cheap(a0),d1			; either for cheap mode
		bra.s	.StillCheap
.StillNormal	move.l	cu_Normal(a0),d1		; or for normal mode
.StillCheap	move.l	#3600,d0
		divu	d1,d0
		and.l	#$0000ffff,d0			; d0 = Number of units/hour
		move.l	CostUnit(a4),d1
		mulu	d1,d0				; d0 = costs/hour
.TotLoop	cmp.l	#100,d0				; convert value
		blt.s	.EndLoop
		sub.l	#100,d0
		addq.l	#1,CostMajor
		bra.s	.TotLoop
.EndLoop	move.l	d0,CostMinor

		lea	FormLongSStr,a0			; Create Onlinetime
		lea	OnlineHour,a1
		lea	PutChProc(pc),a2
		lea	OnlineString(a4),a3
		CALLSYS	RawDoFmt

		tst.l	BillHandle(a4)
		beq	NoCostCalc
		tst.b	Zipped(a4)
		bne.s	.ZippedTitle

		lea	PerHourForm,a0			; Convert values to string
		lea	CostMajor,a1
		lea	PutChProc(pc),a2
		lea	PerHourBuff,a3
		DOLIB	RawDoFmt

		move.l	#GD_BillTime,d0
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		lea	AllTimeString(a4),a2
		bsr	SetTextGad

		move.l	#GD_BillOnline,d0
		lea	OnlineString(a4),a2
		bsr	SetTextGad

		move.l	#GD_BillCost,d0
		lea	CostString,a2
		bsr	SetTextGad

		move.l	#GD_BillHour,d0
		lea	PerHourStr,a2
		bsr	SetTextGad
		bra.s	NoCostCalc

.ZippedTitle	lea	OnlineString(a4),a0
		lea	FinalString(a4),a1
		bsr	StrCpy
		lea	CostString,a0
		lea	FinalString(a4),a1
		bsr	StrCat

		link	a5,#-6
		lea	-6(a5),a0
		move.b	#',',(a0)
		move.b	#' ',1(a0)
		move.l	TimeZone,d0
		add.b	#'1',d0
		move.b	d0,2(a0)
		tst.b	CheapMode(a4)
		beq.s	.NoCheap
		move.b	#'C',3(a0)
		bra.s	.EndZone
.NoCheap	move.b	#'N',3(a0)
.EndZone	clr.b	4(a0)
		lea	FinalString(a4),a1
		bsr	StrCat
		unlk	a5

		move.l	BillHandle(a4),a0		; Display / OnlineString
		lea	FinalString(a4),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
NoCostCalc	rts





**********************************************************************
*                Display new costs of telephone call                 *
**********************************************************************
DisplayCost	move.l	TotalCost(a4),d0
		clr.l	CostMajor
		clr.l	CostMinor

.Loop		cmp.l	#100,d0				; Calc costs
		blt.s	.LoopEnd
		sub.l	#100,d0
		addq.l	#1,CostMajor
		bra.s	.Loop
.LoopEnd	move.l	d0,CostMinor

		lea	CostFormString,a0		; Convert values
		lea	CostMajor,a1
		lea	PutChProc(pc),a2
		lea	CostString,a3
		CALLSYS	RawDoFmt
		rts



**********************************************************************
*                Display the total sum of phone calls                *
**********************************************************************
DisplayTotalSum	lea	LogFileName(a4),a0
		move.l	a0,d1				; First check size of file
		move.l	#ACCESS_READ,d2
		RELLIB	Lock,_DOSBase
		move.l	d0,d7
		tst.l	d0				; IS IT THERE ?
		bne.s	.GotFile
		rts
.GotFile	link	a5,#-fib_SIZEOF			; Get FIB
		lea	-fib_SIZEOF(a5),a0
		move.l	d7,d1				; Get FileInfo
		move.l	a0,d2
		DOLIB	Examine
		move.l	d7,d1
		DOLIB	UnLock				; Unlock file
		lea	-fib_SIZEOF(a5),a0		; Check size
		tst.l	fib_Size(a0)			; on zero quit
		bne.s	.SizeOk
		unlk	a5
		rts
.SizeOk		unlk	a5

		link	a5,#-(LOGENTRYSIZE*2+128)	; Get buffer for a log-entry

		sub.l	a0,a0
		lea	MyEasyRequest(pc),a1
		lea	FileWinTxt(pc),a2
		move.l	a2,es_TextFormat(a1)
		lea	FileWinGads(pc),a2
		move.l	a2,es_GadgetFormat(a1)
		sub.l	a2,a2
		sub.l	a3,a3
		RELLIB	EasyRequestArgs,_IntuitionBase
		tst.l	d0
		beq.s	.DisplayWin
		move.b	#1,SumToFile(a4)

		lea	-(LOGENTRYSIZE*2+128)(a5),a0
		clr.l	(a0)

		pea	0
		pea	0
		pea	0
		clr.w	-(sp)
		pea	-(LOGENTRYSIZE*2+128)(a5)
		pea	FileWinHead(pc)
		move.l	PrefsHandle(a4),-(sp)
		jsr	GetFileName
		lea	26(sp),sp
		tst.l	d0
		beq	.EndTotSum

		lea	-(LOGENTRYSIZE*2+128)(a5),a0
		move.l	a0,d1
		move.l	#MODE_NEWFILE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,TempHand(a4)
		tst.l	d0
		beq	.EndTotSum
		bra.s	.GoOnDisplay

.DisplayWin	clr.b	SumToFile(a4)
		lea	ConWinDef(pc),a0
		move.l	a0,d1				; Open CON: Window
		move.l	#MODE_OLDFILE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,TempHand(a4)
		tst.l	d0
		beq	.EndTotSum

		move.l	TempHand(a4),d1
		move.l	#ClearStr,d2
		move.l	#ClearStrLen,d3
		DOLIB	Write

.GoOnDisplay	lea	LogFileName(a4),a0
		move.l	a0,d1				; Open Log file
		move.l	#MODE_OLDFILE,d2
		DOLIB	Open
		move.l	d0,FileHand(a4)
		tst.l	d0
		beq	.EndTotSum

		moveq	#0,d7				; Clear linenumber
		moveq	#0,d5
		move.l	d7,BillMajor			; and cost
		move.l	d7,BillMinor
		move.l	d7,BillTotalCost
		move.l	d7,BillDayCost

.SumLoop	move.l	FileHand(a4),d1			; Get one line
		lea	-(LOGENTRYSIZE*2)(a5),a0
		move.l	a0,d2
		move.l	#(LOGENTRYSIZE*2)-1,d3
		DOLIB	FGets
		tst.l	d0
		bne.s	.GoOn
		bsr	DisplayDaySum			; Display final day costs
		moveq	#-1,d7				; Indicate end of file
		bra.s	.EndOfAll

.GoOn		bsr	CheckDay

		move.l	TempHand(a4),d1			; Display line
		lea	-(LOGENTRYSIZE*2)(a5),a0
		move.l	a0,d2
		DOLIB	FPuts

		lea	-(LOGENTRYSIZE*2)(a5),a3	; Get start of major-cost
		lea	72(a3),a3
		move.l	a3,a2
.LoopMinor	cmp.b	#'.',(a2)+			; find period
		beq.s	.GotMinor
		bra.s	.LoopMinor
.GotMinor	clr.b	-1(a2)				; Extract minor cost
		clr.b	2(a2)

		move.l	a3,d1
		move.l	#BillMajor,d2
		DOLIB	StrToLong
		tst.l	d0
		ble	.EndTotSum
		mulu	#100,d1
		move.l	d1,d6				; Get costs

		move.l	a2,d1
		move.l	#BillMinor,d2
		DOLIB	StrToLong
		tst.l	d0
		ble	.EndTotSum
		add.l	d1,d6				; ....
		add.l	d6,BillTotalCost
		add.l	d6,BillDayCost

		addq.l	#1,d7				; One line done
		cmp.l	#12,d7				; 12 lines done ?
		blt	.SumLoop
		moveq	#0,d7				; Reset line number
.EndOfAll	tst.l	d7				; All lines done ?
		beq.s	.NoFinalCost
		move.l	BillTotalCost,d6
		divu	#100,d6
		move.w	d6,d5
		swap	d6
		ext.l	d6
		move.l	d6,BillMinor
		ext.l	d5
		move.l	d5,BillMajor
		lea	FinalCostForm,a0		; Format final cost string
		lea	BillMajor,a1
		lea	PutChProc(pc),a2
		lea	-(LOGENTRYSIZE*2)(a5),a3
		CALLSYS	RawDoFmt
		move.l	TempHand(a4),d1			; Display string
		lea	-(LOGENTRYSIZE*2)(a5),a0
		move.l	a0,d2
		RELLIB	FPuts,_DOSBase
.NoFinalCost	tst.b	SumToFile(a4)
		bne.s	.NoKey
		move.l	TempHand(a4),d1			; Display prompt
		move.l	#PressKey,d2
		move.l	#PressKeyLen,d3
		DOLIB	Write
		move.l	TempHand(a4),d1			; Wait for return
		DOLIB	FGetC
.NoKey		tst.l	d7
		blt.s	.EndTotSum
		bra	.SumLoop

.EndTotSum	unlk	a5				; Free buffer

		tst.l	FileHand(a4)			; Close files
		beq.s	.NoFileHand
		move.l	FileHand(a4),d1
		DOLIB	Close
.NoFileHand	tst.l	TempHand(a4)
		beq.s	.NoTempHand
		move.l	TempHand(a4),d1
		DOLIB	Close
.NoTempHand	clr.l	TempHand(a4)
		clr.l	FileHand(a4)
		rts
ConWinDef	dc.b	"RAW:0/0//150/Telephone log info",0
		EVEN



**********************************************************************
*                  Check for a difference in dates                   *
**********************************************************************
CheckDay	move.l	d7,d6				; Store old line number
		tst.b	d5				; First day read ?
		beq.s	.FirstDay
		lea	-(LOGENTRYSIZE*2)(a5),a0	; Compare dates
		lea	BillDayStr,a1
		moveq	#7,d7
		bsr	StrCmp
		tst.l	d0
		beq.s	.End				; On equal -> go on
		bsr.s	DisplayDaySum			; Display sum for a day
.FirstDay	lea	-(LOGENTRYSIZE*2)(a5),a0	; Copy date to buffer
		lea	BillDayStr,a1
		moveq	#7,d7
		bsr	StrNCpy
		moveq	#1,d5				; Set flag
.End		move.l	d6,d7
		rts



**********************************************************************
*                     Display the sum for a day                      *
**********************************************************************
DisplayDaySum	movem.l	RegsAll,-(sp)

		link	a5,#-(LOGENTRYSIZE*2)		; Get buffer for a line

		move.l	BillDayCost,d3			; Get costs
		divu	#100,d3				; convert `em
		move.w	d3,d4
		swap	d3
		ext.l	d3
		move.l	d3,BillMinor
		ext.l	d4
		move.l	d4,BillMajor
		lea	DayCostForm,a0			; Format string
		lea	BillDayPtr,a1
		lea	PutChProc(pc),a2
		lea	-(LOGENTRYSIZE*2)(a5),a3
		CALLSYS	RawDoFmt
		clr.l	BillDayCost
		move.l	TempHand(a4),d1			; Make it appear
		lea	-(LOGENTRYSIZE*2)(a5),a0
		move.l	a0,d2
		RELLIB	FPuts,_DOSBase
		addq.l	#3,d6				; three more lines written
		unlk	a5
		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                      Check if we`re to alarm                       *
**********************************************************************
CheckForAlarm	tst.b	DoAlarm(a4)			; Are we to alarm ?
		beq.s	NoAlarm

		tst.b	EveryHour(a4)
		beq.s	.NoEveryHour
		link	a5,#-12
		lea	AllTimeString(a4),a0
		lea	-4(a5),a1
		move.b	(a0)+,(a1)
		move.b	(a0)+,1(a1)
		clr.b	2(a1)
		clr.b	3(a1)
		move.l	a1,d1
		lea	-12(a5),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		move.l	-12(a5),d0
		unlk	a5
		tst.l	ThisHour(a4)
		bge.s	.GoOn
		move.l	d0,ThisHour(a4)
		bra.s	.NoEveryHour
.GoOn		move.l	ThisHour(a4),d1
		move.l	d0,ThisHour(a4)
		cmp.l	d0,d1
		bne.s	.DoAlarm
.NoEveryHour	lea	AllTimeString(a4),a0
		bsr.s	GetAlarmCode
		cmp.l	AlarmTime(a4),d0
		bne.s	NoAlarm
.DoAlarm	lea	AllTimeString(a4),a0
		cmp.b	#'0',6(a0)
		bne.s	NoAlarm
		cmp.b	#'0',7(a0)
		bne.s	NoAlarm
		move.l	OurTask(a4),a1			; Signal mother to alarm
		move.l	AlarmSigFlag(a4),d0
		CALLSYS	Signal
NoAlarm		rts


**********************************************************************
*                         Get number of time                         *
**********************************************************************
GetAlarmCode	link	a5,#-(8+LEN_DATSTRING)
		lea	-(8+LEN_DATSTRING)(a5),a1
		bsr	StrCpy
		lea	-(8+LEN_DATSTRING)(a5),a3
		clr.b	2(a3)
		clr.b	5(a3)
		move.l	a3,d1
		lea	-4(a5),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		ble.s	.Error
		move.l	a3,d1
		addq.l	#3,d1
		lea	-8(a5),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		ble.s	.Error
		move.l	-4(a5),d0
		mulu	#60,d0
		add.l	-8(a5),d0
		unlk	a5
		rts
.Error		moveq	#-1,d0
		unlk	a5
		rts



**********************************************************************
*                        Do the full dragging                        *
**********************************************************************
DoDragging	movem.l	RegsAll,-(sp)

		link	a5,#-38
		bsr	FindWindow			; Get window underneith mouse
		tst.l	d0
		beq	.NoDrag
		move.l	d0,a0
		tst.l	lr_Window(a0)
		beq	.NoDrag
		move.l	lr_Window(a0),a0		; Window equipped with a dragbar ?
		move.l	wd_Flags(a0),d0
		and.l	#WFLG_DRAGBAR,d0
		beq	.NoDrag
		move.l	a0,-4(a5)			; Store pointer to window
		move.l	wd_WScreen(a0),-8(a5)		; Store Pointer to screen

		move.l	-8(a5),a0			; Set DrawMode
		lea	sc_RastPort(a0),a1
		move.l	a1,-12(a5)
		moveq	#0,d0				; Store old Drawmode
		move.b	rp_DrawMode(a1),d0
		move.w	d0,-14(a5)
		move.l	#RP_COMPLEMENT,d0
		RELLIB	SetDrMd,_GfxBase

		move.l	-4(a5),a0			; Get Window dimensions
		move.w	wd_LeftEdge(a0),-16(a5)
		move.w	wd_TopEdge(a0),-18(a5)
		move.w	wd_Width(a0),-20(a5)
		move.w	wd_Height(a0),-22(a5)
		subq.w	#1,-20(a5)
		subq.w	#1,-22(a5)

		move.l	-8(a5),a0			; Get Screen dimensions
		move.w	sc_Width(a0),d0
		sub.w	-20(a5),d0
		subq.w	#1,d0
		move.w	d0,-24(a5)
		move.w	sc_Height(a0),d0
		sub.w	-22(a5),d0
		subq.w	#1,d0
		move.w	d0,-26(a5)

		move.l	-8(a5),a1			; Get ViewModes to check how to move
		bsr	GetCoords			; Get current mouse coordinates
		move.w	d2,-28(a5)
		move.w	d3,-30(a5)
		move.w	d2,-32(a5)			; Double position
		move.w	d3,-34(a5)
		sub.w	-16(a5),d2
		sub.w	-18(a5),d3
		move.w	d2,-16(a5)
		move.w	d3,-18(a5)

		move.b	#1,ImDragging(a4)
		bsr	DrawWndRec			; Draw first rectangle
.DragLoop	move.l	#SIGMOUSE|SIGLBUTTON,d0
		CALLSYS	Wait
		and.l	#SIGLBUTTON,d0
		bne.s	.DragLoopEnd
		move.l	-8(a5),a1			; Get ViewModes to check how to move
		bsr	GetCoords			; Get mouse coordinates
		cmp.w	-28(a5),d2			; Position changed ?
		bne.s	.NewPos
		cmp.w	-30(a5),d3
		beq.s	.DragLoop
.NewPos		bsr.s	DrawWndRec			; Clear last rec
		move.w	d2,-28(a5)			; Store new positions
		move.w	d3,-30(a5)
		bsr.s	DrawWndRec			; Draw new rec
		bra.s	.DragLoop
.DragLoopEnd	bsr.s	DrawWndRec
		clr.b	ImDragging(a4)

.EndDrag	move.l	-8(a5),a0			; Reset old drawmode
		lea	sc_RastPort(a0),a1
		move.w	-14(a5),d0
		RELLIB	SetDrMd,_GfxBase

		move.w	-28(a5),d0			; Mouse position changed ?
		move.w	-30(a5),d1
		cmp.w	-32(a5),d0
		bne.s	.NewWinPos
		cmp.w	-34(a5),d1
		bne.s	.NewWinPos
.NewWinPos	move.l	-4(a5),a0			; Yep
		bsr	TestPosition			; Get new left/top edge
		move.w	d4,d0
		move.w	d5,d1
		move.w	wd_Width(a0),d2			; Get width
		move.w	wd_Height(a0),d3
		RELLIB	ChangeWindowBox,_IntuitionBase	; Move window
.NoDrag		unlk	a5
		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                    Draw the window`s rectangle                     *
**********************************************************************
DrawWndRec	bsr	TestPosition
		move.l	-12(a5),a1
		move.w	d4,d0
		move.w	d5,d1
		RELLIB	Move,_GfxBase

		move.l	-12(a5),a1
		move.w	d4,d0
		add.w	-20(a5),d0
		move.w	d5,d1
		DOLIB	Draw

		move.l	-12(a5),a1
		move.w	d4,d0
		add.w	-20(a5),d0
		move.w	d5,d1
		add.w	-22(a5),d1
		DOLIB	Draw

		move.l	-12(a5),a1
		move.w	d4,d0
		move.w	d5,d1
		add.w	-22(a5),d1
		DOLIB	Draw

		move.l	-12(a5),a1
		move.w	d4,d0
		move.w	d5,d1
		DOLIB	Draw
		rts



**********************************************************************
*                      Get correct coordinates                       *
**********************************************************************
GetCoords	move.l	a1,-(sp)
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase
		move.l	d0,d5
		move.l	(sp)+,a1
		move.l	ib_ActiveScreen(a6),a0
		moveq	#0,d2
		moveq	#0,d3
		move.w	sc_MouseX(a0),d2
		move.w	sc_MouseY(a0),d3
		movem.l	RegsAll,-(sp)
		move.l	d5,a0
		DOLIB	UnlockIBase
		movem.l	(sp)+,RegsAll
		rts


**********************************************************************
*                     Test the current positions                     *
**********************************************************************
TestPosition	move.w	-28(a5),d4
		sub.w	-16(a5),d4
		bge.s	.XBig
		moveq	#0,d4
		bra.s	.CheckY
.XBig		cmp.w	-24(a5),d4
		ble.s	.CheckY
		move.w	-24(a5),d4
.CheckY		move.w	-30(a5),d5
		sub.w	-18(a5),d5
		bge.s	.YBig
		moveq	#0,d5
		bra.s	.End
.YBig		cmp.w	-26(a5),d5
		ble.s	.End
		move.w	-26(a5),d5
.End		rts




**********************************************************************
*          This is the routine for handleing ARexx command           *
**********************************************************************
HandleARexx	move.l	ARexxPort(a4),a0		; Get ARexx msg
		CALLSYS	GetMsg
		move.l	d0,MyARexxMsg(a4)
		tst.l	d0
		beq	AllARexxDone
		move.l	d0,a0

		move.l	ACTION(a0),d0			; Get action to be taken
		move.l	d0,ARexxAction(a4)
		move.l	ARG0(a0),ARexxCommand(a4)

		move.l	#RC_OK,AResult1(a4)
		clr.l	AResult2(a4)

		and.l	#RXCOMM,d0			; Is it a command ?
		beq	ARexxCommDone

		move.l	ARexxCommand(a4),a0		; Check for activate command
		lea	ActivateStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoActivate

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,DoActivate(a4)
		move.l	#GD_WindowAct,d1
		bsr	SetSetBox
		bra	ARexxCommDone

ANoActivate	move.l	ARexxCommand(a4),a0		; Check for SunMouse command
		lea	MouseStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoSunMouse

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,SunMouse(a4)
		move.l	#GD_SunMouse,d1
		bsr	SetSetBox
		bra	ARexxCommDone

ANoSunMouse	move.l	ARexxCommand(a4),a0		; Check for ShowClock command
		lea	ShowCStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoShowClock

		bsr	CheckABool			; Check for flags (0/1)
		tst.l	d0
		blt	ACommFail
		move.b	d0,ShowClock(a4)		; Save flags
		move.l	#GD_Display,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		tst.b	ShowClock(a4)
		bne.s	.ANoWinClose
		bsr	CloseClockWin
.ANoWinClose	bra	ARexxCommDone


ANoShowClock	move.l	ARexxCommand(a4),a0		; Activate ClockWindow ?
		lea	ClockWStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoClockWin

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ClockWin(a4)
		move.l	#GD_DisplayWin,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoClockWin	move.l	ARexxCommand(a4),a0		; Reposition clockwindow ?
		lea	ClockPosStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoWinPos
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		bsr	GetWinPos
		tst.l	d0
		beq	ACommFail
		move.l	WinLeftEdge(a4),d0		; Store in NewWindow-Structure
		move.l	WinTopEdge(a4),d1
		move.w	d0,ClockWinLeft(a4)
		move.w	d1,ClockWinTop(a4)
		tst.l	ClockHandle(a4)			; Clockwindow open ?
		beq.s	NoReposClockWin
		move.l	ClockHandle(a4),a0
		cmp.w	wd_LeftEdge(a0),d0
		bne.s	.DoWinRepos
		cmp.w	wd_TopEdge(a0),d1
		beq.s	NoReposClockWin
.DoWinRepos	moveq	#0,d2
		moveq	#0,d3
		move.w	wd_Width(a0),d2
		move.b	wd_BorderTop(a0),d3
		RELLIB	ChangeWindowBox,_IntuitionBase	; Resize
		bsr	ClockRemake
NoReposClockWin	bra	ARexxCommDone

ANoWinPos	move.l	ARexxCommand(a4),a0		; Display date ?
		lea	ShowDateStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoShowDate

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ShowDate(a4)
		move.l	#GD_ShowDate,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoShowDate	move.l	ARexxCommand(a4),a0		; Show day ?
		lea	ShowDayStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoShowDay

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ShowDay(a4)
		move.l	#GD_ShowDay,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoShowDay	move.l	ARexxCommand(a4),a0		; Short day string ?
		lea	ShortDayStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoShortDay

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ShortDay(a4)
		move.l	#GD_ShortDay,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoShortDay	move.l	ARexxCommand(a4),a0		; Show seconds ?
		lea	ShowSecsStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoShowSecs

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ShowSecs(a4)
		move.l	#GD_ShowSecs,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoShowSecs	move.l	ARexxCommand(a4),a0		; Show american date ?
		lea	AmiDateStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoAmiDate

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,AmiDate(a4)
		move.l	#GD_AmiDate,d1
		bsr	SetMiscBox
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoAmiDate	move.l	ARexxCommand(a4),a0		; Change display page ?
		lea	PageNumStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoPageNum

		move.l	PageNum(a4),d7
		move.l	a0,d1
		lea	PageNum(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		ble.s	.Error
		tst.l	PageNum(a4)
		blt.s	.Error
		cmp.l	#MAXPAGES,PageNum(a4)
		blt.s	.End
.Error		clr.l	PageNum(a4)
.End		move.l	PageNum(a4),d0
		move.l	d0,OldPageNum(a4)
		bsr	ClearTitleBar
		bsr	SigTime
		bra	ARexxCommDone

ANoPageNum	move.l	ARexxCommand(a4),a0		; Activate alarm
		lea	AlarmStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoAlarm

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,DoAlarm(a4)
		move.l	#GD_AlarmOn,d1
		bsr	SetAlarmBox
		bra	ARexxCommDone

ANoAlarm	move.l	ARexxCommand(a4),a0		; Set alarm time ?
		lea	AlarmTimeStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoAlarmTime

		bsr	GetAlarmCode
		tst.l	d0
		blt	ACommFail
		cmp.l	#(24*60)-1,d0
		bgt	ACommFail
		move.l	d0,AlarmTime(a4)
		bsr	SetAlarmGads
		bra	ARexxCommDone

ANoAlarmTime	move.l	ARexxCommand(a4),a0		; Enable/Disable env vars ?
		lea	SetEnvStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoSetEnv

		bsr	CheckABool			; Bool flag ???
		tst.l	d0
		blt	ACommFail
		move.b	d0,SetEnv(a4)
		move.l	#GD_WriteEnv,d1
		bsr	SetSetBox
		tst.b	SetEnv(a4)
		bne.s	.NoDel
		bsr	DeleteEnvs			; Delete vars if setenv is off
.NoDel		bsr	SigTime				; Set the time
		bra	ARexxCommDone

ANoSetEnv	move.l	ARexxCommand(a4),a0		; New screenblank time ?
		lea	ScreenTStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoScreenTime
		move.l	ScreenTime(a4),d7
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	ARexxBuffer(a4),d1
		lea	ScreenTime(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase		; Get new time
		tst.l	ScreenTime(a4)			; negative ?
		blt.s	.Error				; disable blank
		tst.l	d0
		bge.s	.GoOn
.Error		move.l	d7,ScreenTime(a4)
.GoOn		move.l	#GD_ScrTime,d0
		move.l	d7,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	SetSliderGad
		move.b	#1,TimeReset(a4)
		bra	ARexxCommDone

ANoScreenTime	move.l	ARexxCommand(a4),a0		; New mouseblank time ?
		lea	MouseTStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoMouseTime
		move.l	MouseTime(a4),d7
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	ARexxBuffer(a4),d1
		lea	MouseTime(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase		; Get new time
		tst.l	MouseTime(a4)			; Negative -> disable blank
		blt.s	.Error
		tst.l	d0
		bge.s	.GoOn
.Error		move.l	d7,MouseTime(a4)
.GoOn		move.l	#GD_MouseTime,d0
		move.l	d7,d1
		lea	BlankGads(a4),a0
		move.l	BlankHandle(a4),a1
		bsr	SetIntegerGad
		move.b	#1,TimeReset(a4)
		bra	ARexxCommDone

ANoMouseTime	move.l	ARexxCommand(a4),a0
		lea	ClickVStr(pc),a1		; Remake click volume ?
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoClickVol

		move.l	ClickVol(a4),d7
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	ARexxBuffer(a4),d1
		lea	ClickVol(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		tst.l	d0
		ble.s	.Error
		cmp.l	#64,ClickVol(a4)
		bgt.s	.Error
		tst.l	ClickVol(a4)
		bge.s	.GoOn
.Error		move.l	d7,ClickVol(a4)
.GoOn		move.l	#GD_ClickVol,d0
		move.l	d7,d1
		lea	MiscGads(a4),a0
		move.l	MiscHandle(a4),a1
		bsr	SetSliderGad
		bra	ARexxCommDone

ANoClickVol	move.l	ARexxCommand(a4),a0		; Enable/Disable Window-Cycling ?
		lea	CycleWStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoCycleWin

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,CycleWin(a4)
		move.l	#GD_CycleOn,d1
		lea	CycleGads(a4),a0
		move.l	CycleHandle(a4),a1
		bsr	SetCheckBox
		bra	ARexxCommDone

ANoCycleWin	move.l	ARexxCommand(a4),a0		; Enable/Disable click ?
		lea	ClickStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoClickOff

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,KeyClick(a4)
		move.l	#GD_KeyClick,d1
		bsr	SetMiscBox
		bra	ARexxCommDone

ANoClickOff	move.l	ARexxCommand(a4),a0		; Enable/Disable phone logs ?
		lea	LogCallStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoLogCalls

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,LogCalls(a4)			; Set mode
		move.l	#GD_LogCall,d1
		lea	BillGads(a4),a0
		move.l	BillHandle(a4),a1
		bsr	SetCheckBox
		bra	ARexxCommDone

ANoLogCalls	move.l	ARexxCommand(a4),a0		; Reposition bill window ?
		lea	BillPosStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoBillWinPos

		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy

		bsr	GetWinPos
		tst.l	d0
		beq	ACommFail
		lea	BillWinLeft(a4),a0
		move.l	WinLeftEdge(a4),d0		; Store in NewWindow-Structure
		move.l	WinTopEdge(a4),d1
		move.w	d0,nw_LeftEdge(a0)
		move.w	d1,nw_TopEdge(a0)
		tst.l	BillHandle(a4)			; BillWindow open ?
		beq.s	.End
		move.l	BillHandle(a4),a0
		cmp.w	wd_LeftEdge(a0),d0
		bne.s	.DoWinRepos
		cmp.w	wd_TopEdge(a0),d1
		beq.s	.End
.DoWinRepos	moveq	#0,d2
		moveq	#0,d3
		move.w	wd_Width(a0),d2
		move.w	wd_Height(a0),d3
		RELLIB	ChangeWindowBox,_IntuitionBase	; Resize
.End		bra	ARexxCommDone

ANoBillWinPos	move.l	ARexxCommand(a4),a0
		lea	BillWinStr(pc),a1		; Popup billwindow on carrier detect ?
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoBillPopUp

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,BillPopUp(a4)		; set new state
		move.l	#GD_PopUpBill,d1
		lea	PrefsGads(a4),a0
		move.l	PrefsHandle(a4),a1
		bsr	SetCheckBox
		bra	ARexxCommDone

ANoBillPopUp	move.l	ARexxCommand(a4),a0		; Clear log file ?
		lea	AClearLogStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoClearLog
		lea	LogFileName(a4),a0
		move.l	a0,d1
		RELLIB	DeleteFile,_DOSBase
		bra	ARexxCommDone

ANoClearLog	move.l	ARexxCommand(a4),a0		; Enable/Disable ESC-Close ?
		lea	ESCCloseStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoESCClose

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ESCClose(a4)
		move.l	#GD_ESCClose,d1
		bsr	SetMiscBox
		bra	ARexxCommDone

ANoESCClose	move.l	ARexxCommand(a4),a0		; Enable/Disable "Map Umlauts ?"
		lea	UmlautOnStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoUmlautOn

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,MapUmlaut(a4)
		move.l	#GD_MapUmlauts,d1
		bsr	SetSetBox
		bra	ARexxCommDone

ANoUmlautOn	move.l	ARexxCommand(a4),a0		; Enable/Disable Mouse Accelerator ?
		lea	AccelStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoAccel

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,MouseAccel(a4)
		bsr	SetMouseGads
		bra	ARexxCommDone

ANoAccel	move.l	ARexxCommand(a4),a0		; Enable/Disable Screen-Dimmer ?
		lea	ScrDimmStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoScrDimm

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,ScreenDimm(a4)
		bsr	SetBlankGads
		bra	ARexxCommDone

ANoScrDimm	move.l	ARexxCommand(a4),a0		; Change Auto Center mode ?
		lea	AutoCtrStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoAutoCtr

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,AutoCenter(a4)
		move.b	AutoCenter(a4),d0		; Set Auto Center gadget
		move.l	#GD_AutoCtr,d1
		bsr	SetSetBox
		bra	ARexxCommDone

ANoAutoCtr	move.l	ARexxCommand(a4),a0		; Changed MMBShift mode ?
		lea	MMBShiftStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoMMBShift

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,MMBShift(a4)
		move.b	MMBShift(a4),d0			; Set Auto Center gadget
		move.l	#GD_MMBShift,d1
		bsr	SetSetBox
		bra	ARexxCommDone

ANoMMBShift	move.l	ARexxCommand(a4),a0		; Enable broker ?
		lea	EnableStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoEnable
		clr.b	Disabled(a4)
		move.b	#1,TimeReset(a4)
		bsr	EnableBroker
		bra	ARexxCommDone

ANoEnable	move.l	ARexxCommand(a4),a0		; Disable broker ?
		lea	DisableStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoDisable
		bsr	DisableBroker
		CALLSYS	Forbid
		bsr	OnScreen
		CALLSYS	Permit
		bsr	OnMouse
		move.b	#1,Disabled(a4)
		bra	ARexxCommDone

ANoDisable	move.l	ARexxCommand(a4),a0		; Hide window ?
		lea	HideStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoHide
		bsr	CloseMainWin
		bra	ARexxCommDone

ANoHide		move.l	ARexxCommand(a4),a0		; PopUp window ?
		lea	APopUpStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoPopUp
		bsr	OpenMainWin
		bra	ARexxCommDone

ANoPopUp	move.l	ARexxCommand(a4),a0		; Return a status ?
		lea	AStatusStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoStatus
		bsr	ReturnStatus
		tst.l	d0
		beq	ACommFail
		bra	ARexxCommDone

ANoStatus	move.l	ARexxCommand(a4),a0		; Do a revision ?
		lea	AReviseStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne	ANoRevise
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	ARexxBuffer(a4),a1
		move.l	a1,a0
.Loop		tst.b	(a1)				; Get filename
		beq	ACommFail
		cmp.b	#' ',(a1)
		beq.s	GotFileName
		cmp.b	#'"',(a1)
		beq.s	GotFileName
		cmp.b	#"'",(a1)
		beq.s	GotFileName
		addq.l	#1,a1
		bra	.Loop
GotFileName	clr.b	(a1)+
		move.l	a1,a3
		lea	FileName(a4),a1			; Copy filename
		bsr	StrCpy
		move.l	a3,a0
		bsr	SkipBlanks
		move.l	a0,a3
		lea	AReviseCStr(pc),a1		; C or ASM revision ?
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	NoCMode
		move.l	#CRevDefine1,RevDefine		; Set Pointer to macro text
		move.b	#'/',d0				; First char of header
		move.b	#'*',d1				; Line introducer
		move.b	d0,d2				; Trailing char
		bra.s	GotMode
NoCMode		move.l	a3,a0
		lea	AReviseAsmStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	NoAsmMode
		move.l	#AsmRevDefine1,RevDefine	; Pointer to defines
		move.b	#';',d0
		move.b	d0,d1
		move.b	#'*',d2
		bra.s	GotMode
NoAsmMode	move.l	a3,a0
		lea	ARevisePasStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	NoPasMode
		move.l	#PASRevDefine1,RevDefine	; Pointer to defines
		move.b	#'{',d0
		move.b	#'*',d1
		move.b	#'}',d2
		bra.s	GotMode
NoPasMode	move.l	a3,a0
		lea	AReviseBasStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne	ACommFail
		move.l	#BASRevDefine1,RevDefine	; Pointer to defines
		move.b	#"`",d0
		move.b	d0,d1
		move.b	#'*',d2
GotMode		bsr	DoRevision
		tst.l	d0
		beq	ACommFail
		bra	ARexxCommDone

ANoRevise	move.l	ARexxCommand(a4),a0		; Load new prefs ?
		lea	ALoadPrefsStr,a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoLoadPrefs
		move.l	a0,a3
		lea	PrefsFileName(a4),a0
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	a3,a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy
		jsr	LoadPrefs
		bsr	ClearTitleBar
		bsr	SigTime
		move.l	ARexxBuffer(a4),a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy
		bra	ARexxCommDone

ANoLoadPrefs	move.l	ARexxCommand(a4),a0		; Save prefs to file ?
		lea	ASavePrefsStr,a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoSavePrefs
		move.l	a0,a3
		lea	PrefsFileName(a4),a0
		move.l	ARexxBuffer(a4),a1
		bsr	StrCpy
		move.l	a3,a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy
		jsr	DoublePrefs
		move.l	ARexxBuffer(a4),a0
		lea	PrefsFileName(a4),a1
		bsr	StrCpy
		bra	ARexxCommDone

ANoSavePrefs	move.l	ARexxCommand(a4),a0		; New drive selected ?
		lea	DriveStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoDrive

		link	a5,#-4
		move.l	a0,d1
		lea	-4(a5),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase
		move.l	-4(a5),d1
		unlk	a5
		tst.l	d0
		beq	ACommFail
		move.l	d1,d0
		lea	DriveRequests(a4),a0
		lsl.l	#2,d0
		tst.l	0(a0,d0.w)
		beq	ACommFail
		move.w	d1,FormatDrive(a4)

		move.l	#GD_Drive,d0			; Set Drive gadget
		moveq	#0,d1
		move.w	FormatDrive(a4),d1
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		lea	DriveList(a4),a2
		bsr	SetCycleGad
		bra	ARexxCommDone

ANoDrive	move.l	ARexxCommand(a4),a0		; Change label for disks
		lea	LabelStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoLabel

		lea	DefLabel,a1
		move.l	#29,d7
		bsr	StrNCpy
		move.l	#GD_Label,d0
		lea	FormGads(a4),a0
		move.l	FormHandle(a4),a1
		move.l	#30,d1
		lea	DefLabel,a2
		bsr	SetStringGad
		bra	ARexxCommDone

ANoLabel	move.l	ARexxCommand(a4),a0		; Changed Icons mode ?
		lea	AIconStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoTrash

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,MakeIcons(a4)
		move.l	#GD_Trashcan,d1
		bsr	SetFormBox
		bra	ARexxCommDone

ANoTrash	move.l	ARexxCommand(a4),a0		; Changed Icons mode ?
		lea	QuickStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoQuick

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,QuickFormat(a4)
		move.l	#GD_Quick,d1
		bsr	SetFormBox
		bra	ARexxCommDone

ANoQuick	move.l	ARexxCommand(a4),a0		; Changed Icons mode ?
		lea	FFSStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoFFS

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,FFSDrive(a4)
		move.l	#GD_FFS,d1
		bsr	SetFormBox
		bra	ARexxCommDone

ANoFFS		move.l	ARexxCommand(a4),a0		; Changed Icons mode ?
		lea	VerifyStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoVerify

		bsr	CheckABool
		tst.l	d0
		blt	ACommFail
		move.b	d0,NoVerify(a4)
		move.l	#GD_NoVerify,d1
		bsr	SetFormBox
		bra	ARexxCommDone

ANoVerify	move.l	ARexxCommand(a4),a0		; Changed Trashcan Icons mode ?
		lea	InstallStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoInstall

		bsr	CheckABool
		tst.l	d0
		blt.s	ACommFail
		move.b	d0,Install(a4)
		move.l	#GD_Install,d1
		bsr	SetFormBox
		bra.s	ARexxCommDone

ANoInstall	move.l	ARexxCommand(a4),a0		; Changed Icons mode ?
		lea	EjectStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoEject

		bsr	CheckABool
		tst.l	d0
		blt.s	ACommFail
		move.b	d0,EjectDrive(a4)
		move.l	#GD_Eject,d1
		bsr	SetFormBox
		bra.s	ARexxCommDone

ANoEject	move.l	ARexxCommand(a4),a0		; Changed watch mode ?
		lea	WatchStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ANoWatch

		bsr	CheckABool
		tst.l	d0
		blt.s	ACommFail
		move.b	d0,WatchDisks(a4)
		move.l	#GD_WatchDisks,d1
		bsr	SetFormBox
		bra.s	ARexxCommDone

ANoWatch	move.l	ARexxCommand(a4),a0		; Start format ?
		lea	FormatStr(pc),a1
		bsr	CheckARexxComm
		tst.l	d0
		bne.s	ARexxCommDone

		bsr	GoGoGoFormat
		bra.s	ARexxCommDone

ACommFail	move.l	#RC_FAIL,AResult1(a4)		; Command failed
		clr.l	AResult2(a4)
ARexxCommDone	move.l	MyARexxMsg(a4),a1
		move.l	AResult1(a4),rm_Result1(a1)
		move.l	AResult2(a4),rm_Result2(a1)
		CALLSYS	ReplyMsg
		bra	HandleARexx
AllARexxDone	rts

**********************************************************************
*                          ARexx variables                           *
**********************************************************************
ActivateStr	dc.b	"ACTIVATE",0
MouseStr	dc.b	"SUNMOUSE",0
ShowCStr	dc.b	"SHOWCLOCK",0
ClockWStr	dc.b	"CLOCKWIN",0
ClockPosStr	dc.b	"CLOCKWINPOS",0
ShowDateStr	dc.b	"SHOWDATE",0
ShowDayStr	dc.b	"SHOWDAY",0
ShortDayStr	dc.b	"SHORTDAY",0
ShowSecsStr	dc.b	"SHOWSECS",0
AmiDateStr	dc.b	"AMIDATE",0
PageNumStr	dc.b	"PAGENUM",0
AlarmStr	dc.b	"ALARM",0
AlarmTimeStr	dc.b	"ALARMTIME",0
SetEnvStr	dc.b	"SETENV",0
ScreenTStr	dc.b	"SCREENTIME",0
MouseTStr	dc.b	"MOUSETIME",0
CycleWStr	dc.b	"CYCLING",0
ClickStr	dc.b	"CLICK",0
ClickVStr	dc.b	"CLICKVOL",0
BillPosStr	dc.b	"BILLWINPOS",0
BillWinStr	dc.b	"BILLPOPUP",0
LogCallStr	dc.b	"LOGCALLS",0
ESCCloseStr	dc.b	"ESCCLOSE",0
UmlautOnStr	dc.b	"MAPUMLAUT",0
AccelStr	dc.b	"ACCELERATE",0
ScrDimmStr	dc.b	"SCRDIMM",0
DriveStr	dc.b	"DRIVE",0
LabelStr	dc.b	"LABEL",0
AIconStr	dc.b	"TRASHCAN",0
QuickStr	dc.b	"QUICK",0
FFSStr		dc.b	"FFS",0
VerifyStr	dc.b	"NOVERIFY",0
InstallStr	dc.b	"INSTALL",0
EjectStr	dc.b	"EJECT",0
WatchStr	dc.b	"WATCHDISKS",0
FormatStr	dc.b	"FORMAT",0
AutoCtrStr	dc.b	"AUTOCENTER",0
MMBShiftStr	dc.b	"MMBSHIFT",0
EnableStr	dc.b	"ENABLE",0
DisableStr	dc.b	"DISABLE",0
HideStr		dc.b	"HIDE",0
AClearLogStr	dc.b	"CLEARLOG",0
APopUpStr	dc.b	"POPUP",0
AStatusStr	dc.b	"STATUS",0
AReviseStr	dc.b	"REVISE",0
AReviseAsmStr	dc.b	"ASM",0
AReviseCStr	dc.b	"C",0
ARevisePasStr	dc.b	"PAS",0
AReviseBasStr	dc.b	"BAS",0
ALoadPrefsStr	dc.b	"LOADPREFS",0
ASavePrefsStr	dc.b	"SAVEPREFS",0
		EVEN



**********************************************************************
*            Return a status value to the calling program            *
**********************************************************************
ReturnStatus	movem.l	RegsAll,-(sp)

		link	a5,#-STATUSLINESIZE		; Get buffer for status

		move.l	ARexxAction(a4),d0		; Result expected ?
		and.l	#RXFF_RESULT,d0
		beq	StatError			; Nope -> go on
		lea	-STATUSLINESIZE(a5),a1
		bsr	StrCpy
		lea	-STATUSLINESIZE(a5),a0
		move.l	a0,d1
		lea	StatusNum(a4),a0
		move.l	a0,d2
		RELLIB	StrToLong,_DOSBase		; Convert statusnumber to long
		tst.l	d0
		ble	StatError
		move.l	StatusNum(a4),d0		; Check if status num is ok
		cmp.l	#StatusCount,d0
		bgt	StatError
		subq.l	#1,d0
		lsl.l	#3,d0
		lea	ARexxStatus(pc),a0
		lea	0(a0,d0),a2			; Get address for stat info

		cmp.l	#RESULTCLOCKPOS,(a2)		; Give position of clockwindow ?
		bne.s	NoClockStatus
		move.w	ClockWinLeft(a4),ResultWinData(a4)	; Store position
		move.w	ClockWinTop(a4),ResultWinData+2(a4)
		lea	ResultWinFormat,a0
		lea	ResultWinData(a4),a1
		bra	MakeResultStr

NoClockStatus	cmp.l	#RESULTTIME,(a2)		; Return alarm time ?
		bne.s	NoTimeStatus
		bra	ResultStrDone

NoTimeStatus	cmp.l	#RESULTBILLPOS,(a2)		; Give position of billwindow ?
		bne.s	NoBillStatus
		move.w	BillWinLeft(a4),ResultWinData(a4)	; Store position
		move.w	BillWinTop(a4),ResultWinData+2(a4)
		lea	ResultWinFormat,a0
		lea	ResultWinData(a4),a1
		bra.s	MakeResultStr

NoBillStatus	moveq	#0,d0
		move.l	4(a2),a3
		lea	ResultFormat,a0
		lea	ResultData(a4),a1
		cmp.l	#RESULTBYTE,(a2)		; Is stored as byte ?
		bne.s	NoByteResult
		move.b	(a3),d0
		move.l	d0,ResultData(a4)
		bra.s	MakeResultStr

NoByteResult	cmp.l	#RESULTWORD,(a2)		; ... as word ?
		bne.s	NoWordResult
		move.w	(a3),d0
		move.l	d0,ResultData(a4)
		bra.s	MakeResultStr

NoWordResult	cmp.l	#RESULTLONG,(a2)		; ... as long ?
		bne.s	NoLongResult
		move.l	(a3),d0
		move.l	d0,ResultData(a4)
		bra.s	MakeResultStr

NoLongResult	cmp.l	#RESULTSTRING,(a2)		; Return a string ?
		bne.s	StatError
		move.l	a3,a0
		lea	-STATUSLINESIZE(a5),a1
		bsr	StrCpy
		bra.s	ResultStrDone

MakeResultStr	lea	PutChProc(pc),a2		; Convert string
		lea	-STATUSLINESIZE(a5),a3
		CALLSYS	RawDoFmt

ResultStrDone	lea	-STATUSLINESIZE(a5),a0
		bsr	StrLen
		RELLIB	CreateArgstring,_RexxSysBase	; Create argstring and store it
		tst.l	d0				; If an error occured indicate it
		beq.s	StatError
		move.l	d0,AResult2(a4)
EndStatus	unlk	a5
		movem.l	(sp)+,RegsAll
		moveq	#1,d0
		rts
StatError	unlk	a5
		movem.l	(sp)+,RegsAll
		moveq	#0,d0
		rts


**********************************************************************
*                Checks, if we know the ARexx command                *
**********************************************************************
CheckARexxComm	moveq	#0,d0
		moveq	#0,d1
.Loop		move.b	(a0)+,d0			; Get chars from buffer
		move.b	(a1)+,d1
		or.b	#$20,d0				; Make it case in-sensitive
		or.b	#$20,d1
		cmp.b	#$20,d0				; Argstring end ?
		beq.s	.StringOk
		cmp.b	d0,d1
		beq.s	.Loop
.StringFalse	moveq	#1,d0				; Error flag
		rts
.StringOk	cmp.b	#$20,d1				; Our string also ending ?
		bne	.StringFalse			; Nope -> go on
		bsr	SkipBlanks
		moveq	#0,d0				; Command OK
		rts


**********************************************************************
*             Checks for flags (0/1) in an ARexx-Command             *
**********************************************************************
CheckABool	cmp.b	#'0',(a0)
		beq.s	.False
		cmp.b	#'1',(a0)
		beq.s	.True
		moveq	#-1,d0
		rts
.False		moveq	#0,d0
		rts
.True		moveq	#1,d0
		rts




**********************************************************************
*              Enter a log message and revise the text               *
**********************************************************************
DoRevision	clr.l	OurLock(a4)

		move.b	d0,CHeader			; Write chars to Header
		move.b	d1,CLineNL			; for different languages
		move.b	d1,CLine
		move.b	d1,CCopyRight
		move.b	d1,CCopyRight+21
		move.b	d1,CFile
		move.b	d1,CCreatedOn
		move.b	d1,CAuthor
		move.b	d1,CRevision
		move.b	d1,CPurpose
		move.b	d1,CPurpose+3
		move.b	d1,CPurpose+6
		move.b	d1,CPurpose+17
		move.b	d1,CLog
		move.b	d1,CLog+3
		move.b	d1,CLog+26
		move.b	d1,CLog+44
		move.b	d1,CLogInit
		move.b	d1,CLogInit+3
		move.b	d1,CLogInit+26
		move.b	d1,CLogInit+44
		move.b	d1,CLogInit+75
		move.b	d1,CEnd
		move.b	d2,CEnd+81


		lea	FileName(a4),a0
.LoopDev	cmp.b	#':',(a0)			; Find out whether filename
		beq.s	.GotDev				; is given with complete path
		tst.b	(a0)
		beq.s	.NoDev
		addq.l	#1,a0
		bra.s	.LoopDev

.NoDev		move.l	MyARexxMsg(a4),a0		; Lock to current Dir of
		move.l	MN_REPLYPORT(a0),a0		; ARexx. Normaly the workdirectory
		move.l	MP_SIGTASK(a0),a0		; your editor is running on.
		move.l	pr_CurrentDir(a0),d1		; If a path is specified
		RELLIB	DupLock,_DOSBase
		move.l	d0,OurLock(a4)
		tst.l	d0
		beq	NoRevision
		move.l	d0,d1
		DOLIB	CurrentDir
		move.l	d0,PastLock(a4)
		tst.l	d0
		beq	NoRevision

.GotDev		bsr	CheckRevision			; Check if Revision already there
		tst.l	d7
		blt	NoRevision

		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.LogWinError
		move.l	d0,a0
		RELLIB	ScreenToFront,_IntuitionBase
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,LogVisInfo(a4)
		beq	.LogWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	LogWinWidth(a4),d2
		move.w	LogWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	LogWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	LogWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	LogGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.LogWinError

		lea	LogGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	LogVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#5*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#502*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#14*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_Line1,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#12,d0
		lea.l	Line1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#20*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.w	#GD_Line2,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	Line1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#36*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.w	#GD_Line3,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	Line1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#52*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.w	#GD_Line4,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	Line1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#68*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
  ;		 add.w	 d3,gng_TopEdge(a1)
		move.w	#GD_Line5,gng_GadgetID(a1)
		move.l	#12,d0
		lea.l	Line1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#86*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#67*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#LogOkText,gng_GadgetText(a1)
		move.w	#GD_LogOk,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#440*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#LogCancelText,gng_GadgetText(a1)
		move.w	#GD_LogCancel,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#227*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#36*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#LogVerText,gng_GadgetText(a1)
		move.w	#GD_LogVer,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#3,d0
		lea.l	LogVerTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#286*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#LogRevText,gng_GadgetText(a1)
		move.w	#GD_LogRev,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	LogVerTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.LogWinError

		lea	LogGads(a4),a0
		bsr	SetStrIntGads

		move.l	LogGadget(a4),LogWinWG+4
		move.l	-4(a5),LogWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,LogWinL+4
		move.l	d3,LogWinT+4
		move.l	-4(a5),a0
		move.w	LogWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,LogWinW+4
		move.w	LogWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,LogWinH+4
		suba.l	a0,a0
		lea.l	LogWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,LogHandle(a4)
		beq.s	.LogWinError

		move.l	LogHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr	UnlockScreen
		unlk	a5
		bra.s	.GotLogWin
.LogWinError	bsr	UnlockScreen
		unlk	a5
		bra	NoLogWin

.GotLogWin	lea	NewMsg(a4),a1			; and messages
		move.w	#(62*5)-1,d7
.Loop1		clr.b	(a1)+
		dbf	d7,.Loop1

		tst.b	OnlyLog(a4)			; Enter a new LogMessage ?
		bne.s	DoOnlyLog
		move.l	LogHandle(a4),a0		; Set window title for purpose
		lea	PurposeWinTitle(pc),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		bsr	CheckRevInput
		cmp.b	#2,LogInputEnd(a4)
		beq	NoErrorFound
		lea	NewMsg(a4),a3
		bsr	CopyMessage			; Copy entered message
		bra.s	PurpDone

DoOnlyLog	move.l	LogHandle(a4),a0		; Change to log title
		lea	LogWinTitle(pc),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		bsr	CheckRevInput
		cmp.b	#2,LogInputEnd(a4)
		beq	NoErrorFound
		lea	NewMsg(a4),a3
		bsr	CopyMessage			; Copy entered message

PurpDone	link	a5,#-(4+4+2+2+2+2+20+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.ProgWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,ProgVisInfo(a4)
		beq	.ProgWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	ProgWinWidth(a4),d2
		move.w	ProgWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	ProgWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	ProgWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	ProgGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.ProgWinError

		lea.l	-(4+4+2+2+2+2+20+gng_SIZEOF)(a5),a1
		move.l	ProgVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#6*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#26*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_Prog0,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	Prog0Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+20+gng_SIZEOF)(a5),a1
		move.l	#265*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#42*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.w	#GD_Prog100,gng_GadgetID(a1)
		move.l	#13,d0
		lea.l	Prog100Tags,a2
		DOLIB	CreateGadgetA
		tst.l	d0
		beq	.ProgWinError

		move.l	ProgGadget(a4),ProgWinWG+4
		move.l	-4(a5),ProgWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,ProgWinL+4
		move.l	d3,ProgWinT+4
		move.l	-4(a5),a0
		move.w	ProgWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,ProgWinW+4
		move.w	ProgWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,ProgWinH+4
		suba.l	a0,a0
		lea.l	ProgWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,ProgHandle(a4)
		beq	.ProgWinError
		move.l	d0,a0
		move.l	wd_RPort(a0),ProgRPort(a4)
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		move.l	ProgHandle(a4),a0
		move.w	ProgWinWidth(a4),d2
		move.l	ProgWinHeight(a4),d3
		bsr	ComputeFont

		move.l	ProgHandle(a4),a0
		move.l	wd_RPort(a0),a2
		move.l	a2,a0
		lea.l	-(4+4+2+2+2+2+20)(a5),a1	; Set Bevel tag
		move.l	#GTBB_Recessed,(a1)
		move.l	#1,4(a1)
		move.l	#GT_VisualInfo,8(a1)
		move.l	ProgVisInfo(a4),12(a1)
		move.l	#TAG_DONE,16(a1)
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.l	d0,d1
		move.l	#221*FRAC,d0
		bsr	ComputeX
		move.l	d0,d2
		move.l	#16*FRAC,d0
		bsr	ComputeY
		move.l	d0,d3
		move.l	#39*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		DOLIB	DrawBevelBoxA

		bsr	UnlockScreen
		unlk	a5
		bra.s	.ProgOpen

.ProgWinError	bsr	UnlockScreen
		unlk	a5
		bra	NoLogWin

.ProgOpen	move.l	LogHandle(a4),a0
		bsr	SetBusy

		lea	Author(a4),a0
		move.l	a0,RevAuthorDat			; Set strings to defaults
		lea	Company(a4),a0
		move.l	a0,RevCompanyDat

		lea	AuthorString(pc),a0
		move.l	a0,d1				; Try to get Author(a4) env
		lea	Author(a4),a0
		move.l	a0,d2
		move.l	#40,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		RELLIB	GetVar,_DOSBase
		tst.l	d0
		bgt.s	GotAuthor
		move.l	#DefaultName,RevAuthorDat

GotAuthor	lea	CompanyString(pc),a0
		move.l	a0,d1				; Try to get Company(a4) env
		lea	Company(a4),a0
		move.l	a0,d2
		move.l	#40,d3
		move.l	#GVF_GLOBAL_ONLY,d4
		RELLIB	GetVar,_DOSBase
		tst.l	d0
		bgt.s	GotCompany
		move.l	#DefaultName,RevCompanyDat

GotCompany	moveq	#GD_LogVer,d0			; Get version number
		lea	LogGads(a4),a0
		bsr	GetGadgetPtr
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_LongInt(a0),d0
		move.w	d0,RevRevisionDat

		move.l	#GD_LogRev,d0			; Get revision number
		lea	LogGads(a4),a0
		bsr	GetGadgetPtr
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_LongInt(a0),d0
		move.w	d0,RevRevisionDat+2

		lea	FileName(a4),a0
		move.l	a0,d1				; Open File
		move.l	#MODE_OLDFILE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,InHand(a4)
		tst.l	d0
		beq	NoRevision

		lea	TempName(pc),a0
		move.l	a0,d1
		move.l	#MODE_NEWFILE,d2		; Open temporaryfile
		DOLIB	Open
		move.l	d0,OutHand(a4)
		tst.l	d0
		beq	NoRevision

		tst.b	OnlyLog(a4)			; Enter new LogMessage ?
		beq	WriteHeader

		clr.l	ProgDone(a4)
		move.l	#(PROGWINWIDTH-92)/13,ProgStep(a4)

		bsr	ProgMore

.Loop		move.l	InHand(a4),d1			; Seek for our header within
		move.l	ARexxBuffer(a4),d2			; first 15 lines
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		move.l	OutHand(a4),d1			; Store data unequal to header
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		lea	CHeader(pc),a0
		move.l	ARexxBuffer(a4),a1
		moveq	#-1,d7
		bsr	StrCmp
		tst.l	d0
		beq.s	GotHeader
		bra	.Loop

GotHeader	bsr	ProgMore

		moveq	#5,d7				; Skip comming 6 lines
		bsr	RSkipLines
		tst.l	d0
		beq	NoRevision
		move.l	InHand(a4),d1			; Get line of current revision
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		tst.w	RevRevisionDat
		bne.s	UserRev
		tst.w	RevRevisionDat+2
		bne.s	UserRev
		move.l	ARexxBuffer(a4),a3		; Get address of major version value
		lea	23(a3),a3
		move.l	a3,a0
.Find		cmp.b	#'.',(a0)+			; Find . separating major and minor revision
		beq.s	.GotIt
		bra	.Find
.GotIt		bsr	ProgMore
		clr.b	-1(a0)
		move.l	a0,d1				; Convert value to long
		move.l	ARexxBuffer(a4),d2
		addq.l	#4,d2
		DOLIB	StrToLong
		move.l	a3,d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	StrToLong
		move.l	ARexxBuffer(a4),a0
		move.l	(a0),d0
		move.l	4(a0),d1
		addq.l	#1,d1
		cmp.l	#100,d1				; Over 100 ?
		bne.s	GotNewRev
		moveq	#0,d1
		addq.l	#1,d0
GotNewRev	move.w	d0,RevRevisionDat		; Store major version value
		move.w	d1,RevRevisionDat+2		; Store minor value
UserRev		lea	CRevision(pc),a0		; Convert to new string
		lea	RevRevisionDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1			; Write new string
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		moveq	#3,d7				; Skip the next 4 lines
		bsr	RSkipLines
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
.Loop		move.l	InHand(a4),d1			; Skip purpose description
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		move.l	ARexxBuffer(a4),a0
		bsr	StrLen
		cmp.l	#3,d0
		beq.s	.GotIt
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bra	.Loop
.GotIt		bsr	ProgMore
		lea	CLog(pc),a0			; generate new log entry
		lea	RevRevisionDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		lea	NewMsg(a4),a3
		bsr	RWriteMessage			; Write new logmessage
		tst.l	d0
		blt	NoRevision
		move.l	OutHand(a4),d1
		move.l	#CLineNL,d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
.LoopHeader	move.l	InHand(a4),d1			; Search for end of header
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		lea	CEnd(pc),a0
		move.l	ARexxBuffer(a4),a1
		moveq	#-1,d7
		bsr	StrCmp
		tst.l	d0
		beq.s	GotHeaderEnd
		bra	.LoopHeader
GotHeaderEnd	bsr	ProgMore
		move.l	InHand(a4),d1			; Read next line,
		move.l	ARexxBuffer(a4),d2			; following header
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		move.l	ARexxBuffer(a4),a0
		bsr	StrLen
		move.l	InHand(a4),d1			; Reset filepointer to last read
		move.l	d0,d2				; position
		neg.l	d2
		move.l	#OFFSET_CURRENT,d3
		DOLIB	Seek
		move.l	ARexxBuffer(a4),a0		; Did we read in a define ?
		move.l	RevDefine(pc),a1
		move.l	#9,d7
		bsr	StrCmp				; Check for the first 9 chars
		tst.l	d0
		bne	WriteRest			; Nope -> go on

		move.w	RevRevisionDat(pc),d0
		move.w	RevRevisionDat+2(pc),d1
		move.w	d0,RevDefineDat
		move.w	d1,RevDefineDat+2
		move.w	d0,RevVersionDat
		move.w	d1,RevVersionDat+2
		move.l	RevDefine(pc),a0		; Write new define
		lea	RevDefineDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		moveq	#5,d7				; Skip C lines
		cmp.l	#AsmRevDefine1,RevDefine	; Revise Asm source
		bne.s	NoAsmSkip
		add.l	#8,d7				; skip one more line
		bra.s	DoSkip
NoAsmSkip	cmp.l	#PASRevDefine1,RevDefine
		bne.s	DoSkip
		addq.l	#1,d7
DoSkip		move.l	InHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble	NoRevision
		dbf	d7,DoSkip

		bra	WriteRest			; Append rest of file

WriteHeader	clr.l	ProgDone(a4)
		move.l	#((PROGWINWIDTH-92)/11),ProgStep(a4)

		bsr	ProgMore

		cmp.w	#0,RevRevisionDat
		bne.s	.UserDat
		cmp.w	#0,RevRevisionDat+2
		bne.s	.UserDat
		moveq	#1,d0
		moveq	#0,d1
		move.w	d0,RevRevisionDat
		move.w	d1,RevRevisionDat+2

.UserDat	bsr	ProgMore

		move.l	OutHand(a4),d1			; Write Header
		move.l	#CHeader,d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		lea	CCopyRight(pc),a0		; Convert Company(a4) string
		lea	RevCompanyDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		lea	CFile(pc),a0			; convert and write filename
		lea	RevFileDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		lea	CCreatedOn(pc),a0		; do creation date
		lea	RevCreatedOnDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		lea	CAuthor(pc),a0			; do Author(a4)
		lea	RevAuthorDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		lea	CRevision(pc),a0		; Do initial revision
		lea	RevRevisionDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		move.l	OutHand(a4),d1			; Write purpose header
		move.l	#CPurpose,d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		lea	NewMsg(a4),a3			; Write purpose message
		bsr	RWriteMessage
		tst.l	d0
		blt	NoRevision
		lea	CLogInit(pc),a0
		lea	RevRevisionDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1			; Write initial log message
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision
		bsr	ProgMore
		move.w	RevRevisionDat(pc),d0
		move.w	RevRevisionDat+2(pc),d1
		move.w	d0,RevDefineDat
		move.w	d1,RevDefineDat+2
		move.w	d0,RevVersionDat
		move.w	d1,RevVersionDat+2
		move.l	RevDefine(pc),a0		; Write initial define
		lea	RevDefineDat(pc),a1
		bsr	PrintF
		move.l	OutHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt	NoRevision

WriteRest	bsr	ProgMore
		move.l	OutHand(a4),d1			; Write the remaining part of file
		DOLIB	Flush
		move.l	InHand(a4),d1
		DOLIB	Flush
.Loop		move.l	InHand(a4),d1			; Read a maximum of 4096 bytes
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	Read
		tst.l	d0
		beq.s	RestWritten			; End of file -> go on
		blt	NoRevision			; Error -> quit
		move.l	d0,d3
		move.l	OutHand(a4),d1			; Write buffer to temp file
		move.l	ARexxBuffer(a4),d2
		DOLIB	Write
		tst.l	d0
		ble	NoRevision
		bra	.Loop

RestWritten	bsr	ProgMore

		move.l	OutHand(a4),d1			; Close files
		RELLIB	Close,_DOSBase
		move.l	InHand(a4),d1
		DOLIB	Close

		clr.l	OutHand(a4)
		clr.l	InHand(a4)

		lea	FileName(a4),a0
		move.l	a0,d1				; Copy file back
		move.l	#MODE_NEWFILE,d2
		DOLIB	Open
		move.l	d0,InHand(a4)
		tst.l	d0
		beq.s	NoRevision

		lea	TempName(pc),a0
		move.l	a0,d1
		move.l	#MODE_OLDFILE,d2
		DOLIB	Open
		move.l	d0,OutHand(a4)
		tst.l	d0
		beq.s	NoRevision

		bsr	ProgMore

.Loop		move.l	OutHand(a4),d1			; Read in 4096 bytes
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	Read
		tst.l	d0				; 0 read -> end it
		beq.s	.EndWrite
		blt.s	NoRevision
		move.l	d0,d3				; Store read bytes to new file
		move.l	InHand(a4),d1
		move.l	ARexxBuffer(a4),d2
		DOLIB	Write
		tst.l	d0
		blt.s	NoRevision
		bra	.Loop

.EndWrite	bsr	ProgMore
		bra.s	NoErrorFound

NoRevision	RELLIB	IoErr,_DOSBase			; Get error number
		tst.l	d0
		beq.s	NoErrorFound
		move.l	d0,ErrorNum(a4)
		bsr	DisplayError			; Display error

		moveq	#0,d7
		bra.s	GotError
NoErrorFound	moveq	#1,d7
GotError	lea	TempName(pc),a0
		move.l	a0,d1				; Delete file, if possible
		RELLIB	DeleteFile,_DOSBase
		tst.l	OutHand(a4)			; Close files
		beq.s	NoTempFile
		move.l	OutHand(a4),d1
		DOLIB	Close
		lea	TempName(pc),a0
		move.l	a0,d1				; Delete file, if possible
		DOLIB	DeleteFile
NoTempFile	tst.l	InHand(a4)			; Close input handle
		beq.s	NoLogWin
		move.l	InHand(a4),d1
		DOLIB	Close

NoLogWin	tst.l	OurLock(a4)
		beq.s	.NoLock
		move.l	PastLock(a4),d1
		RELLIB	CurrentDir,_DOSBase
		move.l	OurLock(a4),d1
		DOLIB	UnLock
.NoLock		clr.l	InHand(a4)
		clr.l	OutHand(a4)

		lea	ProgHandle(a4),a3
		bsr	CloseNormWindow

		lea	LogHandle(a4),a3
		bsr	CloseNormWindow			; Close our window (AGAIN ???)

		move.l	ARexxAction(a4),d1
		and.l	#RXFF_RESULT,d1
		beq.s	.End
		cmp.b	#2,LogInputEnd(a4)
		bne.s	.NoCancel
		lea	FalseStr(pc),a0			; Create BOOL for error
		bsr	StrLen
		RELLIB	CreateArgstring,_RexxSysBase
		tst.l	d0
		beq.s	.End
		move.l	d0,AResult2(a4)
		bra.s	.End
.NoCancel	lea	TrueStr(pc),a0			; Create BOOL for ok
		bsr	StrLen
		RELLIB	CreateArgstring,_RexxSysBase
		tst.l	d0
		beq.s	.End
		move.l	d0,AResult2(a4)

.End		move.l	d7,d0
		rts
TempName	dc.b	"T:KCX.TEMPFILE",0
AuthorString	dc.b	"AUTHOR",0
CompanyString	dc.b	"COMPANY",0
		EVEN


**********************************************************************
*             Increase process indicator by given amount             *
**********************************************************************
ProgMore	movem.l	RegsAll,-(sp)			; Set draw-pen first
		move.l	ProgRPort(a4),a1
		moveq	#3,d0
		RELLIB	SetAPen,_GfxBase

		move.l	ProgDone(a4),d2			; Get old ratio
		add.l	ProgStep(a4),d2			; Calc new one
		cmp.l	#PROGWINWIDTH-92,d2		; Keep gauge within bounds
		ble.s	.NoRemake
		move.l	#PROGWINWIDTH-92,d2
.NoRemake	move.l	d2,ProgDone(a4)

		move.l	ProgHandle(a4),a0		; Draw rectangle
		moveq	#0,d7
		move.b	wd_BorderTop(a0),d7
		move.l	ProgRPort(a4),a1
		move.l	#44,d0
		move.l	d7,d1
		move.l	d7,d3
		add.l	#INTERHEIGHT+1,d1
		add.l	#INTERHEIGHT+14,d3
		add.l	d0,d2
		subq.l	#1,d2
		DOLIB	RectFill
		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*           Checks for inputs from Purpose/Log msg window            *
**********************************************************************
CheckRevInput	clr.b	LogInputEnd(a4)			; Set end flag for quit
LoopLog		tst.b	LogInputEnd(a4)			; Are we to quit
		bne	LogInputOver
		move.l	LogHandle(a4),a0		; Wait for a message
		move.l	wd_UserPort(a0),a0
		CALLSYS	WaitPort
LoopLogMsg	move.l	LogHandle(a4),a0		; get it
		move.l	wd_UserPort(a0),a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq.s	LoopLog
		move.l	d0,a1
		move.l	im_Class(a1),d6
		move.l	d6,d0
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		move.l	im_IAddress(a1),a3
		move.w	gg_GadgetID(a3),d7
.NoGad		move.w	im_Code(a1),d5
		cmp.w	#'a',d5
		blt.s	.End
		and.w	#~$20,d5
.End		DOLIB	GT_ReplyIMsg

		cmp.l	#IDCMP_ACTIVEWINDOW,d6		; Window activated ?
		bne.s	LogWinInAct

		moveq	#GD_Line1,d0
		lea	LogGads(a4),a0
		move.l	LogHandle(a4),a1
		bsr	ActStringGad
		bra	LoopLogMsg

LogWinInAct	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released
		bne.s	LogNoGadUp
		cmp.w	#GD_LogOk,d7			; Ok gadget ?
		bne.s	LogNoOk
		move.b	#1,LogInputEnd(a4)		; Yep -> quit input
		bra.s	LoopLogMsg
LogNoOk		cmp.w	#GD_LogCancel,d7		; Cancel gadget ?
		bne.s	LoopLogMsg
		move.b	#2,LogInputEnd(a4)
		bra	LoopLogMsg

LogNoGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Keypress ?
		bne.s	LogNoVKey
		cmp.w	#KD_LogVer,d5			; Enable Revision gadget ?
		bne.s	NoLogRevKey
		move.l	#GD_LogVer,d0
		lea	LogGads(a4),a0
		move.l	LogHandle(a4),a1
		bsr	ActStringGad
		bra	LoopLogMsg

NoLogRevKey	moveq	#0,d0
		cmp.w	#KD_LogOk,d5			; o pressed ?
		bne.s	LogNoOkKey
LogOK		move.b	#1,LogInputEnd(a4)		; quit
		moveq	#GD_LogOk,d0
		bra.s	LogFeedBack
LogNoOkKey	cmp.w	#ESCKEY,d5			; Cancel ?
		beq.s	LogCancel
		cmp.w	#KD_LogCancel,d5		; c pressed ?
		bne	LoopLogMsg
LogCancel	move.b	#2,LogInputEnd(a4)
		moveq	#GD_LogCancel,d0
LogFeedBack	tst.l	d0
		beq	LoopLogMsg
		lea	LogGads(a4),a0
		move.l	LogHandle(a4),a5
		bsr	ButtonCheck
		bra	LoopLogMsg

LogNoVKey	cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne	LoopLogMsg
		move.l	LogHandle(a4),a0		; Store new position
		lea	LogWinLeft(a4),a1
		bsr	StoreWinPos
		bra	LoopLogMsg
LogInputOver	rts




**********************************************************************
*                    Checks for existing revision                    *
**********************************************************************
CheckRevision	lea	FileName(a4),a0
		move.l	a0,d1				; Try to open file
		move.l	#MODE_OLDFILE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,InHand(a4)
		tst.l	d0
		beq.s	FileNotFound

		moveq	#14,d6
CheckLines	move.l	InHand(a4),d1			; Search for our header
		move.l	ARexxBuffer(a4),d2			; within the first 15 lines
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		beq.s	FileError
		blt.s	FileNotFound
		lea	CHeader(pc),a0
		move.l	ARexxBuffer(a4),a1
		moveq	#-1,d7
		bsr	StrCmp				; current line our header ?
		tst.l	d0
		beq.s	IsMine				; Yep -> go on
		dbf	d6,CheckLines			; Loop
FileError	moveq	#0,d7				; Nothing found
		bra.s	EndCheckRev
IsMine		moveq	#1,d7				; Got it
		bra.s	EndCheckRev
FileNotFound	moveq	#-1,d7
EndCheckRev	move.b	d7,OnlyLog(a4)			; store flag
		tst.l	InHand(a4)			; Close file again
		beq.s	.End
		move.l	InHand(a4),d1
		DOLIB	Close
		clr.l	InHand(a4)
.End		rts




**********************************************************************
*                      Skip the following bytes                      *
**********************************************************************
RSkipLines	move.l	InHand(a4),d1			; Read line
		move.l	ARexxBuffer(a4),d2
		move.l	#AREXXBUFFSIZE,d3
		DOLIB	FGets
		tst.l	d0
		ble.s	.Error
		move.l	OutHand(a4),d1			; Store line
		move.l	ARexxBuffer(a4),d2
		DOLIB	FPuts
		tst.l	d0
		blt.s	.Error
		dbf	d7,RSkipLines			; Loop
		bsr	ProgMore
		moveq	#1,d0
		rts
.Error		moveq	#0,d0
		rts





**********************************************************************
*                 Writes Log/Purpose message to file                 *
**********************************************************************
RWriteMessage	moveq	#4,d7				; Now loop for message lines
.LoopPurp	tst.b	(a3)				; line ok ?
		beq.s	.EndPurp
		move.l	OutHand(a4),d1			; Write initial chars
		move.l	#CLine,d2
		DOLIB	FPuts
		tst.l	d0
		blt.s	.Error
		move.l	a3,a0
		bsr	StrLen
		move.b	#$0a,0(a0,d0)
		move.l	OutHand(a4),d1
		move.l	a3,d2
		DOLIB	FPuts
		tst.l	d0
		blt.s	.Error
.EndPurp	lea	62(a3),a3			; Loop
		dbf	d7,.LoopPurp
		bsr	ProgMore
.Error		rts




**********************************************************************
*              Copy message eneterd to desired location              *
**********************************************************************
CopyMessage	lea	LogGads(a4),a2			; Copy contents of string gads
		move.l	(a2),a2
		moveq	#4,d7				; Loop for 5 gadgets
.Loop		move.l	gg_SpecialInfo(a2),a0
		move.l	si_Buffer(a0),a0
		move.l	a3,a1
		bsr	StrCpy				; Copy string to buffer
		move.l	gg_NextGadget(a2),a2
		lea	62(a3),a3			; Next buffer
		dbf	d7,.Loop
		rts




**********************************************************************
*                 Deletes our environment variables                  *
**********************************************************************
DeleteEnvs	tst.l	_DOSBase(a4)
		beq.s	.End
		lea	EnvDayString(pc),a1
		move.l	a1,d1
		move.l	#GVF_GLOBAL_ONLY,d2
		RELLIB	DeleteVar,_DOSBase
		lea	EnvDateString(pc),a1
		move.l	a1,d1
		move.l	#GVF_GLOBAL_ONLY,d2
		DOLIB	DeleteVar
		lea	EnvTimeString(pc),a1
		move.l	a1,d1
		move.l	#GVF_GLOBAL_ONLY,d2
		DOLIB	DeleteVar
.End		rts





**********************************************************************
*           Display Msg that only to be run under Kick2.x            *
**********************************************************************
OnlyKick20	sub.l	a1,a1
		CALLSYS	FindTask
		move.l	d0,a0
		tst.l	pr_CLI(a0)
		beq.s	.FromWB
		lea	DosName,a1
		moveq	#0,d0
		DOLIB	OpenLibrary
		move.l	d0,a6
		DOLIB	Output
		move.l	d0,d1
		move.l	#Only20Txt,d2
		move.l	#Only20TxtEnd-Only20Txt,d3
		DOLIB	Write
		move.l	a6,a1
		CALLSYS	CloseLibrary
		rts
.FromWB		lea	IntName,a1			; try to open IntBase
		moveq	#0,d0
		CALLSYS	OpenLibrary
		tst.l	d0
		beq.s	OnlyKick20Ret
		move.l	d0,a6

		sub.l	a0,a0				; Display requester
		lea	Only20ITxt(pc),a1
		lea	OkITxt(pc),a2
		move.l	a2,a3
		moveq	#0,d0
		moveq	#0,d1
		move.l	#300,d2
		move.l	#60,d3
		DOLIB	AutoRequest

		move.l	a6,a1
		CALLSYS	CloseLibrary
OnlyKick20Ret	rts



**********************************************************************
*                          Display an error                          *
**********************************************************************
DisplayError	tst.l	ErrorNum(a4)
		bge.s	.GoOn
		rts
.GoOn		movem.l	RegsAll,-(sp)
		move.l	ErrorNum(a4),d0			; Get error num
		cmp.l	#BROKER_ERR,d0			; Is it the broker set up error ?
		bne.s	NoDoubleMean			; Nope -> go on
		tst.l	DoublePort(a4)			; Did we already had a port ?
		beq.s	NoDoubleMean			; Nope -> go on
		movem.l	(sp)+,RegsAll
		rts
NoDoubleMean	cmp.l	#500,d0				; Printer Error ?
		blt.s	.NoPrintError
		sub.l	#500,d0
		lea	PrinterErrors(pc),a0
		lsl.l	#2,d0
		move.l	0(a0,d0),a0
		bra.s	.DosError

.NoPrintError	cmp.l	#400,d0				; IFF Error ?
		blt.s	.NoIFFError
		sub.l	#400,d0
		lea	IFFErrors,a0
		lsl.l	#2,d0
		move.l	0(a0,d0),a0
		bra.s	.DosError

.NoIFFError	cmp.l	#200,d0				; Display DOS error ?
		blt.s	.OurError			; Nope -> go on
		move.l	d0,d1
		lea	DosError(pc),a0
		move.l	a0,d2
		lea	DosErrorBuff(a4),a0
		move.l	a0,d3
		move.l	#128,d4
		DOLIB	Fault
		lea	DosErrorBuff(a4),a0
		bra.s	.DosError

.OurError	lea	EasyTexts(pc),a0
		lsl.l	#2,d0
		move.l	0(a0,d0),a0			; get adr of error-txt
.DosError	move.l	a0,d0
		beq.s	.End
		move.l	a0,-(sp)
		bsr	BusyAllWins
		move.l	(sp)+,a0
		lea	MyEasyRequest(pc),a1		; Display Easy-Requester
		move.l	#EasyTitle,es_Title(a1)
		move.l	a0,es_TextFormat(a1)
		move.l	#EasyGadget,es_GadgetFormat(a1)
		sub.l	a0,a0
		sub.l	a2,a2
		lea	EasyArg(a4),a3
		RELLIB	EasyRequestArgs,_IntuitionBase
		move.l	#NO_ERR,ErrorNum(a4)
		bsr	UnbusyAllWins
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                  Just skip the blanks in a string                  *
**********************************************************************
SkipBlanks	cmp.b	#' ',(a0)			; Loop while there are spaces
		beq.s	.NoEnd				; and tabs
		cmp.b	#$09,(a0)
		beq.s	.NoEnd
		cmp.b	#'"',(a0)
		beq.s	.NoEnd
		cmp.b	#"'",(a0)
		beq.s	.NoEnd
		tst.b	(a0)
		beq.s	.GotEnd
		bra.s	.GotEnd
.NoEnd		addq.l	#1,a0
		bra.s	SkipBlanks
.GotEnd		rts



**********************************************************************
*                           Just a printf                            *
**********************************************************************
PrintF		movem.l	RegsAll,-(sp)
		lea	PutChProc(pc),a2
		move.l	ARexxBuffer(a4),a3
		CALLSYS	RawDoFmt
		movem.l	(sp)+,RegsAll
		rts


**********************************************************************
*                      Small dummy for RawDoFmt                      *
**********************************************************************
PutChProc	move.b	d0,(a3)+
		rts


**********************************************************************
*                         Enable the broker                          *
**********************************************************************
EnableBroker	movem.l	RegsAll,-(sp)
		tst.b	Disabled(a4)			; Don`t enable when disabled
		bne.s	.End
		move.l	MyBroker(a4),a0
		moveq	#1,d0
		LNKLIB	ActivateCxObj,_CxBase
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                        Disable broker again                        *
**********************************************************************
DisableBroker	movem.l	RegsAll,-(sp)
		tst.b	Disabled(a4)
		bne.s	.End
		move.l	MyBroker(a4),a0
		moveq	#0,d0
		LNKLIB	ActivateCxObj,_CxBase
		CALLSYS	Forbid
		bsr	OnScreen
		CALLSYS	Permit
		bsr	OnMouse
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                        Display the AppIcon                         *
**********************************************************************
OnAppIcon	tst.l	KCXAppIcon(a4)
		bne.s	.End
		lea	MyAppIconText,a0		; Display AppIcon
		move.l	AppPort(a4),a1
		sub.l	a2,a2
		lea	KCXAppIconDef,a3
		move.l	a4,-(sp)
		move.l	_WorkBenchBase(a4),a6
		sub.l	a4,a4
		DOLIB	AddAppIconA
		move.l	(sp)+,a4
		move.l	d0,KCXAppIcon(a4)
		tst.l	d0
		bne.s	.End
.Error		move.l	#APPICON_ERR,ErrorNum(a4)
		bsr	DisplayError
		clr.b	DispAppIcon(a4)
		moveq	#0,d0
		move.l	#GD_AppIcon,d1
		bsr	SetMiscBox
.End		rts



**********************************************************************
*                 Remove the AppIcon from WorkBench                  *
**********************************************************************
OffAppIcon	tst.l	KCXAppIcon(a4)
		beq.s	.NoIcon
		move.l	KCXAppIcon(a4),a0
		RELLIB	RemoveAppIcon,_WorkBenchBase
		clr.l	KCXAppIcon(a4)
.NoIcon		rts





**********************************************************************
*                      Set new window positions                      *
**********************************************************************
GetWinPos	move.l	ARexxBuffer(a4),a3
		move.l	a3,a5
.FindSlash	tst.b	(a5)				; If there was no / in pos -> quit
		beq.s	.NoWinPos
		cmp.b	#'/',(a5)+
		beq.s	.GotSlash
		bra	.FindSlash
.GotSlash	clr.b	-1(a5)				; Remove slash with 0
		move.l	a3,d1				; a3 = String XPos / a5 = YPos
		lea	WinLeftEdge(a4),a0
		move.l	a0,d2				; Get offset
		RELLIB	StrToLong,_DOSBase
		tst.l	d1
		blt.s	.LError
		tst.l	d0				; If coord is > 0 -> go on
		bge.s	.WinSLOk
.LError		clr.l	WinLeftEdge(a4)			; Set to 0
.WinSLOk	move.l	a5,d1
		lea	WinTopEdge(a4),a0
		move.l	a0,d2				; Get Y offset
		DOLIB	StrToLong
		tst.l	d1
		blt.s	.TError
		tst.l	d0
		bge.s	.WinSTOk
.TError		clr.l	WinTopEdge(a4)			; Set to 0 if specified < 0
.WinSTOk	moveq	#1,d0
		rts
.NoWinPos	moveq	#0,d0
		rts





**********************************************************************
*                   Changes a HotKey for a Filter                    *
* A0 = Pointer to window                                             *
* A1 = Pointer to windowtitle                                        *
* A2 = Pointer to filter                                             *
* A3 = Pointer to new filterdescription                              *
* A5 = Pointer to old filterdescription                              *
**********************************************************************
RemakeHotKey	tst.l	MyBroker(a4)			; Execute routine, only if
		bne.s	.GoOn				; Broker is really there
		rts
.GoOn		move.l	a2,d0
		bne.s	.GoOn2
		rts
.GoOn2		CARGS	#-20,.OldDesc.L,.NewDesc.L,.Filter.L,.Title.L,.Window.L
		movem.l	RegsAll,-(sp)

		move.l	a5,d0

		link	a5,#-(20+HOTKEYSIZE)

		move.l	a0,.Window(a5)
		move.l	a1,.Title(a5)
		move.l	a2,.Filter(a5)
		move.l	a3,.NewDesc(a5)
		move.l	d0,.OldDesc(a5)

		bsr	DisableBroker			; Disable the broker

		move.l	.OldDesc(a5),a0			; Copy old hotkey
		lea	-(20+HOTKEYSIZE)(a5),a1
		bsr	StrCpy

		move.l	.NewDesc(a5),a0			; Copy new HotKey
		move.l	.OldDesc(a5),a1
		bsr	StrCpy

		move.l	.Filter(a5),a0			; Try to set new filter
		move.l	.OldDesc(a5),a1
		move.l	_CxBase,a6
		DOLIB	SetFilter
		move.l	.Filter(a5),a0			; Error occured ?
		DOLIB	CxObjError
		tst.l	d0
		beq.s	.GotNewChangeHK			; Nope -> go on

		lea	-(20+HOTKEYSIZE)(a2),a0		; Remake HotKey
		move.l	.OldDesc(a5),a1
		bsr	StrCpy

		move.l	.Filter(a5),a0			; Reset old hotkey
		move.l	.OldDesc(a5),a1
		DOLIB	SetFilter

.GotNewChangeHK	move.l	.Window(a5),a0
		move.l	a0,d0
		beq.s	.NoNewTitle
		move.l	.Title(a5),a1
		move.l	#-1,a2
		RELLIB	SetWindowTitles,_IntuitionBase
.NoNewTitle	tst.l	HotKeyHandle(a4)
		beq.s	.NoGadRemake
		move.l	HotKeyChange(a4),d0		; Check if HotKey to be changed
		lea	HotKeyGadVars,a0		; is displayed withing HotKey-Win
		mulu	#12,d0
		move.l	8(a0,d0),a0
		move.l	(a0),a0
		cmp.l	.Filter(a5),a0			; Same filter address ???
		bne.s	.NoGadRemake
		move.l	#GD_HotKeyDef,d0		; Remake HotKey string
		lea	HotKeyGads(a4),a0
		move.l	HotKeyHandle(a4),a1
		move.l	.OldDesc(a5),a2
		bsr	SetStringGad
.NoGadRemake	bsr	EnableBroker
		unlk	a5
		movem.l	(sp)+,RegsAll
		rts





**********************************************************************
*         Set busy for a window and disable all it`s gadgets         *
* A0 = Pointer to window                                             *
**********************************************************************
SetBusy		movem.l	RegsAll,-(sp)
		move.l	a0,d0
		beq.s	.EndBusy
		move.l	a0,a3				; Set pointer
		lea	BusyPtr,a1
		moveq	#16,d0
		moveq	#16,d1
		moveq	#-6,d2
		moveq	#0,d3
		RELLIB	SetPointer,_IntuitionBase
		clr.l	wd_UserData(a3)
		move.l	#rq_SIZEOF,d0
		move.l	#MEMF_CLEAR|MEMF_PUBLIC,d1
		CALLSYS	AllocVec
		tst.l	d0
		beq.s	.EndBusy
		move.l	d0,a0				; Open Requester
		move.l	a3,a1
		move.l	d0,wd_UserData(a1)		; Store pointer to structure
		RELLIB	Request,_IntuitionBase
.EndBusy	movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*          Un-Busy a window and reenable all gadgets again           *
* A0 = Pointer to window to be re-enabled                            *
**********************************************************************
UnBusy		movem.l	RegsAll,-(sp)
		move.l	a0,d0
		beq.s	.EndBusy
		move.l	a0,a3				; Clear pointer
		move.l	a0,a1
		move.l	wd_UserData(a0),a0
		RELLIB	EndRequest,_IntuitionBase
		move.l	wd_UserData(a3),a1
		CALLSYS	FreeVec
		move.l	a3,a0
		RELLIB	ClearPointer,_IntuitionBase
.EndBusy	movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                       Busy all main windows                        *
**********************************************************************
BusyAllWins	move.l	MainHandle(a4),a0		; Make all gadgets busy
		bsr	SetBusy
		move.l	SetHandle(a4),a0
		bsr	SetBusy
		move.l	MiscHandle(a4),a0
		bsr	SetBusy
		move.l	AlarmHandle(a4),a0
		bsr	SetBusy
		move.l	CycleHandle(a4),a0
		bsr	SetBusy
		move.l	ColsHandle(a4),a0
		bsr	SetBusy
		move.l	MouseHandle(a4),a0
		bsr	SetBusy
		move.l	HotKeyHandle(a4),a0
		bsr	SetBusy
		move.l	FKeyHandle(a4),a0
		bsr	SetBusy
		move.l	FormHandle(a4),a0
		bsr	SetBusy
		move.l	PrefsHandle(a4),a0
		bsr	SetBusy
		move.l	LockHandle(a4),a0
		bsr	SetBusy
		rts



**********************************************************************
*                         Unbusy all windows                         *
**********************************************************************
UnbusyAllWins	move.l	MainHandle(a4),a0
		bsr	UnBusy
		move.l	SetHandle(a4),a0
		bsr	UnBusy
		move.l	MiscHandle(a4),a0
		bsr	UnBusy
		move.l	AlarmHandle(a4),a0
		bsr	UnBusy
		move.l	CycleHandle(a4),a0
		bsr	UnBusy
		move.l	ColsHandle(a4),a0
		bsr	UnBusy
		move.l	MouseHandle(a4),a0
		bsr	UnBusy
		move.l	HotKeyHandle(a4),a0
		bsr	UnBusy
		move.l	FKeyHandle(a4),a0
		bsr	UnBusy
		move.l	FormHandle(a4),a0
		bsr	UnBusy
		move.l	PrefsHandle(a4),a0
		bsr	UnBusy
		move.l	LockHandle(a4),a0
		bsr	UnBusy
		rts

**********************************************************************
*           Checks if the inserted disk should be formated           *
**********************************************************************
CheckFormat	tst.l	FormHandle(a4)
		bne.s	.End
		sub.l	a0,a0
		lea	MyEasyRequest(pc),a1
		move.l	#EasyTitle,es_Title(a1)
		move.l	#DoFormatText,es_TextFormat(a1)
		move.l	#FormatGads,es_GadgetFormat(a1)
		sub.l	a2,a2
		lea	DriveNames(pc),a3
		move.w	FormatDrive(a4),d0
		lsl.w	#2,d0
		lea	0(a3,d0.w),a3
		RELLIB	EasyRequestArgs,_IntuitionBase
		cmp.l	#1,d0
		bne.s	.End
		bsr	OpenFormWin
.End		rts




**********************************************************************
*                        Start the formatting                        *
**********************************************************************
GoGoGoFormat	lea	MainCom,a0			; Generate main commandline
		lea	FormatCommand(a4),a1
		bsr	StrCpy
		lea	DriveArg,a0
		subq.l	#1,a1
		bsr	StrCpy
		lea	DriveNames(pc),a0
		moveq	#0,d0
		move.w	FormatDrive(a4),d0
		lsl.w	#2,d0
		move.l	0(a0,d0.w),a0
		subq.l	#1,a1
		bsr	StrCpy
		lea	NameArg,a0
		subq.l	#1,a1
		bsr	StrCpy
		move.b	#'"',-1(a1)
		lea	FormGads(a4),a0
		move.l	#GD_Label,d0
		bsr	GetGadgetPtr
		move.l	gg_SpecialInfo(a0),a0
		move.l	si_Buffer(a0),a0
		bsr	StrCpy
		move.b	#'"',-1(a1)
		addq.l	#1,a1
		tst.b	MakeIcons(a4)			; Add switches
		bne.s	.NoIcons
		lea	IconsArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NoIcons	tst.b	QuickFormat(a4)
		beq.s	.NotQuick
		lea	QuickArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NotQuick	tst.b	FFSDrive(a4)
		beq.s	.NotFFS
		lea	FFSArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NotFFS		tst.b	NoVerify(a4)
		beq.s	.NoVerify
		lea	VerifyArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NoVerify	tst.b	Install(a4)
		beq.s	.NoInstall
		lea	InstallArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NoInstall	tst.b	EjectDrive(a4)
		beq.s	.NoEject
		lea	EjectArg,a0
		subq.l	#1,a1
		bsr	StrCpy
.NoEject	move.l	#SystemInOut,d1
		move.l	#MODE_READWRITE,d2
		RELLIB	Open,_DOSBase
		move.l	d0,FormatIn
		move.l	#FormatWin,d1
		move.l	#MODE_READWRITE,d2
		DOLIB	Open
		tst.l	d0
		bne.s	.GoOn
		move.l	FormatIn(pc),d1
		DOLIB	Close
.GoOn		move.l	d0,FormatOut
		lea	FormatCommand(a4),a0
		move.l	a0,d1
		lea	FormatTags(pc),a0
		move.l	a0,d2
		DOLIB	SystemTagList
		rts
**********************************************************************
*              Definitions for launching the formatter               *
**********************************************************************
FormatTags	dc.l	SYS_Input
FormatIn	dc.l	0
		dc.l	SYS_Output
FormatOut	dc.l	0
		dc.l	SYS_Asynch
		dc.l	1
		dc.l	NP_Priority
		dc.l	0
		dc.l	TAG_DONE
FormatWin	dc.b	"CON:0/11//90/KCX-Formatter Shell",0
		EVEN




**********************************************************************
*                   Displays a hotkey by it`s name                   *
* D0 = Code                                                          *
* D1 = Qualifier                                                     *
* D2 = Number of gadget                                              *
* A0 = Pointer to gadgetlist                                         *
* A1 = Pointer to window                                             *
* A2 = Pointer to buffer for string                                  *
**********************************************************************
DisplayHotKey	movem.l	RegsAll,-(sp)

		move.l	a1,d5
		beq	.End

		link	a5,#-(ie_SIZEOF+138)		; Get a buffer

		movem.l	a0-a2/d0-d2,-(sp)		; Filter out qualifiers
		move.l	a2,a1
		clr.b	(a1)
		lea	QualifierTab,a2
		moveq	#NUMQUALIFIER-1,d7
		move.w	d1,d4
.LoopQual	tst.w	d4				; No qualifier ?
		beq.s	.QualDone			; Go on
		move.w	d4,d5
		move.l	(a2),d6				; get qualifier from table
		and.w	d6,d5				; Set in user qual ?
		beq.s	.NotThisOne			; Nope -> go on
		move.l	4(a2),a0			; Append it`s name to string
		bsr	StrCpy
		move.b	#' ',-1(a1)
		not.w	d6				; Clear flag
		and.w	d6,d4
.NotThisOne	addq.l	#8,a2				; loop
		dbf	d7,.LoopQual
.QualDone	move.l	a1,a3
		movem.l	(sp)+,a0-a2/d0-d2

		move.b	#"'",(a3)+
		clr.b	(a3)

		move.l	a2,-(sp)
		tst.w	d0
		beq.s	.GotCode
		lea	CodeTab,a2			; Test for code within table
		move.w	#NUMCODES-1,d7
.Loop		move.l	(a2),d5
		cmp.w	d5,d0
		beq.s	.ThisCode
		addq.l	#8,a2
		dbf	d7,.Loop
		bra.s	.NoSpecCode
.ThisCode	move.l	4(a2),a3
		bra.s	.GotCode

.NoSpecCode	move.l	(sp)+,a2
		movem.l	a0-a2/d0-d2,-(sp)
		lea	-ie_SIZEOF(a5),a1		; Convert RAWKEY
		clr.l	ie_NextEvent(a1)
		move.b	#IECLASS_RAWKEY,ie_Class(a1)
		clr.b	ie_SubClass(a1)
		move.w	d0,ie_Code(a1)
		clr.w	ie_Qualifier(a1)
		clr.l	ie_EventAddress(a1)

		move.l	a1,a0
		lea	-(ie_SIZEOF+10)(a5),a1
		moveq	#9,d1
		sub.l	a2,a2
		RELLIB	RawKeyConvert,_ConsoleBase
		movem.l	(sp)+,a0-a2/d0-d2
		clr.b	-(ie_SIZEOF+9)(a5)
		lea	-(ie_SIZEOF+10)(a5),a3
		cmp.b	#'a',(a3)
		blt.s	.GoOn2
		and.b	#~$20,(a3)			; Uppercase the key
		bra.s	.GoOn2
.GotCode	move.l	(sp)+,a2
.GoOn2		movem.l	a0-a2/d0-d2,-(sp)
		move.l	a3,a0
		move.l	a2,a1
		bsr	StrCat
		move.b	#"'",-1(a1)
		clr.b	(a1)
		movem.l	(sp)+,a0-a2/d0-d2

		move.l	d2,d0
		bsr	SetTextGad

		unlk	a5
.End		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*               Get a qualifier and display in window                *
**********************************************************************
GetQualifier	lea	QualifierFor(a4),a1			; Copy title
		bsr	StrCpy

		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.QualWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,QualVisInfo(a4)
		beq	.QualWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	QualWinWidth(a4),d2
		move.w	QualWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	QualWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	QualWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	QualGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.QualWinError

		lea	QualGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	QualVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#5*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#4*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#412*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_QualTxt,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#21*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#50*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#OkText,gng_GadgetText(a1)
		move.w	#GD_Ok,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#357*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#60*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#CancelText,gng_GadgetText(a1)
		move.w	#GD_Cancel,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.QualWinError

		move.l	QualGadget(a4),QualWinWG+4
		move.l	-4(a5),QualWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,QualWinL+4
		move.l	d3,QualWinT+4
		move.l	-4(a5),a0
		move.w	QualWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,QualWinW+4
		move.w	QualWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,QualWinH+4
		suba.l	a0,a0
		lea.l	QualWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,QualHandle(a4)
		beq.s	.QualWinError
		move.l	d0,a0
		move.l	WindowPort(a4),wd_UserPort(a0)
		move.l	#QUALWINIDCMP,d0
		DOLIB	ModifyIDCMP

		move.l	QualHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		move.w	NewCode(a4),d0			; Display old HotKey
		move.w	NewQual(a4),d1
		move.l	#GD_QualTxt,d2
		lea	QualGads(a4),a0
		move.l	QualHandle(a4),a1
		lea	QualQualStr(a4),a2
		bsr	DisplayHotKey

		bsr	BusyAllWins

		bsr	UnlockScreen
		unlk	a5
		bsr	DisableBroker
		move.b	Disabled(a4),d0
		move.b	d0,OldDisabled(a4)
		move.b	#1,Disabled(a4)
		bra.s	WorkQualWin

.QualWinError	bsr	UnlockScreen
		unlk	a5
		bra	CloseQualWin

WorkQualWin	move.l	WindowPort(a4),a0
		CALLSYS	WaitPort
LoopQualMsg	move.l	QualHandle(a4),a0
		move.l	wd_UserPort(a0),a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq	WorkQualWin

		move.l	d0,a1
		move.l	im_Class(a1),d6			; Get class
		moveq	#0,d5
		move.w	im_Code(a1),d5			; Get code
		tst.b	KeepCode(a4)			; Keep code fixed ?
		beq.s	.NewCode
		and.w	#IECODE_UP_PREFIX,d5
		or.w	NewCode(a4),d5
.NewCode	move.l	d6,d0
		move.w	im_Qualifier(a1),d4		; Get qualifier
		and.w	#~(IEQUALIFIER_REPEAT|IEQUALIFIER_INTERRUPT|IEQUALIFIER_RELATIVEMOUSE),d4
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		move.l	im_IAddress(a1),a2		; Get gadget id
		move.w	gg_GadgetID(a2),d7

.NoGad		DOLIB	GT_ReplyIMsg			; Reply gadtools msg

		cmp.l	#IDCMP_CLOSEWINDOW,d6
		beq	CloseQualWin

		cmp.l	#IDCMP_CHANGEWINDOW,d6
		bne.s	NoQualMove
		move.l	QualHandle(a4),a0
		lea	QualWinLeft(a4),a1
		jsr	StoreWinPos
		bra	LoopQualMsg

NoQualMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget released ?
		bne.s	NoQualGadUp

		cmp.w	#1,d7				; On OK just exit
		beq.s	CloseQualWin

NoQualOk	cmp.w	#2,d7				; On Cancel -> clear code
		bne	LoopQualMsg			; To indicate cancel
		clr.w	NewCode(a4)
		bra.s	CloseQualWin

NoQualGadUp	cmp.l	#IDCMP_RAWKEY,d6		; Key pressed ?
		bne.s	NoQualRaw
		move.w	d5,d0				; Key released ?
		and.w	#IECODE_UP_PREFIX,d0
		bne	LoopQualMsg			; Yep -> return
		tst.b	KeepCode(a4)			; Only change qualifier ?
		bne.s	DisplayQual			; Yep -> go on
		cmp.w	#$60,d5				; Qualifier used as code ?
		bge	LoopQualMsg			; Yep -> return
		bra.s	DisplayQual			; Display qualifier

NoQualRaw	cmp.l	#IDCMP_MOUSEBUTTONS,d6
		bne	LoopQualMsg

		move.w	d5,d0				; Button released ?
		and.w	#IECODE_UP_PREFIX,d0
		bne	LoopQualMsg			; Yep -> return
DisplayQual	move.w	d5,d0				; Filter out double
		move.w	d4,d1				; existence of mouse buttons
		bsr.s	FilterDouble
		move.w	d0,NewCode(a4)			; Store keys
		move.w	d1,NewQual(a4)
		move.l	#GD_QualTxt,d2
		lea	QualGads(a4),a0
		move.l	QualHandle(a4),a1
		lea	QualQualStr(a4),a2
		bsr	DisplayHotKey			; Display HotKey
		bra	LoopQualMsg

CloseQualWin	move.b	OldDisabled(a4),d0
		move.b	d0,Disabled(a4)
		bsr	EnableBroker

		bsr	UnbusyAllWins

		lea	QualHandle(a4),a3
		bra	CloseAWindow




**********************************************************************
*               Filter double Code/Qualifier occurance               *
* D0 = Code                                                          *
* D1 = Qualifier                                                     *
**********************************************************************
FilterDouble	cmp.w	#IECODE_LBUTTON,d0		; If one of the buttons
		bne.s	.NotLeft			; is defined within code and qualifier
		and.w	#~IEQUALIFIER_LEFTBUTTON,d1	; clear the button out of the qualifier
.NotLeft	cmp.w	#IECODE_MBUTTON,d0
		bne.s	.NotMid
		and.w	#~IEQUALIFIER_MIDBUTTON,d1
.NotMid		cmp.w	#IECODE_RBUTTON,d0
		bne.s	.NotRight
		and.w	#~IEQUALIFIER_RBUTTON,d1
.NotRight	rts





**********************************************************************
*                       Init the print checker                       *
**********************************************************************
InitPrintProc	lea	PrinterTags(pc),a0
		move.l	a0,d1				; Start Process with tags
		RELLIB	CreateNewProc,_DOSBase
		tst.l	d0
		beq.s	.Error
		move.l	#SIGHANDSHAKE,d0		; Wait for reply
		CALLSYS	Wait
.Error		rts
**********************************************************************
*                      Tags for printer process                      *
**********************************************************************
PrinterTags	dc.l	NP_Entry			; We only supply an entry point
		dc.l	PrinterProc
		dc.l	NP_Name				; Name of process
		dc.l	PrintProcName
		dc.l	NP_Priority			; We run at a higher proirity
		dc.l	0				; so that we`re quite fast
		dc.l	NP_StackSize			; Stack-Size to be used
		dc.l	4096
		dc.l	TAG_DONE





**********************************************************************
*                    This is the Printer process                     *
**********************************************************************
PrinterProc	movem.l	RegsAll,-(sp)

		lea	ZeroPage,a4

		move.l	#-1,d0				; Get signal for dumping
		CALLSYS	AllocSignal
		move.l	d0,GfxDumpSig(a4)
		tst.l	d0
		blt.s	.Error
		moveq	#1,d1
		lsl.l	d0,d1
		move.l	d1,GfxDumpFlag(a4)

		sub.l	a1,a1				; Get pointer to task
		CALLSYS	FindTask
		move.l	d0,PrintProc(a4)

		move.l	OurTask(a4),a1			; Reply to mother
		move.l	#SIGHANDSHAKE,d0
		DOLIB	Signal

.Loop		move.l	#SIGHANDSHAKE,d0
		or.l	GfxDumpFlag(a4),d0
		CALLSYS	Wait

		move.l	d0,d1
		and.l	#SIGHANDSHAKE,d1
		bne.s	.Error

		and.l	GfxDumpFlag(a4),d0
		beq.s	.Loop
		bsr.s	DumpScreen
		bra.s	.Loop

.Error		tst.l	GfxDumpSig(a4)			; Clear signal
		blt.s	.NoSig
		move.l	GfxDumpSig(a4),d0
		CALLSYS	FreeSignal

.NoSig		move.l	OurTask(a4),a1
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal

		movem.l	(sp)+,RegsAll
		moveq	#0,d0
		rts



**********************************************************************
*                      Dump the current screen                       *
**********************************************************************
DumpScreen	bsr	GetNewSource
		bsr	HandleDumpWin
		tst.l	d0
		beq	.NoPrint

		CALLSYS	CreateMsgPort			; Try to get MsgPort for Printer device
		move.l	d0,PrintPort(a4)
		tst.l	d0
		beq	.PrintError

		move.l	d0,a0				; Get Request block for dump-rastport
		move.l	#iodrpr_SIZEOF,d0
		DOLIB	CreateIORequest
		move.l	d0,PrintReq(a4)
		tst.l	d0
		beq	.PrintError

		lea	PrintName(pc),a0		; Try to open device
		moveq	#0,d0
		move.l	PrintReq(a4),a1
		moveq	#0,d1
		DOLIB	OpenDevice
		tst.l	d0
		bne	.PrintError
		move.l	PrintReq(a4),a0
		move.l	IO_DEVICE(a0),a0
		move.l	pd_SegmentData(a0),a0
		lea	ps_PED(a0),a0
		move.l	ped_PrinterName(a0),a0
		lea	ThisPrinter(a4),a1
		bsr	StrCpy

		move.l	PrintReq(a4),a1			; Do the printing, set prefs
		move.l	IO_DEVICE(a1),a0
		lea	pd_Preferences(a0),a0
		move.l	GfxImage(a4),d0			; Set image
		move.w	d0,pf_PrintImage(a0)
		lea	ShadeFlags,a2
		move.l	GfxShade(a4),d0			; Set shading
		add.w	d0,d0
		move.l	0(a2,d0.w),pf_PrintShade(a0)
		move.l	GfxThreshold(a4),d0		; Set threshold
		move.w	d0,pf_PrintThreshold(a0)
		moveq	#0,d0				; Set Flags
		cmp.l	#3,GfxShade(a4)			; Color enabled ?
		bne.s	.NoCols
		tst.b	GfxRed(a4)			; red set ?
		beq.s	.NoRed
		or.w	#CORRECT_RED,d0
.NoRed		tst.b	GfxGreen(a4)			; green set ?
		beq.s	.NoGreen
		or.w	#CORRECT_GREEN,d0
.NoGreen	tst.b	GfxBlue(a4)			; blue set ?
		beq.s	.NoCols
		or.w	#CORRECT_BLUE,d0
.NoCols		lea	DitherFlags,a2			; Set dithering
		move.l	GfxDithering(a4),d1
		cmp.l	#2,d1				; Floyd selected ?
		beq.s	.NoSmooth
		tst.b	GfxSmooth(a4)			; Set smoothing
		beq.s	.NoSmooth
		or.w	#ANTI_ALIAS,d0
.NoSmooth	add.w	d1,d1				; Set dither flags
		or.w	0(a2,d1.w),d0
		move.w	d0,pf_PrintFlags(a0)
		move.l	GfxDensity(a4),d0		; Set density
		move.b	d0,pf_PrintDensity(a0)

		move.w	#CMD_WRITE,IO_COMMAND(a1)	; Init printer
		lea	PrintInit(pc),a0
		move.l	a0,IO_DATA(a1)
		move.l	#-1,IO_LENGTH(a1)
		CALLSYS	DoIO
		tst.b	d0
		bne	.PrintError1

		move.l	PrintReq(a4),a1
		tst.l	GfxSource(a4)			; Check for source
		beq.s	.PrintScreen
		move.l	GfxWindow(a4),a0
		move.l	wd_RPort(a0),io_RastPort(a1)
		moveq	#0,d0
		moveq	#0,d1
		move.w	wd_Width(a0),d2
		move.w	wd_Height(a0),d3
		move.l	wd_WScreen(a0),a0
		lea	sc_ViewPort(a0),a0
		bra.s	.DumpRPort
.PrintScreen	move.l	GfxScreen(a4),a0
		lea	sc_RastPort(a0),a2
		move.l	a2,io_RastPort(a1)
		moveq	#0,d0
		moveq	#0,d1
		move.w	sc_Width(a0),d2
		move.w	sc_Height(a0),d3
		lea	sc_ViewPort(a0),a0
.DumpRPort	tst.l	GfxComplete(a4)
		beq.s	.NotPartial
		move.l	GfxLeft(a4),d0
		move.l	GfxTop(a4),d1
		move.l	GfxWidth(a4),d2
		move.l	GfxHeight(a4),d3
.NotPartial	move.w	d0,io_SrcX(a1)			; Set rectangle to be dumped
		move.w	d1,io_SrcY(a1)
		move.w	d2,io_SrcWidth(a1)
		move.w	d3,io_SrcHeight(a1)
		move.l	vp_ColorMap(a0),io_ColorMap(a1)	; And ViewPort dependant stuff
		move.l	a1,-(sp)
		RELLIB	GetVPModeID,_GfxBase
		move.l	(sp)+,a1
		move.l	d0,io_Modes(a1)

		move.w	#SPECIAL_TRUSTME,d0		; Set special flags
		tst.b	GfxKeepAspect(a4)
		beq.s	.NoAspect
		or.w	#SPECIAL_ASPECT,d0
.NoAspect	tst.b	GfxCenter(a4)			; Center ?
		beq.s	.NoCenterPic
		or.w	#SPECIAL_CENTER,d0
.NoCenterPic	tst.b	GfxFormFeed(a4)			; Formfeed ?
		bne.s	.NoFormFeed
		or.w	#SPECIAL_NOFORMFEED,d0
.NoFormFeed	tst.l	GfxScale(a4)			; Print inches ?
		bne.s	.NoInchPage
		or.w	#SPECIAL_MILCOLS|SPECIAL_MILROWS,d0
		movem.l	d0/a1,-(sp)
		move.l	GfxOutWidth(a4),d0
		move.l	#1000,d1
		RELLIB	UMult32,_UtilityBase
		move.l	d0,io_DestCols(a1)
		move.l	GfxOutHeight(a4),d0
		move.l	#1000,d1
		RELLIB	UMult32,_UtilityBase
		move.l	d0,io_DestRows(a1)
		movem.l	(sp)+,d0/a1
.NoInchPage	cmp.l	#1,GfxScale(a4)			; Print in mm ?
		bne.s	.NoMMPage
		or.w	#SPECIAL_MILCOLS|SPECIAL_MILROWS,d0
		movem.l	d0/a1,-(sp)
		move.l	GfxOutWidth(a4),d0
		move.l	#10000,d1
		RELLIB	UMult32,_UtilityBase
		move.l	#254,d1
		DOLIB	UDivMod32
		move.l	d0,d6
		move.l	GfxOutHeight(a4),d0
		move.l	#10000,d1
		DOLIB	UMult32
		move.l	#254,d1
		DOLIB	UDivMod32
		move.l	d0,d7
		movem.l	(sp)+,d0/a1
		addq.l	#1,d6
		addq.l	#1,d7
		move.l	d6,io_DestCols(a1)
		move.l	d7,io_DestRows(a1)
.NoMMPage	cmp.l	#2,GfxScale(a4)			; Print in cm ?
		bne.s	.NoCMPage
		or.w	#SPECIAL_MILCOLS|SPECIAL_MILROWS,d0
		movem.l	d0/a1,-(sp)
		move.l	GfxOutWidth(a4),d0
		move.l	#100000,d1
		RELLIB	UMult32,_UtilityBase
		move.l	#254,d1
		DOLIB	UDivMod32
		move.l	d0,d6
		move.l	GfxOutHeight(a4),d0
		move.l	#100000,d1
		DOLIB	UMult32
		move.l	#254,d1
		DOLIB	UDivMod32
		move.l	d0,d7
		movem.l	(sp)+,d0/a1
		addq.l	#1,d6
		addq.l	#1,d7
		move.l	d6,io_DestCols(a1)
		move.l	d7,io_DestRows(a1)
.NoCMPage	cmp.l	#3,GfxScale(a4)			; Fraction of full width/height ?
		bne.s	.NoFracPage
		or.w	#SPECIAL_FRACCOLS|SPECIAL_FRACROWS,d0
		movem.l	d0/a1,-(sp)
		move.l	#$64,d0
		move.l	GfxOutWidth(a4),d1
		RELLIB	UDivMod32,_UtilityBase
		move.l	d0,d1
		moveq	#-1,d0
		DOLIB	UDivMod32
		move.l	d0,d6
		move.l	#$64,d0
		move.l	GfxOutHeight(a4),d1
		DOLIB	UDivMod32
		move.l	d0,d1
		moveq	#-1,d0
		DOLIB	UDivMod32
		move.l	d0,d7
		movem.l	(sp)+,d0/a1
		move.l	d6,io_DestCols(a1)
		move.l	d7,io_DestRows(a1)
.NoFracPage	cmp.l	#4,GfxScale(a4)			; Selected Full Page ?
		bne.s	.NoFullPage
		or.w	#SPECIAL_FULLCOLS|SPECIAL_FULLROWS,d0
		move.l	#-1,io_DestCols(a1)
		move.l	#-1,io_DestRows(a1)
.NoFullPage	move.l	GfxDensity(a4),d1		; Set density
		lsl.l	#8,d1
		or.w	d1,d0
		move.w	d0,io_Special(a1)
		move.w	#PRD_DUMPRPORT,IO_COMMAND(a1)
		CALLSYS	SendIO

		move.b	#1,Dumping(a4)
		move.l	PrintPort(a4),a0		; Get SigFlag
		moveq	#0,d0
		moveq	#1,d1
		move.b	MP_SIGBIT(a0),d0
		lsl.l	d0,d1
		move.l	#SIGHANDSHAKE,d0
		or.l	d1,d0
		DOLIB	Wait				; Wait for signals
		move.l	d0,-(sp)
		move.l	PrintReq(a4),a1
		DOLIB	AbortIO
		move.l	PrintReq(a4),a1
		DOLIB	WaitIO
		move.l	(sp)+,d0

		clr.b	Dumping(a4)
		and.l	#SIGHANDSHAKE,d0
		beq.s	.NoAbort
		move.l	#PDERR_CANCEL+500,ErrorNum(a4)
		bra.s	.PrintError2

.NoAbort	move.l	PrintReq(a4),a1			; Check for error
		tst.b	IO_ERROR(a1)
		bne.s	.PrintError1

		tst.b	GfxFormFeed(a4)
		beq.s	.NoPrint
		move.w	#CMD_WRITE,IO_COMMAND(a1)
		lea	PrintFFeed(pc),a0
		move.l	a0,IO_DATA(a1)
		move.l	#-1,IO_LENGTH(a1)
		CALLSYS	DoIO
		tst.b	d0
		beq.s	.NoPrint

.PrintError1	move.l	PrintReq(a4),a0			; Display printer error
		moveq	#0,d0
		move.b	IO_ERROR(a0),d0
		add.l	#500,d0
		move.l	d0,ErrorNum(a4)
.PrintError2	lea	ThisPrinter(a4),a0
		move.l	a0,EasyArg(a4)
		jsr	DisplayError
		bra.s	.NoPrint
.PrintError	move.l	#NOPRINT_ERR,ErrorNum(a4)	; Display open error
		jsr	DisplayError
.NoPrint	tst.l	PrintReq(a4)			; Close resources
		beq.s	.NoReq
		move.l	PrintReq(a4),a1
		tst.l	IO_DEVICE(a1)
		beq.s	.NoDevice
		CALLSYS	CloseDevice
.NoDevice	move.l	PrintReq(a4),a0
		CALLSYS	DeleteIORequest
.NoReq		tst.l	PrintPort(a4)
		beq.s	.NoPort
		move.l	PrintPort(a4),a0
		CALLSYS	DeleteMsgPort
.NoPort		clr.l	PrintPort(a4)
		clr.l	PrintReq(a4)
		rts
PrintName	dc.b	"printer.device",0
PrintInit	dc.b	27,"#1",0
PrintFFeed	dc.b	12,0
		EVEN




**********************************************************************
*                       Handle the Dump window                       *
**********************************************************************
HandleDumpWin	tst.l	PrintHandle(a4)
		beq.s	.GoOn
		move.l	PrintHandle(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		rts
.GoOn		link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		bsr	LockScreen
		tst.l	d0
		beq	.PrintWinError
		moveq	#0,d2
		moveq	#0,d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,PrintVisInfo(a4)
		beq	.PrintWinError

		move.l	-4(a5),a0
		RELLIB	ScreenToFront,_IntuitionBase

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	PrintWinWidth(a4),d2
		move.w	PrintWinHeight(a4),d3
		bsr	ComputeFont
		move.l	-4(a5),a0
		moveq	#0,d5
		moveq	#0,d6
		move.b	sc_WBorRight(a0),d5
		move.b	sc_WBorBottom(a0),d6
		move.l	#FRAC,d0
		mulu	d2,d0
		bsr	ComputeX
		move.l	d0,d4
		move.w	PrintWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		add.w	d5,d0
		cmp.w	sc_Width(a0),d0
		bls.s	.WOk
		move.w	sc_Width(a0),d0
		sub.w	d4,d0
		move.w	d0,d2
.WOk		move.l	#FRAC,d0
		mulu	d3,d0
		bsr	ComputeY
		move.l	d0,d4
		move.w	PrintWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		add.w	d6,d0
		cmp.w	sc_Height(a0),d0
		bls.s	.HOk
		move.w	sc_Height(a0),d0
		sub.w	d4,d0
		move.w	d0,d3
.HOk		lea.l	PrintGadget(a4),a0
		RELLIB	CreateContext,_GadToolsBase
		move.l	d0,a0
		beq	.PrintWinError

		lea	PrintGads(a4),a3

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	PrintVisInfo(a4),gng_VisualInfo(a1)
		move.l	FontPtr(a5),gng_TextAttr(a1)
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#2*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#154*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxAspectText,gng_GadgetText(a1)
		move.w	#GD_GfxAspect,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#7,d0
		lea.l	GfxAspectTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxShadeText,gng_GadgetText(a1)
		move.w	#GD_GfxShade,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	GfxShadeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#34*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxDitherText,gng_GadgetText(a1)
		move.w	#GD_GfxDither,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	GfxDitherTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#331*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#2*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxImageText,gng_GadgetText(a1)
		move.w	#GD_GfxImage,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	GfxImageTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#134*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#66*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#108*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxDensityText,gng_GadgetText(a1)
		move.w	#GD_GfxDensity,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	GfxDensityTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#263*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#18*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxRedText,gng_GadgetText(a1)
		move.w	#GD_GfxRed,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#336*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxGreenText,gng_GadgetText(a1)
		move.w	#GD_GfxGreen,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#420*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxBlueText,gng_GadgetText(a1)
		move.w	#GD_GfxBlue,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#50*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#154*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxScaleText,gng_GadgetText(a1)
		move.w	#GD_GfxScale,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#7,d0
		lea.l	GfxScaleTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#322*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#69*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxSize1Text,gng_GadgetText(a1)
		move.w	#GD_GfxSize1,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxSize1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#416*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxSize2Text,gng_GadgetText(a1)
		move.w	#GD_GfxSize2,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxSize1Tags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#134*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#81*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#108*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#11*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxThresText,gng_GadgetText(a1)
		move.w	#GD_GfxThres,gng_GadgetID(a1)
		move.l	#11,d0
		lea.l	GfxThresTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#263*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#66*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxCenterText,gng_GadgetText(a1)
		move.w	#GD_GfxCenter,gng_GadgetID(a1)
		move.l	#PLACETEXT_RIGHT,gng_Flags(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#378*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxSmoothText,gng_GadgetText(a1)
		move.w	#GD_GfxSmooth,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#263*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#81*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#GfxFormFeedText,gng_GadgetText(a1)
		move.w	#GD_GfxFormFeed,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#378*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxKeepAspectText,gng_GadgetText(a1)
		move.w	#GD_GfxKeepAspect,gng_GadgetID(a1)
		move.l	#2,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#105*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#94*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxGfxTypeText,gng_GadgetText(a1)
		move.w	#GD_GfxGfxType,gng_GadgetID(a1)
		move.l	#PLACETEXT_LEFT,gng_Flags(a1)
		move.l	#7,d0
		lea.l	GfxGfxTypeTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#210*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#52*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#13*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxXText,gng_GadgetText(a1)
		move.w	#GD_GfxX,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxXTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#288*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxYText,gng_GadgetText(a1)
		move.w	#GD_GfxY,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxXTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#366*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxWidthText,gng_GadgetText(a1)
		move.w	#GD_GfxWidth,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxXTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#444*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxHeightText,gng_GadgetText(a1)
		move.w	#GD_GfxHeight,gng_GadgetID(a1)
		move.l	#3,d0
		lea.l	GfxXTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#88*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#121*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#94*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#12*FRAC,d0
		bsr	ComputeY
		move.w	d0,gng_Height(a1)
		move.l	#GfxSourceText,gng_GadgetText(a1)
		move.w	#GD_GfxSource,gng_GadgetID(a1)
		move.l	#7,d0
		lea.l	GfxSourceTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#185*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#310*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		clr.l	gng_GadgetText(a1)
		move.w	#GD_GfxSourceName,gng_GadgetID(a1)
		clr.l	gng_Flags(a1)
		move.l	#13,d0
		lea.l	NormTxtTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		move.l	d0,a0

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#89*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#140*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#158*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#GfxGetText,gng_GadgetText(a1)
		move.w	#GD_GfxGet,gng_GadgetID(a1)
		move.l	#PLACETEXT_IN,gng_Flags(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#6*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#140*FRAC,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a1)
		move.l	#70*FRAC,d0
		bsr	ComputeX
		move.w	d0,gng_Width(a1)
		move.l	#GfxPrintText,gng_GadgetText(a1)
		move.w	#GD_GfxPrint,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#426*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#GfxCancelText,gng_GadgetText(a1)
		move.w	#GD_GfxCancel,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,a0
		move.l	d0,(a3)+

		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	#257*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a1)
		move.l	#158*FRAC,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		move.w	d0,gng_Width(a1)
		move.l	#GfxBoundsText,gng_GadgetText(a1)
		move.w	#GD_GfxBounds,gng_GadgetID(a1)
		move.l	#1,d0
		lea.l	ButtonTags,a2
		DOLIB	CreateGadgetA
		move.l	d0,(a3)+
		tst.l	d0
		beq	.PrintWinError

		lea	PrintGads(a4),a0
		bsr	SetStrIntGads

		move.l	PrintGadget(a4),PrintWinWG+4
		move.l	-4(a5),PrintWinSC+4
		ext.l	d2
		ext.l	d3
		move.l	d2,PrintWinL+4
		move.l	d3,PrintWinT+4
		move.l	-4(a5),a0
		move.w	PrintWinWidth(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeX
		add.w	OffX(a5),d0
		add.b	sc_WBorRight(a0),d0
		move.l	d0,PrintWinW+4
		move.w	PrintWinHeight(a4),d1
		move.w	#FRAC,d0
		mulu	d1,d0
		bsr	ComputeY
		add.w	OffY(a5),d0
		add.b	sc_WBorBottom(a0),d0
		move.l	d0,PrintWinH+4
		suba.l	a0,a0
		lea.l	PrintWinWindowTags,a1
		RELLIB	OpenWindowTagList,_IntuitionBase
		move.l	d0,PrintHandle(a4)
		beq.s	.PrintWinError

		move.l	PrintHandle(a4),a0
		suba.l	a1,a1
		RELLIB	GT_RefreshWindow,_GadToolsBase

		bsr.s	SetPrintGads
		bsr	UnlockScreen
		unlk	a5
		bra	CheckDumpInput

.PrintWinError	bsr	CloseDumpWin
		move.l	#MEMORY_ERR,ErrorNum(a4)
		bsr	DisplayError
		bsr	UnlockScreen
		unlk	a5
		rts


**********************************************************************
*                      Set print window gadgets                      *
**********************************************************************
SetPrintGads	move.l	#GD_GfxAspect,d0		; Set aspect gadget
		move.l	GfxAspect(a4),d1
		bsr	SetPrintCycle

		move.l	#GD_GfxShade,d0			; Set shade gadget
		move.l	GfxShade(a4),d1
		bsr	SetPrintCycle

		move.l	#GD_GfxDither,d0
		move.l	GfxDithering(a4),d1
		bsr	SetPrintCycle

		move.l	#GD_GfxScale,d0
		move.l	GfxScale(a4),d1
		bsr	SetPrintCycle

		move.l	#GD_GfxImage,d0
		move.l	GfxImage(a4),d1
		bsr	SetPrintCycle

		move.b	GfxRed(a4),d0			; Set colors gadgets
		move.l	#GD_GfxRed,d1
		bsr	SetPrintBox

		move.b	GfxGreen(a4),d0
		move.l	#GD_GfxGreen,d1
		bsr	SetPrintBox

		move.b	GfxBlue(a4),d0
		move.l	#GD_GfxBlue,d1
		bsr	SetPrintBox

		move.l	GfxShade(a4),d1
		cmp.l	#3,d1
		beq.s	.ColorOn
		moveq	#1,d1
		bra.s	.SetColors
.ColorOn	moveq	#0,d1
.SetColors	move.l	#GD_GfxRed,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxGreen,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxBlue,d0
		bsr	GhostPrintGad

		move.l	#GD_GfxSize1,d0			; Set out width/height
		move.l	GfxOutWidth(a4),d1
		bsr	SetPrintInt

		move.l	#GD_GfxSize2,d0
		move.l	GfxOutHeight(a4),d1
		bsr	SetPrintInt

		cmp.l	#4,GfxScale(a4)
		bne.s	.NoFull
		moveq	#1,d1
		move.l	#GD_GfxSize1,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxSize2,d0
		bsr	GhostPrintGad

.NoFull		move.l	#GD_GfxDensity,d0		; Set density/threshold
		move.l	GfxDensity(a4),d1
		bsr	SetPrintSlid

		move.l	#GD_GfxThres,d0
		move.l	GfxThreshold(a4),d1
		bsr	SetPrintSlid

		move.b	GfxCenter(a4),d0		; Set checkboxes
		move.l	#GD_GfxCenter,d1
		bsr	SetPrintBox

		move.b	GfxSmooth(a4),d0
		move.l	#GD_GfxSmooth,d1
		bsr	SetPrintBox

		move.b	GfxFormFeed(a4),d0
		move.l	#GD_GfxFormFeed,d1
		bsr	SetPrintBox

		move.b	GfxKeepAspect(a4),d0
		move.l	#GD_GfxKeepAspect,d1
		bsr	SetPrintBox

		move.l	#GD_GfxGfxType,d0		; Set area and source gadgets
		move.l	GfxComplete(a4),d1
		bsr.s	SetPrintCycle

		bsr	SetPrintArea

		move.l	GfxComplete(a4),d1
		bchg	#0,d1
		move.l	#GD_GfxX,d0
		bsr.s	GhostPrintGad
		move.l	#GD_GfxY,d0
		bsr.s	GhostPrintGad
		move.l	#GD_GfxWidth,d0
		bsr.s	GhostPrintGad
		move.l	#GD_GfxHeight,d0
		bsr.s	GhostPrintGad
		move.l	#GD_GfxBounds,d0
		bsr.s	GhostPrintGad

		move.l	#GD_GfxSource,d0
		move.l	GfxSource(a4),d1
		bsr.s	SetPrintCycle

		cmp.l	#2,GfxDithering(a4)
		beq.s	.SmoothOff
		moveq	#0,d1
		bra.s	.SetSmooth
.SmoothOff	moveq	#1,d1
.SetSmooth	move.l	#GD_GfxSmooth,d0
		bsr.s	GhostPrintGad

		move.l	#GD_GfxSourceName,d0
		tst.l	GfxSource(a4)
		beq.s	.ShowScreen
		lea	GfxSourceWin(a4),a2
		bra.s	.ShowSource
.ShowScreen	lea	GfxSourceScr(a4),a2
.ShowSource	bsr	SetTextGad
		rts
SetPrintCycle	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bra	SetCycleGad
SetPrintBox	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bra	SetCheckBox
GhostPrintGad	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bra	GhostGadget
SetPrintInt	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bra	SetIntegerGad
SetPrintSlid	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bra	SetSliderGad
**********************************************************************
*              Sets all four gadgets for area printing               *
**********************************************************************
SetPrintArea	move.l	#GD_GfxX,d0			; Set area integers
		move.l	GfxLeft(a4),d1
		bsr	SetPrintInt

		move.l	#GD_GfxY,d0
		move.l	GfxTop(a4),d1
		bsr	SetPrintInt

		move.l	#GD_GfxWidth,d0
		move.l	GfxWidth(a4),d1
		bsr	SetPrintInt

		move.l	#GD_GfxHeight,d0
		move.l	GfxHeight(a4),d1
		bsr	SetPrintInt
		rts


**********************************************************************
*                         Close Print window                         *
**********************************************************************
CloseDumpWin	lea	PrintHandle(a4),a3
		bra	CloseNormWindow


**********************************************************************
*                     Handle print window input                      *
**********************************************************************
CheckDumpInput	move.l	PrintHandle(a4),a0
		move.l	wd_UserPort(a0),a0
		CALLSYS	WaitPort
LoopPrintMsg	move.l	PrintHandle(a4),a0
		move.l	wd_UserPort(a0),a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq	CheckDumpInput

		move.l	d0,a1
		move.l	im_Class(a1),d6			; Get class
		moveq	#0,d5
		move.w	im_Code(a1),d5			; Get code
		cmp.l	#IDCMP_VANILLAKEY,d6
		bne.s	.End
		move.w	im_Qualifier(a1),d4
		cmp.w	#'a',d5
		blt.s	.End
		and.w	#~$20,d5
.End		move.l	d6,d0
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		move.l	im_IAddress(a1),a2		; Get gadget id
		move.w	gg_GadgetID(a2),d7

.NoGad		DOLIB	GT_ReplyIMsg			; Reply gadtools msg

		cmp.l	#IDCMP_CLOSEWINDOW,d6		; Close Window ?
		beq	CancelPrint

		cmp.l	#IDCMP_CHANGEWINDOW,d6		; Window moved ?
		bne.s	NoPrintMove
		move.l	PrintHandle(a4),a0
		lea	PrintWinLeft(a4),a1
		bsr	StoreWinPos
		bra	LoopPrintMsg

NoPrintMove	cmp.l	#IDCMP_GADGETUP,d6		; Gadget picked ?
		bne	NoPrintGadUp

		cmp.w	#GD_GfxAspect,d7		; Aspect ?
		bne.s	NoAspectGad
		ext.l	d5
		move.l	d5,GfxAspect(a4)
		bra	LoopPrintMsg

NoAspectGad	cmp.w	#GD_GfxShade,d7			; New Shade ?
		bne.s	NoShadeGad
ShadeKey	ext.l	d5
		move.l	d5,GfxShade(a4)
		cmp.l	#3,d5
		beq.s	.ColorsOn
		moveq	#1,d1
		bra.s	.GoOn
.ColorsOn	moveq	#0,d1
.GoOn		move.l	#GD_GfxRed,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxGreen,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxBlue,d0
		bsr	GhostPrintGad
		bra	LoopPrintMsg

NoShadeGad	cmp.w	#GD_GfxDither,d7		; New dither ?
		bne.s	NoDitherGad
DitherKey	ext.l	d5
		move.l	d5,GfxDithering(a4)
		cmp.l	#2,d5
		beq.s	.SmoothOff
		moveq	#0,d1
		bra.s	.GoOn
.SmoothOff	moveq	#1,d1
.GoOn		move.l	#GD_GfxSmooth,d0
		bsr	GhostPrintGad
		bra	LoopPrintMsg

NoDitherGad	cmp.w	#GD_GfxImage,d7			; Change image type ?
		bne.s	NoImageGad
		ext.l	d5
		move.l	d5,GfxImage(a4)
		bra	LoopPrintMsg

NoImageGad	cmp.w	#GD_GfxDensity,d7		; Changed density ?
		bne.s	NoDensityGad
		ext.l	d5
		move.l	d5,GfxDensity(a4)
		bra	LoopPrintMsg

NoDensityGad	cmp.w	#GD_GfxRed,d7			; Changed red colors ?
		bne.s	NoRedGad
RedKey		cmp.l	#3,GfxShade(a4)
		bne	LoopPrintMsg
		bchg	#0,GfxRed(a4)
		move.b	GfxRed(a4),d0
		move.l	#GD_GfxRed,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoRedGad	cmp.w	#GD_GfxGreen,d7			; Changed green colors ?
		bne.s	NoGreenGad
GreenKey	cmp.l	#3,GfxShade(a4)
		bne	LoopPrintMsg
		bchg	#0,GfxGreen(a4)
		move.b	GfxGreen(a4),d0
		move.l	#GD_GfxGreen,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoGreenGad	cmp.w	#GD_GfxBlue,d7			; Changed blue colors ?
		bne.s	NoBlueGad
BlueKey		cmp.l	#3,GfxShade(a4)
		bne	LoopPrintMsg
		bchg	#0,GfxBlue(a4)
		move.b	GfxBlue(a4),d0
		move.l	#GD_GfxBlue,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoBlueGad	cmp.w	#GD_GfxScale,d7			; Changed scale ?
		bne.s	NoScaleGad
GfxScaleKey	ext.l	d5
		move.l	d5,GfxScale(a4)
		moveq	#0,d1
		cmp.l	#4,d5
		bne.s	.NoFull
		moveq	#1,d1
.NoFull		move.l	#GD_GfxSize1,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxSize2,d0
		bsr	GhostPrintGad
		bra	LoopPrintMsg

NoScaleGad	cmp.w	#GD_GfxSize1,d7			; Changed size1 ?
		bne.s	NoSize1Gad
		lea	GfxOutWidth(a4),a1
CheckPrintInt	move.l	gg_SpecialInfo(a2),a0
		move.l	si_LongInt(a0),d0
		move.l	d0,(a1)
		tst.l	d0
		bge.s	.GoOn
		clr.l	(a1)
		move.w	d7,d0
		moveq	#0,d1
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bsr	SetIntegerGad
		sub.l	a0,a0
		RELLIB	DisplayBeep,_IntuitionBase
.GoOn		bra	LoopPrintMsg

NoSize1Gad	cmp.w	#GD_GfxSize2,d7			; Changed size2 ?
		bne.s	NoSize2Gad
		lea	GfxOutHeight(a4),a1
		bra	CheckPrintInt

NoSize2Gad	cmp.w	#GD_GfxThres,d7			; New threshold ?
		bne.s	NoThresGad
		ext.l	d5
		move.l	d5,GfxThreshold(a4)
		bra	LoopPrintMsg

NoThresGad	cmp.w	#GD_GfxCenter,d7		; Changed center ?
		bne.s	NoCenterGad
CenterKey	bchg	#0,GfxCenter(a4)
		move.b	GfxCenter(a4),d0
		move.l	#GD_GfxCenter,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoCenterGad	cmp.w	#GD_GfxSmooth,d7		; Changed smooth ?
		bne.s	NoSmoothGad
SmoothKey	cmp.l	#2,GfxDithering(a4)
		beq	LoopPrintMsg
		bchg	#0,GfxSmooth(a4)
		move.b	GfxSmooth(a4),d0
		move.l	#GD_GfxSmooth,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoSmoothGad	cmp.w	#GD_GfxFormFeed,d7		; Changed formfeed gad ?
		bne.s	NoFFeedGad
FormFeedKey	bchg	#0,GfxFormFeed(a4)
		move.b	GfxFormFeed(a4),d0
		move.l	#GD_GfxFormFeed,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoFFeedGad	cmp.w	#GD_GfxKeepAspect,d7		; Changed aspect ?
		bne.s	NoKAspectGad
KAspectKey	bchg	#0,GfxKeepAspect(a4)
		move.b	GfxKeepAspect(a4),d0
		move.l	#GD_GfxKeepAspect,d1
		bsr	SetPrintBox
		bra	LoopPrintMsg

NoKAspectGad	cmp.w	#GD_GfxGfxType,d7		; Changed Gfx type ?
		bne.s	NoGfxTypeGad
GfxGfxTypeKey	ext.l	d5
		move.l	d5,GfxComplete(a4)
		bchg	#0,d5
		move.l	d5,d1
		move.l	#GD_GfxX,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxY,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxWidth,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxHeight,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxBounds,d0
		bsr	GhostPrintGad
		bra	LoopPrintMsg

NoGfxTypeGad	cmp.w	#GD_GfxX,d7			; Changed left ?
		bne.s	NoGfxLeftGad
		lea	GfxLeft(a4),a1
		bra	CheckPrintInt

NoGfxLeftGad	cmp.w	#GD_GfxY,d7			; Changed top ?
		bne.s	NoGfxTopEdge
		lea	GfxTop(a4),a1
		bra	CheckPrintInt

NoGfxTopEdge	cmp.w	#GD_GfxWidth,d7			; Changed width ?
		bne.s	NoGfxWidthGad
		lea	GfxWidth(a4),a1
		bra	CheckPrintInt

NoGfxWidthGad	cmp.w	#GD_GfxHeight,d7		; Changed height ?
		bne.s	NoGfxHeightGad
		lea	GfxHeight(a4),a1
		bra	CheckPrintInt

NoGfxHeightGad	cmp.w	#GD_GfxSource,d7		; Changed source ?
		bne.s	NoGfxSourceGad
GfxSourceKey	ext.l	d5
		move.l	d5,GfxSource(a4)
		tst.l	d5
		beq.s	.ShowScreen
		lea	GfxSourceWin(a4),a2
		bra.s	.SetSource
.ShowScreen	lea	GfxSourceScr(a4),a2
.SetSource	move.l	#GD_GfxSourceName,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bsr	SetTextGad
		bra	LoopPrintMsg

NoGfxSourceGad	cmp.w	#GD_GfxGet,d7			; Get new window/screen ?
		bne.s	NoGfxGetGad
GfxGetKey	move.l	PrintHandle(a4),a0
		lea	GfxGetTitle,a1
		lea	WindowScrTitle,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		move.b	#1,GetSource(a4)
		move.l	GfxDumpFlag(a4),d0
		CALLSYS	Wait
		clr.b	GetSource(a4)
		bsr	GetNewSource
		move.l	GfxWindow(a4),d0
		cmp.l	PrintHandle(a4),d0
		bne.s	.NotMe
		move.l	#NOTME_ERR,ErrorNum(a4)
		bsr	DisplayError
		bra.s	GfxGetKey
.NotMe		move.l	PrintHandle(a4),a0
		lea	PrintTitle(a4),a1
		lea	WindowScrTitle,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		move.l	PrintHandle(a4),a0
		DOLIB	WindowToFront
		move.l	PrintHandle(a4),a0
		move.l	wd_WScreen(a0),a0
		DOLIB	ScreenToFront
		move.l	GfxSource(a4),d5
		bra	GfxSourceKey

NoGfxGetGad	cmp.w	#GD_GfxBounds,d7		; Get new bounds for gfx ?
		bne.s	NoGfxBoundGad
		bsr	GetNewBounds
		bra	LoopPrintMsg

NoGfxBoundGad	cmp.w	#GD_GfxPrint,d7			; Print ?
		bne.s	NoPrintGad
		bsr	CheckPrintDim
		tst.l	d0
		beq	LoopPrintMsg
		moveq	#1,d0
		bra	EndInput

NoPrintGad	cmp.w	#GD_GfxCancel,d7		; Cancel ?
		bne.s	NoPrintCancel
CancelPrint	moveq	#0,d0
		bra	EndInput

NoPrintCancel	bra	LoopPrintMsg

NoPrintGadUp	cmp.l	#IDCMP_VANILLAKEY,d6		; Key pressed ?
		bne	NoPrintVKey

		cmp.w	#KD_GfxAspect,d5		; Change Aspect ?
		bne.s	NoAspectKey
		move.l	GfxAspect(a4),d1
		bchg	#0,d1
		move.l	d1,GfxAspect(a4)
		move.l	#GD_GfxAspect,d0
		bsr	SetPrintCycle
		bra	LoopPrintMsg

NoAspectKey	cmp.w	#KD_GfxShade,d5			; Change Shade ?
		bne.s	NoShadeKey
		move.l	GfxShade(a4),d5
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d5
		bge.s	.GoOn
		moveq	#3,d5
		bra.s	.GoOn
.Up		addq.l	#1,d5
		cmp.l	#3,d5
		ble.s	.GoOn
		moveq	#0,d5
.GoOn		move.l	#GD_GfxShade,d0
		move.l	d5,d1
		bsr	SetPrintCycle
		bra	ShadeKey

NoShadeKey	cmp.w	#KD_GfxDither,d5		; Change dither ?
		bne.s	NoDitherKey
		move.l	GfxDithering(a4),d5
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d5
		ble.s	.GoOn
		moveq	#2,d5
		bra.s	.GoOn
.Up		addq.l	#1,d5
		cmp.l	#2,d5
		ble.s	.GoOn
		moveq	#0,d5
.GoOn		move.l	#GD_GfxDither,d0
		move.l	d5,d1
		bsr	SetPrintCycle
		bra	DitherKey

NoDitherKey	cmp.w	#KD_GfxImage,d5			; Changed image ?
		bne.s	NoImageKey
		move.l	GfxImage(a4),d1
		bchg	#0,d1
		move.l	d1,GfxImage(a4)
		move.l	#GD_GfxImage,d0
		bsr	SetPrintCycle
		bra	LoopPrintMsg

NoImageKey	cmp.w	#KD_GfxRed,d5			; Change red ?
		beq	RedKey

		cmp.w	#KD_GfxGreen,d5			; Change green ?
		beq	GreenKey

		cmp.w	#KD_GfxBlue,d5			; Change blue ?
		beq	BlueKey

		cmp.w	#KD_GfxScale,d5			; Changed scale ?
		bne.s	NoScaleKey
		move.l	GfxScale(a4),d1
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d1
		bge.s	.GoOn
		moveq	#4,d1
		bra.s	.GoOn
.Up		addq.l	#1,d1
		cmp.l	#4,d1
		ble.s	.GoOn
		moveq	#0,d1
.GoOn		move.l	d1,GfxScale(a4)
		move.l	#GD_GfxScale,d0
		bsr	SetPrintCycle
		move.l	d1,d5
		bra	GfxScaleKey

NoScaleKey	cmp.w	#KD_GfxSize1,d5			; Change sizes ?
		bne.s	NoGfxSize
		cmp.l	#4,GfxScale(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxSize1,d0
ActPrintGad	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		bsr	ActStringGad
		bra	LoopPrintMsg

NoGfxSize	cmp.w	#KD_GfxThres,d5			; Change threshold ?
		bne.s	NoGfxThresKey
		move.l	GfxThreshold(a4),d1
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d1
		bgt.s	.GoOn
		move.l	#15,d1
		bra.s	.GoOn
.Up		addq.l	#1,d1
		cmp.l	#15,d1
		ble.s	.GoOn
		moveq	#1,d1
.GoOn		move.l	d1,GfxThreshold(a4)
		move.l	#GD_GfxThres,d0
		bsr	SetPrintSlid
		bra	LoopPrintMsg

NoGfxThresKey	cmp.w	#KD_GfxDensity,d5		; New denstity ?
		bne.s	NoDensityKey
		move.l	GfxDensity(a4),d1
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d1
		bgt.s	.GoOn
		move.l	#7,d1
		bra.s	.GoOn
.Up		addq.l	#1,d1
		cmp.l	#7,d1
		ble.s	.GoOn
		moveq	#1,d1
.GoOn		move.l	d1,GfxDensity(a4)
		move.l	#GD_GfxDensity,d0
		bsr	SetPrintSlid
		bra	LoopPrintMsg

NoDensityKey	cmp.w	#KD_GfxCenter,d5		; Center ?
		beq	CenterKey

		cmp.w	#KD_GfxSmooth,d5		; Smooth ?
		beq	SmoothKey

		cmp.w	#KD_GfxFormFeed,d5		; Formfeed ?
		beq	FormFeedKey

		cmp.w	#KD_GfxKeepAspect,d5		; Keep aspect ?
		beq	KAspectKey

		cmp.w	#KD_GfxGfxType,d5		; Change graphix type ?
		bne.s	NoGfxGfxKey
		move.l	GfxComplete(a4),d1
		bchg	#0,d1
		move.l	d1,GfxComplete(a4)
		move.l	#GD_GfxGfxType,d0
		bsr	SetPrintCycle
		move.l	d1,d5
		bra	GfxGfxTypeKey

NoGfxGfxKey	cmp.w	#KD_GfxX,d5			; New Leftedge ?
		bne.s	NoGfxXKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxX,d0
		bra	ActPrintGad

NoGfxXKey	cmp.w	#KD_GfxY,d5			; New top edge ?
		bne.s	NoGfxYKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxY,d0
		bra	ActPrintGad

NoGfxYKey	cmp.w	#KD_GfxWidth,d5			; New width ?
		bne.s	NoGfxWidthKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxWidth,d0
		bra	ActPrintGad

NoGfxWidthKey	cmp.w	#KD_GfxHeight,d5		; New height ?
		bne.s	NoGfxHeightKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxHeight,d0
		bra	ActPrintGad

NoGfxHeightKey	cmp.w	#KD_GfxSource,d5		; Change source ?
		bne.s	NoGfxSourceKey
		move.l	GfxSource(a4),d5
		bchg	#0,d5
		move.l	d5,GfxSource(a4)
		move.l	#GD_GfxSource,d0
		move.l	d5,d1
		bsr	SetPrintCycle
		bra	GfxSourceKey

NoGfxSourceKey	cmp.w	#KD_GfxGet,d5			; Get new source ?
		bne.s	NoGfxGetKey
		move.l	#GD_GfxGet,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
		bra	GfxGetKey

NoGfxGetKey	cmp.w	#KD_GfxBounds,d5		; Get new bounds for area ?
		bne.s	NoGfxBoundKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxBounds,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
		bsr	GetNewBounds
		bra	LoopPrintMsg

NoGfxBoundKey	cmp.w	#KD_GfxPrint,d5			; Print stuff ?
		bne.s	NoGfxPrintKey
		move.l	#GD_GfxPrint,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
		bsr	CheckPrintDim
		tst.l	d0
		beq	LoopPrintMsg
		moveq	#1,d0
		bra.s	EndInput

NoGfxPrintKey	cmp.w	#KD_GfxCancel,d5		; cancel ?
		beq.s	.DoCancel
		cmp.w	#ESCKEY,d5
		bne.s	NoPrintVKey
.DoCancel	move.l	#GD_GfxCancel,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
		moveq	#0,d0
		bra.s	EndInput

NoPrintVKey	bra	LoopPrintMsg
EndInput	move.l	d0,-(sp)
		bsr	CloseDumpWin
		move.l	(sp)+,d0
		rts



**********************************************************************
*                           Get new inputs                           *
**********************************************************************
GetNewSource	clr.l	GfxWindow(a4)			; Get current screen and window
		clr.l	GfxScreen(a4)
		clr.b	GfxSourceScr(a4)
		clr.b	GfxSourceWin(a4)
		bsr	FindWindow
		move.l	a0,a2
		tst.l	d0
		beq.s	.NoLayer
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.NoLayer
		move.l	d0,a0
		move.l	a0,GfxWindow(a4)
		move.l	wd_Title(a0),a0
		lea	GfxSourceWin(a4),a1
		bsr	StrCpy
.NoLayer	move.l	a2,d0
		beq.s	.NoScreen
		move.l	a2,GfxScreen(a4)
		move.l	sc_Title(a2),a0
		lea	GfxSourceScr(a4),a1
		bsr	StrCpy
.NoScreen	rts



**********************************************************************
*                  Get new boundaries for printout                   *
**********************************************************************
GetNewBounds	tst.l	GfxSource(a4)
		beq.s	.FromScreen
		move.l	GfxWindow(a4),a0
		move.l	wd_RPort(a0),GfxRastPort(a4)
		move.l	wd_WScreen(a0),GfxBoundScr(a4)
		moveq	#0,d0
		move.w	wd_LeftEdge(a0),d0
		move.l	d0,GfxLeft(a4)
		move.w	wd_TopEdge(a0),d0
		move.l	d0,GfxTop(a4)
		move.w	wd_Width(a0),d0
		subq.l	#1,d0
		move.l	d0,GfxWidth(a4)
		move.w	wd_Height(a0),d0
		subq.l	#1,d0
		move.l	d0,GfxHeight(a4)
		move.l	GfxWindow(a4),a0
		RELLIB	WindowToFront,_IntuitionBase
		move.l	GfxBoundScr(a4),a0
		DOLIB	ScreenToFront
		bra.s	.GetBounds
.FromScreen	move.l	GfxScreen(a4),a0
		lea	sc_RastPort(a0),a1
		move.l	a1,GfxRastPort(a4)
		move.l	a0,GfxBoundScr(a4)
		moveq	#0,d0
		move.w	sc_LeftEdge(a0),d0
		move.l	d0,GfxLeft(a4)
		move.w	sc_TopEdge(a0),d0
		move.l	d0,GfxTop(a4)
		move.w	sc_Width(a0),d0
		subq.l	#1,d0
		move.l	d0,GfxWidth(a4)
		move.w	sc_Height(a0),d0
		subq.l	#1,d0
		move.l	d0,GfxHeight(a4)
		move.l	GfxScreen(a4),a0
		RELLIB	ScreenToFront,_IntuitionBase

.GetBounds	move.l	GfxRastPort(a4),a1
		moveq	#0,d0
		move.b	rp_DrawMode(a1),d0
		move.w	d0,GfxDrawMode(a4)
		move.l	#RP_COMPLEMENT,d0
		RELLIB	SetDrMd,_GfxBase

		clr.l	GfxRX(a4)
		clr.l	GfxRY(a4)
		clr.l	GfxRX2(a4)
		clr.l	GfxRY2(a4)
		bsr	DrawBoundRec

		move.b	#1,GfxGetting(a4)		; Set flag for Handler

.DrawLoop	move.l	#SIGMOUSE|SIGLBUTTON|SIGRBUTTON,d0
		CALLSYS	Wait				; Wait for signals
		move.l	d0,d1				; Right button pressed ?
		and.l	#SIGRBUTTON,d1			; Quit drawing
		bne	.EndDraw
		move.l	d0,d1				; Left button ?
		and.l	#SIGLBUTTON,d1
		bne.s	.NewPos
		and.l	#SIGMOUSE,d0			; Mouse just moved ?
		bne.s	.NoNewPos
		bra.s	.DrawLoop
.NewPos		bsr	DrawBoundRec			; Get new position
		move.l	GfxBoundScr(a4),a1
		bsr	GetCoords
		sub.l	GfxLeft(a4),d2
		sub.l	GfxTop(a4),d3
		move.l	d2,d4
		move.l	d3,d5
		bsr	TestBounds			; Check boundaries
		move.l	d4,GfxRX(a4)
		move.l	d5,GfxRY(a4)
		addq.l	#1,d4
		addq.l	#1,d5
		move.l	d4,GfxRX2(a4)
		move.l	d5,GfxRY2(a4)
		bsr	DrawBoundRec			; Draw new rec
		bra.s	.DrawLoop
.NoNewPos	move.l	GfxBoundScr(a4),a1		; Mouse really moved ?
		bsr	GetCoords
		sub.l	GfxLeft(a4),d2
		sub.l	GfxTop(a4),d3
		move.l	d2,d6
		move.l	d3,d7
		cmp.l	GfxRX2(a4),d6
		bne.s	.NewRec
		cmp.l	GfxRY2(a4),d7
		beq	.DrawLoop
.NewRec		bsr	DrawBoundRec			; Clear old rec
		move.l	d6,GfxRX2(a4)
		move.l	d7,GfxRY2(a4)
		bsr.s	DrawBoundRec			; Draw new one
		bra	.DrawLoop
.EndDraw	bsr.s	DrawBoundRec
		clr.b	GfxGetting(a4)

		move.l	GfxRX(a4),d4			; Correct coords the second time
		move.l	GfxRY(a4),d5
		bsr	TestBounds
		move.l	d4,d0
		move.l	d5,d2

		move.l	GfxRX2(a4),d4
		move.l	GfxRY2(a4),d5
		bsr	TestBounds
		move.l	d4,d1
		move.l	d5,d3

		cmp.l	d0,d1				; Swap coords if needed
		bge.s	.X2Big
		exg	d0,d1
.X2Big		cmp.l	d2,d3
		bge.s	.Y2Big
		exg	d2,d3
.Y2Big		sub.l	d0,d1
		sub.l	d2,d3

		move.l	d0,GfxLeft(a4)			; Store new coords
		move.l	d2,GfxTop(a4)
		move.l	d1,GfxWidth(a4)
		move.l	d3,GfxHeight(a4)

		move.l	GfxRastPort(a4),a1
		move.w	GfxDrawMode(a4),d0
		RELLIB	SetDrMd,_GfxBase

		move.l	PrintHandle(a4),a0		; Get our window back to front
		RELLIB	WindowToFront,_IntuitionBase
		move.l	PrintHandle(a4),a0
		move.l	wd_WScreen(a0),a0
		DOLIB	ScreenToFront
		bra	SetPrintArea





**********************************************************************
*             Draw the rec showing the boundaries by the             *
**********************************************************************
DrawBoundRec	move.l	GfxRX2(a4),d4
		move.l	GfxRY2(a4),d5
		bsr.s	TestBounds

		move.l	GfxRastPort(a4),a1
		move.l	GfxRX(a4),d0
		move.l	GfxRY(a4),d1
		RELLIB	Move,_GfxBase

		move.l	GfxRastPort(a4),a1
		move.l	d4,d0
		move.l	GfxRY(a4),d1
		DOLIB	Draw

		move.l	GfxRastPort(a4),a1
		move.l	d4,d0
		move.l	d5,d1
		DOLIB	Draw

		move.l	GfxRastPort(a4),a1
		move.l	GfxRX(a4),d0
		move.l	d5,d1
		DOLIB	Draw

		move.l	GfxRastPort(a4),a1
		move.l	GfxRX(a4),d0
		move.l	GfxRY(a4),d1
		DOLIB	Draw
		rts



**********************************************************************
*                        Test current bounds                         *
**********************************************************************
TestBounds	tst.l	d4
		bge.s	.XBig
		moveq	#0,d4
.XBig		cmp.l	GfxWidth(a4),d4
		ble.s	.CheckY
		move.l	GfxWidth(a4),d4
.CheckY		tst.l	d5
		bge.s	.YBig
		moveq	#0,d5
.YBig		cmp.l	GfxHeight(a4),d5
		ble.s	.DrawRec
		move.l	GfxHeight(a4),d5
.DrawRec	rts




**********************************************************************
*                       Checks the user input                        *
**********************************************************************
CheckPrintDim	cmp.l	#4,GfxScale(a4)
		beq.s	.NoFrac
		tst.l	GfxOutWidth(a4)
		beq.s	.Error
		tst.l	GfxOutHeight(a4)
		beq.s	.Error
		cmp.l	#3,GfxScale(a4)
		bne.s	.NoFrac
		cmp.l	#100,GfxOutWidth(a4)
		bgt.s	.Error
		cmp.l	#100,GfxOutHeight(a4)
		bgt.s	.Error
.NoFrac		tst.l	GfxComplete(a4)
		beq.s	.End
		tst.l	GfxWidth(a4)
		beq.s	.Error
		tst.l	GfxHeight(a4)
		beq.s	.Error
.End		moveq	#1,d0
		rts
.Error		move.l	#CHECKDIM_ERR,ErrorNum(a4)
		jsr	DisplayError
		moveq	#0,d0
		rts




**********************************************************************
*                 This the table for all the patches                 *
**********************************************************************
PatchTable	PATCHES	SetPointer,_IntuitionBase
		PATCH	ClearPointer,_IntuitionBase
		PATCH	CloseWindow,_IntuitionBase
		PATCH	OpenScreen,_IntuitionBase
		PATCH	OpenScreenTagList,_IntuitionBase
		PATCH	ScreenToFront,_IntuitionBase
		PATCH	ScreenToBack,_IntuitionBase
		PATCH	WBenchToFront,_IntuitionBase
		PATCH	WBenchToBack,_IntuitionBase
		PATCH	CloseScreen,_IntuitionBase
		PATCH	AutoRequest,_IntuitionBase
		PATCH	EasyRequestArgs,_IntuitionBase
		PATCH	CreateUpfrontLayer,_LayersBase
		PATCH	CreateUpfrontHookLayer,_LayersBase
		PATCH	DeleteLayer,_LayersBase
		PATCH	MoveSizeLayer,_LayersBase


**********************************************************************
*                          Set all patches                           *
**********************************************************************
SetPatch	lea	PatchTable(pc),a2
		moveq	#NumPatch-1,d7
.Loop		move.w	0(a2),d0
		move.l	0(a4,d0.w),a1
		move.w	2(a2),a0
		move.l	4(a2),d0
		move.l	a1,d1
		beq.s	.NoPatch
		CALLSYS	SetFunction
		move.w	8(a2),d1
		move.l	d0,0(a4,d1.w)
.NoPatch	lea	10(a2),a2
		dbf	d7,.Loop
		rts

**********************************************************************
*                     Remove all of our patches                      *
**********************************************************************
UnPatch		lea	PatchTable(pc),a2
		moveq	#NumPatch-1,d7
.Loop		move.w	0(a2),d0
		move.l	0(a4,d0.w),a1
		move.w	2(a2),a0
		move.w	8(a2),d0
		move.l	0(a4,d0.w),d0
		move.l	a1,d1
		beq.s	.NoPatch
		CALLSYS	SetFunction
.NoPatch	lea	10(a2),a2
		dbf	d7,.Loop
		rts





**********************************************************************
*               New function to keep track of blanking               *
**********************************************************************
NewSetPointer	bsr	GetSemaphore
		movem.l	d4-d5/a2-a3/a5,-(sp)
		cmp.l	#NoSpriteDat,a1
		beq.s	.End1
		lea	ZeroPage,a5
		lea	PointerList(a5),a2
		moveq	#MAXPOINTERS-1,d4
		sub.l	a3,a3
.Search		move.l	pt_Window(a2),d5
		bne.s	.Skip
		move.l	a2,a3
.Skip		cmp.l	d5,a0
		beq.s	.GotIt
		lea	pt_SIZEOF(a2),a2
		dbra	d4,.Search
		move.l	a3,a2
		move.l	a2,d4
		beq.s	.End
.GotIt		movem.l	d0-d3/a0-a1,(a2)
.End		cmp.l	MBlankWindow(a5),a0
		beq.s	.End1
		movem.l	(sp)+,d4-d5/a2-a3/a5
		subq.l	#8,sp
		move.l	a0,(sp)
		lea	ZeroPage,a0
		move.l	OldSetPointer(a0),4(sp)
		move.l	(sp)+,a0
		bsr	FreeSemaphore
		rts
.End1		movem.l	(sp)+,d4-d5/a2-a3/a5
		bsr	FreeSemaphore
		rts




**********************************************************************
*           Function to keep track of clearing the pointer           *
**********************************************************************
NewClearPointer	bsr	GetSemaphore
		lea	ZeroPage,a1
		lea	PointerList(a1),a1
		moveq	#MAXPOINTERS-1,d0
.Loop		cmp.l	pt_Window(a1),a0
		beq.s	.GotIt
		lea	pt_SIZEOF(a1),a1
		dbra	d0,.Loop
		bra.s	.End
.GotIt		clr.l	pt_Window(a1)
.End		lea	ZeroPage,a1
		cmp.l	MBlankWindow(a1),a0
		beq.s	.End1
		move.l	OldClearPointer(a1),-(sp)
.End1		bsr	FreeSemaphore
		rts






**********************************************************************
*            New function for checking window close-downs            *
**********************************************************************
NewCloseWindow	bsr	GetSemaphore
		move.l	a0,-(sp)
		DOLIB	ClearPointer
		move.l	(sp)+,a0
		lea	ZeroPage,a1
		cmp.l	MBlankWindow(a1),a0
		bne.s	.Skip
		clr.l	MBlankWindow(a1)
.Skip		move.l	OldCloseWindow(a1),-(sp)
		bsr	FreeSemaphore
		rts



**********************************************************************
*                      New OpenScreen function                       *
**********************************************************************
NewOpenScreen	movem.l	RegsAll,-(sp)
		bsr	GetSemaphore
		lea	ZeroPage,a4
		tst.b	AutoCenter(a4)
		beq.s	.GoOn
		bsr	GetDispCols			; Get Display columns
		bsr	CheckStruct			; Check structure
.GoOn		bsr	FreeSemaphore
		movem.l	(sp)+,RegsAll
		move.l	#OldOpenScreen,d0
		bra	DoRemember




**********************************************************************
*                   New OpenScreenTagList function                   *
**********************************************************************
NewOpenScreenTagList
		bsr	GetSemaphore
		movem.l	RegsAll,-(sp)			; Store registers
		lea	ZeroPage,a4
		tst.b	AutoCenter(a4)
		beq.s	.FullSize
		bsr	GetDispCols			; Get columns
		move.l	a0,d0
		beq.s	.CheckTags			; Nope -> go on
		bsr	CheckStruct			; Check structure
.CheckTags	move.l	a1,d0
		beq.s	.FullSize			; Nope -> go on
		move.l	#SA_Left,d0			; Find LeftEdge tag
		bsr.s	FindTag
		move.l	a2,d0				; Got it ???
		beq.s	.FullSize			; Nope -> go on
		tst.l	ti_Data(a2)			; Screen a TopLeft ?
		bne.s	.FullSize			; Nope -> go on
		move.l	a2,a3				; Store pointer to leftedge
		move.l	#SA_Width,d0			; Find Width tag
		bsr.s	FindTag
		move.l	a2,d0
		beq.s	.FullSize
		tst.l	ti_Data(a2)			; Full width ?
		ble.s	.FullSize			; Yep -> no more stuff
		move.l	ti_Data(a2),d4			; Find display ID
		move.l	#SA_DisplayID,d0
		bsr.s	FindTag
		move.l	a2,d0				; Got it ?
		beq.s	.FullSize			; Nope -> go on
		move.l	ti_Data(a2),d0			; Key Key
		move.l	d0,d1
		and.l	#V_HIRES,d0
		bne.s	.IsHires
		and.l	#V_SUPERHIRES,d1		; Hires ?
		bne.s	.SuperHires
		lsr.w	#1,d5				; Is Lores so half the width
		bra.s	.IsHires
.SuperHires	lsl.w	#1,d5				; Is SuperHires -> double the width
.IsHires	sub.w	d4,d5				; Get difference
		ble.s	.FullSize			; Over boundary -> quit
		lsr.l	#1,d5				; Half the leftedge and store
		move.l	d5,ti_Data(a3)			; it within tag
.FullSize	movem.l	(sp)+,RegsAll
		bsr	FreeSemaphore
		move.l	#OldOpenScreenTagList,d0
		bra	DoRemember



**********************************************************************
*                        Find a specific tag                         *
**********************************************************************
FindTag		move.l	a1,a2
.Loop		cmp.l	#TAG_DONE,ti_Tag(a2)
		bne.s	.GoOn
		sub.l	a2,a2
		bra.s	.End
.GoOn		cmp.l	ti_Tag(a2),d0
		beq.s	.End
		lea	ti_SIZEOF(a2),a2
		bra.s	.Loop
.End		rts



**********************************************************************
*                  Check settings within structure                   *
**********************************************************************
CheckStruct	tst.w	ns_LeftEdge(a0)
		bne.s	.FullSize
		move.w	ns_Width(a0),d1
		cmp.w	#-1,d1
		beq.s	.FullSize
		move.w	ns_ViewModes(a0),d7
		move.w	d7,d6
		and.w	#V_HIRES,d7
		bne.s	.IsHires
		and.w	#V_SUPERHIRES,d6
		bne.s	.SuperHires
		lsr.w	#1,d5
		bra.s	.IsHires
.SuperHires	lsl.w	#1,d5
.IsHires	sub.w	d1,d5
		ble.s	.FullSize
		lsr.w	#1,d5
		move.w	d5,ns_LeftEdge(a0)
.FullSize	rts



**********************************************************************
*               Get currently available DisplayColumns               *
**********************************************************************
GetDispCols	lea	ZeroPage,a4
		move.l	_GfxBase(a4),a3
		move.w	gb_NormalDisplayColumns(a3),d5
		rts



**********************************************************************
*                      Screen to front routine                       *
**********************************************************************
NewScreenToFront
		move.l	#OldScreenToFront,d0
		bsr.s	DoRemember
		bra	RestoreWindow


**********************************************************************
*                           Screen to back                           *
**********************************************************************
NewScreenToBack	move.l	#OldScreenToBack,d0
		bsr.s	DoRemember
		bra	RestoreWindow


**********************************************************************
*                         Workbench to front                         *
**********************************************************************
NewWBenchToFront
		move.l	#OldWBenchToFront,d0
		bsr.s	DoRemember
		bra	RestoreWindow


**********************************************************************
*                         Workbench to back                          *
**********************************************************************
NewWBenchToBack	move.l	#OldWBenchToBack,d0
		bsr.s	DoRemember
		bra	RestoreWindow


**********************************************************************
*                            Close screen                            *
**********************************************************************
NewCloseScreen	bsr	GetSemaphore
		lea	ZeroPage,a1
		lea	ScreenList(a1),a1
		moveq	#MAXSCREENS-1,d0
.Loop		cmp.l	(a1),a0
		beq.s	.GotIt
		addq.l	#8,a1
		dbf	d0,.Loop
.End		lea	ZeroPage,a1
		pea	RestoreWindow(pc)
		move.l	OldCloseScreen(a1),-(sp)
		bsr	FreeSemaphore
		rts
.GotIt		clr.l	(a1)
		bra.s	.End




**********************************************************************
*                  Stub for calling system routines                  *
**********************************************************************
DoRemember	bsr	GetSemaphore
		bsr.s	RememberWindow
		move.l	a0,-(sp)
		lea	ZeroPage,a0
		move.l	0(a0,d0.w),d0
		move.l	(sp)+,a0
		move.l	d0,-(sp)
		bsr	FreeSemaphore
		rts



**********************************************************************
*                   Store screen/window addresses                    *
**********************************************************************
RememberWindow	movem.l	RegsAll,-(sp)
		lea	ZeroPage,a4
		CALLSYS	Forbid
		move.l	_IntuitionBase(a4),a0
		move.l	ib_ActiveWindow(a0),a1
		move.l	ib_ActiveScreen(a0),a0
		CALLSYS	Permit
		move.l	a0,d0
		beq.s	.End
		move.l	a1,d0
		beq.s	.End
		lea	ScreenList(a4),a2		; Check if screen`s already in list
		moveq	#MAXSCREENS-1,d0
.Find		cmp.l	(a2),a0
		beq.s	.GotIt
		addq.l	#8,a2
		dbf	d0,.Find
		lea	ScreenList(a4),a2		; Store screen
		moveq	#MAXSCREENS-1,d0
.Stick		tst.l	(a2)
		beq.s	.Save
		addq.l	#8,a2
		dbf	d0,.Stick
		bra.s	.End
.Save		move.l	a0,(a2)+
		move.l	a1,(a2)
		bra.s	.End
.GotIt		move.l	a1,4(a2)
.End		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*       This routine reactivates the previously active window        *
**********************************************************************
RestoreWindow	bsr	GetSemaphore
		movem.l	RegsAll,-(sp)
		lea	ZeroPage,a4
		lea	ScreenList(a4),a1
		move.l	_IntuitionBase(a4),a6
		move.l	ib_FirstScreen(a6),a0
		move.l	a0,d0
		beq.s	.End
		moveq	#MAXSCREENS-1,d0
.Loop		cmp.l	(a1),a0
		beq.s	.GotIt
		addq.l	#8,a1
		dbf	d0,.Loop
		move.l	sc_FirstWindow(a0),a0
		move.l	a0,d0
		beq.s	.End
		bra.s	.Skip
.GotIt		move.l	4(a1),a0
.Skip		DOLIB	ActivateWindow
.End		movem.l	(sp)+,RegsAll
		bsr	FreeSemaphore
		rts





**********************************************************************
*                       New CreateUpfrontLayer                       *
**********************************************************************
NewCreateUpfrontLayer
		movem.l	d0-d7/a0-a6,-(sp)
		lea	ZeroPage,a4
		tst.b	ExpWindows(a4)
		beq.s	.NoExplode
		and.l	#LAYERBACKDROP,d4		; Backdrop-Layer ?
		bne.s	.NoExplode			; No explode
		move.l	a0,a3
		bsr	GetScreen
		move.l	a3,d7
		beq.s	.NoExplode
		move.l	ExpFrames(a4),-(sp)
		sub.l	d0,d2				; Get dims
		sub.l	d1,d3
		tst.b	MouseCenter(a4)
		bne.s	.GetMousePos
		move.w	sc_Width(a3),d4
		lsr.w	#1,d4
		ext.l	d4
		move.w	sc_Height(a3),d5
		lsr.w	#1,d5
		ext.l	d5
		bra.s	.GotPos
.GetMousePos	move.w	sc_MouseX(a3),d4
		move.w	sc_MouseY(a3),d5
		ext.l	d4
		ext.l	d5
.GotPos		movem.l	d2-d3,-(sp)
		sub.l	d5,d1
		move.l	d1,-(sp)
		sub.l	d4,d0
		move.l	d0,-(sp)
		pea	1.W
		pea	1.W
		movem.l	d4-d5,-(sp)
		move.l	a3,-(sp)
		jsr	LayerFade
		lea	40(sp),sp
.NoExplode	movem.l	(sp)+,d0-d7/a0-a6
		move.l	a5,-(sp)
		move.l	OldCreateUpfrontLayer+ZeroPage,a5
		jsr	(a5)
		move.l	(sp)+,a5
		rts


**********************************************************************
*                     New CreateUpfrontHookLayer                     *
**********************************************************************
NewCreateUpfrontHookLayer
		movem.l	d0-d7/a0-a6,-(sp)
		lea	ZeroPage,a4
		tst.b	ExpWindows(a4)
		beq.s	.NoExplode
		and.l	#LAYERBACKDROP,d4		; BackDrop-Layer ?
		bne.s	.NoExplode			; No explode
		move.l	a0,a3
		bsr	GetScreen
		move.l	a3,d7
		beq.s	.NoExplode
		move.l	ExpFrames(a4),-(sp)
		sub.l	d0,d2				; Get dims
		sub.l	d1,d3
		tst.b	MouseCenter(a4)
		bne.s	.GetMouse
		move.w	sc_Width(a3),d4
		lsr.w	#1,d4
		ext.l	d4
		move.w	sc_Height(a3),d5
		lsr.w	#1,d5
		ext.l	d5
		bra.s	.GotPos
.GetMouse	move.w	sc_MouseX(a3),d4
		move.w	sc_MouseY(a3),d5
		ext.l	d4
		ext.l	d5
.GotPos		move.l	d3,-(sp)
		move.l	d2,-(sp)
		sub.l	d5,d1
		move.l	d1,-(sp)
		sub.l	d4,d0
		move.l	d0,-(sp)
		pea	1.W
		pea	1.W
		move.l	d5,-(sp)
		move.l	d4,-(sp)
		move.l	a3,-(sp)
		jsr	LayerFade
		lea	40(sp),sp
.NoExplode	movem.l	(sp)+,d0-d7/a0-a6
		move.l	a5,-(sp)
		move.l	OldCreateUpfrontHookLayer+ZeroPage,a5
		jsr	(a5)
		move.l	(sp)+,a5
		rts





**********************************************************************
*                      This is our DeleteLayer                       *
**********************************************************************
NewDeleteLayer	movem.l	d2-d7/a2-a6,-(sp)
		lea	ZeroPage,a4
		moveq	#0,d4				; Clear screen pointer
		move.w	lr_Flags(a1),d0			; BACKDROP layer ?
		and.w	#LAYERBACKDROP,d0
		bne.s	.BackLayer			; Yep -> no frames
		move.l	a1,a3
		move.l	lr_LayerInfo(a3),a3
		bsr	GetScreen			; Get layer`s screen
		move.l	a3,d4
		move.w	lr_MinX(a1),d7			; Get layers dims
		move.w	lr_MinY(a1),d1
		move.w	lr_MaxX(a1),d2
		move.w	lr_MaxY(a1),d3
		ext.l	d7
		ext.l	d1
		ext.l	d2
		ext.l	d3
		sub.l	d7,d2
		sub.l	d1,d3
.BackLayer	movem.l	d1-d7,-(sp)
		move.l	OldDeleteLayer(a4),a3		; Delete layer
		jsr	(a3)
		movem.l	(sp)+,d1-d7
		move.l	d0,a3
		beq.s	.NoImplode
		tst.b	ExpWindows(a4)
		beq.s	.NoImplode
		move.l	d7,d0

		tst.l	d4				; Do we have a screen ?
		beq.s	.NoImplode
		move.l	a3,-(sp)
		move.l	ImpFrames(a4),-(sp)
		move.l	d4,a3
		move.l	d2,d5
		move.l	d3,d6
		neg.l	d5
		neg.l	d6
		move.l	d6,-(sp)
		move.l	d5,-(sp)
		tst.b	MouseCenter(a4)
		bne.s	.GetMouse
		move.w	sc_Height(a3),d5
		lsr.w	#1,d5
		ext.l	d5
		sub.l	d1,d5
		move.l	d5,-(sp)
		move.w	sc_Width(a3),d5
		lsr.w	#1,d5
		ext.l	d5
		sub.l	d7,d5
		move.l	d5,-(sp)
		bra.s	.GotPos
.GetMouse	move.w	sc_MouseY(a3),d5
		ext.l	d5
		sub.l	d1,d5
		move.l	d5,-(sp)
		move.w	sc_MouseX(a3),d5
		ext.l	d5
		sub.l	d7,d5
		move.l	d5,-(sp)
.GotPos		move.l	d3,-(sp)
		move.l	d2,-(sp)
		move.l	d1,-(sp)
		move.l	d7,-(sp)
		move.l	d4,-(sp)
		jsr	LayerFade			; Implode
		lea	40(sp),sp
		move.l	(sp)+,a3
.NoImplode	move.l	a3,d0				; Restore returnvalue
		movem.l	(sp)+,d2-d7/a2-a6
		rts



**********************************************************************
*                    New Move/Size Layer function                    *
**********************************************************************
NewMoveSizeLayer
		movem.l	d1-d7/a0-a6,-(sp)
		lea	ZeroPage,a4
		movem.l	RegsAll,-(sp)
		tst.b	ExpWindows(a4)
		beq.s	.NoMove
		move.l	a0,a3
		move.l	lr_LayerInfo(a3),a3
		bsr.s	GetScreen
		move.l	a3,d4				; Get Screen pointer
		beq.s	.NoMove
		move.l	SizeFrames(a4),-(sp)
		move.l	d3,-(sp)
		move.l	d2,-(sp)
		move.l	d1,-(sp)
		move.l	d0,-(sp)
		movem.w	lr_MinX(a0),d0-d3
		ext.l	d0
		ext.l	d1
		ext.l	d2
		ext.l	d3
		sub.l	d0,d2
		sub.l	d1,d3
		move.l	d3,-(sp)
		move.l	d2,-(sp)
		move.l	d1,-(sp)
		move.l	d0,-(sp)
		move.l	d4,-(sp)
		jsr	LayerFade
		lea	40(sp),sp
.NoMove		movem.l	(sp)+,RegsAll
		move.l	OldMoveSizeLayer+ZeroPage,a3	; Move layer
		jsr	(a3)
		movem.l	(sp)+,d1-d7/a0-a6
		rts



**********************************************************************
*             Get address of corresponding to Layer_Info             *
* A3 = Address of Layer_Info                                         *
**********************************************************************
GetScreen	movem.l	d0-d7/a0-a1,-(sp)
		move.l	_IntuitionBase(a4),a0
		move.l	ib_FirstScreen(a0),a0
.FindScreen	move.l	a0,d0
		beq.s	.GotScreen
		move.l	a0,a1
		lea	sc_LayerInfo(a1),a1
		cmp.l	a1,a3
		beq.s	.GotScreen
		move.l	sc_NextScreen(a0),a0
		bra.s	.FindScreen
.GotScreen	move.l	a0,a3
		movem.l	(sp)+,d0-d7/a0-a1
		rts





**********************************************************************
*                      New autorequest routine                       *
**********************************************************************
NewAutoRequest
		pea	OldAutoRequest
		bra.s	DoRequest


**********************************************************************
*                      New Easyrequest routine                       *
**********************************************************************
NewEasyRequestArgs
		pea	OldEasyRequestArgs
		bra.s	DoRequest




**********************************************************************
*                  Do stuff for calling a requester                  *
**********************************************************************
DoRequest	movem.l	d7/a4-a5,-(sp)
		link	a5,#0
		bsr	GetSemaphore
		lea	ZeroPage,a4
		move.l	16(a5),d7
		addq.w	#1,RequestsOpen(a4)
		move.l	0(a4,d7.w),a4
		bsr	FreeSemaphore
		jsr	(a4)
		bsr	GetSemaphore
		lea	ZeroPage,a4
		subq.w	#1,RequestsOpen(a4)
		unlk	a5
		movem.l	(sp)+,d7/a4-a5
		addq.l	#4,sp
		bra	FreeSemaphore




**********************************************************************
*                Edit Hook for String/Integer gadgets                *
* A0 = Pointer to Hook itself                                        *
* A1 = Pointer to parameter                                          *
* A2 = Pointer to SGWork-Structure                                   *
*                       Provided editing is :                        *
* Activating the next gadget on RETURN press                         *
* Actuvating the previous gadget on CONTROL RETURN press             *
* Simulating HELP-Exit of gadget on ESC-Press                        *
* Accessing menus via Key-Stroke RIGHT AMIGA - ShortCut              *
* Using CURSOR UP/DOWN for entering previous/next gadget             *
* Using CONTROL CURSOR LEFT/RIGHT to get to the prev/next word       *
**********************************************************************
StrEditFunc	movem.l	RegsAll,-(sp)
		cmp.l	#SGH_KEY,0(a1)			; Key pressed ?
		bne	.End
		move.l	sgw_Actions(a2),d0
		move.l	d0,d1
		and.l	#SGA_END,d0			; Gadget released ?
		beq.s	.NoReturn			; Nope -> go on
		cmp.w	#HELPKEY,sgw_Code(a2)		; HELP used to escape ?
		beq.s	.NoReturn			; Yep -> go on
		move.l	sgw_IEvent(a2),a3
		move.w	ie_Qualifier(a3),d2
		and.w	#(IEQUALIFIER_CONTROL),d2
		beq.s	.NextGadget
		or.l	#SGA_PREVACTIVE,d1		; On control previous gadget
		bra.s	.ActGadget
.NextGadget	or.l	#SGA_NEXTACTIVE,d1
.ActGadget	move.l	d1,sgw_Actions(a2)
		bra	.End

.NoReturn	move.l	sgw_IEvent(a2),a3		; User pressed ESC ?
		cmp.w	#RESCKEY,ie_Code(a3)
		bne.s	.NoEsc
		move.l	#SGA_END,sgw_Actions(a2)	; Simulate release of gadget
		move.w	#HELPKEY,sgw_Code(a2)
		bra	.End
.NoEsc		cmp.w	#$4c,ie_Code(a3)		; Cursor UP ?
		bne.s	.NoUp
		move.l	#SGA_END|SGA_PREVACTIVE,sgw_Actions(a2)
		move.w	#$44,sgw_Code(a2)
		bra	.End
.NoUp		cmp.w	#$4d,ie_Code(a3)		; Cursor DOWN ?
		bne.s	.NoDown
		move.l	#SGA_END|SGA_NEXTACTIVE,sgw_Actions(a2)
		move.w	#$44,sgw_Code(a2)
		bra	.End
.NoDown		move.w	ie_Qualifier(a3),d0
		and.w	#IEQUALIFIER_CONTROL,d0		; CONTROL pressed ?
		beq	.NoWordJump
		move.l	sgw_WorkBuffer(a2),a1		; Get pointer to buffer
		move.w	sgw_BufferPos(a2),d0		; Get cursor position
		cmp.w	#$4f,ie_Code(a3)		; Jump to left word ?
		beq.s	.JumpLeft
		cmp.w	#$4e,ie_Code(a3)		; Jump to right word ?
		beq.s	.JumpRight
		bra	.NoWordJump
.JumpLeft	tst.w	d0				; Already at beginning ?
		beq	.End
		moveq	#-1,d1				; Set new position
.LeftLoop1	tst.w	d0				; All done ?
		blt.s	.FirstLeft			; Yep -> first loop donw
		cmp.b	#' ',0(a1,d0.w)			; Got a space ?
		beq.s	.NoCharLeft			; Yep -> loop
		move.w	d0,d1				; Nope -> Store new position
		bra.s	.FirstLeft
.NoCharLeft	subq.w	#1,d0				; Next char to the left
		bra.s	.LeftLoop1
.FirstLeft	cmp.w	#-1,d1				; Got new position ?
		bne.s	.NoNegLeft
		moveq	#0,d1				; Nope -> clear position
.NoNegLeft	tst.w	d1				; New position marked ?
		beq.s	.JumpedLeft			; Nope -> jump to first char
		move.w	d1,d0				; Copy new position
		moveq	#-1,d1				; Clear position
.LeftLoop2	tst.w	d0				; Already at first char ?
		blt.s	.JumpedLeft			; Yep -> position cursor
		cmp.b	#' ',0(a1,d0.w)			; Now skip chars different to space
		bne.s	.NoSpaceLeft
		move.w	d0,d1				; Store first pos of char after space
		addq.w	#1,d1
		bra.s	.JumpedLeft			; DONE
.NoSpaceLeft	subq.w	#1,d0				; Loop for chars
		bra	.LeftLoop2
.JumpedLeft	tst.w	d1				; Do we have a new position ?
		bge.s	.GotLeft			; Yep -> Repos
		clr.w	sgw_BufferPos(a2)		; Set cursor to first char
		bra.s	.LeftDone
.GotLeft	move.w	d1,sgw_BufferPos(a2)		; Set cursor to new position
.LeftDone	move.w	#EO_MOVECURSOR,sgw_EditOp(a2)
		bra	.End

.JumpRight	cmp.w	sgw_NumChars(a2),d0		; Already at end of string ?
		beq	.End				; Yep -> no movement
		moveq	#-1,d1
.RightLoop	cmp.w	sgw_NumChars(a2),d0		; All chars checked ?
		beq.s	.JumpedRight			; Yep -> end of movement
		cmp.b	#' ',0(a1,d0.w)			; Space encountered ?
		bne.s	.NoSpaceRight			; Nope -> go on
.RightSpaceLoop	cmp.w	sgw_NumChars(a2),d0		; All chars checked ?
		beq.s	.JumpedRight			; Yep -> end of movement
		cmp.b	#' ',0(a1,d0.w)			; Still a space ?
		beq.s	.NoRightChar			; Yep -> loop for spaces
		move.w	d0,d1				; Got new word
		bra.s	.JumpedRight			; -> Do movement
.NoRightChar	addq.w	#1,d0				; Next char (SPACE)
		bra	.RightSpaceLoop			; Loop for spaces
.NoSpaceRight	addq.w	#1,d0				; Loop for normal chars
		bra	.RightLoop
.JumpedRight	tst.w	d1				; Got new position ?
		bge.s	.GotRight			; Yep -> do so
		move.w	sgw_NumChars(a2),sgw_BufferPos(a2)
		bra.s	.RightDone
.GotRight	move.w	d1,sgw_BufferPos(a2)		; Store new position
.RightDone	move.w	#EO_MOVECURSOR,sgw_EditOp(a2)
		bra.s	.End

.NoWordJump	move.l	sgw_IEvent(a2),a3
		move.w	ie_Qualifier(a3),d0		; Right Amiga pressed ?
		and.w	#IEQUALIFIER_RCOMMAND,d0
		beq.s	.NoAmiga
		cmp.w	#96,ie_Code(a3)			; Char entered ?
		bge.s	.NoAmiga
		move.w	ie_Qualifier(a3),d0		; Any shift pressed ?
		and.w	#(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT),d0
		bne.s	.DoMenu
		cmp.w	#$32,ie_Code(a3)		; Magic X
		beq.s	.NoAmiga
		cmp.w	#$10,ie_Code(a3)		; or Q pressed ?
		beq.s	.NoAmiga
.DoMenu		move.l	sgw_Actions(a2),d0		; Ok -> Then use the menues
		or.l	#(SGA_END|SGA_REUSE),d0
		and.l	#~(SGA_USE|SGA_BEEP),d0
		move.l	d0,sgw_Actions(a2)
		move.l	sgw_GadgetInfo(a2),a0
		lea	ZeroPage,a4
		move.l	ggi_Window(a0),DoActWindow(a4)	; Tell menu owner to reactivate
		move.l	sgw_Gadget(a2),DoActGadget(a4)	; gadget
		bra.s	.End
.NoAmiga
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*              FKey-Command : Minimize a window`s size               *
**********************************************************************
MinimizeWin	movem.l	RegsAll,-(sp)
		bsr	FindWindow
		tst.l	d0
		beq.s	.End
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.End
		move.l	d0,a0				; Get window
		move.l	wd_Flags(a0),d0
		and.l	#WFLG_SIZEGADGET,d0
		beq.s	.End
		move.w	wd_LeftEdge(a0),d0
		move.w	wd_TopEdge(a0),d1
		neg.w	d0
		neg.w	d1
		move.w	wd_Width(a0),d2
		move.w	wd_Height(a0),d3
		sub.w	wd_MinWidth(a0),d2
		sub.w	wd_MinHeight(a0),d3
		neg.w	d2
		neg.w	d3
		RELLIB	ChangeWindowBox,_IntuitionBase
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*              FKey-Command : Maximize a window`s size               *
**********************************************************************
MaximizeWin	movem.l	RegsAll,-(sp)
		bsr	FindWindow
		tst.l	d0
		beq.s	.End
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.End
		move.l	d0,a0				; Get window
		move.l	wd_Flags(a0),d0
		and.l	#WFLG_SIZEGADGET,d0
		beq.s	.End
		move.w	wd_LeftEdge(a0),d0
		move.w	wd_TopEdge(a0),d1
		move.l	wd_WScreen(a0),a1
		move.w	sc_Width(a1),d2
		move.w	sc_Height(a1),d3
		neg.w	d0
		neg.w	d1
		RELLIB	ChangeWindowBox,_IntuitionBase
.End		movem.l	(sp)+,RegsAll
		rts



**********************************************************************
*                   FKey-Command : Zip a window                      *
**********************************************************************
ZipWin		movem.l	RegsAll,-(sp)
		bsr	FindWindow
		tst.l	d0
		beq.s	.End
		move.l	d0,a0
		move.l	lr_Window(a0),d0
		beq.s	.End
		move.l	d0,a0				; Get window
		move.l	wd_Flags(a0),d0
		and.l	#WFLG_HASZOOM,d0
		beq.s	.End
		RELLIB	ZipWindow,_IntuitionBase
.End		movem.l	(sp)+,RegsAll
		rts






PressKey	SETFRONTPEN 2
		dc.b	"Press any key to continue....",13
		SETFRONTPEN 1
PressKeyLen	EQU	*-PressKey
ClearStr	dc.b	$9B,$30,$20,$70
ClearStrLen	EQU	*-ClearStr
EndAnyStr	dc.b	$9B,$20,$70,$9b,$4b,$9B,"0;39;49m",0
EndAnyStrLen	EQU	*-EndAnyStr





**********************************************************************
*                             Variables                              *
**********************************************************************
CheckerName	dc.b	"KCOMM.CHECKER-PROCESS",0
		EVEN
RexxName	dc.b	"KCOMM.REXX-PROCESS",0
		EVEN
PrintProcName	dc.b	"KCOMM.PRINT-PROCESS",0
		EVEN
_SysBase	dc.l	0
_CxBase		dc.l	0
FalseStr	dc.b	"0",0
TrueStr		dc.b	"1",0
		EVEN




**********************************************************************
*       These are the names for external drives to be checked        *
**********************************************************************
DriveNames	dc.l	.Txt1,.Txt2,.Txt3,.Txt4
.Txt1		dc.b	"DF0:",0,0
.Txt2		dc.b	"DF1:",0,0
.Txt3		dc.b	"DF2:",0,0
.Txt4		dc.b	"DF3:",0,0



**********************************************************************
*     Structure definition for our messages send by InputHandler     *
**********************************************************************
		STRUCTURE InputMsg,MN_SIZE
			STRUCT	req_IEvent,ie_SIZEOF
		LABEL	req_SIZEOF



**********************************************************************
*              Structure for storing the mouse pointers              *
**********************************************************************
		STRUCTURE Pointer,0
			LONG	pt_Height
			LONG	pt_Width
			LONG	pt_XOff
			LONG	pt_YOff
			APTR	pt_Window
			APTR	pt_Pointer
		LABEL	pt_SIZEOF



**********************************************************************
*                     Structure for window names                     *
**********************************************************************
		STRUCTURE LockWin,LN_SIZE
			STRUCT	lw_Name,82
		LABEL	lw_SIZEOF




**********************************************************************
*                            Audio-Stuff                             *
**********************************************************************
LEFTCH0		EQU	2
RIGHTCH0	EQU	1
LEFTCH1		EQU	4
RIGHTCH1	EQU	8
AnyChannel	dc.b	LEFTCH0|RIGHTCH0
		dc.b	LEFTCH0|RIGHTCH1
		dc.b	LEFTCH1|RIGHTCH0
		dc.b	LEFTCH1|RIGHTCH1



**********************************************************************
*              ARexx-Status pointers and their numbers               *
**********************************************************************
RESULTBYTE	EQU	1
RESULTWORD	EQU	2
RESULTLONG	EQU	3
RESULTSTRING	EQU	4
RESULTCLOCKPOS	EQU	5
RESULTTIME	EQU	6
RESULTBILLPOS	EQU	8
ARexxStatus	dc.l	RESULTLONG,ToolPri+ZeroPage
		dc.l	RESULTLONG,CxPri+ZeroPage
		dc.l	RESULTSTRING,PopUpKey+ZeroPage
		dc.l	RESULTBYTE,DoPopUp+ZeroPage
		dc.l	RESULTBYTE,DoActivate+ZeroPage
		dc.l	RESULTBYTE,SunMouse+ZeroPage
		dc.l	RESULTBYTE,ShowClock+ZeroPage
		dc.l	RESULTBYTE,ClockWin+ZeroPage
		dc.l	RESULTCLOCKPOS,0		; This is for the ClockWinPos
		dc.l	RESULTBYTE,ShowDate+ZeroPage
		dc.l	RESULTBYTE,ShowDay+ZeroPage
		dc.l	RESULTBYTE,ShowSecs+ZeroPage
		dc.l	RESULTBYTE,AmiDate+ZeroPage
		dc.l	RESULTSTRING,PageHotKey+ZeroPage
		dc.l	RESULTLONG,PageNum+ZeroPage
		dc.l	RESULTBYTE,DoAlarm+ZeroPage
		dc.l	RESULTTIME,0			; This is for alarmtime
		dc.l	RESULTBYTE,Disabled+ZeroPage
		dc.l	RESULTBYTE,SetEnv+ZeroPage
		dc.l	RESULTBYTE,ShortDay+ZeroPage
		dc.l	RESULTLONG,ScreenTime+ZeroPage
		dc.l	RESULTLONG,MouseTime+ZeroPage
		dc.l	RESULTBYTE,CycleWin+ZeroPage
		dc.l	RESULTBYTE,KeyClick+ZeroPage
		dc.l	RESULTLONG,ClickVol+ZeroPage
		dc.l	RESULTBYTE,LogCalls+ZeroPage
		dc.l	RESULTBILLPOS,0			; BillWinPos
		dc.l	RESULTBYTE,BillPopUp+ZeroPage
		dc.l	RESULTBYTE,WBFront+ZeroPage
		dc.l	RESULTBYTE,LeftyMouse+ZeroPage
		dc.l	RESULTBYTE,ESCClose+ZeroPage
		dc.l	RESULTLONG,ESCQual+ZeroPage
		dc.l	RESULTBYTE,MapUmlaut+ZeroPage
		dc.l	RESULTBYTE,DispAppIcon+ZeroPage
		dc.l	RESULTBYTE,ExpWindows+ZeroPage
		dc.l	RESULTLONG,ExpFrames+ZeroPage
		dc.l	RESULTLONG,ImpFrames+ZeroPage
		dc.l	RESULTLONG,SizeFrames+ZeroPage
		dc.l	RESULTBYTE,ScreenDimm+ZeroPage
		dc.l	RESULTLONG,DimmValue+ZeroPage
		dc.l	RESULTLONG,HandlerPri+ZeroPage
		dc.l	RESULTBYTE,DispAppMenu+ZeroPage
		dc.l	RESULTBYTE,MouseAccel+ZeroPage
		dc.l	RESULTLONG,Accelerate+ZeroPage
		dc.l	RESULTLONG,ThresHold+ZeroPage
		dc.l	RESULTWORD,FormatDrive+ZeroPage
		dc.l	RESULTSTRING,DefLabel
		dc.l	RESULTBYTE,MakeIcons+ZeroPage
		dc.l	RESULTBYTE,QuickFormat+ZeroPage
		dc.l	RESULTBYTE,FFSDrive+ZeroPage
		dc.l	RESULTBYTE,NoVerify+ZeroPage
		dc.l	RESULTBYTE,Install+ZeroPage
		dc.l	RESULTBYTE,EjectDrive+ZeroPage
		dc.l	RESULTBYTE,WatchDisks+ZeroPage
		dc.l	RESULTBYTE,AutoCenter+ZeroPage
		dc.l	RESULTWORD,FrontCode+ZeroPage
		dc.l	RESULTWORD,FrontQual+ZeroPage
		dc.l	RESULTWORD,BackCode+ZeroPage
		dc.l	RESULTWORD,BackQual+ZeroPage
		dc.l	RESULTWORD,MiddleQual+ZeroPage
		dc.l	RESULTWORD,FrontClicks+ZeroPage
		dc.l	RESULTWORD,BackClicks+ZeroPage
		dc.l	RESULTWORD,MiddleClicks+ZeroPage
		dc.l	RESULTBYTE,MMBShift+ZeroPage
		dc.l	RESULTLONG,CheapStop+ZeroPage
		dc.l	RESULTLONG,CheapStart+ZeroPage
		dc.l	RESULTBYTE,Saturday+ZeroPage
		dc.l	RESULTBYTE,Sunday+ZeroPage
		dc.l	RESULTBYTE,Monday+ZeroPage
		dc.l	RESULTBYTE,Tuesday+ZeroPage
		dc.l	RESULTBYTE,Wednesday+ZeroPage
		dc.l	RESULTBYTE,Thursday+ZeroPage
		dc.l	RESULTBYTE,Friday+ZeroPage
StatusCount	EQU	(*-ARexxStatus)/8




**********************************************************************
*           Main format-definition for the Revision Header           *
**********************************************************************
CHeader		dc.b	"/* $Revision Header built automatically *************** (do not edit) ************",$0a
CLineNL		dc.b	"**",$0a,0
		EVEN
CLine		dc.b	"**     ",0,0
CCopyRight	dc.b	"** © Copyright by %s",$0a
		dc.b	"**",$0a,0
		EVEN
CFile		dc.b	"** File             : %s",$0a,0
		EVEN
CCreatedOn	dc.b	"** Created on       : %s, %s %s",$0a,0
		EVEN
CAuthor		dc.b	"** Created by       : %s",$0a,0
		EVEN
CRevision	dc.b	"** Current revision : V%d.%02.2d",$0a,0
		EVEN
CPurpose	dc.b	"**",$0a
		dc.b	"**",$0a
		dc.b	"** Purpose",$0a
		dc.b	"** -------",$0a,0
		EVEN
CLog		dc.b	"**",$0a
		dc.b	"** Revision V%d.%02.2d",$0a
		dc.b	"** --------------",$0a
		dc.b	"** changed on %s, %s %s  by  %s.   LogMessage :",$0a,0
		EVEN
CLogInit	dc.b	"**",$0a
		dc.b	"** Revision V%d.%02.2d",$0a
		dc.b	"** --------------",$0a
		dc.b	"**     --- Initial release ---",$0a
		dc.b	"**",$0a
CEnd		dc.b	"*********************************************************************************/",$0a,0
		EVEN


**********************************************************************
*                           Defines for C                            *
**********************************************************************
CRevDefine1	dc.b	'#define REVISION "%d.%02.2d"',$0a
		dc.b	'#define REVDATE  "%s"',$0a
		dc.b	'#define REVTIME  "%s"',$0a
		dc.b	'#define AUTHOR   "%s"',$0a
		dc.b	'#define VERNUM   %02.2d',$0a
		dc.b	'#define REVNUM   %02.2d',$0a,0
		EVEN


**********************************************************************
*                        Macros for Assembler                        *
**********************************************************************
AsmRevDefine1	dc.b	"REVISION  MACRO",$0a
		dc.b	'          dc.b "%d.%02.2d"',$0a
		dc.b	"          ENDM",$0a
		dc.b	"REVDATE   MACRO",$0a
		dc.b	'          dc.b "%s"',$0a
		dc.b	"          ENDM",$0a
		dc.b	"REVTIME   MACRO",$0a
		dc.b	'          dc.b "%s"',$0a
		dc.b	"          ENDM",$0a
		dc.b	"AUTHOR    MACRO",$0a
		dc.b	'          dc.b "%s"',$0a
		dc.b	"          ENDM",$0a
		dc.b	"VERNUM    EQU  %02.2d",$0a
		dc.b	"REVNUM    EQU  %02.2d",$0a,0
		EVEN


**********************************************************************
*                    Constants for Pascal/Modula                     *
**********************************************************************
PASRevDefine1	dc.b	"CONST {* Place all your constants beneith these ones *}",$0a
		dc.b	'        REVISION = "%d.%02.2d"',$0a
		dc.b	'         REVDATE = "%s"',$0a
		dc.b	'         REVTIME = "%s"',$0a
		dc.b	'          AUTHOR = "%s"',$0a
		dc.b	'          VERNUM = %02.2d',$0a
		dc.b	'          REVNUM = %02.2d',$0a,0
		EVEN



**********************************************************************
*                         Strings for Basic                          *
**********************************************************************
BASRevDefine1	dc.b	'REVISION$ = "%d.%02.2d"',$0a
		dc.b	'REVDATE$ = "%s"',$0a
		dc.b	'REVTIME$ = "%s"',$0a
		dc.b	'AUTHOR$ = "%s"',$0a
		dc.b	'VERNUM = %02.2d',$0a
		dc.b	'REVNUM = %02.2d',$0a,0
		EVEN



**********************************************************************
*                   Datablock for Revision Header                    *
**********************************************************************
RevDefine	dc.l	0
RevCompanyDat	dc.l	Company+ZeroPage
RevFileDat	dc.l	FileName+ZeroPage
RevRevisionDat	dc.w	0
		dc.w	0
RevCreatedOnDat	dc.l	RevDayString+ZeroPage
		dc.l	RevDateString+ZeroPage
		dc.l	RevTimeString+ZeroPage
RevAuthorDat	dc.l	Author+ZeroPage
RevDefineDat	dc.w	0
		dc.w	0
		dc.l	RevDateString+ZeroPage
		dc.l	RevTimeString+ZeroPage
		dc.l	Author+ZeroPage
RevVersionDat	dc.w	0
		dc.w	0
DefaultName	dc.b	"--- Unknown ---",0
		EVEN



**********************************************************************
*                 Names for the days to convert them                 *
**********************************************************************
DayNamesEng	dc.l	Day1,Day2,Day3,Day4,Day5,Day6,Day7
Day1		dc.b	"Saturday",0
		EVEN
Day2		dc.b	"Sunday",0
		EVEN
Day3		dc.b	"Monday",0
		EVEN
Day4		dc.b	"Tuesday",0
		EVEN
Day5		dc.b	"Wednesday",0
		EVEN
Day6		dc.b	"Thursday",0
		EVEN
Day7		dc.b	"Friday",0
		EVEN
DayNamesGer	dc.l	.Day1,.Day2,.Day3,.Day4,.Day5,.Day6,.Day7
.Day1		dc.b	"Samstag",0
		EVEN
.Day2		dc.b	"Sonntag",0
		EVEN
.Day3		dc.b	"Montag",0
		EVEN
.Day4		dc.b	"Dienstag",0
		EVEN
.Day5		dc.b	"Mittwoch",0
		EVEN
.Day6		dc.b	"Donnerstag",0
		EVEN
.Day7		dc.b	"Freitag",0
		EVEN


**********************************************************************
*                   Formats for displaying the day                   *
**********************************************************************
FormatData	dc.l	DayString+ZeroPage
		dc.l	DateString+ZeroPage
		dc.l	TimeString+ZeroPage
OnlineFormStr	dc.b	"Online ",0
		EVEN
EString		dc.b	"E",0
		EVEN
FString		dc.b	"F",0
		EVEN


**********************************************************************
*               The main structure of all...The Broker               *
**********************************************************************
		CNOP	0,4
MyBrokerDef	dc.b	NB_VERSION			; Commodities-Version (NEEDED)
		dc.b	0
		dc.l	BrokerName			; Name of broker (For Exchange-Prg)
		dc.l	BrokerTitle			; Title   (For Exchange-Prg)
		dc.l	BrokerDesc			; Broker-Description (For Exchange-Prg)
		dc.w	NBU_NOTIFY!NBU_UNIQUE		; Notify broker, we are unique
		dc.w	COF_SHOW_HIDE			; We can be hidden/shown
		dc.w	0				; Pri of broker plus an alignment byte
		dc.l	0				; Port-Pointer
		dc.w	0				; Dummy
BrokerName	dc.b	"KCommodity",0
		EVEN
BrokerTitle	dc.b	"KCommodity V"
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	")"
		dc.b	", Kai Iske",0
		EVEN
BrokerDesc	dc.b	"Multifunction commodity. SHAREWARE",0
		EVEN


**********************************************************************
*                         AutoRequester-Texts                        *
**********************************************************************
Only20ITxt	dc.b	0,1
		dc.b	RP_JAM1
		dc.b	0
		dc.w	10,10
		dc.l	0
		dc.l	Only20Txt
		dc.l	0
Only20Txt	dc.b	"KCommodity V"
		REVISION
		dc.b	" still only runs under OS 2.x !",$0a,0
Only20TxtEnd
		EVEN
OkITxt		dc.b	2,1
		dc.b	RP_JAM1
		dc.b	0
		dc.w	6,3
		dc.l	0
		dc.l	OkTxt
		dc.l	0
OkTxt		dc.b	"OK",0
		EVEN


**********************************************************************
*                            Error-Texts                             *
**********************************************************************
EasyTitle	dc.b	"KCommodity V"
		REVISION
EasyTitleEnd	dc.b	0
		EVEN
EasyTexts	dc.l	.Txt1,.Txt2,.Txt3,.Txt4,.Txt5,.Txt6,.Txt7,.Txt8
		dc.l	.Txt9,.Txt10,.Txt11,.Txt12,.Txt13,.Txt14,.Txt15,.Txt16
		dc.l	.Txt17,.Txt18,.Txt19,.Txt20,.Txt21,.Txt22,.Txt23,.Txt24
		dc.l	.Txt25,.Txt26,.Txt27,.Txt28,.Txt29,.Txt30

NO_ERR		EQU	-1
NOTFOUND_ERR	EQU	0
.Txt1		dc.b	"%s could not be opened.",0
		EVEN

BROKERPORT_ERR	EQU	1
.Txt2		dc.b	"Broker-Port could not be created.",0
		EVEN

BROKER_ERR	EQU	2
.Txt3		dc.b	"Broker could not be set up.",0
		EVEN

BROKERUP_ERR	EQU	3
.Txt4		dc.b	"Broker could not be set up correctly.",0
		EVEN

BITMAP_ERR	EQU	4
.Txt5		dc.b	"Sorry, could not generate BitMap.",0
		EVEN

RASTPORT_ERR	EQU	5
.Txt6		dc.b	"Sorry, could not generate RastPort.",0
		EVEN

BITPLANE_ERR	EQU	6
.Txt7		dc.b	"Could not allocate memory for BitPlanes.",0
		EVEN

FONT_ERR	EQU	7
.Txt8		dc.b	"Could not set appropriate font.",0
		EVEN

AREXXBUFF_ERR	EQU	8
.Txt9		dc.b	"Could not allocate memory for ARexx-Buffer.",0
		EVEN

AUDIOREQ_ERR	EQU	9
.Txt10		dc.b	"Could not allocate memory for Audio-Request.",0
		EVEN

CONSOLEREQ_ERR	EQU	10
.Txt11		dc.b	"Could not allocate memory for Console-Request.",0
		EVEN

AREXXPORT_ERR	EQU	11
.Txt12		dc.b	"Could not set up ARexx-Port.",0
		EVEN

MEMORY_ERR	EQU	12
.Txt13		dc.b	"Sorry, out of memory.",0
		EVEN

AUDIOPORT_ERR	EQU	13
.Txt14		dc.b	"Audio-Port could not be set up.",$0a
		EVEN

HOTKEY_ERR	EQU	14
.Txt15		dc.b	"Default HotKey",$0a,$0a
		dc.b	"%s",$0a,$0a
		dc.b	"could not be set up. Aborting",0
		EVEN

APPICON_ERR	EQU	15
.Txt16		dc.b	"Sorry,",$0a
		dc.b	"but the AppIcon could not be installed.",0
		EVEN

APPMENU_ERR	EQU	16
.Txt17		dc.b	"Sorry,",$0a
		dc.b	"but the AppMenu could not be installed.",0
		EVEN

PREFS_ERR	EQU	17
.Txt18		dc.b	"The Preferences-File you attempted to",$0a
		dc.b	"    load was not generated with",$0a
		dc.b	"          KCommodity V"
		REVISION
		dc.b	$0a,"    Unable to load preferences.",0
		EVEN

INPUTREQ_ERR	EQU	18
.Txt19		dc.b	"Sorry, memory for InputRequest",$0a
		dc.b	"could not be allocated.",0
		EVEN

INPUTPORT_ERR	EQU	19
.Txt20		dc.b	"Sorry, MessagePort for InputRequest",$0a
		dc.b	"could not be created.",0
		EVEN

HANDLER_ERR	EQU	20
.Txt21		dc.b	"Sorry, InputHandler could not be installed.",0
		EVEN

NOIFF_ERR	EQU	21
.Txt22		dc.b	"Could not allocate IFF-Handle",$0a
		dc.b	"for access to file.",0
		EVEN

USERHOTKEY_ERR	EQU	22
.Txt23		dc.b	"User HotKey",$0a,$0a
		dc.b	"%s",$0a,$0a
		dc.b	"could not be installed.",$0a,$0a
		dc.b	"Now using default : %s",0
		EVEN

CHECKDIM_ERR	EQU	23
.Txt24		dc.b	"Please check your inputs.",0
		EVEN

NOPRINT_ERR	EQU	24
.Txt25		dc.b	"Sorry, can not dump.",$0a
		dc.b	"Needed resources for printer.device",$0a
		dc.b	"could not be allocated.",0
		EVEN

NOTME_ERR	EQU	25
.Txt26		dc.b	"Sorry, but I can`t dump myself.",$0a
		dc.b	"Please select new source.",0
		EVEN


NOTITLE_ERR	EQU	26
.Txt27		dc.b	"Sorry, this window can not be identified",$0a
		dc.b	"by it`s title. I can`t handle something like that.",0
		EVEN

SIGNAL_ERR	EQU	27
.Txt28		dc.b	"Could not allocate User Task-Signal.",0
		EVEN


WINDOWPORT_ERR	EQU	28
.Txt29		dc.b	"Shared IDCMP-Port for windows could",$0a
		dc.b	"not be allocated.",0
		EVEN

TRACKPORT_ERR	EQU	29
.Txt30		dc.b	"Could not allocate Port for trackdisk.device.",0
		EVEN



**********************************************************************
*                      Error texts for IFFParse                      *
**********************************************************************
IFFErrors	dc.l	0,0,0,.Txt3,.Txt4,.Txt5,.Txt6,.Txt7,.Txt8,.Txt9
		dc.l	.Txt10
.Txt3		dc.b	"Did not get a valid scope for property",$0a
		dc.b	"on IFF file.",0
.Txt4		dc.b	"Memory allocation failed while",$0a
		dc.b	"loading IFF file.",0
.Txt5		dc.b	"Read error occured during examination",$0a
		dc.b	"of IFF file.",0
.Txt6		dc.b	"Write error while writing to IFF file.",0
.Txt7		dc.b	"Seek error within IFF file.",0
.Txt8		dc.b	"Data corrupt within IFF file.",0
.Txt9		dc.b	"IFF syntax in bad condition, could",$0a
		dc.b	"not load IFF file correctly.",0
.Txt10		dc.b	"The file %s ",$0a
		dc.b	"you attempted to load is not",$0a
		dc.b	"an IFF file.",0


**********************************************************************
*                      Error texts for printer                       *
**********************************************************************
PrinterErrors	dc.l	0,.Txt2,.Txt3,0,.Txt5,0,.Txt7,.Txt8
.Txt2		dc.b	"Dump canceled on user request.",0
		EVEN
.Txt3		dc.b	"Sorry, the selected printer ",$0a
		dc.b	"%s",$0a
		dc.b	"does not support Graphics dumps.",0
		EVEN
.Txt5		dc.b	"Bad dimensions specified for printout.",0
		EVEN
.Txt7		dc.b	"printer.device could not allocate",$0a
		dc.b	"internal variables.",0
		EVEN
.Txt8		dc.b	"printer.device could not allocate",$0a
		dc.b	"internal buffers",0
		EVEN


**********************************************************************
*                   Special define for Dos-Errors                    *
**********************************************************************
DosError	dc.b	"DOS-Error ",0
		EVEN



**********************************************************************
*                          About requester                           *
**********************************************************************
AboutText	dc.b	"KCommodity V"
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	"), by Kai Iske",$0a

		dc.b	"© 1992 Kai Iske, ShareWare DM 20.-, or an equal amount in a",$0a
		dc.b	"       foreign currency.",$0a,$0a

		dc.b	"User Interface done with the help of GadToolsBox V1.3",$0a,$0a

		dc.b	"To contact me write to :",$0a,$0a

		dc.b	"                     Kai Iske",$0a
		dc.b	"                Brucknerstrasse 18",$0a
		dc.b	"              6450 Hanau 1, Germany",$0a
		dc.b	"    Tel.: +49-(0)6181-850181 (After 6pm only)",$0a,$0a

		dc.b	"or use electronical mail :",$0a,$0a

		dc.b	"       FIDO:  2:249/40.11, Kai Iske",$0a
		dc.b	"       ZNET:  SNAKE%%HTH@AMNET.ZER",0
		EVEN
AboutGadgets	dc.b	"Ok|Print Registration form",0
		EVEN



**********************************************************************
*               Display Requester for unformatted disk               *
**********************************************************************
DoFormatText	dc.b	"You have inserted an unformatted disk",$0a
		dc.b	"in drive %s",$0a
		dc.b	"Would you like to format the disk ?",0
		EVEN
FormatGads	dc.b	"YES|NO",0
		EVEN



**********************************************************************
*                     Requester text for logfile                     *
**********************************************************************
FileWinTxt	dc.b	"Would you like to have the LogFile displayed",$0a
		dc.b	"in a window or should I dump it to a file ?",0
		EVEN
FileWinGads	dc.b	"File|Window",0
		EVEN
FileWinHead	dc.b	"Select output for LogFile",0
		EVEN



**********************************************************************
*                 Include the text for registration                  *
**********************************************************************
RegisterTxt	INCBIN	"Register.TXT"
		dc.b	0
REGISTERLEN	EQU	*-RegisterTxt
		EVEN


**********************************************************************
*                       Easy-Requeststructure                        *
**********************************************************************
MyEasyRequest	dc.l	es_SIZEOF
		dc.l	0
		dc.l	0
		dc.l	0
		dc.l	0
EasyGadget	dc.b	"OK",0
		EVEN


**********************************************************************
*                 Definition for the blanked screen                  *
**********************************************************************
BlankScreenDef	dc.w	0,0
		dc.w	64,-1
		dc.w	1
		dc.b	-1,-1
		dc.w	0
		dc.w	CUSTOMSCREEN|SCREENQUIET
		dc.l	0
		dc.l	0
		dc.l	0
		dc.l	0


**********************************************************************
*                 Some defines fo easy customization                 *
**********************************************************************
MAINWINIDCMP	EQU	BUTTONIDCMP!IDCMP_GADGETDOWN!IDCMP_MENUPICK!IDCMP_CLOSEWINDOW!IDCMP_RAWKEY!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
SETWINIDCMP	EQU	CHECKBOXIDCMP!IDCMP_CLOSEWINDOW!IDCMP_RAWKEY!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW!IDCMP_REFRESHWINDOW
MISCWINIDCMP	EQU	CHECKBOXIDCMP!SLIDERIDCMP!BUTTONIDCMP!TEXTIDCMP!STRINGIDCMP!IDCMP_CLOSEWINDOW!IDCMP_RAWKEY!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
ALARMWINIDCMP	EQU	CHECKBOXIDCMP!SLIDERIDCMP!CYCLEIDCMP!BUTTONIDCMP!TEXTIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
QUALWINIDCMP	EQU	TEXTIDCMP!BUTTONIDCMP!IDCMP_CLOSEWINDOW!IDCMP_REFRESHWINDOW!IDCMP_RAWKEY!IDCMP_MOUSEBUTTONS!IDCMP_CHANGEWINDOW
CYCLEWINIDCMP	EQU	CHECKBOXIDCMP!SLIDERIDCMP!BUTTONIDCMP!TEXTIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
BLANKWINIDCMP	EQU	CHECKBOXIDCMP!SLIDERIDCMP!CYCLEIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
COLSWINIDCMP	EQU	PALETTEIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
MOUSEWINIDCMP	EQU	CHECKBOXIDCMP!SLIDERIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
HOTKEYWINIDCMP	EQU	LISTVIEWIDCMP!STRINGIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
FKEYWINIDCMP	EQU	STRINGIDCMP!CYCLEIDCMP!CHECKBOXIDCMP!BUTTONIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW!IDCMP_ACTIVEWINDOW
FORMWINIDCMP	EQU	CYCLEIDCMP!STRINGIDCMP!CHECKBOXIDCMP!BUTTONIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW!IDCMP_ACTIVEWINDOW
PREFSWINIDCMP	EQU	INTEGERIDCMP!SLIDERIDCMP!CHECKBOXIDCMP!BUTTONIDCMP!STRINGIDCMP!TEXTIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
PROGWINWIDTH	EQU	309
CLOCKWINIDCMP	EQU	IDCMP_CHANGEWINDOW|IDCMP_CLOSEWINDOW
CLOCKWINFLAGS	EQU	WFLG_CLOSEGADGET|WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_RMBTRAP
LOCKWINIDCMP	EQU	BUTTONIDCMP!STRINGIDCMP!LISTVIEWIDCMP!BUTTONIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW


**********************************************************************
*                  Definitions for the main window                   *
**********************************************************************
MainWinWindowTags:
MainWinL:
    DC.L    WA_Left,0
MainWinT:
    DC.L    WA_Top,0
MainWinW:
    DC.L    WA_Width,0
MainWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_SMART_REFRESH!WFLG_ACTIVATE
MainWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,ControlTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
MainWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE




MainWinMenuDef:
    DC.B    NM_TITLE,0
    DC.L    MainWinDefMName0
    DC.L    0
    DC.W    0
    DC.L    0,0

    DC.B    NM_ITEM,0
    DC.L    MainWinDefMName1
    DC.L    MainWinDefMComm1
    DC.W    0
    DC.L    0,ReSavePrefs

    DC.B    NM_ITEM,0
    DC.L    NM_BARLABEL,0
    DC.W    0
    DC.L    0,0

    DC.B    NM_ITEM,0
    DC.L    MainWinDefMName3
    DC.L    MainWinDefMComm3
    DC.W    0
    DC.L    0,DisplayAbout

    DC.B    NM_END,0
    DC.L    0,0
    DC.W    0
    DC.L    0,0

MainWinDefMName0:
    DC.B    'Project',0
    CNOP    0,2
MainWinDefMName1:
    DC.B    'Save Preferences',0
    CNOP    0,2
MainWinDefMComm1:
    DC.B    'S',0
    CNOP    0,2
MainWinDefMName3:
    DC.B    'About',0
    CNOP    0,2
MainWinDefMComm3:
    DC.B    '?',0
    CNOP    0,2

SettingsText:
    DC.B    'Se_ttings...',0
    CNOP    0,2
MiscText:
    DC.B    '_Miscellaneous...',0
    CNOP    0,2
BlankingText:
    DC.B    '_Blanking...',0
    CNOP    0,2
CyclingText:
    DC.B    '_Cycling...',0
    CNOP    0,2
MouseText:
    DC.B    'Mo_use...',0
    CNOP    0,2
HotKeyText:
    DC.B    'Hot_Keys...',0
    CNOP    0,2
FKeyText:
    DC.B    '_Function Keys...',0
    CNOP    0,2
FormatText:
    DC.B    'Fo_rmatter...',0
    CNOP    0,2
BillWinText:
    DC.B    'B_ill window...',0
    CNOP    0,2
BillPrefsText:
    DC.B    'Bill _preferences...',0
    CNOP    0,2
LoadPrefsText:
    DC.B    'L_oad Prefs...',0
    CNOP    0,2
SavePrefsText:
    DC.B    'S_ave Prefs...',0
    CNOP    0,2
HideGadText:
    DC.B    '_Hide',0
    CNOP    0,2
EnableText:
    DC.B    '_Enable',0
    CNOP    0,2
DisableText:
    DC.B    '_Disable',0
    CNOP    0,2
QuitText:
    DC.B    '_Quit',0
    CNOP    0,2
AlarmText:
    DC.B    'A_larm modes...',0
    CNOP    0,2
ColorsText:
    DC.B    'Displa_y colors...',0
    CNOP    0,2
HardCopyText:
    DC.B    '_Graphics dump...',0
    CNOP    0,2
LockWinsText:
    DC.B    'Lock _windows...',0
    CNOP    0,2


GD_Settings                            EQU    0
GD_Misc                                EQU    1
GD_Blanking                            EQU    2
GD_Cycling                             EQU    3
GD_Mouse                               EQU    4
GD_HotKey                              EQU    5
GD_FKey                                EQU    6
GD_Format                              EQU    7
GD_BillWin                             EQU    8
GD_BillPrefs                           EQU    9
GD_LoadPrefs                           EQU    10
GD_SavePrefs                           EQU    11
GD_HideGad                             EQU    12
GD_Enable                              EQU    13
GD_Disable                             EQU    14
GD_Quit                                EQU    15
GD_Alarm                               EQU    16
GD_Colors                              EQU    17
GD_HardCopy                            EQU    18
GD_LockWins                            EQU    19

KD_Settings	EQU	'T'
KD_Misc		EQU	'M'
KD_Blanking	EQU	'B'
KD_Cycling	EQU	'C'
KD_Mouse	EQU	'U'
KD_HotKey	EQU	'K'
KD_FKey		EQU	'F'
KD_Format	EQU	'R'
KD_Bill		EQU	'I'
KD_BillPrefs	EQU	'P'
KD_LoadPrefs	EQU	'O'
KD_SavePrefs	EQU	'A'
KD_Enable	EQU	'E'
KD_Disable	EQU	'D'
KD_HideGad	EQU	'H'
KD_Quit		EQU	'Q'
KD_Alarm	EQU	'L'
KD_Colors	EQU	'Y'
KD_HardCopy	EQU	'G'
KD_LockWins	EQU	'W'



**********************************************************************
*                    Defines for settings window                     *
**********************************************************************
SetWinWindowTags:
SetWinL:
    DC.L    WA_Left,0
SetWinT:
    DC.L    WA_Top,0
SetWinW:
    DC.L    WA_Width,0
SetWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
SetWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,SetTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
SetWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

DisplayText:
    DC.B    '_Display clock/mem',0
    CNOP    0,2
DisplayWinText:
    DC.B    'Display in _window',0
    CNOP    0,2
ShowTimeText:
    DC.B    'Show _time',0
    CNOP    0,2
ShowDateText:
    DC.B    'Sh_ow date',0
    CNOP    0,2
AmiDateText:
    DC.B    '_American date',0
    CNOP    0,2
ShowDayText:
    DC.B    'Show da_y',0
    CNOP    0,2
ShowSecsText:
    DC.B    'Show _seconds',0
    CNOP    0,2
ShortDayText:
    DC.B    'S_hort day string',0
    CNOP    0,2
WriteEnvText:
    DC.B    'W_rite environment',0
    CNOP    0,2
WBFrontText:
    DC.B    'WB to _front',0
    CNOP    0,2
LeftyText:
    DC.B    '_LeftyMouse',0
    CNOP    0,2
MapUmlautsText:
    DC.B    '_Map "Umlauts"',0
    CNOP    0,2
AppIconText:
    DC.B    'A_ppIcon',0
    CNOP    0,2
AutoCtrText:
    DC.B    'Auto _center',0
    CNOP    0,2
MMBShiftText:
    DC.B    'MM_B-Shift',0
    CNOP    0,2
GermanDaysText:
    DC.B    'G_erman day',0
    CNOP    0,2
PDateText:
    DC.B    'Date with "_."',0
    CNOP    0,2
NoClickText:
    DC.B    'Drive _NoClick',0
    CNOP    0,2
ShowMouseText:
    DC.B    'Show Mouse _X/Y',0
    CNOP    0,2


GD_Display                             EQU    0
GD_DisplayWin                          EQU    1
GD_ShowTime                            EQU    2
GD_ShowDate                            EQU    3
GD_AmiDate                             EQU    4
GD_ShowDay                             EQU    5
GD_ShowSecs                            EQU    6
GD_ShortDay                            EQU    7
GD_WriteEnv                            EQU    8
GD_WBFront                             EQU    9
GD_Lefty                               EQU    10
GD_MapUmlauts                          EQU    11
GD_AppIcon                             EQU    12
GD_AutoCtr                             EQU    13
GD_MMBShift                            EQU    14
GD_GermanDays                          EQU    15
GD_PDate                               EQU    16
GD_NoClick                             EQU    17
GD_ShowMouse                           EQU    18

KD_Display	EQU	'D'
KD_DisplayWin	EQU	'W'
KD_ShowTime	EQU	'T'
KD_ShowDate	EQU	'O'
KD_AmiDate	EQU	'A'
KD_ShowDay	EQU	'Y'
KD_ShowSecs	EQU	'S'
KD_ShortDay	EQU	'H'
KD_WriteEnv	EQU	'R'
KD_WBFront	EQU	'F'
KD_Lefty	EQU	'L'
KD_MapUmlauts	EQU	'M'
KD_AppIcon	EQU	'P'
KD_AutoCtr	EQU	'C'
KD_MMBShift	EQU	'B'
KD_GermanDays	EQU	'E'
KD_PDate	EQU	'.'
KD_NoClick	EQU	'N'
KD_ShowMouse	EQU	'X'



**********************************************************************
*                      Defines for Misc-window                       *
**********************************************************************
MiscWinWindowTags:
MiscWinL:
    DC.L    WA_Left,0
MiscWinT:
    DC.L    WA_Top,0
MiscWinW:
    DC.L    WA_Width,0
MiscWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
MiscWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,MiscTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
MiscWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE
ESCCloseText:
    DC.B    '_ESC Window Close',0
    CNOP    0,2
ESCQualText:
    DC.B    'ESC _Qualifier...',0
    CNOP    0,2
KeyClickText:
    DC.B    '_Key-Click',0
    CNOP    0,2
ClickVolText:
    DC.B    'Click _volume       ',0
    CNOP    0,2
UserShellText:
    DC.B    '_User-Shell command',0
    CNOP    0,2
ExpWindowsText:
    DC.B    'Exploding _windows',0
    CNOP    0,2
MouseCtrText:
    DC.B    'From/To _mouse',0
    CNOP    0,2
ExpFramesText:
    DC.B    'E_xplode frames   ',0
    CNOP    0,2
ImpFramesText:
    DC.B    '_Implode frames   ',0
    CNOP    0,2
SizeFramesText:
    DC.B    '_Size/Move frames   ',0
    CNOP    0,2
FullDragText:
    DC.B    '_Full drag',0
    CNOP    0,2
DragQualText:
    DC.B    '_Dragging qualifier...',0
    CNOP    0,2


ClickVolTags:
    DC.L    GTSL_Min,1
    DC.L    GTSL_Max,64
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

UserShellTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_String,SystemComm+ZeroPage
    DC.L    GTST_MaxChars,256
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

ExpFramesTags:
    DC.L    GTSL_Min,10
    DC.L    GTSL_Max,64
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE


GD_ESCClose                            EQU    0
GD_ESCQual                             EQU    1
GD_ESCQualTxt                          EQU    2
GD_KeyClick                            EQU    3
GD_ClickVol                            EQU    4
GD_UserShell                           EQU    5
GD_ExpWindows                          EQU    6
GD_MouseCtr                            EQU    7
GD_ExpFrames                           EQU    8
GD_ImpFrames                           EQU    9
GD_SizeFrames                          EQU    10
GD_FullDrag                            EQU    11
GD_DragQual                            EQU    12
GD_DragQualTxt                         EQU    13

KD_ESCClose	EQU	'E'
KD_ESCQual	EQU	'Q'
KD_KeyClick	EQU	'K'
KD_ClickVol	EQU	'V'
KD_UserShell	EQU	'U'
KD_ExpWindows	EQU	'W'
KD_MouseCtr	EQU	'M'
KD_ExpFrames	EQU	'X'
KD_ImpFrames	EQU	'I'
KD_SizeFrames	EQU	'S'
KD_FullDrag	EQU	'F'
KD_DragQual	EQU	'D'





**********************************************************************
*                  Settings for alarm modes window                   *
**********************************************************************
AlarmWinWindowTags:
AlarmWinL:
    DC.L    WA_Left,0
AlarmWinT:
    DC.L    WA_Top,0
AlarmWinW:
    DC.L    WA_Width,0
AlarmWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
AlarmWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,AlarmTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
AlarmWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


AlarmOnText:
    DC.B    '_Alarm on',0
    CNOP    0,2
AllHoursText:
    DC.B    '_Every hour',0
    CNOP    0,2
ShowAlarmText:
    DC.B    'Show _requester',0
    CNOP    0,2
AlarmTimeText:
    DC.B    'Alarm _time         ',0
    CNOP    0,2
AlSoundTypeText:
    DC.B    '_Sound type',0
    CNOP    0,2
AlarmSampleText:
    DC.B    'Select sa_mple',0
    CNOP    0,2
SampleNameText:
    DC.B    'Sample name',0
    CNOP    0,2

AlarmTimeTags:
    DC.L    GTSL_Max,1439
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,StringFormat
    DC.L    GTSL_DispFunc,ShowAlarm
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
AlSoundTypeTags:
    DC.L    GTCY_Labels,AlSoundTypeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
AlSoundTypeLabels:
    DC.L    AlSoundTypeLab0
    DC.L    AlSoundTypeLab1
    DC.L    0
AlSoundTypeLab0:    DC.B    'DisplayBeep()',0
    CNOP    0,2
AlSoundTypeLab1:    DC.B    'IFF Sample',0
    CNOP    0,2

GD_AlarmOn                             EQU    0
GD_AllHours                            EQU    1
GD_ShowAlarm                           EQU    2
GD_AlarmTime                           EQU    3
GD_AlSoundType                         EQU    4
GD_AlarmSample                         EQU    5
GD_SampleName                          EQU    6

KD_AlarmOn	EQU	'A'
KD_AllHours	EQU	'E'
KD_ShowAlarm	EQU	'R'
KD_AlarmTime	EQU	'T'
KD_AlSoundType	EQU	'S'
KD_AlarmSample	EQU	'M'




**********************************************************************
*                   Settings for qualifier window                    *
**********************************************************************
QualWinWindowTags:
QualWinL:
    DC.L    WA_Left,0
QualWinT:
    DC.L    WA_Top,0
QualWinW:
    DC.L    WA_Width,0
QualWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE!WFLG_RMBTRAP
QualWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,QualTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
QualWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


OkText:
    DC.B    'Ok',0
    CNOP    0,2
CancelText:
    DC.B    'Cancel',0
    CNOP    0,2



GD_QualTxt                             EQU    0
GD_Ok                                  EQU    1
GD_Cancel                              EQU    2




**********************************************************************
*                     Settings for cycle window                      *
**********************************************************************
CycleWinWindowTags:
CycleWinL:
    DC.L    WA_Left,0
CycleWinT:
    DC.L    WA_Top,0
CycleWinW:
    DC.L    WA_Width,0
CycleWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
CycleWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,CycleTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
CycleWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

FrontClickTags:
    DC.L    GTSL_Min,1
    DC.L    GTSL_Max,5
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,LIntFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

CycleOnText:
    DC.B    '_Cycling enabled',0
    CNOP    0,2
FrontClickText:
    DC.B    '_Front clicks',0
    CNOP    0,2
MiddleClickText:
    DC.B    '_Middle clicks',0
    CNOP    0,2
BackClickText:
    DC.B    '_Back clicks',0
    CNOP    0,2
FrontKeyText:
    DC.B    'F_ront Key',0
    CNOP    0,2
MiddleKeyText:
    DC.B    'M_iddle Key',0
    CNOP    0,2
BackKeyText:
    DC.B    'B_ack Key',0
    CNOP    0,2


GD_CycleOn                             EQU    0
GD_FrontClick                          EQU    1
GD_MiddleClick                         EQU    2
GD_BackClick                           EQU    3
GD_FrontKey                            EQU    4
GD_MiddleKey                           EQU    5
GD_BackKey                             EQU    6
GD_FrontQual                           EQU    7
GD_MiddleQual                          EQU    8
GD_BackQual                            EQU    9

KD_CycleOn	EQU	'C'
KD_FrontClick	EQU	'F'
KD_MiddleClick	EQU	'M'
KD_BackClick	EQU	'B'
KD_FrontKey	EQU	'R'
KD_MiddleKey	EQU	'I'
KD_BackKey	EQU	'A'





**********************************************************************
*                    Settings for Blanking window                    *
**********************************************************************
BlankWinWindowTags:
BlankWinL:
    DC.L    WA_Left,0
BlankWinT:
    DC.L    WA_Top,0
BlankWinW:
    DC.L    WA_Width,0
BlankWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
BlankWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,BlankTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
BlankWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


BlankTypeTags:
    DC.L    GTCY_Labels,BlankTypeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
BlankTypeLabels:
    DC.L    BlankTypeLab0
    DC.L    BlankTypeLab1
    DC.L    0
BlankTypeLab0:    DC.B    'Blanker',0
    CNOP    0,2
BlankTypeLab1:    DC.B    'Dimmer',0
    CNOP    0,2

ScrTimeTags:
    DC.L    GTSL_Max,1800
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,StringFormat
    DC.L    GTSL_DispFunc,ShowAlarm
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
DimmFacTags:
    DC.L    GTSL_Min,1
    DC.L    GTSL_Max,48
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE


BlankMouseText:
    DC.B    '_Blank mouse on keystroke',0
    CNOP    0,2
ScrTimeText:
    DC.B    '_Screen time         ',0
    CNOP    0,2
MouseTimeText:
    DC.B    '_Mouse time         ',0
    CNOP    0,2
BlankTypeText:
    DC.B    'Blanker _type',0
    CNOP    0,2
DimmFacText:
    DC.B    '_Dimm factor      ',0
    CNOP    0,2


GD_BlankMouse                          EQU    0
GD_ScrTime                             EQU    1
GD_MouseTime                           EQU    2
GD_BlankType                           EQU    3
GD_DimmFac                             EQU    4

KD_BlankMouse	EQU	'B'
KD_ScrTime	EQU	'S'
KD_MouseTime	EQU	'M'
KD_BlankType	EQU	'T'
KD_DimmFac	EQU	'D'



**********************************************************************
*                     Settings for colors window                     *
**********************************************************************
ColsWinWindowTags:
ColsWinL:
    DC.L    WA_Left,0
ColsWinT:
    DC.L    WA_Top,0
ColsWinW:
    DC.L    WA_Width,0
ColsWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
ColsWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,ColsTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
ColsWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


TFrontPenTags:
    DC.L    GTPA_Color,0
ScrDepth    DC.L    GTPA_Depth,2
    DC.L    GTPA_IndicatorWidth,30
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

TFrontPenText:
    DC.B    'Text _front pen',0
    CNOP    0,2
TBackPenText:
    DC.B    'Text _back pen',0
    CNOP    0,2
GFrontPenText:
    DC.B    'Gauge f_ront pen',0
    CNOP    0,2
GBackPenText:
    DC.B    'Gauge b_ack pen',0
    CNOP    0,2


GD_TFrontPen                           EQU    0
GD_TBackPen                            EQU    1
GD_GFrontPen                           EQU    2
GD_GBackPen                            EQU    3

KD_TFrontPen	EQU	'F'
KD_TBackPen	EQU	'B'
KD_GFrontPen	EQU	'R'
KD_GBackPen	EQU	'A'




**********************************************************************
*                     Settings for Mouse window                      *
**********************************************************************
MouseWinWindowTags:
MouseWinL:
    DC.L    WA_Left,0
MouseWinT:
    DC.L    WA_Top,0
MouseWinW:
    DC.L    WA_Width,0
MouseWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
MouseWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,MouseTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
MouseWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

AccelerateTags:
    DC.L    GTSL_Min,2
    DC.L    GTSL_Max,10
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

ThresholdTags:
    DC.L    GTSL_Max,10
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

WindowActText:
    DC.B    '_Window activation',0
    CNOP    0,2
SunMouseText:
    DC.B    '_Sun mouse',0
    CNOP    0,2
MouseAccelText:
    DC.B    '_Mouse accelerate',0
    CNOP    0,2
AccelerateText:
    DC.B    '_Acceleration      ',0
    CNOP    0,2
ThresholdText:
    DC.B    '_Threshold      ',0
    CNOP    0,2
HoldXQualText:
    DC.B    'Hold _X qualifier',0
    CNOP    0,2
HoldYQualText:
    DC.B    'Hold _Y qualifier',0
    CNOP    0,2

GD_WindowAct                           EQU    0
GD_SunMouse                            EQU    1
GD_MouseAccel                          EQU    2
GD_Accelerate                          EQU    3
GD_Threshold                           EQU    4
GD_HoldX                               EQU    5
GD_HoldY                               EQU    6
GD_HoldXQual                           EQU    7
GD_HoldYQual                           EQU    8

KD_WindowAct	EQU	'W'
KD_SunMouse	EQU	'S'
KD_MouseAccel	EQU	'M'
KD_Accelerate	EQU	'A'
KD_Threshold	EQU	'T'
KD_HoldXQual	EQU	'X'
KD_HoldYQual	EQU	'Y'



**********************************************************************
*                    Settings for HotKeys window                     *
**********************************************************************
HotKeyWinWindowTags:
HotKeyWinL:
    DC.L    WA_Left,0
HotKeyWinT:
    DC.L    WA_Top,0
HotKeyWinW:
    DC.L    WA_Width,0
HotKeyWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
HotKeyWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,HotKeyTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
HotKeyWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

HotKeyListTags:
    DC.L    GT_Underscore,'_'
    DC.L    GTLV_Labels,HotKeyListList
    DC.L    GTLV_ShowSelected,0
    DC.L    TAG_DONE
HotKeyDefTags:
    DC.L    GT_Underscore,'_'
    DC.L    GA_Disabled,1
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_MaxChars,256
    DC.L    TAG_DONE



HotKeyListList:
    DC.L    HotKeyListNodes0,0,HotKeyListNodes20
HotKeyListNodes0:
    DC.L    HotKeyListNodes1
    DC.L    HotKeyListList
    DC.B    0,0
    DC.L    HotKeyListName0
HotKeyListName0:
    DC.B    'CX_PopKey',0
    CNOP    0,2
HotKeyListNodes1:
    DC.L    HotKeyListNodes2
    DC.L    HotKeyListNodes0
    DC.B    0,0
    DC.L    HotKeyListName1
HotKeyListName1:
    DC.B    'Settings',0
    CNOP    0,2
HotKeyListNodes2:
    DC.L    HotKeyListNodes3
    DC.L    HotKeyListNodes1
    DC.B    0,0
    DC.L    HotKeyListName2
HotKeyListName2:
    DC.B    'Blanking',0
    CNOP    0,2
HotKeyListNodes3:
    DC.L    HotKeyListNodes4
    DC.L    HotKeyListNodes2
    DC.B    0,0
    DC.L    HotKeyListName3
HotKeyListName3:
    DC.B    'Mouse',0
    CNOP    0,2
HotKeyListNodes4:
    DC.L    HotKeyListNodes5
    DC.L    HotKeyListNodes3
    DC.B    0,0
    DC.L    HotKeyListName4
HotKeyListName4:
    DC.B    'Function Keys',0
    CNOP    0,2
HotKeyListNodes5:
    DC.L    HotKeyListNodes6
    DC.L    HotKeyListNodes4
    DC.B    0,0
    DC.L    HotKeyListName5
HotKeyListName5:
    DC.B    'Bill',0
    CNOP    0,2
HotKeyListNodes6:
    DC.L    HotKeyListNodes7
    DC.L    HotKeyListNodes5
    DC.B    0,0
    DC.L    HotKeyListName6
HotKeyListName6:
    DC.B    'Miscellaneous',0
    CNOP    0,2
HotKeyListNodes7:
    DC.L    HotKeyListNodes8
    DC.L    HotKeyListNodes6
    DC.B    0,0
    DC.L    HotKeyListName7
HotKeyListName7:
    DC.B    'Cycling',0
    CNOP    0,2
HotKeyListNodes8:
    DC.L    HotKeyListNodes9
    DC.L    HotKeyListNodes7
    DC.B    0,0
    DC.L    HotKeyListName8
HotKeyListName8:
    DC.B    'HotKeys',0
    CNOP    0,2
HotKeyListNodes9:
    DC.L    HotKeyListNodes10
    DC.L    HotKeyListNodes8
    DC.B    0,0
    DC.L    HotKeyListName9
HotKeyListName9:
    DC.B    'Formatter',0
    CNOP    0,2
HotKeyListNodes10:
    DC.L    HotKeyListNodes11
    DC.L    HotKeyListNodes9
    DC.B    0,0
    DC.L    HotKeyListName10
HotKeyListName10:
    DC.B    'Bill Preferences',0
    CNOP    0,2
HotKeyListNodes11:
    DC.L    HotKeyListNodes12
    DC.L    HotKeyListNodes10
    DC.B    0,0
    DC.L    HotKeyListName11
HotKeyListName11:
    DC.B    'Alarm modes',0
    CNOP    0,2
HotKeyListNodes12:
    DC.L    HotKeyListNodes13
    DC.L    HotKeyListNodes11
    DC.B    0,0
    DC.L    HotKeyListName12
HotKeyListName12:
    DC.B    'Display colors',0
    CNOP    0,2
HotKeyListNodes13:
    DC.L    HotKeyListNodes14
    DC.L    HotKeyListNodes12
    DC.B    0,0
    DC.L    HotKeyListName13
HotKeyListName13:
    DC.B    'Page',0
    CNOP    0,2
HotKeyListNodes14:
    DC.L    HotKeyListNodes15
    DC.L    HotKeyListNodes13
    DC.B    0,0
    DC.L    HotKeyListName14
HotKeyListName14:
    DC.B    'UserShell',0
    CNOP    0,2
HotKeyListNodes15:
    DC.L    HotKeyListNodes16
    DC.L    HotKeyListNodes14
    DC.B    0,0
    DC.L    HotKeyListName15
HotKeyListName15:
    DC.B    'Map "Umlauts"',0
    CNOP    0,2
HotKeyListNodes16:
    DC.L    HotKeyListNodes17
    DC.L    HotKeyListNodes15
    DC.B    0,0
    DC.L    HotKeyListName16
HotKeyListName16:
    DC.B    'Snap memory',0
    CNOP    0,2
HotKeyListNodes17:
    DC.L    HotKeyListNodes18
    DC.L    HotKeyListNodes16
    DC.B    0,0
    DC.L    HotKeyListName17
HotKeyListName17:
    DC.B    'Immediate blank',0
    CNOP    0,2
HotKeyListNodes18:
    DC.L    HotKeyListNodes19
    DC.L    HotKeyListNodes17
    DC.B    0,0
    DC.L    HotKeyListName18
HotKeyListName18:
    DC.B    'Display dump',0
    CNOP    0,2
HotKeyListNodes19:
    DC.L    HotKeyListNodes20
    DC.L    HotKeyListNodes18
    DC.B    0,0
    DC.L    HotKeyListName19
HotKeyListName19:
    DC.B    'Lock windows',0
    CNOP    0,2
HotKeyListNodes20:
    DC.L    HotKeyListList+4
    DC.L    HotKeyListNodes19
    DC.B    0,0
    DC.L    HotKeyListName20
HotKeyListName20:
    DC.B    'Center Screen',0
    CNOP    0,2

HotKeyListText:
    DC.B    '_HotKeys',0
    CNOP    0,2
HotKeyDefText:
    DC.B    '_Def:',0
    CNOP    0,2

GD_HotKeyList                          EQU    0
GD_HotKeyDef                           EQU    1

KD_HotKeyList	EQU	'H'
KD_HotKeyDef	EQU	'D'





**********************************************************************
*                       FKeys window settings                        *
**********************************************************************
FKeyWinWindowTags:
FKeyWinL:
    DC.L    WA_Left,0
FKeyWinT:
    DC.L    WA_Top,0
FKeyWinW:
    DC.L    WA_Width,0
FKeyWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
FKeyWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,FKeyTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
FKeyWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


F1Tags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_MaxChars,256
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

FKeyQualTags:
    DC.L    GTCY_Labels,FKeyQualLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
FKeyQualLabels:
    DC.L    FKeyQualLab0
    DC.L    FKeyQualLab1
    DC.L    FKeyQualLab2
    DC.L    FKeyQualLab3
    DC.L    0
FKeyQualLab0:    DC.B    'None',0
    CNOP    0,2
FKeyQualLab1:    DC.B    'Shift',0
    CNOP    0,2
FKeyQualLab2:    DC.B    'Alt',0
    CNOP    0,2
FKeyQualLab3:    DC.B    'Control',0
    CNOP    0,2


F1Text:
    DC.B    'F_1',0
    CNOP    0,2
F2Text:
    DC.B    'F_2',0
    CNOP    0,2
F3Text:
    DC.B    'F_3',0
    CNOP    0,2
F4Text:
    DC.B    'F_4',0
    CNOP    0,2
F5Text:
    DC.B    'F_5',0
    CNOP    0,2
F6Text:
    DC.B    'F_6',0
    CNOP    0,2
F7Text:
    DC.B    'F_7',0
    CNOP    0,2
F8Text:
    DC.B    'F_8',0
    CNOP    0,2
F9Text:
    DC.B    'F_9',0
    CNOP    0,2
F10Text:
    DC.B    'F1_0',0
    CNOP    0,2
FKeyQualText:
    DC.B    '_Qualifier',0
    CNOP    0,2
FKeyActText:
    DC.B    '_Active',0
    CNOP    0,2
FKeyOkText:
    DC.B    '_Ok',0
    CNOP    0,2
FKeyCancelText:
    DC.B    '_Cancel',0
    CNOP    0,2

FKeyQualFlags	dc.w	0,0
		dc.w	IEQUALIFIER_LSHIFT,IEQUALIFIER_RSHIFT
		dc.w	IEQUALIFIER_LALT,IEQUALIFIER_RALT
		dc.w	IEQUALIFIER_CONTROL,-1


GD_F1                                  EQU    0
GD_F2                                  EQU    1
GD_F3                                  EQU    2
GD_F4                                  EQU    3
GD_F5                                  EQU    4
GD_F6                                  EQU    5
GD_F7                                  EQU    6
GD_F8                                  EQU    7
GD_F9                                  EQU    8
GD_F10                                 EQU    9
GD_FKeyQual                            EQU    10
GD_FKeyAct                             EQU    11
GD_FKeyOk                              EQU    12
GD_FKeyCancel                          EQU    13

KD_F1		EQU	'1'
KD_F2		EQU	'2'
KD_F3		EQU	'3'
KD_F4		EQU	'4'
KD_F5		EQU	'5'
KD_F6		EQU	'6'
KD_F7		EQU	'7'
KD_F8		EQU	'8'
KD_F9		EQU	'9'
KD_F10		EQU	'0'
KD_FKeyQual	EQU	'Q'
KD_FKeyAct	EQU	'A'
KD_FKeyOk	EQU	'O'
KD_FKeyCancel	EQU	'C'




**********************************************************************
*                   Settings for Formatter window                    *
**********************************************************************
FormWinWindowTags:
FormWinL:
    DC.L    WA_Left,0
FormWinT:
    DC.L    WA_Top,0
FormWinW:
    DC.L    WA_Width,0
FormWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
FormWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,FormTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
FormWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

DriveTags:
    DC.L    GTCY_Labels,DriveList+ZeroPage
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
LabelTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_MaxChars,256
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
DriveText:
    DC.B    '_Drive',0
    CNOP    0,2
LabelText:
    DC.B    '_Label',0
    CNOP    0,2
TrashcanText:
    DC.B    '_Trashcan',0
    CNOP    0,2
QuickText:
    DC.B    '_Quick',0
    CNOP    0,2
FFSText:
    DC.B    '_FFS',0
    CNOP    0,2
NoVerifyText:
    DC.B    'No _Verify',0
    CNOP    0,2
InstallText:
    DC.B    '_Install',0
    CNOP    0,2
EjectText:
    DC.B    '_Eject',0
    CNOP    0,2
FormOkText:
    DC.B    '_Ok',0
    CNOP    0,2
FormCancelText:
    DC.B    '_Cancel',0
    CNOP    0,2
WatchDisksText:
    DC.B    '_Watch disks',0
    CNOP    0,2



GD_Drive                               EQU    0
GD_Label                               EQU    1
GD_Trashcan                            EQU    2
GD_Quick                               EQU    3
GD_FFS                                 EQU    4
GD_NoVerify                            EQU    5
GD_Install                             EQU    6
GD_Eject                               EQU    7
GD_FormOk                              EQU    8
GD_FormCancel                          EQU    9
GD_WatchDisks                          EQU    10

KD_Drive	EQU	'D'
KD_Label	EQU	'L'
KD_Trashcan	EQU	'T'
KD_Quick	EQU	'Q'
KD_FFS		EQU	'F'
KD_NoVerify	EQU	'V'
KD_Install	EQU	'I'
KD_Eject	EQU	'E'
KD_FormOk	EQU	'O'
KD_FormCancel	EQU	'C'
KD_WatchDisks	EQU	'W'




**********************************************************************
*                      Settings for bill window                      *
**********************************************************************

BillWinWindowTags:
BillWinL:
    DC.L    WA_Left,0
BillWinT:
    DC.L    WA_Top,0
BillWinW:
    DC.L    WA_Width,0
BillWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,TEXTIDCMP!MXIDCMP!CHECKBOXIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH
BillWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,BillTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
BillWinSC:
    DC.L    WA_PubScreen,0
    DC.L    WA_Zoom,BillZoomSize
    DC.L    TAG_DONE

BillZoomSize	dc.w	640-236,11,0,0

BillTimeMXTags:
    DC.L    GTMX_Labels,BillTimeMXLabels
    DC.L    GTMX_Spacing,2
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
BillCheapTags:
    DC.L    GTMX_Labels,BillCheapLabels
    DC.L    GTMX_Spacing,2
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
BillTimeMXLabels:
    DC.L    BillTimeMXLab0
    DC.L    BillTimeMXLab1
    DC.L    BillTimeMXLab2
    DC.L    0
BillTimeMXLab0:    DC.B    'Time _1',0
    CNOP    0,2
BillTimeMXLab1:    DC.B    'Time _2',0
    CNOP    0,2
BillTimeMXLab2:    DC.B    'Time _3',0
    CNOP    0,2
BillCheapLabels:
    DC.L    BillCheapLab0
    DC.L    BillCheapLab1
    DC.L    0
BillCheapLab0:    DC.B    '_Normal',0
    CNOP    0,2
BillCheapLab1:    DC.B    '_Cheap',0
    CNOP    0,2
BillTimeText:
    DC.B    'Time',0
    CNOP    0,2
BillOnlineText:
    DC.B    'Online',0
    CNOP    0,2
BillCostText:
    DC.B    'Cost',0
    CNOP    0,2
LogCallText:
    DC.B    '_Log call',0
    CNOP    0,2


GD_BillTime                            EQU    0
GD_BillOnline                          EQU    1
GD_BillCost                            EQU    2
GD_BillTimeMX                          EQU    3
GD_BillCheap                           EQU    4
GD_BillHour                            EQU    5
GD_LogCall                             EQU    6

KD_BillTime1	EQU	'1'
KD_BillTime2	EQU	'2'
KD_BillTime3	EQU	'3'
KD_BillNormal	EQU	'N'
KD_BillCheap	EQU	'C'
KD_LogCall	EQU	'L'



**********************************************************************
*                  Settings for Preferences window                   *
**********************************************************************
PrefsWinWindowTags:
PrefsWinL:
    DC.L    WA_Left,0
PrefsWinT:
    DC.L    WA_Top,0
PrefsWinW:
    DC.L    WA_Width,0
PrefsWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
PrefsWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,PrefsTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
PrefsWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE

Normal1Tags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
StartNormTags:
    DC.L    GTSL_Max,143
    DC.L    GTSL_MaxLevelLen,9
    DC.L    GTSL_LevelFormat,StringFormat
    DC.L    GTSL_DispFunc,ShowTime
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
OpenBillTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_MaxChars,256
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
LogNameTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GT_Underscore,'_'
    DC.L    GTST_MaxChars,300
    DC.L    TAG_DONE
EverCheapTags:
    DC.L    GTTX_Text,EverCheapString
    DC.L    TAG_DONE

EverCheapString:
    DC.B    'Always cheap on',0
    CNOP     0,2
Normal1Text:
    DC.B    'Normal _1',0
    CNOP    0,2
Cheap1Text:
    DC.B    'Cheap _A',0
    CNOP    0,2
Normal2Text:
    DC.B    'Normal _2',0
    CNOP    0,2
Cheap2Text:
    DC.B    'Cheap _B',0
    CNOP    0,2
Normal3Text:
    DC.B    'Normal _3',0
    CNOP    0,2
Cheap3Text:
    DC.B    'Cheap _C',0
    CNOP    0,2
CostUnitText:
    DC.B    'Costs/_Unit',0
    CNOP    0,2
StartNormText:
    DC.B    'Start _normal         ',0
    CNOP    0,2
StartCheapText:
    DC.B    'Start c_heap         ',0
    CNOP    0,2
PopUpBillText:
    DC.B    'Pop up Bill _window',0
    CNOP    0,2
ClearLogText:
    DC.B    'Clear _Log',0
    CNOP    0,2
TotalSumText:
    DC.B    '_Display total sum',0
    CNOP    0,2
OpenBillText:
    DC.B    'Open Bill _on',0
    CNOP    0,2
SaveLogText:
    DC.B    '_Save Log to...',0
    CNOP    0,2
LogNameText:
    DC.B    'Log _Filename',0
    CNOP    0,2
SaturdayText:
    DC.B    'Saturday _4',0
    CNOP    0,2
SundayText:
    DC.B    'Sunday _5',0
    CNOP    0,2
MondayText:
    DC.B    'Monday _6',0
    CNOP    0,2
TuesdayText:
    DC.B    'Tuesday _7',0
    CNOP    0,2
WednesdayText:
    DC.B    'Wednesday _8',0
    CNOP    0,2
ThursdayText:
    DC.B    'Thursday _9',0
    CNOP    0,2
FridayText:
    DC.B    'Friday _0',0
    CNOP    0,2


GD_Normal1                             EQU    0
GD_Cheap1                              EQU    1
GD_Normal2                             EQU    2
GD_Cheap2                              EQU    3
GD_Normal3                             EQU    4
GD_Cheap3                              EQU    5
GD_CostUnit                            EQU    6
GD_StartNorm                           EQU    7
GD_StartCheap                          EQU    8
GD_PopUpBill                           EQU    9
GD_ClearLog                            EQU    10
GD_TotalSum                            EQU    11
GD_OpenBill                            EQU    12
GD_SaveLog                             EQU    13
GD_LogName                             EQU    14
GD_EverCheap                           EQU    15
GD_Saturday                            EQU    16
GD_Sunday                              EQU    17
GD_Monday                              EQU    18
GD_Tuesday                             EQU    19
GD_Wednesday                           EQU    20
GD_Thursday                            EQU    21
GD_Friday                              EQU    22

KD_Normal1	EQU	'1'
KD_Cheap1	EQU	'A'
KD_Normal2	EQU	'2'
KD_Cheap2	EQU	'B'
KD_Normal3	EQU	'3'
KD_Cheap3	EQU	'C'
KD_CostUnit	EQU	'U'
KD_StartNorm	EQU	'N'
KD_StartCheap	EQU	'H'
KD_PopUpBill	EQU	'W'
KD_ClearLog	EQU	'L'
KD_TotalSum	EQU	'D'
KD_OpenBill	EQU	'O'
KD_SaveLog	EQU	'S'
KD_LogName	EQU	'F'
KD_Saturday	EQU	'4'
KD_Sunday	EQU	'5'
KD_Monday	EQU	'6'
KD_Tuesday	EQU	'7'
KD_Wednesday	EQU	'8'
KD_Thursday	EQU	'9'
KD_Friday	EQU	'0'



**********************************************************************
*                      Settings for Log window                       *
**********************************************************************
LogWinWindowTags:
LogWinL:
    DC.L    WA_Left,0
LogWinT:
    DC.L    WA_Top,0
LogWinW:
    DC.L    WA_Width,0
LogWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,STRINGIDCMP!BUTTONIDCMP!INTEGERIDCMP!IDCMP_CLOSEWINDOW!IDCMP_ACTIVEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW!IDCMP_REFRESHWINDOW
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
LogWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_ScreenTitle,WindowScrTitle
LogWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


Line1Tags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTST_MaxChars,60
    DC.L    TAG_DONE
LogVerTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,2
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

LogOkText:
    DC.B    '_Ok',0
    CNOP    0,2
LogCancelText:
    DC.B    '_Cancel',0
    CNOP    0,2
LogVerText:
    DC.B    '_Revision',0
    CNOP    0,2
LogRevText:
    DC.B    '.',0
    CNOP    0,2

GD_Line1                               EQU    0
GD_Line2                               EQU    1
GD_Line3                               EQU    2
GD_Line4                               EQU    3
GD_Line5                               EQU    4
GD_LogOk                               EQU    5
GD_LogCancel                           EQU    6
GD_LogVer                              EQU    7
GD_LogRev                              EQU    8

KD_LogOk	EQU	'O'
KD_LogCancel	EQU	'C'
KD_LogVer	EQU	'R'




**********************************************************************
*                    Settings for Progress window                    *
**********************************************************************
ProgWinWindowTags:
ProgWinL:
    DC.L    WA_Left,0
ProgWinT:
    DC.L    WA_Top,0
ProgWinW:
    DC.L    WA_Width,0
ProgWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,TEXTIDCMP
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_SMART_REFRESH
ProgWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,ProgWinWTitle
    DC.L    WA_ScreenTitle,WindowScrTitle
ProgWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE
ProgWinWTitle:
    DC.B    'Revision in progress',0
    CNOP    0,2

Prog0Tags:
    DC.L    GTTX_Text,Prog0String
    DC.L    TAG_DONE
Prog0String:
    DC.B    '0%',0
    CNOP     0,2
Prog100Tags:
    DC.L    GTTX_Text,Prog100String
    DC.L    TAG_DONE
Prog100String:
    DC.B    '100%',0
    CNOP     0,2

GD_Prog0                               EQU    0
GD_Prog100                             EQU    1



**********************************************************************
*                 Definitions for Dump screen window                 *
**********************************************************************
PrintWinWindowTags:
PrintWinL:
    DC.L    WA_Left,0
PrintWinT:
    DC.L    WA_Top,0
PrintWinW:
    DC.L    WA_Width,0
PrintWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,CYCLEIDCMP!SLIDERIDCMP!CHECKBOXIDCMP!INTEGERIDCMP!TEXTIDCMP!BUTTONIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY!IDCMP_CHANGEWINDOW!IDCMP_REFRESHWINDOW
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
PrintWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,PrintTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
PrintWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


GfxAspectTags:
    DC.L    GTCY_Labels,GfxAspectLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxShadeTags:
    DC.L    GTCY_Labels,GfxShadeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxDitherTags:
    DC.L    GTCY_Labels,GfxDitherLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxImageTags:
    DC.L    GTCY_Labels,GfxImageLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxDensityTags:
    DC.L    GTSL_Min,1
    DC.L    GTSL_Max,7
    DC.L    GTSL_MaxLevelLen,6
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxScaleTags:
    DC.L    GTCY_Labels,GfxScaleLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxSize1Tags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,6
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxThresTags:
    DC.L    GTSL_Min,1
    DC.L    GTSL_MaxLevelLen,6
    DC.L    GTSL_LevelFormat,ScrDimmFormat
    DC.L    PGA_Freedom,LORIENT_HORIZ
    DC.L    GA_RelVerify,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxGfxTypeTags:
    DC.L    GTCY_Labels,GfxGfxTypeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxXTags:
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTST_EditHook,StrEditHook+ZeroPage
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
GfxSourceTags:
    DC.L    GTCY_Labels,GfxSourceLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

GfxAspectText:
    DC.B    '_Aspect',0
    CNOP    0,2
GfxShadeText:
    DC.B    '_Shade',0
    CNOP    0,2
GfxDitherText:
    DC.B    '_Dithering',0
    CNOP    0,2
GfxImageText:
    DC.B    '_Image',0
    CNOP    0,2
GfxDensityText:
    DC.B    'D_ensity      ',0
    CNOP    0,2
GfxRedText:
    DC.B    '_Red',0
    CNOP    0,2
GfxGreenText:
    DC.B    '_Green',0
    CNOP    0,2
GfxBlueText:
    DC.B    '_Blue',0
    CNOP    0,2
GfxScaleText:
    DC.B    'Sca_ling',0
    CNOP    0,2
GfxSize1Text:
    DC.B    'Si_ze',0
    CNOP    0,2
GfxSize2Text:
    DC.B    'x',0
    CNOP    0,2
GfxThresText:
    DC.B    '_Threshold      ',0
    CNOP    0,2
GfxCenterText:
    DC.B    'Ce_ntered',0
    CNOP    0,2
GfxSmoothText:
    DC.B    'S_moothing',0
    CNOP    0,2
GfxFormFeedText:
    DC.B    '_FormFeed',0
    CNOP    0,2
GfxKeepAspectText:
    DC.B    '_Keep aspect',0
    CNOP    0,2
GfxGfxTypeText:
    DC.B    'Gra_phic',0
    CNOP    0,2
GfxXText:
    DC.B    '_X',0
    CNOP    0,2
GfxYText:
    DC.B    '_Y',0
    CNOP    0,2
GfxWidthText:
    DC.B    '_W',0
    CNOP    0,2
GfxHeightText:
    DC.B    '_H',0
    CNOP    0,2
GfxSourceText:
    DC.B    'S_ource',0
    CNOP    0,2
GfxGetText:
    DC.B    'Reselect source (_1)',0
    CNOP    0,2
GfxPrintText:
    DC.B    'D_ump',0
    CNOP    0,2
GfxCancelText:
    DC.B    '_Cancel',0
    CNOP    0,2
GfxBoundsText:
    DC.B    'Define area (_2)',0
    CNOP    0,2


GfxAspectLabels:
    DC.L    GfxAspectLab0
    DC.L    GfxAspectLab1
    DC.L    0
GfxShadeLabels:
    DC.L    GfxShadeLab0
    DC.L    GfxShadeLab1
    DC.L    GfxShadeLab2
    DC.L    GfxShadeLab3
    DC.L    0
GfxDitherLabels:
    DC.L    GfxDitherLab0
    DC.L    GfxDitherLab1
    DC.L    GfxDitherLab2
    DC.L    0
GfxImageLabels:
    DC.L    GfxImageLab0
    DC.L    GfxImageLab1
    DC.L    0
GfxScaleLabels:
    DC.L    GfxScaleLab0
    DC.L    GfxScaleLab1
    DC.L    GfxScaleLab2
    DC.L    GfxScaleLab3
    DC.L    GfxScaleLab4
    DC.L    0
GfxGfxTypeLabels:
    DC.L    GfxGfxTypeLab0
    DC.L    GfxGfxTypeLab1
    DC.L    0
GfxSourceLabels:
    DC.L    GfxSourceLab0
    DC.L    GfxSourceLab1
    DC.L    0

GfxAspectLab0:    DC.B    'Horizontal',0
    CNOP    0,2
GfxAspectLab1:    DC.B    'Vertical',0
    CNOP    0,2

GfxShadeLab0:    DC.B    'Black & White',0
    CNOP    0,2
GfxShadeLab1:    DC.B    'Grey Scale 1',0
    CNOP    0,2
GfxShadeLab2:    DC.B    'Grey Scale 2',0
    CNOP    0,2
GfxShadeLab3:    DC.B    'Color',0
    CNOP    0,2

GfxDitherLab0:    DC.B    'Ordered',0
    CNOP    0,2
GfxDitherLab1:    DC.B    'Halftone',0
    CNOP    0,2
GfxDitherLab2:    DC.B    'Floyd-Steinberg',0
    CNOP    0,2

GfxImageLab0:    DC.B    'Positive',0
    CNOP    0,2
GfxImageLab1:    DC.B    'Negative',0
    CNOP    0,2

GfxScaleLab0:    DC.B    'inch x inch',0
    CNOP    0,2
GfxScaleLab1:    DC.B    'mm x mm',0
    CNOP    0,2
GfxScaleLab2:    DC.B    'cm x cm',0
    CNOP    0,2
GfxScaleLab3:    DC.B    'Fraction',0
    CNOP    0,2
GfxScaleLab4:    DC.B    'Full page',0
    CNOP    0,2

GfxGfxTypeLab0:    DC.B    'Complete',0
    CNOP    0,2
GfxGfxTypeLab1:    DC.B    'Area',0
    CNOP    0,2

GfxSourceLab0:    DC.B    'Screen',0
    CNOP    0,2
GfxSourceLab1:    DC.B    'Window',0
    CNOP    0,2


GD_GfxAspect                           EQU    0
GD_GfxShade                            EQU    1
GD_GfxDither                           EQU    2
GD_GfxImage                            EQU    3
GD_GfxDensity                          EQU    4
GD_GfxRed                              EQU    5
GD_GfxGreen                            EQU    6
GD_GfxBlue                             EQU    7
GD_GfxScale                            EQU    8
GD_GfxSize1                            EQU    9
GD_GfxSize2                            EQU    10
GD_GfxThres                            EQU    11
GD_GfxCenter                           EQU    12
GD_GfxSmooth                           EQU    13
GD_GfxFormFeed                         EQU    14
GD_GfxKeepAspect                       EQU    15
GD_GfxGfxType                          EQU    16
GD_GfxX                                EQU    17
GD_GfxY                                EQU    18
GD_GfxWidth                            EQU    19
GD_GfxHeight                           EQU    20
GD_GfxSource                           EQU    21
GD_GfxSourceName                       EQU    22
GD_GfxGet                              EQU    23
GD_GfxPrint                            EQU    24
GD_GfxCancel                           EQU    25
GD_GfxBounds                           EQU    26

KD_GfxAspect	EQU	'A'
KD_GfxShade	EQU	'S'
KD_GfxDither	EQU	'D'
KD_GfxImage	EQU	'I'
KD_GfxRed	EQU	'R'
KD_GfxGreen	EQU	'G'
KD_GfxBlue	EQU	'B'
KD_GfxScale	EQU	'L'
KD_GfxSize1	EQU	'Z'
KD_GfxThres	EQU	'T'
KD_GfxDensity	EQU	'E'
KD_GfxCenter	EQU	'N'
KD_GfxSmooth	EQU	'M'
KD_GfxFormFeed	EQU	'F'
KD_GfxKeepAspect	EQU	'K'
KD_GfxGfxType	EQU	'P'
KD_GfxX		EQU	'X'
KD_GfxY		EQU	'Y'
KD_GfxWidth	EQU	'W'
KD_GfxHeight	EQU	'H'
KD_GfxSource	EQU	'O'
KD_GfxGet	EQU	'1'
KD_GfxPrint	EQU	'U'
KD_GfxCancel	EQU	'C'
KD_GfxBounds	EQU	'2'

ShadeFlags	dc.w	SHADE_BW,SHADE_GREYSCALE,SHADE_GREYSCALE,SHADE_COLOR
DitherFlags	dc.w	ORDERED_DITHERING,HALFTONE_DITHERING,FLOYD_DITHERING





**********************************************************************
*                      Settings for lock window                      *
**********************************************************************
LockWinWindowTags:
LockWinL:
    DC.L    WA_Left,0
LockWinT:
    DC.L    WA_Top,0
LockWinW:
    DC.L    WA_Width,0
LockWinH:
    DC.L    WA_Height,0
    DC.L    WA_IDCMP,0
    DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET!WFLG_SMART_REFRESH!WFLG_ACTIVATE
LockWinWG:
    DC.L    WA_Gadgets,0
    DC.L    WA_Title,LockTitle+ZeroPage
    DC.L    WA_ScreenTitle,WindowScrTitle
LockWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE


WindowNameTags:
    DC.L    GA_Disabled,1
    DC.L    GTST_MaxChars,80
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

WindowListTags:
    DC.L    GT_Underscore,'_'
    DC.L    GTLV_Labels,WindowBase+ZeroPage
WindowListGad    DC.L    GTLV_ShowSelected,0
    DC.L    TAG_DONE

SelectWindowTags
    DC.L    GA_Disabled,1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE

WindowNameText:
    DC.B    'Window _name',0
    CNOP    0,2

WindowListText:
    DC.B    'Window _list',0
    CNOP    0,2

AddWindowText:
    DC.B    '_Add window',0
    CNOP    0,2

SelectWindowText:
    DC.B    '_Select window',0
    CNOP    0,2

DeleteWindowText:
    DC.B    '_Delete window',0
    CNOP    0,2

UnusedStr	dc.b	"--- Unused entry ---",0
		EVEN
SelectWinTxt	dc.b	"Click on window to use",0
		EVEN



GD_WindowName                          EQU    0
GD_WindowList                          EQU    1
GD_AddWindow                           EQU    2
GD_SelectWindow                        EQU    3
GD_DeleteWindow                        EQU    4


KD_WindowName	EQU	'N'
KD_WindowList	EQU	'L'
KD_AddWindow	EQU	'A'
KD_SelectWindow	EQU	'S'
KD_DeleteWindow	EQU	'D'



**********************************************************************
*                    Definitions for Clock-Window                    *
**********************************************************************
ClockWindowTags	dc.l	WA_Left
ClockLeft	dc.l	0
		dc.l	WA_Top
ClockTop	dc.l	0
		dc.l	WA_InnerWidth
ClockWidth	dc.l	0
		dc.l	WA_InnerHeight
		dc.l	0
		dc.l	WA_ScreenTitle
		dc.l	WindowScrTitle
		dc.l	WA_IDCMP
		dc.l	CLOCKWINIDCMP
		dc.l	WA_Flags
		dc.l	CLOCKWINFLAGS
		dc.l	WA_Title
		dc.l	0
		dc.l	TAG_DONE



**********************************************************************
*                    Screen title for all windows                    *
**********************************************************************
WindowScrTitle	dc.b	"KCommodity V"
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	") "
		dc.b	"by Kai Iske. SHAREWARE"
		EVEN


**********************************************************************
*                       Names for the windows                        *
**********************************************************************
DefControlTitle	dc.b	"KCommodity : HotKey=",0
DefSetTitle	dc.b	"Settings : HotKey=",0
DefMiscTitle	dc.b	"Miscellaneous : HotKey=",0
DefAlarmTitle	dc.b	"Alarm modes : HotKey=",0
DefQualTitle	dc.b	"Set qualifier for : ",0
DefCycleTitle	dc.b	"Cycle settings : HotKey=",0
DefBlankTitle	dc.b	"Blanking : HotKey=",0
DefColsTitle	dc.b	"Colors : HotKey=",0
DefMouseTitle	dc.b	"Mouse : HotKey=",0
DefHotKeyTitle	dc.b	"HotKeys : HotKey=",0
DefFKeyTitle	dc.b	"Function Keys : HotKey=",0
DefFormTitle	dc.b	"Formatter : HotKey=",0
DefBillTitle	dc.b	"Bill : HotKey=",0
DefPrefsTitle	dc.b	"Bill Prefs : HotKey=",0
DefPrintTitle	dc.b	"Display dump : HotKey=",0
GfxGetTitle	dc.b	"Position mouse and press HotKey",0
DefLockTitle	dc.b	"Lock windows : HotKey=",0
		EVEN

**********************************************************************
*                        Titles for LogWindow                        *
**********************************************************************
LogWinTitle	dc.b	"You can now enter a 5 lines (60 chars per line) Log Message",0
		EVEN
PurposeWinTitle	dc.b	"You can now enter a 5 lines (60 chars per line) Purpose Message",0
		EVEN


**********************************************************************
*               These are the tags for the new gadgets               *
**********************************************************************
ButtonTags	dc.l	GT_Underscore,'_'
		dc.l	TAG_DONE


**********************************************************************
*                    Tags for normal Text gadgets                    *
**********************************************************************
NormTxtTags	DC.L	GTTX_Border,1
		DC.L	TAG_DONE


**********************************************************************
*                      Texts for control window                      *
**********************************************************************
AlarmReqText	dc.b	"Hey guy,",$0a,"It`s time for you to wake up !",0
		EVEN


**********************************************************************
*                  Definitions for qualifier texts                   *
**********************************************************************
ESCQualTxt	dc.b	"ESC Window close",0
		EVEN
DragQualTxt	dc.b	"Full dragging",0
		EVEN
FrontClickTxt	dc.b	"Front click",0
		EVEN
BackClickTxt	dc.b	"Back click",0
		EVEN
MiddleClickTxt	dc.b	"Middle click",0
		EVEN
HoldXQualTxt	dc.b	"Hold X",0
		EVEN
HoldYQualTxt	dc.b	"Hold Y",0
		EVEN


**********************************************************************
*                     Default PublicScreen List                      *
**********************************************************************
DefPubScrName	dc.b	"TERM",0
		EVEN



**********************************************************************
*                      Names for the qualifiers                      *
**********************************************************************
QualifierTab	dc.l	IEQUALIFIER_LSHIFT,LShiftName
		dc.l	IEQUALIFIER_RSHIFT,RShiftName
		dc.l	IEQUALIFIER_CAPSLOCK,CapsName
		dc.l	IEQUALIFIER_CONTROL,ControlName
		dc.l	IEQUALIFIER_LALT,LAltName
		dc.l	IEQUALIFIER_RALT,RAltName
		dc.l	IEQUALIFIER_LCOMMAND,LCommandName
		dc.l	IEQUALIFIER_RCOMMAND,RCommandName
		dc.l	IEQUALIFIER_MIDBUTTON,MidButtonName
		dc.l	IEQUALIFIER_RBUTTON,RightButtonName
		dc.l	IEQUALIFIER_LEFTBUTTON,LeftButtonName
		dc.l	IEQUALIFIER_NUMERICPAD,PadName
NUMQUALIFIER	EQU	((*-QualifierTab)/8)

CodeTab		dc.l	$45,EscName
		dc.l	$50,F1Name
		dc.l	$51,F2Name
		dc.l	$52,F3Name
		dc.l	$53,F4Name
		dc.l	$54,F5Name
		dc.l	$55,F6Name
		dc.l	$56,F7Name
		dc.l	$57,F8Name
		dc.l	$58,F9Name
		dc.l	$59,F10Name
		dc.l	$41,BackName
		dc.l	$46,DelName
		dc.l	$5f,HelpKeyName
		dc.l	$42,TabName
		dc.l	$4c,UpName
		dc.l	$4d,DownName
		dc.l	$4f,LeftName
		dc.l	$4e,RightName
		dc.l	$44,ReturnName
		dc.l	$43,EnterName
		dc.l	$4a,MinusName
		dc.l	$40,SpaceName
		dc.l	IECODE_LBUTTON,LeftButtonName
		dc.l	IECODE_RBUTTON,RightButtonName
		dc.l	IECODE_MBUTTON,MidButtonName
NUMCODES	EQU	((*-CodeTab)/8)

LShiftName	dc.b	"LSHIFT",0
		EVEN
RShiftName	dc.b	"RSHIFT",0
		EVEN
CapsName	dc.b	"CAPSLOCK",0
		EVEN
ControlName	dc.b	"CONTROL",0
		EVEN
LAltName	dc.b	"LALT",0
		EVEN
RAltName	dc.b	"RALT",0
		EVEN
LCommandName	dc.b	"LCOMMAND",0
		EVEN
RCommandName	dc.b	"RCOMMAND",0
		EVEN
LeftButtonName	dc.b	"LBUTTON",0
		EVEN
RightButtonName	dc.b	"RBUTTON",0
		EVEN
MidButtonName	dc.b	"MBUTTON",0
		EVEN
PadName		dc.b	"NUMERICPAD",0
		EVEN
EscName		dc.b	"ESCAPE",0
		EVEN
F1Name		dc.b	"F1",0
		EVEN
F2Name		dc.b	"F2",0
		EVEN
F3Name		dc.b	"F3",0
		EVEN
F4Name		dc.b	"F4",0
		EVEN
F5Name		dc.b	"F5",0
		EVEN
F6Name		dc.b	"F6",0
		EVEN
F7Name		dc.b	"F7",0
		EVEN
F8Name		dc.b	"F8",0
		EVEN
F9Name		dc.b	"F9",0
		EVEN
F10Name		dc.b	"F10",0
		EVEN
BackName	dc.b	"BACKSPACE",0
		EVEN
DelName		dc.b	"DELETE",0
		EVEN
HelpKeyName	dc.b	"HELP",0
		EVEN
TabName		dc.b	"TAB",0
		EVEN
UpName		dc.b	"UP",0
		EVEN
DownName	dc.b	"DOWN",0
		EVEN
LeftName	dc.b	"LEFT",0
		EVEN
RightName	dc.b	"RIGHT",0
		EVEN
EnterName	dc.b	"ENTER",0
		EVEN
ReturnName	dc.b	"RETURN",0
		EVEN
MinusName	dc.b	"MINUS",0
		EVEN
SpaceName	dc.b	"SPACE",0
		EVEN



**********************************************************************
*                   Table for converting "Umlauts"                   *
**********************************************************************
UmlautTab	dc.w	'ä',$20,$12		; Ae
		dc.w	'Ä',$20,$12
		dc.w	'ö',$18,$12		; Oe
		dc.w	'Ö',$18,$12
		dc.w	'ü',$16,$12		; Ue
		dc.w	'Ü',$16,$12
		dc.w	'ß',$21,$21		; ss
		dc.w	0,0,0



**********************************************************************
*                Structures for the costs-calculating                *
**********************************************************************
		RSRESET
cu_Normal	rs.l	1
cu_Cheap	rs.l	1

PerHourStr	dc.b	"Costs per hour : "
PerHourBuff	ds.b	9
		EVEN
CostString	dc.b	"    0.00",0
		EVEN
CostUnitTxt	dc.b	"Cost/_Unit",0
		EVEN





**********************************************************************
*                       Structure for dimming                        *
**********************************************************************
		RSRESET
dm_Screen	rs.l	1
dm_Colors	rs.w	32
dm_Dimmed	rs.w	32
dm_SIZEOF	rs.w	0



**********************************************************************
*              Definitions for userdefinable filenames               *
**********************************************************************
LogFileHeader	dc.b	"Select new Log-File",0
		EVEN
DefLogFileName	dc.b	"S:KCXLOGFILE",0
		EVEN
PrefsLoadHeader	dc.b	"Load preferences",0
		EVEN
PrefsSaveHeader	dc.b	"Save pereferences",0
		EVEN
AlSampLoadHead	dc.b	"Load Alarm sample",0
		EVEN
PrefsHeader	dc.b	"KCXPREF"
		REVISION
		dc.b	0
PREFSHEADERLEN	EQU	*-PrefsHeader-1
		EVEN
DefPrefsFName	dc.b	"KCX.PREFS",0
		EVEN
DirPrefsName	dc.b	"KCX.PREFS",0
		EVEN
EnvPrefsName	dc.b	"ENV:KCX/KCX.PREFS",0
		EVEN
EnvArcPrefsName	dc.b	"ENVARC:KCX/KCX.PREFS",0
		EVEN


**********************************************************************
*                         HotKey definitions                         *
**********************************************************************
DefaultHotKeys	dc.l	DefPopUpKey,DefSetHotKey,DefBlankHotKey
		dc.l	DefMouseHotKey,DefFKeyHotKey,DefBillHotKey
		dc.l	DefMiscHotKey,DefCycleHotKey,DefHotKeyHotKey
		dc.l	DefFormatHotKey,DefPrefsHotKey,DefAlarmHotKey
		dc.l	DefColsHotKey,DefPageHotKey,DefShellHotKey
		dc.l	DefUmlautHotKey,DefSnapHotKey,DefDoBlankHotKey
		dc.l	DefDumpHotKey,DefLockHotKey,DefCenterHotKey
DefPopUpKey	dc.b	"LCOMMAND HELP",0
		EVEN
DefSetHotKey	dc.b	"ALT SHIFT T",0
		EVEN
DefBlankHotKey	dc.b	"ALT SHIFT L",0
		EVEN
DefMouseHotKey	dc.b	"ALT SHIFT E",0
		EVEN
DefFKeyHotKey	dc.b	"ALT SHIFT K",0
		EVEN
DefBillHotKey	dc.b	"ALT SHIFT B",0
		EVEN
DefMiscHotKey	dc.b	"ALT SHIFT M",0
		EVEN
DefCycleHotKey	dc.b	"ALT SHIFT C",0
		EVEN
DefHotKeyHotKey	dc.b	"ALT SHIFT H",0
		EVEN
DefFormatHotKey	dc.b	"ALT SHIFT F",0
		EVEN
DefPrefsHotKey	dc.b	"ALT SHIFT P",0
		EVEN
DefAlarmHotKey	dc.b	"ALT SHIFT A",0
		EVEN
DefColsHotKey	dc.b	"ALT SHIFT O",0
		EVEN
DefPageHotKey	dc.b	"RALT HELP",0
		EVEN
DefShellHotKey	dc.b	"ALT SHIFT S",0
		EVEN
DefUmlautHotKey	dc.b	"ALT SHIFT U",0
		EVEN
DefSnapHotKey	dc.b	"ALT SHIFT G",0
		EVEN
DefDoBlankHotKey	dc.b	"ALT SHIFT D",0
		EVEN
DefDumpHotKey	dc.b	"ALT SHIFT Y",0
		EVEN
DefLockHotKey	dc.b	"ALT SHIFT W",0
		EVEN
DefCenterHotKey	dc.b	"ALT SHIFT X",0
		EVEN

POPUPKEYID	EQU	1			; Definitions for IDs
SETKEYID	EQU	2
BLANKKEYID	EQU	3
MOUSEKEYID	EQU	4
FKEYKEYID	EQU	5
BILLKEYID	EQU	6
MISCKEYID	EQU	7
CYCLEKEYID	EQU	8
HOTWINKEYID	EQU	9
FORMKEYID	EQU	10
PREFSKEYID	EQU	11
ALARMKEYID	EQU	12
COLSKEYID	EQU	13
PAGEKEYID	EQU	14
SHELLKEYID	EQU	15
UMLAUTKEYID	EQU	16
SNAPKEYID	EQU	17
DOBLANKKEYID	EQU	18
DUMPKEYID	EQU	19
LOCKKEYID	EQU	20
CENTERKEYID	EQU	21


**********************************************************************
*                     Defines for HotKey-Window                      *
**********************************************************************
HotKeyGadStat	dc.l	PopUpKey+ZeroPage	; CX_PopKey
		dc.l	SetHotKey+ZeroPage	; Settings
		dc.l	BlankHotKey+ZeroPage	; Blanking
		dc.l	MouseHotKey+ZeroPage	; Mouse
		dc.l	FKeyHotKey+ZeroPage	; FKeys
		dc.l	BillHotKey+ZeroPage	; Bill
		dc.l	MiscHotKey+ZeroPage	; Misc
		dc.l	CycleHotKey+ZeroPage	; Cycling
		dc.l	HotKeyHotKey+ZeroPage	; Hotkeys
		dc.l	FormatHotKey+ZeroPage	; Formatter
		dc.l	PrefsHotKey+ZeroPage	; Preferences
		dc.l	AlarmHotKey+ZeroPage	; Alarm modes
		dc.l	ColsHotKey+ZeroPage	; Display colors
		dc.l	PageHotKey+ZeroPage	; Page
		dc.l	ShellHotKey+ZeroPage	; UserShell
		dc.l	UmlautHotKey+ZeroPage	; Map Umlauts
		dc.l	SnapHotKey+ZeroPage	; Snap memory
		dc.l	DoBlankHotKey+ZeroPage	; Immediate Blank
		dc.l	DumpHotKey+ZeroPage	; Display dump
		dc.l	LockHotKey+ZeroPage	; Lock window
		dc.l	CenterHotKey+ZeroPage	; Center a screen
HOTKEYNUM	EQU	((*-HotKeyGadStat)/4)
HotKeyGadVars	dc.l	MainHandle+ZeroPage,ControlTitle+ZeroPage,PopUpFilter+ZeroPage
		dc.l	SetHandle+ZeroPage,SetTitle+ZeroPage,SetFilter+ZeroPage
		dc.l	BlankHandle+ZeroPage,BlankTitle+ZeroPage,BlankFilter+ZeroPage
		dc.l	MouseHandle+ZeroPage,MouseTitle+ZeroPage,MouseFilter+ZeroPage
		dc.l	FKeyHandle+ZeroPage,FKeyTitle+ZeroPage,FKeyFilter+ZeroPage
		dc.l	BillHandle+ZeroPage,BillTitle+ZeroPage,BillFilter+ZeroPage
		dc.l	MiscHandle+ZeroPage,MiscTitle+ZeroPage,MiscFilter+ZeroPage
		dc.l	CycleHandle+ZeroPage,CycleTitle+ZeroPage,CycleFilter+ZeroPage
		dc.l	HotKeyHandle+ZeroPage,HotKeyTitle+ZeroPage,HotKeyFilter+ZeroPage
		dc.l	FormHandle+ZeroPage,FormTitle+ZeroPage,FormFilter+ZeroPage
		dc.l	PrefsHandle+ZeroPage,PrefsTitle+ZeroPage,PrefsFilter+ZeroPage
		dc.l	AlarmHandle+ZeroPage,AlarmTitle+ZeroPage,AlarmFilter+ZeroPage
		dc.l	ColsHandle+ZeroPage,ColsTitle+ZeroPage,ColsFilter+ZeroPage
		dc.l	0,0,PageFilter+ZeroPage
		dc.l	0,0,ShellFilter+ZeroPage
		dc.l	0,0,UmlautFilter+ZeroPage
		dc.l	0,0,SnapFilter+ZeroPage
		dc.l	0,0,DoBlankFilter+ZeroPage
		dc.l	PrintHandle+ZeroPage,PrintTitle+ZeroPage,DumpFilter+ZeroPage
		dc.l	LockHandle+ZeroPage,LockTitle+ZeroPage,LockFilter+ZeroPage
		dc.l	0,0,CenterFilter+ZeroPage


**********************************************************************
*                      Variables for formatter                       *
**********************************************************************
DriveArg	dc.b	" DRIVE ",0
		EVEN
NameArg		dc.b	" NAME ",0
		EVEN
IconsArg	dc.b	" NOICONS",0
		EVEN
QuickArg	dc.b	" QUICK",0
		EVEN
FFSArg		dc.b	" FFS",0
		EVEN
VerifyArg	dc.b	" NOVERIFY",0
		EVEN
InstallArg	dc.b	" INSTALL",0
		EVEN
EjectArg	dc.b	" EJECT",0
		EVEN
MainCom		dc.b	"SYS:System/Format",0
		EVEN
DefLabel	dc.b	"Empty",0
		ds.b	24
		EVEN


**********************************************************************
*                   Command definitions for FKeys                    *
**********************************************************************
FKeyCmds	dc.l	MinimizeCmd,MaximizeCmd,ZipWinCmd
FKEYCMDNUM	EQU	(*-FKeyCmds)/4
FKeyRouts	dc.l	MinimizeWin,MaximizeWin,ZipWin
MinimizeCmd	dc.b	"MINWIN",0,0
MaximizeCmd	dc.b	"MAXWIN",0,0
ZipWinCmd	dc.b	"ZIPWIN",0,0



**********************************************************************
*              Pointers to window-structures for saving              *
**********************************************************************
WindowHandles	dc.l	MainHandle+ZeroPage,SetHandle+ZeroPage,MiscHandle+ZeroPage
		dc.l	AlarmHandle+ZeroPage,QualHandle+ZeroPage,CycleHandle+ZeroPage
		dc.l	BlankHandle+ZeroPage,ColsHandle+ZeroPage,MouseHandle+ZeroPage
		dc.l	HotKeyHandle+ZeroPage,FKeyHandle+ZeroPage,FormHandle+ZeroPage
		dc.l	BillHandle+ZeroPage,PrefsHandle+ZeroPage
		dc.l	LogHandle+ZeroPage,ProgHandle+ZeroPage,ClockHandle+ZeroPage
		dc.l	PrintHandle+ZeroPage,LockHandle+ZeroPage
WINDOWNUM	EQU	((*-WindowHandles)/4)
WindowRoutines	dc.l	HandleMainWin,HandleSetWin,HandleMiscWin,HandleAlarmWin,0
		dc.l	HandleCycleWin,HandleBlankWin,HandleColsWin,HandleMouseWin
		dc.l	HandleHotKeyWin,HandleFKeyWin,HandleFormWin,0,HandlePrefsWin
		dc.l	0,0,0,0,HandleLockWin



**********************************************************************
*  Text attribute for gadgets. We are stubborn. Let`s take topaz :-) *
**********************************************************************
GadgetTxtAttr	dc.l	FontName
		dc.w	8
		dc.b	FS_NORMAL
		dc.b	FPF_ROMFONT
FontName	dc.b	"topaz.font",0
		EVEN


**********************************************************************
*                     Attribute for System text                      *
**********************************************************************
SysTxtAttr	dc.l	0
		dc.w	0
		dc.b	FS_NORMAL
		dc.b	0


**********************************************************************
*                  String for font-sensitive calcs                   *
**********************************************************************
XStr		DC.B    'm',0
		CNOP    0,2


**********************************************************************
*                 Text attr for the text in titlebar                 *
**********************************************************************
TxtAttr		dc.l	TxtAttrFont+ZeroPage
		dc.w	0
		dc.b	FS_NORMAL
		dc.b	0

**********************************************************************
*                Chunkdefinitions for the Prefs file                 *
**********************************************************************
VersChunk	dc.w	VERNUM,REVNUM
VersChunkSize	EQU	*-VersChunk


**********************************************************************
*                     Definition for VHDR Chunk                      *
**********************************************************************
		RSRESET
oneShotHiSamples	rs.l	1
repeatHiSamples		rs.l	1
samplesPerHiCycle	rs.l	1
samplesPerSec		rs.w	1
ctOctave		rs.b	1
ctCompression		rs.b	1
Volume			rs.l	1

**********************************************************************
*                     Formatstrings for RawDoFmt                     *
**********************************************************************
TimeFormats	dc.l	FormLSec,FormLNSec,FormSSec,FormSNSec
FormLSec	dc.b	" %s %s %s ",0
		EVEN
FormLNSec	dc.b	" %s %s %.5s ",0
		EVEN
FormSSec	dc.b	" %.3s %s %s ",0
		EVEN
FormSNSec	dc.b	" %.3s %s %.5s ",0
		EVEN
ResultFormat	dc.b	"%-ld",0
		EVEN
ResultWinFormat	dc.b	"%d/%d",0
		EVEN
CostFormString	dc.b	"%5ld.%02ld",0
		EVEN
PerHourForm	dc.b	"%4ld.%02ld",0
		EVEN
LIntFormat	dc.b	"%ld",0
		EVEN
StringFormat	dc.b	"%s",0
		EVEN
FormLongSStr	dc.b	"%02ld:%02ld:%02ld",0
		EVEN
FormLongNSStr	dc.b	"%02ld:%02ld",0
		EVEN
ScrDimmFormat	dc.b	"%2.2ld",0
		EVEN
FormMemString	dc.b	" C: %7ld   F: %8ld ",0
		EVEN
DoubleMemString	dc.b	"  C: %ld   F: %ld ",0
		EVEN
FormTMemString	dc.b	" Total Memory : %8ld ",0
		EVEN
FormSnapMemStr	dc.b	" Snapped  C: %7ld   F: %8ld ",0
		EVEN
MousePosForm	dc.b	"  X: %4.4d  Y: %4.4d",0
		EVEN
LogEntryFormat	dc.b	"%8.8s : %8.8s - %8.8s / Zone %ld Tariff %c / Time %02ld:%02ld:%02ld / Cost %ld.%02ld",$0a,0
		EVEN
FinalCostForm	dc.b	"                                                                  -----------",$0a
		dc.b	"                                                Total Sum              %ld.%02ld",$0a,0
		EVEN
DayCostForm	dc.b	"                                                                  -----------",$0a
		dc.b	"                                         Sum for %s               %ld.%02ld",$0a,$0a,0
		EVEN
ChipMem		dc.l	0
FastMem		dc.l	0
TotalMem	dc.l	0
NextUnit	dc.l	0
UnitsDone	dc.l	0
LogEntryDat	dc.l	LogInDate+ZeroPage
		dc.l	LogInTime+ZeroPage
		dc.l	TimeString+ZeroPage
TimeZone	dc.l	0
LogEntryTariff	dc.w	0
OnlineHour	dc.l	0
OnlineMinute	dc.l	0
OnlineSeconds	dc.l	0
CostMajor	dc.l	0
CostMinor	dc.l	0
BillTotalCost	dc.l	0
BillDayCost	dc.l	0
BillDayPtr	dc.l	BillDayStr
BillMajor	dc.l	0
BillMinor	dc.l	0
BillDayStr	ds.b	10
ThisChip	dc.l	0
ThisFast	dc.l	0




**********************************************************************
*                          The AppIcon-Icon                          *
**********************************************************************
KCXAppIconDef	dc.w	0,0

		dc.l	0				; Gadget structure
		dc.w	0,0
		dc.w	49,20
		dc.w	0,0,0
		dc.l	AppIconImg
		dc.l	0,0,0,0
		dc.w	0
		dc.l	0

		dc.b	0,0
		dc.l	0
		dc.l	0
IconXPos	dc.l	NO_ICON_POSITION		; Position of icon
IconYPos	dc.l	NO_ICON_POSITION
		dc.l	0
		dc.l	0
		dc.l	0

AppIconImg	dc.w	0,0				; Image structure
		dc.w	49,19
		dc.w	2
		dc.l	AppIconPic
		dc.b	3,0
		dc.l	0

MyAppIconText	dc.b	"KCommodity",0
		EVEN

**********************************************************************
*                 Structures for the Tools-MenuItem                  *
**********************************************************************
AppMenuTxt	dc.b	"KCX Main-Window",0
		EVEN
MAINITEM	EQU	1



		SECTION	Chips,DATA_C


**********************************************************************
*                           Sound of click                           *
**********************************************************************
ClickData	dc.w	-512,-256,-128,-64,-32,0,32,64,128,256,512
CLICKLEN	EQU	(*-ClickData)


**********************************************************************
*                         Clear sprite data                          *
**********************************************************************
NoSpriteDat	ds.l	1
		ds.l	1
		ds.l	1


**********************************************************************
*                         Busy pointer image                         *
**********************************************************************
BusyPtr		DC.W	$0000,$0000,$0400,$07C0,$0000,$07C0
		DC.W	$0100,$0380,$0000,$07E0,$07C0,$1FF8
		DC.W	$1FF0,$3FEC,$3FF8,$7FDE,$3FF8,$7FBE
		DC.W	$7FFC,$FF7F,$7EFC,$FFFF,$7FFC,$FFFF
		DC.W	$3FF8,$7FFE,$3FF8,$7FFE,$1FF0,$3FFC
		DC.W	$07C0,$1FF8,$0000,$07E0,$0000,$0000

AppIconPic	dc.w $0,$0,$1,$8000,$0,$0,$1,$8000
		dc.w $ff,$ffff,$fe01,$8000,$3aa,$aaaa,$ab81,$8000
		dc.w $2ff,$feaa,$aa81,$8000,$6be,$eeaa,$aac1,$8000
		dc.w $6be,$ebfa,$aac1,$8000,$6ba,$eafa,$aac1,$8000
		dc.w $6be,$eaee,$aac1,$8000,$6be,$eeff,$2ac1,$8000
		dc.w $6ff,$ffff,$cac1,$8000,$6aa,$aaab,$f2c1,$8000
		dc.w $6aa,$aaab,$fec1,$8000,$6aa,$aaab,$eac1,$8000
		dc.w $2aa,$aaab,$f281,$8000,$3aa,$aaaa,$fb81,$8000
		dc.w $ff,$ffff,$fc01,$8000,$0,$0,$601,$8000
		dc.w $7fff,$ffff,$ffff,$8000,$ffff,$ffff,$fffe,$0
		dc.w $d555,$5555,$5554,$0,$d500,$0,$154,$0
		dc.w $d4ff,$ffff,$fe54,$0,$d580,$81ff,$ff54,$0
		dc.w $d3c9,$19ff,$ff94,$0,$d3c3,$3e07,$ff94,$0
		dc.w $d3c7,$3f0f,$ff94,$0,$d3c3,$3f97,$ff94,$0
		dc.w $d3c9,$190b,$ff94,$0,$d380,$8203,$ff94,$0
		dc.w $d3ff,$fffd,$ff94,$0,$d3ff,$fffd,$ff94,$0
		dc.w $d3ff,$fffe,$ff94,$0,$d5ff,$fffe,$df54,$0
		dc.w $d4ff,$ffff,$6e54,$0,$d500,$0,$4754,$0
		dc.w $d555,$5555,$5354,$0,$8000,$0,$0,$0



**********************************************************************
*                              BBS-Hunk                              *
**********************************************************************
		SECTION	ZeroPage,BSS

		RSRESET
_IntuitionBase	rs.l	1
_GadToolsBase	rs.l	1
_GfxBase	rs.l	1
_UtilityBase	rs.l	1
_DOSBase	rs.l	1
_IconBase	rs.l	1
_LayersBase	rs.l	1
_RexxSysBase	rs.l	1
_AslBase	rs.l	1
_ConsoleBase	rs.l	1
_WorkBenchBase	rs.l	1
_IFFParseBase	rs.l	1
_ReqBase	rs.l	1
_ReqToolsBase	rs.l	1
_ArpBase	rs.l	1
WindowPort	rs.l	1
WindowPortSig	rs.l	1
AudioReq	rs.l	1
ConsoleReq	rs.l	1
InputReq	rs.l	1
AlarmReq	rs.l	1
OurTask		rs.l	1
MyToolTypes	rs.l	1
MyDiskObj	rs.l	1
WBMsg		rs.l	1
MyRDArgs	rs.l	1
Args		rs.l	1
BrokerPort	rs.l	1
AudioPort	rs.l	1
ARexxPort	rs.l	1
DoublePort	rs.l	1
AppPort		rs.l	1
InputPort	rs.l	1
EventMsg	rs.l	1
CheckerProc	rs.l	1
CheckerProcSig	rs.l	1
PrintProc	rs.l	1
MyBroker	rs.l	1
MsgType		rs.l	1
MsgID		rs.l	1
PopUpFilter	rs.l	1
PrefsFilter	rs.l	1
BillFilter	rs.l	1
HotKeyFilter	rs.l	1
MiscFilter	rs.l	1
FormFilter	rs.l	1
CycleFilter	rs.l	1
FKeyFilter	rs.l	1
PageFilter	rs.l	1
SnapFilter	rs.l	1
ShellFilter	rs.l	1
UmlautFilter	rs.l	1
DoBlankFilter	rs.l	1
DumpFilter	rs.l	1
SetFilter	rs.l	1
AlarmFilter	rs.l	1
BlankFilter	rs.l	1
ColsFilter	rs.l	1
MouseFilter	rs.l	1
LockFilter	rs.l	1
CenterFilter	rs.l	1
BrokerSigFlag	rs.l	1
ARexxSigFlag	rs.l	1
AlarmSigBit	rs.l	1
AlarmSigFlag	rs.l	1
FormatSigBit	rs.l	1
FormatSigFlag	rs.l	1
AppSigFlag	rs.l	1
DragSigBit	rs.l	1
DragSigFlag	rs.l	1
ThisSig		rs.l	1
RexxSig		rs.l	1
RexxProc	rs.l	1
ClockSigFlag	rs.l	1
MouseX		rs.l	1
MouseY		rs.l	1
ActWindow	rs.l	1
ClockHandle	rs.l	1
MainHandle	rs.l	1
MainGadget	rs.l	1
MainVisInfo	rs.l	1
MainMenu	rs.l	1
SetHandle	rs.l	1
SetGadget	rs.l	1
SetVisInfo	rs.l	1
SetMenu		rs.l	1
MiscHandle	rs.l	1
MiscGadget	rs.l	1
MiscVisInfo	rs.l	1
AlarmHandle	rs.l	1
AlarmGadget	rs.l	1
AlarmVisInfo	rs.l	1
QualHandle	rs.l	1
QualGadget	rs.l	1
QualVisInfo	rs.l	1
CycleHandle	rs.l	1
CycleGadget	rs.l	1
CycleVisInfo	rs.l	1
BlankHandle	rs.l	1
BlankGadget	rs.l	1
BlankVisInfo	rs.l	1
ColsHandle	rs.l	1
ColsGadget	rs.l	1
ColsVisInfo	rs.l	1
MouseHandle	rs.l	1
MouseGadget	rs.l	1
MouseVisInfo	rs.l	1
HotKeyHandle	rs.l	1
HotKeyGadget	rs.l	1
HotKeyVisInfo	rs.l	1
FKeyHandle	rs.l	1
FKeyGadget	rs.l	1
FKeyVisInfo	rs.l	1
FormHandle	rs.l	1
FormGadget	rs.l	1
FormVisInfo	rs.l	1
BillHandle	rs.l	1
BillGadget	rs.l	1
BillVisInfo	rs.l	1
BillSigFlag	rs.l	1
PrefsHandle	rs.l	1
PrefsGadget	rs.l	1
PrefsVisInfo	rs.l	1
LogHandle	rs.l	1
LogGadget	rs.l	1
LogVisInfo	rs.l	1
ProgHandle	rs.l	1
ProgGadget	rs.l	1
ProgVisInfo	rs.l	1
ProgRPort	rs.l	1
ProgDone	rs.l	1
ProgStep	rs.l	1
PrintHandle	rs.l	1
PrintGadget	rs.l	1
PrintVisInfo	rs.l	1
LockHandle	rs.l	1
LockGadget	rs.l	1
LockVisInfo	rs.l	1
BlankScrHandle	rs.l	1
DimmBase	rs.l	1
FileHand	rs.l	1
TempHand	rs.l	1
InHand		rs.l	1
OutHand		rs.l	1
OurLock		rs.l	1
PastLock	rs.l	1
QuitBroker	rs.w	1
ToolPri		rs.l	1
CxPri		rs.l	1
HandlerPri	rs.l	1
WinLeftEdge	rs.l	1
WinTopEdge	rs.l	1
MyBitMap	rs.l	1
MyRastPort	rs.l	1
MyFont		rs.l	1
BitMapWidth	rs.w	1
BitMapHeight	rs.w	1
BitMapDepth	rs.w	1
LeftEdge	rs.l	1
BlitWidth	rs.l	1
MyARexxMsg	rs.l	1
ARexxCommand	rs.l	1
ARexxAction	rs.l	1
AResult1	rs.l	1
AResult2	rs.l	1
IEClass		rs.w	1
IEvent		rs.l	1
ScreenOff	rs.l	1
MouseOff	rs.l	1
PageNum		rs.l	1
OldPageNum	rs.l	1
EWidth		rs.l	1
FWidth		rs.l	1
MyAslRequest	rs.l	1
KCXAppIcon	rs.l	1
KCXAppMenuItem	rs.l	1
DoActWindow	rs.l	1
DoActGadget	rs.l	1
ARexxBuffer	rs.l	1
LoadBuffer	rs.l	1
EventSigFlag	rs.l	1
EventSigBit	rs.l	1
SizeUse		rs.w	1
CheckX		rs.w	1
CheckY		rs.w	1
OldTimeSig	rs.l	1
OldCheckMicro	rs.l	1
DimmColors	rs.w	32
DimmedCols	rs.w	32
StatusNum	rs.l	1
ResultData	rs.l	1
ResultWinData	rs.w	2
HourStr		rs.b	8
FileName	rs.b	256
HandlerIRQ	rs.b	IS_SIZE
NewMsg		rs.b	62*5
Author		rs.b	42
Company		rs.b	42
MyDateTime	rs.b	dat_SIZEOF
DayString	rs.b	LEN_DATSTRING
DateString	rs.b	LEN_DATSTRING
TimeString	rs.b	LEN_DATSTRING
OnlineString	rs.b	LEN_DATSTRING
AllDayString	rs.b	LEN_DATSTRING
AllDateString	rs.b	LEN_DATSTRING
AllTimeString	rs.b	LEN_DATSTRING
RevDayString	rs.b	LEN_DATSTRING
RevDateString	rs.b	LEN_DATSTRING
RevTimeString	rs.b	LEN_DATSTRING
CopyTime	rs.b	LEN_DATSTRING
FinalString	rs.b	((LEN_DATSTRING*3)+10)
DosErrorBuff	rs.b	128
StrEditHook	rs.b	h_SIZEOF
LogInDate	rs.b	LEN_DATSTRING
LogInTime	rs.b	LEN_DATSTRING
DirPath		rs.b	256
DirFile		rs.b	40
MainGads	rs.l	20+1
SetGads		rs.l	18+1
MiscGads	rs.l	14+1
AlarmGads	rs.l	7+1
QualGads	rs.l	3+1
CycleGads	rs.l	10+1
BlankGads	rs.l	5+1
ColsGads	rs.l	4+1
MouseGads	rs.l	9+1
HotKeyGads	rs.l	2+1
FKeyGads	rs.l	14+1
FormGads	rs.l	11+1
BillGads	rs.l	7+1
PrefsGads	rs.l	23+1
LogGads		rs.l	9+1
PrintGads	rs.l	27+1
LockGads	rs.l	5+1
NumDrives	rs.w	1
DriveThere	rs.b	4
DriveChange	rs.l	4
DriveRequests	rs.l	4
DriveList	rs.l	4
FormatDrive	rs.w	1
TrackPort	rs.l	1
FormatCommand	rs.b	256
ThisFrontClick	rs.w	1
ThisBackClick	rs.w	1
ThisMiddleClick	rs.w	1
NewCode		rs.w	1
NewQual		rs.w	1
KeepCode	rs.w	1
ControlTitle	rs.b	20
PopUpKey	rs.b	42
SetTitle	rs.b	18
SetHotKey	rs.b	42
MiscTitle	rs.b	23
MiscHotKey	rs.b	43
AlarmTitle	rs.b	21
AlarmHotKey	rs.b	43
BlankTitle	rs.b	18
BlankHotKey	rs.b	42
ColsTitle	rs.b	16
ColsHotKey	rs.b	42
MouseTitle	rs.b	15
MouseHotKey	rs.b	43
HotKeyTitle	rs.b	17
HotKeyHotKey	rs.b	43
ToolPopUpKey	rs.b	42
PageHotKey	rs.b	42
BillTitle	rs.b	14
BillHotKey	rs.b	42
PrefsTitle	rs.b	20
PrefsHotKey	rs.b	43
ShellHotKey	rs.b	42
UmlautHotKey	rs.b	42
SnapHotKey	rs.b	42
DoBlankHotKey	rs.b	42
PrintTitle	rs.b	22
DumpHotKey	rs.b	42
FormTitle	rs.b	19
FormatHotKey	rs.b	43
CycleTitle	rs.b	24
CycleHotKey	rs.b	42
FKeyTitle	rs.b	23
FKeyHotKey	rs.b	43
LockTitle	rs.b	22
LockHotKey	rs.b	42
CenterHotKey	rs.b	42
QualTitle	rs.b	20
QualifierFor	rs.b	42
PubScreenName	rs.b	258
BillPubScr	rs.b	40
SystemComm	rs.b	256
LogFileName	rs.b	300
PrefsFileName	rs.b	300
FCycleSecs	rs.l	1
FCycleMicro	rs.l	1
BCycleSecs	rs.l	1
BCycleMicro	rs.l	1
MCycleSecs	rs.l	1
MCycleMicro	rs.l	1
CycledWin	rs.l	1
CycledScreen	rs.l	1
OldX		rs.w	1
OldY		rs.w	1
OldSysFont	rs.l	1
FKeys		rs.b	(MAXFKEYWIDTH+2)*10*4
FKeysNew	rs.b	(MAXFKEYWIDTH+2)*10*4
FKeyQual	rs.l	1
ErrorStr	rs.b	256
HotKeyChange	rs.l	1
HotKeyVisTop	rs.l	1
TotalCost	rs.l	1
MyIFFHandle	rs.l	1
AlarmSmpLen	rs.l	1
AlarmSmpStart	rs.l	1
AlarmHiSmp	rs.l	1
AlarmHiRep	rs.l	1
AlarmHiCyc	rs.l	1
AlarmSmpSec	rs.w	1
AlarmOctave	rs.w	1
AlarmVolume	rs.l	1
AlarmPort	rs.l	1
ThisHour	rs.l	1
PrintPort	rs.l	1
PrintReq	rs.l	1
GfxWindow	rs.l	1
GfxScreen	rs.l	1
ThisPrinter	rs.b	80
GfxSourceScr	rs.b	80
GfxSourceWin	rs.b	80
GfxRastPort	rs.l	1
GfxBoundScr	rs.l	1
GfxLeft		rs.l	1
GfxTop		rs.l	1
GfxWidth	rs.l	1
GfxHeight	rs.l	1
GfxDrawMode	rs.w	1
GfxRX		rs.l	1
GfxRY		rs.l	1
GfxRX2		rs.l	1
GfxRY2		rs.l	1
GfxDumpSig	rs.l	1
GfxDumpFlag	rs.l	1
ErrorNum	rs.l	1
EasyArg		rs.l	1
EasyArg2	rs.l	1
EscQualStr	rs.b	128
DragQualStr	rs.b	128
FrontQualStr	rs.b	128
MiddleQualStr	rs.b	128
BackQualStr	rs.b	128
QualQualStr	rs.b	128
HoldXQualStr	rs.b	128
HoldYQualStr	rs.b	128
TxtAttrFont	rs.b	40
PointerList	rs.b	(MAXPOINTERS*pt_SIZEOF)
ScreenList	rs.b	(MAXSCREENS*8)
MBlankWindow	rs.l	1
OldSetPointer			rs.l	1
OldClearPointer			rs.l	1
OldCloseWindow			rs.l	1
OldOpenScreen			rs.l	1
OldOpenScreenTagList		rs.l	1
OldScreenToFront		rs.l	1
OldScreenToBack			rs.l	1
OldWBenchToFront		rs.l	1
OldWBenchToBack			rs.l	1
OldCloseScreen			rs.l	1
OldAutoRequest			rs.l	1
OldEasyRequestArgs		rs.l	1
OldCreateUpfrontLayer		rs.l	1
OldCreateUpfrontHookLayer	rs.l	1
OldDeleteLayer			rs.l	1
OldMoveSizeLayer		rs.l	1
WindowBase	rs.b	MLH_SIZE
SelWindow	rs.w	1
TopWindow	rs.w	1
NumWindows	rs.w	1
RequestsOpen	rs.w	1
MySemaphore	rs.b	SS_SIZE
MaxMem		rs.l	1
EventPool	rs.b	req_SIZEOF*MAXEVENTS
**********************************************************************
*                Name of Sample to be used for alarm                 *
**********************************************************************
AlSampleName	rs.b	256
**********************************************************************
*                        Positions of windows                        *
**********************************************************************
MainWinLeft	rs.w	1
MainWinTop	rs.w	1
MainWinWidth	rs.w	1
MainWinHeight	rs.w	1
SetWinLeft	rs.w	1
SetWinTop	rs.w	1
SetWinWidth	rs.w	1
SetWinHeight	rs.w	1
MiscWinLeft	rs.w	1
MiscWinTop	rs.w	1
MiscWinWidth	rs.w	1
MiscWinHeight	rs.w	1
AlarmWinLeft	rs.w	1
AlarmWinTop	rs.w	1
AlarmWinWidth	rs.w	1
AlarmWinHeight	rs.w	1
QualWinLeft	rs.w	1
QualWinTop	rs.w	1
QualWinWidth	rs.w	1
QualWinHeight	rs.w	1
CycleWinLeft	rs.w	1
CycleWinTop	rs.w	1
CycleWinWidth	rs.w	1
CycleWinHeight	rs.w	1
BlankWinLeft	rs.w	1
BlankWinTop	rs.w	1
BlankWinWidth	rs.w	1
BlankWinHeight	rs.w	1
ColsWinLeft	rs.w	1
ColsWinTop	rs.w	1
ColsWinWidth	rs.w	1
ColsWinHeight	rs.w	1
MouseWinLeft	rs.w	1
MouseWinTop	rs.w	1
MouseWinWidth	rs.w	1
MouseWinHeight	rs.w	1
HotKeyWinLeft	rs.w	1
HotKeyWinTop	rs.w	1
HotKeyWinWidth	rs.w	1
HotKeyWinHeight	rs.w	1
FKeyWinLeft	rs.w	1
FKeyWinTop	rs.w	1
FKeyWinWidth	rs.w	1
FKeyWinHeight	rs.w	1
FormWinLeft	rs.w	1
FormWinTop	rs.w	1
FormWinWidth	rs.w	1
FormWinHeight	rs.w	1
BillWinLeft	rs.w	1
BillWinTop	rs.w	1
BillWinWidth	rs.w	1
BillWinHeight	rs.w	1
PrefsWinLeft	rs.w	1
PrefsWinTop	rs.w	1
PrefsWinWidth	rs.w	1
PrefsWinHeight	rs.w	1
LogWinLeft	rs.w	1
LogWinTop	rs.w	1
LogWinWidth	rs.w	1
LogWinHeight	rs.w	1
ProgWinLeft	rs.w	1
ProgWinTop	rs.w	1
ProgWinWidth	rs.w	1
ProgWinHeight	rs.w	1
ClockWinLeft	rs.w	1
ClockWinTop	rs.w	1
ClockWinWidth	rs.w	1
ClockWinHeight	rs.w	1
PrintWinLeft	rs.w	1
PrintWinTop	rs.w	1
PrintWinWidth	rs.w	1
PrintWinHeight	rs.w	1
LockWinLeft	rs.w	1
LockWinTop	rs.w	1
LockWinWidth	rs.w	1
LockWinHeight	rs.w	1
WINPOSLEN	EQU	__RS-MainWinLeft
**********************************************************************
*                        Non Bool-Qualifiers                         *
**********************************************************************
LONGQUALSTART	rs.b	0
ScreenTime	rs.l	1
MouseTime	rs.l	1
ClickVol	rs.l	1
DimmValue	rs.l	1
ExpFrames	rs.l	1
ImpFrames	rs.l	1
SizeFrames	rs.l	1
Accelerate	rs.l	1
ThresHold	rs.l	1
FrontCode	rs.w	1
FrontQual	rs.w	1
BackCode	rs.w	1
BackQual	rs.w	1
MiddleQual	rs.w	1
FrontClicks	rs.w	1
BackClicks	rs.w	1
MiddleClicks	rs.w	1
ESCQual		rs.w	1
HoldXQual	rs.w	1
HoldYQual	rs.w	1
CheapStart	rs.l	1
CheapStop	rs.l	1
SavedPage	rs.l	1
AlarmTime	rs.l	1
TextFrontPen	rs.l	1
TextBackPen	rs.l	1
GaugeFrontPen	rs.l	1
GaugeBackPen	rs.l	1
CostUnit1	rs.l	2
CostUnit2	rs.l	2
CostUnit3	rs.l	2
CostUnit	rs.l	1
FullDragQual	rs.w	1
GfxAspect	rs.l	1
GfxShade	rs.l	1
GfxDithering	rs.l	1
GfxScale	rs.l	1
GfxImage	rs.l	1
GfxDensity	rs.l	1
GfxThreshold	rs.l	1
GfxComplete	rs.l	1
GfxSource	rs.l	1
GfxOutWidth	rs.l	1
GfxOutHeight	rs.l	1
LONGQUAL	EQU	__RS-ScreenTime
**********************************************************************
*                      Bool flags for settings                       *
**********************************************************************
BOOLQUALSTART	rs.b	0
DoActivate	rs.b	1
SunMouse	rs.b	1
ShowClock	rs.b	1
DoShowTime	rs.b	1
ClockWin	rs.b	1
ShowSecs	rs.b	1
AmiDate		rs.b	1
ShowDay		rs.b	1
ShowDate	rs.b	1
ShortDay	rs.b	1
DoAlarm		rs.b	1
AutoCenter	rs.b	1
MMBShift	rs.b	1
GermanDays	rs.b	1
PointDates	rs.b	1
EveryHour	rs.b	1
DoShowAlarm	rs.b	1
AlarmSample	rs.b	1
SetEnv		rs.b	1
CycleWin	rs.b	1
KeyClick	rs.b	1
BillPopUp	rs.b	1
WBFront		rs.b	1
LeftyMouse	rs.b	1
ESCClose	rs.b	1
MapUmlaut	rs.b	1
ScreenDimm	rs.b	1
ExpWindows	rs.b	1
MouseAccel	rs.b	1
Zipped		rs.b	1
MakeIcons	rs.b	1
QuickFormat	rs.b	1
FFSDrive	rs.b	1
NoVerify	rs.b	1
Install		rs.b	1
EjectDrive	rs.b	1
WatchDisks	rs.b	1
MouseCenter	rs.b	1
LogCalls	rs.b	1
MouseEver	rs.b	1
Saturday	rs.b	1
Sunday		rs.b	1
Monday		rs.b	1
Tuesday		rs.b	1
Wednesday	rs.b	1
Thursday	rs.b	1
Friday		rs.b	1
FKeysOn		rs.b	1
FullDrag	rs.b	1
DriveNoClick	rs.b	1
ShowMouse	rs.b	1
GfxRed		rs.b	1
GfxGreen	rs.b	1
GfxBlue		rs.b	1
GfxCenter	rs.b	1
GfxSmooth	rs.b	1
GfxFormFeed	rs.b	1
GfxKeepAspect	rs.b	1
FLAGSET		EQU	__RS-DoActivate			; Size of Bool table
**********************************************************************
NoBillPDown	rs.b	1
MouseTimeOut	rs.b	1
ScrTimeOut	rs.b	1
OnlyLog		rs.b	1
LogInputEnd	rs.b	1
Disabled	rs.b	1
OldDisabled	rs.b	1
Online		rs.b	1
CheapMode	rs.b	1
DoRemakeCosts	rs.b	1
Scrolling	rs.b	1
FirstPrefs	rs.b	1
Snapped		rs.b	1
Moved		rs.b	1
DoPopUp		rs.b	1
TimeReset	rs.b	1
DispAppIcon	rs.b	1
PDispAppIcon	rs.b	1
DispAppMenu	rs.b	1
DontCheckTime	rs.b	1
SampleLoaded	rs.b	1
HadASample	rs.b	1
GfxGetting	rs.b	1
ImDragging	rs.b	1
DoBlankNow	rs.b	1
SumToFile	rs.b	1
GetNewWindow	rs.b	1
BillPopedUp	rs.b	1
Dumping		rs.b	1
GetSource	rs.b	1
_SIZEOF_PAGE	rs.w	0

ZeroPage	ds.b	_SIZEOF_PAGE
		END
