home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / amiga / workbench / commodoties / patchwb.lha / PatchWB / PatchWB.asm < prev    next >
Assembly Source File  |  1998-01-31  |  5KB  |  204 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.01 (30.01.98)",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.         bsr.s _IsIPrefs
  144.         bne.s _OldLockIBase
  145.  
  146.         saveregs d0/a4
  147.  
  148.         move.l a6,a4            ;keep intuitionbase
  149.  
  150.         move.l SysBase(pc),a6
  151.         jsr Forbid(a6)
  152.  
  153.         do
  154.          tst.w $b3a(a4)         ;Obtain magic intuition lock
  155.          break.s eq
  156.          move.l $568(a4),a6     ;get graphics lib from IBase
  157.                                 ;!!! This works ONLY for V39,V40
  158.          jsr WaitTOF(a6)
  159.         loop.s
  160.         addq.w #1,$b3a(a4)
  161.  
  162.         move.l SysBase(pc),a6
  163.         jsr Permit(a6)
  164.  
  165.         move.l a4,a6
  166.         loadregs
  167.  
  168. _OldLockIBase:
  169.         jmp $aaaaaaaa           ;patch in old address here... Don't try this at home...
  170.  
  171. _NewUnlockIBase:
  172.         move.l a0,d0
  173.         bsr.s _IsIPrefs
  174.         movea.l d0,a0
  175.         bne.s _OldUnlockIBase
  176.         bsr.s _OldUnlockIBase
  177.         subq.w #1,$b3a(a6)      ;free magic intuition base
  178.         rts
  179.  
  180. _OldUnlockIBase:
  181.         jmp $aaaaaaaa
  182.  
  183. _IsIPrefs:
  184.         move.l SysBase(pc),a0
  185.         move.l $114(a0),a0      ;get task
  186.         move.l $a(a0),d1        ;get name
  187.         beq.s .exit
  188.         lea IPrefsName(pc),a1
  189.         move.l d1,a0
  190.         for.l #11,d1
  191.          cmp.b (a0)+,(a1)+
  192.         next ne,d1
  193.         rts
  194. .exit:
  195.         clz
  196.         rts
  197.  
  198.  
  199. IntuitionBase:  dc.l 0
  200. SysBase:        dc.l 0
  201. WBSName:        dc.b "Workbench",0
  202. IPrefsName:     dc.b "½ IPrefs ╗",0
  203.  
  204.