public void Clock() { // Read from HL pointed address if (!_readCycle.IsComplete) { _readCycle.Clock(); if (_readCycle.IsComplete) { _writeCycle.AddressedValue = _readCycle.AddressedValue; } return; } if (!_writeCycle.IsComplete) { _writeCycle.Clock(); return; } var bcValue = WideRegister.BC.GetValue(_cpu); if (((!_repeats || bcValue == 1) && --_additionalCycles > 0) || (_repeats && _additionalCycles-- > 0)) // If it's not repeating we need the last cycle of the additional cycles to carry out the instruction { return; } if (bcValue != 1 && _repeats && --_additionalRepeatCycles > 0) { // Prefix decrement here so we use the last addtional cycle to actually carry out the instruction return; } var deValue = WideRegister.DE.GetValue(_cpu); var hlValue = WideRegister.HL.GetValue(_cpu); if (_increment) { deValue++; hlValue++; } else { deValue--; hlValue--; } WideRegister.DE.SetValueOnProcessor(_cpu, deValue); WideRegister.HL.SetValueOnProcessor(_cpu, hlValue); WideRegister.BC.SetValueOnProcessor(_cpu, --bcValue); Z80Flags.HalfCarry_H.SetOrReset(_cpu, false); Z80Flags.AddSubtract_N.SetOrReset(_cpu, false); Z80Flags.ParityOverflow_PV.SetOrReset(_cpu, bcValue != 0); if (_repeats && bcValue != 0) { _cpu.PC -= 2; } IsComplete = true; }
public void Clock() { if (!_addressMode.IsComplete) { _addressMode.Clock(); if (_addressMode.IsComplete) { _valueReader = _addressMode.Reader; _valueWriter = _addressMode.Writer; if (_valueReader.IsComplete) { PerformDecrement(); } } return; } if (!_valueReader.IsComplete) { _valueReader.Clock(); if (_valueReader.IsComplete) { PerformDecrement(); } return; } if (!_valueWriter.IsComplete) { _valueWriter.Clock(); } }
public void Clock() { if (!_addressMode.IsComplete) { _addressMode.Clock(); if (_addressMode.IsComplete) { _reader = _addressMode.Reader; if (_reader.IsComplete) { ManipulateBit(); } } return; } if (!_reader.IsComplete) { _reader.Clock(); if (_reader.IsComplete) { ManipulateBit(); } return; } if (!_writer.IsComplete) { _writer.Clock(); } }
public void Clock() { if (!_read.IsComplete) { _read.Clock(); if (_read.IsComplete) { _write.AddressedValue = _targetRegister.GetValue(_cpu); _targetRegister.SetValueOnProcessor(_cpu, _read.AddressedValue); } return; } if (_additionalReadCycles-- > 0) { // http://www.baltazarstudios.com/files/xx.html#E3 shows that the cpu read/write signals aren't affected by // the extended cycles so we can just do nothing for these cycles return; } if (!_write.IsComplete) { _write.Clock(); return; } _additionalWriteCycles--; }
public void Clock() { if (!_addressMode.IsComplete) { _addressMode.Clock(); if (_addressMode.IsComplete) { _reader = _addressMode.Reader; _writer = _addressMode.Writer; } return; } if (!_reader.IsComplete) { _reader.Clock(); if (_reader.IsComplete) { DoRotate(); } return; } if (!_writer.IsComplete) { _writer.Clock(); } }
public virtual void Clock() { if (_remainingM1Cycles-- <= 0) { // Destination is checked first as its operand comes first if there are // additional bytes to the instruction. if (!_destinationAddressMode.IsComplete) { _destinationAddressMode.Clock(); if (_destinationAddressMode.IsComplete) { _destinationWriter = _destinationAddressMode.Writer; if (_sourceReader?.IsComplete ?? false) { _destinationWriter.AddressedValue = _sourceReader.AddressedValue; } } return; } if (!_sourceAddressMode.IsComplete) { _sourceAddressMode.Clock(); if (_sourceAddressMode.IsComplete) { _sourceReader = _sourceAddressMode.Reader; if (_sourceReader.IsComplete) { _destinationWriter.AddressedValue = _sourceReader.AddressedValue; } } return; } if (!_sourceReader.IsComplete) { _sourceReader.Clock(); if (_sourceReader.IsComplete) { _destinationWriter.AddressedValue = _sourceReader.AddressedValue; } return; } if (!_destinationWriter.IsComplete) { _destinationWriter.Clock(); } } }
public void Clock() { if (!_reader.IsComplete) { _reader.Clock(); return; } if (!_internalCycle.IsComplete) { _internalCycle.Clock(); if (_internalCycle.IsComplete) { var originalAccBits = _cpu.A & 0x0f; var newAccBits = 0; var shiftedValue = 0; if (_isLeftShift) { newAccBits = (_reader.AddressedValue & 0xf0) >> 4; shiftedValue = _reader.AddressedValue << 4; } else { newAccBits = _reader.AddressedValue & 0x0f; originalAccBits = originalAccBits << 4; shiftedValue = _reader.AddressedValue >> 4; } var newPointedValue = (shiftedValue & 0xff) | originalAccBits; _writer = _addressMode.Writer; _writer.AddressedValue = (byte)newPointedValue; _cpu.A = (byte)((_cpu.A & 0xf0) | newAccBits); // Set the flags Z80Flags.HalfCarry_H.SetOrReset(_cpu, false); Z80Flags.AddSubtract_N.SetOrReset(_cpu, false); Z80Flags.ParityOverflow_PV.SetOrReset(_cpu, _cpu.A.IsEvenParity()); Z80Flags.Sign_S.SetOrReset(_cpu, _cpu.A >= 0x80); Z80Flags.Zero_Z.SetOrReset(_cpu, _cpu.A == 0); } return; } if (!_writer.IsComplete) { _writer.Clock(); } }
public void Clock() { if (_remainingM1Cycles-- <= 0) { if (_remainingM1Cycles == -1) { _inputCycle.Address = (ushort)(_cpu.B << 8 | _cpu.C); } if (!_inputCycle.IsComplete) { _inputCycle.Clock(); if (_inputCycle.IsComplete) { _destinationWriter = _destination.Writer; _destinationWriter.AddressedValue = _inputCycle.LatchedData; } return; } if (!_destinationWriter.IsComplete) { _destinationWriter.Clock(); if (_destinationWriter.IsComplete) { var hlValue = WideRegister.HL.GetValue(_cpu); hlValue = (ushort)(_increment ? hlValue + 1 : hlValue - 1); WideRegister.HL.SetValueOnProcessor(_cpu, hlValue); Register.B.SetValueOnProcessor(_cpu, (byte)(_cpu.B - 1)); var input = _inputCycle.LatchedData; Z80Flags.Zero_Z.SetOrReset(_cpu, _cpu.B == 0); Z80Flags.AddSubtract_N.SetOrReset(_cpu, true); } return; } if (!_repeatCycles.IsComplete) { _repeatCycles.Clock(); if (_repeatCycles.IsComplete) { _cpu.PC -= 2; } } } }