Get Equipable RSM

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: Get Equipable RSM
#       Writes the relevant equipable RSM (Reaction, Support, Movement) abilities into a specified array.  
#       Only gets the abilities that are within the specified slot.
#       Parameters:
#           r4 = (formationUnitIndex) Index of unit on formation screen (*0x8018ba20)
#           r5 = (slot) Reaction = 1, Support = 2, Movement = 3
#           r6 = (RSM_Array) Array to write the equipable RSM abilites into (0x801cd230)
#       Returns:
#           r2 = Number of equipable RSM abilities for the specified slot

80122c20: 27bdfe20 addiu r29,r29,-0x01e0
80122c24: afb301c4 sw r19,0x01c4(r29)
80122c28: 00a09821 addu r19,r5,r0                   #   slot
80122c2c: afb701d4 sw r23,0x01d4(r29)
80122c30: 00c0b821 addu r23,r6,r0                   #   RSM_Array
80122c34: 00041400 sll r2,r4,0x10
80122c38: afb001b8 sw r16,0x01b8(r29)
80122c3c: 00028403 sra r16,r2,0x10                  #   formationUnitIndex
80122c40: 02002021 addu r4,r16,r0                   #   formationUnitIndex
80122c44: afb101bc sw r17,0x01bc(r29)
80122c48: 34110001 ori r17,r0,0x0001                #   count = 1
80122c4c: afb501cc sw r21,0x01cc(r29)
80122c50: 0040a821 addu r21,r2,r0                   #   formationUnitIndex << 16
80122c54: afb401c8 sw r20,0x01c8(r29)
80122c58: 27b40018 addiu r20,r29,0x0018             #   baseAbilitiesPtr
80122c5c: 00101080 sll r2,r16,0x02                  #   formationUnitIndex * 4
80122c60: afbf01d8 sw r31,0x01d8(r29)
80122c64: afb601d0 sw r22,0x01d0(r29)
80122c68: afb201c0 sw r18,0x01c0(r29)
80122c6c: 3c01801d lui r1,0x801d
80122c70: 00220821 addu r1,r1,r2
80122c74: 8c22d5ec lw r2,-0x2a14(r1)                #   formationUnit = formationUnitArray[formationUnitIndex]
80122c78: 00000000 nop
80122c7c: 94560024 lhu r22,0x0024(r2)               #   formationUnit.JobID
80122c80: 0c04890f jal 0x8012243c                   #   baseJobID = Get Base Job (Formation Screen) (formationUnitIndex);
80122c84: 3c12004b lui r18,0x004b                   #   jobValue = 0x4b0000
80122c88: 02002021 addu r4,r16,r0                   #   formationUnitIndex
80122c8c: 00021400 sll r2,r2,0x10
80122c90: 00022c03 sra r5,r2,0x10                   #   baseJobID
80122c94: 02603021 addu r6,r19,r0                   #   slot
80122c98: 27a70018 addiu r7,r29,0x0018              #   baseAbilitiesPtr
80122c9c: 34020001 ori r2,r0,0x0001
80122ca0: 0c048a3c jal 0x801228f0                   #   numAbilities = Find Unit Abilities or Skillsets (formationUnitIndex, baseJobID, slot, baseAbilitiesPtr, 1);
80122ca4: afa20010 sw r2,0x0010(r29)
80122ca8: 00408021 addu r16,r2,r0                   #   numAbilities
                                                    #   do {
80122cac: 34020001 ori r2,r0,0x0001
80122cb0: afa20010 sw r2,0x0010(r29)                
80122cb4: 00152403 sra r4,r21,0x10                  #       formationUnitIndex
80122cb8: 00122c03 sra r5,r18,0x10                  #       jobID = jobValue >> 16
80122cbc: 02603021 addu r6,r19,r0                   #       slot
80122cc0: 00103840 sll r7,r16,0x01
80122cc4: 0c048a3c jal 0x801228f0                   #       loopNumAbilities = Find Unit Abilities or Skillsets (formationUnitIndex, jobID, slot, baseAbilitiesPtr + (numAbilities * 2), 1);
80122cc8: 02873821 addu r7,r20,r7
80122ccc: 02028021 addu r16,r16,r2                  #       numAbilities = numAbilities + loopNumAbilities
80122cd0: 3c020001 lui r2,0x0001
80122cd4: 02429021 addu r18,r18,r2                  #       jobValue = jobValue + 0x10000
80122cd8: 26310001 addiu r17,r17,0x0001             #       count = count + 1
80122cdc: 2a220013 slti r2,r17,0x0013
80122ce0: 1440fff2 bne r2,r0,0x80122cac             #   } while (count < 19);
80122ce4: 2606ffff addiu r6,r16,-0x0001             #   numAbilitiesLeft = numAbilities - 1    
                                                    
