예제 #1
0
        /// <summary>
        /// The INDR instruction.
        /// </summary>
        byte INDR()
        {
            FetchFinished();

            var portNumber = Registers.C;
            var address    = Registers.HL;
            var value      = ProcessorAgent.ReadFromPort(portNumber);

            ProcessorAgent.WriteToMemory(address.ToUShort(), value);

            Registers.HL = address.Dec();
            var counter = Registers.B;

            counter      = counter.Dec();
            Registers.B  = counter;
            Registers.ZF = (counter == 0);
            Registers.NF = 1;
            Registers.SF = counter.GetBit(7);
            SetFlags3and5From(counter);

            if (counter != 0)
            {
                Registers.PC = Registers.PC.Sub(2);
                return(21);
            }

            return(16);
        }
예제 #2
0
        /// <summary>
        /// The LDIR instruction.
        /// </summary>
        byte LDIR()
        {
            FetchFinished();

            var sourceAddress = Registers.HL;
            var destAddress   = Registers.DE;
            var counter       = Registers.BC;
            var value         = ProcessorAgent.ReadFromMemory(sourceAddress.ToUShort());

            ProcessorAgent.WriteToMemory(destAddress.ToUShort(), value);

            Registers.HL = sourceAddress.Inc();
            Registers.DE = destAddress.Inc();
            counter      = counter.Dec();
            Registers.BC = counter;

            Registers.HF = 0;
            Registers.NF = 0;
            Registers.PF = (counter != 0);

            var valuePlusA = value.Add(Registers.A).GetLowByte();

            Registers.Flag3 = valuePlusA.GetBit(3);
            Registers.Flag5 = valuePlusA.GetBit(1);

            if (counter != 0)
            {
                Registers.PC = Registers.PC.Sub(2);
                return(21);
            }

            return(16);
        }
예제 #3
0
        /// <summary>
        /// The LDIR instruction.
        /// </summary>
        byte LDIR()
        {
            FetchFinished();

            var sourceAddress = Registers.HL;
            var destAddress   = Registers.DE;
            var counter       = Registers.BC;
            var value         = ProcessorAgent.ReadFromMemory((ushort)sourceAddress);

            ProcessorAgent.WriteToMemory((ushort)destAddress, value);

            Registers.HL = (short)(sourceAddress + 1);
            Registers.DE = (short)(destAddress + 1);
            counter--;
            Registers.BC = counter;

            Registers.HF = 0;
            Registers.NF = 0;
            Registers.PF = (counter != 0);

            var valuePlusA = (byte)(value + Registers.A);

            Registers.Flag3 = valuePlusA.GetBit(3);
            Registers.Flag5 = valuePlusA.GetBit(1);

            if (counter != 0)
            {
                Registers.PC = (ushort)(Registers.PC - 2);
                return(21);
            }

            return(16);
        }
예제 #4
0
        /// <summary>
        /// The INDR instruction.
        /// </summary>
        byte INDR()
        {
            FetchFinished();

            var portNumber = Registers.C;
            var address    = Registers.HL;
            var value      = ProcessorAgent.ReadFromPort(portNumber);

            ProcessorAgent.WriteToMemory((ushort)address, value);

            Registers.HL--;
            var counter = Registers.B;

            counter      = (byte)(counter - 1);
            Registers.B  = counter;
            Registers.ZF = (counter == 0);
            Registers.NF = 1;
            Registers.SF = counter.GetBit(7);
            SetFlags3and5From(counter);

            if (counter != 0)
            {
                Registers.PC = (ushort)(Registers.PC - 2);
                return(21);
            }

            return(16);
        }
예제 #5
0
        /// <summary>
        /// The LD IXH,n instruction.
        /// </summary>
        byte LD_IXH_n()
        {
            var value = ProcessorAgent.FetchNextOpcode();

            FetchFinished();
            Registers.IXH = value;
            return(11);
        }
예제 #6
0
파일: IM n .cs 프로젝트: rholdorf/Z80dotNet
        /// <summary>
        /// The IM 2 instruction.
        /// </summary>
        private byte IM_2()
        {
            FetchFinished();

            ProcessorAgent.SetInterruptMode(2);

            return(8);
        }
