;	*-------+---------------------------------------*
;	|Name	| FindFile (FF)				|
;	|Version| 0.1	Comment:Com-piling		|
;	+-------+---------------------------------------+
;	|Lists all occurrences of <file> in subdirs to	|
;	|current directory. Option -D lists dirs only.	|
;	+-----------------------------------------------+
;	|	  Copyright (C) 1993 MACROSOFT		|
;	*-----------------------------------------------*
LibBits=%00000001
;if OpenLib/CloseLib is used, set LibBits!
;Bits 0-7=Dos,Int,Gfx,Con,Icon,MathF,MathT,MathI
;Presume that all macros destroy D0-D1/A0-A1, and preserves all other regs.
;Macros that use supplied work-registers preserve ALL registers.
;When calling a macro, A5 MUST BE INIT-ADR+32768 AND A6 MUST BE $DFF002!
;Most Macros CONTAIN GLOBAL LABELS, so use local only in-between Macro calls.
;Labels to define if relevant macros are used:
;Params (#Max longs)
;CurrHdl (current filehandle storage long)
;Buf (blk.b 81,0) for conversion & input routines
INCLUDE "CO:Symbols.S"
INCLUDE "CO:Makaron.S"
B:
	INIT
	OPENLIBS
	beq.s Quit
	GETPARAMS Param-R(a5),2
	beq.s Usage
	ALLOC #65536,_Any
	move.l d0,BufP-R(a5)
	beq.s .
	FREE BufP-R(a5),#65536,
Quit:	CLOSELIBS
	EXIT
****************
Usage:	WRITELNA #Txt1
	bra.s Quit
BufP:	dc.l 0
************ VARS ************
Txt1:	dc.b "FindFile ",$a9," MACROSOFT. Finds a specified file in subdirs",10
dc.b "Usage:   FF file [-D]"
dc.b "Wildcards: ? and * (same as #?)	Option -D lists only Dirnames",10
dc.b "Example: FF *.iff ",0


FRdir:					;DIR OF [DirName].Uses TxtBuf-->DirData
	moveq #0,d5			;nr of files
	lea SubDNames(PC),a3		;file/dirnames dest

	CALL DOS,DLock

	move.l DosBase(PC),a6
	bsr LockIt
	move.l LockSav(PC),d1
	beq.w .Err
	lea FileInfo(PC),a4
	move.l a4,d2
	jsr -102(a6)			;transfer file/dir data
	tst.l d0
	beq.w .Err

	MOVEM.L D0-D7/A0-A6,-(SP)
	bsr RefreshGGs
	lea T02(PC),a0			;"reading dir..."
	bsr BarMsg
	lea 8(a4),a0
	clr.b 29(a0)
	move.w #22*bytes+1,d0		;type disk/dirname
	bsr Print
	lea T04(PC),a0			;":"
	bsr Print
	move.w d0,d7
	move.l LockSav(PC),d1
	lea DiskInfo(PC),a4
	move.l a4,d2
	jsr -114(a6)			;UNIT INFO!
	move.l 12(a4),d0		;numblocks.L
	sub.l 16(a4),d0			;-blocksused.L
	subq.l #2,d0			;=blocksfree
	bpl.s .No9
	moveq #0,d0
.No9:	move.l 20(a4),d1		;(*bytesperblock)
	mulu d1,d0			;bytes free
	moveq #0,d1			;deci
	bsr NumStr
	move.w d7,d0
	bsr Print
	lea T05(PC),a0			;" Free"
	bsr Print
	bsr ClrDirWW
	move.w #339,d0			;clr contents-bar
	moveq #45,d1
	moveq #10,d2
	moveq #70,d3
	moveq #3,d4
	bsr MyRect
	move.l a3,a0			;CLEAR FILENAME-AREA (for dir)
	move.l #$20202020,d0
	move.w #38*128/4-1,d1
.SpcLp:	move.l d0,(a0)+
	dbf d1,.SpcLp
	MOVEM.L (SP)+,D0-D7/A0-A6

.Loop:	move.w #$0100,TxtBpl
	move.l LockSav(PC),d1
	move.l a4,d2
	jsr -108(a6)			;transfer file/dir data
	tst.l d0
	beq.s .Err			;end of files/dirs?
	btst #6,$bfe001
	beq.w .DirBrk
	move.l a3,a1
	tst.l 4(a4)			;dir?
	bmi.s .NoDir
	move.w #$0001,TxtBpl		;yep,set color&skip length
	bra.s .YepDir
.NoDir:	move.l 124(a4),d0		;filelen.L
	moveq #0,d1			;deci
	bsr NumStr
	lea TxtBuf+4(PC),a0		;max 6 digits(999k)
	lea -1(a3),a1
.ZeroLp:addq.w #1,a1
	cmp.b #"0",(a0)+
	beq.s .ZeroLp
	subq.w #1,a0
	bsr Copy0			;copy deci file length
	move.b #32,-(a1)
.YepDir:lea 8(a4),a0
	clr.b 30(a0)			;max 30 chars in item name
	lea 7(a3),a1
	bsr Copy0			;copy filename
	addq.w #1,d5			;d5=file&dirnumber
	cmp.w #128,d5
	bge.s .Err
	cmp.w #12,d5	 		;print the filename to the screen?
	bgt.s .Dont
	move.w d5,d0
	mulu #8*bytes,d0
	add.w #24*bytes+3,d0
	move.l a3,a0
	bsr PrintLF
.Dont:	lea 38(a3),a3
	bra .Loop
.Err:	jsr -132(a6)			;dos error number-->d0
	cmp.l #$e8,d0
	bne.s DIRERR
.NoErr:	move.w d5,DirItems
	subq.w #1,DirItems
	bsr FRsortrtn
	clr.w d0
	bsr UpdateDir
	bsr BarRdy
	bra MLRET
.DirBrk:move.w d5,DirItems
	subq.w #1,DirItems
	lea T03(PC),a0			;"User Break!"
	bsr BarMsg
	clr.w d0
	bsr UpdateDir
	bra MLRET
DIRERR:	move.w #-1,DirItems
	lea T00(PC),a0			;"Dir Error!"
	bsr BarErr
	bsr RefreshGGs
	bsr UpdateDir
	bra MLRET

FRpick:
	tst.w DirItems
	BMI.w MLRET
	lea Vars(PC),a4
	bsr GetMsCrds
	move.w d1,d5
	lsr.w #3,d5
	subq.w #4,d5
	add.w DirOffs(PC),d5
	cmp.w DirItems(PC),d5
	BGT.w MLRET
	and.w #-8,d1
	move.w #16,(a4)
	move.w d1,2(a4)
	move.w #320,4(a4)
	move.w #8,6(a4)
	movem.w (a4),d0-d3
	moveq #3,d4
	bsr MyEorRect
.Wait:	bsr Wrel
	movem.w (a4),d0-d3
	moveq #3,d4
	bsr MyEorRect

	MOVEM.L A0/D4-D7,-(SP)
	bsr GetTime
	lea ClickTime(PC),a0
	move.l (a0),d6
	move.l d7,(a0)
	sub.l d6,d7
	moveq #50,d6
	lea ClickNr(PC),a0
	move.w (a0),d4
	move.w d5,(a0)
	cmp.l d6,d7
	bhi.s .NoDbl
	cmp.w d4,d5
	bne.s .NoDbl
	not.b LoadFlag
.NoDbl:	MOVEM.L (SP)+,A0/D4-D7

	mulu #38,d5
	lea DirData(PC),a2
	add.l d5,a2
	cmp.b #32,5(a2)			;dir or file?
	beq.s .Dir
.File:	lea FileName(PC),a1
	lea 7(a2),a0
	bsr Copy0
	bsr RefreshGGs
	bra MLRET

.Dir:	lea DirName(PC),a1
.zlup:	tst.b (a1)+
	bne.s .zlup
	subq.w #1,a1
	cmp.l #DirName,a1
	beq.s .NoSl
	cmp.b #":",-1(a1)
	beq.s .NoSl
	move.b #"/",(a1)+
.NoSl:	lea 7(a2),a0
	bsr Copy0
	bsr RefreshGGs
	bra FRDIR

FRbar:
.Wait:	bsr GetMsCrds
	sub.w #45,d1
	bpl.s .No1
	clr.w d1
.No1:	cmp.w #70-1,d1
	ble.s .No2
	move.w #70-1,d1
.No2:	addq.w #1,d1
	move.w DirItems(PC),d0
	addq.w #1,d0
	mulu d1,d0
	divu #68,d0
	subq.w #6,d0			;12/2 (visible no. of files)
	bsr.s UpdateDir
	bsr MyGetMsg
	cmp.l #8,d0
	bne.s .Wait
	cmp.w #$e8,d1
	bne.s .Wait
	bra MLRET

FRdirup:
	movem.w (a4),d0-d3
	moveq #2,d4
	bsr MyEorRect
.Wait:	move.w DirOffs(PC),d0
	subq.w #1,d0
	bsr.s UpdateDir
	bsr MyGetMsg
	cmp.l #8,d0
	bne.s .Wait
	cmp.w #$e8,d1
	bne.s .Wait
	movem.w (a4),d0-d3
	moveq #2,d4
	bsr MyEorRect
	bra MLRET

FRdirdn:
	movem.w (a4),d0-d3
	moveq #2,d4
	bsr MyEorRect
.Wait:	move.w DirOffs(PC),d0
	addq.w #1,d0
	bsr.s UpdateDir
	bsr MyGetMsg
	cmp.l #8,d0
	bne.s .Wait
	cmp.w #$e8,d1
	bne.s .Wait
	movem.w (a4),d0-d3
	moveq #2,d4
	bsr MyEorRect
	bra MLRET

UpdateDir:			;update dir display. d0=DirOffs
	tst.w DirItems
	bmi.w .Ret
	MOVEM.L D0-D7/A0-A6,-(SP)
	tst.w d0
	bpl.s .No1
	moveq #0,d0
.No1:	move.w DirItems(PC),d1
	sub.w #12-1,d1
	cmp.w d1,d0
	blt.s .No2
	clr.w d0
	tst.w d1
	bmi.s .No2
	move.w d1,d0
.No2:	cmp.w DirOffs(PC),d0
	beq.w .End2		;if no change to the display, then don't bother
	move.w #-1,ClickNr
	move.w d0,DirOffs
.Update:cmp.b #$a0,$dff006		;time with raster (minimizes flicker!)
	bne.s .Update
	bsr ClrDirWW
	mulu #38,d0
	lea DirData(PC),a1
	add.l d0,a1
	move.w #32*bytes+3,d0
	move.w DirItems(PC),d1
	cmp.w #11,d1
	ble.s .prlup
	moveq #11,d1
.prlup:	move.l a1,a0			;DISPLAY DIR CONTENTS
	move.w #$0100,TxtBpl		;file=color 1 (grey)
	cmp.b #32,5(a0)
	bne.s .NoDir
	move.w #$0001,TxtBpl		;dir=color 2 (white)
.NoDir:	bsr PrintLF
	lea 38(a1),a1
	dbf d1,.prlup
	move.w DirItems(PC),d5		;RESIZE&DISPLAY CONTENTS BAR
	addq.w #1,d5
	cmp.w #12,d5
	bge.s .No3
	moveq #12,d5
.No3:	move.w #339,d0			;clr contents-bar
	moveq #45,d1
	moveq #10,d2
	moveq #70,d3
	moveq #3,d4
	bsr MyRect
	move.w #340,d0			;RESIZE CONTENTS BAR
	moveq #68,d1
	mulu DirOffs(PC),d1
	move.w d5,d2
	lsr.w #1,d2
	addq.w #1,d2
	add.w d2,d1
	divu d5,d1
	add.w #46,d1
	moveq #8,d2
	move.l #12*68+6,d3
	divu d5,d3
	addq.w #1,d3			;ADJUST BAR SO THAT NO "GLITCHES"
	move.w d1,d4
	add.w d3,d4
	cmp.w #46+69,d4
	blt.s .No4
	subq.w #1,d3
.No4:	moveq #2,d4
	bsr MyRect
.End2:	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS
.Ret:	move.w #339,d0			;clr contents-bar
	moveq #45,d1
	moveq #10,d2
	moveq #70,d3
	moveq #3,d4
	bsr MyRect
	bsr ClrDirWW
	RTS

FRsort:
	bsr.s FRsortrtn
	clr.w d0
	bsr UpdateDir
	bsr BarRdy
	bra MLRET

FRsortrtn:
	MOVEM.L D0-D7/A0-A6,-(SP)
	lea T01(PC),a0
	bsr BarMsg
	move.w #-1,DirOffs
	lea DirData(PC),a0
	lea DirData2(PC),a1
	move.w DirItems(PC),d2		;no. of file names
	cmp.w #1,d2
	blt.w .End
	move.w d2,d0
.loop1:	move.b 7(a0),d1			;REMAKE INTO CODED CAPS (DIR=+128)
	cmp.b #"a",d1
	blt.s .NoCaps
	cmp.b #"z",d1
	bgt.s .NoCaps
	sub.w #32,d1
.NoCaps:cmp.b #32,5(a0)
	bne.s .NoDir
	add.b #128,d1			;=negative
.NoDir:	move.b d1,(a1)+
	lea 38(a0),a0
	dbf d0,.loop1
	lea DirData2+128(PC),a5		;sorted dest
	move.w d2,d6
.Sort:	moveq #127,d4			;cmp-val
	lea DirData2(PC),a0
	lea DirData(PC),a2
	move.w d2,d1
.Find:	move.b (a0)+,d5
	beq.s .NoCmp
	cmp.b d5,d4
	ble.s .NoCmp
	move.b d5,d4
	move.l a0,a4
	move.l a2,a3
.NoCmp:	lea 38(a2),a2
	dbf d1,.Find
	clr.b -(a4)
	REPT 9
	move.l (a3)+,(a5)+
	ENDR
	move.w (a3)+,(a5)+
	dbf d6,.Sort
	lea DirData2+128(PC),a0
	lea DirData(PC),a1
	move.w d2,d0
.copy:	movem.l (a0)+,d1-d7/a2-a3
	movem.l d1-d7/a2-a3,(a1)
	lea 36(a1),a1
	move.w (a0)+,(a1)+
	dbf d0,.copy
.End:	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

ClrDirWW:
	MOVEM.L D0-A1/A6,-(SP)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -456(a6)			;OwnBlitter
	MOVEM.L (SP)+,D0-A6
	lea $dff000,a6
	move.w 2(a6),-(SP)
	movem.l BplPtrs(PC),a0-a1
	lea 32*bytes+2(a0),a0
	lea 32*bytes+2(a1),a1
	bsr BlitWt
	move.l a0,$54(a6)
	move.w #40,$66(a6)
	move.l #$01000000,$40(a6)
	move.w #$8400,$96(a6)
	move.w #96*64+20,$58(a6)
	bsr BlitWt
	move.l a1,$54(a6)
	move.w #96*64+20,$58(a6)
	bsr BlitWt
	move.w #$0400,$96(a6)
	move.w (SP)+,d0
	bset #15,d0
	move.w d0,$96(a6)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -462(a6)			;DisOwnBlitter
	MOVEM.L (SP)+,D0-A6
	MOVEM.L (SP)+,D0-A1/A6
	RTS

BarClr:
	MOVEM.L D0-D4,-(SP)
	moveq #8,d0			;clr old msg..
	move.w #186,d1
	move.w #624,d2
	moveq #8,d3
	moveq #1,d4
	bsr MyRect
	MOVEM.L (SP)+,D0-D4
	RTS

BarMsg:					;type text to CommBar.a0=ptr
	MOVE.W D0,-(SP)
	bsr.s BarClr
	move.w #186*bytes+1,d0
	move.w #$0301,TxtBpl
	bsr Print			;...and print new!
	MOVE.W (SP)+,D0
	RTS

BarRdy:					;type "ready" to CommBar.
	lea T06(PC),a0
	bsr.s BarMsg
	RTS

BarErr:					;type (a0)+ + 'beep'
	MOVEM.L D0-D7/A0-A6,-(SP)
	move.l ScrHdl(PC),a0
	move.l IntBase(PC),a6
	jsr -96(a6)
	MOVEM.L (SP)+,D0-D7/A0-A6
	bsr.s BarMsg
	RTS
	
CheckGadget:		;check if gadget pressed.d2-d5=box.destroys d0-d6/a0
	bsr GetMsCrds
	move.w d0,d6
	sub.w d2,d6
	bmi.s .NoHit
	cmp.w d4,d6
	bge.s .NoHit
	move.w d1,d6
	sub.w d3,d6
	bmi.s .NoHit
	cmp.w d5,d6
	bge.s .NoHit
	moveq #-1,d0
	bra.s .End	
.NoHit:	moveq #0,d0
.End:	RTS				;d0=gadget chosen

GadgetPick:			;check MsCrds(d0,d1) against gadget-tbl in a0.
	MOVEM.L D1-D7/A1-A3,-(SP)
	lea Vars(PC),a2
	movem.w d0-d1,(a2)
	move.w (a0)+,d7			;nrgadgets -1
.Loop:	move.w d7,a3
	movem.w (a2),d0-d1
	move.l a0,a1
	move.w (a0)+,d7			;available?
	beq.s .NoHit
	movem.w (a0)+,d2-d5		;x,y,wid,hgt
	move.w d0,d6
	sub.w d2,d6
	bmi.s .NoHit
	cmp.w d4,d6
	bge.s .NoHit
	move.w d1,d6
	sub.w d3,d6
	bmi.s .NoHit
	cmp.w d5,d6
	bge.s .NoHit
.HIT:	tst.w d7			;normal or repeatable gadget?
	bmi.s .Rept
	movem.w -8(a0),d0-d3
	moveq #2,d4
	bsr MyEorRect
.Wait:	bsr.s MyGetMsg			;if non-rept,wait til mouse released
	cmp.l #8,d0
	bne.s .Wait
	cmp.w #$e8,d1
	bne.s .Wait
.Inv2:	movem.w -8(a0),d0-d3
	moveq #2,d4
	bsr MyEorRect
.Rept:	move.l (a0),d0
	bra.s .End
.NoHit:	lea 14(a1),a0
	move.w a3,d7
	dbf d7,.Loop
	moveq #0,d0
.End:	MOVEM.L (SP)+,D1-D7/A1-A3	;d0=jump-address (0=no event)
	RTS

GetMsCrds:
	MOVE.L A0,-(SP)
	move.l WWhdl(PC),a0
	move.l $6c(a0),d1
	move.l d1,d0
	swap d0
	subq.w #2,d1
	move.l d1,MsCrds
	MOVE.L (SP)+,A0
	RTS

MyGetMsg:		;get intuition message -->d0=IDCMP,d1=Code
	MOVEM.L D2-D7/A0-A6,-(SP)
	move.l WWhdl(PC),a0		;CHECK FOR EVENT
	move.l 86(a0),a0		;user port
	move.l 4.w,a6
	jsr -372(a6)
	tst.l d0
	beq.s .end			;no msg
	move.l d0,a2
	move.l a2,a1
	jsr -378(a6)
	move.l a2,MsgStruct
	move.l 20(a2),d0		;event number
	move.l d0,Class
	move.w 24(a2),d1
	move.w d1,Code
.end:	MOVEM.L (SP)+,D2-D7/A0-A6
	RTS

MyRect:		;d0=x,d1=y(GZZ),d2=wid,d3=hgt,d4=color 0-3
	MOVEM.L D0-D7/A0-A6,-(SP)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -456(a6)			;OwnBlitter
	MOVEM.L (SP)+,D0-A6
	LEA $DFF000,A6
	move.w 2(a6),-(SP)
	movem.l BplPtrs(PC),a0-a1
	move.w d0,d5
	lsr.w #4,d5
	mulu #bytes,d1
	add.w d5,d1
	add.w d5,d1
	add.w d1,a0			;a0/a1=bpladdrs
	add.w d1,a1
	add.w d0,d2
	subq.w #1,d2			;last x-pixel
	move.w d2,d6
	lsr.w #4,d2
	addq.w #1,d2
	sub.w d5,d2			;wordwid
	moveq #bytes,d1
	sub.w d2,d1
	sub.w d2,d1			;d1=mod
	lsl.w #6,d3
	add.w d3,d2			;d2=bltsize
	moveq #1,d3
	not.w d0
	and.w #15,d0
	addq.w #1,d0
	lsl.w d0,d3
	subq.w #1,d3
	swap d3				;afwm
	move.w #1,d3
	not.w d6
	and.w #15,d6
	lsl.w d6,d3
	subq.w #1,d3
	not.w d3			;d3=Amask.L
	move.w #$050c,d0
	btst #0,d4
	beq.s .Bpl1
	move.w #$05fc,d0
.Bpl1:	bsr BlitWt
	move.w #$8400,$96(a6)
	move.l a0,$4c(a6)
	move.l a0,$54(a6)
	move.w d1,$62(a6)
	move.w d1,$66(a6)
	move.w #-1,$74(a6)
	move.w d0,$40(a6)
	move.w #0,$42(a6)
	move.l d3,$44(a6)
	move.w d2,$58(a6)
	move.w #$050c,d0
	btst #1,d4
	beq.s .Bpl2
	move.w #$05fc,d0
.Bpl2:	bsr BlitWt
	move.l a1,$4c(a6)
	move.l a1,$54(a6)
	move.w d0,$40(a6)
	move.w d2,$58(a6)
	bsr BlitWt
	move.w #$0400,$96(a6)
	move.w (SP)+,d0
	bset #15,d0
	move.w d0,$96(a6)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -462(a6)			;DisOwnBlitter
	MOVEM.L (SP)+,D0-A6
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

MyEorRect:	;d0=x,d1=y(GZZ),d2=wid,d3=hgt,d4=bplsToEor!
	movem.w d0-d4,dbug
	MOVEM.L D0-D7/A0-A6,-(SP)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -456(a6)			;OwnBlitter
	MOVEM.L (SP)+,D0-A6
	LEA $DFF000,A6
	move.w 2(a6),-(SP)
	movem.l BplPtrs(PC),a0-a1
	move.w d0,d5
	lsr.w #4,d5
	mulu #bytes,d1
	add.w d5,d1
	add.w d5,d1
	add.w d1,a0			;a0/a1=bpladdrs
	add.w d1,a1
	add.w d0,d2
	subq.w #1,d2			;last x-pixel
	move.w d2,d6
	lsr.w #4,d2
	addq.w #1,d2
	sub.w d5,d2			;wordwid
	moveq #bytes,d1
	sub.w d2,d1
	sub.w d2,d1			;d1=mod
	lsl.w #6,d3
	add.w d3,d2			;d2=bltsize
	moveq #1,d3
	not.w d0
	and.w #15,d0
	addq.w #1,d0
	lsl.w d0,d3
	subq.w #1,d3
	swap d3				;afwm
	move.w #-1,d3
	not.w d6
	and.w #15,d6
	lsl.w d6,d3
.Bpl1:	bsr BlitWt
	move.w #$8400,$96(a6)
	move.l a0,$4c(a6)
	move.l a0,$54(a6)
	move.w d1,$62(a6)
	move.w d1,$66(a6)
	move.l #$053c0000,$40(a6)
	move.l d3,$44(a6)
	move.w #-1,$74(a6)
	btst #0,d4
	beq.s .Bpl2
	move.w d2,$58(a6)
.Bpl2:	btst #1,d4
	beq.s .Nope
	bsr BlitWt
	move.l a1,$4c(a6)
	move.l a1,$54(a6)
	move.w d2,$58(a6)
.Nope:	bsr BlitWt
	move.w #$0400,$96(a6)
	move.w (SP)+,d0
	bset #15,d0
	move.w d0,$96(a6)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -462(a6)			;DisOwnBlitter
	MOVEM.L (SP)+,D0-A6
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

InitScr:
	MOVEM.L D0-D7/A0-A6,-(SP)
	move.l WWhdl(PC),a0		;GET SCREEN/WINDOW INFO
	move.l 50(a0),Rport
	move.l ScrHdl(PC),a0
	lea 44(a0),a1
	move.l a1,Vport
	lea BplPtrs(PC),a1
	move.l $c0(a0),a2
	lea 11*bytes(a2),a2
	move.l a2,(a1)+
	move.l $c4(a0),a2
	lea 11*bytes(a2),a2
	move.l a2,(a1)+
	lea ScrCols(PC),a0		;SET SCREEN COLORS
	moveq #0,d0
	moveq #4,d1
	bsr.s MyCols
	lea ScrPtr(PC),a0		;SET DEFAULT POINTER
	bsr.s MyPointer
	lea ScrReq(PC),a0			;SCREEN GADGET
	moveq #0,d0			;TL corner
	bsr MyGadget
	move.w #339,d0
	moveq #45,d1
	moveq #10,d2
	moveq #70,d3
	moveq #3,d4
	bsr MyRect
	bsr RefreshGGs
	lea T13(PC),a0
	bsr BarMsg
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

MyPointer:	;set screen pointer.a0=struct-ptr (see ScrPtr)
	MOVEM.L D0-D7/A0-A6,-(SP)
	moveq #17,d0
	moveq #3,d1
	bsr.s MyCols			;set pointer palette
	lea 6(a0),a1
	move.w (a1)+,d0			;height
	moveq #16,d1			;width
	move.w (a1)+,d2			;x-offset
	move.w (a1)+,d3			;y-offset
	ext.l d0
	ext.l d2
	ext.l d3
	move.l WWhdl(PC),a0
	move.l IntBase(PC),a6
	jsr -270(a6)
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

MyCols:		;set d1 screen colors, starting on color d0. a0=palette-ptr
	MOVEM.L D0-D7/A0-A6,-(SP)
	move.l a0,a3
	move.l Vport(PC),a4		;viewport in a0(in-loop)
	move.l GfxBase(PC),a6
	move.w d0,d6
	move.w d1,d7
	subq.w #1,d7
.loop:	move.l a4,a0
	move.w d6,d0			;colornumber
	move.w (a3)+,d3			;rgb(b)
	move.w d3,d2			;g
	move.w d2,d1			;r
	lsr.w #8,d1			;FILTER R,G,B WORDS
	lsr.w #4,d2
	and.w #$f,d2
	and.w #$f,d3
	jsr -288(a6)			;SET THAT COLOR
	addq.w #1,d6
	dbf d7,.loop
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

MyGadget:				;draw relief gadget.a0=def,d0=y*bytes+x
	MOVEM.L D0-D7/A0-A6,-(SP)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -456(a6)			;OwnBlitter
	MOVEM.L (SP)+,D0-A6
	lea $dff000,a6
	move.w 2(a6),-(SP)
	move.w d0,-(SP)
	move.w d0,d1
	bsr BlitWt
	move.w #$8400,$96(a6)
	move.w #52-2,$64(a6)
	move.w #bytes-2,$66(a6)
	move.l #$09f00000,$40(a6)
	move.l #-1,$44(a6)
	move.w #12*64+1,d3		;BLITTING PRE-SET
	addq.w #2,a6			;OBS!
	movem.l BplPtrs(PC),a3-a4
	lea Blox-"a"*2,a1
	moveq #0,d2
.Loop:	move.b (a0)+,d2
	ble.s .Ctrl
	add.b d2,d2
	lea (a1,d2.w),a2
	lea (a3,d1.w),a5
.bw0:	btst #6,(a6)
	bne.s .bw0
	movem.l a2/a5,$50-2(a6)
	move.w d3,$58-2(a6)
	lea 52*12(a2),a2
	lea (a4,d1.w),a5
.bw1:	btst #6,(a6)
	bne.s .bw1
	movem.l a2/a5,$50-2(a6)
	move.w d3,$58-2(a6)
	addq.w #2,d1
	bra.s .Loop
.Ctrl:	beq.s .End
	cmp.b #-1,d2
	bne.s .NoLF
	add.w #12*bytes,d0
	move.w d0,d1
	bra.s .Loop
.NoLF:	add.w #8*bytes,d0
	move.w d0,d1
	bra.s .Loop
.End:	move.w (SP)+,d0
	add.w #6*bytes+1,d0		;TITLE
	move.w #$0301,TxtBpl
	bsr BlitWt
	move.w #$0400,$96-2(a6)
	move.w (SP)+,d7
	bset #15,d7
	move.w d7,$96-2(a6)
	MOVEM.L D0-A6,-(SP)
	move.l GfxBase(PC),a6
	jsr -462(a6)			;DisOwnBlitter
	MOVEM.L (SP)+,D0-A6
	bsr.s Print
	MOVEM.L (SP)+,D0-D7/A0-A6
	RTS

PrintLF:			;print (a0)+ with LF
	move.w d0,-(SP)
	bsr.s Print
	move.w (SP)+,d0
	add.w #8*bytes,d0
	RTS

Print:				;a0=txt,d0=bploffs
	MOVEM.L D1-D7/A1-A6,-(SP)
	lea BplPtrs(PC),a3
	movem.l (a3)+,d4-d5
	sub.l d4,d5
	ext.l d0
	add.l d0,d4
	moveq #0,d2			;x-add
	moveq #0,d0
	moveq #0,d1
	move.b (a3)+,d0
	move.b (a3)+,d1
	lea Font(PC),a3
	lea 96*8(a3),a1			;inverted font
PRcol:	add.w d0,d0
	add.w d0,d0
	add.w d1,d1
	add.w d1,d1
	lea PrtJmpTbl(PC),a4
	move.l (a4,d0.w),a5
	move.l 4*4(a4,d1.w),a6
PRloop:	moveq #0,d3
	move.b (a0)+,d3
	bmi.w PRnext
	sub.b #32,d3
	bpl.s .Char
.Ctrl:	cmp.b #0-32,d3
	beq.w PRend
	cmp.b #10-32,d3
	bne.s .NoLF
	add.l #8*bytes,d4
	moveq #0,d2
	bra.s PRloop
.NoLF:	cmp.b #5-32,d3
	bne.s .Nolf2
	add.l #4*bytes,d4
	moveq #0,d2
	bra.s PRloop
.Nolf2:	cmp.b #9-32,d3
	bne.s .NoTAB
	addq.w #8,d2
	and.w #-8,d2
	bra.s PRloop
.NoTAB:	cmp.b #1-32,d3
	bne.s .NoCol
	move.b (a0)+,d0
	move.b (a0)+,d1
	bra.s PRcol
.NoCol:	bra.s PRloop

.Char:	lsl.w #3,d3
	move.l d4,a2
	lea (a2,d2.w),a2
	jmp (a5)
Bpl1Ret:move.b (a4)+,(a2)
	move.b (a4)+,bytes*1(a2)
	move.b (a4)+,bytes*2(a2)
	move.b (a4)+,bytes*3(a2)
	move.b (a4)+,bytes*4(a2)
	move.b (a4)+,bytes*5(a2)
	move.b (a4)+,bytes*6(a2)
	move.b (a4)+,bytes*7(a2)
	add.l d5,a2
	jmp (a6)
Bpl2Ret:move.b (a4)+,(a2)
	move.b (a4)+,bytes*1(a2)
	move.b (a4)+,bytes*2(a2)
	move.b (a4)+,bytes*3(a2)
	move.b (a4)+,bytes*4(a2)
	move.b (a4)+,bytes*5(a2)
	move.b (a4)+,bytes*6(a2)
	move.b (a4)+,bytes*7(a2)
PRnext:	addq.w #1,d2
	bra PRloop
PRend:	move.l d4,d0
	add.l d2,d0
	sub.l BplPtrs(PC),d0
	MOVEM.L (SP)+,D1-D7/A1-A6
	RTS

Prt00:	move.l a3,a4
	bra.s Bpl1Ret
Prt01:	lea (a3,d3.w),a4
	bra.s Bpl1Ret
Prt02:	lea (a1,d3.w),a4
	bra.s Bpl1Ret
Prt03:	move.l a1,a4
	bra.s Bpl1Ret
Prt10:	move.l a3,a4
	bra.s Bpl2Ret
Prt11:	lea (a3,d3.w),a4
	bra.s Bpl2Ret
Prt12:	lea (a1,d3.w),a4
	bra.s Bpl2Ret
Prt13:	move.l a1,a4
	bra.s Bpl2Ret

PrtJmpTbl:
dc.l Prt00,Prt01,Prt02,Prt03
dc.l Prt10,Prt11,Prt12,Prt13
************** PREFERENCES ****************
EVEN
ScrCols:dc.w $006,$99b,$eef,$557

ScrPtr:	dc.w $977,$caa,$fee,9,-5,-4	;3 colors,hgt,xoffset,yoffset
	dc.w 0,0
	dc.w %0000100000000000,%0000100000000000
	dc.w %0000000000000000,%0000100000000000
	dc.w %0000100000000000,%0000000000000000
	dc.w %0000000000000000,%0000100000000000
	dc.w %1010001010000000,%1101010110000000
	dc.w %0000000000000000,%0000100000000000
	dc.w %0000100000000000,%0000000000000000
	dc.w %0000000000000000,%0000100000000000
	dc.w %0000100000000000,%0000100000000000
	dc.w 0,0

ScrDefs:
	dc.w 0,0,640,hgt,2		;x,y,wid,hgt,depth
	dc.b 2,3			;txtcol,bkgrcol
	dc.w $c000,15			;viewmode,scrtype
	dc.l 0,ScrName,0,0		;font,title,nogadgets,bitmap

WWdefs:
	dc.w 0,0,640,hgt		;x,y,width,hgt
	dc.b 2,3			;txtcol,bkgrcol
	dc.l %000000000011000001000	;IDCMP flags
	dc.l %000010001111100000000	;window type
	dc.l ScrGGs,0,WWname		;gadgetptr,checkmarkptr,wwnameptr
ScrHdl:	dc.l 0				;pointer to scrhandlerdefs
	dc.l 0				;no own bitmap for this window
	dc.w 640,hgt,640,hgt		;min wid/hgt,max wid/hgt
	dc.w 15				;custom window

ScrGGs:
gg1:	dc.l gg2			;nextgg
	dc.w 52,144,248,8,0,2,4
	dc.l 0,0,0,0,gg1s
	dc.w 1
	dc.l 0
gg1s:	dc.l DirName,0
	dc.w 0,64,0
	blk.w 7,0			;for intuition
	dc.l 0,0			;intvalue,altkeymap
gg2:	dc.l gg3				;nextgg
	dc.w 52,156,248,8,0,2,4
	dc.l 0,0,0,0,gg2s
	dc.w 2
	dc.l 0
gg2s:	dc.l FileName,0
	dc.w 0,32,0
	blk.w 7,0			;for intuition
	dc.l 0,0			;intvalue,altkeymap
gg3:	dc.l 0
	dc.w 476,156,48,8,0,$802,4
	dc.l 0,0,0,0,gg3s
	dc.w 2
	dc.l 0
gg3s:	dc.l ScanBuff,0
	dc.w 0,6,0
	blk.w 7,0			;for intuition
ScanWid:dc.l 256,0			;intvalue,altkeymap

ScrGG:
	dc.w 27			;antal ggs -1
	dc.w 1,0,140,48,12	;type (0=n/a,1=nrml,-1=rept),x,y,w,h
	dc.l FRdir		;jumpaddress
	dc.w 1,0,128,64,12
	dc.l FRparent
	dc.w 1,64,128,48,12
	dc.l FRdh0
	dc.w 1,112,128,48,12
	dc.l FRram
	dc.w 1,160,128,48,12
	dc.l FRdf0
	dc.w 1,208,128,48,12
	dc.l FRdf1
	dc.w 1,256,128,48,12
	dc.l FRdf2
	dc.w 1,304,128,48,12
	dc.l FRdf3
	dc.w 1,304,140,48,12
	dc.l FRroot
	dc.w 1,304,152,48,12
	dc.l FRsort
	dc.w -1,336,32,16,12
	dc.l FRdirup
	dc.w -1,336,116,16,12
	dc.l FRdirdn
	dc.w -1,336,45,16,70
	dc.l FRbar
	dc.w 1,0,152,48,12	;type (0=n/a,1=nrml,-1=rept),x,y,w,h
	dc.l FRfile		;jumpaddress
	dc.w -1,16,32,320,96
	dc.l FRpick
	dc.w 1,0,0,12,7
	dc.l End
	dc.w 1,0,164,48,20
	dc.l LoadFile
	dc.w 1,48,164,48,20
	dc.l SaveFile
	dc.w 1,96,164,64,20
	dc.l DelFile
	dc.w 1,160,164,192,20
	dc.l Crunch
sgg0:	dc.w -1,352,172,56,12
	dc.l Scan0
sgg1:	dc.w -1,408,172,32,12
	dc.l Scan1
sgg2:	dc.w -1,440,172,32,12
	dc.l Scan2
sgg3:	dc.w -1,472,172,32,12
	dc.l Scan3
sgg4:	dc.w -1,504,172,32,12
	dc.l Scan4
sgg5:	dc.w -1,536,172,32,12
	dc.l Scan5
sgg6:	dc.w -1,568,172,32,12
	dc.l Scan6
sgg7:	dc.w -1,600,172,40,12
	dc.l Scan7

**************** DC-DATA ****************
Cop0:
dc.w $180,$000
dc.w $182,$c60				;nice,ginger color! (baesch!)
dc.w $008e,$a4a1			;256x8
dc.w $0090,$ac9f
dc.w $0092,$0048
dc.w $0094,$00c0
dc.w $0108,$0
dc.w $120,$0
dc.w $122,$0
dc.w $124,$0
dc.w $126,$0
dc.w $128,$0
dc.w $12a,$0
dc.w $12c,$0
dc.w $12e,$0
dc.w $130,$0
dc.w $132,$0
dc.w $134,$0
dc.w $136,$0
dc.w $138,$0
dc.w $13a,$0
dc.w $13c,$0
dc.w $13e,$0
BplPtrs0:
dc.w $00e0,0
dc.w $00e2,0
BplEna0:
dc.w $0100,$1200
dc.w $ffff,$fffe			;End of Copper list!
****************
EVEN
FontTbl:
dc.w 0,1,2,3,4,5,6,7,8,9,10,0,11,12,13,0		;OBS! Modulo=50!!!
dc.w 14,15,16,17,18,19,20,21,22,23
dc.w 24,0,0,0,0,25,0
dc.w 26,27,28,29,30,31,32,33,15,34,35,36,37,38,14
dc.w 39,40,41,42,43,44,45,46,47,48,49
Font2:
INCBIN "GFX/DispFont.raw"

ScrName:dc.b "QIK*D*PAK V2.1 by MAX Computer Innovation · "
	dc.b "(C) 1992 Henrik Erlandsson.  ",0
WWname:	dc.b "Whee!",0
ScrReq:				;screen-req
dc.b "abbbbbbbbbbbbbbbbbbbbclmmmmmmmmmmmmmmmmn",-2
dc.b "rsssssssssssssssssssstrsssssssssssssssst",-1
dc.b "rsssssssssssssssssssstpppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxepppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxypppppppppppppppppp",-1
dc.b "yxxxxxxxxxxxxxxxxxxxxdpppppppppppppppppp",-1
dc.b "hiijhijhijhijhijhijhijpppppppppppppppppp",-1
dc.b "hijuvvvvvvvvvvvvvvwhijlmmmmmmmmmmmmmmmmn",-1
dc.b "hijuvvvvvvvvvvvvvvwhijoppppppuvvwppppppq",-1
dc.b "lmnlmnlmmnlmmmmmmmmmmnoppppppppppppppppq",-2
dc.b "rstrstrsstrssssssssssthiikikikikikikikij",-1
dc.b "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiij",0

dc.b "	      * DIRECTORY *				* INFO *",1,2,1,5
blk.b 15,10
dc.b "Parent··DH0:··RAM:··DF0:··DF1:··DF2:··DF3:",10,5
dc.b "Dir				······Root"
dc.b "		EFFICIENCY",10,5
dc.b "File				······Sort",1,3,1
dc.b "	    Scan	··Width",1,2,1,10,10
dc.b "LOAD··SAVE··DELETE·······CRUNCH DATA!",1,2,1,5
dc.b "					····TURBO···1···2···3···4···5···6··MAX"
dc.b 0
**************** MESSAGES ****************
TD_Name:	dc.b "trackdisk.device",0
GFXname:dc.b "graphics.library",0
INTname:dc.b "intuition.library",0
DOSname:dc.b "dos.library",0
T00:	dc.b "Directory error!",0
T01:	dc.b "Sorting Dir...",0
T02:	dc.b "Reading Directory...",0
T03:	dc.b "User Break!",0
T04:	dc.b ":",0
T05:	dc.b " Free",0
T06:	dc.b "Ready.",0
T07:	dc.b "Error!",0
T08:	dc.b "Loading...",0
T09:	dc.b "Orig Size: ",0
T10:	dc.b " (=$",0
T11:	dc.b ")",0
T12:	dc.b "Saving...",0
T13:	dc.b "Let's get to it!",0
T14:	dc.b "Crunch aborted!",0
T15:	dc.b "File became longer!",0
T16:	dc.b " New Size: ",0
T17:	dc.b "    Ratio: ",0
T18:	dc.b "% of original.",0
T19:	dc.b "Sector Write:Insert Disk in DF0: and press Left Mousebutton.",0
T20:	dc.b "Writing sectors...",0
T21:	dc.b "Are you sure Y/N?",0
T22:	dc.b "Incorrect directory name!",0
TS:	dc.b "CRUNCHED:00%  NEW LENGTH:$00000",0
******************* VARS *******************
EVEN
;;
ClickTime:	dc.l 0
ClickNr:	dc.w -1
TD_IO:		blk.l 20,0
TD_Port:	blk.l 8,0
Sound:		dc.w $7f80
Dreg:		dc.b 0
Brk:		dc.b 0
OldVB:		dc.l 0
Ctr:		dc.w 0
OldInts:	dc.w 0
Black:		blk.l 8,0
MulsTbl:	dc.l 1,10,100,1000,10000,100000,1000000,10000000
SysSP:		dc.l 0
SaveSP:		dc.l 0
Vars:		blk.l 8,0
LF:		dc.b 10,0
TxtBuf:		blk.b 82,0
OldDMA:		dc.l 0
OldScan:	blk.w 4,0
OrigSize:	dc.l 0
PakAddr:	dc.l 0
NewAddr:	dc.l 0
NewSize:	dc.l 0
WSsize:		dc.l 0
WSaddr:		dc.l 0
;;
IntBase:	dc.l 0
MsgStruct:	dc.l 0
Class:		dc.l 0
Code:		dc.w 0
MsCrds:		dc.w 0,0
Rport:		dc.l 0
Vport:		dc.l 0
BplPtrs:	blk.l 2,0
TxtBpl:		dc.w 0			;dont sep ^!
;;
GfxBase:	dc.l 0
;;
DosBase:	dc.l 0
WWhdl:		dc.l 0
EVEN
DirName:	dc.b ":",0
		blk.b 62,0
EVEN
FileName:	blk.b 32,0
Name:		blk.b 96,0		;combined name used by Load/Save/Del
ScanBuff:	blk.b 6,0
FileSize:	dc.l 0
FileHdl:	dc.l 0
LockSav:	dc.l 0
EVEN
Most:		dc.b 0
Least:		blk.b 5,0
Frqs:		blk.b 16,0
LoadFlag:	dc.b 0
CNOP 0,8
FileInfo:	blk.l 65,0
CNOP 0,8
DiskInfo:	blk.l 65,0
DirOffs:	dc.w 0
DirItems:	dc.w -1			;if neg, then NOT valid!
DirData:	blk.b 38*128		;asciilen name.max 128 files(!)
DirData2:	blk.b 128+38*128	;asciilen name.max 128 files(!)
Scr:		blk.b 32*8,0
FrqTbl:		blk.l 256,0
FrqTbl2:	blk.l 256,0
Dbug:		blk.l 16,0
**************** LOADED DATA ****************
EVEN
Blox:	INCBIN "GFX/UtilBlox"
Font:	INCBIN "GFX/CleanFont"
	blk.b 768,0
E:
