public Laptop(IMotherboard motherboard, Cpu cpu, HardDriveComponent hardDrive, LaptopBattery laptopBattery)
 {
     this.Motherboard = motherboard;
     this.Cpu = cpu;
     this.HardDrive = hardDrive;
     this.LaptopBattery = laptopBattery;
 }
 internal AbstractComputer(Cpu cpu, Ram ram, IEnumerable<HardDrive> hardDrives, VideoCard videoCard)
 {
     this.Cpu = cpu;
     this.Ram = ram;
     this.HardDrives = hardDrives;
     this.VideoCard = videoCard;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Form1" /> class.
        /// </summary>
        /// <param name="args">The args.</param>
        public Form1(string[] args)
        {
            InitializeComponent();

            cpu = new Cpu();
            cpu.CommandCounter = Cpu.FromShort(100);
            cpu.StepCounter = 0;

            activeMode = fastToolStripMenuItem;
            StepMode = (StepModeEnum)Enum.Parse(typeof(StepModeEnum), activeMode.Text);

            #if DEBUG
            args = new string[1];
            args[0] = @"C:\Dev\ASP.Net\Mini-Power-PC\Examples\Multiplikation.lvhe";
            #endif

            // Falls ein File als Parameter mit angegeben wurde, den Emulator damit starten
            if (args.Length > 0)
            {
                FileTracker.ActiveFile = new FileInfo(args[0]);
                initGui();
            }
            toolStripStatusLabel2.Text = string.Empty;

            updateGui();
        }
Beispiel #4
0
 public void Rebuild(Cpu _CPU)
 {
     blocks.Clear();
     AddBlock(0, 0, _CPU);
     Stack<Block> todo = new Stack<Block>();
     todo.Push(_CPU);
     Block b;
     while (todo.Count > 0)
     {
         b = todo.Pop();
         if (b == null) break;
         foreach (Edge e in b.Edges)
         {
             for (int bidx = 0; bidx < 2; bidx++)
             {
                 if (!blocks.ContainsValue(e.Blocks[1]))
                 {
                     Vector3 pos = _CPU.transform.InverseTransformPoint(e.Blocks[bidx].transform.position);
                     AddBlock((int)(pos.x + 0.5f), (int)(pos.y + 0.5f), e.Blocks[bidx]);
                     todo.Push(e.Blocks[bidx]);
                 }
             }
         }
     }
 }
Beispiel #5
0
 internal Server(
     Cpu cpu,
     Ram ram,
     IEnumerable<HardDriver> hardDrives,
     VideoCard videoCard)
     : base(cpu, ram, hardDrives, videoCard)
 {
 }
Beispiel #6
0
        public PersonalComputer(
			Cpu cpu,
			Rammstein ram,
			IEnumerable<HardDrive> hardDrives,
			ColourVideoCard videoCard)
            : base(cpu, ram, hardDrives, videoCard)
        {
        }
Beispiel #7
0
        public Server(
			Cpu cpu,
			Rammstein ram,
			IEnumerable<HardDrive> hardDrives,
			MonochromeVideoCard videoCard)
            : base(cpu, ram, hardDrives, videoCard)
        {
        }
 internal Computer(Cpu cpu, IRam ram, IEnumerable<HardDrive> hardDrives, VideoCard videoCard)
 {
     this.Cpu = cpu;
     this.Ram = ram;
     this.HardDrives = hardDrives;
     this.VideoCard = videoCard;
     this.motherboard = new Motherboard(this.Cpu, this.Ram, this.VideoCard);
 }
Beispiel #9
0
        public void Setup()
        {
            _memory = Substitute.For<IMemory>();
            _input = Substitute.For<IInput>();
            _output = Substitute.For<IOutput>();

            _cpu = new Cpu(_memory, _input, _output);
        }
 public PersonalComputer(
     Cpu cpu,
     Ram ram,
     IEnumerable<HardDriver> hardDrives,
     VideoCard videoCard)
     : base(cpu, ram, hardDrives, videoCard)
 {
 }
Beispiel #11
0
 public Server(Cpu cpu, Ram ram, IStorageDevice hardDrives, VideoCard videoCard)
     : base(cpu, ram, hardDrives, videoCard)
 {
     if (videoCard.IsMonochrome == false)
     {
         throw new ArgumentException("Cannot initialise server with colourful video card");
     }
 }
    public static void Mount(string path, SPI.SPI_module spi, Cpu.Pin chipSelect, Cpu.Pin cardDetect)
    {
        if (_sdCardPath != null)
            throw new NotSupportedException();

        MountNative(path, (uint) spi, (uint) chipSelect, (uint) cardDetect);
        _sdCardPath = path;
    }
Beispiel #13
0
 public Computer(Cpu cpu, Ram ram, VideoCard videoCard, HardDriver hdd, IEnumerable<HardDriver> hardDrives)
 {
     this.Cpu = cpu;
     this.Ram = ram;
     this.VideoCard = videoCard;
     this.HardDrive = hdd;
     this.HardDrives = hardDrives;
 }
Beispiel #14
0
        public Computer(Cpu cpu, Ram ram, IStorageDevice storage, VideoCard videoCard)
        {
            this.CPU = cpu;
            this.Ram = ram;
            this.StorageDevice = storage;
            this.VideoCard = videoCard;

            this.motherboard = new Motherboard(this.CPU, this.Ram, VideoCard);
        }
Beispiel #15
0
    public PiezoSpeaker(Cpu.Pin pin)
    {
        _pin = new PWM(pin);

        // take the pin low, so the speaker
        // doesn't make any noise until we
        // ask it to
        _pin.SetDutyCycle(0);
    }
Beispiel #16
0
 internal Server(
     Cpu cpu,
     Ram ram,
     IEnumerable<HardDrive> hardDrives,
     VideoCard videoCard)
     : base(cpu, ram, hardDrives, videoCard)
 {
     this.VideoCard.IsMonochrome = true;
 }
Beispiel #17
0
 internal Laptop(
     Cpu cpu,
     Ram ram,
     IEnumerable<HardDrive> hardDrives,
     VideoCard videoCard,
     ILaptopBattery battery)
     : base(cpu, ram, hardDrives, videoCard)
 {
     this.battery = battery;
 }
Beispiel #18
0
        public PC CreatePC()
        {
            var ram = new Ram(8);
            var videoCard = new VideoCard(false);
            var cpu = new Cpu(4, 64, ram, videoCard);
            var storage = new HardDrive(1000);
            var pc = new PC(cpu, ram, storage, videoCard);

            return pc;
        }
Beispiel #19
0
        public override Computer MakePC()
        {
            var ramMemory = new RAMMemory(2);
            var videoCard = new ColorVideoCard();
            var cpu = new Cpu(2, 32);
            var hdd = new[] { new HardDriver(500, false, 0) };
            var pc = new Computer("PC", cpu, ramMemory, hdd, videoCard, null);

            return pc;
        }
Beispiel #20
0
        public PC CreatePC()
        {
            var ram = new Ram(4);
            var videoCard = new VideoCard(true);
            var cpu = new Cpu(2, 64, ram, videoCard);
            var storage = new HardDrive(2000);
            var pc = new PC(cpu, ram, storage, videoCard);

            return pc;
        }
Beispiel #21
0
        public Server CreateServer()
        {
            var ram = new Ram(64);
            var videoCard = new VideoCard(true);
            var cpu = new Cpu(8, 64, ram, videoCard);
            var storage = new RaidArray(2, 2000);
            var server = new Server(cpu, ram, storage, videoCard);

            return server;
        }
Beispiel #22
0
        private IComputer ManufacturePC()
        {
            Ram ram = new Ram(4);
            HardDrive hardDrive = new HardDrive(2000, false, 0);
            IEnumerable<HardDrive> hardDrives = new List<HardDrive>() { hardDrive };
            IVideoCard videoCard = new MonochromeVideoCard();
            ICpu cpu = new Cpu(2, CpuType.Bits64, new Motherboard(ram, videoCard));
            IComputer pc = new PersonalComputer(cpu, ram, hardDrives, videoCard);

            return pc;
        }
Beispiel #23
0
        protected Computer(
				  Cpu cpu,
				  Rammstein ram,
				  IEnumerable<HardDrive> hardDrives,
				  IVideoCard videoCard)
        {
            Cpu = cpu;
            this.Ram = ram;
            this.HardDrives = hardDrives;
            this.VideoCard = videoCard;
        }
Beispiel #24
0
        public override Computer MakeLaptop()
        {
            var videoCard = new ColorVideoCard();
            var ramMemory = new RAMMemory(4);
            var cpu = new Cpu(2, 64);
            var hdd = new[] { new HardDriver(500, false, 0) };
            var battery = new LaptopBattery();
            var laptop = new Computer("LAPTOP", cpu, ramMemory, hdd, videoCard, new LaptopBattery());

            return laptop;
        }
Beispiel #25
0
        public override PersonalComputer CreatePC()
        {
            var ram = new Ram((int)RamType.GB2);
            var videoCard = new VideoCard(false);
            var motherBoard = new Motherboard(ram, videoCard);
            var cpu = new Cpu(2, (int)ArchitectureType.Bits32, motherBoard);
            var hardDrive = new HardDrive(500);
            var pc = new PersonalComputer(motherBoard, cpu, hardDrive);

            return pc;
        }
Beispiel #26
0
        public Laptop CreateLaptop()
        {
            var ram = new Ram(4);
            var videoCard = new VideoCard(false);
            var cpu = new Cpu(4, 32, ram, videoCard);
            var storage = new HardDrive(1000);
            var battery = new LaptopBattery();
            var laptop = new Laptop(cpu, ram, storage, videoCard, battery);

            return laptop;
        }
Beispiel #27
0
        private IComputer ManufactureLaptop()
        {
            Ram ram = new Ram(16);
            HardDrive hardDrive = new HardDrive(1000, false, 0);
            IEnumerable<HardDrive> hardDrives = new List<HardDrive>() { hardDrive };
            IVideoCard videoCard = new ColorfulVideoCard();
            LaptopBatery battery = new LaptopBatery();
            ICpu cpu = new Cpu(2, CpuType.Bits64, new Motherboard(ram, videoCard));
            IComputer laptop = new Laptop(cpu, ram, hardDrives, videoCard, battery);

            return laptop;
        }
Beispiel #28
0
 static void Main(string[] args)
 {
     if(args.Length != 1)
     {
         Console.WriteLine("Usage: pemu binaryFile");
         return;
     }
     var elf = ELFSharp.ELFReader.Load<uint>(args[0]);
     var program = ProgramLoader.ReadProgram(elf);
     var cpu = new Cpu() { Program = program };
     cpu.Run();
 }
        public override IPlayable CreatePc()
        {
            IRam ram = new Ram(InitialPcRam);
            VideoCardBase videoCard = new MonochromeVideoCard();
            ICpu cpu = new Cpu(InitialPcCores, InitialPcCpuBits, ram, videoCard, new Cpu64BitsSquareNumberFinder());
            IEnumerable<HardDrive> hardDrives = new[] 
                    {
                        new HardDrive(InitialPcHardDriveSpace, InitialPcHardDriveInRaid, 0) 
                    };

            return new Pc(cpu, ram, hardDrives, videoCard);
        }
Beispiel #30
0
        private IComputer ManufactureServer()
        {
            Ram ram = new Ram(8);
            HardDrive firstHardDrive = new HardDrive(500, true, 2);
            HardDrive secondHardDrive = new HardDrive(500, true, 2);
            IEnumerable<HardDrive> hardDrives = new List<HardDrive>() { firstHardDrive, secondHardDrive };
            IVideoCard videoCard = new MonochromeVideoCard();
            ICpu cpu = new Cpu(8, CpuType.Bits128, new Motherboard(ram, videoCard));
            IComputer server = new Server(cpu, ram, hardDrives, videoCard);

            return server;
        }
Beispiel #31
0
 public void Add(long value)
 {
     Add(value, Cpu.GetCurrentCoreId());
 }
Beispiel #32
0
 public Cpu VulCPU(Cpu cpu)
 {
     cpu.Wapen  = itemrepo.GetCPUItemsById(cpu.ID)[0];
     cpu.Potion = itemrepo.GetCPUItemsById(cpu.ID)[1];
     return(cpu);
 }
 public bool Return(T obj)
 {
     return(Return(obj, Cpu.GetCurrentCoreId()));
 }
Beispiel #34
0
        /*
         * 20.02
         *
         */


        // Value    Boot    Cert.   Privileged      Immutable
        // 0        3F      3E      2C-2F, 3C-3F    2C-2F, 3F
        // 1        7F      7E      6C-6F, 7C-7F    6C-6F, 7F
        // 2        FF      FE      EC-EF, FC-FF    EC-EF, FF

        public override byte BusRead(object sender, ushort address)
        {
            int  linearAddress = 0;
            bool isRam         = false;

            // Compute linear address in RAM or flash
            switch (address & 0xC000)
            {
            case 0x0000:
                /*
                 * if (BootMode)
                 *  return Flash.ReadByte(sender, address | 0xFFC000);
                 * else
                 *  return Flash.ReadByte(sender, address);*/
                isRam = false;
                if (BootMode)
                {
                    linearAddress = address | Flash.BootSector;
                }
                else
                {
                    linearAddress = address;
                }
                break;

            case 0x4000:
                BootMode      = false;
                linearAddress = (address & 0x3FFF) | bank4000;
                isRam         = Bank4000IsRam;
                break;

            case 0x8000:
                if (address < lowerPageAlwaysPresentLimit && memoryMapMode == 0)
                {
                    isRam         = true;
                    linearAddress = (address & 0x3FFF) | 0x4000;
                    break;
                }
                if (memoryMapMode == 1)
                {
                    BootMode = false;
                }
                linearAddress = (address & 0x3FFF) | bank8000;
                isRam         = Bank8000IsRam;
                break;

            case 0xC000:
                if (address >= upperPageAlawayPresentLimit && memoryMapMode == 0)
                {
                    isRam         = true;
                    linearAddress = (address & 0x3FFF);
                    break;
                }
                linearAddress = (address & 0x3FFF) | bankC000;
                isRam         = BankC000IsRam;
                break;
            }
            Breakpoint bp = new Breakpoint()
            {
                Address = (ushort)(linearAddress & 0x3FFF),
                IsRam   = isRam,
                Page    = linearAddress >> 14,
                Type    = Cpu.M1 ? MemoryBreakpointType.Execution : MemoryBreakpointType.Read
            };

            if (Cpu.M1 && IsExecutionBreakpoint(bp))
            {
                Cpu.BreakExecution();
            }
            else if (haveReadBps && IsReadBreakpoint(bp))
            {
                Cpu.BreakExecution();
            }
            if (isRam)
            {
                // Check execution permissions: address must be within allowed limits, masked by RAM chip size
                if (Cpu.M1 && sender is Z80Cpu)
                {
                    if ((linearAddress & ramTypeMask) < ramLowerLimit || (linearAddress & ramTypeMask) >= ramUpperLimit)
                    {
                        Master.Reset();
                    }
                }
                return(Ram.ReadByte(sender, linearAddress & 0x3FFFF));
            }
            else
            {
                // Check execution permissions: address must be within allowed limits

                if (Cpu.M1 && sender is Z80Cpu)
                {
                    if ((linearAddress & flashTypeMask) >= flashLowerLimit && (linearAddress & flashTypeMask) < flashUpperLimit)
                    {
                        // . . . unless it's on a privileged page, in which case, execution is always allowed
                        if (!((((linearAddress >> 14) & 0xF) >= 0xC) && (((linearAddress >> 18) & 0x2) >= 2) && ((linearAddress >> 20) == (1 << flashType) - 1)))
                        {
                            Master.Reset();
                        }
                    }
                }
                // Check for censorship
                int highBits = ((1 << flashType) - 1) << 20;
                if ((linearAddress & 0xF00000) == highBits && !FlashWriteEnable)
                {
                    highBits = linearAddress & 0xFFFFF;
                    if (highBits >= 0xF8000 && highBits < 0xFC000)
                    {
                        return(0xFF);
                    }
                }
                return(Flash.ReadByte(sender, linearAddress));
            }
        }
 /// <summary>
 /// Creates a new architecture structure with pre-set values.
 /// </summary>
 /// <param name="os">Determines which operating systems are supported.</param>
 /// <param name="cpu">Determines which CPU-architectures are supported.</param>
 public Architecture(OS os, Cpu cpu) : this()
 {
     OS  = os;
     Cpu = cpu;
 }
Beispiel #36
0
        private static void Main(string[] args)
        {
            var loglevel = LogLevel.Debug;

            if (args.Length > 0 && args[0] == "trace")
            {
                loglevel = LogLevel.Trace;
            }
            var logConfig        = new LoggingConfiguration();
            var logTargetConsole = new ConsoleTarget {
                Name   = "console",
                Header = "AutoTx Diagnostics",
                Layout = @"${time} [${level}] ${message}",
            };

            logConfig.AddTarget(logTargetConsole);
            var logRuleConsole = new LoggingRule("*", loglevel, logTargetConsole);

            logConfig.LoggingRules.Add(logRuleConsole);
            LogManager.Configuration = logConfig;

            // set the default performance monitors:
            var perfMonitors = new[] { "CPU", "PhysicalDisk" };

            // if requested explicitly as a command line parameter, override them:
            if (args.Length > 1)
            {
                perfMonitors = args[1].Split(',');
            }

            var commonAssembly    = Assembly.GetAssembly(typeof(Cpu));
            var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location);

            Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion);

            Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:")));

            if (perfMonitors.Contains("CPU"))
            {
                Log.Info("Watching CPU load using ATxCommon.Monitoring...");
                var cpu = new Cpu {
                    Interval  = 250,
                    Limit     = 50,
                    Probation = 4, // 4 * 250 ms = 1 second
                    LogPerformanceReadings = LogLevel.Info,
                    Enabled = true
                };
            }

            if (perfMonitors.Contains("PhysicalDisk"))
            {
                Log.Info("Watching I/O load using ATxCommon.Monitoring...");
                var disk = new PhysicalDisk {
                    Interval  = 250,
                    Limit     = 0.25F,
                    Probation = 4, // 4 * 250 ms = 1 second
                    LogPerformanceReadings = LogLevel.Info,
                    Enabled = true
                };
            }

            while (true)
            {
                System.Threading.Thread.Sleep(10000);
            }
        }
