Handle Menu Action

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: HANDLE MENU ACTION
#       Handles taking a menu action?
#       Parameters:
#           r4 = (p1) Struct data for menu (Example values: 0x80166d68, 0x801c38ac)
#           r5 = (p2) (Flag to check?) (Action ID for menu?) (Row index?) ?

80137c10: 3c028016 lui r2,0x8016
80137c14: 94425ff6 lhu r2,0x5ff6(r2)                #   *0x80165ff6
80137c18: 27bdffb0 addiu r29,r29,-0x0050
80137c1c: afb70044 sw r23,0x0044(r29)
80137c20: 00a0b821 addu r23,r5,r0                   #   r23 = p2
80137c24: afb00028 sw r16,0x0028(r29)
80137c28: 34100002 ori r16,r0,0x0002                #   2
80137c2c: afbf004c sw r31,0x004c(r29)
80137c30: afbe0048 sw r30,0x0048(r29)
80137c34: afb60040 sw r22,0x0040(r29)
80137c38: afb5003c sw r21,0x003c(r29)
80137c3c: afb40038 sw r20,0x0038(r29)
80137c40: afb30034 sw r19,0x0034(r29)
80137c44: afb20030 sw r18,0x0030(r29)
80137c48: afb1002c sw r17,0x002c(r29)
80137c4c: 14500007 bne r2,r16,0x80137c6c              
80137c50: afa40010 sw r4,0x0010(r29)                #   p1
                                                    #   if (*0x80165ff6 == 2) {
80137c54: 0c04ed64 jal 0x8013b590                   #       ROUTINE: result = Get Script Variable (40)
80137c58: 34040028 ori r4,r0,0x0028                 #       40
80137c5c: 02e21007 srav r2,r2,r23                   #       result >> p2
80137c60: 30420001 andi r2,r2,0x0001                #       (result >> p2) & 0x01
80137c64: 1440008e bne r2,r0,0x80137ea0             #       if (((result >> p2) & 0x01) != 0), return
80137c68: 00000000 nop
                                                    #   }
80137c6c: 3c028017 lui r2,0x8017
80137c70: 8c4297d0 lw r2,-0x6830(r2)                #   *0x801697d0
80137c74: 00000000 nop
80137c78: 30420020 andi r2,r2,0x0020                #   *0x801697d0 & 0x20                          // Checks if an option was selected?
80137c7c: 10400088 beq r2,r0,0x80137ea0             #   if ((*0x801697d0 & 0x20) == 0), return
80137c80: 0000b021 addu r22,r0,r0                   #   r22 = 0
80137c84: 0c04dee6 jal 0x80137b98                   #   ROUTINE: result = ? 0x137b98
80137c88: 00000000 nop
80137c8c: 10400084 beq r2,r0,0x80137ea0             #   if (result == 0), return
80137c90: 00000000 nop
80137c94: 3c028017 lui r2,0x8017
80137c98: 8c424038 lw r2,0x4038(r2)                 #   threadID
80137c9c: 00000000 nop
80137ca0: 00021a80 sll r3,r2,0x0a                   #   threadOffset = threadID * sizeof(thread)
80137ca4: 3c018017 lui r1,0x8017
80137ca8: 00230821 addu r1,r1,r3                    #   (thread = *(threads + threadOffset))
80137cac: 8c2298c0 lw r2,-0x6740(r1)                #   thread.0x54
80137cb0: 00000000 nop
80137cb4: 14400007 bne r2,r0,0x80137cd4             #   if (thread.0x54 == 0) {
80137cb8: 00000000 nop
80137cbc: 3c018017 lui r1,0x8017
80137cc0: 00230821 addu r1,r1,r3
80137cc4: ac3098c0 sw r16,-0x6740(r1)               #       thread.0x54 = 2
80137cc8: 3c018017 lui r1,0x8017
80137ccc: 00230821 addu r1,r1,r3
80137cd0: ac2098bc sw r0,-0x6744(r1)                #       thread.0x50 = 0
                                                    #   }
80137cd4: 8fa80010 lw r8,0x0010(r29)                #   p1
80137cd8: 00000000 nop
80137cdc: 8d100024 lw r16,0x0024(r8)                #   p1.0x24
80137ce0: 00000000 nop
80137ce4: 2602000f addiu r2,r16,0x000f              #   p1.0x24 + 15
80137ce8: 2c42000f sltiu r2,r2,0x000f                 
80137cec: 14400004 bne r2,r0,0x80137d00
80137cf0: 0200a021 addu r20,r16,r0                  #   r20 = p1
                                                    #   if ((p1.0x24 + 15) >= 15) {
80137cf4: 00171040 sll r2,r23,0x01                  #       p2 * 2
80137cf8: 00501021 addu r2,r2,r16                   #       (p2 * 2) + p1
80137cfc: 84540000 lh r20,0x0000(r2)                #       r20 = *((p2 * 2) + p1)
                                                    #   }
