#include "Z80Instruction.h" #ifndef __Z80_AND8_H__ #define __Z80_AND8_H__ namespace Z80 { class AND8 :public Z80Instruction { public: virtual AND8* Clone() const {return new AND8();} virtual AND8* ClonePlacement(void* buffer) const {return new(buffer) AND8();} virtual size_t GetOpcodeClassByteSize() const {return sizeof(*this);} virtual bool RegisterOpcode(OpcodeTable& table) const { bool result = true; result &= table.AllocateRegionToOpcode(this, L"10100***", L""); result &= table.AllocateRegionToOpcode(this, L"11100110", L""); return result; } virtual std::wstring GetOpcodeName() const { return L"AND"; } virtual Disassembly Z80Disassemble(const Z80::LabelSubstitutionSettings& labelSettings) const { return Disassembly(GetOpcodeName(), _target.Disassemble() + L", " + _source.Disassemble()); } virtual void Z80Decode(Z80* cpu, const Z80Word& location, const Z80Byte& data, bool transparent) { _source.SetIndexState(GetIndexState(), GetIndexOffset()); _target.SetIndexState(GetIndexState(), GetIndexOffset()); _target.SetMode(EffectiveAddress::Mode::A); if (_source.Decode8BitRegister(data.GetDataSegment(0, 3))) { // AND A,r 10100rrr AddExecuteCycleCount(4); } else if (data.GetBit(6)) { // AND A,n 11100110 _source.BuildImmediateData(BITCOUNT_BYTE, location + GetInstructionSize(), cpu, transparent); AddExecuteCycleCount(7); } else { // AND A,(HL) 10100110 // AND A,(IX + d) 11011101 10100110 dddddddd // AND A,(IY + d) 11111101 10100110 dddddddd _source.SetMode(EffectiveAddress::Mode::HLIndirect); if (GetIndexState() == EffectiveAddress::IndexState::None) { AddExecuteCycleCount(7); } else { AddExecuteCycleCount(15); } } AddInstructionSize(GetIndexOffsetSize(_source.UsesIndexOffset() || _target.UsesIndexOffset())); AddInstructionSize(_source.ExtensionSize()); AddInstructionSize(_target.ExtensionSize()); } virtual ExecuteTime Z80Execute(Z80* cpu, const Z80Word& location) const { double additionalTime = 0; Z80Byte op1; Z80Byte op2; Z80Byte result; // Perform the operation additionalTime += _source.Read(cpu, location, op1); additionalTime += _target.Read(cpu, location, op2); result = op2 & op1; additionalTime += _target.Write(cpu, location, result); // Set the flag results cpu->SetFlagS(result.Negative()); cpu->SetFlagZ(result.Zero()); cpu->SetFlagY(result.GetBit(5)); cpu->SetFlagH(true); cpu->SetFlagX(result.GetBit(3)); cpu->SetFlagPV(result.ParityEven()); cpu->SetFlagN(false); cpu->SetFlagC(false); // Adjust the PC and return the execution time cpu->SetPC(location + GetInstructionSize()); return GetExecuteCycleCount(additionalTime); } private: EffectiveAddress _source; EffectiveAddress _target; }; } // Close namespace Z80 #endif