Calculator Routine

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search

Calculator Routine (returns hit counter)

0017b4d0: 27bdffb0 addiu r29,r29,0xffb0
0017b4d4: afb50044 sw r21,0x0044(r29)
0017b4d8: 0000a821 addu r21,r0,r0		Hit Counter = 0
0017b4dc: 27a50018 addiu r5,r29,0x0018		r5 = Stack Pointer + 0x18
0017b4e0: afbf004c sw r31,0x004c(r29)
0017b4e4: afb60048 sw r22,0x0048(r29)
0017b4e8: afb40040 sw r20,0x0040(r29)
0017b4ec: afb3003c sw r19,0x003c(r29)
0017b4f0: afb20038 sw r18,0x0038(r29)
0017b4f4: afb10034 sw r17,0x0034(r29)
0017b4f8: 0c01788b jal 0x0005e22c		Transfer Target ID? Through Mount Data
0017b4fc: afb00030 sw r16,0x0030(r29)
0017b500: 3407fe62 ori r7,r0,0xfe62		r7 = -0x19e
0017b504: 97a6001c lhu r6,0x001c(r29)		Load Calc Type Ability
0017b508: 93a30018 lbu r3,0x0018(r29)		Load Attacker/Self ID?
0017b50c: 97a5001e lhu r5,0x001e(r29)		Load Calc Multiplier Ability
0017b510: 00c72021 addu r4,r6,r7		Calc Type = Ability ID - 0x19e
0017b514: 000310c0 sll r2,r3,0x03		ID * 8
0017b518: 00431023 subu r2,r2,r3		ID * 7
0017b51c: 00021180 sll r2,r2,0x06		ID * 448
0017b520: 3c038019 lui r3,0x8019
0017b524: 246308cc addiu r3,r3,0x08cc
0017b528: 3084ffff andi r4,r4,0xffff
0017b52c: 2c840008 sltiu r4,r4,0x0008
0017b530: 10800019 beq r4,r0,0x0017b598		Branch if Calc Type doesn't exist
0017b534: 0043b021 addu r22,r2,r3		r22 = Unit's Data Pointer
0017b538: 00a71021 addu r2,r5,r7		Calc Multiplier = Ability ID - 0x19e
0017b53c: 3042ffff andi r2,r2,0xffff
0017b540: 2c420008 sltiu r2,r2,0x0008
0017b544: 10400014 beq r2,r0,0x0017b598		Branch if Calc Multiplier doesn't exist
0017b548: 00061c00 sll r3,r6,0x10
0017b54c: 00031c03 sra r3,r3,0x10
0017b550: 3c048006 lui r4,0x8006
0017b554: 24840eb6 addiu r4,r4,0x0eb6
0017b558: 00641821 addu r3,r3,r4		r3 = Calc Type's ID Pointer
0017b55c: 00051400 sll r2,r5,0x10
0017b560: 00021403 sra r2,r2,0x10
0017b564: 00441021 addu r2,r2,r4		r2 = Calc Multiplier's ID Pointer
0017b568: 90730000 lbu r19,0x0000(r3)		Load Calc Type ID
0017b56c: 90510000 lbu r17,0x0000(r2)		Load Calc Multiplier ID
0017b570: 326300f0 andi r3,r19,0x00f0
0017b574: 10600008 beq r3,r0,0x0017b598		Branch if Calc Type ID doesn't exist
0017b578: 3222000f andi r2,r17,0x000f
0017b57c: 10400006 beq r2,r0,0x0017b598		Branch if Calc ultiplier ID doesn't exist
0017b580: 3262000f andi r2,r19,0x000f
0017b584: 14400080 bne r2,r0,0x0017b788		Branch if Calc Type has Calc Mult Flags
0017b588: 2402ffff addiu r2,r0,0xffff		r2 = -1
0017b58c: 322200f0 andi r2,r17,0x00f0
0017b590: 10400003 beq r2,r0,0x0017b5a0		Branch if Calc Mult has Calc Type Flags
0017b594: 00000000 nop
0017b598: 0805ede2 j 0x0017b788
0017b59c: 2402ffff addiu r2,r0,0xffff		r2 = -1
0017b5a0: 0c05ed28 jal 0x0017b4a0		Disable Green Panel Flags
0017b5a4: 00009021 addu r18,r0,r0		Unit Counter = 0
0017b5a8: 0000a021 addu r20,r0,r0		Pointer Mod = 0
0017b5ac: 3c028019 lui r2,0x8019
0017b5b0: 244208cc addiu r2,r2,0x08cc
0017b5b4: 02828021 addu r16,r20,r2		r16 = Unit Data Pointer
0017b5b8: 92030001 lbu r3,0x0001(r16)		Load Unit's ID
0017b5bc: 340200ff ori r2,r0,0x00ff
0017b5c0: 1062006c beq r3,r2,0x0017b774		Branch if Unit doesn't exist
0017b5c4: 00000000 nop
0017b5c8: 92020058 lbu r2,0x0058(r16)		Load Unit's Current Statuses 1
0017b5cc: 00000000 nop
0017b5d0: 30420044 andi r2,r2,0x0044
0017b5d4: 14400067 bne r2,r0,0x0017b774		Branch if Unit is Jumping/Crystalized
0017b5d8: 00000000 nop
0017b5dc: 92020059 lbu r2,0x0059(r16)		Load Unit's Current Statuses 2
0017b5e0: 00000000 nop
0017b5e4: 30420001 andi r2,r2,0x0001
0017b5e8: 14400062 bne r2,r0,0x0017b774		Branch if Unit is Treasure
0017b5ec: 00000000 nop
0017b5f0: 92020182 lbu r2,0x0182(r16)		Load Unit's Mount Info
0017b5f4: 00000000 nop
0017b5f8: 30420040 andi r2,r2,0x0040
0017b5fc: 1440005d bne r2,r0,0x0017b774		Branch if Unit is Being Ridden
0017b600: 32620080 andi r2,r19,0x0080
0017b604: 1040000a beq r2,r0,0x0017b630		Branch if Calc Type ID != CT
0017b608: 32620040 andi r2,r19,0x0040
0017b60c: 92040039 lbu r4,0x0039(r16)		Load Unit's CT
0017b610: 00000000 nop
0017b614: 2c820065 sltiu r2,r4,0x0065
0017b618: 10400003 beq r2,r0,0x0017b628		Branch if CT >= 101
0017b61c: 00000000 nop
0017b620: 16160016 bne r16,r22,0x0017b67c	Branch if Unit != Self
0017b624: 308500ff andi r5,r4,0x00ff		Type Mod = Unit's CT
0017b628: 0805ed9e j 0x0017b678
0017b62c: 34040064 ori r4,r0,0x0064		Type Mod = 100
0017b630: 10400004 beq r2,r0,0x0017b644		Branch if Calc Type ID != Level
0017b634: 32620020 andi r2,r19,0x0020
0017b638: 92040022 lbu r4,0x0022(r16)		Load Unit's Level
0017b63c: 0805ed9f j 0x0017b67c
0017b640: 308500ff andi r5,r4,0x00ff		Type Mod = Level
0017b644: 10400004 beq r2,r0,0x0017b658		Branch if Calc Type ID != Exp
0017b648: 27a40010 addiu r4,r29,0x0010		r4 = Stack Pointer
0017b64c: 92040021 lbu r4,0x0021(r16)		Load Unit's Experience
0017b650: 0805ed9f j 0x0017b67c
0017b654: 308500ff andi r5,r4,0x00ff		Type Mod = Experience
0017b658: 0c05f056 jal 0x0017c158		Calculate Height Data
0017b65c: 02402821 addu r5,r18,r0		r5 = Unit Counter
0017b660: 93a40015 lbu r4,0x0015(r29)		Load Modified Height
0017b664: 00000000 nop
0017b668: 30820001 andi r2,r4,0x0001
0017b66c: 14400041 bne r2,r0,0x0017b774		Branch if Height isn't a whole number
0017b670: 00000000 nop
0017b674: 00042042 srl r4,r4,0x01		Modified Height / 2
0017b678: 308500ff andi r5,r4,0x00ff		Type Mod = Modified Height / 2 (100 for CT)
0017b67c: 10a0003d beq r5,r0,0x0017b774		Branch if Type Mod = 0
0017b680: 32220008 andi r2,r17,0x0008
0017b684: 1040000e beq r2,r0,0x0017b6c0		Branch if Calc Mult != Prime Number
0017b688: 00003021 addu r6,r0,r0		Hit? = 0 (Fail)
0017b68c: 00001821 addu r3,r0,r0		Prime Counter = 0
0017b690: 00a02021 addu r4,r5,r0		r4 = Type Mod
0017b694: 3c018006 lui r1,0x8006
0017b698: 00230821 addu r1,r1,r3
0017b69c: 90226198 lbu r2,0x6198(r1)		Load Prime Number
0017b6a0: 00000000 nop
0017b6a4: 10440026 beq r2,r4,0x0017b740		Branch if Type Mod = Prime Number
0017b6a8: 24630001 addiu r3,r3,0x0001		Prime Counter ++
0017b6ac: 28620036 slti r2,r3,0x0036
0017b6b0: 10400024 beq r2,r0,0x0017b744		Branch if Prime Counter >= 0x36
0017b6b4: 00000000 nop
0017b6b8: 0805eda5 j 0x0017b694
0017b6bc: 00000000 nop
0017b6c0: 32220004 andi r2,r17,0x0004
0017b6c4: 1040000b beq r2,r0,0x0017b6f4		Branch if Calc Mult != 5
0017b6c8: 3c02cccc lui r2,0xcccc
0017b6cc: 3442cccd ori r2,r2,0xcccd
0017b6d0: 00a20019 multu r5,r2			Type Mod * 0.8
0017b6d4: 00001810 mfhi r3
0017b6d8: 00031882 srl r3,r3,0x02		Type Mod / 5
0017b6dc: 00031080 sll r2,r3,0x02		Type Mod / 5 * 4
0017b6e0: 00431021 addu r2,r2,r3		Type Mod / 5 * 5
0017b6e4: 00a21023 subu r2,r5,r2		Type Mod - Type Mod / 5 * 5
0017b6e8: 304200ff andi r2,r2,0x00ff
0017b6ec: 10400014 beq r2,r0,0x0017b740		Branch if Type Mod is a multiple of 5
0017b6f0: 00000000 nop
0017b6f4: 32220002 andi r2,r17,0x0002
0017b6f8: 10400003 beq r2,r0,0x0017b708		Branch if Multiplier = 4
0017b6fc: 30820003 andi r2,r4,0x0003
0017b700: 1040000f beq r2,r0,0x0017b740		Branch if Mod is a multiple of 4
0017b704: 00000000 nop
0017b708: 32220001 andi r2,r17,0x0001
0017b70c: 1040000d beq r2,r0,0x0017b744		Branch if Multiplier = 3
0017b710: 3c02aaaa lui r2,0xaaaa
0017b714: 3442aaab ori r2,r2,0xaaab
0017b718: 308400ff andi r4,r4,0x00ff
0017b71c: 00820019 multu r4,r2			Type Mod * 0.66666667
0017b720: 00001810 mfhi r3
0017b724: 00031842 srl r3,r3,0x01		Type Mod / 3
0017b728: 00031040 sll r2,r3,0x01		Type Mod / 3 * 2
0017b72c: 00431021 addu r2,r2,r3		Type Mod / 3 * 3
0017b730: 00822023 subu r4,r4,r2		Type Mod - Type Mod / 3 * 3
0017b734: 308400ff andi r4,r4,0x00ff
0017b738: 14800002 bne r4,r0,0x0017b744		Branch if Type Mod isn't a mult of 3
0017b73c: 00000000 nop
0017b740: 34060001 ori r6,r0,0x0001		Hit? = 1 (Success)
0017b744: 10c0000b beq r6,r0,0x0017b774		Branch if Unit isn't Hit
0017b748: 00000000 nop
0017b74c: 0c060428 jal 0x001810a0		Map Location Calculation
0017b750: 02002021 addu r4,r16,r0		r4 = Unit's Data Pointer
0017b754: 000210c0 sll r2,r2,0x03		Tile ID * 8
0017b758: 3c038019 lui r3,0x8019
0017b75c: 2463f8cc addiu r3,r3,0xf8cc
0017b760: 00431021 addu r2,r2,r3
0017b764: 90430005 lbu r3,0x0005(r2)		Load Tile's ?
0017b768: 26b50001 addiu r21,r21,0x0001		Hit Counter ++
0017b76c: 34630080 ori r3,r3,0x0080		Enable Green Panel Flag
0017b770: a0430005 sb r3,0x0005(r2)		Store new ?
0017b774: 26520001 addiu r18,r18,0x0001		Unit Counter 1 ++
0017b778: 2a420015 slti r2,r18,0x0015
0017b77c: 1440ff8b bne r2,r0,0x0017b5ac		Branch if Unit Counter 1 < 0x15
0017b780: 269401c0 addiu r20,r20,0x01c0		Pointer Mod += 0x1c0
0017b784: 02a01021 addu r2,r21,r0		r2 = Hit Counter
0017b788: 8fbf004c lw r31,0x004c(r29)
0017b78c: 8fb60048 lw r22,0x0048(r29)
0017b790: 8fb50044 lw r21,0x0044(r29)
0017b794: 8fb40040 lw r20,0x0040(r29)
0017b798: 8fb3003c lw r19,0x003c(r29)
0017b79c: 8fb20038 lw r18,0x0038(r29)
0017b7a0: 8fb10034 lw r17,0x0034(r29)
0017b7a4: 8fb00030 lw r16,0x0030(r29)
0017b7a8: 27bd0050 addiu r29,r29,0x0050
0017b7ac: 03e00008 jr r31
0017b7b0: 00000000 nop 


Return Locations

0017abc8: - Calculate_Targeting_for_Menu_Types