Difference between revisions of "Initialize Deployed Units' Data"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(far more commented)
m
Line 1: Line 1:
 
<font face='Courier New'>
 
<font face='Courier New'>
 
  # Parameters:
 
  # Parameters:
  #  r4: Pointer (to list of Party IDs?)
+
  #  r4: Pointer to Deployed Unit Map Coordinate Data
  #  r5: 0 if normal deployment or 1 if World Debug Battle Style
+
  #  r5: 0 if normal deployment or 1 if deploying the Red Team for World Debug Battle Style
 
   
 
   
 
  0017f388: 27bdff98 addiu r29,r29,0xff98
 
  0017f388: 27bdff98 addiu r29,r29,0xff98

Revision as of 03:19, 18 May 2025

# Parameters:
#  r4: Pointer to Deployed Unit Map Coordinate Data
#  r5: 0 if normal deployment or 1 if deploying the Red Team for World Debug Battle Style

0017f388: 27bdff98 addiu r29,r29,0xff98
0017f38c: afbe0060 sw r30,0x0060(r29)
0017f390: 00a0f021 addu r30,r5,r0
0017f394: afb7005c sw r23,0x005c(r29)
0017f398: 0000b821 addu r23,r0,r0
0017f39c: afb50054 sw r21,0x0054(r29)
0017f3a0: afbf0064 sw r31,0x0064(r29)
0017f3a4: afb60058 sw r22,0x0058(r29)
0017f3a8: afb40050 sw r20,0x0050(r29)
0017f3ac: afb3004c sw r19,0x004c(r29)
0017f3b0: afb20048 sw r18,0x0048(r29)
0017f3b4: afb10044 sw r17,0x0044(r29)
0017f3b8: afb00040 sw r16,0x0040(r29)
0017f3bc: 3c018006 lui r1,0x8006
0017f3c0: ac246234 sw r4,0x6234(r1)                            # Save pointer to Deployed Unit Map Coordinate Data			
0017f3c4: 13c00006 beq r30,r0,0x0017f3e0                       # Branch if preset value is 0: normal deployment
0017f3c8: 34150001 ori r21,r0,0x0001                           # r21 = 1

## WORLD DEBUG BATTLE STYLE: 
0017f3cc: 341600fe ori r22,r0,0x00fe                           # r22 = 0xFE
0017f3d0: 2408ffff addiu r8,r0,0xffff                          # r8 = -1
0017f3d4: afa80030 sw r8,0x0030(r29)                           # Stack Offset 0x30 = -1
0017f3d8: 0805fcfd j 0x0017f3f4
0017f3dc: afa00038 sw r0,0x0038(r29)                           # Initial Battle Stats slot: 0 (ENTD Unit #1)

## NORMAL DEPLOYMENT: 
0017f3e0: 34160078 ori r22,r0,0x0078                           # r22 = 0x78
0017f3e4: 34080001 ori r8,r0,0x0001                            # r8 = 1
0017f3e8: afa80030 sw r8,0x0030(r29)                           # Stack Offset 0x30 = 1
0017f3ec: 34080010 ori r8,r0,0x0010                            # r8 = 0x10
0017f3f0: afa80038 sw r8,0x0038(r29)                           # Initial Battle Stats slot: 0x10 (Player Unit #1)

