Big map/panel routine
Jump to navigation
Jump to search
This routine searches for a new destination for a unit around its point of origin. (For example to relocate the body of a dead rider around is chocobo) This routine set Targetable grid (0x80192dd8) byte 0x02 to 0x01 if There is a unit on the panel ----------------------------------------------------------------- Parameters r4 = Unit Raw ID (Unit data 0x18a) Returns r2 = 0x00 if Tile to relocated is found and set r2 = -0x01 if No destination has been found ---------------------------------------------------------------- 0017ec18: 27bdffc0 addiu r29,r29,-0x0040 | 0017ec1c: afb40028 sw r20,0x0028(r29) | 0017ec20: 0080a021 addu r20,r4,r0 |r20 = Unit raw ID (Unit data 0x18a) 0017ec24: afb1001c sw r17,0x001c(r29) | 0017ec28: 00a08821 addu r17,r5,r0 |r17 = Misc Unit 0x184 pointer 0017ec2c: 001410c0 sll r2,r20,0x03 |Unit ID * 8 0017ec30: 00541023 subu r2,r2,r20 |Unit ID * 7 0017ec34: 00021180 sll r2,r2,0x06 |Unit ID * 448 0017ec38: 3c038019 lui r3,0x8019 | 0017ec3c: 246308cc addiu r3,r3,0x08cc |0x801908cc (start of unit data - size per unit = 448) 0017ec40: 00432021 addu r4,r2,r3 |r4 = Unit data pointer 0017ec44: 340209fb ori r2,r0,0x09fb |r2 = 0x9fb (last panel offset in targetable panel grid data table) 0x200 panel with 0x05 bytes of data 0017ec48: afbf0038 sw r31,0x0038(r29) | 0017ec4c: afb70034 sw r23,0x0034(r29) | 0017ec50: afb60030 sw r22,0x0030(r29) | 0017ec54: afb5002c sw r21,0x002c(r29) | 0017ec58: afb30024 sw r19,0x0024(r29) | 0017ec5c: afb20020 sw r18,0x0020(r29) | 0017ec60: afb00018 sw r16,0x0018(r29) | 0017ec64: 90970047 lbu r23,0x0047(r4) |r23 = Unit X coordinates 0017ec68: 90960048 lbu r22,0x0048(r4) |r22 = Unit Y coordinates 0017ec6c: 3c018019 lui r1,0x8019 @LOOP - though all panel of targetable grid and clear nb of units 0017ec70: 00220821 addu r1,r1,r2 |r1 = 0x801909fb last panel data pointer 0017ec74: a0202dda sb r0,0x2dda(r1) |Nullify this iteration panel nb of unit 0x80192dd8 + 0x02 = number of unit on panel 0017ec78: 2442fffb addiu r2,r2,-0x0005 |Previous panel offset 0017ec7c: 0441fffb bgez r2,0x0017ec6c Λ Loop until first panel offset 0017ec80: 00008021 addu r16,r0,r0 |Initialize loop counter 0017ec84: 00009021 addu r18,r0,r0 |Initialize unit offset 0017ec88: 3c028019 lui r2,0x8019 @LOOP through all units set r19 and r20 when unit of interest is found 0017ec8c: 244208cc addiu r2,r2,0x08cc |r2 = Start of unit data 0017ec90: 02422021 addu r4,r18,r2 |r4 = this iteration unit data pointer 0017ec94: 90830001 lbu r3,0x0001(r4) |r3 = Unit ID 0017ec98: 340200ff ori r2,r0,0x00ff | 0017ec9c: 1062001b beq r3,r2,0x0017ed0c #If This iteration unit still exists 0017eca0: 00000000 nop | 0017eca4: 0c060428 jal 0x001810a0 |-->Map_Location_Calculation returns r2 = unit Tile ID 0017eca8: 00000000 nop | 0017ecac: 00403021 addu r6,r2,r0 |r6 = Unit's Tile ID 0017ecb0: 00061080 sll r2,r6,0x02 |Tile ID * 4 0017ecb4: 00461021 addu r2,r2,r6 |Tile ID * 5 0017ecb8: 3c038019 lui r3,0x8019 | 0017ecbc: 24632dd8 addiu r3,r3,0x2dd8 |Start of Targetable panel grid 0017ecc0: 00432021 addu r4,r2,r3 |r4 = Unit's Targetable panel pointer 0017ecc4: 000618c0 sll r3,r6,0x03 |Tile ID * 8 0017ecc8: 3c028019 lui r2,0x8019 | 0017eccc: 2442f8cc addiu r2,r2,0xf8cc |Start of Tile's data 0017ecd0: 1614000c bne r16,r20,0x0017ed04 #if Loop counter = Unit of interest ID 0017ecd4: 00623821 addu r7,r3,r2 |r7 = Unit's Tile data pointer 0017ecd8: 90e30002 lbu r3,0x0002(r7) |Load Unit Tile's Height 0017ecdc: 90e20003 lbu r2,0x0003(r7) |Load Unit Tile's Halves + depth 0017ece0: 00031840 sll r3,r3,0x01 |Tile's Height *2 0017ece4: 3042001f andi r2,r2,0x001f |Tile's Halves 0017ece8: 00621821 addu r3,r3,r2 |r3 = Unit's Tile's Total height 0017ecec: 2473fff6 addiu r19,r3,-0x000a |r19 = Tile's height - 10 (Min allowed destination height) 0017ecf0: 06610002 bgez r19,0x0017ecfc #if Unit's Tile's Height - 10 is less than 0 0017ecf4: 24750004 addiu r21,r3,0x0004 |r21 = Tile's height + 4 (Max allowed destination Height) 0017ecf8: 00009821 addu r19,r0,r0 |Force minimal height to 0x00 0017ecfc: 0805fb44 j 0x0017ed10 >>Jump to next iteration 0017ed00: 26100001 addiu r16,r16,0x0001 |Loop counter + 1 #Else - Not unit of interest 0017ed04: 34020001 ori r2,r0,0x0001 |r2 = 0x01 0017ed08: a0820002 sb r2,0x0002(r4) |Set Number of unit in Unit's targetable panel to 0x01 0017ed0c: 26100001 addiu r16,r16,0x0001 #E #E | Loop counter + 1 0017ed10: 2a020015 slti r2,r16,0x0015 |Check loop limit 0017ed14: 1440ffdc bne r2,r0,0x0017ec88 Λ loop 0x15 times (all units) 0017ed18: 265201c0 addiu r18,r18,0x01c0 |Increase unit offset 0017ed1c: 3c028019 lui r2,0x8019 | 0017ed20: 8c42f4f4 lw r2,-0x0b0c(r2) |Number of Relocated units 8018f4f4 / 0x8018f4f4 0017ed24: 00000000 nop | 0017ed28: 18400021 blez r2,0x0017edb0 #If There's relocated units /Else avoid loop 0017ed2c: 00008021 addu r16,r0,r0 |Initialize counter 0017ed30: 3c088019 lui r8,0x8019 | 0017ed34: 25082dd8 addiu r8,r8,0x2dd8 |Start of Targetable panel grid 0017ed38: 34070001 ori r7,r0,0x0001 |r7 = 0x01 0017ed3c: 00002821 addu r5,r0,r0 |Unit's coordinates offset in Table of relocated unit's ( 0x80193880 ) 80193880 0017ed40: 3c018019 lui r1,0x8019 @Loop - Flag relocated units on targetable panel grid 0017ed44: 00250821 addu r1,r1,r5 |Loop offset 0017ed48: 90233881 lbu r3,0x3881(r1) |Load this iteration relocated unit's Y coordinates 0017ed4c: 3c02800e lui r2,0x800e | 0017ed50: 90424e9c lbu r2,0x4e9c(r2) |Load Map max X 0017ed54: 00000000 nop | 0017ed58: 00620018 mult r3,r2 |Y * Map Max X 0017ed5c: 26100001 addiu r16,r16,0x0001 |Counter + 1 0017ed60: 3c018019 lui r1,0x8019 | 0017ed64: 00250821 addu r1,r1,r5 | 0017ed68: 90233882 lbu r3,0x3882(r1) |Load this iteration relocated unit's Elevation 0017ed6c: 3c018019 lui r1,0x8019 | 0017ed70: 00250821 addu r1,r1,r5 | 0017ed74: 90243880 lbu r4,0x3880(r1) |Load this iteration relocated unit's X coordinates 0017ed78: 00031a00 sll r3,r3,0x08 |Elevation is 0x00 or 0x100 0017ed7c: 00001012 mflo r2 |r2 = Y * Map Max X 0017ed80: 00621821 addu r3,r3,r2 |Y * Max X + elevation 0017ed84: 00643021 addu r6,r3,r4 |This iteration relocated unit's tile ID (Y * Map X + X + Elevation) 0017ed88: 00061080 sll r2,r6,0x02 |Tile ID * 4 0017ed8c: 00461021 addu r2,r2,r6 |Tile ID * 5 (offset of data in targetable grid) 0017ed90: 00482021 addu r4,r2,r8 | This iteration Unit Targetable grid's Panel data pointer (matching data stored at 0x80193880) 0017ed94: a0870002 sb r7,0x0002(r4) |Store unit Number on dead rider's panel = 0x01 0017ed98: 3c028019 lui r2,0x8019 | 0017ed9c: 8c42f4f4 lw r2,-0x0b0c(r2) |Number of Relocated units 0017eda0: 00000000 nop | 0017eda4: 0202102a slt r2,r16,r2 |Check counter limit (Nb of relocated units) 0017eda8: 1440ffe5 bne r2,r0,0x0017ed40 Λ loop 0017edac: 24a50003 addiu r5,r5,0x0003 |Panel Offset in panel data 0x3880 0017edb0: 00007821 addu r15,r0,r0 |Initialize LOOP 1 counter @LOOP1 - 2 iteration just set loop 2 limit 0017edb4: 11e00002 beq r15,r0,0x0017edc0 #If First Loop 0017edb8: 34120004 ori r18,r0,0x0004 |r18 = 0x04 (loop 2 limit) 0017edbc: 34120011 ori r18,r0,0x0011 |r18 = 0x11 (loop 2 limit) 0017edc0: 34100001 ori r16,r0,0x0001 |r16 = 0x01 (Loop 2 counter) 0017edc4: 0212102a slt r2,r16,r18 |Check if loop 2 counter is less than its limit 0017edc8: 10400085 beq r2,r0,0x0017efe0 #If limit is not reached (never ?) 0017edcc: 00000000 nop | @LOOP 2 -Proximity Loop - Start at 0x01 (next to point of origin) until 0x04 - then exit loop and come back to 0x11 (whole map ?) 0017edd0: 00104823 subu r9,r0,r16 |Initialize Loop 3 counter at - Loop2 counter 0017edd4: 0209102a slt r2,r16,r9 |Check limits 0017edd8: 1440007d bne r2,r0,0x0017efd0 #If limit not already reached ? (never ?) 0017eddc: 00000000 nop | @LOOP 3 - X coordinates- Counter is r9 (aka Xmod) - [loop for Xmod = -loop2 counter to loop 2 counter] 0017ede0: 02e95821 addu r11,r23,r9 |This iteration X = Unit X coordinates - X mod 0017ede4: 05600076 bltz r11,0x0017efc0 #If This iteration X is >= 0x00 0017ede8: 00000000 nop | 0017edec: 3c02800e lui r2,0x800e | 0017edf0: 90424e9c lbu r2,0x4e9c(r2) |Load Map Max X 0017edf4: 00000000 nop | 0017edf8: 0162102a slt r2,r11,r2 |Check if X is Less than Max X 0017edfc: 10400070 beq r2,r0,0x0017efc0 #If X is Valid (< Max X) 0017ee00: 00000000 nop | 0017ee04: 1d200002 bgtz r9,0x0017ee10 |if r9 <= 0x00 0017ee08: 02096823 subu r13,r16,r9 |Ymod Start at 0x00 increase to r16 and decrease to 0x00 at last loop3 0017ee0c: 02096821 addu r13,r16,r9 |Y mod 0017ee10: 240affff addiu r10,r0,-0x0001 |r10 = -0x01 Loop 4 counter 0017ee14: 01607021 addu r14,r11,r0 |r14 = This iteration X coordinates 0017ee18: 02cd4023 subu r8,r22,r13 |Y coord = Unit Y - Y mod @LOOP 4 - Y coordinates - Counter is r10 - 2 iterations (-Ymod and + Ymod) 0017ee1c: 05000063 bltz r8,0x0017efac #If This iteration Y is >= 0x00 0017ee20: 000d1040 sll r2,r13,0x01 |r2 = r13 * 2 0017ee24: 3c02800e lui r2,0x800e | 0017ee28: 90424ea0 lbu r2,0x4ea0(r2) |Load Map Max Y 0017ee2c: 00000000 nop | 0017ee30: 0102102a slt r2,r8,r2 |Check if Y is valid 0017ee34: 1040005d beq r2,r0,0x0017efac #If Y is Valid (< Max Y) 0017ee38: 000d1040 sll r2,r13,0x01 |r2 = r13 * 2 0017ee3c: 00002021 addu r4,r0,r0 |Initialize Elevation offset 0017ee40: 01006021 addu r12,r8,r0 |r12 = This iteration Y coordinates 0017ee44: 3c02800e lui r2,0x800e @ Elevation LOOP - 2 iteration (0 and 1) 0017ee48: 90424e9c lbu r2,0x4e9c(r2) |Load Map Max X 0017ee4c: 00000000 nop | 0017ee50: 00480018 mult r2,r8 |Y * Max X 0017ee54: 00041a00 sll r3,r4,0x08 |Elevation is 0x00 or 0x100 0017ee58: 00001012 mflo r2 | 0017ee5c: 00621821 addu r3,r3,r2 | 0017ee60: 006b3021 addu r6,r3,r11 |r6 = Tile ID (X + Y*Max X + Elevation) 0017ee64: 000618c0 sll r3,r6,0x03 |Tile ID * 8 0017ee68: 3c028019 lui r2,0x8019 | 0017ee6c: 2442f8cc addiu r2,r2,0xf8cc |Start of Tile's data 0017ee70: 00623821 addu r7,r3,r2 |This iteration Tile's data pointer 0017ee74: 90e30003 lbu r3,0x0003(r7) |Tile's halves + depth 0017ee78: 00000000 nop | 0017ee7c: 00031142 srl r2,r3,0x05 |r2 <> 0x00 if tile's depth is > 1 0017ee80: 28420003 slti r2,r2,0x0003 |Check if Tile's depth < 3 0017ee84: 10400045 beq r2,r0,0x0017ef9c #If Depth < 0x03 0017ee88: 3063001f andi r3,r3,0x001f |Tile's halves 0017ee8c: 28620003 slti r2,r3,0x0003 |Check if tile's halves < 3 0017ee90: 10400042 beq r2,r0,0x0017ef9c #If Tile's halves < 0x03 0017ee94: 00000000 nop | 0017ee98: 90e50006 lbu r5,0x0006(r7) |r5 = Tile's byte 0x06 0017ee9c: 00000000 nop | 0017eea0: 30a20001 andi r2,r5,0x0001 |Check if tile is selectable 0017eea4: 1440003d bne r2,r0,0x0017ef9c #If Tile is selectable 0017eea8: 30a20002 andi r2,r5,0x0002 |Check if tile can be targeted 0017eeac: 1440003b bne r2,r0,0x0017ef9c #If Tile can be targeted 0017eeb0: 00061080 sll r2,r6,0x02 |Tile ID * 4 0017eeb4: 00461021 addu r2,r2,r6 |Tile ID * 5 0017eeb8: 3c018019 lui r1,0x8019 | 0017eebc: 00220821 addu r1,r1,r2 |8019 + Tile's matching panel offset (in targetable grid) 0017eec0: 90222dda lbu r2,0x2dda(r1) |Load This iteration Panel Nb of Unit 0017eec4: 00000000 nop | 0017eec8: 14400034 bne r2,r0,0x0017ef9c #If There's no units on panel 0017eecc: 00000000 nop | 0017eed0: 90e20000 lbu r2,0x0000(r7) |Load this iteration Tile's Type 0017eed4: 00000000 nop | 0017eed8: 3045003f andi r5,r2,0x003f |Filter just terrain type 0017eedc: 34020012 ori r2,r0,0x0012 |r2 = 0x12 (Lava check) 0017eee0: 10a2002e beq r5,r2,0x0017ef9c #If Tile's terrain is not Lava 0017eee4: 3402001c ori r2,r0,0x001c |0x1c (obstacle) 0017eee8: 10a2002c beq r5,r2,0x0017ef9c #If Tile is not an obstacle 0017eeec: 00000000 nop | 0017eef0: 15e0000a bne r15,r0,0x0017ef1c #If r15 = 0x00 0017eef4: 00000000 nop | 0017eef8: 90e20002 lbu r2,0x0002(r7) |Load Tile's Height 0017eefc: 00000000 nop | 0017ef00: 00021040 sll r2,r2,0x01 |Height * 2 0017ef04: 00431821 addu r3,r2,r3 |Height + Halves 0017ef08: 02a3102a slt r2,r21,r3 |Check if Max allowed Height < Total Height 0017ef0c: 14400023 bne r2,r0,0x0017ef9c #If Tile's Height < Max allowed Height 0017ef10: 0073102a slt r2,r3,r19 |Check is Height is > Min allowed Height 0017ef14: 14400021 bne r2,r0,0x0017ef9c #If Tile's Height is > Min allowed Height 0017ef18: 00000000 nop | 0017ef1c: 3c038019 lui r3,0x8019 | 0017ef20: 8c63f4f4 lw r3,-0x0b0c(r3) |Number of Relocated units Dead riders to relocate counter 0017ef24: a62e0000 sh r14,0x0000(r17) |Store new Unit X coord at Misc Unit 0x184 0017ef28: 00031040 sll r2,r3,0x01 |Relocated unit counter * 2 0017ef2c: 00431021 addu r2,r2,r3 |Relocated unit counter * 3 0017ef30: 3c018019 lui r1,0x8019 | 0017ef34: 00220821 addu r1,r1,r2 |8019 + Unit offset in Coordinate Table 80193880 0017ef38: a02e3880 sb r14,0x3880(r1) |Store new Unit X coord at 80193880 (list of relocated unit coordinates) 0017ef3c: 3c038019 lui r3,0x8019 | 0017ef40: 8c63f4f4 lw r3,-0x0b0c(r3) |Number of Relocated units Dead riders to relocate counter 0017ef44: a62c0004 sh r12,0x0004(r17) |Store new Unit Y coord at Misc Unit 0x188 0017ef48: 00031040 sll r2,r3,0x01 | 0017ef4c: 00431021 addu r2,r2,r3 | 0017ef50: 3c018019 lui r1,0x8019 | 0017ef54: 00220821 addu r1,r1,r2 | 0017ef58: a02c3881 sb r12,0x3881(r1) |Store new Unit Y coord at 80193880 (list of relocated unit coordinates) 0017ef5c: 3c038019 lui r3,0x8019 | 0017ef60: 8c63f4f4 lw r3,-0x0b0c(r3) |Number of Relocated units Dead riders to relocate counter 0017ef64: a6240002 sh r4,0x0002(r17) |Store new Unit Elevation at Misc Unit 0x1886 0017ef68: 00031040 sll r2,r3,0x01 | 0017ef6c: 00431021 addu r2,r2,r3 | 0017ef70: 3c018019 lui r1,0x8019 | 0017ef74: 00220821 addu r1,r1,r2 | 0017ef78: a0243882 sb r4,0x3882(r1) |Store new Unit Elevation at 80193880 (list of relocated unit coordinates) 0017ef7c: 3c038019 lui r3,0x8019 | 0017ef80: 8c63f4f4 lw r3,-0x0b0c(r3) |Number of Relocated units Dead riders to relocate counter 0017ef84: 00000000 nop | 0017ef88: 24630001 addiu r3,r3,0x0001 |Counter +1 0017ef8c: 3c018019 lui r1,0x8019 | 0017ef90: ac23f4f4 sw r3,-0x0b0c(r1) |Store updated counter 0017ef94: 0805fbfc j 0x0017eff0 >>Jump to END 0017ef98: 00001021 addu r2,r0,r0 |r2 = 0x00 0017ef9c: 24840001 addiu r4,r4,0x0001 |Elevation counter + 1 0017efa0: 28820002 slti r2,r4,0x0002 |Check elevation limit (0x00 or 0x01) 0017efa4: 1440ffa7 bne r2,r0,0x0017ee44 Λ loop 2 times (elevation 0 and 1) 0017efa8: 000d1040 sll r2,r13,0x01 |r2 = r13 * 2 0017efac: 01024021 addu r8,r8,r2 |This Y + Ymod * 2 0017efb0: 254a0002 addiu r10,r10,0x0002 |r10 + 2 0017efb4: 29420002 slti r2,r10,0x0002 |Check if r10 < 0x02 0017efb8: 1440ff98 bne r2,r0,0x0017ee1c Λ loop 2 times (r10 is -0x01 then 0x01) 0017efbc: 00000000 nop | 0017efc0: 25290001 addiu r9,r9,0x0001 |r9 + 1 0017efc4: 0209102a slt r2,r16,r9 |Check if Loop 2 counter is less then r9 0017efc8: 1040ff85 beq r2,r0,0x0017ede0 Λ loop while r16 >= r9 0017efcc: 00000000 nop | 0017efd0: 26100001 addiu r16,r16,0x0001 |Loop 2 counter + 1 - tile counter 0017efd4: 0212102a slt r2,r16,r18 |Check 0017efd8: 1440ff7d bne r2,r0,0x0017edd0 Λ loop (4 times and then 17 times) 0017efdc: 00000000 nop | 0017efe0: 25ef0001 addiu r15,r15,0x0001 |Main loop counter +1 0017efe4: 29e20002 slti r2,r15,0x0002 |Check Main loop 0017efe8: 1440ff72 bne r2,r0,0x0017edb4 Λ Loop 2 times 0017efec: 2402ffff addiu r2,r0,0xffff |r2 = -0x01 0017eff0: 8fbf0038 lw r31,0x0038(r29) END 0017eff4: 8fb70034 lw r23,0x0034(r29) 0017eff8: 8fb60030 lw r22,0x0030(r29) 0017effc: 8fb5002c lw r21,0x002c(r29) 0017f000: 8fb40028 lw r20,0x0028(r29) 0017f004: 8fb30024 lw r19,0x0024(r29) 0017f008: 8fb20020 lw r18,0x0020(r29) 0017f00c: 8fb1001c lw r17,0x001c(r29) 0017f010: 8fb00018 lw r16,0x0018(r29) 0017f014: 27bd0040 addiu r29,r29,0x0040 0017f018: 03e00008 jr r31 0017f01c: 00000000 nop
Return locations
Battle.bin 00070f5c: In_between_turn_events 00070f8c: In_between_turn_events 00072248: Main_Post_Movement 00073294: 00073250_-_000732c4 00073c60: Set_some_target_coordinates/attacker_animation,_others - Called if Killing blow on ridding unit
Notes
The word at 0x8019f4f4 seems to be the counter of relocated unit (waiting for something i guess since it's reseted after the next action) The Table at 0x80193880 store the coordinates of this relocated units. 0x00 is X coordinates 0x01 is Y coordinates 0x02 is Elevation