Beispiel #37
0
        public bool FrameAdvance(IController controller, bool render, bool renderSound)
        {
            _controller = controller;
            _lagged     = true;
            _frame++;

            if (!IsGameGear)
            {
                PSG.Set_Panning(Settings.ForceStereoSeparation ? ForceStereoByte : (byte)0xFF);
            }

            if (Tracer.Enabled)
            {
                Cpu.TraceCallback = s => Tracer.Put(s);
            }
            else
            {
                Cpu.TraceCallback = null;
            }

            if (IsGameGear_C == false)
            {
                Cpu.NonMaskableInterrupt = controller.IsPressed("Pause");
            }
            else if (!IsGameGear && IsGameGear_C)
            {
                Cpu.NonMaskableInterrupt = controller.IsPressed("P1 Start");
            }

            if (IsGame3D && Settings.Fix3D)
            {
                render = ((Frame & 1) == 0) & render;
            }

            int scanlinesPerFrame = Vdp.DisplayType == DisplayType.NTSC ? 262 : 313;

            Vdp.SpriteLimit = Settings.SpriteLimit;
            for (int i = 0; i < scanlinesPerFrame; i++)
            {
                Vdp.ScanLine = i;

                Vdp.RenderCurrentScanline(render);

                Vdp.ProcessFrameInterrupt();
                Vdp.ProcessLineInterrupt();
                ProcessLineControls();

                for (int j = 0; j < Vdp.IPeriod; j++)
                {
                    Cpu.ExecuteOne();

                    PSG.generate_sound();

                    s_L = PSG.current_sample_L;
                    s_R = PSG.current_sample_R;

                    if (s_L != OldSl)
                    {
                        BlipL.AddDelta(SampleClock, s_L - OldSl);
                        OldSl = s_L;
                    }

                    if (s_R != OldSr)
                    {
                        BlipR.AddDelta(SampleClock, s_R - OldSr);
                        OldSr = s_R;
                    }

                    SampleClock++;
                }

                if (Vdp.ScanLine == scanlinesPerFrame - 1)
                {
                    Vdp.ProcessGGScreen();
                    Vdp.ProcessOverscan();
                }
            }

            if (_lagged)
            {
                _lagCount++;
                _isLag = true;
            }
            else
            {
                _isLag = false;
            }

            return(true);
        }
