		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.

DEBUG		SET     0

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

*AUTO:		smake KCX


;* $Revision Header built automatically *************** (do not edit) ************
;*
;* © Copyright by GuntherSoft
;*
;* File             : SnakeSYS:ASMPrgs/KCX/Printer.Asm
;* Created on       : Tuesday, 10-Nov-92 18:18:58
;* Created by       : Kai Iske
;* Current revision : V2.5
;*
;*
;* Purpose
;* -------
;*     Printer program, which will be loaded on demand.
;*
;* Revision V2.5
;* --------------
;*     --- Initial release ---
;*
;*********************************************************************************




		INCLUDE	KCXBase.i
		INCLUDE	KCX_Lib.i
		INCLUDE	KCX.i

		INCLUDE	Misc/MyMacros.i

		IFGT	DEBUG
		INCLUDE	Misc/Debug.i
		ENDC



**********************************************************************
*         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
		bra.s	PrinterProc
Version		dc.b	"$VER: KCXPrinter "
		REVISION
		dc.b	" ("
		REVDATE
		dc.b	")",0
		EVEN

**********************************************************************
*                    This is the Printer process                     *
**********************************************************************
PrinterProc	movem.l	RegsAll,-(sp)

		sub.l	a4,a4
		sub.l	a1,a1
		CALLSYS	FindTask
		move.l	d0,a5
		tst.l	pr_CLI(a5)
		bne.s	.FromCLI
		lea	pr_MsgPort(a5),a0
		DOLIB	WaitPort
		lea	pr_MsgPort(a5),a0
		DOLIB	GetMsg
		move.l	d0,MyWBMsg

.FromCLI	cmp.w	#NEED_LIBVER,LIB_VERSION(a6)
		bge.s	.IsOver20

		tst.l	MyWBMsg
		bne.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
		bra	.EndPrg
.FromWB		lea	IntName,a1			; try to open IntBase
		moveq	#0,d0
		CALLSYS	OpenLibrary
		tst.l	d0
		beq	.Error
		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
		bra	.EndPrg

