| CPU coach chooses the strongest available keeper from its own unchanged roster.
| Hook native SetPlayer; D3 is the actual roster index passed into native loading.
 .ifndef WITH_TRANSFERS
 .equ WITH_TRANSFERS,0
 .endif
 .text
 .globl _start
_start:
 movem.l %d0-%d2/%d4-%d7/%a0-%a6,-(%sp)
 cmpi.w #1,0xFFFFF07A
 bne.w done
 tst.w 0x34(%a3)
 bne.w done
 moveq #1,%d0
 lea 0xFFFFC6CE,%a2
 btst #6,0x62(%a3)
 beq.w team_ready
 moveq #2,%d0
 adda.w #0x364,%a2
team_ready:
 | Never override any team controlled by a human, including cooperative pads.
 lea 0xFFFFC328,%a0
 moveq #3,%d1
human_scan:
 cmp.w (%a0)+,%d0
 beq.w done
 dbra %d1,human_scan
 tst.w 0x26(%a2)
 bmi.w done
 move.l 0x1E(%a2),%d0
 cmpi.l #0x200,%d0
 blo.w done
 cmpi.l #0x300000,%d0
 bhs.w done
 jsr 0x9F40
 cmpi.w #1,%d0
 blo.w done
 cmpi.w #4,%d0
 bhi.w done
 move.w %d0,%d4
 movea.l 0x1E(%a2),%a4
 adda.w (%a4),%a4
 moveq #0,%d6
 moveq #-1,%d5
 moveq #-1,%d7
candidate:
    .if WITH_TRANSFERS
 jsr 0x236034
    .else
 movea.l %a4,%a1
 adda.w (%a1),%a1
 lea 8(%a1),%a4
    .endif
 move.w %d6,%d0
 add.w %d0,%d0
 move.w 0x66(%a2,%d0.w),%d1
 cmpi.w #-3,%d1
 beq.w next
 cmpi.w #-4,%d1
 beq.w next
 tst.w %d1
 bgt.w next
 | 2*leg power +2*speed +3*defensive awareness +2*agility +four save traits.
 moveq #0,%d0
 move.b 1(%a1),%d0
 andi.w #15,%d0
 add.w %d0,%d0
 moveq #0,%d1
 move.b 2(%a1),%d1
 lsr.w #4,%d1
 add.w %d1,%d1
 add.w %d1,%d0
 moveq #0,%d1
 move.b 3(%a1),%d1
 move.w %d1,%d2
 andi.w #15,%d2
 add.w %d2,%d2
 add.w %d2,%d0
 lsr.w #4,%d1
 mulu.w #3,%d1
 add.w %d1,%d0
 moveq #0,%d1
 move.b 6(%a1),%d1
 move.w %d1,%d2
 andi.w #15,%d2
 add.w %d2,%d0
 lsr.w #4,%d1
 add.w %d1,%d0
 moveq #0,%d1
 move.b 7(%a1),%d1
 move.w %d1,%d2
 andi.w #15,%d2
 add.w %d2,%d0
 lsr.w #4,%d1
 add.w %d1,%d0
 cmp.w %d7,%d0
 bgt.w select
 blt.w next
 cmp.w %d3,%d6
 bne.w next
select:
 move.w %d0,%d7
 move.w %d6,%d5
next:
 addq.w #1,%d6
 cmp.w %d4,%d6
 blo.w candidate
 tst.w %d5
 bmi.w done
 move.w %d5,%d3
 move.w %d5,0x26(%a2)
done:
 movem.l (%sp)+,%d0-%d2/%d4-%d7/%a0-%a6
 bclr #6,0x63(%a3)
 jmp 0x15AAA