Beispiel #38
0
        private void SyncState(Serializer ser)
        {
            byte[] core = null;
            if (ser.IsWriter)
            {
                var ms = new MemoryStream();
                ms.Close();
                core = ms.ToArray();
            }
            Cpu.SyncState(ser);

            ser.BeginSection(nameof(SMS));
            Vdp.SyncState(ser);
            PSG.SyncState(ser);
            ser.Sync("RAM", ref SystemRam, false);
            ser.Sync(nameof(RomBank0), ref RomBank0);
            ser.Sync(nameof(RomBank1), ref RomBank1);
            ser.Sync(nameof(RomBank2), ref RomBank2);
            ser.Sync(nameof(RomBank3), ref RomBank3);
            ser.Sync(nameof(Bios_bank), ref Bios_bank);
            ser.Sync(nameof(Port01), ref Port01);
            ser.Sync(nameof(Port02), ref Port02);
            ser.Sync(nameof(Port05), ref Port05);
            ser.Sync(nameof(Port3E), ref Port3E);
            ser.Sync(nameof(Port3F), ref Port3F);
            ser.Sync(nameof(Controller1SelectHigh), ref Controller1SelectHigh);
            ser.Sync(nameof(Controller2SelectHigh), ref Controller2SelectHigh);
            ser.Sync(nameof(LatchLightPhaser), ref LatchLightPhaser);
            ser.Sync(nameof(start_pressed), ref start_pressed);
            ser.Sync(nameof(cntr_rd_0), ref cntr_rd_0);
            ser.Sync(nameof(cntr_rd_1), ref cntr_rd_1);
            ser.Sync(nameof(cntr_rd_2), ref cntr_rd_2);
            ser.Sync(nameof(stand_alone), ref stand_alone);
            ser.Sync(nameof(disablePSG), ref disablePSG);
            ser.Sync(nameof(sampleclock), ref sampleclock);
            ser.Sync(nameof(old_s_L), ref old_s_L);
            ser.Sync(nameof(old_s_R), ref old_s_R);

            if (SaveRAM != null)
            {
                ser.Sync(nameof(SaveRAM), ref SaveRAM, false);
            }

            ser.Sync(nameof(SaveRamBank), ref SaveRamBank);

            if (ExtRam != null)
            {
                ser.Sync("ExtRAM", ref ExtRam, true);
            }

            if (HasYM2413)
            {
                YM2413.SyncState(ser);
            }

            if (EEPROM != null)
            {
                EEPROM.SyncState(ser);
            }

            ser.Sync("Frame", ref _frame);
            ser.Sync("LagCount", ref _lagCount);
            ser.Sync("IsLag", ref _isLag);

            ser.EndSection();

            if (ser.IsReader)
            {
                SyncAllByteArrayDomains();
            }
        }
