Пример #1
0
		public OpcodeParamResult ParseLiteralParameter (OpcodeParamResult opcodeParamResult, string clearedParameter)
		{
			ushort literalValue;
        	
        	if (clearedParameter.StartsWith("\'") && clearedParameter.EndsWith("\'") && clearedParameter.Length == 3)
        	{
        	    literalValue = clearedParameter[1];
        	}
        	else if (clearedParameter.Contains("0x"))
        	{
        	    literalValue = Convert.ToUInt16(clearedParameter, 16);
        	}
        	else if (clearedParameter.Trim().All(x => char.IsDigit(x)))
        	{
        	    literalValue = Convert.ToUInt16(clearedParameter, 10);
        	}
        	else
        	{
        	    opcodeParamResult.Param = (ushort)dcpuRegisterCodes.NextWord_Literal_Value;
        	    opcodeParamResult.NextWord = true;
        	    opcodeParamResult.LabelName = clearedParameter;
        	    return opcodeParamResult;
        	}

            ushort maxValue = 0x1F;
        		
        	if (literalValue < maxValue)
        	{
                opcodeParamResult.Param = 0x20;
        	    opcodeParamResult.Param += literalValue;
        	}
        	else
        	{
        	    opcodeParamResult.Param = (ushort)dcpuRegisterCodes.NextWord_Literal_Value;
        	    opcodeParamResult.NextWord = true;
        	    opcodeParamResult.NextWordValue = literalValue;
        	}
			
			return opcodeParamResult;
		}
Пример #2
0
		public OpcodeParamResult ParseMemoryAddressPlusRegisterParameter (OpcodeParamResult opcodeParamResult, string clearedParameter)
		{
			var psplit = clearedParameter.Split('+');
        	if (psplit.Length < 2)
        	{
        	    throw new Exception(string.Format("malformated memory reference '{0}'", clearedParameter));
        	}
        	
        	var addressValue = "[+" + psplit[1] + "]";
        	if (!this.registerDictionary.ContainsKey(addressValue))
        	{
        	    throw new Exception(string.Format("Invalid register reference in '{0}'", clearedParameter));
        	}
        	
        	opcodeParamResult.Param = (ushort)this.registerDictionary[addressValue];
        	opcodeParamResult.NextWord = true;
        	
        	if (psplit[0].StartsWith("\'") && psplit[0].EndsWith("\'") && psplit[0].Length == 3)
        	{
        	    var val = (ushort)psplit[0][1];
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else if (psplit[0].Contains("0x"))
        	{
        	    ushort val = Convert.ToUInt16(psplit[0].Trim(), 16);
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else if (psplit[0].Trim().All(x => char.IsDigit(x)))
        	{
        	    var val = Convert.ToUInt16(psplit[0].Trim(), 10);
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else
        	{
        	    opcodeParamResult.NextWord = true;
        	    opcodeParamResult.LabelName = psplit[0].Trim();
        	}
			
			return opcodeParamResult;
		}
Пример #3
0
		public OpcodeParamResult ParseMemoryAddressParameter (OpcodeParamResult opcodeParamResult, string clearedParameter)
		{
			opcodeParamResult.Param = (ushort)dcpuRegisterCodes.NextWord_Literal_Mem;
        	opcodeParamResult.NextWord = true;
        	
        	if (clearedParameter.StartsWith("\'") && clearedParameter.EndsWith("\'") && clearedParameter.Length == 5)
        	{
        	    ushort val = clearedParameter[1];
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else if (clearedParameter.Contains("0x"))
        	{
        	    ushort val = Convert.ToUInt16(clearedParameter.Trim(), 16);
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else if (clearedParameter.Trim().All(x => char.IsDigit(x)))
        	{
        	    ushort val = Convert.ToUInt16(clearedParameter.Trim(), 10);
        	    opcodeParamResult.NextWordValue = val;
        	}
        	else
        	{
        	    opcodeParamResult.NextWord = true;
        	    opcodeParamResult.LabelName = clearedParameter.Trim();
        	}
			
			return opcodeParamResult;
		}
Пример #4
0
        private OpcodeParamResult ParseParam(string param)
        {
            var opcodeParamResult = new OpcodeParamResult();

            var clearedParameter = param.Replace(" ", string.Empty).Trim();

            if (this.registerDictionary.ContainsKey(clearedParameter))
            {
                opcodeParamResult.Param = (ushort)this.registerDictionary[clearedParameter];
            }
            else
            {
                if ((clearedParameter.StartsWith("[") || clearedParameter.StartsWith("("))  && (clearedParameter.EndsWith("]") || clearedParameter.EndsWith(")")))
                {
					clearedParameter = clearedParameter.Substring(1, clearedParameter.Length - 2).Replace(" ", string.Empty);
						
                    if (clearedParameter.Contains("+"))
                    {
						opcodeParamResult = ParseMemoryAddressPlusRegisterParameter(opcodeParamResult, clearedParameter);
                    }
                    else
                    {
                        opcodeParamResult = ParseMemoryAddressParameter(opcodeParamResult, clearedParameter);
                    }
                }
                else
                {
					ParseLiteralParameter (opcodeParamResult, clearedParameter);
                }
            }

            return opcodeParamResult;
        }