Пример #1
0
        protected ushort GetAddress()
        {
            var z = ExecutionEngine.Opcode.Definition.Z;
            var y = ExecutionEngine.Opcode.Definition.Y;
            var x = ExecutionEngine.Opcode.Definition.X;
            var p = ExecutionEngine.Opcode.Definition.P;

            if (x == 0 && z == 2)
            {
                switch (p)
                {
                case 0:
                    return(Registers.BC);

                case 1:
                    return(Registers.DE);
                }
            }

            if (x == 1 && y == 6)
            {
                return(GetHLOrIXIY());
            }

            throw Errors.AssignedToIllegalOpcode();
        }
Пример #2
0
 protected void ThrowIfNoParametersFound()
 {
     if (ExecutionEngine.MultiCycleOpcode == null)
     {
         throw Errors.AssignedToIllegalOpcode();
     }
     if (ExecutionEngine.MultiCycleOpcode.ParameterCount == 0)
     {
         throw Errors.ParametersNotFound();
     }
 }
Пример #3
0
        protected virtual bool IsConditionMet()
        {
            if (ExecutionEngine.Opcode.Definition.Z == 0)
            {
                return(Registers.FlagFromOpcodeY(ExecutionEngine.Opcode.Definition.Y));
            }
            else if (ExecutionEngine.Opcode.Definition.Z == 1)
            {
                // ret (no condition)
                return(true);
            }

            throw Errors.AssignedToIllegalOpcode();
        }
        protected override byte ExecuteOperation(byte value)
        {
            var bit = ExecutionEngine.Opcode.Definition.Y;

            switch (ExecutionEngine.Opcode.Definition.X)
            {
                case 2: //res
                    return Die.Alu.ResetBit(bit, value);
                case 3: //set
                    return Die.Alu.SetBit(bit, value);
                default:
                    throw Errors.AssignedToIllegalOpcode();
            }
        }
Пример #5
0
        protected override void OnLastCycleFirstM()
        {
            switch (ExecutionEngine.Opcode.Definition.Y)
            {
            case 6:
                SetCarryFlag();
                break;

            case 7:
                ComplementCarryFlag();
                break;

            default:
                throw Errors.AssignedToIllegalOpcode();
            }
        }
Пример #6
0
        protected override void OnLastCycleFirstM()
        {
            switch (ExecutionEngine.Opcode.Definition.Y)
            {
            case 4:     //daa
                DecimalAdjustAccumulator();
                break;

            case 5:     //cpl
                ComplementAccumulator();
                break;

            default:
                throw Errors.AssignedToIllegalOpcode();
            }
        }
Пример #7
0
        protected override void OnLastCycleFirstM()
        {
            switch (ExecutionEngine.Opcode.Definition.Y)
            {
            case 6:     // di
                ExecutionEngine.InterruptManager.DisableInterrupt();
                break;

            case 7:     // ei
                ExecutionEngine.InterruptManager.EnableInterrupt();
                ExecutionEngine.InterruptManager.SuspendInterrupts();
                break;

            default:
                throw Errors.AssignedToIllegalOpcode();
            }
        }
Пример #8
0
        protected override void OnClockNeg()
        {
            if (ExecutionEngine.Cycles.IsLastCycle &&
                ExecutionEngine.Cycles.MachineCycle == MachineCycleNames.M3)
            {
                if (IsConditionMet() && IsRepeat)
                {
                    if (ExecutionEngine.Opcode.Definition.AltCycles == null)
                    {
                        throw Errors.AssignedToIllegalOpcode();
                    }

                    ExecutionEngine.Cycles.SetAltCycles();
                }
            }

            base.OnClockNeg();
        }
Пример #9
0
        private ushort GetAddress()
        {
            ushort address;

            if (ExecutionEngine.Opcode.Definition.IsIX)
            {
                address = Registers.IX;
            }
            else if (ExecutionEngine.Opcode.Definition.IsIY)
            {
                address = Registers.IY;
            }
            else
            {
                throw Errors.AssignedToIllegalOpcode();
            }

            return(Alu.Add(address, (sbyte)InstructionM2.Data.Value));
        }
Пример #10
0
        protected ushort GetAddress()
        {
            var z = ExecutionEngine.Opcode.Definition.Z;
            var y = ExecutionEngine.Opcode.Definition.Y;
            var x = ExecutionEngine.Opcode.Definition.X;
            var q = ExecutionEngine.Opcode.Definition.Q;
            var p = ExecutionEngine.Opcode.Definition.P;

            // TODO: check z -for other instructions
            if (x == 0 && z == 2)
            {
                switch (p)
                {
                case 0:
                    return(Registers.BC);

                case 1:
                    return(Registers.DE);

                default:
                    throw Errors.AssignedToIllegalOpcode();
                }
            }

            var isCB = ExecutionEngine.Opcode.Definition.Ext1 == 0xCB ||
                       ExecutionEngine.Opcode.Definition.Ext2 == 0xCB;

            // See OpcodeDefinition.Definitions
            if (((y == 6 && (z == 4 || z == 5 || z == 6) || x == 1)) ||
                ((x == 1 || x == 2) && z == 6) ||
                (isCB && (x == 0 && z == 6))
                )
            {
                return(GetHLOrIXIY());
            }

            throw Errors.AssignedToIllegalOpcode();
        }
Пример #11
0
        protected virtual bool IsConditionMet()
        {
            switch (ExecutionEngine.Opcode.Definition.Y)
            {
            case 3:     // jr d
                return(true);

            case 4:     // jr nz, d
                return(!Registers.Flags.Z);

            case 5:     // jr z, d
                return(Registers.Flags.Z);

            case 6:     // jr nc, d
                return(!Registers.Flags.C);

            case 7:     // jr c, d
                return(Registers.Flags.C);

            default:
                throw Errors.AssignedToIllegalOpcode();
            }
        }
Пример #12
0
        protected override void OnLastCycleFirstM()
        {
            switch (ExecutionEngine.Opcode.Definition.Y)
            {
            case 0:     //ld I, A
                LoadIntAcc();
                break;

            case 1:     //ld R, A
                LoadRefAcc();
                break;

            case 2:     //ld A, I
                LoadAccInt();
                break;

            case 3:     //ld A, R
                LoadAccRef();
                break;

            default:
                throw Errors.AssignedToIllegalOpcode();
            }
        }