


;   ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;   ญญ                                                                ญญ
;   ญญ               Fenster V2.2 [ 14th.April.1990 ]                 ญญ
;   ญญ                                                                ญญ
;   ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;   ญญ                                                                ญญ
;   ญญ                     by Roger Fischlin                          ญญ
;   ญญ                        Steigerwaldweg 6                        ญญ
;   ญญ                        6450 Hanau 7                            ญญ
;   ญญ                        West Germany                            ญญ
;   ญญ                                                                ญญ
;   ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ
;   ญญ                                                                ญญ
;   ญญ    This program is freeware and may be freely distributed as   ญญ
;   ญญ             long as you don't gain any profit.                 ญญ
;   ญญ                                                                ญญ
;   ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ



	incdir   	"ram:include/"

	include	intuition/intuition.i
	include	intuition/intuition_lib.i
        	include 	exec/memory.i
	include	exec/exec_lib.i
	include	graphics/graphics_lib.i
	include	graphics/text.i
	include	libraries/dos_lib.i
	include	libraries/dos.i
	include	devices/printer.i
	include	XColor.i


FontFlag	set	0

SETAPEN	macro
	move.l	WindowPointer(pc),a1
	move.l	wd_RPort(a1),a1	
	moveq.l	\1,d0
	CALLGRAF	SetAPen
	endm

SETBPEN	macro
	move.l	WindowPointer(pc),a1
	move.l	wd_RPort(a1),a1	
	moveq.l	\1,d0
	CALLGRAF	SetBPen
	endm
SETDRMD	macro
 	move.l	WindowPointer(pc),a1
	move.l	wd_RPort(a1),a1	
	moveq.l	\1,d0
	CALLGRAF	SetDrMd
	endm

RECTFILL	macro
	move.l	WindowPointer(pc),a1
	move.l	wd_RPort(a1),a1	
	move.w	\1,d0
	move.w	\2,d1
	move.w	\3,d2
	move.w	\4,d3
	CALLGRAF	RectFill
	endm

BORDER	macro
	bra.s	MakeBox_\@
MakeBox2_\@	BOX	\1,\2,\3,\4,\5,0
MakeBox_\@	move.l	WindowPointer(pc),a0
	move.l	wd_RPort(a0),a0
	lea.l	MakeBox2_\@(pc),a1
	moveq.l	#0,d0
	moveq.l	#0,d1
	CALLINT	DrawBorder
	endm

WRITE	macro
	move.l	WindowPointer(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	a1,a3	
	move.w	\1,d0
	move.w	\2,d1
	CALLGRAF	Move
	move.l	a3,a1	
	moveq.l	\3,d0
	jsr	_LVOSetAPen(a6)
	lea.l	Write_Text\@(pc),a0
	move.l	a3,a1
	move.l	#Write_Ende\@-Write_Text\@,d0
	jsr	_LVOText(a6)
	bra	Write_Label\@
Write_Text\@	dc.b	\4
Write_Ende\@	dc.b	0
	even
Write_Label\@	nop
	endm



BOX	macro			; macro to create a border structure
	dc.w	0,0
	dc.b	\5,0,RP_JAM1,5
	dc.l	box_\@,\6
box_\@	dc.w	\1,\2,\3,\2,\3,\4,\1,\4,\1,\2
	endm

TEXT	macro			; macro to create a text structure	
	dc.b	2,0,RP_JAM1,0
	dc.w	\1+1,\2+1
	dc.l	TOPAZ_80,T_String\@,Text2_\@
Text2_\@	dc.b	\3,0,RP_JAM1,0
	dc.w	\1,\2
	dc.l	TOPAZ_80,T_String\@,0
T_String\@	dc.b	\4,0
	even


	IFEQ	FontFlag

TOPAZ_80	dc.l	T_80name
	dc.w	TOPAZ_EIGHTY
	dc.b	FS_NORMAL,FPF_ROMFONT
	even
T_80name	dc.b	"topaz.font",0

FontFlag	set	1
	endc
	endm


AUTOGADGET	macro
* \1,\2    x,y
* \3,\4    size
* \5,\6    colors (text & Box)
* \7       Text
* \8       ID
* \9       NextGadget

	dc.l	\9
	dc.w	\1,\2,\3,\4
	dc.w	GADGHCOMP,RELVERIFY,BOOLGADGET
	dc.l	AGadget\@_Box
	dc.l	0,AGadget\@_Text,0,0
	dc.w	\8,0,0
AGadget\@_Box	BOX	-1,-1,\3,\4,\5,0
	even

AG_T_String\@	dc.b	\7,0
AG_T_String\@_End	
	even
AGadget\@_Text	dc.b	2,0,RP_JAM1,0
	dc.w	(\3-(AG_T_String\@_End-AG_T_String\@-1)*8)/2+1,((\4-8)/2)+1
	dc.l	TOPAZ_80,AG_T_String\@,AG_Text2_\@

AG_Text2_\@	dc.b	\6,0,RP_JAM1,0
	dc.w	(\3-(AG_T_String\@_End-AG_T_String\@-1)*8)/2),(\4-8)/2
	dc.l	TOPAZ_80,AG_T_String\@,0

	
	IFEQ	FontFlag

TOPAZ_80	dc.l	T_80name
	dc.w	TOPAZ_EIGHTY
	dc.b	FS_NORMAL,FPF_ROMFONT
	even
T_80name	dc.b	"topaz.font",0

FontFlag	set	1
	endc
	endm






	include	"misc/easystart.i"
	
	clr.l	_ColorBase
	clr.l	_XColorBase
	bsr	OpenThem
	move.l	_ARPBase(pc),a1	
	cmp.l	#0,a1
	beq.s	.L1
	CALLEXEC	CloseLibrary
.L1	move.l	_ColorBase(pc),a1	
	cmp.l	#0,a1
	beq.s	.L2
	CALLEXEC	CloseLibrary
.L2	rts	


OpenThem	lea	dosname(pc),a1		; open libs
	moveq.l	#0,d0
	CALLEXEC 	OpenLibrary
	move.l	d0,_DOSBase	
	lea	intname(pc),a1                 
	moveq.l	#0,d0		
	CALLEXEC 	OpenLibrary
	move.l	d0,_IntuitionBase  
	lea	grafname(pc),a1
	moveq.l	#0,d0
	CALLEXEC 	OpenLibrary
	move.l	d0,_GfxBase
	
	lea	xcolorname(pc),a1	; try to use XColor.lib
	moveq.l	#0,d0
	CALLEXEC 	OpenLibrary
	move.l	d0,_XColorBase
	bne.s	.L1	
	lea	colorname(pc),a1	; if failed, try to use Color.lib
	moveq.l	#0,d0
	CALLEXEC 	OpenLibrary
	move.l	d0,_ColorBase
	tst.l	d0
	bne.s	.L1
	or.w	#GADGDISABLED,GadgetV2_33+gg_Flags
.L1	lea	arpname(pc),a1
	moveq.l	#0,d0
	CALLEXEC 	OpenLibrary
	move.l	d0,_ARPBase
	tst.l	d0
	bne	Init
	move.l	#RECOVERY_ALERT,d0	; error message
	move.l	#30,d1
	lea.l	NoARPText(pc),a0
	CALLINT	DisplayAlert
	moveq.l	#0,d0
	rts
NoARPText	dc.w	60
	dc.b	17
	dc.b	"FENSTER  :   ERROR !?!    I cannot open the ARP LIBRARY !"
	dc.b 	0,0

	rts

_DOSBase	dc.l	0
dosname	DOSNAME
_GfxBase	dc.l	0
grafname	GRAFNAME
_IntuitionBase	dc.l	0
intname	INTNAME
_XColorBase	dc.l	0
xcolorname	XCOLORNAME
arpname	dc.b	"arp.library",0
	even
_ARPBase	dc.l	0
colorname	dc.b	"color.library",0
	even
_ColorBase	dc.l	0

CloseThem	move.l	_DOSBase(pc),a1	; close libs
	CALLEXEC	CloseLibrary
	move.l	_GfxBase(pc),a1
	CALLEXEC	CloseLibrary
	move.l	_IntuitionBase(pc),a1
	CALLEXEC	CloseLibrary
	move.l	_ARPBase(pc),a1	
	cmp.l	#0,a1
	beq.s	.L1
	CALLEXEC	CloseLibrary
.L1	move.l	_ColorBase(pc),a1	
	cmp.l	#0,a1
	beq.s	.L2
	CALLEXEC	CloseLibrary
.L2	move.l	_XColorBase(pc),a1	
	cmp.l	#0,a1
	beq.s	.L3
	CALLEXEC	CloseLibrary
.L3	rts	
 
Window1	dc.l	0
Palette	dc.w	$443,$eee,$002,$f80

Start	lea.l	Screendef(pc),a0	; open Screen
	CALLINT	OpenScreen
	tst.l	d0
	beq	ende
	move.l	d0,ScreenPtr1

	move.l	d0,a0		; set colours
	lea.l	sc_ViewPort(a0),a0
	moveq.l	#4,d0
	lea.l	Palette(pc),a1
	CALLGRAF	LoadRGB4
	CALLINT	RemakeDisplay


	lea.l	Windowdef1(pc),a0		; open window	
	CALLINT	OpenWindow
	tst.l	d0
	beq	QUIT2
	move.l	d0,Window1

	
WindowPointer set Window1		;define Window1 as WindowPointer (for macros )


	SETDRMD	#RP_JAM1
	

