private static string GetEffectCode(Propeller.MemoryManager memory, bool useShortOpcodes) { Spin.ParsedAssignment ParsedAssignment = new Spin.ParsedAssignment(memory.ReadByte()); string effect = ParsedAssignment.Push ? "" : "POP "; if (useShortOpcodes) { effect += "(" + ParsedAssignment.GetBasicInstruction().NameBrief + ")"; } else { effect += ParsedAssignment.GetBasicInstruction().Name; } if (!ParsedAssignment.Math) { Propeller.Spin.SubAssignment SubAssignment = ParsedAssignment.GetSubAssignment(); switch (SubAssignment.ArgumentMode) { case Propeller.Spin.ArgumentMode.None: break; case Propeller.Spin.ArgumentMode.SignedPackedOffset: effect += " " + DataUnpacker.GetSignedPackedOffset(memory); break; default: throw new Exception("Unexpected Spin Argument Mode: " + SubAssignment.ArgumentMode.ToString()); } } return(effect); }
public static string GetMemoryOp(Propeller.MemoryManager memory, bool useShortOpcodes) { Spin.ParsedMemoryOperation OP = new Spin.ParsedMemoryOperation(memory.ReadByte()); string Name = OP.GetRegister().Name; switch (OP.Action) { case Propeller.Spin.MemoryAction.PUSH: return(String.Format("PUSH {0}", Name)); case Propeller.Spin.MemoryAction.POP: return(String.Format("POP {0}", Name)); case Propeller.Spin.MemoryAction.EFFECT: return(String.Format("EFFECT {0} {1}", Name, GetEffectCode(memory, useShortOpcodes))); default: return(String.Format("UNKNOWN_{0} {1}", OP.Action, Name)); } }
private void Repaint(bool tick, InterpretedCog host) { Graphics g = Graphics.FromImage((Image)BackBuffer); Brush brush; g.Clear(SystemColors.Control); String display; uint topLine, bottomLine; topLine = 5; bottomLine = (uint)((ClientRectangle.Height / MonoFont.Height) - 5); zeroFlagLabel.Text = ""; carryFlagLabel.Text = ""; OpcodeSize.Visible = true; DisplayUnits.Visible = true; if (memoryViewButton.Checked) { for (uint i = (uint)positionScroll.Value, y = 0; y < ClientRectangle.Height; y += (uint)MonoFont.Height, i++) { if ((i > 0xFFFF) || (i < 0)) { continue; } uint mem = host[(int)i]; string binary = Convert.ToString((long)mem, 2); while (binary.Length < 32) { binary = "0" + binary; } display = String.Format("{0:X4}: {1:X8} {2} ", i, mem, binary); if (displayAsHexadecimal) { display = display + String.Format("{0:X8}", mem); } else { display = display + String.Format("{0}", mem); } g.FillRectangle(SystemBrushes.Control, 0, y, assemblyPanel.Width, y + MonoFont.Height); g.DrawString( display, (host.ProgramCursor == i) ? MonoFontBold : MonoFont, SystemBrushes.ControlText, 0, y); } } else { uint y = 0; for (uint i = (uint)positionScroll.Value, line = 1; y < ClientRectangle.Height; y += (uint)MonoFont.Height, line++) { if (i > 0xFFFF) { continue; } uint start = i; Propeller.MemoryManager mem = new Propeller.MemoryManager(Chip, i); string inst = InstructionDisassembler.InterpreterText(mem, displayAsHexadecimal, useShortOpcodes); i = mem.Address; display = String.Format("{0:X4}: ", start); InterpAddress[line] = start; for (uint q = start; q < start + 4; q++) { if (q < i) { byte b = Chip.DirectReadByte(q); display += String.Format(" {0:X2}", b); } else { display += " "; } } display += " " + inst; if (InterpAddress[line] == host.BreakPoint) { brush = System.Drawing.Brushes.Pink; } else if ((!followPCButton.Checked) || (line <= topLine) || (line >= bottomLine)) { brush = SystemBrushes.Control; } else { brush = SystemBrushes.Window; } g.FillRectangle(brush, 0, y, assemblyPanel.Width, y + MonoFont.Height); g.DrawString( display, (host.ProgramCursor == start) ? MonoFontBold : MonoFont, SystemBrushes.ControlText, 0, y); } StringBrush = SystemBrushes.ControlText; StringY = 0; StringX = (uint)(assemblyPanel.Width - StackMargin); DrawString(g, String.Format("@Stk[0] = ${0:X4} {0}", host.Stack)); DrawString(g, String.Format("@Obj[0] = ${0:X4} {0}", host.Object)); DrawString(g, String.Format("@Loc[0] = ${0:X4} {0}", host.Local)); DrawString(g, String.Format("@Var[0] = ${0:X4} {0}", host.Variable)); g.DrawLine(Pens.Black, assemblyPanel.Width - StackMargin, StringY, assemblyPanel.Width, StringY); DrawString(g, String.Format("Caller& = ${0:X4} {0}", Chip.DirectReadWord(host.Local - 8))); DrawString(g, String.Format(" ${0:X4} {0}", Chip.DirectReadWord(host.Local - 6))); DrawString(g, String.Format(" ${0:X4} {0}", Chip.DirectReadWord(host.Local - 4))); DrawString(g, String.Format("Return& = ${0:X4}", Chip.DirectReadWord(host.Local - 2))); g.DrawLine(Pens.Black, assemblyPanel.Width - StackMargin, StringY, assemblyPanel.Width, StringY); for (uint i = host.Local; i < host.Stack && StringY < ClientRectangle.Height; i += 4) { DrawString(g, String.Format("${0:X8} {0}", (int)Chip.DirectReadLong(i))); } } }
public static string InterpreterText(Propeller.MemoryManager memory, bool displayAsHexadecimal, bool useShortOpcodes) { string format; if (displayAsHexadecimal) { format = "{0} ${1:X}"; } else { format = "{0} {1}"; } Propeller.Spin.Instruction Instr = Propeller.Spin.Instructions[memory.ReadByte()]; string Name; if (useShortOpcodes) { Name = Instr.NameBrief; } else { Name = Instr.Name; } switch (Instr.ArgumentMode) { case Propeller.Spin.ArgumentMode.None: return(Name); case Propeller.Spin.ArgumentMode.UnsignedOffset: return(String.Format(format, Name, DataUnpacker.GetPackedOffset(memory))); case Propeller.Spin.ArgumentMode.UnsignedEffectedOffset: return(String.Format("{0} {1} {2}", Name, DataUnpacker.GetPackedOffset(memory), GetEffectCode(memory, useShortOpcodes))); case Propeller.Spin.ArgumentMode.Effect: return(String.Format(format, Name, GetEffectCode(memory, useShortOpcodes))); case Propeller.Spin.ArgumentMode.SignedOffset: return(String.Format(format, Name, DataUnpacker.GetSignedOffset(memory))); case Propeller.Spin.ArgumentMode.PackedLiteral: return(String.Format(format, Name, DataUnpacker.GetPackedLiteral(memory))); case Propeller.Spin.ArgumentMode.ByteLiteral: return(String.Format(format, Name, memory.ReadByte())); case Propeller.Spin.ArgumentMode.WordLiteral: return(String.Format(format, Name, DataUnpacker.GetWordLiteral(memory))); case Propeller.Spin.ArgumentMode.NearLongLiteral: return(String.Format(format, Name, DataUnpacker.GetNearLongLiteral(memory))); case Propeller.Spin.ArgumentMode.LongLiteral: return(String.Format(format, Name, DataUnpacker.GetLongLiteral(memory))); case Propeller.Spin.ArgumentMode.ObjCallPair: { byte obj = memory.ReadByte(); byte funct = memory.ReadByte(); return(String.Format("{0} {1}.{2}", Name, obj, funct)); } case Propeller.Spin.ArgumentMode.MemoryOpCode: return(String.Format("{0} {1}", Name, GetMemoryOp(memory, useShortOpcodes))); default: throw new Exception("Unknown Spin Argument Mode: " + Instr.ArgumentMode.ToString()); } }