.IsOver20	lea	BackPortName(pc),a1		; Try to find KCX`s port
		CALLSYS	FindPort
		tst.l	d0
		bne.s	.GotBack
		lea	IntName(pc),a1
		moveq	#NEED_LIBVER,d0
		DOLIB	OpenLibrary
		tst.l	d0
		beq	.Error
		move.l	d0,a6
		sub.l	a0,a0
		lea	NoBackRequest(pc),a1
		LOCLEA	PrintHead,a2
		move.l	a2,es_Title(a1)
		LOCLEA	NoBackText,a2
		move.l	a2,es_TextFormat(a1)
		sub.l	a2,a2
		lea	VersionTag,a3
		DOLIB	EasyRequestArgs
		move.l	a6,a1
		CALLSYS	CloseLibrary
		bra	.EndPrg

.GotBack	move.l	d0,a0				; Get address of datablock
		move.l	MP_SIZE(a0),a4
		move.l	a4,ZeroBase

		tst.l	PrintProc(a4)
		bne.s	.Error

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

		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	BackTask(a4),a1
		move.l	#SIGHANDSHAKE,d0
		DOLIB	Signal

		tst.l	_LocaleBase(a4)			; Init locale
		beq.s	.NoLocale
		sub.l	a0,a0
		RELLIB	OpenLocale,_LocaleBase
		move.l	d0,MyLocale
		sub.l	a0,a0
		lea	CatalogName(pc),a1
		sub.l	a2,a2
		DOLIB	OpenCatalogA
		move.l	d0,MyCatalog

.NoLocale	bsr	DumpScreen
		clr.l	PrintProc(a4)
.Error		CALLSYS	Forbid

		tst.l	MyCatalog			; Close Catalog
		beq.s	.NoCat
		move.l	MyCatalog(pc),a0
		RELLIB	CloseCatalog,_LocaleBase
		move.l	MyLocale(pc),a0
		DOLIB	CloseLocale

.NoCat		tst.l	GfxDumpSig(a4)			; Clear signal
		blt.s	.NoSig
		move.l	GfxDumpSig(a4),d0
		CALLSYS	FreeSignal
		clr.l	GfxDumpSig(a4)
		clr.l	GfxDumpFlag(a4)

.NoSig		move.l	BackTask(a4),a1			; Reply to mother
		move.l	#SIGHANDSHAKE,d0
		CALLSYS	Signal

.EndPrg		CALLSYS	Forbid

		tst.l	MyWBMsg
		beq.s	.NoWBMsg
		move.l	MyWBMsg(pc),a1
		CALLSYS	ReplyMsg
.NoWBMsg	movem.l	(sp)+,RegsAll
		moveq	#0,d0
		rts
MyWBMsg		dc.l	0
ZeroBase	dc.l	0
DosName		dc.b	"dos.library",0
IntName		dc.b	"intuition.library",0
CatalogName	dc.b	"kcxdump.catalog",0
BackPortName	dc.b	"KCX-BackPort",0
OkGadget	dc.b	"Ok",0
		EVEN
NoBackRequest	dc.l	es_SIZEOF
		dc.l	0
		dc.l	0
		dc.l	0
		dc.l	OkGadget
MyLocale	dc.l	0
MyCatalog	dc.l	0



**********************************************************************
*                      Dump the current screen                       *
**********************************************************************
DumpScreen	bsr	GetNewSource
		bsr	HandleDumpWin
		tst.l	d0
		bne.s	.GoPrint
		bsr	CloseDumpWin
		rts

.GoPrint	CALLSYS	Forbid				; Lock everything out while grabbing data
		moveq	#0,d0
		RELLIB	LockIBase,_IntuitionBase
		move.l	d0,a3

		clr.w	GfxFileLeft(a4)			; Set offsets for bitmap
		clr.w	GfxFileTop(a4)

		tst.l	GfxSource(a4)
		beq.s	.TakeScreenFile
		move.l	GfxWindow(a4),a0		; Get info about window
		move.l	wd_WScreen(a0),GfxFileScreen(a4)
		move.w	wd_LeftEdge(a0),d0
		move.w	wd_TopEdge(a0),d1
		add.w	d0,GfxFileLeft(a4)
		add.w	d1,GfxFileTop(a4)
		move.w	wd_Width(a0),GfxFileWidth(a4)
		move.w	wd_Height(a0),GfxFileHeight(a4)
		bra.s	.GotSourceInfo
.TakeScreenFile	move.l	GfxScreen(a4),a0
		move.l	a0,GfxFileScreen(a4)
		move.w	sc_Width(a0),GfxFileWidth(a4)
		move.w	sc_Height(a0),GfxFileHeight(a4)

.GotSourceInfo	tst.l	GfxComplete(a4)			; Correct data for partial dump
		beq.s	.NoPartSave
		move.l	GfxLeft(a4),d0
		move.l	GfxTop(a4),d1
		add.w	d0,GfxFileLeft(a4)
		add.w	d1,GfxFileTop(a4)
		move.l	GfxWidth(a4),d0
		move.l	GfxHeight(a4),d1
		move.w	d0,GfxFileWidth(a4)
		move.w	d1,GfxFileHeight(a4)

.NoPartSave	lea	GfxFileBitMap(a4),a0		; Clear BitMap structure
		move.w	#(bm_SIZEOF>>1)-1,d7
.ClearBM	clr.w	(a0)+
		dbf	d7,.ClearBM

		lea	GfxFileBitMap(a4),a0		; Initialize BitMap Structure
		move.l	GfxFileScreen(a4),a2
		moveq	#0,d0
		move.b	sc_BitMap+bm_Depth(a2),d0
		move.w	GfxFileWidth(a4),d1
		move.w	GfxFileHeight(a4),d2
		RELLIB	InitBitMap,_GfxBase

		lea	GfxFileRPort(a4),a1		; Initialize our rastport
		DOLIB	InitRastPort

		lea	GfxFileRPort(a4),a0		; Link Bitmap into RastPort
		lea	GfxFileBitMap(a4),a1
		move.l	a1,rp_BitMap(a0)

		move.l	#MEMORY_ERR,ErrorPrint(a4)	; Try to allocate Planes
		lea	GfxFileBitMap(a4),a2
		moveq	#0,d0
		move.w	bm_BytesPerRow(a2),d0
		moveq	#0,d1
		move.w	bm_Rows(a2),d1
		RELLIB	UMult32,_UtilityBase
		move.l	d0,d6
		moveq	#0,d7
		move.b	bm_Depth(a2),d7
		subq.w	#1,d7
		lea	bm_Planes(a2),a2
.GetBitPlanes	move.l	d6,d0
		move.l	#MEMF_CHIP|MEMF_CLEAR,d1
		CALLSYS	AllocVec
		tst.l	d0
		bne.s	.GotPlane
.AllocErr	move.l	a3,a0
		RELLIB	UnlockIBase,_IntuitionBase
		CALLSYS	Permit
		bsr	DisplayError
		bra	.EndDumping
.GotPlane	move.l	d0,(a2)+			; Store address to plane
		dbf	d7,.GetBitPlanes

		RELLIB	WaitBlit,_GfxBase
		move.l	GfxFileScreen(a4),a0		; Copy BitMap
		move.l	sc_RastPort+rp_BitMap(a0),a0	; To destination bitmap
		lea	GfxFileBitMap(a4),a1		; in that way the needed
		moveq	#0,d0				; data is automatically
		moveq	#0,d1				; stored in the proper format
		moveq	#0,d4
		moveq	#0,d5
		move.w	GfxFileLeft(a4),d0
		move.w	GfxFileTop(a4),d1
		move.w	GfxFileWidth(a4),d4
		move.w	GfxFileHeight(a4),d5
		moveq	#0,d2
		moveq	#0,d3
		move.l	#$c0,d6
		moveq	#-1,d7
		sub.l	a2,a2
		DOLIB	BltBitMap
		move.l	a3,a0
		RELLIB	UnlockIBase,_IntuitionBase
		CALLSYS	Permit

		lea	GfxFileBitMap(a4),a0
		moveq	#0,d0
		move.w	bm_BytesPerRow(a0),d0
		lsl.l	#1,d0
		move.l	#MEMF_CLEAR,d1
		CALLSYS	AllocVec
		move.l	d0,PackedRow
		tst.l	d0
		beq	.AllocErr

* Now to the real dump

		move.l	PrintHandle(a4),a1		; Turn off all gadgets not needed
		lea	PrintGads(a4),a0
		lea	DisableList(pc),a2
		moveq	#1,d1
.Disable	move.l	(a2)+,d0
		blt.s	.AllOff
		RELLIB	GhostGadget,_KCXBase
		bra.s	.Disable

.AllOff		tst.l	GfxDumpType(a4)			; Dump to file or printer ???
		beq	.DumpToPrinter

		move.l	#GD_GfxCancel,d0		; Additionally turn off Cancel gadget
		DOLIB	GhostGadget

		move.l	#NOIFF_ERR,ErrorPrint(a4)	; Allocate IFF-Handle
		RELLIB	AllocIFF,_IFFParseBase
		move.l	d0,GfxFileHandle(a4)
		tst.l	d0
		beq	.FileError1

		lea	PrintFileName(pc),a0		; Try to open dump file
		move.l	a0,d1
		move.l	d1,PrintErrArg(a4)
		move.l	#MODE_NEWFILE,d2
		RELLIB	Open,_DOSBase
		tst.l	d0
		beq	.DosError

		move.l	GfxFileHandle(a4),a0		; Init IFF-Handle
		move.l	d0,iff_Stream(a0)
		RELLIB	InitIFFasDOS,_IFFParseBase

		move.l	GfxFileHandle(a4),a0		; Open IFF for write
		move.l	#IFFF_WRITE,d0
		DOLIB	OpenIFF
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Push FORM Chunk
		move.l	#'ILBM',d0
		move.l	#'FORM',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Push BitMap Header
		move.l	#'ILBM',d0
		move.l	#'BMHD',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0
		lea	BMHDChunk(pc),a1
		move.w	GfxFileWidth(a4),bmh_Width(a1)	; Get width/height of area
		move.w	GfxFileHeight(a4),bmh_Height(a1)
		clr.w	bmh_Left(a1)			; Clear offsets to image
		clr.w	bmh_Top(a1)
		move.l	GfxScreen(a4),a2		; Store depth of BitMap
		move.b	sc_BitMap+bm_Depth(a2),bmh_Depth(a1)
		clr.b	bmh_Masking(a1)			; No masking/tranp.color
		move.b	#1,bmh_Compression(a1)		; Do compression
		clr.w	bmh_Transparent(a1)
		move.b	#10,bmh_XAspect(a1)		; Store aspect
		move.b	#11,bmh_YAspect(a1)
		move.w	sc_Width(a2),bmh_PageWidth(a1)	; And screen size
		move.w	sc_Height(a2),bmh_PageHeight(a1)
		move.l	#BitMapHeader_SIZEOF,d0		; Write header
		DOLIB	WriteChunkBytes
		cmp.l	#BitMapHeader_SIZEOF,d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0
		DOLIB	PopChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Push colors
		move.l	#'ILBM',d0
		move.l	#'CMAP',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileScreen(a4),a2
		moveq	#0,d0
		moveq	#1,d7
		move.b	sc_BitMap+bm_Depth(a2),d0	; Get depth
		lsl.l	d0,d7
		subq.w	#1,d7				; Get number of colors
		moveq	#0,d6
		move.l	sc_ViewPort+vp_ColorMap(a2),a2	; Get address of ColorMap
.GetColors	move.l	a2,a0
		move.l	d6,d0
		RELLIB	GetRGB4,_GfxBase		; Get color value for register
		move.l	GfxFileHandle(a4),a0
		lea	PrintFileCols(pc),a1		; Calculate IFF RGB colors (R0G0B0)
		move.w	d0,d1
		and.w	#$0f00,d1
		lsr.w	#4,d1
		move.b	d1,(a1)
		move.w	d0,d1
		and.w	#$00f0,d1
		move.b	d1,1(a1)
		and.w	#$000f,d0
		lsl.w	#4,d0
		move.b	d0,2(a1)
		moveq	#3,d0
		RELLIB	WriteChunkBytes,_IFFParseBase	; Write bytes
		cmp.l	#3,d0
		bne	.FileError
		addq.l	#1,d6
		dbf	d7,.GetColors

		move.l	GfxFileHandle(a4),a0		; Pop CMAP Chunk
		DOLIB	PopChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Push CAMG Chunk
		move.l	#'ILBM',d0
		move.l	#'CAMG',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileScreen(a4),a0		; Write ViewPort mode
		lea	sc_ViewPort(a0),a0
		RELLIB	GetVPModeID,_GfxBase
		move.l	d0,CMAPVal
		move.l	GfxFileHandle(a4),a0
		lea	CMAPVal(pc),a1
		moveq	#4,d0
		RELLIB	WriteChunkBytes,_IFFParseBase
		cmp.l	#4,d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Pop Chunk
		DOLIB	PopChunk
		tst.l	d0
		bne	.FileError

		move.l	GfxFileHandle(a4),a0		; Now for BODY
		move.l	#'ILBM',d0
		move.l	#'BODY',d1
		move.l	#IFFSIZE_UNKNOWN,d2
		DOLIB	PushChunk
		tst.l	d0
		bne	.FileError

		moveq	#0,d4				; Clear line counter
		move.w	GfxFileHeight(a4),d5		; Get number of lines
		subq.w	#1,d5
.LoopLines	lea	GfxFileBitMap(a4),a2
		moveq	#0,d7
		move.b	bm_Depth(a2),d7			; Get number of planes
		subq.w	#1,d7
		move.w	bm_BytesPerRow(a2),d6		; Get number of bytes per row
		lea	bm_Planes(a2),a2
.LoopPlanes	move.l	d6,d0				; Calc offset to line
		move.l	d4,d1
		RELLIB	UMult32,_UtilityBase
		lea	PackedRow(pc),a0
		move.l	(a0),d3				; Get address (is to be restored)
		move.l	(a2)+,a1			; Get address of bitplane
		add.l	d0,a1				; Get correct address of line
		move.l	a1,FromPtr			; Store within pointer to pointer
		move.l	d6,-(sp)			; Store length of line
		move.l	a0,-(sp)			; Source address
		lea	FromPtr(pc),a0			; Get pointer to pointer
		move.l	a0,-(sp)
		bsr	_packrow
		move.l	d3,PackedRow			; Remake pointer
		lea	12(sp),sp
		move.l	GfxFileHandle(a4),a0		; Save packed row
		move.l	PackedRow(pc),a1
		move.l	d0,d2
		RELLIB	WriteChunkBytes,_IFFParseBase	; Write line
		cmp.l	d2,d0
		bne.s	.FileError
		dbf	d7,.LoopPlanes			; Loop for planes
		addq.l	#1,d4
		dbf	d5,.LoopLines			; Loop for lines

		move.l	GfxFileHandle(a4),a0		; Pop body chunk
		DOLIB	PopChunk
		tst.l	d0
		bne.s	.FileError

		move.l	GfxFileHandle(a4),a0
		DOLIB	PopChunk

.FileError	tst.l	d0				; Error code ?
		beq.s	.EndFile
		neg.l	d0				; Convert to internal error code
		add.l	#400,d0
		move.l	d0,ErrorPrint(a4)
.FileError1	bsr	DisplayError
		bra.s	.EndFile
.DosError	RELLIB	IoErr,_DOSBase			; Display error
		move.l	d0,ErrorPrint(a4)
		bsr	DisplayError
.EndFile	tst.l	GfxFileHandle(a4)		; Did we have a handle ?
		beq.s	.NoHandle
		move.l	GfxFileHandle(a4),a0		; Close IFF
		RELLIB	CloseIFF,_IFFParseBase
		move.l	GfxFileHandle(a4),a0
		tst.l	iff_Stream(a0)
		beq.s	.NoStream
		move.l	iff_Stream(a0),d1		; Close DOS-Handle
		RELLIB	Close,_DOSBase
.NoStream	move.l	GfxFileHandle(a4),a0		; Free IFF-Handle
		RELLIB	FreeIFF,_IFFParseBase
.NoHandle	bra	.EndDumping


* Now we dump to the printer

.DumpToPrinter	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
		clr.l	LN_NAME(a0)
		clr.b	LN_PRI(a0)
		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)
		move.l	GfxAspect(a4),d0
		move.w	d0,pf_PrintAspect(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			; Initialize source
		lea	GfxFileRPort(a4),a0		; to our own RastPort
		move.l	a0,io_RastPort(a1)
		clr.w	io_SrcX(a1)
		clr.w	io_SrcY(a1)
		move.w	GfxFileWidth(a4),io_SrcWidth(a1)
		move.w	GfxFileHeight(a4),io_SrcHeight(a1)
		move.l	GfxFileScreen(a4),a0
		lea	sc_ViewPort(a0),a0
		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.l	PrintHandle(a4),a0		; Set window title
		LOCLEA	GfxDumpingTitle(pc),a1
		move.l	#~0,a2
		RELLIB	SetWindowTitles,_IntuitionBase

		move.l	PrintHandle(a4),a0		; First clear all messages on WindowPort
		move.l	wd_UserPort(a0),a2
.Clear		move.l	a2,a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq.s	.AllGone
		move.l	d0,a1
		DOLIB	GT_ReplyIMsg
		bra.s	.Clear

.AllGone	moveq	#0,d0
		moveq	#1,d1
		move.b	MP_SIGBIT(a2),d0
		lsl.l	d0,d1
		move.l	d1,d7
		move.l	PrintPort(a4),a0		; Get SigFlag of PrinterPort
		moveq	#0,d2
		moveq	#1,d0
		move.b	MP_SIGBIT(a0),d2
		lsl.l	d2,d0
		or.l	d1,d0
		move.l	d0,d6				; Copy flags
.ReWait		move.l	d6,d0				; Restore flags
		CALLSYS	Wait				; Wait for signals
		moveq	#0,d5
		move.l	d0,-(sp)			; Store return signal
		and.l	d7,d0				; From window ?
		beq.s	.NoDisable			; Nope -> must be printer
.CheckMsgs	move.l	a2,a0				; Get Message from window port
		RELLIB	GT_GetIMsg,_GadToolsBase
		move.l	d0,a1
		tst.l	d0
		beq.s	.NoMsg				; No more messages return to wait
		move.l	im_Class(a1),d4			; Get class and code
		move.w	im_Code(a1),d3
		cmp.w	#'a',d3
		blt.s	.End
		cmp.w	#'z',d3
		bgt.s	.End
		and.w	#~$20,d3
.End		DOLIB	GT_ReplyIMsg			; Reply message
		cmp.l	#IDCMP_GADGETUP,d4		; Gadget released ???
		bne.s	.NoGadget			; Yep -> abort
		moveq	#1,d5
		bra.s	.NoDisable
.NoGadget	cmp.l	#IDCMP_VANILLAKEY,d4		; Key pressed ???
		bne.s	.CheckMsgs			; Nope -> Next message
		move.l	#GD_GfxCancel,d0
		lea	PrintGads(a4),a0
		RELLIB	GetGadgetPtr,_KCXBase
		move.l	gg_UserData(a0),d0
		cmp.b	d0,d3
		bne	.CheckMsgs
		move.l	#GD_GfxCancel,d0		; Give visual feedback
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
		moveq	#1,d5
		bra.s	.NoDisable			; Do abort
.NoMsg		move.l	(sp)+,d0
		bra	.ReWait
.NoDisable	move.l	(sp)+,d0			; Abort dump
		move.l	d0,-(sp)
		move.l	PrintReq(a4),a1
		CALLSYS	AbortIO
		move.l	PrintReq(a4),a1
		DOLIB	WaitIO
		move.l	(sp)+,d0

		tst.l	d5
		beq.s	.NoAbort
		move.l	#PDERR_CANCEL+500,ErrorPrint(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,ErrorPrint(a4)
.PrintError2	lea	ThisPrinter(a4),a0
		move.l	a0,PrintErrArg(a4)
		bsr	DisplayError
		bra.s	.NoPrint
.PrintError
		move.l	#NOPRINT_ERR,ErrorPrint(a4)	; Display open error
		bsr	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)

.EndDumping	lea	GfxFileBitMap(a4),a2		; Check for any BitPlanes
		moveq	#0,d7
		move.b	bm_Depth(a2),d7
		beq.s	.NoMaps
		subq.w	#1,d7
		lea	bm_Planes(a2),a2
.FreeBitPlanes	move.l	(a2)+,d0
		beq.s	.NoFree
		move.l	d0,a1
		CALLSYS	FreeVec
.NoFree		dbf	d7,.FreeBitPlanes
.NoMaps		tst.l	PackedRow
		beq.s	.NoPacked
		move.l	PackedRow(pc),a1
		CALLSYS	FreeVec
.NoPacked	clr.l	GfxFileHandle(a4)
		bsr	CloseDumpWin
		rts
PrintName	dc.b	"printer.device",0
PrintInit	dc.b	27,"#1",0
PrintFFeed	dc.b	12,0
		EVEN




**********************************************************************
*                       Handle the Dump window                       *
**********************************************************************
HandleDumpWin	link	a5,#-(4+4+2+2+2+2+gng_SIZEOF)
		lea	PrintTxt(a4),a0
		move.l	a0,FontPtr(a5)

		bsr	OpenPrintScreen
		move.l	d0,PrintScreen(a4)
		tst.l	d0
		beq	.PrintWinError
		move.l	d0,-4(a5)
		moveq	#0,d2
		moveq	#0,d3
		RELLIB	ComputeFont,_KCXBase
		move.l	-4(a5),a0
		sub.l	a1,a1
		RELLIB	GetVisualInfoA,_GadToolsBase
		move.l	d0,PrintVisInfo(a4)
		beq	.PrintWinError

		move.l	-4(a5),a0
		moveq	#0,d3
		moveq	#0,d2
		move.w	PrintWinWidth(a4),d2
		move.w	PrintWinHeight(a4),d3
		RELLIB	ComputeFont,_KCXBase
		move.l	-4(a5),a0
		move.l	d2,d0
		DOLIB	ComputeX
		move.l	d0,d4
		move.w	PrintWinLeft(a4),d2
		add.w	d2,d0
		add.w	OffX(a5),d0
		moveq	#0,d1
		move.b	sc_WBorRight(a0),d1
		add.w	d1,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	d3,d0
		DOLIB	ComputeY
		move.l	d0,d4
		move.w	PrintWinTop(a4),d3
		add.w	d3,d0
		add.w	OffY(a5),d0
		moveq	#0,d1
		move.b	sc_WBorBottom(a0),d1
		add.w	d1,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,a3
		beq	.PrintWinError

		movem.l d2-d3/a4,-(sp)
		moveq	#0,d3
		lea.l	PrintWinGTags,a4
.PrintWinGL	lea.l	PrintWinNGads,a0
		move.l	d3,d0
		mulu	#gng_SIZEOF,d0
		add.l	d0,a0
		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		moveq	#gng_SIZEOF,d0
		CALLSYS	CopyMem
		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a0
		move.l	a4,-(sp)
		move.l	ZeroBase(pc),a4
		move.l	gng_GadgetText(a0),-(sp)
		bsr	GetLocStr
		move.l	(sp)+,d7
		move.l	d7,gng_GadgetText(a0)
		move.l	PrintVisInfo(a4),gng_VisualInfo(a0)
		move.l	FontPtr(a5),gng_TextAttr(a0)
		move.w	gng_LeftEdge(a0),d0
		RELLIB	ComputeX,_KCXBase
		move.l	(sp)+,a4
		add.w	OffX(a5),d0
		move.w	d0,gng_LeftEdge(a0)
		move.w	gng_TopEdge(a0),d0
		DOLIB	ComputeY
		add.w	OffY(a5),d0
		move.w	d0,gng_TopEdge(a0)
		move.w	gng_Width(a0),d0
		DOLIB	ComputeX
		move.w	d0,gng_Width(a0)
		move.w	gng_Height(a0),d0
		DOLIB	ComputeY
		move.w	d0,gng_Height(a0)
		lea.l	PrintWinGTypes,a0
		moveq	#0,d0
		move.l	d3,d1
		lsl.l	#1,d1
		move.w	0(a0,d1.w),d0
		move.w	d0,d6
		lsl.w	#8,d6
		move.l	a3,a0
		lea.l	-(4+4+2+2+2+2+gng_SIZEOF)(a5),a1
		move.l	a4,a2
		move.l	a4,-(sp)
		move.l	ZeroBase(pc),a4
		bsr	LocalizeGadTags
		RELLIB	CreateGadgetA,_GadToolsBase
		move.l	(sp)+,a4
		tst.l	d0
		beq	.PrintWinError
		move.l	d0,a3
		move.l	d7,a0
		bsr	LocalizeGadKey
		move.l	d0,a3
		or.w	d6,d1
		move.l	d1,gg_UserData(a3)
		move.l	d3,d0
		lsl.l	#2,d0
		move.l	a4,-(sp)
		move.l	ZeroBase(pc),a4
		lea.l	PrintGads(a4),a0
		move.l	(sp)+,a4
		move.l	a3,0(a0,d0.w)
.PrintWinTL	tst.l	(a4)
		beq.s	.PrintWinDN
		addq.w	#8,a4
		bra.s	.PrintWinTL
.PrintWinDN	addq.w	#4,a4
		addq.w	#1,d3
		cmp.w	#PrintWin_CNT,d3
		bmi	.PrintWinGL
		movem.l (sp)+,d2-d3/a4
		move.l	PrintGadget(a4),PrintWinWG+4

		lea	PrintGads(a4),a0
		bsr	SetStrIntGads

		LOCLEA	DefPrintTitle,a0
		lea	PrintTitle(a4),a1
		move.l	a1,PrintWinWG+12
		bsr	StrCpy
		lea	DumpHotKey(a4),a0
		lea	PrintTitle(a4),a1
		bsr	StrCat
		LOCLEA	WindowScrTitle,PrintWinWG+20
		move.l	-4(a5),PrintWinSC+4		; Open window
		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),d0
		RELLIB	ComputeX,_KCXBase
		add.w	OffX(a5),d0
		moveq	#0,d1
		move.b	sc_WBorRight(a0),d1
		add.w	d1,d0
		move.l	d0,PrintWinW+4
		move.w	PrintWinHeight(a4),d0
		DOLIB	ComputeY
		add.w	OffY(a5),d0
		moveq	#0,d1
		move.b	sc_WBorBottom(a0),d1
		add.w	d1,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

		move.l	PrintScreen(a4),a0
		RELLIB	ScreenToFront,_IntuitionBase

		bsr.s	SetPrintGads
		unlk	a5
		bra	CheckDumpInput

.PrintWinError	bsr	CloseDumpWin
		move.l	#MEMORY_ERR,ErrorPrint(a4)
		bsr	DisplayError
		unlk	a5
		moveq	#0,d0
		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




**********************************************************************
*                      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	#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.l	GfxShade(a4),d1			; Set shading
		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
		tst.l	GfxShade(a4)
		bne.s	.ThresOn
		moveq	#1,d1
		bra.s	.MakeThres
.ThresOn	moveq	#0,d1
.MakeThres	move.l	#GD_GfxThres,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.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	SetPrintCycle

		move.l	#GD_GfxDumpType,d0		; Set type of output
		move.l	GfxDumpType(a4),d1
		bsr.s	SetPrintCycle

		bsr	SetPrintArea

		move.l	GfxComplete(a4),d1
		bchg	#0,d1
		move.l	#GD_GfxX,d0
		bsr	GhostPrintGad
		move.l	#GD_GfxY,d0
		bsr	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	RELLIB	SetTextGad,_KCXBase
		rts
SetPrintCycle	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	SetCycleGad,_KCXBase
		rts
SetPrintBox	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	SetCheckBox,_KCXBase
		rts
GhostPrintGad	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	GhostGadget,_KCXBase
		rts
SetPrintInt	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	SetIntegerGad,_KCXBase
		rts
SetPrintSlid	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	SetSliderGad,_KCXBase
		rts
**********************************************************************
*              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
		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)
		tst.l	PrintScreen(a4)
		beq.s	.NoScreen
		move.l	PrintScreen(a4),a0
		RELLIB	CloseScreen,_IntuitionBase
.NoScreen	clr.l	PrintScreen(a4)
		tst.l	PrintFont
		beq.s	.NoFont
		move.l	PrintFont(pc),a1
		RELLIB	CloseFont,_GfxBase
.NoFont		rts


**********************************************************************
*                     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
		move.l	d5,d0
		bsr	GetUpperCase
		move.l	d0,d5
.End		move.l	d6,d0
		and.l	#(IDCMP_GADGETUP|IDCMP_GADGETDOWN),d0
		beq.s	.NoGad
		moveq	#0,d7
		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		; Changed window position ?
		bne.s	NoPrintMove
		move.l	PrintHandle(a4),a0
		lea	PrintWinLeft(a4),a1
		move.w	wd_LeftEdge(a0),0(a1)
		move.w	wd_TopEdge(a0),2(a1)
		bra	LoopPrintMsg

NoPrintMove	cmp.l	#IDCMP_VANILLAKEY,d6
		bne.s	NoVKey
		cmp.w	#ESCKEY,d5
		beq	CancelPrint
		lea	PrintGads(a4),a3
		moveq	#0,d1
.FindGad	move.l	(a3),d0
		beq	LoopPrintMsg
		move.l	d0,a0
		move.l	gg_UserData(a0),d0
		cmp.b	d0,d5
		bne.s	.NextGad
		move.l	#IDCMP_GADGETUP,d6
		moveq	#-1,d5
		move.l	d1,d7
		bra.s	NoVKey
.NextGad	addq.l	#4,a3
		addq.l	#1,d1
		bra.s	.FindGad

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

		cmp.w	#GD_GfxAspect,d7		; Aspect ?
		bne.s	NoAspectGad
		move.l	GfxAspect(a4),d1
		bchg	#0,d1
		move.l	d1,GfxAspect(a4)
		move.l	#GD_GfxAspect,d0
		bsr	SetPrintCycle
		bra	LoopPrintMsg

NoAspectGad	cmp.w	#GD_GfxShade,d7			; New Shade ?
		bne.s	NoShadeGad
		tst.l	d5
		bge.s	.DoKey
		move.l	GfxShade(a4),d5
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d5
		bge.s	.GoOnKey
		moveq	#3,d5
		bra.s	.GoOnKey
.Up		addq.l	#1,d5
		cmp.l	#3,d5
		ble.s	.GoOnKey
		moveq	#0,d5
.GoOnKey	move.l	#GD_GfxShade,d0
		move.l	d5,d1
		bsr	SetPrintCycle
.DoKey		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
		tst.l	GfxShade(a4)
		bne.s	.ThresOn
		moveq	#1,d1
		bra.s	.MakeThres
.ThresOn	moveq	#0,d1
.MakeThres	move.l	#GD_GfxThres,d0
		bsr	GhostPrintGad
		bra	LoopPrintMsg

NoShadeGad	cmp.w	#GD_GfxDither,d7		; New dither ?
		bne.s	NoDitherGad
		tst.l	d5
		bge.s	.DoKey
		move.l	GfxDithering(a4),d5
		and.w	#IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT,d4
		beq.s	.Up
		subq.l	#1,d5
		ble.s	.GoOnKey
		moveq	#2,d5
		bra.s	.GoOnKey
.Up		addq.l	#1,d5
		cmp.l	#2,d5
		ble.s	.GoOnKey
		moveq	#0,d5
.GoOnKey	move.l	#GD_GfxDither,d0
		move.l	d5,d1
		bsr	SetPrintCycle
.DoKey		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
		move.l	GfxImage(a4),d1
		bchg	#0,d1
		move.l	d1,GfxImage(a4)
		move.l	#GD_GfxImage,d0
		bsr	SetPrintCycle
		bra	LoopPrintMsg

NoImageGad	cmp.w	#GD_GfxDensity,d7		; Changed density ?
		bne.s	NoDensityGad
		tst.l	d5
		bge.s	.DoKey
		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
.DoKey		ext.l	d5
		move.l	d5,GfxDensity(a4)
		bra	LoopPrintMsg

NoDensityGad	cmp.w	#GD_GfxRed,d7			; Changed red colors ?
		bne.s	NoRedGad
		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
		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
		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
		tst.l	d5
		bge.s	.DoKey
		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
.DoKey		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
		tst.l	d5
		bge.s	DoSize1Key
		cmp.l	#4,GfxScale(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxSize1,d0
ActPrintGad	lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a1
		RELLIB	ActStringGad,_KCXBase
		bra	LoopPrintMsg
DoSize1Key	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
		RELLIB	SetIntegerGad,_KCXBase
		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
		tst.l	d5
		bge.s	.DoKey
		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
.DoKey		ext.l	d5
		move.l	d5,GfxThreshold(a4)
		bra	LoopPrintMsg

NoThresGad	cmp.w	#GD_GfxCenter,d7		; Changed center ?
		bne.s	NoCenterGad
		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
		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
		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
		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
		move.l	GfxComplete(a4),d1
		bchg	#0,d1
		move.l	d1,GfxComplete(a4)
		move.l	#GD_GfxGfxType,d0
		bsr	SetPrintCycle
		bchg	#0,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
		tst.l	d5
		bge.s	.NoKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxX,d0
		bra	ActPrintGad
.NoKey		lea	GfxLeft(a4),a1
		bra	CheckPrintInt

NoGfxLeftGad	cmp.w	#GD_GfxY,d7			; Changed top ?
		bne.s	NoGfxTopEdge
		tst.l	d5
		bge.s	.NoKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxY,d0
		bra	ActPrintGad
.NoKey		lea	GfxTop(a4),a1
		bra	CheckPrintInt

NoGfxTopEdge	cmp.w	#GD_GfxWidth,d7			; Changed width ?
		bne.s	NoGfxWidthGad
		tst.l	d5
		bge.s	.NoKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxWidth,d0
		bra	ActPrintGad
.NoKey		lea	GfxWidth(a4),a1
		bra	CheckPrintInt

NoGfxWidthGad	cmp.w	#GD_GfxHeight,d7		; Changed height ?
		bne.s	NoGfxHeightGad
		tst.l	d5
		bge.s	.NoKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxHeight,d0
		bra	ActPrintGad
.NoKey		lea	GfxHeight(a4),a1
		bra	CheckPrintInt

NoGfxHeightGad	cmp.w	#GD_GfxSource,d7		; Changed source ?
		bne.s	NoGfxSourceGad
		move.l	GfxSource(a4),d5
		bchg	#0,d5
		move.l	d5,GfxSource(a4)
		move.l	#GD_GfxSource,d0
		move.l	d5,d1
		bsr	SetPrintCycle
GfxSourceKey	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
		RELLIB	SetTextGad,_KCXBase
		bra	LoopPrintMsg

NoGfxSourceGad	cmp.w	#GD_GfxGet,d7			; Get new window/screen ?
		bne	NoGfxGetGad
		tst.l	d5
		bge.s	.NoKey
		move.l	#GD_GfxGet,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
.NoKey		move.l	PrintHandle(a4),a0
		LOCLEA	GfxGetTitle,a1
		LOCLEA	WindowScrTitle,a2
		RELLIB	SetWindowTitles,_IntuitionBase
		ST	GetSource(a4)
		move.l	#SIGLBUTTON,d0
		CALLSYS	Wait
		SF	GetSource(a4)
		bsr	GetNewSource
		move.l	PrintHandle(a4),a0
		lea	PrintTitle(a4),a1
		LOCLEA	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
		tst.l	d5
		bge.s	.NoKey
		tst.l	GfxComplete(a4)
		beq	LoopPrintMsg
		move.l	#GD_GfxBounds,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
.NoKey		bsr	GetNewBounds
		bra	LoopPrintMsg

NoGfxBoundGad	cmp.w	#GD_GfxPrint,d7			; Print ?
		bne.s	NoPrintGad
		tst.l	d5
		bge.s	.NoKey
		move.l	#GD_GfxPrint,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
.NoKey		tst.l	GfxDumpType(a4)
		bne.s	.NoDims
		bsr	CheckPrintDim
		tst.l	d0
		beq	LoopPrintMsg
		bra.s	.GoOn
.NoDims		clr.l	-(sp)
		pea	FRF_DOSAVEMODE
		clr.l	-(sp)
		clr.w	-(sp)
		lea	PrintFileName(pc),a0
		move.l	a0,-(sp)
		pea	PrintDumpHeader
		move.l	PrintHandle(a4),-(sp)
		bsr	GetFileName
		lea	26(sp),sp
		bra.s	EndInput
.GoOn		moveq	#1,d0
		bra.s	EndInput

NoPrintGad	cmp.w	#GD_GfxCancel,d7		; Cancel ?
		bne.s	NoPrintCancel
		tst.l	d5
		bge.s	.NoKey
		move.l	#GD_GfxCancel,d0
		lea	PrintGads(a4),a0
		move.l	PrintHandle(a4),a5
		bsr	ButtonCheck
.NoKey
CancelPrint	moveq	#0,d0
		bra.s	EndInput

NoPrintCancel	cmp.w	#GD_GfxDumpType,d7		; New dump type ?
		bne.s	NoDumpType
		move.l	GfxDumpType(a4),d1
		bchg	#0,d1
		move.l	d1,GfxDumpType(a4)
		move.l	#GD_GfxDumpType,d0
		bsr	SetPrintCycle
		bra	LoopPrintMsg
NoDumpType
NoPrintGadUp	bra	LoopPrintMsg
EndInput	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)
		RELLIB	FindWindow,_KCXBase
		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),d0
		beq.s	.NoLayer
		move.l	d0,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),d0
		beq.s	.NoScreen
		move.l	d0,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.l	d0,GfxLeft(a4)
		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	DrawBoundRec			; Draw new one
		bra	.DrawLoop
.EndDraw	bsr	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



**********************************************************************
*                      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




**********************************************************************
*             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,ErrorPrint(a4)
		bsr.s	DisplayError
		moveq	#0,d0
		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


**********************************************************************
*                      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

**********************************************************************
*              Stub for calling the library`s EditHook               *
**********************************************************************
MyStrEditFunc	movem.l	RegsAll,-(sp)
		move.l	h_Data(a0),a4
		RELLIB	StrEditFunc,_KCXBase
		movem.l	(sp)+,RegsAll
		rts




