Maths For Arcing Trajectory

From Final Fantasy Hacktics Wiki
Revision as of 21:10, 30 January 2022 by Orkney (talk | contribs) (→‎Return location)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
001af3dc - 001af584

Big math routine, returns two values used from trajectory calculation

Parameters : r4 = Pointer to some targeting data
             r5 = Pointer 2 (will be used for storage)
             r6 = Pointer 3 (will be used for storage)

Returns : r2 = 0x01 if pointer 2 and 3 hold values / Else 0x00
          Modify eventually Target graphic height at r4 0x2c
          Store [001af3dc val1] at pointer 2 (see notes in routine.. too big)
          Store [001af3dc val2] at pointer 3 ((0xa8000/Attacker to Target distance - 64))
-----------------------------------------------------------------------------------------------------
001af3dc: 27bdffd8 addiu r29,r29,-0x0028    | 
001af3e0: afb00010 sw r16,0x0010(r29)       | 
001af3e4: 00808021 addu r16,r4,r0           |r16 = Stack pointer 1
001af3e8: afb3001c sw r19,0x001c(r29)       |
001af3ec: 00a09821 addu r19,r5,r0           |r19 = Stack pointer 2
001af3f0: afb40020 sw r20,0x0020(r29)       |
001af3f4: 00c0a021 addu r20,r6,r0           |r20 = Stack pointer 3
001af3f8: afbf0024 sw r31,0x0024(r29)       |
001af3fc: afb20018 sw r18,0x0018(r29)       |
001af400: afb10014 sw r17,0x0014(r29)       |
001af404: 8e040028 lw r4,0x0028(r16)        |r4 = Target ID  (may be unit ID from other routines)
001af408: 0c0237eb jal 0x0008dfac           |-->Get_Unit_Tile_data_pointer_from_Unit_ID returns r2 =  Target Tile data pointer)
001af40c: 00009021 addu r18,r0,r0           |r18 = 0x00
001af410: 8e04000c lw r4,0x000c(r16)        |r4 = (Attacker to Target distance)*4096
001af414: 90430003 lbu r3,0x0003(r2)        |r3 = Target tile Halves + depht
001af418: 90450002 lbu r5,0x0002(r2)        |r5 = Target tile Height
001af41c: 00031942 srl r3,r3,0x05           |r3 = Target tile effective depht
001af420: 00a32821 addu r5,r5,r3            |r5 = Target tile Height + depht 
001af424: 00051040 sll r2,r5,0x01           |r2 = (Target tile Height + depht )*2
001af428: 00451021 addu r2,r2,r5            |r2 = (Target tile Height + depht )*3
001af42c: 0c06bce9 jal 0x001af3a4           |-->001af3a4_-_001af3d8 returns r2 =  - 0x54000 - ([AT distance]² *4096/336) gravity related ?
001af430: 00028b80 sll r17,r2,0x0e          |r17 = (Target tile Height + depht)*12*4096
001af434: 8e03000c lw r3,0x000c(r16)        |r3 = (Attacker to Target distance)*4096
001af438: 00000000 nop                      |
001af43c: 1060004d beq r3,r0,0x001af574     #If Attacker to target distance <> 0x00
001af440: 00402821 addu r5,r2,r0                 |r5 =  [AT distance]² *4096/336) - 0x54000 = [001af34 Value]
001af444: 8e03002c lw r3,0x002c(r16)             |r3 = Target graphic height
001af448: 00000000 nop                           |
001af44c: 000317c2 srl r2,r3,0x1f                |r2 = Target graphic height / 2^31 (= 0x00 (rounding stuff))
001af450: 00621821 addu r3,r3,r2                 |r3 = Target graphic height + 0x00 
001af454: 8e020004 lw r2,0x0004(r16)             |r2 = Delta Z (difference of height between Attacker and target))
001af458: 00031843 sra r3,r3,0x01                |r3 = Target graphic height/2
001af45c: 00621021 addu r2,r3,r2                 |r2 = Target graphic height/2 + Delta Z (note that delta Z is negative if attacker is heigher than target)
001af460: 00022300 sll r4,r2,0x0c                |r4 = (Target graphic height/2 + Delta Z )*4096
001af464: 00a4102a slt r2,r5,r4                  |r2 = 0x01 if [001af34 Value] is < than [(Target graphic height/2 + Delta Z )*4096]
001af468: 14400003 bne r2,r0,0x001af478          #If [001af34 Value] > (Target graphic height/2 + Delta Z )*4096
001af46c: 0224102a slt r2,r17,r4                     |r2 = 0x01 if (Target tile Height + depht)*12 < [(Target graphic height/2 + Delta Z )]
001af470: 10400011 beq r2,r0,0x001af4b8              #If  (Target tile Height + depht)*12 < [(Target graphic height/2 + Delta Z )]  / Else branch without checking 3/4 unit height
001af474: 00000000 nop                                   | 
001af478: 8e03002c lw r3,0x002c(r16)             #E      |r3 = Target graphic height
001af47c: 00000000 nop                                   |
001af480: 00031040 sll r2,r3,0x01                        |r2 = Target graphic height*2
001af484: 00431821 addu r3,r2,r3                         |r3 = Target graphic height*3
001af488: 04610002 bgez r3,0x001af494                    #If Target graphic height*3 < 0x00  security ? (not possible ?)
001af48c: 00000000 nop                                       | 
001af490: 24630003 addiu r3,r3,0x0003                        |r3 = r3 + 0x03
001af494: 8e020004 lw r2,0x0004(r16)                     |r2 = delta Z
001af498: 00031883 sra r3,r3,0x02                        |r3 = Target graphic height*3/4
001af49c: 00621021 addu r2,r3,r2                         |r2 = (delta Z + Target graphic height*3/4)
001af4a0: 00022300 sll r4,r2,0x0c                        |r4 = (delta Z + Target graphic height*3/4)*4096
001af4a4: 00a4102a slt r2,r5,r4                          |r2 = 0x01 if [001af34 Value] <  (delta Z + Target graphic height*3/4)*4096
001af4a8: 14400005 bne r2,r0,0x001af4c0                  #if [001af34 Value] >  (delta Z + Target graphic height*3/4)*4096
001af4ac: 0224102a slt r2,r17,r4                             |r2 = 0x01 if (Target tile Height + depht)*12 < [(Target graphic heigh*3/4 + Delta Z )]
001af4b0: 14400003 bne r2,r0,0x001af4c0                      # if (Target tile Height + depht)*12 > [(Target graphic heigh*3/4 + Delta Z )]
001af4b4: 00000000 nop                                           | 
001af4b8: 0806bd3a j 0x001af4e8                      #E          >>jump to next section avoiding Target graphic height nullification
001af4bc: ae03002c sw r3,0x002c(r16)                             |Store Target graphic height (/2 or *3/4) at Stack 1  0x2c
001af4c0: 8e020004 lw r2,0x0004(r16)                     #E  #E  |r2 = delta Z
001af4c4: 00000000 nop                                   
001af4c8: 00022300 sll r4,r2,0x0c                |r4 = delta Z * 4096
001af4cc: 00a4102a slt r2,r5,r4                  |r2 = 0x01 if [001af34 Value] < (delta Z)*4096
001af4d0: 14400029 bne r2,r0,0x001af578          #If [001af34 Value] > (delta Z)*4096 /Else jump to end (r2 = 0x00)
001af4d4: 02401021 addu r2,r18,r0                |r2 = 0x00
001af4d8: 0224102a slt r2,r17,r4                     |r2 = 0x01 if  (Target tile Height + depht)*12*4096 < (delta Z)*4096
001af4dc: 14400026 bne r2,r0,0x001af578              #if (Target tile Height + depht)*12> (delta Z) /Else jump to End (r2 = 0x00)
001af4e0: 02401021 addu r2,r18,r0                    |r2 = 0x00
001af4e4: ae00002c sw r0,0x002c(r16)                     |Store 0x00 as Target graphic height
001af4e8: 3c03801c lui r3,0x801c                         |r3 = 0x801c0000
001af4ec: 8c638878 lw r3,-0x7788(r3)                     |r3 = 0xa8000 (12*28*2048)
001af4f0: 00041143 sra r2,r4,0x05                        |r2 = delta Z * 128
001af4f4: 00031983 sra r3,r3,0x06                        |r3 = 12*28 *32
001af4f8: 00621023 subu r2,r3,r2                         |r2 = delta Z * 128 - (0xa8000/64)
001af4fc: 00430018 mult r2,r3                            |[delta Z * 128 - (0xa8000/64)]*(0xa8000/64)
001af500: 8e02000c lw r2,0x000c(r16)                     |r2 = (Attacker to Target distance)*4096
001af504: 00001812 mflo r3                               |r3 = [delta Z * 128 - (0xa8000/64)]*(0xa8000/64)
001af508: 00021183 sra r2,r2,0x06                        |r2 = (Attacker to Target distance)*64
001af50c: 00000000 nop                                   |
001af510: 00420018 mult r2,r2                            |(Attacker to Target distance)^2*4096
001af514: 00002012 mflo r4                               |r4 = (Attacker to Target distance)^2*4096
001af518: 0c00709a jal 0x0001c268                        |-->Get_Square_root_of_r4_dealing_with_4096 return r2 = (square root of r4/4096)*4096
001af51c: 00642023 subu r4,r3,r4                         |r4 =([delta Z * 128 - (0xa8000/64)]*(0xa8000/64)) -  (Attacker to Target distance)^2*4096
001af520: 3c03801c lui r3,0x801c                         |r3 = 0x801c0000
001af524: 8c638878 lw r3,-0x7788(r3)                     |r3 = 0xa8000 (12*28*2048)
001af528: 8e04000c lw r4,0x000c(r16)                     |r4 = (Attacker to Target distance)*4096
001af52c: 00431821 addu r3,r2,r3                         |r3 = [Long square root]+ 0xa8000 
001af530: 00031a00 sll r3,r3,0x08                        |r3 = ([Long square root] + 0xa8000)*256
001af534: 00042103 sra r4,r4,0x04                        |r4 = (Attacker to Target distance)*256
001af538: 0064001a div r3,r4                             |
001af53c: 00001812 mflo r3                               |r3 = ([Long square root] + 0xa8000)/( Attacker to Target distance) 
001af540: 00000000 nop                                   |
001af544: ae630000 sw r3,0x0000(r19)                     |Store r3 at stack 2  (= [001af3dc Val1] )
001af548: 3c03801c lui r3,0x801c                         |
001af54c: 8c638878 lw r3,-0x7788(r3)                     |r3 = 0xa8000 (12*28*2048)
001af550: 00000000 nop                                   |
001af554: 00621823 subu r3,r3,r2                         |r3 = 0xa8000 - (Attacker to Target distance)*64
001af558: 8e02000c lw r2,0x000c(r16)                     |r2 = (Attacker to Target distance)*4096
001af55c: 00031a00 sll r3,r3,0x08                        |r3 = (0xa8000 - (Attacker to Target distance)*64)*256
001af560: 00021103 sra r2,r2,0x04                        |r2 = (Attacker to Target distance)*256
001af564: 0062001a div r3,r2                             |((0xa8000 - (Attacker to Target distance)*64)*256) / (Attacker to Target distance)*256
001af568: 00001812 mflo r3                               |r3 =  (0xa8000/Attacker to Target distance - 64) 
001af56c: 34120001 ori r18,r0,0x0001                     |r18 = 0x01
001af570: ae830000 sw r3,0x0000(r20)                     |Store r3 maths at stack 3 ( = [001af3dc val2])
001af574: 02401021 addu r2,r18,r0           #E           |r2 = 0x00 if no maths / 0x01 is math is done (branch here if [AT distance] is 0x00)
001af578: 8fbf0024 lw r31,0x0024(r29)       
001af57c: 8fb40020 lw r20,0x0020(r29)       
001af580: 8fb3001c lw r19,0x001c(r29)       
001af584: 8fb20018 lw r18,0x0018(r29)       
001af588: 8fb10014 lw r17,0x0014(r29)       
001af58c: 8fb00010 lw r16,0x0010(r29)       
001af590: 27bd0028 addiu r29,r29,0x0028     
001af594: 03e00008 jr r31                   
001af598: 00000000 nop                      
                

Return location

Battle.bin
001afea8: 001afd90_-_001aff14
001b0118: Set_and_Validate_Arc_Trajectory