[comp.sources.amiga] v02i063: warranger - window arranger v1.25

page@swan.ulowell.edu (Bob Page) (11/18/88)

Submitted-by: schabacker@frambo.DEC.COM (Tim, posting for Christian Balzer)
Posting-number: Volume 2, Issue 63
Archive-name: intuition/warranger.1

WindowArranger is an update to the one on Fish #139.
If there are any questions, email me.

[uuencoded binary also here, because it's small and the
redistribution requirements state that it must be.  ..Bob]

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	Warranger.asm
#	Warranger.uu
# This archive created: Thu Nov 17 23:32:19 1988
cat << \SHAR_EOF > Warranger.asm
;*****************************************************************************
;*
;*		WindowArranger.asm (assembler version)		05.11.88
;*						by Heiko Rath
;*
;* This little goodie is able to send a window to front or back. I wrote it
;* for <CB> who wanted to bring his AMICRON window to front if an event
;* occured.
;*
;* A short description:
;* The program first trys to open the 'dos.library', if it had success to do
;* so it trys to parse your input string. If it can't understand what you want
;* it gives you help how to use it. If it is able to parse your input it trys
;* to open 'intuition.library' and to find a window with a matching name. If
;* there is one it rearranges it to front or to back. After this it closes
;* the 'intuition.library' & the 'dos.library'.
;*
;* Changes since version 1.00 on Fish disk #139:
;* Fixed "Infinity Loop while IntuitionLock" bug that occured when a screen
;* with no window (like DMouse or PopCLI) was in front.
;*
;* Thanx to Larry Phillips, (CIS -76703,4322) & C.Heath.
;*****************************************************************************
;*
;* This program is
;* 
;* Copyright (c) 1988 by Heiko Rath and the Software Brewery.
;*
;* It may be freely distributed for non-profit only.
;* The distribution must contain ALL parts, in this case the following
;* files:
;*
;* Warranger
;* Warranger.asm
;* 
;* Putting it on a commercial product is usually as easy as sending
;* a letter to the author.
;*
;* If you like this program you can do one of the following things:
;*
;* 1.	absolutly nothing
;* 2.	send me something I deserve:
;*				money, yachts, beer, Marabou chocolate
;* 3.	contact us at:
;*
;*				Heiko Rath
;*				Raiffeisenstr.10a
;*				D-6108 Weiterstadt
;*				WEST GERMANY
;*
;*                                     or
;*                          
;*                          
;* ______  /          
;* ______\O                     - The Software Brewery - 
;*       \\ 
;*        o           Sparkling, fresh software from West-Germany
;*           
;*      @@@@@             Straight from the bar to your Amiga
;*      |~~~|\ 
;*      | | |/ 
;*      |___|        With our regards to the Software Distillery
;* 
;* The Brewers are:
;* Christian Balzer alias <CB>, Lattice C, user interfaces, beer addict. 
;* Heiko Rath alias <HR>, Assembler, ROM-Kernal stuff, Marabou addict. 
;* Ralf Woitinas alias RAF, Assembler, anything, Ray-Tracing addict.
;* Andrew Kopp alias Charlie, Aztec C, Hardware & communications, beer addict.
;* Armin Sparr alias MARVIN, Aztec C, ARexx macros, Campari addict.
;* Christof Bonnkirch alias KEY, Aztec C, Hardware & Devices, beer adict.
;* 
;* Beverages: Altenmuenster Brauer Bier, Urfraenkisches Landbier, Jever.
;* 
;* Send exotic drinks, comments, flames to:
;* 
;* The Software Brewery	
;* Christian Balzer		UUCP: decwrl!frambo.dec.com!schabacker
;* Im Wingertsberg 45		ARPA: schabacker@frambo.dec.com
;* D-6108 Weiterstadt		CI$ : 71001,210 (be brief!)
;* West Germany (F.R.G.)	Fone: +49 6150 4151 (18:00-21:00 CET!)
;* 