## PREPARE BATTLE STATS POINTER AND INITIALIZE JOB DATA
0017f3f4: 00009021 addu r18,r0,r0                              # r18 = 0 (unit counter)
0017f3f8: 341400ff ori r20,r0,0x00ff                           # r20 = 0xFF
0017f3fc: 00009821 addu r19,r0,r0                              # r19 = 0 
0017f400: 8fa80038 lw r8,0x0038(r29)                           # r8 = Stack Offset 0x38 (0 or 0x10)
0017f404: 3c038019 lui r3,0x8019
0017f408: 246308cc addiu r3,r3,0x08cc                          # r3 = Battle Stats starting address
0017f40c: 02488821 addu r17,r18,r8                             # r17 = Unit counter + initial Battle Stats slot
0017f410: 001110c0 sll r2,r17,0x03                             # * 8
0017f414: 00511023 subu r2,r2,r17                              # * 7
0017f418: 00021180 sll r2,r2,0x06                              # * 0x1C0
0017f41c: 00438021 addu r16,r2,r3                              # r16 = this unit's Battle Stats
0017f420: a211018a sb r17,0x018a(r16)			        # Store ENTD ID
0017f424: 3c028006 lui r2,0x8006
0017f428: 8c426234 lw r2,0x6234(r2)                            # Load pointer to Deployed Unit Map Coordinate Data
0017f42c: 00000000 nop
0017f430: 02621021 addu r2,r19,r2                              # r2 = pointer to this unit's Deployed Map Coordinate Data
0017f434: 90420000 lbu r2,0x0000(r2)                           # Load Party ID for this unit
0017f438: 00000000 nop
0017f43c: 1054004c beq r2,r20,0x0017f570                       # branch if party ID = 0xff
0017f440: 34080001 ori r8,r0,0x0001
0017f444: a2110001 sb r17,0x0001(r16)                          # store Unit ID = ENTD ID?
0017f448: a2080183 sb r8,0x0183(r16)                           # store unit exists
0017f44c: 3c028006 lui r2,0x8006
0017f450: 8c426234 lw r2,0x6234(r2)                            # Load pointer to Deployed Unit Map Coordinate Data
0017f454: 02002021 addu r4,r16,r0                              # r4 = this unit's Battle Stats
0017f458: 02621021 addu r2,r19,r2                              # r2 = pointer to this unit's Deployed Map Coordinate Data
0017f45c: 90450000 lbu r5,0x0000(r2)                           # load Party ID
0017f460: 0c016a35 jal 0x0005a8d4				# Initialize Unit's Job Data
0017f464: 00003021 addu r6,r0,r0                               # r6 = 0
0017f468: 10400005 beq r2,r0,0x0017f480                        # Branch if r2 = 0 (success)
0017f46c: 02202021 addu r4,r17,r0                              # r4 = ENTD ID?

## INVALID JOB DATA
0017f470: 0c017a3a jal 0x0005e8e8                              # Run a deleted routine, setting r5 to r4's value and r4 to 3 xfer r4 to r5, r4 = 0x03
0017f474: 262401f4 addiu r4,r17,0x01f4                         # r4 = ENTD ID + 0x1f4
0017f478: 0805fd5c j 0x0017f570                                # Jump to INITIALIZATION FAILURE
0017f47c: 02f5b821 addu r23,r23,r21                            # r23 = r23 + r21

## VALIDATE MAP COORDINATES
0017f480: 3c058006 lui r5,0x8006
0017f484: 8ca56234 lw r5,0x6234(r5)                            # Load pointer to Deployed Unit Map Coordinate Data
0017f488: 0c05fd90 jal 0x0017f640                              # Set unit placement and validate map location
0017f48c: 02652821 addu r5,r19,r5                              # r5 = pointer to this unit's Deployed Map Coordinate Data
0017f490: 10400005 beq r2,r0,0x0017f4a8                        # Branch if map coordinates are valid
0017f494: 02002021 addu r4,r16,r0                              # r4 = this unit's Battle Stats

## INVALID MAP COORDINATES
0017f498: 0c017a3a jal 0x0005e8e8                              # Run a deleted routine, setting r5 to r4's value and r4 to 3 xfer r4 to r5, r4 = 0x03
0017f49c: 26240190 addiu r4,r17,0x0190                         # r4 = ENTD ID + 0x190
0017f4a0: 0805fd5c j 0x0017f570                                # Jump to INITIALIZATION FAILURE
0017f4a4: 02f5b821 addu r23,r23,r21                            # r23 = r23 + r21