**********************************************************************
*                          Display an error                          *
**********************************************************************
DisplayError	movem.l	RegsAll,-(sp)
		move.l	ErrorPrint(a4),d0
		lea	PrintErrArg(a4),a3
		RELLIB	DisplayError,_KCXBase
		movem.l	(sp)+,RegsAll
		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	.End
		RELLIB	GetGadgetPtr,_KCXBase
		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	wd_IDCMPFlags(a5),d5
		move.l	a5,a0
		move.l	#IDCMP_RAWKEY,d0
		DOLIB	ModifyIDCMP
.WaitMsg	move.l	wd_UserPort(a5),a0
		CALLSYS	WaitPort
.LoopMsgs	move.l	wd_UserPort(a5),a0
		RELLIB	GT_GetIMsg,_GadToolsBase
		tst.l	d0
		beq.s	.WaitMsg
		move.l	d0,a1
		move.l	im_Class(a1),d6
		move.w	im_Code(a1),d7
		DOLIB	GT_ReplyIMsg
		cmp.l	#IDCMP_RAWKEY,d6
		bne.s	.LoopMsgs
		and.w	#IECODE_UP_PREFIX,d7
		beq.s	.LoopMsgs
		move.l	a5,a0
		move.l	d5,d0
		RELLIB	ModifyIDCMP,_IntuitionBase
		and.w	#~GFLG_SELECTED,gg_Flags(a3)
		move.l	a3,a0
		move.l	a5,a1
		sub.l	a2,a2
		moveq	#1,d0
		DOLIB	RefreshGList
