예제 #1
0
        protected void DumpInfo()
        {
            writer.WriteLine();
            writer.WriteLine("D0: {0}   D4: {1}   A0: {2}   A4: {3}     PC: {4}",
                             cpu.GetDataRegisterLong(0).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetDataRegisterLong(4).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(0).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(4).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetPC().ToString("x8", CultureInfo.InvariantCulture));
            writer.WriteLine("D1: {0}   D5: {1}   A1: {2}   A5: {3}     SR:  {4} {5}",
                             cpu.GetDataRegisterLong(1).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetDataRegisterLong(5).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(1).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(5).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetSR().ToString("x4", CultureInfo.InvariantCulture),
                             MakeFlagView());
            writer.WriteLine("D2: {0}   D6: {1}   A2: {2}   A6: {3}     USP: {4}",
                             cpu.GetDataRegisterLong(2).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetDataRegisterLong(6).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(2).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(6).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetUSP());
            writer.WriteLine("D3: {0}   D7: {1}   A3: {2}   A7: {3}     SSP: {4}",
                             cpu.GetDataRegisterLong(3).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetDataRegisterLong(7).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(3).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetAddrRegisterLong(7).ToString("x8", CultureInfo.InvariantCulture),
                             cpu.GetSSP().ToString("x8", CultureInfo.InvariantCulture));
            buffer.Clear();
            int addr = cpu.GetPC();

            if (addr < 0 || addr >= memory.Size())
            {
                buffer.Append($"{addr.ToString("x8", CultureInfo.InvariantCulture)}   ????");
            }
            else
            {
                int                     opcode = cpu.ReadMemoryWord(addr);
                IInstruction            i      = cpu.GetInstructionFor(opcode);
                DisassembledInstruction di     = i.Disassemble(addr, opcode);
                if (showBytes)
                {
                    di.FormatInstruction(buffer);
                }
                else
                {
                    di.ShortFormat(buffer);
                }
            }

            writer.WriteLine($"==> {buffer}{Environment.NewLine}");
        }
예제 #2
0
        protected void HandleDisassemble(string[] tokens)
        {
            if (tokens is null)
            {
                throw new ArgumentNullException(nameof(tokens));
            }

            int start;
            int num_instructions = 8;

            if (tokens.Length > 2)
            {
                try
                {
                    num_instructions = ParseInt(tokens[2]);
                }
                catch (FormatException)
                {
                    writer.WriteLine($"Invalid instruction count: {tokens[2]}");
                    return;
                }
            }

            if (tokens.Length > 1)
            {
                string address = tokens[1];
                try
                {
                    start = ParseInt(address);
                }
                catch (FormatException)
                {
                    writer.WriteLine($"Unknown address [{address}]");
                    return;
                }
            }
            else
            {
                start = cpu.GetPC();
            }

            int count = 0;

            buffer = new StringBuilder(80);
            while (start < memory.Size() && count < num_instructions)
            {
                buffer.Clear();
                int                     opcode = cpu.ReadMemoryWord(start);
                IInstruction            i      = cpu.GetInstructionFor(opcode);
                DisassembledInstruction di     = i.Disassemble(start, opcode);
                if (showBytes)
                {
                    di.FormatInstruction(buffer);
                }
                else
                {
                    di.ShortFormat(buffer);
                }

                writer.WriteLine(buffer.ToString());
                start += di.Size();
                count++;
            }
        }