diff --git a/libgambatte/src/memory.cpp b/libgambatte/src/memory.cpp index 5c85ccebeb..7c20121b71 100644 --- a/libgambatte/src/memory.cpp +++ b/libgambatte/src/memory.cpp @@ -337,8 +337,8 @@ unsigned long Memory::stop(unsigned long cc) { cc += 4; if (ioamhram_[0x14D] & isCgb()) { - psg_.generateSamples(cc, isDoubleSpeed()); - lcd_.speedChange(cc); + psg_.generateSamples(cc + 4, isDoubleSpeed()); + lcd_.speedChange((cc + 7) & ~7); ioamhram_[0x14D] ^= 0x81; intreq_.setEventTime(ioamhram_[0x140] & lcdc_en ? lcd_.nextMode1IrqTime() @@ -686,7 +686,7 @@ void Memory::nontrivial_ff_write(unsigned const p, unsigned data, unsigned long break; case 0x07: data |= 0xF8; - tima_.setTac(data, cc, TimaInterruptRequester(intreq_), gbIsCgb_); + tima_.setTac(data, cc, TimaInterruptRequester(intreq_), agbMode_); break; case 0x0F: updateIrqs(cc); diff --git a/libgambatte/src/tima.cpp b/libgambatte/src/tima.cpp index aa4038821b..5b935c8a9c 100644 --- a/libgambatte/src/tima.cpp +++ b/libgambatte/src/tima.cpp @@ -117,7 +117,7 @@ void Tima::setTma(unsigned const data, unsigned long const cc, TimaInterruptRequ tma_ = data; } -void Tima::setTac(unsigned const data, unsigned long const cc, TimaInterruptRequester timaIrq, bool gbIsCgb) { +void Tima::setTac(unsigned const data, unsigned long const cc, TimaInterruptRequester timaIrq, bool agbFlag) { if (tac_ ^ data) { unsigned long nextIrqEventTime = timaIrq.nextIrqEventTime(); @@ -141,7 +141,7 @@ void Tima::setTac(unsigned const data, unsigned long const cc, TimaInterruptRequ if (data & 4) { unsigned long diff = cc - basetime_; - if (gbIsCgb) { + if (agbFlag) { if (((diff >> (timaClock[tac_ & 3] - 1)) & 1) == 1 && ((diff >> (timaClock[data & 3] - 1)) & 1) == 0) tima_++; } diff --git a/libgambatte/src/tima.h b/libgambatte/src/tima.h index 55bfe849ad..d1db0854b9 100644 --- a/libgambatte/src/tima.h +++ b/libgambatte/src/tima.h @@ -41,7 +41,7 @@ public: void resetCc(unsigned long oldCc, unsigned long newCc, TimaInterruptRequester timaIrq); void setTima(unsigned tima, unsigned long cc, TimaInterruptRequester timaIrq); void setTma(unsigned tma, unsigned long cc, TimaInterruptRequester timaIrq); - void setTac(unsigned tac, unsigned long cc, TimaInterruptRequester timaIrq, bool gbIsCgb); + void setTac(unsigned tac, unsigned long cc, TimaInterruptRequester timaIrq, bool agbFlag); void resTac(unsigned long cc, TimaInterruptRequester timaIrq); unsigned tima(unsigned long cc); void doIrqEvent(TimaInterruptRequester timaIrq); diff --git a/output/dll/libgambatte.dll b/output/dll/libgambatte.dll index 1fb295ab05..386ccdb45a 100644 Binary files a/output/dll/libgambatte.dll and b/output/dll/libgambatte.dll differ