Attack Preparation

From Final Fantasy Hacktics Wiki
Revision as of 20:02, 20 May 2024 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
BATTLE.BIN :  - Attack_Preparation
------------------------------------------------------------------------------------------
Parameter : r4 : Pointer to Data in Battle 0x16e formating (see return location section) - AI , Battle or Misc
            r5 = Pointer to Data in Battle 0x16e formating (see return location section)
            r6 = Preset Value (0x00 Ability Selected ? / 0x01 AT List Preview / 0x0d mimic Ability ? Unconfirmed) 
Return : r2 = 0x01 if Ability CT = 0x00
         r2 = 0x00 if Ability CT > 0x00
         r2 = -0x01 if Invalid data
------------------------------------------------------------------------------------------
0017c45c: 27bdffb0 addiu r29,r29,-0x0050     |addiu r29,r29,-0x0050
0017c460: afb5003c sw r21,0x003c(r29)        |
0017c464: 00a0a821 addu r21,r5,r0            |Preserve 801908cc + 0x16e Pointer
0017c468: afb40038 sw r20,0x0038(r29)        |
0017c46c: 00c0a021 addu r20,r6,r0            |Preserves Preset Value
0017c470: 27a50010 addiu r5,r29,0x0010       |Stack Pointer + 0x10
0017c474: afbf0048 sw r31,0x0048(r29)        |
0017c478: afb70044 sw r23,0x0044(r29)        |
0017c47c: afb60040 sw r22,0x0040(r29)        |
0017c480: afb30034 sw r19,0x0034(r29)        |
0017c484: afb20030 sw r18,0x0030(r29)        |
0017c488: afb1002c sw r17,0x002c(r29)        |
0017c48c: 0c01788b jal 0x0005e22c            |-->Copy_Byte_Data_(20_Bytes)  From r4 to r5
0017c490: afb00028 sw r16,0x0028(r29)        |
0017c494: 93a30010 lbu r3,0x0010(r29)        |Acting Unit ID
0017c498: 00000000 nop                       |
0017c49c: 2c620015 sltiu r2,r3,0x0015        |
0017c4a0: 104000dd beq r2,r0,0x0017c818      #If Unit ID is invalid Exit Returns -0x01
0017c4a4: 000310c0 sll r2,r3,0x03            |
0017c4a8: 00431023 subu r2,r2,r3             |
0017c4ac: 00021180 sll r2,r2,0x06            |Unit offset (Unit ID * 0x1c0)
0017c4b0: 3c038019 lui r3,0x8019             |
0017c4b4: 246308cc addiu r3,r3,0x08cc        |
0017c4b8: 00439821 addu r19,r2,r3            |Considered Unit Battle data pointer Always acting unit ?
0017c4bc: 92620001 lbu r2,0x0001(r19)        |load unit ID
0017c4c0: 340400ff ori r4,r0,0x00ff          |
0017c4c4: 104400d4 beq r2,r4,0x0017c818      #If considered Unit doesn't exists Exit Returns -0x01
0017c4c8: 34020006 ori r2,r0,0x0006          |
0017c4cc: 93a3001a lbu r3,0x001a(r29)        |Load r4 pointer + 0x0a Could be 6 if Target Map
0017c4d0: 00000000 nop                       |
0017c4d4: 1462000e bne r3,r2,0x0017c510      #If r4 0x0a = 0x06 ( Ability has [Target Map] ? )  Set to 0x06 if Target Map / labeled as Target-specific in wiki
0017c4d8: 0000b021 addu r22,r0,r0                |
0017c4dc: 93a3001b lbu r3,0x001b(r29)            |load Target ID ?
0017c4e0: 00000000 nop                           |
0017c4e4: 2c620015 sltiu r2,r3,0x0015            |
0017c4e8: 104000cb beq r2,r0,0x0017c818          #If Unit ID is invalid Exit Returns -0x01
0017c4ec: 000310c0 sll r2,r3,0x03                |
0017c4f0: 00431023 subu r2,r2,r3                 |
0017c4f4: 00021180 sll r2,r2,0x06                |ID * 0x1c0
0017c4f8: 3c018019 lui r1,0x8019                 |
0017c4fc: 00220821 addu r1,r1,r2                 |
0017c500: 902208cd lbu r2,0x08cd(r1)             |This Unit Battle ID 801908cc + 0x01 + Unit offset
0017c504: 00000000 nop                           |
0017c508: 104400f4 beq r2,r4,0x0017c8dc          #If considered Unit doesn't exists Exit Returns -0x01
0017c50c: 2402ffff addiu r2,r0,-0x0001           |
0017c510: 93a20011 lbu r2,0x0011(r29)        |Considered Ability's skillset
0017c514: 3c018006 lui r1,0x8006             |
0017c518: 00220821 addu r1,r1,r2             |
0017c51c: 90235cb4 lbu r3,0x5cb4(r1)         |Considered Ability's Action Menu 80065cb4 + Skillset offset (Byte)
0017c520: 00000000 nop                       |
0017c524: 2c62000d sltiu r2,r3,0x000d        |set if less than 0d
0017c528: 104000bb beq r2,r0,0x0017c818      #If Action Menu is Unknwon or Blank Exit Returns -0x01
0017c52c: 00031080 sll r2,r3,0x02            |Action Menu Offset (word)
0017c530: 3c018017 lui r1,0x8017             |
0017c534: 00220821 addu r1,r1,r2             |
0017c538: 8c2240e8 lw r2,0x40e8(r1)          |Load return address based on action menu byte
0017c53c: 00000000 nop                       |
0017c540: 00400008 jr r2                     >>jump to dedicated section  See Notes
0017c544: 00000000 nop 

