Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The POP HL instruction.
        /// </summary>
        private byte POP_HL()
        {
            FetchFinished();

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

            Registers.HL = newHL;

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

            return(10);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The RETI instruction.
        /// </summary>
        private byte RETI()
        {
            FetchFinished(isRet: true);

            var sp    = (ushort)Registers.SP;
            var newPC = NumberUtils.CreateShort(
                ProcessorAgent.ReadFromMemory(sp),
                ProcessorAgent.ReadFromMemory((ushort)(sp + 1)));

            Registers.PC = (ushort)newPC;

            Registers.SP += 2;

            return(14);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The BIT 7,(HL) instruction
        /// </summary>
        byte BIT_7_aHL()
        {
            FetchFinished();

            var address  = (ushort)Registers.HL;
            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(12);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The POP BC instruction.
        /// </summary>
        private byte POP_BC()
        {
            FetchFinished();

            var sp    = (ushort)Registers.SP;
            var newBC = NumberUtils.CreateShort(
                ProcessorAgent.ReadFromMemory(sp),
                ProcessorAgent.ReadFromMemory((ushort)(sp + 1)));

            Registers.BC = newBC;

            Registers.SP += 2;

            return(10);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The BIT 7,(IY+n) instruction
        /// </summary>
        byte BIT_7_aIY_plus_n(byte offset)
        {
            FetchFinished();

            var address  = Registers.IY.ToUShort().Add(offset.ToSignedByte());
            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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The RETN instruction.
        /// </summary>
        private byte RETN()
        {
            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);

            Registers.IFF1 = Registers.IFF2;

            return(14);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// The DEC (HL) instruction.
        /// </summary>
        private byte DEC_aHL()
        {
            FetchFinished();

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

            ProcessorAgent.WriteToMemory(address, newValue);

            Registers.SF = newValue.GetBit(7);
            Registers.ZF = (newValue == 0);
            Registers.HF = ((newValue & 0x0F) == 0x0F);
            Registers.PF = (newValue == 0x7F);
            Registers.NF = 1;
            SetFlags3and5From(newValue);

            return(11);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// The INC (HL) instruction.
        /// </summary>
        private byte INC_aHL()
        {
            FetchFinished();

            var address  = (ushort)Registers.HL;
            var oldValue = ProcessorAgent.ReadFromMemory(address);
            var newValue = (byte)(oldValue + 1);

            ProcessorAgent.WriteToMemory(address, newValue);

            Registers.SF = newValue.GetBit(7);
            Registers.ZF = (newValue == 0);
            Registers.HF = ((newValue & 0x0F) == 0x00);
            Registers.PF = (newValue == 0x80);
            Registers.NF = 0;
            SetFlags3and5From(newValue);

            return(11);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// The RET PO instruction.
        /// </summary>
        private byte RET_PO()
        {
            FetchFinished(isRet: true);

            if (Registers.PF == 1)
            {
                return(5);
            }

            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(11);
        }
Ejemplo n.º 11
0
        /// The OR (HL) instruction.
        /// </summary>
        private byte OR_aHL()
        {
            FetchFinished();

            var oldValue = Registers.A;
            var address  = (ushort)Registers.HL;
            var argument = ProcessorAgent.ReadFromMemory(address);
            var newValue = (byte)(oldValue | argument);

            Registers.A = newValue;

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

            return(7);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The DEC (IY+n) instruction.
        /// </summary>
        private byte DEC_aIY_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

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

            ProcessorAgent.WriteToMemory(address, newValue);

            Registers.SF = newValue.GetBit(7);
            Registers.ZF = (newValue == 0);
            Registers.HF = ((newValue & 0x0F) == 0x0F);
            Registers.PF = (newValue == 0x7F);
            Registers.NF = 1;
            SetFlags3and5From(newValue);

            return(23);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// The DEC (IY+n) instruction.
        /// </summary>
        private byte DEC_aIY_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

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

            ProcessorAgent.WriteToMemory(address, newValue);

            Registers.SF = newValue.GetBit(7);
            Registers.ZF = (newValue == 0);
            Registers.HF = ((newValue & 0x0F) == 0x0F);
            Registers.PF = (newValue == 0x7F);
            Registers.NF = 1;
            SetFlags3and5From(newValue);

            return(23);
        }
Ejemplo n.º 14
0
        /// The AND (IY+n) instruction.
        /// </summary>
        private byte AND_aIY_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var oldValue = Registers.A;
            var address  = (ushort)(Registers.IY + (SByte)offset);
            var argument = ProcessorAgent.ReadFromMemory(address);
            var newValue = (byte)(oldValue & argument);

            Registers.A = newValue;

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

            return(19);
        }
Ejemplo n.º 15
0
        /// The OR (IX+n) instruction.
        /// </summary>
        private byte OR_aIX_plus_n()
        {
            var offset = ProcessorAgent.FetchNextOpcode();

            FetchFinished();

            var oldValue = Registers.A;
            var address  = Registers.IX.ToUShort().Add(offset.ToSignedByte());
            var argument = ProcessorAgent.ReadFromMemory(address);
            var newValue = (byte)(oldValue | argument);

            Registers.A = newValue;

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

            return(19);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// The OUTD instruction.
        /// </summary>
        byte OUTD()
        {
            FetchFinished();

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

            ProcessorAgent.WriteToPort(portNumber, 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);


            return(16);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// The OUTI instruction.
        /// </summary>
        byte OUTI()
        {
            FetchFinished();

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

            ProcessorAgent.WriteToPort(portNumber, 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);


            return(16);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// The RLD instruction.
        /// </summary>
        byte RLD()
        {
            FetchFinished();

            var memoryAddress = Registers.HL.ToUShort();

            var Avalue     = Registers.A;
            var HLcontents = ProcessorAgent.ReadFromMemory(memoryAddress);

            var newAvalue     = (byte)((Avalue & 0xF0) | ((HLcontents >> 4) & 0x0F));
            var newHLcontents = (byte)(((HLcontents << 4) & 0xF0) | (Avalue & 0x0F));

            Registers.A = newAvalue;
            ProcessorAgent.WriteToMemory(memoryAddress, newHLcontents);

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

            return(18);
        }