Version		MACRO
		dc.b	'1.25'
		ENDM

ExecBase	Equ	4

;*** Exec Offsets:
FindTask	Equ	-294	;(name)(a1)
WaitPort	Equ	-384	;(port)(a0)
GetMsg		Equ	-372	;(port)(a0)
ReplyMsg	Equ	-378	;(message)(a1)
Forbid		Equ	-132	;()()
OpenLibrary	Equ	-552	;(libName,version)(a1,d0)
CloseLibrary	Equ	-414	;(library)(a1)
OldOpenLibrary	Equ	-408
CLOSEWINDOW	Equ	$200	;IDCMP-Flag CloseWindow
WD_USERPORT	Equ	86	;WD_UserPort
IM_CLASS	Equ	20	;Even Class

;*** DOS Offsets:

Input		Equ	-54	;()
OutPut		Equ	-60	;()
Write		Equ	-48	;(file, buffer, length)(d1,d2,d3)

;*** Intuition Offsets:

OpenWindow	Equ	-204	;(OWArgs)(a0)
CloseWindow	Equ	-72	;(Window)(a0)
LockIBase	Equ	-414	;(dontknow)(d0)
UnlockIBase	Equ	-420	;(IBlock)(a0)
WindowToFront	Equ	-312	;(Window)(a0)
WindowToBack	Equ	-306	;(Window)(a0)
AutoRequest	Equ	-348	;(Window,body,PText,NText,PFlags,NFlags,W,H)
				;(a0,a1,a2,a3,d0,d1,d2)

timer		Equ	0
GfxBase		Equ	2
fac		Equ	6
PR_CLI		Equ	172
PR_MsgPort	Equ	92

;*** Macro Definitions:
push.w	MACRO
	move.w	\1,-(sp)	;push a word onto stack
	ENDM

push.l	MACRO
	move.l	\1,-(sp)	;push a longword onto stack
	ENDM

pop.w	MACRO
	move.w	(sp)+,\1	;pop a word from stack
	ENDM

pop.l	MACRO
	move.l	(sp)+,\1	;pop a longword from stack
	ENDM

pushm	MACRO
	movem.l	\1,-(sp)	;push several register on stack
	ENDM

popm	MACRO
	movem.l	(sp)+,\1	;pop several register from stack
	ENDM


Amiga_Init:
	move.l	sp,d6			;save stack pointer

	move.l	a0,a2			;register a2 is cmdline henceforth
	clr.b	0(a2,d0.w)		;make sure that cmdline is null terminated
	push.w	d0			;save cmdlength

	move.l	ExecBase,a6		;get ExecBaseaddress to a6
	suba.l	a1,a1			;clear a1
	jsr	FindTask(a6)		;get pointer

	move.l	d0,a4			;get process-pointer to a4
	tst.l	PR_CLI(a4)		;pr_CLI: CLI or WB?
	bne	main			;if <> 0 then CLI

fromWB:
	lea	PR_MsgPort(a4),a0	;pr_MsgPort: messageportaddress to a0
	jsr	WaitPort(a6)		;wait until message arrives
	lea.l	PR_MsgPort(a4),a0	;
	jsr	GetMsg(a6)		;get message
	move.l	d0,a5			;save return message in a5
	moveq.l	#0,d0			;any version
	lea.l	INTName,a1		;get address of libraryname to a1
	jsr	OpenLibrary(a6)		;try to open Intuition
	tst.l	d0			;see if d0 = 0
	beq	ErrorExit		;ohh shit, failed to open Intuition
	move.l	d0,a6			;get Baseaddress of Intuition to a6
	moveq.l	#0,d0			;PFlag = 0
	moveq.l	#0,d1			;NFlag = 0
	move.l	#320,d2			;width 320
	move.l	#68,d3			;height 68
	suba.l	a0,a0			;clear a0
	lea.l	ITextId,a1		;get address of ITextId to a1
	suba.l	a2,a2			;PosText = 0
	lea.l	ITextOk,a3		;get address of NegText to a3
	jsr	AutoRequest(a6)		;display Autorequest
	move.l	a6,a1			;get INTBase to a1
	move.l	ExecBase,a6		;get ExecBase to a6
	jsr	CloseLibrary(a6)	;close Intuition

	jsr	Forbid(a6)		;we have to do this, so that WB can't
					; unload us to far
	move.l	a5,a1			;get address of ReturnMessage to a1
	jsr	ReplyMsg(a6)		;reply the message
	pop.w	d0