Item Inventory
0017c548: 93b10018 lbu r17,0x0018(r29)       load used item ID
0017c54c: 00000000 nop 
0017c550: 323200ff andi r18,r17,0x00ff 
0017c554: 00121040 sll r2,r18,0x01           item ID*2
0017c558: 00521021 addu r2,r2,r18            item ID*2 + Item ID
0017c55c: 00021080 sll r2,r2,0x02            (item ID*2 + Item ID)*4
0017c560: 3c018006 lui r1,0x8006 
0017c564: 00220821 addu r1,r1,r2 
0017c568: 90232ebd lbu r3,0x2ebd(r1)         load item type
0017c56c: 34020022 ori r2,r0,0x0022 
0017c570: 146200da bne r3,r2,0x0017c8dc      skip to end if used item is not an item. not necessary?
0017c574: 2402ffff addiu r2,r0,0xffff        r2 = -1
0017c578: 27a40010 addiu r4,r29,0x0010 
0017c57c: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c580: 02a02821 addu r5,r21,r0            r5 = 0x182 in unit data (mount data) 
0017c584: 26300080 addiu r16,r17,0x0080      r16 = used ability ID
0017c588: 12800067 beq r20,r0,0x0017c728     branch if r20 is 0
0017c58c: a6b00002 sh r16,0x0002(r21)        store used ability ID
0017c590: 32820001 andi r2,r20,0x0001 
0017c594: 10400064 beq r2,r0,0x0017c728      branch if r20 is not 01
0017c598: 02602021 addu r4,r19,r0            r4 = unit data
0017c59c: 02402821 addu r5,r18,r0            r5 = used item ID
0017c5a0: 0c05f255 jal 0x0017c954            -->Player_Item_Quantity_decrement
0017c5a4: 34060001 ori r6,r0,0x0001          input value = 01
0017c5a8: 34020001 ori r2,r0,0x0001 
0017c5ac: 0805f1ca j 0x0017c728              jump to write action taken, return r2=01
0017c5b0: a2620188 sb r2,0x0188(r19)         store action taken

 Weapon Inventory
