Cos call function

From Final Fantasy Hacktics Wiki
Revision as of 06:45, 20 March 2022 by Talcall (talk | contribs) (Talcall moved page Sin call function to Cos call function: Cosine is just sine but offset by some value. so, the fact that if the angle is < 90 it grabs the angle of 90 - angle? probably means it's programmed to be cos.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Parameters : r4 = angle  value (degrees*1024/90)

Returns : r2 = sinus (90-angle)*4096 if angle <= 90°
          r2 = -sinus (angle -90)*4096 if angle is between 91° and 180°
          r2 = sinus (angle -270)*4096 if angle is > 270° (0° to -90°)
          r2 = -sinus (270-angle) if angle is between 181° and 270° (-90° to 180°)
----------------------------------------------------------------------------------------------------------
0001bc28: 04810002 bgez r4,0x0001bc34            #If input value < 0x00
0001bc2c: 00000000 nop                               |
0001bc30: 00042023 subu r4,r0,r4                     |r4 = input positive value
0001bc34: 30840fff andi r4,r4,0x0fff             |r4 = remainder of r4/4096 4096 = 360°
0001bc38: 28820801 slti r2,r4,0x0801             |r2 x 0x01 if angle < 0x801
0001bc3c: 10400010 beq r2,r0,0x0001bc80          #If angle < 0x801 (angle <= 180°)
0001bc40: 28820401 slti r2,r4,0x0401                 |r2 = 0x01 if angle <= 0x400
0001bc44: 10400008 beq r2,r0,0x0001bc68              #If angle <= 0x400  (angle <= 90°) #Branch if > 0x400
0001bc48: 34020400 ori r2,r0,0x0400                      |r2 = 0x400
0001bc4c: 00441023 subu r2,r2,r4                         |r2 = 0x400 -angle (r4/4096)
0001bc50: 00021040 sll r2,r2,0x01                        |r2 * 2
0001bc54: 3c018003 lui r1,0x8003                         |r1 = 0x80030000
0001bc58: 00220821 addu r1,r1,r2                         |r1 = 0x80030000 + offset
0001bc5c: 8422b0a4 lh r2,-0x4f5c(r1)                     |r2 = [Sinus(90-r4 angle)]*4096 0x8002b0a4 + offset
0001bc60: 08006f30 j 0x0001bcc0                          >>jump to end
0001bc64: 00000000 nop                                   |
0001bc68: 00041040 sll r2,r4,0x01                    #Else (angle > 400) (>90°) #r2 = angle * 2
0001bc6c: 3c018003 lui r1,0x8003                     |r1 = 0x80030000
0001bc70: 00220821 addu r1,r1,r2                     |r1 = 0x80030000 + offset
0001bc74: 8422a8a4 lh r2,-0x575c(r1)                 |r2 = Sinus (r4 angle-90)*4096 0x8002a8a4 + offset (ignore the first 90° of the angle - 1st available value starts at 0x8002b0a4  ( 0x8002a8a4 + 0x400*2)
0001bc78: 08006f30 j 0x0001bcc0                      >>jump to end
0001bc7c: 00021023 subu r2,r0,r2                     |r2 = - Sinus (r4 angle)*4096
0001bc80: 28820c01 slti r2,r4,0x0c01             #Else (Angle > 180°) r2 = 0x01 if angle <= 270°
0001bc84: 14400007 bne r2,r0,0x0001bca4          #If angle > 0xc00 (> 270°)
0001bc88: 34020c00 ori r2,r0,0x0c00              |r2 = 0x0c00
0001bc8c: 00041040 sll r2,r4,0x01                    |r2 =angle * 2
0001bc90: 3c018003 lui r1,0x8003                     |r1 = 0x80030000
0001bc94: 00220821 addu r1,r1,r2                     |r1 = 0x80030000 + offset
0001bc98: 842298a4 lh r2,-0x675c(r1)                 |r2 = Sinus (r4 angle-270)*4096 0x800298a4 + offset (ignore the first 270° of the angle - 1st available value starts at 0x8002b0a4  ( 0x800298a4 + 0xc00*2)
0001bc9c: 08006f30 j 0x0001bcc0                      >>jump to end
0001bca0: 00000000 nop                               |
0001bca4: 00441023 subu r2,r2,r4                 #Else (Angle between 181° and 270°) r2 = 0xc00 - angle
0001bca8: 00021040 sll r2,r2,0x01                |r2 * 2
0001bcac: 3c018003 lui r1,0x8003                 |r1 = 0x80030000
0001bcb0: 00220821 addu r1,r1,r2                 |r1 = 0x80030000 + offset
0001bcb4: 8422b0a4 lh r2,-0x4f5c(r1)             |r2 = [Sinus(270-r4 angle)]*4096
0001bcb8: 00000000 nop                           |
0001bcbc: 00021023 subu r2,r0,r2                 |r2 = - [Sinus(270-r4 angle)]*4096
0001bcc0: 03e00008 jr r31                        
0001bcc4: 00000000 nop

Return locations

Battle.bin
0007af9c: 0007af44_-_0007b4e8
001a5450: 001a5394_-_001a5794
001a5864: 001a5798_-_001a5b44
001a885c: 001a8834_-_001a8894
001a897c: 001a894c_-_001a89ac 
001a89e0: 001a89b0_-_001a8a10
001a8b18: 001a8ae8_-_001a8b48
001a8b7c: 001a8b4c_-_001a8bac
001af214: 001af108 - 001af3a0
001afba4: 001afb38 - 001afd8c
001b1164: 001b0ffc - 001b1538
001b1fa8: 001b1c04 - 001b27d8
001b2048: 001b1c04 - 001b27d8
001b44fc: 001b4234 - 001b47dc