Load ability data for skillset

From Final Fantasy Hacktics Wiki
Revision as of 12:18, 1 August 2023 by Orkney (talk | contribs) (return location)
Jump to navigation Jump to search
Load ability data for skillset (MP, CT, Turns, req. sword booleans)
0x001817C0: addiu r29, r29, 0xFED0	 -130
0x001817C4: sw r4, 0x00B0(r29)
0x001817C8: lw r4, 0x00B0(r29)          unit data?
0x001817CC: sw r20, 0x0118(r29)
0x001817D0: lw r20, 0x0140(r29)         0x10 stack address (Raw ability CT)
0x001817D4: sw r18, 0x0110(r29)
0x001817D8: lw r18, 0x0148(r29)         0x18 stack address (Silence/reflect/performance checks
0x001817DC: sw r17, 0x010C(r29)
0x001817E0: lw r17, 0x014C(r29)         0x1c stack address (#turns to complete)
0x001817E4: sw r30, 0x0128(r29)
0x001817E8: addu r30, r0, r0		No. Abilities default to 0
0x001817EC: sw r31, 0x012C(r29)
0x001817F0: sw r23, 0x0124(r29)
0x001817F4: sw r22, 0x0120(r29)
0x001817F8: sw r21, 0x011C(r29)
0x001817FC: sw r19, 0x0114(r29)
0x00181800: sw r16, 0x0108(r29)
0x00181804: sw r6, 0x00C0(r29)          Ability ID pointer
0x00181808: sw r0, 0x00E0(r29)		Initialise Materia Blade flag
0x0018180C: sw r0, 0x00E8(r29)		Initialise Sword Flag
0x00181810: sw r0, 0x00F0(r29)		Initialise short/non-charge flags
0x00181814: sw r0, 0x00F8(r29)		Initialise Half MP flag
0x00181818: sw r0, 0x0100(r29)		Initialise frog flag
0x0018181C: sw r7, 0x00C8(r29)          MP Cost pointer
0x00181820: jal 0x001810D4              Get unit data pointer? (r2)
0x00181824: sb r5, 0x00B8(r29)          store primary skillset
0x00181828: addu r16, r2, r0
0x0018182C: beq r16, r0, 0x00181B3C
0x00181830: addu r2, r0, r0
0x00181834: lbu r2, 0x005A(r16)         load statuses
0x00181838: nop
0x0018183C: andi r2, r2, 0x0002
0x00181840: beq r2, r0, 0x00181850      branch if not frog
0x00181844: nop
0x00181848: ori r9, r0, 0x0001
0x0018184C: sw r9, 0x0100(r29)          frog flag
0x00181850: lbu r2, 0x0090(r16)         load support 2
0x00181854: nop
0x00181858: andi r2, r2, 0x0080
0x0018185C: beq r2, r0, 0x0018186C      branch if not half of MP
0x00181860: nop
0x00181864: ori r8, r0, 0x0001
0x00181868: sw r8, 0x00F8(r29)          half mp flag
0x0018186C: lbu r3, 0x0092(r16)         load support 4
0x00181870: nop
0x00181874: andi r2, r3, 0x0004
0x00181878: beq r2, r0, 0x00181888      branch if not non-charge
0x0018187C: ori r9, r0, 0x0002
0x00181880: j 0x00181898		
0x00181884: sw r9, 0x00F0(r29)          non charge flag (0x2)
0x00181888: andi r2, r3, 0x0008
0x0018188C: beq r2, r0, 0x00181898      branch if not short charge
0x00181890: ori r8, r0, 0x0001
0x00181894: sw r8, 0x00F0(r29)          short charge flag (0x1)
0x00181898: addiu r4, r29, 0x0010	parse stack + 0x10 for? (does this point to AT list or smth?)
0x0018189C: jal 0x0018370C              Calculate AT List
0x001818A0: addu r5, r0, r0		r5 = 0
0x001818A4: lbu r3, 0x0184(r16)         load equipped flags
0x001818A8: nop
0x001818AC: andi r2, r3, 0x0004
0x001818B0: beq r2, r0, 0x001818C0      branch if materia blade not equipped
0x001818B4: andi r2, r3, 0x0008
0x001818B8: ori r9, r0, 0x0001
0x001818BC: sw r9, 0x00E0(r29)          materia blade flag
0x001818C0: beq r2, r0, 0x001818D0      branch if sword not equipped
0x001818C4: nop
0x001818C8: ori r8, r0, 0x0001
0x001818CC: sw r8, 0x00E8(r29)          sword flag
0x001818D0: lbu r2, 0x0006(r16)         load gender
0x001818D4: nop
0x001818D8: andi r2, r2, 0x0020
0x001818DC: bne r2, r0, 0x00181938      branch if not human

Human Gender:
0x001818E0: nop
0x001818E4: lbu r9, 0x00B8(r29)         load primary skillset
0x001818E8: nop
0x001818EC: addiu r2, r9, 0xFFFB        primary skillset - 5
0x001818F0: andi r2, r2, 0x00FF
0x001818F4: sltiu r2, r2, 0x0013
0x001818F8: beq r2, r0, 0x0018190C      branch if not a generic skillset
0x001818FC: nop
0x00181900: lbu r2, 0x00B8(r29)         load primary skillset
0x00181904: j 0x0018193C		Assume all abilities learnt if generic skillset
0x00181908: addiu r5, r2, 0xFFFB	skillset - 5
0x0018190C: lbu r2, 0x0012(r16)         load unit's primary skillset
0x00181910: lbu r3, 0x00B8(r29)	Load stored primary skillset
0x00181914: nop
0x00181918: beq r3, r2, 0x00181930      branch if loaded skillset = units primary skillset
0x0018191C: addu r5, r0, r0		skillset = 0
0x00181920: lbu r2, 0x0162(r16)         load unit's special skillset
0x00181924: nop
0x00181928: bne r3, r2, 0x00181938      branch if stored skillset <> unit's special skillset
0x0018192C: nop
0x00181930: j 0x00181940
0x00181934: addiu r2, r0, 0xFFFF

Monster Gender:
0x00181938: addiu r5, r0, 0xFFFF
0x0018193C: addiu r2, r0, 0xFFFF
0x00181940: bne r5, r2, 0x00181954      branch if skillset is not skillset 4 if loaded skillset is < 0x13. branch if unit's special skillset <> 0 if special skillset that is not primary skillset.
0x00181944: lui r8, 0x00FF
store known abilities = all
0x00181948: ori r8, r8, 0xFFFF		if skillset is 4, or if secondary skillset is special that is not unit's special skillset, or if monster skillset:
0x0018194C: j 0x00181960
0x00181950: sw r8, 0x00D0(r29)          store known abilities = all

0x00181954: jal 0x0005E200              Get Known Abilities if generic skillset, or unique skillset equal to unit's unique skillset
0x00181958: addu r4, r16, r0
0x0018195C: sw r2, 0x00D0(r29)          store known abilities
0x00181960: addu r19, r0, r0
0x00181964: addu r23, r30, r17          #turns to complete for ability
0x00181968: addu r22, r30, r18          Silence/reflect/Performance check for ability
0x0018196C: lw r9, 0x00C8(r29)          Ability List
0x00181970: addu r21, r30, r20          Raw Ability CT
0x00181974: addu r20, r30, r9                    Ability list + Counter
0x00181978: lui r2, 0x0080
0x0018197C: lw r8, 0x00D0(r29)          load known abilities
0x00181980: srav r2, r2, r19		0x00800000 bitmask >> r19 counter
0x00181984: and r2, r8, r2              known abilities  AND bitmask flag
0x00181988: beq r2, r0, 0x00181B1C	branch if this ability is not known
0x0018198C: nop
0x00181990: lbu r4, 0x00B8(r29)         load skillset
0x00181994: jal 0x0005A568              Load Ability From Skillset
0x00181998: addu r5, r19, r0		r5 = ability
0x0018199C: lw r9, 0x0100(r29)          load frog flag
0x001819A0: addu r4, r2, r0
0x001819A4: beq r9, r0, 0x001819C0      branch if frog status not present
0x001819A8: sh r4, 0x00D8(r29)          store ability (temp)

if frog

0x001819AC: sll r2, r4, 0x10
0x001819B0: sra r2, r2, 0x10
0x001819B4: ori r3, r0, 0x001D
0x001819B8: bne r2, r3, 0x00181B1C      branch if ability is not frog spell (don't save ability data if ability is not frog while frogged)
0x001819BC: nop

if frog not present OR if frog + spell = 0x1d(frog)

0x001819C0: sll r2, r4, 0x10
0x001819C4: sra r3, r2, 0x10
0x001819C8: beq r3, r0, 0x00181B1C      branch if ability = 0
0x001819CC: addiu r2, r4, 0xFFFF
0x001819D0: andi r2, r2, 0xFFFF
0x001819D4: sltiu r2, r2, 0x016F
0x001819D8: beq r2, r0, 0x00181AB4      branch if ability is not a regular ability

regular ability

0x001819DC: sll r2, r3, 0x03		
0x001819E0: subu r2, r2, r3
0x001819E4: sll r2, r2, 0x01		ability ID * 14
0x001819E8: lui r3, 0x8006
0x001819EC: addiu r3, r3, 0xFBF0        load ability data pointer 2
0x001819F0: addu r4, r2, r3
0x001819F4: lbu r3, 0x0006(r4)		ability flags 4
0x001819F8: nop
0x001819FC: andi r2, r3, 0x0008
0x00181A00: beq r2, r0, 0x00181A18      if ability requires sword: (else, materia blade check)
0x00181A04: nop
0x00181A08: lw r8, 0x00E8(r29)		load sword check from stack
0x00181A0C: nop
0x00181A10: beq r8, r0, 0x00181B1C		if sword check is false, don't check for more requirements
0x00181A14: nop
0x00181A18: andi r2, r3, 0x0004	
0x00181A1C: beq r2, r0, 0x00181A34      if ability requires materia blade: (else, Half of MP check)
0x00181A20: nop
0x00181A24: lw r9, 0x00E0(r29)		load materia blade check from stack
0x00181A28: nop
0x00181A2C: beq r9, r0, 0x00181B1C		if materia blade check is false, don't check for more requirements
0x00181A30: nop
0x00181A34: lw r8, 0x00F8(r29)          load half of mp check
0x00181A38: lbu r17, 0x000D(r4)         load MP cost
0x00181A3C: beq r8, r0, 0x00181A48		branch if half mp check is false
0x00181A40: addiu r2, r17, 0x0001
0x00181A44: sra r17, r2, 0x01           MP cost / 2 (rounded up)
0x00181A48: lbu r2, 0x000C(r4)          load CT
0x00181A4C: lbu r3, 0x0005(r4)          load flags 3
0x00181A50: andi r16, r2, 0x007F        r16 = CT
0x00181A54: srl r4, r3, 0x07
0x00181A58: andi r2, r3, 0x0020         affected by silence
0x00181A5C: srl r2, r2, 0x04
0x00181A60: andi r3, r3, 0x0004         performance
0x00181A64: bne r3, r0, 0x00181A94      branch if performance is true
0x00181A68: or r18, r4, r2              r18 = silence and performance checks
0x00181A6C: lw r9, 0x00F0(r29)		short charge check
0x00181A70: ori r2, r0, 0x0001
0x00181A74: bne r9, r2, 0x00181A80      branch if not short charge
0x00181A78: addiu r2, r16, 0x0001
0x00181A7C: sra r16, r2, 0x01           CT / 2 (rounded up)
0x00181A80: lw r8, 0x00F0(r29)		
0x00181A84: ori r2, r0, 0x0002
0x00181A88: bne r8, r2, 0x00181A98      branch if not non-charge
0x00181A8C: addu r5, r16, r0            store final CT
0x00181A90: addu r16, r0, r0
0x00181A94: addu r5, r16, r0            store 0 CT if non charge
0x00181A98: lw r4, 0x00B0(r29)          load Unit ID
0x00181A9C: jal 0x00181720              Ability Loading?
0x00181AA0: addiu r6, r29, 0x0010	AT list?
0x00181AA4: sb r17, 0x0000(r20)         store MP cost 
0x00181AA8: sb r16, 0x0000(r21)         store Raw Ability CT to stack
0x00181AAC: j 0x00181AF0
0x00181AB0: sb r18, 0x0000(r22)         store silence/persevere checks to stack
0x00181AB4: addiu r2, r4, 0xFE6A
0x00181AB8: andi r2, r2, 0xFFFF
0x00181ABC: sltiu r2, r2, 0x0008
0x00181AC0: beq r2, r0, 0x00181AF4      branch if not charge ability
0x00181AC4: sll r2, r3, 0x01

if charge:
0x00181AC8: addiu r6, r29, 0x0010		AT list?
0x00181ACC: lui r1, 0x8006
0x00181AD0: addu r1, r1, r2		Ability ID * 2 + data table area.
0x00181AD4: lbu r16, 0x0D18(r1)         load charge CT
0x00181AD8: lw r4, 0x00B0(r29)          unit id
0x00181ADC: jal 0x00181720              Ability Loading?
0x00181AE0: addu r5, r16, r0		Parse Charge CT
0x00181AE4: sb r0, 0x0000(r20)          store 0 for mp cost
0x00181AE8: sb r16, 0x0000(r21)         store CT
0x00181AEC: sb r0, 0x0000(r22)          store cannot be affected by silence/performance
0x00181AF0: sb r2, 0x0000(r23)          store #turns to complete

All:
0x00181AF4: addiu r23, r23, 0x0001		Increase #turns pointer by 1 (for next ability)
0x00181AF8: addiu r22, r22, 0x0001		increase silence/performance checks by 1
0x00181AFC: addiu r21, r21, 0x0001		increase Raw CT pointer by 1
0x00181B00: addiu r20, r20, 0x0001		mp cost pointer + 1
0x00181B04: lhu r8, 0x00D8(r29)         load ability ID
0x00181B08: lw r9, 0x00C0(r29)          load Ability ID list
0x00181B0C: addiu r30, r30, 0x0001	Increase number of learnt and usable abilities by 1
0x00181B10: sh r8, 0x0000(r9)           store ability ID
0x00181B14: addiu r9, r9, 0x0002
0x00181B18: sw r9, 0x00C0(r29)          store next ability ID
0x00181B1C: addiu r19, r19, 0x0001
0x00181B20: slti r2, r19, 0x0010        run 15 times, once for each ability (except the last one? aren't skillsets 16 entries long though...?)
0x00181B24: bne r2, r0, 0x0018197C
0x00181B28: lui r2, 0x0080
0x00181B2C: lw r9, 0x00C0(r29)          Ability ID list
0x00181B30: addiu r2, r0, 0xFFFF        store end of list
0x00181B34: sh r2, 0x0000(r9)           store end of list
0x00181B38: addu r2, r30, r0            return number of learnt + usable abilities in r2 (only used for text purposes.)
0x00181B3C: lw r31, 0x012C(r29)
0x00181B40: lw r30, 0x0128(r29)
0x00181B44: lw r23, 0x0124(r29)
0x00181B48: lw r22, 0x0120(r29)
0x00181B4C: lw r21, 0x011C(r29)
0x00181B50: lw r20, 0x0118(r29)
0x00181B54: lw r19, 0x0114(r29)
0x00181B58: lw r18, 0x0110(r29)
0x00181B5C: lw r17, 0x010C(r29)
0x00181B60: lw r16, 0x0108(r29)
0x00181B64: addiu r29, r29, 0x0130
0x00181B68: jr r31
0x00181B6C: nop

Return location

Battle.bin
0013fc20: Main_Skillset/ability_loading
00179e94: Set_Jump_Ability_Targeting
00181638: Skillset_Loading?
00181c0c: Item_Ability_Loading
00181d68: Throw_Ability_&_Item_Loading
00181fbc: Math_Skill
0018212c: Math_Skill_ability_loading
00182238: Elemental_ability_loading
00182700: Draw_Out_2_(main_routine)
001827e0: Charge_Skillset_Loading