001af59c - 001af6d4

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
Parameters : r4 = [001af3dc val2] = (0xa8000/[Attacker to Target distance] - 64)
             r5 = [V2] = 0x76*sin([Attack's angle])*4096    (Angle from 0x801b8b70 / 801b8b70)
*Thoses values came from the 001afb38 - 001afd8c routine

Returns r2 = Some maths that i don't understand anymore
(i give up on this one, tired off all this maths... maths are the only thing here. Nothing stored)
-------------------------------------------------------------------------------------------------
001af59c: 00803021 addu r6,r4,r0            |r6 = [001af3dc val2]
001af5a0: 3c02801c lui r2,0x801c            |r2 = 0x801c0000
001af5a4: 8c428878 lw r2,-0x7788(r2)        |r2 = gravity ? 0xa8000                 
001af5a8: 24c37fff addiu r3,r6,0x7fff       |r3 = [001af3dc val2]+ 0x7fff 
001af5ac: 00021040 sll r2,r2,0x01           |r2 = 0xa8000 * 2
001af5b0: 00024303 sra r8,r2,0x0c           |r8 = 0x150
001af5b4: 3402fffe ori r2,r0,0xfffe         |r2 = 0xfffe
001af5b8: 0043102b sltu r2,r2,r3            |r2 = 0x01 if [001af3dc val2]> 0x7fff (0xfffe = 0x7fff*2)
001af5bc: 1440001e bne r2,r0,0x001af638     #if [001af3dc val2]< 0x7fff
001af5c0: 3c04000f lui r4,0x000f                 |r4 = 0x000f0000
001af5c4: 00c60018 mult r6,r6                    |[001af3dc val2]^2
001af5c8: 3484ffff ori r4,r4,0xffff              |r4 = 0x000fffff
001af5cc: 3c03001f lui r3,0x001f                 |r3 = 0x001f0000
001af5d0: 3463fffe ori r3,r3,0xfffe              |r3 = 0x001ffffe
001af5d4: 00a42021 addu r4,r5,r4                 |r4 = [V2]  +   0xffff
001af5d8: 0064182b sltu r3,r3,r4                 |r3 = 0x01 if [V2] > 0xfffff  (1ffffe = fffff*2)
001af5dc: 00001012 mflo r2                       |r2 = [001af3dc val2]^2
001af5e0: 1460000b bne r3,r0,0x001af610          #if [V2] < 0xfffff
001af5e4: 00023b03 sra r7,r2,0x0c                |r7 = [001af3dc val2]²/4096
001af5e8: 00051143 sra r2,r5,0x05                    |r2 = [V2] / 32
001af5ec: 00420018 mult r2,r2                        |([V2] / 32)²
001af5f0: 00001812 mflo r3                           |r3 = [V2]²/1024
001af5f4: 00000000 nop                               |
001af5f8: 00000000 nop                               |
001af5fc: 00c20018 mult r6,r2                        | [001af3dc val2]* [V2] / 32
001af600: 00031883 sra r3,r3,0x02                    |r3 = [V2]²/4096
001af604: 00001012 mflo r2                           |r2 = [001af3dc val2]* [V2] / 32
001af608: 0806bdab j 0x001af6ac                      >>Jump to near end - do maths with r3,r4, r7 and r8
001af60c: 000221c3 sra r4,r2,0x07                    |r4 = [001af3dc val2]* [V2] / 4096
001af610: 000511c3 sra r2,r5,0x07                #Else r2 = [V2]/128
001af614: 00420018 mult r2,r2                        | ([V2]/128)^2
001af618: 00001812 mflo r3                           |r3 = [V2]^2/16384
001af61c: 00000000 nop                               |
001af620: 00000000 nop                               |
001af624: 00c20018 mult r6,r2                        |[001af3dc val2]*  [V2]/128
001af628: 00031880 sll r3,r3,0x02                    |r3 = [V2]^2/4096
001af62c: 00001012 mflo r2                           |r2 = [001af3dc val2]*  [V2]/128
001af630: 0806bdab j 0x001af6ac                      >>Jump to near end - do maths with r3,r4, r7 and r8
001af634: 00022143 sra r4,r2,0x05                    |r4 = [001af3dc val2]*  [V2]/4
001af638: 00063103 sra r6,r6,0x04           #Else
001af63c: 00c60018 mult r6,r6                    | 
001af640: 3484ffff ori r4,r4,0xffff              |
001af644: 3c03001f lui r3,0x001f                 |
001af648: 3463fffe ori r3,r3,0xfffe              |
001af64c: 00a42021 addu r4,r5,r4                 |
001af650: 0064182b sltu r3,r3,r4                 |
001af654: 00001012 mflo r2                       |
001af658: 1460000b bne r3,r0,0x001af688          #If
001af65c: 00023903 sra r7,r2,0x04                    | 
001af660: 00051143 sra r2,r5,0x05                    |
001af664: 00420018 mult r2,r2                        |
001af668: 00001812 mflo r3                           |
001af66c: 00000000 nop                               |
001af670: 00000000 nop                               |
001af674: 00c20018 mult r6,r2                        |
001af678: 00031883 sra r3,r3,0x02                    |
001af67c: 00001012 mflo r2                           |
001af680: 0806bdab j 0x001af6ac                      >>Jump to near end - do maths with r3,r4, r7 and r8
001af684: 000220c3 sra r4,r2,0x03                    |
001af688: 000511c3 sra r2,r5,0x07                #Else
001af68c: 00420018 mult r2,r2                        | 
001af690: 00001812 mflo r3                           |
001af694: 00000000 nop                               |
001af698: 00000000 nop                               |
001af69c: 00c20018 mult r6,r2                        |
001af6a0: 00031880 sll r3,r3,0x02                    |
001af6a4: 00001012 mflo r2                           |
001af6a8: 00022043 sra r4,r2,0x01                    |
001af6ac: 24e21000 addiu r2,r7,0x1000       |r2 = r7 + 4096
001af6b0: 00021183 sra r2,r2,0x06           |r2 = (r7 + 4096)/64
001af6b4: 00031983 sra r3,r3,0x06           |r3 = r3/64
001af6b8: 00430018 mult r2,r3               |(r7 + 4096)/64  * r3/64
001af6bc: 00001012 mflo r2                  |r2 = ( (r7 + 4096)*  r3 ) /4096
001af6c0: 00000000 nop                      |
001af6c4: 00000000 nop                      |
001af6c8: 0048001a div r2,r8                |
001af6cc: 00001012 mflo r2                  | (r7 + 4096)* r3 ) / (0xa8000*2)
001af6d0: 03e00008 jr r31                   |
001af6d4: 00821023 subu r2,r4,r2            |r2 = r4  -   (r7 + 4096)* r3 ) / (0xa8000*2)

Notes

For documentation / research : this routine uses :
- Value at 801b8878 ( 0x801b8878 ) flagged as gravity mod (= 0xa8000)

Return locations

Battle.bin
001afc80: 001afb38 - 001afd8c
001b1268: 001b0ffc - 001b1538
001b1294: 001b0ffc - 001b1538
001b12b8: 001b0ffc - 001b1538