Get Total Equipment Quantity (Equip Change/Formation Screen?)

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
0005e288 - 0005e474

Parameters : r4 = Checked Item ID
             r5 = Input Value (0x00 or 0x01) see notes
Returns : r2 = Checked Item Quantity              
----------------------------------------------------------------------------------------------
0005e288: 27bdffd0 addiu r29,r29,-0x00030   |
0005e28c: afb3001c sw r19,0x001c(r29)       |
0005e290: 00a09821 addu r19,r5,r0           |r19 = Input Value r19 = Use Unit/Party Data Check
0005e294: afb50024 sw r21,0x0024(r29)       |
0005e298: 0080a821 addu r21,r4,r0           |r21 = Item ID r21 = Item ID
0005e29c: 32a200ff andi r2,r21,0x00ff       |r2 = Item ID
0005e2a0: afb00010 sw r16,0x0010(r29)       |
0005e2a4: 00008021 addu r16,r0,r0           |r16 = 0x00 (Party Counter) Party Counter = 0
0005e2a8: afb40020 sw r20,0x0020(r29)       |
0005e2ac: 341400ff ori r20,r0,0x00ff        |r20 = 0x0ff r20 = FF
0005e2b0: afb60028 sw r22,0x0028(r29)       |
0005e2b4: 3c168019 lui r22,0x8019           |
0005e2b8: 26d608cc addiu r22,r22,0x08cc     |r22 = Start of units data pointer r22 = Unit Data Pointer
0005e2bc: afb20018 sw r18,0x0018(r29)       |
0005e2c0: 00409021 addu r18,r2,r0           |r18 = Item ID r18 = Item ID
0005e2c4: afbf002c sw r31,0x002c(r29)       |
0005e2c8: afb10014 sw r17,0x0014(r29)       |
0005e2cc: 3c018006 lui r1,0x8006            |
0005e2d0: 00220821 addu r1,r1,r2            |r1 = 0x80060000 + Item offset for quantity data
0005e2d4: 903196e0 lbu r17,-0x6920(r1)      |r17 = Item's Quantity  0x800596e0
                                            @LOOP - Loop through each party data section
0005e2d8: 0c0166bc jal 0x00059af0               |-->Get Party Data Pointer
0005e2dc: 02002021 addu r4,r16,r0               |r4 = This Iteration Party Counter
0005e2e0: 00403021 addu r6,r2,r0                |r6 = This Iteration Party Data Pointer
0005e2e4: 90c80001 lbu r8,0x0001(r6)            |r8 = This iteration Party ID
0005e2e8: 00000000 nop                          |
0005e2ec: 1114002a beq r8,r20,0x0005e398        #If This Iteration Party Unit Exists /Else branch to next Party Loop Iteration
0005e2f0: 00000000 nop                              |
0005e2f4: 90c20004 lbu r2,0x0004(r6)                |r2 = This Iteration Unit Gender 
0005e2f8: 00000000 nop                              |
0005e2fc: 30420020 andi r2,r2,0x0020                |r2 = 0x20 if Unit is a monster
0005e300: 14400025 bne r2,r0,0x0005e398             #If This Iteration Unit is not a Monster /Else branch to next Party Loop Iteration
0005e304: 00000000 nop                                  |
0005e308: 12600019 beq r19,r0,0x0005e370                #If Input value <> 0x00 #Branch if using Party Data
0005e30c: 00003821 addu r7,r0,r0                        |r7 = 0x00 (found unit flag)
0005e310: 00001821 addu r3,r0,r0                            |r3 = 0x00 (Next loop counter)
0005e314: 02c02821 addu r5,r22,r0                           |r5 = Start of units data pointer
                                                            @LOOP through all units, seeking the one matching 1st loop iteration Party ID
