Exemplo n.º 1
0
        public void Tick()
        {
            UpdateDiv((_div + 1) & 0xffff);
            if (!_overflow)
            {
                return;
            }

            _ticksSinceOverflow++;
            if (_ticksSinceOverflow == 4)
            {
                _interruptManager.RequestInterrupt(InterruptManager.InterruptType.Timer);
            }

            if (_ticksSinceOverflow == 5)
            {
                _tima = _tma;
            }

            if (_ticksSinceOverflow == 6)
            {
                _tima               = _tma;
                _overflow           = false;
                _ticksSinceOverflow = 0;
            }
        }
Exemplo n.º 2
0
 public void OnButtonPress(Button button)
 {
     if (button != null)
     {
         _interruptManager.RequestInterrupt(InterruptManager.InterruptType.P1013);
         _buttons.TryAdd(button, button);
     }
 }
Exemplo n.º 3
0
        public void UpdateInput(KeyState ks)
        {
            int diff1 =
                (keyState.buttonState ^ ks.buttonState) & ks.buttonState |
                ((keyState.dpadState ^ ks.dpadState) & ks.dpadState);

            if (diff1 != 0)
            {
                interruptManager.RequestInterrupt(InterruptType.Joypad);
            }
            keyState.buttonState = ks.buttonState;
            keyState.dpadState   = ks.dpadState;
        }
Exemplo n.º 4
0
        private void OnLYLineChange()
        {
            if (LCDEnabled)
            {
                if (LY < LCDHeight)
                {
                    ReconstructOAMTable();
                    if (Mode2_OAMInterruptEnabled)
                    {
                        interruptManager.RequestInterrupt(InterruptType.LCDC);
                    }
                    else
                    {
                        LYCoincidenceCheck();
                    }
                }
                else if (LY == LCDHeight)
                {
                    interruptManager.RequestInterrupt(InterruptType.VBlank);
                    GlobalTimer.GetInstance().ResetEventCounter();

                    if (Mode1_VBlankInterruptEnabled)
                    {
                        interruptManager.RequestInterrupt(InterruptType.LCDC);
                    }
                    else
                    {
                        LYCoincidenceCheck();
                    }
                }
                else
                {
                    LYCoincidenceCheck();
                }
            }
        }
Exemplo n.º 5
0
 public override void UpdateTime(int cycles)
 {
     CycleCounter += cycles;
     if (CycleCounter >= DMG_ClockRate)
     {
         CycleCounter -= DMG_ClockRate;
     }
     if (TAC_TimerEnabled)
     {
         TAC_TimerCycles += cycles;
         while (TAC_TimerCycles >= TAC_Timings[TAC_ClockIndex])
         {
             TAC_TimerCycles -= TAC_Timings[TAC_ClockIndex];
             TIMA_TimerCounter++;
             if (TIMA_TimerCounter == 0)
             {
                 interruptManager.RequestInterrupt(InterruptType.Timer);
                 TIMA_TimerCounter = TMA_TimerOverflowValue;
             }
         }
     }
 }
Exemplo n.º 6
0
        public void Tick()
        {
            if (!_transferInProgress)
            {
                return;
            }

            if (++_divider >= Gameboy.TicksPerSec / 8192 / _speedMode.GetSpeedMode())
            {
                _transferInProgress = false;
                try
                {
                    _sb = _serialEndpoint.transfer(_sb);
                }
                catch (IOException e)
                {
                    Debug.WriteLine($"Can't transfer byte {e}");
                    _sb = 0;
                }

                _interruptManager.RequestInterrupt(InterruptManager.InterruptType.Serial);
            }
        }
Exemplo n.º 7
0
        public Mode?Tick()
        {
            if (!_lcdEnabled)
            {
                if (_lcdEnabledDelay != -1)
                {
                    if (--_lcdEnabledDelay == 0)
                    {
                        _display.Enabled = true;
                        _lcdEnabled      = true;
                    }
                }
            }

            if (!_lcdEnabled)
            {
                return(null);
            }

            var oldMode = _mode;

            _ticksInLine++;
            if (_phase.Tick())
            {
                // switch line 153 to 0
                if (_ticksInLine == 4 && _mode == Mode.VBlank && _r.Get(GpuRegister.Ly) == 153)
                {
                    _r.Put(GpuRegister.Ly, 0);
                    RequestLycEqualsLyInterrupt();
                }
            }
            else
            {
                switch (oldMode)
                {
                case Mode.OamSearch:
                    _mode  = Mode.PixelTransfer;
                    _phase = _pixelTransferPhase.Start(_oamSearchPhase.GetSprites());
                    break;

                case Mode.PixelTransfer:
                    _mode  = Mode.HBlank;
                    _phase = _hBlankPhase.Start(_ticksInLine);
                    RequestLcdcInterrupt(3);
                    break;

                case Mode.HBlank:
                    _ticksInLine = 0;
                    if (_r.PreIncrement(GpuRegister.Ly) == 144)
                    {
                        _mode  = Mode.VBlank;
                        _phase = _vBlankPhase.Start();
                        _interruptManager.RequestInterrupt(InterruptManager.InterruptType.VBlank);
                        RequestLcdcInterrupt(4);
                    }
                    else
                    {
                        _mode  = Mode.OamSearch;
                        _phase = _oamSearchPhase.Start();
                    }

                    RequestLcdcInterrupt(5);
                    RequestLycEqualsLyInterrupt();
                    break;

                case Mode.VBlank:
                    _ticksInLine = 0;
                    if (_r.PreIncrement(GpuRegister.Ly) == 1)
                    {
                        _mode = Mode.OamSearch;
                        _r.Put(GpuRegister.Ly, 0);
                        _phase = _oamSearchPhase.Start();
                        RequestLcdcInterrupt(5);
                    }
                    else
                    {
                        _phase = _vBlankPhase.Start();
                    }

                    RequestLycEqualsLyInterrupt();
                    break;
                }
            }

            if (oldMode == _mode)
            {
                return(null);
            }

            return(_mode);
        }