Level Up Section

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
Level Up Section
Parameters : r4 = Unit data pointer
             r5 = 0x01 if unit is leveling down, 0x00 if leveling Up
Returns nothing
------------------------------------------------------------------------------------------------------------
0005da10: 27bdffc8 addiu r29,r29,-0x0038    |
0005da14: afb3001c sw r19,0x001c(r29)       |
0005da18: 00809821 addu r19,r4,r0           |r19 = Unit's Data Pointer
0005da1c: afb60028 sw r22,0x0028(r29)       |
0005da20: 00a0b021 addu r22,r5,r0           |r22 = Level UP/Down Flag
0005da24: afb50024 sw r21,0x0024(r29)       |
0005da28: 26750072 addiu r21,r19,0x0072     |r21 = Unit's Raw Stat Pointer
0005da2c: afb20018 sw r18,0x0018(r29)       |
0005da30: 02a09021 addu r18,r21,r0          |r18 = Unit's Raw Stat Pointer (increased while looping)
0005da34: afb40020 sw r20,0x0020(r29)       |
0005da38: 26740081 addiu r20,r19,0x0081     |r20 = Unit's Stat Growth Pointer (increased while looping)
0005da3c: afbf0030 sw r31,0x0030(r29)       |
0005da40: afb7002c sw r23,0x002c(r29)       |
0005da44: afb10014 sw r17,0x0014(r29)       |
0005da48: afb00010 sw r16,0x0010(r29)       |
0005da4c: 92770022 lbu r23,0x0022(r19)      |r23 =  Unit's Level
0005da50: 92440001 lbu r4,0x0001(r18)       @LOOP Load Second byte of Raw Stat (Raw Stat 2 ->  0xBB)
0005da54: 92910000 lbu r17,0x0000(r20)          |r17 = Stat Growth
0005da58: 92430000 lbu r3,0x0000(r18)           |Load first byte of Raw Stat (Raw Stat 1 -> 0xAA)
0005da5c: 92420002 lbu r2,0x0002(r18)           |Load third byte of Raw Stat (Raw Stat 3 -> 0xCC)
0005da60: 00042200 sll r4,r4,0x08               |r4 = 0xBB00
0005da64: 00641821 addu r3,r3,r4                |r3 = 0xBBAA
0005da68: 00021400 sll r2,r2,0x10               |r2 = 0xCC0000
0005da6c: 00628021 addu r16,r3,r2               |r16 = 0xCCBBAA (full raw stat)
0005da70: 16200002 bne r17,r0,0x0005da7c        #If Unit Stat growth = 0
0005da74: 02201021 addu r2,r17,r0               |r2 = Stat Growth
0005da78: 34020001 ori r2,r0,0x0001                 |r2 = 1 (Min 1 growth)
0005da7c: 0c0088c3 jal 0x0002230c               |-->Random Number Generator Return r2 between 0 and 0x7fff
0005da80: 00578821 addu r17,r2,r23              |r17 = Stat Growth + Level
0005da84: 12c00005 beq r22,r0,0x0005da9c        #If Unit is Leveling Down
0005da88: 00000000 nop                              |
0005da8c: 0211001b divu r16,r17                     |
0005da90: 00001012 mflo r2                          |Raw Stat modification = Raw Stat / (Stat Growth + Level)
0005da94: 080176ab j 0x0005daac                     >>Jump after lv up section
0005da98: 02028023 subu r16,r16,r2                  |r16 = Raw Stat -  Raw Stat modification
0005da9c: 0211001b divu r16,r17                 #Else : Unit is leveling Up
0005daa0: 00001012 mflo r2                          |Raw Stat modification = Raw Stat / (Stat Growth + Level)
0005daa4: 00000000 nop                              |
0005daa8: 02028021 addu r16,r16,r2                  |r16 = Raw Stat +  Raw Stat modification
0005daac: 3c0200ff lui r2,0x00ff                |
0005dab0: 3442ffff ori r2,r2,0xffff             |r2 = 0x00ffffff (maximum possible raw stat)
0005dab4: 0050102b sltu r2,r2,r16               |r2 = 0x01 if New raw stat > 0x00ffffff
0005dab8: 10400003 beq r2,r0,0x0005dac8         #If new Raw Stat is to high
0005dabc: 26940002 addiu r20,r20,0x0002         |Unit next growth pointer
0005dac0: 3c1000ff lui r16,0x00ff                   |
0005dac4: 3610ffff ori r16,r16,0xffff               |r16 = 0x00ffffff
0005dac8: 00101202 srl r2,r16,0x08              |r2 = middle byte (0xBB)
0005dacc: a2420001 sb r2,0x0001(r18)            |Store Raw Stat 2
0005dad0: 00101402 srl r2,r16,0x10              |r2 = Left Byte (0xCC)
0005dad4: a2500000 sb r16,0x0000(r18)           |Store Raw Stat 1
0005dad8: a2420002 sb r2,0x0002(r18)            |Store Raw Stat 3
0005dadc: 26520003 addiu r18,r18,0x0003         |Unit's Next Raw Stat Pointer
0005dae0: 26a2000f addiu r2,r21,0x000f          |r2 = Unit HP growth pointer (used as unit raw stat limit)
0005dae4: 0242102a slt r2,r18,r2                |r2 = 0x01 while limit is not reached
0005dae8: 1440ffd9 bne r2,r0,0x0005da50     Λ Loop while current pointer < Max
0005daec: 00000000 nop                          |
0005daf0: 0c017578 jal 0x0005d5e0           |-->Status_Setting/Checking_%2B_Equip/R/S/M_Stats_Prep_2
0005daf4: 02602021 addu r4,r19,r0           |r4 = Unit's Data Pointer
0005daf8: 96630028 lhu r3,0x0028(r19)       |Load Unit's HP
0005dafc: 9662002a lhu r2,0x002a(r19)       |Load Unit's Max HP
0005db00: 00000000 nop                      |
0005db04: 0043102b sltu r2,r2,r3            |r2 = 0x01 if Max HP < Current HP
0005db08: 10400004 beq r2,r0,0x0005db1c     #If Unit Current HP > Unit Max HP
0005db0c: 00000000 nop                          |
0005db10: 9662002a lhu r2,0x002a(r19)           |Load Unit's Max HP
0005db14: 00000000 nop                          |
0005db18: a6620028 sh r2,0x0028(r19)            |Store Current HP = Max HP
0005db1c: 9663002c lhu r3,0x002c(r19)       |Load Unit's MP
0005db20: 9662002e lhu r2,0x002e(r19)       |Load Unit's Max MP
0005db24: 00000000 nop                      |
0005db28: 0043102b sltu r2,r2,r3            |r2 = 0x01 if Max MP < Current MP
0005db2c: 10400004 beq r2,r0,0x0005db40     #If Unit Current MP > Unit Max MP
0005db30: 00000000 nop                          |
0005db34: 9662002e lhu r2,0x002e(r19)           |Load Unit's Max MP
0005db38: 00000000 nop                          |
0005db3c: a662002c sh r2,0x002c(r19)            |Store Current MP = Max MP
0005db40: 8fbf0030 lw r31,0x0030(r29)       END
0005db44: 8fb7002c lw r23,0x002c(r29)
0005db48: 8fb60028 lw r22,0x0028(r29)
0005db4c: 8fb50024 lw r21,0x0024(r29)
0005db50: 8fb40020 lw r20,0x0020(r29)
0005db54: 8fb3001c lw r19,0x001c(r29)
0005db58: 8fb20018 lw r18,0x0018(r29)
0005db5c: 8fb10014 lw r17,0x0014(r29)
0005db60: 8fb00010 lw r16,0x0010(r29)
0005db64: 27bd0038 addiu r29,r29,0x0038
0005db68: 03e00008 jr r31
0005db6c: 00000000 nop

Return locations

Battle.bin
0018c90c: Level_up/down_ability

SCUS
0005d8c4: Check_if_Unit_Leveled_UP

DEBUGCHR.OUT
001c4bcc: DEBUGCHR.OUT/001c438c_-_001c5240