Load ENTD Units
Jump to navigation
Jump to search
# ROUTINE: Load ENTD Units # Parameters: # r4 = (p_ENTDPointer) Current ENTD pointer? 8017f8a0: 27bdff80 addiu r29,r29,-0x0080 8017f8a4: 340800fe ori r8,r0,0x00fe # 0xfe 8017f8a8: afb00058 sw r16,0x0058(r29) 8017f8ac: afbf007c sw r31,0x007c(r29) 8017f8b0: afbe0078 sw r30,0x0078(r29) 8017f8b4: afb70074 sw r23,0x0074(r29) 8017f8b8: afb60070 sw r22,0x0070(r29) 8017f8bc: afb5006c sw r21,0x006c(r29) 8017f8c0: afb40068 sw r20,0x0068(r29) 8017f8c4: afb30064 sw r19,0x0064(r29) 8017f8c8: afb20060 sw r18,0x0060(r29) 8017f8cc: afb1005c sw r17,0x005c(r29) 8017f8d0: afa00040 sw r0,0x0040(r29) # stack.0x40 = 0 8017f8d4: afa00048 sw r0,0x0048(r29) # stack.0x48 = 0 8017f8d8: a3a80050 sb r8,0x0050(r29) # stack.0x50 = 0xfe 8017f8dc: 3c018019 lui r1,0x8019 8017f8e0: a0203898 sb r0,0x3898(r1) # *0x80193898 = 0 8017f8e4: 3c018019 lui r1,0x8019 8017f8e8: a4203844 sh r0,0x3844(r1) # *0x80193844 = 0 8017f8ec: 3c018019 lui r1,0x8019 8017f8f0: a0203920 sb r0,0x3920(r1) # *0x80193920 = 0 8017f8f4: 0c0172f4 jal 0x8005cbd0 # Calculate Highest Party Level (); 8017f8f8: 00808021 addu r16,r4,r0 # p1 8017f8fc: 0c04ed64 jal 0x8013b590 # var_0x39 = Get Script Variable (0x39); 8017f900: 34040039 ori r4,r0,0x0039 8017f904: afa20030 sw r2,0x0030(r29) # stack.0x30 = var_0x39 8017f908: 2842000a slti r2,r2,0x000a 8017f90c: 10400004 beq r2,r0,0x8017f920 8017f910: 34020009 ori r2,r0,0x0009 # 9 # if (var_0x39 < 10) # { 8017f914: 8fa80030 lw r8,0x0030(r29) # var_0x39 8017f918: 0805fe49 j 0x8017f924 8017f91c: 00481023 subu r2,r2,r8 # newValue = 9 - var_0x39 # } else { 8017f920: 00001021 addu r2,r0,r0 # newValue = 0 # } 8017f924: afa20030 sw r2,0x0030(r29) # stack.0x30 = newValue 8017f928: 24480007 addiu r8,r2,0x0007 # stack.0x30 + 7 8017f92c: 0000b021 addu r22,r0,r0 # v22 = 0 8017f930: 340400ff ori r4,r0,0x00ff 8017f934: 00002821 addu r5,r0,r0 8017f938: 00003021 addu r6,r0,r0 8017f93c: 0c05fefb jal 0x8017fbec # Add Unique Value to List (0xff, 0, 0); 8017f940: afa80038 sw r8,0x0038(r29) # stack.0x38 = stack.0x30 + 7 8017f944: 00009021 addu r18,r0,r0 # unitIndex = 0 8017f948: 0200b821 addu r23,r16,r0 # loopENTDPointer = p_ENTDPointer 8017f94c: 0000f021 addu r30,r0,r0 # unitPtrOffset = 0 # do { 8017f950: 3c028019 lui r2,0x8019 8017f954: 244208cc addiu r2,r2,0x08cc 8017f958: 03c28021 addu r16,r30,r2 # unit = battleUnits[unitIndex] 8017f95c: a212018a sb r18,0x018a(r16) # unit.ENTDUnitID = unitIndex 8017f960: 3c018006 lui r1,0x8006 8017f964: ac376238 sw r23,0x6238(r1) # currentENTDPointer = loopENTDPointer; 8017f968: 92e20000 lbu r2,0x0000(r23) # ENTDunit.BaseClass 8017f96c: 00000000 nop 8017f970: 14400005 bne r2,r0,0x8017f988 8017f974: 02002021 addu r4,r16,r0 # unit # if (ENTDunit.BaseClass == 0) { 8017f978: 340800ff ori r8,r0,0x00ff 8017f97c: a2080001 sb r8,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017f980: 0805fee9 j 0x8017fba4 # continue; 8017f984: a2080183 sb r8,0x0183(r16) # unit.0x183 = 0xff; // Unit doesn't exist # } 8017f988: 00003021 addu r6,r0,r0 8017f98c: 34020001 ori r2,r0,0x0001 8017f990: a2120001 sb r18,0x0001(r16) # unit.UnitIndex = unitIndex; 8017f994: a2020183 sb r2,0x0183(r16) # unit.0x183 = 1 8017f998: 3c058006 lui r5,0x8006 8017f99c: 8ca56238 lw r5,0x6238(r5) # currentENTDPointer 8017f9a0: 0c016a6d jal 0x8005a9b4 # initResult = Unit Battle Initialization (unit, currentENTDPointer, 0, 0); 8017f9a4: 00003821 addu r7,r0,r0 8017f9a8: 10400004 beq r2,r0,0x8017f9bc 8017f9ac: 02002021 addu r4,r16,r0 # if (initResult != 0) { // Init failed 8017f9b0: 0c017a3a jal 0x8005e8e8 8017f9b4: 26440258 addiu r4,r18,0x0258 # Empty Routine (0x5e8e8) (unitIndex + 0x258); // Routine has no effect 8017f9b8: 02002021 addu r4,r16,r0 # } 8017f9bc: 0c017822 jal 0x8005e088 # portrait = Calculate Unit's Palette/Portrait (return Portrait) (unit, stack.0x28); 8017f9c0: 27a50028 addiu r5,r29,0x0028 8017f9c4: 02002021 addu r4,r16,r0 8017f9c8: 00002821 addu r5,r0,r0 8017f9cc: 0c0177f5 jal 0x8005dfd4 # Minimum SP Capping/War Trophy Nulling/Status Initialization (unit, 0); 8017f9d0: 0040a821 addu r21,r2,r0 # portrait 8017f9d4: 3c028006 lui r2,0x8006 8017f9d8: 8c426238 lw r2,0x6238(r2) # currentENTDPointer 8017f9dc: 00000000 nop 8017f9e0: 90530020 lbu r19,0x0020(r2) # entdUnitID = currentENTDPointer.ENTDUnitID 8017f9e4: 340800ff ori r8,r0,0x00ff 8017f9e8: 16680007 bne r19,r8,0x8017fa08 # if (currentENTDPointer.ENTDUnitID == 0xff) { 8017f9ec: 00000000 nop 8017f9f0: 93a20050 lbu r2,0x0050(r29) # stack.0x50 8017f9f4: 00000000 nop 8017f9f8: 00404021 addu r8,r2,r0 # stack.0x50 8017f9fc: 2508ffff addiu r8,r8,-0x0001 # stack.0x50 - 1 8017fa00: 305300ff andi r19,r2,0x00ff # entdUnitID = stack.0x50 8017fa04: a3a80050 sb r8,0x0050(r29) # stack.0x50 = stack.0x50 - 1 # } 8017fa08: 92020005 lbu r2,0x0005(r16) # unit.ENTDFlags 8017fa0c: 00000000 nop 8017fa10: 305400c0 andi r20,r2,0x00c0 # presentFlags = unit.ENTDFlags & ((ENTD_FLAG_ALWAYS_PRESENT) | (ENTD_FLAG_RANDOMLY_PRESENT)) 8017fa14: 328300ff andi r3,r20,0x00ff 8017fa18: 10600009 beq r3,r0,0x8017fa40 8017fa1c: a2130161 sb r19,0x0161(r16) # unit.ENTD_ID = entdUnitID # if ((presentFlags == 0) 8017fa20: 34020040 ori r2,r0,0x0040 8017fa24: 1462000f bne r3,r2,0x8017fa64 # || ((presentFlags == ENTD_FLAG_RANDOMLY_PRESENT) 8017fa28: 00000000 nop 8017fa2c: 0c0088c3 jal 0x8002230c 8017fa30: 00000000 nop 8017fa34: 30420001 andi r2,r2,0x0001 8017fa38: 1040000a beq r2,r0,0x8017fa64 # && ((rand() % 2) != 0)) // 50% random chance 8017fa3c: 00000000 nop # ) { 8017fa40: 340200ff ori r2,r0,0x00ff 8017fa44: a2020001 sb r2,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017fa48: a2000183 sb r0,0x0183(r16) # unit.0x183 = 0; 8017fa4c: 3c058006 lui r5,0x8006 8017fa50: 8ca56238 lw r5,0x6238(r5) 8017fa54: 0c01791e jal 0x8005e478 # Initialize Unit's X/Y+Facing/Battle Rewards (unit, currentENTDPointer); 8017fa58: 02002021 addu r4,r16,r0 8017fa5c: 0805feea j 0x8017fba8 # continue; 8017fa60: 26f70028 addiu r23,r23,0x0028 # } 8017fa64: 3c058006 lui r5,0x8006 8017fa68: 8ca56238 lw r5,0x6238(r5) # currentENTDPointer 8017fa6c: 0c01791e jal 0x8005e478 # Initialize Unit's X/Y+Facing/Battle Rewards (unit, currentENTDPointer); 8017fa70: 02002021 addu r4,r16,r0 8017fa74: 0c05fdb1 jal 0x8017f6c4 # validateResult = Validate unit placement (unitIndex); 8017fa78: 02402021 addu r4,r18,r0 8017fa7c: 10400007 beq r2,r0,0x8017fa9c # if (validateResult != 0) { // Failed validation 8017fa80: 340800ff ori r8,r0,0x00ff 8017fa84: 0c017a3a jal 0x8005e8e8 # Empty Routine (0x5e8e8) (unitIndex + 0x12c); // Routine has no effect 8017fa88: 2644012c addiu r4,r18,0x012c 8017fa8c: 340200ff ori r2,r0,0x00ff 8017fa90: a2020001 sb r2,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017fa94: 0805fee9 j 0x8017fba4 8017fa98: a2020183 sb r2,0x0183(r16) # unit.0x183 = 0xff; // Unit doesn't exist # } 8017fa9c: 92020001 lbu r2,0x0001(r16) # unit.UnitIndex 8017faa0: 00000000 nop 8017faa4: 1048003f beq r2,r8,0x8017fba4 # if (unit.UnitIndex == 0xff) continue; 8017faa8: 02402021 addu r4,r18,r0 8017faac: 8fa60030 lw r6,0x0030(r29) 8017fab0: 0c05fefb jal 0x8017fbec # result = Add Unique Value to List (unitIndex, portrait, stack.0x30); 8017fab4: 32a500ff andi r5,r21,0x00ff 8017fab8: 1040000c beq r2,r0,0x8017faec # if (result != 0) { 8017fabc: 340200ff ori r2,r0,0x00ff 8017fac0: a2020001 sb r2,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017fac4: a2000183 sb r0,0x0183(r16) # unit.0x183 = 0; 8017fac8: 8fa80040 lw r8,0x0040(r29) # stack.0x40 8017facc: 00000000 nop 8017fad0: 15000034 bne r8,r0,0x8017fba4 # if (stack.0x40 != 0) continue; 8017fad4: 00000000 nop 8017fad8: 0c017a3a jal 0x8005e8e8 # Empty Routine (0x5e8e8) (unitIndex + 0x64); // Routine has no effect 8017fadc: 26440064 addiu r4,r18,0x0064 8017fae0: 34080001 ori r8,r0,0x0001 8017fae4: 0805fee9 j 0x8017fba4 8017fae8: afa80040 sw r8,0x0040(r29) # stack.0x40 = 1 # continue; # } 8017faec: 328300ff andi r3,r20,0x00ff # presentFlags 8017faf0: 340200c0 ori r2,r0,0x00c0 # bothPresentFlags = (ENTD_FLAG_ALWAYS_PRESENT) | (ENTD_FLAG_RANDOMLY_PRESENT) 8017faf4: 10620012 beq r3,r2,0x8017fb40 8017faf8: 34110001 ori r17,r0,0x0001 # v17 = 1 # skipNextSection = false # if ((presentFlags == bothPresentFlags) { // Both always and randomly present! 8017fafc: 8fa80038 lw r8,0x0038(r29) # stack.0x38 8017fb00: 00000000 nop 8017fb04: 02c8102a slt r2,r22,r8 8017fb08: 14400011 bne r2,r0,0x8017fb50 8017fb0c: 00008821 addu r17,r0,r0 # v17 = 0 # skipNextSection = true # if (v22 >= stack.0x38) { 8017fb10: 340200ff ori r2,r0,0x00ff 8017fb14: a2020001 sb r2,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017fb18: a2020183 sb r2,0x0183(r16) # unit.0x183 = 0xff; // Unit doesn't exist 8017fb1c: 8fa80048 lw r8,0x0048(r29) # stack.0x48 8017fb20: 00000000 nop 8017fb24: 1500001f bne r8,r0,0x8017fba4 # if (stack.0x48 != 0) continue; 8017fb28: 00000000 nop 8017fb2c: 0c017a3a jal 0x8005e8e8 # Empty Routine (0x5e8e8) (unitIndex + 0xc8); // Routine has no effect 8017fb30: 264400c8 addiu r4,r18,0x00c8 8017fb34: 34080001 ori r8,r0,0x0001 8017fb38: 0805fee8 j 0x8017fba0 8017fb3c: afa80048 sw r8,0x0048(r29) # stack.0x48 = 1 # v22 = v22 + 1; continue; # } # } # if (!skipNextSection) { 8017fb40: 340200ff ori r2,r0,0x00ff 8017fb44: a2020001 sb r2,0x0001(r16) # unit.UnitIndex = 0xff; // Unit doesn't exist 8017fb48: 0805fed6 j 0x8017fb58 8017fb4c: a2000183 sb r0,0x0183(r16) # unit.0x183 = 0xff; // Unit doesn't exist # } else { 8017fb50: 0c06036c jal 0x80180db0 # Set Enemy Level Data (unit); 8017fb54: 02002021 addu r4,r16,r0 # } 8017fb58: 92040047 lbu r4,0x0047(r16) # unit.X 8017fb5c: 92050048 lbu r5,0x0048(r16) # unit.Y 8017fb60: 96070048 lhu r7,0x0048(r16) 8017fb64: 32a200ff andi r2,r21,0x00ff # portrait 8017fb68: afa20010 sw r2,0x0010(r29) # portrait 8017fb6c: 93a20028 lbu r2,0x0028(r29) # stack.0x28 8017fb70: afb30018 sw r19,0x0018(r29) # entdUnitID 8017fb74: afb0001c sw r16,0x001c(r29) # unit 8017fb78: afb10020 sw r17,0x0020(r29) # v17 8017fb7c: 000733c2 srl r6,r7,0x0f # unit.0x49 >> 3 8017fb80: 00073a02 srl r7,r7,0x08 # unit.0x49 8017fb84: 30e7000f andi r7,r7,0x000f 8017fb88: 0c023950 jal 0x8008e540 # 0x8e540 (unit.X, unit.Y, (unit.0x49 >> 3), unit.0x49, portrait, stack.0x28, entdUnitID, unit, v17); 8017fb8c: afa20014 sw r2,0x0014(r29) 8017fb90: 328300ff andi r3,r20,0x00ff # presentFlags 8017fb94: 340200c0 ori r2,r0,0x00c0 # bothPresentFlags 8017fb98: 10620002 beq r3,r2,0x8017fba4 # if (presentFlags != bothPresentFlags) { 8017fb9c: 00000000 nop 8017fba0: 26d60001 addiu r22,r22,0x0001 # v22 = v22 + 1 # } 8017fba4: 26f70028 addiu r23,r23,0x0028 # loopENTDPointer = loopENTDPointer + 0x28 8017fba8: 26520001 addiu r18,r18,0x0001 # unitIndex = unitIndex + 1 8017fbac: 2a420010 slti r2,r18,0x0010 8017fbb0: 1440ff67 bne r2,r0,0x8017f950 8017fbb4: 27de01c0 addiu r30,r30,0x01c0 # unitPtrOffset += sizeof(BattleUnit) // 0x1c0 # } while (unitIndex < 16); 8017fbb8: 8fbf007c lw r31,0x007c(r29) 8017fbbc: 8fbe0078 lw r30,0x0078(r29) 8017fbc0: 8fb70074 lw r23,0x0074(r29) 8017fbc4: 8fb60070 lw r22,0x0070(r29) 8017fbc8: 8fb5006c lw r21,0x006c(r29) 8017fbcc: 8fb40068 lw r20,0x0068(r29) 8017fbd0: 8fb30064 lw r19,0x0064(r29) 8017fbd4: 8fb20060 lw r18,0x0060(r29) 8017fbd8: 8fb1005c lw r17,0x005c(r29) 8017fbdc: 8fb00058 lw r16,0x0058(r29) 8017fbe0: 27bd0080 addiu r29,r29,0x0080 8017fbe4: 03e00008 jr r31 8017fbe8: 00000000 nop