Esempio n. 1
0
        public void ExecuteRet()
        {
            var sp    = (ushort)Registers.SP;
            var newPC = NumberUtils.CreateShort(ReadFromMemoryInternal(sp), ReadFromMemoryInternal((ushort)(sp + 1)));

            Registers.PC  = (ushort)newPC;
            Registers.SP += 2;
        }
Esempio n. 2
0
        private int AcceptPendingInterrupt()
        {
            if (executionContext.IsEiOrDiInstruction)
            {
                return(0);
            }

            if (NmiInterruptPending)
            {
                IsHalted       = false;
                Registers.IFF1 = 0;
                this.ExecuteCall(NmiServiceRoutine);
                return(11);
            }

            if (!InterruptsEnabled)
            {
                return(0);
            }

            var activeIntSource = InterruptSources.FirstOrDefault(s => s.IntLineIsActive);

            if (activeIntSource == null)
            {
                return(0);
            }

            Registers.IFF1 = 0;
            Registers.IFF2 = 0;
            IsHalted       = false;

            switch (InterruptMode)
            {
            case 0:
                var opcode = activeIntSource.ValueOnDataBus.GetValueOrDefault(0xFF);
                InstructionExecutor.Execute(opcode);
                return(13);

            case 1:
                InstructionExecutor.Execute(RST38h_opcode);
                return(13);

            case 2:
                var pointerAddress = NumberUtils.CreateShort(
                    lowByte: activeIntSource.ValueOnDataBus.GetValueOrDefault(0xFF),
                    highByte: Registers.I);
                var callAddress = NumberUtils.CreateShort(
                    lowByte: Memory[pointerAddress],
                    highByte: Memory[pointerAddress.Inc()]);
                this.ExecuteCall(callAddress.ToUShort());
                return(19);
            }

            return(0);
        }
Esempio n. 3
0
 private short ReadShortFromMemory(ushort address)
 {
     return(NumberUtils.CreateShort(
                ProcessorAgent.ReadFromMemory(address),
                ProcessorAgent.ReadFromMemory((ushort)(address + 1))));
 }
Esempio n. 4
0
 private short FetchWord()
 {
     return(NumberUtils.CreateShort(
                lowByte: ProcessorAgent.FetchNextOpcode(),
                highByte: ProcessorAgent.FetchNextOpcode()));
 }