diff --git a/Assets/dll/bsnes.wbx.gz b/Assets/dll/bsnes.wbx.gz index 9fc7feb00c..1af28e1d32 100644 Binary files a/Assets/dll/bsnes.wbx.gz and b/Assets/dll/bsnes.wbx.gz differ diff --git a/waterbox/bsnescore/bsnes/sfc/cartridge/load.cpp b/waterbox/bsnescore/bsnes/sfc/cartridge/load.cpp index 21b50de9fd..6f27c33eb6 100644 --- a/waterbox/bsnescore/bsnes/sfc/cartridge/load.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cartridge/load.cpp @@ -135,7 +135,7 @@ auto Cartridge::loadMap(Markup::Node map, T& memory) -> uint { auto mask = map["mask"].natural(); if(size == 0) size = memory.size(); if(size == 0) return print("loadMap(): size=0\n"), 0; //does this ever actually occur? - return bus.map({&T::read, &memory}, {&T::write, &memory}, addr, size, base, mask); + return bus.map({&T::read, &memory}, {&T::write, &memory}, addr, true, size, base, mask); } auto Cartridge::loadMap( @@ -147,7 +147,7 @@ auto Cartridge::loadMap( auto size = map["size"].natural(); auto base = map["base"].natural(); auto mask = map["mask"].natural(); - return bus.map(reader, writer, addr, size, base, mask); + return bus.map(reader, writer, addr, false, size, base, mask); } //memory(type=ROM,content=Program) @@ -726,5 +726,5 @@ auto Cartridge::loadOBC1(Markup::Node node) -> void { auto Cartridge::loadMSU1() -> void { has.MSU1 = true; - bus.map({&MSU1::readIO, &msu1}, {&MSU1::writeIO, &msu1}, "00-3f,80-bf:2000-2007"); + bus.map({&MSU1::readIO, &msu1}, {&MSU1::writeIO, &msu1}, "00-3f,80-bf:2000-2007", false); } diff --git a/waterbox/bsnescore/bsnes/sfc/coprocessor/sdd1/sdd1.cpp b/waterbox/bsnescore/bsnes/sfc/coprocessor/sdd1/sdd1.cpp index 0727e1b233..1c1fe67b6c 100644 --- a/waterbox/bsnescore/bsnes/sfc/coprocessor/sdd1/sdd1.cpp +++ b/waterbox/bsnescore/bsnes/sfc/coprocessor/sdd1/sdd1.cpp @@ -14,7 +14,7 @@ auto SDD1::unload() -> void { auto SDD1::power() -> void { //hook S-CPU DMA MMIO registers to gather information for struct dma[]; //buffer address and transfer size information for use in SDD1::mcu_read() - bus.map({&SDD1::dmaRead, &sdd1}, {&SDD1::dmaWrite, &sdd1}, "00-3f,80-bf:4300-437f"); + bus.map({&SDD1::dmaRead, &sdd1}, {&SDD1::dmaWrite, &sdd1}, "00-3f,80-bf:4300-437f", true); r4800 = 0x00; r4801 = 0x00; diff --git a/waterbox/bsnescore/bsnes/sfc/cpu/cpu.cpp b/waterbox/bsnescore/bsnes/sfc/cpu/cpu.cpp index 6822a65f4a..bba37ed3cf 100644 --- a/waterbox/bsnescore/bsnes/sfc/cpu/cpu.cpp +++ b/waterbox/bsnescore/bsnes/sfc/cpu/cpu.cpp @@ -87,20 +87,20 @@ auto CPU::power(bool reset) -> void { reader = {&CPU::readRAM, this}; writer = {&CPU::writeRAM, this}; - bus.map(reader, writer, "00-3f,80-bf:0000-1fff", 0x2000); - bus.map(reader, writer, "7e-7f:0000-ffff", 0x20000); + bus.map(reader, writer, "00-3f,80-bf:0000-1fff", true, 0x2000); + bus.map(reader, writer, "7e-7f:0000-ffff", true, 0x20000); reader = {&CPU::readAPU, this}; writer = {&CPU::writeAPU, this}; - bus.map(reader, writer, "00-3f,80-bf:2140-217f"); + bus.map(reader, writer, "00-3f,80-bf:2140-217f", false); reader = {&CPU::readCPU, this}; writer = {&CPU::writeCPU, this}; - bus.map(reader, writer, "00-3f,80-bf:2180-2183,4016-4017,4200-421f"); + bus.map(reader, writer, "00-3f,80-bf:2180-2183,4016-4017,4200-421f", false); reader = {&CPU::readDMA, this}; writer = {&CPU::writeDMA, this}; - bus.map(reader, writer, "00-3f,80-bf:4300-437f"); + bus.map(reader, writer, "00-3f,80-bf:4300-437f", true); if(!reset) random.array(wram, sizeof(wram)); diff --git a/waterbox/bsnescore/bsnes/sfc/expansion/21fx/21fx.cpp b/waterbox/bsnescore/bsnes/sfc/expansion/21fx/21fx.cpp index dbf891c931..3bd96891ce 100644 --- a/waterbox/bsnescore/bsnes/sfc/expansion/21fx/21fx.cpp +++ b/waterbox/bsnescore/bsnes/sfc/expansion/21fx/21fx.cpp @@ -8,8 +8,8 @@ S21FX::S21FX() { resetVector.byte(0) = bus.read(0xfffc, 0x00); resetVector.byte(1) = bus.read(0xfffd, 0x00); - bus.map({&S21FX::read, this}, {&S21FX::write, this}, "00-3f,80-bf:2184-21ff"); - bus.map({&S21FX::read, this}, {&S21FX::write, this}, "00:fffc-fffd"); + bus.map({&S21FX::read, this}, {&S21FX::write, this}, "00-3f,80-bf:2184-21ff", false); + bus.map({&S21FX::read, this}, {&S21FX::write, this}, "00:fffc-fffd", false); booted = false; @@ -44,7 +44,7 @@ S21FX::~S21FX() { bus.map([vector](uint24 addr, uint8) -> uint8 { return vector >> addr * 8; }, [](uint24, uint8) -> void { - }, "00:fffc-fffd", 2); + }, "00:fffc-fffd", false, 2); if(link.open()) link.close(); linkInit.reset(); diff --git a/waterbox/bsnescore/bsnes/sfc/expansion/satellaview/satellaview.cpp b/waterbox/bsnescore/bsnes/sfc/expansion/satellaview/satellaview.cpp index 74ffa9f259..146bac7686 100644 --- a/waterbox/bsnescore/bsnes/sfc/expansion/satellaview/satellaview.cpp +++ b/waterbox/bsnescore/bsnes/sfc/expansion/satellaview/satellaview.cpp @@ -3,7 +3,7 @@ namespace SuperFamicom { Satellaview::Satellaview() { - bus.map({&Satellaview::read, this}, {&Satellaview::write, this}, "00-3f,80-bf:2188-219f"); + bus.map({&Satellaview::read, this}, {&Satellaview::write, this}, "00-3f,80-bf:2188-219f", false); regs = {}; } diff --git a/waterbox/bsnescore/bsnes/sfc/memory/memory-inline.hpp b/waterbox/bsnescore/bsnes/sfc/memory/memory-inline.hpp index c20d0eca49..3bc5f4dc1e 100644 --- a/waterbox/bsnescore/bsnes/sfc/memory/memory-inline.hpp +++ b/waterbox/bsnescore/bsnes/sfc/memory/memory-inline.hpp @@ -23,6 +23,10 @@ auto Bus::reduce(uint addr, uint mask) -> uint { return addr; } +auto Bus::peek(uint addr, uint8 data) -> uint8 { + return peekable[lookup[addr]] ? read(addr, data) : 0; +} + auto Bus::read(uint addr, uint8 data) -> uint8 { return reader[lookup[addr]](target[addr], data); } diff --git a/waterbox/bsnescore/bsnes/sfc/memory/memory.cpp b/waterbox/bsnescore/bsnes/sfc/memory/memory.cpp index 144e0d6566..c9174e7eec 100644 --- a/waterbox/bsnescore/bsnes/sfc/memory/memory.cpp +++ b/waterbox/bsnescore/bsnes/sfc/memory/memory.cpp @@ -16,6 +16,7 @@ auto Bus::reset() -> void { reader[id].reset(); writer[id].reset(); counter[id] = 0; + peekable[id] = true; } //if(lookup) delete[] lookup; @@ -34,7 +35,7 @@ auto Bus::reset() -> void { auto Bus::map( const function& read, const function& write, - const string& addr, uint size, uint base, uint mask + const string& addr, bool isPeekable, uint size, uint base, uint mask ) -> uint { uint id = 1; while(counter[id]) { @@ -43,6 +44,7 @@ auto Bus::map( reader[id] = read; writer[id] = write; + peekable[id] = isPeekable; auto p = addr.split(":", 1L); auto banks = p(0).split(","); diff --git a/waterbox/bsnescore/bsnes/sfc/memory/memory.hpp b/waterbox/bsnescore/bsnes/sfc/memory/memory.hpp index fa028309d8..e880a9dc0a 100644 --- a/waterbox/bsnescore/bsnes/sfc/memory/memory.hpp +++ b/waterbox/bsnescore/bsnes/sfc/memory/memory.hpp @@ -26,6 +26,7 @@ struct Bus { ~Bus(); + alwaysinline auto peek(uint address, uint8 data = 0) -> uint8; alwaysinline auto read(uint address, uint8 data = 0) -> uint8; alwaysinline auto write(uint address, uint8 data) -> void; @@ -33,7 +34,7 @@ struct Bus { auto map( const function& read, const function& write, - const string& address, uint size = 0, uint base = 0, uint mask = 0 + const string& address, bool isPeekable, uint size = 0, uint base = 0, uint mask = 0 ) -> uint; auto unmap(const string& address) -> void; @@ -44,6 +45,7 @@ private: function reader[256]; function writer[256]; uint counter[256]; + bool peekable[256]; }; extern Bus bus; diff --git a/waterbox/bsnescore/bsnes/sfc/ppu-fast/ppu.cpp b/waterbox/bsnescore/bsnes/sfc/ppu-fast/ppu.cpp index 18f84d2702..fedda02ad2 100644 --- a/waterbox/bsnescore/bsnes/sfc/ppu-fast/ppu.cpp +++ b/waterbox/bsnescore/bsnes/sfc/ppu-fast/ppu.cpp @@ -186,7 +186,7 @@ auto PPU::power(bool reset) -> void { function reader{&PPU::readIO, this}; function writer{&PPU::writeIO, this}; - bus.map(reader, writer, "00-3f,80-bf:2100-213f"); + bus.map(reader, writer, "00-3f,80-bf:2100-213f", false); if(!reset) { for(auto& word : vram) word = 0x0000; diff --git a/waterbox/bsnescore/bsnes/sfc/ppu/ppu.cpp b/waterbox/bsnescore/bsnes/sfc/ppu/ppu.cpp index dc8d135fce..a4cc9f70f8 100644 --- a/waterbox/bsnescore/bsnes/sfc/ppu/ppu.cpp +++ b/waterbox/bsnescore/bsnes/sfc/ppu/ppu.cpp @@ -86,7 +86,7 @@ auto PPU::power(bool reset) -> void { function reader{&PPU::readIO, this}; function writer{&PPU::writeIO, this}; - bus.map(reader, writer, "00-3f,80-bf:2100-213f"); + bus.map(reader, writer, "00-3f,80-bf:2100-213f", false); if(!reset) random.array((uint8*)vram.data, sizeof(vram.data)); diff --git a/waterbox/bsnescore/bsnes/target-bsnescore/bsnescore.cpp b/waterbox/bsnescore/bsnes/target-bsnescore/bsnescore.cpp index c7b54e3570..0804bb8648 100644 --- a/waterbox/bsnescore/bsnes/target-bsnescore/bsnescore.cpp +++ b/waterbox/bsnescore/bsnes/target-bsnescore/bsnescore.cpp @@ -397,7 +397,7 @@ EXPORT void* snes_get_memory_region(int id, int* size, int* word_size) EXPORT uint8_t snes_bus_read(unsigned addr) { - return bus.read(addr); + return bus.peek(addr); } EXPORT void snes_bus_write(unsigned addr, uint8_t value)