80122ce8: 18c00013 blez r6,0x80122d38               #   if (numAbilitiesLeft > 0) {
80122cec: 2408ffff addiu r8,r0,-0x0001
80122cf0: 27a70018 addiu r7,r29,0x0018              #       baseAbilitiesPtr
                                                    #       do {   
80122cf4: 18c0000d blez r6,0x80122d2c
80122cf8: 00008821 addu r17,r0,r0                   #           count = 0
                                                    #           if (numAbilitiesLeft > 0) {
80122cfc: 00e02021 addu r4,r7,r0                    #               abilityPtr = baseAbilitiesPtr
                                                    #               do {
80122d00: 84820002 lh r2,0x0002(r4)                 #                   abilityID2 = *(abilityPtr + 2)
80122d04: 84850000 lh r5,0x0000(r4)                 #                   abilityID1 = *(abilityPtr)
80122d08: 00401821 addu r3,r2,r0                    #                   abilityID2
80122d0c: 00a2102a slt r2,r5,r2
80122d10: 14400003 bne r2,r0,0x80122d20
80122d14: 26310001 addiu r17,r17,0x0001             #                   count = count + 1
                                                    #                   if (abilityID1 >= abilityID2) {
80122d18: a4830000 sh r3,0x0000(r4)                 #                       *(abilityPtr) = abilityID2
80122d1c: a4850002 sh r5,0x0002(r4)                 #                       *(abilityPtr + 1) = abilityID1
                                                    #                   }
80122d20: 0226102a slt r2,r17,r6
80122d24: 1440fff6 bne r2,r0,0x80122d00
80122d28: 24840002 addiu r4,r4,0x0002               #                   abilityPtr = abilityPtr + 2
                                                    #               } while (count < numAbilitiesLeft);
                                                    #           }
80122d2c: 24c6ffff addiu r6,r6,-0x0001              #           numAbilitiesLeft = numAbilitiesLeft - 1
80122d30: 1cc0fff0 bgtz r6,0x80122cf4
80122d34: 2408ffff addiu r8,r0,-0x0001                      
                                                    #       } while (numAbilitiesLeft > 0);
                                                    #   }
80122d38: 00008021 addu r16,r0,r0                   #   index = 0
80122d3c: 87a20018 lh r2,0x0018(r29)                #   *baseAbilitiesPtr
80122d40: 00000000 nop
80122d44: 1048002d beq r2,r8,0x80122dfc             
80122d48: 27a40018 addiu r4,r29,0x0018              #   baseAbilitiesPtr
                                                    #   if ((*baseAbilitiesPtr) != -1) {
                                                    #       testAbilityID = -1
80122d4c: 00161400 sll r2,r22,0x10
80122d50: 00023c03 sra r7,r2,0x10                   #       jobID = formationUnit.JobID
80122d54: 00002821 addu r5,r0,r0                    #       offset = 0
80122d58: 02e04821 addu r9,r23,r0                   #       RSM_Array_Ptr = &RSM_Array[0]
80122d5c: 00a41021 addu r2,r5,r4                    #       baseAbilitiesPtr + offset
                                                    #       do {
80122d60: 84460000 lh r6,0x0000(r2)                 #           storeValue = *(baseAbilitiesPtr + offset)
80122d64: 00000000 nop
80122d68: 10c8001d beq r6,r8,0x80122de0
80122d6c: 3402004b ori r2,r0,0x004b
                                                    #           if (storeValue != testAbilityID) {
80122d70: 14e20005 bne r7,r2,0x80122d88             #               if ((jobID == 0x4b)                 //  Chemist
80122d74: 3402004e ori r2,r0,0x004e
80122d78: 340201da ori r2,r0,0x01da
80122d7c: 14c20002 bne r6,r2,0x80122d88             #                   and (storeValue == 0x01da))     //  Throw Item
80122d80: 3402004e ori r2,r0,0x004e
                                                    #               {
