2018-11-17 05:01:31 +01:00
|
|
|
using Ryujinx.Common.Logging;
|
2019-11-22 03:46:14 +01:00
|
|
|
using Ryujinx.Graphics.Gpu.State;
|
2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine.MME
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Macro code interpreter.
|
|
|
|
/// </summary>
|
2020-08-03 03:36:57 +02:00
|
|
|
class MacroInterpreter : IMacroEE
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2020-08-03 03:36:57 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Arguments FIFO.
|
|
|
|
/// </summary>
|
2020-03-13 02:30:26 +01:00
|
|
|
public Queue<int> Fifo { get; }
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int[] _gprs;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int _methAddr;
|
|
|
|
private int _methIncr;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private bool _carry;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int _opCode;
|
|
|
|
private int _pipeOp;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-01-22 02:11:43 +01:00
|
|
|
private bool _ignoreExitFlag;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private int _pc;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance of the macro code interpreter.
|
|
|
|
/// </summary>
|
|
|
|
public MacroInterpreter()
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
Fifo = new Queue<int>();
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_gprs = new int[8];
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Executes a macro program until it exits.
|
|
|
|
/// </summary>
|
2020-08-03 03:36:57 +02:00
|
|
|
/// <param name="code">Code of the program to execute</param>
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <param name="state">Current GPU state</param>
|
2020-08-03 03:36:57 +02:00
|
|
|
/// <param name="arg0">Optional argument passed to the program, 0 if not used</param>
|
|
|
|
public void Execute(ReadOnlySpan<int> code, GpuState state, int arg0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
_gprs[1] = arg0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
_pc = 0;
|
2020-03-13 02:30:26 +01:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
FetchOpCode(code);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
while (Step(code, state)) ;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-07-02 04:39:22 +02:00
|
|
|
// Due to the delay slot, we still need to execute
|
|
|
|
// one more instruction before we actually exit.
|
2020-08-03 03:36:57 +02:00
|
|
|
Step(code, state);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Resets the internal interpreter state.
|
|
|
|
/// Call each time you run a new program.
|
|
|
|
/// </summary>
|
2018-04-08 21:17:35 +02:00
|
|
|
private void Reset()
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int index = 0; index < _gprs.Length; index++)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gprs[index] = 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_methAddr = 0;
|
|
|
|
_methIncr = 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_carry = false;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Executes a single instruction of the program.
|
|
|
|
/// </summary>
|
2020-08-03 03:36:57 +02:00
|
|
|
/// <param name="code">Program code to execute</param>
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <param name="state">Current GPU state</param>
|
|
|
|
/// <returns>True to continue execution, false if the program exited</returns>
|
2020-08-03 03:36:57 +02:00
|
|
|
private bool Step(ReadOnlySpan<int> code, GpuState state)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int baseAddr = _pc - 1;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
FetchOpCode(code);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if ((_opCode & 7) < 7)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Operation produces a value.
|
2019-03-04 02:45:25 +01:00
|
|
|
AssignmentOperation asgOp = (AssignmentOperation)((_opCode >> 4) & 7);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-11-22 03:46:14 +01:00
|
|
|
int result = GetAluResult(state);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (asgOp)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Fetch parameter and ignore result.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.IgnoreAndFetch:
|
|
|
|
SetDstGpr(FetchParam());
|
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move result.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.Move:
|
2019-03-04 02:45:25 +01:00
|
|
|
SetDstGpr(result);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move result and use as Method Address.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.MoveAndSetMaddr:
|
2019-03-04 02:45:25 +01:00
|
|
|
SetDstGpr(result);
|
|
|
|
SetMethAddr(result);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Fetch parameter and send result.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.FetchAndSend:
|
|
|
|
SetDstGpr(FetchParam());
|
2020-04-25 15:56:56 +02:00
|
|
|
Send(state, result);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move and send result.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.MoveAndSend:
|
2019-03-04 02:45:25 +01:00
|
|
|
SetDstGpr(result);
|
2020-04-25 15:56:56 +02:00
|
|
|
Send(state, result);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Fetch parameter and use result as Method Address.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.FetchAndSetMaddr:
|
|
|
|
SetDstGpr(FetchParam());
|
2019-03-04 02:45:25 +01:00
|
|
|
SetMethAddr(result);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move result and use as Method Address, then fetch and send parameter.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.MoveAndSetMaddrThenFetchAndSend:
|
2019-03-04 02:45:25 +01:00
|
|
|
SetDstGpr(result);
|
|
|
|
SetMethAddr(result);
|
2020-04-25 15:56:56 +02:00
|
|
|
Send(state, FetchParam());
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
2019-07-02 04:39:22 +02:00
|
|
|
// Move result and use as Method Address, then send bits 17:12 of result.
|
2018-04-08 21:17:35 +02:00
|
|
|
case AssignmentOperation.MoveAndSetMaddrThenSendHigh:
|
2019-03-04 02:45:25 +01:00
|
|
|
SetDstGpr(result);
|
|
|
|
SetMethAddr(result);
|
2020-04-25 15:56:56 +02:00
|
|
|
Send(state, (result >> 12) & 0x3f);
|
2018-04-08 21:17:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Branch.
|
2019-03-04 02:45:25 +01:00
|
|
|
bool onNotZero = ((_opCode >> 4) & 1) != 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool taken = onNotZero
|
2018-04-08 21:17:35 +02:00
|
|
|
? GetGprA() != 0
|
|
|
|
: GetGprA() == 0;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (taken)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_pc = baseAddr + GetImm();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
bool noDelays = (_opCode & 0x20) != 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (noDelays)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2020-08-03 03:36:57 +02:00
|
|
|
FetchOpCode(code);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
2020-01-22 02:11:43 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// The delay slot instruction exit flag should be ignored.
|
|
|
|
_ignoreExitFlag = true;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 02:11:43 +01:00
|
|
|
bool exit = (_opCode & 0x80) != 0 && !_ignoreExitFlag;
|
|
|
|
|
|
|
|
_ignoreExitFlag = false;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return !exit;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches a single operation code from the program code.
|
|
|
|
/// </summary>
|
2020-08-03 03:36:57 +02:00
|
|
|
/// <param name="code">Program code</param>
|
|
|
|
private void FetchOpCode(ReadOnlySpan<int> code)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_opCode = _pipeOp;
|
2020-08-03 03:36:57 +02:00
|
|
|
_pipeOp = code[_pc++];
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the result of the current Arithmetic and Logic unit operation.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">Current GPU state</param>
|
|
|
|
/// <returns>Operation result</returns>
|
2019-11-22 03:46:14 +01:00
|
|
|
private int GetAluResult(GpuState state)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
AluOperation op = (AluOperation)(_opCode & 7);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (op)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case AluOperation.AluReg:
|
2020-08-03 03:36:57 +02:00
|
|
|
return GetAluResult((AluRegOperation)((_opCode >> 17) & 0x1f), GetGprA(), GetGprB());
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluOperation.AddImmediate:
|
|
|
|
return GetGprA() + GetImm();
|
|
|
|
|
|
|
|
case AluOperation.BitfieldReplace:
|
|
|
|
case AluOperation.BitfieldExtractLslImm:
|
|
|
|
case AluOperation.BitfieldExtractLslReg:
|
2019-03-04 02:45:25 +01:00
|
|
|
int bfSrcBit = (_opCode >> 17) & 0x1f;
|
2020-08-03 03:36:57 +02:00
|
|
|
int bfSize = (_opCode >> 22) & 0x1f;
|
2019-03-04 02:45:25 +01:00
|
|
|
int bfDstBit = (_opCode >> 27) & 0x1f;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int bfMask = (1 << bfSize) - 1;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int dst = GetGprA();
|
|
|
|
int src = GetGprB();
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (op)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case AluOperation.BitfieldReplace:
|
2019-03-04 02:45:25 +01:00
|
|
|
src = (int)((uint)src >> bfSrcBit) & bfMask;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
dst &= ~(bfMask << bfDstBit);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
dst |= src << bfDstBit;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return dst;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluOperation.BitfieldExtractLslImm:
|
2019-03-04 02:45:25 +01:00
|
|
|
src = (int)((uint)src >> dst) & bfMask;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return src << bfDstBit;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluOperation.BitfieldExtractLslReg:
|
2019-03-04 02:45:25 +01:00
|
|
|
src = (int)((uint)src >> bfSrcBit) & bfMask;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return src << dst;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AluOperation.ReadImmediate:
|
2019-11-22 03:46:14 +01:00
|
|
|
return Read(state, GetGprA() + GetImm());
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
throw new InvalidOperationException($"Invalid operation \"{op}\" on instruction 0x{_opCode:X8}.");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
2020-01-02 00:14:18 +01:00
|
|
|
/// Gets the result of an Arithmetic and Logic operation using registers.
|
2019-12-31 21:08:20 +01:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="aluOp">Arithmetic and Logic unit operation with registers</param>
|
|
|
|
/// <param name="a">First operand value</param>
|
|
|
|
/// <param name="b">Second operand value</param>
|
|
|
|
/// <returns>Operation result</returns>
|
2019-03-04 02:45:25 +01:00
|
|
|
private int GetAluResult(AluRegOperation aluOp, int a, int b)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2020-08-03 03:36:57 +02:00
|
|
|
ulong result;
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (aluOp)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case AluRegOperation.Add:
|
2020-08-03 03:36:57 +02:00
|
|
|
result = (ulong)a + (ulong)b;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_carry = result > 0xffffffff;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return (int)result;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluRegOperation.AddWithCarry:
|
2020-08-03 03:36:57 +02:00
|
|
|
result = (ulong)a + (ulong)b + (_carry ? 1UL : 0UL);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_carry = result > 0xffffffff;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return (int)result;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluRegOperation.Subtract:
|
2020-08-03 03:36:57 +02:00
|
|
|
result = (ulong)a - (ulong)b;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_carry = result < 0x100000000;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return (int)result;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
case AluRegOperation.SubtractWithBorrow:
|
2020-08-03 03:36:57 +02:00
|
|
|
result = (ulong)a - (ulong)b - (_carry ? 0UL : 1UL);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_carry = result < 0x100000000;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return (int)result;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
case AluRegOperation.BitwiseExclusiveOr: return a ^ b;
|
|
|
|
case AluRegOperation.BitwiseOr: return a | b;
|
|
|
|
case AluRegOperation.BitwiseAnd: return a & b;
|
|
|
|
case AluRegOperation.BitwiseAndNot: return a & ~b;
|
|
|
|
case AluRegOperation.BitwiseNotAnd: return ~(a & b);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
throw new InvalidOperationException($"Invalid operation \"{aluOp}\" on instruction 0x{_opCode:X8}.");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Extracts a 32-bits signed integer constant from the current operation code.
|
|
|
|
/// </summary>
|
2020-01-01 16:39:09 +01:00
|
|
|
/// <returns>The 32-bits immediate value encoded at the current operation code</returns>
|
2018-04-08 21:17:35 +02:00
|
|
|
private int GetImm()
|
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Note: The immediate is signed, the sign-extension is intended here.
|
2019-03-04 02:45:25 +01:00
|
|
|
return _opCode >> 14;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the current method address, for method calls.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Packed address and increment value</param>
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetMethAddr(int value)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2020-08-03 03:36:57 +02:00
|
|
|
_methAddr = (value >> 0) & 0xfff;
|
2019-03-04 02:45:25 +01:00
|
|
|
_methIncr = (value >> 12) & 0x3f;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the destination register value.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">Value to set (usually the operation result)</param>
|
2019-03-04 02:45:25 +01:00
|
|
|
private void SetDstGpr(int value)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
_gprs[(_opCode >> 8) & 7] = value;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets first operand value from the respective register.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Operand value</returns>
|
2018-04-08 21:17:35 +02:00
|
|
|
private int GetGprA()
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return GetGprValue((_opCode >> 11) & 7);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets second operand value from the respective register.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Operand value</returns>
|
2018-04-08 21:17:35 +02:00
|
|
|
private int GetGprB()
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return GetGprValue((_opCode >> 14) & 7);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the value from a register, or 0 if the R0 register is specified.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="index">Index of the register</param>
|
|
|
|
/// <returns>Register value</returns>
|
2019-03-04 02:45:25 +01:00
|
|
|
private int GetGprValue(int index)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return index != 0 ? _gprs[index] : 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches a call argument from the call argument FIFO.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The call argument, or 0 if the FIFO is empty</returns>
|
2018-04-08 21:17:35 +02:00
|
|
|
private int FetchParam()
|
|
|
|
{
|
2019-12-31 21:08:20 +01:00
|
|
|
if (!Fifo.TryDequeue(out int value))
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");
|
2018-11-17 05:01:31 +01:00
|
|
|
|
|
|
|
return 0;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return value;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Reads data from a GPU register.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">Current GPU state</param>
|
|
|
|
/// <param name="reg">Register offset to read</param>
|
|
|
|
/// <returns>GPU register value</returns>
|
2019-11-22 03:46:14 +01:00
|
|
|
private int Read(GpuState state, int reg)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-11-22 03:46:14 +01:00
|
|
|
return state.Read(reg);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:08:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Performs a GPU method call.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="state">Current GPU state</param>
|
|
|
|
/// <param name="value">Call argument</param>
|
2020-04-25 15:56:56 +02:00
|
|
|
private void Send(GpuState state, int value)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-10-13 08:02:07 +02:00
|
|
|
MethodParams meth = new MethodParams(_methAddr, value);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2020-08-03 03:36:57 +02:00
|
|
|
state.CallMethod(meth);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
_methAddr += _methIncr;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|