Find Next Text Character

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: FIND NEXT TEXT CHARACTER
#       Finds the next character of an FFT text string.  Takes jumping into account (0xF0 - 0xF3)?
#       Parameters: 
#           r4 = Struct? (Stored in scratchpad)?
#               Struct data, on breakpoint when about to display "Charging" text: (Runs once per character of the text)
#                   0x00 (1 byte): (Though never loaded in this routine) is equal to the current character of the text "Charging"
#                   0x14 (4 bytes) = ? (Starts equal to 0x10100404)
#                   0x18 (4 bytes) = ? Starts equal to 0
#                   0x1c (4 bytes) = ? Starts equal to -1
#           r5 = [Character pointer] (Pointer to current character)
#       Returns:
#           r2 = ? (Next character pointer?)

0014ba28: 8c820018 lw r2,0x0018(r4)             #   [Parameter 1].0x18 (Zero when loading "Charging" text)
0014ba2c: 00000000 nop
0014ba30: 18400007 blez r2,0x0014ba50
0014ba34: 24a50001 addiu r5,r5,0x0001           #   [Character pointer] = [Pointer to next character]
                                                #   if ([Parameter 1].0x18 > 0) {
0014ba38: 2442ffff addiu r2,r2,-0x0001          #       [Parameter 1].0x18 - 1
0014ba3c: 14400004 bne r2,r0,0x0014ba50         
0014ba40: ac820018 sw r2,0x0018(r4)
                                                #       if (([Parameter 1].0x18 - 1) == 0) {
0014ba44: 8c85001c lw r5,0x001c(r4)             #           [Character pointer] = [Parameter 1].0x1c
0014ba48: 2402ffff addiu r2,r0,-0x0001          #           -1
0014ba4c: ac82001c sw r2,0x001c(r4)                         [Parameter 1].0x1c = -1
                                                #       }
                                                #   }
0014ba50: 90a60000 lbu r6,0x0000(r5)            #   [Current character] = (Byte loaded from [Character pointer])
0014ba54: 340200f0 ori r2,r0,0x00f0
0014ba58: 30c300f0 andi r3,r6,0x00f0
0014ba5c: 1462001f bne r3,r2,0x0014badc         #   if (([Current character] & 0xF0 == 0xF0)  // Check for special value?
0014ba60: 00000000 nop                          
0014ba64: 30c2000f andi r2,r6,0x000f
0014ba68: 2c420004 sltiu r2,r2,0x0004
0014ba6c: 1040001b beq r2,r0,0x0014badc         #       AND ([Current character] & 0x0F < 4))
0014ba70: 00000000 nop                          #   {
                                        
                                                #       (To get to this section, [Current character] must be between 0xF0 - 0xF3, inclusive)
                                                
0014ba74: 24a20003 addiu r2,r5,0x0003           #       [Character pointer] + 3
0014ba78: ac82001c sw r2,0x001c(r4)             #       [Parameter 1].0x1c = [Character pointer] + 3
0014ba7c: 90a20000 lbu r2,0x0000(r5)            #       [Current character]
0014ba80: 00000000 nop
0014ba84: 30420003 andi r2,r2,0x0003            #       [Current character] & 0x03 (Last 2 bits)
0014ba88: 000210c0 sll r2,r2,0x03               #       ([Current character] & 0x03) * 8
0014ba8c: ac820014 sw r2,0x0014(r4)             #       [Parameter 1].0x14 = ([Current character] & 0x03) * 8
0014ba90: 90a20001 lbu r2,0x0001(r5)            #       [Next character]
0014ba94: 8c830014 lw r3,0x0014(r4)             #       [Parameter 1].0x14
0014ba98: 00021142 srl r2,r2,0x05               #       [Next character] >> 5
0014ba9c: ac820018 sw r2,0x0018(r4)             #       [Parameter 1].0x18 = [Next character] >> 5
0014baa0: 00431021 addu r2,r2,r3                #       ([Next character] >> 5) + [Parameter 1].0x14
0014baa4: 24420004 addiu r2,r2,0x0004           #       ([Next character] >> 5) + [Parameter 1].0x14 + 4
0014baa8: ac820018 sw r2,0x0018(r4)             #       [Parameter 1].0x18 = ([Next character] >> 5) + [Parameter 1].0x14 + 4
0014baac: 90a20001 lbu r2,0x0001(r5)            #       [Next character]
0014bab0: 00000000 nop
0014bab4: 3042000f andi r2,r2,0x000f            #       [Next character] & 0x0F
0014bab8: 000219c0 sll r3,r2,0x07               #       ([Next character] & 0x0F) * 128
0014babc: 00621823 subu r3,r3,r2                #       ([Next character] & 0x0F) * 127
0014bac0: 00031840 sll r3,r3,0x01               #       ([Next character] & 0x0F) * 254
0014bac4: ac830014 sw r3,0x0014(r4)             #       [Parameter 1].0x14 = ([Next character] & 0x0F) * 254
0014bac8: 90a20002 lbu r2,0x0002(r5)            #       [Character after next character]
0014bacc: 00000000 nop
0014bad0: 00431021 addu r2,r2,r3                #       [Character after next character] + ([Next character] & 0x0F) * 254
0014bad4: 00a22823 subu r5,r5,r2                #       [Character pointer] = [Character pointer] - ([Character after next character] + ([Next character] & 0x0F) * 254)
0014bad8: ac820014 sw r2,0x0014(r4)             #       [Parameter 1].0x14 = [Character after next character] + ([Next character] & 0x0F) * 254
                                                #   }
                                                
0014badc: 03e00008 jr r31                       #   return [Character pointer]
0014bae0: 00a01021 addu r2,r5,r0