You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
682 lines
20 KiB
682 lines
20 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace DisComputer
|
|
{
|
|
/// <summary>
|
|
/// 分布操作码单元集
|
|
/// </summary>
|
|
public class IIIOperationUnitSet : MonoBehaviour
|
|
{
|
|
|
|
|
|
//操作码单元
|
|
public OpCodeUnit op_code_unit;
|
|
|
|
//操作数01单元
|
|
public TwoWayUnit op01_number_unit;
|
|
|
|
//操作数02单元
|
|
public TwoWayUnit op02_number_unit;
|
|
|
|
//寄存数集
|
|
public IIIRegsUnitSet regsUnitSet;
|
|
|
|
//MEM
|
|
public IIIMEMUnitSet mEMUnitSet;
|
|
|
|
//pReg
|
|
public IIIPRegUnit pRegUnit;
|
|
|
|
//命令
|
|
public IIICommandUnitSet commandUnitSet;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 激活
|
|
/// </summary>
|
|
public void Active(Action finish = null)
|
|
{
|
|
CommandData data = VonNeumann.data;
|
|
string order = data.ActName;
|
|
string temp = order.ToLower();
|
|
|
|
Debug.LogFormat("Act name {0}", temp);
|
|
if (temp.Contains("mov3"))
|
|
{
|
|
SetOperationMov3(order, finish);
|
|
}
|
|
else if (temp.Contains("add"))
|
|
{
|
|
SetOperation(order, finish);
|
|
}
|
|
else if (temp.Contains("div"))
|
|
{
|
|
SetOperation(order, finish);
|
|
}
|
|
else if (temp.Contains("mul"))
|
|
{
|
|
SetOperation(order, finish);
|
|
}
|
|
else if (temp.Contains("sub"))
|
|
{
|
|
SetOperation(order, finish);
|
|
}
|
|
else if (temp.Contains("out"))
|
|
{
|
|
SetOperationOut(order, finish);
|
|
}
|
|
else if (temp.Contains("halt"))
|
|
{
|
|
SetOperationHalt(order, finish);
|
|
}
|
|
else if (temp.Contains("in"))
|
|
{
|
|
SetOperationIn(order, finish);
|
|
}
|
|
else if (temp.Contains("mov1"))
|
|
{
|
|
SetOperationMov1(order, finish);
|
|
}
|
|
else if (temp.Contains("mov2"))
|
|
{
|
|
SetOperationMov2(order, finish);
|
|
}
|
|
else if (temp.Contains("jmp"))
|
|
{
|
|
SetCmdJmp(order, finish);
|
|
}
|
|
else if (temp.Contains("jz"))
|
|
{
|
|
SetCmdJz(order, finish);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#region Mov
|
|
/// <summary>
|
|
/// mov3 启动
|
|
/// </summary>
|
|
void SetOperationMov3(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
|
|
int reg_index = 1;
|
|
|
|
if (1 < orders.Length)
|
|
{
|
|
reg_index = int.Parse(orders[1]);
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
Debug.LogFormat("reg_index {0} ", reg_index);
|
|
|
|
if (2 < orders.Length)
|
|
{
|
|
op02_number_unit.ShakeUnit();
|
|
op02_number_unit.SetInfoTxt(orders[2]);
|
|
op02_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
finish?.Invoke();
|
|
//向下
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, orders[2], () =>
|
|
{
|
|
|
|
if (VonNeumannControll.Instance != null)
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
Debug.LogFormat("VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// mov1 启动
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationMov1(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
|
|
int reg_index = 1;
|
|
|
|
if (1 < orders.Length)
|
|
{
|
|
reg_index = int.Parse(orders[1]);
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
Debug.LogFormat("reg_index {0} ", reg_index);
|
|
|
|
if (2 < orders.Length)
|
|
{
|
|
op02_number_unit.ShakeUnit();
|
|
op02_number_unit.SetInfoTxt(orders[2]);
|
|
op02_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
finish?.Invoke();
|
|
|
|
mEMUnitSet.comboomItems[VonNeumann.movMemIndex].CommandAct(VonNeumann.data.num02.ToString());
|
|
|
|
regsUnitSet.PlayTopArrow(reg_index, 11, -1, () =>
|
|
{
|
|
//向下
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, VonNeumann.data.num02.ToString(), () =>
|
|
{
|
|
|
|
//VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// mov2 启动
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationMov2(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
int reg_index = 1;
|
|
if (1 < orders.Length)
|
|
{
|
|
reg_index = VonNeumann.data.num01;
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
Debug.LogFormat("reg_index {0} ", reg_index);
|
|
|
|
if (2 < orders.Length)
|
|
{
|
|
op02_number_unit.ShakeUnit();
|
|
op02_number_unit.SetInfoTxt(orders[2]);
|
|
op02_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
finish?.Invoke();
|
|
|
|
|
|
//向下
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, VonNeumann.data.num02.ToString(), () =>
|
|
{
|
|
|
|
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(1, VonNeumann.data.num02.ToString(), () =>
|
|
{
|
|
|
|
//VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
regsUnitSet.PlayTopArrow(reg_index, 11, 1, () =>
|
|
{
|
|
mEMUnitSet.comboomItems[VonNeumann.movMemIndex].CommandAct(VonNeumann.data.num02.ToString(),()=>
|
|
{
|
|
|
|
});
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 运算
|
|
/// <summary>
|
|
/// 运算指令
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperation(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
int reg_index = int.Parse(orders[1]);
|
|
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, VonNeumann.data.num01.ToString(), () =>
|
|
{
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
op02_number_unit.ShakeUnit();
|
|
op02_number_unit.SetInfoTxt(orders[2]);
|
|
|
|
op02_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
finish?.Invoke();
|
|
//向下
|
|
regsUnitSet.regs_list[reg_index + 1].ArrowActive(0, VonNeumann.data.num02.ToString(), () =>
|
|
{
|
|
StartCoroutine(OpProgress(reg_index, orders[0]));
|
|
});
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 运算式进度
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator OpProgress(int regIndex, string commandVal)
|
|
{
|
|
yield return new WaitForSeconds(1.5f);
|
|
regsUnitSet.regs_list[regIndex].SelfActiveArrow(1, "", () =>
|
|
{
|
|
|
|
regsUnitSet.top_arrow.PlayTopCenter(0, regIndex + 1, -1, () => {
|
|
|
|
op_code_unit.ShakeUnit();
|
|
op_code_unit.ShowArrow(0, false, () =>
|
|
{
|
|
IIIALUUnit aLUUnit = op_code_unit.nextUnit.GetComponent<IIIALUUnit>();
|
|
aLUUnit.CommandRegist();
|
|
aLUUnit.ShakeUnit();
|
|
|
|
regsUnitSet.top_arrow.PlayTopCenter(0, regIndex, 1, () =>
|
|
{
|
|
regsUnitSet.regs_list[regIndex].ArrowActive(0, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
if (VonNeumannControll.Instance != null)
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("operation VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
});
|
|
regsUnitSet.regs_list[regIndex + 1].RewindUnit();
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//向上
|
|
regsUnitSet.regs_list[regIndex + 1].SelfActiveArrow(1, "", () =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 输入 输出 I/O
|
|
|
|
/// <summary>
|
|
/// 输出
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationOut(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
int reg_index = int.Parse(orders[1]);
|
|
|
|
regsUnitSet.regs_list[reg_index].SelfActiveArrow(1, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
//播放中间指向箭头
|
|
regsUnitSet.top_arrow.PlayTopCenter(reg_index, 10, 1, () =>
|
|
{
|
|
regsUnitSet.io_unit.ArrowActive(0, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
if (VonNeumannControll.Instance != null)
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
|
|
Debug.LogFormat("out VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
if (reg_index + 1 < regsUnitSet.regs_list.Count)
|
|
{
|
|
regsUnitSet.regs_list[reg_index + 1].RewindUnit();
|
|
}
|
|
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
|
|
op02_number_unit.SetInfoTxt("");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 输入
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationIn(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
int reg_index = int.Parse(orders[1]);
|
|
|
|
regsUnitSet.io_unit.SelfActiveArrow(1, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
//播放中间指向箭头
|
|
regsUnitSet.top_arrow.PlayTopCenter(reg_index, 10, -1, () =>
|
|
{
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
if (VonNeumannControll.Instance != null)
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
|
|
Debug.LogFormat("out VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
if (reg_index + 1 < regsUnitSet.regs_list.Count)
|
|
{
|
|
regsUnitSet.regs_list[reg_index + 1].RewindUnit();
|
|
}
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
|
|
op02_number_unit.SetInfoTxt("");
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 条件
|
|
/// <summary>
|
|
/// 无条件跳转
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetCmdJmp(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
int reg_index = int.Parse(orders[1]);
|
|
|
|
|
|
if (reg_index + 1 < regsUnitSet.regs_list.Count)
|
|
{
|
|
regsUnitSet.regs_list[reg_index + 1].RewindUnit();
|
|
}
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
|
|
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
IIICommandUnitSet iIICommandUnitSet = IIINonNeumannControll.Instance.commandUnitSet.GetComponent<IIICommandUnitSet>();
|
|
|
|
int arrowIndex = iIICommandUnitSet.GetMatchCmdIndex();
|
|
|
|
regsUnitSet.top_arrow.PlayCmdJmpTopCenter(() =>
|
|
{
|
|
regsUnitSet.jump_arr.PlayArrow(true, () =>
|
|
{
|
|
pRegUnit.ShakeUnit();
|
|
pRegUnit.SetInfoTxt(orders[1]);
|
|
pRegUnit.Active(
|
|
() =>
|
|
{
|
|
commandUnitSet.comboomItems[arrowIndex].AddressAct(orders[1]);
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
}, arrowIndex);
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 条件跳转
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetCmdJz(string data, Action finish = null)
|
|
{
|
|
string[] orders = data.Split(' ');
|
|
foreach (var order in orders)
|
|
{
|
|
Debug.LogFormat("orders go {0}", order);
|
|
}
|
|
op_code_unit.SetInfoTxt(orders[0]);
|
|
op_code_unit.ShakeUnit();
|
|
int reg_index = int.Parse(orders[1]);
|
|
|
|
|
|
if (reg_index + 1 < regsUnitSet.regs_list.Count)
|
|
{
|
|
regsUnitSet.regs_list[reg_index + 1].RewindUnit();
|
|
}
|
|
|
|
op01_number_unit.ShakeUnit();
|
|
op01_number_unit.SetInfoTxt(orders[1]);
|
|
|
|
|
|
|
|
op02_number_unit.ShakeUnit();
|
|
op02_number_unit.SetInfoTxt(orders[2]);
|
|
|
|
op01_number_unit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
regsUnitSet.regs_list[reg_index].ArrowActive(0, VonNeumann.data.num02.ToString(), () =>
|
|
{
|
|
|
|
StartCoroutine(ConditionProgress(reg_index, orders));
|
|
});
|
|
|
|
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 条件进度
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator ConditionProgress(int regIndex, string[] orders)
|
|
{
|
|
yield return new WaitForSeconds(1.5f);
|
|
regsUnitSet.regs_list[regIndex].SelfActiveArrow(1, "", () =>
|
|
{
|
|
|
|
regsUnitSet.top_arrow.PlayTopCenter(0, regIndex, -1, () => {
|
|
|
|
op_code_unit.ShakeUnit();
|
|
op_code_unit.ShowArrow(0, false, () =>
|
|
{
|
|
IIIALUUnit aLUUnit = op_code_unit.nextUnit.GetComponent<IIIALUUnit>();
|
|
aLUUnit.CommandRegist();
|
|
aLUUnit.ShakeUnit();
|
|
regsUnitSet.top_arrow.RewindTopArrow();
|
|
|
|
if (VonNeumann.data.num02 == 0)
|
|
{
|
|
aLUUnit.SetInfoTxt("值为0");
|
|
regsUnitSet.top_arrow.PlayCmdJmpTopCenter(() =>
|
|
{
|
|
JmpCmd();
|
|
});
|
|
|
|
void JmpCmd()
|
|
{
|
|
regsUnitSet.jump_arr.PlayArrow(true, () =>
|
|
{
|
|
pRegUnit.ShakeUnit();
|
|
pRegUnit.SetInfoTxt(orders[2]);
|
|
IIICommandUnitSet iIICommandUnitSet = IIINonNeumannControll.Instance.commandUnitSet.GetComponent<IIICommandUnitSet>();
|
|
|
|
int arrowIndex = iIICommandUnitSet.GetMatchCmdIndex();
|
|
pRegUnit.Active(
|
|
() =>
|
|
{
|
|
commandUnitSet.comboomItems[arrowIndex].AddressAct(orders[2]);
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
}, arrowIndex);
|
|
});
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
aLUUnit.SetInfoTxt("值为非0");
|
|
|
|
IIINonNeumannControll.Instance.SendSuccessToWeb();
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// 终止
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationHalt(string data, Action finish = null)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Rewind()
|
|
{
|
|
op_code_unit.RewindUnit();
|
|
op01_number_unit.RewindUnit();
|
|
op02_number_unit.RewindUnit();
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|