Beispiel #1
0
        public Processor()
            : base()
        {
            Instructions = new InstructionDictionary(this);

            Draw = true;

            ModifyI = false;

            Printed = false;
            Playing = false;

            Stack = new NotifiableList <ushort>();
            for (int i = 0; i < 16; i++)
            {
                Stack.Add(0);
            }

            V = new NotifiableList <byte>();
            for (int i = 0; i < 16; i++)
            {
                V.Add(0);
            }

            // Reset random number generator.
            RandomGenerator = new Random();
        }
        private void disassemble(ushort start, ushort end)
        {
            Generic.DataStructures.InstructionTemplate instTemplate;
            Instruction inst;

            Memory mem = (Memory)Source.Memory;
            InstructionDictionary instructions = ((Processor)Source.Processor).Instructions;

            sb.Length = 0;

            List <object> dumpArgs = new List <object>();

            const int instWidth = 17;

            ushort opcode;

            for (int i = start; i <= end; i += 2)
            {
                dumpArgs.Clear();
                dumpArgs.Add(i);

                if (i == end)
                {
                    dumpArgs.Add(String.Format("{0:X2}  ", mem[end]));
                    dumpArgs.Add("".PadRight(instWidth, ' '));
                    dumpArgs.Add(getDrawingBytes((ushort)(mem[end] << 8)));
                }
                else
                {
                    opcode = (ushort)((mem[i] << 8) | mem[i + 1]);

                    instructions.TryGetValue(opcode, out instTemplate);
                    inst = (Instruction)instTemplate.FormInstruction(opcode);

                    dumpArgs.Add(String.Format("{0:X4}", opcode));
                    dumpArgs.Add(inst.ToString().PadRight(instWidth, ' '));
                    dumpArgs.Add(getDrawingBytes(opcode));
                }

                sb.Append(String.Format("0x{0:X4}:  0x{1}  {2}  {3}", dumpArgs.ToArray()));

                if (i < end - 1)
                {
                    sb.Append(Environment.NewLine);
                }
            }

            txtDisasm.Text = sb.ToString();
        }