Exemple #1
0
        protected void HandleMemByte(string[] tokens)
        {
            if (tokens is null)
            {
                throw new ArgumentNullException(nameof(tokens));
            }

            if (tokens.Length != 2 && tokens.Length != 3)
            {
                writer.WriteLine("usage: mb <address> [value]");
            }
            else
            {
                string address = tokens[1];
                if (tokens.Length == 2)
                {
                    try
                    {
                        int addr = ParseInt(address);
                        if (addr < 0 || addr >= memory.Size())
                        {
                            writer.WriteLine("Address out of range");
                        }
                        else
                        {
                            writer.WriteLine("{0} {1}", addr.ToString("x", CultureInfo.InvariantCulture), cpu.ReadMemoryByte(addr).ToString("x", CultureInfo.InvariantCulture));
                        }
                    }
                    catch (FormatException e)
                    {
                        writer.Write(e.StackTrace);
                    }
                }
                else
                {
                    string value = tokens[2];
                    try
                    {
                        int addr = ParseInt(address);
                        if (addr < 0 || addr >= memory.Size())
                        {
                            writer.WriteLine("Address out of range");
                            return;
                        }

                        int v = ParseInt(value);
                        cpu.WriteMemoryByte(addr, v);
                    }
                    catch (FormatException e)
                    {
                        writer.Write(e.StackTrace);
                    }
                }
            }
        }