Find Free Party Index

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: FIND FREE PARTY INDEX
#       Parameters:
#           r4 = (joinAsGuest) Join as Guest flag
#           r5 = (zeroPtr) Pointer to write a zero byte to
#       Returns:
#           r2 = (unitIndex), if a free slot was found;
#                   -1, otherwise

80059d5c: 27bdff90 addiu r29,r29,-0x0070
80059d60: afb20068 sw r18,0x0068(r29)
80059d64: 00809021 addu r18,r4,r0                   #   joinAsGuest (Join as Guest flag)
80059d68: afb00060 sw r16,0x0060(r29)
80059d6c: 00008021 addu r16,r0,r0                   #   unitIndex = 0
80059d70: afb10064 sw r17,0x0064(r29)
80059d74: 27b10010 addiu r17,r29,0x0010             #   localArrayPtr
80059d78: afbf006c sw r31,0x006c(r29) 
80059d7c: a0a00000 sb r0,0x0000(r5)                 #   *zeroPtr = 0
                                                    #   do {
80059d80: 0c0166bc jal 0x80059af0                   #       partyUnit = Get Party Data Pointer (unitIndex);
80059d84: 02002021 addu r4,r16,r0
80059d88: ae220000 sw r2,0x0000(r17)                #       *localArrayPtr = partyUnit
80059d8c: 26100001 addiu r16,r16,0x0001             #       unitIndex = unitIndex + 1
80059d90: 2a020014 slti r2,r16,0x0014
80059d94: 1440fffa bne r2,r0,0x80059d80
80059d98: 26310004 addiu r17,r17,0x0004             #       localArrayPtr = localArrayPtr + 4   
                                                    #   } while (unitIndex < 20);
80059d9c: 12400003 beq r18,r0,0x80059dac            #   if (joinAsGuest) {
80059da0: 34020010 ori r2,r0,0x0010                 #       startIndex = 16
80059da4: 0801676d j 0x80059db4
80059da8: 34050014 ori r5,r0,0x0014                 #       endIndex = 20
                                                    #   } else {
80059dac: 00001021 addu r2,r0,r0                    #       startIndex = 0
80059db0: 34050010 ori r5,r0,0x0010                 #       endIndex = 16
                                                    #   }
80059db4: 00408021 addu r16,r2,r0                   #   index = startIndex
80059db8: 0205102a slt r2,r16,r5                    
80059dbc: 1040000e beq r2,r0,0x80059df8
80059dc0: 00101080 sll r2,r16,0x02
                                                    #   if (startIndex < endIndex) {
80059dc4: 340400ff ori r4,r0,0x00ff                 #       0xff
80059dc8: 27a30010 addiu r3,r29,0x0010              #       localArrayBasePtr
80059dcc: 00431821 addu r3,r2,r3                    #       localArrayPtr = localArrayBasePtr + startIndex
                                                    #       do {
80059dd0: 8c620000 lw r2,0x0000(r3)                 #           *localArrayPtr
80059dd4: 00000000 nop
80059dd8: 90420001 lbu r2,0x0001(r2)                #           unitIndex = *localArrayPtr.unitIndex
80059ddc: 00000000 nop
80059de0: 10440006 beq r2,r4,0x80059dfc             #           if (unitIndex == 0xff) return index;
80059de4: 02001021 addu r2,r16,r0
80059de8: 26100001 addiu r16,r16,0x0001             #           index = index + 1
80059dec: 0205102a slt r2,r16,r5
80059df0: 1440fff7 bne r2,r0,0x80059dd0
80059df4: 24630004 addiu r3,r3,0x0004               #           localArrayPtr = localArrayPtr + 4
                                                    #       } while (startIndex < endIndex);
                                                    #   }
80059df8: 2402ffff addiu r2,r0,-0x0001              #   return -1;
80059dfc: 8fbf006c lw r31,0x006c(r29)
80059e00: 8fb20068 lw r18,0x0068(r29)
80059e04: 8fb10064 lw r17,0x0064(r29)
80059e08: 8fb00060 lw r16,0x0060(r29)
80059e0c: 27bd0070 addiu r29,r29,0x0070
80059e10: 03e00008 jr r31
80059e14: 00000000 nop

Return Locations

SCUS_942.21
0x80059c18 - Save Unit to Party
0x80059c4c - Save Unit to Party

REQUIRE.OUT
0x801c6078 - Get Free Party Slot Status