GameBoy\Core::clockUpdate PHP Method

clockUpdate() public method

public clockUpdate ( )
    public function clockUpdate()
    {
        //We're tying in the same timer for RTC and frame skipping, since we can and this reduces load.
        if (Settings::$autoFrameskip || $this->cTIMER) {
            $timeElapsed = (int) (microtime(true) * 1000) - $this->lastIteration;
            //Get the numnber of milliseconds since this last executed.
            if ($this->cTIMER && !$this->RTCHALT) {
                //Update the MBC3 RTC:
                $this->RTCSeconds += $timeElapsed / 1000;
                //System can stutter, so the seconds difference can get large, thus the "while".
                while ($this->RTCSeconds >= 60) {
                    $this->RTCSeconds -= 60;
                    ++$this->RTCMinutes;
                    if ($this->RTCMinutes >= 60) {
                        $this->RTCMinutes -= 60;
                        ++$this->RTCHours;
                        if ($this->RTCHours >= 24) {
                            $this->RTCHours -= 24;
                            ++$this->RTCDays;
                            if ($this->RTCDays >= 512) {
                                $this->RTCDays -= 512;
                                $this->RTCDayOverFlow = true;
                            }
                        }
                    }
                }
            }
            if (Settings::$autoFrameskip) {
                //Auto Frame Skip:
                if ($timeElapsed > Settings::$loopInterval) {
                    //Did not finish in time...
                    if (Settings::$frameskipAmout < Settings::$frameskipMax) {
                        ++Settings::$frameskipAmout;
                    }
                } elseif (Settings::$frameskipAmout > 0) {
                    //We finished on time, decrease frame skipping (throttle to somewhere just below full speed)...
                    --Settings::$frameskipAmout;
                }
            }
            $this->lastIteration = (int) (microtime(true) * 1000);
        }
    }