diff --git a/Assets/dll/bsnes.wbx.zst b/Assets/dll/bsnes.wbx.zst index 38774aefc9d..542e9e7fe14 100644 Binary files a/Assets/dll/bsnes.wbx.zst and b/Assets/dll/bsnes.wbx.zst differ diff --git a/waterbox/bsnescore/bsnes/sfc/cpu/cpu.hpp b/waterbox/bsnescore/bsnes/sfc/cpu/cpu.hpp index 60a6f691f43..e636f8e8e5d 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/cpu.hpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/cpu.hpp @@ -165,7 +165,9 @@ struct CPU : Processor::WDC65816, Thread, PPUcounter { struct ALU { uint mpyctr = 0; + uint mpylast = 0; uint divctr = 0; + uint divlast = 0; uint shift = 0; } alu; diff --git a/waterbox/bsnescore/bsnes/sfc/cpu/io.cpp b/waterbox/bsnescore/bsnes/sfc/cpu/io.cpp index f08102ac05a..233c402b9c9 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/io.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/io.cpp @@ -159,8 +159,10 @@ auto CPU::writeCPU(uint addr, uint8 data) -> void { io.rddiv = io.wrmpyb << 8 | io.wrmpya; if(!configuration.hacks.cpu.fastMath) { - alu.mpyctr = 8; //perform multiplication over the next eight cycles - alu.shift = io.wrmpyb; + if (!alu.mpylast) { + alu.mpyctr = 8; //perform multiplication over the next eight cycles + alu.shift = io.wrmpyb; + } } else { io.rdmpy = io.wrmpya * io.wrmpyb; } @@ -178,12 +180,14 @@ auto CPU::writeCPU(uint addr, uint8 data) -> void { io.rdmpy = io.wrdiva; if(alu.mpyctr || alu.divctr) return; - io.wrdivb = data; - if(!configuration.hacks.cpu.fastMath) { - alu.divctr = 16; //perform division over the next sixteen cycles - alu.shift = io.wrdivb << 16; + if (!alu.divlast) { + io.wrdivb = data; + alu.divctr = 16; //perform division over the next sixteen cycles + alu.shift = io.wrdivb << 16; + } } else { + io.wrdivb = data; if(io.wrdivb) { io.rddiv = io.wrdiva / io.wrdivb; io.rdmpy = io.wrdiva % io.wrdivb; diff --git a/waterbox/bsnescore/bsnes/sfc/cpu/timing.cpp b/waterbox/bsnescore/bsnes/sfc/cpu/timing.cpp index 553f13f8210..d0e64022f60 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/timing.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/timing.cpp @@ -143,13 +143,19 @@ auto CPU::scanline() -> void { auto CPU::aluEdge() -> void { if(alu.mpyctr) { alu.mpyctr--; + if (!alu.mpyctr) + alu.mpylast = 1; if(io.rddiv & 1) io.rdmpy += alu.shift; io.rddiv >>= 1; alu.shift <<= 1; } + else + alu.mpylast = 0; if(alu.divctr) { alu.divctr--; + if (!alu.divctr) + alu.divlast = 1; io.rddiv <<= 1; alu.shift >>= 1; if(io.rdmpy >= alu.shift) { @@ -157,6 +163,8 @@ auto CPU::aluEdge() -> void { io.rddiv |= 1; } } + else + alu.divlast = 0; } auto CPU::dmaEdge() -> void {