Load Ability From Skillset

From Final Fantasy Hacktics Wiki
Revision as of 20:16, 19 April 2023 by Orkney (talk | contribs)
Jump to navigation Jump to search
Load Ability From Skillset
---------------------------------------------------------------------------------------------- 
Parameters : r4 - Skillset ID
             r5 - Ability counter (position in the skillset)

Returns : r2 = Ability ID (halfword)
----------------------------------------------------------------------------------------------
0005a568: 288200b0 slti r2,r4,0x00b0        |Check if skillset is a monster skillset
0005a56c: 10400017 beq r2,r0,0x0005a5cc     #If Not a monster skillset
0005a570: 28a20016 slti r2,r5,0x0016            |Check if Ability counter is valid (max is 0x15 for skillset)
0005a574: 1040002d beq r2,r0,0x0005a62c         #Branch to  END if Ability counter is invalid
0005a578: 00a03021 addu r6,r5,r0                |r6 = Ability Counter
0005a57c: 3c038006 lui r3,0x8006                |
0005a580: 24634a94 addiu r3,r3,0x4a94           |1st skillset data address
0005a584: 00041040 sll r2,r4,0x01               |Skillset ID * 2
0005a588: 00441021 addu r2,r2,r4                |ID * 3
0005a58c: 000210c0 sll r2,r2,0x03               |ID * 24
0005a590: 00441021 addu r2,r2,r4                |ID * 25 (Size of each skillset data)
0005a594: 04a10002 bgez r5,0x0005a5a0           #If counter < 0  ?
0005a598: 00432021 addu r4,r2,r3                |r4 = Pointer to Skillset's data
0005a59c: 24a60007 addiu r6,r5,0x0007               |r6 = Counter + 7
0005a5a0: 000618c3 sra r3,r6,0x03               |Ability Counter / 8 0x00 or 0x01 (used to check the  [100h] flag of ability
0005a5a4: 00831021 addu r2,r4,r3                |Skillset pointer +0 or +1
0005a5a8: 000318c0 sll r3,r3,0x03               |Counter / 8 * 8 - 0x00 or 0x08  (prep bitmask for [100h] flag)
0005a5ac: 00a31823 subu r3,r5,r3                |r3 is between 0x00 and 0x07  (prep bitmask for [100h] flag)
0005a5b0: 90420000 lbu r2,0x0000(r2)            |Load Ability Flag 1 or 2  (based on counter being more than 8 or not)
0005a5b4: 24630001 addiu r3,r3,0x0001           |Bitmask for [100h] flag  between 0x1 and 0x8
0005a5b8: 00621004 sllv r2,r2,r3                |Shift ability flag so the ability [100h] becomes 0x100
0005a5bc: 00851821 addu r3,r4,r5                |Pointer to Ability ID byte in skillset data
0005a5c0: 90630003 lbu r3,0x0003(r3)            |Load Ability ID (Byte without [100h] flag
0005a5c4: 08016989 j 0x0005a624                 |
0005a5c8: 30420100 andi r2,r2,0x0100            |0x000 or 0x100 (will be added to r3 to gve the Ability ID)
                                            #Else : Monster section
0005a5cc: 288200e0 slti r2,r4,0x00e0            |Check if skillset is valid (last ID if 0xDF)
0005a5d0: 10400016 beq r2,r0,0x0005a62c         #Branch to  END if skillset ID is invalid
0005a5d4: 28a20004 slti r2,r5,0x0004            |Check if ability counter is valid (max is 0x3 for monsters)
0005a5d8: 10400014 beq r2,r0,0x0005a62c         #Branch to  END if ability counter is invalid
0005a5dc: 00a03021 addu r6,r5,r0                |r6 = Counter
0005a5e0: 3c038006 lui r3,0x8006                |
0005a5e4: 24635854 addiu r3,r3,0x5854           |Fake pointer to monster skillset (Avoid substraction of 0xB0 to set the offset)
0005a5e8: 00041080 sll r2,r4,0x02               |Skillset * 4
0005a5ec: 00441021 addu r2,r2,r4                |Skillset * 5
0005a5f0: 04a10002 bgez r5,0x0005a5fc           #If Ability counter < 0x00
0005a5f4: 00432021 addu r4,r2,r3                |Pointer to monster skillset data
0005a5f8: 24a60007 addiu r6,r5,0x0007               |Ability Counter +7
0005a5fc: 000618c3 sra r3,r6,0x03               |Always 0x00 (for monsters)
0005a600: 00831021 addu r2,r4,r3                |
0005a604: 000318c0 sll r3,r3,0x03               |0x00
0005a608: 00a31823 subu r3,r5,r3                |r3 = Ability counter
0005a60c: 90420000 lbu r2,0x0000(r2)            |Load Ability Flag 1
0005a610: 24630001 addiu r3,r3,0x0001           |Bitmask for [100h] flag  between 0x1 and 0x4
0005a614: 00621004 sllv r2,r2,r3                |Shift ability flag so the ability [100h] becomes 0x100
0005a618: 00851821 addu r3,r4,r5                |Pointer to Ability ID byte in skillset data
0005a61c: 90630001 lbu r3,0x0001(r3)            |Load Ability ID (Byte without [100h] flag
0005a620: 30420100 andi r2,r2,0x0100            |0x000 or 0x100 (will be added to r3 to gve the Ability ID)
0005a624: 0801698c j 0x0005a630             >>Avoid Ability ID nullification and returns ability ID
0005a628: 00621025 or r2,r3,r2              |returns Full Ability ID (Base ID +  0x100 flag)
---- Invalid ID/Ability counter ----   
0005a62c: 00001021 addu r2,r0,r0            |r2 = 0 (Attack)

0005a630: 03e00008 jr r31                   
0005a634: 00000000 nop 

Return location

SCUS_942.21
0005a67c:  Store Skillset's Abilities
0005cfac:  Calculate Learned Abilities
0005d268:  Calculate Unit's R/S/M

Battle.bin
001807c4:  Generate Crystal or Treasure
0018199c:  Load ability data for skillset
00182380:  Monster skill, frog attack ability loading
0018e830:  Learn on hit 1
0018e964:  Learn on hit 2