예제 #7
0
        /// <summary>
        /// The OUT (C),0 instruction.
        /// </summary>
        byte OUT_C_0()
        {
            FetchFinished();

            ProcessorAgent.WriteToPort(Registers.C, 0);

            return(12);
        }
예제 #8
0
        /// <summary>
        /// The LD L,n instruction.
        /// </summary>
        byte LD_L_n()
        {
            var value = ProcessorAgent.FetchNextOpcode();

            FetchFinished();
            Registers.L = value;
            return(7);
        }
예제 #9
0
파일: JR .cs 프로젝트: rholdorf/Z80dotNet
        /// <summary>
        /// The JR d instruction.
        /// </summary>
        byte JR_d()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            Registers.PC = (ushort)(Registers.PC + (SByte)offset);

            return(12);
        }
예제 #10
0
        /// <summary>
        /// The OUT (n),A instruction.
        /// </summary>
        byte OUT_n_A()
        {
            var portNumber = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            ProcessorAgent.WriteToPort(portNumber, Registers.A);

            return(11);
        }
예제 #11
0
        /// <summary>
        /// The IN A,(n) instruction.
        /// </summary>
        byte IN_A_n()
        {
            var portNumber = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            Registers.A = ProcessorAgent.ReadFromPort(portNumber);

            return(11);
        }
예제 #12
0
        /// <summary>
        /// The LD (nn),A instruction.
        /// </summary>
        private byte LD_aa_A()
        {
            var address = FetchWord().ToUShort();

            FetchFinished();

            ProcessorAgent.WriteToMemory(address, Registers.A);

            return(13);
        }
예제 #13
0
파일: JR .cs 프로젝트: drako0812/Z80dotNet
        /// <summary>
        /// The JR d instruction.
        /// </summary>
        byte JR_d()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            Registers.PC = Registers.PC.AddSignedByte(offset);

            return(12);
        }
예제 #14
0
        /// <summary>
        /// The LD A,(nn) instruction.
        /// </summary>
        private byte LD_A_aa()
        {
            var address = FetchWord().ToUShort();

            FetchFinished();

            Registers.A = ProcessorAgent.ReadFromMemory(address);

            return(13);
        }
예제 #15
0
        /// <summary>
        /// The LD (HL),A instruction.
        /// </summary>
        byte LD_aHL_A()
        {
            FetchFinished();

            var newValue = Registers.A;
            var address  = (ushort)Registers.HL;

            ProcessorAgent.WriteToMemory(address, newValue);

            return(7);
        }
예제 #16
0
        /// <summary>
        /// The LD (DE),A instruction.
        /// </summary>
        byte LD_aDE_A()
        {
            FetchFinished();

            var newValue = Registers.A;
            var address  = Registers.DE.ToUShort();

            ProcessorAgent.WriteToMemory(address, newValue);

            return(7);
        }
예제 #17
0
        /// <summary>
        /// The LD L,(HL) instruction.
        /// </summary>
        byte LD_L_aHL()
        {
            FetchFinished();

            var address  = Registers.HL.ToUShort();
            var oldValue = ProcessorAgent.ReadFromMemory(address);

            Registers.L = oldValue;

            return(7);
        }
예제 #18
0
        /// <summary>
        /// The LD A,(HL) instruction.
        /// </summary>
        byte LD_A_aHL()
        {
            FetchFinished();

            var address  = (ushort)Registers.HL;
            var oldValue = ProcessorAgent.ReadFromMemory(address);

            Registers.A = oldValue;

            return(7);
        }
예제 #19
0
        /// <summary>
        /// The LD A,(DE) instruction.
        /// </summary>
        byte LD_A_aDE()
        {
            FetchFinished();

            var address  = Registers.DE.ToUShort();
            var oldValue = ProcessorAgent.ReadFromMemory(address);

            Registers.A = oldValue;

            return(7);
        }
예제 #20
0
        /// <summary>
        /// The LD (HL),n instruction.
        /// </summary>
        private byte LD_aHL_N()
        {
            var newValue = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var address = (ushort)Registers.HL;

            ProcessorAgent.WriteToMemory(address, newValue);

            return(10);
        }
예제 #21
0
        /// <summary>
        /// The LD (IY+n),L instruction.
        /// </summary>
        byte LD_aIY_plus_n_L()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var newValue = Registers.L;
            var address  = (ushort)(Registers.IY + (SByte)offset);

            ProcessorAgent.WriteToMemory(address, newValue);

            return(19);
        }