ErrorExit:
	rts

main:
	move.l	ExecBase,a6		;ExecBase to a6
	lea	DOSName(pc),a1		;Address of string 'dos.library',0
	jsr	OldOpenLibrary(a6)	;open library
	move.l	d0,DOSBase		;save DOSBaseaddress
	beq	Exit			;if d0=0 then Exit (System is realy sick!)
	move.l	D0,A6			;move DOSBasepointer to a6
	jsr	OutPut(A6)		;identify the initial output handle
	move.l	D0,stdout		;save stdout

	pop.w	d0			;get cmdlength
SkipSP:	
	move.b	(a2)+,d1		;skip spaces
	beq.b	ShowHow			;if NULL-String then /* help */
	cmp.b	#' ',d1			;is it a Space ?
	beq.b	SkipSP			;yes -> SkipSP

	sub.l	#1,a2
	move.l	a2,StringAddress	;store windownamestart
	add.l	#1,a2

	cmp.b	#$0a,d1			;is it #$0a ?
	beq.b	ShowHow			;yes -> ShowHow /* help */

	cmp.b	#'?',d1			;is it '?' ?
	beq.b	ShowHow			;yes -> ShowHow /* help required */

	cmp.b	#'"',d1			;is it '"' ?
	beq.b	DoQuotes		;yes -> DoQuotes

DoTheMainParsing:
	cmp.b	#'-',d1			;is it '-' ?
	beq.b	Parser			;yes -> Parser /* see if -f or -b */
	move.b	(a2)+,d1		;get the next byte
	bne.b	DoTheMainParsing	;-> DoTheMainParsing

ShowHow:
	lea	HelpString(pc),a0	;give the user help
	move.l	a0,d2			;copy address of string to d2
	bsr	TextOutPut		;output text via Amiga-Dog
	bra	DosClose		;close DOS

DoQuotes:
	move.l	a2,StringAddress	;store address of string
QuotesLoop:
	move.b	(a2)+,d1		;get the next character
	beq.b	ShowHow			;if we have reached the end -> ShowHow
	cmp.b	#'"',d1			;is it '"' ?
	bne.b	QuotesLoop		;no ->QuotesLoop
	move.b	#0,-(a2)		;clear the last '"'
	addq.l	#1,a2
	bra.b	DoTheMainParsing	;-> DoTheMainParsing


Parser:
	move.b	#0,-(a2)

	add.l	#1,a2
	move.b	(a2),d1
	and.b	#%11011111,d1		;convert lowercase to uppercase
	cmp.b	#'F',d1
	beq.b	Front
	cmp.b	#'B',d1
	beq.b	Back
	bra.b	ShowHow

Front:	push.w	#'FR'			;this is only to remember that the user
					; wanted '-f'
	bra.b	Intuitionopen

Back:	push.w	#'BA'

Intuitionopen:				;try to open Intuition
	move.l	ExecBase,a6
	lea	INTName,a1
	jsr	OldOpenLibrary(a6)
	move.l	d0,IntuitionBase	;save IntuitionBase
	beq	DosClose		;if d0=0 then DosClose (Unable to open Intuition)
	move.l	d0,a6			;copy IntuitionBase to a6
	moveq	#0,d0			;clear d0
	jsr	LockIBase(a6)		;lock Intuition
	move.l	d0,MyLock		;store lock

	move.l	60(a6),d0		;get address of first screen
	beq	Same			;if d0=0 then /* there is no
					; Screen !? */
	move.l	d0,ScreenPointer	;store address of screen
	move.l	d0,a0
