home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff332.lzh
/
DevPatch
/
DevPatchII.doc
< prev
next >
Wrap
Text File
|
1990-03-20
|
15KB
|
329 lines
'DevPatch II'
-------------
by PowerPeak '89
This little utility was written by three people, the skeleton was
written by Jorrit Tyberghein and the rest by all three of us. The idea for
the program came when we were assembling with DevPac II and we were low on
chip memory. As you may know DevPac opens a full screen window to print
error messages while assembling. It also opens a window for default output
when you run your program. These windows that are rarely used eat up 40K of
precious chip memory !!! We decided to do something about it and wrote this
little utility : DevPatch II.
The program will install a patch for OpenWindow, this means it will
catch every OpenWindow call by ANY program so it can check the NewWindow
structure passed to the function. If a program tries to open a window with
a title of 'Assembling...' or 'Default Output Window' the height will be
forced to 45 pixels. This way the DevPac windows will open, but they will
be very small so they don't use up a lot of chip memory. Problem solved !!
The patch only requires 144 bytes of memory, so this shouldn't be a problem.
If you run the program a second time it will remove the patch.
We find this program very useful, we hope you do as well.
DevPatch II
-----------------------------------------------------------------------------
OPT c+,l-
****************************************
* DevPatch II *
* © J.Tyberghein N.François P.Marivoet *
* Dec 1989 *
****************************************
-----------------------------------------------------------------------------
You will probably have to change this include directory.
-----------------------------------------------------------------------------
incdir "DevPacII:include"
include "exec/types.i"
include "exec/memory.i"
include "exec/ports.i"
include "exec/exec_lib.i"
-----------------------------------------------------------------------------
Some equals so we don't have to include too much.
-----------------------------------------------------------------------------
;IntuitionBase routines
_LVOOpenWindow equ -204
;DosBase
_LVOOutput equ -60
_LVOWrite equ -48
nw_Title equ $1a
nw_Height equ 6
PRI equ 0
;*** Start code ***
-----------------------------------------------------------------------------
Open all the necessary libraries.
-----------------------------------------------------------------------------
;IntuitionLibrary
lea IntLib(PC),a1
CALLEXEC OldOpenLibrary
move.l d0,_IntBase
;DosLibrary
lea DosLib(PC),a1
CALLEXEC OldOpenLibrary
move.l d0,_DosBase
-----------------------------------------------------------------------------
Print copyright message to screen.
-----------------------------------------------------------------------------
;Say we exist
lea StartupMsg(PC),a2
moveq #StartupMsgLen,d2
bsr myPuts
-----------------------------------------------------------------------------
Here we test to see if the patch is already installed. We do this by
looking for the named message port we left open when we installed the
patch.
-----------------------------------------------------------------------------
;Test if the MsgPort exists
lea StartBlock(PC),a1
lea PortName(a1),a1
CALLEXEC FindPort
tst.l d0
bne.s PortAlreadyExists
-----------------------------------------------------------------------------
The message port didn't exist so we must install the patch.
First we allocate memory for the message port structure AND the patch
code.
-----------------------------------------------------------------------------
;Create MsgPort
move.l #BlockLen,d0
move.l #MEMF_CLEAR+MEMF_PUBLIC,d1
CALLEXEC AllocMem
tst.l d0
beq CloseLib
-----------------------------------------------------------------------------
Now copy the message port and the code to the allocated block.
-----------------------------------------------------------------------------
move.l d0,Port
lea StartBlock(PC),a0
move.l d0,a1
move.l #BlockLen,d0
CALLEXEC CopyMem
-----------------------------------------------------------------------------
Ask EXEC to add our port. The message port is not correctly initialized,
but since this is a dummy port this is not important. The port is only
used to find our patch the second time we get run.
-----------------------------------------------------------------------------
move.l Port(PC),a1
lea PortName(a1),a0
move.l a0,LN_NAME(a1)
CALLEXEC AddPort
-----------------------------------------------------------------------------
Now, install the OpenWindow patch !
After the CALLEXEC D0 holds the old address of OpenWindow, we put this
into our jmp instruction at the end of the patch.
-----------------------------------------------------------------------------
;Install patch
move.l Port(PC),a1
lea OpenPatch(a1),a0
move.l a0,d0
move.l _IntBase(PC),a1
move.l #_LVOOpenWindow,a0
CALLEXEC SetFunction
move.l Port(PC),a1
move.l d0,JmpLab1(a1)
-----------------------------------------------------------------------------
From this point on our OpenWindow is called.
Inform the user we installed the patch and exit.
-----------------------------------------------------------------------------
lea PatchedMsg(PC),a2
moveq #PatchedMsgLen,d2
bsr.s myPuts
bra.s CloseLib
-----------------------------------------------------------------------------
Here, the port already exists and we have to remove the patch (and port).
-----------------------------------------------------------------------------
PortAlreadyExists:
move.l d0,a2
-----------------------------------------------------------------------------
First restore the old OpenWindow function.
-----------------------------------------------------------------------------
;Remove patch
move.l JmpLab1(a2),d0
move.l _IntBase(PC),a1
move.l #_LVOOpenWindow,a0
CALLEXEC SetFunction
-----------------------------------------------------------------------------
Remove the message port from the system list.
-----------------------------------------------------------------------------
;Remove Port
move.l a2,a1
CALLEXEC RemPort
-----------------------------------------------------------------------------
Free the memory we allocated for the message port and the code.
-----------------------------------------------------------------------------
;Free Patch memory
move.l a2,a1
move.l #BlockLen,d0
CALLEXEC FreeMem
-----------------------------------------------------------------------------
Tell user what happened.
-----------------------------------------------------------------------------
;Say it's done
lea RemovedMsg(PC),a2
moveq #RemovedMsgLen,d2
bsr.s myPuts
-----------------------------------------------------------------------------
Close everything we opened before we exit !
-----------------------------------------------------------------------------
CloseLib:
;Close libraries
move.l _DosBase(PC),a1
CALLEXEC CloseLibrary
move.l _IntBase(PC),a1
CALLEXEC CloseLibrary
rts
-----------------------------------------------------------------------------
Print a message to the console.
-----------------------------------------------------------------------------
myPuts:
move.l _DosBase(PC),a6
jsr _LVOOutput(a6)
move.l d0,d1
move.l d2,d3
move.l a2,d2
jsr _LVOWrite(a6)
rts
-----------------------------------------------------------------------------
The part between stars is the block that gets copied when we install the
patch. It holds a message port structure and the actual patch code.
This will need very little memory.
The patch code MUST be PC-relative !!! (so e.g. NO 'move.l d0,label')
-----------------------------------------------------------------------------
*****************************************************************************
;This is our MsgPort followed by our patch function
;this data and code will be copied in one block
StartBlock:
dc.l 0,0
dc.b NT_MSGPORT,PRI
dc.l 0 ;Pointer to our MsgPort name
dc.b 0,0
dc.l 0,0,0,0
dc.b 0,0
-----------------------------------------------------------------------------
The patch !!!! First save all registers we use !!! (VERY IMPORTANT)
-----------------------------------------------------------------------------
OpenPatch equ *-StartBlock
movem.l d7/a2-a3,-(a7)
-----------------------------------------------------------------------------
A0 holds address of NewWindow structure. Check if the title equals
'Assembling...' or 'Default Output Window'.
-----------------------------------------------------------------------------
move.l nw_Title(a0),a2
lea Assembling(PC),a3
moveq #13,d7
CmpLoop:
cmp.b (a2)+,(a3)+
dbne d7,CmpLoop
addq.w #1,d7
beq.s PatchIt
move.l nw_Title(a0),a2
lea DefaultOutput(PC),a3
moveq #21,d7
CmpLoop2:
cmp.b (a2)+,(a3)+
dbne d7,CmpLoop2
addq.w #1,d7
bne.s NotDevpac
-----------------------------------------------------------------------------
The title was recognized, so we force the window height to 45
-----------------------------------------------------------------------------
PatchIt:
move.w #45,nw_Height(a0)
NotDevpac:
movem.l (a7)+,d7/a2-a3
-----------------------------------------------------------------------------
Jump to old OpenWindow (most probably in KickStart)
-----------------------------------------------------------------------------
JmpLab1 equ *+2-StartBlock
jmp $0.l
-----------------------------------------------------------------------------
Portname and strings to compare with. Note that it is VERY important
that these strings are in the allocated block, otherwise they become
invalid when your program exits !!!
-----------------------------------------------------------------------------
PortName equ *-StartBlock
dc.b "DevPatch.port",0
Assembling: dc.b "Assembling...",0
DefaultOutput: dc.b "Default Output Window",0
BlockLen equ *-StartBlock
*****************************************************************************
-----------------------------------------------------------------------------
Data
-----------------------------------------------------------------------------
_IntBase: dc.l 0
_DosBase: dc.l 0
Port: dc.l 0
IntLib: dc.b "intuition.library",0
DosLib: dc.b "dos.library",0
StartupMsg: dc.b 27,"[33mDevPatch II",27,"[0m by PowerPeak",10,0
StartupMsgLen equ *-StartupMsg
PatchedMsg: dc.b "Patch installed.",10,0
PatchedMsgLen equ *-PatchedMsg
RemovedMsg: dc.b "Patch removed.",10,0
RemovedMsgLen equ *-RemovedMsg
END
-----------------------------------------------------------------------------
The end. Nico François
-----------------------------------------------------------------------------