* == patchwb.asm =======================================================
*
* Written May, 1988 by William S. Hawes >>> Freely Distributable <<<
*
* ======================================================================
* Clears the pr_ConsoleTask pointer for the WorkBench process.  This is
* necessary because the ConsoleTask pointer becomes invalid as soon as
* the CLI from which WorkBench was launched (via LoadWB) is closed.
* Clearing the ConsoleTask pointer will help prevent crashes when the
* DOS Execute() function is called later.

         INCLUDE  "exec/types.i"
         INCLUDE  "exec/macros.i"
         INCLUDE  "exec/tasks.i"
         INCLUDE  "exec/interrupts.i"
         INCLUDE  "exec/execbase.i"

         INCLUDE  "libraries/dos.i"
         INCLUDE  "libraries/dosextens.i"

         XREF     _AbsExecBase

         XLIB     FindName
         XLIB     Disable
         XLIB     Enable

start    movea.l  _AbsExecBase,a6

         moveq    #0,d2                ; clear flag
         moveq    #10,d6               ; default return

         CALLSYS  Disable              ; no interrupts, please

         ; Look for WorkBench on the Ready list ...

         lea      TaskReady(a6),a0     ; ready list
         bra.s    2$                   ; jump in

         ; (A) WorkBench task found ... patch it

1$:      clr.l    pr_ConsoleTask(a0)   ; clear slot
         moveq    #0,d6                ; all OK

2$:      lea      WBName(pc),a1        ; WorkBench name
         CALLSYS  FindName             ; D0=node
         movea.l  d0,a0
         tst.l    d0                   ; found?
         bne.s    1$                   ; yes

         lea      TaskWait(a6),a0      ; waiting list
         not.w    d2                   ; loop back?
         bne.s    2$                   ; yes

         CALLSYS  Enable               ; reenable switching
         move.l   d6,d0                ; return code
         rts

         ; String constants

WBName   dc.b     'Workbench',0        ; WorkBench name

         END
