Find Unit Data Pointer For ENTD Unit ID
Jump to navigation
Jump to search
# ROUTINE: FIND UNIT DATA POINTER FOR ENTD UNIT ID # Parameters: # r4 = (param_ENTD_Unit_ID) # r5 = (&resultCode); resultCode = { # Unit index , if the unit was found without crystal or treasure status; # -3 , if the unit was found with crystal or treasure status, or the unit could not be found at all (or 0x183 flags = 0x80?) # (Possibly -2 if 0x183 flags = 0, or -6 if 0x183 flags = 0x02, but not sure those cases can be hit?) # } # Returns: # r2 = (Unit in-battle pointer) for specified unit 80180c90: 00003821 addu r7,r0,r0 # index = 0 80180c94: 340800ff ori r8,r0,0x00ff # 0xff 80180c98: 308600ff andi r6,r4,0x00ff # param_ENTD_Unit_ID 80180c9c: 2409fffd addiu r9,r0,-0x0003 # -3 80180ca0: 3c038019 lui r3,0x8019 80180ca4: 246308cc addiu r3,r3,0x08cc # unit = units[0] # do { 80180ca8: 90620001 lbu r2,0x0001(r3) # unit.UnitID 80180cac: 00000000 nop 80180cb0: 1048000e beq r2,r8,0x80180cec # if (unit.UnitID != 0xff) { 80180cb4: 00000000 nop 80180cb8: 90620161 lbu r2,0x0161(r3) # unit.ENTD_Unit_ID 80180cbc: 00000000 nop 80180cc0: 1446000a bne r2,r6,0x80180cec # if (unit.ENTD_Unit_ID == param_ENTD_Unit_ID) { 80180cc4: 00000000 nop 80180cc8: 94620058 lhu r2,0x0058(r3) # unit.CurrentStatuses1 80180ccc: 00000000 nop 80180cd0: 30420140 andi r2,r2,0x0140 # unit.CurrentStatuses1 & 0x140 // Check for Crystal or Treasure status 80180cd4: 10400003 beq r2,r0,0x80180ce4 80180cd8: 00601021 addu r2,r3,r0 # result = unit # if (unit.CurrentStatuses1 & 0x140) { 80180cdc: 0806036a j 0x80180da8 80180ce0: aca90000 sw r9,0x0000(r5) # resultCode = -3; return result; # } else { 80180ce4: 0806036a j 0x80180da8 80180ce8: aca70000 sw r7,0x0000(r5) # resultCode = index; return result; # } # } # } 80180cec: 24e70001 addiu r7,r7,0x0001 # index = index + 1 80180cf0: 28e20015 slti r2,r7,0x0015 80180cf4: 1440ffec bne r2,r0,0x80180ca8 80180cf8: 246301c0 addiu r3,r3,0x01c0 # unit = *(&unit + 1) // Unit = (Next unit in array) # } while (index < 21) 80180cfc: 00003821 addu r7,r0,r0 # index = 0 80180d00: 340c00ff ori r12,r0,0x00ff # 0xff 80180d04: 308400ff andi r4,r4,0x00ff # param_ENTD_Unit_ID 80180d08: 240bfffe addiu r11,r0,-0x0002 # -2 80180d0c: 34090080 ori r9,r0,0x0080 # 0x80 80180d10: 240afffd addiu r10,r0,-0x0003 # -3 80180d14: 34080002 ori r8,r0,0x0002 # 2 80180d18: 3c038019 lui r3,0x8019 80180d1c: 246308cc addiu r3,r3,0x08cc # unit = units[0] # do { 80180d20: 90660001 lbu r6,0x0001(r3) # unit.UnitID 80180d24: 00000000 nop 80180d28: 14cc0018 bne r6,r12,0x80180d8c # if (unit.UnitID != 0xff) { 80180d2c: 00000000 nop 80180d30: 90620161 lbu r2,0x0161(r3) # unit.ENTD_Unit_ID 80180d34: 00000000 nop 80180d38: 14440014 bne r2,r4,0x80180d8c # if (unit.ENTD_Unit_ID == param_ENTD_Unit_ID) { 80180d3c: 00000000 nop # // Is it even possible to get in here? We would have returned out of the routine in the previous loop if these conditions were true! 80180d40: 90620183 lbu r2,0x0183(r3) # unit.Flags_0x183 80180d44: 00000000 nop 80180d48: 10460010 beq r2,r6,0x80180d8c # if (unit.Flags_0x183 != unit.UnitID) { 80180d4c: 00000000 nop 80180d50: 14400004 bne r2,r0,0x80180d64 # if (unit.Flags_0x183 == 0) { 80180d54: 00000000 nop 80180d58: acab0000 sw r11,0x0000(r5) # resultCode = -2 80180d5c: 0806036a j 0x80180da8 # return unit 80180d60: 00601021 addu r2,r3,r0 # } 80180d64: 14490004 bne r2,r9,0x80180d78 # if (unit.Flags_0x183 == 0x80) { 80180d68: 00000000 nop 80180d6c: acaa0000 sw r10,0x0000(r5) # resultCode = -3 80180d70: 0806036a j 0x80180da8 # return unit 80180d74: 00601021 addu r2,r3,r0 # } 80180d78: 14480004 bne r2,r8,0x80180d8c # if (unit.Flags_0x183 == 0x02) { 80180d7c: 2402fffa addiu r2,r0,-0x0006 # -6 80180d80: aca20000 sw r2,0x0000(r5) # resultCode = -6 80180d84: 0806036a j 0x80180da8 # return unit 80180d88: 00601021 addu r2,r3,r0 # } # } # } # } 80180d8c: 24e70001 addiu r7,r7,0x0001 # index = index + 1 80180d90: 28e20015 slti r2,r7,0x0015 80180d94: 1440ffe2 bne r2,r0,0x80180d20 80180d98: 246301c0 addiu r3,r3,0x01c0 # unit = *(&unit + 1) // Unit = (Next unit in array) # } while (index < 21) 80180d9c: 2402fffd addiu r2,r0,-0x0003 # -3 80180da0: aca20000 sw r2,0x0000(r5) # resultCode = -3 80180da4: 00001021 addu r2,r0,r0 # result = 0 80180da8: 03e00008 jr r31 # return result 80180dac: 00000000 nop