.End		movem.l	(sp)+,RegsAll
		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 (Offset)                              *
**********************************************************************
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,#-(ra_SIZEOF)
		move.l	.Window(a5),a0
		move.l	wd_WScreen(a0),a0
		lea	sc_ViewPort(a0),a0
		RELLIB	GetVPModeID,_GfxBase
		move.l	d0,a0
		lea	-(ra_SIZEOF)(a5),a1
		move.l	#OSCAN_TEXT,d0
		RELLIB	QueryOverscan,_IntuitionBase
		lea	-(ra_SIZEOF)(a5),a2
		moveq	#0,d0
		move.w	ra_MaxX(a2),d0
		sub.w	ra_MinX(a2),d0
		addq.w	#1,d0
		move.l	#45,d1
		RELLIB	UMult32,_UtilityBase
		move.l	#100,d1
		DOLIB	UDivMod32
		move.l	d0,d2				; Width of FileReq
		moveq	#0,d0
		move.w	ra_MaxY(a2),d0
		sub.w	ra_MinY(a2),d0
		addq.w	#1,d0
		moveq	#8,d1
		DOLIB	UMult32
		moveq	#10,d1
		DOLIB	UDivMod32
		move.l	d0,d3				; Height of FileReq
		move.l	d2,FileReqWidth
		move.l	d3,FileReqHeight
		moveq	#0,d0
		moveq	#0,d1
		move.w	ra_MaxX(a2),d0
		addq.w	#1,d0
		move.w	ra_MaxY(a2),d1
		addq.w	#1,d1
		sub.w	d2,d0
		sub.w	d3,d1
		lsr.w	#1,d0
		lsr.w	#1,d1
		move.l	.Window(a5),a2
		move.l	wd_WScreen(a2),a2
		sub.w	sc_LeftEdge(a2),d0
		sub.w	sc_TopEdge(a2),d1
		move.l	d0,FileReqLeft
		move.l	d1,FileReqTop

		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
		bsr	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
		bsr	StrCpy
		tst.l	d0
		blt.s	.NoDir
		move.b	(a2),d6
		clr.b	(a2)
		move.l	.CompleteName(a5),a0
		lea	DirPath(a4),a1
		bsr	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
		bsr	StrCpy
		move.l	.CompleteName(a5),a0
		bsr	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
		bsr	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),d7
		move.l	_KCXBase(a4),a6
		jsr	0(a6,d7)
		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	ASLFR_TitleText
