****************************************************************************
* FixReq.asm -- makes all "System Request" requesters       Bill Kelly
* appear in the current active window.                      08/24/87
*
* This code is placed into the public domain without any
* guarantees or support of any kind.
*
* To the best of my knowledge, this program follows all of
* the "rules" for hacking at library vectors and is perfectly
* safe.  However, when you execute it, you are doing so at
* your own risk -- please don't try to sue me if it malfunctions!
*
* With that said, here's what it's doing:
* Every time the Intuition library AutoRequest() function is
* called, FixReq replaces the Window pointer supplied to
* AutoRequest() with a pointer to the currently active window.
*
* The result: All of the "System Request" requesters will conveniently
* pop up right in front of you instead of bringing the WorkBench
* Screen to front and not putting it back.  I find it kinda handy... :-)
****************************************************************************

LibVersion          equ     31              ; 1.1 should work fine.
_LVOOpenLibrary     equ     -($228)
_LVOCloseLibrary    equ     -($19e)
_LVOAllocMem        equ     -($0c6)
_LVOSetFunction     equ     -($1a4)
_LVOAutoRequest     equ     -($15c)
ib_ActiveWindow     equ     52              ; from intuition/intuiBase.i

            lea     newreq(pc),a0
            lea     newreqEnd(pc),a1
            suba.l  a0,a1                   ; find size of newreq routine
            move.l  a1,_newreqSize          ; save for later

            move.l  $4,a6                   ; get execbase

            move.l  _newreqSize,d0          ; bytesize
            moveq   #0,d1                   ; requirements
            jsr     _LVOAllocMem(a6)
            move.l  d0,_newreqAddr          ; save address
            beq.s   error                   ; wow, you are **low** on RAM!

            lea     _IntuiName(pc),a1       ; need to get intuiBase
            move.l  #LibVersion,d0
            jsr     _LVOOpenLibrary(a6)
            move.l  d0,_IntuiBase           ; save intuibase for newreq
            beq.s   error                   ; ..huh? where's intuition???

            move.l  _IntuiBase,a0
            adda.l  #_LVOAutoRequest+2,a0   ; ptr to addr of prev. AutoReq
            move.l  (a0),_oldreq            ; save addr of previous AutoReq

            lea     newreq(pc),a0
            move.l  _newreqAddr,a1
            move.l  _newreqSize,d0
            subq.l  #1,d0
newreqCopy: move.b  (a0)+,(a1)+             ; copy the code
            dbf     d0,newreqCopy

            move.l  _IntuiBase,a1           ; library
            move.l  #_LVOAutoRequest,a0     ; funcOffset
            move.l  _newreqAddr,d0          ; funcEntry
            jsr     _LVOSetFunction(a6)

            moveq   #0,d0                   ; no errors
            rts                             ; exit without error

error:      moveq   #20,d0                  ; no RAM or no intuiBase
            rts                             ; exit with FAIL errorcode

newreq:     move.l  _IntuiBase(pc),a0
            move.l  ib_ActiveWindow(a0),a0  ; get addr of active window
            move.l  _oldreq(pc),-(sp)       ; push prev AutoReq addr
            rts                             ; and return to it
_IntuiBase: ds.l    1                       ; space for intuibase
_oldreq:    ds.l    1                       ; space for addr of oldreq
newreqEnd:                                  ; used to find newreq size

    CNOP    0,4

_newreqSize ds.l    1
_newreqAddr ds.l    1

    CNOP    0,4

_IntuiName  dc.b    'intuition.library',0,0

    END

