; FindTaskByName  0.03  17-12-2006


FindTaskByName                         ROUT
; Function:     Find a task by its name.
; Entry   :     r1 = pointer to name
;               wp = pointer to workspace
; Exit    :     r0 = pointer to task block (PRM 3-315) or undefined
;               r2 = taskhandle or undefined
; APCS    :     no, but useable in an APCS environment
; Alters  :     r0,r2,lr
; Flags   :     C=1 if task not found - others undefined
; Requires:     Scratch                    - offset of buffer (16 bytes minimum) in workspace relative to wp
;               X                          - &20000
;               TaskManager_EnumerateTasks - &42681
        STMFD   sp!, {r1, r3-r4, lr}
        MOV     r0, #0
0000    ADD     r1, wp, #Scratch
        MOV     r2, #16
        SWI     X+TaskManager_EnumerateTasks
        MOVVS   r0, #1<<31
        CMP     r0, #1<<31                       ; all done when negative
        BCS     %f0020
        LDR     r1, [sp]                         ; get pointer to input
        LDR     r2, [wp, #Scratch+4]             ; get pointer name of current entry
0010    LDRB    r3, [r1], #1
        LDRB    r4, [r2], #1
        CMP     r3, #' '                         ; no terminator in input?
        EORHS   lr, r3, r4
        TSTHS   lr ,#&DF                         ; then compare case insensitive
        BEQ     %b0010                           ; continue while equal
        CMPLO   r4, #' '                         ; not equal and no terminator in entry or no comparison (i.e. no terminator in input)?
        BHS     %b0000                           ; then try next
        ADD     r0, wp, #Scratch                 ; else found
        LDR     r2, [r0]                         ; get handle
0020    LDMFD   sp!, {r1, r3-r4, pc}

        END