Beispiel #39
0
        /// <summary>
        /// Checks whether the execution cycle should be stopped for debugging
        /// </summary>
        /// <param name="options">Execution options</param>
        /// <param name="executedInstructionCount">
        /// The count of instructions already executed in this cycle
        /// </param>
        /// <param name="entryStepOutStackDepth">The initial depth of the Step-Out stack</param>
        /// <returns>True, if the execution should be stopped</returns>
        private bool IsDebugStop(ExecuteCycleOptions options, int executedInstructionCount, int entryStepOutStackDepth)
        {
            // --- No debug provider, no stop
            if (DebugInfoProvider == null)
            {
                return(false);
            }

            switch (options.DebugStepMode)
            {
            // --- In Step-Into mode we always stop when we're about to
            // --- execute the next instruction
            case DebugStepMode.StepInto:
                return(executedInstructionCount > 0);

            // --- In Stop-At-Breakpoint mode we stop only if a predefined
            // --- breakpoint is reached
            case DebugStepMode.StopAtBreakpoint
                when DebugInfoProvider.ShouldBreakAtAddress(Cpu.Registers.PC) && (executedInstructionCount > 0 ||
                                                                                  _lastBreakpoint == null ||
                                                                                  _lastBreakpoint != Cpu.Registers.PC):
                // --- If we are paused at a breakpoint, we do not want
                // --- to pause again and again, unless we step through
                _lastBreakpoint = Cpu.Registers.PC;

                return(true);

            // --- We're in Step-Over mode
            case DebugStepMode.StepOver
                when DebugInfoProvider.ImminentBreakpoint != null:
            {
                // --- We also stop, if an imminent breakpoint is reached, and also remove
                // --- this breakpoint
                if (DebugInfoProvider.ImminentBreakpoint == Cpu.Registers.PC)
                {
                    DebugInfoProvider.ImminentBreakpoint = null;
                    return(true);
                }
                break;
            }

            case DebugStepMode.StepOver:
            {
                var imminentJustCreated = false;

                // --- We check for a CALL-like instruction
                var length = Cpu.GetCallInstructionLength();
                if (length > 0)
                {
                    // --- Its a CALL-like instruction, create an imminent breakpoint
                    DebugInfoProvider.ImminentBreakpoint = (ushort)(Cpu.Registers.PC + length);
                    imminentJustCreated = true;
                }

                // --- We stop, we executed at least one instruction and if there's no imminent
                // --- breakpoint or we've just created one
                if (executedInstructionCount > 0 &&
                    (DebugInfoProvider.ImminentBreakpoint == null || imminentJustCreated))
                {
                    return(true);
                }
                break;
            }

            // --- We're in Step-Out mode and want to complete the current subroutine call
            case DebugStepMode.StepOut
                when Cpu.StackDebugSupport.RetExecuted &&
                executedInstructionCount > 0 &&
                entryStepOutStackDepth == Cpu.StackDebugSupport.StepOutStackDepth + 1:
            {
                if (Cpu.Registers.PC != Cpu.StackDebugSupport.StepOutAddress)
                {
                    Cpu.StackDebugSupport.ClearStepOutStack();
                }
                return(true);
            }
            }

            // --- In any other case, we carry on
            return(false);
        }