GetFirst:
	move.l	4(a0),d0		;get address of 1. Window
	move.l	d0,a2
	tst.l	d0			;is d0=0?
	beq	NextScreen		;if a2=0 then /* there is no
					; window in this screen */
****						 ****
* Compare the name of the windowtitle with a string *
* if equal then rearrange window		    *
*****						 ****
DoCompare:
	move.l	StringAddress,a1	;get address of String to a1
	move.l	32(a2),d0		;get address of windowtitle to d0
	beq.b	NotTheSame
	move.l	d0,a0
001$:
	move.b	(a0)+,d0		;copy one byte to d0
	move.b	(a1)+,d1		;copy one byte to d1
	and.b	#%11011111,d0		;convert lowercase to uppercase
	and.b	#%11011111,d1		;convert lowercase to uppercase
	cmp.b	d0,d1			;see if equal
	bne.b	NotTheSame		;if no then -> NotTheSame	
	tst.b	d0			;see if NULL
	beq.b	Same			;if yes then -> Same
	bra.b	001$			;-> 001$

NotTheSame:
	move.l	(a2),d0			;get address of next window
	move.l	d0,a2			;copy address to a2
	tst.l	d0			;is d0=0?
	bne.b	DoCompare		;look at the next windowtitle
					;if a2=0 then/* this was the last window */
NextScreen:
	move.l	ScreenPointer,a0
	move.l	(a0),a0			;get address of next screen
	move.l	a0,d0
	tst.l	d0			;is a0=0?
	beq.b	NotFound		;if a0=0 then /* no more screens */
	move.l	a0,ScreenPointer
	bra.b	GetFirst		;get first windowaddress

NotFound:
	pop.w	d0
	move.l	MyLock,a0		;get lockvalue
	jsr	UnlockIBase(a6)		;unlock Intuition
	lea	HelpString(pc),a0	;get address of Helpstring to a0
	move.l	a0,d2			;copy address to d2
	bsr	TextOutPut		;output text
	lea	NotFoundString(pc),a0	;get address of NotFoundString to a0
	move.l	a0,d2			;copy address to d2
	bsr	TextOutPut		;output text
	bra.b	NoScreen		;-> NoScreen

Same:
	move.l	MyLock,a0		;get lockvalue
	jsr	UnlockIBase(a6)		;unlock Intuition

	move.l	a2,a0			;copy windowaddress to a0
	pop.w	d0
	cmp.w	#'BA',d0
	beq.b	MoveToBack 
	cmp.w	#'FR',d0
	bne.b	NoScreen
	jsr	WindowToFront(a6)	;window to front
	bra.b	NoScreen

MoveToBack:
	jsr	WindowToBack(a6)	;window to back

NoScreen:

Intuitionclose:				;close Intuition
	move.l	ExecBase,a6
	move.l	IntuitionBase,a1
	jsr	CloseLibrary(a6)

DosClose:				;close Amiga-DOG
	move.l	ExecBase,a6
	move.l	DOSBase,a1
	jsr	CloseLibrary(a6)
Exit:
	move.l	#0,d0			;no return-error
	rts

;*****************************************************************************
;*
;*	TextOutPut
;*			by	Heiko Rath
;*
;* PURPOSE: 		output a NULL-terminated string via stdout
;*
;* ROUTINE TYPE: 	subroutine
;*
;* SYNTAX:		bsr	TextOutPut	(stringaddress)(d2)
;*
;* ENTRY CONDITIONS:	needs DOSlibrary opened and stdout defined
;*			also needs DOS-'Write' offset -48 defined.
;*
;* RETURNS:		Text via DOS-stdout
;*
;* NOTE:		its better if the string is really NULL-terminated
;*
;* CHANGED:		nothing
;*
;* USAGE:		move.l	#Textaddress,d2
;*			bsr	TextOutPut
;*
;*****************************************************************************



