aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Tamper/CodeEmitters/LoadRegisterWithConstant.cs
blob: 501936b895499d351dca4028ecc14519903fdc00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Ryujinx.HLE.HOS.Tamper.Operations;

namespace Ryujinx.HLE.HOS.Tamper.CodeEmitters
{
    /// <summary>
    /// Code type 4 allows setting a register to a constant value.
    /// </summary>
    class LoadRegisterWithConstant
    {
        const int RegisterIndex = 3;
        const int ValueImmediateIndex = 8;

        const int ValueImmediateSize = 16;

        public static void Emit(byte[] instruction, CompilationContext context)
        {
            // 400R0000 VVVVVVVV VVVVVVVV
            // R: Register to use.
            // V: Value to load.

            Register destinationRegister = context.GetRegister(instruction[RegisterIndex]);
            ulong immediate = InstructionHelper.GetImmediate(instruction, ValueImmediateIndex, ValueImmediateSize);
            Value<ulong> sourceValue = new(immediate);

            context.CurrentOperations.Add(new OpMov<ulong>(destinationRegister, sourceValue));
        }
    }
}