/// <summary> /// Initializes a new instance of the <see cref="TimerRegisters"/> class. /// </summary> /// <param name="timerControlRegister">The timer control register.</param> /// <param name="interruptFlagsRegister">The interrupt flags register.</param> /// <param name="instructionTimer">The instruction timer.</param> public TimerRegisters(ITimerControlRegister timerControlRegister, IInterruptFlagsRegister interruptFlagsRegister, IInstructionTimer instructionTimer) { TimerControlRegister = timerControlRegister; _interruptFlagsRegister = interruptFlagsRegister; TimerModuloRegister = new SimpleRegister(0xff06, "Timer Modulo (TMA R/W)"); TimerCounterRegister = new SimpleRegister(0xff05, "Timer counter (TIMA R/W)"); instructionTimer.TimingSync += timings => { if (!TimerControlRegister.TimerEnabled) { return; } _cyclesSinceLastIncrement += timings.MachineCycles; if (_cyclesSinceLastIncrement > TimerControlRegister.TimerFrequency) { if (TimerCounterRegister.Register == 0xff) { // Overflow. TimerCounterRegister.Register = TimerModuloRegister.Register; _interruptFlagsRegister.UpdateInterrupts(InterruptFlag.TimerOverflow); } else { TimerCounterRegister.Register++; } } _cyclesSinceLastIncrement -= TimerControlRegister.TimerFrequency; }; }
/// <summary> /// Initializes a new instance of the <see cref="GpuRegisters"/> class. /// </summary> /// <param name="lcdControlRegister">The LCD control register.</param> /// <param name="currentScanlineRegister">The current scanline register.</param> /// <param name="lcdMonochromePaletteRegister">The LCD monochrome palette register.</param> /// <param name="lcdStatusRegister">The LCD status register.</param> /// <param name="interruptFlagsRegister">The interrupt flags register.</param> public GpuRegisters(ILcdControlRegister lcdControlRegister, ICurrentScanlineRegister currentScanlineRegister, ILcdMonochromePaletteRegister lcdMonochromePaletteRegister, ILcdStatusRegister lcdStatusRegister, IInterruptFlagsRegister interruptFlagsRegister) { LcdStatusRegister = lcdStatusRegister; _interruptFlagsRegister = interruptFlagsRegister; LcdControlRegister = lcdControlRegister; CurrentScanlineRegister = currentScanlineRegister; LcdMonochromePaletteRegister = lcdMonochromePaletteRegister; ScrollXRegister = new SimpleRegister(0xff43, "Background Horizontal Scrolling (SCROLLX R/W)"); ScrollYRegister = new SimpleRegister(0xff42, "Background Vertical Scrolling (SCROLLY R/W)"); CurrentScanlineCompareRegister = new SimpleRegister(0xff45, "LY Compare (LYC R/W)"); WindowYPositionRegister = new SimpleRegister(0xff4a, "Window Y Position (WY R/W)"); WindowXPositionRegister = new SimpleRegister(0xff4b, "Window X Position minus 7 (WX R/W)"); }
protected SerialPortBase() { SerialData = new SimpleRegister(0xff01, "Serial data (SIODATA R/W)"); }