0017c5b4: 3410017e ori r16,r0,0x017e 
0017c5b8: 93b10018 lbu r17,0x0018(r29) 
0017c5bc: 3c048006 lui r4,0x8006 
0017c5c0: 24840ea2 addiu r4,r4,0x0ea2        load ability data 2 (@ ability 0x170)
0017c5c4: 00111040 sll r2,r17,0x01 
0017c5c8: 00511021 addu r2,r2,r17 
0017c5cc: 00021080 sll r2,r2,0x02 
0017c5d0: 3c018006 lui r1,0x8006 
0017c5d4: 00220821 addu r1,r1,r2 
0017c5d8: 90232ebd lbu r3,0x2ebd(r1)         load item type?
0017c5dc: 00101400 sll r2,r16,0x10 
0017c5e0: 00021403 sra r2,r2,0x10 
0017c5e4: 00441021 addu r2,r2,r4 
0017c5e8: 90420000 lbu r2,0x0000(r2) 
0017c5ec: 00000000 nop 
0017c5f0: 10430007 beq r2,r3,0x0017c610 
0017c5f4: 26020001 addiu r2,r16,0x0001 
0017c5f8: 00408021 addu r16,r2,r0 
0017c5fc: 00021400 sll r2,r2,0x10 
0017c600: 00021403 sra r2,r2,0x10 
0017c604: 2842018a slti r2,r2,0x018a 
0017c608: 1440fff5 bne r2,r0,0x0017c5e0 
0017c60c: 00101400 sll r2,r16,0x10 
0017c610: 00101400 sll r2,r16,0x10 
0017c614: 00021403 sra r2,r2,0x10 
0017c618: 3403018a ori r3,r0,0x018a 
0017c61c: 1043007e beq r2,r3,0x0017c818 
0017c620: 27a40010 addiu r4,r29,0x0010 
0017c624: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c628: 02a02821 addu r5,r21,r0 
0017c62c: 1280003e beq r20,r0,0x0017c728 
0017c630: a6b00002 sh r16,0x0002(r21) 
0017c634: 32820001 andi r2,r20,0x0001 
0017c638: 1040003b beq r2,r0,0x0017c728 
0017c63c: 02602021 addu r4,r19,r0 
0017c640: 02202821 addu r5,r17,r0 
0017c644: 0c05f255 jal 0x0017c954            -->Player_Item_Quantity_decrement
0017c648: 34060001 ori r6,r0,0x0001 
0017c64c: 34020001 ori r2,r0,0x0001 
0017c650: 0805f1ca j 0x0017c728 
0017c654: a2620188 sb r2,0x0188(r19) 

Math Skill
0017c658: 3404fe62 ori r4,r0,0xfe62 
0017c65c: 97b00012 lhu r16,0x0012(r29) 
0017c660: 97a20014 lhu r2,0x0014(r29) 
0017c664: 97a30016 lhu r3,0x0016(r29) 
0017c668: 00441021 addu r2,r2,r4             r2 - 19e
0017c66c: 3042ffff andi r2,r2,0xffff 
0017c670: 2c420008 sltiu r2,r2,0x0008 
0017c674: 10400068 beq r2,r0,0x0017c818      branch if not using a math skill ability
0017c678: 00641021 addu r2,r3,r4 
0017c67c: 3042ffff andi r2,r2,0xffff 
0017c680: 2c420008 sltiu r2,r2,0x0008 
0017c684: 10400064 beq r2,r0,0x0017c818      same check for 2nd parameter?
0017c688: 3202ffff andi r2,r16,0xffff 
0017c68c: 2c420170 sltiu r2,r2,0x0170 
0017c690: 10400061 beq r2,r0,0x0017c818      check if 3rd parameter is an active ability
0017c694: 27a40010 addiu r4,r29,0x0010 
0017c698: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c69c: 02a02821 addu r5,r21,r0 
0017c6a0: 12800021 beq r20,r0,0x0017c728 
0017c6a4: 32820001 andi r2,r20,0x0001 
0017c6a8: 1040001f beq r2,r0,0x0017c728 
0017c6ac: 34020001 ori r2,r0,0x0001 
0017c6b0: 0805f1ca j 0x0017c728 
0017c6b4: a2620188 sb r2,0x0188(r19) 

Elements
0017c6b8: 0c05fcb6 jal 0x0017f2d8 
0017c6bc: 02602021 addu r4,r19,r0 
0017c6c0: 0805f1ff j 0x0017c7fc 
0017c6c4: a7a20012 sh r2,0x0012(r29) 