FileReqHeader	dc.l	0
		dc.l	ASLFR_Window
FileReqWin	dc.l	0
		dc.l	ASLFR_InitialLeftEdge
FileReqLeft	dc.l	0
		dc.l	ASLFR_InitialTopEdge
FileReqTop	dc.l	0
		dc.l	ASLFR_InitialWidth
FileReqWidth	dc.l	320
		dc.l	ASLFR_InitialHeight
FileReqHeight	dc.l	140
		dc.l	ASLFR_InitialFile
FileReqFile	dc.l	0
		dc.l	ASLFR_InitialDrawer
FileReqDir	dc.l	0
		dc.l	ASLFR_Flags1
FileReqDirs	dc.l	0
		dc.l	ASLFR_Flags2
		dc.l	FRF_REJECTICONS
		dc.l	ASLFR_Locale
FileReqLoc	dc.l	0
		dc.l	TAG_DONE





**********************************************************************
*                        Close the WB-Screen                         *
**********************************************************************
OpenPrintScreen	CARGS	#-12,.WBScreen.L,.ModeID.L,.WBDrawInfo.L
		link	a5,#-(12+dim_SIZEOF)
		lea	WBName(pc),a0			; Lock WB-Screen
		RELLIB	LockPubScreen,_IntuitionBase
		move.l	d0,.WBScreen(a5)
		tst.l	d0
		beq	.NoScreen

		move.l	.WBScreen(a5),a0		; Get Screen`s DrawInfo
		DOLIB	GetScreenDrawInfo
		move.l	d0,.WBDrawInfo(a5)
		tst.l	d0
		beq	.NoScreen

		move.l	.WBScreen(a5),a0		; No get ViewPort`s ModeID
		lea	sc_ViewPort(a0),a0
		RELLIB	GetVPModeID,_GfxBase
		move.l	d0,.ModeID(a5)
		cmp.l	#INVALID_ID,d0
		beq	.NoScreen

		move.l	.WBDrawInfo(a5),a0		; Close the WB`s font
		move.l	dri_Font(a0),a0
		move.l	a0,a2
		move.l	LN_NAME(a0),a0
		lea	PrintFontName(pc),a1
		bsr	StrCpy

		lea	PrintScreenTxt(pc),a0
		lea	PrintFontName(pc),a1
		move.l	a1,ta_Name(a0)
		move.w	tf_YSize(a2),ta_YSize(a0)
		move.b	tf_Style(a2),ta_Style(a0)
		move.b	tf_Flags(a2),ta_Flags(a0)
		DOLIB	OpenFont			; Try to open font
		move.l	d0,PrintFont
		tst.l	d0
		beq	.NoScreen

		sub.l	a0,a0				; Get default sizes of Screen
		lea	-(12+dim_SIZEOF)(a5),a1
		move.l	#dim_SIZEOF,d0
		move.l	#DTAG_DIMS,d1
		move.l	.ModeID(a5),d2
		DOLIB	GetDisplayInfoData
		lea	(-(12+dim_SIZEOF)+dim_Nominal)(a5),a0
		moveq	#0,d0
		move.w	ra_MaxX(a0),d0
		addq.w	#1,d0
		move.l	d0,ScrWidth+4
		move.w	ra_MaxY(a0),d0
		addq.w	#1,d0
		move.l	d0,ScrHeight+4

		LOCLEA	WindowScrTitle,a0
		move.l	a0,ScrName+4

		moveq	#0,d0				; Now fill in our taglist
		move.l	.WBScreen(a5),a2		; and open the screen
		sub.l	a0,a0
		lea	PrintScreenTags(pc),a1
		moveq	#0,d0
		move.b	sc_BitMap+bm_Depth(a2),d0
		move.l	d0,ScrDepth+4
		move.l	.WBDrawInfo(a5),a3
		move.l	dri_Pens(a3),ScrPens+4
		move.l	.ModeID(a5),ScrMode+4
		RELLIB	OpenScreenTagList,_IntuitionBase
		move.l	d0,PrintScreen(a4)
		beq.s	.NoScreen

		move.l	.WBDrawInfo(a5),a0		; We don`t need no DrawInfo anymore
		DOLIB	FreeScreenDrawInfo
		sub.l	a0,a0
		move.l	.WBScreen(a5),a1		; And no lock on the screen
		DOLIB	UnlockPubScreen

		move.l	PrintScreen(a4),d0		; Return pointer to screen
		unlk	a5
		rts
