public OutputLog(Disassembly disassembly) { DisassemblyOutput = disassembly.DisassemblyOutput; HighAddress = disassembly.HighAddress; LowAddress = disassembly.LowAddress; OpCodeString = disassembly.OpCodeString; }
private void SetDisassembly() { var addressMode = GetAddressingMode(); var currentProgramCounter = ProgramCounter; currentProgramCounter = WrapProgramCounter(++currentProgramCounter); int? address1 = Memory.ReadValue(currentProgramCounter); currentProgramCounter = WrapProgramCounter(++currentProgramCounter); int? address2 = Memory.ReadValue(currentProgramCounter); string disassembledStep = string.Empty; switch (addressMode) { case AddressingMode.Absolute: { disassembledStep = string.Format("${0}{1}", address2.Value.ToString("X").PadLeft(2, '0'), address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.AbsoluteX: { disassembledStep = string.Format("${0}{1},X", address2.Value.ToString("X").PadLeft(2, '0'), address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.AbsoluteY: { disassembledStep = string.Format("${0}{1},Y", address2.Value.ToString("X").PadLeft(2, '0'), address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.Accumulator: { address1 = null; address2 = null; disassembledStep = "A"; break; } case AddressingMode.Immediate: { disassembledStep = string.Format("#${0}", address1.Value.ToString("X").PadLeft(4, '0')); address2 = null; break; } case AddressingMode.Implied: { address1 = null; address2 = null; break; } case AddressingMode.Indirect: { disassembledStep = string.Format("(${0}{1})", address2.Value.ToString("X").PadLeft(2, '0'), address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.IndirectX: { address2 = null; disassembledStep = string.Format("(${0},X)", address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.IndirectY: { address2 = null; disassembledStep = string.Format("(${0}),Y", address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.Relative: { var relativeAddress = MoveProgramCounterByRelativeValue((byte)address1.Value); relativeAddress = WrapProgramCounter(relativeAddress); var stringAddress = relativeAddress.ToString("X").PadLeft(4, '0'); address1 = int.Parse(stringAddress.Substring(0, 2), NumberStyles.AllowHexSpecifier); address2 = int.Parse(stringAddress.Substring(2, 2),NumberStyles.AllowHexSpecifier); disassembledStep = string.Format("${0}", relativeAddress.ToString("X").PadLeft(4, '0')); break; } case AddressingMode.ZeroPage: { address2 = null; disassembledStep = string.Format("${0}", address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.ZeroPageX: { address2 = null; disassembledStep = string.Format("${0},X", address1.Value.ToString("X").PadLeft(2, '0')); break; } case AddressingMode.ZeroPageY: { address2 = null; disassembledStep = string.Format("${0},Y", address1.Value.ToString("X").PadLeft(4, '0')); break; } default: throw new InvalidEnumArgumentException("Invalid Addressing Mode"); } CurrentDisassembly = new Disassembly { HighAddress = address2.HasValue ? address2.Value.ToString("X").PadLeft(2,'0') : string.Empty, LowAddress = address1.HasValue ? address1.Value.ToString("X").PadLeft(2,'0') : string.Empty, OpCodeString = CurrentOpCode.ConvertOpCodeIntoString(), DisassemblyOutput = disassembledStep }; Log.DebugFormat("{0} : {1}{2}{3} {4} {5} A: {6} X: {7} Y: {8} SP {9} N: {10} V: {11} B: {12} D: {13} I: {14} Z: {15} C: {16}", ProgramCounter.ToString("X").PadLeft(4, '0'), CurrentOpCode.ToString("X").PadLeft(2, '0'), CurrentDisassembly.LowAddress, CurrentDisassembly.HighAddress, CurrentDisassembly.OpCodeString, CurrentDisassembly.DisassemblyOutput.PadRight(10, ' '), Accumulator.ToString("X").PadLeft(3, '0'), XRegister.ToString("X").PadLeft(3, '0'), YRegister.ToString("X").PadLeft(3, '0'), StackPointer.ToString("X").PadLeft(3, '0'), Convert.ToInt16(NegativeFlag), Convert.ToInt16(OverflowFlag), 0, Convert.ToInt16(DecimalFlag), Convert.ToInt16(DisableInterruptFlag), Convert.ToInt16(ZeroFlag), Convert.ToInt16(CarryFlag)); }