0005e318: 00a02021 addu r4,r5,r0                                |r4 = 2nd Loop Iteration Unit Data Pointer
0005e31c: 90820183 lbu r2,0x0183(r4)                            |r2 = Unit 0x183 (Battle status - appear ? Exist ?)
0005e320: 00000000 nop                                          |
0005e324: 1054000c beq r2,r20,0x0005e358                        #If 2nd loop iteration Unit Exists (<> 0x0ff) /Else Branch to next 2nd loop iteration
0005e328: 00000000 nop                                              |
0005e32c: 90820006 lbu r2,0x0006(r4)                                |r2 = 2nd loop iteration Unit's gender
0005e330: 00000000 nop                                              |
0005e334: 30420020 andi r2,r2,0x0020                                |r2 = 0x20 if 2nd loop iteration Unit is a monster
0005e338: 14400007 bne r2,r0,0x0005e358                             #If 2nd loop iteration Unit is not a monster /Else Branch to next 2nd loop iteration
0005e33c: 00000000 nop                                                  |
0005e340: 90820002 lbu r2,0x0002(r4)                                    |r2 = 2nd loop iteration Unit's Party ID
0005e344: 00000000 nop                                                  |
0005e348: 14480003 bne r2,r8,0x0005e358                                 #If 2nd loop iteration Unit is 1st Loop Unit /Else Branch to next 2nd loop iteration
0005e34c: 00000000 nop                                                      |
0005e350: 080178da j 0x0005e368                                             >>Jump out from the 2nd loop (unit found !)
0005e354: 34070001 ori r7,r0,0x0001                                         |r7 = 0x01 (Unit is found in battle flag)
0005e358: 24630001 addiu r3,r3,0x0001                           |r3 = 2nd loop counter + 0x01
0005e35c: 28620015 slti r2,r3,0x0015                            |r2 = 0x01 if counter < 0x15
0005e360: 1440ffed bne r2,r0,0x0005e318                     Λ Loop while counter < 0x15 (through all units)
0005e364: 24a501c0 addiu r5,r5,0x01c0                           |r5 = Unit Data Offset (+0x1c0 Each iteration)
0005e368: 14e0000b bne r7,r0,0x0005e398                     #If Unit has not been found in Battle /Else Branch if unit is found (skip the loop adding equiped Item to Item quantity)
0005e36c: 00000000 nop                                          |
0005e370: 00001821 addu r3,r0,r0                        |r3 = 0x00 (3rd loop counter)
0005e374: 00c31021 addu r2,r6,r3                        |r2 = This Iteration Party data pointer
                                                        @LOOP Through all equipment Party data 0xe to 0x14