Beispiel #40
0
 public void cpu_OnPH(Cpu cpu)
 {
     _stackBytes[StackPtr + 1].SignalPH(cpu.Cycles);
     OnPH?.Invoke(null);
 }
        private void WriteMemorySF2(int addr, byte value)
        {
            if ((addr & 0x1FFC) == 0x1FF0)
            {
                // Set SF2 pager.
                SF2MapperLatch = (byte)(addr & 0x03);

                if (SF2UpdateCDLMappings)
                {
                    CDLMappingApplyRange(Cpu.Mappings, "ROM", 0x40, 0x80000, (SF2MapperLatch + 1) * 0x80000);
                }

                return;
            }

            if (addr >= 0x1F0000 && addr < 0x1F8000)             // write RAM.
            {
                Ram[addr & 0x1FFF] = value;
            }

            else if (addr >= 0x1FE000)             // hardware page.
            {
                if (addr < 0x1FE400)
                {
                    VDC1.WriteVDC(addr, value);
                }
                else if (addr < 0x1FE800)
                {
                    Cpu.PendingCycles--; VCE.WriteVCE(addr, value);
                }
                else if (addr < 0x1FEC00)
                {
                    IOBuffer = value; PSG.WritePSG((byte)addr, value, Cpu.TotalExecutedCycles);
                }
                else if (addr == 0x1FEC00)
                {
                    IOBuffer = value; Cpu.WriteTimer(value);
                }
                else if (addr == 0x1FEC01)
                {
                    IOBuffer = value; Cpu.WriteTimerEnable(value);
                }
                else if (addr >= 0x1FF000 &&
                         addr < 0x1FF400)
                {
                    IOBuffer = value; WriteInput(value);
                }
                else if (addr == 0x1FF402)
                {
                    IOBuffer = value; Cpu.WriteIrqControl(value);
                }
                else if (addr == 0x1FF403)
                {
                    IOBuffer = value; Cpu.WriteIrqStatus();
                }
                else
                {
                    Log.Error("MEM", "unhandled hardware write [{0:X6}] : {1:X2}", addr, value);
                }
            }
            else
            {
                Log.Error("MEM", "UNHANDLED WRITE: {0:X6}:{1:X2}", addr, value);
            }
        }
Beispiel #42
0
 public void InterlockedAdd(long value)
 {
     InterlockedAdd(value, Cpu.GetCurrentCoreId());
 }
Beispiel #43
0
 public void Increment()
 {
     Increment(Cpu.GetCurrentCoreId());
 }
Beispiel #44
0
        public override void BusWrite(object sender, ushort address, byte value)
        {
            int  linearAddress = 0;
            bool isRam         = false;

            switch (address & 0xC000)
            {
            case 0x0000:
                if (BootMode)
                {
                    return;
                }
                linearAddress = address & 0x3FFF;
                isRam         = false;
                break;

            case 0x4000:
                linearAddress = (address & 0x3FFF) | bank4000;
                isRam         = Bank4000IsRam;
                break;

            case 0x8000:
                if (address < lowerPageAlwaysPresentLimit && memoryMapMode == 0)
                {
                    isRam         = true;
                    linearAddress = (address & 0x3FFF) | 0x4000;
                    break;
                }
                linearAddress = (address & 0x3FFF) | bank8000;
                isRam         = Bank8000IsRam;
                break;

            case 0xC000:
                if (address >= upperPageAlawayPresentLimit && memoryMapMode == 0)
                {
                    isRam         = true;
                    linearAddress = (address & 0x3FFF);
                    break;
                }
                linearAddress = (address & 0x3FFF) | bankC000;
                isRam         = BankC000IsRam;
                break;
            }
            Breakpoint bp = new Breakpoint()
            {
                Address = (ushort)(linearAddress & 0x3FFF),
                IsRam   = isRam,
                Page    = linearAddress >> 14,
                Type    = MemoryBreakpointType.Write
            };

            if (haveWriteBps && IsWriteBreakpoint(bp))
            {
                Cpu.BreakExecution();
            }
            if (isRam)
            {
                Ram.WriteByte(sender, linearAddress & 0x3FFFF, value);
            }
            else
            {
                if (!FlashWriteEnable)
                {
                    return;
                }
                int highBits = ((1 << flashType) - 1) << 20;
                if ((linearAddress & 0xF00000) == highBits)
                {
                    highBits = linearAddress & 0xFFFFF;
                    if (highBits >= 0xB0000 && highBits < 0xC000 || highBits >= 0xFC000)
                    {
                        return;
                    }
                }
                Flash.WriteByte(sender, linearAddress, value);
            }
        }
Beispiel #45
0
 public BLDX(Cpu cpu, AddressingModes addressingMode) : base(cpu, addressingMode)
 {
 }
Beispiel #46
0
        public void Process(int data)
        {
            this.Ram.SaveValue(data);

            Cpu.SquareNumber();
        }
