Пример #1
0
            public override string ToText(MonitorContent content)
            {
                switch (content.Subtype)
                {
                case "progress": return($"{CurrentProgress:P2}");

                case "mode": return(AssemblerMode.ToString());

                case "coop": return(CooperativeMode ? "Cooperative" : "");

                case "repeat": return(Repeating ? "Repeating" : "");

                default: return("");
                }
            }
Пример #2
0
        /// <summary>
        /// The first pass for the assembler
        /// </summary>
        private void FirstPass(string[] lines, List <string[]> splitedLines,
                               Dictionary <string, uint> symbolTable, Dictionary <string, DefinedDataVariable> dataVariables, HashSet <string> functions)
        {
            int           currentLineNum = 0;
            AssemblerMode mode           = AssemblerMode.Text;

            for (int i = 0; i < lines.Length; i++)
            {
                string currentLine = lines[i];

                //Get the instruction and operands
                string[] instructionAndOperands = ExtractInstructionAndOperands(RemoveComments(currentLine));

                //Ignore empty lines
                if (instructionAndOperands.Length > 0)
                {
                    bool handled = false;

                    //Must be atleast 1 token
                    if (instructionAndOperands.Length >= 1)
                    {
                        bool skipLine = false;

                        //Check if assembler directive
                        if (instructionAndOperands[0].StartsWith("."))
                        {
                            if (instructionAndOperands[0] == ".data")
                            {
                                mode     = AssemblerMode.Data;
                                handled  = true;
                                skipLine = true;
                            }

                            if (instructionAndOperands[0] == ".text")
                            {
                                mode     = AssemblerMode.Text;
                                handled  = true;
                                skipLine = true;
                            }
                        }

                        //Check if starts with an label
                        if (instructionAndOperands[0].EndsWith(":"))
                        {
                            string label = instructionAndOperands[0].Substring(0, instructionAndOperands[0].Length - 1);

                            if (mode == AssemblerMode.Text)
                            {
                                symbolTable.Add(label, (uint)currentLineNum * 4);

                                //Must be atleast 2 tokens
                                if (instructionAndOperands.Length >= 2)
                                {
                                    instructionAndOperands = instructionAndOperands.Skip(1).ToArray();
                                    handled = true;
                                }

                                //Only a label, insert a NOP
                                if (instructionAndOperands.Length == 1)
                                {
                                    instructionAndOperands = new string[] { "nop" };
                                    handled = true;
                                }
                            }
                            else
                            {
                                string varType       = instructionAndOperands[1];
                                string varStartValue = instructionAndOperands[2];
                                int    startValue    = 0;

                                if (!int.TryParse(varStartValue, out startValue))
                                {
                                    throw new AssemblerException(i, "", "The current start value is not an integer.");
                                }

                                switch (varType)
                                {
                                case ".word":
                                    dataVariables.Add(label, new DefinedDataVariable()
                                    {
                                        StartValue = startValue, DataType = DataType.Word
                                    });
                                    break;

                                case ".byte":
                                    if (startValue >= 0 && startValue <= 255)
                                    {
                                        dataVariables.Add(label, new DefinedDataVariable()
                                        {
                                            StartValue = startValue, DataType = DataType.Byte
                                        });
                                    }
                                    else
                                    {
                                        throw new AssemblerException(i, "", "The byte value must be in the range [0, 255].");
                                    }
                                    break;

                                default:
                                    throw new AssemblerException(i, "", "Unrecognized data variable type '" + varType + "'.");
                                }

                                skipLine = true;
                                handled  = true;
                            }
                        }

                        //Check if a marco
                        if (!skipLine && mode == AssemblerMode.Text)
                        {
                            if (macros.ContainsKey(instructionAndOperands[0]))
                            {
                                //Get the macro
                                var macro = macros[instructionAndOperands[0]];

                                CurrentInstruction currentInstruction = new CurrentInstruction()
                                {
                                    LineNumber = i,
                                    Operands   = instructionAndOperands.Skip(1).ToArray(),
                                };

                                splitedLines.AddRange(macro(currentInstruction));
                                handled = true;
                            }
                            else
                            {
                                splitedLines.Add(instructionAndOperands);
                                handled = true;
                            }
                        }
                    }

                    if (!handled)
                    {
                        throw new AssemblerException(i, currentLine, string.Format("Unhandled instruction \"{0}\"", currentLine));
                    }

                    if (handled)
                    {
                        //Check if call instruction
                        if (instructionAndOperands[0] == "call" && instructionAndOperands.Length == 2)
                        {
                            //Add the called function to the list of functions
                            functions.Add(instructionAndOperands[1]);
                        }
                    }

                    currentLineNum++;
                }
            }
        }
Пример #3
0
	public void SetAssemblerMode(AssemblerMode mode, bool active) {
		switch (mode) {
		case AssemblerMode.WeaponOverviewMode :
			if (active) {
				PreviewWeaponComponents();
				weapon.gameObject.SetActive(true);
				preview.gameObject.SetActive(true);
			} else {
				weapon.gameObject.SetActive(false);
				preview.gameObject.SetActive(false);
				ClearPreviews();
			}
			break;
		case AssemblerMode.ComponentSelectionMode :
			if (active) {
				DisplayWeaponComponents();
				display.gameObject.SetActive(true);
			} else {
				display.gameObject.SetActive(false);
				ClearDisplays();
			}
			break;
		}
	}