TextOutPut:		;TextOutPut (Textaddress)(d2)
			;prints a NULL-terminated string via stdout
			;changed: nothing
	movem.l	d0-d7/a0-a6,-(sp)	;save registers
	move.l	d2,a0			;address to a0
	clr.l	d3			;count = 0
CountLoop:
	tst.b	(a0)+			;is it NULL ?
	beq.b	PMsg			;yes: -=> determine length
	addq.l	#1,d3			;count = count+1
	bra.b	CountLoop		;test next byte
PMsg:
	move.l	stdout,d1		;get stdout to d1
	move.l	DOSBase,a6		;move DOSBase to a6
	jsr	Write(a6)		;write the Text
	movem.l	(sp)+,a0-a6/d0-d7	;reserve registers
	rts

;*** variables:

DOSBase		dc.l	0			;pointer to the DOSBaseaddress
stdout		dc.l	0			;pointer to standard output
IntuitionBase:					;address of Intuitionbase
		dc.l	0
UserPort:
		dc.l	0
MyLock		dc.l	0
ScreenPointer	dc.l	0
StringAddress	dc.l	0

		cnop	0,2
;*** constants:
DOSName		dc.b	'dos.library',0		;name of the DOS-library
INTName		dc.b	'intuition.library',0	;name of the Intuition-library

		cnop	0,2

HelpString:
	dc.b	$9b,'0;33;40m','WindowArranger',$9b,'0;31;40m'
	dc.b	' by Heiko Rath - ',169,' 1987/88 by '
	dc.b	$9b,'1;31;40m','The Software Brewery',$9b,'0;31;40m',10
	dc.b	'  V.'
	Version
	dc.b	'       '
	dc.b	'Raiffeisenstr.10a,D-6108 Weiterstadt,WEST GERMANY',10
	dc.b	'               '
	dc.b	'Send me: Mail, $$$$$, girls or Marabou chocolate.'
	dc.b	10,10
	dc.b	'To arrange a window use ',$9b,'0;33;40m'
	dc.b	'WindowArranger ',$9b,'0;31;40m','name -f or '
	dc.b	'-b',10
	dc.b	$9b,'1;31;40m','f',$9b,'0;31;40m'
	dc.b	'= window to front & '
	dc.b	$9b,'1;31;40m','b',$9b,'0;31;40m'
	dc.b	'= window to back',10
	dc.b	0
	cnop	0,2
NotFoundString:
		dc.b	$9b,'0;32;40m','Please give me a babel fish'
		dc.b	' or a new windowname!!',$9b,'0;31;40m',10,0

		cnop	0,2
******************************************************************************
*
*	This is the IntuitionTextStructure of the AutoRequester
*
******************************************************************************
ITextId:	dc.b	0,1,1,0	     ;pens, drawmode and filler
		dc.w	17,6	     ;XY
		dc.l	0	     ;NULL for default font
		dc.l	S1 	     ;pointer to text
		dc.l	ITextId2     ;next IntuitText structure
ITextId2	dc.b	0,1,1,0
		dc.w	17,18
		dc.l	0
		dc.l	S2
		dc.l	0
ITextOk:	dc.b	0,1,1,0
		dc.w	6,3
		dc.l	0
		dc.l	SOk
		dc.l	0
		cnop	0,2
S1		dc.b	'WindowArranger must be',0
		cnop	0,2
S2		dc.b	'started from the CLI.',0
		cnop	0,2
SOk		dc.b	'Ok',0
		cnop	0,2
SHAR_EOF
cat << \SHAR_EOF > Warranger.uu

