Run Script Variable Command
Jump to navigation
Jump to search
# ROUTINE: RUN SCRIPT VARIABLE COMMAND - Non programmers notes here : Run_Script_Variable_Command_(Alternative) # Parameters: # r4 = (commandID) Command ID (0xB0 - 0xBE); Corresponds with event instruction IDs # r5 = (inputVariable) Variable whose value is being assigned # r6 = (inputValue) Value to use for assignment. Could be either an immediate value or a variable ID, depending on command [0x8014a018] addiu r29,r29,-0x0030 [0x8014a01c] sw r18,0x0018(r29) [0x8014a020] addu r18,r4,r0 # commandID [0x8014a024] sw r19,0x001c(r29) [0x8014a028] addu r19,r5,r0 # inputVariable [0x8014a02c] sw r16,0x0010(r29) [0x8014a030] addu r16,r6,r0 # inputValue [0x8014a034] ori r2,r0,0x00be # 0xBE [0x8014a038] sw r31,0x002c(r29) [0x8014a03c] sw r22,0x0028(r29) [0x8014a040] sw r21,0x0024(r29) [0x8014a044] sw r20,0x0020(r29) [0x8014a048] beq r18,r2,0x8014a0c0 [0x8014a04c] sw r17,0x0014(r29) # if (commandID != 0xBE) { // If not ZERO [0x8014a050] andi r2,r18,0x0001 # commandID & 1 [0x8014a054] bne r2,r0,0x8014a064 [0x8014a058] ori r2,r0,0x0021 # 0x21 # if ((commandID & 1) == 0) { // If value is an immediate rather than a variable ID [0x8014a05c] j 0x8014a0c0 [0x8014a060] addu r17,r16,r0 # operandValue = inputValue # } [0x8014a064] bne r16,r2,0x8014a07c # else if (inputValue == 0x21) { [0x8014a068] nop [0x8014a06c] jal 0x8014a48c # result = rand16 (Events) // Gets a 16-bit random number [0x8014a070] addiu r22,r0,-0x0001 # andMask = 0xffffffff [0x8014a074] j 0x8014a0c4 [0x8014a078] addu r17,r2,r0 # operandValue = result # } else { [0x8014a07c] jal 0x8014a2ec # result_14a2ec = 0014a2ec (inputValue); [0x8014a080] addu r4,r16,r0 [0x8014a084] addu r4,r16,r0 [0x8014a088] jal 0x8014a39c # result_14a39c = 0x14a39c (inputValue); [0x8014a08c] addu r17,r2,r0 # result_14a2ec [0x8014a090] addu r5,r2,r0 # result_14a39c [0x8014a094] bltz r5,0x8014a0bc # if (result_14a39c >= 0) { [0x8014a098] slti r2,r16,0x0360 [0x8014a09c] bne r2,r0,0x8014a0a8 [0x8014a0a0] ori r4,r0,0x0001 # tempValue = 1 # if (inputValue >= 0x360) { [0x8014a0a4] ori r4,r0,0x000f # tempValue = 15 # } [0x8014a0a8] lw r3,0x0000(r17) # value_14a2ec = *result_14a2ec [0x8014a0ac] sllv r2,r4,r5 # tempValue << result_14a39c [0x8014a0b0] and r2,r2,r3 # (tempValue << result_14a39c) & value_14a2ec [0x8014a0b4] j 0x8014a0c0 [0x8014a0b8] srlv r17,r2,r5 # operandValue = ((tempValue << result_14a39c) & value_14a2ec) >> result_14a39c # } else { [0x8014a0bc] lw r17,0x0000(r17) # operandValue = *result_14a2ec # } # } # } [0x8014a0c0] addiu r22,r0,-0x0001 # andMask = 0xffffffff [0x8014a0c4] jal 0x8014a2ec # result_14a2ec = 0014a2ec_-_0014a398 (inputVariable); [0x8014a0c8] addu r4,r19,r0 [0x8014a0cc] addu r4,r19,r0 [0x8014a0d0] jal 0x8014a39c # result_14a39c = 0014a39c_-_0014a3f4 (inputVariable); [0x8014a0d4] addu r21,r2,r0 # result_14a2ec [0x8014a0d8] addu r20,r2,r0 # result_14a39c [0x8014a0dc] bltz r20,0x8014a108 # if (result_14a39c >= 0) { [0x8014a0e0] slti r2,r19,0x0360 [0x8014a0e4] bne r2,r0,0x8014a0f0 [0x8014a0e8] ori r4,r0,0x0001 # tempValue = 1 # if (inputVariable >= 0x360) { [0x8014a0ec] ori r4,r0,0x000f # tempValue = 15 # } [0x8014a0f0] sllv r2,r4,r20 # tempValue << result_14a39c [0x8014a0f4] lw r3,0x0000(r21) # value_14a2ec = *result_14a2ec [0x8014a0f8] nor r22,r0,r2 # andMask = ~(tempValue << result_14a39c) [0x8014a0fc] and r2,r2,r3 # (tempValue << result_14a39c) & value_14a2ec [0x8014a100] j 0x8014a10c [0x8014a104] srlv r16,r2,r20 # newValue = ((tempValue << result_14a39c) & value_14a2ec) >> result_14a39c # } else { [0x8014a108] lw r16,0x0000(r21) # newValue = *result_14a2ec # } [0x8014a10c] ori r2,r0,0x00be [0x8014a110] bne r18,r2,0x8014a120 # if (commandID == 0xBE) { // ZERO [0x8014a114] slti r2,r18,0x00b2 [0x8014a118] j 0x8014a1b8 [0x8014a11c] addu r16,r0,r0 # newValue = 0 [0x8014a120] beq r2,r0,0x8014a130 # } else if (commandID < 0xB2) { // ADD or ADDVar [0x8014a124] slti r2,r18,0x00b4 [0x8014a128] j 0x8014a1b8 [0x8014a12c] addu r16,r16,r17 # newValue = newValue + operandValue [0x8014a130] beq r2,r0,0x8014a140 # } else if (commandID < 0xB4) { // SUB or SUBVar [0x8014a134] slti r2,r18,0x00b6 [0x8014a138] j 0x8014a1b8 [0x8014a13c] subu r16,r16,r17 # newValue = newValue - operandValue [0x8014a140] beq r2,r0,0x8014a154 # } else if (commandID < 0xB6) { // MULT or MULTVar [0x8014a144] mult r16,r17 [0x8014a148] mflo r16 # newValue = newValue * operandValue [0x8014a14c] j 0x8014a1b8 [0x8014a150] nop [0x8014a154] slti r2,r18,0x00b8 [0x8014a158] beq r2,r0,0x8014a180 # } else if (commandID < 0xB8) { // DIV or DIVVar [0x8014a15c] nop [0x8014a160] bne r17,r0,0x8014a170 # if (operandValue == 0) { [0x8014a164] nop [0x8014a168] jal 0x0014c958 # Stop Current Thread (); [0x8014a16c] nop # } [0x8014a170] div r16,r17 [0x8014a174] mflo r16 # newValue = newValue / operandValue [0x8014a178] j 0x8014a1b8 [0x8014a17c] nop [0x8014a180] slti r2,r18,0x00ba # } else if (commandID < 0xBA) { // MOD or MODVar (Modulus division... called DIVHI on Wiki) [0x8014a184] beq r2,r0,0x8014a19c [0x8014a188] slti r2,r18,0x00bc [0x8014a18c] div r16,r17 [0x8014a190] mfhi r16 # newValue = newValue % operandValue [0x8014a194] j 0x8014a1b8 [0x8014a198] nop [0x8014a19c] beq r2,r0,0x8014a1ac # } else if (commandID < 0xBC) { // AND or ANDVar [0x8014a1a0] slti r2,r18,0x00be [0x8014a1a4] j 0x8014a1b8 [0x8014a1a8] and r16,r16,r17 # newValue = newValue & operandValue [0x8014a1ac] beq r2,r0,0x8014a1b8 # } else if (commandID < 0xBE) { // OR or ORVar [0x8014a1b0] nop [0x8014a1b4] or r16,r16,r17 # newValue = newValue | operandValue # } [0x8014a1b8] lui r2,0x8016 [0x8014a1bc] lbu r2,0x60a3(r2) # *0x801660a3 [0x8014a1c0] nop [0x8014a1c4] bne r2,r0,0x8014a27c [0x8014a1c8] slti r2,r19,0x03c0 # if (*0x801660a3 == 0) { [0x8014a1cc] bne r2,r0,0x8014a1f8 [0x8014a1d0] ori r2,r0,0x0001 # if (inputVariable >= 0x3c0) { [0x8014a1d4] lui r1,0x8016 [0x8014a1d8] sb r2,0x60a3(r1) # *0x801660a3 = 1 [0x8014a1dc] jal 0x0013b590 # scriptVarValue = Get Script Variable (inputVariable); [0x8014a1e0] addu r4,r19,r0 [0x8014a1e4] sltiu r2,r2,0x000c [0x8014a1e8] lui r1,0x8016 [0x8014a1ec] sb r0,0x60a3(r1) # *0x801660a3 = 0 [0x8014a1f0] beq r2,r0,0x8014a2c0 # if (scriptVarValue >= 13) return; [0x8014a1f4] nop # } [0x8014a1f8] lui r2,0x8016 [0x8014a1fc] lbu r2,0x60a3(r2) # *0x801660a3 [0x8014a200] nop [0x8014a204] bne r2,r0,0x8014a27c [0x8014a208] ori r2,r0,0x0001 # if (*0x801660a3 == 0) { [0x8014a20c] lui r1,0x8016 [0x8014a210] sb r2,0x60a3(r1) # *0x801660a3 = 1 [0x8014a214] jal 0x0013b590 # scriptVarValue = Get Script Variable (0x1fc); [0x8014a218] ori r4,r0,0x01fc [0x8014a21c] lui r1,0x8016 [0x8014a220] sb r0,0x60a3(r1) # *0x801660a3 = 0 [0x8014a224] beq r2,r0,0x8014a27c # if ((scriptVarValue != 0) [0x8014a228] addiu r2,r19,-0x0070 [0x8014a22c] sltiu r2,r2,0x0020 [0x8014a230] bne r2,r0,0x8014a27c # && ((inputVariable < 0x70) || (inputVariable >= 0x90)) [0x8014a234] addiu r2,r19,-0x01fc [0x8014a238] sltiu r2,r2,0x0004 [0x8014a23c] bne r2,r0,0x8014a27c # && ((inputVariable < 0x1fc) || (inputVariable >= 0x200)) [0x8014a240] ori r2,r0,0x0066 [0x8014a244] beq r19,r2,0x8014a27c # && (inputVariable != 0x66) [0x8014a248] addiu r2,r19,-0x0032 [0x8014a24c] sltiu r2,r2,0x0008 [0x8014a250] bne r2,r0,0x8014a27c # && ((inputVariable < 0x32) || (inputVariable >= 0x3a)) [0x8014a254] slti r2,r19,0x002c [0x8014a258] bne r2,r0,0x8014a27c # && (inputVariable > 0x2c) [0x8014a25c] ori r2,r0,0x0030 [0x8014a260] beq r19,r2,0x8014a27c # && (inputVariable != 0x30) [0x8014a264] addiu r2,r19,-0x0056 [0x8014a268] sltiu r2,r2,0x0005 [0x8014a26c] bne r2,r0,0x8014a27c # && ((inputVariable < 0x56) || (inputVariable >= 0x5b)) [0x8014a270] ori r2,r0,0x0053 [0x8014a274] bne r19,r2,0x8014a2c0 # && (inputVariable != 0x53)) return; [0x8014a278] nop # } # } [0x8014a27c] bltz r20,0x8014a2ac [0x8014a280] slti r2,r19,0x0360 # if (result_14a39c >= 0) { [0x8014a284] bne r2,r0,0x8014a290 [0x8014a288] ori r4,r0,0x0001 # tempValue = 1 # if (inputVariable >= 0x360) { [0x8014a28c] ori r4,r0,0x000f # tempValue = 15 # } [0x8014a290] and r16,r16,r4 # newValue = newValue & 15 [0x8014a294] lw r2,0x0000(r21) # value_14a2ec = *result_14a2ec [0x8014a298] sllv r16,r16,r20 # newValue = newValue << result_14a39c [0x8014a29c] and r2,r22,r2 # andMask & value_14a2ec [0x8014a2a0] or r2,r16,r2 # newValue | (andMask & value_14a2ec) [0x8014a2a4] j 0x8014a2c0 [0x8014a2a8] sw r2,0x0000(r21) # *result_14a2ec = newValue | (andMask & value_14a2ec) # } else { [0x8014a2ac] ori r2,r0,0x0019 [0x8014a2b0] bne r19,r2,0x8014a2c0 [0x8014a2b4] sw r16,0x0000(r21) # *result_14a2ec = newValue # if (inputVariable == 0x19) { [0x8014a2b8] lui r1,0x8016 [0x8014a2bc] sw r16,0x5ef4(r1) # *0x80165ef4 = newValue # } # } [0x8014a2c0] lw r31,0x002c(r29) [0x8014a2c4] lw r22,0x0028(r29) [0x8014a2c8] lw r21,0x0024(r29) [0x8014a2cc] lw r20,0x0020(r29) [0x8014a2d0] lw r19,0x001c(r29) [0x8014a2d4] lw r18,0x0018(r29) [0x8014a2d8] lw r17,0x0014(r29) [0x8014a2dc] lw r16,0x0010(r29) [0x8014a2e0] addiu r29,r29,0x0030 [0x8014a2e4] jr r31 [0x8014a2e8] nop
Return location
0013b600: Get_Script_Variable 0013b614: Get_Script_Variable 0013b6a4: 0013b644_-_0013b6e0 0013b6b8: 0013b644_-_0013b6e0 00143da8: 00143bd0_-_00145f74 - Event_Instruction_Main_Routine_1