0005e378: 9042000e lbu r2,0x000e(r2)                        |r2 = This Iteration Unit's 3rd loop iteration equipment
0005e37c: 00000000 nop                                      |
0005e380: 14520002 bne r2,r18,0x0005e38c                    #If Equipment ID = Desired Item ID
0005e384: 24630001 addiu r3,r3,0x0001                       |r3 = Third loop counter + 0x01
0005e388: 26310001 addiu r17,r17,0x0001                         |r17 = Desired Item quantity + 1
0005e38c: 28620007 slti r2,r3,0x0007                        |r2 = 0x01 if counter < 0x07
0005e390: 1440fff9 bne r2,r0,0x0005e378                 Λ Loop while counter < 0x07 (all unit's equipment slots)
0005e394: 00c31021 addu r2,r6,r3                            |r2 = Equipment slot offset (+0x01 each iteration)
0005e398: 26100001 addiu r16,r16,0x0001         |r16 = Party Counter + 0x01
0005e39c: 2a020014 slti r2,r16,0x0014           |r2 = 0x01 While counter < 0x14
0005e3a0: 1440ffcd bne r2,r0,0x0005e2d8     Λ Loop while Party Counter < 0x14
0005e3a4: 00000000 nop                          |
0005e3a8: 12600028 beq r19,r0,0x0005e44c    #If Input Value <> 0x00 /Else Branch to  END returns r2 = Item Quantity + Equiped Item Quantity
0005e3ac: 02201021 addu r2,r17,r0           |r2 = Item's Quantity + Equiped Items Quantity (whole party or Not in battle units)
0005e3b0: 00008021 addu r16,r0,r0               |r16 = 0x00 (next loop counter)
0005e3b4: 340700ff ori r7,r0,0x00ff             |r7 = 0x0ff
0005e3b8: 3406005d ori r6,r0,0x005d             |r6 = 0x5d (Mime Job ID)
0005e3bc: 32a400ff andi r4,r21,0x00ff           |r4 = Item ID
0005e3c0: 3c058019 lui r5,0x8019                |
0005e3c4: 24a508cc addiu r5,r5,0x08cc           |r5 = Start of unit data
                                                @LOOP through all in battle units
0005e3c8: 90a20183 lbu r2,0x0183(r5)                |r2 = This Iteration Unit 0x183 (Battle status - appear ? Exist ?)
0005e3cc: 00000000 nop                              |
0005e3d0: 10470019 beq r2,r7,0x0005e438             #If Unit Exists (r2 <> 0x0ff) /Else branch to next Loop Iteration
0005e3d4: 00000000 nop                                  |
0005e3d8: 90a20006 lbu r2,0x0006(r5)                    |r2 = This iteration Unit's gender
0005e3dc: 00000000 nop                                  |
0005e3e0: 30420020 andi r2,r2,0x0020                    |r2 = 0x20 if Unit is a monster
0005e3e4: 14400014 bne r2,r0,0x0005e438                 #If This iteration unit is not a monster
0005e3e8: 00000000 nop                                      |
0005e3ec: 90a201ba lbu r2,0x01ba(r5)                        |r2 = Unit's modified ENTD flags
0005e3f0: 00000000 nop                                      |
0005e3f4: 30420030 andi r2,r2,0x0030                        |r2 <> 0x00 if Unit is not in player Team
0005e3f8: 1440000f bne r2,r0,0x0005e438                     #If This Iteration Unit is in the player Team
0005e3fc: 00000000 nop                                          |
0005e400: 90a20003 lbu r2,0x0003(r5)                            |r2 = Unit's Job
0005e404: 00000000 nop                                          |
0005e408: 1046000b beq r2,r6,0x0005e438                         #If This iteration unit is not a Mime
0005e40c: 00000000 nop                                              |
0005e410: 00001821 addu r3,r0,r0                                    |r3 = 0x00 (Next loop counter)
0005e414: 00a31021 addu r2,r5,r3                                    |
                                                                    @LOOP through all unit's equipment slots
0005e418: 9042001a lbu r2,0x001a(r2)                                    |r2 = This Iteration 1st loop Unit's 2nd loop iteration equipment ID
0005e41c: 00000000 nop                                                  |
0005e420: 14440002 bne r2,r4,0x0005e42c                                 #If Equiped Item is desired Item
0005e424: 24630001 addiu r3,r3,0x0001                                   |r3 = loop 2 counter + 1
0005e428: 26310001 addiu r17,r17,0x0001                                     |r17 = Desired Item quantity +1
0005e42c: 28620007 slti r2,r3,0x0007                                    |r2 = 0x01 if counter <0x07
0005e430: 1440fff9 bne r2,r0,0x0005e418                             Λ Loop while counter < 0x07
0005e434: 00a31021 addu r2,r5,r3                                        |r2 =Equipment offset (+1 each 2nd loop iteration)
0005e438: 26100001 addiu r16,r16,0x0001             |r16 = Loop Counter + 1 (Units loop)
0005e43c: 2a020015 slti r2,r16,0x0015               |r2 = 0x01 if 1st loop counter < 0x15
0005e440: 1440ffe1 bne r2,r0,0x0005e3c8         Λ Loop while counter < 0x15
0005e444: 24a501c0 addiu r5,r5,0x01c0               |r5 = Unit pointer offset (+0x1c0 each iteration)
0005e448: 02201021 addu r2,r17,r0               Returns r2 = Desired Item Quantity (Party Inventary and equiped on units)
0005e44c: 8fbf002c lw r31,0x002c(r29)           
0005e450: 8fb60028 lw r22,0x0028(r29)           
0005e454: 8fb50024 lw r21,0x0024(r29)           
0005e458: 8fb40020 lw r20,0x0020(r29)           
0005e45c: 8fb3001c lw r19,0x001c(r29)           
0005e460: 8fb20018 lw r18,0x0018(r29)           
0005e464: 8fb10014 lw r17,0x0014(r29)           
0005e468: 8fb00010 lw r16,0x0010(r29)           
0005e46c: 27bd0030 addiu r29,r29,0x0030         
0005e470: 03e00008 jr r31                       
0005e474: 00000000 nop                          

Notes

If r5 = 0x00 : Return Item Quantity as a sum of :
 - Number of items at [0x800596e0 + Item ID]
 - Number of equiped Item by party members
 
If r5 = 0x01 The routine checks in battle members too and r2 becomes a sum of :
 - Number of items at [0x800596e0 + Item ID]
 - Number of equiped Item by party members not in battle
 - Number of equiped Item by unit in battle that are in player team
 

Return location

Battle.bin
00142288: Routine_at_141b0c 		            r5 = 0x01
0018ea3c: Item_quantity_increment_for_steal/break?  r5 = 0x01
 
World.bin
000f5b00: 000f5384_-_000f5d7c r5 = 0x01 (? seems to be the same routine than Routine_at_141b0c)
001024b8: 001022bc_-_00102924 r5 = 0x01
 
Require.out
001c7294: Handle_War_Trophies_and_Bonus_Money r5 = 0x01