Difference between revisions of "Calculate Clockticks Until Unit Acts"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Created page with "<font face='Courier New'> 001999c8: 3c02801a lui r2,0x801a 001999cc: 90420d7b lbu r2,0x0d7b(r2) 001999d0: 27bdffc8 addiu r29,r29,0xffc8 001999d4: afb3002c sw r19,0x002c(...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<font face='Courier New'>
+
BATTLE.BIN : Calculate Clockticks Until Unit Acts
 +
------------------------------------------------------------------------------------------
 +
Parameters - r4 : Considered Unit data pointer (Battle stats)
 +
             
 +
Returns r2 : Remaining Ticks before unit get an active turn
 +
              = 0x7fffffff if unit won't get a turn ever (crystal, treasure, petrified, etc...) 
 +
-----------------------------------------------------------------------------------------
 +
00199b98: 90860038 lbu r6,0x0038(r4)        |{{f/load|Load Unit's SP}}
 +
00199b9c: 3c03801a lui r3,0x801a            |
 +
00199ba0: 2463f3c4 addiu r3,r3,-0x0c3c      |{{f/adr|Start of AI data pointer}} {{f/std| 8019f3c4}}
 +
00199ba4: 10c00010 beq r6,r0,0x00199be8    {{f/Cond|If speed is not 0x00}}
 +
00199ba8: 00002821 addu r5,r0,r0            |{{f/std|Initialize Tick counter}}
 +
00199bac: 94820058 lhu r2,0x0058(r4)            |{{f/load|Load Unit's Current Statuses 1+2}}
 +
00199bb0: 00000000 nop                          |
 +
00199bb4: 30428140 andi r2,r2,0x8140            |{{f/std|Check [Crystal], [Petrify] and [Treasure]}}
 +
00199bb8: 1440000c bne r2,r0,0x00199bec        {{f/Cond|If Unit is not affected by Crystal, treasure or Petrify}}
 +
00199bbc: 3c027fff lui r2,0x7fff                |{{f/std|<nowiki>r2 = 0x7fff0000</nowiki>}}
 +
00199bc0: 90820001 lbu r2,0x0001(r4)                |{{f/load|Load Unit's ID}}
 +
00199bc4: 00000000 nop                              |
 +
00199bc8: 00021100 sll r2,r2,0x04                  |{{f/std|ID * 16 }}
 +
00199bcc: 00431021 addu r2,r2,r3                    |{{f/adr|Start of AI data pointer + Unit offset}}
 +
00199bd0: 90421833 lbu r2,0x1833(r2)                |{{f/load|Load Unit's AI Targetting flags}} {{f/std|8019f3c4 + 0x182c + 0x07 + Unit offset}}
 +
00199bd4: 00000000 nop                              |
 +
00199bd8: 00021142 srl r2,r2,0x05                  |{{f/std|Flag 0x20 becomes 0x01}}
 +
00199bdc: 30420001 andi r2,r2,0x0001                |{{f/std|Check [Dead without reraise]}}
 +
00199be0: 10400004 beq r2,r0,0x00199bf4            {{f/Cond|If Unit is dead without reraise}}
 +
00199be4: 00000000 nop                                  |
 +
00199be8: 3c027fff lui r2,0x7fff            {{f/Cond|E        }} |{{f/std|<nowiki>r2 = 0x7fff0000</nowiki>}}
 +
00199bec: 08066720 j 0x00199c80                {{f/Cond|E    }} |{{f/jump|jump to END and returns }} {{f/loc|<nowiki>r2 = 0x7fffffff</nowiki>}}
 +
00199bf0: 3442ffff ori r2,r2,0xffff                    |{{f/std|<nowiki>Turns = 0x7fffffff</nowiki>}}
 
   
 
   
  001999c8: 3c02801a lui r2,0x801a
+
  {{f/sec|--- Unit will eventually get an active Turn (Speed > 0, CT not frozen, alive) ---}}
001999cc: 90420d7b lbu r2,0x0d7b(r2)
+
  00199bf4: 9082005b lbu r2,0x005b(r4)       |{{f/load|Load Unit's Statuses 4}}
001999d0: 27bdffc8 addiu r29,r29,0xffc8
+
  00199bf8: 00000000 nop                      |
001999d4: afb3002c sw r19,0x002c(r29)
+
  00199bfc: 30420002 andi r2,r2,0x0002        |{{f/std|Check [Stop]}}
  001999d8: 3c13801a lui r19,0x801a
+
  00199c00: 10400002 beq r2,r0,0x00199c0c    {{f/Cond|If Unit has stop}}
001999dc: 2673f3c4 addiu r19,r19,0xf3c4
+
  00199c04: 00000000 nop                          |
001999e0: afbf0034 sw r31,0x0034(r29)
+
  00199c08: 90850063 lbu r5,0x0063(r4)           |{{f/load|Load Stop CT }} {{f/std|Remaining ticks before stops fade}}
  001999e4: afb40030 sw r20,0x0030(r29)
+
  00199c0c: 90830039 lbu r3,0x0039(r4)       |{{f/load|Load Unit CT}}
  001999e8: afb20028 sw r18,0x0028(r29)
+
  00199c10: 00000000 nop                      |
001999ec: afb10024 sw r17,0x0024(r29)
+
  00199c14: 2c620064 sltiu r2,r3,0x0064      |{{f/std|Check if Unit CT is Above 100}}
  001999f0: 10400019 beq r2,r0,0x00199a58
+
  00199c18: 10400008 beq r2,r0,0x00199c3c    {{f/Cond|If Unit CT is > 100 (will get his turn right now)}}
  001999f4: afb00020 sw r16,0x0020(r29)
+
  00199c1c: 34020064 ori r2,r0,0x0064            |{{f/std|<nowiki>r2 = 100</nowiki>}}
  001999f8: 3c10801a lui r16,0x801a
+
  00199c20: 00431023 subu r2,r2,r3                |{{f/std|Remaining CT before active turn}}
001999fc: 9210f3dc lbu r16,-0x0c24(r16) load acting unit X
+
  00199c24: 0046001a div r2,r6                    |{{f/std|Remaining CT / SP}}
00199a00: 3c11801a lui r17,0x801a
+
  00199c28: 00001012 mflo r2                     |{{f/std|Remaining Ticks before turn (or close)}}
  00199a04: 9231f3de lbu r17,-0x0c22(r17) load acting unit Y
+
  00199c2c: 00001810 mfhi r3                     |{{f/std|Remainder (0 if unit get his turns, not 0 if there's still a Tick before the turn)}}
  00199a08: 3c02801a lui r2,0x801a
+
  00199c30: 10600002 beq r3,r0,0x00199c3c        {{f/Cond|If remainder is not 0x00}}
  00199a0c: 904201f1 lbu r2,0x01f1(r2) ??
+
  00199c34: 00a22821 addu r5,r5,r2               |{{f/std|Ticks before first active turn (with Stop CT or not)}}
  00199a10: 3c12801a lui r18,0x801a
+
  00199c38: 24a50001 addiu r5,r5,0x0001              |{{f/std|Add one ticks if needed}}
00199a14: 9252f3dd lbu r18,-0x0c23(r18) load map level
+
  00199c3c: 90820058 lbu r2,0x0058(r4)       |{{f/load|Load Unit's Statuses 1}}
  00199a18: 000218c0 sll r3,r2,0x03 ??*8
+
  00199c40: 00000000 nop                     |
00199a1c: 00621821 addu r3,r3,r2 ??*9
+
  00199c44: 30420020 andi r2,r2,0x0020        |{{f/std|check [Dead]}}
  00199a20: 000318c0 sll r3,r3,0x03 ??*72
+
  00199c48: 1440000d bne r2,r0,0x00199c80    {{f/Cond|If Unit is not Dead}} {{f/std|<nowiki>Else Dead with reraise - returns r2 = Ticks left</nowiki>}}
00199a24: 00731821 addu r3,r3,r19
+
  00199c4c: 00a01021 addu r2,r5,r0           |{{f/std|Returns remaining Ticks before action}}
00199a28: 24630a74 addiu r3,r3,0x0a74
+
  00199c50: 9082005c lbu r2,0x005c(r4)           |{{f/load|Load Unit's Statuses 5}}
00199a2c: 001210c0 sll r2,r18,0x03 maplevel*8
+
  00199c54: 00000000 nop                         |
00199a30: 00521021 addu r2,r2,r18 maplevel*9
+
  00199c58: 30420010 andi r2,r2,0x0010            |{{f/std|check [Sleep]}}
  00199a34: 00021080 sll r2,r2,0x02 maplevel*36
+
  00199c5c: 10400008 beq r2,r0,0x00199c80        {{f/Cond|If Unit is sleeping}} {{f/std|<nowiki>Else returns r2 = Ticks left</nowiki>}}
  00199a38: 00431021 addu r2,r2,r3 maplevel*36 + r3 address
+
  00199c60: 00a01021 addu r2,r5,r0                |{{f/std|<nowiki>r2 = Ticks</nowiki>}}
  00199a3c: 00111840 sll r3,r17,0x01 Y coordinate*2
+
  00199c64: 90840068 lbu r4,0x0068(r4)               |{{f/load|Load Sleep CT}}
  00199a40: 00621821 addu r3,r3,r2
+
  00199c68: 00000000 nop                             |
00199a44: 94740000 lhu r20,0x0000(r3)
+
  00199c6c: 00a4102a slt r2,r5,r4                    |{{f/std|Check Ticks left Vs Sleep CT}} {{f/std| ? It's like sleep don't freeze CT}}
00199a48: 080666bc j 0x00199af0
+
  00199c70: 10400003 beq r2,r0,0x00199c80            {{f/Cond|If Ticks left > sleep CT }}
00199a4c: 00000000 nop
+
  00199c74: 00a01021 addu r2,r5,r0                    |{{f/std|Returns Ticks left}}
00199a50: 080666dd j 0x00199b74
+
  00199c78: 00802821 addu r5,r4,r0                        |{{f/std|<nowiki>Ticks = Sleep CT</nowiki>}}
00199a54: 2402ffff addiu r2,r0,0xffff
+
  00199c7c: 00a01021 addu r2,r5,r0                        |{{f/std|<nowiki>Returns Tick left = sleep CT</nowiki>}}
  00199a58: 00009021 addu r18,r0,r0
+
  00199c80: 03e00008 jr r31                  END
00199a5c: 3c01801a lui r1,0x801a
+
  00199c84: 00000000 nop
00199a60: a020f3d8 sb r0,-0x0c28(r1)
+
 
00199a64: 3c01801a lui r1,0x801a
+
=== Notes ===
00199a68: a020f3e1 sb r0,-0x0c1f(r1)
+
  '''Mechanics'''
00199a6c: 92620e3b lbu r2,0x0e3b(r19)
+
  Test Status freezing CT that will not fade
  00199a70: 00000000 nop
+
  Add Stop CT to the remaining Ticks
00199a74: 18400038 blez r2,0x00199b58
+
   
00199a78: 00008821 addu r17,r0,r0
+
  '''Bugs ?'''
  00199a7c: 92620e2d lbu r2,0x0e2d(r19)
+
  No checks for don't act ? (When looking to returns location, it seems this routine is focusing on the unit getting a turn or not, i guess the don't act check will occurs later)
  00199a80: 00000000 nop
+
  Sleep is checked as if the unit CT is not frozen
  00199a84: 000218c0 sll r3,r2,0x03
+
   
00199a88: 00621821 addu r3,r3,r2
+
  '''Hard coding'''
00199a8c: 000318c0 sll r3,r3,0x03
+
  AI checks Status ID and not [freeze CT] flag for Crystal, Treasure, Petrify and Stop
  00199a90: 00731821 addu r3,r3,r19
+
 
00199a94: 24630a74 addiu r3,r3,0x0a74
+
===Return Locations===
00199a98: 001210c0 sll r2,r18,0x03
+
  '''BATTLE.BIN'''
00199a9c: 00521021 addu r2,r2,r18
+
  001942a4: [[Acting_Unit%27s_Data_Setup]]
00199aa0: 00021080 sll r2,r2,0x02
+
  00194f14: [[Set_AI_ability_considerations_for_all_units_and_self]]
  00199aa4: 00431021 addu r2,r2,r3
+
  00199918: [[Check_if_Regen/Charm/DM/Reraise/DA_Can_be_Inflicted]]
00199aa8: 00111840 sll r3,r17,0x01
+
  0019e780: [[AI_Ability_Use_Decisions]]
00199aac: 00621821 addu r3,r3,r2
+
  0019efe8: [[0019efb0_-_0019f018]]
00199ab0: 94740000 lhu r20,0x0000(r3)
+
  0019f114: [[See_if_ability_should_be_used_based_on_CT]]
00199ab4: 00000000 nop
+
  0019f230: [[Status/CT_based_decision]]
00199ab8: 12800022 beq r20,r0,0x00199b44
 
  00199abc: 00000000 nop
 
00199ac0: 92620e3a lbu r2,0x0e3a(r19)
 
  00199ac4: 00000000 nop
 
  00199ac8: 1840001e blez r2,0x00199b44
 
00199acc: 00008021 addu r16,r0,r0
 
00199ad0: 02141004 sllv r2,r20,r16
 
00199ad4: 30428000 andi r2,r2,0x8000
 
  00199ad8: 10400015 beq r2,r0,0x00199b30
 
  00199adc: 00000000 nop
 
00199ae0: a2700018 sb r16,0x0018(r19)
 
00199ae4: a271001a sb r17,0x001a(r19)
 
  00199ae8: 0c066ec8 jal 0x0019bb20
 
00199aec: a2720019 sb r18,0x0019(r19)
 
  00199af0: 0c0674df jal 0x0019d37c
 
00199af4: 00000000 nop
 
  00199af8: 2403ffff addiu r3,r0,0xffff
 
  00199afc: 1043ffd4 beq r2,r3,0x00199a50
 
  00199b00: 001210c0 sll r2,r18,0x03
 
00199b04: 00521021 addu r2,r2,r18
 
00199b08: 00021180 sll r2,r2,0x06
 
  00199b0c: 00531021 addu r2,r2,r19
 
  00199b10: 244205f4 addiu r2,r2,0x05f4
 
00199b14: 00111940 sll r3,r17,0x05
 
00199b18: 00621821 addu r3,r3,r2
 
00199b1c: 00102040 sll r4,r16,0x01
 
  00199b20: 96620032 lhu r2,0x0032(r19)
 
  00199b24: 00832021 addu r4,r4,r3
 
00199b28: 00021023 subu r2,r0,r2
 
00199b2c: a4820000 sh r2,0x0000(r4)
 
  00199b30: 92620e3a lbu r2,0x0e3a(r19)
 
  00199b34: 26100001 addiu r16,r16,0x0001
 
  00199b38: 0202102a slt r2,r16,r2
 
  00199b3c: 1440ffe5 bne r2,r0,0x00199ad4
 
  00199b40: 02141004 sllv r2,r20,r16
 
  00199b44: 92620e3b lbu r2,0x0e3b(r19)
 
00199b48: 26310001 addiu r17,r17,0x0001
 
  00199b4c: 0222102a slt r2,r17,r2
 
  00199b50: 1440ffca bne r2,r0,0x00199a7c
 
  00199b54: 00000000 nop
 
  00199b58: 26520001 addiu r18,r18,0x0001
 
00199b5c: 2a420002 slti r2,r18,0x0002
 
00199b60: 1440ffc2 bne r2,r0,0x00199a6c
 
  00199b64: 00000000 nop
 
  00199b68: 0c067c96 jal 0x0019f258
 
  00199b6c: 26640e30 addiu r4,r19,0x0e30
 
  00199b70: 00001021 addu r2,r0,r0
 
  00199b74: 8fbf0034 lw r31,0x0034(r29)
 
  00199b78: 8fb40030 lw r20,0x0030(r29)
 
  00199b7c: 8fb3002c lw r19,0x002c(r29)
 
  00199b80: 8fb20028 lw r18,0x0028(r29)
 
00199b84: 8fb10024 lw r17,0x0024(r29)
 
00199b88: 8fb00020 lw r16,0x0020(r29)
 
00199b8c: 27bd0038 addiu r29,r29,0x0038
 
00199b90: 03e00008 jr r31
 
00199b94: 00000000 nop
 
</font>
 

Latest revision as of 08:58, 4 May 2023

BATTLE.BIN : Calculate Clockticks Until Unit Acts
------------------------------------------------------------------------------------------
Parameters - r4 : Considered Unit data pointer (Battle stats)
             
Returns r2 : Remaining Ticks before unit get an active turn
             = 0x7fffffff if unit won't get a turn ever (crystal, treasure, petrified, etc...)  
-----------------------------------------------------------------------------------------
00199b98: 90860038 lbu r6,0x0038(r4)        |Load Unit's SP
00199b9c: 3c03801a lui r3,0x801a            |
00199ba0: 2463f3c4 addiu r3,r3,-0x0c3c      |Start of AI data pointer  8019f3c4
00199ba4: 10c00010 beq r6,r0,0x00199be8     #If speed is not 0x00 
00199ba8: 00002821 addu r5,r0,r0            |Initialize Tick counter
00199bac: 94820058 lhu r2,0x0058(r4)            |Load Unit's Current Statuses 1+2
00199bb0: 00000000 nop                          |
00199bb4: 30428140 andi r2,r2,0x8140            |Check [Crystal], [Petrify] and [Treasure]
00199bb8: 1440000c bne r2,r0,0x00199bec         #If Unit is not affected by Crystal, treasure or Petrify 
00199bbc: 3c027fff lui r2,0x7fff                |r2 = 0x7fff0000
00199bc0: 90820001 lbu r2,0x0001(r4)                |Load Unit's ID
00199bc4: 00000000 nop                              |
00199bc8: 00021100 sll r2,r2,0x04                   |ID * 16 
00199bcc: 00431021 addu r2,r2,r3                    |Start of AI data pointer + Unit offset
00199bd0: 90421833 lbu r2,0x1833(r2)                |Load Unit's AI Targetting flags 8019f3c4 + 0x182c + 0x07 + Unit offset
00199bd4: 00000000 nop                              |
00199bd8: 00021142 srl r2,r2,0x05                   |Flag 0x20 becomes 0x01
00199bdc: 30420001 andi r2,r2,0x0001                |Check [Dead without reraise]
00199be0: 10400004 beq r2,r0,0x00199bf4             #If Unit is dead without reraise
00199be4: 00000000 nop                                  |
00199be8: 3c027fff lui r2,0x7fff            #E          |r2 = 0x7fff0000
00199bec: 08066720 j 0x00199c80                 #E      |>>jump to END and returns  r2 = 0x7fffffff
00199bf0: 3442ffff ori r2,r2,0xffff                     |Turns = 0x7fffffff

--- Unit will eventually get an active Turn (Speed > 0, CT not frozen, alive) ---
00199bf4: 9082005b lbu r2,0x005b(r4)        |Load Unit's Statuses 4
00199bf8: 00000000 nop                      |
00199bfc: 30420002 andi r2,r2,0x0002        |Check [Stop]
00199c00: 10400002 beq r2,r0,0x00199c0c     #If Unit has stop
00199c04: 00000000 nop                          |
00199c08: 90850063 lbu r5,0x0063(r4)            |Load Stop CT  Remaining ticks before stops fade
00199c0c: 90830039 lbu r3,0x0039(r4)        |Load Unit CT
00199c10: 00000000 nop                      |
00199c14: 2c620064 sltiu r2,r3,0x0064       |Check if Unit CT is Above 100
00199c18: 10400008 beq r2,r0,0x00199c3c     #If Unit CT is > 100 (will get his turn right now)
00199c1c: 34020064 ori r2,r0,0x0064             |r2 = 100
00199c20: 00431023 subu r2,r2,r3                |Remaining CT before active turn
00199c24: 0046001a div r2,r6                    |Remaining CT / SP
00199c28: 00001012 mflo r2                      |Remaining Ticks before turn (or close)
00199c2c: 00001810 mfhi r3                      |Remainder (0 if unit get his turns, not 0 if there's still a Tick before the turn)
00199c30: 10600002 beq r3,r0,0x00199c3c         #If remainder is not 0x00
00199c34: 00a22821 addu r5,r5,r2                |Ticks before first active turn (with Stop CT or not)
00199c38: 24a50001 addiu r5,r5,0x0001               |Add one ticks if needed
00199c3c: 90820058 lbu r2,0x0058(r4)        |Load Unit's Statuses 1
00199c40: 00000000 nop                      |
00199c44: 30420020 andi r2,r2,0x0020        |check [Dead]
00199c48: 1440000d bne r2,r0,0x00199c80     #If Unit is not Dead Else Dead with reraise - returns r2 = Ticks left
00199c4c: 00a01021 addu r2,r5,r0            |Returns remaining Ticks before action
00199c50: 9082005c lbu r2,0x005c(r4)            |Load Unit's Statuses 5
00199c54: 00000000 nop                          |
00199c58: 30420010 andi r2,r2,0x0010            |check [Sleep]
00199c5c: 10400008 beq r2,r0,0x00199c80         #If Unit is sleeping Else returns r2 = Ticks left
00199c60: 00a01021 addu r2,r5,r0                |r2 = Ticks
00199c64: 90840068 lbu r4,0x0068(r4)                |Load Sleep CT
00199c68: 00000000 nop                              |
00199c6c: 00a4102a slt r2,r5,r4                     |Check Ticks left Vs Sleep CT  ? It's like sleep don't freeze CT
00199c70: 10400003 beq r2,r0,0x00199c80             #If Ticks left > sleep CT 
00199c74: 00a01021 addu r2,r5,r0                    |Returns Ticks left
00199c78: 00802821 addu r5,r4,r0                        |Ticks = Sleep CT
00199c7c: 00a01021 addu r2,r5,r0                        |Returns Tick left = sleep CT
00199c80: 03e00008 jr r31                   END
00199c84: 00000000 nop

Notes

Mechanics
Test Status freezing CT that will not fade
Add Stop CT to the remaining Ticks

Bugs ?
No checks for don't act ? (When looking to returns location, it seems this routine is focusing on the unit getting a turn or not, i guess the don't act check will occurs later)
Sleep is checked as if the unit CT is not frozen

Hard coding
AI checks Status ID and not [freeze CT] flag for Crystal, Treasure, Petrify and Stop

Return Locations

BATTLE.BIN
001942a4: Acting_Unit's_Data_Setup
00194f14: Set_AI_ability_considerations_for_all_units_and_self
00199918: Check_if_Regen/Charm/DM/Reraise/DA_Can_be_Inflicted
0019e780: AI_Ability_Use_Decisions
0019efe8: 0019efb0_-_0019f018
0019f114: See_if_ability_should_be_used_based_on_CT
0019f230: Status/CT_based_decision