Katana Inventory
0017c6c8: 93b10018 lbu r17,0x0018(r29) 
0017c6cc: 00000000 nop 
0017c6d0: 2622ffda addiu r2,r17,0xffda 
0017c6d4: 2c42000a sltiu r2,r2,0x000a 
0017c6d8: 1040004f beq r2,r0,0x0017c818      Branch if ?? not a draw out thing?
0017c6dc: 26300026 addiu r16,r17,0x0026 
0017c6e0: 32820001 andi r2,r20,0x0001 
0017c6e4: 10400045 beq r2,r0,0x0017c7fc      Branch if ???
0017c6e8: a7b00012 sh r16,0x0012(r29) 
0017c6ec: 02602021 addu r4,r19,r0 
0017c6f0: 02202821 addu r5,r17,r0 
0017c6f4: 0c05f255 jal 0x0017c954            -->Player_Item_Quantity_decrement
0017c6f8: 34060001 ori r6,r0,0x0001 
0017c6fc: 0805f1ff j 0x0017c7fc 
0017c700: 00000000 nop 

Attack
0017c704: 27a40010 addiu r4,r29,0x0010 
0017c708: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c70c: 02a02821 addu r5,r21,r0 
0017c710: 12800004 beq r20,r0,0x0017c724 
0017c714: 32820001 andi r2,r20,0x0001 
0017c718: 10400002 beq r2,r0,0x0017c724 
0017c71c: 34020001 ori r2,r0,0x0001 
0017c720: a2620188 sb r2,0x0188(r19) 
0017c724: a6a00002 sh r0,0x0002(r21)         store last attack used?
0017c728: 0805f237 j 0x0017c8dc 
0017c72c: 34020001 ori r2,r0,0x0001 

Jump
0017c730: 27a40010 addiu r4,r29,0x0010 
0017c734: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c738: 02a02821 addu r5,r21,r0 
0017c73c: 12800013 beq r20,r0,0x0017c78c 
0017c740: 34030032 ori r3,r0,0x0032 
0017c744: 92620038 lbu r2,0x0038(r19)        load speed
0017c748: 00000000 nop 
0017c74c: 0062001a div r3,r2                 0x32 / speed?
0017c750: 00001812 mflo r3 
0017c754: 00000000 nop 
0017c758: 00609021 addu r18,r3,r0 
0017c75c: 16400002 bne r18,r0,0x0017c768 
0017c760: 02401021 addu r2,r18,r0 
0017c764: 34020001 ori r2,r0,0x0001 
0017c768: a262015d sb r2,0x015d(r19)         store current ability CT
0017c76c: 32820001 andi r2,r20,0x0001 
0017c770: 10400006 beq r2,r0,0x0017c78c 
0017c774: 02602021 addu r4,r19,r0 
0017c778: 34050006 ori r5,r0,0x0006 
0017c77c: 34020001 ori r2,r0,0x0001 
0017c780: a0820188 sb r2,0x0188(r4)          Store action taken
0017c784: 0c0179ea jal 0x0005e7a8            set status flags - jump
0017c788: a0820187 sb r2,0x0187(r4)          store movement taken
0017c78c: 3402018a ori r2,r0,0x018a 
0017c790: a6a20002 sh r2,0x0002(r21)         store last attack used
0017c794: 0805f237 j 0x0017c8dc 
0017c798: 34020003 ori r2,r0,0x0003 

Charge
0017c79c: 97b00012 lhu r16,0x0012(r29) 
0017c7a0: 00000000 nop 
0017c7a4: 2602fe6a addiu r2,r16,0xfe6a       ability ID - 196
0017c7a8: 2c420008 sltiu r2,r2,0x0008 
0017c7ac: 1040001a beq r2,r0,0x0017c818      check if ability is charge ability
0017c7b0: 27a40010 addiu r4,r29,0x0010 
0017c7b4: 0c01788b jal 0x0005e22c            -->Copy_Byte_Data_(20_Bytes)
0017c7b8: 02a02821 addu r5,r21,r0 
0017c7bc: 00101400 sll r2,r16,0x10 
0017c7c0: 000213c3 sra r2,r2,0x0f 
0017c7c4: 3c018006 lui r1,0x8006 
0017c7c8: 00220821 addu r1,r1,r2 
0017c7cc: 90320d18 lbu r18,0x0d18(r1)        get charges power?
0017c7d0: 32820001 andi r2,r20,0x0001 
0017c7d4: 10400003 beq r2,r0,0x0017c7e4 
0017c7d8: 34160001 ori r22,r0,0x0001 
0017c7dc: 34020001 ori r2,r0,0x0001 
0017c7e0: a2620187 sb r2,0x0187(r19)         store movement taken
0017c7e4: 0805f1ff j 0x0017c7fc 
0017c7e8: 0000b821 addu r23,r0,r0 