Beispiel #47
0
        public void Step()
        {
            //if (State.Memory[0xFF50].GetBit(0)) // Bootrom disabled
            //{
            //    //var nextInstr = Disassembler.DisassembleInstruction(InstructionLookahead.Passive(State));
            //    //_log[State.Registers.PC.Value] = nextInstr;
            //    //if (!_logHits.ContainsKey(State.Registers.PC.Value)) _logHits[State.Registers.PC.Value] = 0;
            //    //_logHits[State.Registers.PC.Value]++;

            //    _trace.WriteLine(DebugUtils.Trace(State));

            //    if (State.Registers.PC.Value == 0x00F0)
            //    {
            //        _trace.Flush();
            //        Environment.Exit(0);
            //    }
            //}

            if (State.Stopped)
            {
                // STOP mode is exited when a button is pressed.
                // IF bit 4 is set when a button is pressed, so we can use that.
                if (State.Memory[0xFF0F].GetBit(4))
                {
                    State.Stopped = false;
                }
                else
                {
                    return;
                }
            }

            if (State.Halted)
            {
                _lcdController.Tick();
                _timerController.Tick();
                ElapsedCycles += 1;
            }
            else
            {
                var cycles = Cpu.ExecuteNextInstruction(State);
                ElapsedCycles += cycles;

                for (var i = 0; i < cycles; i++)
                {
                    _lcdController.Tick();
                    _timerController.Tick();
                }
            }

            // Handle interrupts
            var firedInterrupts = (byte)(State.Memory[0xFF0F] & State.Memory[0xFFFF]);

            if (State.InterruptMasterEnable && firedInterrupts != 0)
            {
                // Save PC
                // TODO: push 16 bit values onto the stack in one call
                var pc = State.Registers.PC.Value;
                State.Stack.Push(pc.GetHigh());
                State.Stack.Push(pc.GetLow());

                State.InterruptMasterEnable = false;

                //_logger.WriteLine($"Servicing interrupt ... {State.Memory[0xFF0F].ToBinaryString()} {State.Memory[0xFFFF].ToBinaryString()} {firedInterrupts.ToBinaryString()} {ElapsedCycles - _c}");
                _c = ElapsedCycles;

                if (firedInterrupts.GetBit(0)) // VBlank
                {
                    State.Registers.PC.Value = 0x0040;
                    State.Memory[0xFF0F]     = State.Memory[0xFF0F].SetBit(0, false);
                }
                else if (firedInterrupts.GetBit(1)) // LCD status
                {
                    State.Registers.PC.Value = 0x0048;
                    State.Memory[0xFF0F]     = State.Memory[0xFF0F].SetBit(1, false);
                }
                else if (firedInterrupts.GetBit(2)) // Timer
                {
                    State.Registers.PC.Value = 0x0050;
                    State.Memory[0xFF0F]     = State.Memory[0xFF0F].SetBit(2, false);
                }
                else if (firedInterrupts.GetBit(3)) // Serial link
                {
                    State.Registers.PC.Value = 0x0058;
                    State.Memory[0xFF0F]     = State.Memory[0xFF0F].SetBit(3, false);
                }
                else if (firedInterrupts.GetBit(4)) // Keypad press
                {
                    State.Registers.PC.Value = 0x0060;
                    State.Memory[0xFF0F]     = State.Memory[0xFF0F].SetBit(4, false);
                }
            }

            // HALT mode is always exited regardless of the state of the IME
            if (firedInterrupts != 0)
            {
                State.Halted = false;
            }
        }
            public static void QueryDevices(IMessageNotifier messageNotifier)
            {
                MessageNotifier = messageNotifier;
                // #0 get video controllers, used for cross checking
                WindowsDisplayAdapters.QueryVideoControllers();
                // Order important CPU Query must be first
                // #1 CPU
                Cpu.QueryCpus();
                // #2 CUDA
                if (Nvidia.IsSkipNvidia())
                {
                    Helpers.ConsolePrint(Tag, "Skipping NVIDIA device detection, settings are set to disabled");
                }
                else
                {
                    ShowMessageAndStep(International.GetText("Compute_Device_Query_Manager_CUDA_Query"));
                    Nvidia.QueryCudaDevices();
                }
                // OpenCL and AMD
                if (ConfigManager.GeneralConfig.DeviceDetection.DisableDetectionAMD)
                {
                    Helpers.ConsolePrint(Tag, "Skipping AMD device detection, settings set to disabled");
                    ShowMessageAndStep(International.GetText("Compute_Device_Query_Manager_AMD_Query_Skip"));
                }
                else
                {
                    // #3 OpenCL
                    ShowMessageAndStep(International.GetText("Compute_Device_Query_Manager_OpenCL_Query"));
                    OpenCL.QueryOpenCLDevices();
                    // #4 AMD query AMD from OpenCL devices, get serial and add devices
                    ShowMessageAndStep(International.GetText("Compute_Device_Query_Manager_AMD_Query"));
                    var amd = new AmdQuery(AvaliableVideoControllers);
                    AmdDevices = amd.QueryAmd(_isOpenCLQuerySuccess, _openCLJsonData);
                }
                // #5 uncheck CPU if GPUs present, call it after we Query all devices
                Group.UncheckedCpu();

                // TODO update this to report undetected hardware
                // #6 check NVIDIA, AMD devices count
                var nvidiaCount = 0;

                {
                    var amdCount = 0;
                    foreach (var vidCtrl in AvaliableVideoControllers)
                    {
                        if (vidCtrl.Name.ToLower().Contains("nvidia") && CudaUnsupported.IsSupported(vidCtrl.Name))
                        {
                            nvidiaCount += 1;
                        }
                        else if (vidCtrl.Name.ToLower().Contains("nvidia"))
                        {
                            Helpers.ConsolePrint(Tag,
                                                 "Device not supported NVIDIA/CUDA device not supported " + vidCtrl.Name);
                        }
                        amdCount += (vidCtrl.Name.ToLower().Contains("amd")) ? 1 : 0;
                    }
                    Helpers.ConsolePrint(Tag,
                                         nvidiaCount == _cudaDevices.Count
                            ? "Cuda NVIDIA/CUDA device count GOOD"
                            : "Cuda NVIDIA/CUDA device count BAD!!!");
                    Helpers.ConsolePrint(Tag,
                                         amdCount == AmdDevices.Count ? "AMD GPU device count GOOD" : "AMD GPU device count BAD!!!");
                }
                // allerts
                _currentNvidiaSmiDriver = GetNvidiaSmiDriver();
                // if we have nvidia cards but no CUDA devices tell the user to upgrade driver
                var isNvidiaErrorShown = false; // to prevent showing twice
                var showWarning        = ConfigManager.GeneralConfig.ShowDriverVersionWarning &&
                                         WindowsDisplayAdapters.HasNvidiaVideoController();

                if (showWarning && _cudaDevices.Count != nvidiaCount &&
                    _currentNvidiaSmiDriver.IsLesserVersionThan(NvidiaMinDetectionDriver))
                {
                    isNvidiaErrorShown = true;
                    var minDriver      = NvidiaMinDetectionDriver.ToString();
                    var recomendDrvier = NvidiaRecomendedDriver.ToString();
                    MessageBox.Show(string.Format(
                                        International.GetText("Compute_Device_Query_Manager_NVIDIA_Driver_Detection"),
                                        minDriver, recomendDrvier),
                                    International.GetText("Compute_Device_Query_Manager_NVIDIA_RecomendedDriver_Title"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // recomended driver
                if (showWarning && _currentNvidiaSmiDriver.IsLesserVersionThan(NvidiaRecomendedDriver) &&
                    !isNvidiaErrorShown && _currentNvidiaSmiDriver.LeftPart > -1)
                {
                    var recomendDrvier = NvidiaRecomendedDriver.ToString();
                    var nvdriverString = _currentNvidiaSmiDriver.LeftPart > -1
                        ? string.Format(
                        International.GetText("Compute_Device_Query_Manager_NVIDIA_Driver_Recomended_PART"),
                        _currentNvidiaSmiDriver)
                        : "";
                    MessageBox.Show(string.Format(
                                        International.GetText("Compute_Device_Query_Manager_NVIDIA_Driver_Recomended"),
                                        recomendDrvier, nvdriverString, recomendDrvier),
                                    International.GetText("Compute_Device_Query_Manager_NVIDIA_RecomendedDriver_Title"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                // no devices found
                if (Available.Devices.Count <= 0)
                {
                    var result = MessageBox.Show(International.GetText("Compute_Device_Query_Manager_No_Devices"),
                                                 International.GetText("Compute_Device_Query_Manager_No_Devices_Title"),
                                                 MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.OK)
                    {
                        Process.Start(Links.NhmNoDevHelp);
                    }
                }

                // create AMD bus ordering for Claymore
                var amdDevices = Available.Devices.FindAll((a) => a.DeviceType == DeviceType.AMD);

                amdDevices.Sort((a, b) => a.BusID.CompareTo(b.BusID));
                for (var i = 0; i < amdDevices.Count; i++)
                {
                    amdDevices[i].IDByBus = i;
                }
                //create NV bus ordering for Claymore
                var nvDevices = Available.Devices.FindAll((a) => a.DeviceType == DeviceType.NVIDIA);

                nvDevices.Sort((a, b) => a.BusID.CompareTo(b.BusID));
                for (var i = 0; i < nvDevices.Count; i++)
                {
                    nvDevices[i].IDByBus = i;
                }

                // get GPUs RAM sum
                // bytes
                Available.NvidiaRamSum = 0;
                Available.AmdRamSum    = 0;
                foreach (var dev in Available.Devices)
                {
                    if (dev.DeviceType == DeviceType.NVIDIA)
                    {
                        Available.NvidiaRamSum += dev.GpuRam;
                    }
                    else if (dev.DeviceType == DeviceType.AMD)
                    {
                        Available.AmdRamSum += dev.GpuRam;
                    }
                }
                // Make gpu ram needed not larger than 4GB per GPU
                var totalGpuRam = Math.Min((Available.NvidiaRamSum + Available.AmdRamSum) * 0.6 / 1024,
                                           (double)Available.AvailGpUs * 4 * 1024 * 1024);
                double totalSysRam = SystemSpecs.FreePhysicalMemory + SystemSpecs.FreeVirtualMemory;

                // check
                if (ConfigManager.GeneralConfig.ShowDriverVersionWarning && totalSysRam < totalGpuRam)
                {
                    Helpers.ConsolePrint(Tag, "virtual memory size BAD");
                    MessageBox.Show(International.GetText("VirtualMemorySize_BAD"),
                                    International.GetText("Warning_with_Exclamation"),
                                    MessageBoxButtons.OK);
                }
                else
                {
                    Helpers.ConsolePrint(Tag, "virtual memory size GOOD");
                }

                // #x remove reference
                MessageNotifier = null;
            }
 public T?Rent()
 {
     return(Rent(Cpu.GetCurrentCoreId()));
 }
Beispiel #50
0
    void CpuExecutionThread()
    {
        Debug.Log("CPU is waiting for hardware to become ready");

        while (!mem.isReady)
        {
            Thread.Sleep(10);
        }

        while (!screen.isReady)
        {
            Thread.Sleep(10);
        }

        Debug.Log("CPU started");
        Cpu.Reset();
        dasm = Cpu.Disassemble(Cpu.Registers.PC);

        Cpu.ExecutionInfo ei;
        int cycles;

        while (!stopped)
        {
            if (triggerReset)
            {
                triggerReset = false;
                mem.LoadRom();
                Cpu.Reset();
            }

            if (stepMode)
            {
                if (!nextStep)
                {
                    Thread.Sleep(10);
                    continue;
                }
                else
                {
                    nextStep        = false;
                    cycles          = Cpu.ExecuteSingle();
                    cyclesExecuted += cycles;
                    dasm            = Cpu.Disassemble(Cpu.Registers.PC);
                }
            }
            else
            {
                ei = Cpu.Execute(cyclesPerExec);
                if (ei.cyclesExecuted == 0)
                {
                    stopped = true; // breakpoint probably
                }

                if (autoAdjustCycles)
                {
                    if (ei.cyclesSlept > 5)
                    {
                        cyclesPerExec -= (ei.cyclesSlept - 5) * 1000;
                        if (cyclesPerExec < 1000)
                        {
                            cyclesPerExec = 1000;
                        }
                    }
                    else if (ei.cyclesSlept < 1)
                    {
                        cyclesPerExec += 5000;
                    }
                }

                cyclesExecuted += ei.cyclesExecuted;
                dasm            = Cpu.Disassemble(Cpu.Registers.PC);
            }
        }

        Debug.Log("CPU has stopped");
    }
Beispiel #51
0
 public Resource Subtract(JobBatch batch)
 {
     Cpu.Subtract(batch.Cpu * batch.Size, batch.BeginTime, batch.Duration);
     Mem.Subtract(batch.Mem * batch.Size, batch.BeginTime, batch.Duration);
     return(this);
 }
Beispiel #52
0
 public void InterlockedDecrement()
 {
     InterlockedDecrement(Cpu.GetCurrentCoreId());
 }
Beispiel #53
0
 public Resource Add(JobBatch batch)
 {
     Cpu.Add(batch.Cpu * batch.Size, batch.BeginTime, batch.Duration);
     Mem.Add(batch.Mem * batch.Size, batch.BeginTime, batch.Duration);
     return(this);
 }
Beispiel #54
0
        private void SyncState(Serializer ser)
        {
            byte[] core = null;
            if (ser.IsWriter)
            {
                var ms = new MemoryStream();
                ms.Close();
                core = ms.ToArray();
            }
            Cpu.SyncState(ser);

            ser.BeginSection("SMS");
            Vdp.SyncState(ser);
            PSG.SyncState(ser);
            ser.Sync("RAM", ref SystemRam, false);
            ser.Sync("RomBank0", ref RomBank0);
            ser.Sync("RomBank1", ref RomBank1);
            ser.Sync("RomBank2", ref RomBank2);
            ser.Sync("RomBank3", ref RomBank3);
            ser.Sync("Bios_bank", ref Bios_bank);
            ser.Sync("Port01", ref Port01);
            ser.Sync("Port02", ref Port02);
            ser.Sync("Port3E", ref Port3E);
            ser.Sync("Port3F", ref Port3F);
            ser.Sync("Controller1SelectHigh", ref Controller1SelectHigh);
            ser.Sync("ControllerSelect2High", ref Controller2SelectHigh);
            ser.Sync("LatchLightPhaser", ref LatchLightPhaser);

            if (SaveRAM != null)
            {
                ser.Sync("SaveRAM", ref SaveRAM, false);
            }

            ser.Sync("SaveRamBank", ref SaveRamBank);

            if (ExtRam != null)
            {
                ser.Sync("ExtRAM", ref ExtRam, true);
            }

            if (HasYM2413)
            {
                YM2413.SyncState(ser);
            }

            if (EEPROM != null)
            {
                EEPROM.SyncState(ser);
            }

            ser.Sync("Frame", ref _frame);
            ser.Sync("LagCount", ref _lagCount);
            ser.Sync("IsLag", ref _isLag);

            ser.EndSection();

            if (ser.IsReader)
            {
                SyncAllByteArrayDomains();
            }
        }
 internal void Process(int data)
 {
     Ram.SaveValue(data);
     // TODO: Fix it
     Cpu.SquareNumber();
 }
Beispiel #56
0
 internal override void Execute(Cpu cpu)
 {
     cpu.VRegisters[Vx] |= cpu.VRegisters[Vy];
 }
Beispiel #57
0
 public override bool Execute(InstructionData aData, Cpu aCpu)
 {
     return(false);
 }
Beispiel #58
0
 public void Decrement()
 {
     Decrement(Cpu.GetCurrentCoreId());
 }
Beispiel #59
0
        /// <summary>
        /// The main execution cycle of the Spectrum VM
        /// </summary>
        /// <param name="token">Cancellation token</param>
        /// <param name="options">Execution options</param>
        /// <param name="completeOnCpuFrame">The cycle should complete on CPU frame completion</param>
        /// <return>True, if the cycle completed; false, if it has been cancelled</return>
        public bool ExecuteCycle(CancellationToken token, ExecuteCycleOptions options, bool completeOnCpuFrame = false)
        {
            ExecuteCycleOptions       = options;
            ExecutionCompletionReason = ExecutionCompletionReason.None;
            LastExecutionStartTact    = Cpu.Tacts;

            // --- We use this variables to check whether to stop in Debug mode
            var executedInstructionCount = -1;
            var entryStepOutDepth        = Cpu.StackDebugSupport.StepOutStackDepth;

            // --- Check if we're just start running the next frame
            if (HasFrameCompleted)
            {
                // --- This counter helps us to calculate where we are in the frame after
                // --- each CPU operation cycle
                LastFrameStartCpuTick = Cpu.Tacts - Overflow;

                // --- Notify devices to start a new frame
                OnNewFrame();
                LastRenderedUlaTact = Overflow;
                HasFrameCompleted   = false;
            }

            // --- The physical frame cycle that goes on while CPU and ULA
            // --- processes everything within a physical frame (0.019968 second)
            while (!HasFrameCompleted)
            {
                // --- Check debug mode when a CPU instruction has been entirely executed
                if (!Cpu.IsInOpExecution)
                {
                    // --- The next instruction is about to be executed
                    executedInstructionCount++;

                    // --- Check for cancellation
                    if (token.IsCancellationRequested)
                    {
                        ExecutionCompletionReason = ExecutionCompletionReason.Cancelled;
                        return(false);
                    }

                    // --- Check for CPU frame completion
                    if (completeOnCpuFrame && Cpu.Tacts > LastExecutionStartTact + CPU_FRAME)
                    {
                        ExecutionCompletionReason = ExecutionCompletionReason.CpuFrameCompleted;
                        return(true);
                    }

                    // --- Check for several termination modes
                    switch (options.EmulationMode)
                    {
                    // --- Check for reaching the termination point
                    case EmulationMode.UntilExecutionPoint when options.TerminationPoint < 0x4000:
                    {
                        // --- ROM & address must match
                        if (options.TerminationRom == MemoryDevice.GetSelectedRomIndex() &&
                            options.TerminationPoint == Cpu.Registers.PC)
                        {
                            // --- We reached the termination point within ROM
                            ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                            return(true);
                        }

                        break;
                    }

                    // --- Check if we reached the termination point within RAM
                    case EmulationMode.UntilExecutionPoint
                        when options.TerminationPoint == Cpu.Registers.PC:

                        ExecutionCompletionReason = ExecutionCompletionReason.TerminationPointReached;
                        return(true);

                    // --- Check for a debugging stop point
                    case EmulationMode.Debugger
                        when IsDebugStop(options, executedInstructionCount, entryStepOutDepth) &&
                        DebugConditionSatisfied():

                        // --- At this point, the cycle should be stopped because of debugging reasons
                        // --- The screen should be refreshed
                        ExecutionCompletionReason = ExecutionCompletionReason.BreakpointReached;

                        return(true);
                    }
                }

                // --- Check for interrupt signal generation
                InterruptDevice.CheckForInterrupt(CurrentFrameTact);

                // --- Run a single Z80 instruction
                Cpu.ExecuteCpuCycle();
                _lastBreakpoint = null;

                // --- Run a rendering cycle according to the current CPU tact count
                var lastTact = CurrentFrameTact;
                ScreenDevice.RenderScreen(LastRenderedUlaTact + 1, lastTact);
                LastRenderedUlaTact = lastTact;

                // --- Exit if the CPU is HALTed and the emulation mode specifies so
                if (options.EmulationMode == EmulationMode.UntilHalt &&
                    (Cpu.StateFlags & Z80StateFlags.Halted) != 0)
                {
                    ExecutionCompletionReason = ExecutionCompletionReason.Halted;
                    return(true);
                }

                // --- Notify each CPU-bound device that the current operation has been completed
                foreach (var device in _cpuBoundDevices)
                {
                    device.OnCpuOperationCompleted();
                }

                // --- Decide whether this frame has been completed
                HasFrameCompleted = !Cpu.IsInOpExecution && CurrentFrameTact >= FrameTacts;
            }

            // --- A physical frame has just been completed. Take care about screen refresh
            FrameCount++;
            Overflow = CurrentFrameTact % FrameTacts;

            // --- Notify devices that the current frame completed
            OnFrameCompleted();

            // --- We exit the cycle when the render frame has completed
            ExecutionCompletionReason = ExecutionCompletionReason.RenderFrameCompleted;
            return(true);
        }
Beispiel #60
0
 public void cpu_OnTXS(Cpu cpu)
 {
     Debug.Assert(false, "UNHANDLED TXS");
     OnTXS.Invoke(null);
 }