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.
282 lines
7.5 KiB
282 lines
7.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
namespace DisComputer
|
|
{
|
|
/// <summary>
|
|
/// 操作码单元集
|
|
/// </summary>
|
|
public class OperationUnitSet : MonoBehaviour
|
|
{
|
|
|
|
//操作码单元
|
|
public OpCodeUnit op_code_unit;
|
|
|
|
//操作数01单元
|
|
public TwoWayUnit op01_number_unit;
|
|
|
|
//操作数02单元
|
|
public TwoWayUnit op02_number_unit;
|
|
|
|
//寄存数集
|
|
public RegsUnitSet regsUnitSet;
|
|
|
|
|
|
// 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;
|
|
if (order.Contains("mov3"))
|
|
{
|
|
SetOperationMov3(order,finish);
|
|
}
|
|
else if (order.Contains("add"))
|
|
{
|
|
SetOperationAdd(order,finish);
|
|
}
|
|
else if (order.Contains("div"))
|
|
{
|
|
SetOperationAdd(order, finish);
|
|
}
|
|
else if (order.Contains("mul"))
|
|
{
|
|
SetOperationAdd(order, finish);
|
|
}
|
|
else if (order.Contains("sub"))
|
|
{
|
|
SetOperationAdd(order, finish);
|
|
}
|
|
else if (order.Contains("out"))
|
|
{
|
|
SetOperationOut(order,finish);
|
|
}
|
|
else if (order.Contains("halt"))
|
|
{
|
|
SetOperationHalt(order,finish);
|
|
}
|
|
|
|
}
|
|
|
|
/// <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],()=>
|
|
{
|
|
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加法指令
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="finish"></param>
|
|
void SetOperationAdd(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, "", () =>
|
|
{
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
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, "", () =>
|
|
{
|
|
StartCoroutine(AddProgress(reg_index, orders[0]));
|
|
});
|
|
});
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加法进度
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator AddProgress(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, () =>
|
|
{
|
|
ALUUnit aLUUnit = op_code_unit.nextUnit.GetComponent<ALUUnit>();
|
|
aLUUnit.CommandRegist();
|
|
aLUUnit.ShakeUnit();
|
|
|
|
regsUnitSet.top_arrow.PlayTopCenter(0, regIndex, 1, () =>
|
|
{
|
|
regsUnitSet.regs_list[regIndex].ArrowActive(0, VonNeumann.data.result.ToString(), () =>
|
|
{
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("operation VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
});
|
|
regsUnitSet.regs_list[regIndex + 1].RewindUnit();
|
|
});
|
|
});
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
//向上
|
|
regsUnitSet.regs_list[regIndex + 1].SelfActiveArrow(1, "", () =>
|
|
{
|
|
|
|
});
|
|
}
|
|
|
|
|
|
/// <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, "", () =>
|
|
{
|
|
//播放中间指向箭头
|
|
regsUnitSet.top_arrow.PlayTopCenter(reg_index, 10, 1, () =>
|
|
{
|
|
regsUnitSet.io_unit.ArrowActive(0, "", () =>
|
|
{
|
|
VonNeumannControll.Instance.FinishCurStep();
|
|
Debug.LogFormat("out VonNeumann.CommandIndex {0}", VonNeumann.CommandIndex);
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
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 SetOperationHalt(string data, Action finish = null)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Rewind()
|
|
{
|
|
op_code_unit.RewindUnit();
|
|
op01_number_unit.RewindUnit();
|
|
op02_number_unit.RewindUnit();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|