private void PUSH(byte opcode, Register?registerPair) { _emulator.StackPointer = 0x2099; ProgramOptions options; if (registerPair.HasValue) { _emulator[registerPair.Value] = 0x32; _emulator[registerPair.Value + 1] = 0x57; options = new ProgramOptions(1); } else { // PSW will be modified options = new ProgramOptions(1, registerPair.Value, registerPair.Value + 1); } SetProgramAndStep(options, opcode); Assert.AreEqual(0x2097, _emulator.StackPointer); if (registerPair.HasValue) { Assert.AreEqual(0x57, _emulator[0x2097]); Assert.AreEqual(0x32, _emulator[0x2098]); } }
public Instruction(Operation op, Register?src, Register?dest, byte?[] immVal) { Operation = op; SourceRegister = src; DestinationRegister = dest; ImmediateValue = immVal; }
public static bool RegisterOverlap(Register?register1, Register?register2) { if ((register1 == null) || (register2 == null)) { return(false); } if (register1.Equals(register2)) { return(true); } string name1 = Enum.GetName(typeof(Register), register1), name2 = Enum.GetName(typeof(Register), register2); if ((name1.Contains("h") && name2.Contains("l")) || (name1.Contains("l") && name2.Contains("h"))) { return(false); } name1 = name1.Replace("h", "").Replace("l", "").Replace("x", "").Replace("e", "").Replace("r", ""); name2 = name2.Replace("h", "").Replace("l", "").Replace("x", "").Replace("e", "").Replace("r", ""); return(name1.Equals(name2)); }
// ------------------------------------------------------------------------ public static bool RegisterOverlap(Register?register1, Register?register2) { if ((register1 == null) || (register2 == null)) { return(false); } if (register1.Equals(register2)) { return(true); } string name1 = Enum.GetName(typeof(Register), register1), name2 = Enum.GetName(typeof(Register), register2); name1 = (name1.Length == 3) ? name1.Substring(1) : name1; name2 = (name2.Length == 3) ? name2.Substring(1) : name2; if ((name1.Contains("h") && name2.Contains("l")) || (name1.Contains("l") && name2.Contains("h"))) { return(false); } name1 = (name1.Contains("h") || name1.Contains("l") || name1.Contains("x")) ? name1.Substring(0, 1) : name1; name2 = (name2.Contains("h") || name2.Contains("l") || name2.Contains("x")) ? name2.Substring(0, 1) : name2; return(name1.Equals(name2)); }
private void POP(byte opcode, Register?registerPair) { _emulator.StackPointer = 0x2090; _emulator[0x2090] = 0xF5; _emulator[0x2091] = 0x01; ProgramOptions options; if (registerPair.HasValue) { options = new ProgramOptions(1, registerPair.Value, registerPair.Value + 1); } else { // PSW will be modified options = new ProgramOptions(1, registerPair.Value, registerPair.Value + 1); } SetProgramAndStep(options, opcode); Assert.AreEqual(0x2092, _emulator.StackPointer); if (registerPair.HasValue) { Assert.AreEqual(0x01, _emulator[registerPair.Value]); Assert.AreEqual(0xF5, _emulator[registerPair.Value + 1]); } }
Operand(Register?reg, Register?second, uint?val, string label, bool address = false) { this.Reg = reg; this.SecondReg = second; this.Disp = val; this.IsAddress = address; this.Label = label; }
public AddrMode(Register baseRegister, Register?indexRegister, int offset, byte scale, AddrModeSize size) { _baseReg = baseRegister; _indexReg = indexRegister; _offset = offset; _scale = scale; _size = size; }
public Expression(Symbol symbol, List <MiddleCode> shortList = null, List <MiddleCode> longList = null, Register?register = null) { m_symbol = symbol; m_shortList = (shortList != null) ? shortList : (new List <MiddleCode>()); m_longList = (longList != null) ? longList : (new List <MiddleCode>()); m_register = register; }
public AddrMode(Register baseRegister, Register? indexRegister, int offset, byte scale, AddrModeSize size) { BaseReg = baseRegister; IndexReg = indexRegister; Offset = offset; Scale = scale; Size = size; }
public Track(Symbol symbol, Register?register = null) { m_id = m_count++; Register = register; Assert.ErrorXXX(symbol != null); //Assert.ErrorXXX(!symbol.Type.IsStructOrUnion()); CurrentSize = m_maxSize = symbol.Type.ReturnSize(); }
public AddrMode(Register baseRegister, Register?indexRegister, int offset, byte scale, AddrModeSize size) { BaseReg = baseRegister; IndexReg = indexRegister; Offset = offset; Scale = scale; Size = size; }
private static void MoveImmediate(Emulator emulator, Register?register, byte value) { if (register.HasValue) { emulator[register.Value] = value; } else { emulator[emulator.Get16BitValue(Register.H, Register.L)] = value; } }
private void SUB(byte opcode, Register?register) { if (register.HasValue) { _emulator[register.Value] = 0x40; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0x40; } _emulator[Register.A] = 0x37; SetProgramAndStep(new ProgramOptions(1, new Register[] { Register.A }, register == Register.A ? new Flag[] { Flag.Z, Flag.P } : new Flag[] { Flag.S }), opcode); Assert.AreEqual(register == Register.A ? 0x00 : 0xF7, _emulator[Register.A]); }
private void ADD(byte opcode, Register?register) { if (register.HasValue) { _emulator[register.Value] = 0x51; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0x51; } _emulator[Register.A] = 0x47; SetProgramAndStep(new ProgramOptions(1, new Register[] { Register.A }, register == Register.A ? new Flag[] { Flag.S, Flag.P } : new Flag[] { Flag.S }), opcode); Assert.AreEqual(register == Register.A ? 0x8E : 0x98, _emulator[Register.A]); Assert.IsTrue(_emulator[Flag.S]); }
private void CMP(byte opcode, Register?register) { if (register.HasValue) { _emulator[register.Value] = 0x62; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0x62; } _emulator[Register.A] = 0x57; SetProgramAndStep(new ProgramOptions(1, new Register[] { }, register == Register.A ? new Flag[] { Flag.Z, Flag.P } : new Flag[] { Flag.S, Flag.P, Flag.C }), opcode); }
private void ANA(byte opcode, Register?register) { if (register.HasValue) { _emulator[register.Value] = 0x82; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0x82; } _emulator[Register.A] = 0x54; SetProgramAndStep(new ProgramOptions(1, register == Register.A ? new Register[] { } : new Register[] { Register.A }, register == Register.A ? new Flag[] { Flag.AC } : new Flag[] { Flag.Z, Flag.AC, Flag.P }), opcode); Assert.AreEqual(register == Register.A ? 0x54 : 0x00, _emulator[Register.A]); }
private void MOV(byte opcode, Register destination, Register?source) { if (source.HasValue) { _emulator[source.Value] = 0x34; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0x34; } var options = new ProgramOptions(1, source == destination ? new Register[] { } : new Register[] { destination }); SetProgramAndStep(options, opcode); Assert.AreEqual(0x34, _emulator[destination]); }
private void ADC(byte opcode, Register?register) { if (register.HasValue) { _emulator[register.Value] = 0xA1; } else { _emulator[Register.H] = 0x20; _emulator[Register.L] = 0x50; _emulator[0x2050] = 0xA1; } _emulator[Register.A] = 0x98; _emulator[Flag.C] = true; SetProgramAndStep(new ProgramOptions(1, new Register[] { Register.A }, register == Register.A ? new Flag[] { Flag.C } : new Flag[] { Flag.C, Flag.P }), opcode); Assert.AreEqual(register == Register.A ? 0x31 : 0x3A, _emulator[Register.A]); Assert.IsFalse(_emulator[Flag.C]); }
private static void IncrementSourceBy(Emulator emulator, Register?register, int increment) { var memoryAddress = emulator.Get16BitValue(Register.H, Register.L); var current = register.HasValue ? emulator[register.Value] : emulator[memoryAddress]; emulator[Flag.AC] = current.AuxiliaryCarryFlag((byte)(increment < 0 ? (-increment) : increment), increment > 0); current = (byte)(current + increment); emulator[Flag.P] = current.ParityFlag(); emulator[Flag.Z] = current == 0; emulator[Flag.S] = current.SignFlag(); if (register.HasValue) { emulator[register.Value] = current; } else { emulator[memoryAddress] = current; } }
public Track(Symbol symbol, Register?register = null) { m_name = "track" + (TrackCount++); m_register = register; Assert.ErrorXXX(symbol != null); Type type = symbol.Type; Assert.ErrorXXX(/*!type.IsFunction() &&*/ !type.IsStructOrUnion()); if (type.IsArrayFunctionOrString()) { m_minSize = m_currSize = m_maxSize = TypeSize.PointerSize; } else { m_minSize = m_currSize = m_maxSize = type.Size(); } Assert.ErrorXXX((m_currSize == 1) || (m_currSize == 2) || (m_currSize == 4) || (m_currSize == 8)); }
private static void CopyFromSourceToDestination(Emulator emulator, Register?source, Register destination) { emulator[destination] = source.HasValue ? emulator[source.Value] : emulator.GetHLMemoryValue(); }
/// <summary> /// Attempts to find the register associated with the specified index. /// </summary> /// <param name="index">The register index.</param> /// <param name="result">If successful, will contain the matching register.</param> public static bool TryGetRegister(uint index, [NotNullWhen(true)] out Register?result) { return(Registers.TryGetValue(index, out result)); }
public Address(Register? @base = null, ScaledIndex?scaledIndex = null, int displacement = 0) { Base = @base; ScaledIndex = scaledIndex; Displacement = displacement; }