Defend
0017c7ec: 0805f237 j 0x0017c8dc 
0017c7f0: 00001021 addu r2,r0,r0 

Change Equipment
0017c7f4: 0805f237 j 0x0017c8dc 
0017c7f8: 34020002 ori r2,r0,0x0002 

 Default / Monster / ( end of Katana Inventory / Charge)
0017c7fc: 16c00020 bne r22,r0,0x0017c880     #If r22 <> 0x00  Skip CT section Keep r22 with his value (instead of setting it to CT)
0017c800: 00000000 nop                       |
0017c804: 97b00012 lhu r16,0x0012(r29)       |Considered Ability ID
0017c808: 00000000 nop                       |
0017c80c: 2e020170 sltiu r2,r16,0x0170       |
0017c810: 14400003 bne r2,r0,0x0017c820      #If Ability Has a data 2 section  Avoid Fail 
0017c814: 27a40010 addiu r4,r29,0x0010       |

Fails and Blank action Menu 
0017c818: 0805f237 j 0x0017c8dc              >>Jump to  Exit returns -0x01
0017c81c: 2402ffff addiu r2,r0,-0x0001       |

Load and Check Ability CT
0017c820: 0c01788b jal 0x0005e22c            |-->Copy_Byte_Data_(20_Bytes)  From r4 (stack data coming from r4 passed pointer )  to r5 (r5 passed pointer)
0017c824: 02a02821 addu r5,r21,r0            |
0017c828: 00101c00 sll r3,r16,0x10           |
0017c82c: 00031c03 sra r3,r3,0x10            |Ability ID
0017c830: 000310c0 sll r2,r3,0x03            |
0017c834: 00431023 subu r2,r2,r3             |
0017c838: 00021040 sll r2,r2,0x01            |14
0017c83c: 3c038006 lui r3,0x8006             |
0017c840: 2463fbf0 addiu r3,r3,-0x0410       |
0017c844: 00431021 addu r2,r2,r3             |0x8005fbf0 + Ability offset (0xe bytes)
0017c848: 9043000c lbu r3,0x000c(r2)         |Ability  CT
0017c84c: 90420005 lbu r2,0x0005(r2)         |load flags 3
0017c850: 3072007f andi r18,r3,0x007f        |r18 = CT as signed?
0017c854: 30570004 andi r23,r2,0x0004        |persevere check
0017c858: 92630092 lbu r3,0x0092(r19)        |Acting Unit support 4
0017c85c: 16e00008 bne r23,r0,0x0017c880     #If Ability do NOT have [Persevere] aka performing
0017c860: 30620008 andi r2,r3,0x0008             |
0017c864: 10400002 beq r2,r0,0x0017c870          #If Acting Unit uses [Short Charge]
0017c868: 26420001 addiu r2,r18,0x0001               |
0017c86c: 00029042 srl r18,r2,0x01                   |CT / 2
0017c870: 30620004 andi r2,r3,0x0004             |
0017c874: 10400002 beq r2,r0,0x0017c880          #If Acting Unit used [Non Charge]
0017c878: 00000000 nop                               |
0017c87c: 00009021 addu r18,r0,r0                    |CT = 0