.NoScreen	tst.l	PrintFont			; Close open resources
		beq.s	.NoFont
		move.l	PrintFont(pc),a1
		RELLIB	CloseFont,_GfxBase
.NoFont		tst.l	.WBDrawInfo(a5)
		beq.s	.NoDrawInfo
		move.l	.WBDrawInfo(a5),a0
		RELLIB	FreeScreenDrawInfo,_IntuitionBase
.NoDrawInfo	tst.l	.WBScreen(a5)
		beq.s	.NoWBScreen
		sub.l	a0,a0
		move.l	.WBScreen(a5),a1
		RELLIB	UnlockPubScreen,_IntuitionBase
.NoWBScreen	moveq	#0,d0
		unlk	a5
		rts
WBName		dc.b	"Workbench",0
		EVEN











**********************************************************************
*                     Get a string froma locale                      *
**********************************************************************
GetLocStr	movem.l	d0-d1/a0-a1/a6,-(sp)
		move.l	MyCatalog,d1
		beq.s	.End
		move.l	24(sp),d0
		beq.s	.End
		move.l	d0,a1
		moveq	#0,d0
		move.l	a1,d1
		lea	LOCALE_END(pc),a0
		cmp.l	a0,d1
		bgt.s	.End
		lea	LOCALE_START(pc),a0
		cmp.l	a0,d1
		blt.s	.End
		sub.l	a0,d1
		beq.s	.GetIt

.Loop		tst.b	(a0)+
		bne.s	.Ok
		addq.l	#1,d0
.Ok		subq.l	#1,d1
		bne.s	.Loop

.GetIt		move.l	MyCatalog,a0
		RELLIB	GetCatalogStr,_LocaleBase
		move.l	d0,24(sp)
.End		movem.l	(sp)+,d0-d1/a0-a1/a6
		rts


