private static void Branch( uint Instruction, uint Op, ref ARM9.ArmArchitecture.ArmContext Context) { uint num1 = Instruction >> 24 & 1U; int num2 = ((int)Instruction & 16777215) << 8 >> 8; if (num1 == 1U) { Context.Registers[14] = Context.Registers[15] + 4U; } Context.Registers[15] = (uint)((int)Context.Registers[15] + 8 + num2 * 4); }
public static void RunCode(NDS Rom) { ARM9.ArmArchitecture.ArmContext Context = new ARM9.ArmArchitecture.ArmContext(); Array.Copy((Array)Rom.Arm9, 0L, (Array)Context.Memory, (long)Rom.ARM9LoadAddress, (long)Rom.Arm9.Length); Context.Registers[15] = Rom.ARM9EntryAddress; while (true) { if (!Context.T) { uint Instruction = Bytes.Read4BytesAsUInt32(Context.Memory, (int)Context.Registers[15]); uint num = Instruction >> 28; uint Op = Instruction >> 25 & 7U; switch (Op) { case 0: case 1: ARM9.ArmArchitecture.DataProc(Instruction, Op, ref Context); Context.Registers[15] += 4U; break; case 2: case 3: ARM9.ArmArchitecture.SingleDataTrans(Instruction, Op, ref Context); Context.Registers[15] += 4U; break; case 5: ARM9.ArmArchitecture.Branch(Instruction, Op, ref Context); break; case 7: Context.Registers[15] += 4U; break; default: Context.Registers[15] += 4U; break; } } } }
private static void SingleDataTrans( uint Instruction, uint Op, ref ARM9.ArmArchitecture.ArmContext Context) { bool flag1 = ((int)Op & 1) == 1; bool flag2 = ((int)(Instruction >> 24) & 1) == 1; bool flag3 = ((int)(Instruction >> 23) & 1) == 1; bool flag4 = ((int)(Instruction >> 22) & 1) == 1; bool flag5 = false; bool flag6 = false; if (flag2) { flag6 = ((int)(Instruction >> 21) & 1) == 1; } else { flag5 = ((int)(Instruction >> 21) & 1) == 1; } bool flag7 = ((int)(Instruction >> 20) & 1) == 1; uint num1 = Instruction >> 16 & 15U; uint num2 = Instruction >> 12 & 15U; uint num3; if (flag1) { uint NrBits = Instruction >> 7 & 31U; uint ShiftType = Instruction >> 5 & 3U; uint num4 = Instruction >> 4 & 1U; uint num5 = Instruction & 15U; num3 = ARM9.ArmArchitecture.Shift(ShiftType, Context.Registers[(IntPtr)num5], NrBits); } else { num3 = Instruction & 4095U; } uint register = Context.Registers[(IntPtr)num1]; if (num1 == 15U) { register += 8U; } if (flag2) { if (flag3) { register += num3; } else { register -= num3; } if (flag6) { Context.Registers[(IntPtr)num1] = register; } } if (flag7) { Context.Registers[(IntPtr)num2] = !flag4?Bytes.Read4BytesAsUInt32(Context.Memory, (int)register) : (uint)Context.Memory[(IntPtr)register]; } else if (num2 == 15U) { if (flag4) { Context.Memory[(IntPtr)register] = (byte)((int)Context.Registers[(IntPtr)num2] + 12 & (int)byte.MaxValue); } else { Array.Copy((Array)BitConverter.GetBytes(Context.Registers[(IntPtr)num2] + 12U), 0L, (Array)Context.Memory, (long)register, 4L); } } else if (flag4) { Context.Memory[(IntPtr)register] = (byte)(Context.Registers[(IntPtr)num2] & (uint)byte.MaxValue); } else { Array.Copy((Array)BitConverter.GetBytes(Context.Registers[(IntPtr)num2]), 0L, (Array)Context.Memory, (long)register, 4L); } if (flag2) { return; } uint num6 = !flag3 ? register - num3 : register + num3; Context.Registers[(IntPtr)num1] = num6; }
private static void DataProc( uint Instruction, uint Op, ref ARM9.ArmArchitecture.ArmContext Context) { bool flag1 = ((int)Op & 1) == 1; uint num1 = Instruction >> 21 & 15U; bool flag2 = ((int)(Instruction >> 20) & 1) == 1; uint num2 = Instruction >> 16 & 15U; uint num3 = Instruction >> 12 & 15U; uint num4; if (flag1) { uint num5 = Instruction >> 8 & 15U; uint num6 = Instruction & (uint)byte.MaxValue; num4 = num6 >> (int)num5 * 2 | num6 << 32 - (int)num5 * 2; } else { uint ShiftType = Instruction >> 5 & 3U; bool flag3 = ((int)(Instruction >> 4) & 1) == 1; uint num5 = Instruction & 15U; if (flag3) { uint NrBits = Instruction >> 7 & 31U; num4 = ARM9.ArmArchitecture.Shift(ShiftType, Context.Registers[(IntPtr)num5], NrBits); } else { uint num6 = Instruction >> 8 & 15U; uint num7 = Instruction >> 7 & 1U; num4 = ARM9.ArmArchitecture.Shift(ShiftType, Context.Registers[(IntPtr)num5], Context.Registers[(IntPtr)num6] & (uint)byte.MaxValue); } } switch (num1) { case 12: Context.Registers[(IntPtr)num3] = Context.Registers[(IntPtr)num2] | num4; break; case 13: Context.Registers[(IntPtr)num3] = num4; break; case 14: Context.Registers[(IntPtr)num3] = Context.Registers[(IntPtr)num2] & ~num4; break; } if (!flag2) { return; } bool flag4 = Context.Registers[(IntPtr)num3] == 0U; bool flag5 = Context.Registers[(IntPtr)num3] >> 31 == 1U; if (num3 != 15U) { switch (num1) { } } }