begin 644 Warranger
M```#\P`````````!``````````````$?```#Z0```1\L#R1(0C(``#\`+'@`A
M!)/)3J[^VBA`2JP`K&8``%I![`!<3J[^@$'L`%Q.KOZ,*D!P`$/Z`@9.KOW8`
M2H!G```V+$!P`'(`)#P```%`=D21R$/Z`[R5RD?Z`]Y.KOZD(DXL>``$3J[^6
M8DZN_WPB34ZN_H8P'TYU+'@`!$/Z`;).KOYH(\````(29P`!8BQ`3J[_Q"/`C
M```"%C`?$AIG+`P!`"!G]E.*(\H```(J4HH,`0`*9Q8,`0`_9Q`,`0`B9Q@,3
M`0`M9RH2&F;V0?H!@"0(80`!'F```0HCR@```BH2&F?H#`$`(F;V%3P``%**F
M8-`5/```4HH2$@(!`-\,`0!&9P@,`0!"9PA@P#\\1E)@!#\\0D$L>``$0_H!>
M($ZN_F@CP````AIG``"X+$!P`$ZN_F(CP````B(@+@`\9P``="/````")B!`O
M("@`!"1`2H!G```L(GH`U"`J`"!G&"!`$!@2&0(``-\"`0#?L@!F!DH`9SY@)
MZB`2)$!*@&;6('H`IB!0(`A*@&<((\@```(F8+8P'R!Z`(Q.KOY<0?H`KB0(@
M80``3$'Z`B`D"&$``$)@(B!Z`&Y.KOY<($HP'PQ`0D%G#`Q`1E)F"DZN_LA@J
M!$ZN_LXL>``$(GH`0$ZN_F(L>``$(GH`+$ZN_F)P`$YU2.?__B!"0H-*&&<$+
M4H-@^"(Z`!0L>@`,3J[_T$S??_].=0``````````````````````````````&
M``````!D;W,N;&EB<F%R>0!I;G1U:71I;VXN;&EB<F%R>0";,#LS,SLT,&U7^
M:6YD;W=!<G)A;F=E<ILP.S,Q.S0P;2!B>2!(96EK;R!2871H("T@J2`Q.3@W2
M+S@X(&)Y()LQ.S,Q.S0P;51H92!3;V9T=V%R92!"<F5W97)YFS`[,S$[-#!MS
M"B`@5BXQ+C(U("`@("`@(%)A:69F96ES96YS='(N,3!A+$0M-C$P."!796ET>
M97)S=&%D="Q715-4($=%4DU!3ED*("`@("`@("`@("`@("`@4V5N9"!M93H@9
M36%I;"P@)"0D)"0L(&=I<FQS(&]R($UA<F%B;W4@8VAO8V]L871E+@H*5&\@/
M87)R86YG92!A('=I;F1O=R!U<V4@FS`[,S,[-#!M5VEN9&]W07)R86YG97(@H
MFS`[,S$[-#!M;F%M92`M9B!O<B`M8@J;,3LS,3LT,&UFFS`[,S$[-#!M/2!WK
M:6YD;W<@=&\@9G)O;G0@)B";,3LS,3LT,&UBFS`[,S$[-#!M/2!W:6YD;W<@W
M=&\@8F%C:PH``)LP.S,R.S0P;5!L96%S92!G:79E(&UE(&$@8F%B96P@9FESE
M:"!O<B!A(&YE=R!W:6YD;W=N86UE(2&;,#LS,3LT,&T*`````0$``!$`!@``(
M``````1*```$(@`!`0``$0`2````````!&(```````$!```&``,````````$.
M>`````!7:6YD;W=!<G)A;F=E<B!M=7-T(&)E``!S=&%R=&5D(&9R;VT@=&AE>
M($-,22X`3VL``````^P````,`````````(0```"4````J````-H```$B```!9
A-````4(```&,```$&@``!!X```0N```$0@````````/RQ
``
end
size 1248
SHAR_EOF
#	End of shell archive
exit 0
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
Have five nice days.