Get Existent Battle Unit Pointer
Jump to navigation
Jump to search
Alternate documentation here: Get unit data pointer?
# ROUTINE: GET EXISTENT BATTLE UNIT POINTER # Parameters: # r4 = (unitIndex) In-battle unit index # Returns: # r2 = (unit) In-battle unit pointer of unit with specified unit index, if index is valid (0 to 20) and unit exists; null, otherwise 801810d4: 2c820015 sltiu r2,r4,0x0015 801810d8: 1040000c beq r2,r0,0x8018110c # if (unitIndex >= 21) 801810dc: 00002821 addu r5,r0,r0 # return null; 801810e0: 000410c0 sll r2,r4,0x03 # unitIndex * 8 801810e4: 00441023 subu r2,r2,r4 # unitIndex * 7 801810e8: 00021180 sll r2,r2,0x06 # unitIndex * 442 // 442 == sizeof(unit) 801810ec: 3c038019 lui r3,0x8019 801810f0: 246308cc addiu r3,r3,0x08cc # In-battle Unit array base pointer (units) 801810f4: 00432821 addu r5,r2,r3 # unit = units[unitIndex] 801810f8: 90a30001 lbu r3,0x0001(r5) # unit.UnitID 801810fc: 340200ff ori r2,r0,0x00ff 80181100: 14620002 bne r3,r2,0x8018110c # if (unit.UnitID != 0xff) // Unit doesn't exist 80181104: 00000000 nop # return unit; 80181108: 00002821 addu r5,r0,r0 8018110c: 03e00008 jr r31 # return null; 80181110: 00a01021 addu r2,r5,r0