80122d84: 340641da ori r6,r0,0x41da                 #                   storeValue = 0x41da             //  Throw Item (Disabled)
                                                    #               }
80122d88: 14e20005 bne r7,r2,0x80122da0                        
80122d8c: 34020054 ori r2,r0,0x0054                 #               if ((jobID == 0x4e)                 //  Monk
80122d90: 340201d8 ori r2,r0,0x01d8
80122d94: 14c20002 bne r6,r2,0x80122da0             #                   and (storeValue == 0x01d8))     //  Martial Arts
80122d98: 34020054 ori r2,r0,0x0054
                                                    #               {
80122d9c: 340641d8 ori r6,r0,0x41d8                 #                   storeValue = 0x41d8             //  Martial Arts (Disabled)
                                                    #               }
80122da0: 14e20005 bne r7,r2,0x80122db8             #               if ((jobID == 0x54)                 //  Mediator
80122da4: 34020059 ori r2,r0,0x0059
80122da8: 340201d9 ori r2,r0,0x01d9
80122dac: 14c20002 bne r6,r2,0x80122db8             #                   and (storeValue == 0x01d9))     //  Monster Talk
80122db0: 34020059 ori r2,r0,0x0059
                                                    #               {
80122db4: 340641d9 ori r6,r0,0x41d9                 #                   storeValue = 0x41d9             //  Monster Talk (Disabled)
                                                    #               }
80122db8: 14e20005 bne r7,r2,0x80122dd0
80122dbc: 26100001 addiu r16,r16,0x0001             #               index = index + 1
                                                    #               if ((jobID == 0x59)                 //  Ninja
80122dc0: 340201dd ori r2,r0,0x01dd
80122dc4: 14c20002 bne r6,r2,0x80122dd0             #                   and (storeValue == 0x01dd))     //  Two Swords
80122dc8: 00000000 nop    
                                                    #               {                          
80122dcc: 340641dd ori r6,r0,0x41dd                 #                   storeValue = 0x41dd             //  Two Swords (Disabled)            
                                                    #               }
80122dd0: a5260000 sh r6,0x0000(r9)                 #               *(RSM_Array_Ptr) = storeValue
80122dd4: 25290002 addiu r9,r9,0x0002               #               RSM_Array_Ptr = RSM_Array_Ptr + 2
80122dd8: 03a51021 addu r2,r29,r5
80122ddc: 84480018 lh r8,0x0018(r2)                 #               testAbilityID = *(baseAbilitiesPtr + offset)
                                                    #           }
80122de0: 24a50002 addiu r5,r5,0x0002               #           offset = offset + 2
80122de4: 27a40018 addiu r4,r29,0x0018              #           baseAbilitiesPtr
80122de8: 00a41021 addu r2,r5,r4                    #           baseAbilitiesPtr + offset
80122dec: 84430000 lh r3,0x0000(r2)                 #           abilityID = *(baseAbilitiesPtr + offset)
80122df0: 2402ffff addiu r2,r0,-0x0001
80122df4: 1462ffda bne r3,r2,0x80122d60
80122df8: 00a41021 addu r2,r5,r4                    #           baseAbilitiesPtr + offset
                                                    #       } while (abilityID != -1);
                                                    #   }
80122dfc: 00101040 sll r2,r16,0x01
80122e00: 00571021 addu r2,r2,r23
80122e04: 2403ffff addiu r3,r0,-0x0001
80122e08: a4430000 sh r3,0x0000(r2)                 #   *(RSM_Array_Ptr) = -1
80122e0c: 02001021 addu r2,r16,r0                   #   return index;       // Number of RSM abilities
80122e10: 8fbf01d8 lw r31,0x01d8(r29)
80122e14: 8fb701d4 lw r23,0x01d4(r29)
80122e18: 8fb601d0 lw r22,0x01d0(r29)
80122e1c: 8fb501cc lw r21,0x01cc(r29)
80122e20: 8fb401c8 lw r20,0x01c8(r29)
80122e24: 8fb301c4 lw r19,0x01c4(r29)
80122e28: 8fb201c0 lw r18,0x01c0(r29)
80122e2c: 8fb101bc lw r17,0x01bc(r29)
80122e30: 8fb001b8 lw r16,0x01b8(r29)
80122e34: 27bd01e0 addiu r29,r29,0x01e0
80122e38: 03e00008 jr r31
80122e3c: 00000000 nop