## STORE UNIT ID
0017f4a8: 0c017822 jal 0x0005e088                              # Calculate Unit's Palette/Portrait (return Portrait)
0017f4ac: 27a50028 addiu r5,r29,0x0028                         # r5 = Stack Pointer + 0x28
0017f4b0: 92030000 lbu r3,0x0000(r16)                          # r3 = load spriteset
0017f4b4: 00403021 addu r6,r2,r0                               # r6 = Portrait
0017f4b8: 306200ff andi r2,r3,0x00ff
0017f4bc: 10400003 beq r2,r0,0x0017f4cc                        # branch if spriteset = 0x00 (nonexistent)
0017f4c0: 2c420004 sltiu r2,r2,0x0004
0017f4c4: 14400004 bne r2,r0,0x0017f4d8                        # Branch if a Ramza sprite: save portrait ID as unit ID instead of 0x78+
0017f4c8: 00000000 nop
0017f4cc: 8fa80030 lw r8,0x0030(r29)                           # Load Stack Offset 0x30
0017f4d0: 02c01821 addu r3,r22,r0
0017f4d4: 0068b021 addu r22,r3,r8
0017f4d8: 13c00006 beq r30,r0,0x0017f4f4                       # Branch if preset value = 0 (normal deployment)
0017f4dc: a2030161 sb r3,0x0161(r16)                           # store Unit ID (portrait ID if Ramza, 0x78+ if normal deployment, else 0xFE(+?))

## WORLD DEBUG BATTLE STYLE: Set team and palette for these units
0017f4e0: 34020018 ori r2,r0,0x0018
0017f4e4: 34080001 ori r8,r0,0x0001
0017f4e8: a2020005 sb r2,0x0005(r16)                           # store ENTD flags = 0x18 (red team and control)
0017f4ec: a20201ba sb r2,0x01ba(r16)                           # store modified ENTD flags
0017f4f0: a2080004 sb r8,0x0004(r16)                           # Store palette = player team

## CHECK FOR 0x10 FLAG IN FACING/ELEVATION
0017f4f4: 3c028006 lui r2,0x8006
0017f4f8: 8c426234 lw r2,0x6234(r2)                            # Load pointer to Deployed Unit Map Coordinate Data
0017f4fc: 00000000 nop
0017f500: 02621021 addu r2,r19,r2                              # r2 = pointer to this unit's Deployed Map Coordinate Data
0017f504: 90420003 lbu r2,0x0003(r2)                           # Load facing/elevation from unit's Deployed Map Coordinate Data
0017f508: 00000000 nop
0017f50c: 30420010 andi r2,r2,0x0010                           # Check for the 0x10 flag (purpose unknown)
0017f510: 10400004 beq r2,r0,0x0017f524                        # Branch if no 0x10 flag
0017f514: 30c200ff andi r2,r6,0x00ff

## 0x10 FLAG IN FACING/ELEVATION
0017f518: a2000183 sb r0,0x0183(r16)                           # store unit doesn't exist, but can later?
0017f51c: 0805fd5e j 0x0017f578                                # Jump to CHECK NEXT UNIT
0017f520: a2140001 sb r20,0x0001(r16)                          # store unit ID = 0xff 