80137d00: 00000000 nop
80137d04: 06800023 bltz r20,0x80137d94          
80137d08: 32821000 andi r2,r20,0x1000               #   r20 & 0x1000
                                                    #   if (r20 >= 0) {
80137d0c: 10400003 beq r2,r0,0x80137d1c             #       if ((r20 & 0x1000) != 0) {
80137d10: 00000000 nop
80137d14: 34160001 ori r22,r0,0x0001                #           r22 = 1
80137d18: 2694f000 addiu r20,r20,-0x1000            #           r20 = r20 - 0x1000
                                                    #       }
80137d1c: 0680001d bltz r20,0x80137d94              #       if (r20 >= 0) {
80137d20: 2a820100 slti r2,r20,0x0100                                 
80137d24: 10400016 beq r2,r0,0x80137d80
80137d28: 00148100 sll r16,r20,0x04                 #           r20 * 16
                                                    #           if (r20 < 0x100) {
80137d2c: 02148023 subu r16,r16,r20                 #               r20 * 15
80137d30: 00108080 sll r16,r16,0x02                 #               r20 * 60
80137d34: 3c028017 lui r2,0x8017
80137d38: 8c423cb8 lw r2,0x3cb8(r2)                 #               *0x80173cb8
80137d3c: 3c048017 lui r4,0x8017
80137d40: 8c844038 lw r4,0x4038(r4)                 #               *0x80174038
80137d44: 02021021 addu r2,r16,r2                   #               *0x80173cb8 + (r20 * 60)
80137d48: 8c450028 lw r5,0x0028(r2)                 #               *(*0x80173cb8 + (r20 * 60) + 0x28)
80137d4c: 0c053228 jal 0x8014c8a0                   #               Initialize Thread (threadID - 1, *(*0x80173cb8 + (r20 * 60) + 0x28)) // Circle button action doesn't work if removed
80137d50: 2484ffff addiu r4,r4,-0x0001              #               *0x80174038 - 1
80137d54: 00003021 addu r6,r0,r0                    #               0
80137d58: 00003821 addu r7,r0,r0                    #               0
80137d5c: 3c048017 lui r4,0x8017
80137d60: 8c844038 lw r4,0x4038(r4)                 #               *0x80174038
80137d64: 3c058017 lui r5,0x8017
80137d68: 8ca53cb8 lw r5,0x3cb8(r5)                 #               *0x80173cb8
80137d6c: 2484ffff addiu r4,r4,-0x0001              #               *0x80174038 - 1
80137d70: 0c05328e jal 0x8014ca38                   #               Store Thread Function Parameters (threadID - 1, *0x80173cb8 + (r20 * 60), 0, 0) 
                                                    #                   // Display problems with Option menu if removed
80137d74: 02052821 addu r5,r16,r5                   #               *0x80173cb8 + (r20 * 60)
80137d78: 0804df99 j 0x80137e64
80137d7c: 00000000 nop
                                                    #           }
80137d80: 340204d2 ori r2,r0,0x04d2
80137d84: 16820037 bne r20,r2,0x80137e64            #           if (r20 == 0x4d2 (1234)) {
80137d88: 00000000 nop
80137d8c: 0804df99 j 0x80137e64
80137d90: 2417ffff addiu r23,r0,-0x0001             #               r23 = -1
                                                    #           }
                                                    #       }
                                                    #   } else {
80137d94: 0014a023 subu r20,r0,r20                  #       r20 = -r20
80137d98: 00009821 addu r19,r0,r0                   #       count = 0
80137d9c: 34050001 ori r5,r0,0x0001                 #       1
80137da0: 34040003 ori r4,r0,0x0003                 #       3
80137da4: 3c038017 lui r3,0x8017                    #       (index = 0)
80137da8: 246398b8 addiu r3,r3,-0x6748              #       ptr = &threads[0].TaskID
                                                    #       do {
80137dac: 8c620000 lw r2,0x0000(r3)                 #           threads[index].TaskID
80137db0: 00000000 nop
80137db4: 14450002 bne r2,r5,0x80137dc0             
80137db8: 26730001 addiu r19,r19,0x0001             #           count = count + 1
                                                    #           if (threads[index].TaskID == 1) {
80137dbc: ac640000 sw r4,0x0000(r3)                 #               threads[index].TaskID = 3
                                                    #           }
80137dc0: 2a620010 slti r2,r19,0x0010
80137dc4: 1440fff9 bne r2,r0,0x80137dac             
80137dc8: 24630400 addiu r3,r3,0x0400               #           ptr = ptr + sizeof(thread) (index = index + 1) // (Points to next TaskID)
                                                    #       } while (count < 16)
80137dcc: 1a800025 blez r20,0x80137e64
80137dd0: 00009821 addu r19,r0,r0                   #       count = 0
                                                    #       if (r20 > 0) {
80137dd4: 34150008 ori r21,r0,0x0008                #           8
80137dd8: 3c1e8016 lui r30,0x8016
80137ddc: 27de5ee4 addiu r30,r30,0x5ee4             #           0x80165ee4
                                                    #           do {
