
;	This is the code created by PBar V1.0
;	by Preben Nielsen.
;	Assemble it as case-sensitive.
	OPT O+
;	OPT O1+		;Tells when a branch could be optimised to short
;	OPT i+		;Tells when '#' is probably missing

	incdir	"INCLUDE:"
	include "exec/exec_lib.i"
	include "intuition/intuition.i"
	include "intuition/intuition_lib.i"
	include "libraries/dosextens.i"

LoadBase	MACRO
		IFNC		'\1','ExecBase'
		movea.l		\1,A6
		ENDC
		IFC		'\1','ExecBase'
		movea.l		4.W,A6
		ENDC
		ENDM
CallLib		MACRO
		jsr		_LVO\1(A6)
		ENDM
Call		MACRO
		bsr		\1
		ENDM
Push		MACRO
		movem.l		\1,-(SP)
		ENDM
Pop		MACRO
		movem.l		(SP)+,\1
		ENDM

IntBase		EQUR		A5
PatExe		Push		D0-D7/A0-A6
		LoadBase	ExecBase
		suba.l		A1,A1
		CallLib		FindTask		;Find us
		movea.l		D0,A2
		tst.l		pr_CLI(A2)
		bne.S		WBAndCLIStartUp
		lea		pr_MsgPort(A2),A0
		CallLib		WaitPort		;wait for a message
		lea		pr_MsgPort(A2),A0
		CallLib		GetMsg			;then get it
		move.l		D0,WBenchMsg		;save it for later reply
WBAndCLIStartUp	lea		IntName(PC),A1
		CallLib		OldOpenLibrary
		move.l		D0,IntBase
		tst.l		D0
		beq.S		Exit

		lea		790(IntBase),A1		;Private part of IntuitionBase
		lea		Pattern(PC),A0
		moveq		#23,D0
CopyPatLoop	move.b		(A0)+,(A1)+
		dbra		D0,CopyPatLoop
		LoadBase	IntBase
RefreshWindows	move.l		ib_FirstScreen(IntBase),A4
RSLoop		move.l		A4,D0
		beq.S		EndRS
		move.l		sc_FirstWindow(A4),A3
RWLoop		move.l		A3,D0
		beq.S		EndRW
		move.l		D0,A0
		CallLib		RefreshWindowFrame
		move.l		wd_NextWindow(A3),A3
		bra.S		RWLoop
EndRW		move.l		sc_NextScreen(A4),A4
		bra.S		RSLoop
EndRS

Exit		LoadBase	ExecBase
FreeInt		move.l		IntBase,D0
		beq.S		ReplyWB
		movea.l		D0,A1
		CallLib		CloseLibrary
ReplyWB		move.l		WBenchMsg(PC),D0
		beq.S		AllDone
		CallLib		Forbid
		movea.l		D0,A1
		CallLib		ReplyMsg		;Reply WBenchMessage if we are started from WB
AllDone		Pop		D0-D7/A0-A6
		moveq		#0,D0
		rts

IntName		dc.b		'intuition.library',0
		EVEN
WBenchMsg	dc.l		0
;This is where PBar stores the pattern 
Pattern		dc.w		$0000,$0000,$ffff,$ffff,$0000,$0000,$ffff,$ffff
;This is where PBar stores the mask
		dc.w		$4444,$1111,$4444,$1111
		END