예제 #22
0
        /// <summary>
        /// The LD L,(IY+n) instruction.
        /// </summary>
        byte LD_L_aIY_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var address  = (ushort)(Registers.IY + (SByte)offset);
            var oldValue = ProcessorAgent.ReadFromMemory(address);

            Registers.L = oldValue;

            return(19);
        }
예제 #23
0
        /// <summary>
        /// The LD (IY+n),L instruction.
        /// </summary>
        byte LD_aIY_plus_n_L()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var newValue = Registers.L;
            var address  = Registers.IY.ToUShort().Add(offset.ToSignedByte());

            ProcessorAgent.WriteToMemory(address, newValue);

            return(19);
        }
예제 #24
0
        /// <summary>
        /// The LD L,(IY+n) instruction.
        /// </summary>
        byte LD_L_aIY_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var address  = Registers.IY.ToUShort().Add(offset.ToSignedByte());
            var oldValue = ProcessorAgent.ReadFromMemory(address);

            Registers.L = oldValue;

            return(19);
        }
예제 #25
0
        /// <summary>
        /// The PUSH DE instruction.
        /// </summary>
        private byte PUSH_DE()
        {
            FetchFinished();

            var valueToPush = Registers.DE;
            var sp          = (ushort)(Registers.SP - 1);

            ProcessorAgent.WriteToMemory(sp, valueToPush.GetHighByte());
            sp--;
            ProcessorAgent.WriteToMemory(sp, valueToPush.GetLowByte());
            Registers.SP = (short)sp;

            return(11);
        }
예제 #26
0
        /// <summary>
        /// The PUSH DE instruction.
        /// </summary>
        private byte PUSH_DE()
        {
            FetchFinished();

            var valueToPush = Registers.DE;
            var sp          = Registers.SP.Dec();

            ProcessorAgent.WriteToMemory(sp.ToUShort(), valueToPush.GetHighByte());
            sp = sp.Dec();
            ProcessorAgent.WriteToMemory(sp.ToUShort(), valueToPush.GetLowByte());
            Registers.SP = sp;

            return(11);
        }
예제 #27
0
        /// <summary>
        /// The RETI instruction.
        /// </summary>
        private byte RETI()
        {
            FetchFinished(isRet: true);

            var sp    = Registers.SP.ToUShort();
            var newPC = NumberUtils.CreateShort(
                ProcessorAgent.ReadFromMemory(sp),
                ProcessorAgent.ReadFromMemory(sp.Inc()));

            Registers.PC = newPC.ToUShort();

            Registers.SP = Registers.SP.Add(2);

            return(14);
        }
예제 #28
0
        /// <summary>
        /// The BIT 7,(IY+n) instruction
        /// </summary>
        byte BIT_7_aIY_plus_n(byte offset)
        {
            FetchFinished();

            var address  = (ushort)(Registers.IY + (SByte)offset);
            var oldValue = ProcessorAgent.ReadFromMemory(address);
            var bitValue = oldValue.GetBit(7);

            Registers.ZF = Registers.PF = ~bitValue;
            Registers.SF = bitValue;
            Registers.HF = 1;
            Registers.NF = 0;

            return(20);
        }
예제 #29
0
        /// <summary>
        /// The IN F,(C) instruction.
        /// </summary>
        byte IN_F_C()
        {
            FetchFinished();

            var value = ProcessorAgent.ReadFromPort(Registers.C);

            Registers.SF = value.GetBit(7);
            Registers.ZF = (value == 0);
            Registers.NF = 0;
            Registers.HF = 0;
            Registers.PF = Parity[value];
            SetFlags3and5From(value);

            return(12);
        }
예제 #30
0
        /// <summary>
        /// The POP BC instruction.
        /// </summary>
        private byte POP_BC()
        {
            FetchFinished();

            var sp    = Registers.SP.ToUShort();
            var newBC = NumberUtils.CreateShort(
                ProcessorAgent.ReadFromMemory(sp),
                ProcessorAgent.ReadFromMemory(sp.Inc()));

            Registers.BC = newBC;

            Registers.SP = Registers.SP.Add(2);

            return(10);
        }