Get Next Available Thread ID

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: GET NEXT AVAILABLE THREAD ID
#       Get next available (non-running) thread ID (or the specified one, if it is less than 16)
#       Parameters:
#           r4 = (p_ThreadID) Thread ID
#               0x10 (16) tells the routine to find next available thread ID
#       Returns:
#           r2 = (Thread ID)

80149bec: 27bdffe8 addiu r29,r29,-0x0018
80149bf0: 28820010 slti r2,r4,0x0010
80149bf4: afbf0014 sw r31,0x0014(r29)
80149bf8: 10400003 beq r2,r0,0x80149c08
80149bfc: afb00010 sw r16,0x0010(r29)
                                                    #   if (p_ThreadID < 16) {
80149c00: 0805270d j 0x80149c34
80149c04: 00801021 addu r2,r4,r0                    #       return p_ThreadID;
                                                    #   }
80149c08: 34100001 ori r16,r0,0x0001                #   index = 1
                                                    #   do {
80149c0c: 0c053325 jal 0x8014cc94                   #       ROUTINE: result = Check Thread Running Status (index);  // Find if thread index (ID) is in use
80149c10: 02002021 addu r4,r16,r0                   #       index
80149c14: 10400007 beq r2,r0,0x80149c34             #       if (result == 0)
80149c18: 02001021 addu r2,r16,r0                   #           return index;                                           // If not, pick it (return this thread index (ID))     
80149c1c: 26100001 addiu r16,r16,0x0001             #       index = index + 1
80149c20: 2a020010 slti r2,r16,0x0010
80149c24: 1440fff9 bne r2,r0,0x80149c0c
80149c28: 00000000 nop                              #   } while (index < 16)

80149c2c: 0c053256 jal 0x8014c958                   #   ROUTINE: result = Stop Current Thread ();                   // If all threads in use, stop the current thread
80149c30: 00000000 nop                              
80149c34: 8fbf0014 lw r31,0x0014(r29)               #   return result;
80149c38: 8fb00010 lw r16,0x0010(r29)
80149c3c: 27bd0018 addiu r29,r29,0x0018
80149c40: 03e00008 jr r31
80149c44: 00000000 nop