Find Event Instruction Byte Offset

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: FIND EVENT INSTRUCTION BYTE OFFSET
#       Finds the next byte offset in the current event, from the specified starting point, of the specified instruction ID.
#       Parameters:
#           r4 = (p_startingByteOffset) Byte offset to start at
#           r5 = (p_instructionID)      Instruction ID to find the byte offset for

80149ebc: 3c068017 lui r6,0x8017
80149ec0: 8cc63ca4 lw r6,0x3ca4(r6)             #   eventBasePtr (*0x80173ca4)
80149ec4: 340700db ori r7,r0,0x00db             #   0xdb                                            // EventEnd instruction ID
                                                #   byteOffset = startingByteOffset
                                                #   while (true) {
80149ec8: 00c41021 addu r2,r6,r4                #       instructionPtr = eventBasePtr + p_startingByteOffset
80149ecc: 90420000 lbu r2,0x0000(r2)            #       instructionID = *(instructionPtr)
80149ed0: 00000000 nop
80149ed4: 14470003 bne r2,r7,0x80149ee4         #       if (instructionID == 0xdb) {                // EventEnd
80149ed8: 00000000 nop
80149edc: 080527c2 j 0x80149f08                 #           return 0;
80149ee0: 00001021 addu r2,r0,r0
                                                #       }
80149ee4: 10450007 beq r2,r5,0x80149f04         #       if (instructionID == p_instructionID) break;
80149ee8: 00000000 nop
80149eec: 3c018015 lui r1,0x8015
80149ef0: 00220821 addu r1,r1,r2
80149ef4: 9023d170 lbu r3,-0x2e90(r1)           #       eventParameterLengthArray[instructionID]    // = Number of total bytes the parameters are for this instruction ID
80149ef8: 24820001 addiu r2,r4,0x0001           #       byteOffset + 1
80149efc: 080527b2 j 0x80149ec8
80149f00: 00432021 addu r4,r2,r3                #       byteOffset = (byteOffset + 1) + eventParameterLengthArray[instructionID]
                                                #   }
80149f04: 00801021 addu r2,r4,r0                #   return byteOffset;
                                               
80149f08: 03e00008 jr r31
80149f0c: 00000000 nop