Stat Increment/Decrement

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
Parameters : r4 = Stat Change (0x7f = holds value - 0x80 if it's a bonus)
             r5 = Unit Stat data pointer (details in return location)
             r6 = Stat maximum cap
             r7 = Stat minimum cap
             
Returns : r2 = 0x00 if no stat change
          r2 = 0x01 if stat changes 
------------------------------------------------------------------------------------------------------------------------
0018d570: 90a80000 lbu r8,0x0000(r5)        |r8 = Unit Stat
0018d574: 30c300ff andi r3,r6,0x00ff        |r3 = Stat Cap
0018d578: 340200ff ori r2,r0,0x00ff         |r2 = 0x0ff
0018d57c: 14620005 bne r3,r2,0x0018d594     #If Stat Cap = 0x0ff Quick effect ?
0018d580: 3089007f andi r9,r4,0x007f        |r9 = Stat change value (flag 0x80 = + or -)
0018d584: 3402007f ori r2,r0,0x007f             |r2 = 0x7f
0018d588: 15220003 bne r9,r2,0x0018d598         #If Stat Change = 0x7f (maximum change value)

0018d58c: 30820080 andi r2,r4,0x0080                |r2 = stat change bonus or malus flag
0018d590: 340900ff ori r9,r0,0x00ff                 |r9 = 0x0ff (forces CT value at 0x0ff)
0018d594: 30820080 andi r2,r4,0x0080        |r2 = stat change bonus or malus flag
0018d598: 10400003 beq r2,r0,0x0018d5a8     #If TCA add a bonus to desired stat
0018d59c: 00000000 nop                          |
0018d5a0: 0806356b j 0x0018d5ac                 >>Jump (add stat)
0018d5a4: 01094021 addu r8,r8,r9                |r8 = Unit stat + Bonus value
                                            Else (Malus)
0018d5a8: 01094023 subu r8,r8,r9                |r8 = Unit stat - Malus value
0018d5ac: 30e700ff andi r7,r7,0x00ff        |r7 = Stat minimum value
0018d5b0: 0107102a slt r2,r8,r7             |r2 = 0x01 if Unit's new stat < Minimum value
0018d5b4: 10400002 beq r2,r0,0x0018d5c0     #If Unit's new stats < Minimum value
0018d5b8: 30c600ff andi r6,r6,0x00ff        |r6 = Stat's Maximum value
0018d5bc: 00e04021 addu r8,r7,r0                |r8 = Minimum stat value
0018d5c0: 00c8102a slt r2,r6,r8             |r2 = 0x01 if Maximum value < New value
0018d5c4: 10400002 beq r2,r0,0x0018d5d0     #If Unit's New Stats value > Maximum value
0018d5c8: 00000000 nop                          |
0018d5cc: 00c04021 addu r8,r6,r0                |r8 = Maximum stat value
0018d5d0: 90a20000 lbu r2,0x0000(r5)        |r2 = Unit stat
0018d5d4: 00000000 nop                      |
0018d5d8: 15020003 bne r8,r2,0x0018d5e8     #If There's no stat modification   already at min or max value
0018d5dc: 34020001 ori r2,r0,0x0001         |r2 = 0x01
0018d5e0: 08063586 j 0x0018d618                 >>jump to end (r2 = 0x00)
0018d5e4: 00001021 addu r2,r0,r0                |r2 = 0x00
                                            Else (There is a modification)
0018d5e8: 14e2000a bne r7,r2,0x0018d614     #If Minimum stat value is 0x01 (MA - PA - Speed)
0018d5ec: a0a80000 sb r8,0x0000(r5)         |Store new Unit stat value
0018d5f0: 90a20000 lbu r2,0x0000(r5)            |r2 = New stat value
0018d5f4: 90a30003 lbu r3,0x0003(r5)            |r3 = Unit Stats from equipment
0018d5f8: 00000000 nop                          |
0018d5fc: 00434021 addu r8,r2,r3                |r8 = New Value + Bonus from equipment
0018d600: 00c8102a slt r2,r6,r8                 |r2 = 0x01 if Max stats value < Total value
0018d604: 10400002 beq r2,r0,0x0018d610         #If Total Stat value > Max Value
0018d608: 00000000 nop                              |
0018d60c: 00c04021 addu r8,r6,r0                    |r8 = Max value
0018d610: a0a80006 sb r8,0x0006(r5)             |Store New Total value (raw + equipement)
0018d614: 34020001 ori r2,r0,0x0001         |r2 = 0x01
0018d618: 03e00008 jr r31                   END
0018d61c: 00000000 nop

Return location

Battle.bin
0018c094: Attack_Finalisation_&_Reaction_Flagging r5 = 0x32 (raw speed)
0018c0bc: Attack_Finalisation_&_Reaction_Flagging r5 = 0x39 (CT)
0018c0e4: Attack_Finalisation_&_Reaction_Flagging r5 = 0x30 (raw PA)
0018c10c: Attack_Finalisation_&_Reaction_Flagging r5 = 0x31 (raw MA)
0018c140: Attack_Finalisation_&_Reaction_Flagging r5 = 0x24 (Brave)
0018c168: Attack_Finalisation_&_Reaction_Flagging r5 = 0x26 (Faith)