## UNKNOWN, STAT CAPPING AND ETC.
0017f524: 92040047 lbu r4,0x0047(r16)
0017f528: 92050048 lbu r5,0x0048(r16)
0017f52c: 96070048 lhu r7,0x0048(r16)			        # Load map location data
0017f530: afa20010 sw r2,0x0010(r29)
0017f534: 93a20028 lbu r2,0x0028(r29)
0017f538: afb40018 sw r20,0x0018(r29)
0017f53c: afb0001c sw r16,0x001c(r29)
0017f540: afa00020 sw r0,0x0020(r29)
0017f544: 000733c2 srl r6,r7,0x0f
0017f548: 00073a02 srl r7,r7,0x08
0017f54c: 30e7000f andi r7,r7,0x000f
0017f550: 0c023950 jal 0x0008e540                              # 0008e540 - 0008e6cc ???
0017f554: afa20014 sw r2,0x0014(r29)
0017f558: 02002021 addu r4,r16,r0
0017f55c: 0c0177f5 jal 0x0005dfd4				# Minimum SP Capping/War Trophy Nulling/Status Initialization
0017f560: 34050001 ori r5,r0,0x0001
0017f564: 34080001 ori r8,r0,0x0001
0017f568: 0805fd5e j 0x0017f578                                # Jump to CHECK NEXT UNIT
0017f56c: a2080183 sb r8,0x0183(r16)                           # store unit exists

## INITIALIZATION FAILURE
0017f570: a2140001 sb r20,0x0001(r16)                          # store unit ID = 0xff
0017f574: a2140183 sb r20,0x0183(r16)                          # store unit cannot appear in battle

## CHECK NEXT UNIT
0017f578: 26730004 addiu r19,r19,0x0004                        # Current Unit (for map coordinate data) ++
0017f57c: 26520001 addiu r18,r18,0x0001                        # Current Unit ++
0017f580: 2a420005 slti r2,r18,0x0005                          # 
0017f584: 1440ff9e bne r2,r0,0x0017f400                        # Loop back if the maximum number of deployed units haven't been checked yet
0017f588: 0015a840 sll r21,r21,0x01                            # r21 * 2
0017f58c: 13c0000d beq r30,r0,0x0017f5c4                       # Branch to end if Preset Value is 0 (just a normal deployment)
0017f590: 02e01021 addu r2,r23,r0                              # r2 = r23

## WORLD DEBUG BATTLE STYLE: Remove all units in Battle Stats ENTD Slots #6-16
0017f594: 34120005 ori r18,r0,0x0005                           # r18 = 5
0017f598: 340400ff ori r4,r0,0x00ff                            # r4 = 0xFF
0017f59c: 3c038019 lui r3,0x8019
0017f5a0: 2463118c addiu r3,r3,0x118c				# r3 = Battle Stats ENTD slot #6
0017f5a4: a072018a sb r18,0x018a(r3)				# store ENTD = 0x05
0017f5a8: a0640001 sb r4,0x0001(r3)                            # store Unit ID = 0xff
0017f5ac: a0640183 sb r4,0x0183(r3)                            # store unit doesn't exist
0017f5b0: 26520001 addiu r18,r18,0x0001
0017f5b4: 2a420010 slti r2,r18,0x0010
0017f5b8: 1440fffa bne r2,r0,0x0017f5a4                        # perform for the rest of the ENTD slots in Battle Stats
0017f5bc: 246301c0 addiu r3,r3,0x01c0
0017f5c0: 02e01021 addu r2,r23,r0                              # r2 = r23

## END
0017f5c4: 8fbf0064 lw r31,0x0064(r29)
0017f5c8: 8fbe0060 lw r30,0x0060(r29)
0017f5cc: 8fb7005c lw r23,0x005c(r29)
0017f5d0: 8fb60058 lw r22,0x0058(r29)
0017f5d4: 8fb50054 lw r21,0x0054(r29)
0017f5d8: 8fb40050 lw r20,0x0050(r29)
0017f5dc: 8fb3004c lw r19,0x004c(r29)
0017f5e0: 8fb20048 lw r18,0x0048(r29)
0017f5e4: 8fb10044 lw r17,0x0044(r29)
0017f5e8: 8fb00040 lw r16,0x0040(r29)
0017f5ec: 27bd0068 addiu r29,r29,0x0068
0017f5f0: 03e00008 jr r31
0017f5f4: 00000000 nop

Return Locations

0x0017f610: Initialize ENTD units
0x0017f630: Initialize deployed units