ChangeScreen	SETAPEN	#0
	RECTFILL	#10+184,#10,#270+184,#165

	clr.l	Mode		; mode = select Screen
	bsr	ShowScreen		; Select Screen

	lea.l	Gadget1(pc),a0		
	move.l	Window1(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets



wait	move.l	Window1(pc),a0		; wait .....
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_Class(a1),d4	; get data
	move.w	im_Code(a1),d5
	move.l	im_IAddress(a1),a4
	moveq.l	#0,d6
	move.w	im_MouseY(a1),d6
	CALLEXEC 	ReplyMsg		; reply message		
	cmp.l	#MOUSEBUTTONS,d4
	bne.s	.Goon
	cmp.w	#MENUDOWN,d5
	beq	QUIT
.Goon	cmp.l	#VANILLAKEY,d4
	beq	KEY

	moveq.l	#0,d0		; use table to get subroutine		
	move.w	gg_GadgetID(a4),d0
	subq	#1,d0
	lsl.l	#2,d0
	lea.l	Vektoren(pc),a0
	tst.l	Mode
	bne	modus2	
	lea.l	VektorenScreen(pc),a0
modus2	move.l	(a0,d0),a0
	jmp	(a0)
Vektoren	dc.l	ChangeScreen,GetWindows,KillWindow,FRONT,BACK	; 1
	dc.l	CLEAR,FRAME,ALL,REFRESH,IDCMP			; 6
	dc.l	ABOUT,NewLimits,NewLimits,NewLimits,NewLimits	; 11
	dc.l	NewPen,MoveWindow,MoveWindow,SizeWindow,SizeWindow	; 16
	dc.l	NewPen,WindowSelect,PrintWindow,SaveWindow,ALL	; 21
	dc.l	wait,ScreenFRONT,ScreenBACK,SaveScreen,PrintScreen	; 26
	dc.l	ADD,SUB,ColReq,TOP,wait			; 31
	dc.l	wait,wait,wait,wait,wait

VektorenScreen	dc.l	ChangeScreen,ChangeScreen,Error,Error,Error
	dc.l	Error,Error,Error,Error,Error
	dc.l	ABOUT,Error,Error,Error,Error
	dc.l	Error,Error,Error,Error,Error
	dc.l	Error,ScreenSelect,wait,wait
	dc.l	Error,Error,Error,Error,Error
	dc.l	Error,Error,Error,Error,Error
	dc.l	Error,Error,Error,Error,Error
	
Error	move.l	ScreenPtr1(pc),a0
	CALLINT	DisplayBeep
	bra	wait


	
QUIT	move.l	Window1(pc),a0		; bye, bye !
	CALLINT	CloseWindow

	move.l	ScreenPtr1(pc),a0
	CALLINT	CloseScreen

	moveq.l	#0,d0
	rts

KEY	cmp.b	#"f",d5		; useful key pressed ?
	beq	KEY2
	cmp.b	#"s",d5
	bne	KEY3
	tst.l	Mode
	beq	wait

	move.l	BILDSCHIRM(pc),a0
	CALLINT	ScreenToFront
	bra	wait

KEY2	move.l	ScreenPtr1(pc),a0
	CALLINT	ScreenToFront
	bra	wait

KEY3	cmp.b	#"u",d5
	beq	UP
	cmp.b	#"d",d5
	bne	wait
	move.l	Top,d0	; move down
	add.l	#17,d0
	cmp.l	Anzahl,d0
	bge	wait
	add.l	#1,Top
	bra	ShowWindow


UP	tst.l	Top	; move up
	beq	wait
	sub.l	#1,Top
	bra	ShowWindow
	
	


Mode	dc.l	0


Screendef	dc.w	0,0,640,199,2
	dc.b	0,1
	dc.w	V_HIRES
	dc.w	CUSTOMSCREEN
	dc.l	TOPAZ_80
	dc.l	S_Title,0,0
	

Windowdef1	dc.w	0,0,640,199
	dc.b	-1,-1
	dc.l	GADGETUP!MOUSEBUTTONS!VANILLAKEY
	dc.l	WINDOWDRAG!WINDOWCLOSE!ACTIVATE!SMART_REFRESH!BACKDROP!RMBTRAP
	dc.l	GadgetV2_1
	dc.l	0
	dc.l	0
ScreenPtr1	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
S_Title	dc.b	"RF-Tools : FENSTER V2.2 by Roger Fischlin April/1990            ",0
	even

Gadget1	AUTOGADGET 	10,13+0*14,165,10,3,1,<"Show Screens">,1,Gadget2
	even
Gadget2	AUTOGADGET 	10,13+1*14,165,10,3,1,<"Update List">,2,Gadget3
	even
Gadget3	AUTOGADGET 	280+184,13+2*14,165,10,3,1,<"Close Window">,3,Gadget4
	even
Gadget4	AUTOGADGET 	280+184,13+3*14,165,10,3,1,<"Window To Front">,4,Gadget5
	even
Gadget5	AUTOGADGET 	280+184,13+4*14,165,10,3,1,<"Window To Back">,5,Gadget6
	even
Gadget6	AUTOGADGET 	280+184,13+5*14,165,10,3,1,<"Clear Pointer">,6,Gadget7
	even
Gadget7	AUTOGADGET 	280+184,13+6*14,165,10,3,1,<"Redraw Frame">,7,Gadget9
	even
Gadget9	AUTOGADGET 	280+184,13+7*14,165,10,3,1,<"Refresh Gadgets">,9,Gadget10
	even
Gadget10	AUTOGADGET 	280+184,13+8*14,165,10,3,1,<"Modify IDCMP">,10,Gadget11
	even
Gadget11	AUTOGADGET 	280+184,13+9*14+7,165,10,1,3,<"About Fenster">,11,Gadget12
	even



Gadget12	dc.l	Gadget13
	dc.w	55+184,185+3,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G12_Text,0,G12_Info
	dc.w	12,0,0
G12_box	BOX	-5,-4,36,12,1,G12_Box2
	even
G12_Box2	BOX	-5,-4,-55,12,1,0
	even
G12_Text	TEXT	-50,0,3,<"min.X">
	even
G12_Info	dc.l	G12_Puffer,G12_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G12_Puffer	ds.b	6
G12_Undo	ds.b	6

Gadget13	dc.l	Gadget14
	dc.w	5*8+150-45+1+184,185+3,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G13_Text,0,G13_Info
	dc.w	13,0,0
	even
G13_Text	TEXT	-50,0,3,<"min.Y">
	even
G13_Info	dc.l	G13_Puffer,G13_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G13_Puffer	ds.b	6
G13_Undo	ds.b	6

Gadget14	dc.l	Gadget15
	dc.w	5*8+250-10-45+2+184,185+3,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G14_Text,0,G14_Info
	dc.w	14,0,0
	even
G14_Text	TEXT	-50,0,3,<"max.X">
	even
G14_Info	dc.l	G14_Puffer,G14_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G14_Puffer	ds.b	6
G14_Undo	ds.b	6

Gadget15	dc.l	Gadget16
	dc.w	5*8+350-20-45+3+184,185+3,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G15_Text,0,G15_Info
	dc.w	15,0,0
	even
G15_Text	TEXT	-53,0,3,<"max.Y">
	even
G15_Info	dc.l	G15_Puffer,G15_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G15_Puffer	ds.b	6
G15_Undo	ds.b	6
Gadget16	dc.l	Gadget17
	dc.w	5*8+450-30-45+4+184,185+3,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G16_box
	dc.l	0,G16_Text,0,G16_Info
	dc.w	16,0,0
	even
G16_box	BOX	-5,-4,35,12,1,G16_Box2
	even
G16_Box2	BOX	-5,-4,-55,12,1,0
	even
G16_Text	TEXT	-50,0,3,<"BPen">
	even
G16_Info	dc.l	G16_Puffer,G16_Undo
	dc.w	0,3
	ds.b	si_SIZEOF
G16_Puffer	ds.b	6
G16_Undo	ds.b	6

Gadget17	dc.l	Gadget18
	dc.w	55+184,185+3-16,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G17_Text,0,G17_Info
	dc.w	17,0,0
G17_Text	TEXT	-50,0,3,<"X">
	even
G17_Info	dc.l	G17_Puffer,G17_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G17_Puffer	ds.b	6
G17_Undo	ds.b	6

Gadget18	dc.l	Gadget19
	dc.w	5*8+150-45+1+184,185+3-16,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G18_Text,0,G18_Info
	dc.w	18,0,0
	even
G18_Text	TEXT	-50,0,3,<"Y">
	even
G18_Info	dc.l	G18_Puffer,G18_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G18_Puffer	ds.b	6
G18_Undo	ds.b	6

Gadget19	dc.l	Gadget20
	dc.w	5*8+250-10-45+2+184,185+3-16,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G19_Text,0,G19_Info
	dc.w	19,0,0
	even
G19_Text	TEXT	-50,0,3,<"Width">
	even
G19_Info	dc.l	G19_Puffer,G19_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G19_Puffer	ds.b	6
G19_Undo	ds.b	6

Gadget20	dc.l	Gadget21
	dc.w	5*8+350-20-45+3+184,185+3-16,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G12_box
	dc.l	0,G20_Text,0,G20_Info
	dc.w	20,0,0
	even
G20_Text	TEXT	-53,0,3,<"Height">
	even
G20_Info	dc.l	G20_Puffer,G20_Undo
	dc.w	0,4
	ds.b	si_SIZEOF
G20_Puffer	ds.b	6
G20_Undo	ds.b	6
Gadget21	dc.l	0	
	dc.w	5*8+450-30-45+4+184,185+3-16,41,12
	dc.w	GADGHCOMP,RELVERIFY!LONGINT,STRGADGET
	dc.l	G16_box
	dc.l	0,G21_Text,0,G21_Info
	dc.w	21,0,0
	even
G21_Text	TEXT	-50,0,3,<"DPen">
	even
G21_Info	dc.l	G21_Puffer,G21_Undo
	dc.w	0,3
	ds.b	si_SIZEOF
G21_Puffer	ds.b	6
G21_Undo	ds.b	6
	even
GadgetV2_1
Gadget22	dc.l	GadgetV2_23
	dc.w	10+184,32-6,240+16,128+8
	dc.w	GADGHNONE,RELVERIFY!LONGINT,BOOLGADGET
	dc.l	0
	dc.l	0,0,0,0
	dc.w	22,0,0
	even


GadgetV2_23	AUTOGADGET 	280+184,13+0*14,165,10,3,1,<"Print Window">,23,GadgetV2_24
	even
GadgetV2_24	AUTOGADGET 	280+184,13+1*14,165,10,3,1,<"Save Window">,24,GadgetV2_25
	even
GadgetV2_25	AUTOGADGET 	10,13+2*14,165,10,3,1,<"Close Screen">,25,GadgetV2_27
	even
GadgetV2_27	AUTOGADGET 	10,13+3*14,165,10,3,1,<"Screen To Front">,27,GadgetV2_28
	even
GadgetV2_28	AUTOGADGET 	10,13+4*14,165,10,3,1,<"Screen To Back">,28,GadgetV2_29
	even
GadgetV2_29	AUTOGADGET 	10,13+5*14,165,10,3,1,<"Save Screen">,29,GadgetV2_30
	even
GadgetV2_30	AUTOGADGET 	10,13+6*14,165,10,3,1,<"Print Screen">,30,GadgetV2_31
	even
GadgetV2_31	AUTOGADGET 	10,13+7*14,165,10,3,1,<"Add Bitplane">,31,GadgetV2_32
	even
GadgetV2_32	AUTOGADGET 	10,13+8*14,165,10,3,1,<"Sub Bitplane">,32,GadgetV2_33
	even
GadgetV2_33	AUTOGADGET 	10,13+10*14,165,10,3,1,<"Colour Requester">,33,GadgetV2_34
	even
GadgetV2_34	AUTOGADGET 	10,13+9*14,165,10,3,1,<"Move To Left Edge">,34,Gadget1
	even



Windowdef3	dc.w	(640-300)/2,25,300,120
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	Gadget_About
	dc.l	0
	dc.l	W3_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W3_Title	dc.b	"        ป ABOUT  FENSTER ซ           ",0
	even
Gadget_About	AUTOGADGET 	20,100,260,12,3,1,<"Exit">,0,0
	even



Window2	dc.l	0


ABOUT	lea.l	Windowdef3(pc),a0	; about FENSTER
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	wait
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#297,#118

	SETDRMD	#RP_JAM1
	WRITE	#6+((290-23*8)/2),#20+1,#0,<"RF-Tools : FENSTER V2.2">
	WRITE	#6+((290-31*8)/2),#29+1,#0,<"This utility is public domain !">
	WRITE	#6+((290-24*8)/2),#40+1,#0,<"by: Roger Fischlin  ">
	WRITE	#6+((290-24*8)/2),#49+1,#0,<"    Steigerwaldweg 6">
	WRITE	#6+((290-24*8)/2),#58+1,#0,<"    D-6450 Hanau 7">
	WRITE	#6+((290-24*8)/2),#67+1,#0,<"    West Germany">
	WRITE	#6+((290-32*8)/2),#86+1,#0,<"How about reading the doc file ?">


	WRITE	#5+((290-23*8)/2),#20,#1,<"RF-Tools : FENSTER V2.2">
	WRITE	#5+((290-31*8)/2),#29,#1,<"This utility is public domain !">
	WRITE	#5+((290-24*8)/2),#40,#3,<"by: Roger Fischlin  ">
	WRITE	#5+((290-24*8)/2),#49,#3,<"    Steigerwaldweg 6">
	WRITE	#5+((290-24*8)/2),#58,#3,<"    D-6450 Hanau 7">
	WRITE	#5+((290-24*8)/2),#67,#3,<"    West Germany">
	WRITE	#5+((290-32*8)/2),#86,#1,<"How about reading the doc file ?">
	
	lea.l	Gadget_About(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets


	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	CALLEXEC	WaitPort

	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	bra	wait


Zeile	dc.b	"                   ... x ..  x .    ",0

	even


* Ask User to select screen .... 
	
WindowPointer set Window1


ShowScreen	moveq.l	#0,d0
	move.b	d0,G12_Puffer
	move.b	d0,G13_Puffer
	move.b	d0,G14_Puffer
	move.b	d0,G15_Puffer
	move.b	d0,G16_Puffer
	move.b	d0,G17_Puffer
	move.b	d0,G18_Puffer
	move.b	d0,G19_Puffer
	move.b	d0,G20_Puffer
	move.b	d0,G21_Puffer

	lea.l	Gadget12(pc),a0		
	move.l	Window1(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets


	WRITE	#10+184,#20,#2,<"        Select Screen">
	WRITE	#11+184,#19,#1,<"        Select Screen">
	WRITE	#10+184,#26,#2,<"--------------------------------">
	WRITE	#11+184,#25,#1,<"--------------------------------">
	
	SETAPEN	#3
	moveq.l	#0,d5		; get pointer to first screen
	move.l	_IntuitionBase,a6
	move.l	ib_FirstScreen(a6),a5
	lea.l	Pointer(pc),a3
	clr.l	Anzahl
	clr.l	Top

.SS1	move.l	sc_DefaultTitle(a5),a4	; get screen title
	lea.l	Zeile(pc),a0		; up to 32 characters
	move.b	#"?",(a0)+
	move.l	#30,d0
.SS5	move.b	#" ",(a0)+
	dbra	d0,.SS5
	move.b	#"x",Zeile+59-32-4
	move.b	#"x",Zeile+63-32-2
	
	lea.l	Zeile(pc),a0

.SS2	tst.b	(a4)		; leave out spaces
	beq	.SS3
	cmp.b	#" ",(a4)+
	beq	.SS2
	tst.b	-(a4)
	beq	.SS3
	move.l	#21,d0
.SS4	move.b	(a4)+,d1
	beq	.SS3
	move.b	d1,(a0)+
	dbra	d0,.SS4

.SS3	moveq.l	#0,d0		; write screen width & height
	move.w	sc_Width(a5),d0
	lea.l	Zeile+54-32-4(pc),a0
	bsr	MakeZahl	
	moveq.l	#0,d0
	move.w	sc_Height(a5),d0
	lea.l	Zeile+60-32-4,a0
	bsr	MakeZahl	
	lea.l	sc_BitMap(a5),a0
	move.b	bm_Depth(a0),d0
	add.b	#"0",d0
	move.b	d0,Zeile+63-32	
		


	move.l	Window1(pc),a1		
	move.l	wd_RPort(a1),a1
	move.l	#10+184,d0
	move.l	d5,d1
	lsl.l	#3,d1
	add.l	#32,d1
	CALLGRAF	Move
	lea.l	Zeile(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#33,d0
	CALLGRAF	Text
	addq.l	#1,Anzahl
	
	move.l	a5,(a3)+		; any more screens ?
	move.l	(a5),a5
	cmp.l	#0,a5
	beq	.SS6
	
	addq	#1,d5
	cmp.w	#14,d5		; up to 14 screens (DID YOU HAVE HAD MORE THAN 14 SCREENS ?!?)
	bne	.SS1
.SS6	rts

Top	dc.l	0		; nummer of first pointer on display
Anzahl	dc.l	0		; number of pointers displayed
FENSTER	dc.l	0		; pointer to current window
BILDSCHIRM	dc.l	0		; pointer to current screen
Pointer	ds.l	20*5		; array containing the window pointers 


MakeZahl	moveq.l	#3,d2		; convert number (<1024)  into ASCII text 
	moveq.l	#0,d3
	lea.l	.Potenzen(pc),a1
.MZ1	move.b	#"0"-1,d1
.MZ2	addq	#1,d1
	sub.l	(a1),d0
	bcc.s	.MZ2
	add.l	(a1)+,d0
	tst.b	d2
	beq.s	.MZ3
	cmp.b	#"0",d1
	beq.s	.MZ4
	moveq.l	#1,d3
	bra.s	.MZ3
.MZ4	tst.b	d3
	bne.s	.MZ3
	move.b	#" ",d1
.MZ3	move.b	d1,(a0)+
	dbra	d2,.MZ1
	rts
.Potenzen	dc.l	1000
	dc.l	100
	dc.l	10
	dc.l	1

MakeZahl3	moveq.l	#2,d2	; convert number (<1000)  into ASCII text
	moveq.l	#0,d3
	lea.l	.Potenzen(pc),a1
.MZ1	move.b	#"0"-1,d1
.MZ2	addq	#1,d1
	sub.l	(a1),d0
	bcc.s	.MZ2
	add.l	(a1)+,d0
	tst.b	d2
	beq.s	.MZ3
	cmp.b	#"0",d1
	beq.s	.MZ4
	moveq.l	#1,d3
	bra	.MZ3
.MZ4	tst.b	d3
	beq.s	.MZ5
.MZ3	move.b	d1,(a0)+
.MZ5	dbra	d2,.MZ1
	clr.b	(a0)
	rts
.Potenzen	dc.l	100
	dc.l	10
	dc.l	1

MakeZahl2	moveq.l	#1,d2	; convert number (<99)  into ASCII text
	moveq.l	#0,d3
	lea.l	.Potenzen(pc),a1
.MZ1	move.b	#"0"-1,d1
.MZ2	addq	#1,d1
	sub.l	(a1),d0
	bcc.s	.MZ2
	add.l	(a1)+,d0
	tst.b	d2
	beq.s	.MZ3
	cmp.b	#"0",d1
	beq	.MZ4
	moveq.l	#1,d3
	bra.s	.MZ3
.MZ4	tst.b	d3
	beq.s	.MZ5
.MZ3	move.b	d1,(a0)+
.MZ5	dbra	d2,.MZ1
	clr.b	(a0)
	rts
.Potenzen	dc.l	10
	dc.l	1

GetLine	sub.w	gg_TopEdge(a4),d6	; calculate which screen / window was selected  
	lsr.w	#3,d6
	and.l	#$ffff,d6
	move.l	Anzahl(pc),d0
	add.l	Top,d6
	cmp.l	d0,d6
	bge	.GetLine1
	lea.l	Pointer(pc),a0
	lsl.l	#2,d6
	move.l	(a0,d6),a0		; a0 contains pointer
	moveq.l	#0,d0
	rts
.GetLine1	moveq.l	#-1,d0		; error - user selected space
	rts

ScreenSelect	bsr	GetLine		; list windows of selected screen	
	tst.l	d0
	bne	wait
	move.l	a0,a5
	move.l	a5,BILDSCHIRM
	
	SETAPEN	#0
	RECTFILL	#10+184,#10,#270+184,#165
	WRITE	#10+184,#26,#2,<"--------------------------------">
	WRITE	#11+184,#25,#1,<"--------------------------------">
	
.SS1	move.l	sc_DefaultTitle(a5),a4	; get screen title
	lea.l	Zeile(pc),a0		; up to 32 characters
	move.b	#"?",(a0)+
	move.w	#30,d0
.SS5	move.b	#" ",(a0)+
	dbra	d0,.SS5
	move.b	#"x",Zeile+59-32-4
	move.b	#"x",Zeile+63-32-2
	
	lea.l	Zeile(pc),a0

.SS2	tst.b	(a4)		; leave out spaces
	beq.s	.SS3
	cmp.b	#" ",(a4)+
	beq.s	.SS2
	tst.b	-(a4)
	beq.s	.SS3
	move.l	#21,d0
.SS4	move.b	(a4)+,d1
	beq.s	.SS3
	move.b	d1,(a0)+
	dbra	d0,.SS4

.SS3	moveq.l	#0,d0		; write screen width & height
	move.w	sc_Width(a5),d0
	lea.l	Zeile+54-32-4(pc),a0
	bsr	MakeZahl	
	moveq.l	#0,d0
	move.w	sc_Height(a5),d0
	lea.l	Zeile+60-32-4(pc),a0
	bsr	MakeZahl	
	lea.l	sc_BitMap(a5),a0
	move.b	bm_Depth(a0),d0
	add.b	#"0",d0
	move.b	d0,Zeile+63-32	
			

	SETAPEN	#2
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.w	#10+1+184,d0
	move.w	#19+1,d1
	CALLGRAF	Move
	lea.l	Zeile(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#33,d0
	CALLGRAF	Text
	
	SETAPEN	#1
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.w	#10+184,d0
	move.w	#19,d1
	CALLGRAF	Move
	lea.l	Zeile(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#33,d0
	CALLGRAF	Text

	move.l	#1,Mode


GetWindows	SETAPEN	#0		; store all windows on the screen in array and print their names 
	RECTFILL	#10+184,#25,#270+184,#165
	move.l	BILDSCHIRM(pc),a5
	clr.l	FENSTER		
	lea.l	Pointer(pc),a1
	move.l	#20*5,d0
	clr.l	Top
	clr.l	Anzahl
	clr.l	Pointer
	move.l	sc_FirstWindow(a5),a5
.Loop	cmp.l	#0,a5
	beq.s	.Loop2
.Loop3	move.l	a5,(a1)+
	addq.l	#1,Anzahl
	move.l	(a5),a5
	dbra	d0,.Loop
.Loop2	move.l	Pointer(pc),FENSTER	; define first window as already selected

	bsr	FillIn		; Fill in the gadgets on the bottom

ShowWindow	SETAPEN	#3
	SETBPEN	#0
	SETDRMD	#RP_JAM2

	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.w	#10+184,d0
	move.w	#32,d1
	CALLGRAF	Move
	lea.l	ClearZeile(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#32,d0
	CALLGRAF	Text


	moveq.l	#0,d5
	lea.l	Pointer(pc),a3
	move.l	Top(pc),d4
	lsl.l	#2,d4
	add.l	d4,a3

.SS1	move.l	d5,d0
	add.l	Top(pc),d0
	cmp.l	Anzahl(pc),d0
	bge	.SS6
	
	SETBPEN	#0
	move.l	(a3)+,a5
	cmp.l	FENSTER(pc),a5
	bne	.SS0
	SETBPEN	#2

.SS0	move.l	wd_Title(a5),a4	; title up to 31 characters
	lea.l	Zeile(pc),a0
	move.b	#"?",(a0)+
	move.w	#30,d0
.SS5	move.b	#" ",(a0)+
	dbra	d0,.SS5
	lea.l	Zeile(pc),a0

.SS2	tst.b	(a4)
	beq.s	.SS3
	cmp.b	#" ",(a4)+
	beq.s	.SS2
	tst.b	-(a4)
	beq.s	.SS3
	move.l	#31,d0
.SS4	move.b	(a4)+,d1
	beq.s	.SS3
	move.b	d1,(a0)+
	dbra	d0,.SS4

.SS3	
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#10+184,d0
	move.l	d5,d1
	lsl.w	#3,d1
	add.w	#32,d1
	CALLGRAF	Move
	lea.l	Zeile(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.l	#32,d0
	CALLGRAF	Text

	addq	#1,d5
	cmp.w	#17,d5
	bne	.SS1
.SS6	SETDRMD	#RP_JAM1
	bra	wait


ClearZeile	dc.b	"                                     "
	even

WindowSelect	bsr	GetLine	; which window was selected ?	
	tst.l	d0
	bne	wait
	move.l	a0,FENSTER
	bsr	FillIn

	bra	ShowWindow


FRONT	move.l	FENSTER(pc),a0	; move window to front
	cmp.l	#0,a0
	beq	Error
	CALLINT	WindowToFront
	bra	wait
BACK	move.l	FENSTER(pc),a0	;  "    "     " back
	cmp.l	#0,a0
	beq	Error
	CALLINT	WindowToBack
	bra	wait
CLEAR	move.l	FENSTER(pc),a0	; clear pointer
	cmp.l	#0,a0
	beq	Error
	CALLINT	ClearPointer
	bra	wait

NewLimits	move.l	FENSTER(pc),a0	; define new limits
	cmp.l	#0,a0
	beq	Error
	moveq.l	#0,d0
	moveq.l	#0,d1
	moveq.l	#0,d2
	moveq.l	#0,d3

	move.w	G12_Info+si_LongInt+2(pc),d0	
	move.w	G13_Info+si_LongInt+2(pc),d1	
	move.w	G14_Info+si_LongInt+2(pc),d2	
	move.w	G15_Info+si_LongInt+2(pc),d3
	
	CALLINT	WindowLimits
	bra	wait	

NewPen	move.l	FENSTER(pc),a0 	; define new pens
	cmp.l	#0,a0
	beq	Error
	move.b	G16_Info+si_LongInt+3(pc),wd_BlockPen(a0)
	move.b	G21_Info+si_LongInt+3(pc),wd_DetailPen(a0)


FRAME	move.l	FENSTER(pc),a0
	cmp.l	#0,a0
	beq	Error
	CALLINT	RefreshWindowFrame	; use them !
	bra	wait
REFRESH	move.l	FENSTER(pc),a1		; refresh gadgets (if there are any to be refreshed !)
	cmp.l	#0,a1
	beq	Error
	move.l	wd_FirstGadget(a1),a0
	sub.l	a2,a2
	cmp.l	#0,a0
	beq	Error
	CALLINT	RefreshGadgets
	bra	wait

FillIn	move.l	FENSTER(pc),a6		; put data from window into longint gadgets
	cmp.l	#0,a6
	beq	.Label1
	
	lea.l	G12_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_MinWidth(a6),d0

	move.l	d0,G12_Info+si_LongInt

	bsr	MakeZahl3
	
	lea.l	G13_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_MinHeight(a6),d0
	move.l	d0,G13_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G14_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_MaxWidth(a6),d0
	cmp.w	#999,d0
	bls	.Label3
	moveq.l	#0,d0
.Label3	move.l	d0,G14_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G15_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_MaxHeight(a6),d0
	cmp.w	#999,d0
	bls	.Label4
	moveq.l	#0,d0
.Label4	move.l	d0,G15_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G17_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_LeftEdge(a6),d0
	move.l	d0,G17_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G18_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_TopEdge(a6),d0
	move.l	d0,G18_Info+si_LongInt

	bsr	MakeZahl3


	lea.l	G19_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_Width(a6),d0
	move.l	d0,G19_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G20_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_Height(a6),d0
	move.l	d0,G20_Info+si_LongInt

	bsr	MakeZahl3

	
	lea.l	G16_Puffer(pc),a0
	moveq.l	#0,d0
	move.b	wd_BlockPen(a6),d0
	move.l	d0,G16_Info+si_LongInt

	bsr	MakeZahl2

	lea.l	G21_Puffer(pc),a0
	moveq.l	#0,d0
	move.b	wd_DetailPen(a6),d0
	move.l	d0,G21_Info+si_LongInt

	bsr	MakeZahl2

	lea.l	Gadget12(pc),a0
	move.l	Window1(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets
	rts

.Label1	clr.b	G12_Puffer
	clr.b	G13_Puffer
	clr.b	G14_Puffer
	clr.b	G15_Puffer
	clr.b	G16_Puffer
	clr.b	G17_Puffer
	clr.b	G18_Puffer
	clr.b	G19_Puffer
	clr.b	G20_Puffer
	clr.b	G21_Puffer
	
	lea.l	Gadget12(pc),a0
	move.l	Window1(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets
	rts



Windowdef4	dc.w	(640-300)/2,45,300,80
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	GadgetGURU
	dc.l	0
	dc.l	W4_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W4_Title	dc.b	"          ป ERROR MESSAGE ซ           ",0
	even
GadgetGURU	AUTOGADGET 	20,60,260,12,3,1,<"Exit">,0,0
	even

GURU	lea.l	Windowdef4(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	Undo
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#297,#78

	SETDRMD	#RP_JAM1
	WRITE	#6+((290-32*8)/2),#20+1,#0,<"Sorry - But if I moved / resized">
	WRITE	#6+((290-29*8)/2),#30+1,#0,<"the window , the system would">
	WRITE	#6+((290-30*8)/2),#40+1,#0,<"crash !!!  Check screen size !">

	WRITE	#5+((290-32*8)/2),#20,#1,<"Sorry - But if I moved / resized">
	WRITE	#5+((290-29*8)/2),#30,#1,<"the window , the system would">
	WRITE	#5+((290-30*8)/2),#40,#1,<"crash !!!  Check screen size !">


	
	lea.l	GadgetGURU(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets

	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	CALLEXEC	WaitPort

	move.l	Window2(pc),a0
	CALLINT	CloseWindow

Undo	move.l	FENSTER(pc),a6		; get current data (to undo illegal data) 
	lea.l	G17_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_LeftEdge(a6),d0
	move.l	d0,G17_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G18_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_TopEdge(a6),d0
	move.l	d0,G18_Info+si_LongInt

	bsr	MakeZahl3


	lea.l	G19_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_Width(a6),d0
	move.l	d0,G19_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	G20_Puffer(pc),a0
	moveq.l	#0,d0
	move.w	wd_Height(a6),d0
	move.l	d0,G20_Info+si_LongInt

	bsr	MakeZahl3

	lea.l	Gadget17(pc),a0
	move.l	Window1(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets

	bra	wait
	
WindowPointer set Window1

MoveWindow	move.l	FENSTER(pc),a0		; move window
	move.l	G17_Info+si_LongInt(pc),d0
	move.l	G18_Info+si_LongInt(pc),d1

	move.l	d0,d2
	move.l	d1,d3

	add.w	wd_Width(a0),d2
	add.w	wd_Height(a0),d3

	move.l	wd_WScreen(a0),a1

	cmp.w	sc_Width(a1),d2	; check if they are possible !!!!
	bhi	GURU
	cmp.w	sc_Height(a1),d3
	bhi	GURU
	
	sub.w	wd_LeftEdge(a0),d0
	sub.w	wd_TopEdge(a0),d1

	CALLINT	MoveWindow
	bra	wait

SizeWindow	move.l	FENSTER(pc),a0		; re-size window
	move.l	G19_Info+si_LongInt(pc),d0
	move.l	G20_Info+si_LongInt(pc),d1

	move.l	d0,d2
	move.l	d1,d3

	add.w	wd_LeftEdge(a0),d2
	add.w	wd_TopEdge(a0),d3

	move.l	wd_WScreen(a0),a1

	cmp.w	sc_Width(a1),d2	; check if they are possible !!!!
	bhi	GURU
	cmp.w	sc_Height(a1),d3
	bhi	GURU
	
	sub.w	wd_Width(a0),d0
	sub.w	wd_Height(a0),d1

	CALLINT	SizeWindow
	bra	wait	
	


Windowdef5	dc.w	275+184,30,174,100
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	GadgetKILL1
	dc.l	0
	dc.l	W5_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W5_Title	dc.b	" ป KILL WINDOW ซ     ",0
	even
GadgetKILL1	AUTOGADGET 	10,60,154,12,3,1,<"YES !">,0,GadgetKILL2
	even
GadgetKILL2	AUTOGADGET 	10,80,154,12,3,1,<"No - forget it !">,1,0
	even

KillWindow	tst.l	FENSTER
	beq	Error

	lea.l	Windowdef5(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	KILL_IT
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#171,#98

	SETDRMD	#RP_JAM1
	WRITE	#1+((174-18*8)/2),#20+1,#0,<"Do you really want">
	WRITE	#1+((174-18*8)/2),#30+1,#0,<"to    close    the">
	WRITE	#1+((174-18*8)/2),#40+1,#0,<"     window ?     ">

	WRITE	#0+((174-18*8)/2),#20,#1,<"Do you really want">
	WRITE	#0+((174-18*8)/2),#30,#1,<"to    close    the">
	WRITE	#0+((174-18*8)/2),#40,#1,<"     window ?     ">
	

	lea.l	GadgetKILL1(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets

	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		

	tst.w	gg_GadgetID(a4)
	beq	KILL_IT

	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	bra	wait

KILL_IT	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	move.l	FENSTER(pc),a0
	CALLINT	CloseWindow
	bra	GetWindows

Windowpointer	set Window1


	

AUTOGADGET2	macro
* \1,\2    x,y
* \3,\4    size
* \5,\6    colors (text & Box)
* \7       Text
* \8       ID
* \9       NextGadget

	dc.l	\9
	dc.w	\1,\2,\3,\4
	dc.w	GADGHCOMP!SELECTED,RELVERIFY!TOGGLESELECT,BOOLGADGET
	dc.l	AG2adget\@_Box
	dc.l	0,AG2adget\@_Text,0,0
	dc.w	\8,0,0
AG2adget\@_Box	BOX	-1,-1,\3,\4,\5,0
	even

AG2_T_String\@	dc.b	\7,0
AG2_T_String\@_End	
	even
AG2adget\@_Text	dc.b	2,0,RP_JAM1,0
	dc.w	(\3-(AG2_T_String\@_End-AG2_T_String\@-1)*8)/2+1,((\4-8)/2)+1
	dc.l	TOPAZ_80,AG2_T_String\@,AG2_Text2_\@

AG2_Text2_\@	dc.b	\6,0,RP_JAM1,0
	dc.w	(\3-(AG2_T_String\@_End-AG2_T_String\@-1)*8)/2),(\4-8)/2
	dc.l	TOPAZ_80,AG2_T_String\@,0

	
	IFEQ	FontFlag

TOPAZ_80	dc.l	T_80name
	dc.w	TOPAZ_EIGHTY
	dc.b	FS_NORMAL,FPF_ROMFONT
	even
T_80name	dc.b	"topaz.font",0

FontFlag	set	1
	endc
	endm




Windowdef6	dc.w	640-300-10,0,300,199
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	GadgetIDCMP
	dc.l	0
	dc.l	W6_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W6_Title	dc.b	"          ป IDCMP FLAGS ซ                  ",0
	even
GadgetIDCMP	AUTOGADGET2 	20,20,120,10,3,1,<"SIZEVERIFY">,0,GadgetIDCMP2
	even
GadgetIDCMP2	AUTOGADGET2 	20,35,120,10,3,1,<"NEWSIZE">,1,GadgetIDCMP3
	even
GadgetIDCMP3	AUTOGADGET2 	20,50,120,10,3,1,<"REFRESHWINDOW">,2,GadgetIDCMP4
	even
GadgetIDCMP4	AUTOGADGET2 	20,65,120,10,3,1,<"MOUSEBUTTONS">,3,GadgetIDCMP5
	even
GadgetIDCMP5	AUTOGADGET2 	20,80,120,10,3,1,<"MOUSEMOVE">,4,GadgetIDCMP6
	even
GadgetIDCMP6	AUTOGADGET2 	20,95,120,10,3,1,<"GADGETDOWN">,5,GadgetIDCMP7
	even
GadgetIDCMP7	AUTOGADGET2 	20,110,120,10,3,1,<"GADGETUP">,6,GadgetIDCMP8
	even
GadgetIDCMP8	AUTOGADGET2 	20,125,120,10,3,1,<"REQSET">,7,GadgetIDCMP9
	even
GadgetIDCMP9	AUTOGADGET2 	20,140,120,10,3,1,<"MENUPICK">,8,GadgetIDCMP10
	even
GadgetIDCMP10	AUTOGADGET2 	20,155,120,10,3,1,<"CLOSEWINDOW">,9,GadgetIDCMP11
	even
GadgetIDCMP11	AUTOGADGET2 	20,170,120,10,3,1,<"RAWKEY">,10,GadgetIDCMP12
	even
GadgetIDCMP12	AUTOGADGET2 	20,185,120,10,3,1,<"REQVERIFY">,11,GadgetIDCMP13
	even

GadgetIDCMP13	AUTOGADGET2 	160,20,120,10,3,1,<"REQCLEAR">,12,GadgetIDCMP14
	even
GadgetIDCMP14	AUTOGADGET2 	160,35,120,10,3,1,<"MENUVERIFY">,13,GadgetIDCMP15
	even
GadgetIDCMP15	AUTOGADGET2 	160,50,120,10,3,1,<"NEWPREFS">,14,GadgetIDCMP16
	even
GadgetIDCMP16	AUTOGADGET2 	160,65,120,10,3,1,<"DISKINSERTED">,15,GadgetIDCMP17
	even
GadgetIDCMP17	AUTOGADGET2 	160,80,120,10,3,1,<"DISKREMOVED">,16,GadgetIDCMP18
	even
GadgetIDCMP18	AUTOGADGET2 	160,95,120,10,3,1,<"WBENCHMESSAGE">,17,GadgetIDCMP19
	even
GadgetIDCMP19	AUTOGADGET2 	160,110,120,10,3,1,<"ACTIVEWINDOW">,18,GadgetIDCMP20
	even
GadgetIDCMP20	AUTOGADGET2 	160,125,120,10,3,1,<"INACTIVEWINDOW">,19,GadgetIDCMP21
	even
GadgetIDCMP21	AUTOGADGET2 	160,140,120,10,3,1,<"DELTAMOVE">,20,GadgetIDCMP22
	even
GadgetIDCMP22	AUTOGADGET2 	160,155,120,10,3,1,<"VANILLAKEY">,21,GadgetIDCMP23
	even
GadgetIDCMP23	AUTOGADGET2 	160,170,120,10,3,1,<"INTUITICKS">,22,GadgetIDCMP_CA
	even

GadgetIDCMP_CA	AUTOGADGET 	160,185,60,10,1,3,<"Cancel">,100,GadgetIDCMP_OK
	even

GadgetIDCMP_OK	AUTOGADGET 	240,185,40,10,1,3,<"OK">,101,0
	even






IDCMP	tst.l	FENSTER
	beq	Error

	move.l	FENSTER(pc),a0
	move.l	wd_IDCMPFlags(a0),.IDCMPFlags
	move.l	wd_IDCMPFlags(a0),d1
	

	moveq.l	#0,d0		; if bit is 1, set gadget selected
	lea.l	.GadgetList(pc),a0
.Label1	move.l	(a0)+,a1
	btst	d0,d1
	bne	.Label2
	and.w	#$ffff-SELECTED,gg_Flags(a1)
	bra	.Label3
.Label2	or.w	#SELECTED,gg_Flags(a1)
.Label3	addq	#1,d0
	cmp.b	#23,d0
	bne	.Label1


	
	lea.l	Windowdef6(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	wait
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#297,#197

	
	lea.l	GadgetIDCMP(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets


	


.wait	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		

	moveq.l	#0,d0		
	move.w	gg_GadgetID(a4),d0

	cmp.w	#100,d0
	beq	.Quit
	cmp.w	#101,d0
	beq	.Change
	
	move.l	.IDCMPFlags(pc),d1
	bchg	d0,d1
	move.l	d1,.IDCMPFlags
	bra	.wait
.Change	move.l	FENSTER(pc),a0
	move.l	.IDCMPFlags(pc),d0
	CALLINT	ModifyIDCMP
	
.Quit	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	
	bra	wait

.GadgetList	dc.l	GadgetIDCMP
	dc.l	GadgetIDCMP2
	dc.l	GadgetIDCMP3
	dc.l	GadgetIDCMP4
	dc.l	GadgetIDCMP5
	dc.l	GadgetIDCMP6
	dc.l	GadgetIDCMP7
	dc.l	GadgetIDCMP8
	dc.l	GadgetIDCMP9
	dc.l	GadgetIDCMP10
	dc.l	GadgetIDCMP11
	dc.l	GadgetIDCMP12
	dc.l	GadgetIDCMP13
	dc.l	GadgetIDCMP14
	dc.l	GadgetIDCMP15
	dc.l	GadgetIDCMP16
	dc.l	GadgetIDCMP17
	dc.l	GadgetIDCMP18
	dc.l	GadgetIDCMP19
	dc.l	GadgetIDCMP20
	dc.l	GadgetIDCMP21
	dc.l	GadgetIDCMP22
	dc.l	GadgetIDCMP23
	
.IDCMPFlags	dc.l	0

Windowdef9	dc.w	5,30,174,100
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	GadgetKILL1
	dc.l	0
	dc.l	W9_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W9_Title	dc.b	"  ป KILL SCREEN ซ    ",0	


ALL	lea.l	Windowdef9(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	KILL_ALL
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#171,#98

	SETDRMD	#RP_JAM1
	WRITE	#1+((174-18*8)/2),#20+1,#0,<"Do you really want">
	WRITE	#1+((174-18*8)/2),#30+1,#0,<"to    close    the">
	WRITE	#1+((174-18*8)/2),#40+1,#0,<"     screen ?     ">

	WRITE	#0+((174-18*8)/2),#20,#1,<"Do you really want">
	WRITE	#0+((174-18*8)/2),#30,#1,<"to    close    the">
	WRITE	#0+((174-18*8)/2),#40,#1,<"     screen ?     ">
	

	lea.l	GadgetKILL1(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets

	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		

	tst.w	gg_GadgetID(a4)
	beq	KILL_ALL

	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	bra	wait

KILL_ALL	
	move.l	BILDSCHIRM(pc),a5

.Label1	move.l	sc_FirstWindow(a5),a0	; close window (if there are any windows left )
	cmp.l	#0,a0
	beq	.Label2
	CALLINT	CloseWindow
	bra	.Label1
.Label2	move.l	BILDSCHIRM(pc),a0
	CALLINT	CloseScreen
	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	bra	ChangeScreen


Windowdef7	dc.w	5,50,174,100
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	Gadget_7_1
	dc.l	0
	dc.l	W7_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W7_Title	dc.b	"  Save Screen As     ",0
	even
Gadget_7_1	AUTOGADGET 	10,20,154,12,3,1,<"IFF-ILBM">,0,Gadget_7_2
	even
Gadget_7_2	AUTOGADGET 	10,40,154,12,3,1,<"Dump">,1,Gadget_7_3
	even
Gadget_7_3	AUTOGADGET 	10,60,154,12,3,1,<"Colour & Dump">,2,Gadget_7_4
	even
Gadget_7_4	AUTOGADGET 	10,80,154,12,3,1,<"No - forget it !">,3,0
	even

SaveMode	dc.b	0
	even

SaveScreen	clr.b	SaveMode
	lea.l	Windowdef7(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	SS_IFF
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#171,#98


	lea.l	Gadget_7_1(pc),a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets

	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		
	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	move.b	gg_GadgetID+1(a4),SaveMode
	cmp.b	#3,SaveMode
	beq	wait
SS_IFF	moveq.l	#0,d0
	move.b	SaveMode(pc),d0
	mulu	#40,d0
	add.l	#SaveText1,d0
	lea.l	FileReq(pc),a0	
	move.l	d0,(a0)
	move.l	_ARPBase(pc),a6
	move.l	Window1(pc),12(a0)
	jsr	-294(a6)		; file requester
	tst.l	d0
	beq	wait	
	move.l	d0,d6
	move.l	#Dir,d1
	moveq.l	#ACCESS_READ,d2
	CALLDOS	Lock
	tst.l	d0
	beq	.O1
	move.l	d0,d1
	CALLDOS	CurrentDir		; set current dir
.O1	move.l	d6,d0
	tst.b	SaveMode
	beq	SaveIFF
	move.l	d0,d1
	move.l	#MODE_NEWFILE,d2
	CALLDOS	Open
	tst.l	d0
	beq	.Error
	move.l	d0,d7
	cmp.b	#1,SaveMode
	beq	.SaveDump
	move.l	BILDSCHIRM(pc),a0	;save screen as COLOUR & DUMP
	lea.l	sc_ViewPort(a0),a0
	move.l	vp_ColorMap(a0),a0	
	moveq.l	#0,d3
	move.w	cm_Count(a0),d3			
	add.w	d3,d3
	move.l	cm_ColorTable(a0),d2
	move.l	d7,d1
	CALLDOS	Write
	cmp.l	d3,d0
	bne	.DiskError
.SaveDump	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_BitMap(a0),a0
	moveq.l	#0,d4
	move.b	bm_Depth(a0),d4
	subq.l	#1,d4
	moveq.l	#0,d5
	move.w	bm_BytesPerRow(a0),d5
	mulu	bm_Rows(a0),d5

	lea.l	bm_Planes(a0),a4
.L1	move.l	(a4)+,d2
	move.l	d5,d3
	move.l	d7,d1
	CALLDOS	Write
	cmp.l	d5,d0	
	bne	.DiskError
	dbra	d4,.L1
	bra.s	.L2
.DiskError	move.l	ScreenPtr1(pc),a0	
	CALLINT	DisplayBeep
.L2	move.l	d7,d1
	CALLDOS	Close
	bra	wait
.Error	move.l	ScreenPtr1(pc),a0	
	CALLINT	DisplayBeep
	bra	wait

FileReq	dc.l	0
	dc.l	File
	dc.l	Dir
	dc.l	0
	dc.b	0,0
	dc.l	0,0

SaveText1	dc.b	"Save Screen As IFF                     ",0
	even
SaveText2	dc.b	"Save Screen As DUMP                    ",0
	even
SaveText3	dc.b	"Save Screen As COLOUR & DUMP           ",0
	even
File	ds.b	34
	even
Dir	ds.b	34
	even

SPic_File		dc.l	0
SPic_BMHD		dc.l	Header	
SPic_BitMap		dc.l	0		
SPic_Mask		dc.l	0
SPic_Colortable	dc.l	0
SPic_Chunks		dc.l	0	
SPic_ChunkSize		dc.l	0
SPic_ViewMode		dc.l	V_HIRES	
SPic_SelectPlanes	dc.l	-1	
SPic_Flags		dc.l	1
SPic_Buffer		ds.b	200
SPic_PackerBuffer	ds.b	200
SPic_BMwidth		dc.l	0	
SPic_BytesPerRow	dc.l	0
SPic_StartRow		dc.l	0
SPic_EndRow		dc.l	0
SPic_SkipBytes		dc.l	0
SPic_Shift		dc.l	0
SPic_BodyPos		dc.l	0
SPic_FileHandle	dc.l	0	
SPic_A6		dc.l	0
SPic_PlaneBuffer	ds.l	10


Header	dc.w	80,3
	dc.w	0,0
	dc.b	1,0,1,0
	dc.w	0
	dc.b	1,1
	dc.w	640,256


SaveIFF	move.l	d0,SPic_File		; save as IFF pic
	move.l	BILDSCHIRM(pc),a0
	move.l	sc_Width(a0),Header
	move.l	sc_Width(a0),Header+16
	clr.l	Header+4
SaveWind	lea.l	sc_BitMap(a0),a0
	move.l	a0,SPic_BitMap
	move.b	bm_Depth(a0),Header+8
	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_ViewPort(a0),a0
	moveq.l	#0,d0
	move.w	vp_Modes(a0),d0
	and.w	#%1000100010000100,d0
	move.l	d0,SPic_ViewMode
	move.l	vp_ColorMap(a0),a0	
	moveq.l	#0,d3
	move.w	cm_Count(a0),d3			
	add.w	d3,d3
	move.l	cm_ColorTable(a0),SPic_Colortable
	bsr.s	.Save
	bra	wait	

	
.Save	move.l	a6,SPic_A6

	move.l	SPic_BitMap(pc),a0	; verify sizes
	move.l	SPic_BMHD(pc),a1
	moveq.l	#0,d0
	move.w	bm_BytesPerRow(a0),d0	
	move.l	d0,SPic_BMwidth		;
	lsl.w	#3,d0			; width of bitmap
	move.w	(a1),d1
	add.w	4(a1),d1			; IFF_width + IFF_offsetX 
	cmp.w	d0,d1
	bhi	.SizeError
	move.w	bm_Rows(a0),d0			; height of bitmap	
	move.w	2(a1),d1			; IFF_heigth + IFF_offsetY
	add.w	6(a1),d1
	cmp.w	d0,d1
	bhi	.SizeError

	moveq.l	#0,d0			; calculate ...
	move.w	(a1),d0		 	; bytes of IFF_width ( word alligned)
	add.w	#15,d0
	lsr.l	#3,d0		
	bclr	#0,d0
	move.l	d0,SPic_BytesPerRow
	moveq.l	#0,d0
	move.w	6(a1),d0
	move.l	d0,SPic_StartRow		; start at row
	moveq.l	#0,d0
	move.w	4(a1),d0
	and.l	#15,d0
	move.l	d0,SPic_Shift			; how often should I move bits to the left
	moveq.l	#0,d0
	move.w	4(a1),d0
	lsr.w	#3,d0
	bclr	#0,d0
	move.l	d0,SPic_SkipBytes		; how many bytes should I skip per row


	moveq.l	#0,d0
	move.w	2(a1),d0
	add.w	6(a1),d0
	move.l	d0,SPic_EndRow			; stop at row


	moveq.l	#0,d0
	move.b	8(a1),d0	
	subq.l	#1,d0
	lea.l	bm_Planes(a0),a2
	lea.l	SPic_PlaneBuffer(pc),a3
.K1	move.l	(a2)+,(a3)+
	dbra	d0,.K1
	clr.l	(a3)+

	move.l	SPic_File(pc),d1
	move.l	#MODE_NEWFILE,d2
	CALLDOS	Open
	tst.l	d0
	beq	.L1
	move.l	d0,SPic_FileHandle
	CALLEXEC	Forbid
	move.l	SPic_FileHandle(pc),d1
	move.l	#.FORM,d2		; write IFF File Header
	move.l	#20,d3
	CALLDOS	Write
	cmp.l	#20,d0
	bne	.WriteError
	

	move.l	SPic_BMHD(pc),a0	; write BMHD
	move.l	a0,d2
	move.l	#20,d3
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	#20,d0
	bne	.WriteError

	lea.l	SPic_Buffer(pc),a0	; write CMAP
	move.l	a0,d6
	move.l	SPic_BMHD(pc),a1	
	moveq.l	#0,d0		; number of colours (2^depth)
	move.b	8(a1),d0
	moveq.l	#0,d1
	bset	d0,d1
	move.l	#"CMAP",(a0)+
	move.l	d1,d0
	mulu	#3,d0
	move.l	d0,d5
	move.l	d0,(a0)+
	subq.l	#1,d1
	move.l	SPic_Colortable(pc),a1	
.L2	move.w	(a1)+,d2		; copy colours into buffer
	move.w	d2,d3
	move.w	d2,d4
	lsr.w	#4,d2
	lsl.w	#4,d3
	and.w	#$f0,d2
	and.w	#$f0,d3
	and.w	#$f0,d4
	move.b	d2,(a0)+
	move.b	d4,(a0)+
	move.b	d3,(a0)+
	dbra	d0,.L2
	move.l	d6,d2
	move.l	d5,d3
	add.l	#8,d3
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	d3,d0
	bne	.WriteError

	lea.l	SPic_Buffer(pc),a0		; write CAMG
	move.l	a0,d2
	move.l	#"CAMG",(a0)+
	move.l	#4,(a0)+
	move.l	SPic_ViewMode(pc),(a0)
	move.l	#12,d3
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	#12,d0
	bne	.WriteError

	move.l	SPic_Chunks(pc),d2		; write additional chunks
	move.l	SPic_ChunkSize(pc),d3
	tst.l	d2
	beq.s	.L3
	tst.l	d3
	beq.s	.L3
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	move.l	SPic_ChunkSize(pc),d1
	cmp.l	d1,d0
	bne	.WriteError


.L3	move.l	#.BODY,d2			; write BODY
	moveq.l	#8,d3		
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	#8,d0
	bne	.WriteError

	move.l	SPic_FileHandle(pc),d1	; we'll write the chunk size later...	
	moveq.l	#OFFSET_CURRENT,d3
	moveq.l	#0,d2
	CALLDOS	Seek
	move.l	d0,SPic_BodyPos

	move.l	SPic_StartRow(pc),d7	; current row = d7
	subq.l	#1,d7	
.U4	addq.l	#1,d7
.U1	cmp.l	SPic_EndRow(pc),d7		; last row ????
	beq	.Q1
	lea.l	SPic_PlaneBuffer(pc),a4	; get pointer to bitplane
.U2	move.l	(a4)+,a0		
	cmp.l	#0,a0		; last bitplane ????
	beq	.U4
	move.l	SPic_BMwidth(pc),d0	; offset
	mulu	d7,d0
	add.l	d0,a0
	lea.l	SPic_Buffer(pc),a1		; copy row to buffer
	move.l	a0,d2
	move.l	SPic_BMwidth(pc),d0
	subq.l	#1,d0
.U3	move.b	(a0)+,(a1)+
	dbra	d0,.U3
	add.l	SPic_SkipBytes(pc),d2	; skip some bytes

	move.l	SPic_Shift(pc),d4		; shift bits to the left
	tst.l	d0
	beq	.U5
	move.l	d2,a0
	move.l	SPic_BytesPerRow(pc),d0
	addq.l	#1,d0		; if you save byte alligned
	lsr.w	#1,d0
	subq.l	#1,d0
.U6	move.w	(a0),d1		; copy two words to d1
	swap	d1
	move.w	2(a0),d1
	lsl.l	d4,d1		; now move bits of 2nd word into the 1st word
	swap	d1
	move.w	d1,(a0)+		; copy 1st word back to buffer 
	dbra	d0,.U6

.U5	move.l	SPic_BytesPerRow(pc),d3
	move.l	SPic_BMHD,a0
	cmp.b	#1,10(a0)
	bne	.U7
	movem.l	d4-d7/a0-a6,-(sp)
	bsr	Packer
	movem.l	(sp)+,d4-d7/a0-a6

.U7	move.l	SPic_FileHandle(pc),d1	; write row to file
	CALLDOS	Write
	cmp.l	d3,d0
	bne	.WriteError
	bra	.U2		; next bitplane

.Q1	move.l	SPic_FileHandle(pc),d1	; get file size
	moveq.l	#OFFSET_CURRENT,d3
	moveq.l	#0,d2
	CALLDOS	Seek
	move.l	d0,d7
	sub.l	SPic_BodyPos(pc),d0
	move.l	d0,.BODY+4

	move.l	SPic_FileHandle(pc),d1	; write BODY size
	moveq.l	#OFFSET_BEGINNING,d3
	move.l	SPic_BodyPos(pc),d2
	subq.l	#4,d2
	CALLDOS	Seek
	
	move.l	#.BODY+4,d2
	moveq.l	#4,d3		
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	#4,d0
	bne	.WriteError

	subq.l	#8,d7
	move.l	d7,.FORM+4
	move.l	SPic_FileHandle(pc),d1	; write FORM size
	moveq.l	#OFFSET_BEGINNING,d3
	moveq.l	#4,d2
	CALLDOS	Seek
	
	move.l	#.FORM+4,d2
	moveq.l	#4,d3		
	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Write
	cmp.l	#4,d0
	bne	.WriteError

	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Close
	CALLEXEC	Permit
	moveq.l	#0,d0
	rts
.L1	
.SizeError	move.l	ScreenPtr1(pc),a0	
	CALLINT	DisplayBeep
	moveq.l	#-1,d0
	rts
.WriteError	move.l	SPic_FileHandle(pc),d1
	CALLDOS	Close	
	CALLEXEC	Permit
	move.l	SPic_File(pc),d1
	CALLDOS	DeleteFile
	move.l	ScreenPtr1(pc),a0	
	CALLINT	DisplayBeep
	moveq.l	#-1,d0
	rts
		



.FORM	dc.b	"FORM"
	dc.l	0
	dc.b	"ILBM"
	dc.b	"BMHD"
	dc.l	20
.BODY	dc.b	"BODY"
	dc.l	0
	

	
	

Packer	lea.l	SPic_PackerBuffer(pc),a0	; a0 ^buffer
	move.l	d2,a1		; a1 ^row
	move.l	a1,a2		
	add.l	d3,a2		; a2 ^ end of row		
	move.l	a1,a4
	
.P0	cmp.l	a2,a1
	beq	.Pexit
	bhi	.Pexit
	moveq.l	#-1,d5		; d5 = counter
.P1	moveq.l	#0,d0		; wait until two identical bytes  appear
	addq.l	#1,d5
	move.b	(a1,d5),d0		; compare
	move.l	a1,d1
	add.l	d5,d1
*	addq.l	#1,d1
	cmp.l	a2,d1		; end of row ????
	beq	.P5
	cmp.b	1(a1,d5),d0
	bne	.P1
.P5	tst.l	d5		; are there bytes between two parts of identical bytes
	beq	.P2
.P3	subq.l	#1,d5		; code = n-1
	move.b	d5,(a0)+
.P4	move.b	(a1)+,(a0)+		; copy bytes
	dbra	d5,.P4
	bra.s	.P0

.P2	moveq.l	#-1,d4		; pack it !
.P6	addq.l	#1,d4
	cmp.l	a2,a1
	beq	.P7	
	cmp.b	(a1)+,d0
	beq	.P6
	tst.b	-(a1)
.P7	move.l	#257,d1		; code = 257-n
	sub.l	d4,d1
	move.b	d1,(a0)+
	move.b	d0,(a0)+
	bra	.P0
.Pexit	move.l	#SPic_PackerBuffer,d2
	move.l	a0,d3
	sub.l	d2,d3
	btst	#0,d3
	beq	.P10
	move.b	#128,(a0)+
	addq.l	#1,d3
.P10	rts

	

SWindow	dc.b	"Save Window As IFF                      ",0

SaveWindow	tst.l	FENSTER
	beq	Error
	lea.l	FileReq(pc),a0	
	move.l	#SWindow,(a0)
	move.l	_ARPBase(pc),a6
	move.l	Window1(pc),12(a0)
	jsr	-294(a6)		; file requester
	tst.l	d0
	beq	wait	
	move.l	d0,d6
	move.l	#Dir,d1
	moveq.l	#ACCESS_READ,d2
	CALLDOS	Lock
	tst.l	d0
	beq	.O1
	move.l	d0,d1
	CALLDOS	CurrentDir		; set current dir
.O1	move.l	d6,d0
	move.l	d0,SPic_File		; save as IFF pic
	move.l	FENSTER(pc),a0
	CALLINT	WindowToFront
	move.l	FENSTER(pc),a0
	CALLINT	ActivateWindow
	move.l	BILDSCHIRM(pc),a0
	move.l	FENSTER(pc),a1
	move.l	wd_Width(a1),Header
	move.l	wd_LeftEdge(a1),Header+4
	move.l	sc_Width(a0),Header+16
	bra	SaveWind



ScreenBACK	move.l	BILDSCHIRM(pc),a0	; move screen to back
	CALLINT	ScreenToBack
	bra	wait
ScreenFRONT	move.l	BILDSCHIRM(pc),a0	; move screen to front
	CALLINT	ScreenToFront
	bra	QUIT		; and exit fenster screen


QUIT2	move.l	ScreenPtr1(pc),a0
	CALLINT	CloseScreen

ende	move.l	#RECOVERY_ALERT,d0	; error message
	move.w	#30,d1
	lea.l	ErrorText(pc),a0
	CALLINT	DisplayAlert
	moveq.l	#0,d0
	rts
ErrorText	dc.w	60
	dc.b	17
	dc.b	"FENSTER  :   ERROR !?!    I cannot open the screen / window !"
	dc.b 	0,0

SUB	CALLEXEC	Forbid		; sub Bitplane
	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_ViewPort(a0),a1		
	move.w	vp_Modes(a1),d0
	and.l	#$800,d0		; HAM ?
	bne	SUB1
	lea.l	sc_BitMap(a0),a0
	moveq.l	#0,d2
	move.b	bm_Depth(a0),d2			
	cmp.b	#1,d2		; depth =1 ?
	bls	SUB1
	sub.b	#1,bm_Depth(a0)
	subq	#1,d2
	lsl.l	#2,d2
	add.l	#bm_Planes,d2
	moveq.l	#0,d0
	moveq.l	#0,d1
	move.w	bm_BytesPerRow(a0),d0
	lsl.l	#3,d0
	move.w	bm_Rows(a0),d1
	move.l	(a0,d2),a0
	CALLGRAF	FreeRaster		; free memory
	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_ViewPort(a0),a1
	lea.l	sc_BitMap(a0),a0
	cmp.b	#5,bm_Depth(a0)
	bne	SUB2
	and.w	#$ffff-$80,vp_Modes(a1)	; clear EHB flag !
SUB2	CALLINT	RemakeDisplay
	CALLEXEC	Permit
	bra	NewDepth
SUB1	CALLEXEC	Permit		; cannot sub bitplane
	sub.l	a0,a0
	CALLINT	DisplayBeep
	bra	wait

ADD	CALLEXEC	Forbid		; add bitplane
	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_BitMap(a0),a0
	moveq.l	#0,d2
	move.b	bm_Depth(a0),d2			
	cmp.b	#5,d2		; depth = 6 ?
	bhi	ADD1
	move.l	BILDSCHIRM(pc),a1
	lea.l	sc_ViewPort(a1),a1
	move.w	vp_Modes(a1),d0
	and.l	#$8000,d0		; HIRES (x=640) ?
	beq.s	ADD2
	move.b	bm_Depth(a0),d2			
	cmp.b	#3,d2
	bhi	ADD1
ADD2	moveq.l	#0,d0
	moveq.l	#0,d1
	move.w	bm_BytesPerRow(a0),d0
	lsl.l	#3,d0
	move.w	bm_Rows(a0),d1
	CALLGRAF	AllocRaster		; get memory ?
	tst.l	d0
	beq	ADD1
	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_BitMap(a0),a0
	moveq.l	#0,d2
	move.b	bm_Depth(a0),d2
	add.b	#1,bm_Depth(a0)
	lsl.l	#2,d2
	add.l	#bm_Planes,d2
	move.l	d0,(a0,d2)
	move.l	d0,a1
	move.l	(a0),d0
	swap	d0
	moveq.l	#3,d1
	CALLGRAF	BltClear		; clear bitplane

	move.l	BILDSCHIRM(pc),a0
	lea.l	sc_BitMap(a0),a0
	cmp.b	#6,bm_Depth(a0)
	bne.s	ADD3
	move.l	BILDSCHIRM(pc),a1
	lea.l	sc_ViewPort(a1),a1
	or.w	#$80,vp_Modes(a1)	; depth =6 => set EHB flag !
ADD3	CALLINT	RemakeDisplay
	CALLEXEC	Permit
	bra	NewDepth
ADD1	CALLEXEC	Permit		; cannot add bitplane
	sub.l	a0,a0
	CALLINT	DisplayBeep
	bra	wait

WindowPointer set Window1

NewDepth	SETAPEN	#0			; show new
	RECTFILL	#10+184+(31*8),#19-6,#10+1+184+(32*8),#19+1
	move.l	BILDSCHIRM(pc),a5			; depth
	lea.l	sc_BitMap(a5),a0
	move.b	bm_Depth(a0),d0
	add.b	#"0",d0
	move.b	d0,Zeile+63-32	
	SETAPEN	#2
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.w	#10+1+184+(31*8),d0
	move.w	#19+1,d1
	CALLGRAF	Move
	lea.l	Zeile+31(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	moveq.l	#1,d0
	CALLGRAF	Text
	SETAPEN	#1
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	move.w	#10+184+(31*8),d0
	move.w	#19,d1
	CALLGRAF	Move
	lea.l	Zeile+31(pc),a0
	move.l	Window1(pc),a1
	move.l	wd_RPort(a1),a1
	moveq.l	#1,d0
	CALLGRAF	Text
	bra	wait

PrintMode	dc.b	0
	even
Windowdef8	dc.w	635-174,50,174,100
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	Gadget_8_1
	dc.l	0
	dc.l	W8_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W8_Title	dc.b	"    Print Window     ",0
	even
Gadget_8_1	AUTOGADGET 	10,20,154,12,3,1,<"Page Size">,1,Gadget_8_2
	even
Gadget_8_2	AUTOGADGET 	10,40,154,12,3,1,<"Window Size">,3,Gadget_8_3
	even
Gadget_8_3	AUTOGADGET 	10,60,154,12,3,1,<"Change Colours">,0,Gadget_8_4
	even
Gadget_8_4	AUTOGADGET 	10,80,154,12,3,1,<"No - forget it !">,0,0
	even

Windowdef10	dc.w	5,50,174,100
	dc.b	-1,-1
	dc.l	GADGETUP
	dc.l	WINDOWDRAG!ACTIVATE!SMART_REFRESH
	dc.l	Gadget_10_1
	dc.l	0
	dc.l	W10_Title
	dc.l	0,0
	dc.w	0,0,0,0,CUSTOMSCREEN
W10_Title	dc.b	"    Print Screen      ",0
	even
Gadget_10_1	AUTOGADGET 	10,20,154,12,3,1,<"Page Size">,0,Gadget_10_2
	even
Gadget_10_2	AUTOGADGET 	10,40,154,12,3,1,<"Screen Size">,2,Gadget_8_3
	even


PrintWindow	move.b	#1,PrintMode
	lea.l	Gadget_8_3(pc),a0
	move.w	#TOGGLESELECT,gg_Activation(a0)
	lea.l	Windowdef8(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	.PW
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#171,#98
	lea.l	Gadget_8_1,a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets
	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		
	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	move.b	gg_GadgetID+1(a4),PrintMode
	tst.b	PrintMode
	beq	wait
.PW	move.l	FENSTER(pc),a0
	CALLINT	ActivateWindow
	bra	PS1


PrintScreen	clr.b	PrintMode		; print screen	
	lea.l	Gadget_8_3(pc),a0
	move.w	#TOGGLESELECT,gg_Activation(a0)
	lea.l	Windowdef10(pc),a0
	move.l	ScreenPtr1(pc),nw_Screen(a0)	
	CALLINT	OpenWindow
	tst.l	d0
	beq	PS1
	move.l	d0,Window2

WindowPointer set Window2

	SETAPEN	#2
	RECTFILL	#2,#10,#171,#98
	lea.l	Gadget_10_1,a0
	move.l	Window2(pc),a1
	sub.l	a2,a2
	CALLINT	RefreshGadgets
	move.l	Window2(pc),a0		
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_IAddress(a1),a4
	CALLEXEC 	ReplyMsg		; reply message		
	move.l	Window2(pc),a0
	CALLINT	CloseWindow
	move.b	gg_GadgetID+1(a4),PrintMode
	and.b	#$fe,PrintMode
	tst.b	PrintMode
	beq	wait

PS1	sub.l	a1,a1
	CALLEXEC	FindTask
	lea.l	Reply(pc),a1
	move.l	d0,$10(a1)
	CALLEXEC	AddPort
	lea	DevName(pc),a0
	lea.l	DevIO(pc),a1
	moveq.l	#0,d0	
	move.l	#iodrpr_SIZEOF,d1
	CALLEXEC	OpenDevice		; open printer device
	tst.l	d0
	bne	.Error

	move.l	BILDSCHIRM(pc),a1
	lea.l	DevIO(pc),a0

	lea.l	sc_RastPort(a1),a2
	move.l	a2,io_RastPort(a0)
	btst	#0,PrintMode
	beq.s	.P1
	move.l	FENSTER(pc),a3
	move.l	wd_RPort(a3),io_RastPort(a0)

.P1	lea.l	sc_ViewPort(a1),a2
	move.l	vp_ColorMap(a2),a3
	move.l	a3,io_ColorMap(a0)
	move.l	cm_ColorTable(a3),a3
	move.l	(a3),PrintColors
	move.l	a3,ColorTable

	btst	#7,Gadget_8_3+gg_Flags+1	; if selected set colours 0/1 to white/black
	beq	.P2
	move.l	#$0fff0000,(a3)	


.P2	moveq.l	#0,d0
	move.w	vp_Modes(a2),d0
	move.l	d0,io_Modes(a0)
	
	move.w	#0,io_SrcX(a0)
	move.w	#0,io_SrcY(a0)
	move.w	sc_Width(a1),io_SrcWidth(a0)
	move.w	sc_Height(a1),io_SrcHeight(a0)
	moveq.l	#0,d0
	move.l	d0,io_DestCols(a0)
	move.l	d0,io_DestRows(a0)
	btst	#0,PrintMode
	beq.s	.P3
	move.l	FENSTER(pc),a3
	move.w	wd_Width(a3),io_SrcWidth(a0)
	move.w	wd_Height(a3),io_SrcHeight(a0)


.P3	btst	#1,PrintMode		; use page size ?
	beq.s	.P5
	moveq.l	#0,d2
	moveq.l	#0,d3
	move.w	sc_Width(a3),d2
	move.w	sc_Height(a3),d3
	move.l	d2,io_DestCols(a0)	; use pic size
	move.l	d3,io_DestRows(a0)
	btst	#0,PrintMode
	beq.s	.P5
	moveq.l	#0,d2
	moveq.l	#0,d3
	move.w	wd_Width(a3),d2
	move.w	wd_Height(a3),d3
	move.l	d2,io_DestCols(a0)	; use pic size
	move.l	d3,io_DestRows(a0)
	
.P5	moveq.l	#0,d0
	move.w	d0,io_Special(a0)
	move.w	#PRD_DUMPRPORT,IO_COMMAND(a0)
	move.l	#Reply,14(a0)
	
	move.l	a0,a1
	CALLEXEC	DoIO

	move.l	ColorTable(pc),a3	; restore colours
	move.l	PrintColors(pc),(a3)
	
	lea.l	DevIO(pc),a1
	move.b	IO_ERROR(a1),d0
	CALLEXEC	CloseDevice
	
.Error	lea.l	Reply(pc),a1
	CALLEXEC	RemPort
	bra	wait
DevName	dc.b	"printer.device",0
Reply	ds.l	8
DevIO	ds.b	iodrpr_SIZEOF
	even
PrintColors	dc.l	0
ColorTable	dc.l	0


ColReq	move.l	BILDSCHIRM(pc),a0
	CALLINT	ScreenToFront
	move.l	_XColorBase(pc),d0	; which library ???
	bne.s	.XColor
	move.l	BILDSCHIRM(pc),a1	; colour requester (color.library needed)
	sub.l	a0,a0
	move.l	_ColorBase(pc),a6
	jsr	-30(a6)
	move.l	d0,d5
	move.l	ScreenPtr1(pc),a0
	CALLINT	ScreenToFront
	tst.l	d5
	bmi	Error
	bra	wait

; use xcolor library

.XColor	lea.l	.Palette(pc),a0	; put up ColorRequester structure
	move.l	BILDSCHIRM(pc),CR_Screen(a0)	; ^screen
	move.b	#0,CR_TextColour(a0)	; pens
	move.b	#1,CR_BackColour(a0)
	move.b	#2,CR_GBorderColour(a0)
	move.b	#0,CR_GTextColour(a0)
	move.w	#10,CR_LeftEdge(a0)	; X,Y
	move.w	#10,CR_TopEdge(a0)
	move.l	#4,CR_DefaultEntries(a0)	; default workbench palette
	move.l	#.DefaultPalette,CR_DefaultColourMap(a0)
	move.l	#.ScreenTitle,CR_ScreenTitle(a0)	; screen title		
	move.l	#.WindowTitle,CR_DefaultWTitle(a0)	; defalut window title		

	clr.l	CR_JMPWindow(a0)	; no user interface
	clr.l	CR_JMPDraw(a0)
	clr.l	CR_JMPMode(a0)
	clr.l	CR_JMPMessage(a0)
	clr.l	CR_Font(a0)		; use default font (should be 8x8)
	clr.l	CR_Mode(a0)

	move.l	#FLAG_RMBTRAP!FLAG_NORMAL!FLAG_RGB,CR_Flags(a0)

	CALLXCOLOR	ColourRequester
	
	move.l	ScreenPtr1(pc),a0
	CALLINT	ScreenToFront
	bra	wait

.Palette	ds.b	CR_SIZEOF
	even
.DefaultPalette	dc.w	$05a,$fff,$000,$f80
	even
.ScreenTitle	dc.b	"XCOLOR LIBRARY BY ROGER FISCHLIN",0
	even
.WindowTitle	dc.b	"Palette                           ",0
	even

;ญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญญ

TOP	move.l	BILDSCHIRM(pc),a0	; move screnen to left edge
	move.l	#-1000,d1
	move.l	#-1000,d0
	CALLINT	MoveScreen
	bra	wait
	



Windowdef	dc.w	20,20,140,10
	dc.b	-1,-1
	dc.l	MOUSEBUTTONS!CLOSEWINDOW
	dc.l	WINDOWDRAG!WINDOWCLOSE!ACTIVATE!SMART_REFRESH!WINDOWDEPTH!RMBTRAP
	dc.l	0
	dc.l	0
	dc.l	W_Title
	dc.l	0,0
	dc.w	0,0,0,0,WBENCHSCREEN
W_Title	dc.b	"Fenster      ",0
	even 
WindowPtr	dc.l	0

Init	lea.l	Windowdef(pc),a0	; create window on WB	
	CALLINT	OpenWindow
	tst.l	d0
	beq	ende
	move.l	d0,WindowPtr


.wait	move.l	WindowPtr(pc),a0	; wait .....
	move.l	wd_UserPort(a0),a0
	move.l	a0,a5
	CALLEXEC	WaitPort		
	move.l	a5,a0
	CALLEXEC	GetMsg		; get message
	move.l	d0,a1	
	move.l	im_Class(a1),d4	; get data
	move.w	im_Code(a1),d5
	CALLEXEC 	ReplyMsg		; reply message		
	cmp.l	#MOUSEBUTTONS,d4		; right mouse button pressed ?
	bne.s	.Close
	cmp.w	#MENUDOWN,d5
	bne.s	.wait
	bsr	Start		; open FENSTER
	bra.s	.wait
.Close	move.l	WindowPtr(pc),a0
	CALLINT	CloseWindow
	rts



