home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / DevPatch / DevPatchII.doc < prev    next >
Text File  |  1990-04-10  |  15KB  |  329 lines

  1.  
  2.  
  3.                                 'DevPatch II'
  4.                                 -------------
  5.                                by PowerPeak '89
  6.  
  7.     This little utility was written by three people, the skeleton was
  8. written by Jorrit Tyberghein and the rest by all three of us.  The idea for
  9. the program came when we were assembling with DevPac II and we were low on
  10. chip memory.  As you may know DevPac opens a full screen window to print
  11. error messages while assembling.  It also opens a window for default output
  12. when you run your program.  These windows that are rarely used eat up 40K of
  13. precious chip memory !!!  We decided to do something about it and wrote this
  14. little utility : DevPatch II.
  15.  
  16.     The program will install a patch for OpenWindow, this means it will
  17. catch every OpenWindow call by ANY program so it can check the NewWindow
  18. structure passed to the function.  If a program tries to open a window with
  19. a title of 'Assembling...' or 'Default Output Window' the height will be
  20. forced to 45 pixels.  This way the DevPac windows will open, but they will
  21. be very small so they don't use up a lot of chip memory.  Problem solved !!
  22. The patch only requires 144 bytes of memory, so this shouldn't be a problem.
  23.     If you run the program a second time it will remove the patch.
  24.  
  25.     We find this program very useful, we hope you do as well.
  26.  
  27.  
  28.                                 DevPatch II
  29. -----------------------------------------------------------------------------
  30.  
  31.           OPT c+,l-
  32.  
  33. ****************************************
  34. * DevPatch II                          *
  35. * © J.Tyberghein N.François P.Marivoet *
  36. * Dec 1989                             *
  37. ****************************************
  38.  
  39. -----------------------------------------------------------------------------
  40.    You will probably have to change this include directory.                  
  41. -----------------------------------------------------------------------------
  42.                                                                              
  43.    incdir  "DevPacII:include"
  44.    include "exec/types.i"
  45.    include "exec/memory.i"
  46.    include "exec/ports.i"
  47.    include "exec/exec_lib.i"
  48.  
  49. -----------------------------------------------------------------------------
  50.    Some equals so we don't have to include too much.                         
  51. -----------------------------------------------------------------------------
  52.                                                                              
  53.    ;IntuitionBase routines
  54. _LVOOpenWindow  equ   -204
  55.    ;DosBase
  56. _LVOOutput      equ   -60
  57. _LVOWrite       equ   -48
  58.  
  59. nw_Title        equ   $1a
  60. nw_Height       equ   6
  61. PRI             equ   0
  62.  
  63.    ;*** Start code ***
  64.  
  65. -----------------------------------------------------------------------------
  66.    Open all the necessary libraries.
  67. -----------------------------------------------------------------------------
  68.                                                                              
  69.    ;IntuitionLibrary
  70.       lea IntLib(PC),a1
  71.       CALLEXEC   OldOpenLibrary
  72.       move.l d0,_IntBase
  73.    ;DosLibrary
  74.       lea DosLib(PC),a1
  75.       CALLEXEC   OldOpenLibrary
  76.       move.l d0,_DosBase
  77.  
  78. -----------------------------------------------------------------------------
  79.    Print copyright message to screen.                                        
  80. -----------------------------------------------------------------------------
  81.  
  82.    ;Say we exist
  83.       lea StartupMsg(PC),a2
  84.       moveq #StartupMsgLen,d2
  85.       bsr myPuts
  86.  
  87. -----------------------------------------------------------------------------
  88.    Here we test to see if the patch is already installed.  We do this by     
  89.    looking for the named message port we left open when we installed the     
  90.    patch.                                                                    
  91. -----------------------------------------------------------------------------
  92.                                                                              
  93.    ;Test if the MsgPort exists
  94.       lea StartBlock(PC),a1
  95.       lea PortName(a1),a1
  96.       CALLEXEC FindPort
  97.       tst.l d0
  98.       bne.s PortAlreadyExists
  99.  
  100. -----------------------------------------------------------------------------
  101.    The message port didn't exist so we must install the patch.               
  102.    First we allocate memory for the message port structure AND the patch     
  103.    code.                                                                     
  104. -----------------------------------------------------------------------------
  105.                                                                              
  106.    ;Create MsgPort
  107.       move.l #BlockLen,d0
  108.       move.l #MEMF_CLEAR+MEMF_PUBLIC,d1
  109.       CALLEXEC AllocMem
  110.       tst.l d0
  111.       beq CloseLib
  112.  
  113. -----------------------------------------------------------------------------
  114.    Now copy the message port and the code to the allocated block.            
  115. -----------------------------------------------------------------------------
  116.                                                                              
  117.       move.l d0,Port
  118.       lea StartBlock(PC),a0
  119.       move.l d0,a1
  120.       move.l #BlockLen,d0
  121.       CALLEXEC CopyMem
  122.  
  123. -----------------------------------------------------------------------------
  124.    Ask EXEC to add our port.  The message port is not correctly initialized, 
  125.    but since this is a dummy port this is not important.  The port is only   
  126.    used to find our patch the second time we get run.                        
  127. -----------------------------------------------------------------------------
  128.                                                                              
  129.       move.l Port(PC),a1
  130.       lea PortName(a1),a0
  131.       move.l a0,LN_NAME(a1)
  132.       CALLEXEC AddPort
  133.  
  134. -----------------------------------------------------------------------------
  135.    Now, install the OpenWindow patch !                                       
  136.    After the CALLEXEC D0 holds the old address of OpenWindow, we put this
  137.    into our jmp instruction at the end of the patch.                         
  138. -----------------------------------------------------------------------------
  139.                                                                              
  140.    ;Install patch
  141.       move.l Port(PC),a1
  142.       lea OpenPatch(a1),a0
  143.       move.l a0,d0
  144.       move.l _IntBase(PC),a1
  145.       move.l #_LVOOpenWindow,a0
  146.       CALLEXEC   SetFunction
  147.       move.l Port(PC),a1
  148.       move.l d0,JmpLab1(a1)
  149.  
  150. -----------------------------------------------------------------------------
  151.    From this point on our OpenWindow is called.                              
  152.    Inform the user we installed the patch and exit.                          
  153. -----------------------------------------------------------------------------
  154.                                                                              
  155.       lea PatchedMsg(PC),a2
  156.       moveq #PatchedMsgLen,d2
  157.       bsr.s myPuts
  158.       bra.s CloseLib
  159.  
  160. -----------------------------------------------------------------------------
  161.    Here, the port already exists and we have to remove the patch (and port).
  162. -----------------------------------------------------------------------------
  163.                                                                              
  164. PortAlreadyExists:
  165.       move.l d0,a2
  166.  
  167. -----------------------------------------------------------------------------
  168.    First restore the old OpenWindow function.                                
  169. -----------------------------------------------------------------------------
  170.                                                                              
  171.    ;Remove patch
  172.       move.l JmpLab1(a2),d0
  173.       move.l _IntBase(PC),a1
  174.       move.l #_LVOOpenWindow,a0
  175.       CALLEXEC   SetFunction
  176.  
  177. -----------------------------------------------------------------------------
  178.    Remove the message port from the system list.                             
  179. -----------------------------------------------------------------------------
  180.                                                                              
  181.    ;Remove Port
  182.       move.l a2,a1
  183.       CALLEXEC RemPort
  184.  
  185. -----------------------------------------------------------------------------
  186.    Free the memory we allocated for the message port and the code.
  187. -----------------------------------------------------------------------------
  188.                                                                              
  189.    ;Free Patch memory
  190.       move.l a2,a1
  191.       move.l #BlockLen,d0
  192.       CALLEXEC FreeMem
  193.  
  194. -----------------------------------------------------------------------------
  195.    Tell user what happened.                                                  
  196. -----------------------------------------------------------------------------
  197.                                                                              
  198.    ;Say it's done
  199.       lea RemovedMsg(PC),a2
  200.       moveq #RemovedMsgLen,d2
  201.       bsr.s myPuts
  202.  
  203. -----------------------------------------------------------------------------
  204.    Close everything we opened before we exit !                               
  205. -----------------------------------------------------------------------------
  206.  
  207. CloseLib:
  208.    ;Close libraries
  209.       move.l _DosBase(PC),a1
  210.       CALLEXEC   CloseLibrary
  211.       move.l _IntBase(PC),a1
  212.       CALLEXEC   CloseLibrary
  213.       rts
  214.  
  215. -----------------------------------------------------------------------------
  216.    Print a message to the console.                                           
  217. -----------------------------------------------------------------------------
  218.                                                                              
  219. myPuts:
  220.       move.l _DosBase(PC),a6
  221.       jsr _LVOOutput(a6)
  222.       move.l d0,d1
  223.       move.l d2,d3
  224.       move.l a2,d2
  225.       jsr _LVOWrite(a6)
  226.       rts
  227.  
  228. -----------------------------------------------------------------------------
  229.    The part between stars is the block that gets copied when we install the  
  230.    patch.  It holds a message port structure and the actual patch code.      
  231.    This will need very little memory.
  232.    The patch code MUST be PC-relative !!! (so e.g. NO 'move.l d0,label')     
  233. -----------------------------------------------------------------------------
  234.                                                                              
  235. *****************************************************************************
  236.  
  237.    ;This is our MsgPort followed by our patch function
  238.    ;this data and code will be copied in one block
  239. StartBlock:
  240.       dc.l   0,0
  241.       dc.b   NT_MSGPORT,PRI
  242.       dc.l   0                     ;Pointer to our MsgPort name
  243.       dc.b   0,0
  244.       dc.l   0,0,0,0
  245.       dc.b   0,0
  246.  
  247. -----------------------------------------------------------------------------
  248.    The patch !!!!  First save all registers we use !!! (VERY IMPORTANT)      
  249. -----------------------------------------------------------------------------
  250.                                                                              
  251. OpenPatch equ *-StartBlock
  252.       movem.l   d7/a2-a3,-(a7)
  253.  
  254. -----------------------------------------------------------------------------
  255.    A0 holds address of NewWindow structure.  Check if the title equals       
  256.    'Assembling...' or 'Default Output Window'.
  257. -----------------------------------------------------------------------------
  258.                                                                              
  259.       move.l nw_Title(a0),a2
  260.       lea Assembling(PC),a3
  261.       moveq #13,d7
  262. CmpLoop:
  263.       cmp.b (a2)+,(a3)+
  264.       dbne d7,CmpLoop
  265.       addq.w #1,d7
  266.       beq.s PatchIt
  267.       move.l nw_Title(a0),a2
  268.       lea DefaultOutput(PC),a3
  269.       moveq #21,d7
  270. CmpLoop2:
  271.       cmp.b (a2)+,(a3)+
  272.       dbne d7,CmpLoop2
  273.       addq.w #1,d7
  274.       bne.s NotDevpac
  275.  
  276. -----------------------------------------------------------------------------
  277.    The title was recognized, so we force the window height to 45             
  278. -----------------------------------------------------------------------------
  279.                                                                              
  280. PatchIt:
  281.       move.w #45,nw_Height(a0)
  282. NotDevpac:
  283.       movem.l (a7)+,d7/a2-a3
  284.  
  285. -----------------------------------------------------------------------------
  286.    Jump to old OpenWindow (most probably in KickStart)
  287. -----------------------------------------------------------------------------
  288.                                                                              
  289. JmpLab1 equ *+2-StartBlock
  290.       jmp $0.l
  291.  
  292. -----------------------------------------------------------------------------
  293.    Portname and strings to compare with.  Note that it is VERY important     
  294.    that these strings are in the allocated block, otherwise they become      
  295.    invalid when your program exits !!!                                       
  296. -----------------------------------------------------------------------------
  297.                                                                              
  298. PortName equ *-StartBlock
  299.                  dc.b "DevPatch.port",0
  300. Assembling:      dc.b "Assembling...",0
  301. DefaultOutput:   dc.b "Default Output Window",0
  302.  
  303. BlockLen equ *-StartBlock
  304.  
  305. *****************************************************************************
  306.  
  307. -----------------------------------------------------------------------------
  308.    Data                                                                      
  309. -----------------------------------------------------------------------------
  310.                                                                              
  311. _IntBase:     dc.l 0
  312. _DosBase:     dc.l 0
  313. Port:         dc.l 0
  314. IntLib:       dc.b "intuition.library",0
  315. DosLib:       dc.b "dos.library",0
  316. StartupMsg:   dc.b 27,"[33mDevPatch II",27,"[0m by PowerPeak",10,0
  317. StartupMsgLen equ *-StartupMsg
  318. PatchedMsg:   dc.b "Patch installed.",10,0
  319. PatchedMsgLen equ *-PatchedMsg
  320. RemovedMsg:   dc.b "Patch removed.",10,0
  321. RemovedMsgLen equ *-RemovedMsg
  322.  
  323.    END
  324.  
  325. -----------------------------------------------------------------------------
  326.    The end.                                                   Nico François  
  327. -----------------------------------------------------------------------------
  328.                                                                              
  329.