**********************************************************************
*                    Localize a gadget`s shortcut                    *
*  A0 = Pointer to text                                              *
*  RETURN :                                                          *
*  D1 = Shortcut                                                     *
**********************************************************************
LocalizeGadKey	move.l	d0,-(sp)
		moveq	#0,d1
		move.l	a0,d2
		beq.s	.End
.GetShort	move.b	(a0)+,d2
		beq.s	.End
		cmp.b	#'_',d2
		bne.s	.GetShort
		moveq	#0,d0
		move.b	(a0),d0
		bsr.s	GetUpperCase
		move.l	d0,d1
.End		move.l	(sp)+,d0
		rts


**********************************************************************
*          Convert a char to uppercase using Locale or Util          *
**********************************************************************
GetUpperCase	movem.l	d1-d7/a0-a6,-(sp)		; Convert a char to upper case
		move.l	ZeroBase(pc),a4
		cmp.l	#48,d0
		blt.s	.NormChar
		cmp.l	#57,d0
		bgt.s	.NormChar
		lea	ConvTable(pc),a0
		sub.w	#48,d0
		moveq	#0,d1
		move.b	0(a0,d0),d1
		move.l	d1,d0
.NormChar	tst.l	MyLocale
		beq.s	.UseUtil
		move.l	MyLocale,a0			; Using Locale
		RELLIB	ConvToUpper,_LocaleBase
		bra.s	.End
.UseUtil	RELLIB	ToUpper,_UtilityBase		; or utility.library
.End		movem.l	(sp)+,d1-d7/a0-a6
		rts
ConvTable	dc.b	"=","!",'"',"§","$","%","&","/","(",")"
		EVEN



**********************************************************************
*         Localizes tags of a ListView, Cycle and MX gadget          *
* D0 = Type of Gadget                                                *
* A2 = Pointer to TagList                                            *
**********************************************************************
LocalizeGadTags	movem.l	RegsAll,-(sp)
		cmp.w	#CYCLE_KIND,d0
		bne.s	.NoCycle
		move.l	#GTCY_Labels,d0
		move.l	a2,a0
		RELLIB	FindTagItem,_UtilityBase
		tst.l	d0
		beq.s	.End
		move.l	d0,a2
		move.l	ti_Data(a2),a2
.PatchCycles	move.l	(a2),d0
		beq.s	.End
		move.l	d0,-(sp)
		bsr	GetLocStr
		move.l	(sp)+,(a2)
		addq.l	#4,a2
		bra.s	.PatchCycles
.NoCycle
.End		movem.l	(sp)+,RegsAll
		rts






**********************************************************************
*           Include the other`s ByteRunEncoding routine :)           *
**********************************************************************
		INCLUDE	PackRow.Asm
		EVEN





**********************************************************************
*                 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
    DC.L    WA_ScreenTitle,WindowScrTitle
PrintWinSC:
    DC.L    WA_PubScreen,0
    DC.L    TAG_DONE



PrintWinGTypes:
    DC.W    CYCLE_KIND
    DC.W    CYCLE_KIND
    DC.W    CYCLE_KIND
    DC.W    CYCLE_KIND
    DC.W    SLIDER_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CYCLE_KIND
    DC.W    INTEGER_KIND
    DC.W    INTEGER_KIND
    DC.W    SLIDER_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CHECKBOX_KIND
    DC.W    CYCLE_KIND
    DC.W    INTEGER_KIND
    DC.W    INTEGER_KIND
    DC.W    INTEGER_KIND
    DC.W    INTEGER_KIND
    DC.W    CYCLE_KIND
    DC.W    TEXT_KIND
    DC.W    BUTTON_KIND
    DC.W    BUTTON_KIND
    DC.W    BUTTON_KIND
    DC.W    BUTTON_KIND
    DC.W    CYCLE_KIND



PrintWinNGads:
    DC.W    123,2,167,12
    DC.L    GfxAspectText,0
    DC.W    GD_GfxAspect
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    123,18,167,12
    DC.L    GfxShadeText,0
    DC.W    GD_GfxShade
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    123,34,167,12
    DC.L    GfxDitherText,0
    DC.W    GD_GfxDither
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    367,2,167,12
    DC.L    GfxImageText,0
    DC.W    GD_GfxImage
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    182,66,108,11
    DC.L    GfxDensityText,0
    DC.W    GD_GfxDensity
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    299,18,26,11
    DC.L    GfxRedText,0
    DC.W    GD_GfxRed
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    372,18,26,11
    DC.L    GfxGreenText,0
    DC.W    GD_GfxGreen
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    456,18,26,11
    DC.L    GfxBlueText,0
    DC.W    GD_GfxBlue
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    123,50,167,12
    DC.L    GfxScaleText,0
    DC.W    GD_GfxScale
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    371,50,70,12
    DC.L    GfxSize1Text,0
    DC.W    GD_GfxSize1
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    465,50,70,12
    DC.L    GfxSize2Text,0
    DC.W    GD_GfxSize2
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    182,81,108,11
    DC.L    GfxThresText,0
    DC.W    GD_GfxThres
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    299,66,26,11
    DC.L    GfxCenterText,0
    DC.W    GD_GfxCenter
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    433,66,26,11
    DC.L    GfxSmoothText,0
    DC.W    GD_GfxSmooth
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    299,81,26,11
    DC.L    GfxFormFeedText,0
    DC.W    GD_GfxFormFeed
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    433,81,26,11
    DC.L    GfxKeepAspectText,0
    DC.W    GD_GfxKeepAspect
    DC.L    PLACETEXT_RIGHT,0,0
    DC.W    117,114,120,12
    DC.L    GfxGfxTypeText,0
    DC.W    GD_GfxGfxType
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    257,114,52,13
    DC.L    GfxXText,0
    DC.W    GD_GfxX
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    337,114,52,13
    DC.L    GfxYText,0
    DC.W    GD_GfxY
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    417,114,52,13
    DC.L    GfxWidthText,0
    DC.W    GD_GfxWidth
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    497,114,52,13
    DC.L    GfxHeightText,0
    DC.W    GD_GfxHeight
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    117,130,120,12
    DC.L    GfxSourceText,0
    DC.W    GD_GfxSource
    DC.L    PLACETEXT_LEFT,0,0
    DC.W    238,130,310,12
    DC.L    0,0
    DC.W    GD_GfxSourceName
    DC.L    0,0,0
    DC.W    124,148,166,12
    DC.L    GfxGetText,0
    DC.W    GD_GfxGet
    DC.L    PLACETEXT_IN,0,0
    DC.W    34,148,86,12
    DC.L    GfxPrintText,0
    DC.W    GD_GfxPrint
    DC.L    PLACETEXT_IN,0,0
    DC.W    464,148,86,12
    DC.L    GfxCancelText,0
    DC.W    GD_GfxCancel
    DC.L    PLACETEXT_IN,0,0
    DC.W    294,148,166,12
    DC.L    GfxBoundsText,0
    DC.W    GD_GfxBounds
    DC.L    PLACETEXT_IN,0,0
    DC.W    257,100,120,12
    DC.L    GfxDumpTypeText,0
    DC.W    GD_GfxDumpType
    DC.L    PLACETEXT_LEFT,0,0

PrintWinGTags:
    DC.L    GTCY_Labels,GfxAspectLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxShadeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxDitherLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxImageLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    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
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxScaleLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,6
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,6
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    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
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCB_Scaled,-1
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxGfxTypeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTST_EditHook,StrEditHook
    DC.L    STRINGA_ExitHelp,1
    DC.L    GTIN_Number,0
    DC.L    GTIN_MaxChars,4
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxSourceLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTTX_Border,1
    DC.L    TAG_DONE
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE
    DC.L    GTCY_Labels,GfxDumpTypeLabels
    DC.L    GT_Underscore,'_'
    DC.L    TAG_DONE



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
GfxDumpTypeLabels:
    DC.L    GfxDumpTypeLab0
    DC.L    GfxDumpTypeLab1
    DC.L    0

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
GD_GfxDumpType                         EQU    27


ShadeFlags	dc.w	SHADE_BW,SHADE_GREYSCALE,SHADE_GREYSCALE,SHADE_COLOR
DitherFlags	dc.w	ORDERED_DITHERING,HALFTONE_DITHERING,FLOYD_DITHERING





**********************************************************************
*                    Tags for opening the screen                     *
**********************************************************************
PrintScreenTags
ScrWidth	dc.l	SA_Width,0
ScrHeight	dc.l	SA_Height,0
ScrDepth	dc.l	SA_Depth,2
		dc.l	SA_Overscan,OSCAN_TEXT
		dc.l	SA_AutoScroll,1
