home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / workbench / patchwb / patchwb.asm next >
Encoding:
Assembly Source File  |  1998-01-08  |  4.7 KB  |  177 lines

  1.         opt o+,ow-
  2. ;*************************************************
  3. ;** PatchWB © 1997,98 THOR                      **
  4. ;**                                             **
  5. ;** Fixes bugs in the workbench library         **
  6. ;** AddAppItem crashes if the WB is closed      **
  7. ;** IPrefs/OpenWorkBench() hang                 **
  8. ;*************************************************
  9.  
  10.         opt o+,ow-
  11.  
  12.         include inc:macros.asm
  13.         include inc:exec_lib.asm
  14.         include inc:intuition_lib.asm
  15.         include inc:workbench_lib.asm
  16.         include inc:graphics_lib.asm
  17.  
  18.         section main_code,code
  19.  
  20. ;*************************************************
  21. ;** Program starts here                         **
  22. ;*************************************************
  23. Start:
  24.         move.l ExecBase,a6
  25.         lea WBName(pc),a1
  26.         move.l a6,SysBase       ;SaveBack SysBase
  27.         moveq #39,d0            ;Only V39,V40
  28.         jsr OpenLibrary(a6)
  29.         move.l d0,a4
  30.         tst.l d0
  31.         beq .nowblib
  32.         cmp.w #40,20(a4)        ;newer version -> forget it!
  33.         bhi .nowblib
  34.  
  35.         lea IntName,a1
  36.         moveq #37,d0
  37.         jsr OpenLibrary(a6)
  38.         move.l d0,a3
  39.         tst.l d0
  40.         beq.s .nointuilib
  41.  
  42.         jsr Forbid(a6)
  43.  
  44.         move.l #_NewLockIBase,d0
  45.         lea LockIBase,a0
  46.         move.l a3,a1
  47.         jsr SetFunction(a6)
  48.         move.l d0,_OldLockIBase+2
  49.  
  50.         move.l #_NewUnlockIBase,d0
  51.         lea UnlockIBase,a0
  52.         move.l a3,a1
  53.         jsr SetFunction(a6)
  54.         move.l d0,_OldUnLockIBase+2
  55.  
  56.         move.l #_NewAppMenu,d0
  57.         lea AddAppMenuItemA,a0
  58.         move.l a4,a1
  59.         jsr SetFunction(a6)
  60.         move.l d0,_OldAppMenu+2
  61.  
  62.         move.l #_NewRemMenu,d0
  63.         lea RemoveAppMenuItem,a0
  64.         move.l a4,a1
  65.         jsr SetFunction(a6)
  66.         move.l d0,_OldRemMenu+2
  67.         
  68.         jsr CacheClearU(a6)                     ;Execbase still in a6: Flush Cache
  69.  
  70.         lea Start(pc),a0
  71.         move.l a3,IntuitionBase                 ;save back intuition for later use
  72.         clr.l -4(a0)                            ;Unlink segments...
  73.  
  74.         jsr Permit(a6)
  75.  
  76.                                                 ;intuition isn't closed
  77.                                                 ;it won't get away and
  78.                                                 ;can't be flushed from memory
  79. .nointuilib:
  80.         move.l a4,a1                            ;close workbench
  81.         jsr CloseLibrary(a6)
  82. .nowblib:
  83.         moveq #0,d0                             ;fail quietly
  84.         rts
  85.  
  86. WBName:         dc.b "workbench.library",0
  87. IntName:        dc.b "intuition.library",0
  88.                 dc.b "$VER: PatchWB 1.00",0
  89.  
  90.         section resident_code,code
  91.  
  92. ;*************************************************
  93. ;** The resident code starts here               **
  94. ;** this segment is unlinked and stays          **
  95. ;** resident                                    **
  96. ;** Remember that this is still a patch         **
  97. ;** don't try this at home!                     **
  98. ;*************************************************
  99. _NewAppMenu:
  100.         saveregs d0-d1/a0-a1/a6
  101.  
  102.         move.l IntuitionBase(pc),a6
  103.         lea WBSName(pc),a0
  104.         jsr LockPubScreen(a6)   ;WB MUST be open ! This call will do that
  105.  
  106.         loadregs
  107. _OldAppMenu:
  108.         jsr $aaaaaaaa           ;old address gets patched in here! Don't try this at home!
  109.  
  110.         saveregs d0/a6
  111.  
  112.         move.l IntuitionBase(pc),a6
  113.         lea WBSName(pc),a0
  114.         sub.l a1,a1
  115.         jsr UnlockPubScreen(a6)
  116.  
  117.         loadregs
  118.         rts
  119.  
  120. _NewRemMenu:
  121.         saveregs a0/a6
  122.  
  123.         move.l IntuitionBase(pc),a6
  124.         lea WBSName(pc),a0
  125.         jsr LockPubScreen(a6)   ;WB MUST be open ! This call will do that
  126.  
  127.         loadregs
  128. _OldRemMenu:
  129.         jsr $aaaaaaaa           ;old address gets patched in here! Don't try this at home!
  130.  
  131.         saveregs d0/a6
  132.  
  133.         move.l IntuitionBase(pc),a6
  134.         lea WBSName(pc),a0
  135.         sub.l a1,a1
  136.         jsr UnlockPubScreen(a6)
  137.  
  138.         loadregs
  139.         rts
  140.  
  141.  
  142. _NewLockIBase:
  143.         saveregs d0/a4
  144.  
  145.         move.l a6,a4            ;keep intuitionbase
  146.  
  147.         move.l SysBase(pc),a6
  148.         jsr Forbid(a6)
  149.  
  150.         do
  151.          tst.w $b3a(a4)         ;Obtain magic intuition lock
  152.          break.s eq
  153.          move.l $568(a4),a6     ;get graphics lib from IBase
  154.                                 ;!!! This works ONLY for V39,V40
  155.          jsr WaitTOF(a6)
  156.         loop.s
  157.         addq.w #1,$b3a(a4)
  158.  
  159.         move.l SysBase(pc),a6
  160.         jsr Permit(a6)
  161.  
  162.         move.l a4,a6
  163.         loadregs
  164.  
  165. _OldLockIBase:
  166.         jmp $aaaaaaaa           ;patch in old address here... Don't try this at home...
  167.  
  168. _NewUnlockIBase:
  169. _OldUnlockIBase:
  170.         jsr $aaaaaaaa
  171.         subq.w #1,$b3a(a6)      ;free magic intuition base
  172.         rts
  173.  
  174. IntuitionBase:  dc.l 0
  175. SysBase:        dc.l 0
  176. WBSName:        dc.b "Workbench",0
  177.