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.
232 lines
5.3 KiB
232 lines
5.3 KiB
using DisComputer;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 指令数据
|
|
/// </summary>
|
|
public class CommandData
|
|
{
|
|
|
|
//指令内容
|
|
public CommandType command;
|
|
|
|
public int num01;
|
|
|
|
public int num02;
|
|
|
|
public int result;
|
|
|
|
/// <summary>
|
|
/// 内存地址
|
|
/// </summary>
|
|
public string mem;
|
|
|
|
|
|
//具体执行名称
|
|
public string ActName;
|
|
|
|
/// <summary>
|
|
/// 指令名称
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
string _name = "空指令";
|
|
|
|
switch (command)
|
|
{
|
|
case CommandType.Add:
|
|
_name = "加法指令";
|
|
break;
|
|
case CommandType.Div:
|
|
_name = "除法指令";
|
|
break;
|
|
case CommandType.Mul:
|
|
_name = "乘法指令";
|
|
break;
|
|
case CommandType.Sub:
|
|
_name = "减法指令";
|
|
break;
|
|
}
|
|
|
|
return _name;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回算式指令
|
|
/// </summary>
|
|
public List<string> ActCommandList { get {
|
|
List<string> _temp = new List<string>();
|
|
string[] _tempArr;
|
|
switch (command)
|
|
{
|
|
case CommandType.Add:
|
|
_tempArr = new string[5] { "mov3","mov3","add","out","halt"};
|
|
_temp = new List<string>(_tempArr);
|
|
break;
|
|
case CommandType.Div:
|
|
_tempArr = new string[5] { "mov3", "mov3", "div", "out", "halt" };
|
|
_temp = new List<string>(_tempArr);
|
|
break;
|
|
case CommandType.Mul:
|
|
_tempArr = new string[5] { "mov3", "mov3", "mul", "out", "halt" };
|
|
_temp = new List<string>(_tempArr);
|
|
break;
|
|
case CommandType.Sub:
|
|
_tempArr = new string[5] { "mov3", "mov3", "sub", "out", "halt" };
|
|
_temp = new List<string>(_tempArr);
|
|
break;
|
|
}
|
|
return _temp;
|
|
} }
|
|
|
|
|
|
/// <summary>
|
|
/// 随机干扰指令
|
|
/// </summary>
|
|
public List<string> JamCommandList {
|
|
get {
|
|
string[] _tempArr = new string[9] { "mov1", "mov2","add","div","mul" , "sub" ,"jmp","jz","in"};
|
|
List<string> _temp = new List<string>(_tempArr);
|
|
return _temp;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置随机指令集
|
|
/// </summary>
|
|
/// <param name="type"> mov operations io jmp</param>
|
|
public void SetRandomCmdType(string type)
|
|
{
|
|
if (type.Contains("mov"))//mov指令
|
|
{
|
|
CommandType[] commands = { CommandType.Mov1, CommandType.Mov2, CommandType.Mov3 };
|
|
command = commands[Random.Range(0, commands.Length)];
|
|
}
|
|
else if (type.Contains("operations"))//运算指令
|
|
{
|
|
CommandType[] commands = { CommandType.Mul, CommandType.Sub, CommandType.Add ,CommandType.Div};
|
|
command = commands[Random.Range(0, commands.Length)];
|
|
}
|
|
else if (type.Contains("IO"))//IO流指令
|
|
{
|
|
CommandType[] commands = { CommandType.Out, CommandType.In };
|
|
command = commands[Random.Range(0, commands.Length)];
|
|
}
|
|
else if (type.Contains("jmp"))//条件指令
|
|
{
|
|
CommandType[] commands = { CommandType.Jz, CommandType.Jmp };
|
|
command = commands[Random.Range(0, commands.Length)];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public enum CommandType
|
|
{
|
|
Null,
|
|
//加法
|
|
Add,
|
|
//减法
|
|
Sub,
|
|
//乘法,
|
|
Mul,
|
|
//除法
|
|
Div,
|
|
//mov1指令
|
|
Mov1,
|
|
//mov2指令
|
|
Mov2,
|
|
//mov3指令
|
|
Mov3,
|
|
//无条件跳转指令
|
|
Jmp,
|
|
//条件跳转指令
|
|
Jz,
|
|
//输入指令
|
|
In,
|
|
//输出指令
|
|
Out,
|
|
//运算式
|
|
Operator
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 诺依曼指令数据
|
|
/// </summary>
|
|
public class VonNeumann
|
|
{
|
|
public static CommandData data;
|
|
/// <summary>
|
|
/// 指令下标
|
|
/// </summary>
|
|
public static int CommandIndex = 0;
|
|
|
|
/// <summary>
|
|
/// 指令正在运行
|
|
/// </summary>
|
|
public static bool isRunning = false;
|
|
|
|
/// <summary>
|
|
/// 是否完成
|
|
/// </summary>
|
|
public static bool isFinish = false;
|
|
|
|
|
|
/// <summary>
|
|
/// 指令操作说明
|
|
/// </summary>
|
|
public static string cmdTipInfo = "";
|
|
|
|
|
|
/// <summary>
|
|
/// 当前指令地址
|
|
/// </summary>
|
|
public static int curpRegIndex;
|
|
|
|
/// <summary>
|
|
/// 当前mov1 mov2 mem 下标值
|
|
/// </summary>
|
|
public static int movMemIndex;
|
|
|
|
/// <summary>
|
|
/// 当前寄存器下标
|
|
/// </summary>
|
|
public static int curRexIndex;
|
|
|
|
/// <summary>
|
|
/// 当前指令配置信息
|
|
/// </summary>
|
|
public static IIICmdConfig cmdConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 数据匹对
|
|
/// </summary>
|
|
public class MatchVonNeuData
|
|
{
|
|
public static int rexIndex = -1;
|
|
|
|
public static int pRegIndex = -1;
|
|
|
|
public static int mem = -1;
|
|
|
|
public static int op01Index = -1;
|
|
|
|
public static int op02Index = -1;
|
|
}
|