/// <summary> /// Signs that the device has been attached to the Spectrum virtual machine /// </summary> public void OnAttachedToVm(ISpectrumVm hostVm) { HostVm = hostVm; var screenInfo = hostVm.GetDeviceInfo <IScreenDevice>(); ScreenConfiguration = hostVm.ScreenConfiguration; _pixelRenderer = (IScreenFrameProvider)screenInfo.Provider ?? new NoopPixelRenderer(); _memoryDevice = hostVm.MemoryDevice; _contentionType = hostVm.MemoryConfiguration.ContentionType; InitializeScreenRenderingTactTable(); _flashPhase = false; FrameCount = 0; // --- Calculate refresh rate related values RefreshRate = (decimal)hostVm.BaseClockFrequency / ScreenConfiguration.ScreenRenderingFrameTactCount; FlashToggleFrames = (int)Math.Round(RefreshRate / 2); // --- Calculate color conversion table _flashOffColors = new int[0x200]; _flashOnColors = new int[0x200]; for (var attr = 0; attr < 0x100; attr++) { var ink = (attr & 0x07) | ((attr & 0x40) >> 3); var paper = ((attr & 0x38) >> 3) | ((attr & 0x40) >> 3); _flashOffColors[attr] = paper; _flashOffColors[0x100 + attr] = ink; _flashOnColors[attr] = (attr & 0x80) != 0 ? ink : paper; _flashOnColors[0x100 + attr] = (attr & 0x80) != 0 ? paper : ink; } _screenWidth = hostVm.ScreenDevice.ScreenConfiguration.ScreenWidth; _pixelBuffer = new byte[_screenWidth * hostVm.ScreenDevice.ScreenConfiguration.ScreenLines]; }
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary> public SpectrumAdvancedTestMachine(IScreenFrameProvider renderer = null, IScreenConfiguration screenConfig = null, ICpuConfiguration cpuConfig = null): base(new DeviceInfoCollection { new CpuDeviceInfo(cpuConfig ?? SpectrumModels.ZxSpectrum48Pal.Cpu), new RomDeviceInfo(new ResourceRomProvider(), new RomConfigurationData { NumberOfRoms = 1, RomName = "ZXSpectrum48", Spectrum48RomIndex = 0 }, new SpectrumRomDevice()), new ClockDeviceInfo(new ClockProvider()), new BeeperDeviceInfo(new BeeperConfigurationData { AudioSampleRate = 35000, SamplesPerFrame = 699, TactsPerSample = 100 }, null), new ScreenDeviceInfo(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen, renderer ?? new TestPixelRenderer(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen)) }) { }
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary> public SpectrumAdvancedTestMachine(IScreenFrameProvider renderer = null, IScreenConfiguration screenConfig = null, ICpuConfiguration cpuConfig = null, string ulaIssue = "3") : base(new DeviceInfoCollection { new CpuDeviceInfo(cpuConfig ?? SpectrumModels.ZxSpectrum48Pal.Cpu), new RomDeviceInfo(new ResourceRomProvider(typeof(RomResourcesPlaceHolder).Assembly), new RomConfigurationData { NumberOfRoms = 1, RomName = "ZxSpectrum48", Spectrum48RomIndex = 0 }, new SpectrumRomDevice()), new MemoryDeviceInfo( new MemoryConfigurationData { SupportsBanking = false, ContentionType = MemoryContentionType.Ula }, null), new ClockDeviceInfo(new ClockProvider()), new BeeperDeviceInfo(new AudioConfigurationData { AudioSampleRate = 35000, SamplesPerFrame = 699, TactsPerSample = 100 }, null), new ScreenDeviceInfo(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen, renderer ?? new TestPixelRenderer(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen)) }, ulaIssue) { StackPointerManipulations = new List <StackPointerManipulationEvent>(); StackContentManipulations = new List <StackContentManipulationEvent>(); BranchEvents = new List <BranchEvent>(); Cpu.StackDebugSupport = this; }
/// /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public Spectrum128AdvancedTestMachine(IScreenFrameProvider renderer = null, IScreenConfiguration screenConfig = null, ICpuConfiguration cpuConfig = null) : base(new DeviceInfoCollection { new CpuDeviceInfo(cpuConfig ?? SpectrumModels.ZxSpectrum128Pal.Cpu), new RomDeviceInfo(new ResourceRomProvider(typeof(RomResourcesPlaceHolder).Assembly), new RomConfigurationData { NumberOfRoms = 2, RomName = "ZxSpectrum128", Spectrum48RomIndex = 1 }, new SpectrumRomDevice()), new ClockDeviceInfo(new ClockProvider()), new MemoryDeviceInfo(new MemoryConfigurationData { SupportsBanking = true, RamBanks = 8 }, new Spectrum128MemoryDevice()), new PortDeviceInfo(null, new Spectrum128PortDevice()), new BeeperDeviceInfo(new AudioConfigurationData { AudioSampleRate = 35000, SamplesPerFrame = 699, TactsPerSample = 100 }, null), new ScreenDeviceInfo(screenConfig ?? SpectrumModels.ZxSpectrum128Pal.Screen, renderer ?? new TestPixelRenderer(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen)), new SoundDeviceInfo(new AudioConfigurationData { AudioSampleRate = 55420, SamplesPerFrame = 1107, TactsPerSample = 64 }, null) }) { StackPointerManipulations = new List <StackPointerManipulationEvent>(); StackContentManipulations = new List <StackContentManipulationEvent>(); BranchEvents = new List <BranchEvent>(); Cpu.StackDebugSupport = this; }
/// /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public Spectrum128AdvancedTestMachine(IScreenFrameProvider renderer = null, IScreenConfiguration screenConfig = null, ICpuConfiguration cpuConfig = null) : base(new DeviceInfoCollection { new CpuDeviceInfo(cpuConfig ?? SpectrumModels.ZxSpectrum128Pal.Cpu), new RomDeviceInfo(new ResourceRomProvider(), new RomConfigurationData { NumberOfRoms = 2, RomName = "ZxSpectrum128", Spectrum48RomIndex = 1 }, new SpectrumRomDevice()), new ClockDeviceInfo(new ClockProvider()), new MemoryDeviceInfo(new MemoryConfigurationData { SupportsBanking = true, SlotSize = 16, RamBanks = 8 }, new Spectrum128MemoryDevice()), new PortDeviceInfo(null, new Spectrum128PortDevice()), new BeeperDeviceInfo(new AudioConfigurationData { AudioSampleRate = 35000, SamplesPerFrame = 699, TactsPerSample = 100 }, null), new ScreenDeviceInfo(screenConfig ?? SpectrumModels.ZxSpectrum128Pal.Screen, renderer ?? new TestPixelRenderer(screenConfig ?? SpectrumModels.ZxSpectrum48Pal.Screen)), new SoundDeviceInfo(new AudioConfigurationData { AudioSampleRate = 55420, SamplesPerFrame = 1107, TactsPerSample = 64 }, null) }) { }
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary> public Spectrum48( IRomProvider romProvider, IClockProvider clockProvider, IKeyboardProvider keyboardProvider, IScreenFrameProvider pixelRenderer, IEarBitFrameProvider earBitFrameProvider = null, ITapeContentProvider loadContentProvider = null, ISaveToTapeProvider tapeSaveToTapeProvider = null) { // --- Init the CPU MemoryDevice = new Spectrum48MemoryDevice(); PortDevice = new Spectrum48PortDevice(); Cpu = new Z80Cpu(MemoryDevice, PortDevice); OsInitialized = false; // --- Setup the clock Clock = clockProvider; // --- Set up Spectrum devices BorderDevice = new BorderDevice(); ScreenDevice = new Spectrum48ScreenDevice(pixelRenderer); BeeperDevice = new BeeperDevice(earBitFrameProvider); KeyboardDevice = new KeyboardDevice(keyboardProvider); InterruptDevice = new InterruptDevice(InterruptTact); TapeDevice = new TapeDevice(loadContentProvider, tapeSaveToTapeProvider); // --- Carry out frame calculations ResetUlaTact(); _frameTacts = ScreenDevice.ScreenConfiguration.UlaFrameTactCount; PhysicalFrameClockCount = Clock.GetFrequency() / (double)ClockFrequeny * _frameTacts; FrameCount = 0; Overflow = 0; _frameCompleted = true; // --- Collect Spectrum devices _spectrumDevices.Add(MemoryDevice); _spectrumDevices.Add(PortDevice); _spectrumDevices.Add(BorderDevice); _spectrumDevices.Add(ScreenDevice); _spectrumDevices.Add(BeeperDevice); _spectrumDevices.Add(KeyboardDevice); _spectrumDevices.Add(InterruptDevice); _spectrumDevices.Add(TapeDevice); // --- Now, prepare devices to find each other foreach (var device in _spectrumDevices) { device.OnAttachedToVm(this); } // --- Prepare bound devices _frameBoundDevices = _spectrumDevices .OfType <IFrameBoundDevice>() .ToList(); _cpuBoundDevices = _spectrumDevices .OfType <ICpuOperationBoundDevice>() .ToList(); DebugInfoProvider = new SpectrumDebugInfoProvider(); // --- Init the ROM InitRom(romProvider, "ZXSpectrum48"); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class /// using the specified display parameters /// </summary> /// <param name="pixelRenderer">Object that renders the screen pixels</param> public Spectrum48ScreenDevice(IScreenFrameProvider pixelRenderer) { ScreenConfiguration = new ScreenConfiguration(); _pixelRenderer = pixelRenderer ?? new NoopPixelRenderer(); }
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary> public SpectrumAdvancedTestMachine(ScreenConfiguration pars = null, IScreenFrameProvider renderer = null) : base(new ResourceRomProvider(), new ClockProvider(), null, renderer ?? new TestPixelRenderer(pars ?? new ScreenConfiguration())) { }