80137de0: 3c028017 lui r2,0x8017
80137de4: 8c424038 lw r2,0x4038(r2)                 #               threadID
80137de8: 34030001 ori r3,r0,0x0001                 #               1
80137dec: 02621021 addu r2,r19,r2                   #               count + threadID
80137df0: 00022280 sll r4,r2,0x0a                   #               threadOffset = (count + threadID) * sizeof(thread)
80137df4: 3c018017 lui r1,0x8017
80137df8: 00240821 addu r1,r1,r4
80137dfc: ac239874 sw r3,-0x678c(r1)                #               *(0x80169874 + ((count + threadID) * sizeof(thread)) = 1
80137e00: 14550014 bne r2,r21,0x80137e54            #               if ((count + threadID) == 8) {
80137e04: 00000000 nop
80137e08: 1a800012 blez r20,0x80137e54
80137e0c: 00008821 addu r17,r0,r0                   #                   innerCount = 0
                                                    #                   if (r20 > 0) {
80137e10: 03c09021 addu r18,r30,r0                  #                       innerPtr = 0x80165ee4
                                                    #                       do {
80137e14: 02b18023 subu r16,r21,r17                 #                           loopThreadID = 8 - innerCount
80137e18: 0c053325 jal 0x8014cc94                   #                           ROUTINE: result = Check Thread Running Status (8 - innerCount)
80137e1c: 02002021 addu r4,r16,r0                   #                           loopThreadID 
80137e20: 10400009 beq r2,r0,0x80137e48
80137e24: 26310001 addiu r17,r17,0x0001             #                           innerCount = innerCount + 1
                                                    #                           if (result != 0) {
80137e28: 00101280 sll r2,r16,0x0a                  #                               loopThreadID * sizeof(thread)
80137e2c: 3c018017 lui r1,0x8017
80137e30: 00220821 addu r1,r1,r2
80137e34: 8c22986c lw r2,-0x6794(r1)                #                               loopThread = *(0x8016986c + (loopThreadID * sizeof(thread))
80137e38: 00000000 nop
80137e3c: 94420038 lhu r2,0x0038(r2)                #                               loopThread.GlobalPointer
80137e40: 00000000 nop
80137e44: a6420000 sh r2,0x0000(r18)                #                               *innerPtr = loopThread.GlobalPointer
                                                    #                           }
80137e48: 0234102a slt r2,r17,r20
80137e4c: 1440fff1 bne r2,r0,0x80137e14
80137e50: 26520002 addiu r18,r18,0x0002             #                           innerPtr = innerPtr + 2
                                                    #                       } while (innerCount < r20)
                                                    #                   }
                                                    #               }
80137e54: 26730001 addiu r19,r19,0x0001             #               count = count + 1
80137e58: 0274102a slt r2,r19,r20
80137e5c: 1440ffe0 bne r2,r0,0x80137de0             #           } while (count < r20)
80137e60: 00000000 nop
                                                    #       }
                                                    #   }
80137e64: 8fa80010 lw r8,0x0010(r29)                #   p1
80137e68: 00000000 nop
80137e6c: 8d020034 lw r2,0x0034(r8)                 #   p1.0x34
80137e70: 3c018017 lui r1,0x8017
80137e74: ac2097d0 sw r0,-0x6830(r1)                #   *0x80176830 = 0
80137e78: a4570000 sh r23,0x0000(r2)                #   p1.0x34 = r23
80137e7c: 3c028016 lui r2,0x8016
80137e80: 8c425fbc lw r2,0x5fbc(r2)                 #   *0x80165fbc
80137e84: 00000000 nop
80137e88: 14400005 bne r2,r0,0x80137ea0             #   if ((*0x80165fbc == 0)
80137e8c: 00000000 nop
80137e90: 16c00003 bne r22,r0,0x80137ea0            #       and (r22 == 0)) {
80137e94: 00000000 nop
80137e98: 0c04b747 jal 0x8012dd1c                   #           ROUTINE: ? 0x12dd1c ()
80137e9c: 00000000 nop
                                                    #   }
80137ea0: 8fbf004c lw r31,0x004c(r29)
80137ea4: 8fbe0048 lw r30,0x0048(r29)
80137ea8: 8fb70044 lw r23,0x0044(r29)
80137eac: 8fb60040 lw r22,0x0040(r29)
80137eb0: 8fb5003c lw r21,0x003c(r29)
80137eb4: 8fb40038 lw r20,0x0038(r29)
80137eb8: 8fb30034 lw r19,0x0034(r29)
80137ebc: 8fb20030 lw r18,0x0030(r29)
80137ec0: 8fb1002c lw r17,0x002c(r29)
80137ec4: 8fb00028 lw r16,0x0028(r29)
80137ec8: 27bd0050 addiu r29,r29,0x0050
80137ecc: 03e00008 jr r31
80137ed0: 00000000 nop