void Emu::Cpu::updateTimer(uint16_t m) { uint8_t tmc = emu->mmu->rb(0xFF07); bool timerEnabled = ((tmc & 0x04) != 0); if (timerEnabled) { timerClocks -= m; if (timerClocks <= 0) { setTimerFreq(); if(emu->mmu->rb(0xFF05) == 0xFF) { emu->mmu->wb(0xFF05, emu->mmu->rb(0xFF06)); requestInterrupt(Timer); } else { emu->mmu->wb(0xFF05, emu->mmu->rb(0xFF05) + 1); } } } }
signed int RtcTimer::initTimer(unsigned long desiredFrequency) { if(TIMER_DEBUG) printf("RtcTimer::initTimer()\n"); if (timerFd != -1) { fprintf(stderr,"RtcTimer::initTimer(): called on initialised timer!\n"); return -1; } MusEGlobal::doSetuid(); #ifdef _WIN32 QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(showGPS())); timer->start(15000); //time specified in ms //https://stackoverflow.com/questions/19287550/how-to-call-a-function-after-every-15-seconds-using-qt //http://doc.qt.io/qt-5/qtimer.html#details //http://doc.qt.io/qt-5/qt.html#TimerType-enum #else timerFd = ::open("/dev/rtc", O_RDONLY); if (timerFd == -1) { fprintf(stderr, "fatal error: open /dev/rtc failed: %s\n", strerror(errno)); MusEGlobal::undoSetuid(); return timerFd; } if (!setTimerFreq(desiredFrequency)) { // unable to set timer frequency return -1; } // check if timer really works, start and stop it once. if (!startTimer()) { return -1; } if (!stopTimer()) { return -1; } return timerFd; #endif }