diff --git a/libgambatte/src/mem/cartridge.cpp b/libgambatte/src/mem/cartridge.cpp index 4ffab795..57509482 100644 --- a/libgambatte/src/mem/cartridge.cpp +++ b/libgambatte/src/mem/cartridge.cpp @@ -278,7 +278,7 @@ public: break; case 1: rombank_ = data & 0x7F; - memptrs_.setRombank(rombank_ & (rombanks(memptrs_) - 1)); + setRombank(); break; case 2: rambank_ = data; @@ -303,7 +303,7 @@ public: rambank_ = ss.rambank; enableRam_ = ss.enableRam; setRambank(); - memptrs_.setRombank(rombank_ & (rombanks(memptrs_) - 1)); + setRombank(); } private: @@ -325,6 +325,10 @@ private: memptrs_.setRambank(flags, rambank_ & (rambanks(memptrs_) - 1)); } + + void setRombank() const { + memptrs_.setRombank(std::max(rombank_ & (rombanks(memptrs_) - 1), 1u)); + } }; class HuC1 : public DefaultMbc {