Try Get Unit Misc Data By Unit ID

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: TRY GET UNIT MISC DATA BY UNIT ID
#       Parameters:
#           r4 = (ptr_UnitID) Pointer to a Unit ID (for events?)
#               Referenced value is overwritten by the corresponding Unit Misc ID, if:
#                   (*ptr_UnitID) != 0) and (*ptr_UnitID) < 0x100, and misc unit was found for the specified ID
#           r5 = (ptr_State) Pointer to write state value to
#               State =    (*ptr_UnitID) - 0xFE,   if (*ptr_UnitID) > 0x100
#                           1,                      if (*ptr_UnitID) == 0
#                           0,                      Otherwise
#
#       Returns:
#           r2  =   0,  if (*ptr_UnitID) != 0) and (*ptr_UnitID) < 0x100, and no misc unit could be found for the specified ID
#               =   1,  Otherwise

80147928: 27bdffe0 addiu r29,r29,-0x0020
8014792c: afb00010 sw r16,0x0010(r29)
80147930: 00808021 addu r16,r4,r0                   #   ptr_UnitID
80147934: afbf0018 sw r31,0x0018(r29)
80147938: afb10014 sw r17,0x0014(r29)
8014793c: 96040000 lhu r4,0x0000(r16)               #   unitID = *ptr_UnitID
80147940: 00000000 nop
80147944: 10800010 beq r4,r0,0x80147988
80147948: 00a08821 addu r17,r5,r0                   #   ptr_State
                                                    #   if (unitID != 0) {
8014794c: 2c820100 sltiu r2,r4,0x0100               
80147950: 1040000b beq r2,r0,0x80147980             #       if (unitID < 0x100) {
80147954: 00000000 nop
80147958: 0c04cc56 jal 0x80133158                   #           miscUnitID = Get misc ID (unitID);
8014795c: 00000000 nop
80147960: a6020000 sh r2,0x0000(r16)                #           *ptr_UnitID = miscUnitID
80147964: ae200000 sw r0,0x0000(r17)                #           *ptr_State = 0
80147968: 96030000 lhu r3,0x0000(r16)               #           miscUnitID
8014796c: 340207d0 ori r2,r0,0x07d0                 #           2000
80147970: 14620008 bne r3,r2,0x80147994             #           if (miscUnitID != 2000)
80147974: 34020001 ori r2,r0,0x0001                 #               return 1;
80147978: 08051e65 j 0x80147994                     #           else
8014797c: 00001021 addu r2,r0,r0                    #               return 0;
                                                    #       } else {
80147980: 14800002 bne r4,r0,0x8014798c
80147984: 2482ff02 addiu r2,r4,-0x00fe              #           state = unitID - 0xFE
                                                    #       }
                                                    #   } else {
80147988: 34020001 ori r2,r0,0x0001                 #       state = 1
                                                    #   }
8014798c: ae220000 sw r2,0x0000(r17)                #   *ptr_State = state
80147990: 34020001 ori r2,r0,0x0001                 #   return 1;
80147994: 8fbf0018 lw r31,0x0018(r29)
80147998: 8fb10014 lw r17,0x0014(r29)
8014799c: 8fb00010 lw r16,0x0010(r29)
801479a0: 27bd0020 addiu r29,r29,0x0020
801479a4: 03e00008 jr r31
801479a8: 00000000 nop