diff --git a/libgambatte/src/memory.cpp b/libgambatte/src/memory.cpp index 3b255d7d62..f76da1511d 100644 --- a/libgambatte/src/memory.cpp +++ b/libgambatte/src/memory.cpp @@ -655,6 +655,11 @@ unsigned Memory::nontrivial_read(unsigned const p, unsigned long const cc) { if (!lcd_.vramReadable(cc)) return 0xFF; + if (lcd_.vramExactlyReadable(cc)) + if (p < 0x9000) { + return 0x00; + } + return cart_.vrambankptr()[p]; } diff --git a/libgambatte/src/video.cpp b/libgambatte/src/video.cpp index 654c8bbd50..f1075178ce 100644 --- a/libgambatte/src/video.cpp +++ b/libgambatte/src/video.cpp @@ -290,6 +290,15 @@ bool LCD::vramReadable(unsigned long const cc) { || cc + 2 >= m0TimeOfCurrentLine(cc); } +bool LCD::vramExactlyReadable(unsigned long const cc) { + bool currentVramExactlyReadable = (cc + 2 == m0TimeOfCurrentLine(cc)); + bool vramAlreadyExactlyRead = vramHasBeenExactlyRead; + if (currentVramExactlyReadable) { + vramHasBeenExactlyRead = true; + } + return !vramAlreadyExactlyRead && currentVramExactlyReadable; +} + bool LCD::vramWritable(unsigned long const cc) { if (cc >= eventTimes_.nextEventTime()) update(cc); @@ -848,4 +857,5 @@ SYNCFUNC(LCD) SSS(lycIrq_); SSS(nextM0Time_); NSS(statReg_); + NSS(vramHasBeenExactlyRead); } diff --git a/libgambatte/src/video.h b/libgambatte/src/video.h index ab8b25475c..60e05bbf42 100644 --- a/libgambatte/src/video.h +++ b/libgambatte/src/video.h @@ -102,6 +102,7 @@ public: void resetCc(unsigned long oldCC, unsigned long newCc); void speedChange(unsigned long cycleCounter); bool vramReadable(unsigned long cycleCounter); + bool vramExactlyReadable(unsigned long cycleCounter); bool vramWritable(unsigned long cycleCounter); bool oamReadable(unsigned long cycleCounter); bool oamWritable(unsigned long cycleCounter); @@ -228,6 +229,7 @@ public: LycIrq lycIrq_; NextM0Time nextM0Time_; unsigned char statReg_; + bool vramHasBeenExactlyRead = false; static void setDmgPalette(unsigned long palette[], unsigned long const dmgColors[], @@ -235,13 +237,13 @@ public: unsigned long gbcToRgb32(const unsigned bgr15); void doCgbColorChange(unsigned char *const pdata, unsigned long *const palette, unsigned index, const unsigned data); - void refreshPalettes(); void setDBuffer(); void doMode2IrqEvent(); void event(); unsigned long m0TimeOfCurrentLine(unsigned long cc); bool cgbpAccessible(unsigned long cycleCounter); + bool lycRegChangeStatTriggerBlockedByM0OrM1Irq(unsigned data, unsigned long cc); bool lycRegChangeTriggersStatIrq(unsigned old, unsigned data, unsigned long cc); bool statChangeTriggersM0LycOrM1StatIrqCgb(unsigned old, unsigned data, bool lycperiod, unsigned long cc); diff --git a/output/dll/libgambatte.dll b/output/dll/libgambatte.dll index 3292e503ac..59d464690c 100644 Binary files a/output/dll/libgambatte.dll and b/output/dll/libgambatte.dll differ