Store Ability CT and Action Taken- Set Charging/Performing Status
0017c880: 12800014 beq r20,r0,0x0017c8d4     #If Preset Value (r6) = 0x00 Avoid Status section
0017c884: 32820001 andi r2,r20,0x0001        |
0017c888: 10400012 beq r2,r0,0x0017c8d4      #If Preset Value (r6) = 0x01 (or 0x0d ?)
0017c88c: a272015d sb r18,0x015d(r19)        |Store current ability CT
0017c890: 3c028019 lui r2,0x8019                 |
0017c894: 8c42f5f0 lw r2,-0x0a10(r2)             |Load Type of Action
0017c898: 00000000 nop                           |
0017c89c: 1440000e bne r2,r0,0x0017c8d8          #If Reaction (<> 0x00)  Exit returns r2 based on CT
0017c8a0: 324200ff andi r2,r18,0x00ff            |r2 = CT
0017c8a4: 34020001 ori r2,r0,0x0001              |
0017c8a8: a2620188 sb r2,0x0188(r19)             |Store action taken flag
0017c8ac: 324200ff andi r2,r18,0x00ff            |
0017c8b0: 10400008 beq r2,r0,0x0017c8d4          #if CT <> 0x00
0017c8b4: 32e200ff andi r2,r23,0x00ff                |
0017c8b8: 10400003 beq r2,r0,0x0017c8c8              #If Ability has [Persevere]
0017c8bc: 02602021 addu r4,r19,r0                    |Prepare Acting Unit Battle data pointer
0017c8c0: 0805f233 j 0x0017c8cc                          |
0017c8c4: 34050008 ori r5,r0,0x0008                      |Inflict Performing and remove everything else
                                                     Else : Not Persevere
0017c8c8: 34050005 ori r5,r0,0x0005                      |Inflict Charging and remove everything else
0017c8cc: 0c0179ea jal 0x0005e7a8                    |-->Status_infliction/removal%3F
0017c8d0: 00000000 nop                               |
0017c8d4: 324200ff andi r2,r18,0x00ff        |r2 = CT
0017c8d8: 2c420001 sltiu r2,r2,0x0001        |0x01 if CT = 0x00 Else 0x00
0017c8dc: 8fbf0048 lw r31,0x0048(r29)
0017c8e0: 8fb70044 lw r23,0x0044(r29)
0017c8e4: 8fb60040 lw r22,0x0040(r29)
0017c8e8: 8fb5003c lw r21,0x003c(r29)
0017c8ec: 8fb40038 lw r20,0x0038(r29)
0017c8f0: 8fb30034 lw r19,0x0034(r29)
0017c8f4: 8fb20030 lw r18,0x0030(r29)
0017c8f8: 8fb1002c lw r17,0x002c(r29)
0017c8fc: 8fb00028 lw r16,0x0028(r29)
0017c900: 27bd0050 addiu r29,r29,0x0050
0017c904: 03e00008 jr r31
0017c908: 00000000 nop

Notes

    RAM    | Rank  | Action Menu        | Jump Address  |   
-----------|-------|--------------------|---------------|
0x801740e8 | 0x00  | Default            | 0x8017c7fc    |
0x801740ec | 0x01  | Item Inventory     | 0x8017c548    |
0x801740f0 | 0x02  | Weapon Inventory   | 0x8017c5b4    |
0x801740f4 | 0x03  | Arithmeticks       | 0x8017c658    |
0x801740f8 | 0x04  | Elements           | 0x8017c6b8    |
0x801740fc | 0x05  | Blank              | 0x8017c818    |
0x80174100 | 0x06  | Monster            | 0x8017c7fc    |
0x80174104 | 0x07  | Katana Inventory   | 0x8017c6c8    |
0x80174108 | 0x08  | Attack             | 0x8017c704    |
0x8017410c | 0x09  | Jump               | 0x8017c730    |
0x80174110 | 0x0A  | Charge             | 0x8017c79c    |
0x80174114 | 0x0B  | Defend             | 0x8017c7ec    |
0x80174118 | 0x0C  | Change Equipment   | 0x8017c7f4    |

Return locations

BATTLE.BIN
 0017c3cc: Call_Attack_Preparation_(ability_selected)  r4 Misc Unit 0x15c / r5 Misc Unit 0x15c / r6 = 0x00
 0017c414: Call_Attack_Preparation_(AT_list_preview)   r4 AI 0x1c         / r5 Battle 0x16e    / r6 = 0x01
 0018f254: Mimic_ability_setting                       r4 = Stack 0x20    / r5 = Battle 0x16e  / r6 = 0x01