ScrPens		dc.l	SA_Pens,0
ScrFont		dc.l	SA_Font,PrintScreenTxt
ScrMode		dc.l	SA_DisplayID,0
ScrName		dc.l	SA_Title,0
		dc.l	TAG_DONE
PrintScreenTxt	ds.b	ta_SIZEOF
PrintFontName	ds.b	80
PrintFont	dc.l	0


**********************************************************************
*         List of gadgets to be disabled before dump to file         *
**********************************************************************
DisableList	dc.l	GD_GfxAspect
		dc.l	GD_GfxShade
		dc.l	GD_GfxDither
		dc.l	GD_GfxImage
		dc.l	GD_GfxDensity
		dc.l	GD_GfxRed
		dc.l	GD_GfxGreen
		dc.l	GD_GfxBlue
		dc.l	GD_GfxScale
		dc.l	GD_GfxSize1
		dc.l	GD_GfxSize2
		dc.l	GD_GfxThres
		dc.l	GD_GfxCenter
		dc.l	GD_GfxSmooth
		dc.l	GD_GfxFormFeed
		dc.l	GD_GfxKeepAspect
		dc.l	GD_GfxGfxType
		dc.l	GD_GfxX
		dc.l	GD_GfxY
		dc.l	GD_GfxWidth
		dc.l	GD_GfxHeight
		dc.l	GD_GfxSource
		dc.l	GD_GfxSourceName
		dc.l	GD_GfxGet
		dc.l	GD_GfxPrint
		dc.l	GD_GfxBounds
		dc.l	GD_GfxDumpType
		dc.l	-1

**********************************************************************
*                             Edit-Hook                              *
**********************************************************************
StrEditHook	ds.b	h_SIZEOF



**********************************************************************
*                      Buffers for File-Dumping                      *
**********************************************************************
CMAPVal		dc.l	0
PackedRow	dc.l	0
FromPtr		dc.l	0
PrintFileCols	ds.b	4
PrintFileName	ds.b	256
PrintDumpHeader	dc.b	"Select file to dump to",0
		EVEN



**********************************************************************
*                            Some titles                             *
**********************************************************************
ScrDimmFormat	dc.b	"%2.2ld",0
		EVEN




**********************************************************************
*                  Definitions for ILBM-Structures                   *
**********************************************************************
	STRUCTURE BitMapHeader,0
		UWORD	 bmh_Width
		UWORD	 bmh_Height
		WORD	 bmh_Left
		WORD	 bmh_Top
		UBYTE	 bmh_Depth
		UBYTE	 bmh_Masking
		UBYTE	 bmh_Compression
		UBYTE	 bmh_Pad
		UWORD	 bmh_Transparent
		UBYTE	 bmh_XAspect
		UBYTE	 bmh_YAspect
		WORD	 bmh_PageWidth
		WORD	 bmh_PageHeight
	LABEL BitMapHeader_SIZEOF
BMHDChunk	ds.b	BitMapHeader_SIZEOF



**********************************************************************
*                         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



**********************************************************************
*                            Revision Tag                            *
**********************************************************************
VersionTag	dc.l	RevStr
RevStr		REVISION
		dc.b	0
		EVEN




LOCALE_START
* CATALOG kcxdump
* VERSION 2.5
* DATE 01.02.93
DefPrintTitle		dc.b	"Graphics dump : HotKey=",0
* D				"Graphikausdruck : HotKey=",0
WindowScrTitle		dc.b	"KCommodity by Kai Iske. ShareWare",0
* D				"KCommodity von Kai Iske. ShareWare",0
GfxGetTitle		dc.b	"Position mouse and press left button",0
* D				"Positionieren Sie die Maus und drücken Sie die linke Maustaste.",0
GfxDumpingTitle		dc.b	"Dump in progress !!!",0
* D				"Druck in Arbeit !!!",0
PrintHead		dc.b	"KCX-GraphicsDump",0
* D				"KCX-GraphikDruck",0
NoBackText		dc.b	"KCommodity V%s is not running. Aborting.",10,0
* D				"KCommodity V%s ist nicht aktiv. Abbruch.",10,0
GfxAspectText		dc.b	"_Aspect",0
* D				"Ausrich_tung",0
GfxShadeText		dc.b	"_Shade",0
* D				"_Schattierung",0
GfxDitherText		dc.b	"_Dithering",0
* D				"Schatt_en",0
GfxImageText		dc.b	"_Image",0
* D				"B_ild",0
GfxDensityText		dc.b	"D_ensity      ",0
* D				"_Dichte      ",0
GfxRedText		dc.b	"_Red",0
* D				"_Rot",0
GfxGreenText		dc.b	"_Green",0
* D				"_Grün",0
GfxBlueText		dc.b	"_Blue",0
* D				"B_lau",0
GfxScaleText		dc.b	"Sca_ling",0
* D				"S_kalierung",0
GfxSize1Text		dc.b	"Si_ze",0
* D				"Grö_ße",0
GfxSize2Text		dc.b	"x",0
* D				"x",0
GfxThresText		dc.b	"_Threshold      ",0
* D				"SW-Gren_ze      ",0
GfxCenterText		dc.b	"Ce_ntered",0
* D				"Ze_ntriert",0
GfxSmoothText		dc.b	"S_moothing",0
* D				"_Weich",0
GfxFormFeedText		dc.b	"_FormFeed",0
* D				"_FormFeed",0
GfxKeepAspectText	dc.b	"_Keep aspect",0
* D				"Pr_oportionen",0
GfxGfxTypeText		dc.b	"Gra_phic",0
* D				"Gra_phik",0
GfxXText		dc.b	"_X",0
* D				"_X",0
GfxYText		dc.b	"_Y",0
* D				"_Y",0
GfxWidthText		dc.b	"_W",0
* D				"_B",0
GfxHeightText		dc.b	"_H",0
* D				"_H",0
GfxSourceText		dc.b	"S_ource",0
* D				"Quelle",0
GfxGetText		dc.b	"Reselect source (_1)",0
* D				"Neue Quelle (_1)",0
GfxPrintText		dc.b	"D_ump",0
* D				"Dr_ucken",0
GfxCancelText		dc.b	"_Cancel",0
* D				"_Abbruch",0
GfxBoundsText		dc.b	"Define area (_2)",0
* D				"Ausschnitt (_2)",0
GfxDumpTypeText		dc.b	"Dump type (_3)",0
* D				"Druck Typ (_3)",0
GfxAspectLab0		dc.b	"Horizontal",0
* D				"Horizontal",0
GfxAspectLab1		dc.b	"Vertical",0
* D				"Vertikal",0
GfxShadeLab0		dc.b	"Black & White",0
* D				"Schwarz & Weiß",0
GfxShadeLab1		dc.b	"Grey Scale 1",0
* D				"Graustufen 1",0
GfxShadeLab2		dc.b	"Grey Scale 2",0
* D				"Graustufen 2",0
GfxShadeLab3		dc.b	"Color",0
* D				"Farbe",0
GfxDitherLab0		dc.b	"Ordered",0
* D				"Geordnet",0
GfxDitherLab1		dc.b	"Halftone",0
* D				"Halbtöne",0
GfxDitherLab2		dc.b	"Floyd-Steinberg",0
* D				"Floyd-Steinberg",0
GfxImageLab0		dc.b	"Positive",0
* D				"Positiv ",0
GfxImageLab1		dc.b	"Negative",0
* D				"Negativ ",0
GfxScaleLab0		dc.b	"inch x inch",0
* D				"Zoll x Zoll",0
GfxScaleLab1		dc.b	"mm x mm",0
* D				"mm x mm",0
GfxScaleLab2		dc.b	"cm x cm",0
* D				"cm x cm",0
GfxScaleLab3		dc.b	"Fraction",0
* D				"Prozentual",0
GfxScaleLab4		dc.b	"Full page",0
* D				"Ganze Seite",0
GfxGfxTypeLab0		dc.b	"Complete",0
* D				"Komplett",0
GfxGfxTypeLab1		dc.b	"Area",0
* D				"Ausschnitt",0
GfxSourceLab0		dc.b	"Screen",0
* D				"Screen",0
GfxSourceLab1		dc.b	"Window",0
* D				"Fenster",0
GfxDumpTypeLab0		dc.b	"Printer",0
* D				"Drucker",0
GfxDumpTypeLab1		dc.b	"File",0
* D				"Datei",0
LOCALE_END


		INCLUDE	KCX.BSS
		END
